diff --git a/docs/changes.txt b/docs/changes.txt index cf3b6c9ba2..4aefb01833 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -268,6 +268,7 @@ wxGTK: - Fix compilation with GTK 3.22.z and z < 25 (#22816). - Fix compilation with GTK < 2.21.8 (mkirkham, #22830). - Fix display artefacts when using AUI without compositor under X11 (#23135). +- Allow selecting and copying text in wxMessageDialog (Ian McInerney, #23039). wxMSW: diff --git a/src/gtk/msgdlg.cpp b/src/gtk/msgdlg.cpp index b617297f11..b3b4f1add3 100644 --- a/src/gtk/msgdlg.cpp +++ b/src/gtk/msgdlg.cpp @@ -23,6 +23,7 @@ #include "wx/modalhook.h" #include "wx/gtk/private.h" +#include "wx/gtk/private/list.h" #include "wx/gtk/private/messagetype.h" #include "wx/gtk/private/mnemonics.h" #include "wx/gtk/private/dialogcount.h" @@ -187,6 +188,26 @@ void wxMessageDialog::GTKCreateMsgDialog() 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 // Yes/No/Cancel dialog as GTK+ doesn't support it natively const bool addButtons = buttons == GTK_BUTTONS_NONE;