📄 toolctrlseh.pas
字号:
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.State := State;
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);
if Flat then
begin
InflateRect(ARect,1,1);
Brush := CreateSolidBrush(ColorToRGB(ParentColor));
FrameRect(DC, ARect, Brush);
DeleteObject(Brush);
end;
end else
begin
BitmapInfo.Active := Active;
BitmapInfo.Enabled := Enabled;
IsClipRgn := Flat and not Active;
if IsClipRgn then
begin
DRect := ARect;
LPtoDP(DC,DRect,2);
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);
end;
end else if UseButtonsBitmapCache then
begin
BitmapInfo.Size := Point(ARect.Right-ARect.Left,ARect.Bottom-ARect.Top);
BitmapInfo.Pressed := DownButton<>0;
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
DrawOneButton(DC, Style, ARect, Enabled, Flat, Active, DownButton<>0, True);
if IsClipRgn then
begin
InflateRect(ARect,1,1);
if not UseButtonsBitmapCache then
begin
if r = 0
then SelectClipRgn(DC, 0)
else SelectClipRgn(DC, SaveRgn);
DeleteObject(SaveRgn);
end;
Brush := CreateSolidBrush(ColorToRGB(ParentColor));
FrameRect(DC, ARect, Brush);
DeleteObject(Brush);
end;
end;
end;
function GetDefaultFlatButtonWidth:Integer;
var
DC: HDC;
SysMetrics: TTextMetric;
begin
DC := GetDC(0);
GetTextMetrics(DC, SysMetrics);
ReleaseDC(0, DC);
Result := Round(SysMetrics.tmHeight / 3 * 2);
if Result mod 2 = 0 then Dec(Result);
if Result > GetSystemMetrics(SM_CXVSCROLL)
then Result := GetSystemMetrics(SM_CXVSCROLL);
end;
{$DEBUGINFO OFF}
function VarEquals(const V1, V2: Variant): Boolean;
var i:Integer;
begin
Result := not (VarIsArray(V1) xor VarIsArray(V2));
if not Result then Exit;
Result := False;
try
if VarIsArray(V1) and VarIsArray(V2) and
(VarArrayDimCount(V1) = VarArrayDimCount(V2)) and
(VarArrayLowBound(V1,1) = VarArrayLowBound(V2,1)) and
(VarArrayHighBound(V1,1) = VarArrayHighBound(V2,1))
then
for i := VarArrayLowBound(V1,1) to VarArrayHighBound(V1,1) do
begin
Result := V1[i] = V2[i];
if not Result then Exit;
end
else
Result := V1 = V2;
except
end;
end;
{$DEBUGINFO ON}
function TButtonsBitmapCache.GetButtonBitmap(ButtonBitmapInfo: TButtonBitmapInfoEh):TBitmap;
var i: Integer;
BitmapInfoBitmap: PButtonBitmapInfoBitmapEh;
begin
if ButtonBitmapInfo.Size.X < 0 then ButtonBitmapInfo.Size.X := 0;
if ButtonBitmapInfo.Size.Y < 0 then ButtonBitmapInfo.Size.Y := 0;
for i := 0 to Count-1 do
if CompareMem(@ButtonBitmapInfo,Items[i],SizeOf(TButtonBitmapInfoEh)) then
begin
Result := Items[i].Bitmap;
Exit;
end;
New(BitmapInfoBitmap);
Add(BitmapInfoBitmap);
BitmapInfoBitmap.BitmapInfo := ButtonBitmapInfo;
BitmapInfoBitmap.Bitmap := TBitmap.Create;
BitmapInfoBitmap.Bitmap.Width := ButtonBitmapInfo.Size.X;
BitmapInfoBitmap.Bitmap.Height := ButtonBitmapInfo.Size.Y;
case ButtonBitmapInfo.BitmapType of
bcsCheckboxEh:
DrawCheck(BitmapInfoBitmap.Bitmap.Canvas.Handle,
Rect(0,0,ButtonBitmapInfo.Size.X,ButtonBitmapInfo.Size.Y),
ButtonBitmapInfo.State,
True,
ButtonBitmapInfo.Flat
);
bcsEllipsisEh, bcsUpDownEh, bcsDropDownEh, bcsPlusEh, bcsMinusEh:
DrawOneButton(BitmapInfoBitmap.Bitmap.Canvas.Handle,ButtonBitmapInfo.BitmapType,
Rect(0,0,ButtonBitmapInfo.Size.X,ButtonBitmapInfo.Size.Y),
ButtonBitmapInfo.Enabled, ButtonBitmapInfo.Flat,
ButtonBitmapInfo.Active, ButtonBitmapInfo.Pressed,
ButtonBitmapInfo.DownDirect);
end;
Result := BitmapInfoBitmap.Bitmap;
end;
function TButtonsBitmapCache.Get(Index: Integer): PButtonBitmapInfoBitmapEh;
begin
Result := inherited Items[Index];
end;
{procedure TButtonsBitmapCache.Put(Index: Integer; const Value: PButtonBitmapInfoBitmapEh);
begin
inherited Items[Index] := Value;
end;}
procedure TButtonsBitmapCache.Clear;
var i: Integer;
begin
for i := 0 to Count-1 do
begin
Items[i].Bitmap.Free;
Dispose(Items[i]);
end;
inherited Clear;
end;
{ TEditButtonControlEh }
procedure TEditButtonControlEh.EditButtonDown(TopButton: Boolean; var AutoRepeat: Boolean);
var Handled: Boolean;
begin
if Assigned(FOnDown) then
FOnDown(Self,TopButton,AutoRepeat,Handled);
end;
procedure TEditButtonControlEh.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var AutoRepeat: Boolean;
// OldState: TButtonState;
begin
if Style = ebsUpDownEh
then AutoRepeat := True
else AutoRepeat := False;
// OldState := FState;
inherited MouseDown(Button, Shift, X, Y);
if (Button = mbLeft) then
begin
UpdateDownButtonNum(X, Y);
if FButtonNum > 0 then
begin
EditButtonDown(FButtonNum = 1,AutoRepeat);
if AutoRepeat then ResetTimer(InitRepeatPause);
end;
end;
end;
procedure TEditButtonControlEh.MouseMove(Shift: TShiftState; X,Y: Integer);
begin
inherited MouseMove(Shift, X, Y);
if MouseCapture and (FStyle = ebsUpDownEh) and (FState = bsDown) then
begin
if ( (FButtonNum = 2) and (Y < (Height div 2)) ) or
( (FButtonNum = 1) and (Y > (Height - Height div 2)) ) then
begin
FState := bsUp;
Invalidate;
end;
end;
end;
procedure TEditButtonControlEh.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if (FStyle = ebsUpDownEh) and (FState <> bsDown) then
FNoDoClick := True;
try
inherited MouseUp(Button, Shift, X, Y);
finally
FNoDoClick := False;
end;
UpdateDownButtonNum(X, Y);
if (FTimer <> nil) and FTimer.Enabled then
FTimer.Enabled := False;
end;
procedure TEditButtonControlEh.UpdateDownButtonNum(X, Y: Integer);
var OldButtonNum: Integer;
begin
OldButtonNum := FButtonNum;
if FState in [bsDown,bsExclusive] then
if FStyle = ebsUpDownEh then
begin
if Y < (Height div 2) then
FButtonNum := 1
else if Y > (Height - Height div 2) then
FButtonNum := 2
else
FButtonNum := 0;
end
else FButtonNum := 1
else
FButtonNum := 0;
if FButtonNum <> OldButtonNum then
Invalidate;
end;
procedure TEditButtonControlEh.Paint;
const
StyleFlags : array [TEditButtonStyleEh] of TDrawButtonControlStyleEh =
(bcsDropDownEh, bcsEllipsisEh, bcsUpDownEh, bcsUpDownEh, bcsPlusEh, bcsMinusEh);
DownStyles: array[Boolean] of Integer = (BDR_RAISEDINNER, BDR_SUNKENOUTER);
var Rgn, SaveRgn: HRgn;
r:Integer;
BRect: TRect;
IsClipRgn:Boolean;
AButtonNum: Integer;
begin
AButtonNum := FButtonNum;
if not (FState in [bsDown,bsExclusive]) then
AButtonNum := 0;
//else if AButtonNum = 0 then
// AButtonNum := 1;
if not (Style = ebsGlyphEh) then
PaintButtonControlEh(Canvas.Handle,Rect(0,0,Width,Height),
TWinControlCracker(Parent).Color,StyleFlags[Style],AButtonNum,
Flat, FActive, Enabled, cbUnchecked)
else
begin
IsClipRgn := Flat {and not FActive};
BRect := BoundsRect;
r := 0;
SaveRgn := 0;
if IsClipRgn then
begin
SaveRgn := CreateRectRgn(0,0,0,0);
r := GetClipRgn(Canvas.Handle, SaveRgn);
with BRect do
Rgn := CreateRectRgn(Left+1, Top+1, Right-1, Bottom-1);
SelectClipRgn(Canvas.Handle, Rgn);
DeleteObject(Rgn);
end;
inherited Paint;
if IsClipRgn then
begin
if r = 0 then
SelectClipRgn(Canvas.Handle, 0)
else
SelectClipRgn(Canvas.Handle, SaveRgn);
DeleteObject(SaveRgn);
OffsetRect(BRect,-Left,-Top);
if FActive then
DrawEdge(Canvas.Handle, BRect, DownStyles[FState in [bsDown, bsExclusive]],BF_RECT)
else
begin
Canvas.Brush.Color := TWinControlCracker(Parent).Color;
Canvas.FrameRect(BRect);
end;
end;
end;
end;
procedure TEditButtonControlEh.SetState(NewState:TButtonState; IsActive:Boolean; ButtonNum:Integer);
begin
if (FState <> NewState) or (IsActive <> FActive) or (ButtonNum <> FButtonNum) then
begin
FActive := IsActive;
FState := NewState;
FButtonNum := ButtonNum;
//Invalidate;
Repaint;
end;
end;
procedure TEditButtonControlEh.SetStyle(const Value: TEditButtonStyleEh);
begin
if FStyle <> Value then
begin
FStyle := Value;
Invalidate;
end;
end;
procedure TEditButtonControlEh.SetWidthNoNotify(AWidth: Integer);
begin
inherited Width := AWidth;
end;
procedure TEditButtonControlEh.SetActive(const Value: Boolean);
begin
if Active <> Value then
begin
FActive := Value;
Invalidate;
end;
end;
procedure TEditButtonControlEh.Click;
begin
if not FNoDoClick then
begin
inherited Click;
end;
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -