ExCtrls/QuestionDlg: Support custom dialog image (QuestionDlgEx_CustomIcon)

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8159 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2021-11-24 21:06:10 +00:00
parent cb744ff5de
commit 3ffa05fdeb
3 changed files with 156 additions and 13 deletions

View File

@ -261,7 +261,7 @@ object DemoForm: TDemoForm
AnchorSideBottom.Control = rgMsgType
AnchorSideBottom.Side = asrBottom
Left = 231
Height = 123
Height = 127
Top = 364
Width = 458
Anchors = [akTop, akLeft, akRight, akBottom]
@ -277,7 +277,7 @@ object DemoForm: TDemoForm
ChildSizing.ShrinkVertical = crsScaleChilds
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 3
ClientHeight = 103
ClientHeight = 107
ClientWidth = 454
Columns = 3
ItemIndex = 9
@ -297,7 +297,7 @@ object DemoForm: TDemoForm
object edX: TEdit
Left = 159
Height = 23
Top = 69
Top = 73
Width = 139
TabOrder = 0
TextHint = 'Enter X value'
@ -305,7 +305,7 @@ object DemoForm: TDemoForm
object edY: TEdit
Left = 314
Height = 23
Top = 69
Top = 73
Width = 128
TabOrder = 1
TextHint = 'Enter Y value'
@ -318,7 +318,7 @@ object DemoForm: TDemoForm
AnchorSideRight.Control = rgMessage
AnchorSideRight.Side = asrBottom
Left = 16
Height = 123
Height = 127
Top = 364
Width = 191
Anchors = [akTop, akLeft, akRight]
@ -327,14 +327,14 @@ object DemoForm: TDemoForm
BorderSpacing.Top = 12
Caption = 'Message type'
ChildSizing.LeftRightSpacing = 12
ChildSizing.VerticalSpacing = 2
ChildSizing.VerticalSpacing = 3
ChildSizing.EnlargeHorizontal = crsHomogenousChildResize
ChildSizing.EnlargeVertical = crsHomogenousChildResize
ChildSizing.ShrinkHorizontal = crsScaleChilds
ChildSizing.ShrinkVertical = crsScaleChilds
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 1
ClientHeight = 103
ClientHeight = 107
ClientWidth = 187
ItemIndex = 0
Items.Strings = (
@ -644,7 +644,7 @@ object DemoForm: TDemoForm
AnchorSideRight.Side = asrBottom
Left = 16
Height = 52
Top = 499
Top = 503
Width = 191
Anchors = [akTop, akLeft, akRight]
AutoFill = True
@ -669,6 +669,105 @@ object DemoForm: TDemoForm
OnClick = rgTextBkColorClick
TabOrder = 11
end
object btnLoadCustomIcon: TBitBtn
AnchorSideRight.Control = rgMsgType
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = rgMsgType
AnchorSideBottom.Side = asrBottom
Left = 161
Height = 26
Top = 465
Width = 46
Anchors = [akRight, akBottom]
AutoSize = True
Glyph.Data = {
36040000424D3604000000000000360000002800000010000000100000000100
2000000000000004000064000000640000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000003591
DBFA439FDDFA439FDDFA429FDDFA429EDDFA419EDCFA419EDCFA419EDCFA419E
DCFA419EDCFA419EDCFA419EDCFA3792DAFB3080DF100000000000000000429C
DEF76EC7EBFF6DC7EAFF6BC6EAFF6AC5E9FF68C4E9FF67C3E8FF65C2E8FF64C1
E7FF63C0E7FF61BFE6FF60BEE5FF51AFE3FE308CD6450000000000000000409A
DDF47CD0F1FF7BD0F0FF7ACFEFFF79CEEFFF77CDEEFF76CCEEFF74CBEDFF73CA
EDFF71C9ECFF70C8ECFF6EC7EBFF6AC3E9FF3993DB8E00000000000000003E99
DCEC7ECEF1FF8AD9F6FF89D8F5FF87D7F4FF86D6F4FF84D5F3FF83D5F3FF81D4
F2FF80D3F2FF7ED2F1FF7DD1F1FF7BD0F0FF439ADEB40000000000000000409B
DDE470C1EDFF99E2FBFF97E2FBFF96E1FAFF94E0F9FF93DFF9FF91DEF8FF90DD
F8FF8EDCF7FF8DDBF7FF8CDAF6FF8AD9F6FF4EA4E2CD00000000000000004AA5
E0DF61B3E8FFA3E9FFFFA3E9FFFFA3E9FFFFA3E9FFFFA2E8FEFFA0E7FEFF9FE6
FDFF9DE5FDFF9CE4FCFF9AE3FCFF99E2FBFF5FB3E9E33080DF100000000051A8
E2DF5EB2E8FFA3E9FFFFA3E9FFFFA3E9FFFFA3E9FFFFA3E9FFFFA3E9FFFFA3E9
FFFFA3E9FFFFA3E9FFFFA3E9FFFFA3E9FFFF84CFF5FB348CDA450000000058AD
E5DF60B3E8FF61B3E9FF61B3E9FF60B2E9FF60B2E8FF60B2E8FF5FB1E8FF5FB1
E8FF5EB1E8FF5EB1E8FF5EB1E7FF59ADE7FB55A9E5E33B94DC85000000005FB0
E8DF9DE4FBFF9AE3FAFF97E1F9FF94DFF8FF91DDF7FF8EDBF5FF8BD9F4FF88D8
F3FF85D6F2FF82D4F1FF7FD2F0FF4FA7E1DF00000000000000000000000061B1
E8DFA6EAFFFFA6EAFFFFA6EAFFFFA3E8FEFF7AC6F1ED59ACE6DF58AAE5DF57AA
E5DF56AAE5DF53A9E4DF53A8E4DF3C94DCE20000000000000000000000004096
DEE25DAEE7DF5DAEE7DF5DAEE7DF57A9E6DF4399DF6E00000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000
}
OnClick = btnLoadCustomIconClick
TabOrder = 12
end
object btnClearCustomIcon: TBitBtn
AnchorSideRight.Control = btnLoadCustomIcon
AnchorSideBottom.Control = rgMsgType
AnchorSideBottom.Side = asrBottom
Left = 115
Height = 26
Top = 465
Width = 46
Anchors = [akRight, akBottom]
AutoSize = True
Glyph.Data = {
36040000424D3604000000000000360000002800000010000000100000000100
2000000000000004000064000000640000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000500B6690500B669000000000000000000000000000000000000
0000000000000500B6690500B669000000000000000000000000000000000000
00000200B5680C00CFE90D00D0EB0500B66D0000000000000000000000000000
00000200B56B0C00CFE90D00D0EB0500B86B0000000000000000000000000000
00000200B5680C00CFE91400E6FF0D00D0EB0500B66D00000000000000000200
B56B0C00CFE91400E6FF0D00D0EB0500B86B0000000000000000000000000000
0000000000000300B7660C00CFE91400E6FF0D00D1EB0500B66D0300B6650C00
CFE91400E6FF0D00D1EB0500B66D000000000000000000000000000000000000
000000000000000000000500B66C0C00CFEA1400E6FF0C00D0EA0C00D0EA1400
E6FF0C00CFEA0500B66C00000000000000000000000000000000000000000000
00000000000000000000000000000200B56B0C00D0E81400E6FF1400E6FF0D00
D0EB0500B66D0000000000000000000000000000000000000000000000000000
00000000000000000000000000000200B56B0C00D0E81400E6FF1400E6FF0D00
D0EB0500B66D0000000000000000000000000000000000000000000000000000
000000000000000000000500B66C0C00CFEA1400E6FF0C00D0EA0C00D0EA1400
E6FF0C00CFEA0500B66C00000000000000000000000000000000000000000000
0000000000000300B6650C00CFE91400E6FF0D00D1EB0500B66D0300B7660C00
CFE91400E6FF0D00D1EB0500B66D000000000000000000000000000000000000
00000200B5680C00CFE91400E6FF0D00D0EB0500B66D00000000000000000200
B56B0C00CFE91400E6FF0D00D0EB0500B86B0000000000000000000000000000
00000200B5680C00CFE90D00D0EB0500B66D0000000000000000000000000000
00000200B56B0C00CFE90D00D0EB0500B86B0000000000000000000000000000
0000000000000500B66C0500B66C000000000000000000000000000000000000
0000000000000500B6690500B669000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000
}
OnClick = btnClearCustomIconClick
TabOrder = 13
end
object FontDialog: TFontDialog
MinFontSize = 0
MaxFontSize = 0
@ -688,4 +787,9 @@ object DemoForm: TDemoForm
Left = 296
Top = 72
end
object OpenDialog: TOpenDialog
Filter = 'Bitmap files (*.bmp)|*.bmp|PNG files (*.png)|*.png|GIF files (*.gif)|*.gif|All files (*.*)|*.bmp;*.png;*.gif'
Left = 156
Top = 380
end
end

View File

@ -6,7 +6,7 @@ interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls,
Spin, Menus, LazHelpHTML, ExQuestionDlg;
Spin, Menus, LazHelpHTML, Buttons, ExtDlgs, ExQuestionDlg;
type
@ -15,6 +15,8 @@ type
TDemoForm = class(TForm)
Bevel1: TBevel;
Bevel2: TBevel;
btnLoadCustomIcon: TBitBtn;
btnClearCustomIcon: TBitBtn;
btnQuestionDlgEx: TButton;
btnQuestionDlg: TButton;
btnMessageDlg: TButton;
@ -29,6 +31,7 @@ type
gbMaxWidth: TGroupBox;
gbTestStd: TGroupBox;
gbTest: TGroupBox;
OpenDialog: TOpenDialog;
Panel1: TPanel;
Panel2: TPanel;
rgTextBkColor: TRadioGroup;
@ -52,6 +55,8 @@ type
seMinWidth: TSpinEdit;
seFontSize: TSpinEdit;
seMaxWidth: TSpinEdit;
procedure btnLoadCustomIconClick(Sender: TObject);
procedure btnClearCustomIconClick(Sender: TObject);
procedure btnDefaultPromptDlgClick(Sender: TObject);
procedure btnDefaultQuestionDlgClick(Sender: TObject);
procedure btnMessageDlgClick(Sender: TObject);
@ -75,7 +80,7 @@ implementation
{$R *.lfm}
uses
LCLIntf, LCLType, InterfaceBase, TypInfo, Math, Buttons,
LCLIntf, LCLType, InterfaceBase, TypInfo, Math,
{$IF FPC_FullVersion >= 30202}System.{$IFEND}UITypes;
const
@ -244,6 +249,23 @@ begin
Caption := FORM_CAPTION + '- Result: ' +BUTTON_NAMES[res];
end;
procedure TDemoForm.btnLoadCustomIconClick(Sender: TObject);
begin
if OpenDialog.Execute then
begin
if QuestionDlgEx_CustomIcon = nil then
QuestionDlgEx_CustomIcon := TPicture.Create
else
QuestionDlgEx_CustomIcon.Clear;
QuestionDlgEx_CustomIcon.LoadFromFile(OpenDialog.FileName);
end;
end;
procedure TDemoForm.btnClearCustomIconClick(Sender: TObject);
begin
FreeAndNil(QuestionDlgEx_CustomIcon);
end;
procedure TDemoForm.cbDefaultFontChange(Sender: TObject);
begin
cbFontName.Enabled := not cbDefaultFont.Checked;

View File

@ -55,6 +55,7 @@ var
QuestionDlgEx_MinWidth: Integer = 250;
QuestionDlgEx_MinHeight: Integer = 50; // Text part only
QuestionDlgEx_ButtonAlignment: TAlignment = taCenter;
QuestionDlgEx_CustomIcon: TPicture;
QuestionDlgEx_TextAlignment: TAlignment = taLeftJustify;
QuestionDlgEx_TextBkColor: TColor = clWindow;
QuestionDlgEx_TextLayout: TTextLayout = tlCenter;
@ -105,7 +106,7 @@ type
FButtons: array of TBitBtn;
FButtonPanel: TPanel;
FDialogType: TMsgDlgType;
FImage: TCustomBitmap;
FImage: TGraphic;
FImageBorder: TSize;
FInnerButtonPanel: TPanel;
FText: String;
@ -458,7 +459,21 @@ begin
FDialogType := AValue;
iconKind := idDialogBase + 1 + ord(FDialogType);
FImage.Free;
FImage := GetDialogIcon(iconKind);
if (FDialogType = mtCustom) and Assigned(QuestionDlgEx_CustomIcon) then
begin
if QuestionDlgEx_CustomIcon.Png <> nil then
FImage := TPortableNetworkGraphic.Create
else if QuestionDlgEx_CustomIcon.Bitmap <> nil then
FImage := TBitmap.Create
else if QuestionDlgEx_CustomIcon.Icon <> nil then
FImage := TIcon.Create
else if QuestionDlgEx_CustomIcon.Graphic <> nil then
FImage := TGraphic(QuestionDlgEx_CustomIcon.ClassType).Create
else
exit;
Fimage.Assign(QuestionDlgEx_CustomIcon);
end else
FImage := GetDialogIcon(iconKind);
end;
procedure TQForm.SetFormPosition(AX, AY: Integer);
@ -565,6 +580,8 @@ begin
end;
end;
finalization
FreeAndNil(QuestionDlgex_CustomIcon);
end.