2012-06-04 00:49:51 +00:00
|
|
|
unit spkt_Checkboxes;
|
|
|
|
|
|
|
|
{$mode objfpc}{$H+}
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
Graphics, Classes, SysUtils, Controls, StdCtrls, ActnList,
|
|
|
|
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);
|
2016-11-27 16:13:48 +00:00
|
|
|
function GetChecked: Boolean; override;
|
2012-06-04 00:49:51 +00:00
|
|
|
function GetDefaultCaption: String; override;
|
|
|
|
procedure SetAction(const AValue: TBasicAction); override;
|
2016-11-27 16:13:48 +00:00
|
|
|
procedure SetChecked(const AValue: Boolean); override;
|
2012-06-04 00:49:51 +00:00
|
|
|
procedure SetEnabled(const AValue: Boolean); override;
|
|
|
|
procedure SetState(AValue: TCheckboxState); virtual;
|
|
|
|
public
|
|
|
|
constructor Create(AOwner: TComponent); override;
|
|
|
|
procedure Draw(ABuffer: TBitmap; ClipRect: T2DIntRect); override;
|
|
|
|
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;
|
|
|
|
published
|
2016-11-27 16:13:48 +00:00
|
|
|
property Checked;
|
2012-06-04 00:49:51 +00:00
|
|
|
property State: TCheckboxState read FState write SetState;
|
|
|
|
property TableBehaviour : TSpkItemTableBehaviour read FTableBehaviour write SetTableBehaviour;
|
|
|
|
property GroupBehaviour : TSpkItemGroupBehaviour read FGroupBehaviour write SetGroupBehaviour;
|
|
|
|
end;
|
|
|
|
|
|
|
|
TSpkCheckbox = class(TSpkCustomCheckbox)
|
|
|
|
public
|
|
|
|
constructor Create(AOwner: TComponent); override;
|
|
|
|
end;
|
|
|
|
|
|
|
|
TSpkRadioButton = class(TSpkCustomCheckbox)
|
|
|
|
protected
|
|
|
|
function GetDefaultCaption: String; override;
|
|
|
|
procedure SetState(AValue: TCheckboxState); override;
|
2016-11-27 16:13:48 +00:00
|
|
|
procedure UncheckSiblings; override;
|
2012-06-04 00:49:51 +00:00
|
|
|
public
|
|
|
|
constructor Create(AOwner: TComponent); override;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
2014-10-13 19:04:19 +00:00
|
|
|
LCLType, LCLIntf, Math, Themes,
|
2016-11-18 22:22:49 +00:00
|
|
|
SpkGraphTools, spkt_Const, spkt_Tools, spkt_Pane, spkt_Appearance;
|
2012-06-04 00:49:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
{ 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
|
2016-11-26 23:56:34 +00:00
|
|
|
if IsCheckedLinked then
|
|
|
|
begin
|
2012-06-04 00:49:51 +00:00
|
|
|
cb := TSpkCustomCheckbox(FClient);
|
|
|
|
cb.Checked := Value;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
{ TSpkCustomCheckbox }
|
|
|
|
|
|
|
|
constructor TSpkCustomCheckbox.Create(AOwner: TComponent);
|
|
|
|
begin
|
|
|
|
inherited Create(AOwner);
|
|
|
|
FHideFrameWhenIdle := true;
|
|
|
|
FTableBehaviour := tbContinuesRow;
|
|
|
|
FGroupBehaviour := gbSingleItem;
|
|
|
|
FCheckboxStyle := cbsCheckbox;
|
|
|
|
FState := cbUnchecked;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TSpkCustomCheckbox.ActionChange(Sender: TObject);
|
|
|
|
begin
|
|
|
|
if Sender is TCustomAction then
|
2016-11-26 23:56:34 +00:00
|
|
|
with TCustomAction(Sender) do
|
|
|
|
begin
|
2012-06-04 00:49:51 +00:00
|
|
|
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
|
2016-11-26 23:56:34 +00:00
|
|
|
RectVector: T2DIntVector;
|
2012-06-04 00:49:51 +00:00
|
|
|
begin
|
|
|
|
ConstructRect(FButtonRect);
|
|
|
|
{$IFDEF EnhancedRecordSupport}
|
|
|
|
FDropdownRect := T2DIntRect.Create(0, 0, 0, 0);
|
|
|
|
RectVector := T2DIntVector.Create(FRect.Left, FRect.Top);
|
|
|
|
{$ELSE}
|
|
|
|
FDropdownRect.Create(0, 0, 0, 0);
|
|
|
|
RectVector.Create(FRect.Left, FRect.Top);
|
|
|
|
{$ENDIF}
|
|
|
|
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
|
2016-11-26 23:56:34 +00:00
|
|
|
BtnWidth: integer;
|
|
|
|
Bitmap: TBitmap;
|
2012-06-04 00:49:51 +00:00
|
|
|
TextWidth: Integer;
|
|
|
|
begin
|
|
|
|
{$IFDEF EnhancedRecordSupport}
|
2016-11-26 23:56:34 +00:00
|
|
|
BtnRect := T2DIntRect.Create(0, 0, 0, 0);
|
2012-06-04 00:49:51 +00:00
|
|
|
{$ELSE}
|
|
|
|
BtnRect.Create(0, 0, 0, 0);
|
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
if not(Assigned(FToolbarDispatch)) then
|
|
|
|
exit;
|
|
|
|
if not(Assigned(FAppearance)) then
|
|
|
|
exit;
|
|
|
|
|
|
|
|
Bitmap := FToolbarDispatch.GetTempBitmap;
|
2016-11-26 23:56:34 +00:00
|
|
|
if not Assigned(Bitmap) then
|
2012-06-04 00:49:51 +00:00
|
|
|
exit;
|
|
|
|
|
|
|
|
Bitmap.Canvas.Font.Assign(FAppearance.Element.CaptionFont);
|
|
|
|
TextWidth := Bitmap.Canvas.TextWidth(FCaption);
|
|
|
|
|
2016-08-05 21:11:23 +00:00
|
|
|
BtnWidth := SmallButtonPadding + SmallButtonGlyphWidth +
|
|
|
|
SmallButtonPadding + TextWidth + SmallButtonPadding;
|
|
|
|
BtnWidth := Max(SmallButtonMinWidth, BtnWidth);
|
2012-06-04 00:49:51 +00:00
|
|
|
|
|
|
|
if FGroupBehaviour in [gbContinuesGroup, gbEndsGroup] then
|
2016-08-05 21:11:23 +00:00
|
|
|
BtnWidth := BtnWidth + SmallButtonHalfBorderWidth
|
2012-06-04 00:49:51 +00:00
|
|
|
else
|
2016-08-05 21:11:23 +00:00
|
|
|
BtnWidth := BtnWidth + SmallButtonBorderWidth;
|
2012-06-04 00:49:51 +00:00
|
|
|
|
|
|
|
// Prawa krawêdŸ przycisku
|
|
|
|
if (FGroupBehaviour in [gbBeginsGroup, gbContinuesGroup]) then
|
2016-08-05 21:11:23 +00:00
|
|
|
BtnWidth := BtnWidth + SmallButtonHalfBorderWidth
|
2012-06-04 00:49:51 +00:00
|
|
|
else
|
2016-08-05 21:11:23 +00:00
|
|
|
BtnWidth := BtnWidth + SmallButtonBorderWidth;
|
2012-06-04 00:49:51 +00:00
|
|
|
|
|
|
|
{$IFDEF EnhancedRecordSupport}
|
2016-08-05 21:11:23 +00:00
|
|
|
BtnRect := T2DIntRect.Create(0, 0, BtnWidth - 1, PaneRowHeight - 1);
|
2012-06-04 00:49:51 +00:00
|
|
|
{$ELSE}
|
2016-08-05 21:11:23 +00:00
|
|
|
BtnRect.Create(0, 0, BtnWidth - 1, PaneRowHeight - 1);
|
2012-06-04 00:49:51 +00:00
|
|
|
{$ENDIF}
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TSpkCustomCheckbox.Draw(ABuffer: TBitmap; ClipRect: T2DIntRect);
|
|
|
|
var
|
2016-11-18 22:22:49 +00:00
|
|
|
fontColor: TColor;
|
2012-06-04 00:49:51 +00:00
|
|
|
x, y: Integer;
|
|
|
|
h: Integer;
|
2014-10-13 19:04:19 +00:00
|
|
|
te: TThemedElementDetails;
|
2016-11-18 22:22:49 +00:00
|
|
|
cornerRadius: Integer;
|
2012-06-04 00:49:51 +00:00
|
|
|
begin
|
|
|
|
if FToolbarDispatch = nil then
|
|
|
|
exit;
|
|
|
|
if FAppearance = nil then
|
|
|
|
exit;
|
2016-08-05 21:11:23 +00:00
|
|
|
if (FRect.Width < 2*LargeButtonRadius) or (FRect.Height < 2*LargeButtonRadius) then
|
2012-06-04 00:49:51 +00:00
|
|
|
exit;
|
|
|
|
|
2016-11-18 22:22:49 +00:00
|
|
|
case FAppearance.Element.Style of
|
|
|
|
esRounded:
|
|
|
|
cornerRadius := SmallButtonRadius;
|
|
|
|
esRectangle:
|
|
|
|
cornerRadius := 0;
|
|
|
|
end;
|
|
|
|
|
2012-06-04 00:49:51 +00:00
|
|
|
// Border
|
2016-11-26 23:56:34 +00:00
|
|
|
if (FButtonState = bsIdle) and (not(FHideFrameWhenIdle)) then
|
|
|
|
begin
|
2012-06-04 00:49:51 +00:00
|
|
|
with FAppearance.Element do
|
|
|
|
TButtonTools.DrawButton(
|
|
|
|
ABuffer,
|
|
|
|
FButtonRect,
|
|
|
|
IdleFrameColor,
|
|
|
|
IdleInnerLightColor,
|
|
|
|
IdleInnerDarkColor,
|
|
|
|
IdleGradientFromColor,
|
|
|
|
IdleGradientToColor,
|
|
|
|
IdleGradientType,
|
|
|
|
(FGroupBehaviour in [gbContinuesGroup, gbEndsGroup]),
|
|
|
|
(FGroupBehaviour in [gbBeginsGroup, gbContinuesGroup]) or (FButtonKind = bkButtonDropdown),
|
|
|
|
false,
|
|
|
|
false,
|
2016-11-18 22:22:49 +00:00
|
|
|
cornerRadius,
|
2012-06-04 00:49:51 +00:00
|
|
|
ClipRect
|
|
|
|
);
|
|
|
|
end else
|
2016-11-26 23:56:34 +00:00
|
|
|
if (FButtonState=bsBtnHottrack) then
|
|
|
|
begin
|
2012-06-04 00:49:51 +00:00
|
|
|
with FAppearance.Element do
|
|
|
|
TButtonTools.DrawButton(
|
|
|
|
ABuffer,
|
|
|
|
FButtonRect,
|
|
|
|
HotTrackFrameColor,
|
|
|
|
HotTrackInnerLightColor,
|
|
|
|
HotTrackInnerDarkColor,
|
|
|
|
HotTrackGradientFromColor,
|
|
|
|
HotTrackGradientToColor,
|
|
|
|
HotTrackGradientType,
|
|
|
|
(FGroupBehaviour in [gbContinuesGroup, gbEndsGroup]),
|
|
|
|
(FGroupBehaviour in [gbBeginsGroup, gbContinuesGroup]) or (FButtonKind = bkButtonDropdown),
|
|
|
|
false,
|
|
|
|
false,
|
2016-11-18 22:22:49 +00:00
|
|
|
cornerRadius,
|
2012-06-04 00:49:51 +00:00
|
|
|
ClipRect
|
|
|
|
);
|
|
|
|
end else
|
2016-11-26 23:56:34 +00:00
|
|
|
if (FButtonState = bsBtnPressed) then
|
|
|
|
begin
|
2012-06-04 00:49:51 +00:00
|
|
|
with FAppearance.Element do
|
|
|
|
TButtonTools.DrawButton(
|
|
|
|
ABuffer,
|
|
|
|
FButtonRect,
|
|
|
|
ActiveFrameColor,
|
|
|
|
ActiveInnerLightColor,
|
|
|
|
ActiveInnerDarkColor,
|
|
|
|
ActiveGradientFromColor,
|
|
|
|
ActiveGradientToColor,
|
|
|
|
ActiveGradientType,
|
|
|
|
(FGroupBehaviour in [gbContinuesGroup, gbEndsGroup]),
|
|
|
|
(FGroupBehaviour in [gbBeginsGroup, gbContinuesGroup]) or (FButtonKind = bkButtonDropdown),
|
|
|
|
false,
|
|
|
|
false,
|
2016-11-18 22:22:49 +00:00
|
|
|
cornerRadius,
|
2012-06-04 00:49:51 +00:00
|
|
|
ClipRect
|
|
|
|
);
|
|
|
|
end;
|
|
|
|
|
|
|
|
// Checkbox
|
2016-11-26 23:56:34 +00:00
|
|
|
if ThemeServices.ThemesEnabled then
|
|
|
|
begin
|
2014-10-13 19:04:19 +00:00
|
|
|
te := ThemeServices.GetElementDetails(tbCheckboxCheckedNormal);
|
|
|
|
h := ThemeServices.GetDetailSize(te).cy;
|
|
|
|
end else
|
|
|
|
h := GetSystemMetrics(SM_CYMENUCHECK);
|
2016-11-26 23:56:34 +00:00
|
|
|
|
2012-06-04 00:49:51 +00:00
|
|
|
if (FGroupBehaviour in [gbContinuesGroup, gbEndsGroup]) then
|
2016-08-05 21:11:23 +00:00
|
|
|
x := FButtonRect.Left + SmallButtonHalfBorderWidth + SmallButtonPadding
|
2012-06-04 00:49:51 +00:00
|
|
|
else
|
2016-08-05 21:11:23 +00:00
|
|
|
x := FButtonRect.Left + SmallButtonBorderWidth + SmallButtonPadding;
|
2014-10-13 19:04:19 +00:00
|
|
|
y := FButtonRect.Top + (FButtonRect.Height - h) div 2;
|
2012-06-04 00:49:51 +00:00
|
|
|
|
|
|
|
TGUITools.DrawCheckbox(
|
|
|
|
ABuffer.Canvas,
|
|
|
|
x,y,
|
|
|
|
FState,
|
|
|
|
FCheckboxState,
|
|
|
|
FCheckboxStyle,
|
|
|
|
ClipRect
|
|
|
|
);
|
|
|
|
|
|
|
|
// Text
|
|
|
|
ABuffer.Canvas.Font.Assign(FAppearance.Element.CaptionFont);
|
|
|
|
|
2016-11-18 22:22:49 +00:00
|
|
|
case FButtonState of
|
|
|
|
bsIdle : fontColor := FAppearance.Element.IdleCaptionColor;
|
|
|
|
bsBtnHottrack,
|
|
|
|
bsDropdownHottrack : fontColor := FAppearance.Element.HotTrackCaptionColor;
|
|
|
|
bsBtnPressed,
|
|
|
|
bsDropdownPressed : fontColor := FAppearance.ELement.ActiveCaptionColor;
|
|
|
|
end;
|
2012-06-04 00:49:51 +00:00
|
|
|
if not(FEnabled) then
|
2016-11-18 22:22:49 +00:00
|
|
|
fontColor := TColorTools.ColorToGrayscale(fontColor);
|
2012-06-04 00:49:51 +00:00
|
|
|
|
|
|
|
if (FGroupBehaviour in [gbContinuesGroup, gbEndsGroup]) then
|
2016-08-05 21:11:23 +00:00
|
|
|
x := FButtonRect.Left + SmallButtonHalfBorderWidth
|
2012-06-04 00:49:51 +00:00
|
|
|
else
|
2016-08-05 21:11:23 +00:00
|
|
|
x := FButtonRect.Left + SmallButtonBorderWidth;
|
|
|
|
x := x + 2 * SmallButtonPadding + SmallButtonGlyphWidth;
|
2012-06-04 00:49:51 +00:00
|
|
|
y := FButtonRect.Top + (FButtonRect.Height - ABuffer.Canvas.TextHeight('Wy')) div 2;
|
|
|
|
|
2016-11-18 22:22:49 +00:00
|
|
|
TGUITools.DrawText(ABuffer.Canvas, x, y, FCaption, fontColor, ClipRect);
|
2012-06-04 00:49:51 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TSpkCustomCheckbox.GetChecked: Boolean;
|
|
|
|
begin
|
2016-11-26 23:56:34 +00:00
|
|
|
Result := (FState = cbChecked);
|
2012-06-04 00:49:51 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TSpkCustomCheckbox.GetDefaultCaption: String;
|
|
|
|
begin
|
2016-11-26 23:56:34 +00:00
|
|
|
Result := 'Checkbox';
|
2012-06-04 00:49:51 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TSpkCustomCheckbox.GetGroupBehaviour: TSpkItemGroupBehaviour;
|
|
|
|
begin
|
2016-11-26 23:56:34 +00:00
|
|
|
Result := FGroupBehaviour;
|
2012-06-04 00:49:51 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TSpkCustomCheckbox.GetSize: TSpkItemSize;
|
|
|
|
begin
|
2016-11-26 23:56:34 +00:00
|
|
|
Result := isNormal;
|
2012-06-04 00:49:51 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TSpkCustomCheckbox.GetTableBehaviour: TSpkItemTableBehaviour;
|
|
|
|
begin
|
2016-11-26 23:56:34 +00:00
|
|
|
Result := FTableBehaviour;
|
2012-06-04 00:49:51 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TSpkCustomCheckbox.GetWidth: integer;
|
|
|
|
var
|
2016-11-26 23:56:34 +00:00
|
|
|
BtnRect, DropRect: T2DIntRect;
|
2012-06-04 00:49:51 +00:00
|
|
|
begin
|
2016-11-26 23:56:34 +00:00
|
|
|
Result := -1;
|
2012-06-04 00:49:51 +00:00
|
|
|
if FToolbarDispatch = nil then
|
|
|
|
exit;
|
|
|
|
if FAppearance = nil then
|
|
|
|
exit;
|
|
|
|
ConstructRect(BtnRect);
|
2016-11-26 23:56:34 +00:00
|
|
|
Result := BtnRect.Right + 1;
|
2012-06-04 00:49:51 +00:00
|
|
|
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;
|
|
|
|
|
2016-11-27 16:13:48 +00:00
|
|
|
procedure TSpkCustomCheckbox.SetChecked(const AValue: Boolean);
|
2012-06-04 00:49:51 +00:00
|
|
|
begin
|
|
|
|
if AValue 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
|
2016-11-26 23:56:34 +00:00
|
|
|
if AValue <> FState then
|
|
|
|
begin
|
2012-06-04 00:49:51 +00:00
|
|
|
FState := AValue;
|
2016-11-27 18:50:10 +00:00
|
|
|
{
|
2012-06-04 00:49:51 +00:00
|
|
|
if Assigned(FToolbarDispatch) then
|
|
|
|
FToolbarDispatch.NotifyVisualsChanged;
|
2016-11-27 18:50:10 +00:00
|
|
|
}
|
|
|
|
inherited SetChecked(Checked);
|
2012-06-04 00:49:51 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TSpkCustomCheckbox.SetTableBehaviour(const Value: TSpkItemTableBehaviour);
|
|
|
|
begin
|
|
|
|
FTableBehaviour := Value;
|
|
|
|
if Assigned(FToolbarDispatch) then
|
2016-11-27 16:13:48 +00:00
|
|
|
FToolbarDispatch.NotifyMetricsChanged;
|
2012-06-04 00:49:51 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
{ TSpkCheckbox }
|
|
|
|
|
|
|
|
constructor TSpkCheckbox.Create(AOwner: TComponent);
|
|
|
|
begin
|
|
|
|
inherited Create(AOwner);
|
|
|
|
FCheckboxStyle := cbsCheckbox;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
{ TSpkRadioButton }
|
2016-11-26 23:56:34 +00:00
|
|
|
|
2012-06-04 00:49:51 +00:00
|
|
|
constructor TSpkRadioButton.Create(AOwner: TComponent);
|
|
|
|
begin
|
|
|
|
inherited Create(AOwner);
|
|
|
|
FCheckboxStyle := cbsRadioButton;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TSpkRadioButton.GetDefaultCaption: string;
|
|
|
|
begin
|
2016-11-26 23:56:34 +00:00
|
|
|
Result := 'RadioButton';
|
2012-06-04 00:49:51 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TSpkRadioButton.SetState(AValue: TCheckboxState);
|
|
|
|
begin
|
|
|
|
inherited SetState(AValue);
|
|
|
|
if (AValue = cbChecked) then
|
|
|
|
UncheckSiblings;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TSpkRadioButton.UncheckSiblings;
|
|
|
|
var
|
|
|
|
i: Integer;
|
|
|
|
pane: TSpkPane;
|
2016-11-27 16:13:48 +00:00
|
|
|
rb: TSpkRadioButton;
|
2012-06-04 00:49:51 +00:00
|
|
|
begin
|
2016-11-27 16:13:48 +00:00
|
|
|
if (Parent is TSpkPane) then begin
|
2012-06-04 00:49:51 +00:00
|
|
|
pane := TSpkPane(Parent);
|
2016-11-27 16:13:48 +00:00
|
|
|
for i := 0 to pane.Items.Count-1 do
|
|
|
|
if (pane.Items[i] is TSpkRadioButton) then
|
|
|
|
begin
|
|
|
|
rb := TSpkRadioButton(pane.Items[i]);
|
|
|
|
if (rb <> self) and (rb.GroupIndex = GroupIndex) then
|
|
|
|
rb.State := cbUnchecked;
|
|
|
|
end;
|
2012-06-04 00:49:51 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|
|
|
|
|