extctrls/exquestiondlg: replace TImage and TLabel by directly drawn bitmap and text.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8154 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz 2021-11-23 17:17:28 +00:00
parent d95f7b808e
commit aad769d418
3 changed files with 359 additions and 235 deletions

View File

@ -1,12 +1,12 @@
object DemoForm: TDemoForm
Left = 257
Height = 563
Height = 585
Top = 128
Width = 686
Width = 708
AutoSize = True
Caption = 'Test QuestionDlgEx'
ClientHeight = 563
ClientWidth = 686
ClientHeight = 585
ClientWidth = 708
OnCreate = FormCreate
LCLVersion = '2.3.0.0'
object rgButtons: TRadioGroup
@ -16,9 +16,9 @@ object DemoForm: TDemoForm
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = rgMessage
AnchorSideBottom.Side = asrBottom
Left = 188
Height = 115
Top = 280
Left = 235
Height = 96
Top = 298
Width = 112
Anchors = [akTop, akLeft, akRight, akBottom]
AutoFill = True
@ -30,7 +30,7 @@ object DemoForm: TDemoForm
ChildSizing.ShrinkVertical = crsScaleChilds
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 1
ClientHeight = 95
ClientHeight = 76
ClientWidth = 108
ItemIndex = 1
Items.Strings = (
@ -43,15 +43,14 @@ object DemoForm: TDemoForm
end
object rgMessage: TRadioGroup
AnchorSideLeft.Control = gbTest
AnchorSideTop.Control = rgTextAlignment
AnchorSideTop.Control = gbTextAlignmentLayout
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = rgMsgType
AnchorSideRight.Control = gbTextAlignmentLayout
AnchorSideRight.Side = asrBottom
Left = 24
Height = 115
Top = 280
Width = 132
Anchors = [akTop, akLeft, akRight]
Height = 96
Top = 298
Width = 179
AutoFill = True
AutoSize = True
BorderSpacing.Top = 24
@ -62,9 +61,10 @@ object DemoForm: TDemoForm
ChildSizing.ShrinkHorizontal = crsScaleChilds
ChildSizing.ShrinkVertical = crsScaleChilds
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 1
ClientHeight = 95
ClientWidth = 128
ChildSizing.ControlsPerLine = 2
ClientHeight = 76
ClientWidth = 175
Columns = 2
ItemIndex = 2
Items.Strings = (
'very short'
@ -72,6 +72,8 @@ object DemoForm: TDemoForm
'medium'
'long'
'very long'
'high'
'long && linebreak'
)
TabOrder = 1
end
@ -80,17 +82,17 @@ object DemoForm: TDemoForm
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = Bevel1
AnchorSideTop.Side = asrBottom
AnchorSideBottom.Control = rgTextAlignment
AnchorSideBottom.Control = gbTextAlignmentLayout
AnchorSideBottom.Side = asrBottom
Left = 332
Height = 77
Left = 379
Height = 95
Top = 179
Width = 322
Anchors = [akTop, akLeft, akBottom]
BorderSpacing.Left = 32
BorderSpacing.Right = 24
Caption = 'Font'
ClientHeight = 57
ClientHeight = 75
ClientWidth = 318
TabOrder = 2
object cbDefaultFont: TCheckBox
@ -131,14 +133,14 @@ object DemoForm: TDemoForm
end
end
object rgBtnAlignment: TRadioGroup
AnchorSideLeft.Control = rgTextAlignment
AnchorSideLeft.Control = gbTextAlignmentLayout
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = Bevel1
AnchorSideTop.Side = asrBottom
AnchorSideBottom.Control = rgTextAlignment
AnchorSideBottom.Control = gbTextAlignmentLayout
AnchorSideBottom.Side = asrBottom
Left = 188
Height = 77
Left = 235
Height = 95
Top = 179
Width = 112
Anchors = [akTop, akLeft, akBottom]
@ -153,7 +155,7 @@ object DemoForm: TDemoForm
ChildSizing.ShrinkVertical = crsScaleChilds
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 1
ClientHeight = 57
ClientHeight = 75
ClientWidth = 108
ItemIndex = 2
Items.Strings = (
@ -163,37 +165,6 @@ object DemoForm: TDemoForm
)
TabOrder = 3
end
object rgTextAlignment: TRadioGroup
AnchorSideLeft.Control = gbTest
AnchorSideTop.Control = Bevel1
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = rgMsgType
AnchorSideRight.Side = asrBottom
Left = 24
Height = 77
Top = 179
Width = 132
Anchors = [akTop, akLeft, akRight]
AutoFill = True
AutoSize = True
Caption = 'Text alignment'
ChildSizing.LeftRightSpacing = 12
ChildSizing.EnlargeHorizontal = crsHomogenousChildResize
ChildSizing.EnlargeVertical = crsHomogenousChildResize
ChildSizing.ShrinkHorizontal = crsScaleChilds
ChildSizing.ShrinkVertical = crsScaleChilds
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 1
ClientHeight = 57
ClientWidth = 128
ItemIndex = 0
Items.Strings = (
'left'
'right'
'center'
)
TabOrder = 4
end
object gbMaxWidth: TGroupBox
AnchorSideLeft.Control = rgGlyphShowMode
AnchorSideLeft.Side = asrBottom
@ -202,16 +173,16 @@ object DemoForm: TDemoForm
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = rgGlyphShowMode
AnchorSideBottom.Side = asrBottom
Left = 486
Height = 115
Top = 280
Left = 533
Height = 96
Top = 298
Width = 168
Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Left = 24
Caption = 'Dialog size limits'
ClientHeight = 95
ClientHeight = 76
ClientWidth = 164
TabOrder = 5
TabOrder = 4
object Label1: TLabel
AnchorSideLeft.Control = gbMaxWidth
AnchorSideTop.Control = seMaxWidth
@ -224,15 +195,18 @@ object DemoForm: TDemoForm
Caption = 'Max width'
end
object seMaxWidth: TSpinEdit
AnchorSideLeft.Control = Label1
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = gbMaxWidth
AnchorSideRight.Control = gbMaxWidth
AnchorSideRight.Side = asrBottom
Left = 90
Left = 88
Height = 23
Top = 12
Width = 58
Width = 60
Alignment = taRightJustify
Anchors = [akTop, akRight]
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Left = 16
BorderSpacing.Top = 12
BorderSpacing.Right = 16
MaxValue = 10000
@ -249,16 +223,17 @@ object DemoForm: TDemoForm
Caption = 'Min width'
end
object seMinWidth: TSpinEdit
AnchorSideLeft.Control = seMaxWidth
AnchorSideTop.Control = seMaxWidth
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = gbMaxWidth
AnchorSideRight.Side = asrBottom
Left = 90
Left = 88
Height = 23
Top = 51
Width = 58
Width = 60
Alignment = taRightJustify
Anchors = [akTop, akRight]
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 16
BorderSpacing.Right = 16
MaxValue = 10000
@ -273,9 +248,9 @@ object DemoForm: TDemoForm
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = rgMsgType
AnchorSideBottom.Side = asrBottom
Left = 188
Left = 235
Height = 115
Top = 419
Top = 418
Width = 466
Anchors = [akTop, akLeft, akRight, akBottom]
AutoFill = True
@ -306,7 +281,7 @@ object DemoForm: TDemoForm
'poWorkAreaCenter'
'(Custom)'
)
TabOrder = 6
TabOrder = 5
object edX: TEdit
Left = 162
Height = 23
@ -328,10 +303,13 @@ object DemoForm: TDemoForm
AnchorSideLeft.Control = gbTest
AnchorSideTop.Control = rgMessage
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = gbTextAlignmentLayout
AnchorSideRight.Side = asrBottom
Left = 24
Height = 115
Top = 419
Width = 132
Top = 418
Width = 179
Anchors = [akTop, akLeft, akRight]
AutoFill = True
AutoSize = True
BorderSpacing.Top = 24
@ -345,7 +323,7 @@ object DemoForm: TDemoForm
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 1
ClientHeight = 95
ClientWidth = 128
ClientWidth = 175
ItemIndex = 0
Items.Strings = (
'mtWarning'
@ -354,7 +332,7 @@ object DemoForm: TDemoForm
'mtConfirmation'
'mtCustom'
)
TabOrder = 7
TabOrder = 6
end
object rgGlyphShowMode: TRadioGroup
AnchorSideLeft.Control = gbFont
@ -362,9 +340,9 @@ object DemoForm: TDemoForm
AnchorSideTop.Side = asrBottom
AnchorSideBottom.Control = rgMessage
AnchorSideBottom.Side = asrBottom
Left = 332
Height = 115
Top = 280
Left = 379
Height = 96
Top = 298
Width = 130
Anchors = [akTop, akLeft, akBottom]
AutoFill = True
@ -378,7 +356,7 @@ object DemoForm: TDemoForm
ChildSizing.ShrinkVertical = crsScaleChilds
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 1
ClientHeight = 95
ClientHeight = 76
ClientWidth = 126
ItemIndex = 2
Items.Strings = (
@ -387,7 +365,7 @@ object DemoForm: TDemoForm
'gsmApplication'
'gsmSystem '
)
TabOrder = 8
TabOrder = 7
end
object gbTest: TGroupBox
AnchorSideLeft.Control = Owner
@ -402,7 +380,7 @@ object DemoForm: TDemoForm
Caption = 'Test QuestionDlgEx'
ClientHeight = 84
ClientWidth = 260
TabOrder = 9
TabOrder = 8
object btnQuestionDlgEx: TButton
AnchorSideLeft.Control = gbTest
AnchorSideTop.Control = gbTest
@ -438,7 +416,7 @@ object DemoForm: TDemoForm
AnchorSideTop.Control = gbTest
AnchorSideRight.Control = gbFont
AnchorSideRight.Side = asrBottom
Left = 332
Left = 379
Height = 104
Top = 24
Width = 322
@ -446,7 +424,7 @@ object DemoForm: TDemoForm
Caption = 'Test standard dialogs'
ClientHeight = 84
ClientWidth = 318
TabOrder = 10
TabOrder = 9
object btnQuestionDlg: TButton
AnchorSideTop.Control = gbTestStd
Left = 32
@ -522,11 +500,143 @@ object DemoForm: TDemoForm
Left = 24
Height = 3
Top = 152
Width = 638
Width = 660
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Around = 24
Shape = bsTopLine
end
object gbTextAlignmentLayout: TGroupBox
AnchorSideLeft.Control = gbTest
AnchorSideTop.Control = Bevel1
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = rgMessage
AnchorSideRight.Side = asrBottom
Left = 24
Height = 95
Top = 179
Width = 179
Anchors = [akTop, akLeft, akRight]
AutoSize = True
Caption = 'Text alignment/layout'
ClientHeight = 75
ClientWidth = 175
TabOrder = 10
object Panel1: TPanel
AnchorSideLeft.Control = gbTextAlignmentLayout
AnchorSideTop.Control = gbTextAlignmentLayout
AnchorSideRight.Control = Bevel2
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = gbTextAlignmentLayout
AnchorSideBottom.Side = asrBottom
Left = 8
Height = 69
Top = 0
Width = 72
Anchors = [akTop, akLeft, akRight]
AutoSize = True
BorderSpacing.Left = 8
BorderSpacing.Right = 8
BorderSpacing.Bottom = 6
BevelOuter = bvNone
ChildSizing.VerticalSpacing = 6
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 1
ClientHeight = 69
ClientWidth = 72
TabOrder = 0
object rbLeftJustify: TRadioButton
Left = 0
Height = 19
Top = 0
Width = 63
Caption = 'left'
Checked = True
TabOrder = 2
TabStop = True
end
object rbHCenter: TRadioButton
Tag = 2
Left = 0
Height = 19
Top = 25
Width = 63
Caption = 'h-center'
TabOrder = 0
end
object rbRightJustify: TRadioButton
Tag = 1
Left = 0
Height = 19
Top = 50
Width = 63
Caption = 'right'
TabOrder = 1
end
end
object Panel2: TPanel
AnchorSideLeft.Control = Bevel2
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = gbTextAlignmentLayout
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = gbTextAlignmentLayout
AnchorSideBottom.Side = asrBottom
Left = 100
Height = 69
Top = 0
Width = 62
AutoSize = True
BorderSpacing.Left = 12
BorderSpacing.Right = 8
BorderSpacing.Bottom = 6
BevelOuter = bvNone
ChildSizing.VerticalSpacing = 6
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 1
ClientHeight = 69
ClientWidth = 62
TabOrder = 1
object rbTop: TRadioButton
Left = 0
Height = 19
Top = 0
Width = 62
Caption = 'top'
TabOrder = 0
end
object rbVCenter: TRadioButton
Tag = 1
Left = 0
Height = 19
Top = 25
Width = 62
Caption = 'v-center'
Checked = True
TabOrder = 2
TabStop = True
end
object rbBottom: TRadioButton
Tag = 2
Left = 0
Height = 19
Top = 50
Width = 62
Caption = 'bottom'
TabOrder = 1
end
end
object Bevel2: TBevel
AnchorSideLeft.Control = gbTextAlignmentLayout
AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = Panel1
AnchorSideBottom.Control = Panel2
AnchorSideBottom.Side = asrBottom
Left = 86
Height = 69
Top = 0
Width = 2
Anchors = [akTop, akLeft, akBottom]
end
end
object FontDialog1: TFontDialog
MinFontSize = 0
MaxFontSize = 0

View File

@ -14,6 +14,7 @@ type
TDemoForm = class(TForm)
Bevel1: TBevel;
Bevel2: TBevel;
btnQuestionDlgEx: TButton;
btnQuestionDlg: TButton;
btnMessageDlg: TButton;
@ -28,6 +29,15 @@ type
gbMaxWidth: TGroupBox;
gbTest: TGroupBox;
gbTestStd: TGroupBox;
Panel1: TPanel;
Panel2: TPanel;
rbLeftJustify: TRadioButton;
rbHCenter: TRadioButton;
rbRightJustify: TRadioButton;
rbTop: TRadioButton;
rbVCenter: TRadioButton;
rbBottom: TRadioButton;
gbTextAlignmentLayout: TGroupBox;
HTMLBrowserHelpViewer1: THTMLBrowserHelpViewer;
HTMLHelpDatabase1: THTMLHelpDatabase;
Label1: TLabel;
@ -38,7 +48,6 @@ type
rgMsgType: TRadioGroup;
rgPosition: TRadioGroup;
rgBtnAlignment: TRadioGroup;
rgTextAlignment: TRadioGroup;
rgButtons: TRadioGroup;
rgMessage: TRadioGroup;
seMinWidth: TSpinEdit;
@ -71,12 +80,14 @@ uses
const
DLG_TITLE = 'This is the caption of the dialog';
MSG_TEXT: array[0..4] of String = (
MSG_TEXT: array[0..6] of String = (
'msg',
'Short text',
'Text text text text text text text.',
'This is a long long long long text.',
'This is a very very very very very very very very very very very very very very long text.',
'This is even longer, another very very very very very very very very very very very very very very very very very very very very very very long text.'
'This is even longer, another very very very very very very very very very very very very very very very very very very very very very very long text.',
'Line 1' + LineEnding + 'Line 2' + LineEnding + 'Line 3' + LineEnding + 'Line 4' + LineEnding + 'Line 5',
'This is a long long long long text.' + LineEnding + 'Short text.' + 'This is a very very very very very very very very very very very very very very long text.'
);
@ -86,7 +97,6 @@ procedure TDemoForm.btnQuestionDlgExClick(Sender: TObject);
var
msg: String;
X, Y: Integer;
// F: TForm;
mt: Dialogs.TMsgDlgType;
res: TModalResult;
begin
@ -95,11 +105,16 @@ begin
QuestionDlgEx_MaxWidth := seMaxWidth.Value;
QuestionDlgEx_MinWidth := seMinWidth.Value;
QuestionDlgEx_ButtonAlignment := TAlignment(rgBtnAlignment.ItemIndex);
QuestionDlgEx_TextAlignment := TAlignment(rgTextAlignment.ItemIndex);
if rbLeftJustify.Checked then QuestionDlgEx_TextAlignment := taLeftJustify
else if rbRightJustify.Checked then QuestionDlgEx_TextAlignment := taRightJustify
else if rbHCenter.Checked then QuestionDlgEx_TextAlignment := taCenter;
if rbTop.Checked then QuestionDlgEx_TextLayout := tlTop
else if rbVCenter.Checked then QuestionDlgEx_TextLayout := tlCenter
else if rbBottom.Checked then QuestionDlgEx_TextLayout := tlBottom;
QuestionDlgEx_GlyphShowMode := TGlyphShowMode(rgGlyphShowMode.ItemIndex);
if cbDefaultFont.Checked then
begin
QuestionDlgEx_FontName := 'default';
QuestionDlgEx_FontName := '';
QuestionDlgEx_FontSize := 0;
end else
begin

View File

@ -17,7 +17,7 @@ unit ExQuestionDlg;
interface
uses
uses
LclIntf, LclType, Types,
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, Buttons,
ExtCtrls, Menus;
@ -53,9 +53,11 @@ function CreateQuestionDlgEx(const ACaption, AMsg: string; ADlgType: TMsgDlgType
var
QuestionDlgEx_MaxWidth: Integer = 500;
QuestionDlgEx_MinWidth: Integer = 250;
QuestionDlgEx_MinHeight: Integer = 50; // Text part only
QuestionDlgEx_ButtonAlignment: TAlignment = taCenter;
QuestionDlgEx_TextAlignment: TAlignment = taLeftJustify;
QuestionDlgEx_FontName: String = '';
QuestionDlgEx_TextLayout: TTextLayout = tlCenter;
QuestionDlgEx_FontName: String = ''; // the same as "default"
QuestionDlgEx_FontSize: Integer = 0;
QuestionDlgEx_GlyphShowMode: TGlyphShowMode = gsmApplication;
@ -64,6 +66,12 @@ implementation
uses
TypInfo, Math;
const
DEFAULT_IMAGE_BORDER_X = 10;
DEFAULT_IMAGE_BORDER_Y = 5;
DEFAULT_TEXT_BORDER_X = 10;
DEFAULT_TEXT_BORDER_Y = 10;
function GetBKType(str:string):TBitBtnKind;
var
value: Integer;
@ -90,37 +98,39 @@ type
FButtons: array of TBitBtn;
FButtonPanel: TPanel;
FDialogType: TMsgDlgType;
FImage: TImage;
FImage: TCustomBitmap;
FImageBorder: TSize;
FInnerButtonPanel: TPanel;
FLabel: TLabel;
FText: String;
FTextBorder: TSize;
FTextAlignment: TAlignment;
FTextLayout: TTextLayout;
FTextPanel: TPanel;
FXPos, FYPos: Integer;
function GetMsg: String;
procedure SetDialogType(AValue: TMsgDlgType);
procedure SetMsg(const AValue: String);
protected
procedure Activate; override;
procedure AdjustFormSizeAndPosition(AX, AY: Integer);
procedure AdjustForm;
procedure ApplyButtonAlignment;
procedure ApplyTextAlignment;
procedure CreateButtonPanel;
procedure CreateImage;
procedure CreateLabel;
procedure CreateInnerButtonPanel;
procedure CreateTextPanel;
procedure HelpClickHandler(Sender: TObject);
function MeasureButtonPanel: Integer;
function MeasureTextPanel: Integer;
procedure MeasureButtonPanel(var AWidth, AHeight: Integer);
procedure MeasureText(var AWidth, AHeight: Integer);
procedure MeasureTextPanel(Wrapped: Boolean; var AWidth, AHeight: Integer);
procedure PaintTextPanelHandler(Sender: TObject);
function PrepareButtons(const AButtons: array of const): TBtnParamsArray;
procedure SetFormPosition(AX, AY: Integer);
public
constructor CreateNew(AOwner: TComponent; Num: Integer = 0); override;
destructor Destroy; override;
procedure AddButtons(const AButtons: array of const);
property ButtonAlignment: TAlignment read FButtonAlignment write FButtonAlignment;
property DialogType: TMsgDlgType read FDialogType write SetDialogType;
property Msg: String read GetMsg write SetMsg;
property Msg: String read FText write FText;
property TextAlignment: TAlignment read FTextAlignment write FTextAlignment;
property TextLayout: TTextLayout read FTextLayout write FTextLayout;
property XPos: Integer read FXPos write FXPos;
property YPos: Integer read FYPos write FYPos;
end;
@ -128,22 +138,31 @@ type
constructor TQForm.CreateNew(AOwner: TComponent; Num: Integer = 0);
begin
inherited;
BorderStyle := bsSingle; // In gth2, bsDialog "glues" the dialog to the calling form
BorderStyle := bsSingle; // In gtk2, bsDialog "glues" the dialog to the calling form
BorderIcons := [biSystemMenu];
Color := clWindow;
PopupMode := pmAuto;
FImageBorder.CX := Scale96ToFont(DEFAULT_IMAGE_BORDER_X);
FImageBorder.CY := Scale96ToFont(DEFAULT_IMAGE_BORDER_Y);
FTextBorder.CX := Scale96ToFont(DEFAULT_TEXT_BORDER_X);
FTextBorder.CY := Scale96ToFont(DEFAULT_TEXT_BORDER_Y);
CreateTextPanel;
CreateImage;
CreateLabel;
CreateButtonPanel;
CreateInnerButtonPanel;
end;
destructor TQForm.Destroy;
begin
FImage.Free;
inherited;
end;
procedure TQForm.Activate;
begin
AdjustFormSizeAndPosition(FXPos, FYPos);
AdjustForm;
SetFormPosition(FXPos, FYPos);
inherited;
end;
@ -193,61 +212,50 @@ begin
// MeasureButtonPanel;
end;
procedure TQForm.AdjustFormSizeAndPosition(AX, AY: Integer);
procedure TQForm.AdjustForm;
var
buttonPanelWidth, textPanelWidth: Integer;
w, h: Integer;
buttonPanelWidth: Integer = 0;
buttonPanelHeight: Integer = 0;
textPanelWidth: Integer = 0;
textPanelHeight: Integer = 0;
begin
if (FTextPanel = nil) or (FLabel = nil) or (FButtonPanel = nil) then
begin
inherited;
if (FTextPanel = nil) or (FButtonPanel = nil) then
exit;
end;
FTextPanel.Anchors := [akLeft, akTop];
FLabel.Anchors := [akLeft, akTop];
FButtonPanel.Anchors := [akLeft, akTop];
buttonPanelWidth := MeasureButtonPanel;
textPanelWidth := MeasureTextPanel;
MeasureButtonPanel(buttonPanelWidth, buttonPanelHeight);
MeasureTextPanel(false, textPanelWidth, textPanelHeight);
if buttonPanelWidth > textPanelWidth then
begin
Constraints.MinWidth := buttonPanelWidth;
Constraints.MaxWidth := buttonPanelWidth;
Width := buttonPanelWidth;
textPanelWidth := buttonPanelWidth;
end else
begin
MeasureTextPanel(true, textPanelWidth, textPanelHeight);
if textPanelWidth > QuestionDlgEx_MaxWidth then
begin
if buttonPanelWidth > QuestionDlgEx_Maxwidth then
textPanelWidth := buttonPanelWidth
else
textPanelWidth := QuestionDlgEx_MaxWidth;
MeasureTextPanel(true, textPanelWidth, textPanelheight);
end;
Constraints.MinWidth := textPanelWidth;
Constraints.MaxWidth := textPanelWidth;
Width := textPanelWidth;
end;
HandleNeeded;
AutoSize := true;
FTextPanel.Anchors := [akLeft, akRight, akTop];
FLabel.Anchors := [akLeft, akRight, akTop];
FButtonPanel.Anchors := [akLeft, akRight, akTop];
ApplyButtonAlignment;
ApplyTextAlignment;
SetFormPosition(AX, AY);
FTextPanel.SetBounds(0, 0, textPanelWidth, textPanelHeight);
FButtonPanel.SetBounds(0, textPanelHeight, textPanelWidth, buttonPanelHeight);
Width := textPanelWidth;
Height := textPanelHeight + buttonPanelHeight;
ApplyButtonAlignment;
end;
procedure TQForm.ApplyButtonAlignment;
begin
// Set button and text alignments
case FButtonAlignment of
taLeftJustify: ;
taLeftJustify:
FInnerButtonPanel.AnchorSideLeft.Side := asrLeft;
taCenter:
FInnerButtonPanel.AnchorSideLeft.Side := asrCenter;
taRightJustify:
@ -259,11 +267,6 @@ begin
end;
end;
procedure TQForm.ApplyTextAlignment;
begin
FLabel.Alignment := FTextAlignment;
end;
procedure TQForm.CreateButtonPanel;
begin
FButtonPanel := TPanel.Create(Self);
@ -272,61 +275,10 @@ begin
BevelOuter := bvNone;
Caption := '';
Color := clBtnFace;
AutoSize := true;
AnchorSideTop.Control := FTextPanel;
AnchorSideTop.Side := asrBottom;
AnchorSideLeft.Control := Self;
AnchorSideRight.Control := Self;
AnchorSideRight.Side := asrBottom;
Parent := Self;
end;
end;
procedure TQForm.CreateImage;
var
lSize: TSize;
begin
lSize.cx := GetSystemMetrics(SM_CXICON);
lSize.cy := GetSystemMetrics(SM_CYICON);
FImage := TImage.Create(Self);
with FImage do
begin
Parent := FTextPanel;
AnchorSideTop.Control := FTextPanel;
BorderSpacing.Left := 10;
BorderSpacing.Top := 5;
BorderSpacing.Bottom := 10;
Width:= Min(32, lSize.CY);
Height:= Min(32, lSize.CY);
Transparent := true;
Proportional := true;
AntialiasingMode := amON;
Center := true;
if lSize.CX > Width then
Stretch := true;
end;
end;
procedure TQForm.CreateLabel;
begin
FLabel := TLabel.Create(Self);
with FLabel do
begin
Parent := FTextPanel;
AnchorSideLeft.Control := FImage;
AnchorSideLeft.Side := asrBottom;
AnchorSideTop.Control := FTextPanel;
AnchorSideTop.Side := asrTop;
AnchorSideRight.Control := FTextPanel;
AnchorSideRight.Side := asrBottom;
BorderSpacing.Around := 10;
WordWrap := true;
Transparent := true;
AutoSize := true;
end;
end;
procedure TQForm.CreateInnerButtonPanel;
begin
FInnerButtonPanel := TPanel.Create(Self);
@ -348,50 +300,107 @@ begin
FTextPanel := TPanel.Create(Self);
with FTextPanel do
begin
AnchorSideLeft.Control := Self;
AnchorSideTop.Control := Self;
AnchorSideRight.Control := Self;
AnchorSideRight.Side := asrBottom;
BevelOuter := bvNone;
Caption := '';
Color := clWindow;
AutoSize := true;
Parent := Self;
OnPaint := @PaintTextPanelHandler;
end;
end;
function TQForm.GetMsg: String;
begin
Result := FLabel.Caption;
end;
procedure TQForm.HelpClickHandler(Sender: TObject);
begin
ShowHelp;
end;
function TQForm.MeasureButtonPanel: Integer;
var
h: Integer = 0;
procedure TQForm.MeasureButtonPanel(var AWidth, AHeight: Integer);
begin
Result := 0;
AWidth := 0;
AHeight := 0;
FButtonPanel.HandleNeeded;
FButtonPanel.GetPreferredSize(Result, h);
Result := Max(QuestionDlgEx_MinWidth, result);
FButtonPanel.GetPreferredSize(AWidth, AHeight);
if QuestionDlgEx_MinWidth > AWidth then AWidth := QuestionDlgEx_MinWidth;
end;
function TQForm.MeasureTextPanel: Integer;
procedure TQForm.MeasureText(var AWidth, AHeight: Integer);
var
h: Integer = 0;
savedAutoSize: Boolean;
R: TRect;
flags: integer;
begin
Result := 0;
savedAutoSize := FTextPanel.AutoSize;
FTextPanel.AutoSize := true;
FTextPanel.HandleNeeded;
FTextPanel.GetPreferredSize(Result, h);
Result := Max(QuestionDlgEx_MinWidth, Result);
FTextPanel.AutoSize := savedAutoSize;
R := Rect(0, 0, AWidth, AHeight);
flags := DT_CALCRECT or DT_WORDBREAK;
DrawText(Canvas.Handle, PChar(FText), Length(FText), R, flags);
AWidth := R.Right;
AHeight := R.Bottom;
end;
procedure TQForm.MeasureTextPanel(Wrapped: Boolean; var AWidth, AHeight: Integer);
var
R: TRect;
x: Integer;
flags: Integer;
imgHeight: Integer;
begin
x := FImageBorder.CX;
if Assigned(FImage) then
inc(x, FImage.Width + Max(FImageBorder.CX, FTextBorder.CX));
if not Wrapped then AWidth := 9999;
R := Rect(x, FTextBorder.CY, AWidth, 9999);
flags := DT_CALCRECT;
if Wrapped then flags := flags or DT_WORDBREAK;
HandleNeeded;
DrawText(Canvas.Handle, PChar(FText), Length(FText), R, flags);
inc(R.Bottom, FTextBorder.CY);
AWidth := R.Right;
if AWidth < QuestionDlgEx_MinWidth then
AWidth := QuestionDlgEx_MinWidth;
AHeight := R.Bottom;
if Assigned(FImage) then
imgHeight := FImage.Height
else
imgHeight := 32;
if (AHeight < 2*FImageBorder.CY + imgHeight) then
AHeight := 2*FImageBorder.CY + imgHeight;
if AHeight < QuestionDlgEx_MinHeight then
AHeight := QuestionDlgEx_MinHeight;
end;
procedure TQForm.PaintTextPanelHandler(Sender: TObject);
var
x, y: Integer;
R: TRect;
flags: Integer;
w, h: Integer;
begin
with FTextPanel do begin
Canvas.Brush.Color := Color;
Canvas.FillRect(0, 0, Width, Height);
x := FImageBorder.CX;
if Assigned(FImage) then
begin
Canvas.Draw(x, FImageBorder.CY, FImage);
inc(x, FImage.Width + Max(FImageBorder.CX, FTextBorder.CX));
end;
if FText <> '' then
begin
R := Rect(x, FTextBorder.CY, Width - FTextBorder.CX, Height - FTextBorder.CY);
w := R.Right - x;
h := R.Bottom - FTextBorder.CY;
MeasureText(w, h);
flags := DT_WORDBREAK;
case FTextAlignment of
taLeftJustify: flags := flags or DT_LEFT;
taCenter: flags := flags or DT_CENTER;
taRightJustify: flags := flags or DT_RIGHT;
end;
case FTextLayout of
tlTop: ;
tlCenter: R.Top := (R.Top + R.Bottom - h) div 2;
tlBottom: R.Top := R.Bottom - h;
end;
DrawText(Canvas.Handle, PChar(FText), Length(FText), R, flags);
end;
end;
end;
function TQForm.PrepareButtons(const AButtons: array of const): TBtnParamsArray;
@ -424,16 +433,11 @@ end;
procedure TQForm.SetDialogType(AValue: TMsgDlgType);
var
iconKind: Integer;
bmp: TCustomBitmap;
begin
FDialogType := AValue;
iconKind := idDialogBase + 1 + ord(FDialogType);
bmp := GetDialogIcon(iconKind);
try
FImage.Picture.Assign(bmp);
finally
bmp.Free;
end;
FImage.Free;
FImage := GetDialogIcon(iconKind);
end;
procedure TQForm.SetFormPosition(AX, AY: Integer);
@ -467,12 +471,6 @@ begin
end;
end;
procedure TQForm.SetMsg(const AValue: String);
begin
FLabel.Caption := AValue;
// MeasureTextPanel;
end;
function CreateQuestionDlgEx(const ACaption, AMsg: string; ADlgType: TMsgDlgType;
const AButtons: array of const; AX, AY: Integer): TForm;
@ -484,6 +482,7 @@ begin
QForm.Font.Size := QuestionDlgEx_FontSize;
QForm.ButtonAlignment := QuestionDlgEx_ButtonAlignment;
QForm.TextAlignment := QuestionDlgEx_TextAlignment;
QForm.TextLayout := QuestionDlgEx_TextLayout;
QForm.Caption := ACaption;
QForm.DialogType := ADlgtype;
QForm.Msg := AMsg;