aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorColomban Wendling <ban@herbesfolles.org>2016-04-27 16:01:17 +0200
committerColomban Wendling <ban@herbesfolles.org>2016-04-27 16:01:17 +0200
commit77c31b70c5af50ceabe8728e1d80069226f2b199 (patch)
tree97ecc952aad50ae23e9c805fb507a97cf7f5dc88
parent66d16bf968a861fa232d73df7661b9297826c3ab (diff)
downloadscintilla-mirror-77c31b70c5af50ceabe8728e1d80069226f2b199.tar.gz
GTK: Fix auto-completion popup sizing code for GTK 3.20
GTK 3.20's GtkScrolledWinodw doesn't like having a too small allocation and spews scary assertion failures. Fix that by requesting the real size we'd like instead of hard-coding 1 as small-enough value in our overriding height requisition method. The actual value doesn't really matter so long as it's small enough anyway, as we resize the popup to fit later on. Note: this moves the actual implementation of ListBoxX::GetRowHeight() to the new convenience function treeViewGetRowHeight(), with no changes in implementation.
-rw-r--r--gtk/PlatGTK.cxx63
1 files changed, 39 insertions, 24 deletions
diff --git a/gtk/PlatGTK.cxx b/gtk/PlatGTK.cxx
index ed1844963..11aff4313 100644
--- a/gtk/PlatGTK.cxx
+++ b/gtk/PlatGTK.cxx
@@ -1263,6 +1263,31 @@ ListBox *ListBox::Allocate() {
return lb;
}
+static int treeViewGetRowHeight(GtkTreeView *view)
+{
+#if GTK_CHECK_VERSION(3,0,0)
+ // This version sometimes reports erroneous results on GTK2, but the GTK2
+ // version is inaccurate for GTK 3.14.
+ GdkRectangle rect;
+ GtkTreePath *path = gtk_tree_path_new_first();
+ gtk_tree_view_get_background_area(view, path, NULL, &rect);
+ gtk_tree_path_free(path);
+ return rect.height;
+#else
+ int row_height=0;
+ int vertical_separator=0;
+ int expander_size=0;
+ GtkTreeViewColumn *column = gtk_tree_view_get_column(view, 0);
+ gtk_tree_view_column_cell_get_size(column, NULL, NULL, NULL, NULL, &row_height);
+ gtk_widget_style_get(GTK_WIDGET(view),
+ "vertical-separator", &vertical_separator,
+ "expander-size", &expander_size, NULL);
+ row_height += vertical_separator;
+ row_height = Platform::Maximum(row_height, expander_size);
+ return row_height;
+#endif
+}
+
// SmallScroller, a GtkScrolledWindow that can shrink very small, as
// gtk_widget_set_size_request() cannot shrink widgets on GTK3
typedef struct {
@@ -1287,9 +1312,19 @@ G_DEFINE_TYPE(SmallScroller, small_scroller, GTK_TYPE_SCROLLED_WINDOW)
#if GTK_CHECK_VERSION(3,0,0)
static void small_scroller_get_preferred_height(GtkWidget *widget, gint *min, gint *nat) {
- GTK_WIDGET_CLASS(small_scroller_parent_class)->get_preferred_height(widget, min, nat);
- if (*min > 1)
- *min = 1;
+ GtkWidget *child = gtk_bin_get_child(GTK_BIN(widget));
+ if (GTK_IS_TREE_VIEW(child)) {
+ GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(child));
+ int n_rows = gtk_tree_model_iter_n_children(model, NULL);
+ int row_height = treeViewGetRowHeight(GTK_TREE_VIEW(child));
+
+ *min = MAX(1, row_height);
+ *nat = MAX(*min, n_rows * row_height);
+ } else {
+ GTK_WIDGET_CLASS(small_scroller_parent_class)->get_preferred_height(widget, min, nat);
+ if (*min > 1)
+ *min = 1;
+ }
}
#else
static void small_scroller_size_request(GtkWidget *widget, GtkRequisition *req) {
@@ -1488,27 +1523,7 @@ int ListBoxX::GetVisibleRows() const {
int ListBoxX::GetRowHeight()
{
-#if GTK_CHECK_VERSION(3,0,0)
- // This version sometimes reports erroneous results on GTK2, but the GTK2
- // version is inaccurate for GTK 3.14.
- GdkRectangle rect;
- GtkTreePath *path = gtk_tree_path_new_first();
- gtk_tree_view_get_background_area(GTK_TREE_VIEW(list), path, NULL, &rect);
- gtk_tree_path_free(path);
- return rect.height;
-#else
- int row_height=0;
- int vertical_separator=0;
- int expander_size=0;
- GtkTreeViewColumn *column = gtk_tree_view_get_column(GTK_TREE_VIEW(list), 0);
- gtk_tree_view_column_cell_get_size(column, NULL, NULL, NULL, NULL, &row_height);
- gtk_widget_style_get(PWidget(list),
- "vertical-separator", &vertical_separator,
- "expander-size", &expander_size, NULL);
- row_height += vertical_separator;
- row_height = Platform::Maximum(row_height, expander_size);
- return row_height;
-#endif
+ return treeViewGetRowHeight(GTK_TREE_VIEW(list));
}
PRectangle ListBoxX::GetDesiredRect() {