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

View File

@ -14,6 +14,7 @@ type
TDemoForm = class(TForm) TDemoForm = class(TForm)
Bevel1: TBevel; Bevel1: TBevel;
Bevel2: TBevel;
btnQuestionDlgEx: TButton; btnQuestionDlgEx: TButton;
btnQuestionDlg: TButton; btnQuestionDlg: TButton;
btnMessageDlg: TButton; btnMessageDlg: TButton;
@ -28,6 +29,15 @@ type
gbMaxWidth: TGroupBox; gbMaxWidth: TGroupBox;
gbTest: TGroupBox; gbTest: TGroupBox;
gbTestStd: TGroupBox; gbTestStd: TGroupBox;
Panel1: TPanel;
Panel2: TPanel;
rbLeftJustify: TRadioButton;
rbHCenter: TRadioButton;
rbRightJustify: TRadioButton;
rbTop: TRadioButton;
rbVCenter: TRadioButton;
rbBottom: TRadioButton;
gbTextAlignmentLayout: TGroupBox;
HTMLBrowserHelpViewer1: THTMLBrowserHelpViewer; HTMLBrowserHelpViewer1: THTMLBrowserHelpViewer;
HTMLHelpDatabase1: THTMLHelpDatabase; HTMLHelpDatabase1: THTMLHelpDatabase;
Label1: TLabel; Label1: TLabel;
@ -38,7 +48,6 @@ type
rgMsgType: TRadioGroup; rgMsgType: TRadioGroup;
rgPosition: TRadioGroup; rgPosition: TRadioGroup;
rgBtnAlignment: TRadioGroup; rgBtnAlignment: TRadioGroup;
rgTextAlignment: TRadioGroup;
rgButtons: TRadioGroup; rgButtons: TRadioGroup;
rgMessage: TRadioGroup; rgMessage: TRadioGroup;
seMinWidth: TSpinEdit; seMinWidth: TSpinEdit;
@ -71,12 +80,14 @@ uses
const const
DLG_TITLE = 'This is the caption of the dialog'; DLG_TITLE = 'This is the caption of the dialog';
MSG_TEXT: array[0..4] of String = ( MSG_TEXT: array[0..6] of String = (
'msg', 'msg',
'Short text', '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 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 var
msg: String; msg: String;
X, Y: Integer; X, Y: Integer;
// F: TForm;
mt: Dialogs.TMsgDlgType; mt: Dialogs.TMsgDlgType;
res: TModalResult; res: TModalResult;
begin begin
@ -95,11 +105,16 @@ begin
QuestionDlgEx_MaxWidth := seMaxWidth.Value; QuestionDlgEx_MaxWidth := seMaxWidth.Value;
QuestionDlgEx_MinWidth := seMinWidth.Value; QuestionDlgEx_MinWidth := seMinWidth.Value;
QuestionDlgEx_ButtonAlignment := TAlignment(rgBtnAlignment.ItemIndex); 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); QuestionDlgEx_GlyphShowMode := TGlyphShowMode(rgGlyphShowMode.ItemIndex);
if cbDefaultFont.Checked then if cbDefaultFont.Checked then
begin begin
QuestionDlgEx_FontName := 'default'; QuestionDlgEx_FontName := '';
QuestionDlgEx_FontSize := 0; QuestionDlgEx_FontSize := 0;
end else end else
begin begin

View File

@ -53,9 +53,11 @@ function CreateQuestionDlgEx(const ACaption, AMsg: string; ADlgType: TMsgDlgType
var var
QuestionDlgEx_MaxWidth: Integer = 500; QuestionDlgEx_MaxWidth: Integer = 500;
QuestionDlgEx_MinWidth: Integer = 250; QuestionDlgEx_MinWidth: Integer = 250;
QuestionDlgEx_MinHeight: Integer = 50; // Text part only
QuestionDlgEx_ButtonAlignment: TAlignment = taCenter; QuestionDlgEx_ButtonAlignment: TAlignment = taCenter;
QuestionDlgEx_TextAlignment: TAlignment = taLeftJustify; QuestionDlgEx_TextAlignment: TAlignment = taLeftJustify;
QuestionDlgEx_FontName: String = ''; QuestionDlgEx_TextLayout: TTextLayout = tlCenter;
QuestionDlgEx_FontName: String = ''; // the same as "default"
QuestionDlgEx_FontSize: Integer = 0; QuestionDlgEx_FontSize: Integer = 0;
QuestionDlgEx_GlyphShowMode: TGlyphShowMode = gsmApplication; QuestionDlgEx_GlyphShowMode: TGlyphShowMode = gsmApplication;
@ -64,6 +66,12 @@ implementation
uses uses
TypInfo, Math; 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; function GetBKType(str:string):TBitBtnKind;
var var
value: Integer; value: Integer;
@ -90,37 +98,39 @@ type
FButtons: array of TBitBtn; FButtons: array of TBitBtn;
FButtonPanel: TPanel; FButtonPanel: TPanel;
FDialogType: TMsgDlgType; FDialogType: TMsgDlgType;
FImage: TImage; FImage: TCustomBitmap;
FImageBorder: TSize;
FInnerButtonPanel: TPanel; FInnerButtonPanel: TPanel;
FLabel: TLabel; FText: String;
FTextBorder: TSize;
FTextAlignment: TAlignment; FTextAlignment: TAlignment;
FTextLayout: TTextLayout;
FTextPanel: TPanel; FTextPanel: TPanel;
FXPos, FYPos: Integer; FXPos, FYPos: Integer;
function GetMsg: String;
procedure SetDialogType(AValue: TMsgDlgType); procedure SetDialogType(AValue: TMsgDlgType);
procedure SetMsg(const AValue: String);
protected protected
procedure Activate; override; procedure Activate; override;
procedure AdjustFormSizeAndPosition(AX, AY: Integer); procedure AdjustForm;
procedure ApplyButtonAlignment; procedure ApplyButtonAlignment;
procedure ApplyTextAlignment;
procedure CreateButtonPanel; procedure CreateButtonPanel;
procedure CreateImage;
procedure CreateLabel;
procedure CreateInnerButtonPanel; procedure CreateInnerButtonPanel;
procedure CreateTextPanel; procedure CreateTextPanel;
procedure HelpClickHandler(Sender: TObject); procedure HelpClickHandler(Sender: TObject);
function MeasureButtonPanel: Integer; procedure MeasureButtonPanel(var AWidth, AHeight: Integer);
function MeasureTextPanel: 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; function PrepareButtons(const AButtons: array of const): TBtnParamsArray;
procedure SetFormPosition(AX, AY: Integer); procedure SetFormPosition(AX, AY: Integer);
public public
constructor CreateNew(AOwner: TComponent; Num: Integer = 0); override; constructor CreateNew(AOwner: TComponent; Num: Integer = 0); override;
destructor Destroy; override;
procedure AddButtons(const AButtons: array of const); procedure AddButtons(const AButtons: array of const);
property ButtonAlignment: TAlignment read FButtonAlignment write FButtonAlignment; property ButtonAlignment: TAlignment read FButtonAlignment write FButtonAlignment;
property DialogType: TMsgDlgType read FDialogType write SetDialogType; 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 TextAlignment: TAlignment read FTextAlignment write FTextAlignment;
property TextLayout: TTextLayout read FTextLayout write FTextLayout;
property XPos: Integer read FXPos write FXPos; property XPos: Integer read FXPos write FXPos;
property YPos: Integer read FYPos write FYPos; property YPos: Integer read FYPos write FYPos;
end; end;
@ -128,22 +138,31 @@ type
constructor TQForm.CreateNew(AOwner: TComponent; Num: Integer = 0); constructor TQForm.CreateNew(AOwner: TComponent; Num: Integer = 0);
begin begin
inherited; 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]; BorderIcons := [biSystemMenu];
Color := clWindow; Color := clWindow;
PopupMode := pmAuto; PopupMode := pmAuto;
CreateTextPanel; FImageBorder.CX := Scale96ToFont(DEFAULT_IMAGE_BORDER_X);
CreateImage; FImageBorder.CY := Scale96ToFont(DEFAULT_IMAGE_BORDER_Y);
CreateLabel; FTextBorder.CX := Scale96ToFont(DEFAULT_TEXT_BORDER_X);
FTextBorder.CY := Scale96ToFont(DEFAULT_TEXT_BORDER_Y);
CreateTextPanel;
CreateButtonPanel; CreateButtonPanel;
CreateInnerButtonPanel; CreateInnerButtonPanel;
end; end;
destructor TQForm.Destroy;
begin
FImage.Free;
inherited;
end;
procedure TQForm.Activate; procedure TQForm.Activate;
begin begin
AdjustFormSizeAndPosition(FXPos, FYPos); AdjustForm;
SetFormPosition(FXPos, FYPos);
inherited; inherited;
end; end;
@ -193,61 +212,50 @@ begin
// MeasureButtonPanel; // MeasureButtonPanel;
end; end;
procedure TQForm.AdjustFormSizeAndPosition(AX, AY: Integer); procedure TQForm.AdjustForm;
var var
buttonPanelWidth, textPanelWidth: Integer; buttonPanelWidth: Integer = 0;
w, h: Integer; buttonPanelHeight: Integer = 0;
textPanelWidth: Integer = 0;
textPanelHeight: Integer = 0;
begin begin
if (FTextPanel = nil) or (FLabel = nil) or (FButtonPanel = nil) then if (FTextPanel = nil) or (FButtonPanel = nil) then
begin
inherited;
exit; exit;
end;
FTextPanel.Anchors := [akLeft, akTop]; MeasureButtonPanel(buttonPanelWidth, buttonPanelHeight);
FLabel.Anchors := [akLeft, akTop]; MeasureTextPanel(false, textPanelWidth, textPanelHeight);
FButtonPanel.Anchors := [akLeft, akTop];
buttonPanelWidth := MeasureButtonPanel;
textPanelWidth := MeasureTextPanel;
if buttonPanelWidth > textPanelWidth then if buttonPanelWidth > textPanelWidth then
begin begin
Constraints.MinWidth := buttonPanelWidth; textPanelWidth := buttonPanelWidth;
Constraints.MaxWidth := buttonPanelWidth;
Width := buttonPanelWidth;
end else end else
begin begin
MeasureTextPanel(true, textPanelWidth, textPanelHeight);
if textPanelWidth > QuestionDlgEx_MaxWidth then if textPanelWidth > QuestionDlgEx_MaxWidth then
begin begin
if buttonPanelWidth > QuestionDlgEx_Maxwidth then if buttonPanelWidth > QuestionDlgEx_Maxwidth then
textPanelWidth := buttonPanelWidth textPanelWidth := buttonPanelWidth
else else
textPanelWidth := QuestionDlgEx_MaxWidth; textPanelWidth := QuestionDlgEx_MaxWidth;
MeasureTextPanel(true, textPanelWidth, textPanelheight);
end; end;
Constraints.MinWidth := textPanelWidth;
Constraints.MaxWidth := textPanelWidth;
Width := textPanelWidth;
end; end;
HandleNeeded; FTextPanel.SetBounds(0, 0, textPanelWidth, textPanelHeight);
AutoSize := true; FButtonPanel.SetBounds(0, textPanelHeight, textPanelWidth, buttonPanelHeight);
FTextPanel.Anchors := [akLeft, akRight, akTop]; Width := textPanelWidth;
FLabel.Anchors := [akLeft, akRight, akTop]; Height := textPanelHeight + buttonPanelHeight;
FButtonPanel.Anchors := [akLeft, akRight, akTop];
ApplyButtonAlignment; ApplyButtonAlignment;
ApplyTextAlignment;
SetFormPosition(AX, AY);
end; end;
procedure TQForm.ApplyButtonAlignment; procedure TQForm.ApplyButtonAlignment;
begin begin
// Set button and text alignments // Set button and text alignments
case FButtonAlignment of case FButtonAlignment of
taLeftJustify: ; taLeftJustify:
FInnerButtonPanel.AnchorSideLeft.Side := asrLeft;
taCenter: taCenter:
FInnerButtonPanel.AnchorSideLeft.Side := asrCenter; FInnerButtonPanel.AnchorSideLeft.Side := asrCenter;
taRightJustify: taRightJustify:
@ -259,11 +267,6 @@ begin
end; end;
end; end;
procedure TQForm.ApplyTextAlignment;
begin
FLabel.Alignment := FTextAlignment;
end;
procedure TQForm.CreateButtonPanel; procedure TQForm.CreateButtonPanel;
begin begin
FButtonPanel := TPanel.Create(Self); FButtonPanel := TPanel.Create(Self);
@ -272,61 +275,10 @@ begin
BevelOuter := bvNone; BevelOuter := bvNone;
Caption := ''; Caption := '';
Color := clBtnFace; Color := clBtnFace;
AutoSize := true;
AnchorSideTop.Control := FTextPanel;
AnchorSideTop.Side := asrBottom;
AnchorSideLeft.Control := Self;
AnchorSideRight.Control := Self;
AnchorSideRight.Side := asrBottom;
Parent := Self; Parent := Self;
end; end;
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; procedure TQForm.CreateInnerButtonPanel;
begin begin
FInnerButtonPanel := TPanel.Create(Self); FInnerButtonPanel := TPanel.Create(Self);
@ -348,50 +300,107 @@ begin
FTextPanel := TPanel.Create(Self); FTextPanel := TPanel.Create(Self);
with FTextPanel do with FTextPanel do
begin begin
AnchorSideLeft.Control := Self;
AnchorSideTop.Control := Self;
AnchorSideRight.Control := Self;
AnchorSideRight.Side := asrBottom;
BevelOuter := bvNone; BevelOuter := bvNone;
Caption := ''; Caption := '';
Color := clWindow; Color := clWindow;
AutoSize := true;
Parent := Self; Parent := Self;
OnPaint := @PaintTextPanelHandler;
end; end;
end; end;
function TQForm.GetMsg: String;
begin
Result := FLabel.Caption;
end;
procedure TQForm.HelpClickHandler(Sender: TObject); procedure TQForm.HelpClickHandler(Sender: TObject);
begin begin
ShowHelp; ShowHelp;
end; end;
function TQForm.MeasureButtonPanel: Integer; procedure TQForm.MeasureButtonPanel(var AWidth, AHeight: Integer);
var
h: Integer = 0;
begin begin
Result := 0; AWidth := 0;
AHeight := 0;
FButtonPanel.HandleNeeded; FButtonPanel.HandleNeeded;
FButtonPanel.GetPreferredSize(Result, h); FButtonPanel.GetPreferredSize(AWidth, AHeight);
Result := Max(QuestionDlgEx_MinWidth, result); if QuestionDlgEx_MinWidth > AWidth then AWidth := QuestionDlgEx_MinWidth;
end; end;
function TQForm.MeasureTextPanel: Integer; procedure TQForm.MeasureText(var AWidth, AHeight: Integer);
var var
h: Integer = 0; R: TRect;
savedAutoSize: Boolean; flags: integer;
begin begin
Result := 0; R := Rect(0, 0, AWidth, AHeight);
savedAutoSize := FTextPanel.AutoSize; flags := DT_CALCRECT or DT_WORDBREAK;
FTextPanel.AutoSize := true; DrawText(Canvas.Handle, PChar(FText), Length(FText), R, flags);
FTextPanel.HandleNeeded; AWidth := R.Right;
FTextPanel.GetPreferredSize(Result, h); AHeight := R.Bottom;
Result := Max(QuestionDlgEx_MinWidth, Result); end;
FTextPanel.AutoSize := savedAutoSize;
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; end;
function TQForm.PrepareButtons(const AButtons: array of const): TBtnParamsArray; function TQForm.PrepareButtons(const AButtons: array of const): TBtnParamsArray;
@ -424,16 +433,11 @@ end;
procedure TQForm.SetDialogType(AValue: TMsgDlgType); procedure TQForm.SetDialogType(AValue: TMsgDlgType);
var var
iconKind: Integer; iconKind: Integer;
bmp: TCustomBitmap;
begin begin
FDialogType := AValue; FDialogType := AValue;
iconKind := idDialogBase + 1 + ord(FDialogType); iconKind := idDialogBase + 1 + ord(FDialogType);
bmp := GetDialogIcon(iconKind); FImage.Free;
try FImage := GetDialogIcon(iconKind);
FImage.Picture.Assign(bmp);
finally
bmp.Free;
end;
end; end;
procedure TQForm.SetFormPosition(AX, AY: Integer); procedure TQForm.SetFormPosition(AX, AY: Integer);
@ -467,12 +471,6 @@ begin
end; end;
end; end;
procedure TQForm.SetMsg(const AValue: String);
begin
FLabel.Caption := AValue;
// MeasureTextPanel;
end;
function CreateQuestionDlgEx(const ACaption, AMsg: string; ADlgType: TMsgDlgType; function CreateQuestionDlgEx(const ACaption, AMsg: string; ADlgType: TMsgDlgType;
const AButtons: array of const; AX, AY: Integer): TForm; const AButtons: array of const; AX, AY: Integer): TForm;
@ -484,6 +482,7 @@ begin
QForm.Font.Size := QuestionDlgEx_FontSize; QForm.Font.Size := QuestionDlgEx_FontSize;
QForm.ButtonAlignment := QuestionDlgEx_ButtonAlignment; QForm.ButtonAlignment := QuestionDlgEx_ButtonAlignment;
QForm.TextAlignment := QuestionDlgEx_TextAlignment; QForm.TextAlignment := QuestionDlgEx_TextAlignment;
QForm.TextLayout := QuestionDlgEx_TextLayout;
QForm.Caption := ACaption; QForm.Caption := ACaption;
QForm.DialogType := ADlgtype; QForm.DialogType := ADlgtype;
QForm.Msg := AMsg; QForm.Msg := AMsg;