diff options
| -rw-r--r-- | gtk/PlatGTK.cxx | 63 | 
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() { | 
