📄 rxspin.pas
字号:
{*******************************************************}
{ }
{ Delphi VCL Extensions (RX) }
{ }
{ Copyright (c) 1995 AO ROSNO }
{ Copyright (c) 1997, 1998 Master-Bank }
{ }
{ Patched by Polaris Software }
{*******************************************************}
unit RXSpin;
interface
{$I RX.INC}
//>Polaris
{$DEFINE POLESPIN} {Classic style in RxSpinButton and rxSpinEdit}
//<Polaris
uses
Windows, ComCtrls,
Controls, ExtCtrls, Classes, Graphics, Messages, Forms, StdCtrls, Menus,
SysUtils, Mask;
type
{ TRxSpinButton }
TSpinButtonState = (sbNotDown, sbTopDown, sbBottomDown);
//>Polaris
TrSpinButtonStyle = (sbsDefault, sbsClassic);
//<Polaris
TRxSpinButton = class(TGraphicControl)
private
FDown: TSpinButtonState;
FUpBitmap: TBitmap;
FDownBitmap: TBitmap;
FDragging: Boolean;
FInvalidate: Boolean;
FTopDownBtn: TBitmap;
FBottomDownBtn: TBitmap;
FRepeatTimer: TTimer;
FNotDownBtn: TBitmap;
FLastDown: TSpinButtonState;
FFocusControl: TWinControl;
FOnTopClick: TNotifyEvent;
FOnBottomClick: TNotifyEvent;
//>Polaris
FButtonStyle: TrSpinButtonStyle;
procedure SetButtonStyle(Value: TrSpinButtonStyle);
//<Polaris
procedure TopClick;
procedure BottomClick;
procedure GlyphChanged(Sender: TObject);
function GetUpGlyph: TBitmap;
function GetDownGlyph: TBitmap;
procedure SetUpGlyph(Value: TBitmap);
procedure SetDownGlyph(Value: TBitmap);
procedure SetDown(Value: TSpinButtonState);
procedure SetFocusControl(Value: TWinControl);
procedure DrawAllBitmap;
procedure DrawBitmap(ABitmap: TBitmap; ADownState: TSpinButtonState);
procedure TimerExpired(Sender: TObject);
procedure CMEnabledChanged(var Message: TMessage); message CM_ENABLEDCHANGED;
protected
procedure Paint; 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;
procedure Notification(AComponent: TComponent;
Operation: TOperation); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
property Down: TSpinButtonState read FDown write SetDown default sbNotDown;
published
//>Polaris
property ButtonStyle: TrSpinButtonStyle read FButtonStyle write SetButtonStyle default sbsDefault;
//<Polaris
property DragCursor;
property DragMode;
property Enabled;
property Visible;
property DownGlyph: TBitmap read GetDownGlyph write SetDownGlyph;
property UpGlyph: TBitmap read GetUpGlyph write SetUpGlyph;
property FocusControl: TWinControl read FFocusControl write SetFocusControl;
property ShowHint;
property ParentShowHint;
{$IFDEF RX_D4}
property Anchors;
property Constraints;
property DragKind;
{$ENDIF}
property OnBottomClick: TNotifyEvent read FOnBottomClick write FOnBottomClick;
property OnTopClick: TNotifyEvent read FOnTopClick write FOnTopClick;
property OnDragDrop;
property OnDragOver;
property OnEndDrag;
property OnStartDrag;
{$IFDEF RX_D4}
property OnEndDock;
property OnStartDock;
{$ENDIF}
end;
{ TRxCustomSpinEdit }
{$IFDEF CBUILDER}
TValueType = (vtInt, vtFloat, vtHex);
{$ELSE}
TValueType = (vtInteger, vtFloat, vtHex);
{$ENDIF}
//>Polaris
// TSpinButtonKind = (bkStandard, bkDiagonal);
TSpinButtonKind = (bkStandard, bkDiagonal, bkClassic);
//Polaris TRxSpinEdit = class(TCustomEdit)
TRxCustomSpinEdit = class(TCustomMaskEdit)
private
//Polaris
FFocused,
FCheckOnExit,
FLCheckMinValue,
FLCheckMaxValue,
FCheckMinValue,
FCheckMaxValue: Boolean;
FDisplayFormat: String;
//Polaris
FAlignment: TAlignment;
FMinValue: Extended;
FMaxValue: Extended;
FIncrement: Extended;
FDecimal: Byte;
FChanging: Boolean;
FEditorEnabled: Boolean;
FValueType: TValueType;
FButton: TRxSpinButton;
FBtnWindow: TWinControl;
FArrowKeys: Boolean;
FOnTopClick: TNotifyEvent;
FOnBottomClick: TNotifyEvent;
// FButtonKind: TSpinButtonKind;
FUpDown: TCustomUpDown;
//Polaris
procedure SetMinValue(NewValue: Extended);
procedure SetMaxValue(NewValue: Extended);
procedure SetCheckMinValue(NewValue: Boolean);
function StoreCheckMinValue: Boolean;
procedure SetCheckMaxValue(NewValue: Boolean);
function StoreCheckMaxValue: Boolean;
function CheckDefaultRange(CheckMax: Boolean): Boolean;
procedure SetDisplayFormat(const Value: string);
function IsFormatStored: Boolean;
function TextToValText(const AValue: string): string;
//Polaris
procedure SetFocused(Value: Boolean);
procedure CheckRange;
function GetButtonKind: TSpinButtonKind;
procedure SetButtonKind(Value: TSpinButtonKind);
procedure UpDownClick(Sender: TObject; Button: TUDBtnType);
function GetMinHeight: Integer;
procedure GetTextHeight(var SysHeight, Height: Integer);
function GetAsInteger: Longint;
function IsIncrementStored: Boolean;
function IsMaxStored: Boolean;
function IsMinStored: Boolean;
function IsValueStored: Boolean;
procedure SetArrowKeys(Value: Boolean);
procedure SetAsInteger(NewValue: Longint);
procedure SetDecimal(NewValue: Byte);
function GetButtonWidth: Integer;
// procedure RecreateButton;
procedure ResizeButton;
procedure SetEditRect;
procedure SetAlignment(Value: TAlignment);
procedure WMSize(var Message: TWMSize); message WM_SIZE;
procedure CMEnter(var Message: TMessage); message CM_ENTER;
procedure CMExit(var Message: TCMExit); message CM_EXIT;
procedure WMPaste(var Message: TWMPaste); message WM_PASTE;
procedure WMCut(var Message: TWMCut); message WM_CUT;
procedure CMCtl3DChanged(var Message: TMessage); message CM_CTL3DCHANGED;
procedure CMEnabledChanged(var Message: TMessage); message CM_ENABLEDCHANGED;
procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
{$IFDEF RX_D4}
procedure CMBiDiModeChanged(var Message: TMessage); message CM_BIDIMODECHANGED;
{$ENDIF}
protected
//Polaris up to protected
FButtonKind: TSpinButtonKind;
procedure RecreateButton;
function CheckValue(NewValue: Extended): Extended;
function CheckValueRange(NewValue: Extended; RaiseOnError: Boolean): Extended;
procedure SetValue(NewValue: Extended); virtual; abstract;
function GetValue: Extended; virtual; abstract;
procedure SetValueType(NewType: TValueType); virtual;
procedure DataChanged; virtual;
//Polaris up to protected
//Polaris
procedure Loaded; override;
function DefaultDisplayFormat: string; virtual;
property DisplayFormat: string read FDisplayFormat write SetDisplayFormat
stored IsFormatStored;
// procedure DefinePropertyes(Filer: TFiler); override;
//Polaris
procedure Change; override;
function IsValidChar(Key: Char): Boolean; virtual;
procedure UpClick(Sender: TObject); virtual;
procedure DownClick(Sender: TObject); virtual;
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure KeyPress(var Key: Char); override;
procedure CreateParams(var Params: TCreateParams); override;
procedure CreateWnd; override;
property ButtonWidth: Integer read GetButtonWidth;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
property AsInteger: Longint read GetAsInteger write SetAsInteger default 0;
property Text;
//Polaris published
property Alignment: TAlignment read FAlignment write SetAlignment
default taLeftJustify;
property ArrowKeys: Boolean read FArrowKeys write SetArrowKeys default True;
property ButtonKind: TSpinButtonKind read FButtonKind write SetButtonKind
// {$IFDEF POLESPIN}
// default bkClassic
// {$ELSE}
default bkDiagonal
// {$ENDIF}
;
property Decimal: Byte read FDecimal write SetDecimal default 2;
property EditorEnabled: Boolean read FEditorEnabled write FEditorEnabled default True;
property Increment: Extended read FIncrement write FIncrement stored IsIncrementStored;
property MaxValue: Extended read FMaxValue write SetMaxValue stored IsMaxStored;
property MinValue: Extended read FMinValue write SetMinValue stored IsMinStored;
//Polaris
property CheckOnExit: Boolean read FCheckOnExit write FCheckOnExit default False;
property CheckMinValue: Boolean read FCheckMinValue write SetCheckMinValue stored StoreCheckMinValue;//default False;
property CheckMaxValue: Boolean read FCheckMaxValue write SetCheckMaxValue stored StoreCheckMaxValue;//default False;
//Polaris
property ValueType: TValueType read FValueType write SetValueType
default {$IFDEF CBUILDER} vtInt {$ELSE} vtInteger {$ENDIF};
property Value: Extended read GetValue write SetValue stored IsValueStored;
property OnBottomClick: TNotifyEvent read FOnBottomClick write FOnBottomClick;
property OnTopClick: TNotifyEvent read FOnTopClick write FOnTopClick;
end;
TRxSpinEdit = class(TRxCustomSpinEdit)
protected
procedure SetValue(NewValue: Extended); override;
function GetValue: Extended; override;
public
constructor Create(AOwner: TComponent); override;
published
//Polaris
property CheckOnExit;
property CheckMinValue;
property CheckMaxValue;
property Align;
property Alignment;
property ArrowKeys;
property DisplayFormat;
property ButtonKind default bkDiagonal;
property Decimal;
property EditorEnabled;
property Increment;
property MaxValue;
property MinValue;
property ValueType;
property Value;
property OnBottomClick;
property OnTopClick;
property AutoSelect;
property AutoSize;
property BorderStyle;
property Color;
property Ctl3D;
property DragCursor;
property DragMode;
property Enabled;
property Font;
{$IFDEF RX_D4}
property Anchors;
property BiDiMode;
property Constraints;
property DragKind;
property ParentBiDiMode;
{$ENDIF}
{$IFNDEF VER90}
property ImeMode;
property ImeName;
{$ENDIF}
property MaxLength;
property ParentColor;
property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ReadOnly;
property ShowHint;
property TabOrder;
property TabStop;
property Visible;
property OnChange;
property OnClick;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnStartDrag;
{$IFDEF RX_D5}
property OnContextPopup;
{$ENDIF}
{$IFDEF RX_D4}
property OnMouseWheelDown;
property OnMouseWheelUp;
property OnEndDock;
property OnStartDock;
{$ENDIF}
end;
implementation
uses
CommCtrl, Consts,
RxStrUtils, rxVCLUtils;
{$R *.R32}
const
sSpinUpBtn = 'RXSPINUP';
sSpinDownBtn = 'RXSPINDOWN';
const
InitRepeatPause = 400; { pause before repeat timer (ms) }
RepeatPause = 100;
{ TRxSpinButton }
constructor TRxSpinButton.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
{$IFDEF POLESPIN}
FButtonStyle := sbsDefault;
{$ENDIF}
FUpBitmap := TBitmap.Create;
FDownBitmap := TBitmap.Create;
FUpBitmap.OnChange := GlyphChanged;
FDownBitmap.OnChange := GlyphChanged;
Height := 20;
Width := 20;
FTopDownBtn := TBitmap.Create;
FBottomDownBtn := TBitmap.Create;
FNotDownBtn := TBitmap.Create;
DrawAllBitmap;
FLastDown := sbNotDown;
end;
destructor TRxSpinButton.Destroy;
begin
FTopDownBtn.Free;
FBottomDownBtn.Free;
FNotDownBtn.Free;
FUpBitmap.Free;
FDownBitmap.Free;
FRepeatTimer.Free;
inherited Destroy;
end;
procedure TRxSpinButton.GlyphChanged(Sender: TObject);
begin
FInvalidate := True;
Invalidate;
end;
function TRxSpinButton.GetUpGlyph: TBitmap;
begin
Result := FUpBitmap;
end;
procedure TRxSpinButton.SetUpGlyph(Value: TBitmap);
begin
if Value <> nil then FUpBitmap.Assign(Value)
// else FUpBitmap.Handle := LoadBitmap(HInstance, sSpinUpBtn);
//>Polaris
else FUpBitmap.Handle := 0;
end;
function TRxSpinButton.GetDownGlyph: TBitmap;
begin
Result := FDownBitmap;
end;
procedure TRxSpinButton.SetDownGlyph(Value: TBitmap);
begin
if Value <> nil then FDownBitmap.Assign(Value)
// else FDownBitmap.Handle := LoadBitmap(HInstance, sSpinDownBtn);
//Polaris
else FDownBitmap.Handle := 0;
end;
procedure TRxSpinButton.SetDown(Value: TSpinButtonState);
var
OldState: TSpinButtonState;
begin
OldState := FDown;
FDown := Value;
if OldState <> FDown then Repaint;
end;
procedure TRxSpinButton.SetFocusControl(Value: TWinControl);
begin
FFocusControl := Value;
if Value <> nil then Value.FreeNotification(Self);
end;
procedure TRxSpinButton.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if (Operation = opRemove) and (AComponent = FFocusControl) then
FFocusControl := nil;
end;
procedure TRxSpinButton.Paint;
begin
if not Enabled and not (csDesigning in ComponentState) then
FDragging := False;
if (FNotDownBtn.Height <> Height) or (FNotDownBtn.Width <> Width) or
FInvalidate then DrawAllBitmap;
FInvalidate := False;
with Canvas do
case FDown of
sbNotDown: Draw(0, 0, FNotDownBtn);
sbTopDown: Draw(0, 0, FTopDownBtn);
sbBottomDown: Draw(0, 0, FBottomDownBtn);
end;
end;
procedure TRxSpinButton.DrawAllBitmap;
begin
DrawBitmap(FTopDownBtn, sbTopDown);
DrawBitmap(FBottomDownBtn, sbBottomDown);
DrawBitmap(FNotDownBtn, sbNotDown);
end;
(*Polaris
procedure TRxSpinButton.DrawBitmap(ABitmap: TBitmap; ADownState: TSpinButtonState);
var
R, RSrc: TRect;
dRect: Integer;
{Temp: TBitmap;}
begin
ABitmap.Height := Height;
ABitmap.Width := Width;
with ABitmap.Canvas do begin
R := Bounds(0, 0, Width, Height);
Pen.Width := 1;
Brush.Color := clBtnFace;
Brush.Style := bsSolid;
FillRect(R);
{ buttons frame }
Pen.Color := clWindowFrame;
Rectangle(0, 0, Width, Height);
MoveTo(-1, Height);
LineTo(Width, -1);
{ top button }
if ADownState = sbTopDown then Pen.Color := clBtnShadow
else Pen.Color := clBtnHighlight;
MoveTo(1, Height - 4);
LineTo(1, 1);
LineTo(Width - 3, 1);
if ADownState = sbTopDown then Pen.Color := clBtnHighlight
else Pen.Color := clBtnShadow;
if ADownState <> sbTopDown then begin
MoveTo(1, Height - 3);
LineTo(Width - 2, 0);
end;
{ bottom button }
if ADownState = sbBottomDown then Pen.Color := clBtnHighlight
else Pen.Color := clBtnShadow;
MoveTo(2, Height - 2);
LineTo(Width - 2, Height - 2);
LineTo(Width - 2, 1);
if ADownState = sbBottomDown then Pen.Color := clBtnShadow
else Pen.Color := clBtnHighlight;
MoveTo(2, Height - 2);
LineTo(Width - 1, 1);
{ top glyph }
dRect := 1;
if ADownState = sbTopDown then Inc(dRect);
R := Bounds(Round((Width / 4) - (FUpBitmap.Width / 2)) + dRect,
Round((Height / 4) - (FUpBitmap.Height / 2)) + dRect, FUpBitmap.Width,
FUpBitmap.Height);
RSrc := Bounds(0, 0, FUpBitmap.Width, FUpBitmap.Height);
{
if Self.Enabled or (csDesigning in ComponentState) then
BrushCopy(R, FUpBitmap, RSrc, FUpBitmap.TransparentColor)
else begin
Temp := CreateDisabledBitmap(FUpBitmap, clBlack);
try
BrushCopy(R, Temp, RSrc, Temp.TransparentColor);
finally
Temp.Free;
end;
end;
}
BrushCopy(R, FUpBitmap, RSrc, FUpBitmap.TransparentColor);
{ bottom glyph }
R := Bounds(Round((3 * Width / 4) - (FDownBitmap.Width / 2)) - 1,
Round((3 * Height / 4) - (FDownBitmap.Height / 2)) - 1,
FDownBitmap.Width, FDownBitmap.Height);
RSrc := Bounds(0, 0, FDownBitmap.Width, FDownBitmap.Height);
{
if Self.Enabled or (csDesigning in ComponentState) then
BrushCopy(R, FDownBitmap, RSrc, FDownBitmap.TransparentColor)
else begin
Temp := CreateDisabledBitmap(FDownBitmap, clBlack);
try
BrushCopy(R, Temp, RSrc, Temp.TransparentColor);
finally
Temp.Free;
end;
end;
}
BrushCopy(R, FDownBitmap, RSrc, FDownBitmap.TransparentColor);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -