mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-13 12:29:24 +02:00
customdrawn: Fixes the checked states in buttons and fixes focus by mouse in all controls
git-svn-id: trunk@33281 -
This commit is contained in:
parent
943326f458
commit
d381754c91
@ -47,6 +47,8 @@ type
|
|||||||
// mouse
|
// mouse
|
||||||
procedure MouseEnter; override;
|
procedure MouseEnter; override;
|
||||||
procedure MouseLeave; override;
|
procedure MouseLeave; override;
|
||||||
|
procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
|
||||||
|
X, Y: integer); override;
|
||||||
//
|
//
|
||||||
property DrawStyle: TCDDrawStyle read FDrawStyle write SetDrawStyle;
|
property DrawStyle: TCDDrawStyle read FDrawStyle write SetDrawStyle;
|
||||||
public
|
public
|
||||||
@ -65,6 +67,9 @@ type
|
|||||||
TCDButtonControl = class(TCDControl)
|
TCDButtonControl = class(TCDControl)
|
||||||
private
|
private
|
||||||
protected
|
protected
|
||||||
|
// This fields are set by descendents
|
||||||
|
FHasOnOffStates: Boolean;
|
||||||
|
FHasPartiallyOnState: Boolean;
|
||||||
// keyboard
|
// keyboard
|
||||||
procedure DoEnter; override;
|
procedure DoEnter; override;
|
||||||
procedure DoExit; override;
|
procedure DoExit; override;
|
||||||
@ -173,26 +178,6 @@ type
|
|||||||
property Text: string read GetText write SetText;
|
property Text: string read GetText write SetText;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{@@
|
|
||||||
TCDGroupBox is a custom-drawn group box control
|
|
||||||
}
|
|
||||||
|
|
||||||
{ TCDGroupBox }
|
|
||||||
|
|
||||||
TCDGroupBox = class(TCDControl)
|
|
||||||
private
|
|
||||||
function GetControlId: TCDControlID; override;
|
|
||||||
protected
|
|
||||||
procedure RealSetText(const Value: TCaption); override; // to update on caption changes
|
|
||||||
public
|
|
||||||
constructor Create(AOwner: TComponent); override;
|
|
||||||
destructor Destroy; override;
|
|
||||||
published
|
|
||||||
property DrawStyle;
|
|
||||||
property Caption;
|
|
||||||
property TabStop default False;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{ TCDCheckBox }
|
{ TCDCheckBox }
|
||||||
|
|
||||||
TCDCheckBox = class(TCDButtonControl)
|
TCDCheckBox = class(TCDButtonControl)
|
||||||
@ -213,6 +198,26 @@ type
|
|||||||
property State: TCheckBoxState read FCheckedState write FCheckedState default cbUnchecked;
|
property State: TCheckBoxState read FCheckedState write FCheckedState default cbUnchecked;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{@@
|
||||||
|
TCDGroupBox is a custom-drawn group box control
|
||||||
|
}
|
||||||
|
|
||||||
|
{ TCDGroupBox }
|
||||||
|
|
||||||
|
TCDGroupBox = class(TCDControl)
|
||||||
|
private
|
||||||
|
function GetControlId: TCDControlID; override;
|
||||||
|
protected
|
||||||
|
procedure RealSetText(const Value: TCaption); override; // to update on caption changes
|
||||||
|
public
|
||||||
|
constructor Create(AOwner: TComponent); override;
|
||||||
|
destructor Destroy; override;
|
||||||
|
published
|
||||||
|
property DrawStyle;
|
||||||
|
property Caption;
|
||||||
|
property TabStop default False;
|
||||||
|
end;
|
||||||
|
|
||||||
// ===================================
|
// ===================================
|
||||||
// Common Controls Tab
|
// Common Controls Tab
|
||||||
// ===================================
|
// ===================================
|
||||||
@ -633,8 +638,7 @@ begin
|
|||||||
Width := 80;
|
Width := 80;
|
||||||
Height := 25;
|
Height := 25;
|
||||||
TabStop := True;
|
TabStop := True;
|
||||||
ControlStyle := [csCaptureMouse, csClickEvents,
|
ControlStyle := ControlStyle - [csAcceptsControls];
|
||||||
csDoubleClicks, csReplicatable];
|
|
||||||
|
|
||||||
// State information
|
// State information
|
||||||
FEditState.VisibleTextStart := 1;
|
FEditState.VisibleTextStart := 1;
|
||||||
@ -692,6 +696,7 @@ begin
|
|||||||
ControlStyle := [csCaptureMouse, csClickEvents,
|
ControlStyle := [csCaptureMouse, csClickEvents,
|
||||||
csDoubleClicks, csReplicatable];
|
csDoubleClicks, csReplicatable];
|
||||||
AutoSize := True;
|
AutoSize := True;
|
||||||
|
FHasOnOffStates := True;
|
||||||
|
|
||||||
PrepareCurrentDrawer();
|
PrepareCurrentDrawer();
|
||||||
end;
|
end;
|
||||||
@ -939,6 +944,13 @@ begin
|
|||||||
inherited MouseLeave;
|
inherited MouseLeave;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCDControl.MouseDown(Button: TMouseButton; Shift: TShiftState; X,
|
||||||
|
Y: integer);
|
||||||
|
begin
|
||||||
|
inherited MouseDown(Button, Shift, X, Y);
|
||||||
|
SetFocus();
|
||||||
|
end;
|
||||||
|
|
||||||
constructor TCDControl.Create(AOwner: TComponent);
|
constructor TCDControl.Create(AOwner: TComponent);
|
||||||
begin
|
begin
|
||||||
inherited Create(AOwner);
|
inherited Create(AOwner);
|
||||||
@ -988,8 +1000,6 @@ end;
|
|||||||
|
|
||||||
procedure TCDButtonControl.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: integer);
|
procedure TCDButtonControl.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: integer);
|
||||||
begin
|
begin
|
||||||
if not Focused then
|
|
||||||
SetFocus;
|
|
||||||
DoButtonDown();
|
DoButtonDown();
|
||||||
|
|
||||||
inherited MouseDown(Button, Shift, X, Y);
|
inherited MouseDown(Button, Shift, X, Y);
|
||||||
@ -1030,6 +1040,26 @@ begin
|
|||||||
FState := FState - [csfSunken];
|
FState := FState - [csfSunken];
|
||||||
Invalidate;
|
Invalidate;
|
||||||
end;
|
end;
|
||||||
|
// Only for buttons with checked/down states
|
||||||
|
if FHasOnOffStates then
|
||||||
|
begin
|
||||||
|
if FHasPartiallyOnState then
|
||||||
|
begin
|
||||||
|
if csfOn in FState then
|
||||||
|
FState := FState + [csfOff] - [csfOn, csfPartiallyOn]
|
||||||
|
else if csfPartiallyOn in FState then
|
||||||
|
FState := FState + [csfOn] - [csfOff, csfPartiallyOn]
|
||||||
|
else
|
||||||
|
FState := FState + [csfPartiallyOn] - [csfOn, csfOff];
|
||||||
|
end
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
if csfOn in FState then
|
||||||
|
FState := FState + [csfOff] - [csfOn]
|
||||||
|
else
|
||||||
|
FState := FState + [csfOn] - [csfOff];
|
||||||
|
end;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCDButtonControl.RealSetText(const Value: TCaption);
|
procedure TCDButtonControl.RealSetText(const Value: TCaption);
|
||||||
|
Loading…
Reference in New Issue
Block a user