📄 flatbtns.pas
字号:
begin
FGroupIndex := Value;
UpdateExclusive;
end;
end;
procedure TFlatSpeedBtn.SetLayout (Value: TButtonLayout);
begin
if FLayout <> Value then
begin
FLayout := Value;
Invalidate;
end;
end;
procedure TFlatSpeedBtn.SetMargin (Value: Integer);
begin
if (Value <> FMargin) and (Value >= -1) then
begin
FMargin := Value;
Invalidate;
end;
end;
procedure TFlatSpeedBtn.SetSpacing (Value: Integer);
begin
if Value <> FSpacing then
begin
FSpacing := Value;
Invalidate;
end;
end;
procedure TFlatSpeedBtn.SetAllowAllUp (Value: Boolean);
begin
if FAllowAllUp <> Value then
begin
FAllowAllUp := Value;
UpdateExclusive;
end;
end;
procedure TFlatSpeedBtn.WMLButtonDblClk (var Message: TWMLButtonDown);
begin
inherited;
if FDown then DblClick;
end;
procedure TFlatSpeedBtn.CMEnabledChanged (var Message: TMessage);
begin
inherited;
if not Enabled then
begin
FMouseInSpeedControl := False;
FState := bsDisabled;
RemoveMouseTimer;
end;
UpdateTracking;
Invalidate;
end;
procedure TFlatSpeedBtn.CMButtonPressed (var Message: TMessage);
var
Sender: TFlatSpeedBtn;
begin
if Message.WParam = FGroupIndex then
begin
Sender := TFlatSpeedBtn(Message.LParam);
if Sender <> Self then
begin
if Sender.Down and FDown then
begin
FDown := False;
FState := bsUp;
Invalidate;
end;
FAllowAllUp := Sender.AllowAllUp;
end;
end;
end;
procedure TFlatSpeedBtn.CMDialogChar (var Message: TCMDialogChar);
begin
with Message do
if IsAccel(CharCode, Caption) and Enabled then
begin
Click;
Result := 1;
end else
inherited;
end;
procedure TFlatSpeedBtn.CMFontChanged (var Message: TMessage);
begin
Invalidate;
end;
procedure TFlatSpeedBtn.CMTextChanged (var Message: TMessage);
begin
Invalidate;
end;
procedure TFlatSpeedBtn.CMSysColorChange (var Message: TMessage);
begin
if FUseAdvColors then
begin
ParentColor := True;
CalcAdvColors;
end;
Invalidate;
end;
procedure TFlatSpeedBtn.CMParentColorChanged (var Message: TWMNoParams);
begin
inherited;
if FUseAdvColors then
begin
ParentColor := True;
CalcAdvColors;
end;
Invalidate;
end;
procedure TFlatSpeedBtn.MouseEnter;
begin
if Enabled and not FMouseInSpeedControl then
begin
FMouseInSpeedControl := True;
Invalidate;
end;
end;
procedure TFlatSpeedBtn.MouseLeave;
begin
if Enabled and FMouseInSpeedControl and not FDragging then
begin
FMouseInSpeedControl := False;
RemoveMouseTimer;
Invalidate;
end;
end;
procedure TFlatSpeedBtn.MouseTimerHandler (Sender: TObject);
var
P: TPoint;
begin
GetCursorPos (P);
if FindDragTarget(P, True) <> Self then
MouseLeave;
end;
procedure TFlatSpeedBtn.RemoveMouseTimer;
begin
if MouseInSpeedControl = Self then
begin
MouseTimer.Enabled := False;
MouseInSpeedControl := nil;
end;
end;
{$IFDEF DFS_DELPHI_4_UP}
procedure TFlatSpeedBtn.ActionChange(Sender: TObject; CheckDefaults: Boolean);
procedure CopyImage(ImageList: TCustomImageList; Index: Integer);
begin
with Glyph do
begin
Width := ImageList.Width;
Height := ImageList.Height;
Canvas.Brush.Color := clFuchsia;//! for lack of a better color
Canvas.FillRect(Rect(0,0, Width, Height));
ImageList.Draw(Canvas, 0, 0, Index);
end;
end;
begin
inherited ActionChange(Sender, CheckDefaults);
if Sender is TCustomAction then
with TCustomAction(Sender) do
begin
{ Copy image from action's imagelist }
if (Glyph.Empty) and (ActionList <> nil) and (ActionList.Images <> nil) and
(ImageIndex >= 0) and (ImageIndex < ActionList.Images.Count) then
CopyImage(ActionList.Images, ImageIndex);
end;
end;
{$ENDIF}
procedure TFlatSpeedBtn.SetTransparent(const Value: TTransparentMode);
begin
FTransparent := Value;
Invalidate;
end;
procedure TFlatSpeedBtn.CMMouseEnter(var Message: TMessage);
begin
inherited;
if Assigned(FOnMouseEnter) then
FOnMouseEnter(Self);
end;
procedure TFlatSpeedBtn.CMMouseLeave(var Message: TMessage);
begin
inherited;
if Assigned(FOnMouseLeave) then
FOnMouseLeave(Self);
end;
{ TFlatSpinButton }
constructor TFlatSpinButton.Create (AOwner: TComponent);
begin
inherited Create(AOwner);
ControlStyle := ControlStyle - [csAcceptsControls, csSetCaption] + [csFramed, csOpaque];
FUpButton := CreateButton;
FDownButton := CreateButton;
UpGlyph := nil;
DownGlyph := nil;
Width := 21;
Height := 10;
FFocusedButton := FUpButton;
end;
function TFlatSpinButton.CreateButton: TTimerSpeedBtn;
begin
Result := TTimerSpeedBtn.Create(Self);
Result.OnClick := BtnClick;
Result.OnMouseDown := BtnMouseDown;
Result.Visible := True;
Result.Enabled := True;
Result.TimeBtnState := [tbAllowTimer];
Result.Parent := Self;
end;
procedure TFlatSpinButton.Notification (AComponent: TComponent; Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if (Operation = opRemove) and (AComponent = FFocusControl) then
FFocusControl := nil;
end;
procedure TFlatSpinButton.AdjustSize (var W, H: Integer);
begin
if (FUpButton = nil) or (csLoading in ComponentState) then Exit;
FUpButton.SetBounds(0, 0, 11, H);
FDownButton.SetBounds(10, 0, 11, H);
end;
procedure TFlatSpinButton.SetBounds (ALeft, ATop, AWidth, AHeight: Integer);
var
W, H: Integer;
begin
W := AWidth;
H := AHeight;
AdjustSize (W, H);
inherited SetBounds (ALeft, ATop, W, H);
end;
procedure TFlatSpinButton.WMSize (var Message: TWMSize);
var
W, H: Integer;
begin
inherited;
// check for minimum size
W := Width;
H := Height;
AdjustSize (W, H);
if (W <> Width) or (H <> Height) then
inherited SetBounds(Left, Top, W, H);
Message.Result := 0;
end;
procedure TFlatSpinButton.WMSetFocus (var Message: TWMSetFocus);
begin
FFocusedButton.TimeBtnState := FFocusedButton.TimeBtnState + [tbFocusRect];
FFocusedButton.Invalidate;
end;
procedure TFlatSpinButton.WMKillFocus (var Message: TWMKillFocus);
begin
FFocusedButton.TimeBtnState := FFocusedButton.TimeBtnState - [tbFocusRect];
FFocusedButton.Invalidate;
end;
procedure TFlatSpinButton.KeyDown (var Key: Word; Shift: TShiftState);
begin
case Key of
VK_UP:
begin
SetFocusBtn(FUpButton);
FUpButton.Click;
end;
VK_DOWN:
begin
SetFocusBtn(FDownButton);
FDownButton.Click;
end;
VK_SPACE:
FFocusedButton.Click;
end;
end;
procedure TFlatSpinButton.BtnMouseDown (Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if Button = mbLeft then
begin
SetFocusBtn (TTimerSpeedBtn (Sender));
if (FFocusControl <> nil) and FFocusControl.TabStop and
FFocusControl.CanFocus and (GetFocus <> FFocusControl.Handle) then
FFocusControl.SetFocus
else if TabStop and (GetFocus <> Handle) and CanFocus then
SetFocus;
end;
end;
procedure TFlatSpinButton.BtnClick (Sender: TObject);
begin
if Sender = FUpButton then
if Assigned(FOnUpClick) then
FOnUpClick(Self);
if Sender = FDownButton then
if Assigned(FOnDownClick) then
FOnDownClick(Self);
end;
procedure TFlatSpinButton.SetFocusBtn (Btn: TTimerSpeedBtn);
begin
if TabStop and CanFocus and (Btn <> FFocusedButton) then
begin
FFocusedButton.TimeBtnState := FFocusedButton.TimeBtnState - [tbFocusRect];
FFocusedButton := Btn;
if (GetFocus = Handle) then
begin
FFocusedButton.TimeBtnState := FFocusedButton.TimeBtnState + [tbFocusRect];
Invalidate;
end;
end;
end;
procedure TFlatSpinButton.WMGetDlgCode (var Message: TWMGetDlgCode);
begin
Message.Result := DLGC_WANTARROWS;
end;
procedure TFlatSpinButton.Loaded;
var
W, H: Integer;
begin
inherited Loaded;
W := Width;
H := Height;
AdjustSize (W, H);
if (W <> Width) or (H <> Height) then
inherited SetBounds(Left, Top, Width, Height);
end;
function TFlatSpinButton.GetUpGlyph: TBitmap;
begin
Result := FUpButton.Glyph;
end;
procedure TFlatSpinButton.SetUpGlyph (Value: TBitmap);
begin
if Value <> nil then
FUpButton.Glyph := Value
else
begin
FUpButton.Glyph.Handle := LoadBitmap(HInstance, 'FlatUp');
FUpButton.NumGlyphs := 1;
FUpButton.Margin := 2;
FUpButton.Invalidate;
FUpButton.Layout := blGlyphTop;
end;
end;
function TFlatSpinButton.GetUpNumGlyphs: TNumGlyphs;
begin
Result := FUpButton.NumGlyphs;
end;
procedure TFlatSpinButton.SetUpNumGlyphs (Value: TNumGlyphs);
begin
FUpButton.NumGlyphs := Value;
end;
function TFlatSpinButton.GetDownGlyph: TBitmap;
begin
Result := FDownButton.Glyph;
end;
procedure TFlatSpinButton.SetDownGlyph (Value: TBitmap);
begin
if Value <> nil then
FDownButton.Glyph := Value
else
begin
FDownButton.Glyph.Handle := LoadBitmap(HInstance, 'FlatDown');
FDownButton.NumGlyphs := 1;
FDownButton.Margin := 2;
FDownButton.Invalidate;
FDownButton.Layout := blGlyphBottom;
end;
end;
function TFlatSpinButton.GetDownNumGlyphs: TNumGlyphs;
begin
Result := FDownButton.NumGlyphs;
end;
procedure TFlatSpinButton.SetDownNumGlyphs (Value: TNumGlyphs);
begin
FDownButton.NumGlyphs := Value;
end;
{TTimerSpeedBtn}
destructor TTimerSpeedBtn.Destroy;
begin
if FRepeatTimer <> nil then
FRepeatTimer.Free;
inherited Destroy;
end;
procedure TTimerSpeedBtn.MouseDown (Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
inherited MouseDown (Button, Shift, X, Y);
if tbAllowTimer in FTimeBtnState then
begin
if FRepeatTimer = nil then
FRepeatTimer := TTimer.Create(Self);
FRepeatTimer.OnTimer := TimerExpired;
FRepeatTimer.Interval := InitRepeatPause;
FRepeatTimer.Enabled := True;
end;
end;
procedure TTimerSpeedBtn.MouseUp (Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -