Allow selecting and copying text in wxMessageDialog on GTK

Normally the GTK message dialogs have non-selectable text, but that also
means users can't copy the text. This can be inconvenient if the dialog
is used for error messages, since then the error message can't be
copied.

Instead, make the text labels used in the GTK message dialog selectable
to fix that.

See #23039.

(cherry picked from commit a8ea3eda116ae895446fc720943702f0c9c52b90)
This commit is contained in:
Ian McInerney 2022-12-15 22:58:43 +00:00 committed by Vadim Zeitlin
parent 0fd9546295
commit e2470b2c8b
2 changed files with 22 additions and 0 deletions

View File

@ -268,6 +268,7 @@ wxGTK:
- Fix compilation with GTK 3.22.z and z < 25 (#22816). - Fix compilation with GTK 3.22.z and z < 25 (#22816).
- Fix compilation with GTK < 2.21.8 (mkirkham, #22830). - Fix compilation with GTK < 2.21.8 (mkirkham, #22830).
- Fix display artefacts when using AUI without compositor under X11 (#23135). - Fix display artefacts when using AUI without compositor under X11 (#23135).
- Allow selecting and copying text in wxMessageDialog (Ian McInerney, #23039).
wxMSW: wxMSW:

View File

@ -23,6 +23,7 @@
#include "wx/modalhook.h" #include "wx/modalhook.h"
#include "wx/gtk/private.h" #include "wx/gtk/private.h"
#include "wx/gtk/private/list.h"
#include "wx/gtk/private/messagetype.h" #include "wx/gtk/private/messagetype.h"
#include "wx/gtk/private/mnemonics.h" #include "wx/gtk/private/mnemonics.h"
#include "wx/gtk/private/dialogcount.h" #include "wx/gtk/private/dialogcount.h"
@ -187,6 +188,26 @@ void wxMessageDialog::GTKCreateMsgDialog()
gtk_window_set_keep_above(GTK_WINDOW(m_widget), TRUE); gtk_window_set_keep_above(GTK_WINDOW(m_widget), TRUE);
} }
// A GTKMessageDialog usually displays its labels without selection enabled,
// so we enable selection to allow the user to select+copy the text out of
// the dialog.
{
GtkMessageDialog * const msgdlg = GTK_MESSAGE_DIALOG(m_widget);
GtkWidget* const area = gtk_message_dialog_get_message_area(msgdlg);
wxGtkList labels(gtk_container_get_children(GTK_CONTAINER(area)));
for ( GList* elem = labels; elem; elem = elem->next )
{
GtkWidget* const widget = GTK_WIDGET( elem->data );
if ( GTK_IS_LABEL(widget) )
{
gtk_label_set_selectable(GTK_LABEL(widget), TRUE);
}
}
}
// we need to add buttons manually if we use custom labels or always for // we need to add buttons manually if we use custom labels or always for
// Yes/No/Cancel dialog as GTK+ doesn't support it natively // Yes/No/Cancel dialog as GTK+ doesn't support it natively
const bool addButtons = buttons == GTK_BUTTONS_NONE; const bool addButtons = buttons == GTK_BUTTONS_NONE;