📄 jvtooledit.pas
字号:
if DWORD(GetWindowLong(ed.Handle, GWL_EXSTYLE)) <> ExStyle then
SetWindowLong(ed.Handle, GWL_EXSTYLE, ExStyle);
end;
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 := Msg.DC;
if DC = 0 then
DC := BeginPaint(ed.Handle, PS);
ACanvas.Handle := DC;
try
ACanvas.Font := ed.Font;
with ACanvas do
begin
SendMessage(Editor.Handle, EM_GETRECT, 0, Integer(@EditRect));
if not (NewStyleControls and ed.Ctl3D) and (ed.BorderStyle = bsSingle) then
begin
Brush.Color := clWindowFrame;
FrameRect(ed.ClientRect);
end;
S := AText;
LTextWidth := TextWidth(S);
if PopupVisible then
X := EditRect.Left
else
begin
case AAlignment of
taLeftJustify:
X := EditRect.Left;
taRightJustify:
X := EditRect.Right - LTextWidth;
else
X := (EditRect.Right + EditRect.Left - LTextWidth) div 2;
end;
end;
if SysLocale.MiddleEast then
UpdateTextFlags;
if not ed.Enabled then
begin
// if PS.fErase then // (p3) fErase is not set to true when control is disabled
ed.Perform(WM_ERASEBKGND, ACanvas.Handle, 0);
SaveDC(ACanvas.Handle);
try
ACanvas.Brush.Style := bsClear;
ACanvas.Font.Color := DisabledTextColor;
ACanvas.TextRect(EditRect, X, EditRect.Top, S);
finally
RestoreDC(ACanvas.Handle, -1);
end;
end
else
begin
Brush.Color := ed.Color;
ACanvas.TextRect(EditRect, X, EditRect.Top, S);
end;
end;
finally
ACanvas.Handle := 0;
if Msg.DC = 0 then
EndPaint(ed.Handle, PS);
end;
end;
{$ENDIF VCL}
{$IFDEF VisualCLX}
{ PaintEdit (CLX) needs an implemented EM_GETRECT message handler. If no
EM_GETTEXT handler exists or the edit control does not implement
IComboEditHelper, it uses the ClientRect of the edit control. }
function PaintEdit(Editor: TCustomEdit; const AText: WideString;
AAlignment: TAlignment; PopupVisible: Boolean;
DisabledTextColor: TColor; StandardPaint: Boolean; Flat: Boolean;
ACanvas: TCanvas): Boolean;
var
LTextWidth, X: Integer;
EditRect: TRect;
S: WideString;
ed: TCustomEditAccessProtected;
SavedFont: TFontRecall;
SavedBrush: TBrushRecall;
Offset: Integer;
R: TRect;
EditHelperIntf: IComboEditHelper;
begin
Result := True;
if csDestroying in Editor.ComponentState then
Exit;
ed := TCustomEditAccessProtected(Editor);
if StandardPaint and not (csPaintCopy in ed.ControlState) then
begin
Result := False;
{ return false if we need to use standard paint handler }
Exit;
end;
SavedFont := TFontRecall.Create(ACanvas.Font);
SavedBrush := TBrushRecall.Create(ACanvas.Brush);
try
ACanvas.Font := ed.Font;
// paint Border
R := ed.ClientRect;
Offset := 0;
if (ed.BorderStyle = bsSingle) then
begin
ACanvas.Start;
QStyle_drawPanel(QWidget_style(Editor.Handle), ACanvas.Handle,
R.Left, R.Top, R.Right - R.Left, R.Bottom - R.Top, QWidget_colorGroup(Editor.Handle),
True, 2, nil);
ACanvas.Stop;
//QGraphics.DrawEdge(ACanvas, R, esLowered, esLowered, ebRect)
end
else
begin
if Flat then
QGraphics.DrawEdge(ACanvas, R, esNone, esLowered, ebRect);
Offset := 2;
end;
with ACanvas do
begin
if Supports(Editor, IComboEditHelper, EditHelperIntf) then
begin
EditRect := EditHelperIntf.GetEditorRect;
EditHelperIntf := nil;
end
else
begin
EditRect := Rect(0, 0, 0, 0);
SendMessage(Editor.Handle, EM_GETRECT, 0, Integer(@EditRect));
end;
if IsRectEmpty(EditRect) then
begin
EditRect := ed.ClientRect;
if ed.BorderStyle = bsSingle then
InflateRect(EditRect, -2, -2);
end
else
InflateRect(EditRect, -Offset, -Offset);
if Flat and (ed.BorderStyle = bsSingle) then
begin
Brush.Color := clWindowFrame;
FrameRect(ACanvas, ed.ClientRect);
end;
S := AText;
LTextWidth := TextWidth(S);
if PopupVisible then
X := EditRect.Left
else
begin
case AAlignment of
taLeftJustify:
X := EditRect.Left;
taRightJustify:
X := EditRect.Right - LTextWidth;
else
X := (EditRect.Right + EditRect.Left - LTextWidth) div 2;
end;
end;
if not ed.Enabled then
begin
if Supports(ed, IJvWinControlEvents) then
(ed as IJvWinControlEvents).DoEraseBackground(ACanvas, 0);
ACanvas.Brush.Style := bsClear;
ACanvas.Font.Color := DisabledTextColor;
ACanvas.TextRect(EditRect, X, EditRect.Top + 1, S);
end
else
begin
Brush.Color := ed.Color;
DrawSelectedText(ACanvas, EditRect, X, EditRect.Top + 1, S,
ed.SelStart, ed.SelLength,
clHighlight, clHighlightText);
end;
end;
finally
SavedFont.Free;
SavedBrush.Free;
end;
end;
{$ENDIF VisualCLX}
{$IFDEF VCL}
//=== { TAutoCompleteSource } ================================================
constructor TAutoCompleteSource.Create(AComboEdit: TJvCustomComboEdit; const StartIndex: Integer);
begin
inherited Create;
FComboEdit := AComboEdit;
FCurrentIndex := StartIndex;
end;
function TAutoCompleteSource.Clone(out enm: IEnumString): HRESULT;
begin
{ Save state }
try
enm := TAutoCompleteSource.Create(FComboEdit, FCurrentIndex);
Result := S_OK;
except
Result := E_UNEXPECTED;
end;
end;
function TAutoCompleteSource.Next(celt: Integer; out elt;
pceltFetched: PLongint): HRESULT;
var
Fetched: Integer;
S: string;
Ptr: POleStr;
Size: Integer;
begin
if Pointer(elt) = nil then
begin
Result := E_FAIL;
Exit;
end;
Fetched := 0;
while (Fetched < celt) and (FCurrentIndex < FComboEdit.AutoCompleteItems.Count) do
begin
S := FComboEdit.AutoCompleteItems[FCurrentIndex];
Size := (Length(S) + 1) * SizeOf(WideChar);
Ptr := CoTaskMemAlloc(Size);
if Ptr = nil then
begin
Result := E_OUTOFMEMORY;
Exit;
end;
// StringToWideChar() available in D5..D7?
StringToWideChar(S, Ptr, Size);
//lstrcpyW(Ptr, PWideChar(@W[1]));
TOleStrList(elt)[Fetched] := Ptr;
Inc(FCurrentIndex);
Inc(Fetched);
end;
if Assigned(pceltFetched) then
pceltFetched^ := Fetched;
if Fetched = celt then
Result := S_OK
else
Result := S_FALSE;
end;
function TAutoCompleteSource.Reset: HRESULT;
begin
FCurrentIndex := 0;
Result := S_OK;
end;
function TAutoCompleteSource.Skip(celt: Integer): HRESULT;
begin
Inc(FCurrentIndex, celt);
if FCurrentIndex < FComboEdit.AutoCompleteItems.Count then
Result := S_OK
else
begin
Result := S_FALSE;
FCurrentIndex := FComboEdit.AutoCompleteItems.Count;
end;
end;
//=== { TDateHook } ==========================================================
procedure TDateHook.Add;
begin
if FCount = 0 then
Hook;
Inc(FCount);
end;
procedure TDateHook.Delete;
begin
if FCount > 0 then
Dec(FCount);
if FCount = 0 then
UnHook;
end;
function TDateHook.FormatSettingsChange(var Msg: TMessage): Boolean;
begin
Result := False;
if (Msg.Msg = WM_WININICHANGE) and Application.UpdateFormatSettings then
begin
// Let the application obj do the changing; we receive the message
// before the application obj, thus jump over it:
PostMessage(Application.Handle, WM_NULL, 0, 0);
FWinIniChangeReceived := True;
end
else
if (Msg.Msg = WM_NULL) and FWinIniChangeReceived then
begin
FWinIniChangeReceived := False;
DateFormatChanged;
end;
end;
procedure TDateHook.Hook;
begin
if FHooked then
Exit;
Application.HookMainWindow(FormatSettingsChange);
FHooked := True;
end;
procedure TDateHook.UnHook;
begin
if not FHooked then
Exit;
Application.UnhookMainWindow(FormatSettingsChange);
FHooked := False;
end;
{$ENDIF VCL}
//=== { TJvCustomComboEdit } =================================================
constructor TJvCustomComboEdit.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ControlStyle := ControlStyle + [csCaptureMouse];
// AutoSize := False; // Polaris
Height := 21;
FDirectInput := True;
FClickKey := scAltDown;
FPopupAlign := epaRight;
FBtnControl := TWinControl.Create(Self);
with FBtnControl do
ControlStyle := ControlStyle + [csReplicatable];
FBtnControl.Width := DefEditBtnWidth;
FBtnControl.Height := 17;
FBtnControl.Visible := True;
{$IFDEF VCL}
FBtnControl.Parent := Self;
{$IFDEF COMPILER6_UP}
FBtnControl.Align := alCustom;
{$ELSE}
FBtnControl.Align := alRight;
{$ENDIF COMPILER6_UP}
{$ENDIF VCL}
{$IFDEF VisualCLX}
FBtnControl.Parent := Self.ClientArea;
FBtnControl.Left := Self.ClientArea.Width - DefEditBtnWidth;
FBtnControl.Anchors := [akRight, akTop, akBottom];
{$ENDIF VisualCLX}
FButton := TJvEditButton.Create(Self);
FButton.SetBounds(0, 0, FBtnControl.Width, FBtnControl.Height);
FButton.Visible := True;
FButton.Parent := FBtnControl;
FButton.Align := alClient;
TJvEditButton(FButton).OnClick := EditButtonClick;
FAlwaysEnableButton := False;
(* ++ RDB ++ *)
FDisabledColor := clWindow;
FDisabledTextColor := clGrayText;
FGroupIndex := -1;
FStreamedButtonWidth := -1;
FImageKind := ikCustom;
FImageIndex := -1;
FNumGlyphs := 1;
{$IFDEF VCL}
FAutoCompleteItems := TStringList.Create;
FAutoCompleteOptions := [];
CoInitialize(nil);
{$ENDIF VCL}
inherited OnKeyDown := LocalKeyDown;
(* -- RDB -- *)
end;
destructor TJvCustomComboEdit.Destroy;
begin
PopupCloseUp(Self, False);
FButton.OnClick := nil;
{$IFDEF VCL}
FAutoCompleteSource := nil;
FAutoCompleteItems.Free;
FAutoC
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -