diff options
author | Mike Kestner <mkestner@ximian.com> | 2003-10-01 06:35:10 +0800 |
---|---|---|
committer | Mike Kestner <mkestner@src.gnome.org> | 2003-10-01 06:35:10 +0800 |
commit | 642e0e5abd8486793e95fab56e9fd9f3dd0394f8 (patch) | |
tree | 7e870fc0b1bbeb379ba6c982de04346f3a636b73 /widgets/misc/e-cell-renderer-combo.c | |
parent | 8660505eb2c7c1e539b7c5741bf282348bbfc5d9 (diff) | |
download | gsoc2013-evolution-642e0e5abd8486793e95fab56e9fd9f3dd0394f8.tar.gz gsoc2013-evolution-642e0e5abd8486793e95fab56e9fd9f3dd0394f8.tar.zst gsoc2013-evolution-642e0e5abd8486793e95fab56e9fd9f3dd0394f8.zip |
new, treeview renderer for combo cells new, GtkCellEditable for combo
2003-09-30 Mike Kestner <mkestner@ximian.com>
* e-cell-renderer-combo.* : new, treeview renderer for combo cells
* e-combo-cell-editable.* : new, GtkCellEditable for combo cells
* Makefile.am : build the new files
svn path=/trunk/; revision=22773
Diffstat (limited to 'widgets/misc/e-cell-renderer-combo.c')
-rw-r--r-- | widgets/misc/e-cell-renderer-combo.c | 180 |
1 files changed, 180 insertions, 0 deletions
diff --git a/widgets/misc/e-cell-renderer-combo.c b/widgets/misc/e-cell-renderer-combo.c new file mode 100644 index 0000000000..8b4134fdce --- /dev/null +++ b/widgets/misc/e-cell-renderer-combo.c @@ -0,0 +1,180 @@ +/* + * e-cell-renderer-combo.c + * + * Author: Mike Kestner <mkestner@ximian.com> + * + * Copyright (C) 2003 Ximian Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * 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 <config.h> +#include <gtk/gtkcellrenderertext.h> +#include <gtk/gtkarrow.h> +#include <gtk/gtkbutton.h> +#include <gal/util/e-util.h> + +#include "e-combo-cell-editable.h" +#include "e-cell-renderer-combo.h" + +enum { + PROP_0, + PROP_LIST +}; + +struct _ECellRendererComboPriv { + EComboCellEditable *editable; + gchar *path; + GList *list; +}; + +static GtkCellRendererTextClass *parent_class; + +static void +ecrc_editing_done (GtkCellEditable *editable, ECellRendererCombo *cell) +{ + const gchar *new_text; + + if (e_combo_cell_editable_cancelled (E_COMBO_CELL_EDITABLE (editable))) + return; + + new_text = e_combo_cell_editable_get_text (E_COMBO_CELL_EDITABLE (editable)); + + g_signal_emit_by_name (cell, "edited", cell->priv->path, new_text); + g_free (cell->priv->path); + cell->priv->path = NULL; +} + +static GtkCellEditable * +ecrc_start_editing (GtkCellRenderer *cell, GdkEvent *event, GtkWidget *widget, const gchar *path, + GdkRectangle *bg_area, GdkRectangle *cell_area, GtkCellRendererState flags) +{ + ECellRendererCombo *combo_cell = E_CELL_RENDERER_COMBO (cell); + GtkCellRendererText *text_cell = GTK_CELL_RENDERER_TEXT (cell); + EComboCellEditable *editable; + + if (!text_cell->editable) + return NULL; + + editable = E_COMBO_CELL_EDITABLE (e_combo_cell_editable_new ()); + e_combo_cell_editable_set_text (editable, text_cell->text); + e_combo_cell_editable_set_list (editable, combo_cell->priv->list); + gtk_widget_show (GTK_WIDGET (editable)); + + g_signal_connect (editable, "editing-done", G_CALLBACK (ecrc_editing_done), combo_cell); + + combo_cell->priv->editable = g_object_ref (editable); + combo_cell->priv->path = g_strdup (path); + + return GTK_CELL_EDITABLE (editable); +} + +static void +ecrc_get_size (GtkCellRenderer *cell, GtkWidget *widget, GdkRectangle *cell_area, + gint *x_offset, gint *y_offset, gint *width, gint *height) +{ + GtkWidget *btn; + GtkRequisition req; + + if (GTK_CELL_RENDERER_CLASS (parent_class)->get_size) + GTK_CELL_RENDERER_CLASS (parent_class)->get_size (cell, widget, cell_area, x_offset, y_offset, width, height); + + btn = gtk_button_new (); + gtk_container_add (GTK_CONTAINER (btn), gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_OUT)); + gtk_widget_size_request (btn, &req); + *width += req.width; + gtk_widget_destroy (btn); +} + +static void +ecrc_get_prop (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) +{ + ECellRendererCombo *ecrc = E_CELL_RENDERER_COMBO (object); + + switch (prop_id) { + case PROP_LIST: + g_value_set_pointer (value, ecrc->priv->list); + break; + default: + break; + } +} + +static void +ecrc_set_prop (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) +{ + ECellRendererCombo *ecrc = E_CELL_RENDERER_COMBO (object); + + switch (prop_id) { + case PROP_LIST: + ecrc->priv->list = g_value_get_pointer (value); + break; + default: + break; + } +} + +static void +ecrc_finalize (GObject *obj) +{ + ECellRendererCombo *cell = (ECellRendererCombo *) obj; + + if (cell->priv->editable) + g_object_unref (cell->priv->editable); + cell->priv->editable = NULL; + + if (cell->priv->path) + g_free (cell->priv->path); + cell->priv->path = NULL; + + g_free (cell->priv); + + if (G_OBJECT_CLASS (parent_class)->finalize) + G_OBJECT_CLASS (parent_class)->finalize (obj); +} + +static void +ecrc_init (ECellRendererCombo *cell) +{ + cell->priv = g_new0 (ECellRendererComboPriv, 1); +} + +static void +ecrc_class_init (ECellRendererComboClass *class) +{ + GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS (class); + GObjectClass *obj_class = G_OBJECT_CLASS (class); + + parent_class = GTK_CELL_RENDERER_TEXT_CLASS (g_type_class_peek_parent (class)); + + obj_class->get_property = ecrc_get_prop; + obj_class->set_property = ecrc_set_prop; + obj_class->finalize = ecrc_finalize; + + cell_class->start_editing = ecrc_start_editing; + cell_class->get_size = ecrc_get_size; + + g_object_class_install_property (obj_class, PROP_LIST, + g_param_spec_pointer ("list", "List", "List of items to popup.", G_PARAM_READWRITE)); +} + +E_MAKE_TYPE (e_cell_renderer_combo, "ECellRendererCombo", ECellRendererCombo, ecrc_class_init, ecrc_init, GTK_TYPE_CELL_RENDERER_TEXT) + +GtkCellRenderer * +e_cell_renderer_combo_new (void) +{ + return GTK_CELL_RENDERER (g_object_new (E_TYPE_CELL_RENDERER_COMBO, NULL)); +} + |