fd556ea
From 115f3749a737de337f6b456dcc84b6e3a6fdfc0e Mon Sep 17 00:00:00 2001
fd556ea
From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= <caolanm@redhat.com>
fd556ea
Date: Thu, 21 Feb 2019 15:57:22 +0000
fd556ea
Subject: [PATCH] menu of currency combobox in format-cells is too narrow
fd556ea
fd556ea
we want the combobox to be narrower than it wants to be.  To make that happen
fd556ea
we have only the option of shrinking the cell renderer of the combobox area.
fd556ea
And that is also used by the menu.
fd556ea
fd556ea
Setting a small value of e.g. 1 works to let the combobox not request more
fd556ea
width than that, and the combobox will correctly render within the wider size
fd556ea
it actually gets. But then the menu is a min width menu, which is undesirable,
fd556ea
we want the menu to be as wide as it can be.
fd556ea
fd556ea
So calculate what part of the combobox belongs to the cell area and set
fd556ea
the widest cell area we can within the overall combobox width, resulting
fd556ea
in the widest menu we can get.
fd556ea
fd556ea
Change-Id: Ie3e9960a320a70471ac21d2a88f32632cafa951f
fd556ea
Reviewed-on: https://gerrit.libreoffice.org/68168
fd556ea
Tested-by: Jenkins
fd556ea
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
fd556ea
---
fd556ea
 cui/source/tabpages/numfmt.cxx |  2 +-
fd556ea
 vcl/unx/gtk3/gtk3gtkinst.cxx   | 23 +++++++++++++++++------
fd556ea
 2 files changed, 18 insertions(+), 7 deletions(-)
fd556ea
fd556ea
diff --git a/cui/source/tabpages/numfmt.cxx b/cui/source/tabpages/numfmt.cxx
fd556ea
index b6a4a8ba4d5c..d202232b951d 100644
fd556ea
--- a/cui/source/tabpages/numfmt.cxx
fd556ea
+++ b/cui/source/tabpages/numfmt.cxx
fd556ea
@@ -234,7 +234,7 @@ SvxNumberFormatTabPage::SvxNumberFormatTabPage(TabPageParent pParent,
fd556ea
     auto nWidth = approximate_char_width() * 26;
fd556ea
     m_xLbCategory->set_size_request(nWidth, m_xLbCategory->get_height_rows(7));
fd556ea
     m_xLbFormat->set_size_request(nWidth, m_xLbFormat->get_height_rows(5));
fd556ea
-    m_xLbCurrency->set_size_request(1, -1);  // width of 1, so real width will be that of its LbFormat sibling
fd556ea
+    m_xLbCurrency->set_size_request(nWidth, -1);  // width of 1, so real width will be that of its LbFormat sibling
fd556ea
 
fd556ea
     // Initially remove the "Automatically" entry.
fd556ea
     m_xLbCurrency->set_active(-1); // First ensure that nothing is selected.
fd556ea
diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx
fd556ea
index a9fdfd3615eb..e81f451f7fa0 100644
fd556ea
--- a/vcl/unx/gtk3/gtk3gtkinst.cxx
fd556ea
+++ b/vcl/unx/gtk3/gtk3gtkinst.cxx
fd556ea
@@ -6978,20 +6978,31 @@ public:
fd556ea
         // tweak the cell render to get a narrower size to stick
fd556ea
         GList* cells = gtk_cell_layout_get_cells(GTK_CELL_LAYOUT(m_pComboBox));
fd556ea
         GtkCellRenderer* cell = static_cast<GtkCellRenderer*>(cells->data);
fd556ea
-        GtkRequisition size;
fd556ea
-        gtk_cell_renderer_get_preferred_size(cell, m_pWidget, &size, nullptr);
fd556ea
-        if (nWidth < size.width)
fd556ea
+
fd556ea
+        if (nWidth != -1)
fd556ea
         {
fd556ea
             // this bit isn't great, I really want to be able to ellipse the text in the comboboxtext itself and let
fd556ea
-            // the popup menu render them in full, in the interim ellipse both
fd556ea
+            // the popup menu render them in full, in the interim ellipse both of them
fd556ea
             g_object_set(G_OBJECT(m_pTextRenderer), "ellipsize", PANGO_ELLIPSIZE_MIDDLE, nullptr);
fd556ea
-            gtk_cell_renderer_set_fixed_size(cell, nWidth, size.height);
fd556ea
+
fd556ea
+            // to find out how much of the width of the combobox belongs to the cell, set
fd556ea
+            // the cell and widget to the min cell width and see what the difference is
fd556ea
+            int min;
fd556ea
+            gtk_cell_renderer_get_preferred_width(cell, m_pWidget, &min, nullptr);
fd556ea
+            gtk_cell_renderer_set_fixed_size(cell, min, -1);
fd556ea
+            gtk_widget_set_size_request(m_pWidget, min, -1);
fd556ea
+            int nNonCellWidth = get_preferred_size().Width() - min;
fd556ea
+
fd556ea
+            // now set the cell to the max width which it can be within the
fd556ea
+            // requested widget width
fd556ea
+            gtk_cell_renderer_set_fixed_size(cell, nWidth - nNonCellWidth, -1);
fd556ea
         }
fd556ea
         else
fd556ea
         {
fd556ea
             g_object_set(G_OBJECT(m_pTextRenderer), "ellipsize", PANGO_ELLIPSIZE_NONE, nullptr);
fd556ea
-            gtk_cell_renderer_set_fixed_size(cell, -1, size.height);
fd556ea
+            gtk_cell_renderer_set_fixed_size(cell, -1, -1);
fd556ea
         }
fd556ea
+
fd556ea
         g_list_free(cells);
fd556ea
 
fd556ea
         gtk_widget_set_size_request(m_pWidget, nWidth, nHeight);
fd556ea
-- 
fd556ea
2.21.0
fd556ea