View Issue Details

IDProjectCategoryView StatusLast Update
0020154LazarusLCLpublic2011-09-24 15:21
ReporterFlávio Etrusco Assigned ToMaxim Ganetsky  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version0.9.31 (SVN) 
Fixed in Version0.9.31 (SVN) 
Summary0020154: [patch] Non-themed (non-native) MessageDlg can't default to mbYes or mbNo buttons if mbOk is also displayed
DescriptionBecause TCustomButton.Default is assigned according to ButtonKind, mbYes and mbNo buttons, which are placed before mbOk, don't obey 'default' setting in MessageDlg.
A lame patch is attached. Obvious options include accessing the buttons by control index or crack the 'protected' visibility of 'Loading' method to force csLoading state ;-)
TagsNo tags attached.
Fixed in Revision32191
LazTarget-
Widgetset
Attached Files

Activities

2011-09-05 13:33

 

MessageDlg-notheme-defaultbtn-r32181.patch (1,076 bytes)   
diff --git lcl/include/promptdialog.inc lcl/include/promptdialog.inc
index 865d9b0..8b74882 100644
--- lcl/include/promptdialog.inc
+++ lcl/include/promptdialog.inc
@@ -213,6 +213,7 @@ var
   CurButton: TBitBtn;
   ButtonTop: Integer;
   CurBtnSize: TPoint;
+  DefaultButton: TBitBtn;
 
   function GetButtonSize(AButton: TBitBtn): TPoint;
   begin
@@ -241,6 +242,7 @@ begin
   MinBtnHeight:=Max(15,MinimumDialogButtonHeight);
   reqBtnWidth := 0;
 
+  DefaultButton := nil;
   // create the buttons, without positioning
   ButtonIndex := -1;
   for curBtn := 0 to NumButtons - 1 do
@@ -261,7 +263,7 @@ begin
           Height := Glyph.Height + 5;
 
         if ButtonIndex = TheDefaultIndex then
-          Default := true;
+          DefaultButton := CurButton;
 
         CurBtnSize:=GetButtonSize(CurButton);
         if reqBtnWidth > 0 then inc(reqBtnWidth, cBtnDist);
@@ -269,6 +271,8 @@ begin
       end;
     end;
   end;
+  if DefaultButton <> nil then
+    DefaultButton.Default := true;
 
   // calculate the minimum text offset from left
   if FBitmap <> nil then

Bart Broersma

2011-09-05 20:26

developer   ~0051479

The patch is incomplete, you forgot the SmallDevices part ;-)

I attached a new patch, based on yours.

2011-09-05 20:28

 

promptdialog.defaultbutton.diff (1,799 bytes)   
Index: lcl/include/promptdialog.inc
===================================================================
--- lcl/include/promptdialog.inc	(revision 31810)
+++ lcl/include/promptdialog.inc	(working copy)
@@ -56,10 +56,12 @@
   curBtn      : Longint; // variable to loop through TMsgDlgButtons
   ButtonIndex : integer;
   CurButton: TBitBtn;
+  DefaultButton: TBitBtn;
 begin
   Result := 0;
 
   ButtonIndex := -1;
+  DefaultButton := nil;
   for curBtn := 0 to NumButtons - 1 do
   begin
     if (Buttons[curBtn] >= Low(DialogButtonKind)) and
@@ -81,7 +83,7 @@
           Height := Glyph.Height + 5;
 
         if ButtonIndex = TheDefaultIndex then
-          Default := true;
+          DefaultButton := CurButton;
 
         Inc(Result, ASpacing);
 
@@ -94,6 +96,8 @@
       end;
     end;
   end;
+  if DefaultButton <> nil then
+    DefaultButton.Default := True;
 end;
 
 procedure TPromptDialog.Paint;
@@ -214,6 +218,7 @@
   CurButton: TBitBtn;
   ButtonTop: Integer;
   CurBtnSize: TPoint;
+  DefaultButton: TBitBtn;
 
   function GetButtonSize(AButton: TBitBtn): TPoint;
   begin
@@ -244,6 +249,7 @@
 
   // create the buttons, without positioning
   ButtonIndex := -1;
+  DefaultButton := nil;
   for curBtn := 0 to NumButtons - 1 do
   begin
     if (Buttons[curBtn] >= Low(DialogButtonKind)) and
@@ -262,7 +268,7 @@
           Height := Glyph.Height + 5;
 
         if ButtonIndex = TheDefaultIndex then
-          Default := true;
+          DefaultButton := CurButton;
 
         CurBtnSize:=GetButtonSize(CurButton);
         if reqBtnWidth > 0 then inc(reqBtnWidth, cBtnDist);
@@ -270,6 +276,8 @@
       end;
     end;
   end;
+  if DefaultButton <> nil then
+    DefaultButton.Default := True;
 
   // calculate the minimum text offset from left
   if FBitmap <> nil then

Maxim Ganetsky

2011-09-06 00:33

developer   ~0051491

Applied, thanks.

Issue History

Date Modified Username Field Change
2011-09-05 13:33 Flávio Etrusco New Issue
2011-09-05 13:33 Flávio Etrusco File Added: MessageDlg-notheme-defaultbtn-r32181.patch
2011-09-05 13:33 Flávio Etrusco LazTarget => -
2011-09-05 13:33 Flávio Etrusco Widgetset => Win32/Win64
2011-09-05 13:35 Flávio Etrusco Summary [patch] Non-themed (non-native) dialogs can't default to mbYes or mbNo buttons if mbOk is also displayed => [patch] Non-themed (non-native) MessageDlg can't default to mbYes or mbNo buttons if mbOk is also displayed
2011-09-05 20:26 Bart Broersma Note Added: 0051479
2011-09-05 20:28 Bart Broersma File Added: promptdialog.defaultbutton.diff
2011-09-05 20:28 Bart Broersma Status new => confirmed
2011-09-05 20:28 Bart Broersma Target Version => 0.99.0
2011-09-06 00:33 Maxim Ganetsky Fixed in Revision => 32191
2011-09-06 00:33 Maxim Ganetsky Widgetset Win32/Win64 =>
2011-09-06 00:33 Maxim Ganetsky Status confirmed => resolved
2011-09-06 00:33 Maxim Ganetsky Fixed in Version => 0.9.31 (SVN)
2011-09-06 00:33 Maxim Ganetsky Resolution open => fixed
2011-09-06 00:33 Maxim Ganetsky Assigned To => Maxim Ganetsky
2011-09-06 00:33 Maxim Ganetsky Note Added: 0051491
2011-09-24 15:21 Bart Broersma Status resolved => closed