Recent

Author Topic: QuestionDlg Button layout on MacOS  (Read 647 times)

apeoperaio

  • Full Member
  • ***
  • Posts: 237
QuestionDlg Button layout on MacOS
« on: August 03, 2022, 11:50:57 am »
Hi,

I need to use custom dialog in my application. Currently I use QuestionDlg. There is a way to put the buttons vertically instead of horizontally?
Since it seems that default dialogs draw the buttons vertically instead of horizontally in MacOS. See attached images.

Thank you,
Andrea

AlexTP

  • Hero Member
  • *****
  • Posts: 1961
    • UVviewsoft
Re: QuestionDlg Button layout on MacOS
« Reply #1 on: August 03, 2022, 06:03:28 pm »
There is no way to do so.
You can copy/paste LCL implementation and change it like you need.

apeoperaio

  • Full Member
  • ***
  • Posts: 237
Re: QuestionDlg Button layout on MacOS
« Reply #2 on: August 04, 2022, 12:50:47 pm »
Ok, thank you

wp

  • Hero Member
  • *****
  • Posts: 10291
Re: QuestionDlg Button layout on MacOS
« Reply #3 on: August 04, 2022, 01:20:28 pm »
I don't understand: What do you want to achieve? A dialog with vertically arranged buttons? I've never seen this on my mac VM, all standard dialogs seem to have a horizontal button layout. Therefore, I do not understand your statement that "default dialogs draw the buttons vertically instead of horizontally in MacOS". Honestly, I cannot imagine that Apple provides its users with such an ugly GUI (I must confess that I am not a heavy mac user, though).

Hansaplast

  • Hero Member
  • *****
  • Posts: 629
  • Tweaking4All.com
    • Tweaking4All
Re: QuestionDlg Button layout on MacOS
« Reply #4 on: August 06, 2022, 01:38:52 pm »

Some (sloppy) code I threw together when I was playing with "CocoaPromptUser" which shows a macOS correct modal dialog.


The idea was to make an overload for MessageDlg (the last parameter, the form, would be the difference).


Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3.  
  4. {$mode objfpc}{$H+}
  5. {$modeswitch objectivec1}
  6.  
  7.  
  8. interface
  9.  
  10.  
  11. uses
  12.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls
  13.   , CocoaInt, CocoaAll;
  14.  
  15.  
  16. type
  17.  
  18.  
  19.   { TForm1 }
  20.  
  21.  
  22.   TForm1 = class(TForm)
  23.     Button1: TButton;
  24.     procedure Button1Click(Sender: TObject);
  25.   private
  26.  
  27.  
  28.   public
  29.  
  30.  
  31.   end;
  32.  
  33.  
  34. var
  35.   Form1: TForm1;
  36.  
  37.  
  38. implementation
  39.  
  40.  
  41. {$R *.lfm}
  42.  
  43.  
  44. function MessageDlg( aCaption, aMsg: string; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons; HelpCtx: Longint; DefaultButton: TMsgDlgBtn; const Sender:TForm): TModalResult;
  45. var
  46.   ButtonArrayPtr     : PLongint;            // Pointer to the button array
  47.   ButtonCount        : Integer;             // Number of buttons
  48.   Counter            : integer;
  49.   NSParentWindow     : NSWindow;            // Parent Form that the sheet is attached to
  50.   DlgTypeID          : longint;             // DialogType for conversion from TMsgDlgType
  51.   ButtonIDs          : array of Longint;    // ButtonTypes for conversion from TMsgDlgBtn array
  52.   ButtonPressed      : longint;             // ModalResult which gets converted to TModalResult
  53.   aButton            : TMsgDlgBtn;
  54.   DefaultButtonIndex : integer;
  55.   ReversedButtons    : TMsgDlgButtons;
  56. begin
  57.   // Show regular message dialog if no form assigned or form not showing
  58.   if (not Assigned(Sender)) or (not Sender.Visible) then
  59.     begin
  60.       Result := MessageDlg(aCaption, aMsg, DlgType, Buttons, HelpCtx, DefaultButton, Sender);
  61.       exit;
  62.     end;
  63.  
  64.  
  65.   { Convert array of TMsgDlgBtn to idButtonXYZ (See LCLType) and convert default button (TMsgDlgBtn) to index }
  66.   ButtonCount := 0;
  67.   DefaultButtonIndex := -1;
  68.   ReversedButtons := [];
  69.   Result := mrNone;
  70.  
  71.  
  72.   if Buttons<>[] then
  73.     begin
  74.       for aButton in Buttons do
  75.         ReversedButtons := [aButton] + ReversedButtons;
  76.  
  77.  
  78.       for aButton in ReversedButtons do
  79.         begin
  80.           SetLength(ButtonIDs,ButtonCount+1);
  81.  
  82.  
  83.           case aButton of
  84.             mbYes      : ButtonIDs[ButtonCount]:= 4;
  85.             mbNo       : ButtonIDs[ButtonCount]:= 5;
  86.             mbOK       : ButtonIDs[ButtonCount]:= 1;
  87.             mbCancel   : ButtonIDs[ButtonCount]:= 2;
  88.             mbAbort    : ButtonIDs[ButtonCount]:= 7;
  89.             mbRetry    : ButtonIDs[ButtonCount]:= 8;
  90.             mbIgnore   : ButtonIDs[ButtonCount]:= 9;
  91.             mbAll      : ButtonIDs[ButtonCount]:= 10;
  92.             mbNoToAll  : ButtonIDs[ButtonCount]:= 12;
  93.             mbYesToAll : ButtonIDs[ButtonCount]:= 11;
  94.             mbHelp     : ButtonIDs[ButtonCount]:= 3;
  95.             else         ButtonIDs[ButtonCount]:= 6; // mbClose
  96.           end;
  97.  
  98.  
  99.           if (aButton=DefaultButton) then
  100.             DefaultButtonIndex := ButtonCount;
  101.  
  102.  
  103.           inc(ButtonCount);
  104.         end;
  105.     end;
  106.  
  107.  
  108.   if (ButtonCount>0) then
  109.     ButtonArrayPtr:=@{%H-}ButtonIDs[0]{%H+}
  110.   else
  111.     ButtonArrayPtr:=nil;
  112.  
  113.  
  114.  
  115.  
  116.   { Convert TMsgDlgType to idDialogXYZ (See LCLType) }
  117.   case DlgType of
  118.     mtWarning      : DlgTypeID := $FF +1;
  119.     mtError        : DlgTypeID := $FF +2;
  120.     mtInformation  : DlgTypeID := $FF +3;
  121.     mtConfirmation : DlgTypeID := $FF +4;
  122.     else             DlgTypeID := $FF +5; //mtCustom:
  123.   end;
  124.  
  125.  
  126.   NSParentWindow := nil;
  127.   if Assigned(Sender) then
  128.     begin
  129.       if not Sender.HandleAllocated then Exit;
  130.       NSParentWindow := NSView(Sender.Handle).window;
  131.     end
  132.   else
  133.     NSParentWindow := NSApplication.sharedApplication.keyWindow;
  134.  
  135.  
  136.   if Assigned(NSParentWindow) then
  137.     begin
  138.       ButtonPressed := CocoaPromptUser(aCaption, aMsg ,DlgTypeID, ButtonArrayPtr, ButtonCount, DefaultButtonIndex, 0, NSParentWindow, true);
  139.  
  140.  
  141.       case ButtonPressed of
  142.         1  : Result := mrOK;
  143.         2  : Result := mrCancel;
  144.         //3:   Result := mrHelp  // Help does not return from modal;
  145.         4  : Result := mrYes;
  146.         5  : Result := mrNo;
  147.         6  : Result := mrClose;
  148.         7  : Result := mrAbort;
  149.         8  : Result := mrRetry;
  150.         9  : Result := mrIgnore;
  151.         10 : Result := mrAll;
  152.         11 : Result := mrYesToAll;
  153.         12 : Result := mrNoToAll
  154.         else Result := mrNone;
  155.       end;
  156.     end
  157.   else
  158.     Result := mrNone;
  159. end;
  160.  
  161.  
  162. { TForm1 }
  163.  
  164.  
  165. procedure TForm1.Button1Click(Sender: TObject);
  166. begin
  167.   MessageDlg('Caption','',mtInformation,[mbYes,mbNo,mbIgnore],0,mbYes,self);
  168. end;
  169.  
  170.  
  171. end.
  172.  



apeoperaio

  • Full Member
  • ***
  • Posts: 237
Re: QuestionDlg Button layout on MacOS
« Reply #5 on: August 08, 2022, 12:02:04 pm »
Dear @wp the attached image, with vertical button layout (messagedlg_lazarus.jpg) is produced using lazarus, specifically:
MessageDlg('lazarus', 'messagedlg', mtInformation, [mbOK, mbCancel, mbIgnore], 0);

Additionally you can find attached the image Mail_messagedlg.png that is shown by MacOS "Mai" app.

This is what I meant with standard vertical layout.

To @Hansaplast, thank you, I will check it!

 



 

TinyPortal © 2005-2018