cell renderer with spin button
- From: Lorenzo Gil Sanchez <lgs sicem biz>
- To: gtk-app-devel-list gnome org
- Subject: cell renderer with spin button
- Date: Fri, 05 Mar 2004 13:56:18 +0100
Hi,
I made a cell renderer with a spin button as its cell editable and it
seems to work but I have some problems when the user clicks on the arrow
buttons of the spin button. If he/she clicks too fast the focus go back
to the TreeView and some weird behavior happens.
You can grab the source (it is just 3 small files) at
http://www.sicem.biz/personal/lgs/cosas/rendererspin.tgz and type make;
./demo_spin to see what I mean
Anyhow, the relevant part of the cell renderer is:
static GtkCellEditable *
gtk_cell_renderer_spin_start_editing (GtkCellRenderer *cell,
GdkEvent *event,
GtkWidget *widget,
const gchar *path,
GdkRectangle *background_area,
GdkRectangle *cell_area,
GtkCellRendererState flags)
{
GtkCellRendererText *cell_text;
GtkWidget *spin;
cell_text = GTK_CELL_RENDERER_TEXT (cell);
if (cell_text->editable == FALSE)
return NULL;
spin = gtk_spin_button_new_with_range (0, 100, 1);
if (cell_text->text)
gtk_spin_button_set_value (spin, g_ascii_strtod (cell_text->text,
NULL));
g_object_set_data_full (G_OBJECT (spin), GTK_CELL_RENDERER_SPIN_PATH,
g_strdup (path), g_free);
gtk_widget_show (spin);
g_signal_connect (spin, "focus_out_event",
G_CALLBACK (gtk_cell_renderer_spin_focus_out_event),
cell);
return GTK_CELL_EDITABLE (spin);
}
static gboolean
gtk_cell_renderer_spin_focus_out_event (GtkWidget *widget,
GdkEvent *event,
gpointer data)
{
const gchar *path;
const gchar *new_text;
path = g_object_get_data (G_OBJECT (widget),
GTK_CELL_RENDERER_SPIN_PATH);
new_text = gtk_entry_get_text (GTK_ENTRY (widget));
g_signal_emit_by_name (data, "edited", path, new_text);
g_signal_handlers_disconnect_by_func (widget,
gtk_cell_renderer_spin_focus_out_event,
data);
return FALSE;
}
Can anybody help me on this? Thanks in advance
Lorenzo Gil
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]