📄 scombobox.pas
字号:
Canvas.Handle := 0;
// end
// end;
end;
end
else begin
BitBlt(DC, 0, 0, Width, FCommonData.FCacheBmp.Height, FCommonData.FCacheBmp.Canvas.Handle, 0, 0, SRCCOPY);
end;
{$IFDEF DYNAMICCACHE}
if Assigned(FCommonData.FCacheBmp) then FreeAndNil(FCommonData.FCacheBmp);
{$ENDIF}
end;
finally
if iDC = 0 then ReleaseDC(Handle, DC);
end;
end;
procedure TsCustomComboBox.PaintButton;
var
R : TRect;
Mode : integer;
c : TsColor;
glIndex : integer;
TmpBtn : TBitmap;
begin
if FDropDown then Mode := 2 else if ControlIsActive(FCommonData) then Mode := 1 else Mode := 0;
R := ButtonRect;
if FCommonData.SkinManager.ConstData.ComboBtnIndex > -1 then begin
TmpBtn := CreateBmpLike(FCommonData.FCacheBmp);
BitBlt(TmpBtn.Canvas.Handle, 0, 0, TmpBtn.Width, TmpBtn.Height, FCommonData.FCacheBmp.Canvas.Handle, 0, 0, SRCCOPY);
PaintItem(FCommonData.SkinManager.ConstData.ComboBtnIndex, s_ComboBtn, MakeCacheInfo(TmpBtn),
True, Mode, R, Point(0, 0), FCommonData.FCacheBmp, FCommonData.SkinManager, FCommonData.SkinManager.ConstData.ComboBtnBG, FCommonData.SkinManager.ConstData.ComboBtnBGHot);
FreeAndNil(TmpBtn);
end;
glIndex := FCommonData.SkinManager.ConstData.ComboGlyph;
if glIndex > -1 then begin
if ControlIsActive(FCommonData)
then c.C := FCommonData.SkinManager.gd[FCommonData.SkinIndex].HotColor
else c.C := FCommonData.SkinManager.gd[FCommonData.SkinIndex].Color;
DrawSkinGlyph(FCommonData.FCacheBmp,
Point(R.Left + (WidthOf(R) - WidthOf(FCommonData.SkinManager.ma[glIndex].R) div FCommonData.SkinManager.ma[glIndex].ImageCount) div 2,
(Height - ButtonHeight) div 2), Mode, 1, FCommonData.SkinManager.ma[FCommonData.SkinManager.ConstData.ComboGlyph]);
end;
end;
procedure TsCustomComboBox.PaintText;
var
R : TRect;
begin
FCommonData.FCacheBMP.Canvas.Font.Assign(Font);
R := Rect(4, 3, ButtonRect.Left, Height - 3);
if ItemIndex > -1 then begin
{$IFDEF TNTUNICODE}
FCommonData.FCacheBMP.Canvas.Font.Color := FCommonData.SkinManager.gd[FCommonData.SkinIndex].FontColor[1];
WideCanvasTextOut(FCommonData.FCacheBMP.Canvas, R.Left, R.Top, Text);
{$ELSE}
WriteTextEx(FCommonData.FCacheBMP.Canvas, PChar(Text), True, R, DT_NOPREFIX or DT_TOP or DT_SINGLELINE or DT_WORDBREAK or GetStringFlags(Self, Alignment),
FCommonData, ControlIsActive(FCommonData));
{$ENDIF}
end;
end;
procedure TsCustomComboBox.PrepareCache;
const
BordWidth = 3;
var
R : TRect;
State : TOwnerDrawState;
begin
FCommonData.InitCacheBmp;
if Style <> csSimple then begin
PaintItem(FCommonData,
GetParentCache(FCommonData), True,
integer(ControlIsActive(FCommonData)),
Rect(0, 0, Width, Height),
Point(Left, top), FCommonData.FCacheBmp, False);
if FShowButton then PaintButton;
if not IsOwnerDraw(Self) then begin
R := Rect(BordWidth, BordWidth, ButtonRect.Left, Height - BordWidth);
State := [odComboBoxEdit];
if (Focused or SkinData.FFocused) and (Style = csDropDownList) and Enabled
then State := State + [odFocused, odSelected];
DrawSkinItem(ItemIndex, R, State);
end;
end
else begin
FCommonData.FCacheBmp.Height := ItemHeight + 8;
PaintItem(FCommonData,
GetParentCache(FCommonData), True,
integer(ControlIsActive(FCommonData)),
Rect(0, 0, Width, FCommonData.FCacheBmp.Height),
Point(Left, top), FCommonData.FCacheBmp, False);
end;
if not Enabled then BmpDisabledKind(FCommonData.FCacheBmp, FDisabledKind, Parent, GetParentCache(FCommonData), Point(Left, Top));
FCommonData.BGChanged := False;
end;
procedure TsCustomComboBox.SetAlignment(const Value: TAlignment);
begin
if FAlignment <> Value then begin
FAlignment := Value;
FCommonData.Invalidate;
end;
end;
procedure TsCustomComboBox.SetButtonMargin(const Value: integer);
begin
if FButtonMargin <> Value then begin
FButtonMargin := Value;
FCommonData.Invalidate;
end;
end;
procedure TsCustomComboBox.SetDisabledKind(const Value: TsDisabledKind);
begin
if FDisabledKind <> Value then begin
FDisabledKind := Value;
FCommonData.Invalidate;
end;
end;
{$IFDEF TNTUNICODE}
procedure TsCustomComboBox.SetHint(const Value: WideString);
begin
TntControl_SetHint(Self, Value);
end;
procedure TsCustomComboBox.SetItems(const Value: TTntStrings);
begin
FItems.Assign(Value);
end;
{$ENDIF}
procedure TsCustomComboBox.SetReadOnly(const Value: boolean);
begin
if FReadOnly <> Value then begin
FReadOnly := Value;
end;
end;
{$IFDEF TNTUNICODE}
procedure TsCustomComboBox.SetSelLength(const Value: Integer);
begin
TntCombo_SetSelLength(Self, Value);
end;
procedure TsCustomComboBox.SetSelStart(const Value: Integer);
begin
TntCombo_SetSelStart(Self, Value);
end;
procedure TsCustomComboBox.SetSelText(const Value: WideString);
begin
TntCombo_SetSelText(Self, Value);
end;
procedure TsCustomComboBox.SetText(const Value: WideString);
begin
TntControl_SetText(Self, Value);
end;
procedure TsCustomComboBox.WMChar(var Message: TWMChar);
begin
TntCombo_AutoSearchKeyPress(Self, Items, Message, FFilter, FLastTime);
if Message.CharCode <> 0 then inherited;
end;
{$ENDIF}
procedure TsCustomComboBox.WMLButtonDblClk(var Message: TMessage);
begin
if FReadOnly then begin
SetFocus;
if Assigned(OnDblClick) then OnDblClick(Self);
end
else inherited;
end;
procedure TsCustomComboBox.WMLButtonDown(var Message: TWMLButtonDown);
begin
if FReadOnly then SetFocus else inherited
end;
procedure TsCustomComboBox.SetShowButton(const Value: boolean);
begin
if FShowButton <> Value then begin
FShowButton := Value;
FCommonData.Invalidate;
end;
end;
procedure TsCustomComboBox.WndProc(var Message: TMessage);
var
PS : TPaintStruct;
DC : hdc;
begin
{$IFDEF LOGGED}
AddToLog(Message);
{$ENDIF}
if Message.Msg = SM_ALPHACMD then case Message.WParamHi of
AC_CTRLHANDLED : begin Message.LParam := 1; Exit end; // AlphaSkins supported
AC_GETAPPLICATION : begin Message.Result := longint(Application); Exit end;
AC_REMOVESKIN : if LongWord(Message.LParam) = LongWord(SkinData.SkinManager) then begin
CommonWndProc(Message, FCommonData);
if not FCommonData.CustomColor then Color := clWindow;
if not FCommonData.CustomFont then Font.Color := clWindowText;
if Assigned(ListSW) then begin
FreeAndNil(ListSW);
lBoxHandle := 0;
end;
RecreateWnd;
exit
end;
AC_REFRESH : if (LongWord(Message.LParam) = LongWord(SkinData.SkinManager)) then begin
CommonWndProc(Message, FCommonData);
if FCommonData.Skinned then begin
if not FCommonData.CustomColor then Color := FCommonData.SkinManager.gd[FCommonData.SkinIndex].Color;
if not FCommonData.CustomFont
then Font.Color := ColorToRGB(FCommonData.SkinManager.gd[FCommonData.SkinIndex].FontColor[1]);
end;
Repaint;
exit
end;
AC_SETNEWSKIN : if (LongWord(Message.LParam) = LongWord(SkinData.SkinManager)) then begin
CommonWndProc(Message, FCommonData);
if ListSW <> nil then ListSW.acWndProc(Message);
exit
end;
AC_ENDPARENTUPDATE : if FCommonData.Updating then begin
FCommonData.Updating := False;
Repaint;
Exit
end;
end
else case Message.Msg of
WM_SYSCHAR, WM_SYSKEYDOWN, CN_SYSCHAR, CN_SYSKEYDOWN, WM_KEYDOWN, CN_KEYDOWN : case TWMKey(Message).CharCode of
38, 40 : if ReadOnly then Exit;
end;
WM_COMMAND, CN_COMMAND : if (Message.WParam = CBN_DROPDOWN) and ReadOnly then Exit;
end;
if not ControlIsReady(Self) or not FCommonData.Skinned then inherited else begin
case Message.Msg of
CN_COMMAND : case TWMCommand(Message).NotifyCode of
CBN_CLOSEUP : begin
FDropDown := False;
FCommonData.BGChanged := True;
OurPaintHandler(0);
end;
CBN_DROPDOWN : FDropDown := True;
end;
WM_SETFOCUS, CM_ENTER : if CanFocus then begin
FCommonData.FFocused := True;
FCommonData.FMouseAbove := False;
FCommonData.BGChanged := True;
inherited;
Exit
end;
WM_KILLFOCUS, CM_EXIT: begin
DroppedDown := False;
FCommonData.FFocused := False;
FCommonData.FMouseAbove := False;
FCommonData.BGChanged := True;
Repaint;
inherited;
Exit
end;
WM_NCPAINT : begin
OurPaintHandler(0);
Exit
end;
WM_PAINT : begin
// if Focused {and DroppedDown {v5.01} then inherited;
BeginPaint(Handle, PS);
if TWMPaint(Message).DC = 0 then DC := GetDC(Handle) else DC := TWMPaint(Message).DC;
OurPaintHandler(DC);
if TWMPaint(Message).DC = 0 then ReleaseDC(Handle, DC);
EndPaint(Handle, PS);
Exit
end;
CM_MOUSEENTER, CM_MOUSELEAVE : if not DroppedDown {v4.14} then {if gd[FCommonData.Skinindex].ReservedBoolean then v4} begin
FCommonData.FMouseAbove := Message.Msg = CM_MOUSEENTER;
FCommonData.BGChanged := True;
bFlag := True;
Repaint;
inherited;
bFlag := False;
exit;
end;
WM_COMMAND : if ReadOnly then Exit else begin
FDropDown := False;
OurPaintHandler(0);
end;
WM_CTLCOLORLISTBOX : if not (csLoading in ComponentState) and (lBoxHandle = 0) then begin
if Items.Count > DropDownCount then begin
lBoxHandle := hwnd(Message.LParam);
ListSW := TacComboListWnd.Create(lboxhandle, nil, SkinData.SkinManager, s_Edit);
if Style = csSimple then TacComboListWnd(ListSW).SimplyBox := True else TacComboListWnd(ListSW).SimplyBox := False;
end;
end;
WM_PRINT : begin
try
SkinData.Updating := False;
if SkinData.BGChanged then PrepareCache;
UpdateCorners(SkinData, 0);
try
// bw := (1 + integer(Ctl3d));
// BitBltBorder(DC, 0, 0, SkinData.FCacheBmp.Width, SkinData.FCacheBmp.Height, SkinData.FCacheBmp.Canvas.Handle, 0, 0, bw);
OurPaintHandler(TWMPaint(Message).DC);
finally
end;
Exit;
except
end;
end;
end;
CommonWndProc(Message, FCommonData);
inherited;
if Message.Msg = SM_ALPHACMD then case Message.WParamHi of
AC_DROPPEDDOWN : Message.Result := integer(DroppedDown);
end
else case Message.Msg of
CN_COMMAND : case TWMCommand(Message).NotifyCode of
CBN_CLOSEUP : begin
// DropDownCount := OldDropcountValue;
end;
end;
CB_SETCURSEL : begin FCommonData.BGChanged := True; Repaint end; // v4.43
CM_TEXTCHANGED : begin
FCommonData.BGChanged := True;
Repaint;
end;
CM_VISIBLECHANGED, CM_ENABLEDCHANGED, WM_SETFONT : begin
FCommonData.BGChanged := True;
OurPaintHandler(0);
end;
end;
end;
// Aligning of the bound label
if Assigned(BoundLabel) and Assigned(BoundLabel.FtheLabel) then case Message.Msg of
WM_SIZE, WM_WINDOWPOSCHANGED : begin BoundLabel.AlignLabel end;
CM_VISIBLECHANGED : begin BoundLabel.FtheLabel.Visible := Visible; BoundLabel.AlignLabel end;
CM_ENABLEDCHANGED : begin BoundLabel.FtheLabel.Enabled := Enabled; BoundLabel.AlignLabel end;
CM_BIDIMODECHANGED : begin BoundLabel.FtheLabel.BiDiMode := BiDiMode; BoundLabel.AlignLabel end;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -