📄 scustomcomboedit.pas
字号:
WM_ERASEBKGND : if SkinData.Skinned and IsWindowVisible(Handle) then begin
SkinData.Updating := SkinData.Updating;
if SkinData.Updating then Exit;
end;
end;
inherited;
if Message.MSG = SM_ALPHACMD then case Message.WParamHi of
AC_REMOVESKIN, AC_SETNEWSKIN, AC_REFRESH : if LongWord(Message.LParam) = LongWord(SkinData.SkinManager) then begin
AlphaBroadcast(Self, Message);
SetEditRect
end;
AC_GETCACHE : begin
GlobalCacheInfo.X := 2;
GlobalCacheInfo.Y := 2;
GlobalCacheInfo.Ready := True;
end;
AC_PREPARING : Message.LParam := 0;
end
else case Message.Msg of
WM_SETFOCUS : if AutoSelect then SelectAll;
WM_SIZE, CM_FONTCHANGED : SetEditRect
end
end;
procedure TsCustomComboEdit.Invalidate;
begin
inherited;
if Assigned(Button) then begin
if not RestrictDrawing then Button.SkinData.BGChanged := True;
if FShowButton then begin
if not Button.Visible then begin
Button.Width := 22;
Button.Visible := True
end;
end
else begin
if Button.Visible then begin
Button.Visible := False;
Button.Width := 0
end
end;
Button.Invalidate
end;
end;
procedure TsCustomComboEdit.PopupWindowClose;
begin
if Assigned(FPopupWindow) and TForm(FPopupWindow).Visible then TForm(FPopupWindow).Close;
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 Alignments[FAlignment] or WS_CLIPCHILDREN;
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;
SkinData.Loaded;
end;
procedure TsCustomComboEdit.Loaded;
begin
inherited;
SkinData.Loaded;
SetEditRect;
end;
procedure TsEditButton.DrawGlyph;
const
Offs = 0;
var
RDst, IRect : TRect;
Bmp : TBitmap;
c : TsColor;
R : TRect;
CI : TCacheInfo;
function CurrentMaskRect : TRect; begin
if CurrentState = 2
then Result := Rect(2 * FOwner.GlyphMode.Width, 0, 3 * FOwner.GlyphMode.Width - Offs, FOwner.GlyphMode.Height - Offs)
else if SkinData.FMouseAbove then begin
Result := Rect(FOwner.GlyphMode.Width, 0, 2 * FOwner.GlyphMode.Width - Offs, FOwner.GlyphMode.Height - Offs);
end
else begin
Result := Rect(0, 0, FOwner.GlyphMode.Width - Offs, FOwner.GlyphMode.Height - Offs);
end;
end;
begin
if FOwner.GlyphMode.AssignDefaultBitmap and (DefBmp <> nil) then begin
Bmp := TBitmap.Create;
Bmp.Assign(SkinData.FCacheBmp);
Bmp.Width := DefBMP.Width;
Bmp.Height := DefBMP.Height;
Bmp.PixelFormat := pf24bit;
CI := MakeCacheInfo(SkinData.FCacheBmp);
RDst.Left := (Width - FOwner.GlyphMode.Width) div 3;
RDst.Top := (Height - FOwner.GlyphMode.Height) div 2;
RDst.Right := RDst.Left + FOwner.GlyphMode.Width;
RDst.Bottom := RDst.Top + FOwner.GlyphMode.Height;
IRect := ImgRect;
try
R := CurrentMaskRect;
EmptyCI.X := 0;
CopyByMask(RDst, R, Bmp, DefBMP, CI, True);
if not ControlIsActive(FOwner.SkinData) and not SkinData.FMouseAbove and FOwner.GlyphMode.Grayed then GrayScale(Bmp);
if not ControlIsActive(FOwner.SkinData) and not SkinData.FMouseAbove and (FOwner.GlyphMode.Blend > 0) then begin
c.R := round(2.56 * FOwner.GlyphMode.Blend); c.G := c.R; c.B := c.R;
c.A := 0;
SumBitmaps(Bmp, SkinData.FCacheBmp, c);
end;
if not FOwner.Enabled then BmpDisabledKind(Bmp, DisabledKind, Parent, CI, Point(0, 0));
BitBlt(SkinData.FCacheBmp.Canvas.Handle, 0, 0, Width, Height, Bmp.Canvas.Handle, 0, 0, SRCCOPY);
finally
FreeAndNil(Bmp);
end;
DefBmp := nil;
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
end;
procedure TsCustomComboEdit.EditButtonMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
end;
function TsCustomComboEdit.GetReadOnly: Boolean;
begin
Result := FReadOnly;
end;
procedure TsCustomComboEdit.SetDisabledKind(const Value: TsDisabledKind);
begin
if FDisabledKind <> Value then begin
FDisabledKind := Value;
SkinData.Invalidate;
end;
end;
procedure TsCustomComboEdit.OurPaintHandler(DC : hdc);
var
NewDC, SavedDC : hdc;
PS : TPaintStruct;
begin
BeginPaint(Handle, PS);
if DC = 0 then NewDC := GetWindowDC(Handle) else NewDC := DC;
SavedDC := SaveDC(NewDC);
try
if SkinData.Skinned then begin
SkinData.Updating := SkinData.Updating;
if not SkinData.Updating then begin
SkinData.BGChanged := SkinData.BGChanged or SkinData.HalfVisible or GetBoolMsg(Parent, AC_GETHALFVISIBLE);
SkinData.HalfVisible := not RectInRect(Parent.ClientRect, BoundsRect);
if SkinData.BGChanged then PrepareCache;
UpdateCorners(SkinData, 0);
BitBlt(NewDC, 0, 0, Width, Height, SkinData.FCacheBmp.Canvas.Handle, 0, 0, SRCCOPY);
if (not ControlIsActive(SkinData) or (acPrintDC = NewDC)) and FButton.Visible
then FButton.PaintTo(NewDC, Point(FButton.Left + 2, FButton.Top + 2));
{$IFDEF DYNAMICCACHE}
if Assigned(SkinData.FCacheBmp) then FreeAndNil(SkinData.FCacheBmp);
{$ENDIF}
end;
end
else begin
PrepareCache;
BitBlt(NewDC, 3, 3, Width - 6, Height - 6, SkinData.FCacheBmp.Canvas.Handle, 3, 3, SRCCOPY);
if FButton.Visible then FButton.Paint;
end;
finally
RestoreDC(NewDC, SavedDC);
if DC = 0 then ReleaseDC(Handle, NewDC);
EndPaint(Handle, PS);
end;
end;
procedure TsCustomComboEdit.PaintBorder(DC : hdc);
const
BordWidth = 2;
var
NewDC, SavedDC: HDC;
begin
if not Assigned(Parent) or not Visible or not Parent.Visible or (csCreating in ControlState) or SkinData.Updating then exit;
if DC = 0 then NewDC := GetWindowDC(Handle) else NewDC := DC;
SavedDC := SaveDC(NewDC);
try
if SkinData.BGChanged {and ControlIsActive(SkinData) }then PrepareCache;
UpdateCorners(SkinData, 0);
BitBltBorder(NewDC, 0, 0, Width, Height, SkinData.FCacheBmp.Canvas.Handle, 0, 0, BordWidth);
if ControlIsActive(SkinData) and FButton.Visible
then FButton.PaintTo(NewDC, Point(FButton.Left + BordWidth, FButton.Top + BordWidth));
{$IFDEF DYNAMICCACHE}
if Assigned(SkinData.FCacheBmp) then FreeAndNil(SkinData.FCacheBmp);
{$ENDIF}
finally
RestoreDC(NewDC, SavedDC);
if DC = 0 then ReleaseDC(Handle, NewDC);
end;
end;
procedure TsEditButton.DrawStandardGlyph;
var
TmpBmp : TBitmap;
R, RDst : TRect;
function CurrentMaskRect : TRect; begin
if CurrentState = 2
then Result := Rect(2 * FOwner.GlyphMode.Width, 0, 3 * FOwner.GlyphMode.Width - 1, FOwner.GlyphMode.Height - 1)
else Result := Rect(FOwner.GlyphMode.Width, 0, 2 * FOwner.GlyphMode.Width - 1, FOwner.GlyphMode.Height - 1);
end;
begin
TmpBmp := CreateBmp24(Width, Height);
BitBlt(TmpBmp.Canvas.Handle, 0, 0, Width, Height, Canvas.Handle, 0, 0, SRCCOPY);
FOwner.GlyphMode.AssignDefaultBitmap;
if DefBmp = nil then Exit;
R := CurrentMaskRect;
RDst.Left := (Width - FOwner.GlyphMode.Width) div 2;
RDst.Top := (Height - FOwner.GlyphMode.Height) div 2;
RDst.Right := RDst.Left + FOwner.GlyphMode.Width;
RDst.Bottom := RDst.Top + FOwner.GlyphMode.Height;
DefBmp.PixelFormat := pf24bit;
CopyByMask(
RDst,
R,
TmpBmp,
DefBMP, EmptyCI, True);
BitBlt(Canvas.Handle, 0, 0, Width, Height, TmpBmp.Canvas.Handle, 0, 0, SRCCOPY);
FreeAndNil(TmpBmp);
end;
function TsEditButton.GlyphHeight: integer;
begin
Result := FOwner.GlyphMode.Height;
end;
function TsEditButton.GlyphWidth: integer;
begin
Result := FOwner.GlyphMode.Width;
end;
procedure TsEditButton.Paint;
begin
inherited;
if not SkinData.Skinned then DrawStandardGlyph
end;
procedure TsEditButton.PaintTo(DC: hdc; R: TPoint);
begin
if not FOwner.SkinData.Skinned then begin
Paint;
end
else begin
PrepareCache;
BitBlt(DC, R.x, R.y, SkinData.FCacheBmp.Width, SkinData.FCacheBmp.Height, SkinData.FCacheBmp.Canvas.Handle, 0, 0, SRCCOPY);
end;
end;
procedure TsCustomComboEdit.PaintText;
var
R : TRect;
s : string;
bw : integer;
begin
SkinData.FCacheBMP.Canvas.Font.Assign(Font);
bw := BorderWidth;
R := Rect(bw, bw, Width - bw, bw + SkinData.FCacheBMP.Canvas.TextHeight(EditText));
if Ctl3d and (BorderStyle = bsSingle) then dec(R.Top);
if PasswordChar = #0 then
WriteTextEx(SkinData.FCacheBMP.Canvas, PChar(EditText), Enabled or SkinData.Skinned, R, DT_TOP or DT_WORDBREAK or GetStringFlags(Self, Alignment) or DT_NOPREFIX, SkinData, ControlIsActive(SkinData))
else
begin
SetLength(s, Length(EditText));
FillChar(s[1], Length(s), PasswordChar);
WriteTextEx(SkinData.FCacheBMP.Canvas, PChar(s), Enabled or SkinData.Skinned, R, DT_TOP or DT_WORDBREAK or GetStringFlags(Self, Alignment) or DT_NOPREFIX,
SkinData, ControlIsActive(SkinData));
end;
end;
procedure TsEditButton.PrepareCache;
begin
SkinData.InitCacheBmp;
BitBlt(SkinData.FCacheBmp.Canvas.Handle, 0, 0, Width, Height, FOwner.SkinData.FCacheBmp.Canvas.Handle, Left + 2, Top + 2, SRCCOPY);
DrawGlyph;
SkinData.BGChanged := False;
end;
function TsCustomComboEdit.IsActive: boolean;
begin
Result := inherited IsActive or FButton.SkinData.FMouseAbove or ControlIsActive(FButton.SkinData);
end;
procedure TsCustomComboEdit.CMFocuseChanged(var Message: TCMFocusChanged);
begin
if DroppedDown and (Message.Sender <> Self) then begin
PopupWindowClose
end;
inherited;
end;
procedure TsCustomComboEdit.SetShowButton(const Value: boolean);
begin
if FShowButton <> Value then begin
FShowButton := Value;
Invalidate
end;
end;
procedure TsCustomComboEdit.CreateWnd;
begin
inherited;
SetEditRect
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -