ExCtrls/QuestionDlgEx: Add variable for text background color.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8158 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2021-11-24 20:28:10 +00:00
parent 17a5b7035b
commit cb744ff5de
3 changed files with 100 additions and 55 deletions

View File

@ -18,7 +18,7 @@ object DemoForm: TDemoForm
AnchorSideBottom.Side = asrBottom AnchorSideBottom.Side = asrBottom
Left = 231 Left = 231
Height = 108 Height = 108
Top = 252 Top = 244
Width = 112 Width = 112
Anchors = [akLeft, akRight, akBottom] Anchors = [akLeft, akRight, akBottom]
AutoFill = True AutoFill = True
@ -49,11 +49,11 @@ object DemoForm: TDemoForm
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
Left = 16 Left = 16
Height = 108 Height = 108
Top = 252 Top = 244
Width = 191 Width = 191
AutoFill = True AutoFill = True
AutoSize = True AutoSize = True
BorderSpacing.Top = 16 BorderSpacing.Top = 12
Caption = 'Message' Caption = 'Message'
ChildSizing.LeftRightSpacing = 12 ChildSizing.LeftRightSpacing = 12
ChildSizing.HorizontalSpacing = 12 ChildSizing.HorizontalSpacing = 12
@ -88,7 +88,7 @@ object DemoForm: TDemoForm
AnchorSideBottom.Side = asrBottom AnchorSideBottom.Side = asrBottom
Left = 367 Left = 367
Height = 95 Height = 95
Top = 141 Top = 137
Width = 322 Width = 322
Anchors = [akTop, akLeft, akRight, akBottom] Anchors = [akTop, akLeft, akRight, akBottom]
Caption = 'Font' Caption = 'Font'
@ -150,7 +150,7 @@ object DemoForm: TDemoForm
AnchorSideBottom.Side = asrBottom AnchorSideBottom.Side = asrBottom
Left = 231 Left = 231
Height = 95 Height = 95
Top = 141 Top = 137
Width = 112 Width = 112
Anchors = [akTop, akLeft, akBottom] Anchors = [akTop, akLeft, akBottom]
AutoFill = True AutoFill = True
@ -183,7 +183,7 @@ object DemoForm: TDemoForm
AnchorSideBottom.Side = asrBottom AnchorSideBottom.Side = asrBottom
Left = 521 Left = 521
Height = 108 Height = 108
Top = 252 Top = 244
Width = 168 Width = 168
Anchors = [akTop, akLeft, akBottom] Anchors = [akTop, akLeft, akBottom]
AutoSize = True AutoSize = True
@ -262,7 +262,7 @@ object DemoForm: TDemoForm
AnchorSideBottom.Side = asrBottom AnchorSideBottom.Side = asrBottom
Left = 231 Left = 231
Height = 123 Height = 123
Top = 376 Top = 364
Width = 458 Width = 458
Anchors = [akTop, akLeft, akRight, akBottom] Anchors = [akTop, akLeft, akRight, akBottom]
AutoFill = True AutoFill = True
@ -319,13 +319,12 @@ object DemoForm: TDemoForm
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
Left = 16 Left = 16
Height = 123 Height = 123
Top = 376 Top = 364
Width = 191 Width = 191
Anchors = [akTop, akLeft, akRight] Anchors = [akTop, akLeft, akRight]
AutoFill = True AutoFill = True
AutoSize = True AutoSize = True
BorderSpacing.Top = 16 BorderSpacing.Top = 12
BorderSpacing.Bottom = 16
Caption = 'Message type' Caption = 'Message type'
ChildSizing.LeftRightSpacing = 12 ChildSizing.LeftRightSpacing = 12
ChildSizing.VerticalSpacing = 2 ChildSizing.VerticalSpacing = 2
@ -355,7 +354,7 @@ object DemoForm: TDemoForm
AnchorSideBottom.Side = asrBottom AnchorSideBottom.Side = asrBottom
Left = 367 Left = 367
Height = 108 Height = 108
Top = 252 Top = 244
Width = 130 Width = 130
Anchors = [akTop, akLeft, akBottom] Anchors = [akTop, akLeft, akBottom]
AutoFill = True AutoFill = True
@ -445,16 +444,17 @@ object DemoForm: TDemoForm
end end
object btnDefaultPromptDlg: TButton object btnDefaultPromptDlg: TButton
AnchorSideLeft.Control = btnDefaultQuestionDlg AnchorSideLeft.Control = btnDefaultQuestionDlg
AnchorSideTop.Control = btnMessageDlg AnchorSideTop.Control = btnDefaultQuestionDlg
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = btnDefaultQuestionDlg AnchorSideRight.Control = btnDefaultQuestionDlg
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
Left = 156 Left = 156
Height = 25 Height = 25
Top = 39 Top = 37
Width = 130 Width = 130
Anchors = [akTop, akLeft, akRight] Anchors = [akTop, akLeft, akRight]
AutoSize = True AutoSize = True
BorderSpacing.Top = 2 BorderSpacing.Top = 4
Caption = 'DefaultPromptDlg' Caption = 'DefaultPromptDlg'
OnClick = btnDefaultPromptDlgClick OnClick = btnDefaultPromptDlgClick
TabOrder = 3 TabOrder = 3
@ -481,10 +481,10 @@ object DemoForm: TDemoForm
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
Left = 16 Left = 16
Height = 95 Height = 95
Top = 141 Top = 137
Width = 192 Width = 192
BorderSpacing.Left = 16 BorderSpacing.Left = 16
BorderSpacing.Top = 16 BorderSpacing.Top = 12
Caption = 'Text alignment/layout' Caption = 'Text alignment/layout'
ClientHeight = 75 ClientHeight = 75
ClientWidth = 188 ClientWidth = 188
@ -629,7 +629,6 @@ object DemoForm: TDemoForm
Width = 307 Width = 307
Align = alClient Align = alClient
Anchors = [akTop, akLeft, akRight] Anchors = [akTop, akLeft, akRight]
AutoSize = True
BorderSpacing.Around = 8 BorderSpacing.Around = 8
BorderSpacing.InnerBorder = 8 BorderSpacing.InnerBorder = 8
Caption = 'QuestionDlgEx' Caption = 'QuestionDlgEx'
@ -637,7 +636,40 @@ object DemoForm: TDemoForm
TabOrder = 0 TabOrder = 0
end end
end end
object FontDialog1: TFontDialog object rgTextBkColor: TRadioGroup
AnchorSideLeft.Control = gbTextAlignmentLayout
AnchorSideTop.Control = rgMsgType
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = rgMessage
AnchorSideRight.Side = asrBottom
Left = 16
Height = 52
Top = 499
Width = 191
Anchors = [akTop, akLeft, akRight]
AutoFill = True
BorderSpacing.Top = 12
BorderSpacing.Bottom = 16
Caption = 'Text background color'
ChildSizing.LeftRightSpacing = 12
ChildSizing.EnlargeHorizontal = crsHomogenousChildResize
ChildSizing.EnlargeVertical = crsHomogenousChildResize
ChildSizing.ShrinkHorizontal = crsScaleChilds
ChildSizing.ShrinkVertical = crsScaleChilds
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 2
ClientHeight = 32
ClientWidth = 187
Columns = 2
ItemIndex = 0
Items.Strings = (
'clWindow'
'clForm'
)
OnClick = rgTextBkColorClick
TabOrder = 11
end
object FontDialog: TFontDialog
MinFontSize = 0 MinFontSize = 0
MaxFontSize = 0 MaxFontSize = 0
Left = 584 Left = 584
@ -647,13 +679,13 @@ object DemoForm: TDemoForm
BaseURL = 'file://html/' BaseURL = 'file://html/'
AutoRegister = True AutoRegister = True
KeywordPrefix = 'HTML/' KeywordPrefix = 'HTML/'
Left = 312 Left = 296
Top = 80 Top = 16
end end
object HTMLBrowserHelpViewer: THTMLBrowserHelpViewer object HTMLBrowserHelpViewer: THTMLBrowserHelpViewer
BrowserParams = '%s' BrowserParams = '%s'
AutoRegister = True AutoRegister = True
Left = 168 Left = 296
Top = 80 Top = 72
end end
end end

View File

@ -24,13 +24,14 @@ type
cbFontName: TComboBox; cbFontName: TComboBox;
edX: TEdit; edX: TEdit;
edY: TEdit; edY: TEdit;
FontDialog1: TFontDialog; FontDialog: TFontDialog;
gbFont: TGroupBox; gbFont: TGroupBox;
gbMaxWidth: TGroupBox; gbMaxWidth: TGroupBox;
gbTestStd: TGroupBox; gbTestStd: TGroupBox;
gbTest: TGroupBox; gbTest: TGroupBox;
Panel1: TPanel; Panel1: TPanel;
Panel2: TPanel; Panel2: TPanel;
rgTextBkColor: TRadioGroup;
rbLeftJustify: TRadioButton; rbLeftJustify: TRadioButton;
rbHCenter: TRadioButton; rbHCenter: TRadioButton;
rbRightJustify: TRadioButton; rbRightJustify: TRadioButton;
@ -51,13 +52,14 @@ type
seMinWidth: TSpinEdit; seMinWidth: TSpinEdit;
seFontSize: TSpinEdit; seFontSize: TSpinEdit;
seMaxWidth: TSpinEdit; seMaxWidth: TSpinEdit;
procedure btnMessageDlgClick(Sender: TObject);
procedure btnQuestionDlgExClick(Sender: TObject);
procedure btnQuestionDlgClick(Sender: TObject);
procedure btnDefaultPromptDlgClick(Sender: TObject); procedure btnDefaultPromptDlgClick(Sender: TObject);
procedure cbDefaultFontChange(Sender: TObject);
procedure btnDefaultQuestionDlgClick(Sender: TObject); procedure btnDefaultQuestionDlgClick(Sender: TObject);
procedure btnMessageDlgClick(Sender: TObject);
procedure btnQuestionDlgClick(Sender: TObject);
procedure btnQuestionDlgExClick(Sender: TObject);
procedure cbDefaultFontChange(Sender: TObject);
procedure FormCreate(Sender: TObject); procedure FormCreate(Sender: TObject);
procedure rgTextBkColorClick(Sender: TObject);
private private
function GetModalResultStr(res: TModalResult): String; function GetModalResultStr(res: TModalResult): String;
@ -73,7 +75,7 @@ implementation
{$R *.lfm} {$R *.lfm}
uses uses
LCLIntf, LCLType, InterfaceBase, TypInfo, Math, LCLIntf, LCLType, InterfaceBase, TypInfo, Math, Buttons,
{$IF FPC_FullVersion >= 30202}System.{$IFEND}UITypes; {$IF FPC_FullVersion >= 30202}System.{$IFEND}UITypes;
const const
@ -88,6 +90,12 @@ const
'Line 1' + LineEnding + 'Line 2' + LineEnding + 'Line 3' + LineEnding + 'Line 4' + LineEnding + 'Line 5', '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.' '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.'
); );
BUTTON_NAMES: array[idButtonOK..idButtonShield] of string = (
'idButtonOk', 'idButtonCancel', 'idButtonHelp', 'idButtonYes', 'idButtonNo',
'idButtonClose', 'idButtonAbort', 'idButtonRetry', 'idButtonIgnore',
'idButtonAll', 'idButtonYesToAll', 'idButtonNoToAll', 'idButtonOpen',
'idButtonSave', 'idButtonShield'
);
{ TDemoForm } { TDemoForm }
@ -177,7 +185,7 @@ end;
procedure TDemoForm.btnQuestionDlgClick(Sender: TObject); procedure TDemoForm.btnQuestionDlgClick(Sender: TObject);
var var
mt: TMsgDlgType; mt: TMsgDlgType;
res: TModalResult; res: Integer;
msg: String; msg: String;
helpkwd: String; helpkwd: String;
begin begin
@ -185,23 +193,28 @@ begin
mt := TMsgDlgType(rgMsgType.ItemIndex); mt := TMsgDlgType(rgMsgType.ItemIndex);
msg := MSG_TEXT[rgMessage.ItemIndex]; msg := MSG_TEXT[rgMessage.ItemIndex];
helpkwd := 'HTML/index.html'; helpkwd := 'HTML/index.html';
// There are two ways to work with this dialog:
// - use the Delphi compatible mrXXX constants (DO NOT USE THE mbXXX CONSTANTS!)
// - use the LCL idButtonXXX constants
case rgButtons.ItemIndex of case rgButtons.ItemIndex of
0: res := QuestionDlg(DLG_TITLE, msg, mt, [mbYes, 'Yes sir'], helpkwd); 0: res := QuestionDlg(DLG_TITLE, msg, mt, [mrYes, 'Yes sir'], helpkwd);
1: res := QuestionDlg(DLG_TITLE, msg, mt, [mbYes, 'Yes sir', mbNo, 'No sir', 'IsDefault', mbCancel, 'Changed my mind'], helpkwd); 1: res := QuestionDlg(DLG_TITLE, msg, mt, [mrYes, 'Yes sir', mrNo, 'No sir', 'IsDefault', mrCancel, 'Changed my mind'], helpkwd);
2: res := QuestionDlg(DLG_TITLE, msg, mt, [mbYes, 'Yes sir', mbYesToAll, 'I fully agree', mbNo, 'No sir', 'IsDefault', mbNoToAll, 'I fully disagree', mbCancel, 'Changed my mind', 'IsCancel'], helpkwd); 2: res := QuestionDlg(DLG_TITLE, msg, mt, [mrYes, 'Yes sir', mrYesToAll, 'I fully agree', mrNo, 'No sir', 'IsDefault', mrNoToAll, 'I fully disagree', mrCancel, 'Changed my mind', 'IsCancel'], helpkwd);
3: res := QuestionDlg(DLG_TITLE, msg, mt, [mbYes, 'Yes sir', mbYesToAll, 'I fully agree', mbNo, 'No sir', 'IsDefault', mbNoToAll, 'I fully disagree', mbCancel, 'Changed my mind', 'IsCancel', mbClose, 'Schließen', mbHelp, 'Hilfe'], helpkwd); 3: res := QuestionDlg(DLG_TITLE, msg, mt, [mrYes, 'Yes sir', mrYesToAll, 'I fully agree', mrNo, 'No sir', 'IsDefault', mrNoToAll, 'I fully disagree', mrCancel, 'Changed my mind', 'IsCancel', mrClose, 'Schließen', mrNone, 'Hilfe'], helpkwd);
end; end;
Caption := GetModalResultStr(res); Caption := GetModalResultStr(res);
(*
case rgButtons.ItemIndex of
0: res := QuestionDlg(DLG_TITLE, msg, mt, [idButtonYes, 'Yes sir'], helpkwd);
1: res := QuestionDlg(DLG_TITLE, msg, mt, [idButtonYes, 'Yes sir', idButtonNo, 'No sir', 'IsDefault', idButtonCancel, 'Changed my mind'], helpkwd);
2: res := QuestionDlg(DLG_TITLE, msg, mt, [idButtonYes, 'Yes sir', idButtonYesToAll, 'I fully agree', idButtonNo, 'No sir', 'IsDefault', idButtonNoToAll, 'I fully disagree', idButtonCancel, 'Changed my mind', 'IsCancel'], helpkwd);
3: res := QuestionDlg(DLG_TITLE, msg, mt, [idButtonYes, 'Yes sir', idButtonYesToAll, 'I fully agree', idButtonNo, 'No sir', 'IsDefault', idButtonNoToAll, 'I fully disagree', idButtonCancel, 'Changed my mind', 'IsCancel', idButtonClose, 'Schließen', idButtonHelp, 'Hilfe'], helpkwd);
end;
Caption := FORM_CAPTION + ' - Result: ' + BUTTON_NAMES[res];
*)
end; end;
procedure TDemoForm.btnDefaultPromptDlgClick(Sender: TObject); procedure TDemoForm.btnDefaultPromptDlgClick(Sender: TObject);
const
BUTTON_NAMES: array[idButtonOK..idButtonShield] of string = (
'idButtonOk', 'idButtonCancel', 'idButtonHelp', 'idButtonYes', 'idButtonNo',
'idButtonClose', 'idButtonAbort', 'idButtonRetry', 'idButtonIgnore',
'idButtonAll', 'idButtonYesToAll', 'idButtonNoToAll', 'idButtonOpen',
'idButtonSave', 'idButtonShield'
);
var var
mt: Integer; mt: Integer;
res: Integer; res: Integer;
@ -302,6 +315,14 @@ begin
seFontSize.Enabled := false; seFontSize.Enabled := false;
end; end;
procedure TDemoForm.rgTextBkColorClick(Sender: TObject);
begin
case rgTextBkColor.ItemIndex of
0: QuestionDlgEx_TextBkColor := clWindow;
1: QuestionDlgEx_TextBkColor := clBtnFace;
end;
end;
function TDemoForm.GetModalResultStr(res: TModalResult): String; function TDemoForm.GetModalResultStr(res: TModalResult): String;
begin begin
Result := FORM_CAPTION + ' - ModalResult: ' + {$IF FPC_FullVersion>=30202}System.{$IFEND}UITypes.ModalResultStr[res]; Result := FORM_CAPTION + ' - ModalResult: ' + {$IF FPC_FullVersion>=30202}System.{$IFEND}UITypes.ModalResultStr[res];

View File

@ -56,6 +56,7 @@ var
QuestionDlgEx_MinHeight: Integer = 50; // Text part only QuestionDlgEx_MinHeight: Integer = 50; // Text part only
QuestionDlgEx_ButtonAlignment: TAlignment = taCenter; QuestionDlgEx_ButtonAlignment: TAlignment = taCenter;
QuestionDlgEx_TextAlignment: TAlignment = taLeftJustify; QuestionDlgEx_TextAlignment: TAlignment = taLeftJustify;
QuestionDlgEx_TextBkColor: TColor = clWindow;
QuestionDlgEx_TextLayout: TTextLayout = tlCenter; QuestionDlgEx_TextLayout: TTextLayout = tlCenter;
QuestionDlgEx_FontName: String = ''; // the same as "default" QuestionDlgEx_FontName: String = ''; // the same as "default"
QuestionDlgEx_FontSize: Integer = 0; QuestionDlgEx_FontSize: Integer = 0;
@ -110,12 +111,12 @@ type
FText: String; FText: String;
FTextBorder: TSize; FTextBorder: TSize;
FTextAlignment: TAlignment; FTextAlignment: TAlignment;
FTextBkColor: TColor;
FTextLayout: TTextLayout; FTextLayout: TTextLayout;
FTextPanel: TPanel; FTextPanel: TPanel;
FXPos, FYPos: Integer; FXPos, FYPos: Integer;
procedure SetDialogType(AValue: TMsgDlgType); procedure SetDialogType(AValue: TMsgDlgType);
protected protected
// procedure Activate; override;
procedure AdjustForm; procedure AdjustForm;
procedure ApplyButtonAlignment; procedure ApplyButtonAlignment;
procedure CreateButtonPanel; procedure CreateButtonPanel;
@ -137,6 +138,7 @@ type
property DialogType: TMsgDlgType read FDialogType write SetDialogType; property DialogType: TMsgDlgType read FDialogType write SetDialogType;
property Msg: String read FText write FText; property Msg: String read FText write FText;
property TextAlignment: TAlignment read FTextAlignment write FTextAlignment; property TextAlignment: TAlignment read FTextAlignment write FTextAlignment;
property TextBkColor: TColor read FTextBkColor write FTextBkColor;
property TextLayout: TTextLayout read FTextLayout write FTextLayout; 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;
@ -146,7 +148,6 @@ constructor TQForm.CreateNew(AOwner: TComponent; Num: Integer = 0);
begin begin
inherited; inherited;
BorderStyle := bsDialog; BorderStyle := bsDialog;
Color := clWindow;
PopupMode := pmAuto; PopupMode := pmAuto;
FImageBorder.CX := Scale96ToFont(DEFAULT_IMAGE_BORDER_X); FImageBorder.CX := Scale96ToFont(DEFAULT_IMAGE_BORDER_X);
@ -165,14 +166,6 @@ begin
inherited; inherited;
end; end;
{
procedure TQForm.Activate;
begin
AdjustForm;
SetFormPosition(FXPos, FYPos);
inherited;
end;
}
procedure TQForm.AddButtons(const AButtons: array of const); procedure TQForm.AddButtons(const AButtons: array of const);
const const
MsgDlgBtnStr : array [0..11] of string = ( MsgDlgBtnStr : array [0..11] of string = (
@ -294,8 +287,6 @@ begin
begin begin
AnchorSideLeft.Control := FButtonPanel; AnchorSideLeft.Control := FButtonPanel;
AnchorSideTop.Control := FButtonPanel; AnchorSideTop.Control := FButtonPanel;
// AnchorSideRight.Control := FButtonPanel;
// AnchorSideRight.Side := asrBottom;
BevelOuter := bvNone; BevelOuter := bvNone;
BorderSpacing.Top := Scale96ToFont(BUTTON_SPACING); BorderSpacing.Top := Scale96ToFont(BUTTON_SPACING);
BorderSpacing.Bottom := Scale96ToFont(BUTTON_SPACING); BorderSpacing.Bottom := Scale96ToFont(BUTTON_SPACING);
@ -312,7 +303,7 @@ begin
begin begin
BevelOuter := bvNone; BevelOuter := bvNone;
Caption := ''; Caption := '';
Color := clWindow; Color := QuestionDlgEx_TextBkColor;
Parent := Self; Parent := Self;
OnPaint := @PaintTextPanelHandler; OnPaint := @PaintTextPanelHandler;
end; end;
@ -521,6 +512,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.TextBkColor := QuestionDlgEx_TextBkColor;
QForm.TextLayout := QuestionDlgEx_TextLayout; QForm.TextLayout := QuestionDlgEx_TextLayout;
QForm.Caption := ACaption; QForm.Caption := ACaption;
QForm.DialogType := ADlgtype; QForm.DialogType := ADlgtype;