mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-14 19:19:18 +02:00
merged r50774 #8fd069e64f-r50778: QuestionDlg+DefaultQuestionDialog fixes
git-svn-id: branches/fixes_1_6@50788 -
This commit is contained in:
parent
2f1e28d82f
commit
033d704341
@ -22,7 +22,7 @@ interface
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
// RTL + FCL + LCL
|
// RTL + FCL + LCL
|
||||||
Types, typinfo, Classes, SysUtils,
|
Types, typinfo, Classes, SysUtils, LMessages,
|
||||||
LResources, LCLIntf, InterfaceBase, LCLStrConsts, LCLType, LCLProc, Forms,
|
LResources, LCLIntf, InterfaceBase, LCLStrConsts, LCLType, LCLProc, Forms,
|
||||||
Controls, Themes, GraphType, Graphics, Buttons, ButtonPanel, StdCtrls,
|
Controls, Themes, GraphType, Graphics, Buttons, ButtonPanel, StdCtrls,
|
||||||
ExtCtrls, LCLClasses, ClipBrd,
|
ExtCtrls, LCLClasses, ClipBrd,
|
||||||
|
@ -550,6 +550,9 @@ type
|
|||||||
FBitmap: TCustomBitmap;
|
FBitmap: TCustomBitmap;
|
||||||
FBitmapX, FBitmapY: Integer;
|
FBitmapX, FBitmapY: Integer;
|
||||||
FMsgMemo: TMemo;
|
FMsgMemo: TMemo;
|
||||||
|
protected
|
||||||
|
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
|
||||||
|
procedure WMCloseQuery(var message: TLMessage); message LM_CLOSEQUERY;
|
||||||
public
|
public
|
||||||
TextBox: TRect;
|
TextBox: TRect;
|
||||||
TextStyle: TTextStyle;
|
TextStyle: TTextStyle;
|
||||||
@ -727,6 +730,20 @@ begin
|
|||||||
Result := inherited ShowModal;
|
Result := inherited ShowModal;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TQuestionDlg.WMCloseQuery(var message: TLMessage);
|
||||||
|
begin
|
||||||
|
if fsModal in FFormState then
|
||||||
|
begin
|
||||||
|
if CancelControl <> nil then
|
||||||
|
CancelControl.ExecuteCancelAction
|
||||||
|
else
|
||||||
|
ModalResult := mrCancel;
|
||||||
|
end else
|
||||||
|
Close;
|
||||||
|
// Always return 0, because we destroy the window ourselves
|
||||||
|
Message.Result := 0;
|
||||||
|
end;
|
||||||
|
|
||||||
constructor TQuestionDlg.CreateQuestionDlg(const aCaption, aMsg: string;
|
constructor TQuestionDlg.CreateQuestionDlg(const aCaption, aMsg: string;
|
||||||
DlgType: LongInt; Buttons: TDialogButtons; HelpCtx: Longint);
|
DlgType: LongInt; Buttons: TDialogButtons; HelpCtx: Longint);
|
||||||
var
|
var
|
||||||
@ -742,6 +759,7 @@ begin
|
|||||||
Position := poScreenCenter;
|
Position := poScreenCenter;
|
||||||
MessageTxt := ConvertLineEndings(aMsg);
|
MessageTxt := ConvertLineEndings(aMsg);
|
||||||
HelpContext := HelpCtx;
|
HelpContext := HelpCtx;
|
||||||
|
KeyPreview := True;
|
||||||
|
|
||||||
// Initialize TextStyle
|
// Initialize TextStyle
|
||||||
FillChar(TextStyle, SizeOf(TTextStyle), 0);
|
FillChar(TextStyle, SizeOf(TTextStyle), 0);
|
||||||
@ -799,6 +817,8 @@ begin
|
|||||||
Caption := CurBtn.Caption;
|
Caption := CurBtn.Caption;
|
||||||
Parent := Self;
|
Parent := Self;
|
||||||
Default := CurBtn.Default;
|
Default := CurBtn.Default;
|
||||||
|
if Default then
|
||||||
|
ActiveControl := NewButton;
|
||||||
Cancel := CurBtn.Cancel;
|
Cancel := CurBtn.Cancel;
|
||||||
end;
|
end;
|
||||||
if FButtons = nil then
|
if FButtons = nil then
|
||||||
@ -814,6 +834,17 @@ begin
|
|||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TQuestionDlg.KeyDown(var Key: Word; Shift: TShiftState);
|
||||||
|
begin
|
||||||
|
if (Key = VK_ESCAPE) and (CancelControl = nil) then
|
||||||
|
begin
|
||||||
|
ModalResult := mrCancel;
|
||||||
|
Key := 0;
|
||||||
|
end;
|
||||||
|
|
||||||
|
inherited KeyDown(Key, Shift);
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
function DefaultQuestionDialog(const aCaption, aMsg: string; DlgType: LongInt;
|
function DefaultQuestionDialog(const aCaption, aMsg: string; DlgType: LongInt;
|
||||||
Buttons: TDialogButtons; HelpCtx: Longint): LongInt;
|
Buttons: TDialogButtons; HelpCtx: Longint): LongInt;
|
||||||
@ -857,7 +888,7 @@ var
|
|||||||
CurBtnValue: TModalResult;
|
CurBtnValue: TModalResult;
|
||||||
CurBtnCaption, CurOptions: String;
|
CurBtnCaption, CurOptions: String;
|
||||||
HasOptions: Boolean;
|
HasOptions: Boolean;
|
||||||
IsDefault: Boolean;
|
IsDefault, IsCancel: Boolean;
|
||||||
NewButton: TDialogButton;
|
NewButton: TDialogButton;
|
||||||
begin
|
begin
|
||||||
DialogButtons := TDialogButtons.Create(TDialogButton);
|
DialogButtons := TDialogButtons.Create(TDialogButton);
|
||||||
@ -895,6 +926,7 @@ begin
|
|||||||
// get options
|
// get options
|
||||||
CurOptions := '';
|
CurOptions := '';
|
||||||
IsDefault := False;
|
IsDefault := False;
|
||||||
|
IsCancel := False;
|
||||||
if (i <= High(Buttons)) then
|
if (i <= High(Buttons)) then
|
||||||
begin
|
begin
|
||||||
HasOptions := True;
|
HasOptions := True;
|
||||||
@ -911,12 +943,20 @@ begin
|
|||||||
end;
|
end;
|
||||||
if HasOptions then
|
if HasOptions then
|
||||||
begin
|
begin
|
||||||
if SysUtils.CompareText(CurOptions,'isdefault')<>0 then
|
if SysUtils.CompareText(CurOptions,'isdefault')=0 then
|
||||||
|
begin
|
||||||
|
if DialogButtons.DefaultButton <> nil then
|
||||||
|
raise Exception.Create('TQuestionDlg.CreateQuestionDlg only one button can be default');
|
||||||
|
IsDefault := True;
|
||||||
|
end else
|
||||||
|
if SysUtils.CompareText(CurOptions,'iscancel')=0 then
|
||||||
|
begin
|
||||||
|
if DialogButtons.CancelButton <> nil then
|
||||||
|
raise Exception.Create('TQuestionDlg.CreateQuestionDlg only one button can be cancel');
|
||||||
|
IsCancel := True;
|
||||||
|
end else
|
||||||
raise Exception.Create('TQuestionDlg.CreateQuestionDlg option expected at '
|
raise Exception.Create('TQuestionDlg.CreateQuestionDlg option expected at '
|
||||||
+IntToStr(i)+' but "'+CurOptions+'" found.');
|
+IntToStr(i)+' but "'+CurOptions+'" found.');
|
||||||
if DialogButtons.DefaultButton <> nil then
|
|
||||||
raise Exception.Create('TQuestionDlg.CreateQuestionDlg only one button can be default');
|
|
||||||
IsDefault := True;
|
|
||||||
inc(i);
|
inc(i);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -947,6 +987,8 @@ begin
|
|||||||
end;
|
end;
|
||||||
if IsDefault then
|
if IsDefault then
|
||||||
DialogButtons.DefaultButton := NewButton;
|
DialogButtons.DefaultButton := NewButton;
|
||||||
|
if IsCancel then
|
||||||
|
DialogButtons.CancelButton := NewButton;
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
raise Exception.Create('TQuestionDlg.Create: invalid Buttons parameter '+dbgs(i));
|
raise Exception.Create('TQuestionDlg.Create: invalid Buttons parameter '+dbgs(i));
|
||||||
|
Loading…
Reference in New Issue
Block a user