📄 toolctrlseh.pas
字号:
PlusInd := PWid div 2 - PHet div 2;
W := ElRect.Left + (ElRect.Right - ElRect.Left - PWid) div 2; //- Ord(not Active and Flat);
//if W * 2 + PWid > (ElRect.Right - ElRect.Left) then Dec(W);
Inc(W, Ord(Pressed));
H := ElRect.Top + (ElRect.Bottom - ElRect.Top - PHet) div 2 + Ord(Pressed);
if not Enabled then
begin
Inc(W); Inc(H);
Brush := GetSysColorBrush(COLOR_BTNHILIGHT);
SaveBrush := SelectObject(DC, Brush);
PatBlt(DC, W, H, PWid, PHet, PATCOPY);
if Plus then PatBlt(DC, W + PlusInd, H - PlusInd, PHet, PWid, PATCOPY);
Dec(W); Dec(H);
SelectObject(DC, SaveBrush);
Brush := GetSysColorBrush(COLOR_BTNSHADOW);
end else
Brush := GetSysColorBrush(COLOR_BTNTEXT);
SaveBrush := SelectObject(DC, Brush);
PatBlt(DC, W, H, PWid, PHet, PATCOPY);
if Plus then PatBlt(DC, W + PlusInd, H - PlusInd, PHet, PWid, PATCOPY);
SelectObject(DC, SaveBrush);
end;
procedure DrawDropDownButton(DC: HDC; ARect: TRect; Enabled, Flat, Active, Down: Boolean);
var
Flags: Integer;
{$IFDEF EH_LIB_7}
Details: TThemedElementDetails;
{$ENDIF}
// Rgn, SaveRgn: HRGN;
// r: Integer;
// IsClip: Boolean;
begin
{$IFDEF EH_LIB_7}
if ThemeServices.ThemesEnabled then
begin
if not Enabled then
Details := ThemeServices.GetElementDetails(tcDropDownButtonDisabled)
else
if Down then
Details := ThemeServices.GetElementDetails(tcDropDownButtonPressed)
else
if Active
then Details := ThemeServices.GetElementDetails(tcDropDownButtonHot)
else Details := ThemeServices.GetElementDetails(tcDropDownButtonNormal);
{ with Details do
GetThemeBackgroundRegion(ThemeServices.Theme[Element], DC, Part, State, ARect, Rgn);
IsClip := False;
SaveRgn := 0;
r := 0;
if Rgn <> 0 then
begin
IsClip := True;
SaveRgn := CreateRectRgn(0, 0, 0, 0);
r := GetClipRgn(DC, SaveRgn);
SelectClipRgn(DC, Rgn);
DeleteObject(Rgn);
end;}
ThemeServices.DrawElement(DC, Details, ARect);
{ if IsClip = True then
begin
if r = 0
then SelectClipRgn(DC, 0)
else SelectClipRgn(DC, SaveRgn);
DeleteObject(SaveRgn);
end;}
end else
{$ENDIF}
begin
Flags := DownFlags[Down] or FlatFlags[Flat] or EnabledFlags[Enabled];
DrawFrameControl(DC, ARect, DFC_SCROLL, Flags or DFCS_SCROLLCOMBOBOX);
end;
end;
procedure DrawUpDownButton(DC: HDC; ARect: TRect; Enabled, Flat, Active, Down, DownDirection: Boolean);
var
Flags: Integer;
{$IFDEF EH_LIB_7}
Details: TThemedElementDetails;
{$ENDIF}
begin
{$IFDEF EH_LIB_7}
if ThemeServices.ThemesEnabled then
begin
if DownDirection then
if not Enabled then
Details := ThemeServices.GetElementDetails(tsDownDisabled)
else
if Down then
Details := ThemeServices.GetElementDetails(tsDownPressed)
else
if Active
then Details := ThemeServices.GetElementDetails(tsDownHot)
else Details := ThemeServices.GetElementDetails(tsDownNormal)
else
if not Enabled then
Details := ThemeServices.GetElementDetails(tsUpDisabled)
else
if Down then
Details := ThemeServices.GetElementDetails(tsUpPressed)
else
if Active
then Details := ThemeServices.GetElementDetails(tsUpHot)
else Details := ThemeServices.GetElementDetails(tsUpNormal);
ThemeServices.DrawElement(DC, Details, ARect);
end else
{$ENDIF}
begin
Flags := DownFlags[Down] or FlatFlags[Flat] or EnabledFlags[Enabled];
DrawFrameControl(DC, ARect, DFC_SCROLL, Flags or IsDownFlags[DownDirection]);
end;
end;
procedure DrawOneButton(DC: HDC; Style: TDrawButtonControlStyleEh;
ARect: TRect; Enabled, Flat, Active, Down, DownDirection: Boolean);
var
Rgn, SaveRgn: HRgn;
r: Integer;
IsClipRgn: Boolean;
DRect: TRect;
// Brush: HBRUSH;
begin
DRect := ARect;
// LPtoDP(DC, DRect, 2);
WindowsLPtoDP(DC, DRect);
{$IFDEF EH_LIB_7}
IsClipRgn := Flat and Active and not ThemeServices.ThemesEnabled;
{$ELSE}
IsClipRgn := Flat and Active;
{$ENDIF}
r := 0; SaveRgn := 0;
if IsClipRgn then
begin
SaveRgn := CreateRectRgn(0, 0, 0, 0);
r := GetClipRgn(DC, SaveRgn);
with DRect do
Rgn := CreateRectRgn(Left + 1, Top + 1, Right - 1, Bottom - 1);
SelectClipRgn(DC, Rgn);
DeleteObject(Rgn);
end;
if Flat {$IFDEF EH_LIB_7} and not ThemeServices.ThemesEnabled {$ENDIF} then
if not Active {and not (Style=bcsUpDownEh)}
then InflateRect(ARect, 2, 2)
else InflateRect(ARect, 1, 1);
case Style of
bcsDropDownEh: DrawDropDownButton(DC, ARect, Enabled, Flat, Active, Down);
bcsEllipsisEh: DrawEllipsisButton(DC, ARect, Enabled, Active, Flat, Down);
bcsUpDownEh: DrawUpDownButton(DC, ARect, Enabled, Flat, Active, Down, DownDirection);
bcsMinusEh, bcsPlusEh: DrawPlusMinusButton(DC, ARect, Enabled, Active, Flat, Down, bcsPlusEh = Style);
end;
if Flat then
if not Active {and not (Style=bcsUpDownEh)}
then InflateRect(ARect, -2, -2)
else InflateRect(ARect, -1, -1);
if IsClipRgn then
begin
if r = 0
then SelectClipRgn(DC, 0)
else SelectClipRgn(DC, SaveRgn);
DeleteObject(SaveRgn);
if Down
then DrawEdge(DC, ARect, BDR_SUNKENOUTER, BF_RECT)
else DrawEdge(DC, ARect, BDR_RAISEDINNER, BF_RECT)
end;
end;
type
PPoints = ^TPoints;
TPoints = array[0..0] of TPoint;
TButtonBitmapInfoEh = record
Size: TPoint;
BitmapType: TDrawButtonControlStyleEh;
Flat: Boolean;
Pressed: Boolean;
Active: Boolean;
Enabled: Boolean;
DownDirect: Boolean;
CheckState: TCheckBoxState;
end;
function CompareButtonBitmapInfo(Info1, Info2: TButtonBitmapInfoEh): Boolean;
begin
Result := (Info1.Size.X = Info2.Size.X) and (Info1.Size.Y = Info2.Size.Y)
and (Info1.BitmapType = Info2.BitmapType)
and (Info1.Flat = Info2.Flat)
and (Info1.Pressed = Info2.Pressed)
and (Info1.Active = Info2.Active)
and (Info1.Enabled = Info2.Enabled)
and (Info1.DownDirect = Info2.DownDirect)
and (Info1.CheckState = Info2.CheckState);
end;
type
{ TButtonsBitmapCache }
TButtonBitmapInfoBitmapEh = class(TObject)
public
BitmapInfo: TButtonBitmapInfoEh;
Bitmap: TBitmap;
end;
// PButtonBitmapInfoBitmapEh = ^TButtonBitmapInfoBitmapEh;
TButtonsBitmapCache = class(TObjectList)
private
function Get(Index: Integer): TButtonBitmapInfoBitmapEh;
// procedure Put(Index: Integer; const Value: PButtonBitmapInfoBitmapEh);
public
constructor Create; overload;
procedure Clear; override;
function GetButtonBitmap(ButtonBitmapInfo: TButtonBitmapInfoEh): TBitmap;
property Items[Index: Integer]: TButtonBitmapInfoBitmapEh read Get {write Put}; default;
end;
var ButtonsBitmapCache: TButtonsBitmapCache;
procedure ClearButtonsBitmapCache;
begin
ButtonsBitmapCache.Clear;
end;
function RectSize(ARect: TRect): TSize;
begin
Result.cx := ARect.Right - ARect.Left;
Result.cy := ARect.Bottom - ARect.Top;
end;
procedure PaintButtonControlEh(DC: HDC; ARect: TRect; ParentColor: TColor;
Style: TDrawButtonControlStyleEh; DownButton: Integer;
Flat, Active, Enabled: Boolean; State: TCheckBoxState);
var
Rgn, SaveRgn: HRgn;
HalfRect, DRect: TRect;
ASize: TSize;
r: Integer;
Brush: HBRUSH;
IsClipRgn: Boolean;
BitmapInfo: TButtonBitmapInfoEh;
Bitmap: TBitmap;
begin
SaveRgn := 0; r := 0;
// FillChar(BitmapInfo, Sizeof(BitmapInfo), #0);
BitmapInfo.BitmapType := Style;
BitmapInfo.Flat := Flat;
if Style = bcsCheckboxEh then
begin
ASize := RectSize(ARect);
if ASize.cx < ASize.cy then
begin
ARect.Top := ARect.Top + (ASize.cy - ASize.cx) div 2;
ARect.Bottom := ARect.Bottom - (ASize.cy - ASize.cx) div 2 - (ASize.cy - ASize.cx) mod 2;
end else if ASize.cx > ASize.cy then
begin
ARect.Left := ARect.Left + (ASize.cx - ASize.cy) div 2;
ARect.Right := ARect.Right - (ASize.cx - ASize.cy) div 2 - (ASize.cx - ASize.cy) mod 2;
end;
if Flat then InflateRect(ARect, -1, -1);
if UseButtonsBitmapCache then
begin
BitmapInfo.Size := Point(ARect.Right - ARect.Left, ARect.Bottom - ARect.Top);
BitmapInfo.CheckState := State;
BitmapInfo.Pressed := DownButton <> 0;
BitmapInfo.Active := Active;
BitmapInfo.Enabled := Enabled;
Bitmap := ButtonsBitmapCache.GetButtonBitmap(BitmapInfo);
StretchBlt(DC, ARect.Left, ARect.Top, ARect.Right - ARect.Left,
ARect.Bottom - ARect.Top, Bitmap.Canvas.Handle, 0, 0,
Bitmap.Width, Bitmap.Height, cmSrcCopy);
end else
DrawCheck(DC, ARect, State, Enabled, Flat, DownButton <> 0, Active);
if Flat then
begin
InflateRect(ARect, 1, 1);
if Active then
DrawEdge(DC, ARect, BDR_SUNKENOUTER, BF_RECT)
else
begin
// FrameRect(DC, ARect, GetCurrentObject(DC, OBJ_BRUSH));
Brush := CreateSolidBrush(ColorToRGB(ParentColor));
FrameRect(DC, ARect, Brush);
DeleteObject(Brush);
end;
end;
end else
begin
BitmapInfo.Active := Active;
BitmapInfo.Enabled := Enabled;
{$IFDEF EH_LIB_7}
IsClipRgn := Flat and not Active and not ThemeServices.ThemesEnabled;
{$ELSE}
IsClipRgn := Flat and not Active;
{$ENDIF}
if IsClipRgn then
begin
DRect := ARect;
WindowsLPtoDP(DC, DRect);
InflateRect(ARect, -1, -1);
if not UseButtonsBitmapCache then
begin
SaveRgn := CreateRectRgn(0, 0, 0, 0);
r := GetClipRgn(DC, SaveRgn);
with DRect do
Rgn := CreateRectRgn(Left + 1, Top + 1, Right - 1, Bottom - 1);
SelectClipRgn(DC, Rgn);
DeleteObject(Rgn);
end;
end;
if Style = bcsUpDownEh then
begin
if IsClipRgn then InflateRect(ARect, 1, 1);
HalfRect := ARect;
with HalfRect do
Bottom := Top + (Bottom - Top) div 2;
if IsClipRgn then InflateRect(HalfRect, -1, -1);
if UseButtonsBitmapCache then
begin
BitmapInfo.Size := Point(HalfRect.Right - HalfRect.Left, HalfRect.Bottom - HalfRect.Top);
BitmapInfo.Pressed := DownButton = 1;
BitmapInfo.DownDirect := False;
Bitmap := ButtonsBitmapCache.GetButtonBitmap(BitmapInfo);
StretchBlt(DC, HalfRect.Left, HalfRect.Top, HalfRect.Right - HalfRect.Left,
HalfRect.Bottom - HalfRect.Top, Bitmap.Canvas.Handle, 0, 0,
Bitmap.Width, Bitmap.Height, cmSrcCopy);
end else
DrawOneButton(DC, Style, HalfRect, Enabled, Flat, Active, DownButton = 1, False);
if IsClipRgn then InflateRect(HalfRect, 1, 1);
HalfRect.Bottom := ARect.Bottom;
with HalfRect do
Top := Bottom - (Bottom - Top) div 2;
if IsClipRgn then InflateRect(HalfRect, -1, -1);
if UseButtonsBitmapCache then
begin
BitmapInfo.Size := Point(HalfRect.Right - HalfRect.Left, HalfRect.Bottom - HalfRect.Top);
BitmapInfo.Pressed := DownButton = 2;
BitmapInfo.DownDirect := True;
Bitmap := ButtonsBitmapCache.GetButtonBitmap(BitmapInfo);
StretchBlt(DC, HalfRect.Left, HalfRect.Top, HalfRect.Right - HalfRect.Left,
HalfRect.Bottom - HalfRect.Top, Bitmap.Canvas.Handle, 0, 0,
Bitmap.Width, Bitmap.Height, cmSrcCopy);
end else
DrawOneButton(DC, Style, HalfRect, Enabled, Flat, Active, DownButton = 2, True);
if IsClipRgn
then InflateRect(ARect, -1, -1);
if ((ARect.Bottom - ARect.Top) mod 2 = 1) or (IsClipRgn) then
begin
HalfRect := ARect;
HalfRect.Top := (HalfRect.Bottom + HalfRect.Top) div 2;
HalfRect.Bottom := HalfRect.Top;
if (ARect.Bottom - ARect.Top) mod 2 = 1 then Inc(HalfRect.Bottom);
if IsClipRgn then InflateRect(HalfRect, 0, 1);
Brush := CreateSolidBrush(ColorToRGB(ParentColor));
FillRect(DC, HalfRect, Brush);
DeleteObject(Brush);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -