View Issue Details

IDProjectCategoryView StatusLast Update
0037825LazarusWidgetsetpublic2020-10-05 15:38
ReporterCudaText man_ Assigned To 
PrioritynormalSeverityminorReproducibilityalways
Status newResolutionopen 
OSubuntu 20 x64 
Product Version2.1 (SVN) 
Summary0037825: gtk2: LCLIntf.MessageBox doesnt wrap very long text
Descriptiondemo
https://github.com/Alexey-T/Lazarus_test_messageboxes

enter message text very long: longer than one monitor width. I have 2 monitors.
demo has 5 buttons for messageboxes.
button "LCLIntf.MessageBox" fails to wrap very long text. (it shows msgbox across 2 monitors)
other 4 buttons do it ok.
TagsNo tags attached.
Fixed in Revision
LazTarget
WidgetsetGTK 2
Attached Files

Activities

CudaText man_

2020-10-05 15:38

reporter   ~0126098

I rewrote TGtk2Widgetset.MessageBox. It was doing nasty gtk code (which misses icons and word-wrap), now it makes wrapper call to AskUser().
Its ok now.
msg1.diff (5,269 bytes)   
Index: lcl/interfaces/gtk2/gtk2winapi.inc
===================================================================
--- lcl/interfaces/gtk2/gtk2winapi.inc	(revision 63959)
+++ lcl/interfaces/gtk2/gtk2winapi.inc	(working copy)
@@ -6683,86 +6683,86 @@
 
 function TGtk2WidgetSet.MessageBox(hWnd: HWND; lpText, lpCaption: PChar;
   uType : Cardinal): integer;
-var Dialog, ALabel : PGtkWidget;
-    ButtonCount, DefButton, ADialogResult : Integer;
-
-    procedure CreateButton(const ALabel : PChar; const RetValue : integer);
-    var AButton : PGtkWidget;
+var
+  Buttons: TDialogButtons;
+  //
+  procedure CreateButton(const ACaption: string; ARes: TModalResult);
+  begin
+    with Buttons.Add do
     begin
-      AButton:= gtk_button_new_with_mnemonic(Ampersands2Underscore(ALabel));
-      Inc(ButtonCount);
-      if ButtonCount = DefButton then begin
-        gtk_window_set_focus(PGtkWindow(Dialog), AButton);
-      end;
-      { If there is the Cancel button, allow the dialog to close }
-      if RetValue = IDCANCEL then begin
-        g_object_set_data(PGObject(Dialog), 'modal_result', Pointer(IDCANCEL));
-      end;
-      g_object_set_data(PGObject(AButton), 'modal_result',
-                          {%H-}Pointer(PtrInt(RetValue)));
-      g_signal_connect(PGtkObject(AButton), 'clicked',
-                       TGtkSignalFunc(@MessageButtonClicked), @ADialogResult);
-      gtk_container_add (PGtkContainer(PGtkDialog(Dialog)^.action_area), AButton);
+      Caption := ACaption;
+      ModalResult := ARes;
     end;
-
+  end;
+  //
+var
+  NType: integer;
+  NDefIndex: integer;
 begin
-  ButtonCount:= 0;
-  { Determine which is the default button }
-  DefButton:= ((uType and $00000300) shr 8) + 1;
-  //DebugLn('Trace:Default button is ' + IntToStr(DefButton));
+  NDefIndex := (uType and $300) shr 8;
 
-  ADialogResult:= 0;
-  Dialog:= gtk_dialog_new;
-  {$IFDEF DebugLCLComponents}
-  DebugGtkWidgets.MarkCreated(Dialog,'TGtk2WidgetSet.MessageBox');
-  {$ENDIF}
-  g_signal_connect(PGtkObject(Dialog), 'delete-event', TGtkSignalFunc(@MessageBoxClosed), @ADialogResult);
-  gtk_window_set_default_size(PGtkWindow(Dialog), 100, 100);
-  ALabel:= gtk_label_new(lpText);
-  gtk_container_add (PGtkContainer(PGtkDialog(Dialog)^.vbox), ALabel);
-  case (uType and $0000000F) of
-    MB_OKCANCEL:
-      begin
-        CreateButton(PChar(rsMbOK), IDOK);
-        CreateButton(PChar(rsMbCancel), IDCANCEL);
-      end;
-    MB_ABORTRETRYIGNORE:
-      begin
-        CreateButton(PChar(rsMbAbort), IDABORT);
-        CreateButton(PChar(rsMbRetry), IDRETRY);
-        CreateButton(PChar(rsMbIgnore), IDIGNORE);
-      end;
-    MB_YESNOCANCEL:
-      begin
-        CreateButton(PChar(rsMbYes), IDYES);
-        CreateButton(PChar(rsMbNo), IDNO);
-        CreateButton(PChar(rsMbCancel), IDCANCEL);
-      end;
-    MB_YESNO:
-      begin
-        CreateButton(PChar(rsMbYes), IDYES);
-        CreateButton(PChar(rsMbNo), IDNO);
-      end;
-    MB_RETRYCANCEL:
-      begin
-        CreateButton(PChar(rsMbRetry), IDRETRY);
-        CreateButton(PChar(rsMbCancel), IDCANCEL);
-      end;
+  case (uType and $F0) of
+    MB_ICONINFORMATION:
+      NType := idDialogInfo;
+    MB_ICONWARNING:
+      NType := idDialogWarning;
+    MB_ICONERROR:
+      NType := idDialogError;
+    MB_ICONQUESTION:
+      NType := idDialogConfirm;
     else
-      begin
-        { We have no buttons to show. Create the default of OK button }
-        CreateButton(PChar(rsMbOK), IDOK);
-      end;
+      NType := 0;
   end;
-  gtk_window_set_title(PGtkWindow(Dialog), lpCaption);
-  gtk_window_set_position(PGtkWindow(Dialog), GTK_WIN_POS_CENTER);
-  gtk_window_set_modal(PGtkWindow(Dialog), true);
-  gtk_widget_show_all(Dialog);
-  while ADialogResult = 0 do begin
-    Application.HandleMessage;
+
+  Buttons := TDialogButtons.Create(TDialogButton);
+  try
+    case (uType and $0000000F) of
+      MB_OKCANCEL:
+        begin
+          CreateButton(rsMbOK, mrOK);
+          CreateButton(rsMbCancel, mrCancel);
+        end;
+      MB_ABORTRETRYIGNORE:
+        begin
+          CreateButton(rsMbAbort, mrAbort);
+          CreateButton(rsMbRetry, mrRetry);
+          CreateButton(rsMbIgnore, mrIgnore);
+        end;
+      MB_YESNOCANCEL:
+        begin
+          CreateButton(rsMbYes, mrYes);
+          CreateButton(rsMbNo, mrNo);
+          CreateButton(rsMbCancel, mrCancel);
+        end;
+      MB_YESNO:
+        begin
+          CreateButton(rsMbYes, mrYes);
+          CreateButton(rsMbNo, mrNo);
+        end;
+      MB_RETRYCANCEL:
+        begin
+          CreateButton(rsMbRetry, mrRetry);
+          CreateButton(rsMbCancel, mrCancel);
+        end;
+      else
+        begin
+          { We have no buttons to show. Create the default of OK button }
+          CreateButton(rsMbOK, mrOK);
+        end;
+    end;
+
+    if (NDefIndex >= 0) and (NDefIndex < Buttons.Count) then
+      Buttons.DefaultButton := Buttons[NDefIndex];
+
+    Result := AskUser(
+      string(lpCaption),
+      string(lpText),
+      NType,
+      Buttons,
+      0);
+  finally
+    FreeAndNil(Buttons);
   end;
-  DestroyConnectedWidget(Dialog,true);
-  Result:= ADialogResult;
 end;
 
 {------------------------------------------------------------------------------
msg1.diff (5,269 bytes)   

Issue History

Date Modified Username Field Change
2020-09-27 19:22 CudaText man_ New Issue
2020-10-05 15:38 CudaText man_ Note Added: 0126098
2020-10-05 15:38 CudaText man_ File Added: msg1.diff