From bf09ff2320537ceabf55b3067afec16061c16cb9 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 31 Dec 2017 02:26:22 +0100 Subject: [PATCH 1/3] Remove unused GTK_IS_WX_CELL_EDITOR_BIN* macros No real changes, just don't define macros that we never use and don't plan on using it (why would we need to test whether something is of this type when we already know it). --- src/gtk/dataview.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/gtk/dataview.cpp b/src/gtk/dataview.cpp index 6e102ae7c4..f72a4518fc 100644 --- a/src/gtk/dataview.cpp +++ b/src/gtk/dataview.cpp @@ -1151,8 +1151,6 @@ extern "C" { #define GTK_TYPE_WX_CELL_EDITOR_BIN (gtk_wx_cell_editor_bin_get_type ()) #define GTK_WX_CELL_EDITOR_BIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_CELL_EDITOR_BIN, GtkWxCellEditorBin)) -#define GTK_IS_WX_CELL_EDITOR_BIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_CELL_EDITOR_BIN)) -#define GTK_IS_WX_CELL_EDITOR_BIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_CELL_EDITOR_BIN)) struct GtkWxCellEditorBin { From bde62ce981271fdd93c94909ba2f543e6c75c568 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 31 Dec 2017 02:33:26 +0100 Subject: [PATCH 2/3] Get rid of unused renderer rect in gtk_wx_cell_renderer_new() No real changes, just don't call gtk_wx_cell_renderer_get_size() unnecessarily as we never use its result: the code using the returned rectangle was commented out ever since it was added (more than 10 years ago) in 1e510b1e2d0270caf227c3fc0cf34ae2e7dd6794 --- src/gtk/dataview.cpp | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/src/gtk/dataview.cpp b/src/gtk/dataview.cpp index f72a4518fc..edd9dbcd08 100644 --- a/src/gtk/dataview.cpp +++ b/src/gtk/dataview.cpp @@ -1420,7 +1420,7 @@ gtk_wx_cell_renderer_new (void) static GtkCellEditable *gtk_wx_cell_renderer_start_editing( GtkCellRenderer *renderer, GdkEvent *WXUNUSED(event), - GtkWidget *widget, + GtkWidget *WXUNUSED(widget), const gchar *path, wxConstGdkRect *WXUNUSED(background_area), wxConstGdkRect *cell_area, @@ -1437,25 +1437,10 @@ static GtkCellEditable *gtk_wx_cell_renderer_start_editing( if (cell->GetEditorCtrl()) return NULL; - GdkRectangle rect; - gtk_wx_cell_renderer_get_size (renderer, widget, cell_area, - &rect.x, - &rect.y, - &rect.width, - &rect.height); - - rect.x += cell_area->x; - rect.y += cell_area->y; -// rect.width -= renderer->xpad * 2; -// rect.height -= renderer->ypad * 2; - -// wxRect renderrect(wxRectFromGDKRect(&rect)); - wxRect renderrect(wxRectFromGDKRect(cell_area)); - wxDataViewItem item(cell->GetOwner()->GetOwner()->GTKPathToItem(wxGtkTreePath(path))); - if (!cell->StartEditing(item, renderrect)) + if (!cell->StartEditing(item, wxRectFromGDKRect(cell_area))) return NULL; wxrenderer->editor_bin = gtk_wx_cell_editor_bin_new(cell->GetEditorCtrl()); From 827e90e8deb2add5d10aec1fdb8730dcd05c1248 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 31 Dec 2017 02:28:14 +0100 Subject: [PATCH 3/3] Use GtkHBox as GtkWxCellEditorBin parent with GTK+ < 4 Using GtkBin as widget parent didn't work without overriding its size-related vfuncs until GTK+ 3.8 and, in particular, resulted in the editor (which was the child of the bin) not being visible at all with GTK+ 2. Switch to using GtkHBox as parent, which does work with both GTK+ 2 and any GTK+ 3 version, but keep using GtkBin with GTK+ 4 as GtkHBox is removed in it. This fixes bug introduced in c2821dcea0d88828149c9a1ffe50544564250aa8 since which custom wxDataViewCtrl editors were not visible any more. Closes #17686. --- src/gtk/dataview.cpp | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/gtk/dataview.cpp b/src/gtk/dataview.cpp index edd9dbcd08..e89c058c05 100644 --- a/src/gtk/dataview.cpp +++ b/src/gtk/dataview.cpp @@ -1152,9 +1152,33 @@ extern "C" { #define GTK_TYPE_WX_CELL_EDITOR_BIN (gtk_wx_cell_editor_bin_get_type ()) #define GTK_WX_CELL_EDITOR_BIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_CELL_EDITOR_BIN, GtkWxCellEditorBin)) +// In GTK+ < 3.8 GtkBin can't be used as widget base type without defining our +// own size_allocate and related (either size_request for GTK+ 2 or +// get_preferred_height for GTK+ 3) vfuncs, so we use GtkHBox instead. But in +// GTK+ 4, GtkHBox is removed, so we do use GtkBin with it. +#ifdef __WXGTK4__ + typedef GtkBin GtkWxCellEditorBinBase; + typedef GtkBinClass GtkWxCellEditorBinBaseClass; + + // Notice that this can't be just a (const) variable as GTK+ type constants + // are actually macros expanding into function calls, which shouldn't be + // performed before the library is initialized, so we need to use either an + // inline function or a define, which is simpler. + #define GtkWxCellEditorBinBaseType GTK_TYPE_BIN +#else // GTK+ < 4 + // GtkHBox is deprecated since 3.2, so avoid warnings about using it. + wxGCC_WARNING_SUPPRESS(deprecated-declarations) + + typedef GtkHBox GtkWxCellEditorBinBase; + typedef GtkHBoxClass GtkWxCellEditorBinBaseClass; + #define GtkWxCellEditorBinBaseType GTK_TYPE_HBOX + + wxGCC_WARNING_RESTORE(deprecated-declarations) +#endif // GTK+ version + struct GtkWxCellEditorBin { - GtkBin parent; + GtkWxCellEditorBinBase parent; // The actual user-created editor. wxWindow* editor; @@ -1182,7 +1206,7 @@ gtk_wx_cell_editor_bin_get_type() { const GTypeInfo cell_editor_bin_info = { - sizeof (GtkBinClass), + sizeof (GtkWxCellEditorBinBaseClass), NULL, /* base_init */ NULL, /* base_finalize */ gtk_wx_cell_editor_bin_class_init, @@ -1194,7 +1218,8 @@ gtk_wx_cell_editor_bin_get_type() NULL }; - cell_editor_bin_type = g_type_register_static( GTK_TYPE_BIN, + cell_editor_bin_type = g_type_register_static( + GtkWxCellEditorBinBaseType, "GtkWxCellEditorBin", &cell_editor_bin_info, (GTypeFlags)0 );