#include "gtkintl.h"
#include "gtkcellrenderertext.h"
#include "gtkcellrendererpixbuf.h"
-#include "gtksizerequest.h"
-#include "gtkcellsizerequest.h"
#include "gtkprivate.h"
+#include "gtksizerequest.h"
#include <gobject/gmarshal.h>
#include "gtkbuildable.h"
GList *cell_list;
gint spacing;
- GdkColor background;
+ GdkRGBA background;
gboolean background_set;
};
static void gtk_cell_view_finalize (GObject *object);
static void gtk_cell_view_size_allocate (GtkWidget *widget,
GtkAllocation *allocation);
-static gboolean gtk_cell_view_expose (GtkWidget *widget,
- GdkEventExpose *event);
+static gboolean gtk_cell_view_draw (GtkWidget *widget,
+ cairo_t *cr);
static void gtk_cell_view_set_value (GtkCellView *cell_view,
GtkCellRenderer *renderer,
gchar *property,
const gchar *tagname,
gpointer *data);
-static void gtk_cell_view_size_request_init (GtkSizeRequestIface *iface);
-static void gtk_cell_view_get_width (GtkSizeRequest *widget,
+static void gtk_cell_view_get_preferred_width (GtkWidget *widget,
gint *minimum_size,
gint *natural_size);
-static void gtk_cell_view_get_height (GtkSizeRequest *widget,
+static void gtk_cell_view_get_preferred_height (GtkWidget *widget,
gint *minimum_size,
gint *natural_size);
-static void gtk_cell_view_get_width_for_height (GtkSizeRequest *widget,
+static void gtk_cell_view_get_preferred_width_for_height (GtkWidget *widget,
gint avail_size,
gint *minimum_size,
gint *natural_size);
-static void gtk_cell_view_get_height_for_width (GtkSizeRequest *widget,
+static void gtk_cell_view_get_preferred_height_for_width (GtkWidget *widget,
gint avail_size,
gint *minimum_size,
gint *natural_size);
PROP_0,
PROP_BACKGROUND,
PROP_BACKGROUND_GDK,
+ PROP_BACKGROUND_RGBA,
PROP_BACKGROUND_SET,
PROP_MODEL
};
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_SIZE_REQUEST,
- gtk_cell_view_size_request_init))
+ gtk_cell_view_buildable_init))
static void
gobject_class->set_property = gtk_cell_view_set_property;
gobject_class->finalize = gtk_cell_view_finalize;
- widget_class->expose_event = gtk_cell_view_expose;
- widget_class->size_allocate = gtk_cell_view_size_allocate;
+ widget_class->draw = gtk_cell_view_draw;
+ widget_class->size_allocate = gtk_cell_view_size_allocate;
+ widget_class->get_preferred_width = gtk_cell_view_get_preferred_width;
+ widget_class->get_preferred_height = gtk_cell_view_get_preferred_height;
+ widget_class->get_preferred_width_for_height = gtk_cell_view_get_preferred_width_for_height;
+ widget_class->get_preferred_height_for_width = gtk_cell_view_get_preferred_height_for_width;
/* properties */
g_object_class_install_property (gobject_class,
P_("Background color as a GdkColor"),
GDK_TYPE_COLOR,
GTK_PARAM_READWRITE));
+ /**
+ * GtkCellView:background-rgba
+ *
+ * The background color as a #GdkRGBA
+ *
+ * Since: 3.0
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_BACKGROUND_RGBA,
+ g_param_spec_boxed ("background-rgba",
+ P_("Background RGBA color"),
+ P_("Background color as a GdkRGBA"),
+ GDK_TYPE_RGBA,
+ GTK_PARAM_READWRITE));
/**
* GtkCellView:model
{
GdkColor color;
- color = view->priv->background;
+ color.red = (guint) (view->priv->background.red * 65535);
+ color.green = (guint) (view->priv->background.green * 65535);
+ color.blue = (guint) (view->priv->background.blue * 65535);
+ color.pixel = 0;
g_value_set_boxed (value, &color);
}
break;
+ case PROP_BACKGROUND_RGBA:
+ g_value_set_boxed (value, &view->priv->background);
+ break;
case PROP_BACKGROUND_SET:
g_value_set_boolean (value, view->priv->background_set);
break;
case PROP_BACKGROUND_GDK:
gtk_cell_view_set_background_color (view, g_value_get_boxed (value));
break;
+ case PROP_BACKGROUND_RGBA:
+ gtk_cell_view_set_background_rgba (view, g_value_get_boxed (value));
+ break;
case PROP_BACKGROUND_SET:
view->priv->background_set = g_value_get_boolean (value);
break;
}
static gboolean
-gtk_cell_view_expose (GtkWidget *widget,
- GdkEventExpose *event)
+gtk_cell_view_draw (GtkWidget *widget,
+ cairo_t *cr)
{
- GtkAllocation allocation;
GList *list;
GtkCellView *cellview;
GdkRectangle area;
GtkCellRendererState state;
gboolean rtl = (gtk_widget_get_direction(widget) == GTK_TEXT_DIR_RTL);
GtkPackType packing;
- cairo_t *cr;
+ int width;
cellview = GTK_CELL_VIEW (widget);
- if (!gtk_widget_is_drawable (widget))
- return FALSE;
-
- gtk_widget_get_allocation (widget, &allocation);
- cr = gdk_cairo_create (event->window);
- gdk_cairo_region (cr, event->region);
- cairo_clip (cr);
+ /* render cells */
+ area.x = 0;
+ area.y = 0;
+ area.width = width = gtk_widget_get_allocated_width (widget);
+ area.height = gtk_widget_get_allocated_height (widget);
/* "blank" background */
if (cellview->priv->background_set)
{
- gdk_cairo_rectangle (cr, &allocation);
- cairo_set_source_rgb (cr,
- cellview->priv->background.red / 65535.,
- cellview->priv->background.green / 65535.,
- cellview->priv->background.blue / 65535.);
+ gdk_cairo_rectangle (cr, &area);
+ gdk_cairo_set_source_rgba (cr, &cellview->priv->background);
cairo_fill (cr);
}
if (cellview->priv->displayed_row)
gtk_cell_view_set_cell_data (cellview);
else if (cellview->priv->model)
- {
- cairo_destroy (cr);
- return FALSE;
- }
-
- /* render cells */
- area = allocation;
-
- /* we draw on our very own window, initialize x and y to zero */
- area.y = allocation.y;
+ return FALSE;
if (gtk_widget_get_state (widget) == GTK_STATE_PRELIGHT)
state = GTK_CELL_RENDERER_PRELIT;
for (packing = GTK_PACK_START; packing <= GTK_PACK_END; ++packing)
{
if (packing == GTK_PACK_START)
- area.x = allocation.x + (rtl ? allocation.width : 0);
+ area.x = rtl ? width : 0;
else
- area.x = rtl ? allocation.x : (allocation.x + allocation.width);
+ area.x = rtl ? 0 : width;
for (list = cellview->priv->cell_list; list; list = list->next)
{
(packing == GTK_PACK_END && !rtl))
area.x -= area.width;
- gtk_cell_renderer_render_cairo (info->cell,
- cr,
- widget,
- /* FIXME! */
- &area, &area, state);
+ gtk_cell_renderer_render (info->cell,
+ cr,
+ widget,
+ /* FIXME! */
+ &area, &area, state);
if ((packing == GTK_PACK_START && !rtl) ||
(packing == GTK_PACK_END && rtl))
}
}
- cairo_destroy (cr);
-
return FALSE;
}
cell_view->priv->displayed_row =
gtk_tree_row_reference_new (cell_view->priv->model, path);
- gtk_cell_view_get_width (GTK_SIZE_REQUEST (cell_view), minimum_size, natural_size);
+ gtk_cell_view_get_preferred_width (GTK_WIDGET (cell_view), minimum_size, natural_size);
gtk_tree_row_reference_free (cell_view->priv->displayed_row);
cell_view->priv->displayed_row = tmp;
/* Restore active size (this will restore the cellrenderer info->width/requested_width's) */
- gtk_cell_view_get_width (GTK_SIZE_REQUEST (cell_view), NULL, NULL);
+ gtk_cell_view_get_preferred_width (GTK_WIDGET (cell_view), NULL, NULL);
}
gtk_tree_row_reference_new (cell_view->priv->model, path);
/* Then get the collective height_for_width based on the cached values */
- gtk_cell_view_get_height_for_width (GTK_SIZE_REQUEST (cell_view), avail_size, minimum_size, natural_size);
+ gtk_cell_view_get_preferred_height_for_width (GTK_WIDGET (cell_view), avail_size, minimum_size, natural_size);
gtk_tree_row_reference_free (cell_view->priv->displayed_row);
cell_view->priv->displayed_row = tmp;
/* Restore active size (this will restore the cellrenderer info->width/requested_width's) */
- gtk_cell_view_get_width (GTK_SIZE_REQUEST (cell_view), NULL, NULL);
+ gtk_cell_view_get_preferred_width (GTK_WIDGET (cell_view), NULL, NULL);
}
/**
g_object_notify (G_OBJECT (cell_view), "background-set");
}
- cell_view->priv->background = *color;
+ cell_view->priv->background.red = color->red / 65535.;
+ cell_view->priv->background.green = color->green / 65535.;
+ cell_view->priv->background.blue = color->blue / 65535.;
+ cell_view->priv->background.alpha = 1;
+ }
+ else
+ {
+ if (cell_view->priv->background_set)
+ {
+ cell_view->priv->background_set = FALSE;
+ g_object_notify (G_OBJECT (cell_view), "background-set");
+ }
+ }
+
+ gtk_widget_queue_draw (GTK_WIDGET (cell_view));
+}
+
+/**
+ * gtk_cell_view_set_background_rgba:
+ * @cell_view: a #GtkCellView
+ * @rgba: the new background color
+ *
+ * Sets the background color of @cell_view.
+ *
+ * Since: 3.0
+ */
+void
+gtk_cell_view_set_background_rgba (GtkCellView *cell_view,
+ const GdkRGBA *rgba)
+{
+ g_return_if_fail (GTK_IS_CELL_VIEW (cell_view));
+
+ if (rgba)
+ {
+ if (!cell_view->priv->background_set)
+ {
+ cell_view->priv->background_set = TRUE;
+ g_object_notify (G_OBJECT (cell_view), "background-set");
+ }
+
+ cell_view->priv->background = *rgba;
}
else
{
}
static void
-gtk_cell_view_size_request_init (GtkSizeRequestIface *iface)
-{
- iface->get_width = gtk_cell_view_get_width;
- iface->get_height = gtk_cell_view_get_height;
- iface->get_width_for_height = gtk_cell_view_get_width_for_height;
- iface->get_height_for_width = gtk_cell_view_get_height_for_width;
-}
-
-static void
-gtk_cell_view_get_width (GtkSizeRequest *widget,
- gint *minimum_size,
- gint *natural_size)
+gtk_cell_view_get_preferred_width (GtkWidget *widget,
+ gint *minimum_size,
+ gint *natural_size)
{
GList *list;
gint cell_min, cell_nat;
natural += cellview->priv->spacing;
}
- gtk_cell_size_request_get_width (GTK_CELL_SIZE_REQUEST (info->cell),
- GTK_WIDGET (cellview), &cell_min, &cell_nat);
+ gtk_cell_renderer_get_preferred_width (info->cell,
+ GTK_WIDGET (cellview), &cell_min, &cell_nat);
info->requested_width = cell_min;
info->natural_width = cell_nat;
}
static void
-gtk_cell_view_get_height (GtkSizeRequest *widget,
- gint *minimum_size,
- gint *natural_size)
+gtk_cell_view_get_preferred_height (GtkWidget *widget,
+ gint *minimum_size,
+ gint *natural_size)
{
gint minimum_width;
/* CellViews only need to respond to height-for-width mode (cellview is pretty much
* an implementation detail of GtkComboBox) */
- gtk_cell_view_get_width (widget, &minimum_width, NULL);
- gtk_cell_view_get_height_for_width (widget, minimum_width, minimum_size, natural_size);
+ gtk_cell_view_get_preferred_width (widget, &minimum_width, NULL);
+ gtk_cell_view_get_preferred_height_for_width (widget, minimum_width, minimum_size, natural_size);
}
static void
-gtk_cell_view_get_width_for_height (GtkSizeRequest *widget,
- gint for_size,
- gint *minimum_size,
- gint *natural_size)
+gtk_cell_view_get_preferred_width_for_height (GtkWidget *widget,
+ gint for_size,
+ gint *minimum_size,
+ gint *natural_size)
{
/* CellViews only need to respond to height-for-width mode (cellview is pretty much
* an implementation detail of GtkComboBox) */
- gtk_cell_view_get_width (widget, minimum_size, natural_size);
+ gtk_cell_view_get_preferred_width (widget, minimum_size, natural_size);
}
static void
-gtk_cell_view_get_height_for_width (GtkSizeRequest *widget,
- gint for_size,
- gint *minimum_size,
- gint *natural_size)
+gtk_cell_view_get_preferred_height_for_width (GtkWidget *widget,
+ gint for_size,
+ gint *minimum_size,
+ gint *natural_size)
{
GtkCellView *cellview = GTK_CELL_VIEW (widget);
GList *list;
{
GtkRequestedSize requested;
- gtk_cell_size_request_get_width (GTK_CELL_SIZE_REQUEST (info->cell),
- GTK_WIDGET (cellview),
- &requested.minimum_size,
- &requested.natural_size);
+ gtk_cell_renderer_get_preferred_width (GTK_CELL_RENDERER (info->cell),
+ GTK_WIDGET (cellview),
+ &requested.minimum_size,
+ &requested.natural_size);
requested.data = info;
g_array_append_val (array, requested);
}
/* Get the height for the real width of this cell */
- gtk_cell_size_request_get_height_for_width (GTK_CELL_SIZE_REQUEST (info->cell),
- GTK_WIDGET (widget),
- cell_width, &cell_minimum, &cell_natural);
+ gtk_cell_renderer_get_preferred_height_for_width (GTK_CELL_RENDERER (info->cell),
+ GTK_WIDGET (widget),
+ cell_width, &cell_minimum, &cell_natural);
minimum = MAX (minimum, cell_minimum);
natural = MAX (natural, cell_natural);