📄 rxtooledit.pas
字号:
if ButtonWidth <> Value then begin
FBtnControl.Visible := Value > 1;
if (csCreating in ControlState) then begin
FBtnControl.Width := Value;
FButton.Width := Value;
with FButton do
ControlStyle := ControlStyle - [csFixedWidth];
RecreateGlyph;
end
// else if (Value <> ButtonWidth) and (Value < ClientWidth) then begin
//Polaris
else if (Value <> ButtonWidth) and
((Assigned(Parent) and (Value < ClientWidth)) or
(not Assigned(Parent) and (Value < Width)))
then begin
FButton.Width := Value;
with FButton do
ControlStyle := ControlStyle - [csFixedWidth];
if HandleAllocated then RecreateWnd;
RecreateGlyph;
end;
end;
end;
function TCustomComboEdit.GetButtonHint: string;
begin
Result := FButton.Hint;
end;
procedure TCustomComboEdit.SetButtonHint(const Value: string);
begin
FButton.Hint := Value;
end;
function TCustomComboEdit.GetGlyph: TBitmap;
begin
Result := FButton.Glyph;
end;
procedure TCustomComboEdit.SetGlyph(Value: TBitmap);
begin
FButton.Glyph := Value;
FGlyphKind := gkCustom;
end;
function TCustomComboEdit.GetNumGlyphs: TNumGlyphs;
begin
Result := FButton.NumGlyphs;
end;
procedure TCustomComboEdit.SetNumGlyphs(Value: TNumGlyphs);
begin
if FGlyphKind in [gkDropDown, gkEllipsis] then FButton.NumGlyphs := 1
else if FGlyphKind = gkDefault then FButton.NumGlyphs := FDefNumGlyphs
else FButton.NumGlyphs := Value;
end;
procedure TCustomComboEdit.SetEditRect;
var
Loc: TRect;
begin
SetRect(Loc, 0, 0, ClientWidth - FBtnControl.Width{Polaris - 2}, ClientHeight + 1);
SendMessage(Handle, EM_SETRECTNP, 0, LongInt(@Loc));
//Polaris
// SendMessage(Handle, EM_SETMARGINS, EC_RIGHTMARGIN, MakeLong(0, FBtnControl.Width));
end;
procedure TCustomComboEdit.UpdateBtnBounds;
var
BtnRect: TRect;
begin
{$IFDEF WIN32}
if NewStyleControls then begin
if Ctl3D and (BorderStyle = bsSingle) then
BtnRect := Bounds(Width - FButton.Width - 4, 0,
FButton.Width, Height - 4)
else begin
if BorderStyle = bsSingle then
BtnRect := Bounds(Width - FButton.Width - 2, 2,
FButton.Width, Height - 4)
else
BtnRect := Bounds(Width - FButton.Width, 0,
FButton.Width, Height);
end;
end
else
BtnRect := Bounds(Width - FButton.Width, 0, FButton.Width, Height);
{$ELSE}
BtnRect := Bounds(Width - FButton.Width, 0, FButton.Width, Height);
{$ENDIF}
with BtnRect do
FBtnControl.SetBounds(Left, Top, Right - Left, Bottom - Top);
FButton.Height := FBtnControl.Height;
SetEditRect;
end;
{$IFDEF WIN32}
procedure TCustomComboEdit.CMCtl3DChanged(var Message: TMessage);
begin
inherited;
UpdateBtnBounds;
end;
{$ENDIF}
procedure TCustomComboEdit.WMSize(var Message: TWMSize);
var
MinHeight: Integer;
begin
inherited;
if not (csLoading in ComponentState) then begin
MinHeight := GetMinHeight;
{ text edit bug: if size to less than MinHeight, then edit ctrl does
not display the text }
if Height < MinHeight then begin
Height := MinHeight;
Exit;
end;
end
else begin
if (FPopup <> nil) and (csDesigning in ComponentState) then
FPopup.SetBounds(0, Height + 1, 10, 10);
end;
UpdateBtnBounds;
end;
function TCustomComboEdit.GetTextHeight: Integer;
var
DC: HDC;
SaveFont: HFont;
SysMetrics, Metrics: TTextMetric;
begin
DC := GetDC(0);
try
GetTextMetrics(DC, SysMetrics);
SaveFont := SelectObject(DC, Font.Handle);
GetTextMetrics(DC, Metrics);
SelectObject(DC, SaveFont);
finally
ReleaseDC(0, DC);
end;
// Result := Min(SysMetrics.tmHeight, Metrics.tmHeight); // Polaris
Result := Metrics.tmHeight; // Polaris
end;
function TCustomComboEdit.GetMinHeight: Integer;
var
I: Integer;
begin
I := GetTextHeight;
Result := I + GetSystemMetrics(SM_CYBORDER) * 4 +
1 {$IFNDEF WIN32} + (I div 4) {$ENDIF};
end;
procedure TCustomComboEdit.UpdatePopupVisible;
begin
FPopupVisible := (FPopup <> nil) and FPopup.Visible;
end;
function TCustomComboEdit.GetPopupVisible: Boolean;
begin
Result := (FPopup <> nil) and FPopupVisible;
end;
procedure TCustomComboEdit.CMFontChanged(var Message: TMessage);
begin
inherited;
if HandleAllocated then SetEditRect;
end;
procedure TCustomComboEdit.CMEnabledChanged(var Message: TMessage);
begin
inherited;
FButton.Enabled := Enabled;
end;
procedure TCustomComboEdit.CMCancelMode(var Message: TCMCancelMode);
begin
if (Message.Sender <> Self) and (Message.Sender <> FPopup) and
(Message.Sender <> FButton) and ((FPopup <> nil) and
not FPopup.ContainsControl(Message.Sender)) then
PopupCloseUp(FPopup, False);
end;
procedure TCustomComboEdit.CMEnter(var Message: TMessage);
begin
if AutoSelect and not (csLButtonDown in ControlState) then SelectAll;
inherited;
end;
procedure TCustomComboEdit.CNCtlColor(var Message: TMessage);
var
TextColor: Longint;
begin
inherited;
if NewStyleControls then begin
TextColor := ColorToRGB(Font.Color);
if not Enabled and (ColorToRGB(Color) <> ColorToRGB(clGrayText)) then
TextColor := ColorToRGB(clGrayText);
SetTextColor(Message.WParam, TextColor);
end;
end;
procedure TCustomComboEdit.WMKillFocus(var Message: TWMKillFocus);
begin
inherited;
FFocused := False;
PopupCloseUp(FPopup, False);
end;
procedure TCustomComboEdit.WMSetFocus(var Message: TMessage);
begin
inherited;
FFocused := True;
SetShowCaret;
end;
{$IFDEF RX_D4}
procedure TCustomComboEdit.CMBiDiModeChanged(var Message: TMessage);
begin
inherited;
if FPopup <> nil then FPopup.BiDiMode := BiDiMode;
end;
{$ENDIF}
procedure TCustomComboEdit.SetShowCaret;
const
CaretWidth: array[Boolean] of Byte = (1, 2);
begin
CreateCaret(Handle, 0, CaretWidth[fsBold in Font.Style], GetTextHeight);
ShowCaret(Handle);
end;
procedure TCustomComboEdit.EditButtonClick(Sender: TObject);
begin
if (not FReadOnly) or AlwaysEnable then ButtonClick;
end;
procedure TCustomComboEdit.DoClick;
begin
EditButtonClick(Self);
end;
procedure TCustomComboEdit.ButtonClick;
begin
if Assigned(FOnButtonClick) then FOnButtonClick(Self);
if FPopup <> nil then begin
if FPopupVisible then PopupCloseUp(FPopup, True) else PopupDropDown(True);
end;
end;
procedure TCustomComboEdit.SelectAll;
begin
if DirectInput then inherited SelectAll;
end;
function TCustomComboEdit.GetDirectInput: Boolean;
begin
Result := FDirectInput;
end;
procedure TCustomComboEdit.SetDirectInput(Value: Boolean);
begin
inherited ReadOnly := not Value or FReadOnly;
FDirectInput := Value;
end;
procedure TCustomComboEdit.WMPaste(var Message: TWMPaste);
begin
if not FDirectInput or ReadOnly then Exit;
inherited;
end;
procedure TCustomComboEdit.WMCut(var Message: TWMCut);
begin
if not FDirectInput or ReadOnly then Exit;
inherited;
end;
function TCustomComboEdit.GetReadOnly: Boolean;
begin
Result := FReadOnly;
end;
procedure TCustomComboEdit.SetReadOnly(Value: Boolean);
begin
if Value <> FReadOnly then begin
FReadOnly := Value;
inherited ReadOnly := Value or not FDirectInput;
end;
end;
procedure TCustomComboEdit.SetAlignment(Value: TAlignment);
begin
if FAlignment <> Value then begin
FAlignment := Value;
RecreateWnd;
end;
end;
function TCustomComboEdit.BtnWidthStored: Boolean;
begin
if (FGlyphKind = gkDefault) and (Glyph <> nil) then
Result := ButtonWidth <> Max(Glyph.Width div FButton.NumGlyphs + 6,
DefEditBtnWidth)
else if FGlyphKind = gkDropDown then
Result := ButtonWidth <> GetSystemMetrics(SM_CXVSCROLL)
{$IFNDEF WIN32} + 1{$ENDIF}
else Result := ButtonWidth <> DefEditBtnWidth;
end;
function TCustomComboEdit.IsCustomGlyph: Boolean;
begin
Result := FGlyphKind = gkCustom;
end;
procedure TCustomComboEdit.SetGlyphKind(Value: TGlyphKind);
begin
if FGlyphKind <> Value then begin
FGlyphKind := Value;
if (FGlyphKind = gkCustom) and (csReading in ComponentState) then begin
Glyph := nil;
end;
RecreateGlyph;
if (FGlyphKind = gkDefault) and (Glyph <> nil) then
ButtonWidth := Max(Glyph.Width div FButton.NumGlyphs + 6, FButton.Width)
else if FGlyphKind = gkDropDown then begin
ButtonWidth := GetSystemMetrics(SM_CXVSCROLL){$IFNDEF WIN32} + 1{$ENDIF};
with FButton do
ControlStyle := ControlStyle + [csFixedWidth];
end;
end;
end;
function TCustomComboEdit.GetDefaultBitmap(var DestroyNeeded: Boolean): TBitmap;
begin
Result := nil;
end;
procedure TCustomComboEdit.RecreateGlyph;
function CreateEllipsisGlyph: TBitmap;
var
W, G, I: Integer;
begin
Result := TBitmap.Create;
with Result do
try
Monochrome := True;
Width := Max(1, FButton.Width - 6);
Height := 4;
W := 2;
G := (Result.Width - 3 * W) div 2;
if G <= 0 then G := 1;
if G > 3 then G := 3;
I := (Width - 3 * W - 2 * G) div 2;
PatBlt(Canvas.Handle, I, 1, W, W, BLACKNESS);
PatBlt(Canvas.Handle, I + G + W, 1, W, W, BLACKNESS);
PatBlt(Canvas.Handle, I + 2 * G + 2 * W, 1, W, W, BLACKNESS);
except
Free;
raise;
end;
end;
var
NewGlyph: TBitmap;
DestroyNeeded: Boolean;
begin
case FGlyphKind of
gkDefault:
begin
DestroyNeeded := False;
NewGlyph := GetDefaultBitmap(DestroyNeeded);
try
FButton.Glyph.Assign(NewGlyph);
NumGlyphs := FDefNumGlyphs;
finally
if DestroyNeeded then NewGlyph.Destroy;
end;
end;
gkDropDown:
begin
FButton.Glyph.Handle := LoadBitmap(0, PChar(32738));
NumGlyphs := 1;
end;
gkEllipsis:
begin
NewGlyph := CreateEllipsisGlyph;
try
FButton.Glyph := NewGlyph;
NumGlyphs := 1;
finally
NewGlyph.Destroy;
end;
end;
end;
end;
const
FileBitmap: TBitmap = nil;
DateBitmap: TBitmap = nil;
{ TFileDirEdit }
constructor TFileDirEdit.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
OEMConvert := True;
{$IFNDEF WIN32}
MaxLength := MaxFileLength;
{$ENDIF}
ControlState := ControlState + [csCreating];
try
GlyphKind := gkDefault; { force update }
finally
ControlState := ControlState - [csCreating];
end;
end;
function TFileDirEdit.GetDefaultBitmap(var DestroyNeeded: Boolean): TBitmap;
begin
DestroyNeeded := False;
if FileBitmap = nil then begin
FileBitmap := TBitmap.Create;
FileBitmap.Handle := LoadBitmap(hInstance, sFileBmp);
end;
Result := FileBitmap;
end;
procedure TFileDirEdit.DoBeforeDialog(var FileName: string;
var Action: Boolean);
begin
if Assigned(FOnBeforeDialog) then FOnBeforeDialog(Self, FileName, Action);
end;
procedure TFileDirEdit.DoAfterDialog(var FileName: string;
var Action: Boolean);
begin
if Assigned(FOnAfterDialog) then FOnAfterDialog(Self, FileName, Action);
end;
procedure TFileDirEdit.CreateHandle;
begin
inherited CreateHandle;
if FAcceptFiles then SetDragAccept(True);
end;
procedure TFileDirEdit.DestroyWindowHandle;
begin
SetDragAccept(False);
inherited DestroyWindowHandle;
end;
procedure TFileDirEdit.SetDragAccept(Value: Boolean);
begin
if not (csDesigning in ComponentState) and (Handle <> 0) then
DragAcceptFiles(Handle, Value);
end;
procedure TFileDirEdit.SetAcceptFiles(Value: Boolean);
begin
if FAcceptFiles <> Value then begin
SetDragAccept(Value);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -