Просмотр исходного кода

Fix for incorrect text fitting on gtk comboboxes.

fixes #4584
tamasmeszaros 4 лет назад
Родитель
Сommit
2505c0a82d
3 измененных файлов с 74 добавлено и 21 удалено
  1. 46 0
      cmake/modules/FindGTK3.cmake
  2. 8 8
      src/slic3r/CMakeLists.txt
  3. 20 13
      src/slic3r/GUI/PresetComboBoxes.cpp

+ 46 - 0
cmake/modules/FindGTK3.cmake

@@ -0,0 +1,46 @@
+# - Try to find GTK+ 3
+# Once done, this will define
+#
+# GTK3_FOUND - system has GTK+ 3.
+# GTK3_INCLUDE_DIRS - the GTK+ 3. include directories
+# GTK3_LIBRARIES - link these to use GTK+ 3.
+#
+# Copyright (C) 2012 Raphael Kubo da Costa <rakuco@webkit.org>
+# Copyright (C) 2013 Igalia S.L.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND ITS CONTRIBUTORS ``AS
+# IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR ITS
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+find_package(PkgConfig)
+pkg_check_modules(GTK3 QUIET gtk+-3.0)
+set(VERSION_OK TRUE)
+if (GTK3_VERSION)
+if (GTK3_FIND_VERSION_EXACT)
+if (NOT("${GTK3_FIND_VERSION}" VERSION_EQUAL "${GTK3_VERSION}"))
+set(VERSION_OK FALSE)
+endif ()
+else ()
+if ("${GTK3_VERSION}" VERSION_LESS "${GTK3_FIND_VERSION}")
+set(VERSION_OK FALSE)
+endif ()
+endif ()
+endif ()
+include(FindPackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(GTK3 DEFAULT_MSG GTK3_INCLUDE_DIRS GTK3_LIBRARIES VERSION_OK)

+ 8 - 8
src/slic3r/CMakeLists.txt

@@ -256,11 +256,11 @@ if (SLIC3R_PCH AND NOT SLIC3R_SYNTAXONLY)
     add_precompiled_header(libslic3r_gui pchheader.hpp FORCEINCLUDE)
 endif ()
 
-target_include_directories(libslic3r_gui PUBLIC /usr/include/glib-2.0)
-target_include_directories(libslic3r_gui PUBLIC /usr/lib/glib-2.0/include)
-target_include_directories(libslic3r_gui PUBLIC /usr/include/pango-1.0)
-target_include_directories(libslic3r_gui PUBLIC /usr/include/harfbuzz)
-target_include_directories(libslic3r_gui PUBLIC /usr/include/gtk-3.0/)
-target_include_directories(libslic3r_gui PUBLIC /usr/include/cairo/)
-target_include_directories(libslic3r_gui PUBLIC /usr/include/gdk-pixbuf-2.0/)
-target_include_directories(libslic3r_gui PUBLIC /usr/include/atk-1.0/)
+# We need to implement some hacks for wxWidgets and touch the underlying GTK
+# layer and sub-libraries. This forces us to use the include locations of these
+# libraries. No need to link to them, wxWidgets does that already.
+# See PresetComboBox.cpp for the includes and subsequent workarounds.
+if (UNIX AND NOT APPLE)
+    find_package(GTK${SLIC3R_GTK} REQUIRED)
+    target_include_directories(libslic3r_gui PRIVATE ${GTK${SLIC3R_GTK}_INCLUDE_DIRS})
+endif ()

+ 20 - 13
src/slic3r/GUI/PresetComboBoxes.cpp

@@ -32,9 +32,13 @@
 #include "PhysicalPrinterDialog.hpp"
 #include "SavePresetDialog.hpp"
 
-#include <glib-2.0/glib-object.h>
-#include <pango-1.0/pango/pango-layout.h>
-#include <gtk/gtk.h>
+// A workaround for a set of issues related to text fitting into gtk widgets:
+// See e.g.: https://github.com/prusa3d/PrusaSlicer/issues/4584
+#if defined(__WXGTK20__) || defined(__WXGTK3__)
+    #include <glib-2.0/glib-object.h>
+    #include <pango-1.0/pango/pango-layout.h>
+    #include <gtk/gtk.h>
+#endif
 
 using Slic3r::GUI::format_wxstr;
 
@@ -134,8 +138,6 @@ PresetComboBox::PresetComboBox(wxWindow* parent, Preset::Type preset_type, const
         }
         evt.Skip();
     });
-
-//    g_object_set( G_OBJECT( this ), "ellipsize", PANGO_ELLIPSIZE_END, nullptr);
 }
 
 PresetComboBox::~PresetComboBox()
@@ -186,19 +188,24 @@ void PresetComboBox::update_selection()
     SetSelection(m_last_selected);
     SetToolTip(GetString(m_last_selected));
 
-    GList* cells = gtk_cell_layout_get_cells( GTK_CELL_LAYOUT( m_widget ) );
-    if( !cells )
-        return;
+// A workaround for a set of issues related to text fitting into gtk widgets:
+// See e.g.: https://github.com/prusa3d/PrusaSlicer/issues/4584
+#if defined(__WXGTK20__) || defined(__WXGTK3__)
+    GList* cells = gtk_cell_layout_get_cells(GTK_CELL_LAYOUT(m_widget));
 
-    GtkCellRendererText* cell = (GtkCellRendererText *) cells->next->data;
+    // 'cells' contains the GtkCellRendererPixBuf for the icon,
+    // 'cells->next' contains GtkCellRendererText for the text we need to ellipsize
+    if (!cells || !cells->next) return;
 
-    if( !cell )
-        return;
+    auto cell = static_cast<GtkCellRendererText *>(cells->next->data);
+
+    if (!cell) return;
 
-    g_object_set( G_OBJECT( cell ), "ellipsize", PANGO_ELLIPSIZE_END, NULL );
+    g_object_set(G_OBJECT(cell), "ellipsize", PANGO_ELLIPSIZE_END, NULL);
 
     // Only the list of cells must be freed, the renderer isn't ours to free
-    g_list_free( cells );
+    g_list_free(cells);
+#endif
 }
 
 void PresetComboBox::update(std::string select_preset_name)