X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=gtk%2Fgtkcelllayout.c;h=d56747c1c49b632d03ef8d9a638c83e45ba9eba5;hb=6cf78a12c1e179b2d5eef4f045e242ceae475709;hp=35ff6f5344992511ea637c2618352490cb3dc4f6;hpb=e9cc9d5c47e93396101a47192775031df149b690;p=~andy%2Fgtk diff --git a/gtk/gtkcelllayout.c b/gtk/gtkcelllayout.c index 35ff6f534..d56747c1c 100644 --- a/gtk/gtkcelllayout.c +++ b/gtk/gtkcelllayout.c @@ -93,16 +93,220 @@ #include "gtkbuilderprivate.h" #include "gtkintl.h" +#define warn_no_cell_area(func) \ + g_critical ("%s: Called but no GtkCellArea is available yet", func) typedef GtkCellLayoutIface GtkCellLayoutInterface; G_DEFINE_INTERFACE (GtkCellLayout, gtk_cell_layout, G_TYPE_OBJECT); +static void gtk_cell_layout_default_pack_start (GtkCellLayout *cell_layout, + GtkCellRenderer *cell, + gboolean expand); +static void gtk_cell_layout_default_pack_end (GtkCellLayout *cell_layout, + GtkCellRenderer *cell, + gboolean expand); +static void gtk_cell_layout_default_clear (GtkCellLayout *cell_layout); +static void gtk_cell_layout_default_add_attribute (GtkCellLayout *cell_layout, + GtkCellRenderer *cell, + const gchar *attribute, + gint column); +static void gtk_cell_layout_default_set_cell_data_func (GtkCellLayout *cell_layout, + GtkCellRenderer *cell, + GtkCellLayoutDataFunc func, + gpointer func_data, + GDestroyNotify destroy); +static void gtk_cell_layout_default_clear_attributes (GtkCellLayout *cell_layout, + GtkCellRenderer *cell); +static void gtk_cell_layout_default_reorder (GtkCellLayout *cell_layout, + GtkCellRenderer *cell, + gint position); +static GList *gtk_cell_layout_default_get_cells (GtkCellLayout *cell_layout); + + +static void +gtk_cell_layout_default_init (GtkCellLayoutIface *iface) +{ + iface->pack_start = gtk_cell_layout_default_pack_start; + iface->pack_end = gtk_cell_layout_default_pack_end; + iface->clear = gtk_cell_layout_default_clear; + iface->add_attribute = gtk_cell_layout_default_add_attribute; + iface->set_cell_data_func = gtk_cell_layout_default_set_cell_data_func; + iface->clear_attributes = gtk_cell_layout_default_clear_attributes; + iface->reorder = gtk_cell_layout_default_reorder; + iface->get_cells = gtk_cell_layout_default_get_cells; +} + +/* Default implementation is to fall back on an underlying cell area */ +static void +gtk_cell_layout_default_pack_start (GtkCellLayout *cell_layout, + GtkCellRenderer *cell, + gboolean expand) +{ + GtkCellLayoutIface *iface; + GtkCellArea *area; + + iface = GTK_CELL_LAYOUT_GET_IFACE (cell_layout); + + if (iface->get_area) + { + area = iface->get_area (cell_layout); + + if (area) + gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (area), cell, expand); + else + warn_no_cell_area ("GtkCellLayoutIface->pack_start()"); + } +} + +static void +gtk_cell_layout_default_pack_end (GtkCellLayout *cell_layout, + GtkCellRenderer *cell, + gboolean expand) +{ + GtkCellLayoutIface *iface; + GtkCellArea *area; + + iface = GTK_CELL_LAYOUT_GET_IFACE (cell_layout); + + if (iface->get_area) + { + area = iface->get_area (cell_layout); + + if (area) + gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (area), cell, expand); + else + warn_no_cell_area ("GtkCellLayoutIface->pack_end()"); + } +} static void -gtk_cell_layout_default_init (GtkCellLayoutInterface *iface) +gtk_cell_layout_default_clear (GtkCellLayout *cell_layout) +{ + GtkCellLayoutIface *iface; + GtkCellArea *area; + + iface = GTK_CELL_LAYOUT_GET_IFACE (cell_layout); + + if (iface->get_area) + { + area = iface->get_area (cell_layout); + + if (area) + gtk_cell_layout_clear (GTK_CELL_LAYOUT (area)); + else + warn_no_cell_area ("GtkCellLayoutIface->clear()"); + } +} + +static void +gtk_cell_layout_default_add_attribute (GtkCellLayout *cell_layout, + GtkCellRenderer *cell, + const gchar *attribute, + gint column) +{ + GtkCellLayoutIface *iface; + GtkCellArea *area; + + iface = GTK_CELL_LAYOUT_GET_IFACE (cell_layout); + + if (iface->get_area) + { + area = iface->get_area (cell_layout); + + if (area) + gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (area), cell, attribute, column); + else + warn_no_cell_area ("GtkCellLayoutIface->add_attribute()"); + } +} + +static void +gtk_cell_layout_default_set_cell_data_func (GtkCellLayout *cell_layout, + GtkCellRenderer *cell, + GtkCellLayoutDataFunc func, + gpointer func_data, + GDestroyNotify destroy) +{ + GtkCellLayoutIface *iface; + GtkCellArea *area; + + iface = GTK_CELL_LAYOUT_GET_IFACE (cell_layout); + + if (iface->get_area) + { + area = iface->get_area (cell_layout); + + if (area) + _gtk_cell_area_set_cell_data_func_with_proxy (area, cell, + (GFunc)func, func_data, destroy, + cell_layout); + else + warn_no_cell_area ("GtkCellLayoutIface->set_cell_data_func()"); + } +} + +static void +gtk_cell_layout_default_clear_attributes (GtkCellLayout *cell_layout, + GtkCellRenderer *cell) +{ + GtkCellLayoutIface *iface; + GtkCellArea *area; + + iface = GTK_CELL_LAYOUT_GET_IFACE (cell_layout); + + if (iface->get_area) + { + area = iface->get_area (cell_layout); + + if (area) + gtk_cell_layout_clear_attributes (GTK_CELL_LAYOUT (area), cell); + else + warn_no_cell_area ("GtkCellLayoutIface->clear_attributes()"); + } +} + +static void +gtk_cell_layout_default_reorder (GtkCellLayout *cell_layout, + GtkCellRenderer *cell, + gint position) +{ + GtkCellLayoutIface *iface; + GtkCellArea *area; + + iface = GTK_CELL_LAYOUT_GET_IFACE (cell_layout); + + if (iface->get_area) + { + area = iface->get_area (cell_layout); + + if (area) + gtk_cell_layout_reorder (GTK_CELL_LAYOUT (area), cell, position); + else + warn_no_cell_area ("GtkCellLayoutIface->reorder()"); + } +} + +static GList * +gtk_cell_layout_default_get_cells (GtkCellLayout *cell_layout) { + GtkCellLayoutIface *iface; + GtkCellArea *area; + + iface = GTK_CELL_LAYOUT_GET_IFACE (cell_layout); + + if (iface->get_area) + { + area = iface->get_area (cell_layout); + + if (area) + return gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (area)); + else + warn_no_cell_area ("GtkCellLayoutIface->get_cells()"); + } + return NULL; } + /** * gtk_cell_layout_pack_start: * @cell_layout: a #GtkCellLayout @@ -122,23 +326,10 @@ gtk_cell_layout_pack_start (GtkCellLayout *cell_layout, GtkCellRenderer *cell, gboolean expand) { - GtkCellLayoutIface *iface; - GtkCellArea *area; - g_return_if_fail (GTK_IS_CELL_LAYOUT (cell_layout)); g_return_if_fail (GTK_IS_CELL_RENDERER (cell)); - iface = GTK_CELL_LAYOUT_GET_IFACE (cell_layout); - - if (iface->pack_start) - iface->pack_start (cell_layout, cell, expand); - else - { - area = iface->get_area (cell_layout); - - if (area) - gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (area), cell, expand); - } + GTK_CELL_LAYOUT_GET_IFACE (cell_layout)->pack_start (cell_layout, cell, expand); } /** @@ -160,23 +351,10 @@ gtk_cell_layout_pack_end (GtkCellLayout *cell_layout, GtkCellRenderer *cell, gboolean expand) { - GtkCellLayoutIface *iface; - GtkCellArea *area; - g_return_if_fail (GTK_IS_CELL_LAYOUT (cell_layout)); g_return_if_fail (GTK_IS_CELL_RENDERER (cell)); - iface = GTK_CELL_LAYOUT_GET_IFACE (cell_layout); - - if (iface->pack_end) - iface->pack_end (cell_layout, cell, expand); - else - { - area = iface->get_area (cell_layout); - - if (area) - gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (area), cell, expand); - } + GTK_CELL_LAYOUT_GET_IFACE (cell_layout)->pack_end (cell_layout, cell, expand); } /** @@ -191,22 +369,9 @@ gtk_cell_layout_pack_end (GtkCellLayout *cell_layout, void gtk_cell_layout_clear (GtkCellLayout *cell_layout) { - GtkCellLayoutIface *iface; - GtkCellArea *area; - g_return_if_fail (GTK_IS_CELL_LAYOUT (cell_layout)); - iface = GTK_CELL_LAYOUT_GET_IFACE (cell_layout); - - if (iface->clear) - iface->clear (cell_layout); - else - { - area = iface->get_area (cell_layout); - - if (area) - gtk_cell_layout_clear (GTK_CELL_LAYOUT (area)); - } + GTK_CELL_LAYOUT_GET_IFACE (cell_layout)->clear (cell_layout); } static void @@ -216,28 +381,16 @@ gtk_cell_layout_set_attributesv (GtkCellLayout *cell_layout, { gchar *attribute; gint column; - GtkCellLayoutIface *iface; - GtkCellArea *area; attribute = va_arg (args, gchar *); - iface = GTK_CELL_LAYOUT_GET_IFACE (cell_layout); - - if (iface->get_area) - area = iface->get_area (cell_layout); - - if (iface->clear_attributes) - iface->clear_attributes (cell_layout, cell); - else if (area) - gtk_cell_layout_clear_attributes (GTK_CELL_LAYOUT (area), cell); + gtk_cell_layout_clear_attributes (cell_layout, cell); while (attribute != NULL) { column = va_arg (args, gint); - if (iface->add_attribute) - iface->add_attribute (cell_layout, cell, attribute, column); - else if (area) - gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (area), cell, attribute, column); + + gtk_cell_layout_add_attribute (cell_layout, cell, attribute, column); attribute = va_arg (args, gchar *); } @@ -294,35 +447,19 @@ gtk_cell_layout_add_attribute (GtkCellLayout *cell_layout, const gchar *attribute, gint column) { - GtkCellLayoutIface *iface; - GtkCellArea *area; - g_return_if_fail (GTK_IS_CELL_LAYOUT (cell_layout)); g_return_if_fail (GTK_IS_CELL_RENDERER (cell)); g_return_if_fail (attribute != NULL); g_return_if_fail (column >= 0); - iface = GTK_CELL_LAYOUT_GET_IFACE (cell_layout); - - if (iface->add_attribute) - iface->add_attribute (cell_layout, - cell, - attribute, - column); - else - { - area = iface->get_area (cell_layout); - - if (area) - gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (area), cell, attribute, column); - } + GTK_CELL_LAYOUT_GET_IFACE (cell_layout)->add_attribute (cell_layout, cell, attribute, column); } /** * gtk_cell_layout_set_cell_data_func: * @cell_layout: a #GtkCellLayout * @cell: a #GtkCellRenderer - * @func (allow-none: the #GtkCellLayoutDataFunc to use, or %NULL + * @func: (allow-none): the #GtkCellLayoutDataFunc to use, or %NULL * @func_data: user data for @func * @destroy: destroy notify for @func_data * @@ -343,36 +480,11 @@ gtk_cell_layout_set_cell_data_func (GtkCellLayout *cell_layout, gpointer func_data, GDestroyNotify destroy) { - GtkCellLayoutIface *iface; - GtkCellArea *area; - g_return_if_fail (GTK_IS_CELL_LAYOUT (cell_layout)); g_return_if_fail (GTK_IS_CELL_RENDERER (cell)); - iface = GTK_CELL_LAYOUT_GET_IFACE (cell_layout); - - if (iface->set_cell_data_func) - iface->set_cell_data_func (cell_layout, - cell, - func, - func_data, - destroy); - else - { - area = iface->get_area (cell_layout); - - if (area) - { - /* Ensure that the correct proxy object is sent to 'func' */ - if (GTK_CELL_LAYOUT (area) != cell_layout) - _gtk_cell_area_set_cell_data_func_with_proxy (area, cell, - (GFunc)func, func_data, destroy, - cell_layout); - else - gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (area), cell, - func, func_data, destroy); - } - } + GTK_CELL_LAYOUT_GET_IFACE + (cell_layout)->set_cell_data_func (cell_layout, cell, func, func_data, destroy); } /** @@ -389,23 +501,10 @@ void gtk_cell_layout_clear_attributes (GtkCellLayout *cell_layout, GtkCellRenderer *cell) { - GtkCellLayoutIface *iface; - GtkCellArea *area; - g_return_if_fail (GTK_IS_CELL_LAYOUT (cell_layout)); g_return_if_fail (GTK_IS_CELL_RENDERER (cell)); - iface = GTK_CELL_LAYOUT_GET_IFACE (cell_layout); - - if (iface->clear_attributes) - iface->clear_attributes (cell_layout, cell); - else - { - area = iface->get_area (cell_layout); - - if (area) - gtk_cell_layout_clear_attributes (GTK_CELL_LAYOUT (area), cell); - } + GTK_CELL_LAYOUT_GET_IFACE (cell_layout)->clear_attributes (cell_layout, cell); } /** @@ -426,23 +525,10 @@ gtk_cell_layout_reorder (GtkCellLayout *cell_layout, GtkCellRenderer *cell, gint position) { - GtkCellLayoutIface *iface; - GtkCellArea *area; - g_return_if_fail (GTK_IS_CELL_LAYOUT (cell_layout)); g_return_if_fail (GTK_IS_CELL_RENDERER (cell)); - iface = GTK_CELL_LAYOUT_GET_IFACE (cell_layout); - - if (iface->reorder) - iface->reorder (cell_layout, cell, position); - else - { - area = iface->get_area (cell_layout); - - if (area) - gtk_cell_layout_reorder (GTK_CELL_LAYOUT (area), cell, position); - } + GTK_CELL_LAYOUT_GET_IFACE (cell_layout)->reorder (cell_layout, cell, position); } /** @@ -461,23 +547,9 @@ gtk_cell_layout_reorder (GtkCellLayout *cell_layout, GList * gtk_cell_layout_get_cells (GtkCellLayout *cell_layout) { - GtkCellLayoutIface *iface; - GtkCellArea *area; - g_return_val_if_fail (GTK_IS_CELL_LAYOUT (cell_layout), NULL); - iface = GTK_CELL_LAYOUT_GET_IFACE (cell_layout); - if (iface->get_cells) - return iface->get_cells (cell_layout); - else - { - area = iface->get_area (cell_layout); - - if (area) - return gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (area)); - } - - return NULL; + return GTK_CELL_LAYOUT_GET_IFACE (cell_layout)->get_cells (cell_layout); } /** @@ -488,9 +560,7 @@ gtk_cell_layout_get_cells (GtkCellLayout *cell_layout) * if called on a #GtkCellArea or might be %NULL if no #GtkCellArea * is used by @cell_layout. * - * Return value: (transfer none): a list of cell renderers. The list, - * but not the renderers has been newly allocated and should be - * freed with g_list_free() when no longer needed. + * Return value: (transfer none): the cell area used by @cell_layout. * * Since: 3.0 */