Commit 218930c1 authored by Andreas J. Guelzow's avatar Andreas J. Guelzow Committed by Andreas J. Guelzow

use gnumeric_cell_renderer_expr_entry_new rather than

2002-03-21  Andreas J. Guelzow <aguelzow@taliesin.ca>

	* dialog-formula-guru.c (dialog_formula_guru_init) : use
	  gnumeric_cell_renderer_expr_entry_new rather than
	  gtk_cell_renderer_text_new for editable column

2002-03-21  Andreas J. Guelzow <aguelzow@taliesin.ca>

	* gnumeric-cell-renderer-expr-entry.[ch] : new cell renderer using
	  the expresion entry widget
	* src/widgets/gnumeric-expr-entry.[ch] : implement GtkCellEditables
	  interface
	* Makefile.am : add gnumeric-cell-renderer-expr-entry.[ch
parent cd01976f
2002-03-21 Andreas J. Guelzow <aguelzow@taliesin.ca>
* dialog-formula-guru.c (dialog_formula_guru_init) : use
gnumeric_cell_renderer_expr_entry_new rather than
gtk_cell_renderer_text_new for editable column
2002-03-21 Jukka-Pekka Iivonen <jiivonen@hutcs.cs.hut.fi>
* dialog-about.c (dialog_about): Added the authors of the LP Solve
......
......@@ -38,6 +38,7 @@
#include <func.h>
#include <format.h>
#include <widgets/gnumeric-expr-entry.h>
#include <widgets/gnumeric-cell-renderer-expr-entry.h>
#include <libgnome/gnome-i18n.h>
#include <gdk/gdkkeysyms.h>
......@@ -610,7 +611,7 @@ dialog_formula_guru_init (FormulaGuruState *state)
gtk_cell_renderer_text_new (),
"text", ARG_TYPE, NULL);
gtk_tree_view_append_column (state->treeview, column);
renderer = gtk_cell_renderer_text_new ();
renderer = gnumeric_cell_renderer_expr_entry_new (state->wbcg);
g_signal_connect (G_OBJECT (renderer), "edited",
G_CALLBACK (cb_dialog_formula_guru_edited), state);
column = gtk_tree_view_column_new_with_attributes (_("Function/Argument"),
......
2002-03-21 Andreas J. Guelzow <aguelzow@taliesin.ca>
* gnumeric-cell-renderer-expr-entry.[ch] : new cell renderer using
the expresion entry widget
* src/widgets/gnumeric-expr-entry.[ch] : implement GtkCellEditables
interface
* Makefile.am : add gnumeric-cell-renderer-expr-entry.[ch
2002-03-17 Jody Goldberg <jody@gnome.org>
* widget-editable-label.c (editable_label_set_color) : fix sense of
......
......@@ -16,6 +16,8 @@ libwidgets_a_SOURCES = \
gnumeric-cell-renderer.h \
gnumeric-cell-renderer-text.c \
gnumeric-cell-renderer-text.h \
gnumeric-cell-renderer-expr-entry.c \
gnumeric-cell-renderer-expr-entry.h \
gnumeric-dashed-canvas-line.c \
gnumeric-dashed-canvas-line.h \
gnumeric-expr-entry.c \
......
/* gnumeric-cell-renderer-expr-entry.c
* Copyright (C) 2002 Andreas J. Guelzow <aguelzow@taliesin.ca>
*
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
#include "gnumeric-cell-renderer-expr-entry.h"
#include "gnumeric-expr-entry.h"
#include "workbook-edit.h"
#define GNUMERIC_CELL_RENDERER_EXPR_ENTRY_PATH "gnumeric-cell-renderer-expr-entry-path"
static void gnumeric_cell_renderer_expr_entry_class_init
(GnumericCellRendererExprEntryClass *cell_expr_entry_class);
static GtkCellRendererTextClass *parent_class = NULL;
static GtkCellEditable *gnumeric_cell_renderer_expr_entry_start_editing
(GtkCellRenderer *cell,
GdkEvent *event,
GtkWidget *widget,
const gchar *path,
GdkRectangle *background_area,
GdkRectangle *cell_area,
GtkCellRendererState flags);
GType
gnumeric_cell_renderer_expr_entry_get_type (void)
{
static GType cell_expr_entry_type = 0;
if (!cell_expr_entry_type)
{
static const GTypeInfo cell_expr_entry_info =
{
sizeof (GnumericCellRendererExprEntryClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc)gnumeric_cell_renderer_expr_entry_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GtkCellRendererText),
0, /* n_preallocs */
(GInstanceInitFunc) NULL,
};
cell_expr_entry_type = g_type_register_static (GTK_TYPE_CELL_RENDERER_TEXT, "GnumericCellRendererExprEntry", &cell_expr_entry_info, 0);
}
return cell_expr_entry_type;
}
static void
gnumeric_cell_renderer_expr_entry_class_init (GnumericCellRendererExprEntryClass *class)
{
GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS (class);
GObjectClass *object_class = G_OBJECT_CLASS (class);
parent_class = g_type_class_peek_parent (object_class);
cell_class->start_editing = gnumeric_cell_renderer_expr_entry_start_editing;
}
GtkCellRenderer *
gnumeric_cell_renderer_expr_entry_new (WorkbookControlGUI *wbcg)
{
GnumericCellRendererExprEntry *this =
GNUMERIC_CELL_RENDERER_EXPR_ENTRY(g_object_new
(GNUMERIC_TYPE_CELL_RENDERER_EXPR_ENTRY, NULL));
this->wbcg = wbcg;
return GTK_CELL_RENDERER (this);
}
static void
gnumeric_cell_renderer_expr_entry_editing_done (GtkCellEditable *entry,
gpointer data)
{
const gchar *path;
const gchar *new_text;
GnumericCellRendererExprEntry *celltext = GNUMERIC_CELL_RENDERER_EXPR_ENTRY (data);
printf ("Finish Editing\n");
if (gnm_expr_entry_editing_canceled (GNUMERIC_EXPR_ENTRY (entry)))
return;
wbcg_set_entry (celltext->wbcg, NULL);
path = g_object_get_data (G_OBJECT (entry), GNUMERIC_CELL_RENDERER_EXPR_ENTRY_PATH);
new_text = gnm_expr_entry_get_text (GNUMERIC_EXPR_ENTRY (entry));
g_signal_emit_by_name (G_OBJECT (data), "edited", path, new_text);
}
static GtkCellEditable *
gnumeric_cell_renderer_expr_entry_start_editing (GtkCellRenderer *cell,
GdkEvent *event,
GtkWidget *widget,
const gchar *path,
GdkRectangle *background_area,
GdkRectangle *cell_area,
GtkCellRendererState flags)
{
GnumericCellRendererExprEntry *celltext;
GtkEntry *entry;
GnumericExprEntry *gentry;
printf ("Start Editing\n");
celltext = GNUMERIC_CELL_RENDERER_EXPR_ENTRY (cell);
/* If the cell isn't editable we return NULL. */
if (celltext->parent.editable == FALSE)
return NULL;
gentry = gnumeric_expr_entry_new (celltext->wbcg, FALSE);
gnm_expr_entry_set_scg (gentry, wbcg_cur_scg (celltext->wbcg));
entry = gnm_expr_entry_get_entry (gentry);
gtk_entry_set_text (entry, celltext->parent.text);
g_object_set_data_full (G_OBJECT (gentry), GNUMERIC_CELL_RENDERER_EXPR_ENTRY_PATH, g_strdup (path), g_free);
gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
gtk_widget_show_all (GTK_WIDGET (gentry));
gtk_signal_connect (GTK_OBJECT (gentry),
"editing_done",
G_CALLBACK (gnumeric_cell_renderer_expr_entry_editing_done),
celltext);
wbcg_set_entry (celltext->wbcg, gentry);
/* FIXME FIXME FIXME FIXME FIXME FIXME FIXME */
/* The next line is a very bad hack. */
/* GTK_WIDGET (entry)->parent = NULL; */
return GTK_CELL_EDITABLE (gentry);
}
/* gnumeric-cell-renderer-expr-entry.h
* Copyright (C) 2002 Andreas J. Guelzow <aguelzow@taliesin.ca>
*
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __GNUMERIC_CELL_RENDERER_EXPR_ENTRY_H__
#define __GNUMERIC_CELL_RENDERER_EXPR_ENTRY_H__
#include <gtk/gtkcellrenderertext.h>
#include "workbook-control-gui.h"
G_BEGIN_DECLS
#define GNUMERIC_TYPE_CELL_RENDERER_EXPR_ENTRY (gnumeric_cell_renderer_expr_entry_get_type ())
#define GNUMERIC_CELL_RENDERER_EXPR_ENTRY(obj) (GTK_CHECK_CAST ((obj), GNUMERIC_TYPE_CELL_RENDERER_EXPR_ENTRY, GnumericCellRendererExprEntry))
#define GNUMERIC_CELL_RENDERER_EXPR_ENTRY_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GNUMERIC_TYPE_CELL_RENDERER_EXPR_ENTRY, GnumericCellRendererExprEntryClass))
#define GNUMERIC_IS_CELL_RENDERER_EXPR_ENTRY(obj) (GTK_CHECK_TYPE ((obj), GNUMERIC_TYPE_CELL_RENDERER_EXPR_ENTRY))
#define GNUMERIC_IS_CELL_RENDERER_EXPR_ENTRY_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GNUMERIC_TYPE_CELL_RENDERER_EXPR_ENTRY))
#define GNUMERIC_CELL_RENDERER_EXPR_ENTRY_GET_CLASS(obj) (GTK_CHECK_GET_CLASS ((obj), GNUMERIC_TYPE_CELL_RENDERER_EXPR_ENTRY, GnumericCellRendererExprEntryClass))
typedef struct _GnumericCellRendererExprEntry GnumericCellRendererExprEntry;
typedef struct _GnumericCellRendererExprEntryClass GnumericCellRendererExprEntryClass;
struct _GnumericCellRendererExprEntry
{
GtkCellRendererText parent;
WorkbookControlGUI *wbcg;
};
struct _GnumericCellRendererExprEntryClass
{
GtkCellRendererTextClass parent_class;
};
GType gnumeric_cell_renderer_expr_entry_get_type (void);
GtkCellRenderer *gnumeric_cell_renderer_expr_entry_new (WorkbookControlGUI *wbcg);
G_END_DECLS
#endif /* __GNUMERIC_CELL_RENDERER_EXPR_ENTRY_H__ */
......@@ -28,11 +28,10 @@
#include <gal/util/e-util.h>
#include <gtk/gtkentry.h>
#include <gtk/gtkcelleditable.h>
#include <ctype.h>
#include <stdio.h>
static GtkObjectClass *gnumeric_expr_entry_parent_class;
typedef struct {
Range range;
Sheet *sheet;
......@@ -55,6 +54,9 @@ struct _GnumericExprEntry {
GtkUpdateType update_policy;
guint update_timeout_id;
gboolean is_cell_renderer; /* as cell_editable */
gboolean editing_canceled; /* as cell_editable */
};
typedef struct _GnumericExprEntryClass {
......@@ -79,6 +81,184 @@ enum {
static GQuark signals [LAST_SIGNAL] = { 0 };
/* GObject, GtkObject methods
*/
static void gee_set_property (GObject *object, guint prop_id,
GValue const *value, GParamSpec *pspec);
static void gee_get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec);
static void gee_class_init (GtkObjectClass *klass);
static void gee_init (GnumericExprEntry *entry);
static void gnumeric_expr_entry_cell_editable_init (GtkCellEditableIface *iface);
/* GtkHBox methods
*/
/* GtkCellEditable
*/
static void gnumeric_expr_entry_start_editing (GtkCellEditable *cell_editable,
GdkEvent *event);
static gboolean gnumeric_cell_editable_key_press_event (GnumericExprEntry *entry,
GdkEventKey *key_event,
gpointer data);
static void gnumeric_cell_editable_entry_activated (GnumericExprEntry *entry,
gpointer data);
/* Call Backs
*/
static void cb_scg_destroy (GnumericExprEntry *gee, SheetControlGUI *scg);
static void cb_entry_changed (GtkEntry *ignored, GnumericExprEntry *gee);
/* Internal routines
*/
static void gee_rangesel_reset (GnumericExprEntry *gee);
static void gee_make_display_range (GnumericExprEntry *gee, Range *dst);
static char *gee_rangesel_make_text (GnumericExprEntry *gee);
static void gee_rangesel_update_text (GnumericExprEntry *gee);
static gboolean split_char_p (unsigned char c);
static void gee_detach_scg (GnumericExprEntry *gee);
static gboolean gee_update_timeout (gpointer data);
static void gee_remove_update_timer (GnumericExprEntry *range);
static void gee_reset_update_timer (GnumericExprEntry *gee);
static void gee_destroy (GtkObject *object);
static gint gee_key_press_event (GtkWidget *widget, GdkEventKey *event);
static void gee_notify_cursor_position (GObject *object, GParamSpec *pspec,
GnumericExprEntry *gee);
static GtkHBoxClass *gnumeric_expr_entry_parent_class = NULL;
/* E_MAKE_TYPE (gnumeric_expr_entry, "GnumericExprEntry", GnumericExprEntry, */
/* gee_class_init, NULL, GTK_TYPE_HBOX) */
GType gnumeric_expr_entry_get_type(void)
{
static GType type = 0;
if (!type){
static GtkTypeInfo const object_info = {
(char *) "GnumericExprEntry",
sizeof (GnumericExprEntry),
sizeof (GnumericExprEntryClass),
(GtkClassInitFunc) gee_class_init,
(GtkObjectInitFunc) gee_init,
NULL,
NULL, /* class_data */
(GtkClassInitFunc) NULL,
};
static const GInterfaceInfo cell_editable_info =
{
(GInterfaceInitFunc) gnumeric_expr_entry_cell_editable_init,
NULL,
NULL
};
type = gtk_type_unique (GTK_TYPE_HBOX, &object_info);
g_type_add_interface_static (type,
GTK_TYPE_CELL_EDITABLE,
&cell_editable_info);
}
return type;
}
static void
gee_class_init (GtkObjectClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gnumeric_expr_entry_parent_class
= gtk_type_class (gtk_hbox_get_type());
gobject_class->set_property = gee_set_property;
gobject_class->get_property = gee_get_property;
klass->destroy = gee_destroy;
signals [UPDATE] = g_signal_new ("update",
GNUMERIC_TYPE_EXPR_ENTRY,
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GnumericExprEntryClass, update),
(GSignalAccumulator) NULL, NULL,
gnm__VOID__VOID,
G_TYPE_NONE,
0, G_TYPE_NONE);
signals [CHANGED] = g_signal_new ("changed",
GNUMERIC_TYPE_EXPR_ENTRY,
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GnumericExprEntryClass, changed),
(GSignalAccumulator) NULL, NULL,
gnm__VOID__VOID,
G_TYPE_NONE,
0, G_TYPE_NONE);
g_object_class_install_property (gobject_class,
PROP_UPDATE_POLICY,
g_param_spec_enum ("update_policy",
"Update policy",
"How frequently changes to the entry should be applied",
GTK_TYPE_UPDATE_TYPE,
GTK_UPDATE_CONTINUOUS,
G_PARAM_READWRITE));
}
static void
gee_init (GnumericExprEntry *entry)
{
entry->editing_canceled = FALSE;
entry->is_cell_renderer = FALSE;
}
static void
gnumeric_expr_entry_cell_editable_init (GtkCellEditableIface *iface)
{
iface->start_editing = gnumeric_expr_entry_start_editing;
}
static void
gnumeric_expr_entry_start_editing (GtkCellEditable *cell_editable,
GdkEvent *event)
{
GNUMERIC_EXPR_ENTRY (cell_editable)->is_cell_renderer = TRUE;
g_signal_connect (G_OBJECT (gnm_expr_entry_get_entry (GNUMERIC_EXPR_ENTRY (cell_editable))),
"activate",
G_CALLBACK (gnumeric_cell_editable_entry_activated), NULL);
g_signal_connect (G_OBJECT (gnm_expr_entry_get_entry (GNUMERIC_EXPR_ENTRY (cell_editable))),
"key_press_event",
G_CALLBACK (gnumeric_cell_editable_key_press_event), NULL);
gtk_widget_grab_focus (GTK_WIDGET (gnm_expr_entry_get_entry (GNUMERIC_EXPR_ENTRY
(cell_editable))));
}
static void
gnumeric_cell_editable_entry_activated (GnumericExprEntry *entry, gpointer data)
{
gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
}
static gboolean
gnumeric_cell_editable_key_press_event (GnumericExprEntry *entry,
GdkEventKey *key_event,
gpointer data)
{
if (key_event->keyval == GDK_Escape)
{
entry->editing_canceled = TRUE;
gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
return TRUE;
}
return FALSE;
}
static void
gee_rangesel_reset (GnumericExprEntry *gee)
{
......@@ -538,49 +718,6 @@ gee_get_property (GObject *object,
}
}
static void
gee_class_init (GtkObjectClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gnumeric_expr_entry_parent_class
= gtk_type_class (gtk_entry_get_type());
gobject_class->set_property = gee_set_property;
gobject_class->get_property = gee_get_property;
klass->destroy = gee_destroy;
signals [UPDATE] = g_signal_new ("update",
GNUMERIC_TYPE_EXPR_ENTRY,
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GnumericExprEntryClass, update),
(GSignalAccumulator) NULL, NULL,
gnm__VOID__VOID,
G_TYPE_NONE,
0, G_TYPE_NONE);
signals [CHANGED] = g_signal_new ("changed",
GNUMERIC_TYPE_EXPR_ENTRY,
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GnumericExprEntryClass, changed),
(GSignalAccumulator) NULL, NULL,
gnm__VOID__VOID,
G_TYPE_NONE,
0, G_TYPE_NONE);
g_object_class_install_property (gobject_class,
PROP_UPDATE_POLICY,
g_param_spec_enum ("update_policy",
"Update policy",
"How frequently changes to the entry should be applied",
GTK_TYPE_UPDATE_TYPE,
GTK_UPDATE_CONTINUOUS,
G_PARAM_READWRITE));
}
E_MAKE_TYPE (gnumeric_expr_entry, "GnumericExprEntry", GnumericExprEntry,
gee_class_init, NULL, GTK_TYPE_HBOX)
static void
cb_entry_changed (GtkEntry *ignored, GnumericExprEntry *gee)
{
......@@ -1102,3 +1239,11 @@ gnm_expr_entry_grab_focus (GnumericExprEntry *gee, gboolean select_all)
gtk_entry_select_region (gee->entry, 0, gee->entry->text_length);
}
}
gboolean
gnm_expr_entry_editing_canceled (GnumericExprEntry *gee)
{
g_return_val_if_fail (IS_GNUMERIC_EXPR_ENTRY (gee), TRUE);
return gee->editing_canceled;
}
......@@ -68,6 +68,10 @@ void gnumeric_expr_entry_set_update_policy (GnumericExprEntry *e,
GtkUpdateType policy);
void gnm_expr_entry_grab_focus (GnumericExprEntry *e, gboolean select_all);
/* Cell Renderer Specific Method */
gboolean gnm_expr_entry_editing_canceled (GnumericExprEntry *e);
/* private : for internal use */
void gnm_expr_entry_end_of_drag (GnumericExprEntry *gee);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment