spktoolbar: Fix action behavior in TSpkCheckbox and TSpkRadioButtons. Remove redundant code. Remove unneeded property Groupbehavior from these controls - THIS MAY BREAK EXISTING FORMS!

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6170 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz 2018-02-04 17:29:22 +00:00
parent a3ade40d34
commit eb414f9593
3 changed files with 34 additions and 180 deletions

View File

@ -20,8 +20,11 @@ type
TBackgroundKind = (bkSolid, bkVerticalGradient, bkHorizontalGradient,
bkConcave);
TSpkButtonState = (bsIdle,
bsBtnHottrack, bsBtnPressed, bsDropdownHottrack, bsDropdownPressed);
TSpkCheckboxStyle = (cbsCheckbox, cbsRadioButton);
TSpkCheckboxState = (cbsIdle, cbsHotTrack, cbsPressed, cbsDisabled);
// TSpkCheckboxState = (cbsIdle, cbsHotTrack, cbsPressed, cbsDisabled);
TGUITools = class(TObject)
protected
@ -294,12 +297,12 @@ type
class procedure DrawCheckbox(ACanvas: TCanvas;
x,y: Integer;
AState: TCheckboxState;
ACheckboxState: TSpkCheckboxState;
AButtonState: TSpkButtonState;
AStyle: TSpkCheckboxStyle); overload;
class procedure DrawCheckbox(ACanvas: TCanvas;
x,y: Integer;
AState: TCheckboxState;
ACheckboxState: TSpkCheckboxState;
AButtonState: TSpkButtonState;
AStyle: TSpkCheckboxStyle;
ClipRect: T2DIntRect); overload;
@ -2833,7 +2836,7 @@ begin
end;
class procedure TGUITools.DrawCheckbox(ACanvas:TCanvas; x,y: Integer;
AState: TCheckboxState; ACheckboxState:TSpkCheckboxState;
AState: TCheckboxState; AButtonState:TSpkButtonState;
AStyle: TSpkCheckboxStyle; ClipRect:T2DIntRect);
var
UseOrgClipRgn: Boolean;
@ -2847,27 +2850,29 @@ begin
if UseOrgClipRgn then
CombineRgn(ClipRgn, ClipRgn, OrgRgn, RGN_AND);
SelectClipRgn(ACanvas.Handle, ClipRgn);
DrawCheckbox(ACanvas, x,y, AState, ACheckboxState, AStyle);
DrawCheckbox(ACanvas, x,y, AState, AButtonState, AStyle);
RestoreClipRgn(ACanvas.Handle, UseOrgClipRgn, OrgRgn);
DeleteObject(ClipRgn);
end;
class procedure TGUITools.DrawCheckbox(ACanvas: TCanvas; x,y: Integer;
AState: TCheckboxState; ACheckboxState: TSpkCheckboxState;
AStyle:TSpkCheckboxStyle);
AState: TCheckboxState; AButtonState: TSpkButtonState;
AStyle: TSpkCheckboxStyle);
const
NOT_USED = tbCheckboxCheckedNormal;
const
UNTHEMED_FLAGS: array [TSpkCheckboxStyle, TCheckboxState] of Integer = (
(DFCS_BUTTONCHECK, DFCS_BUTTONCHECK or DFCS_CHECKED, DFCS_BUTTONCHECK or DFCS_BUTTON3STATE),
(DFCS_BUTTONRADIO, DFCS_BUTTONRADIO or DFCS_CHECKED, DFCS_BUTTONRADIO or DFCS_BUTTON3STATE)
);
THEMED_FLAGS: array [TSpkCheckboxStyle, TCheckboxState, TSpkCheckboxState] of TThemedButton = (
( (tbCheckboxUncheckedNormal, tbCheckboxUncheckedHot, tbCheckboxUncheckedPressed, tbCheckboxUncheckedDisabled),
(tbCheckboxCheckedNormal, tbCheckboxCheckedHot, tbCheckboxCheckedPressed, tbCheckboxCheckedDisabled),
(tbCheckboxMixedNormal, tbCheckboxMixedHot, tbCheckboxMixedPressed, tbCheckboxMixedDisabled)
THEMED_FLAGS: array [TSpkCheckboxStyle, TCheckboxState, TSpkButtonState] of TThemedButton = (
( (tbCheckboxUncheckedNormal, tbCheckboxUncheckedHot, tbCheckboxUncheckedPressed, tbCheckboxUncheckedDisabled, NOT_USED),
(tbCheckboxCheckedNormal, tbCheckboxCheckedHot, tbCheckboxCheckedPressed, tbCheckboxCheckedDisabled, NOT_USED),
(tbCheckboxMixedNormal, tbCheckboxMixedHot, tbCheckboxMixedPressed, tbCheckboxMixedDisabled, NOT_USED)
),
( (tbRadioButtonUncheckedNormal, tbRadioButtonUncheckedHot, tbRadioButtonUncheckedPressed, tbRadioButtonUncheckedDisabled),
(tbRadioButtonCheckedNormal, tbRadioButtonCheckedHot, tbRadioButtonCheckedPressed, tbRadioButtonCheckedDisabled),
(tbRadioButtonCheckedNormal, tbRadioButtonCheckedHot, tbRadioButtonCheckedPressed, tbRadioButtonCheckedDisabled)
( (tbRadioButtonUncheckedNormal, tbRadioButtonUncheckedHot, tbRadioButtonUncheckedPressed, tbRadioButtonUncheckedDisabled, NOT_USED),
(tbRadioButtonCheckedNormal, tbRadioButtonCheckedHot, tbRadioButtonCheckedPressed, tbRadioButtonCheckedDisabled, NOT_USED),
(tbRadioButtonCheckedNormal, tbRadioButtonCheckedHot, tbRadioButtonCheckedPressed, tbRadioButtonCheckedDisabled, NOT_USED)
)
);
var
@ -2877,7 +2882,7 @@ var
te: TThemedElementDetails;
begin
if ThemeServices.ThemesEnabled then begin
te := ThemeServices.GetElementDetails(THEMED_FLAGS[AStyle, AState, ACheckboxState]);
te := ThemeServices.GetElementDetails(THEMED_FLAGS[AStyle, AState, AButtonState]);
sz := ThemeServices.GetDetailSize(te);
R := Bounds(x, y, sz.cx, sz.cy);
InflateRect(R, 1, 1);

View File

@ -22,12 +22,6 @@ uses
spkt_Const, spkt_BaseItem, spkt_Exceptions, spkt_Tools;
type
TSpkButtonState = (
bsIdle,
bsBtnHottrack, bsBtnPressed,
bsDropdownHottrack, bsDropdownPressed
);
TSpkMouseButtonElement = (beNone, beButton, beDropdown);
TSpkButtonKind = (bkButton, bkButtonDropdown, bkDropdown, bkToggle);

View File

@ -9,36 +9,20 @@ uses
SpkMath, SpkGUITools, spkt_BaseItem, spkt_Buttons;
type
TSpkCustomCheckbox = class;
TSpkCheckboxActionLink = class(TSpkButtonActionLink)
protected
procedure SetChecked(Value: Boolean); override;
public
function IsCheckedLinked: Boolean; override;
end;
TSpkCustomCheckBox = class(TSPkBaseButton)
private
FState: TCheckboxState; // unchecked, checked, grayed
FCheckboxState: TSpkCheckboxState; // incl Hot, Pressed, Disabled
FHideFrameWhenIdle : boolean;
FTableBehaviour : TSpkItemTableBehaviour;
FGroupBehaviour : TSPkItemGroupBehaviour;
FCheckboxStyle: TSpkCheckboxStyle;
procedure SetGroupBehaviour(const Value: TSpkItemGroupBehaviour);
procedure SetTableBehaviour(const Value: TSpkItemTableBehaviour);
protected
procedure ActionChange(Sender : TObject);
procedure BtnStateToCheckboxState;
procedure CalcRects; override;
procedure Click; override;
procedure ConstructRect(var BtnRect: T2DIntRect);
function GetChecked: Boolean; override;
function GetDefaultCaption: String; override;
procedure SetAction(const AValue: TBasicAction); override;
procedure SetChecked(const AValue: Boolean); override;
procedure SetEnabled(const AValue: Boolean); override;
procedure SetState(AValue: TCheckboxState); virtual;
public
constructor Create(AOwner: TComponent); override;
@ -46,18 +30,11 @@ type
function GetGroupBehaviour : TSpkItemGroupBehaviour; override;
function GetSize: TSpkItemSize; override;
function GetTableBehaviour : TSpkItemTableBehaviour; override;
function GetWidth : integer; override;
procedure MouseLeave; override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer); override;
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer); override;
function GetWidth: integer; override;
published
property Checked;
property State: TCheckboxState read FState write SetState;
property TableBehaviour : TSpkItemTableBehaviour read FTableBehaviour write SetTableBehaviour;
property GroupBehaviour : TSpkItemGroupBehaviour read FGroupBehaviour write SetGroupBehaviour;
property TableBehaviour: TSpkItemTableBehaviour read FTableBehaviour write SetTableBehaviour;
end;
TSpkCheckbox = class(TSpkCustomCheckbox)
@ -72,6 +49,9 @@ type
procedure UncheckSiblings; override;
public
constructor Create(AOwner: TComponent); override;
published
property AllowAllUp;
property GroupIndex;
end;
@ -82,34 +62,12 @@ uses
SpkGraphTools, spkt_Const, spkt_Tools, spkt_Pane, spkt_Appearance;
{ TSpkCheckboxActionLink }
function TSpkCheckboxActionLink.IsCheckedLinked: Boolean;
var
cb: TSpkCustomCheckbox;
begin
cb := FClient as TSpkCustomCheckbox;
result := (inherited IsCheckedLinked) and
Assigned(cb) and (cb.Checked = (Action as TCustomAction).Checked);
end;
procedure TSpkCheckboxActionLink.SetChecked(Value: Boolean);
var
cb: TSpkCustomCheckbox;
begin
if IsCheckedLinked then
begin
cb := TSpkCustomCheckbox(FClient);
cb.Checked := Value;
end;
end;
{ TSpkCustomCheckbox }
constructor TSpkCustomCheckbox.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ButtonKind := bkToggle;
FHideFrameWhenIdle := true;
FTableBehaviour := tbContinuesRow;
FGroupBehaviour := gbSingleItem;
@ -117,36 +75,6 @@ begin
FState := cbUnchecked;
end;
procedure TSpkCustomCheckbox.ActionChange(Sender: TObject);
begin
if Sender is TCustomAction then
with TCustomAction(Sender) do
begin
if (Self.Caption = '') or (Self.Caption = GetDefaultCaption) then
Self.Caption := Caption;
if (Self.Enabled = True) then
Self.Enabled := Enabled;
if (Self.Visible = True) then
Self.Visible := Visible;
if not Assigned(Self.OnClick) then
Self.OnClick := OnExecute;
if (Self.Checked = false) then
Self.Checked := Checked;
end;
end;
procedure TSpkCustomCheckbox.BtnStateToCheckboxState;
begin
if FEnabled then
case FButtonState of
bsIdle : FCheckboxState := cbsIdle;
bsBtnHotTrack : FCheckboxState := cbsHotTrack;
bsBtnPressed : FCheckboxState := cbsPressed;
end
else
FCheckboxState := cbsDisabled;
end;
procedure TSpkCustomCheckbox.CalcRects;
var
RectVector: T2DIntVector;
@ -162,22 +90,6 @@ begin
FButtonRect := FButtonRect + RectVector;
end;
procedure TSpkCustomCheckbox.Click;
begin
if Enabled then begin
case FState of
cbGrayed : Checked := true;
cbChecked : Checked := false;
cbUnchecked : Checked := true;
end;
if not (csDesigning in ComponentState) and (FActionLink <> nil) then
FActionLink.Execute(Self)
else
if Assigned(FOnClick) and ((Action = nil) or (FOnClick <> Action.OnExecute)) then
FOnClick(Self);
end;
end;
procedure TSpkCustomCheckbox.ConstructRect(var BtnRect: T2DIntRect);
var
BtnWidth: integer;
@ -326,7 +238,7 @@ begin
ABuffer.Canvas,
x,y,
FState,
FCheckboxState,
FButtonState,
FCheckboxStyle,
ClipRect
);
@ -366,7 +278,7 @@ end;
function TSpkCustomCheckbox.GetGroupBehaviour: TSpkItemGroupBehaviour;
begin
Result := FGroupBehaviour;
Result := gbSingleitem; //FGroupBehaviour;
end;
function TSpkCustomCheckbox.GetSize: TSpkItemSize;
@ -392,79 +304,20 @@ begin
Result := BtnRect.Right + 1;
end;
procedure TSpkCustomCheckbox.MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer);
begin
inherited;
BtnStateToCheckboxState;
end;
procedure TSpkCustomCheckbox.MouseLeave;
begin
inherited MouseLeave;
if FEnabled then
FCheckboxState := cbsIdle
else
FCheckboxState := cbsDisabled;
end;
procedure TSpkCustomCheckbox.MouseMove(Shift: TShiftState; X, Y: Integer);
begin
inherited MouseMove(Shift, X, Y);
BtnStateToCheckboxState;
end;
procedure TSpkCustomCheckbox.MouseUp(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer);
begin
inherited MouseUp(Button, Shift, X, Y);
BtnStateToCheckboxState;
end;
procedure TSpkCustomCheckbox.SetAction(const AValue: TBasicAction);
begin
if AValue = nil then begin
FActionLink.Free;
FActionLink := nil;
end else begin
if FActionLink = nil then
FActionLink := TSpkCheckboxActionLink.Create(self);
FActionLink.Action := AValue;
FActionLink.OnChange := @ActionChange;
ActionChange(AValue);
end;
end;
procedure TSpkCustomCheckbox.SetChecked(const AValue: Boolean);
begin
if AValue then
inherited SetChecked(AValue);
if FChecked then
SetState(cbChecked)
else
SetState(cbUnchecked);
end;
procedure TSpkCustomCheckbox.SetEnabled(const AValue: Boolean);
begin
inherited SetEnabled(AValue);
BtnStateToCheckboxState;
end;
procedure TSpkCustomCheckbox.SetGroupBehaviour(const Value: TSpkItemGroupBehaviour);
begin
FGroupBehaviour := Value;
if Assigned(FToolbarDispatch) then
FToolbarDispatch.NotifyMetricsChanged;
end;
procedure TSpkCustomCheckbox.SetState(AValue:TCheckboxState);
begin
if AValue <> FState then
begin
FState := AValue;
{
if Assigned(FToolbarDispatch) then
FToolbarDispatch.NotifyVisualsChanged;
}
inherited SetChecked(Checked);
end;
end;
@ -518,8 +371,10 @@ begin
if (pane.Items[i] is TSpkRadioButton) then
begin
rb := TSpkRadioButton(pane.Items[i]);
if (rb <> self) and (rb.GroupIndex = GroupIndex) then
rb.State := cbUnchecked;
if (rb <> self) and (rb.GroupIndex = GroupIndex) then begin
rb.FChecked := false;
rb.FState := cbUnchecked;
end;
end;
end;
end;