forked from AuroraMiddleware/gtk
Add new GtkExtendedCell interface
Added a new interface to extend layout information of GtkCellRenderers, GtkCellRenderer is a prerequisite of GtkExtendedCellIface and provides a base implementation of ->get_desired_size() with ->get_size(). Note that the api for GtkExtendedCell differs from GtkExtendedLayout since the cells need to be passed an additional widget to calculate sizes contextual to the widget/screen (fonts etc).
This commit is contained in:
parent
8263633478
commit
7beb83cea4
@ -212,6 +212,7 @@ gtk_public_h_sources = \
|
||||
gtkenums.h \
|
||||
gtkeventbox.h \
|
||||
gtkexpander.h \
|
||||
gtkextendedcell.h \
|
||||
gtkextendedlayout.h \
|
||||
gtkfilechooser.h \
|
||||
gtkfilechooserbutton.h \
|
||||
@ -467,6 +468,7 @@ gtk_base_c_sources = \
|
||||
gtkentrycompletion.c \
|
||||
gtkeventbox.c \
|
||||
gtkexpander.c \
|
||||
gtkextendedcell.c \
|
||||
gtkextendedlayout.c \
|
||||
gtkfilechooser.c \
|
||||
gtkfilechooserbutton.c \
|
||||
|
@ -1503,6 +1503,13 @@ 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_size
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if IN_HEADER(__GTK_EXTENDED_LAYOUT_H__)
|
||||
#if IN_FILE(__GTK_EXTENDED_LAYOUT_C__)
|
||||
gtk_extended_layout_get_type G_GNUC_CONST
|
||||
@ -4807,6 +4814,7 @@ 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
|
||||
@ -5242,7 +5250,6 @@ gtk_widget_show_all
|
||||
gtk_widget_show_now
|
||||
gtk_widget_size_allocate
|
||||
gtk_widget_size_request
|
||||
gtk_widget_get_desired_size
|
||||
gtk_widget_style_attach
|
||||
gtk_widget_style_get G_GNUC_NULL_TERMINATED
|
||||
gtk_widget_style_get_property
|
||||
|
@ -19,12 +19,15 @@
|
||||
|
||||
#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,
|
||||
@ -36,6 +39,8 @@ static void gtk_cell_renderer_set_property (GObject *object,
|
||||
static void set_cell_bg_color (GtkCellRenderer *cell,
|
||||
GdkColor *color);
|
||||
|
||||
static void gtk_cell_renderer_extended_cell_init (GtkExtendedCellIface *iface);
|
||||
|
||||
|
||||
#define GTK_CELL_RENDERER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_CELL_RENDERER, GtkCellRendererPrivate))
|
||||
|
||||
@ -72,9 +77,50 @@ enum {
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
static guint cell_renderer_signals[LAST_SIGNAL] = { 0 };
|
||||
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;
|
||||
}
|
||||
|
||||
G_DEFINE_ABSTRACT_TYPE (GtkCellRenderer, gtk_cell_renderer, GTK_TYPE_OBJECT)
|
||||
|
||||
static void
|
||||
gtk_cell_renderer_init (GtkCellRenderer *cell)
|
||||
@ -990,5 +1036,42 @@ gtk_cell_renderer_stop_editing (GtkCellRenderer *cell,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
gtk_cell_renderer_extended_cell_get_desired_size (GtkExtendedCell *cell,
|
||||
GtkWidget *widget,
|
||||
GtkRequisition *minimum_size,
|
||||
GtkRequisition *natural_size)
|
||||
{
|
||||
GtkRequisition min_req;
|
||||
|
||||
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 (minimum_size)
|
||||
{
|
||||
minimum_size->width = min_req.width;
|
||||
minimum_size->height = min_req.height;
|
||||
}
|
||||
|
||||
if (natural_size)
|
||||
{
|
||||
natural_size->width = min_req.width;
|
||||
natural_size->height = min_req.height;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_cell_renderer_extended_cell_init (GtkExtendedCellIface *iface)
|
||||
{
|
||||
iface->get_desired_size = gtk_cell_renderer_extended_cell_get_desired_size;
|
||||
}
|
||||
|
||||
#define __GTK_CELL_RENDERER_C__
|
||||
#include "gtkaliasdef.c"
|
||||
|
75
gtk/gtkextendedcell.c
Normal file
75
gtk/gtkextendedcell.c
Normal file
@ -0,0 +1,75 @@
|
||||
/* gtkextendedcell.c
|
||||
* Copyright (C) 2010 Openismus GmbH
|
||||
*
|
||||
* Author:
|
||||
* Tristan Van Berkom <tristan.van.berkom@gmail.com>
|
||||
*
|
||||
* 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 <config.h>
|
||||
#include "gtkcellrenderer.h"
|
||||
#include "gtkextendedcell.h"
|
||||
#include "gtkintl.h"
|
||||
#include "gtkalias.h"
|
||||
|
||||
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_size:
|
||||
* @cell: a #GtkExtendedCell instance
|
||||
* @widget: the #GtkWidget this cell will be rendering to
|
||||
* @minimum_size: location for storing the minimum size, or %NULL
|
||||
* @natural_size: location for storing the preferred size, or %NULL
|
||||
*
|
||||
* Retreives a renderer's desired size.
|
||||
*
|
||||
* Since: 3.0
|
||||
*/
|
||||
void
|
||||
gtk_extended_cell_get_desired_size (GtkExtendedCell *cell,
|
||||
GtkWidget *widget,
|
||||
GtkRequisition *minimum_size,
|
||||
GtkRequisition *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_size (cell, widget, minimum_size, natural_size);
|
||||
}
|
||||
|
||||
#define __GTK_EXTENDED_CELL_C__
|
||||
#include "gtkaliasdef.c"
|
62
gtk/gtkextendedcell.h
Normal file
62
gtk/gtkextendedcell.h
Normal file
@ -0,0 +1,62 @@
|
||||
/* GTK - The GIMP Toolkit
|
||||
* Copyright (C) 2010 Openismus GmbH
|
||||
*
|
||||
* Author:
|
||||
* Tristan Van Berkom <tristan.van.berkom@gmail.com>
|
||||
*
|
||||
* 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 <gtk/gtkwidget.h>
|
||||
|
||||
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_size) (GtkExtendedCell *cell,
|
||||
GtkWidget *widget,
|
||||
GtkRequisition *minimum_size,
|
||||
GtkRequisition *natural_size);
|
||||
};
|
||||
|
||||
GType gtk_extended_cell_get_type (void) G_GNUC_CONST;
|
||||
|
||||
void gtk_extended_cell_get_desired_size (GtkExtendedCell *cell,
|
||||
GtkWidget *widget,
|
||||
GtkRequisition *minimum_size,
|
||||
GtkRequisition *natural_size);
|
||||
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GTK_EXTENDED_CELL_H__ */
|
Loading…
Reference in New Issue
Block a user