📄 dxbarcustform.pas
字号:
begin
R := ClientRect;
GetCursorPos(P);
P := ScreenToClient(P);
if PtInRect(R, P) and GetParentForm(Self).Active or FDown then
DrawEdge(Handle, R, Borders[FDown], BF_RECT);
InflateRect(R, -1, -1);
if FDown then OffsetRect(R, 1, 1);
Brush.Style := bsClear;
Font := Self.Font;
Font.Color := clBtnText;
cxDrawText(Handle, Caption, R, DT_CENTER or DT_NOCLIP or DT_SINGLELINE or DT_VCENTER);
Brush.Style := bsSolid;
end;
end;
{ TdxBarCustomizingFormPainter }
class function TdxBarCustomizingFormPainter.BrushColors(Selected: Boolean; AItem: TdxBarItem): TColor;
begin
if Selected then
Result := clHighlight
else
Result := clBtnFace;
end;
class procedure TdxBarCustomizingFormPainter.DrawButtonOrSubItem(ACanvas: TCanvas;
ARect: TRect; AItem: TdxBarItem; ACaption: string; Selected: Boolean);
var
R: TRect;
S: string;
IsGlyph: Boolean;
W, H: Integer;
FullImageRect: TRect;
begin
R := ARect;
with TdxBarItemAccess(AItem) do
IsGlyph := not Glyph.Empty or CurImageIndexLinked;
with ACanvas, R do
begin
Right := Left + dxBarButtonWidth;
Brush.Color := BrushColors(not IsGlyph and Selected, AItem);
FillRect(R);
Pen.Color := Brush.Color;
MoveTo(Right, Top);
LineTo(Right, Bottom);
if IsGlyph then
begin
if Selected then
DrawEdge(Handle, R, BDR_RAISEDINNER, BF_RECT);
if AItem.Glyph.Empty then
with AItem.GetCurImages do
begin
W := Width;
H := Height;
end
else
with AItem.Glyph do
begin
W := Width;
H := Height;
end;
with R do
R := Bounds((Left + Right - W) div 2, (Top + Bottom - H) div 2, W, H);
FullImageRect := R;
TransparentDraw(Handle, Brush.Handle, FullImageRect, R, AItem.Glyph,
AItem.GetCurImages, AItem.ImageIndex, AItem.BarManager.ImageListBkColor,
True, False, False{Flat}, Selected, False, False, False{Shadow}, False{Faded},
AItem.BarManager.ImageOptions.UseLeftBottomPixelAsTransparent);
end;
Font.Color := FontColors(Selected);
Brush.Color := BrushColors(Selected, AItem);
R := ARect;
if (AItem is TdxBarButton) and (TdxBarButton(AItem).ButtonStyle = bsDropDown) then
Dec(R.Right, 4 + 4 + 5);
Inc(Left, dxBarButtonWidth + 1);
FillRect(R);
Inc(Left, 2);
S := ACaption;
if (AItem is TCustomdxBarContainerItem) and
TCustomdxBarContainerItemAccess(AItem).HideWhenRun then
S := '(' + ACaption + ')';
cxDrawText(Handle, S, R, DT_NOCLIP or DT_NOPREFIX or DT_SINGLELINE or DT_LEFT or DT_VCENTER);
if (AItem is TdxBarButton) and (TdxBarButton(AItem).ButtonStyle = bsDropDown) then
begin
R.Left := R.Right;
R.Right := ARect.Right;
if Selected then
begin
DrawEdge(Handle, R, BDR_RAISEDINNER, BF_RECT);
InflateRect(R, -1, -1);
end
else
begin
Dec(R.Left);
DrawEdge(Handle, R, EDGE_ETCHED, BF_LEFT);
Inc(R.Left, 2);
end;
Brush.Color := BrushColors(False, AItem);
FillRect(R);
Font.Color := FontColors(False);
DrawSubItemArrow(ACanvas, ARect.Right - (4 + 5), ARect.Top + (dxBarButtonHeight - 7) div 2, False);
end
else
if (AItem is TCustomdxBarSubItem) and not (AItem is TCustomdxBarContainerItem) or
(AItem is TCustomdxBarContainerItem) and not TCustomdxBarContainerItemAccess(AItem).HideWhenRun then
DrawSubItemArrow(ACanvas, ARect.Right - (4 + 5), ARect.Top + (dxBarButtonHeight - 7) div 2, False);
end;
end;
class procedure TdxBarCustomizingFormPainter.DrawComboBoxButton(
ACanvas: TCanvas; AItem: TdxBarItem; ARect: TRect; ASelected: Boolean);
begin
with ACanvas do
begin
Inc(ARect.Left);
if ASelected then
begin
DrawEdge(Handle, ARect, BDR_RAISEDINNER, BF_RECT);
Pen.Color := BrushColors(False, AItem);
end
else
begin
Brush.Color := clBtnHighlight;
FrameRect(ARect);
Pen.Color := Brush.Color;
end;
MoveTo(ARect.Left - 1, ARect.Top);
LineTo(ARect.Left - 1, ARect.Bottom);
InflateRect(ARect, -1, -1);
Brush.Color := BrushColors(False, AItem);
FillRect(ARect);
Pen.Color := clBtnText;
InflateRect(ARect, 2, 0);
DrawItemArrow(Handle, ARect, adDown, True, False, False{Flat});
end;
end;
class procedure TdxBarCustomizingFormPainter.DrawEdit(ACanvas: TCanvas;
ARect: TRect; AItem: TdxCustomBarEdit; Selected, ADrawArrowButton: Boolean);
begin
DrawCaption(ACanvas, ARect, AItem, Selected);
DrawEditEdge(ACanvas, ARect, AItem, Selected);
DrawEditContent(ACanvas, ARect, AItem, Selected, ADrawArrowButton);
end;
class procedure TdxBarCustomizingFormPainter.DrawFocusedRect(ACanvas: TCanvas;
ARect: TRect; AItem: TdxBarItem);
begin
SetTextColor(ACanvas.Handle, ColorToRGB(FontColors(True)));
SetBkColor(ACanvas.Handle, ColorToRGB(BrushColors(True, AItem)));
Windows.DrawFocusRect(ACanvas.Handle, ARect);
end;
class function TdxBarCustomizingFormPainter.FontColors(Selected: Boolean): TColor;
begin
if Selected then
Result := clHighlightText
else
Result := clBtnText;
end;
class function TdxBarCustomizingFormPainter.GetButtonColor(
AItem: TdxBarItem; ASelected: Boolean): Integer;
begin
Result := clBtnFace;
end;
class function TdxBarCustomizingFormPainter.GetComboBoxButtonWidth: Integer;
begin
Result := dxBarComboBoxArrowWidth + 1;
end;
class procedure TdxBarCustomizingFormPainter.DrawCaption(ACanvas: TCanvas;
var AItemRect: TRect; AItem: TdxCustomBarEdit; ASelected: Boolean);
var
ATextRect: TRect;
AText: string;
begin
AText := GetTextOf(AItem.Caption);
ATextRect := AItemRect;
ATextRect.Right := ACanvas.TextWidth(AText);
InternalDrawCaption(ACanvas, ATextRect, AText, AItem, ASelected);
AItemRect.Left := ATextRect.Right;
end;
class procedure TdxBarCustomizingFormPainter.DrawEditEdge(ACanvas: TCanvas;
var AItemRect: TRect; AItem: TdxCustomBarEdit; ASelected: Boolean);
begin
if ASelected then
DrawEdge(ACanvas.Handle, AItemRect, BDR_SUNKENOUTER, BF_RECT)
else
ACanvas.FrameRect(AItemRect);
InflateRect(AItemRect, -1, -1);
ACanvas.FrameRect(AItemRect);
InflateRect(AItemRect, -1, -1);
end;
class procedure TdxBarCustomizingFormPainter.DrawEditContent(ACanvas: TCanvas;
AItemRect: TRect; AItem: TdxCustomBarEdit; ASelected, ADrawArrowButton: Boolean);
begin
if ADrawArrowButton then
begin
Dec(AItemRect.Right, GetComboBoxButtonWidth);
DrawComboBoxButton(ACanvas, AItem,
Rect(AItemRect.Right, AItemRect.Top, AItemRect.Right + GetComboBoxButtonWidth, AItemRect.Bottom), ASelected);
end;
InternalDrawEditContent(ACanvas, AItemRect, AItem, ASelected);
end;
class procedure TdxBarCustomizingFormPainter.DrawSubItemArrow(ACanvas: TCanvas;
X, Y: Integer; ASelected: Boolean);
begin
with ACanvas do
begin
if ASelected and IsHighContrastWhite then
Pen.Color := clWhite
else
Pen.Color := Font.Color;
Brush.Color := Pen.Color;
Polygon([Point(X, Y), Point(X, Y + 6), Point(X + 3, Y + 3)]);
end;
end;
class procedure TdxBarCustomizingFormPainter.InternalDrawCaption(ACanvas: TCanvas;
var ATextRect: TRect; const AText: string; AItem: TdxCustomBarEdit; ASelected: Boolean);
const
ATextOffset = 2;
var
ARect: TRect;
begin
ARect := ATextRect;
ACanvas.Brush.Color := BrushColors(ASelected, AItem);
Inc(ARect.Right, ATextOffset + 1);
ACanvas.FillRect(ARect);
Inc(ARect.Left, ATextOffset);
ACanvas.Font.Color := FontColors(ASelected);
cxDrawText(ACanvas.Handle, AText, ARect, DT_NOCLIP or DT_NOPREFIX or DT_SINGLELINE or DT_LEFT or DT_VCENTER);
ACanvas.Brush.Color := BrushColors(False, AItem);
ARect.Left := ARect.Right;
Inc(ARect.Right, 4);
ACanvas.FillRect(ARect);
ATextRect.Right := ARect.Right;
end;
class procedure TdxBarCustomizingFormPainter.InternalDrawEditContent(ACanvas: TCanvas;
AItemRect: TRect; AItem: TdxCustomBarEdit; ASelected: Boolean);
begin
ACanvas.Font.Color := FontColors(False);
TdxCustomBarEditAccess(AItem).DrawCustomizingImageContent(ACanvas, AItemRect, ASelected);
end;
{ TdxBarCustomizingFormStandardPainter }
class procedure TdxBarCustomizingFormStandardPainter.DrawFocusedRect(ACanvas: TCanvas;
ARect: TRect; AItem: TdxBarItem);
begin
InflateRect(ARect, -2, -2);
inherited DrawFocusedRect(ACanvas, ARect, AItem);
end;
{ TdxBarCustomizingFormFlatPainter }
class function TdxBarCustomizingFormFlatPainter.BrushColors(Selected: Boolean; AItem: TdxBarItem): TColor;
begin
if Selected then
Result := TdxBarManagerAccess(AItem.BarManager).FlatToolbarsSelColor
else
Result := clWindow;
end;
class procedure TdxBarCustomizingFormFlatPainter.DrawButtonOrSubItem(ACanvas: TCanvas;
ARect: TRect; AItem: TdxBarItem; ACaption: string; Selected: Boolean);
var
R: TRect;
S: string;
IsGlyph: Boolean;
W, H: Integer;
FullImageRect: TRect;
begin
R := ARect;
with TdxBarItemAccess(AItem) do
IsGlyph := not Glyph.Empty or CurImageIndexLinked;
with ACanvas, R do
begin
Brush.Color := BrushColors(Selected, AItem);
if Selected then
begin
FillRect(R);
Right := Left + Bottom - Top;
end
else
begin
Inc(Left, Bottom - Top);
FillRect(R);
Right := Left;
Left := ARect.Left;
Brush.Color := clBtnFace;
FillRect(R);
end;
if IsGlyph then
begin
if AItem.Glyph.Empty then
with AItem.GetCurImages do
begin
W := Width;
H := Height;
end
else
with AItem.Glyph do
begin
W := Width;
H := Height;
end;
with R do
R := Bounds((Left + Right - W) div 2, (Top + Bottom - H) div 2, W, H);
FullImageRect := R;
InflateRect(FullImageRect, 1, 1);
TransparentDraw(Handle, Brush.Handle, FullImageRect, R, AItem.Glyph,
AItem.GetCurImages, AItem.ImageIndex, AItem.BarManager.ImageListBkColor,
True, False, True{Flat}, Selected, False, False, True{Shadow}, False{Faded},
AItem.BarManager.ImageOptions.UseLeftBottomPixelAsTransparent);
end;
Font.Color := FontColors(Selected);
Brush.Color := BrushColors(Selected, AItem);
R := ARect;
if (AItem is TdxBarButton) and (TdxBarButton(AItem).ButtonStyle = bsDropDown) then
Dec(R.Right, 4 + 4 + 5);
Left := Bottom - Top + 10;
S := ACaption;
if (AItem is TCustomdxBarContainerItem) and
TCustomdxBarContainerItemAccess(AItem).HideWhenRun then
S := '(' + ACaption + ')';
cxDrawText(Handle, S, R, DT_NOCLIP or DT_NOPREFIX or DT_SINGLELINE or DT_LEFT or DT_VCENTER);
if (AItem is TdxBarButton) and (TdxBarButton(AItem).ButtonStyle = bsDropDown) then
begin
R.Left := R.Right;
R.Right := ARect.Right;
if Selected then
FrameFlatSelRect(Handle, R)
else
Windows.FrameRect(Handle, R, GetSysColorBrush(COLOR_BTNSHADOW));
InflateRect(R, -1, -1);
Brush.Color := BrushColors(Selected, AItem);
FillRect(R);
Font.Color := FontColors(False);
DrawSubItemArrow(ACanvas, ARect.Right - (4 + 5), ARect.Top + (dxBarButtonHeight - 7) div 2, Selected);
end
else
if (AItem is TCustomdxBarSubItem) and not (AItem is TCustomdxBarContainerItem) or
(AItem is TCustomdxBarContainerItem) and not TCustomdxBarContainerItemAccess(AItem).HideWhenRun then
DrawSubItemArrow(ACanvas, ARect.Right - (4 + 5), ARect.Top + (dxBarButtonHeight - 7) div 2, Selected);
if Selected then
FrameFlatSelRect(Handle, ARect);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -