cxgroupbox.pas
来自「胜天进销存源码,国产优秀的进销存」· PAS 代码 · 共 1,801 行 · 第 1/5 页
PAS
1,801 行
begin
with AEditViewInfo do
begin
TextRect := cxRectContent(CaptionRect, ABorderSize);
if Edit.Alignment in [alTopRight, alBottomRight] then
TextRect.Left := TextRect.Right - ATextWidth;
if Edit.Alignment in [alTopCenter, alBottomCenter] then
TextRect.Left := (TextRect.Left + TextRect.Right - ATextWidth) div 2;
if Edit.Alignment in [alLeftTop, alRightTop] then
TextRect.Bottom := TextRect.Top + ATextWidth;
if Edit.Alignment in [alLeftBottom, alRightBottom] then
TextRect.Top := TextRect.Bottom - ATextWidth;
if Edit.Alignment in [alLeftCenter, alRightCenter] then
begin
TextRect.Top := (TextRect.Bottom + TextRect.Top - ATextWidth) div 2;
TextRect.Bottom := TextRect.Top + ATextWidth;
end;
end;
end;
var
ACaptionPos: TcxGroupBoxCaptionPosition;
ARect: TRect;
ATextSize: TSize;
begin
if Edit.IsPanelStyle then
begin
AEditViewInfo.CalcBoundsForPanel;
Exit;
end;
if Style.LookAndFeel.SkinPainter = nil then
begin
AEditViewInfo.CaptionRect := GetCaptionRect(ACanvas);
AEditViewInfo.TextRect := AEditViewInfo.CaptionRect;
end
else
with AEditViewInfo do
begin
ARect := GetCaptionRectIndent;
BorderRect := ControlRect;
CaptionRect := BorderRect;
Edit.AdjustCanvasFontSettings(ACanvas);
ATextSize := ACanvas.TextExtent(Edit.FVisibleCaption);
ATextSize.cy := Max(ATextSize.cy, ACanvas.TextHeight('Qq'));
ACaptionPos := cxGroupBoxAlignment2GroupBoxCaption(Edit.Alignment);
CalculateCaptionRect(CaptionRect, ARect, ATextSize, ACaptionPos);
CalculateBorderRect(BorderRect, ARect, ACaptionPos);
CalculateTextRect(Style.LookAndFeel.SkinPainter.GroupBoxBorderSize(True,
ACaptionPos), ATextSize.cx);
AdjustCaptionRect(ACaptionPos);
end;
end;
{ TcxButtonGroupViewInfo }
procedure TcxButtonGroupViewInfo.DrawEditButton(ACanvas: TcxCanvas;
AButtonVisibleIndex: Integer);
var
AButtonViewInfo: TcxGroupBoxButtonViewInfo;
AGlyphRect: TRect;
begin
AButtonViewInfo := TcxGroupBoxButtonViewInfo(ButtonsInfo[AButtonVisibleIndex]);
AGlyphRect := AButtonViewInfo.GetGlyphRect(ACanvas, GetGlyphSize,
Alignment, IsDBEditPaintCopyDrawing);
if not IsDBEditPaintCopyDrawing then
DrawEditBackground(ACanvas, AButtonViewInfo.Bounds, AGlyphRect,
IsButtonGlypthTransparent(AButtonViewInfo));
DrawButtonGlyph(ACanvas, AButtonViewInfo, AGlyphRect);
DrawButtonCaption(ACanvas, AButtonViewInfo, AGlyphRect);
end;
function TcxButtonGroupViewInfo.GetGlyphSize: TSize;
begin
Result := GlyphSize;
end;
{ TcxButtonGroupViewData }
procedure TcxButtonGroupViewData.Calculate(ACanvas: TcxCanvas;
const ABounds: TRect; const P: TPoint; Button: TcxMouseButton;
Shift: TShiftState; AViewInfo: TcxCustomEditViewInfo;
AIsMouseEvent: Boolean);
begin
inherited Calculate(ACanvas, ABounds, P, Button, Shift, AViewInfo,
AIsMouseEvent);
with TcxButtonGroupViewInfo(AViewInfo) do
begin
DrawTextFlags := GetDrawTextFlags;
CaptionExtent := GetCaptionRectExtent;
end;
end;
procedure TcxButtonGroupViewData.CalculateButtonsViewInfo(ACanvas: TcxCanvas;
const ABounds: TRect; const P: TPoint; Button: TcxMouseButton;
Shift: TShiftState; AViewInfo: TcxCustomEditViewInfo; AIsMouseEvent: Boolean);
procedure CalculateButtonStates;
var
AButtonsCount, APrevPressedButton, I: Integer;
AButtonViewInfo: TcxGroupBoxButtonViewInfo;
ACapturePressing, AHoldPressing, AIsButtonPressed, AMouseButtonPressing: Boolean;
begin
AButtonsCount := Properties.Items.Count;
AViewInfo.IsButtonReallyPressed := False;
if AIsMouseEvent then
APrevPressedButton := AViewInfo.PressedButton
else
APrevPressedButton := -1;
AViewInfo.PressedButton := -1;
AViewInfo.SelectedButton := -1;
for I := 0 to AButtonsCount - 1 do
begin
AButtonViewInfo := TcxGroupBoxButtonViewInfo(AViewInfo.ButtonsInfo[I]);
AButtonViewInfo.Index := I;
AButtonViewInfo.Data.NativeStyle := IsButtonNativeStyle(Style.LookAndFeel);
AButtonViewInfo.Data.Transparent := (Self.Style.ButtonTransparency = ebtAlways) or
(Self.Style.ButtonTransparency = ebtInactive) and not Selected;
AButtonViewInfo.Data.BackgroundColor := AViewInfo.BackgroundColor;
AIsButtonPressed := IsButtonPressed(AViewInfo, I);
with AButtonViewInfo do
begin
if not Enabled then
Data.State := ebsDisabled
else
if AIsButtonPressed or (not IsDesigning and PtInRect(AButtonViewInfo.Bounds, P)) then
begin
ACapturePressing := (Button = cxmbNone) and (ButtonToShift(mbLeft) *
Shift <> []) and (Data.State = ebsNormal) and (GetCaptureButtonVisibleIndex =
I);
AMouseButtonPressing := (Button = ButtonTocxButton(mbLeft)) and
((Shift = ButtonToShift(mbLeft)) or
(Shift = ButtonToShift(mbLeft) + [ssDouble]));
AHoldPressing := (Data.State = ebsPressed) and (Shift * ButtonToShift(mbLeft) <> []);
if AIsButtonPressed or AMouseButtonPressing or AHoldPressing or
ACapturePressing then
AViewInfo.IsButtonReallyPressed := True;
if not AIsButtonPressed and (Shift = []) and not ACapturePressing then
begin
Data.State := ebsSelected;
AViewInfo.SelectedButton := I;
end
else
if (AIsButtonPressed or ACapturePressing and CanPressButton(AViewInfo, I) or ((Shift = [ssLeft]) or (Shift = [ssLeft, ssDouble])) and
((Button = cxmbLeft) and CanPressButton(AViewInfo, I) or
(APrevPressedButton = I))) or AHoldPressing then
begin
Data.State := ebsPressed;
AViewInfo.PressedButton := I;
end
else
Data.State := ebsNormal;
end
else
Data.State := ebsNormal;
CalculateButtonNativeState(AViewInfo, AButtonViewInfo);
end;
end;
end;
var
AButtonsCount: Integer;
begin
AButtonsCount := Properties.Items.Count;
TcxGroupBoxViewInfo(AViewInfo).SetButtonCount(AButtonsCount);
if AButtonsCount = 0 then
Exit;
CalculateButtonViewInfos(AViewInfo);
CalculateButtonPositions(ACanvas, AViewInfo);
CalculateButtonStates;
end;
function TcxButtonGroupViewData.GetEditConstantPartSize(ACanvas: TcxCanvas;
const AEditSizeProperties: TcxEditSizeProperties;
var MinContentSize: TSize; AViewInfo: TcxCustomEditViewInfo = nil): TSize;
var
AButtonsCount, AButtonsPerColumn, AColumnsCount: Integer;
ACaption: string;
AColumnWidth, AMaxButtonHeight: Integer;
ADefaultButtonHeight, AButtonHeight: Integer;
AFlags: Integer;
AMaxColumnWidth: Integer;
ASizeCorrection: TSize;
ATextWidth: Integer;
I: Integer;
R: TRect;
AEditMetrics: TcxEditMetrics;
begin
MinContentSize := cxNullSize;
ACanvas.Font := Style.GetVisibleFont;
ASizeCorrection := Self.GetEditContentSizeCorrection;
AButtonsCount := Properties.Items.Count;
AColumnsCount := Properties.GetColumnCount;
GetEditMetrics(AEditSizeProperties.Width >= 0, ACanvas, AEditMetrics);
ADefaultButtonHeight := ACanvas.TextHeight('Zg') + ASizeCorrection.cy;
if AEditSizeProperties.Width >= 0 then
begin
Result.cx := AEditSizeProperties.Width;
if AButtonsCount = 0 then
Result.cy := ADefaultButtonHeight
else
begin
Result.cy := 0;
AButtonsPerColumn := Properties.GetButtonsPerColumn;
AColumnWidth := AEditSizeProperties.Width - ContentOffset.Left -
ContentOffset.Right + AEditMetrics.AutoHeightWidthCorrection -
AEditMetrics.ColumnOffset * (AColumnsCount - 1);
AColumnWidth := AColumnWidth div AColumnsCount - AEditMetrics.ButtonSize.cx -
AEditMetrics.AutoHeightColumnWidthCorrection;
if AColumnWidth <= 0 then
AColumnWidth := 1;
AMaxButtonHeight := ADefaultButtonHeight;
Include(PaintOptions, epoAutoHeight);
AFlags := GetDrawTextFlags and not cxAlignVCenter or cxAlignTop;
for I := 0 to AButtonsCount - 1 do
begin
R := Rect(0, 0, AColumnWidth, MaxInt);
ACaption := Properties.Items[I].Caption;
if Properties.WordWrap and (ACaption <> '') then
begin
ACanvas.TextExtent(ACaption, R, AFlags);
AButtonHeight := R.Bottom - R.Top + ASizeCorrection.cy;
if AMaxButtonHeight < AButtonHeight then
AMaxButtonHeight := AButtonHeight;
end;
end;
Result.cy := AMaxButtonHeight * AButtonsPerColumn;
if not IsInplace then
begin
R := GetClientExtent(ACanvas, nil);
Result.cy := Result.cy + R.Top + R.Bottom;
end;
end;
end else
begin
if AButtonsCount = 0 then
begin
Result.cx := 0;
Result.cy := ACanvas.TextHeight('Zg') + ASizeCorrection.cy;
end else
begin
AMaxColumnWidth := 0;
AButtonsPerColumn := Properties.GetButtonsPerColumn;
for I := 0 to AButtonsCount - 1 do
begin
ATextWidth := ACanvas.TextWidth(Properties.Items[I].Caption);
if ATextWidth > AMaxColumnWidth then
AMaxColumnWidth := ATextWidth;
end;
Result.cx := (AMaxColumnWidth + AEditMetrics.ColumnWidthCorrection + AEditMetrics.ButtonSize.cx) *
AColumnsCount + AEditMetrics.ColumnOffset * (AColumnsCount - 1) + AEditMetrics.WidthCorrection;
if ADefaultButtonHeight > AEditMetrics.ButtonSize.cy then
Result.cy := ADefaultButtonHeight
else
Result.cy := AEditMetrics.ButtonSize.cy;
Result.cy := Result.cy * AButtonsPerColumn;
end;
end;
end;
class function TcxButtonGroupViewData.IsButtonNativeStyle(
ALookAndFeel: TcxLookAndFeel): Boolean;
begin
Result := AreVisualStylesMustBeUsed(ALookAndFeel.NativeStyle, totButton);
end;
procedure TcxButtonGroupViewData.CalculateButtonPositions(ACanvas: TcxCanvas;
AViewInfo: TcxCustomEditViewInfo);
var
AButtonsCount, AButtonsPerColumn, AButtonHeight, AButtonWidth, AClientHeight,
AColumnsCount, ATopOffset, I: Integer;
AButtonViewInfo: TcxGroupBoxButtonViewInfo;
AClientExtent: TRect;
AEditMetrics: TcxEditMetrics;
begin
AButtonsCount := Properties.Items.Count;
AColumnsCount := Properties.GetColumnCount;
AButtonsPerColumn := Properties.GetButtonsPerColumn;
AClientExtent := GetClientExtent(ACanvas, AViewInfo);
GetEditMetrics(False, nil, AEditMetrics);
AButtonWidth := (Bounds.Right - Bounds.Left - (AClientExtent.Left +
AClientExtent.Right) + AEditMetrics.ClientWidthCorrection -
AEditMetrics.ColumnOffset * (AColumnsCount - 1)) div AColumnsCount;
AClientHeight := Bounds.Bottom - Bounds.Top - AClientExtent.Top - AClientExtent.Bottom;
ATopOffset := Bounds.Top + AClientExtent.Top + (AClientHeight mod AButtonsPerColumn) div 2;
AButtonHeight := AClientHeight div AButtonsPerColumn;
for I := 0 to AButtonsCount - 1 do
begin
AButtonViewInfo := TcxGroupBoxButtonViewInfo(AViewInfo.ButtonsInfo[I]);
AButtonViewInfo.Bounds.Left := Bounds.Left + AClientExtent.Left +
AButtonViewInfo.Column * (AButtonWidth + AEditMetrics.ColumnOffset) +
AEditMetrics.ClientLeftBoundCorrection;
AButtonViewInfo.Bounds.Top := ATopOffset + AButtonViewInfo.Row * AButtonHeight;
AButtonViewInfo.Bounds.Right := AButtonViewInfo.Bounds.Left + AButtonWidth;
AButtonViewInfo.Bounds.Bottom := AButtonViewInfo.Bounds.Top + AButtonHeight;
AButtonViewInfo.VisibleBounds := AButtonViewInfo.Bounds;
end;
end;
procedure TcxButtonGroupViewData.CalculateButtonViewInfos(AViewInfo: TcxCustomEditViewInfo);
function GetButtonStyle: TcxEditButtonStyle;
const
AButtonInplaceStyleMap: array[TcxLookAndFeelKind] of TcxEditButtonStyle =
(btsFlat, bts3D, btsUltraFlat,
btsOffice11);
AButtonStyleMap: array [TcxEditBorderStyle] of TcxEditButtonStyle =
(bts3D, btsFlat, btsFlat, btsFlat, bts3D, btsUltraFlat,
btsOffice11);
begin
if IsInplace then
Result := AButtonInplaceStyleMap[Style.LookAndFeel.Kind]
else
case Style.BorderStyle of
ebsUltraFlat:
Result := btsUltraFlat;
ebsOffice11:
Result := btsOffice11;
else
Result := AButtonStyleMap[AViewInfo.BorderStyle];
end;
end;
var
AButtonsCount, AButtonsPerColumn, I: Integer;
AButtonStyle: TcxEditButtonStyle;
AButtonViewInfo: TcxGroupBoxButtonViewInfo;
begin
AButtonStyle := GetButtonStyle;
AButtonsCount := Properties.Items.Count;
AButtonsPerColumn := Properties.GetButtonsPerColumn;
for I := 0 to AButtonsCount - 1 do
begin
AButtonViewInfo := TcxGroupBoxButtonViewInfo(AViewInfo.ButtonsInfo[I]);
with AButtonViewInfo do
begin
HasBackground := AViewInfo.HasBackground;
Data.Style := AButtonStyle;
Caption := Properties.FItems[I].Caption;
Column := I div AButtonsPerColumn;
Row := I mod AButtonsPerColumn;
end;
end;
end;
function TcxButtonGroupViewData.GetDrawTextFlags: Integer;
begin
Result := cxAlignLeft or cxAlignVCenter or cxShowPrefix;
if (epoAutoHeight in PaintOptions) and
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?