📄 tooledit.pas
字号:
public
constructor Create(AOwner: TComponent); override;
published
{$IFDEF WIN32}
property DialogKind: TDirDialogKind read FDialogKind write FDialogKind
default dkVCL;
property DialogText: string read FDialogText write FDialogText;
{$ENDIF}
property DialogOptions: TSelectDirOpts read FOptions write FOptions default [];
property InitialDir: string read FInitialDir write FInitialDir;
property MultipleDirs: Boolean read FMultipleDirs write FMultipleDirs default False;
property AutoSelect;
property ButtonHint;
property BorderStyle;
property CharCase;
property ClickKey;
property Color;
property Ctl3D;
property DirectInput;
property DragCursor;
property DragMode;
property EditMask;
property Enabled;
property Font;
property GlyphKind;
{ Ensure GlyphKind is declared before Glyph and ButtonWidth }
property Glyph;
property NumGlyphs;
property ButtonWidth;
property HideSelection;
{$IFDEF RX_D4}
property Anchors;
property BiDiMode;
property Constraints;
property DragKind;
property ParentBiDiMode;
{$ENDIF}
{$IFDEF WIN32}
{$IFNDEF VER90}
property ImeMode;
property ImeName;
{$ENDIF}
{$ENDIF}
property ParentColor;
property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ReadOnly;
property ShowHint;
property TabOrder;
property TabStop;
property Text;
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;
{$IFDEF WIN32}
property OnStartDrag;
{$ENDIF}
{$IFDEF RX_D5}
property OnContextPopup;
{$ENDIF}
{$IFDEF RX_D4}
property OnEndDock;
property OnStartDock;
{$ENDIF}
end;
{ TCustomDateEdit }
TCalendarStyle = (csPopup, csDialog);
TYearDigits = (dyDefault, dyFour, dyTwo);
const
{$IFDEF DEFAULT_POPUP_CALENDAR}
dcsDefault = csPopup;
{$ELSE}
dcsDefault = csDialog;
{$ENDIF DEFAULT_POPUP_CALENDAR}
type
TExecDateDialog = procedure(Sender: TObject; var ADate: TDateTime;
var Action: Boolean) of object;
TCustomDateEdit = class(TCustomComboEdit)
private
FTitle: String;
FOnAcceptDate: TExecDateDialog;
FDefaultToday: Boolean;
FHooked: Boolean;
FPopupColor: TColor;
FCheckOnExit: Boolean;
FBlanksChar: Char;
FCalendarHints: TStrings;
FStartOfWeek: TDayOfWeekName;
FWeekends: TDaysOfWeek;
FWeekendColor: TColor;
FYearDigits: TYearDigits;
FDateFormat: string[10];
FFormatting: Boolean;
function GetDate: TDateTime;
procedure SetDate(Value: TDateTime);
procedure SetYearDigits(Value: TYearDigits);
function GetPopupColor: TColor;
procedure SetPopupColor(Value: TColor);
function GetDialogTitle: string;
procedure SetDialogTitle(const Value: string);
function IsCustomTitle: Boolean;
function GetCalendarStyle: TCalendarStyle;
procedure SetCalendarStyle(Value: TCalendarStyle);
procedure SetCalendarHints(Value: TStrings);
procedure CalendarHintsChanged(Sender: TObject);
procedure SetWeekendColor(Value: TColor);
procedure SetWeekends(Value: TDaysOfWeek);
procedure SetStartOfWeek(Value: TDayOfWeekName);
procedure SetBlanksChar(Value: Char);
function TextStored: Boolean;
function FourDigitYear: Boolean;
function FormatSettingsChange(var Message: TMessage): Boolean;
procedure CMExit(var Message: TCMExit); message CM_EXIT;
protected
procedure Change; override;
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure KeyPress(var Key: Char); override;
procedure CreateWindowHandle(const Params: TCreateParams); override;
procedure DestroyWindowHandle; override;
{$IFDEF WIN32}
function AcceptPopup(var Value: Variant): Boolean; override;
procedure AcceptValue(const Value: Variant); override;
procedure SetPopupValue(const Value: Variant); override;
{$ELSE}
function AcceptPopup(var Value: string): Boolean; override;
{$ENDIF}
function GetDateFormat: string;
procedure ApplyDate(Value: TDateTime); virtual;
function GetDefaultBitmap(var DestroyNeeded: Boolean): TBitmap; override;
procedure UpdateFormat;
procedure UpdatePopup;
procedure ButtonClick; override;
property BlanksChar: Char read FBlanksChar write SetBlanksChar default ' ';
property CalendarHints: TStrings read FCalendarHints write SetCalendarHints;
property CheckOnExit: Boolean read FCheckOnExit write FCheckOnExit default False;
property DefaultToday: Boolean read FDefaultToday write FDefaultToday
default False;
property DialogTitle: string read GetDialogTitle write SetDialogTitle
stored IsCustomTitle;
property EditMask stored False;
property Formatting: Boolean read FFormatting;
property GlyphKind default gkDefault;
property PopupColor: TColor read GetPopupColor write SetPopupColor
default clBtnFace;
property CalendarStyle: TCalendarStyle read GetCalendarStyle
write SetCalendarStyle default dcsDefault;
property StartOfWeek: TDayOfWeekName read FStartOfWeek write SetStartOfWeek default Mon;
property Weekends: TDaysOfWeek read FWeekends write SetWeekends default [Sun];
property WeekendColor: TColor read FWeekendColor write SetWeekendColor default clRed;
property YearDigits: TYearDigits read FYearDigits write SetYearDigits default dyDefault;
property OnAcceptDate: TExecDateDialog read FOnAcceptDate write FOnAcceptDate;
property MaxLength stored False;
property Text stored TextStored;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure CheckValidDate;
function GetDateMask: string;
procedure UpdateMask; virtual;
property Date: TDateTime read GetDate write SetDate;
property PopupVisible;
end;
{ TDateEdit }
TDateEdit = class(TCustomDateEdit)
public
constructor Create(AOwner: TComponent); override;
property EditMask;
published
property AutoSelect;
property BlanksChar;
property BorderStyle;
property ButtonHint;
property CalendarHints;
property CheckOnExit;
property ClickKey;
property Color;
property Ctl3D;
property DefaultToday;
property DialogTitle;
property DirectInput;
property DragCursor;
property DragMode;
property Enabled;
property Font;
property GlyphKind;
{ Ensure GlyphKind is declared before Glyph and ButtonWidth }
property Glyph;
property ButtonWidth;
property HideSelection;
{$IFDEF RX_D4}
property Anchors;
property BiDiMode;
property Constraints;
property DragKind;
property ParentBiDiMode;
{$ENDIF}
{$IFDEF WIN32}
{$IFNDEF VER90}
property ImeMode;
property ImeName;
{$ENDIF}
{$ENDIF}
property MaxLength;
property NumGlyphs;
property ParentColor;
property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property PopupAlign;
property PopupColor;
property PopupMenu;
property ReadOnly;
property ShowHint;
property CalendarStyle;
property StartOfWeek;
property Weekends;
property WeekendColor;
property YearDigits;
property TabOrder;
property TabStop;
property Text;
property Visible;
property OnAcceptDate;
property OnButtonClick;
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;
{$IFDEF WIN32}
property OnStartDrag;
{$ENDIF}
{$IFDEF RX_D5}
property OnContextPopup;
{$ENDIF}
{$IFDEF RX_D4}
property OnEndDock;
property OnStartDock;
{$ENDIF}
end;
EComboEditError = class(Exception);
{ Utility routines }
procedure DateFormatChanged;
function EditorTextMargins(Editor: TCustomComboEdit): TPoint;
function PaintComboEdit(Editor: TCustomComboEdit; const AText: string;
AAlignment: TAlignment; StandardPaint: Boolean;
var ACanvas: TControlCanvas; var Message: TWMPaint): Boolean;
implementation
uses ShellAPI, Consts, {$IFDEF RX_D3} ExtDlgs, {$ENDIF} RXCConst, VCLUtils,
rxStrUtils, FileUtil, PickDate, MaxMin;
{$IFDEF WIN32}
{$R *.R32}
{$ELSE}
{$R *.R16}
{$ENDIF}
const
sFileBmp = 'FEDITBMP'; { Filename and directory editor button glyph }
sDateBmp = 'DEDITBMP'; { Date editor button glyph }
{ Utility routines }
function EditorTextMargins(Editor: TCustomComboEdit): TPoint;
var
DC: HDC;
SaveFont: HFont;
I: Integer;
SysMetrics, Metrics: TTextMetric;
begin
with Editor do begin
{$IFDEF WIN32}
if NewStyleControls then begin
if BorderStyle = bsNone then I := 0
else if Ctl3D then I := 1
else I := 2;
Result.X := SendMessage(Handle, EM_GETMARGINS, 0, 0) and $0000FFFF + I;
Result.Y := I;
end
else begin
{$ENDIF}
if BorderStyle = bsNone then I := 0
else begin
DC := GetDC(0);
GetTextMetrics(DC, SysMetrics);
SaveFont := SelectObject(DC, Font.Handle);
GetTextMetrics(DC, Metrics);
SelectObject(DC, SaveFont);
ReleaseDC(0, DC);
I := SysMetrics.tmHeight;
if I > Metrics.tmHeight then I := Metrics.tmHeight;
I := I div 4;
end;
Result.X := I;
Result.Y := I;
{$IFDEF WIN32}
end;
{$ENDIF}
end;
end;
function PaintComboEdit(Editor: TCustomComboEdit; const AText: string;
AAlignment: TAlignment; StandardPaint: Boolean;
var ACanvas: TControlCanvas; var Message: TWMPaint): Boolean;
var
AWidth, ALeft: Integer;
Margins: TPoint;
R: TRect;
DC: HDC;
PS: TPaintStruct;
S: string;
{$IFDEF RX_D4}
ExStyle: DWORD;
const
AlignStyle: array[Boolean, TAlignment] of DWORD =
((WS_EX_LEFT, WS_EX_RIGHT, WS_EX_LEFT),
(WS_EX_RIGHT, WS_EX_LEFT, WS_EX_LEFT));
{$ENDIF}
begin
Result := True;
with Editor do begin
{$IFDEF RX_D4}
if UseRightToLeftAlignment then ChangeBiDiModeAlignment(AAlignment);
{$ENDIF}
if StandardPaint {$IFDEF WIN32} and not
(csPaintCopy in ControlState) {$ENDIF} then
begin
{$IFDEF RX_D4}
if SysLocale.MiddleEast and HandleAllocated and (IsRightToLeft) then
begin { This keeps the right aligned text, right aligned }
ExStyle := DWORD(GetWindowLong(Handle, GWL_EXSTYLE)) and (not WS_EX_RIGHT) and
(not WS_EX_RTLREADING) and (not WS_EX_LEFTSCROLLBAR);
if UseRightToLeftReading then
ExStyle := ExStyle or WS_EX_RTLREADING;
if UseRightToLeftScrollbar then
ExStyle := ExStyle or WS_EX_LEFTSCROLLBAR;
ExStyle := ExStyle or
AlignStyle[UseRightToLeftAlignment, AAlignment];
if DWORD(GetWindowLong(Handle, GWL_EXSTYLE)) <> ExStyle then
SetWindowLong(Handle, GWL_EXSTYLE, ExStyle);
end;
{$ENDIF RX_D4}
Result := False;
{ return false if we need to use standard paint handler }
Exit;
end;
{ Since edit controls do not handle justification unless multi-line (and
then only poorly) we will draw right and center justify manually unless
the edit has the focus. }
if ACanvas = nil then begin
ACanvas := TControlCanvas.Create;
ACanvas.Control := Editor;
end;
DC := Message.DC;
if DC = 0 then DC := BeginPaint(Handle, PS);
ACanvas.Handle := DC;
try
ACanvas.Font := Font;
if not Enabled and NewStyleControls and not
(csDesigning in ComponentState) and
(ColorToRGB(Color) <> ColorToRGB(clGrayText)) then
ACanvas.Font.Color := clGrayText;
with ACanvas do begin
R := ClientRect;
if {$IFDEF WIN32} not (NewStyleControls and Ctl3D) and {$ENDIF}
(BorderStyle = bsSingle) then
begin
Brush.Color := clWindowFrame;
FrameRect(R);
InflateRect(R, -1, -1);
end;
Brush.Color := Color;
S := AText;
AWidth := TextWidth(S);
Margins := EditorTextMargins(Editor);
if PopupVisible then ALeft := Margins.X
else begin
if ButtonWidth > 0 then Inc(AWidth);
case AAlignment of
taLeftJustify:
ALeft := Margins.X;
taRightJustify:
ALeft := ClientWidth - ButtonWidth - AWidth - Margins.X - 2;
else
ALeft := (ClientWidth - ButtonWidth - AWidth) div 2;
end;
end;
{$IFDEF RX_D4}
if SysLocale.MiddleEast then UpdateTextFlags;
{$ENDIF}
TextRect(R, ALeft, Margins.Y, S);
end;
finally
ACanvas.Handle := 0;
if Message.DC = 0 then EndPaint(Handle, PS);
end;
end;
end;
{ TEditButton }
constructor TEditButton.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
{$IFDEF WIN32}
ControlStyle := ControlStyle + [csReplicatable];
{$ELSE}
Style := bsWin31;
{$ENDIF}
ParentShowHint := True;
end;
{$IFDEF WIN32}
procedure TEditButton.Paint;
begin
inherited Paint;
if (FState <> rbsDown) then
with Canvas do begin
if NewStyleControls then Pen.Color := clBtnFace
else Pen.Color := clBtnShadow;
MoveTo(0, 0);
LineTo(0, Self.Height - 1);
Pen.Color := clBtnHighlight;
MoveTo(1, 1);
LineTo(1, Self.Height - 2);
end;
end;
{$ENDIF WIN32}
procedure TEditButton.MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer);
begin
if (Button = mbLeft) then
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -