Provide natural size information. Consider and provide natural size

2007-08-01  Mathias Hasselmann  <mathias.hasselmann@gmx.de>

	* gtk/gtkcellrenderertext.c: Provide natural size information.
	* gtk/gtkcellview.c: Consider and provide natural size information.
	* tests/testextendedlayout.c: Change background of testing cell view.

svn path=/branches/extended-layout/; revision=18567
This commit is contained in:
Mathias Hasselmann
2007-08-01 15:53:34 +00:00
committed by Mathias Hasselmann
parent 0dd9d1d11c
commit f1d13bd56b
4 changed files with 110 additions and 6 deletions

View File

@@ -1,3 +1,9 @@
2007-08-01 Mathias Hasselmann <mathias.hasselmann@gmx.de>
* gtk/gtkcellrenderertext.c: Provide natural size information.
* gtk/gtkcellview.c: Consider and provide natural size information.
* tests/testextendedlayout.c: Change background of testing cell view.
2007-08-01 Mathias Hasselmann <mathias.hasselmann@gmx.de>
* gtk/gtkcellview.c: Seems there is no point in distinguishing between

View File

@@ -20,6 +20,7 @@
#include <config.h>
#include <stdlib.h>
#include "gtkcellrenderertext.h"
#include "gtkextendedlayout.h"
#include "gtkeditable.h"
#include "gtkentry.h"
#include "gtkmarshalers.h"
@@ -61,6 +62,8 @@ static GtkCellEditable *gtk_cell_renderer_text_start_editing (GtkCellRenderer
GdkRectangle *cell_area,
GtkCellRendererState flags);
static void gtk_cell_renderer_text_extended_layout_init (GtkExtendedLayoutIface *iface);
enum {
EDITED,
LAST_SIGNAL
@@ -148,9 +151,12 @@ struct _GtkCellRendererTextPrivate
gint wrap_width;
GtkWidget *entry;
GtkWidget *owner;
};
G_DEFINE_TYPE (GtkCellRendererText, gtk_cell_renderer_text, GTK_TYPE_CELL_RENDERER)
G_DEFINE_TYPE_WITH_CODE (GtkCellRendererText, gtk_cell_renderer_text, GTK_TYPE_CELL_RENDERER,
G_IMPLEMENT_INTERFACE (GTK_TYPE_EXTENDED_LAYOUT,
gtk_cell_renderer_text_extended_layout_init))
static void
gtk_cell_renderer_text_init (GtkCellRendererText *celltext)
@@ -1489,6 +1495,7 @@ get_size (GtkCellRenderer *cell,
GtkCellRendererTextPrivate *priv;
priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (cell);
priv->owner = widget;
if (celltext->calc_fixed_height)
{
@@ -1920,5 +1927,37 @@ gtk_cell_renderer_text_set_fixed_height_from_font (GtkCellRendererText *renderer
}
}
static GtkExtendedLayoutFeatures
gtk_cell_renderer_text_extended_layout_get_features (GtkExtendedLayout *layout)
{
return GTK_EXTENDED_LAYOUT_NATURAL_SIZE;
}
static void
gtk_cell_renderer_text_extended_layout_get_natural_size (GtkExtendedLayout *layout,
GtkRequisition *requisition)
{
GtkCellRendererTextPrivate *priv;
PangoEllipsizeMode ellipsize;
priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (layout);
ellipsize = priv->ellipsize;
priv->ellipsize = PANGO_ELLIPSIZE_NONE;
get_size (GTK_CELL_RENDERER (layout),
priv->owner, NULL, NULL, NULL, NULL,
&requisition->width, &requisition->height);
priv->ellipsize = ellipsize;
}
static void
gtk_cell_renderer_text_extended_layout_init (GtkExtendedLayoutIface *iface)
{
iface->get_features = gtk_cell_renderer_text_extended_layout_get_features;
iface->get_natural_size = gtk_cell_renderer_text_extended_layout_get_natural_size;
}
#define __GTK_CELL_RENDERER_TEXT_C__
#include "gtkaliasdef.c"

View File

@@ -21,10 +21,12 @@
#include <string.h>
#include "gtkcellview.h"
#include "gtkcelllayout.h"
#include "gtkextendedlayout.h"
#include "gtkintl.h"
#include "gtksignal.h"
#include "gtkcellrenderertext.h"
#include "gtkcellrendererpixbuf.h"
#include "gtkextendedlayout.h"
#include "gtkprivate.h"
#include <gobject/gmarshal.h>
#include "gtkbuildable.h"
@@ -36,6 +38,7 @@ struct _GtkCellViewCellInfo
GtkCellRenderer *cell;
gint requested_width;
gint natural_width;
gint real_width;
guint expand : 1;
guint pack : 1;
@@ -121,6 +124,9 @@ static void gtk_cell_view_buildable_custom_tag_end (GtkBuildable
const gchar *tagname,
gpointer *data);
/* extended layout */
static void gtk_cell_view_extended_layout_init (GtkExtendedLayoutIface *iface);
static GtkBuildableIface *parent_buildable_iface;
#define GTK_CELL_VIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_CELL_VIEW, GtkCellViewPrivate))
@@ -138,7 +144,9 @@ 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))
gtk_cell_view_buildable_init)
G_IMPLEMENT_INTERFACE (GTK_TYPE_EXTENDED_LAYOUT,
gtk_cell_view_extended_layout_init))
static void
gtk_cell_view_class_init (GtkCellViewClass *klass)
@@ -317,6 +325,7 @@ gtk_cell_view_size_request (GtkWidget *widget,
GList *i;
gboolean first_cell = TRUE;
GtkCellView *cellview;
GtkRequisition natural_size;
cellview = GTK_CELL_VIEW (widget);
@@ -341,6 +350,15 @@ gtk_cell_view_size_request (GtkWidget *widget,
&width, &height);
info->requested_width = width;
if (GTK_EXTENDED_LAYOUT_HAS_NATURAL_SIZE (info->cell))
{
gtk_extended_layout_get_natural_size (GTK_EXTENDED_LAYOUT (info->cell), &natural_size);
info->natural_width = natural_size.width;
}
else
info->natural_width = info->requested_width;
requisition->width += width;
requisition->height = MAX (requisition->height, height);
@@ -356,8 +374,9 @@ gtk_cell_view_size_allocate (GtkWidget *widget,
GList *i;
gint nexpand_cells = 0;
gint full_requested_width = 0;
gint available, extra;
gint requested_width = 0;
gint natural_width = 0;
gint available, natural, extra;
widget->allocation = *allocation;
@@ -374,10 +393,13 @@ gtk_cell_view_size_allocate (GtkWidget *widget,
if (info->expand)
nexpand_cells++;
full_requested_width += info->requested_width;
requested_width += info->requested_width;
natural_width += info->natural_width - info->requested_width;
}
available = MAX (0, widget->allocation.width - full_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;
@@ -393,6 +415,9 @@ gtk_cell_view_size_allocate (GtkWidget *widget,
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 (1 == nexpand_cells)
@@ -1123,6 +1148,36 @@ gtk_cell_view_buildable_custom_tag_end (GtkBuildable *buildable,
data);
}
static GtkExtendedLayoutFeatures
gtk_cell_view_extended_layout_get_features (GtkExtendedLayout *layout)
{
return GTK_EXTENDED_LAYOUT_NATURAL_SIZE;
}
static void
gtk_cell_view_extended_layout_get_natural_size (GtkExtendedLayout *layout,
GtkRequisition *requisition)
{
GList *i;
requisition->width = 0;
requisition->height = GTK_WIDGET (layout)->requisition.height;
for (i = GTK_CELL_VIEW (layout)->priv->cell_list; i; i = i->next)
{
GtkCellViewCellInfo *info = (GtkCellViewCellInfo *)i->data;
if (info->cell->visible)
requisition->width += info->natural_width;
}
}
static void
gtk_cell_view_extended_layout_init (GtkExtendedLayoutIface *iface)
{
iface->get_features = gtk_cell_view_extended_layout_get_features;
iface->get_natural_size = gtk_cell_view_extended_layout_get_natural_size;
}
#define __GTK_CELL_VIEW_C__
#include "gtkaliasdef.c"

View File

@@ -492,6 +492,7 @@ natural_size_test_misc_create_child (TestCase *test,
GError *error = NULL;
gint child_stdout;
char buffer[32];
GdkColor color;
if (type >= 3)
{
@@ -577,6 +578,9 @@ natural_size_test_misc_create_child (TestCase *test,
case 3:
child = gtk_cell_view_new ();
if (gdk_color_parse ("#ffc", &color))
gtk_cell_view_set_background_color (GTK_CELL_VIEW (child), &color);
cell = gtk_cell_renderer_pixbuf_new ();
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (child), cell, FALSE);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (child), cell,