vcl/unx/gtk3/fpicker/SalGtkFilePicker.cxx | 42 +++++++++++++++++++++++++++--- vcl/unx/gtk3/fpicker/SalGtkFilePicker.hxx | 5 +++ 2 files changed, 44 insertions(+), 3 deletions(-)
New commits: commit 76bd6bf83309c50177fc230231755b8aaffb1e77 Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Fri Mar 7 11:04:12 2025 -0800 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Fri Mar 7 21:41:45 2025 +0100 tdf#162995 gtk4: Add combobox in file dialog after its label First add the label, then the combobox that labels it. This ensures that the label comes first visually, then the combobox for the gtk4 VCL plugin, as is already the case for gen, gtk3 or qt6. This can be seen e.g. in the "File" -> "Open" dialog where using an LTR locale now results in "Version: [Current version]" instead of "[Current version] Version:". ("[Current version]" here refers to the combobox with the "Current version" entry selected.) Change-Id: Ib814bba460ca84a694029107d4a66a274860b716 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182641 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> diff --git a/vcl/unx/gtk3/fpicker/SalGtkFilePicker.cxx b/vcl/unx/gtk3/fpicker/SalGtkFilePicker.cxx index 5919845d067a..d2344fc39627 100644 --- a/vcl/unx/gtk3/fpicker/SalGtkFilePicker.cxx +++ b/vcl/unx/gtk3/fpicker/SalGtkFilePicker.cxx @@ -261,8 +261,8 @@ SalGtkFilePicker::SalGtkFilePicker( const uno::Reference< uno::XComponentContext gtk_box_pack_end( GTK_BOX( m_pHBoxs[i] ), m_pLists[i], false, false, 0 ); gtk_box_pack_end( GTK_BOX( m_pHBoxs[i] ), m_pListLabels[i], false, false, 0 ); #else - gtk_box_append(GTK_BOX(m_pHBoxs[i]), m_pLists[i]); gtk_box_append(GTK_BOX(m_pHBoxs[i]), m_pListLabels[i]); + gtk_box_append(GTK_BOX(m_pHBoxs[i]), m_pLists[i]); #endif gtk_label_set_mnemonic_widget( GTK_LABEL(m_pListLabels[i]), m_pLists[i] ); gtk_box_set_spacing( GTK_BOX( m_pHBoxs[i] ), 12 ); commit 122de03c9693089b2b7b9f26a6faf33d9ecce417 Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Fri Mar 7 10:56:57 2025 -0800 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Fri Mar 7 21:41:36 2025 +0100 tdf#162995 gtk4: Handle file dialog selection changes The GtkFileChooser::selection-changed signal used by the gtk3 VCL plugin no longer exists in GTK 4 and there doesn't seem to be any equivalent new API. In order to still be notified about selection changes in the file dialog, make use of GTK implementation details of the GtkFileChooserDialog to retrieve the GtkColumnView used in the dialog and connect to the GtkSelectionModel::selection-changed signal of its model. With this in place, the "Version" combobox in the file picker triggered via "File" -> "Open" from Writer now has a "Current Version" entry as expected (and seen with gtk3, gen, or qt6) when an ODT file is selected, while the combobox had no entry at all previously when using the gtk4 VCL plugin. (Tested with gtk git main as of commit 739467d16fc465089dcfc4defd5a80dbf1b9d044) Regarding the non-existance of an official GtkFileChooser::selection-changed replacement, see also GNOME forum discussion at [1], which also mentions another workaround: > I ended up implementing the preview by adding atick_callback to the > widget and just checking every frame if the selection changed and then > emitting my own signal. Obviously this is terrible style and goes > against the signal architecture but it will have to do for now, as I > needed the custom preview to display information about a custom > file-type that’s specific to my application. [1] https://discourse.gnome.org/t/gtk4-filechooser-selection-changed-signal-alternative/12180 Change-Id: Ieafea7bead5ed4f419ee21e83679c4834d50fff0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182640 Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> diff --git a/vcl/unx/gtk3/fpicker/SalGtkFilePicker.cxx b/vcl/unx/gtk3/fpicker/SalGtkFilePicker.cxx index 18781c5b41ee..5919845d067a 100644 --- a/vcl/unx/gtk3/fpicker/SalGtkFilePicker.cxx +++ b/vcl/unx/gtk3/fpicker/SalGtkFilePicker.cxx @@ -902,6 +902,29 @@ void SAL_CALL SalGtkFilePicker::setTitle( const OUString& rTitle ) implsetTitle(rTitle); } +#if GTK_CHECK_VERSION(4, 0, 0) +namespace +{ + +GtkColumnView* lcl_findColumnView(GtkWidget* pWidget) +{ + if (GTK_IS_COLUMN_VIEW(pWidget)) + return GTK_COLUMN_VIEW(pWidget); + + GtkWidget* pChild = gtk_widget_get_first_child(GTK_WIDGET(pWidget)); + while (pChild) + { + if (GtkColumnView* pColumnView = lcl_findColumnView(pChild)) + return pColumnView; + pChild = gtk_widget_get_next_sibling(pChild); + } + + return nullptr; +} + +} +#endif + sal_Int16 SAL_CALL SalGtkFilePicker::execute() { SolarMutexGuard g; @@ -937,8 +960,16 @@ sal_Int16 SAL_CALL SalGtkFilePicker::execute() g_signal_connect( GTK_FILE_CHOOSER( m_pDialog ), "selection-changed", G_CALLBACK( selection_changed_cb ), static_cast<gpointer>(this) ); #else - // no replacement in 4-0 that I can see :-( - mnHID_SelectionChange = 0; + // GtkFileChooser::selection-changed was dropped in GTK 4 + // Make use of GTK implementation details to connect to + // GtkSelectionModel::selection-changed signal of the underlying model instead + GtkColumnView* pColumnView = lcl_findColumnView(m_pDialog); + assert(pColumnView && "Couldn't find the file dialog's column view"); + GtkSelectionModel* pSelectionModel = gtk_column_view_get_model(pColumnView); + assert(pSelectionModel); + mnHID_SelectionChange + = g_signal_connect(pSelectionModel, "selection-changed", G_CALLBACK(selection_changed_cb), + static_cast<gpointer>(this)); #endif int btn = GTK_RESPONSE_NO; @@ -1540,7 +1571,12 @@ void SalGtkFilePicker::folder_changed_cb( GtkFileChooser *, SalGtkFilePicker *po pobjFP->impl_directoryChanged( evt ); } +#if !GTK_CHECK_VERSION(4, 0, 0) void SalGtkFilePicker::selection_changed_cb( GtkFileChooser *, SalGtkFilePicker *pobjFP ) +#else +void SalGtkFilePicker::selection_changed_cb(GtkSelectionModel*, guint, guint, + SalGtkFilePicker* pobjFP) +#endif { FilePickerEvent evt; SAL_INFO( "vcl.gtk", "selection_changed, isn't it great " << pobjFP ); diff --git a/vcl/unx/gtk3/fpicker/SalGtkFilePicker.hxx b/vcl/unx/gtk3/fpicker/SalGtkFilePicker.hxx index 93c9d818e755..ddf37a8cdb5c 100644 --- a/vcl/unx/gtk3/fpicker/SalGtkFilePicker.hxx +++ b/vcl/unx/gtk3/fpicker/SalGtkFilePicker.hxx @@ -229,7 +229,12 @@ class SalGtkFilePicker : public SalGtkPicker, public SalGtkFilePicker_Base static void filter_changed_cb( GtkFileChooser *file_chooser, GParamSpec *pspec, SalGtkFilePicker *pobjFP ); static void type_changed_cb( GtkTreeSelection *selection, SalGtkFilePicker *pobjFP ); static void folder_changed_cb (GtkFileChooser *file_chooser, SalGtkFilePicker *pobjFP); +#if !GTK_CHECK_VERSION(4, 0, 0) static void selection_changed_cb (GtkFileChooser *file_chooser, SalGtkFilePicker *pobjFP); +#else + static void selection_changed_cb(GtkSelectionModel* pSelectionModel, guint nPosition, + guint nItemCount, SalGtkFilePicker* pobjFP); +#endif static void update_preview_cb (GtkFileChooser *file_chooser, SalGtkFilePicker *pobjFP); static void dialog_mapped_cb(GtkWidget *widget, SalGtkFilePicker *pobjFP); public: