You've already forked lazarus-ccr
Industrial: Add property Switchmode to TOnOffSwitch to control how the switch state can be changed by the mouse.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8965 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -59,6 +59,9 @@
|
|||||||
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
|
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
|
||||||
</SearchPaths>
|
</SearchPaths>
|
||||||
<Linking>
|
<Linking>
|
||||||
|
<Debugging>
|
||||||
|
<DebugInfoType Value="dsDwarf3"/>
|
||||||
|
</Debugging>
|
||||||
<Options>
|
<Options>
|
||||||
<Win32>
|
<Win32>
|
||||||
<GraphicApplication Value="True"/>
|
<GraphicApplication Value="True"/>
|
||||||
|
@ -26,6 +26,7 @@ type
|
|||||||
bsNone, bsThin, bsThick, bsThin3D, bsThick3D,
|
bsNone, bsThin, bsThick, bsThin3D, bsThick3D,
|
||||||
bsNoneRounded, bsThinRounded, bsThickRounded
|
bsNoneRounded, bsThinRounded, bsThickRounded
|
||||||
);
|
);
|
||||||
|
TSwitchMode = (smClick, smDblClick, smSlide, smSlideDblClick);
|
||||||
TSwitchOrientation = (soHorizontal, soVertical);
|
TSwitchOrientation = (soHorizontal, soVertical);
|
||||||
|
|
||||||
TCustomOnOffSwitch = class(TCustomControl)
|
TCustomOnOffSwitch = class(TCustomControl)
|
||||||
@ -49,6 +50,7 @@ type
|
|||||||
FShowButtonBorder: Boolean;
|
FShowButtonBorder: Boolean;
|
||||||
FShowCaption: Boolean;
|
FShowCaption: Boolean;
|
||||||
FShowFocusRect: Boolean;
|
FShowFocusRect: Boolean;
|
||||||
|
FSwitchMode: TSwitchMode;
|
||||||
FOnChange: TNotifyEvent;
|
FOnChange: TNotifyEvent;
|
||||||
FDblClickTimer: TTimer;
|
FDblClickTimer: TTimer;
|
||||||
FPicture: array[0..1] of TPicture;
|
FPicture: array[0..1] of TPicture;
|
||||||
@ -85,6 +87,7 @@ type
|
|||||||
procedure DrawCaption(ARect: TRect; AChecked: Boolean); virtual;
|
procedure DrawCaption(ARect: TRect; AChecked: Boolean); virtual;
|
||||||
procedure DrawFocusRect(ARect: TRect);
|
procedure DrawFocusRect(ARect: TRect);
|
||||||
class function GetControlClassDefaultSize: TSize; override;
|
class function GetControlClassDefaultSize: TSize; override;
|
||||||
|
function HasPicture: Boolean;
|
||||||
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
|
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
|
||||||
procedure MouseDown(Button: TMouseButton; Shift:TShiftState; X,Y:Integer); override;
|
procedure MouseDown(Button: TMouseButton; Shift:TShiftState; X,Y:Integer); override;
|
||||||
procedure MouseMove(Shift: TShiftState; X,Y: Integer); override;
|
procedure MouseMove(Shift: TShiftState; X,Y: Integer); override;
|
||||||
@ -108,6 +111,7 @@ type
|
|||||||
property ShowButtonBorder: Boolean read FShowButtonBorder write SetShowButtonBorder default true;
|
property ShowButtonBorder: Boolean read FShowButtonBorder write SetShowButtonBorder default true;
|
||||||
property ShowFocusRect: Boolean read FShowFocusRect write SetShowFocusRect default true;
|
property ShowFocusRect: Boolean read FShowFocusRect write SetShowFocusRect default true;
|
||||||
property ShowCaption: Boolean read FShowCaption write SetShowCaption default true;
|
property ShowCaption: Boolean read FShowCaption write SetShowCaption default true;
|
||||||
|
property SwitchMode: TSwitchMode read FSwitchMode write FSwitchMode default smSlideDblClick;
|
||||||
property OnChange: TNotifyEvent read FOnChange write FOnChange;
|
property OnChange: TNotifyEvent read FOnChange write FOnChange;
|
||||||
public
|
public
|
||||||
constructor Create(AOwner: TComponent); override;
|
constructor Create(AOwner: TComponent); override;
|
||||||
@ -135,6 +139,7 @@ type
|
|||||||
property ShowButtonBorder;
|
property ShowButtonBorder;
|
||||||
property ShowCaption;
|
property ShowCaption;
|
||||||
property ShowFocusRect;
|
property ShowFocusRect;
|
||||||
|
property SwitchMode;
|
||||||
|
|
||||||
// inherited
|
// inherited
|
||||||
property Action;
|
property Action;
|
||||||
@ -214,6 +219,7 @@ begin
|
|||||||
FShowCaption := true;
|
FShowCaption := true;
|
||||||
FShowButtonBorder := true;
|
FShowButtonBorder := true;
|
||||||
FShowFocusRect := true;
|
FShowFocusRect := true;
|
||||||
|
FSwitchMode := smSlideDblClick;
|
||||||
FDblClickTimer := TTimer.Create(self);
|
FDblClickTimer := TTimer.Create(self);
|
||||||
FDblClickTimer.Interval := 500;
|
FDblClickTimer.Interval := 500;
|
||||||
FDblClickTimer.Enabled := false;
|
FDblClickTimer.Enabled := false;
|
||||||
@ -453,6 +459,11 @@ begin
|
|||||||
Result := FPicture[AIndex];
|
Result := FPicture[AIndex];
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TCustomOnOffSwitch.HasPicture: Boolean;
|
||||||
|
begin
|
||||||
|
Result := (FPicture[0].Width <> 0) or (FPicture[1].Width <> 0);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TCustomOnOffSwitch.KeyDown(var Key: Word; Shift: TShiftState);
|
procedure TCustomOnOffSwitch.KeyDown(var Key: Word; Shift: TShiftState);
|
||||||
begin
|
begin
|
||||||
inherited;
|
inherited;
|
||||||
@ -465,7 +476,7 @@ begin
|
|||||||
inherited;
|
inherited;
|
||||||
SetFocus;
|
SetFocus;
|
||||||
if CanChange and (Button = mbLeft) and MouseOnButton(X, Y) then begin
|
if CanChange and (Button = mbLeft) and MouseOnButton(X, Y) then begin
|
||||||
FDragging := true;
|
if (FSwitchMode in [smSlide, smSlideDblClick]) then FDragging := true;
|
||||||
FMousePt := Point(X, Y);
|
FMousePt := Point(X, Y);
|
||||||
FDraggedDistance := 0;
|
FDraggedDistance := 0;
|
||||||
FDblClickTimer.Enabled := true;
|
FDblClickTimer.Enabled := true;
|
||||||
@ -498,21 +509,25 @@ var
|
|||||||
d: Integer;
|
d: Integer;
|
||||||
begin
|
begin
|
||||||
inherited;
|
inherited;
|
||||||
if Button = mbLeft then begin
|
if (Button = mbLeft) and CanChange then begin
|
||||||
oldChecked := FChecked;
|
oldChecked := FChecked;
|
||||||
d := FDraggedDistance;
|
d := FDraggedDistance;
|
||||||
FDraggedDistance := 0;
|
FDraggedDistance := 0;
|
||||||
if FDragging then begin
|
if FDragging then begin
|
||||||
FChecked := DraggingToValue(d);
|
FChecked := DraggingToValue(d);
|
||||||
end;
|
FDragging := false;
|
||||||
FDragging := false;
|
end else
|
||||||
if CanChange then begin
|
begin
|
||||||
|
if (FSwitchMode = smClick) or (HasPicture and (FSwitchMode = smSlide)) then
|
||||||
|
FChecked := not FChecked;
|
||||||
if FChecked <> oldChecked then
|
if FChecked <> oldChecked then
|
||||||
DoChange
|
DoChange
|
||||||
else
|
else
|
||||||
|
if (FSwitchMode in [smDblClick, smSlideDblClick]) then
|
||||||
FTogglePending := true;
|
FTogglePending := true;
|
||||||
end;
|
end;
|
||||||
Invalidate;
|
if FChecked <> oldChecked then
|
||||||
|
Invalidate;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -527,7 +542,7 @@ begin
|
|||||||
R := Rect(0, 0, Width, Height);
|
R := Rect(0, 0, Width, Height);
|
||||||
|
|
||||||
picIdx := IfThen(FChecked, 1, 0);
|
picIdx := IfThen(FChecked, 1, 0);
|
||||||
if FPicture[picIdx].Width > 0 then
|
if HasPicture then
|
||||||
begin
|
begin
|
||||||
Canvas.StretchDraw(R, FPicture[picIdx].Graphic);
|
Canvas.StretchDraw(R, FPicture[picIdx].Graphic);
|
||||||
exit;
|
exit;
|
||||||
|
Reference in New Issue
Block a user