diff --git a/gtk/Makefile.am b/gtk/Makefile.am index 3bec78fc75..5ecf7301d4 100644 --- a/gtk/Makefile.am +++ b/gtk/Makefile.am @@ -212,7 +212,6 @@ gtk_public_h_sources = \ gtkenums.h \ gtkeventbox.h \ gtkexpander.h \ - gtkextendedcell.h \ gtkextendedlayout.h \ gtkfilechooser.h \ gtkfilechooserbutton.h \ @@ -468,7 +467,6 @@ gtk_base_c_sources = \ gtkentrycompletion.c \ gtkeventbox.c \ gtkexpander.c \ - gtkextendedcell.c \ gtkextendedlayout.c \ gtkfilechooser.c \ gtkfilechooserbutton.c \ diff --git a/gtk/gtk.h b/gtk/gtk.h index 21fd518a40..63e96d519f 100644 --- a/gtk/gtk.h +++ b/gtk/gtk.h @@ -83,7 +83,6 @@ #include #include #include -#include #include #include #include diff --git a/gtk/gtk.symbols b/gtk/gtk.symbols index 3f0815e13b..43c5754ac6 100644 --- a/gtk/gtk.symbols +++ b/gtk/gtk.symbols @@ -719,8 +719,6 @@ gtk_cell_renderer_toggle_set_radio #ifndef GTK_DISABLE_DEPRECATED gtk_cell_view_get_cell_renderers #endif -gtk_cell_view_get_desired_height_of_row -gtk_cell_view_get_desired_width_of_row gtk_cell_view_get_displayed_row gtk_cell_view_get_model gtk_cell_view_get_size_of_row @@ -1505,16 +1503,6 @@ gtk_expander_set_use_underline #endif #endif -#if IN_HEADER(__GTK_EXTENDED_CELL_H__) -#if IN_FILE(__GTK_EXTENDED_CELL_C__) -gtk_extended_cell_get_type G_GNUC_CONST -gtk_extended_cell_get_desired_height -gtk_extended_cell_get_desired_width -gtk_extended_cell_get_height_for_width -gtk_extended_cell_get_width_for_height -#endif -#endif - #if IN_HEADER(__GTK_EXTENDED_LAYOUT_H__) #if IN_FILE(__GTK_EXTENDED_LAYOUT_C__) gtk_extended_layout_get_type G_GNUC_CONST @@ -4819,7 +4807,6 @@ gtk_tree_view_column_get_alignment gtk_tree_view_column_get_cell_renderers #endif gtk_tree_view_column_get_clickable -gtk_tree_view_column_get_desired_size gtk_tree_view_column_get_expand gtk_tree_view_column_get_fixed_width gtk_tree_view_column_get_max_width diff --git a/gtk/gtkcellrenderer.c b/gtk/gtkcellrenderer.c index 03d62a463e..b55b0985ae 100644 --- a/gtk/gtkcellrenderer.c +++ b/gtk/gtkcellrenderer.c @@ -19,15 +19,12 @@ #include "config.h" #include "gtkcellrenderer.h" -#include "gtkextendedcell.h" #include "gtkintl.h" #include "gtkmarshalers.h" #include "gtkprivate.h" #include "gtktreeprivate.h" #include "gtkalias.h" -static void gtk_cell_renderer_init (GtkCellRenderer *cell); -static void gtk_cell_renderer_class_init (GtkCellRendererClass *class); static void gtk_cell_renderer_get_property (GObject *object, guint param_id, GValue *value, @@ -39,28 +36,6 @@ static void gtk_cell_renderer_set_property (GObject *object, static void set_cell_bg_color (GtkCellRenderer *cell, GdkColor *color); -/* Fallback GtkExtendedCell implementation to use remaining ->get_size() implementations */ -static void gtk_cell_renderer_extended_cell_init (GtkExtendedCellIface *iface); -static void gtk_cell_renderer_get_desired_width (GtkExtendedCell *cell, - GtkWidget *widget, - gint *minimum_size, - gint *natural_size); -static void gtk_cell_renderer_get_desired_height (GtkExtendedCell *cell, - GtkWidget *widget, - gint *minimum_size, - gint *natural_size); -static void gtk_cell_renderer_get_height_for_width (GtkExtendedCell *cell, - GtkWidget *widget, - gint width, - gint *minimum_height, - gint *natural_height); -static void gtk_cell_renderer_get_width_for_height (GtkExtendedCell *cell, - GtkWidget *widget, - gint height, - gint *minimum_width, - gint *natural_width); - - #define GTK_CELL_RENDERER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_CELL_RENDERER, GtkCellRendererPrivate)) @@ -97,50 +72,9 @@ enum { LAST_SIGNAL }; -static guint cell_renderer_signals[LAST_SIGNAL] = { 0 }; - - -/* Do a manual _get_type() here to avoid a deadlock implementing - * the interface which we are a prerequisite of. - */ -GType -gtk_cell_renderer_get_type (void) -{ - static GType cell_renderer_type = 0; - - if (G_UNLIKELY (cell_renderer_type == 0)) - { - const GTypeInfo cell_renderer_info = - { - sizeof (GtkCellRendererClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) gtk_cell_renderer_class_init, - NULL, /* class_finalize */ - NULL, /* class_init */ - sizeof (GtkCellRenderer), - 0, /* n_preallocs */ - (GInstanceInitFunc) gtk_cell_renderer_init, - NULL, /* value_table */ - }; - - const GInterfaceInfo extended_cell_info = - { - (GInterfaceInitFunc) gtk_cell_renderer_extended_cell_init, - (GInterfaceFinalizeFunc) NULL, - NULL /* interface data */ - }; - - cell_renderer_type = g_type_register_static (GTK_TYPE_OBJECT, "GtkCellRenderer", - &cell_renderer_info, G_TYPE_FLAG_ABSTRACT); - - g_type_add_interface_static (cell_renderer_type, GTK_TYPE_EXTENDED_CELL, - &extended_cell_info) ; - } - - return cell_renderer_type; -} +static guint cell_renderer_signals[LAST_SIGNAL] = { 0 }; +G_DEFINE_ABSTRACT_TYPE (GtkCellRenderer, gtk_cell_renderer, GTK_TYPE_OBJECT) static void gtk_cell_renderer_init (GtkCellRenderer *cell) @@ -1056,96 +990,5 @@ gtk_cell_renderer_stop_editing (GtkCellRenderer *cell, } } -static void -gtk_cell_renderer_extended_cell_init (GtkExtendedCellIface *iface) -{ - iface->get_desired_width = gtk_cell_renderer_get_desired_width; - iface->get_desired_height = gtk_cell_renderer_get_desired_height; - - iface->get_width_for_height = gtk_cell_renderer_get_width_for_height; - iface->get_height_for_width = gtk_cell_renderer_get_height_for_width; -} - -static void -gtk_cell_renderer_get_desired_size (GtkExtendedCell *cell, - GtkWidget *widget, - GtkOrientation orientation, - gint *minimum_size, - gint *natural_size) -{ - GtkRequisition min_req; - - /* Fallback on the old API to get the size. */ - if (GTK_CELL_RENDERER_GET_CLASS (cell)->get_size) - gtk_cell_renderer_get_size (GTK_CELL_RENDERER (cell), widget, NULL, NULL, NULL, - &min_req.width, &min_req.height); - else - { - min_req.width = 0; - min_req.height = 0; - } - - if (orientation == GTK_ORIENTATION_HORIZONTAL) - { - if (minimum_size) - *minimum_size = min_req.width; - - if (natural_size) - *natural_size = min_req.width; - } - else - { - if (minimum_size) - *minimum_size = min_req.height; - - if (natural_size) - *natural_size = min_req.height; - } -} - -static void -gtk_cell_renderer_get_desired_width (GtkExtendedCell *cell, - GtkWidget *widget, - gint *minimum_size, - gint *natural_size) -{ - gtk_cell_renderer_get_desired_size (cell, widget, GTK_ORIENTATION_HORIZONTAL, - minimum_size, natural_size); -} - -static void -gtk_cell_renderer_get_desired_height (GtkExtendedCell *cell, - GtkWidget *widget, - gint *minimum_size, - gint *natural_size) -{ - gtk_cell_renderer_get_desired_size (cell, widget, GTK_ORIENTATION_VERTICAL, - minimum_size, natural_size); -} - - -static void -gtk_cell_renderer_get_height_for_width (GtkExtendedCell *cell, - GtkWidget *widget, - gint width, - gint *minimum_height, - gint *natural_height) -{ - /* Fall back on the height reported from ->get_size() */ - gtk_extended_cell_get_desired_height (cell, widget, minimum_height, natural_height); -} - -static void -gtk_cell_renderer_get_width_for_height (GtkExtendedCell *cell, - GtkWidget *widget, - gint height, - gint *minimum_width, - gint *natural_width) -{ - /* Fall back on the width reported from ->get_size() */ - gtk_extended_cell_get_desired_width (cell, widget, minimum_width, natural_width); -} - - #define __GTK_CELL_RENDERER_C__ #include "gtkaliasdef.c" diff --git a/gtk/gtkcellrenderertext.c b/gtk/gtkcellrenderertext.c index 859bcc1a19..8060ade4ac 100644 --- a/gtk/gtkcellrenderertext.c +++ b/gtk/gtkcellrenderertext.c @@ -21,7 +21,6 @@ #include #include "gtkcellrenderertext.h" #include "gtkeditable.h" -#include "gtkextendedcell.h" #include "gtkentry.h" #include "gtkmarshalers.h" #include "gtkintl.h" @@ -62,16 +61,6 @@ static GtkCellEditable *gtk_cell_renderer_text_start_editing (GtkCellRenderer GdkRectangle *cell_area, GtkCellRendererState flags); -static void gtk_cell_renderer_text_extended_cell_init (GtkExtendedCellIface *iface); -static void gtk_cell_renderer_text_get_desired_width (GtkExtendedCell *cell, - GtkWidget *widget, - gint *minimal_size, - gint *desired_size); -static void gtk_cell_renderer_text_get_desired_height (GtkExtendedCell *cell, - GtkWidget *widget, - gint *minimal_size, - gint *desired_size); - enum { EDITED, LAST_SIGNAL @@ -161,9 +150,7 @@ struct _GtkCellRendererTextPrivate GtkWidget *entry; }; -G_DEFINE_TYPE_WITH_CODE (GtkCellRendererText, gtk_cell_renderer_text, GTK_TYPE_CELL_RENDERER, - G_IMPLEMENT_INTERFACE (GTK_TYPE_EXTENDED_CELL, - gtk_cell_renderer_text_extended_cell_init)) +G_DEFINE_TYPE (GtkCellRendererText, gtk_cell_renderer_text, GTK_TYPE_CELL_RENDERER) static void gtk_cell_renderer_text_init (GtkCellRendererText *celltext) @@ -1943,80 +1930,5 @@ gtk_cell_renderer_text_set_fixed_height_from_font (GtkCellRendererText *renderer } } -static void -gtk_cell_renderer_text_extended_cell_init (GtkExtendedCellIface *iface) -{ - /* Currently cell renderers do natural widths for ellipsizing text - * but dont yet do height-for-width/width-for-height calculations for - * wordwrapping - */ - iface->get_desired_width = gtk_cell_renderer_text_get_desired_width; - iface->get_desired_height = gtk_cell_renderer_text_get_desired_height; -} - -static void -gtk_cell_renderer_text_get_desired_size (GtkExtendedCell *cell, - GtkWidget *widget, - GtkOrientation orientation, - gint *minimal_size, - gint *desired_size) -{ - GtkCellRendererTextPrivate *priv; - - priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (cell); - - if (minimal_size) - { - if (orientation == GTK_ORIENTATION_HORIZONTAL) - get_size (GTK_CELL_RENDERER (cell), - widget, NULL, NULL, NULL, NULL, - minimal_size, NULL); - else - get_size (GTK_CELL_RENDERER (cell), - widget, NULL, NULL, NULL, NULL, - NULL, minimal_size); - } - - if (desired_size) - { - PangoEllipsizeMode ellipsize; - - ellipsize = priv->ellipsize; - priv->ellipsize = PANGO_ELLIPSIZE_NONE; - - if (orientation == GTK_ORIENTATION_HORIZONTAL) - get_size (GTK_CELL_RENDERER (cell), - widget, NULL, NULL, NULL, NULL, - desired_size, NULL); - else - get_size (GTK_CELL_RENDERER (cell), - widget, NULL, NULL, NULL, NULL, - NULL, desired_size); - - priv->ellipsize = ellipsize; - } -} - -static void -gtk_cell_renderer_text_get_desired_width (GtkExtendedCell *cell, - GtkWidget *widget, - gint *minimum_size, - gint *desired_size) -{ - gtk_cell_renderer_text_get_desired_size (cell, widget, GTK_ORIENTATION_HORIZONTAL, - minimum_size, desired_size); -} - -static void -gtk_cell_renderer_text_get_desired_height (GtkExtendedCell *cell, - GtkWidget *widget, - gint *minimum_size, - gint *desired_size) -{ - gtk_cell_renderer_text_get_desired_size (cell, widget, GTK_ORIENTATION_VERTICAL, - minimum_size, desired_size); -} - - #define __GTK_CELL_RENDERER_TEXT_C__ #include "gtkaliasdef.c" diff --git a/gtk/gtkcellview.c b/gtk/gtkcellview.c index a85c0d7b9a..0dd98b0a76 100644 --- a/gtk/gtkcellview.c +++ b/gtk/gtkcellview.c @@ -24,8 +24,6 @@ #include "gtkintl.h" #include "gtkcellrenderertext.h" #include "gtkcellrendererpixbuf.h" -#include "gtkextendedlayout.h" -#include "gtkextendedcell.h" #include "gtkprivate.h" #include #include "gtkbuildable.h" @@ -37,7 +35,6 @@ struct _GtkCellViewCellInfo GtkCellRenderer *cell; gint requested_width; - gint natural_width; gint real_width; guint expand : 1; guint pack : 1; @@ -71,6 +68,8 @@ static void gtk_cell_view_set_property (GObject *obj const GValue *value, GParamSpec *pspec); static void gtk_cell_view_finalize (GObject *object); +static void gtk_cell_view_size_request (GtkWidget *widget, + GtkRequisition *requisition); static void gtk_cell_view_size_allocate (GtkWidget *widget, GtkAllocation *allocation); static gboolean gtk_cell_view_expose (GtkWidget *widget, @@ -121,14 +120,6 @@ static void gtk_cell_view_buildable_custom_tag_end (GtkBuildable const gchar *tagname, gpointer *data); -static void gtk_cell_view_extended_layout_init (GtkExtendedLayoutIface *iface); -static void gtk_cell_view_get_desired_width (GtkExtendedLayout *layout, - gint *minimum_size, - gint *natural_size); -static void gtk_cell_view_get_desired_height (GtkExtendedLayout *layout, - gint *minimum_size, - gint *natural_size); - static GtkBuildableIface *parent_buildable_iface; #define GTK_CELL_VIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_CELL_VIEW, GtkCellViewPrivate)) @@ -146,10 +137,7 @@ G_DEFINE_TYPE_WITH_CODE (GtkCellView, gtk_cell_view, GTK_TYPE_WIDGET, G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT, gtk_cell_view_cell_layout_init) G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE, - gtk_cell_view_buildable_init) - G_IMPLEMENT_INTERFACE (GTK_TYPE_EXTENDED_LAYOUT, - gtk_cell_view_extended_layout_init)) - + gtk_cell_view_buildable_init)) static void gtk_cell_view_class_init (GtkCellViewClass *klass) @@ -163,6 +151,7 @@ gtk_cell_view_class_init (GtkCellViewClass *klass) widget_class->expose_event = gtk_cell_view_expose; widget_class->size_allocate = gtk_cell_view_size_allocate; + widget_class->size_request = gtk_cell_view_size_request; /* properties */ g_object_class_install_property (gobject_class, @@ -320,16 +309,53 @@ gtk_cell_view_finalize (GObject *object) G_OBJECT_CLASS (gtk_cell_view_parent_class)->finalize (object); } +static void +gtk_cell_view_size_request (GtkWidget *widget, + GtkRequisition *requisition) +{ + GList *i; + gboolean first_cell = TRUE; + GtkCellView *cellview; + + cellview = GTK_CELL_VIEW (widget); + + requisition->width = 0; + requisition->height = 0; + + if (cellview->priv->displayed_row) + gtk_cell_view_set_cell_data (cellview); + + for (i = cellview->priv->cell_list; i; i = i->next) + { + gint width, height; + GtkCellViewCellInfo *info = (GtkCellViewCellInfo *)i->data; + + if (!info->cell->visible) + continue; + + if (!first_cell) + requisition->width += cellview->priv->spacing; + + gtk_cell_renderer_get_size (info->cell, widget, NULL, NULL, NULL, + &width, &height); + + info->requested_width = width; + requisition->width += width; + requisition->height = MAX (requisition->height, height); + + first_cell = FALSE; + } +} + static void gtk_cell_view_size_allocate (GtkWidget *widget, GtkAllocation *allocation) { - GtkCellView *cellview; GList *i; - gint nexpand_cells = 0; - gint requested_width = 0; - gint natural_width = 0; - gint available, natural, extra; + gint expand_cell_count = 0; + gint full_requested_width = 0; + gint extra_space; + GtkCellView *cellview; widget->allocation = *allocation; @@ -344,20 +370,16 @@ gtk_cell_view_size_allocate (GtkWidget *widget, continue; if (info->expand) - nexpand_cells++; + expand_cell_count++; - requested_width += info->requested_width; - natural_width += info->natural_width - info->requested_width; + full_requested_width += info->requested_width; } - available = MAX (0, widget->allocation.width - requested_width); - natural = MIN (available, natural_width); - available -= natural; - - if (nexpand_cells > 0) - extra = available / nexpand_cells; - else - extra = 0; + extra_space = widget->allocation.width - full_requested_width; + if (extra_space < 0) + extra_space = 0; + else if (extra_space > 0 && expand_cell_count > 0) + extra_space /= expand_cell_count; for (i = cellview->priv->cell_list; i; i = i->next) { @@ -366,21 +388,8 @@ gtk_cell_view_size_allocate (GtkWidget *widget, if (!info->cell->visible) continue; - info->real_width = info->requested_width; - - if (natural_width > 0) - info->real_width += natural * (info->natural_width - info->requested_width) / natural_width; - - if (info->expand) - { - if (nexpand_cells == 1) - info->real_width += available; - else - info->real_width += extra; - - nexpand_cells -= 1; - available -= extra; - } + info->real_width = info->requested_width + + (info->expand ? extra_space : 0); } } @@ -571,8 +580,6 @@ gtk_cell_view_cell_layout_pack_start (GtkCellLayout *layout, info->pack = GTK_PACK_START; cellview->priv->cell_list = g_list_append (cellview->priv->cell_list, info); - - gtk_widget_queue_resize (GTK_WIDGET (cellview)); } static void @@ -593,8 +600,6 @@ gtk_cell_view_cell_layout_pack_end (GtkCellLayout *layout, info->pack = GTK_PACK_END; cellview->priv->cell_list = g_list_append (cellview->priv->cell_list, info); - - gtk_widget_queue_resize (GTK_WIDGET (cellview)); } static void @@ -974,108 +979,32 @@ gtk_cell_view_get_displayed_row (GtkCellView *cell_view) * Return value: %TRUE * * Since: 2.6 - * - * Deprecated: 3.0: Use gtk_cell_view_get_desired_width_of_row() and - * gtk_cell_view_get_desired_height_of_row() instead. */ gboolean gtk_cell_view_get_size_of_row (GtkCellView *cell_view, GtkTreePath *path, GtkRequisition *requisition) { + GtkTreeRowReference *tmp; GtkRequisition req; g_return_val_if_fail (GTK_IS_CELL_VIEW (cell_view), FALSE); g_return_val_if_fail (path != NULL, FALSE); - - gtk_cell_view_get_desired_width_of_row (cell_view, path, &req.width, NULL); - gtk_cell_view_get_desired_height_of_row (cell_view, path, &req.height, NULL); - - if (requisition) - *requisition = req; - - return TRUE; -} - - - -static void -gtk_cell_view_get_desired_size_of_row (GtkCellView *cell_view, - GtkTreePath *path, - GtkOrientation orientation, - gint *minimum_size, - gint *natural_size) -{ - GtkTreeRowReference *tmp; + g_return_val_if_fail (requisition != NULL, FALSE); tmp = cell_view->priv->displayed_row; cell_view->priv->displayed_row = gtk_tree_row_reference_new (cell_view->priv->model, path); - if (orientation == GTK_ORIENTATION_HORIZONTAL) - gtk_cell_view_get_desired_width (GTK_EXTENDED_LAYOUT (cell_view), minimum_size, natural_size); - else - gtk_cell_view_get_desired_height (GTK_EXTENDED_LAYOUT (cell_view), minimum_size, natural_size); + gtk_cell_view_size_request (GTK_WIDGET (cell_view), requisition); gtk_tree_row_reference_free (cell_view->priv->displayed_row); cell_view->priv->displayed_row = tmp; - /* Restore active size */ - if (orientation == GTK_ORIENTATION_HORIZONTAL) - gtk_cell_view_get_desired_width (GTK_EXTENDED_LAYOUT (cell_view), NULL, NULL); - else - gtk_cell_view_get_desired_height (GTK_EXTENDED_LAYOUT (cell_view), NULL, NULL); -} + /* restore actual size info */ + gtk_cell_view_size_request (GTK_WIDGET (cell_view), &req); -/** - * gtk_cell_view_get_desired_width_of_row: - * @cell_view: a #GtkCellView - * @path: a #GtkTreePath - * @minimum_size: location to store the minimum size - * @natural_size: location to store the natural size - * - * Sets @minimum_size and @natural_size to the width desired by @cell_view - * to display the model row pointed to by @path. - * - * Since: 3.0 - */ -void -gtk_cell_view_get_desired_width_of_row (GtkCellView *cell_view, - GtkTreePath *path, - gint *minimum_size, - gint *natural_size) -{ - g_return_if_fail (GTK_IS_CELL_VIEW (cell_view)); - g_return_if_fail (path != NULL); - g_return_if_fail (minimum_size != NULL || natural_size != NULL); - - gtk_cell_view_get_desired_size_of_row (cell_view, path, GTK_ORIENTATION_HORIZONTAL, minimum_size, natural_size); -} - - -/** - * gtk_cell_view_get_desired_height_of_row: - * @cell_view: a #GtkCellView - * @path: a #GtkTreePath - * @minimum_size: location to store the minimum size - * @natural_size: location to store the natural size - * - * Sets @minimum_size and @natural_size to the height desired by @cell_view - * to display the model row pointed to by @path. - * - * Since: 3.0 - */ -void -gtk_cell_view_get_desired_height_of_row (GtkCellView *cell_view, - GtkTreePath *path, - gint *minimum_size, - gint *natural_size) -{ - g_return_if_fail (GTK_IS_CELL_VIEW (cell_view)); - g_return_if_fail (path != NULL); - g_return_if_fail (minimum_size != NULL || natural_size != NULL); - - gtk_cell_view_get_desired_size_of_row (cell_view, path, GTK_ORIENTATION_VERTICAL, minimum_size, natural_size); + return TRUE; } /** @@ -1188,88 +1117,5 @@ gtk_cell_view_buildable_custom_tag_end (GtkBuildable *buildable, } -static void -gtk_cell_view_extended_layout_init (GtkExtendedLayoutIface *iface) -{ - iface->get_desired_width = gtk_cell_view_get_desired_width; - iface->get_desired_height = gtk_cell_view_get_desired_height; -} - -static void -gtk_cell_view_get_desired_size (GtkExtendedLayout *layout, - GtkOrientation orientation, - gint *minimum_size, - gint *natural_size) -{ - GList *i; - gint cell_min, cell_nat; - gboolean first_cell = TRUE; - GtkCellView *cellview = GTK_CELL_VIEW (layout); - gint minimum, natural; - - minimum = natural = 0; - - if (cellview->priv->displayed_row) - gtk_cell_view_set_cell_data (cellview); - - for (i = cellview->priv->cell_list; i; i = i->next) - { - GtkCellViewCellInfo *info = (GtkCellViewCellInfo *)i->data; - - if (info->cell->visible) - { - - if (!first_cell && orientation == GTK_ORIENTATION_HORIZONTAL) - { - minimum += cellview->priv->spacing; - natural += cellview->priv->spacing; - } - - if (orientation == GTK_ORIENTATION_HORIZONTAL) - { - gtk_extended_cell_get_desired_width (GTK_EXTENDED_CELL (info->cell), - GTK_WIDGET (cellview), &cell_min, &cell_nat); - - info->requested_width = cell_min; - info->natural_width = cell_nat; - - minimum += info->requested_width; - natural += info->natural_width; - } - else - { - gtk_extended_cell_get_desired_height (GTK_EXTENDED_CELL (info->cell), - GTK_WIDGET (cellview), &cell_min, &cell_nat); - minimum = MAX (minimum, cell_min); - natural = MAX (natural, cell_nat); - } - first_cell = FALSE; - } - } - - if (minimum_size) - *minimum_size = minimum; - - if (natural_size) - *natural_size = natural; -} - -static void -gtk_cell_view_get_desired_width (GtkExtendedLayout *layout, - gint *minimum_size, - gint *natural_size) -{ - gtk_cell_view_get_desired_size (layout, GTK_ORIENTATION_HORIZONTAL, minimum_size, natural_size); -} - -static void -gtk_cell_view_get_desired_height (GtkExtendedLayout *layout, - gint *minimum_size, - gint *natural_size) -{ - gtk_cell_view_get_desired_size (layout, GTK_ORIENTATION_VERTICAL, minimum_size, natural_size); -} - - #define __GTK_CELL_VIEW_C__ #include "gtkaliasdef.c" diff --git a/gtk/gtkcellview.h b/gtk/gtkcellview.h index 3d83ad1800..73de84e191 100644 --- a/gtk/gtkcellview.h +++ b/gtk/gtkcellview.h @@ -69,17 +69,6 @@ GtkTreePath *gtk_cell_view_get_displayed_row (GtkCellView *cell_v gboolean gtk_cell_view_get_size_of_row (GtkCellView *cell_view, GtkTreePath *path, GtkRequisition *requisition); -gboolean gtk_cell_view_get_size_of_row (GtkCellView *cell_view, - GtkTreePath *path, - GtkRequisition *requisition); -void gtk_cell_view_get_desired_width_of_row(GtkCellView *cell_view, - GtkTreePath *path, - gint *minimum_size, - gint *natural_size); -void gtk_cell_view_get_desired_height_of_row(GtkCellView *cell_view, - GtkTreePath *path, - gint *minimum_size, - gint *natural_size); void gtk_cell_view_set_background_color (GtkCellView *cell_view, const GdkColor *color); diff --git a/gtk/gtkcombobox.c b/gtk/gtkcombobox.c index 5a5f3b94a0..fd92dd0d5d 100644 --- a/gtk/gtkcombobox.c +++ b/gtk/gtkcombobox.c @@ -38,7 +38,6 @@ #include "gtktreeselection.h" #include "gtkvseparator.h" #include "gtkwindow.h" -#include "gtkextendedlayout.h" #include "gtkprivate.h" #include @@ -110,9 +109,8 @@ struct _GtkComboBoxPrivate guint scroll_timer; guint resize_idle_id; - GtkRequisition minimum_size; - GtkRequisition natural_size; - + gint width; + gint height; GSList *cells; guint popup_in_progress : 1; @@ -279,6 +277,8 @@ static void gtk_combo_box_remeasure (GtkComboBox *combo_box) static void gtk_combo_box_unset_model (GtkComboBox *combo_box); +static void gtk_combo_box_size_request (GtkWidget *widget, + GtkRequisition *requisition); static void gtk_combo_box_size_allocate (GtkWidget *widget, GtkAllocation *allocation); static void gtk_combo_box_forall (GtkContainer *container, @@ -463,16 +463,8 @@ static void gtk_combo_box_buildable_custom_tag_end (GtkBuildable *bui gpointer *data); /* GtkCellEditable method implementations */ -static void gtk_combo_box_start_editing (GtkCellEditable *cell_editable, - GdkEvent *event); - -static void gtk_combo_box_extended_layout_init (GtkExtendedLayoutIface *iface); -static void gtk_combo_box_get_desired_width (GtkExtendedLayout *layout, - gint *minimum_size, - gint *natural_size); -static void gtk_combo_box_get_desired_height (GtkExtendedLayout *layout, - gint *minimum_size, - gint *natural_size); +static void gtk_combo_box_start_editing (GtkCellEditable *cell_editable, + GdkEvent *event); G_DEFINE_TYPE_WITH_CODE (GtkComboBox, gtk_combo_box, GTK_TYPE_BIN, @@ -481,9 +473,7 @@ G_DEFINE_TYPE_WITH_CODE (GtkComboBox, gtk_combo_box, GTK_TYPE_BIN, G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE, gtk_combo_box_cell_editable_init) G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE, - gtk_combo_box_buildable_init) - G_IMPLEMENT_INTERFACE (GTK_TYPE_EXTENDED_LAYOUT, - gtk_combo_box_extended_layout_init)) + gtk_combo_box_buildable_init)) /* common */ @@ -505,6 +495,7 @@ gtk_combo_box_class_init (GtkComboBoxClass *klass) widget_class = (GtkWidgetClass *)klass; widget_class->size_allocate = gtk_combo_box_size_allocate; + widget_class->size_request = gtk_combo_box_size_request; widget_class->expose_event = gtk_combo_box_expose_event; widget_class->scroll_event = gtk_combo_box_scroll_event; widget_class->mnemonic_activate = gtk_combo_box_mnemonic_activate; @@ -941,9 +932,8 @@ gtk_combo_box_init (GtkComboBox *combo_box) GTK_BIN (combo_box)->child = priv->cell_view; gtk_widget_show (priv->cell_view); - memset (&priv->minimum_size, 0x0, sizeof (GtkRequisition)); - memset (&priv->natural_size, 0x0, sizeof (GtkRequisition)); - + priv->width = 0; + priv->height = 0; priv->wrap_width = 0; priv->active = -1; @@ -2057,6 +2047,164 @@ gtk_combo_box_calc_requested_width (GtkComboBox *combo_box, return req.width + padding; } +static void +gtk_combo_box_remeasure (GtkComboBox *combo_box) +{ + GtkComboBoxPrivate *priv = combo_box->priv; + GtkTreeIter iter; + GtkTreePath *path; + + if (!priv->model || + !gtk_tree_model_get_iter_first (priv->model, &iter)) + return; + + priv->width = 0; + priv->height = 0; + + path = gtk_tree_path_new_from_indices (0, -1); + + do + { + GtkRequisition req; + + if (priv->cell_view) + gtk_cell_view_get_size_of_row (GTK_CELL_VIEW (priv->cell_view), + path, &req); + else + { + req.width = 0; + req.height = 0; + } + + priv->width = MAX (priv->width, req.width); + priv->height = MAX (priv->height, req.height); + + gtk_tree_path_next (path); + } + while (gtk_tree_model_iter_next (priv->model, &iter)); + + gtk_tree_path_free (path); +} + +static void +gtk_combo_box_size_request (GtkWidget *widget, + GtkRequisition *requisition) +{ + gint width, height; + gint focus_width, focus_pad; + gint font_size; + gint arrow_size; + GtkRequisition bin_req; + PangoContext *context; + PangoFontMetrics *metrics; + PangoFontDescription *font_desc; + + GtkComboBox *combo_box = GTK_COMBO_BOX (widget); + GtkComboBoxPrivate *priv = combo_box->priv; + + /* common */ + gtk_widget_size_request (GTK_BIN (widget)->child, &bin_req); + gtk_combo_box_remeasure (combo_box); + bin_req.width = MAX (bin_req.width, priv->width); + bin_req.height = MAX (bin_req.height, priv->height); + + gtk_widget_style_get (GTK_WIDGET (widget), + "focus-line-width", &focus_width, + "focus-padding", &focus_pad, + "arrow-size", &arrow_size, + NULL); + + font_desc = GTK_BIN (widget)->child->style->font_desc; + context = gtk_widget_get_pango_context (widget); + metrics = pango_context_get_metrics (context, font_desc, + pango_context_get_language (context)); + font_size = PANGO_PIXELS (pango_font_metrics_get_ascent (metrics) + + pango_font_metrics_get_descent (metrics)); + pango_font_metrics_unref (metrics); + + arrow_size = MAX (arrow_size, font_size); + + gtk_widget_set_size_request (priv->arrow, arrow_size, arrow_size); + + if (!priv->tree_view) + { + /* menu mode */ + + if (priv->cell_view) + { + GtkRequisition button_req, sep_req, arrow_req; + gint border_width, xthickness, ythickness; + + gtk_widget_size_request (priv->button, &button_req); + border_width = GTK_CONTAINER (combo_box)->border_width; + xthickness = priv->button->style->xthickness; + ythickness = priv->button->style->ythickness; + + bin_req.width = MAX (bin_req.width, priv->width); + bin_req.height = MAX (bin_req.height, priv->height); + + gtk_widget_size_request (priv->separator, &sep_req); + gtk_widget_size_request (priv->arrow, &arrow_req); + + height = MAX (sep_req.height, arrow_req.height); + height = MAX (height, bin_req.height); + + width = bin_req.width + sep_req.width + arrow_req.width; + + height += 2*(border_width + ythickness + focus_width + focus_pad); + width += 2*(border_width + xthickness + focus_width + focus_pad); + + requisition->width = width; + requisition->height = height; + } + else + { + GtkRequisition but_req; + + gtk_widget_size_request (priv->button, &but_req); + + requisition->width = bin_req.width + but_req.width; + requisition->height = MAX (bin_req.height, but_req.height); + } + } + else + { + /* list mode */ + GtkRequisition button_req, frame_req; + + /* sample + frame */ + *requisition = bin_req; + + requisition->width += 2 * focus_width; + + if (priv->cell_view_frame) + { + gtk_widget_size_request (priv->cell_view_frame, &frame_req); + if (priv->has_frame) + { + requisition->width += 2 * + (GTK_CONTAINER (priv->cell_view_frame)->border_width + + GTK_WIDGET (priv->cell_view_frame)->style->xthickness); + requisition->height += 2 * + (GTK_CONTAINER (priv->cell_view_frame)->border_width + + GTK_WIDGET (priv->cell_view_frame)->style->ythickness); + } + } + + /* the button */ + gtk_widget_size_request (priv->button, &button_req); + + requisition->height = MAX (requisition->height, button_req.height); + requisition->width += button_req.width; + } + + if (GTK_SHADOW_NONE != priv->shadow_type) + { + requisition->height += 2 * widget->style->ythickness; + requisition->width += 2 * widget->style->xthickness; + } +} + #define GTK_COMBO_BOX_SIZE_ALLOCATE_BUTTON \ gtk_widget_size_request (combo_box->priv->button, &req); \ \ @@ -3507,14 +3655,14 @@ gtk_combo_box_menu_row_changed (GtkTreeModel *model, width = gtk_combo_box_calc_requested_width (combo_box, path); - if (width > priv->minimum_size.width) + if (width > priv->width) { if (priv->cell_view) { gtk_widget_set_size_request (priv->cell_view, width, -1); gtk_widget_queue_resize (priv->cell_view); } - priv->minimum_size.width = width; + priv->width = width; } } @@ -4020,14 +4168,14 @@ gtk_combo_box_list_row_changed (GtkTreeModel *model, width = gtk_combo_box_calc_requested_width (combo_box, path); - if (width > priv->minimum_size.width) + if (width > priv->width) { if (priv->cell_view) { gtk_widget_set_size_request (priv->cell_view, width, -1); gtk_widget_queue_resize (priv->cell_view); } - priv->minimum_size.width = width; + priv->width = width; } } @@ -4079,11 +4227,8 @@ gtk_combo_box_cell_layout_pack_start (GtkCellLayout *layout, priv->cells = g_slist_append (priv->cells, info); if (priv->cell_view) - { - gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (priv->cell_view), - cell, expand); - - } + gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (priv->cell_view), + cell, expand); if (priv->column) gtk_tree_view_column_pack_start (priv->column, cell, expand); @@ -5817,241 +5962,5 @@ gtk_combo_box_buildable_custom_tag_end (GtkBuildable *buildable, data); } - -static void -gtk_combo_box_extended_layout_init (GtkExtendedLayoutIface *iface) -{ - iface->get_desired_width = gtk_combo_box_get_desired_width; - iface->get_desired_height = gtk_combo_box_get_desired_height; -} - -static void -gtk_combo_box_remeasure (GtkComboBox *combo_box) -{ - GtkComboBoxPrivate *priv = combo_box->priv; - GtkTreeIter iter; - GtkTreePath *path; - - if (!priv->model || - !gtk_tree_model_get_iter_first (priv->model, &iter)) - return; - - memset (&priv->minimum_size, 0x0, sizeof (GtkRequisition)); - memset (&priv->natural_size, 0x0, sizeof (GtkRequisition)); - - path = gtk_tree_path_new_from_indices (0, -1); - - do - { - GtkRequisition req, nat_req; - - if (priv->cell_view) - { - /* XXX FIXME: Currently still not doing height-for-width in cell renderers here */ - gtk_cell_view_get_desired_width_of_row (GTK_CELL_VIEW (priv->cell_view), - path, &req.width, &nat_req.width); - gtk_cell_view_get_desired_height_of_row (GTK_CELL_VIEW (priv->cell_view), - path, &req.height, &nat_req.height); - } - else - { - memset (&req, 0x0, sizeof (GtkRequisition)); - memset (&nat_req, 0x0, sizeof (GtkRequisition)); - } - - priv->minimum_size.width = MAX (priv->minimum_size.width, req.width); - priv->minimum_size.height = MAX (priv->minimum_size.height, req.height); - - priv->natural_size.width = MAX (priv->natural_size.width, nat_req.width); - priv->natural_size.height = MAX (priv->natural_size.height, nat_req.height); - - gtk_tree_path_next (path); - } - while (gtk_tree_model_iter_next (priv->model, &iter)); - - gtk_tree_path_free (path); -} - - -/* XXX TODO: Split this up into 2 orientations so as - * to properly support height-for-width/width-for-height here - * - */ -static void -gtk_combo_box_get_desired_size (GtkExtendedLayout *layout, - GtkRequisition *minimum_size, - GtkRequisition *natural_size) -{ - GtkComboBox *combo_box = GTK_COMBO_BOX (layout); - GtkComboBoxPrivate *priv = combo_box->priv; - gint focus_width, focus_pad; - gint font_size, arrow_size; - GtkRequisition bin_req, bin_nat_req; - PangoContext *context; - PangoFontMetrics *metrics; - PangoFontDescription *font_desc; - GtkWidget *child; - - child = gtk_bin_get_child (GTK_BIN (layout)); - - /* common */ - gtk_extended_layout_get_desired_size (GTK_EXTENDED_LAYOUT (child), FALSE, &bin_req, &bin_nat_req); - gtk_combo_box_remeasure (combo_box); - - bin_req.width = MAX (bin_req.width, priv->minimum_size.width); - bin_req.height = MAX (bin_req.height, priv->minimum_size.height); - bin_nat_req.width = MAX (bin_nat_req.width, priv->natural_size.width); - bin_nat_req.height = MAX (bin_nat_req.height, priv->natural_size.height); - - gtk_widget_style_get (GTK_WIDGET (layout), - "focus-line-width", &focus_width, - "focus-padding", &focus_pad, - "arrow-size", &arrow_size, - NULL); - - font_desc = child->style->font_desc; - context = gtk_widget_get_pango_context (GTK_WIDGET (layout)); - metrics = pango_context_get_metrics (context, font_desc, - pango_context_get_language (context)); - font_size = PANGO_PIXELS (pango_font_metrics_get_ascent (metrics) + - pango_font_metrics_get_descent (metrics)); - pango_font_metrics_unref (metrics); - - arrow_size = MAX (arrow_size, font_size); - - gtk_widget_set_size_request (priv->arrow, arrow_size, arrow_size); - - if (!priv->tree_view) - { - /* menu mode */ - - if (priv->cell_view) - { - GtkRequisition button_req, sep_req, arrow_req; - gint border_width, xthickness, ythickness, xpad, ypad; - - gtk_widget_size_request (priv->button, &button_req); - border_width = GTK_CONTAINER (combo_box)->border_width; - xthickness = priv->button->style->xthickness; - ythickness = priv->button->style->ythickness; - - xpad = 2*(border_width + xthickness + focus_width + focus_pad); - ypad = 2*(border_width + ythickness + focus_width + focus_pad); - - gtk_widget_size_request (priv->separator, &sep_req); - gtk_widget_size_request (priv->arrow, &arrow_req); - - minimum_size->width = bin_req.width + sep_req.width + arrow_req.width; - minimum_size->height = MAX (sep_req.height, arrow_req.height); - minimum_size->height = MAX (minimum_size->height, bin_req.height); - - natural_size->width = bin_nat_req.width + sep_req.width + arrow_req.width; - natural_size->height = MAX (minimum_size->height, bin_nat_req.height); - - minimum_size->width += xpad; - minimum_size->height += ypad; - natural_size->width += xpad; - natural_size->height += ypad; - } - else - { - GtkRequisition but_req, but_nat_req; - - gtk_extended_layout_get_desired_size (GTK_EXTENDED_LAYOUT (priv->button), - FALSE, - &but_req, &but_nat_req); - - minimum_size->width = bin_req.width + but_req.width; - minimum_size->height = MAX (bin_req.height, but_req.height); - - natural_size->width = bin_nat_req.width + but_nat_req.width; - natural_size->height = MAX (bin_nat_req.height, but_nat_req.height); - } - } - else - { - /* list mode */ - GtkRequisition button_req, button_nat_req, frame_req; - - /* sample + frame */ - *minimum_size = bin_req; - *natural_size = bin_nat_req; - - minimum_size->width += 2 * focus_width; - natural_size->width += 2 * focus_width; - - if (priv->cell_view_frame) - { - gtk_widget_size_request (priv->cell_view_frame, &frame_req); - if (priv->has_frame) - { - gint xpad = 2 * (GTK_CONTAINER (priv->cell_view_frame)->border_width + - GTK_WIDGET (priv->cell_view_frame)->style->xthickness); - - gint ypad = 2 * (GTK_CONTAINER (priv->cell_view_frame)->border_width + - GTK_WIDGET (priv->cell_view_frame)->style->ythickness); - - minimum_size->width += xpad; - minimum_size->height += ypad; - natural_size->width += xpad; - natural_size->height += ypad; - } - } - - /* the button */ - gtk_extended_layout_get_desired_size (GTK_EXTENDED_LAYOUT (priv->button), - FALSE, - &button_req, &button_nat_req); - - minimum_size->width += button_req.width; - minimum_size->height = MAX (minimum_size->height, button_req.height); - - natural_size->width += button_nat_req.width; - natural_size->height = MAX (natural_size->height, button_nat_req.height); - } - - if (GTK_SHADOW_NONE != priv->shadow_type) - { - minimum_size->width += 2 * GTK_WIDGET (layout)->style->xthickness; - minimum_size->height += 2 * GTK_WIDGET (layout)->style->ythickness; - - natural_size->width += 2 * GTK_WIDGET (layout)->style->xthickness; - natural_size->height += 2 * GTK_WIDGET (layout)->style->ythickness; - } -} - -static void -gtk_combo_box_get_desired_width (GtkExtendedLayout *layout, - gint *minimum_size, - gint *natural_size) -{ - GtkRequisition minimum, natural; - - gtk_combo_box_get_desired_size (layout, &minimum, &natural); - - if (minimum_size) - *minimum_size = minimum.width; - - if (natural_size) - *natural_size = natural.width; -} - -static void -gtk_combo_box_get_desired_height (GtkExtendedLayout *layout, - gint *minimum_size, - gint *natural_size) -{ - GtkRequisition minimum, natural; - - gtk_combo_box_get_desired_size (layout, &minimum, &natural); - - if (minimum_size) - *minimum_size = minimum.height; - - if (natural_size) - *natural_size = natural.height; -} - - #define __GTK_COMBO_BOX_C__ #include "gtkaliasdef.c" diff --git a/gtk/gtkextendedcell.c b/gtk/gtkextendedcell.c deleted file mode 100644 index 67c6bacda3..0000000000 --- a/gtk/gtkextendedcell.c +++ /dev/null @@ -1,193 +0,0 @@ -/* gtkextendedcell.c - * Copyright (C) 2010 Openismus GmbH - * - * Author: - * Tristan Van Berkom - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - - -#include -#include "gtkcellrenderer.h" -#include "gtkextendedcell.h" -#include "gtkintl.h" -#include "gtkalias.h" - - -#define DEBUG_EXTENDED_CELL 0 - -GType -gtk_extended_cell_get_type (void) -{ - static GType extended_cell_type = 0; - - if (G_UNLIKELY(!extended_cell_type)) - { - extended_cell_type = - g_type_register_static_simple (G_TYPE_INTERFACE, I_("GtkExtendedCell"), - sizeof (GtkExtendedCellIface), - NULL, 0, NULL, 0); - - g_type_interface_add_prerequisite (extended_cell_type, GTK_TYPE_CELL_RENDERER); - } - return extended_cell_type; -} - -/** - * gtk_extended_cell_get_desired_width: - * @cell: a #GtkExtendedCell instance - * @widget: the #GtkWidget this cell will be rendering to - * @minimum_size: location to store the minimum size, or %NULL - * @natural_size: location to store the natural size, or %NULL - * - * Retreives a renderer's desired size when rendered to @widget. - * - * Since: 3.0 - */ -void -gtk_extended_cell_get_desired_width (GtkExtendedCell *cell, - GtkWidget *widget, - gint *minimum_size, - gint *natural_size) -{ - GtkExtendedCellIface *iface; - - g_return_if_fail (GTK_IS_EXTENDED_CELL (cell)); - g_return_if_fail (GTK_IS_WIDGET (widget)); - g_return_if_fail (NULL != minimum_size || NULL != natural_size); - - iface = GTK_EXTENDED_CELL_GET_IFACE (cell); - iface->get_desired_width (cell, widget, minimum_size, natural_size); - -#if DEBUG_EXTENDED_CELL - g_message ("%s returning minimum width: %d and natural width: %d", - G_OBJECT_TYPE_NAME (cell), - minimum_size ? *minimum_size : 20000, - natural_size ? *natural_size : 20000); -#endif -} - - -/** - * gtk_extended_cell_get_desired_height: - * @cell: a #GtkExtendedCell instance - * @widget: the #GtkWidget this cell will be rendering to - * @minimum_size: location to store the minimum size, or %NULL - * @natural_size: location to store the natural size, or %NULL - * - * Retreives a renderer's desired size when rendered to @widget. - * - * Since: 3.0 - */ -void -gtk_extended_cell_get_desired_height (GtkExtendedCell *cell, - GtkWidget *widget, - gint *minimum_size, - gint *natural_size) -{ - GtkExtendedCellIface *iface; - - g_return_if_fail (GTK_IS_EXTENDED_CELL (cell)); - g_return_if_fail (GTK_IS_WIDGET (widget)); - g_return_if_fail (NULL != minimum_size || NULL != natural_size); - - iface = GTK_EXTENDED_CELL_GET_IFACE (cell); - iface->get_desired_height (cell, widget, minimum_size, natural_size); - -#if DEBUG_EXTENDED_CELL - g_message ("%s returning minimum height: %d and natural height: %d", - G_OBJECT_TYPE_NAME (cell), - minimum_size ? *minimum_size : 20000, - natural_size ? *natural_size : 20000); -#endif -} - - -/** - * gtk_extended_cell_get_width_for_height: - * @cell: a #GtkExtendedCell instance - * @height: the size which is available for allocation - * @minimum_width: location for storing the minimum size, or %NULL - * @natural_width: location for storing the preferred size, or %NULL - * - * Retreives a cell renderers's desired width if it were rendered to - * @widget with the specified @height. - * - * Since: 3.0 - */ -void -gtk_extended_cell_get_width_for_height (GtkExtendedCell *cell, - GtkWidget *widget, - gint height, - gint *minimum_width, - gint *natural_width) -{ - GtkExtendedCellIface *iface; - - g_return_if_fail (GTK_IS_EXTENDED_CELL (cell)); - g_return_if_fail (GTK_IS_WIDGET (widget)); - g_return_if_fail (NULL != minimum_width || NULL != natural_width); - - iface = GTK_EXTENDED_CELL_GET_IFACE (cell); - iface->get_width_for_height (cell, widget, height, minimum_width, natural_width); - -#if DEBUG_EXTENDED_CELL - g_message ("%s width for height: %d is minimum %d and natural: %d", - G_OBJECT_TYPE_NAME (cell), height, - minimum_width ? *minimum_width : 20000, - natural_width ? *natural_width : 20000); -#endif -} - -/** - * gtk_extended_cell_get_height_for_width: - * @cell: a #GtkExtendedCell instance - * @width: the size which is available for allocation - * @minimum_height: location for storing the minimum size, or %NULL - * @natural_height: location for storing the preferred size, or %NULL - * - * Retreives a cell renderers's desired height if it were rendered to - * @widget with the specified @width. - * - * Since: 3.0 - */ -void -gtk_extended_cell_get_height_for_width (GtkExtendedCell *cell, - GtkWidget *widget, - gint width, - gint *minimum_height, - gint *natural_height) -{ - GtkExtendedCellIface *iface; - - g_return_if_fail (GTK_IS_EXTENDED_CELL (cell)); - g_return_if_fail (GTK_IS_WIDGET (widget)); - g_return_if_fail (NULL != minimum_height || NULL != natural_height); - - iface = GTK_EXTENDED_CELL_GET_IFACE (cell); - iface->get_height_for_width (cell, widget, width, minimum_height, natural_height); - -#if DEBUG_EXTENDED_CELL - g_message ("%s height for width: %d is minimum %d and natural: %d", - G_OBJECT_TYPE_NAME (cell), width, - minimum_height ? *minimum_height : 20000, - natural_height ? *natural_height : 20000); -#endif -} - -#define __GTK_EXTENDED_CELL_C__ -#include "gtkaliasdef.c" diff --git a/gtk/gtkextendedcell.h b/gtk/gtkextendedcell.h deleted file mode 100644 index 8bd38f7e2c..0000000000 --- a/gtk/gtkextendedcell.h +++ /dev/null @@ -1,88 +0,0 @@ -/* GTK - The GIMP Toolkit - * Copyright (C) 2010 Openismus GmbH - * - * Author: - * Tristan Van Berkom - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifndef __GTK_EXTENDED_CELL_H__ -#define __GTK_EXTENDED_CELL_H__ - -#include - -G_BEGIN_DECLS - -#define GTK_TYPE_EXTENDED_CELL (gtk_extended_cell_get_type ()) -#define GTK_EXTENDED_CELL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_EXTENDED_CELL, GtkExtendedCell)) -#define GTK_EXTENDED_CELL_CLASS(klass) ((GtkExtendedCellIface*)g_type_interface_peek ((klass), GTK_TYPE_EXTENDED_CELL)) -#define GTK_IS_EXTENDED_CELL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_EXTENDED_CELL)) -#define GTK_EXTENDED_CELL_GET_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GTK_TYPE_EXTENDED_CELL, GtkExtendedCellIface)) - -typedef struct _GtkExtendedCell GtkExtendedCell; -typedef struct _GtkExtendedCellIface GtkExtendedCellIface; - -struct _GtkExtendedCellIface -{ - GTypeInterface g_iface; - - /* virtual table */ - - void (* get_desired_width) (GtkExtendedCell *cell, - GtkWidget *widget, - gint *minimum_size, - gint *natural_size); - void (* get_desired_height) (GtkExtendedCell *cell, - GtkWidget *widget, - gint *minimum_size, - gint *natural_size); - void (* get_width_for_height) (GtkExtendedCell *cell, - GtkWidget *widget, - gint height, - gint *minimum_width, - gint *natural_width); - void (* get_height_for_width) (GtkExtendedCell *cell, - GtkWidget *widget, - gint width, - gint *minimum_height, - gint *natural_height); -}; - -GType gtk_extended_cell_get_type (void) G_GNUC_CONST; - -void gtk_extended_cell_get_desired_width (GtkExtendedCell *cell, - GtkWidget *widget, - gint *minimum_size, - gint *natural_size); -void gtk_extended_cell_get_desired_height (GtkExtendedCell *cell, - GtkWidget *widget, - gint *minimum_size, - gint *natural_size); -void gtk_extended_cell_get_width_for_height (GtkExtendedCell *cell, - GtkWidget *widget, - gint height, - gint *minimum_width, - gint *natural_width); -void gtk_extended_cell_get_height_for_width (GtkExtendedCell *cell, - GtkWidget *widget, - gint width, - gint *minimum_height, - gint *natural_height); - -G_END_DECLS - -#endif /* __GTK_EXTENDED_CELL_H__ */ diff --git a/gtk/gtkextendedlayout.c b/gtk/gtkextendedlayout.c index da4ac26ded..30a0495561 100644 --- a/gtk/gtkextendedlayout.c +++ b/gtk/gtkextendedlayout.c @@ -467,8 +467,7 @@ gtk_extended_layout_get_height_for_width (GtkExtendedLayout *layout, * be used to make the contextual request; otherwise the minimum will be used. * * This is used to retreive a suitable size by container widgets whom dont - * impose any restrictions on the child placement, examples of these are - * #GtkWindow and #GtkScrolledWindow. + * impose any restrictions on the child placement * * Since: 3.0 */ diff --git a/gtk/gtkextendedlayout.h b/gtk/gtkextendedlayout.h index c3fdc0a0b9..5c282cf9b4 100644 --- a/gtk/gtkextendedlayout.h +++ b/gtk/gtkextendedlayout.h @@ -1,8 +1,9 @@ /* GTK - The GIMP Toolkit - * Copyright (C) 2007 Openismus GmbH + * Copyright (C) 2007-2010 Openismus GmbH * - * Author: + * Authors: * Mathias Hasselmann + * Tristan Van Berkom * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public diff --git a/gtk/gtkplug-x11.c b/gtk/gtkplug-x11.c index fa81b61b54..95dcf1ab6f 100644 --- a/gtk/gtkplug-x11.c +++ b/gtk/gtkplug-x11.c @@ -32,7 +32,6 @@ #include "gtkplugprivate.h" #include "x11/gdkx.h" -#include #include "gtkxembed.h" #include "gtkalias.h" @@ -331,29 +330,3 @@ _gtk_plug_windowing_filter_func (GdkXEvent *gdk_xevent, return return_val; } - -void -_gtk_plug_windowing_publish_natural_size (GtkPlug *plug, - GtkRequisition *requisition) -{ - GtkWidget *widget = GTK_WIDGET (plug); - GdkDisplay *display; - GdkWindow *window; - gint32 data[2]; - Atom property; - - gtk_widget_realize (widget); - - window = GTK_WIDGET (plug)->window; - display = gdk_drawable_get_display (window); - property = gdk_x11_get_xatom_by_name_for_display (display, "_GTK_NATURAL_SIZE"); - - data[0] = requisition->width; - data[1] = requisition->height; - - XChangeProperty (GDK_DISPLAY_XDISPLAY (display), - GDK_WINDOW_XWINDOW (window), property, - XA_CARDINAL, 32, PropModeReplace, - (unsigned char*)data, 2); -} - diff --git a/gtk/gtkplug.c b/gtk/gtkplug.c index 340bcb2a14..52d2b925f9 100644 --- a/gtk/gtkplug.c +++ b/gtk/gtkplug.c @@ -30,7 +30,6 @@ #include "gtkmain.h" #include "gtkmarshalers.h" #include "gtkplug.h" -#include "gtkextendedlayout.h" #include "gtkintl.h" #include "gtkprivate.h" #include "gtkplugprivate.h" @@ -751,8 +750,6 @@ static void gtk_plug_size_allocate (GtkWidget *widget, GtkAllocation *allocation) { - GtkBin *bin = GTK_BIN (widget); - GtkRequisition natural_size; if (gtk_widget_is_toplevel (widget)) GTK_WIDGET_CLASS (gtk_plug_parent_class)->size_allocate (widget, allocation); else @@ -780,10 +777,6 @@ gtk_plug_size_allocate (GtkWidget *widget, } } - - gtk_extended_layout_get_desired_size (GTK_EXTENDED_LAYOUT (bin->child), - TRUE, NULL, &natural_size); - _gtk_plug_windowing_publish_natural_size (GTK_PLUG (widget), &natural_size); } static gboolean diff --git a/gtk/gtkplugprivate.h b/gtk/gtkplugprivate.h index 83dcaaf7ff..74f0374bc5 100644 --- a/gtk/gtkplugprivate.h +++ b/gtk/gtkplugprivate.h @@ -138,7 +138,4 @@ GdkFilterReturn _gtk_plug_windowing_filter_func (GdkXEvent *gdk_xevent, GdkEvent *event, gpointer data); -void _gtk_plug_windowing_publish_natural_size (GtkPlug *plug, - GtkRequisition *requisition); - #endif /* __GTK_PLUG_PRIVATE_H__ */ diff --git a/gtk/gtksocket-x11.c b/gtk/gtksocket-x11.c index c3f3b5b160..5dbde457a8 100644 --- a/gtk/gtksocket-x11.c +++ b/gtk/gtksocket-x11.c @@ -39,7 +39,6 @@ #include "gtkdnd.h" #include "x11/gdkx.h" -#include #ifdef HAVE_XFIXES #include @@ -123,63 +122,6 @@ _gtk_socket_windowing_size_request (GtkSocket *socket) gdk_error_trap_pop (); } -void -_gtk_socket_windowing_get_natural_size (GtkSocket *socket) -{ - GtkSocketPrivate *priv; - GdkDisplay *display; - - Atom property, type; - int format, status; - - unsigned long nitems, bytes_after; - unsigned char *data; - gint32 *data_long; - - priv = _gtk_socket_get_private (socket); - - priv->natural_width = 1; - priv->natural_height = 1; - - if (gtk_widget_get_mapped (GTK_WIDGET (socket))) - { - display = gdk_drawable_get_display (socket->plug_window); - property = gdk_x11_get_xatom_by_name_for_display (display, "_GTK_NATURAL_SIZE"); - - gdk_error_trap_push (); - status = XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), - GDK_WINDOW_XWINDOW (socket->plug_window), - property, 0, 2, False, XA_CARDINAL, - &type, &format, &nitems, &bytes_after, - &data); - gdk_error_trap_pop (); - - priv->have_natural_size = TRUE; - - if (Success != status || !type) - return; - - if (type != XA_CARDINAL) - { - g_warning ("_GTK_NATURAL_SIZE property has wrong type: %d\n", (int)type); - return; - } - - if (nitems < 2) - { - g_warning ("_GTK_NATURAL_SIZE too short\n"); - XFree (data); - return; - } - - data_long = (gint32*) data; - priv->natural_width = MAX (1, data_long[0]); - priv->natural_height = MAX (1, data_long[1]); - - XFree (data); - } -} - void _gtk_socket_windowing_send_key_event (GtkSocket *socket, GdkEvent *gdk_event, @@ -660,10 +602,6 @@ _gtk_socket_windowing_filter_func (GdkXEvent *gdk_xevent, } return_val = GDK_FILTER_REMOVE; } - else if (xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (display, "_GTK_NATURAL_SIZE")) - { - _gtk_socket_windowing_get_natural_size (socket); - } } break; case ReparentNotify: diff --git a/gtk/gtksocket.c b/gtk/gtksocket.c index e64f308011..847ee9ff01 100644 --- a/gtk/gtksocket.c +++ b/gtk/gtksocket.c @@ -37,7 +37,6 @@ #include "gtksocket.h" #include "gtksocketprivate.h" #include "gtkdnd.h" -#include "gtkextendedlayout.h" #include "gtkintl.h" #include "gtkalias.h" @@ -68,13 +67,6 @@ static void gtk_socket_forall (GtkContainer *container, GtkCallback callback, gpointer callback_data); -static void gtk_socket_extended_layout_init (GtkExtendedLayoutIface *iface); -static void gtk_socket_get_desired_width (GtkExtendedLayout *layout, - gint *minimum_size, - gint *natural_size); -static void gtk_socket_get_desired_height (GtkExtendedLayout *layout, - gint *minimum_size, - gint *natural_size); /* Local data */ @@ -106,10 +98,7 @@ _gtk_socket_get_private (GtkSocket *socket) return G_TYPE_INSTANCE_GET_PRIVATE (socket, GTK_TYPE_SOCKET, GtkSocketPrivate); } -G_DEFINE_TYPE_WITH_CODE (GtkSocket, gtk_socket, GTK_TYPE_CONTAINER, - G_IMPLEMENT_INTERFACE (GTK_TYPE_EXTENDED_LAYOUT, - gtk_socket_extended_layout_init)) - +G_DEFINE_TYPE (GtkSocket, gtk_socket, GTK_TYPE_CONTAINER) static void gtk_socket_finalize (GObject *object) @@ -196,8 +185,6 @@ gtk_socket_class_init (GtkSocketClass *class) static void gtk_socket_init (GtkSocket *socket) { - GtkSocketPrivate *priv; - socket->request_width = 0; socket->request_height = 0; socket->current_width = 0; @@ -212,9 +199,6 @@ gtk_socket_init (GtkSocket *socket) socket->accel_group = gtk_accel_group_new (); g_object_set_data (G_OBJECT (socket->accel_group), I_("gtk-socket"), socket); - - priv = _gtk_socket_get_private (socket); - priv->have_natural_size = FALSE; } /** @@ -1018,83 +1002,5 @@ _gtk_socket_advance_toplevel_focus (GtkSocket *socket, } } -static void -gtk_socket_extended_layout_init (GtkExtendedLayoutIface *iface) -{ - iface->get_desired_width = gtk_socket_get_desired_width; - iface->get_desired_height = gtk_socket_get_desired_height; -} - -static void -gtk_socket_get_desired_size (GtkExtendedLayout *layout, - GtkOrientation orientation, - gint *minimum_size, - gint *natural_size) -{ - GtkSocket *socket = GTK_SOCKET (layout); - GtkSocketPrivate *priv; - - if (socket->plug_widget) - { - if (orientation == GTK_ORIENTATION_HORIZONTAL) - gtk_extended_layout_get_desired_width (GTK_EXTENDED_LAYOUT (socket->plug_widget), - minimum_size, natural_size); - else - gtk_extended_layout_get_desired_height (GTK_EXTENDED_LAYOUT (socket->plug_widget), - minimum_size, natural_size); - } - else - { - priv = _gtk_socket_get_private (socket); - - if (socket->is_mapped && !priv->have_natural_size && socket->plug_window) - { - _gtk_socket_windowing_size_request (socket); - _gtk_socket_windowing_get_natural_size (socket); - } - - if (socket->is_mapped && priv->have_natural_size) - { - if (minimum_size) - { - *minimum_size = - (orientation == GTK_ORIENTATION_HORIZONTAL) ? - MAX (socket->request_width, 1) : MAX (socket->request_height, 1); - } - if (natural_size) - { - *natural_size = - (orientation == GTK_ORIENTATION_HORIZONTAL) ? - MAX (priv->natural_width, 1) : MAX (priv->natural_height, 1); - } - } - else - { - if (minimum_size) - *minimum_size = 1; - - if (natural_size) - *natural_size = 1; - } - } -} - -static void -gtk_socket_get_desired_width (GtkExtendedLayout *layout, - gint *minimum_size, - gint *natural_size) -{ - gtk_socket_get_desired_size (layout, GTK_ORIENTATION_HORIZONTAL, minimum_size, natural_size); -} - -static void -gtk_socket_get_desired_height (GtkExtendedLayout *layout, - gint *minimum_size, - gint *natural_size) -{ - gtk_socket_get_desired_size (layout, GTK_ORIENTATION_VERTICAL, minimum_size, natural_size); -} - - #define __GTK_SOCKET_C__ #include "gtkaliasdef.c" diff --git a/gtk/gtksocketprivate.h b/gtk/gtksocketprivate.h index 8eda1ae6b3..44a6c6b36e 100644 --- a/gtk/gtksocketprivate.h +++ b/gtk/gtksocketprivate.h @@ -31,9 +31,6 @@ typedef struct _GtkSocketPrivate GtkSocketPrivate; struct _GtkSocketPrivate { gint resize_count; - gint natural_width; - gint natural_height; - gboolean have_natural_size; }; /* In gtksocket.c: */ @@ -86,7 +83,6 @@ void _gtk_socket_windowing_end_embedding_toplevel (GtkSocket *socket); */ void _gtk_socket_windowing_size_request (GtkSocket *socket); -void _gtk_socket_windowing_get_natural_size (GtkSocket *socket); /* * _gtk_socket_windowing_send_key_event: * diff --git a/gtk/gtkspinner.c b/gtk/gtkspinner.c index 0f328ac0f0..736b03f406 100644 --- a/gtk/gtkspinner.c +++ b/gtk/gtkspinner.c @@ -211,8 +211,6 @@ gtk_spinner_init (GtkSpinner *spinner) spinner->priv = priv; - gtk_widget_set_size_request (GTK_WIDGET (spinner), 12, 12); - gtk_widget_set_has_window (GTK_WIDGET (spinner), FALSE); } @@ -222,9 +220,16 @@ gtk_spinner_expose (GtkWidget *widget, { GtkStateType state_type; GtkSpinnerPrivate *priv; + int width, height; priv = GTK_SPINNER (widget)->priv; + width = widget->allocation.width; + height = widget->allocation.height; + + if ((width < 12) || (height <12)) + gtk_widget_set_size_request (widget, 12, 12); + state_type = GTK_STATE_NORMAL; if (!gtk_widget_is_sensitive (widget)) state_type = GTK_STATE_INSENSITIVE; diff --git a/gtk/gtktreeprivate.h b/gtk/gtktreeprivate.h index 8a84e89cdb..c44d61813d 100644 --- a/gtk/gtktreeprivate.h +++ b/gtk/gtktreeprivate.h @@ -77,8 +77,6 @@ enum */ #define TREE_VIEW_COLUMN_DRAG_DEAD_MULTIPLIER(tree_view) (10*TREE_VIEW_HEADER_HEIGHT(tree_view)) -#define GTK_TREE_VIEW_COLUMN_GET_PRIVATE(column) (G_TYPE_INSTANCE_GET_PRIVATE ((column), GTK_TYPE_TREE_VIEW_COLUMN, GtkTreeViewColumnPrivate)) - typedef struct _GtkTreeViewColumnReorder GtkTreeViewColumnReorder; struct _GtkTreeViewColumnReorder { @@ -302,11 +300,6 @@ struct _GtkTreeViewPrivate guint search_entry_avoid_unhandled_binding : 1; }; -struct _GtkTreeViewColumnPrivate -{ - gint natural_width; -}; - #ifdef __GNUC__ #define TREE_VIEW_INTERNAL_ASSERT(expr, ret) G_STMT_START{ \ diff --git a/gtk/gtktreeview.c b/gtk/gtktreeview.c index 95d0e1ae68..93bb688616 100644 --- a/gtk/gtktreeview.c +++ b/gtk/gtktreeview.c @@ -27,7 +27,6 @@ #include "gtktreednd.h" #include "gtktreeprivate.h" #include "gtkcellrenderer.h" -#include "gtkextendedlayout.h" #include "gtkmain.h" #include "gtkmarshalers.h" #include "gtkbuildable.h" @@ -166,6 +165,8 @@ static void gtk_tree_view_destroy (GtkObject *object); static void gtk_tree_view_realize (GtkWidget *widget); static void gtk_tree_view_unrealize (GtkWidget *widget); static void gtk_tree_view_map (GtkWidget *widget); +static void gtk_tree_view_size_request (GtkWidget *widget, + GtkRequisition *requisition); static void gtk_tree_view_size_allocate (GtkWidget *widget, GtkAllocation *allocation); static gboolean gtk_tree_view_expose (GtkWidget *widget, @@ -468,13 +469,6 @@ static void gtk_tree_view_buildable_add_child (GtkBuildable *tree_view, GObject *child, const gchar *type); static void gtk_tree_view_buildable_init (GtkBuildableIface *iface); -static void gtk_tree_view_extended_layout_init (GtkExtendedLayoutIface *iface); -static void gtk_tree_view_get_desired_width (GtkExtendedLayout *layout, - gint *minimum_size, - gint *natural_size); -static void gtk_tree_view_get_desired_height (GtkExtendedLayout *layout, - gint *minimum_size, - gint *natural_size); static gboolean scroll_row_timeout (gpointer data); @@ -490,10 +484,7 @@ static guint tree_view_signals [LAST_SIGNAL] = { 0 }; G_DEFINE_TYPE_WITH_CODE (GtkTreeView, gtk_tree_view, GTK_TYPE_CONTAINER, G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE, - gtk_tree_view_buildable_init) - G_IMPLEMENT_INTERFACE (GTK_TYPE_EXTENDED_LAYOUT, - gtk_tree_view_extended_layout_init)) - + gtk_tree_view_buildable_init)) static void gtk_tree_view_class_init (GtkTreeViewClass *class) @@ -523,6 +514,7 @@ gtk_tree_view_class_init (GtkTreeViewClass *class) widget_class->map = gtk_tree_view_map; widget_class->realize = gtk_tree_view_realize; widget_class->unrealize = gtk_tree_view_unrealize; + widget_class->size_request = gtk_tree_view_size_request; widget_class->size_allocate = gtk_tree_view_size_allocate; widget_class->button_press_event = gtk_tree_view_button_press; widget_class->button_release_event = gtk_tree_view_button_release; @@ -2031,6 +2023,37 @@ gtk_tree_view_update_size (GtkTreeView *tree_view) tree_view->priv->height = tree_view->priv->tree->root->offset; } +static void +gtk_tree_view_size_request (GtkWidget *widget, + GtkRequisition *requisition) +{ + GtkTreeView *tree_view = GTK_TREE_VIEW (widget); + GList *tmp_list; + + /* we validate some rows initially just to make sure we have some size. + * In practice, with a lot of static lists, this should get a good width. + */ + do_validate_rows (tree_view, FALSE); + gtk_tree_view_size_request_columns (tree_view); + gtk_tree_view_update_size (GTK_TREE_VIEW (widget)); + + requisition->width = tree_view->priv->width; + requisition->height = tree_view->priv->height + TREE_VIEW_HEADER_HEIGHT (tree_view); + + tmp_list = tree_view->priv->children; + + while (tmp_list) + { + GtkTreeViewChild *child = tmp_list->data; + GtkRequisition child_requisition; + + tmp_list = tmp_list->next; + + if (gtk_widget_get_visible (child->widget)) + gtk_widget_size_request (child->widget, &child_requisition); + } +} + static int gtk_tree_view_calculate_width_before_expander (GtkTreeView *tree_view) { @@ -2139,28 +2162,6 @@ gtk_tree_view_get_real_requested_width_from_column (GtkTreeView *tree_view return real_requested_width; } -static gint -gtk_tree_view_get_real_natural_width_from_column (GtkTreeView *tree_view, - GtkTreeViewColumn *column) -{ - GtkTreeViewColumnPrivate *column_priv; - GtkRequisition button_natural_size; - gint column_natural_width; - - column_priv = GTK_TREE_VIEW_COLUMN_GET_PRIVATE (column); - column_natural_width = column_priv->natural_width; - - if (GTK_TREE_VIEW_FLAG_SET (tree_view, GTK_TREE_VIEW_HEADERS_VISIBLE)) - { - gtk_extended_layout_get_desired_size (GTK_EXTENDED_LAYOUT (column->button), - TRUE, NULL, &button_natural_size); - - column_natural_width = MAX (column_natural_width, button_natural_size.width); - } - - return column_natural_width; -} - /* GtkWidget::size_allocate helper */ static void gtk_tree_view_size_allocate_columns (GtkWidget *widget, @@ -2170,10 +2171,9 @@ gtk_tree_view_size_allocate_columns (GtkWidget *widget, GList *list, *first_column, *last_column; GtkTreeViewColumn *column; GtkAllocation allocation; - gint width = 0, natural_width = 0; + gint width = 0; gint extra, extra_per_column, extra_for_last; gint full_requested_width = 0; - gint full_natural_width = 0; gint number_of_expand_columns = 0; gboolean column_changed = FALSE; gboolean rtl; @@ -2207,7 +2207,6 @@ gtk_tree_view_size_allocate_columns (GtkWidget *widget, continue; full_requested_width += gtk_tree_view_get_real_requested_width_from_column (tree_view, column); - full_natural_width += gtk_tree_view_get_real_natural_width_from_column (tree_view, column); if (column->expand) number_of_expand_columns++; @@ -2232,9 +2231,7 @@ gtk_tree_view_size_allocate_columns (GtkWidget *widget, } else { - full_natural_width -= full_requested_width; extra = MAX (widget->allocation.width - full_requested_width, 0); - natural_width = MIN (extra, full_natural_width); extra_for_last = 0; tree_view->priv->last_extra_space = extra; @@ -2256,7 +2253,6 @@ gtk_tree_view_size_allocate_columns (GtkWidget *widget, list = (rtl ? list->prev : list->next)) { gint real_requested_width = 0; - gint real_natural_width = 0; gint old_width; column = list->data; @@ -2282,14 +2278,10 @@ gtk_tree_view_size_allocate_columns (GtkWidget *widget, } real_requested_width = gtk_tree_view_get_real_requested_width_from_column (tree_view, column); - real_natural_width = gtk_tree_view_get_real_natural_width_from_column (tree_view, column); - real_natural_width -= real_requested_width; allocation.x = width; column->width = real_requested_width; - if (full_natural_width > 0) - column->width += natural_width * real_natural_width / full_natural_width; if (column->expand) { if (number_of_expand_columns == 1) @@ -5717,13 +5709,10 @@ validate_row (GtkTreeView *tree_view, for (list = tree_view->priv->columns; list; list = list->next) { - GtkTreeViewColumnPrivate *column_priv; - GtkRequisition requested_size; - GtkRequisition natural_size; - gint padding; + gint tmp_width; + gint tmp_height; column = list->data; - column_priv = GTK_TREE_VIEW_COLUMN_GET_PRIVATE (column); if (! column->visible) continue; @@ -5734,13 +5723,14 @@ validate_row (GtkTreeView *tree_view, gtk_tree_view_column_cell_set_cell_data (column, tree_view->priv->model, iter, GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_PARENT), node->children?TRUE:FALSE); - - gtk_tree_view_column_get_desired_size (column, &requested_size, &natural_size); + gtk_tree_view_column_cell_get_size (column, + NULL, NULL, NULL, + &tmp_width, &tmp_height); if (!is_separator) { - requested_size.height += vertical_separator; - height = MAX (height, requested_size.height); + tmp_height += vertical_separator; + height = MAX (height, tmp_height); height = MAX (height, tree_view->priv->expander_size); } else @@ -5753,31 +5743,26 @@ validate_row (GtkTreeView *tree_view, if (gtk_tree_view_is_expander_column (tree_view, column)) { - padding = horizontal_separator + (depth - 1) * tree_view->priv->level_indentation; + tmp_width = tmp_width + horizontal_separator + (depth - 1) * tree_view->priv->level_indentation; if (TREE_VIEW_DRAW_EXPANDERS (tree_view)) - padding += depth * tree_view->priv->expander_size; + tmp_width += depth * tree_view->priv->expander_size; } else - padding = horizontal_separator; + tmp_width = tmp_width + horizontal_separator; if (draw_vgrid_lines) { if (list->data == first_column || list->data == last_column) - padding += grid_line_width / 2.0; + tmp_width += grid_line_width / 2.0; else - padding += grid_line_width; + tmp_width += grid_line_width; } - requested_size.width += padding; - natural_size.width += padding; - - if (requested_size.width > column->requested_width || - natural_size.width > column_priv->natural_width) + if (tmp_width > column->requested_width) { retval = TRUE; - column->requested_width = requested_size.width; - column_priv->natural_width = natural_size.width; + column->requested_width = tmp_width; } } @@ -15707,103 +15692,5 @@ gtk_tree_view_get_tooltip_column (GtkTreeView *tree_view) return tree_view->priv->tooltip_column; } - -static void -gtk_tree_view_get_minimum_size (GtkWidget *widget, - GtkRequisition *requisition) -{ - GtkTreeView *tree_view = GTK_TREE_VIEW (widget); - GList *tmp_list; - - /* we validate some rows initially just to make sure we have some size. - * In practice, with a lot of static lists, this should get a good width. - */ - do_validate_rows (tree_view, FALSE); - gtk_tree_view_size_request_columns (tree_view); - gtk_tree_view_update_size (GTK_TREE_VIEW (widget)); - - requisition->width = tree_view->priv->width; - requisition->height = tree_view->priv->height + TREE_VIEW_HEADER_HEIGHT (tree_view); - - tmp_list = tree_view->priv->children; - - while (tmp_list) - { - GtkTreeViewChild *child = tmp_list->data; - GtkRequisition child_requisition; - - tmp_list = tmp_list->next; - - if (gtk_widget_get_visible (child->widget)) - gtk_widget_size_request (child->widget, &child_requisition); - } -} - -static void -gtk_tree_view_extended_layout_init (GtkExtendedLayoutIface *iface) -{ - iface->get_desired_width = gtk_tree_view_get_desired_width; - iface->get_desired_height = gtk_tree_view_get_desired_height; -} - -static void -gtk_tree_view_get_desired_size (GtkExtendedLayout *layout, - GtkOrientation orientation, - gint *minimum_size, - gint *natural_size) -{ - GtkTreeView *tree_view; - gint natural_width = 0; - GList *column_iter; - GtkRequisition requisition; - - tree_view = GTK_TREE_VIEW (layout); - - gtk_tree_view_get_minimum_size (GTK_WIDGET (layout), &requisition); - - if (orientation == GTK_ORIENTATION_HORIZONTAL) - { - for (column_iter = tree_view->priv->columns; column_iter; column_iter = column_iter->next) - { - GtkTreeViewColumn *column = column_iter->data; - - if (!column->visible) - continue; - - natural_width += gtk_tree_view_get_real_natural_width_from_column (tree_view, column); - } - - if (minimum_size) - *minimum_size = requisition.width; - - if (natural_size) - *natural_size = MAX (requisition.width, natural_width); - } - else - { - if (minimum_size) - *minimum_size = requisition.height; - - if (natural_size) - *natural_size = requisition.height; - } -} - -static void -gtk_tree_view_get_desired_width (GtkExtendedLayout *layout, - gint *minimum_size, - gint *natural_size) -{ - gtk_tree_view_get_desired_size (layout, GTK_ORIENTATION_HORIZONTAL, minimum_size, natural_size); -} - -static void -gtk_tree_view_get_desired_height (GtkExtendedLayout *layout, - gint *minimum_size, - gint *natural_size) -{ - gtk_tree_view_get_desired_size (layout, GTK_ORIENTATION_VERTICAL, minimum_size, natural_size); -} - #define __GTK_TREE_VIEW_C__ #include "gtkaliasdef.c" diff --git a/gtk/gtktreeviewcolumn.c b/gtk/gtktreeviewcolumn.c index 9f3f25382d..348a9df98a 100644 --- a/gtk/gtktreeviewcolumn.c +++ b/gtk/gtktreeviewcolumn.c @@ -26,7 +26,6 @@ #include "gtkbutton.h" #include "gtkalignment.h" #include "gtklabel.h" -#include "gtkextendedcell.h" #include "gtkhbox.h" #include "gtkmarshalers.h" #include "gtkarrow.h" @@ -165,7 +164,6 @@ G_DEFINE_TYPE_WITH_CODE (GtkTreeViewColumn, gtk_tree_view_column, GTK_TYPE_OBJEC gtk_tree_view_column_buildable_init)) - static void gtk_tree_view_column_class_init (GtkTreeViewColumnClass *class) { @@ -346,8 +344,6 @@ gtk_tree_view_column_class_init (GtkTreeViewColumnClass *class) G_MAXINT, -1, GTK_PARAM_READWRITE)); - - g_type_class_add_private (class, sizeof (GtkTreeViewColumnPrivate)); } static void @@ -2599,79 +2595,6 @@ gtk_tree_view_column_cell_set_cell_data (GtkTreeViewColumn *tree_column, } -static void -gtk_tree_view_column_cell_get_real_size (GtkTreeViewColumn *tree_column, - const GdkRectangle *cell_area, - gint *x_offset, - gint *y_offset, - GtkRequisition *minimal_size, - GtkRequisition *desired_size) -{ - GList *list; - gboolean first_cell = TRUE; - gint focus_line_width; - - g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column)); - - if (minimal_size) - { - minimal_size->height = 0; - minimal_size->width = 0; - } - - if (desired_size) - { - desired_size->height = 0; - desired_size->width = 0; - } - - gtk_widget_style_get (tree_column->tree_view, "focus-line-width", &focus_line_width, NULL); - - for (list = tree_column->cell_list; list; list = list->next) - { - GtkTreeViewColumnCellInfo *info = (GtkTreeViewColumnCellInfo *) list->data; - gboolean visible; - GtkRequisition min_req, nat_req; - - g_object_get (info->cell, "visible", &visible, NULL); - - if (visible == FALSE) - continue; - - if (first_cell == FALSE) - { - min_req.width += tree_column->spacing; - nat_req.width += tree_column->spacing; - } - - /* XXX TODO: Cell renderers are not really doing height-for-width yet. - */ - gtk_extended_cell_get_desired_width (GTK_EXTENDED_CELL (info->cell), - tree_column->tree_view, - &min_req.width, &nat_req.width); - gtk_extended_cell_get_height_for_width (GTK_EXTENDED_CELL (info->cell), - tree_column->tree_view, - nat_req.width, - &min_req.height, &nat_req.height); - - min_req.width += focus_line_width * 2; - min_req.height += focus_line_width * 2; - nat_req.width += focus_line_width * 2; - nat_req.height += focus_line_width * 2; - - info->requested_width = MAX (info->requested_width, min_req.width); - - first_cell = FALSE; - - if (minimal_size) - *minimal_size = min_req; - - if (desired_size) - *desired_size = nat_req; - } -} - - /** * gtk_tree_view_column_cell_get_size: * @tree_column: A #GtkTreeViewColumn. @@ -2689,19 +2612,51 @@ gtk_tree_view_column_cell_get_size (GtkTreeViewColumn *tree_column, const GdkRectangle *cell_area, gint *x_offset, gint *y_offset, - gint *width, - gint *height) + gint *width, + gint *height) { - GtkRequisition min_req; + GList *list; + gboolean first_cell = TRUE; + gint focus_line_width; - gtk_tree_view_column_cell_get_real_size (tree_column, cell_area, - x_offset, y_offset, &min_req, NULL); - - if (width) - *width = min_req.width; + g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column)); if (height) - *height = min_req.height; + * height = 0; + if (width) + * width = 0; + + gtk_widget_style_get (tree_column->tree_view, "focus-line-width", &focus_line_width, NULL); + + for (list = tree_column->cell_list; list; list = list->next) + { + GtkTreeViewColumnCellInfo *info = (GtkTreeViewColumnCellInfo *) list->data; + gboolean visible; + gint new_height = 0; + gint new_width = 0; + g_object_get (info->cell, "visible", &visible, NULL); + + if (visible == FALSE) + continue; + + if (first_cell == FALSE && width) + *width += tree_column->spacing; + + gtk_cell_renderer_get_size (info->cell, + tree_column->tree_view, + cell_area, + x_offset, + y_offset, + &new_width, + &new_height); + + if (height) + * height = MAX (*height, new_height + focus_line_width * 2); + info->requested_width = MAX (info->requested_width, new_width + focus_line_width * 2); + if (width) + * width += info->requested_width; + first_cell = FALSE; + } } /* rendering, event handling and rendering focus are somewhat complicated, and @@ -3829,29 +3784,5 @@ gtk_tree_view_column_get_tree_view (GtkTreeViewColumn *tree_column) return tree_column->tree_view; } - -/** - * gtk_tree_view_column_get_desired_size: - * @tree_column: A #GtkTreeViewColumn - * @minimum_size: location for storing the minimum size, or %NULL - * @natural_size: location for storing the preferred size, or %NULL - * - * - * Retreives @tree_column's minimum and natural size. - * - * Since: 3.0 - */ -void -gtk_tree_view_column_get_desired_size (GtkTreeViewColumn *column, - GtkRequisition *minimal_size, - GtkRequisition *desired_size) -{ - g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (column)); - - gtk_tree_view_column_cell_get_real_size (column, - NULL, NULL, NULL, - minimal_size, desired_size); -} - #define __GTK_TREE_VIEW_COLUMN_C__ #include "gtkaliasdef.c" diff --git a/gtk/gtktreeviewcolumn.h b/gtk/gtktreeviewcolumn.h index 5b9cd2a880..b06e845d9f 100644 --- a/gtk/gtktreeviewcolumn.h +++ b/gtk/gtktreeviewcolumn.h @@ -51,7 +51,6 @@ typedef enum typedef struct _GtkTreeViewColumn GtkTreeViewColumn; typedef struct _GtkTreeViewColumnClass GtkTreeViewColumnClass; -typedef struct _GtkTreeViewColumnPrivate GtkTreeViewColumnPrivate; typedef void (* GtkTreeCellDataFunc) (GtkTreeViewColumn *tree_column, GtkCellRenderer *cell, @@ -229,9 +228,6 @@ void gtk_tree_view_column_cell_get_size (GtkTreeViewCol gint *y_offset, gint *width, gint *height); -void gtk_tree_view_column_get_desired_size (GtkTreeViewColumn *column, - GtkRequisition *minimal_size, - GtkRequisition *desired_size); gboolean gtk_tree_view_column_cell_is_visible (GtkTreeViewColumn *tree_column); void gtk_tree_view_column_focus_cell (GtkTreeViewColumn *tree_column, GtkCellRenderer *cell);