⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scustomcomboedit.pas

📁 AlphaControls是一个Delphi标准控件的集合
💻 PAS
📖 第 1 页 / 共 2 页
字号:
begin
  SetEditRect;
end;

procedure TsCustomComboEdit.WMSize(var Message: TWMSize);
var
  MinHeight: Integer;
begin
  inherited;
  if not (csLoading in ComponentState) then begin
    MinHeight := GetMinHeight;
    if Height < MinHeight then begin
      Height := MinHeight;
      Exit;
    end;
  end
  else begin
    if (FPopupWindow <> nil) and (csDesigning in ComponentState) then
      FPopupWindow.SetBounds(0, Height + 1, 10, 10);
  end;
  UpdateBtnBounds;
  SetSelLength(10);
end;

function TsCustomComboEdit.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 := Mini(SysMetrics.tmHeight, Metrics.tmHeight);
end;

function TsCustomComboEdit.GetMinHeight: Integer;
var
  I: Integer;
begin
  I := GetTextHeight;
  Result := I + GetSystemMetrics(SM_CYBORDER) * 4 + 1;
end;

function TsCustomComboEdit.GetDroppedDown : Boolean;
begin
  Result := (FPopupWindow <> nil) and FPopupWindow.Visible;
end;

procedure TsCustomComboEdit.CMFontChanged(var Message: TMessage);
begin
  inherited;
  if HandleAllocated then SetEditRect;
end;

procedure TsCustomComboEdit.CMEnabledChanged(var Message: TMessage);
begin
  inherited;
//  FButton.Enabled := Enabled;
end;

procedure TsCustomComboEdit.CMCancelMode(var Message: TCMCancelMode);
begin
  if (Message.Sender <> Self) and
     (Message.Sender <> FPopupWindow) and
     (Message.Sender <> FButton) and
     ((FPopupWindow <> nil) and
     not FPopupWindow.ContainsControl(Message.Sender)) then begin
       PopupWindowClose;
  end;
end;

procedure TsCustomComboEdit.CMEnter(var Message: TMessage);
begin
  if AutoSelect and not (csLButtonDown in ControlState) then SelectAll;
  inherited;
end;

procedure TsCustomComboEdit.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 TsCustomComboEdit.WMKillFocus(var Message: TWMKillFocus);
begin
  inherited;
  FFocused := False;
end;

procedure TsCustomComboEdit.WMSetFocus(var Message: TMessage);
begin
  inherited;
  FFocused := True;
  SetShowCaret;
end;

procedure TsCustomComboEdit.SetShowCaret;
begin
  CreateCaret(Handle, 0, integer(fsBold in Font.Style) + 1, GetTextHeight);
  ShowCaret(Handle);
end;

procedure TsCustomComboEdit.EditButtonClick(Sender: TObject);
begin
  if not FReadOnly then ButtonClick;
end;

procedure TsCustomComboEdit.DoClick;
begin
  EditButtonClick(Self);
end;

procedure TsCustomComboEdit.ButtonClick;
begin
  if Assigned(FOnButtonClick) then FOnButtonClick(Self);
  if DontPopup then DontPopup := False else
  if FPopupWindow <> nil then begin
    if DroppedDown
      then PopupWindowClose
      else
        if not DontPopup then PopupWindowShow;
  end;
end;

procedure TsCustomComboEdit.SelectAll;
begin
  if DirectInput then inherited SelectAll;
end;

function TsCustomComboEdit.GetDirectInput: Boolean;
begin
  Result := FDirectInput;
end;

procedure TsCustomComboEdit.SetDirectInput(Value: Boolean);
begin
  inherited ReadOnly := not Value or FReadOnly;
  FDirectInput := Value;
end;

procedure TsCustomComboEdit.WMPaste(var Message: TWMPaste);
begin
  if not FDirectInput or ReadOnly then Exit;
  inherited;
end;

procedure TsCustomComboEdit.WMCut(var Message: TWMCut);
begin
  if not FDirectInput or ReadOnly then Exit;
  inherited;
end;

procedure TsCustomComboEdit.SetReadOnly(Value: Boolean);
begin
  if Value <> FReadOnly then begin
    FReadOnly := Value;
    inherited ReadOnly := Value or not FDirectInput;
  end;
end;

procedure TsCustomComboEdit.SetAlignment(Value: TAlignment);
begin
  if FAlignment <> Value then begin
    FAlignment := Value;
    sStyle.Invalidate;
  end;
end;

function EditorTextMargins(Editor: TsCustomComboEdit): TPoint;
var
  DC: HDC;
  SaveFont: HFont;
  I: Integer;
  SysMetrics, Metrics: TTextMetric;
begin
  with Editor do begin
    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
      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;
    end;
  end;
end;

procedure TsCustomComboEdit.WMNCCalcSize(var Message: TWMNCCalcSize);
begin
  inherited;
  InflateRect(Message.CalcSize_Params^.rgrc[0], -3, -3);
//  Message.CalcSize_Params^.rgrc[0].Right := Message.CalcSize_Params^.rgrc[0].Right - {FButton.Width -} 6;
  SetEditRect;
end;

procedure TsCustomComboEdit.WMNCPaint(var Message: TMessage);
begin
  if (csDestroying in ComponentState) or (csLoading in ComponentState) then Exit;
  Color := sStyle.GetActiveColor;
  inherited;
  sStyle.RedrawBorder;
end;

procedure TsCustomComboEdit.WndProc(var Message: TMessage);
begin
  if Assigned(FsStyle) then FsStyle.WndProc(Message);
  if Message.Result <> 1 then inherited;
end;

procedure TsCustomComboEdit.Invalidate;
begin
  Color := sStyle.GetActiveColor;
  if (csDesigning in ComponentState) and Assigned(FsStyle) then begin
    if not RestrictDrawing then FsStyle.BGChanged := True;
  end;
  if Assigned(Button) then begin
    if not RestrictDrawing then Button.sStyle.BGChanged := True;
    Button.Invalidate;
  end;
  if Assigned(Parent) then sStyle.RedrawBorder;
  inherited;
end;

procedure TsCustomComboEdit.PopupWindowClose;
begin
  if Assigned(FPopupWindow) and TForm(FPopupWindow).Visible then begin
    TForm(FPopupWindow).Close;
    DontPopup := True;
  end;
end;

procedure TsCustomComboEdit.CreateParams(var Params: TCreateParams);
const
  Alignments: array[TAlignment] of Longword = (ES_LEFT, ES_RIGHT, ES_CENTER);
begin
  inherited CreateParams(Params);
  Params.Style := Params.Style or ES_MULTILINE or WS_CLIPCHILDREN
    or Alignments[FAlignment];
end;

procedure TsCustomComboEdit.KeyPress(var Key: Char);
begin
  if (Key = Char(VK_RETURN)) or (Key = Char(VK_ESCAPE)) then
  begin
      { must catch and remove this, since is actually multi-line }
      GetParentForm(Self).Perform(CM_DIALOGKEY, Byte(Key), 0);
      if Key = Char(VK_RETURN) then begin
        inherited KeyPress(Key);
        Key := #0;
        Exit;
      end;
  end;
  inherited KeyPress(Key);
end;

procedure TsCustomComboEdit.AfterConstruction;
begin
  inherited;
  sStyle.Loaded;
end;

procedure TsCustomComboEdit.Loaded;
begin
  inherited;
  sStyle.Loaded;
end;

procedure TsEditButton.DrawGlyph;
var
  IRect : TRect;
  Bmp : TBitmap;
begin
  Exit;
  IRect := ImgRect;

  Bmp := TBitmap.Create;
  Bmp.Assign(DefBMP);
  Bmp.PixelFormat := pf24bit;
  Bmp.TransparentColor := Bmp.Canvas.Pixels[0, Bmp.Height - 1];

  if not Enabled then begin
//    DisableBmp(Bmp);
  end;

  try
{
    if not sStyle.ControlIsActive and Grayed then begin
      GrayScale(Bmp);
    end;
    MaskColor := TsColor(Bmp.Canvas.Pixels[0, Bmp.Height - 1]);


    if not sStyle.ControlIsActive and (Blend > 0) then begin
      c.C := ColorToRGB(sStyle.Painting.Color);
      BlendTransRectangle(sStyle.FCacheBmp, IRect.Left, IRect.Top, Bmp,
                          Rect(0,
                               0,
                               Bmp.Width,
                               Bmp.Height),
                          Blend / 100, MaskColor);
    end
    else begin
      CopyTransBitmaps(sStyle.FCacheBmp, Bmp, IRect.Left, IRect.Top, MaskColor);
    end;
}
  finally
    FreeAndNil(Bmp);
  end;
end;

procedure TsCustomComboEdit.SetPopupWidth(const Value: integer);
begin
  FPopupWidth := Value;
end;

procedure TsCustomComboEdit.EditButtonMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  MousePressed := True;
//  if DroppedDown then Alert;//DontPopup := True;
end;

procedure TsCustomComboEdit.EditButtonMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  MousePressed := False;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -