d95352c
From c73a30d4574d0a8baeb3945190c93b952b2d4b17 Mon Sep 17 00:00:00 2001
2326f9a
From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= <caolanm@redhat.com>
2326f9a
Date: Thu, 21 Feb 2019 15:57:22 +0000
2326f9a
Subject: [PATCH] menu of currency combobox in format-cells is too narrow
2326f9a
2326f9a
we want the combobox to be narrower than it wants to be.  To make that happen
2326f9a
we have only the option of shrinking the cell renderer of the combobox area.
2326f9a
And that is also used by the menu.
2326f9a
2326f9a
Setting a small value of e.g. 1 works to let the combobox not request more
2326f9a
width than that, and the combobox will correctly render within the wider size
2326f9a
it actually gets. But then the menu is a min width menu, which is undesirable,
2326f9a
we want the menu to be as wide as it can be.
2326f9a
2326f9a
So calculate what part of the combobox belongs to the cell area and set
2326f9a
the widest cell area we can within the overall combobox width, resulting
2326f9a
in the widest menu we can get.
2326f9a
2326f9a
Change-Id: Ie3e9960a320a70471ac21d2a88f32632cafa951f
2326f9a
---
d95352c
 vcl/unx/gtk3/gtk3gtkinst.cxx | 23 +++++++++++++++++------
d95352c
 1 file changed, 17 insertions(+), 6 deletions(-)
2326f9a
2326f9a
diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx
d95352c
index 253698f..e71aec7 100644
2326f9a
--- a/vcl/unx/gtk3/gtk3gtkinst.cxx
2326f9a
+++ b/vcl/unx/gtk3/gtk3gtkinst.cxx
d95352c
@@ -6729,20 +6729,31 @@ public:
2326f9a
         // tweak the cell render to get a narrower size to stick
2326f9a
         GList* cells = gtk_cell_layout_get_cells(GTK_CELL_LAYOUT(m_pComboBox));
2326f9a
         GtkCellRenderer* cell = static_cast<GtkCellRenderer*>(cells->data);
2326f9a
-        GtkRequisition size;
2326f9a
-        gtk_cell_renderer_get_preferred_size(cell, m_pWidget, &size, nullptr);
d95352c
-        if (nWidth < size.width)
2326f9a
+
2326f9a
+        if (nWidth != -1)
d95352c
         {
d95352c
             // this bit isn't great, I really want to be able to ellipse the text in the comboboxtext itself and let
d95352c
-            // the popup menu render them in full, in the interim ellipse both
2326f9a
+            // the popup menu render them in full, in the interim ellipse both of them
d95352c
             g_object_set(G_OBJECT(m_pTextRenderer), "ellipsize", PANGO_ELLIPSIZE_MIDDLE, nullptr);
d95352c
-            gtk_cell_renderer_set_fixed_size(cell, nWidth, size.height);
2326f9a
+
2326f9a
+            // to find out how much of the width of the combobox belongs to the cell, set
2326f9a
+            // the cell and widget to the min cell width and see what the difference is
2326f9a
+            int min;
2326f9a
+            gtk_cell_renderer_get_preferred_width(cell, m_pWidget, &min, nullptr);
2326f9a
+            gtk_cell_renderer_set_fixed_size(cell, min, -1);
2326f9a
+            gtk_widget_set_size_request(m_pWidget, min, -1);
2326f9a
+            int nNonCellWidth = get_preferred_size().Width() - min;
2326f9a
+
2326f9a
+            // now set the cell to the max width which it can be within the
2326f9a
+            // requested widget width
2326f9a
+            gtk_cell_renderer_set_fixed_size(cell, nWidth - nNonCellWidth, -1);
d95352c
         }
d95352c
         else
d95352c
         {
d95352c
             g_object_set(G_OBJECT(m_pTextRenderer), "ellipsize", PANGO_ELLIPSIZE_NONE, nullptr);
d95352c
-            gtk_cell_renderer_set_fixed_size(cell, size.width, size.height);
2326f9a
+            gtk_cell_renderer_set_fixed_size(cell, -1, -1);
d95352c
         }
2326f9a
+
2326f9a
         g_list_free(cells);
2326f9a
 
2326f9a
         gtk_widget_set_size_request(m_pWidget, nWidth, nHeight);
2326f9a
-- 
a18dca2
2.20.1
2326f9a