📄 toolctrlseh.pas
字号:
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 Inc(Result);
if Result > GetSystemMetrics(SM_CXVSCROLL)
then Result := GetSystemMetrics(SM_CXVSCROLL);
end;
function DefaultEditButtonHeight(EditButtonWidth: Integer; Flat: Boolean): Integer;
begin
if Flat
then Result := Round(EditButtonWidth * 3 / 2)
else Result := EditButtonWidth;
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
begin
Result := not (VarIsEmpty(V1) xor VarIsEmpty(V2));
if not Result
then Exit
else Result := (V1 = V2);
end;
except
end;
end;
//{$DEBUGINFO ON}
{$IFNDEF EH_LIB_6}
function VarCompareValue(const A, B: Variant): TVariantRelationship;
const
CTruth: array [Boolean] of TVariantRelationship = (vrNotEqual, vrEqual);
var
LA, LB: TVarData;
begin
LA := TVarData(A);
LB := TVarData(B);
if LA.VType = varEmpty then
Result := CTruth[LB.VType = varEmpty]
else if LA.VType = varNull then
Result := CTruth[LB.VType = varNull]
else if LB.VType in [varEmpty, varNull] then
Result := vrNotEqual
else if A = B then
Result := vrEqual
else if A < B then
Result := vrLessThan
else
Result := vrGreaterThan;
end;
{$ENDIF}
function DBVarCompareOneValue(const A, B: Variant): TVariantRelationship;
begin
if VarIsNull(A) and VarIsNull(B) then
Result := vrEqual
else if VarIsNull(A) then
Result := vrLessThan
else if VarIsNull(B) then
Result := vrGreaterThan
else Result := VarCompareValue(A, B);
end;
function DBVarCompareValue(const A, B: Variant): TVariantRelationship;
var
i: Integer;
IsComparable: Boolean;
begin
Result := vrNotEqual;
IsComparable := not (VarIsArray(A) xor VarIsArray(B));
if not IsComparable then Exit;
if VarIsArray(A) and VarIsArray(B) and
(VarArrayDimCount(A) = VarArrayDimCount(B)) and
(VarArrayLowBound(A, 1) = VarArrayLowBound(B, 1)) and
(VarArrayHighBound(A, 1) = VarArrayHighBound(B, 1))
then
for i := VarArrayLowBound(A, 1) to VarArrayHighBound(A, 1) do
begin
Result := DBVarCompareOneValue(A[i], B[i]);
if Result <> vrEqual then Exit;
end
else
Result := DBVarCompareOneValue(A, B);
end;
function GetRGBColor(Value: TColor): DWORD;
begin
Result := ColorToRGB(Value);
case Result of
clNone: Result := CLR_NONE;
clDefault: Result := CLR_DEFAULT;
end;
end;
procedure DrawImage(DC: HDC; ARect: TRect; Images: TCustomImageList;
ImageIndex: Integer; Selected: Boolean);
const
ImageTypes: array[TImageType] of Longint = (0, ILD_MASK);
ImageSelTypes: array[Boolean] of Longint = (0, ILD_SELECTED);
var CheckedRect, AUnionRect: TRect;
OldRectRgn, RectRgn: HRGN;
r, x, y: Integer;
procedure DrawIm;
var ABlendColor: TColor;
begin
with Images do
if HandleAllocated then
begin
if Selected then ABlendColor := clHighlight
else ABlendColor := BlendColor;
ImageList_DrawEx(Handle, ImageIndex, DC, x, y, 0, 0,
GetRGBColor(BkColor), GetRGBColor(ABlendColor),
ImageTypes[ImageType] or ImageSelTypes[Selected]);
end;
end;
begin
with Images do
begin
x := (ARect.Right + ARect.Left - Images.Width) div 2;
y := (ARect.Bottom + ARect.Top - Images.Height) div 2;
CheckedRect := Rect(X, Y, X + Images.Width, Y + Images.Height);
UnionRect(AUnionRect, CheckedRect, ARect);
if EqualRect(AUnionRect, ARect) then // ARect containt image
DrawIm
else
begin // Need clip
OldRectRgn := CreateRectRgn(0, 0, 0, 0);
r := GetClipRgn(DC, OldRectRgn);
RectRgn := CreateRectRgn(ARect.Left, ARect.Top, ARect.Right, ARect.Bottom);
SelectClipRgn(DC, RectRgn);
DeleteObject(RectRgn);
DrawIm;
if r = 0
then SelectClipRgn(DC, 0)
else SelectClipRgn(DC, OldRectRgn);
DeleteObject(OldRectRgn);
end;
end;
end;
function AlignDropDownWindowRect(MasterAbsRect: TRect; DropDownWin: TWinControl; Align: TDropDownAlign): TPoint;
var
P: TPoint;
Y: Integer;
WorkArea: TRect;
MonInfo: TMonitorInfo;
begin
P := MasterAbsRect.TopLeft;
Y := P.Y + (MasterAbsRect.Bottom - MasterAbsRect.Top);
MonInfo.cbSize := SizeOf(MonInfo);
{$IFDEF CIL}
GetMonitorInfo(MonitorFromRect(MasterAbsRect, MONITOR_DEFAULTTONEAREST), MonInfo);
{$ELSE}
GetMonitorInfo(MonitorFromRect(@MasterAbsRect, MONITOR_DEFAULTTONEAREST), @MonInfo);
{$ENDIF}
WorkArea := MonInfo.rcWork;
// SystemParametersInfo(SPI_GETWORKAREA, 0, Pointer(@WorkArea), 0);
if ((Y + DropDownWin.Height > WorkArea.Bottom) and (P.Y - DropDownWin.Height >= WorkArea.Top)) or
((P.Y - DropDownWin.Height < WorkArea.Top) and (WorkArea.Bottom - Y < P.Y - WorkArea.Top))
then
begin
if P.Y - DropDownWin.Height < WorkArea.Top then
DropDownWin.Height := P.Y - WorkArea.Top;
Y := P.Y - DropDownWin.Height;
DropDownWin.Perform(cm_SetSizeGripChangePosition, Ord(sgcpToTop), 0);
end else
begin
if Y + DropDownWin.Height > WorkArea.Bottom then
DropDownWin.Height := WorkArea.Bottom - Y;
DropDownWin.Perform(cm_SetSizeGripChangePosition, Ord(sgcpToBottom), 0);
end;
case Align of
daRight: Dec(P.X, DropDownWin.Width - (MasterAbsRect.Right - MasterAbsRect.Left));
daCenter: Dec(P.X, (DropDownWin.Width - (MasterAbsRect.Right - MasterAbsRect.Left)) div 2);
end;
if (DropDownWin.Width > WorkArea.Right - WorkArea.Left) then
DropDownWin.Width := WorkArea.Right - WorkArea.Left;
if (P.X + DropDownWin.Width > WorkArea.Right) then
begin
P.X := WorkArea.Right - DropDownWin.Width;
DropDownWin.Perform(cm_SetSizeGripChangePosition, Ord(sgcpToLeft), 0);
end
else if P.X < WorkArea.Left then
begin
P.X := WorkArea.Left;
DropDownWin.Perform(cm_SetSizeGripChangePosition, Ord(sgcpToRight), 0);
end else if Align = daRight then
DropDownWin.Perform(cm_SetSizeGripChangePosition, Ord(sgcpToLeft), 0)
else
DropDownWin.Perform(cm_SetSizeGripChangePosition, Ord(sgcpToRight), 0);
Result := Point(P.X, Y);
end;
function AlignDropDownWindow(MasterWin, DropDownWin: TWinControl; Align: TDropDownAlign): TPoint;
var
MasterAbsRect: TRect;
begin
MasterAbsRect.TopLeft := MasterWin.Parent.ClientToScreen(Point(MasterWin.Left, MasterWin.Top));
MasterAbsRect.Bottom := MasterAbsRect.Top + MasterWin.Height;
MasterAbsRect.Right := MasterAbsRect.Left + MasterWin.Width;
Result := AlignDropDownWindowRect(MasterAbsRect, DropDownWin, Align);
end;
type
TIntArray = array[0..16384] of Integer;
PIntArray = ^TIntArray;
procedure DrawDotLine(Canvas: TCanvas; FromPoint: TPoint; ALength: Integer;
Along: Boolean; BackDot: Boolean);
var
Points: array of TPoint;
StrokeList: array of DWORD;
DotWidth, DotCount, I: Integer;
begin
// Canvas.Pen.Style
if Along then
begin
if ((FromPoint.X mod 2) <> (FromPoint.Y mod 2)) xor BackDot then
begin
Inc(FromPoint.X);
Dec(ALength);
end;
end else
begin
if ((FromPoint.X mod 2) <> (FromPoint.Y mod 2)) xor BackDot then
begin
Inc(FromPoint.Y);
Dec(ALength);
end;
end;
DotWidth := Canvas.Pen.Width;
DotCount := ALength div (2 * DotWidth);
if DotCount < 0 then Exit;
if ALength mod 2 <> 0 then
Inc(DotCount);
SetLength(Points, DotCount * 2); // two points per stroke
SetLength(StrokeList, DotCount);
for I := 0 to DotCount - 1 do
StrokeList[I] := 2;
if Along then
for I := 0 to DotCount - 1 do
begin
Points[I * 2] := Point(FromPoint.X, FromPoint.Y);
Points[I * 2 + 1] := Point(FromPoint.X + 1, FromPoint.Y);
Inc(FromPoint.X, (2 * DotWidth));
end
else
for I := 0 to DotCount - 1 do
begin
Points[I * 2] := Point(FromPoint.X, FromPoint.Y);
Points[I * 2 + 1] := Point(FromPoint.X, FromPoint.Y + 1);
Inc(FromPoint.Y, (2 * DotWidth));
end;
{$IFDEF CIL}
PolyPolyLine(Canvas.Handle, Points, StrokeList, DotCount);
{$ELSE}
PolyPolyLine(Canvas.Handle, PIntArray(Points)^, PIntArray(StrokeList)^, DotCount);
{$ENDIF}
end;
procedure DrawTreeElement(Canvas: TCanvas; ARect: TRect;
TreeElement: TTreeElementEh; BackDot: Boolean; ScaleX, ScaleY: Double;
RightToLeft: Boolean);
var
ABoxRect: TRect;
// ABoxRectWidth: Integer;
ACenter: TPoint;
X1, X2, X4, Y1, Y2, Y4: Integer;
begin
ACenter.X := (ARect.Right + ARect.Left) div 2;
ACenter.Y := (ARect.Bottom + ARect.Top) div 2;
X1 := Trunc(ScaleX);
X2 := Trunc(ScaleX*2);
X4 := Trunc(ScaleX*4);
Y1 := Trunc(ScaleY);
Y2 := Trunc(ScaleY*2);
Y4 := Trunc(ScaleY*4);
with Canvas do
begin
ABoxRect := Rect(ACenter.X-X4, ACenter.Y-Y4, ACenter.X+X4+1, ACenter.Y+Y4+1);
// ABoxRectWidth := ABoxRect.Right - ABoxRect.Left;
if TreeElement in [tehMinusUpDown .. tehPlusDown] then
begin
Brush.Color := clWindow;
Pen.Color := clBtnShadow;
Pen.Style := psSolid;
if RightToLeft
then Rectangle(ABoxRect.Left-1, ABoxRect.Top, ABoxRect.Right-1, ABoxRect.Bottom)
else Rectangle(ABoxRect.Left, ABoxRect.Top, ABoxRect.Right, ABoxRect.Bottom);
Pen.Color := clWindowText;
MoveTo(ABoxRect.Left + X2, ACenter.Y);
LineTo(ABoxRect.Right - X2, ACenter.Y);
if TreeElement in [tehPlusUpDown, tehPlusUp, tehPlusDown] then
begin
MoveTo(ACenter.X, ABoxRect.Top + Y2);
LineTo(ACenter.X, ABoxRect.Bottom - Y2);
end;
Pen.Color := clBtnShadow;
DrawDotLine(Canvas, Point(ABoxRect.Right + X1, ACenter.Y),
(ARect.Right - ABoxRect.Right), True, False);
if Tre
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -