Landing the new ComboBox. Note that only gtkcombobox.h and

Fri Sep 26 23:49:44 2003  Kristian Rietveld  <kris@gtk.org>

	Landing the new ComboBox. Note that only gtkcombobox.h and
	gtkcomboboxentry.h are public.

	* gtk/gtkcellview.[ch], gtk/gtkcellviewmenuitem.[ch],
	gtk/gtkcombobox.[ch], gtk/gtkcomboboxentry.[ch]: new files.

	* gtk/Makefile.am, gtk/gtk.h: adding the new files.

	* tests/testcombo.c: and a new test.

	* tests/Makefile.am: adding the new test.
This commit is contained in:
Kristian Rietveld 2003-09-26 21:57:06 +00:00 committed by Kristian Rietveld
parent 4a2de86c44
commit c920afd9c5
17 changed files with 4154 additions and 0 deletions

View File

@ -1,3 +1,17 @@
Fri Sep 26 23:49:44 2003 Kristian Rietveld <kris@gtk.org>
Landing the new ComboBox. Note that only gtkcombobox.h and
gtkcomboboxentry.h are public.
* gtk/gtkcellview.[ch], gtk/gtkcellviewmenuitem.[ch],
gtk/gtkcombobox.[ch], gtk/gtkcomboboxentry.[ch]: new files.
* gtk/Makefile.am, gtk/gtk.h: adding the new files.
* tests/testcombo.c: and a new test.
* tests/Makefile.am: adding the new test.
2003-09-25 Tor Lillqvist <tml@iki.fi>
* demos/gtk-demo/main.c: Don't use hardcoded DEMOCODEDIR on Windows.

View File

@ -1,3 +1,17 @@
Fri Sep 26 23:49:44 2003 Kristian Rietveld <kris@gtk.org>
Landing the new ComboBox. Note that only gtkcombobox.h and
gtkcomboboxentry.h are public.
* gtk/gtkcellview.[ch], gtk/gtkcellviewmenuitem.[ch],
gtk/gtkcombobox.[ch], gtk/gtkcomboboxentry.[ch]: new files.
* gtk/Makefile.am, gtk/gtk.h: adding the new files.
* tests/testcombo.c: and a new test.
* tests/Makefile.am: adding the new test.
2003-09-25 Tor Lillqvist <tml@iki.fi>
* demos/gtk-demo/main.c: Don't use hardcoded DEMOCODEDIR on Windows.

View File

@ -1,3 +1,17 @@
Fri Sep 26 23:49:44 2003 Kristian Rietveld <kris@gtk.org>
Landing the new ComboBox. Note that only gtkcombobox.h and
gtkcomboboxentry.h are public.
* gtk/gtkcellview.[ch], gtk/gtkcellviewmenuitem.[ch],
gtk/gtkcombobox.[ch], gtk/gtkcomboboxentry.[ch]: new files.
* gtk/Makefile.am, gtk/gtk.h: adding the new files.
* tests/testcombo.c: and a new test.
* tests/Makefile.am: adding the new test.
2003-09-25 Tor Lillqvist <tml@iki.fi>
* demos/gtk-demo/main.c: Don't use hardcoded DEMOCODEDIR on Windows.

View File

@ -1,3 +1,17 @@
Fri Sep 26 23:49:44 2003 Kristian Rietveld <kris@gtk.org>
Landing the new ComboBox. Note that only gtkcombobox.h and
gtkcomboboxentry.h are public.
* gtk/gtkcellview.[ch], gtk/gtkcellviewmenuitem.[ch],
gtk/gtkcombobox.[ch], gtk/gtkcomboboxentry.[ch]: new files.
* gtk/Makefile.am, gtk/gtk.h: adding the new files.
* tests/testcombo.c: and a new test.
* tests/Makefile.am: adding the new test.
2003-09-25 Tor Lillqvist <tml@iki.fi>
* demos/gtk-demo/main.c: Don't use hardcoded DEMOCODEDIR on Windows.

View File

@ -1,3 +1,17 @@
Fri Sep 26 23:49:44 2003 Kristian Rietveld <kris@gtk.org>
Landing the new ComboBox. Note that only gtkcombobox.h and
gtkcomboboxentry.h are public.
* gtk/gtkcellview.[ch], gtk/gtkcellviewmenuitem.[ch],
gtk/gtkcombobox.[ch], gtk/gtkcomboboxentry.[ch]: new files.
* gtk/Makefile.am, gtk/gtk.h: adding the new files.
* tests/testcombo.c: and a new test.
* tests/Makefile.am: adding the new test.
2003-09-25 Tor Lillqvist <tml@iki.fi>
* demos/gtk-demo/main.c: Don't use hardcoded DEMOCODEDIR on Windows.

View File

@ -118,6 +118,8 @@ gtk_public_h_sources = \
gtkcolorsel.h \
gtkcolorseldialog.h \
gtkcombo.h \
gtkcombobox.h \
gtkcomboboxentry.h \
gtkcontainer.h \
gtkctree.h \
gtkcurve.h \
@ -249,6 +251,8 @@ gtk_public_h_sources = \
# GTK+ header files that don't get installed
gtk_private_h_sources = \
gtkcellview.h \
gtkcellviewmenuitem.h \
gtkentryprivate.h \
gtkrbtree.h \
gtktextbtree.h \
@ -290,6 +294,8 @@ gtk_c_sources = \
gtkcellrendererpixbuf.c \
gtkcellrenderertext.c \
gtkcellrenderertoggle.c \
gtkcellview.c \
gtkcellviewmenuitem.c \
gtkcheckbutton.c \
gtkcheckmenuitem.c \
gtkclipboard.c \
@ -298,6 +304,8 @@ gtk_c_sources = \
gtkcolorsel.c \
gtkcolorseldialog.c \
gtkcombo.c \
gtkcombobox.c \
gtkcomboboxentry.c \
gtkcontainer.c \
gtkctree.c \
gtkcurve.c \

View File

@ -58,6 +58,8 @@
#include <gtk/gtkcolorsel.h>
#include <gtk/gtkcolorseldialog.h>
#include <gtk/gtkcombo.h>
#include <gtk/gtkcombobox.h>
#include <gtk/gtkcomboboxentry.h>
#include <gtk/gtkcontainer.h>
#include <gtk/gtkctree.h>
#include <gtk/gtkcurve.h>

835
gtk/gtkcellview.c Normal file
View File

@ -0,0 +1,835 @@
/* gtkellview.c
* Copyright (C) 2002, 2003 Kristian Rietveld <kris@gtk.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include <gtk/gtkcellview.h>
#include <gtk/gtkintl.h>
#include <gtk/gtksignal.h>
#include <gtk/gtkcellrenderertext.h>
#include <gtk/gtkcellrendererpixbuf.h>
#include <gobject/gmarshal.h>
typedef struct _GtkCellViewCellInfo GtkCellViewCellInfo;
struct _GtkCellViewCellInfo
{
GtkCellRenderer *cell;
gint requested_width;
gint real_width;
guint expand : 1;
guint pack : 1;
GSList *attributes;
};
struct _GtkCellViewPrivate
{
GtkTreeModel *model;
GtkTreeRowReference *displayed_row;
GList *cell_list;
gint spacing;
GdkColor background;
gboolean background_set;
};
static void gtk_cell_view_class_init (GtkCellViewClass *klass);
static void gtk_cell_view_get_property (GObject *object,
guint param_id,
GValue *value,
GParamSpec *pspec);
static void gtk_cell_view_set_property (GObject *object,
guint param_id,
const GValue *value,
GParamSpec *pspec);
static void gtk_cell_view_init (GtkCellView *cellview);
static void gtk_cell_view_finalize (GObject *object);
static void gtk_cell_view_style_set (GtkWidget *widget,
GtkStyle *previous_style);
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,
GdkEventExpose *event);
static void gtk_cell_view_set_attributesv (GtkCellView *cellview,
GtkCellRenderer *renderer,
va_list args);
static void gtk_cell_view_set_valuesv (GtkCellView *cellview,
GtkCellRenderer *renderer,
va_list args);
static void gtk_cell_view_set_cell_data (GtkCellView *cellview);
enum
{
PROP_0,
PROP_BACKGROUND,
PROP_BACKGROUND_GDK,
PROP_BACKGROUND_SET
};
static GtkObjectClass *parent_class = NULL;
GType
gtk_cell_view_get_type (void)
{
static GType cell_view_type = 0;
if (!cell_view_type)
{
static const GTypeInfo cell_view_info =
{
sizeof (GtkCellViewClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) gtk_cell_view_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GtkCellView),
0,
(GInstanceInitFunc) gtk_cell_view_init
};
cell_view_type = g_type_register_static (GTK_TYPE_WIDGET, "GtkCellView",
&cell_view_info, 0);
}
return cell_view_type;
}
static void
gtk_cell_view_class_init (GtkCellViewClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
gobject_class->get_property = gtk_cell_view_get_property;
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->size_request = gtk_cell_view_size_request;
widget_class->style_set = gtk_cell_view_style_set;
/* properties */
g_object_class_install_property (gobject_class,
PROP_BACKGROUND,
g_param_spec_string ("background",
_("Background color name"),
_("Background color as a string"),
NULL,
G_PARAM_WRITABLE));
g_object_class_install_property (gobject_class,
PROP_BACKGROUND_GDK,
g_param_spec_boxed ("background_gdk",
_("Background color"),
_("Background color as a GdkColor"),
GDK_TYPE_COLOR,
G_PARAM_READABLE | G_PARAM_WRITABLE));
#define ADD_SET_PROP(propname, propval, nick, blurb) g_object_class_install_property (gobject_class, propval, g_param_spec_boolean (propname, nick, blurb, FALSE, G_PARAM_READABLE | G_PARAM_WRITABLE))
ADD_SET_PROP ("background_set", PROP_BACKGROUND_SET,
_("Background set"),
_("Whether this tag affects the background color"));
g_type_class_add_private (gobject_class, sizeof (GtkCellViewPrivate));
}
static void
gtk_cell_view_get_property (GObject *object,
guint param_id,
GValue *value,
GParamSpec *pspec)
{
GtkCellView *view = GTK_CELL_VIEW (object);
switch (param_id)
{
case PROP_BACKGROUND_GDK:
{
GdkColor color;
color = view->priv->background;
g_value_set_boxed (value, &color);
}
break;
case PROP_BACKGROUND_SET:
g_value_set_boolean (value, view->priv->background_set);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
}
}
static void
gtk_cell_view_set_property (GObject *object,
guint param_id,
const GValue *value,
GParamSpec *pspec)
{
GtkCellView *view = GTK_CELL_VIEW (object);
switch (param_id)
{
case PROP_BACKGROUND:
{
GdkColor color;
if (!g_value_get_string (value))
gtk_cell_view_set_background_color (view, NULL);
else if (gdk_color_parse (g_value_get_string (value), &color))
gtk_cell_view_set_background_color (view, &color);
else
g_warning ("Don't know color `%s'", g_value_get_string (value));
g_object_notify (object, "background_gdk");
}
break;
case PROP_BACKGROUND_GDK:
gtk_cell_view_set_background_color (view, g_value_get_boxed (value));
break;
case PROP_BACKGROUND_SET:
view->priv->background_set = g_value_get_boolean (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
}
}
static void
gtk_cell_view_init (GtkCellView *cellview)
{
GTK_WIDGET_SET_FLAGS (cellview, GTK_NO_WINDOW);
cellview->priv = GTK_CELL_VIEW_GET_PRIVATE (cellview);
}
static void
gtk_cell_view_style_set (GtkWidget *widget,
GtkStyle *previous_style)
{
if (previous_style && GTK_WIDGET_REALIZED (widget))
gdk_window_set_background (widget->window,
&widget->style->base[GTK_WIDGET_STATE (widget)]);
}
static void
gtk_cell_view_finalize (GObject *object)
{
GtkCellView *cellview = GTK_CELL_VIEW (object);
if (cellview->priv->cell_list)
{
g_list_foreach (cellview->priv->cell_list, (GFunc)g_free, NULL);
g_list_free (cellview->priv->cell_list);
}
cellview->priv->cell_list = NULL;
if (G_OBJECT_CLASS (parent_class)->finalize)
(* G_OBJECT_CLASS (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)
{
GList *i;
gint expand_cell_count = 0;
gint full_requested_width = 0;
gint extra_space;
GtkCellView *cellview;
widget->allocation = *allocation;
cellview = GTK_CELL_VIEW (widget);
/* checking how much extra space we have */
for (i = cellview->priv->cell_list; i; i = i->next)
{
GtkCellViewCellInfo *info = (GtkCellViewCellInfo *)i->data;
if (!info->cell->visible)
continue;
if (info->expand)
expand_cell_count++;
full_requested_width += info->requested_width;
}
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;
/* iterate list for PACK_START cells */
for (i = cellview->priv->cell_list; i; i = i->next)
{
GtkCellViewCellInfo *info = (GtkCellViewCellInfo *)i->data;
if (info->pack == GTK_PACK_END)
continue;
if (!info->cell->visible)
continue;
info->real_width = info->requested_width + (info->expand?extra_space:0);
}
/* iterate list for PACK_END cells */
for (i = cellview->priv->cell_list; i; i = i->next)
{
GtkCellViewCellInfo *info = (GtkCellViewCellInfo *)i->data;
if (info->pack == GTK_PACK_START)
continue;
if (!info->cell->visible)
continue;
info->real_width = info->requested_width + (info->expand?extra_space:0);
}
}
static gboolean
gtk_cell_view_expose (GtkWidget *widget,
GdkEventExpose *event)
{
GList *i;
GtkCellView *cellview;
GdkRectangle area;
cellview = GTK_CELL_VIEW (widget);
if (! GTK_WIDGET_DRAWABLE (widget))
return FALSE;
/* "blank" background */
if (cellview->priv->background_set)
{
GdkGC *gc;
gc = gdk_gc_new (GTK_WIDGET (cellview)->window);
gdk_gc_set_rgb_fg_color (gc, &cellview->priv->background);
gdk_draw_rectangle (GTK_WIDGET (cellview)->window,
gc,
TRUE,
/*0, 0,*/
widget->allocation.x,
widget->allocation.y,
widget->allocation.width,
widget->allocation.height);
g_object_unref (G_OBJECT (gc));
}
/* set cell data (if applicable) */
if (cellview->priv->displayed_row)
gtk_cell_view_set_cell_data (cellview);
/* render cells */
area = widget->allocation;
/* we draw on our very own window, initialize x and y to zero */
area.x = widget->allocation.x;
area.y = widget->allocation.y;
/* PACK_START */
for (i = cellview->priv->cell_list; i; i = i->next)
{
GtkCellViewCellInfo *info = (GtkCellViewCellInfo *)i->data;
if (info->pack == GTK_PACK_END)
continue;
if (!info->cell->visible)
continue;
area.width = info->real_width;
gtk_cell_renderer_render (info->cell,
event->window,
widget,
/* FIXME! */
&area, &area, &event->area, 0);
area.x += info->real_width;
}
/* PACK_END */
for (i = cellview->priv->cell_list; i; i = i->next)
{
GtkCellViewCellInfo *info = (GtkCellViewCellInfo *)i->data;
if (info->pack == GTK_PACK_START)
continue;
if (!info->cell->visible)
continue;
area.width = info->real_width;
gtk_cell_renderer_render (info->cell,
widget->window,
widget,
/* FIXME ! */
&area, &area, &event->area, 0);
area.x += info->real_width;
}
return FALSE;
}
GtkWidget *
gtk_cell_view_new (void)
{
GtkCellView *cellview;
cellview = GTK_CELL_VIEW (g_object_new (gtk_cell_view_get_type (), NULL));
return GTK_WIDGET (cellview);
}
GtkWidget *
gtk_cell_view_new_with_text (const gchar *text)
{
GtkCellView *cellview;
GtkCellRenderer *renderer;
GValue value = {0, };
cellview = GTK_CELL_VIEW (gtk_cell_view_new ());
renderer = gtk_cell_renderer_text_new ();
gtk_cell_view_pack_start (cellview, renderer, TRUE);
g_value_init (&value, G_TYPE_STRING);
g_value_set_string (&value, text);
gtk_cell_view_set_values (cellview, renderer, "text", &value, NULL);
g_value_unset (&value);
return GTK_WIDGET (cellview);
}
GtkWidget *
gtk_cell_view_new_with_markup (const gchar *markup)
{
GtkCellView *cellview;
GtkCellRenderer *renderer;
GValue value = {0, };
cellview = GTK_CELL_VIEW (gtk_cell_view_new ());
renderer = gtk_cell_renderer_text_new ();
gtk_cell_view_pack_start (cellview, renderer, TRUE);
g_value_init (&value, G_TYPE_STRING);
g_value_set_string (&value, markup);
gtk_cell_view_set_values (cellview, renderer, "markup", &value, NULL);
g_value_unset (&value);
return GTK_WIDGET (cellview);
}
GtkWidget *
gtk_cell_view_new_with_pixbuf (GdkPixbuf *pixbuf)
{
GtkCellView *cellview;
GtkCellRenderer *renderer;
GValue value = {0, };
cellview = GTK_CELL_VIEW (gtk_cell_view_new ());
renderer = gtk_cell_renderer_pixbuf_new ();
gtk_cell_view_pack_start (cellview, renderer, TRUE);
g_value_init (&value, GDK_TYPE_PIXBUF);
g_value_set_object (&value, pixbuf);
gtk_cell_view_set_values (cellview, renderer, "pixbuf", &value, NULL);
g_value_unset (&value);
return GTK_WIDGET (cellview);
}
static GtkCellViewCellInfo *
gtk_cell_view_get_cell_info (GtkCellView *cellview,
GtkCellRenderer *renderer)
{
GList *i;
for (i = cellview->priv->cell_list; i; i = i->next)
{
GtkCellViewCellInfo *info = (GtkCellViewCellInfo *)i->data;
if (info->cell == renderer)
return info;
}
return NULL;
}
void
gtk_cell_view_pack_start (GtkCellView *cellview,
GtkCellRenderer *renderer,
gboolean expand)
{
GtkCellViewCellInfo *info;
g_return_if_fail (GTK_IS_CELL_VIEW (cellview));
g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
g_return_if_fail (!gtk_cell_view_get_cell_info (cellview, renderer));
g_object_ref (G_OBJECT (renderer));
gtk_object_sink (GTK_OBJECT (renderer));
info = g_new0 (GtkCellViewCellInfo, 1);
info->cell = renderer;
info->expand = expand ? TRUE : FALSE;
info->pack = GTK_PACK_START;
cellview->priv->cell_list = g_list_append (cellview->priv->cell_list, info);
}
void
gtk_cell_view_pack_end (GtkCellView *cellview,
GtkCellRenderer *renderer,
gboolean expand)
{
GtkCellViewCellInfo *info;
g_return_if_fail (GTK_IS_CELL_VIEW (cellview));
g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
g_return_if_fail (!gtk_cell_view_get_cell_info (cellview, renderer));
g_object_ref (G_OBJECT (renderer));
gtk_object_sink (GTK_OBJECT (renderer));
info = g_new0 (GtkCellViewCellInfo, 1);
info->cell = renderer;
info->expand = expand ? TRUE : FALSE;
info->pack = GTK_PACK_END;
cellview->priv->cell_list = g_list_append (cellview->priv->cell_list, info);
}
void
gtk_cell_view_add_attribute (GtkCellView *cellview,
GtkCellRenderer *renderer,
const gchar *attribute,
gint column)
{
GtkCellViewCellInfo *info;
g_return_if_fail (GTK_IS_CELL_VIEW (cellview));
info = gtk_cell_view_get_cell_info (cellview, renderer);
g_return_if_fail (info != NULL);
info->attributes = g_slist_prepend (info->attributes,
GINT_TO_POINTER (column));
info->attributes = g_slist_prepend (info->attributes,
g_strdup (attribute));
}
void
gtk_cell_view_clear (GtkCellView *cellview)
{
GList *i;
for (i = cellview->priv->cell_list; i; i = i->next)
{
GtkCellViewCellInfo *info = (GtkCellViewCellInfo *)i->data;
gtk_cell_view_clear_attributes (cellview, info->cell);
g_object_unref (G_OBJECT (info->cell));
g_free (info);
}
g_list_free (cellview->priv->cell_list);
cellview->priv->cell_list = NULL;
}
void
gtk_cell_view_clear_attributes (GtkCellView *cellview,
GtkCellRenderer *renderer)
{
GtkCellViewCellInfo *info;
GSList *list;
g_return_if_fail (GTK_IS_CELL_VIEW (cellview));
g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
info = gtk_cell_view_get_cell_info (cellview, renderer);
list = info->attributes;
while (list && list->next)
{
g_free (list->data);
list = list->next->next;
}
g_slist_free (list);
info->attributes = NULL;
}
static void
gtk_cell_view_set_attributesv (GtkCellView *cellview,
GtkCellRenderer *renderer,
va_list args)
{
gchar *attribute;
gint column;
attribute = va_arg (args, gchar *);
gtk_cell_view_clear_attributes (cellview, renderer);
while (attribute)
{
column = va_arg (args, gint);
gtk_cell_view_add_attribute (cellview, renderer, attribute, column);
attribute = va_arg (args, gchar *);
}
}
void
gtk_cell_view_set_attributes (GtkCellView *cellview,
GtkCellRenderer *renderer,
...)
{
va_list args;
g_return_if_fail (GTK_IS_CELL_VIEW (cellview));
g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
g_return_if_fail (gtk_cell_view_get_cell_info (cellview, renderer));
va_start (args, renderer);
gtk_cell_view_set_attributesv (cellview, renderer, args);
va_end (args);
}
void
gtk_cell_view_set_value (GtkCellView *cellview,
GtkCellRenderer *renderer,
gchar *property,
GValue *value)
{
g_return_if_fail (GTK_IS_CELL_VIEW (cellview));
g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
g_object_set_property (G_OBJECT (renderer), property, value);
/* force redraw */
gtk_widget_queue_draw (GTK_WIDGET (cellview));
}
static void
gtk_cell_view_set_valuesv (GtkCellView *cellview,
GtkCellRenderer *renderer,
va_list args)
{
gchar *attribute;
GValue *value;
attribute = va_arg (args, gchar *);
while (attribute)
{
value = va_arg (args, GValue *);
gtk_cell_view_set_value (cellview, renderer, attribute, value);
attribute = va_arg (args, gchar *);
}
}
void
gtk_cell_view_set_values (GtkCellView *cellview,
GtkCellRenderer *renderer,
...)
{
va_list args;
g_return_if_fail (GTK_IS_CELL_VIEW (cellview));
g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
g_return_if_fail (gtk_cell_view_get_cell_info (cellview, renderer));
va_start (args, renderer);
gtk_cell_view_set_valuesv (cellview, renderer, args);
va_end (args);
}
void
gtk_cell_view_set_model (GtkCellView *cellview,
GtkTreeModel *model)
{
g_return_if_fail (GTK_IS_CELL_VIEW (cellview));
g_return_if_fail (GTK_IS_TREE_MODEL (model));
if (cellview->priv->model)
{
if (cellview->priv->displayed_row)
gtk_tree_row_reference_free (cellview->priv->displayed_row);
cellview->priv->displayed_row = NULL;
g_object_unref (G_OBJECT (cellview->priv->model));
cellview->priv->model = NULL;
}
cellview->priv->model = model;
if (cellview->priv->model)
g_object_ref (G_OBJECT (cellview->priv->model));
}
static void
gtk_cell_view_set_cell_data (GtkCellView *cellview)
{
GList *i;
GtkTreeIter iter;
GtkTreePath *path;
g_return_if_fail (cellview->priv->displayed_row != NULL);
path = gtk_tree_row_reference_get_path (cellview->priv->displayed_row);
gtk_tree_model_get_iter (cellview->priv->model, &iter, path);
gtk_tree_path_free (path);
for (i = cellview->priv->cell_list; i; i = i->next)
{
GSList *j;
GtkCellViewCellInfo *info = i->data;
for (j = info->attributes; j && j->next; j = j->next->next)
{
gchar *property = j->data;
gint column = GPOINTER_TO_INT (j->next->data);
GValue value = {0, };
gtk_tree_model_get_value (cellview->priv->model, &iter,
column, &value);
g_object_set_property (G_OBJECT (info->cell),
property, &value);
g_value_unset (&value);
}
}
}
void
gtk_cell_view_set_displayed_row (GtkCellView *cellview,
GtkTreePath *path)
{
g_return_if_fail (GTK_IS_CELL_VIEW (cellview));
g_return_if_fail (GTK_IS_TREE_MODEL (cellview->priv->model));
g_return_if_fail (path != NULL);
if (cellview->priv->displayed_row)
gtk_tree_row_reference_free (cellview->priv->displayed_row);
cellview->priv->displayed_row =
gtk_tree_row_reference_new (cellview->priv->model, path);
/* force redraw */
gtk_widget_queue_draw (GTK_WIDGET (cellview));
}
GtkTreePath *
gtk_cell_view_get_displayed_row (GtkCellView *cellview)
{
g_return_val_if_fail (GTK_IS_CELL_VIEW (cellview), NULL);
if (!cellview->priv->displayed_row)
return NULL;
return gtk_tree_row_reference_get_path (cellview->priv->displayed_row);
}
void
gtk_cell_view_set_background_color (GtkCellView *view,
GdkColor *color)
{
g_return_if_fail (GTK_IS_CELL_VIEW (view));
if (color)
{
if (!view->priv->background_set)
{
view->priv->background_set = TRUE;
g_object_notify (G_OBJECT (view), "background_set");
}
view->priv->background = *color;
}
else
{
if (view->priv->background_set)
{
view->priv->background_set = FALSE;
g_object_notify (G_OBJECT (view), "background_set");
}
}
}

96
gtk/gtkcellview.h Normal file
View File

@ -0,0 +1,96 @@
/* gtkcellview.h
* Copyright (C) 2002, 2003 Kristian Rietveld <kris@gtk.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __GTK_CELL_VIEW_H__
#define __GTK_CELL_VIEW_H__
#include <gtk/gtkwidget.h>
#include <gtk/gtkcellrenderer.h>
#include <gtk/gtktreemodel.h>
G_BEGIN_DECLS
#define GTK_TYPE_CELL_VIEW (gtk_cell_view_get_type ())
#define GTK_CELL_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_CELL_VIEW, GtkCellView))
#define GTK_CELL_VIEW_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), GTK_TYPE_CELL_VIEW, GtkCellViewClass))
#define GTK_IS_CELL_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_CELL_VIEW))
#define GTK_IS_CELL_VIEW_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), GTK_TYPE_CELL_VIEW))
#define GTK_CELL_VIEW_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), GTK_TYPE_CELL_VIEW, GtkCellViewClass))
#define GTK_CELL_VIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_CELL_VIEW, GtkCellViewPrivate))
typedef struct _GtkCellView GtkCellView;
typedef struct _GtkCellViewClass GtkCellViewClass;
typedef struct _GtkCellViewPrivate GtkCellViewPrivate;
struct _GtkCellView
{
GtkWidget parent_instance;
/*< private >*/
GtkCellViewPrivate *priv;
};
struct _GtkCellViewClass
{
GtkWidgetClass parent_class;
};
GType gtk_cell_view_get_type (void);
GtkWidget *gtk_cell_view_new (void);
GtkWidget *gtk_cell_view_new_with_text (const gchar *text);
GtkWidget *gtk_cell_view_new_with_markup (const gchar *markup);
GtkWidget *gtk_cell_view_new_with_pixbuf (GdkPixbuf *pixbuf);
void gtk_cell_view_pack_start (GtkCellView *cell_view,
GtkCellRenderer *renderer,
gboolean expand);
void gtk_cell_view_pack_end (GtkCellView *cell_view,
GtkCellRenderer *renderer,
gboolean expand);
void gtk_cell_view_clear (GtkCellView *cell_view);
void gtk_cell_view_add_attribute (GtkCellView *cell_view,
GtkCellRenderer *renderer,
const gchar *attribute,
gint column);
void gtk_cell_view_clear_attributes (GtkCellView *cell_view,
GtkCellRenderer *attribute);
void gtk_cell_view_set_attributes (GtkCellView *cell_view,
GtkCellRenderer *renderer,
...);
void gtk_cell_view_set_value (GtkCellView *cell_view,
GtkCellRenderer *renderer,
gchar *property,
GValue *value);
void gtk_cell_view_set_values (GtkCellView *cell_view,
GtkCellRenderer *renderer,
...);
void gtk_cell_view_set_model (GtkCellView *cell_view,
GtkTreeModel *model);
void gtk_cell_view_set_displayed_row (GtkCellView *cell_view,
GtkTreePath *path);
GtkTreePath *gtk_cell_view_get_displayed_row (GtkCellView *cell_view);
void gtk_cell_view_set_background_color (GtkCellView *cell_view,
GdkColor *color);
G_END_DECLS
#endif /* __GTK_CELL_VIEW_H__ */

146
gtk/gtkcellviewmenuitem.c Normal file
View File

@ -0,0 +1,146 @@
/* gtkcellviewmenuitem.c
* Copyright (C) 2003 Kristian Rietveld <kris@gtk.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include <gtk/gtkcellviewmenuitem.h>
#include <gtk/gtkcellview.h>
struct _GtkCellViewMenuItemPrivate
{
GtkWidget *cell_view;
};
static void gtk_cell_view_menu_item_init (GtkCellViewMenuItem *item);
static void gtk_cell_view_menu_item_class_init (GtkCellViewMenuItemClass *klass);
GType
gtk_cell_view_menu_item_get_type (void)
{
static GType cell_view_menu_item_type = 0;
if (!cell_view_menu_item_type)
{
static const GTypeInfo cell_view_menu_item_info =
{
sizeof (GtkCellViewMenuItemClass),
NULL,
NULL,
(GClassInitFunc) gtk_cell_view_menu_item_class_init,
NULL,
NULL,
sizeof (GtkCellViewMenuItem),
0,
(GInstanceInitFunc) gtk_cell_view_menu_item_init
};
cell_view_menu_item_type =
g_type_register_static (GTK_TYPE_MENU_ITEM, "GtkCellViewMenuItem",
&cell_view_menu_item_info, 0);
}
return cell_view_menu_item_type;
}
static void
gtk_cell_view_menu_item_class_init (GtkCellViewMenuItemClass *klass)
{
g_type_class_add_private ((GObjectClass *)klass,
sizeof (GtkCellViewMenuItemPrivate));
}
static void
gtk_cell_view_menu_item_init (GtkCellViewMenuItem *item)
{
item->priv = GTK_CELL_VIEW_MENU_ITEM_GET_PRIVATE (item);
}
GtkWidget *
gtk_cell_view_menu_item_new (void)
{
GtkCellViewMenuItem *item;
item = g_object_new (GTK_TYPE_CELL_VIEW_MENU_ITEM, NULL);
item->priv->cell_view = gtk_cell_view_new ();
gtk_container_add (GTK_CONTAINER (item), item->priv->cell_view);
gtk_widget_show (item->priv->cell_view);
return GTK_WIDGET (item);
}
GtkWidget *
gtk_cell_view_menu_item_new_with_pixbuf (GdkPixbuf *pixbuf)
{
GtkCellViewMenuItem *item;
item = g_object_new (GTK_TYPE_CELL_VIEW_MENU_ITEM, NULL);
item->priv->cell_view = gtk_cell_view_new_with_pixbuf (pixbuf);
gtk_container_add (GTK_CONTAINER (item), item->priv->cell_view);
gtk_widget_show (item->priv->cell_view);
return GTK_WIDGET (item);
}
GtkWidget *
gtk_cell_view_menu_item_new_with_text (const gchar *text)
{
GtkCellViewMenuItem *item;
item = g_object_new (GTK_TYPE_CELL_VIEW_MENU_ITEM, NULL);
item->priv->cell_view = gtk_cell_view_new_with_text (text);
gtk_container_add (GTK_CONTAINER (item), item->priv->cell_view);
gtk_widget_show (item->priv->cell_view);
return GTK_WIDGET (item);
}
GtkWidget *
gtk_cell_view_menu_item_new_with_markup (const gchar *markup)
{
GtkCellViewMenuItem *item;
item = g_object_new (GTK_TYPE_CELL_VIEW_MENU_ITEM, NULL);
item->priv->cell_view = gtk_cell_view_new_with_markup (markup);
gtk_container_add (GTK_CONTAINER (item), item->priv->cell_view);
gtk_widget_show (item->priv->cell_view);
return GTK_WIDGET (item);
}
GtkWidget *
gtk_cell_view_menu_item_new_from_model (GtkTreeModel *model,
GtkTreePath *path)
{
GtkCellViewMenuItem *item;
item = g_object_new (GTK_TYPE_CELL_VIEW_MENU_ITEM, NULL);
item->priv->cell_view = gtk_cell_view_new ();
gtk_container_add (GTK_CONTAINER (item), item->priv->cell_view);
gtk_cell_view_set_model (GTK_CELL_VIEW (item->priv->cell_view), model);
gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (item->priv->cell_view), path);
gtk_widget_show (item->priv->cell_view);
return GTK_WIDGET (item);
}

68
gtk/gtkcellviewmenuitem.h Normal file
View File

@ -0,0 +1,68 @@
/* gtkcellviewmenuitem.h
* Copyright (C) 2003 Kristian Rietveld <kris@gtk.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __GTK_CELL_VIEW_MENU_ITEM_H__
#define __GTK_CELL_VIEW_MENU_ITEM_H__
#include <gtk/gtkmenuitem.h>
#include <gtk/gtktreemodel.h>
G_BEGIN_DECLS
#define GTK_TYPE_CELL_VIEW_MENU_ITEM (gtk_cell_view_menu_item_get_type ())
#define GTK_CELL_VIEW_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_CELL_VIEW_MENU_ITEM, GtkCellViewMenuItem))
#define GTK_CELL_VIEW_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_CELL_VIEW_MENU_ITEM, GtkCellViewMenuItemClass))
#define GTK_IS_CELL_VIEW_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_CELL_VIEW_MENU_ITEM))
#define GTK_IS_CELL_VIEW_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_CELL_VIEW_MENU_ITEM))
#define GTK_CELL_VIEW_MENU_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_CELL_VIEW_MENU_ITEM, GtkCellViewMenuItemClass))
#define GTK_CELL_VIEW_MENU_ITEM_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_CELL_VIEW_MENU_ITEM, GtkCellViewMenuItemPrivate))
typedef struct _GtkCellViewMenuItem GtkCellViewMenuItem;
typedef struct _GtkCellViewMenuItemClass GtkCellViewMenuItemClass;
typedef struct _GtkCellViewMenuItemPrivate GtkCellViewMenuItemPrivate;
struct _GtkCellViewMenuItem
{
GtkMenuItem parent_instance;
/*< private >*/
GtkCellViewMenuItemPrivate *priv;
};
struct _GtkCellViewMenuItemClass
{
GtkMenuItemClass parent_class;
};
GType gtk_cell_view_menu_item_get_type (void);
GtkWidget *gtk_cell_view_menu_item_new (void);
GtkWidget *gtk_cell_view_menu_item_new_with_pixbuf (GdkPixbuf *pixbuf);
GtkWidget *gtk_cell_view_menu_item_new_with_text (const gchar *text);
GtkWidget *gtk_cell_view_menu_item_new_with_markup (const gchar *markup);
GtkWidget *gtk_cell_view_menu_item_new_from_model (GtkTreeModel *model,
GtkTreePath *path);
G_END_DECLS
#endif /* __GTK_CELL_VIEW_MENU_ITEM_H__ */

2271
gtk/gtkcombobox.c Normal file

File diff suppressed because it is too large Load Diff

102
gtk/gtkcombobox.h Normal file
View File

@ -0,0 +1,102 @@
/* gtkcombobox.h
* Copyright (C) 2002, 2003 Kristian Rietveld <kris@gtk.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __GTK_COMBO_BOX_H__
#define __GTK_COMBO_BOX_H__
#include <gtk/gtkbin.h>
#include <gtk/gtktreemodel.h>
#include <gtk/gtktreeview.h>
G_BEGIN_DECLS
#define GTK_TYPE_COMBO_BOX (gtk_combo_box_get_type ())
#define GTK_COMBO_BOX(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_COMBO_BOX, GtkComboBox))
#define GTK_COMBO_BOX_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), GTK_TYPE_COMBO_BOX, GtkComboBoxClass))
#define GTK_IS_COMBO_BOX(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_COMBO_BOX))
#define GTK_IS_COMBO_BOX_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), GTK_TYPE_COMBO_BOX))
#define GTK_COMBO_BOX_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), GTK_TYPE_COMBO_BOX, GtkComboBoxClass))
#define GTK_COMBO_BOX_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_COMBO_BOX, GtkComboBoxPrivate))
typedef struct _GtkComboBox GtkComboBox;
typedef struct _GtkComboBoxClass GtkComboBoxClass;
typedef struct _GtkComboBoxPrivate GtkComboBoxPrivate;
struct _GtkComboBox
{
GtkBin parent_instance;
/*< private >*/
GtkComboBoxPrivate *priv;
};
struct _GtkComboBoxClass
{
GtkBinClass parent_class;
/* signals */
void (* changed) (GtkComboBox *combo_box);
};
/* construction */
GType gtk_combo_box_get_type (void);
GtkWidget *gtk_combo_box_new (GtkTreeModel *model);
/* manipulate list of cell renderers */
void gtk_combo_box_pack_start (GtkComboBox *combo_box,
GtkCellRenderer *cell,
gboolean expand);
void gtk_combo_box_pack_end (GtkComboBox *combo_box,
GtkCellRenderer *cell,
gboolean expand);
void gtk_combo_box_set_attributes (GtkComboBox *combo_box,
GtkCellRenderer *cell,
...);
void gtk_combo_box_clear (GtkComboBox *combo_box);
/* grids */
void gtk_combo_box_set_wrap_width (GtkComboBox *combo_box,
gint width);
void gtk_combo_box_set_row_span_column (GtkComboBox *combo_box,
gint row_span);
void gtk_combo_box_set_column_span_column (GtkComboBox *combo_box,
gint column_span);
/* get/set active item */
gint gtk_combo_box_get_active (GtkComboBox *combo_box);
void gtk_combo_box_set_active (GtkComboBox *combo_box,
gint index);
/* getters and setters */
GtkTreeModel *gtk_combo_box_get_model (GtkComboBox *combo_box);
/* convenience -- text */
GtkWidget *gtk_combo_box_new_text (void);
void gtk_combo_box_append_text (GtkComboBox *combo_box,
const gchar *text);
void gtk_combo_box_insert_text (GtkComboBox *combo_box,
gint position,
const gchar *text);
void gtk_combo_box_prepend_text (GtkComboBox *combo_box,
const gchar *text);
G_END_DECLS
#endif /* __GTK_COMBO_BOX_H__ */

177
gtk/gtkcomboboxentry.c Normal file
View File

@ -0,0 +1,177 @@
/* gtkcomboboxentry.c
* Copyright (C) 2002, 2003 Kristian Rietveld <kris@gtk.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include <gtk/gtkcomboboxentry.h>
#include <gtk/gtkentry.h>
#include <gtk/gtkcellrenderertext.h>
struct _GtkComboBoxEntryPrivate
{
GtkWidget *entry;
gint text_column;
};
static void gtk_combo_box_entry_class_init (GtkComboBoxEntryClass *klass);
static void gtk_combo_box_entry_init (GtkComboBoxEntry *entry_box);
static void gtk_combo_box_entry_active_changed (GtkComboBox *combo_box,
gpointer user_data);
static void gtk_combo_box_entry_contents_changed (GtkEntry *entry,
gpointer user_data);
GType
gtk_combo_box_entry_get_type (void)
{
static GType combo_box_entry_type = 0;
if (!combo_box_entry_type)
{
static const GTypeInfo combo_box_entry_info =
{
sizeof (GtkComboBoxEntryClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) gtk_combo_box_entry_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GtkComboBoxEntry),
0,
(GInstanceInitFunc) gtk_combo_box_entry_init
};
combo_box_entry_type = g_type_register_static (GTK_TYPE_COMBO_BOX,
"GtkComboBoxEntry",
&combo_box_entry_info,
0);
}
return combo_box_entry_type;
}
static void
gtk_combo_box_entry_class_init (GtkComboBoxEntryClass *klass)
{
g_type_class_add_private ((GObjectClass *) klass,
sizeof (GtkComboBoxEntryPrivate));
}
static void
gtk_combo_box_entry_init (GtkComboBoxEntry *entry_box)
{
entry_box->priv = GTK_COMBO_BOX_ENTRY_GET_PRIVATE (entry_box);
}
static void
gtk_combo_box_entry_active_changed (GtkComboBox *combo_box,
gpointer user_data)
{
gint index;
GtkComboBoxEntry *entry_box = GTK_COMBO_BOX_ENTRY (combo_box);
index = gtk_combo_box_get_active (combo_box);
g_signal_handlers_block_by_func (entry_box->priv->entry,
gtk_combo_box_entry_contents_changed,
combo_box);
if (index < 0)
gtk_entry_set_text (GTK_ENTRY (entry_box->priv->entry), "");
else
{
gchar *str = NULL;
GtkTreeIter iter;
GtkTreeModel *model;
model = gtk_combo_box_get_model (combo_box);
gtk_tree_model_iter_nth_child (model, &iter, NULL, index);
gtk_tree_model_get (model, &iter,
entry_box->priv->text_column, &str,
-1);
gtk_entry_set_text (GTK_ENTRY (entry_box->priv->entry), str);
g_free (str);
}
g_signal_handlers_unblock_by_func (entry_box->priv->entry,
gtk_combo_box_entry_contents_changed,
combo_box);
}
static void
gtk_combo_box_entry_contents_changed (GtkEntry *entry,
gpointer user_data)
{
GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
g_signal_handlers_block_by_func (combo_box,
gtk_combo_box_entry_active_changed,
NULL);
gtk_combo_box_set_active (combo_box, -1);
g_signal_handlers_unblock_by_func (combo_box,
gtk_combo_box_entry_active_changed,
NULL);
}
/* public API */
GtkWidget *
gtk_combo_box_entry_new (GtkTreeModel *model,
gint text_column)
{
GtkWidget *ret;
GtkCellRenderer *renderer;
g_return_val_if_fail (GTK_IS_TREE_MODEL (model), NULL);
g_return_val_if_fail (text_column >= 0, NULL);
g_return_val_if_fail (text_column < gtk_tree_model_get_n_columns (model), NULL);
ret = g_object_new (gtk_combo_box_entry_get_type (),
"model", model,
NULL);
GTK_COMBO_BOX_ENTRY (ret)->priv->entry = gtk_entry_new ();
gtk_container_add (GTK_CONTAINER (ret),
GTK_COMBO_BOX_ENTRY (ret)->priv->entry);
GTK_COMBO_BOX_ENTRY (ret)->priv->text_column = text_column;
renderer = gtk_cell_renderer_text_new ();
gtk_combo_box_pack_start (GTK_COMBO_BOX (ret), renderer, TRUE);
gtk_combo_box_set_attributes (GTK_COMBO_BOX (ret), renderer,
"text", text_column,
NULL);
g_signal_connect (GTK_COMBO_BOX_ENTRY (ret)->priv->entry, "changed",
G_CALLBACK (gtk_combo_box_entry_contents_changed), ret);
g_signal_connect (ret, "changed",
G_CALLBACK (gtk_combo_box_entry_active_changed), NULL);
return ret;
}
gint
gtk_combo_box_entry_get_text_column (GtkComboBoxEntry *entry_box)
{
g_return_val_if_fail (GTK_IS_COMBO_BOX_ENTRY (entry_box), 0);
return entry_box->priv->text_column;
}

63
gtk/gtkcomboboxentry.h Normal file
View File

@ -0,0 +1,63 @@
/* gtkcomboboxentry.h
* Copyright (C) 2002, 2003 Kristian Rietveld <kris@gtk.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __GTK_COMBO_BOX_ENTRY_H__
#define __GTK_COMBO_BOX_ENTRY_H__
#include <gtk/gtkcombobox.h>
#include <gtk/gtktreemodel.h>
G_BEGIN_DECLS
#define GTK_TYPE_COMBO_BOX_ENTRY (gtk_combo_box_entry_get_type ())
#define GTK_COMBO_BOX_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_COMBO_BOX_ENTRY, GtkComboBoxEntry))
#define GTK_COMBO_BOX_ENTRY_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), GTK_TYPE_COMBO_BOX_ENTRY, GtkComboBoxEntryClass))
#define GTK_IS_COMBO_BOX_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_COMBO_BOX_ENTRY))
#define GTK_IS_COMBO_BOX_ENTRY_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), GTK_TYPE_COMBO_BOX_ENTRY))
#define GTK_COMBO_BOX_ENTRY_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), GTK_TYPE_COMBO_BOX_ENTRY, GtkComboBoxEntryClass))
#define GTK_COMBO_BOX_ENTRY_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_COMBO_BOX_ENTRY, GtkComboBoxEntryPrivate))
typedef struct _GtkComboBoxEntry GtkComboBoxEntry;
typedef struct _GtkComboBoxEntryClass GtkComboBoxEntryClass;
typedef struct _GtkComboBoxEntryPrivate GtkComboBoxEntryPrivate;
struct _GtkComboBoxEntry
{
GtkComboBox parent_instance;
/*< private >*/
GtkComboBoxEntryPrivate *priv;
};
struct _GtkComboBoxEntryClass
{
GtkComboBoxClass parent_class;
};
GType gtk_combo_box_entry_get_type (void);
GtkWidget *gtk_combo_box_entry_new (GtkTreeModel *model,
gint text_column);
gint gtk_combo_box_entry_get_text_column (GtkComboBoxEntry *entry_box);
G_END_DECLS
#endif /* __GTK_COMBO_BOX_ENTRY_H__ */

View File

@ -29,6 +29,7 @@ endif
noinst_PROGRAMS = \
simple \
testcalendar \
testcombo \
testdnd \
testgtk \
testicontheme \
@ -61,6 +62,7 @@ noinst_PROGRAMS = \
simple_DEPENDENCIES = $(TEST_DEPS)
testicontheme_DEPENDENCIES = $(TEST_DEPS)
testcalendar_DEPENDENCIES = $(TEST_DEPS)
testcombo_DEPENDENCIES = $(TEST_DEPS)
testdnd_DEPENDENCIES = $(TEST_DEPS)
testgtk_DEPENDENCIES = $(TEST_DEPS)
testinput_DEPENDENCIES = $(TEST_DEPS)
@ -86,6 +88,7 @@ testactions_DEPENDENCIES = $(TEST_DEPS)
simple_LDADD = $(LDADDS)
testcalendar_LDADD = $(LDADDS)
testcombo_LDADD = $(LDADDS)
testdnd_LDADD = $(LDADDS)
testgtk_LDADD = $(LDADDS)
testicontheme_LDADD = $(LDADDS)

313
tests/testcombo.c Normal file
View File

@ -0,0 +1,313 @@
#include <gtk/gtk.h>
#include <gtk/gtkcellview.h>
#include <gtk/gtkcellviewmenuitem.h>
#include <string.h>
#include <stdio.h>
/**
* oh yes, this test app surely has a lot of ugly code
*/
/* grid combo demo */
static GdkPixbuf *
create_color_pixbuf (const char *color)
{
GdkPixbuf *pixbuf;
GdkColor col;
int x;
int num;
int rowstride;
guchar *pixels, *p;
if (!gdk_color_parse (color, &col))
return NULL;
pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
FALSE, 8,
16, 16);
rowstride = gdk_pixbuf_get_rowstride (pixbuf);
p = pixels = gdk_pixbuf_get_pixels (pixbuf);
num = gdk_pixbuf_get_width (pixbuf) *
gdk_pixbuf_get_height (pixbuf);
for (x = 0; x < num; x++) {
p[0] = col.red / 65535 * 255;
p[1] = col.green / 65535 * 255;
p[2] = col.blue / 65535 * 255;
p += 3;
}
return pixbuf;
}
static GtkWidget *
create_combo_box_grid_demo ()
{
GtkWidget *combo;
GtkTreeIter iter;
GtkCellRenderer *cell = gtk_cell_renderer_pixbuf_new ();
GtkListStore *store;
store = gtk_list_store_new (1, GDK_TYPE_PIXBUF);
combo = gtk_combo_box_new (GTK_TREE_MODEL (store));
gtk_combo_box_pack_start (GTK_COMBO_BOX (combo),
cell, TRUE);
gtk_combo_box_set_attributes (GTK_COMBO_BOX (combo),
cell, "pixbuf", 0, NULL);
gtk_combo_box_set_wrap_width (GTK_COMBO_BOX (combo),
3);
/* first row */
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
0, create_color_pixbuf ("red"),
-1);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
0, create_color_pixbuf ("green"),
-1);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
0, create_color_pixbuf ("blue"),
-1);
/* second row */
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
0, create_color_pixbuf ("yellow"),
-1);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
0, create_color_pixbuf ("black"),
-1);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
0, create_color_pixbuf ("white"),
-1);
/* third row */
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
0, create_color_pixbuf ("gray"),
-1);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
0, create_color_pixbuf ("snow"),
-1);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
0, create_color_pixbuf ("magenta"),
-1);
gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
return combo;
}
/* blaat */
static GtkTreeModel *
create_blaat ()
{
GdkPixbuf *pixbuf;
GtkWidget *cellview;
GtkTreeIter iter;
GtkListStore *store;
cellview = gtk_cell_view_new ();
store = gtk_list_store_new (2, GDK_TYPE_PIXBUF, G_TYPE_STRING);
pixbuf = gtk_widget_render_icon (cellview, GTK_STOCK_DIALOG_WARNING,
GTK_ICON_SIZE_BUTTON, NULL);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
0, pixbuf,
1, "gtk-stock-dialog-warning",
-1);
pixbuf = gtk_widget_render_icon (cellview, GTK_STOCK_STOP,
GTK_ICON_SIZE_BUTTON, NULL);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
0, pixbuf,
1, "gtk-stock-stop",
-1);
pixbuf = gtk_widget_render_icon (cellview, GTK_STOCK_NEW,
GTK_ICON_SIZE_BUTTON, NULL);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
0, pixbuf,
1, "gtk-stock-new",
-1);
pixbuf = gtk_widget_render_icon (cellview, GTK_STOCK_CLEAR,
GTK_ICON_SIZE_BUTTON, NULL);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
0, pixbuf,
1, "gtk-stock-clear",
-1);
gtk_widget_destroy (cellview);
return GTK_TREE_MODEL (store);
}
static GtkTreeModel *
create_text_store ()
{
GtkTreeIter iter;
GtkListStore *store;
store = GTK_LIST_STORE (gtk_list_store_new (1, G_TYPE_STRING));
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter, 0, "dum de dum", -1);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter, 0, "la la la", -1);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter, 0, "la la la dum de dum la la la la la la boom de da la la", -1);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter, 0, "bloop", -1);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter, 0, "bleep", -1);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter, 0, "klaas", -1);
return GTK_TREE_MODEL (store);
}
int
main (int argc, char **argv)
{
GtkWidget *window, *cellview, *mainbox;
GtkWidget *combobox, *comboboxtext, *comboboxgrid;
GtkWidget *tmp, *boom;
GtkCellRenderer *renderer;
GdkPixbuf *pixbuf;
GValue value = {0, };
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_container_set_border_width (GTK_CONTAINER (window), 5);
g_signal_connect (window, "delete_event", gtk_main_quit, NULL);
mainbox = gtk_vbox_new (FALSE, 2);
gtk_container_add (GTK_CONTAINER (window), mainbox);
/* GtkCellView */
tmp = gtk_frame_new ("GtkCellView");
gtk_box_pack_start (GTK_BOX (mainbox), tmp, FALSE, FALSE, 0);
boom = gtk_vbox_new (FALSE, 0);
gtk_container_set_border_width (GTK_CONTAINER (boom), 5);
gtk_container_add (GTK_CONTAINER (tmp), boom);
cellview = gtk_cell_view_new ();
renderer = gtk_cell_renderer_pixbuf_new ();
pixbuf = gtk_widget_render_icon (cellview, GTK_STOCK_DIALOG_WARNING,
GTK_ICON_SIZE_BUTTON, NULL);
gtk_cell_view_pack_start (GTK_CELL_VIEW (cellview),
renderer,
FALSE);
g_value_init (&value, GDK_TYPE_PIXBUF);
g_value_set_instance (&value, pixbuf);
gtk_cell_view_set_values (GTK_CELL_VIEW (cellview),
renderer,
"pixbuf", &value,
NULL);
g_value_unset (&value);
renderer = gtk_cell_renderer_text_new ();
gtk_cell_view_pack_start (GTK_CELL_VIEW (cellview),
renderer,
TRUE);
g_value_init (&value, G_TYPE_STRING);
g_value_set_string (&value, "la la la");
gtk_cell_view_set_values (GTK_CELL_VIEW (cellview),
renderer,
"text", &value,
NULL);
g_value_unset (&value);
gtk_container_add (GTK_CONTAINER (boom), cellview);
/* GtkComboBox */
tmp = gtk_frame_new ("GtkComboBox");
gtk_box_pack_start (GTK_BOX (mainbox), tmp, FALSE, FALSE, 0);
boom = gtk_vbox_new (FALSE, 0);
gtk_container_set_border_width (GTK_CONTAINER (boom), 5);
gtk_container_add (GTK_CONTAINER (tmp), boom);
combobox = gtk_combo_box_new (create_blaat ());
gtk_container_add (GTK_CONTAINER (boom), combobox);
renderer = gtk_cell_renderer_pixbuf_new ();
gtk_combo_box_pack_start (GTK_COMBO_BOX (combobox),
renderer,
FALSE);
gtk_combo_box_set_attributes (GTK_COMBO_BOX (combobox), renderer, "pixbuf", 0, NULL);
renderer = gtk_cell_renderer_text_new ();
gtk_combo_box_pack_start (GTK_COMBO_BOX (combobox),
renderer,
TRUE);
gtk_combo_box_set_attributes (GTK_COMBO_BOX (combobox), renderer, "text", 1, NULL);
gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), 1);
/* GtkComboBox (grid mode) */
tmp = gtk_frame_new ("GtkComboBox (grid mode)");
gtk_box_pack_start (GTK_BOX (mainbox), tmp, FALSE, FALSE, 0);
boom = gtk_vbox_new (FALSE, 0);
gtk_container_set_border_width (GTK_CONTAINER (boom), 5);
gtk_container_add (GTK_CONTAINER (tmp), boom);
comboboxgrid = create_combo_box_grid_demo ();
gtk_box_pack_start (GTK_BOX (boom), comboboxgrid, FALSE, FALSE, 0);
/* GtkComboBoxEntry */
tmp = gtk_frame_new ("GtkComboBoxEntry");
gtk_box_pack_start (GTK_BOX (mainbox), tmp, FALSE, FALSE, 0);
boom = gtk_vbox_new (FALSE, 0);
gtk_container_set_border_width (GTK_CONTAINER (boom), 5);
gtk_container_add (GTK_CONTAINER (tmp), boom);
comboboxtext = gtk_combo_box_entry_new (create_text_store (), 0);
gtk_container_add (GTK_CONTAINER (boom), comboboxtext);
/* done */
gtk_widget_show_all (window);
gtk_main ();
return 0;
}
/* vim:expandtab
*/