View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0037825 | Lazarus | Widgetset | public | 2020-09-27 19:22 | 2020-12-29 18:04 |
Reporter | CudaText man_ | Assigned To | |||
Priority | normal | Severity | minor | Reproducibility | always |
Status | new | Resolution | open | ||
OS | ubuntu 20 x64 | ||||
Product Version | 2.1 (SVN) | ||||
Summary | 0037825: gtk2: LCLIntf.MessageBox doesnt wrap very long text | ||||
Description | demo 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. | ||||
Tags | No tags attached. | ||||
Fixed in Revision | |||||
LazTarget | |||||
Widgetset | GTK 2 | ||||
Attached Files |
|
|
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; {------------------------------------------------------------------------------ |
|
I think this fix is safe. I had tested it. In different msgbox modes. pls apply? |
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 | |
2020-12-29 18:04 | CudaText man_ | Note Added: 0127909 |