📄 secedit.pas
字号:
UnhookWindowsHookEx(COMBOHOOK);
COMBOHOOK := 0;
end;
end;
end;
procedure TSecCustomEdit.CMCancelMode(var Message: TCMCancelMode);
begin
//
end;
procedure TSecCustomEdit.CMEnabledChanged(var Message: TMessage);
begin
inherited;
FButton.Enabled:=Enabled;
end;
constructor TSecCustomEdit.create(AOwner: TComponent);
begin
inherited create(AOwner);
FControl:=TWinControl.Create(self);
with FControl do
begin
ControlStyle := ControlStyle + [csReplicatable];
Width := Max(GetSystemMetrics(SM_CXVSCROLL), 17);
Height := 17;
Visible := True;
Parent := Self;
end;
FButton:=TSecCustomBtn.Create(self);
with FButton do
begin
ControlStyle := ControlStyle + [csReplicatable];
SetBounds (0, 0, FControl.Width, FControl.Height);
Align:=alclient;
Parent := FControl;
OnMouseDown := BtnMouseDown;
end;
end;
procedure TSecCustomEdit.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
with Params do
Style := Style and not (ES_AUTOVSCROLL or ES_WANTRETURN) or
WS_CLIPCHILDREN or ES_MULTILINE;
end;
procedure TSecCustomEdit.CreateWnd;
begin
inherited;
SetEditRect;
end;
destructor TSecCustomEdit.destroy;
begin
FButton.Free;
FControl.Free;
inherited destroy;
end;
procedure TSecCustomEdit.DoCloseUp(Accept: Boolean);
begin
if Assigned(FOnCloseUp) then
FOnCloseUp(self, Accept);
end;
procedure TSecCustomEdit.DoDropDown;
begin
if Assigned(FOnDropDown) then FOnDropDown(self);
end;
procedure TSecCustomEdit.DropDown;
var
p:TPoint;
NewControlSize:TSize;
Border:Integer;
begin
if COMBOHOOK = 0 then
COMBOHOOK := SetWindowsHookEx(WH_MOUSE, @ComboHookProc, HINSTANCE, GetCurrentThreadID);
DoDropDown;
p:=Parent.ClientToScreen(Point(Left,Top));
Border:=2*GetSystemMetrics(SM_CYBORDER);
NewControlSize:=ItemSize;
if ItemCount > 0 then
NewControlSize.cy:=Min(DropDownCount, ItemCount) * NewControlSize.cy
else
NewControlSize.cy:=Height;
inc(NewControlSize.cy,Border);
DropDownContainer.Height:=NewControlSize.cy;
if NewControlSize.cx=0 then
NewControlSize.cx:=Width
else
NewControlSize.cx:=Max(Width, NewControlSize.cx + Border + 2 * GetSystemMetrics(SM_CXVSCROLL));
if p.x > Screen.Width - NewControlSize.cx then
p.x := (p.x + Width) - NewControlSize.cx;
if p.y + Height + NewControlSize.cy > Screen.Height then
p.y := (p.y - Height) - NewControlSize.cy;
TEdit(DropDownContainer).Color := TEdit(DropDownControl).Color;
if TForm(GetParentForm(self)).formstyle = fsStayOnTop then
SetWindowPos(DropDownContainer.Handle, HWND_TOPMOST, p.x, p.y + Height, NewControlSize.cx, NewControlSize.cy,
SWP_NOACTIVATE or SWP_SHOWWINDOW)
else
SetWindowPos(DropDownContainer.Handle, HWND_TOP, p.x, p.y + Height, NewControlSize.cx, NewControlSize.cy,
SWP_NOACTIVATE or SWP_SHOWWINDOW);
DropDownContainer.Visible := True;
DropDownControl.Update;
ShowCaret;
end;
function TSecCustomEdit.GetButtonStyle: TSecCustomBtnStyle;
begin
result:=FButton.BtnStlye;
end;
function TSecCustomEdit.GetEditRect: TRect;
begin
result.Bottom:=ClientHeight+1;
if ShowButton then
result.Right:=FControl.Left-1
else
result.Right:=ClientWidth-2;
result.Top:=0;
result.Left:=0;
if BorderStyle=bsNone then
begin
result.Top:=1;
result.Left:=1;
end;
end;
function TSecCustomEdit.GetOnButtonClick: TNotifyEvent;
begin
result:=FButton.OnClick;
end;
function TSecCustomEdit.GetShowButton: Boolean;
begin
result:=FControl.Visible;
end;
procedure TSecCustomEdit.HideCaret;
begin
Windows.HideCaret(Handle);
inherited ReadOnly := True;
end;
function TSecCustomEdit.IsDroppedDown: Boolean;
begin
result:=false;
end;
procedure TSecCustomEdit.loaded;
begin
inherited;
//UpdateButtonPosition;
end;
procedure TSecCustomEdit.MouseDown(Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
inherited;
if Style = csDropDownList then
begin
if not IsDroppedDown and (Button = mbLeft) then begin
PostMessage(Handle, WM_SEC_CALLDROPDOWN, 0, 0);
ReleaseCapture;
end
else
CloseUp(True);
end;
end;
procedure TSecCustomEdit.SetButtonStyle(const Value: TSecCustomBtnStyle);
begin
FButton.BtnStlye:=Value;
end;
procedure TSecCustomEdit.SetDropDownCount(const Value: Integer);
begin
FDropDownCount := Value;
end;
procedure TSecCustomEdit.SetEditRect;
var
r:TRect;
begin
r := GetEditRect;
SendMessage(Handle, EM_SETRECTNP, 0, LPARAM(@r));
end;
procedure TSecCustomEdit.SetOnButtonClick(const Value: TNotifyEvent);
begin
FButton.OnClick:=Value;
end;
procedure TSecCustomEdit.SetOnCloseUp(const Value: TSecComboCloseUpEvent);
begin
FOnCloseUp := Value;
end;
procedure TSecCustomEdit.SetOnDropDown(const Value: TNotifyEvent);
begin
FOnDropDown := Value;
end;
procedure TSecCustomEdit.SetShowButton(const Value: Boolean);
begin
if FControl.Visible<>Value then
begin
FControl.Visible:=Value;
UpdateButtonPosition;
if not (csLoading in Owner.ComponentState) then
SetEditRect;
Invalidate;
end;
end;
procedure TSecCustomEdit.SetStyle(const Value: TSecComboStyle);
begin
FStyle := Value;
end;
procedure TSecCustomEdit.ShowCaret;
begin
if not HandleAllocated then
exit;
Windows.ShowCaret(Handle);
inherited ReadOnly := False;
end;
procedure TSecCustomEdit.UpdateButtonPosition;
var
offset: integer;
begin
offset:= 0;
if not Ctl3d then
offset:=1;
if (not NewStyleControls) or (BorderStyle = bsNone) or (not Ctl3d) then
FControl.SetBounds (Width - FControl.Width - offset, offset, FControl.Width, ClientHeight-offset*2)
else
FControl.SetBounds (Width - FControl.Width - 4, offset, FControl.Width, ClientHeight-offset);
if not FControl.Visible and (csDesigning in ComponentState) then
FControl.Left:=BoundsRect.Right;
end;
procedure TSecCustomEdit.WMKillFocus(var Message: TWMKillFocus);
begin
inherited;
if (DropdownContainer<>nil) and
DropDownContainer.HandleAllocated and (Message.FocusedWnd <> DropDownContainer.Handle) then
CloseUp(True);
if Style = csDropDownList then
Invalidate;
end;
procedure TSecCustomEdit.WMSetFocus(var Message: TWMSetFocus);
begin
inherited;
if Style = csDropDownList then
begin
Invalidate;
ShowCaret;
HideCaret;
end;
end;
procedure TSecCustomEdit.WMSize(var Message: TWMSize);
begin
inherited;
UpdateButtonPosition;
SetEditRect;
end;
procedure TSecCustomEdit.WndProc(var Message: TMessage);
begin
if Message.Msg = WM_SEC_CALLDROPDOWN then
DropDown;
case Message.Msg of
//WM_PASTE, WM_CUT, WM_KEYFIRST..WM_KEYLAST:
//if fcIsInwwGrid(self) then Change;
WM_NCLBUTTONDOWN: CloseUp(True);
end;
inherited;
end;
{ TSecEdit }
constructor TSecEdit.create(AOwner: TComponent);
begin
inherited;
end;
{ TSecCustomTreeCombo }
procedure TSecCustomTreeCombo.BtnMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
parentForm: TCustomForm;
begin
inherited;
if Button <> mbLeft then
Exit;
if IsDroppedDown then
CloseUp(True)
else
begin
parentForm:= GetParentForm(self);
if (parentForm<>nil) and (TForm(parentForm).formstyle = fsMDIChild) then
if Screen.ActiveForm <> parentForm then
SendMessage(parentform.Handle, WM_ACTIVATE, 0, 0);
if CanFocus then
begin
SetFocus;
if Handle<>GetFocus then
windows.SetFocus(Handle);
end;
if (Screen.ActiveControl=self) or Focused then
PostMessage(Handle, WM_SEC_CALLDROPDOWN, 0, 0);
end;
end;
procedure TSecCustomTreeCombo.CloseUp(Accept: Boolean);
var
IsDroppedDown: Boolean;
begin
IsDroppedDown := self.IsDroppedDown;
inherited;
if IsDroppedDown then
begin
if Accept and (FOriginalNode<>FSelectedNode) {and EditCanModify} then
begin
if FSelectedNode<>nil then
begin
Text:= FSelectedNode.Text;
end;
end
else
begin
TreeView.Selected := FOriginalNode;
if TreeView.Selected <> nil then
Text := TreeView.Selected.Text
else
Text:= FOriginalText;
end;
DoCloseUp(Accept);
end;
TreeView.KillTimer;
//if Editable then
SelectAll;
end;
constructor TSecCustomTreeCombo.create(AOwner: TComponent);
begin
inherited create(AOwner);
ButtonStyle:=cbsDownArrow;
DropDownCount:=8;
FPanel:=TSecPanel.Create(self);
FPanel.Visible:=False;
FTreeView:=TSecPopupTreeView.Create(self);
FTreeView.FTreeCombo := self;
with FTreeView do
begin
BorderStyle := bsNone;
Parent := FPanel;
Visible := True;
Align := alClient;
//OnItemChange := ItemsChange;
end;
end;
procedure TSecCustomTreeCombo.CreateWnd;
begin
inherited CreateWnd;
FPanel.Parent:=self;
end;
destructor TSecCustomTreeCombo.destroy;
begin
FTreeView.Free;
FPanel.Free;
inherited;
end;
procedure TSecCustomTreeCombo.DropDown;
begin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -