Make a GtkCellEditable (get_widget_window_size): Change to let it honor

Tue Sep 25 12:34:42 2001  Jonathan Blandford  <jrb@redhat.com>

	* gtk/gtkentry.c: Make a GtkCellEditable
	(get_widget_window_size): Change to let it honor size_allocate
	when a CellEditable.

	* gtk/gtktreeview.c: M-x clean-line-ends.  Lots of focus and
	editable changes.
	(gtk_tree_view_set_cursor): Now you can set the cursor
	horizontally, as well as start editing.

	* gtk/gtkstyle.c (gtk_default_draw_check): changing toggle drawing
	code to look more like the other check buttons.

	* gtk/gtkcellrenderertoggle.c (gtk_cell_renderer_toggle_get_size):
	Change the way we calculate cell size.

	* gtk/gtkmarshal.list (VOID:STRING,STRING): new marshaller.

	* demos/gtk-demo/sizegroup.c: Add mnemonics.

	* gtk/gtkcellrenderer.c (gtk_cell_renderer_get_size): Fix docs.
	Fix logic.

	* gtk/gtkcellrenderertext.c: Change to be editable.

	* gtk/gtkcellrenderertoggle.c: Change to be activatable.

	* test/testtreesort.c: Fix misspelling

	* test/testreecolumns.c: Add mnemonics.

	* test/testreeedit.c: New test program.
This commit is contained in:
Jonathan Blandford 2001-09-25 16:44:39 +00:00 committed by Jonathan Blandford
parent 8a2d408dae
commit 92841cb95a
30 changed files with 1233 additions and 506 deletions

View File

@ -1,3 +1,37 @@
Tue Sep 25 12:34:42 2001 Jonathan Blandford <jrb@redhat.com>
* gtk/gtkentry.c: Make a GtkCellEditable
(get_widget_window_size): Change to let it honor size_allocate
when a CellEditable.
* gtk/gtktreeview.c: M-x clean-line-ends. Lots of focus and
editable changes.
(gtk_tree_view_set_cursor): Now you can set the cursor
horizontally, as well as start editing.
* gtk/gtkstyle.c (gtk_default_draw_check): changing toggle drawing
code to look more like the other check buttons.
* gtk/gtkcellrenderertoggle.c (gtk_cell_renderer_toggle_get_size):
Change the way we calculate cell size.
* gtk/gtkmarshal.list (VOID:STRING,STRING): new marshaller.
* demos/gtk-demo/sizegroup.c: Add mnemonics.
* gtk/gtkcellrenderer.c (gtk_cell_renderer_get_size): Fix docs.
Fix logic.
* gtk/gtkcellrenderertext.c: Change to be editable.
* gtk/gtkcellrenderertoggle.c: Change to be activatable.
* test/testtreesort.c: Fix misspelling
* test/testreecolumns.c: Add mnemonics.
* test/testreeedit.c: New test program.
2001-09-25 Havoc Pennington <hp@pobox.com>
* gtk/gtkwindow.c: Put notes in gtk_window_set_has_frame(),

View File

@ -1,3 +1,37 @@
Tue Sep 25 12:34:42 2001 Jonathan Blandford <jrb@redhat.com>
* gtk/gtkentry.c: Make a GtkCellEditable
(get_widget_window_size): Change to let it honor size_allocate
when a CellEditable.
* gtk/gtktreeview.c: M-x clean-line-ends. Lots of focus and
editable changes.
(gtk_tree_view_set_cursor): Now you can set the cursor
horizontally, as well as start editing.
* gtk/gtkstyle.c (gtk_default_draw_check): changing toggle drawing
code to look more like the other check buttons.
* gtk/gtkcellrenderertoggle.c (gtk_cell_renderer_toggle_get_size):
Change the way we calculate cell size.
* gtk/gtkmarshal.list (VOID:STRING,STRING): new marshaller.
* demos/gtk-demo/sizegroup.c: Add mnemonics.
* gtk/gtkcellrenderer.c (gtk_cell_renderer_get_size): Fix docs.
Fix logic.
* gtk/gtkcellrenderertext.c: Change to be editable.
* gtk/gtkcellrenderertoggle.c: Change to be activatable.
* test/testtreesort.c: Fix misspelling
* test/testreecolumns.c: Add mnemonics.
* test/testreeedit.c: New test program.
2001-09-25 Havoc Pennington <hp@pobox.com>
* gtk/gtkwindow.c: Put notes in gtk_window_set_has_frame(),

View File

@ -1,3 +1,37 @@
Tue Sep 25 12:34:42 2001 Jonathan Blandford <jrb@redhat.com>
* gtk/gtkentry.c: Make a GtkCellEditable
(get_widget_window_size): Change to let it honor size_allocate
when a CellEditable.
* gtk/gtktreeview.c: M-x clean-line-ends. Lots of focus and
editable changes.
(gtk_tree_view_set_cursor): Now you can set the cursor
horizontally, as well as start editing.
* gtk/gtkstyle.c (gtk_default_draw_check): changing toggle drawing
code to look more like the other check buttons.
* gtk/gtkcellrenderertoggle.c (gtk_cell_renderer_toggle_get_size):
Change the way we calculate cell size.
* gtk/gtkmarshal.list (VOID:STRING,STRING): new marshaller.
* demos/gtk-demo/sizegroup.c: Add mnemonics.
* gtk/gtkcellrenderer.c (gtk_cell_renderer_get_size): Fix docs.
Fix logic.
* gtk/gtkcellrenderertext.c: Change to be editable.
* gtk/gtkcellrenderertoggle.c: Change to be activatable.
* test/testtreesort.c: Fix misspelling
* test/testreecolumns.c: Add mnemonics.
* test/testreeedit.c: New test program.
2001-09-25 Havoc Pennington <hp@pobox.com>
* gtk/gtkwindow.c: Put notes in gtk_window_set_has_frame(),

View File

@ -1,3 +1,37 @@
Tue Sep 25 12:34:42 2001 Jonathan Blandford <jrb@redhat.com>
* gtk/gtkentry.c: Make a GtkCellEditable
(get_widget_window_size): Change to let it honor size_allocate
when a CellEditable.
* gtk/gtktreeview.c: M-x clean-line-ends. Lots of focus and
editable changes.
(gtk_tree_view_set_cursor): Now you can set the cursor
horizontally, as well as start editing.
* gtk/gtkstyle.c (gtk_default_draw_check): changing toggle drawing
code to look more like the other check buttons.
* gtk/gtkcellrenderertoggle.c (gtk_cell_renderer_toggle_get_size):
Change the way we calculate cell size.
* gtk/gtkmarshal.list (VOID:STRING,STRING): new marshaller.
* demos/gtk-demo/sizegroup.c: Add mnemonics.
* gtk/gtkcellrenderer.c (gtk_cell_renderer_get_size): Fix docs.
Fix logic.
* gtk/gtkcellrenderertext.c: Change to be editable.
* gtk/gtkcellrenderertoggle.c: Change to be activatable.
* test/testtreesort.c: Fix misspelling
* test/testreecolumns.c: Add mnemonics.
* test/testreeedit.c: New test program.
2001-09-25 Havoc Pennington <hp@pobox.com>
* gtk/gtkwindow.c: Put notes in gtk_window_set_has_frame(),

View File

@ -1,3 +1,37 @@
Tue Sep 25 12:34:42 2001 Jonathan Blandford <jrb@redhat.com>
* gtk/gtkentry.c: Make a GtkCellEditable
(get_widget_window_size): Change to let it honor size_allocate
when a CellEditable.
* gtk/gtktreeview.c: M-x clean-line-ends. Lots of focus and
editable changes.
(gtk_tree_view_set_cursor): Now you can set the cursor
horizontally, as well as start editing.
* gtk/gtkstyle.c (gtk_default_draw_check): changing toggle drawing
code to look more like the other check buttons.
* gtk/gtkcellrenderertoggle.c (gtk_cell_renderer_toggle_get_size):
Change the way we calculate cell size.
* gtk/gtkmarshal.list (VOID:STRING,STRING): new marshaller.
* demos/gtk-demo/sizegroup.c: Add mnemonics.
* gtk/gtkcellrenderer.c (gtk_cell_renderer_get_size): Fix docs.
Fix logic.
* gtk/gtkcellrenderertext.c: Change to be editable.
* gtk/gtkcellrenderertoggle.c: Change to be activatable.
* test/testtreesort.c: Fix misspelling
* test/testreecolumns.c: Add mnemonics.
* test/testreeedit.c: New test program.
2001-09-25 Havoc Pennington <hp@pobox.com>
* gtk/gtkwindow.c: Put notes in gtk_window_set_has_frame(),

View File

@ -1,3 +1,37 @@
Tue Sep 25 12:34:42 2001 Jonathan Blandford <jrb@redhat.com>
* gtk/gtkentry.c: Make a GtkCellEditable
(get_widget_window_size): Change to let it honor size_allocate
when a CellEditable.
* gtk/gtktreeview.c: M-x clean-line-ends. Lots of focus and
editable changes.
(gtk_tree_view_set_cursor): Now you can set the cursor
horizontally, as well as start editing.
* gtk/gtkstyle.c (gtk_default_draw_check): changing toggle drawing
code to look more like the other check buttons.
* gtk/gtkcellrenderertoggle.c (gtk_cell_renderer_toggle_get_size):
Change the way we calculate cell size.
* gtk/gtkmarshal.list (VOID:STRING,STRING): new marshaller.
* demos/gtk-demo/sizegroup.c: Add mnemonics.
* gtk/gtkcellrenderer.c (gtk_cell_renderer_get_size): Fix docs.
Fix logic.
* gtk/gtkcellrenderertext.c: Change to be editable.
* gtk/gtkcellrenderertoggle.c: Change to be activatable.
* test/testtreesort.c: Fix misspelling
* test/testreecolumns.c: Add mnemonics.
* test/testreeedit.c: New test program.
2001-09-25 Havoc Pennington <hp@pobox.com>
* gtk/gtkwindow.c: Put notes in gtk_window_set_has_frame(),

View File

@ -1,3 +1,37 @@
Tue Sep 25 12:34:42 2001 Jonathan Blandford <jrb@redhat.com>
* gtk/gtkentry.c: Make a GtkCellEditable
(get_widget_window_size): Change to let it honor size_allocate
when a CellEditable.
* gtk/gtktreeview.c: M-x clean-line-ends. Lots of focus and
editable changes.
(gtk_tree_view_set_cursor): Now you can set the cursor
horizontally, as well as start editing.
* gtk/gtkstyle.c (gtk_default_draw_check): changing toggle drawing
code to look more like the other check buttons.
* gtk/gtkcellrenderertoggle.c (gtk_cell_renderer_toggle_get_size):
Change the way we calculate cell size.
* gtk/gtkmarshal.list (VOID:STRING,STRING): new marshaller.
* demos/gtk-demo/sizegroup.c: Add mnemonics.
* gtk/gtkcellrenderer.c (gtk_cell_renderer_get_size): Fix docs.
Fix logic.
* gtk/gtkcellrenderertext.c: Change to be editable.
* gtk/gtkcellrenderertoggle.c: Change to be activatable.
* test/testtreesort.c: Fix misspelling
* test/testreecolumns.c: Add mnemonics.
* test/testreeedit.c: New test program.
2001-09-25 Havoc Pennington <hp@pobox.com>
* gtk/gtkwindow.c: Put notes in gtk_window_set_has_frame(),

View File

@ -43,12 +43,12 @@ static GtkItemFactoryEntry menu_items[] =
{ "/File/sep1", NULL, menuitem_cb, 0, "<Separator>" },
{ "/File/_Quit", "<control>Q", menuitem_cb, 0, "<StockItem>", GTK_STOCK_QUIT },
{ "/_Preferences", NULL, 0, 0, "<Branch>" },
{ "/_Preferences/_Color", NULL, 0, 0, "<Branch>" },
{ "/_Preferences/Color/_Red", NULL, menuitem_cb, 0, "<RadioItem>" },
{ "/_Preferences/Color/_Green", NULL, menuitem_cb, 0, "/Preferences/Color/Red" },
{ "/_Preferences", NULL, 0, 0, "<Branch>" },
{ "/_Preferences/_Color", NULL, 0, 0, "<Branch>" },
{ "/_Preferences/Color/_Red", NULL, menuitem_cb, 0, "<RadioItem>" },
{ "/_Preferences/Color/_Green", NULL, menuitem_cb, 0, "/Preferences/Color/Red" },
{ "/_Preferences/Color/_Blue", NULL, menuitem_cb, 0, "/Preferences/Color/Red" },
{ "/_Preferences/_Shape", NULL, 0, 0, "<Branch>" },
{ "/_Preferences/_Shape", NULL, 0, 0, "<Branch>" },
{ "/_Preferences/Shape/_Square", NULL, menuitem_cb, 0, "<RadioItem>" },
{ "/_Preferences/Shape/_Rectangle", NULL, menuitem_cb, 0, "/Preferences/Shape/Square" },
{ "/_Preferences/Shape/_Oval", NULL, menuitem_cb, 0, "/Preferences/Shape/Rectangle" },

View File

@ -52,7 +52,7 @@ add_row (GtkTable *table,
GtkWidget *option_menu;
GtkWidget *label;
label = gtk_label_new (label_text);
label = gtk_label_new_with_mnemonic (label_text);
gtk_misc_set_alignment (GTK_MISC (label), 0, 1);
gtk_table_attach (GTK_TABLE (table), label,
0, 1, row, row + 1,
@ -60,6 +60,7 @@ add_row (GtkTable *table,
0, 0);
option_menu = create_option_menu (options);
gtk_label_set_mnemonic_widget (GTK_LABEL (label), option_menu);
gtk_size_group_add_widget (size_group, option_menu);
gtk_table_attach (GTK_TABLE (table), option_menu,
1, 2, row, row + 1,
@ -137,8 +138,8 @@ do_sizegroup (void)
gtk_table_set_col_spacings (GTK_TABLE (table), 10);
gtk_container_add (GTK_CONTAINER (frame), table);
add_row (GTK_TABLE (table), 0, size_group, "Foreground", color_options);
add_row (GTK_TABLE (table), 1, size_group, "Background", color_options);
add_row (GTK_TABLE (table), 0, size_group, "_Foreground", color_options);
add_row (GTK_TABLE (table), 1, size_group, "_Background", color_options);
/* And another frame holding line style options
*/
@ -151,11 +152,11 @@ do_sizegroup (void)
gtk_table_set_col_spacings (GTK_TABLE (table), 10);
gtk_container_add (GTK_CONTAINER (frame), table);
add_row (GTK_TABLE (table), 0, size_group, "Dashing", dash_options);
add_row (GTK_TABLE (table), 1, size_group, "Line ends", end_options);
add_row (GTK_TABLE (table), 0, size_group, "_Dashing", dash_options);
add_row (GTK_TABLE (table), 1, size_group, "_Line ends", end_options);
/* And a check button to turn grouping on and off */
check_button = gtk_check_button_new_with_label ("Enable grouping");
check_button = gtk_check_button_new_with_mnemonic ("_Enable grouping");
gtk_box_pack_start (GTK_BOX (vbox), check_button, FALSE, FALSE, 0);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button), TRUE);

View File

@ -30,7 +30,7 @@ HOW THE GTKTREEVIEWCOLUMN STORES SIZE:
======================================
There are a number of size related fields in the GtkTreeViewColumn
structure:
structure. These are all valid after realization:
sizing The sizing method to use when calculating the size
of the column. Can be grow_only, resizable, auto, and fixed.

View File

@ -318,7 +318,9 @@ gtk_cell_renderer_set_property (GObject *object,
* Obtains the width and height needed to render the cell. Used by view widgets
* to determine the appropriate size for the cell_area passed to
* gtk_cell_renderer_render(). If @cell_area is not %NULL, fills in the x and y
* offsets (if set) of the cell relative to this location.
* offsets (if set) of the cell relative to this location. Please note that the
* values set in @width and @height, as well as those in @x_offset and @y_offset
* are inclusive of the xpad and ypad properties.
**/
void
gtk_cell_renderer_get_size (GtkCellRenderer *cell,
@ -329,29 +331,24 @@ gtk_cell_renderer_get_size (GtkCellRenderer *cell,
gint *width,
gint *height)
{
gint *real_width = NULL;
gint *real_height = NULL;
gint *real_width = width;
gint *real_height = height;
g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
g_return_if_fail (GTK_CELL_RENDERER_GET_CLASS (cell)->get_size != NULL);
if (width)
if (width && cell->width != -1)
{
if (cell->width == -1)
real_width = width;
else
*width = cell->width;
real_width = NULL;
*width = cell->width;
}
if (height)
if (height && cell->height != -1)
{
if (cell->height == -1)
real_height = height;
else
*height = cell->height;
real_height = NULL;
*height = cell->height;
}
if (real_width || real_height)
GTK_CELL_RENDERER_GET_CLASS (cell)->get_size (cell, widget, cell_area, x_offset, y_offset, real_width, real_height);
GTK_CELL_RENDERER_GET_CLASS (cell)->get_size (cell, widget, cell_area, x_offset, y_offset, real_width, real_height);
}
/**
@ -364,15 +361,13 @@ gtk_cell_renderer_get_size (GtkCellRenderer *cell,
* @expose_area: area that actually needs updating
* @flags: flags that affect rendering
*
* Invokes the virtual render function of the #GtkCellRenderer. The
* three passed-in rectangles are areas of @window. Most renderers
* will draw to @cell_area; the xalign, yalign, xpad, and ypad fields
* of the #GtkCellRenderer should be honored with respect to
* @cell_area. @background_area includes the blank space around the
* cell, and also the area containing the tree expander; so the
* @background_area rectangles for all cells tile to cover the entire
* @window. Cell renderers can use the @background_area to draw custom expanders, for
* example. @expose_area is a clip rectangle.
* Invokes the virtual render function of the #GtkCellRenderer. The three
* passed-in rectangles are areas of @window. Most renderers will draw within
* @cell_area; the xalign, yalign, xpad, and ypad fields of the #GtkCellRenderer
* should be honored with respect to @cell_area. @background_area includes the
* blank space around the cell, and also the area containing the tree expander;
* so the @background_area rectangles for all cells tile to cover the entire
* @window. @expose_area is a clip rectangle.
*
**/
void
@ -384,11 +379,6 @@ gtk_cell_renderer_render (GtkCellRenderer *cell,
GdkRectangle *expose_area,
GtkCellRendererState flags)
{
/* It's actually okay to pass in a NULL cell, as we run into that
* a lot
*/
if (cell == NULL)
return;
g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
g_return_if_fail (GTK_CELL_RENDERER_GET_CLASS (cell)->render != NULL);
@ -407,8 +397,8 @@ gtk_cell_renderer_render (GtkCellRenderer *cell,
* @event: a #GdkEvent
* @widget: widget that received the event
* @path: widget-dependent string representation of the event location; e.g. for #GtkTreeView, a string representation of #GtkTreePath
* @background_area: background area as passed to gtk_cell_renderer_render()
* @cell_area: cell area as passed to gtk_cell_renderer_render()
* @background_area: background area as passed to @gtk_cell_renderer_render
* @cell_area: cell area as passed to @gtk_cell_renderer_render
* @flags: render flags
*
* Passes an activate event to the cell renderer for possible processing. Some
@ -449,8 +439,8 @@ gtk_cell_renderer_activate (GtkCellRenderer *cell,
* @event: a #GdkEvent
* @widget: widget that received the event
* @path: widget-dependent string representation of the event location; e.g. for #GtkTreeView, a string representation of #GtkTreePath
* @background_area: background area as passed to gtk_cell_renderer_render()
* @cell_area: cell area as passed to gtk_cell_renderer_render()
* @background_area: background area as passed to @gtk_cell_renderer_render
* @cell_area: cell area as passed to @gtk_cell_renderer_render
* @flags: render flags
*
* Passes an activate event to the cell renderer for possible processing.

View File

@ -19,6 +19,9 @@
#include <stdlib.h>
#include "gtkcellrenderertext.h"
#include "gtkeditable.h"
#include "gtkentry.h"
#include "gtksignal.h"
#include "gtkintl.h"
static void gtk_cell_renderer_text_init (GtkCellRendererText *celltext);
@ -48,7 +51,18 @@ static void gtk_cell_renderer_text_render (GtkCellRenderer *cell,
GdkRectangle *expose_area,
guint flags);
static GtkCellEditable *gtk_cell_renderer_text_start_editing (GtkCellRenderer *cell,
GdkEvent *event,
GtkWidget *widget,
gchar *path,
GdkRectangle *background_area,
GdkRectangle *cell_area,
GtkCellRendererState flags);
enum {
EDITED,
LAST_SIGNAL
};
enum {
PROP_0,
@ -94,6 +108,9 @@ enum {
};
static gpointer parent_class;
static guint text_cell_renderer_signals [LAST_SIGNAL];
#define GTK_CELL_RENDERER_TEXT_PATH "gtk-cell-renderer-text-path"
GtkType
gtk_cell_renderer_text_get_type (void)
@ -128,7 +145,7 @@ gtk_cell_renderer_text_init (GtkCellRendererText *celltext)
GTK_CELL_RENDERER (celltext)->yalign = 0.5;
GTK_CELL_RENDERER (celltext)->xpad = 2;
GTK_CELL_RENDERER (celltext)->ypad = 2;
GTK_CELL_RENDERER (celltext)->mode = GTK_CELL_RENDERER_MODE_EDITABLE;
celltext->fixed_height_rows = -1;
celltext->font = pango_font_description_new ();
}
@ -148,7 +165,8 @@ gtk_cell_renderer_text_class_init (GtkCellRendererTextClass *class)
cell_class->get_size = gtk_cell_renderer_text_get_size;
cell_class->render = gtk_cell_renderer_text_render;
cell_class->start_editing = gtk_cell_renderer_text_start_editing;
g_object_class_install_property (object_class,
PROP_TEXT,
g_param_spec_string ("text",
@ -390,6 +408,17 @@ gtk_cell_renderer_text_class_init (GtkCellRendererTextClass *class)
ADD_SET_PROP ("underline_set", PROP_UNDERLINE_SET,
_("Underline set"),
_("Whether this tag affects underlining"));
text_cell_renderer_signals [EDITED] =
gtk_signal_new ("edited",
GTK_RUN_LAST,
GTK_CLASS_TYPE (object_class),
GTK_SIGNAL_OFFSET (GtkCellRendererTextClass, edited),
gtk_marshal_VOID__STRING_STRING,
GTK_TYPE_NONE, 2,
G_TYPE_STRING,
G_TYPE_STRING);
}
static void
@ -1135,12 +1164,12 @@ gtk_cell_renderer_text_get_size (GtkCellRenderer *cell,
if (x_offset)
{
*x_offset = cell->xalign * (cell_area->width - rect.width - (2 * cell->xpad));
*x_offset = MAX (*x_offset, 0) + cell->xpad;
*x_offset = MAX (*x_offset, 0);
}
if (y_offset)
{
*y_offset = cell->yalign * (cell_area->height - rect.height - (2 * cell->ypad));
*y_offset = MAX (*y_offset, 0) + cell->ypad;
*y_offset = MAX (*y_offset, 0);
}
}
@ -1202,7 +1231,7 @@ gtk_cell_renderer_text_render (GtkCellRenderer *cell,
g_object_unref (G_OBJECT (gc));
}
gtk_paint_layout (widget->style,
window,
state,
@ -1210,12 +1239,60 @@ gtk_cell_renderer_text_render (GtkCellRenderer *cell,
cell_area,
widget,
"cellrenderertext",
cell_area->x + x_offset,
cell_area->y + y_offset,
cell_area->x + x_offset + cell->xpad,
cell_area->y + y_offset + cell->ypad,
layout);
g_object_unref (G_OBJECT (layout));
}
static void
gtk_cell_renderer_text_editing_done (GtkCellEditable *entry,
gpointer data)
{
gchar *path;
gchar *new_text;
path = g_object_get_data (G_OBJECT (entry), GTK_CELL_RENDERER_TEXT_PATH);
new_text = gtk_entry_get_text (GTK_ENTRY (entry));
gtk_signal_emit (GTK_OBJECT (data), text_cell_renderer_signals[EDITED], path, new_text);
}
static GtkCellEditable *
gtk_cell_renderer_text_start_editing (GtkCellRenderer *cell,
GdkEvent *event,
GtkWidget *widget,
gchar *path,
GdkRectangle *background_area,
GdkRectangle *cell_area,
GtkCellRendererState flags)
{
GtkCellRendererText *celltext;
GtkWidget *entry;
celltext = GTK_CELL_RENDERER_TEXT (cell);
/* If the cell isn't editable we return NULL. */
if (celltext->editable == FALSE)
return NULL;
entry = g_object_new (GTK_TYPE_ENTRY,
"has_frame", FALSE,
NULL);
gtk_entry_set_text (GTK_ENTRY (entry), celltext->text);
g_object_set_data_full (G_OBJECT (entry), GTK_CELL_RENDERER_TEXT_PATH, g_strdup (path), g_free);
gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
gtk_widget_show (entry);
gtk_signal_connect (GTK_OBJECT (entry),
"editing_done",
G_CALLBACK (gtk_cell_renderer_text_editing_done),
celltext);
return GTK_CELL_EDITABLE (entry);
}
/**
* gtk_cell_renderer_text_set_fixed_height_from_font:
@ -1226,8 +1303,9 @@ gtk_cell_renderer_text_render (GtkCellRenderer *cell,
* "y_pad" property set on it. Further changes in these properties do not
* affect the height, so they must be accompanied by a subsequent call to this
* function. Using this function is unflexible, and should really only be used
* if calculating the size of a cell is too slow. If @no_rows is -1, then the
* fixed height is unset, and the height is determined by the properties again.
* if calculating the size of a cell is too slow (ie, a massive number of cells
* displayed). If @number_of_rows is -1, then the fixed height is unset, and
* the height is determined by the properties again.
**/
void
gtk_cell_renderer_text_set_fixed_height_from_font (GtkCellRendererText *renderer,

View File

@ -79,6 +79,10 @@ struct _GtkCellRendererText
struct _GtkCellRendererTextClass
{
GtkCellRendererClass parent_class;
void (* edited) (GtkCellRendererText *cell_renderer_text,
gchar *path,
gchar *new_text);
};
GtkType gtk_cell_renderer_text_get_type (void);

View File

@ -62,6 +62,7 @@ enum {
enum {
PROP_ZERO,
PROP_ACTIVATABLE,
PROP_ACTIVE,
PROP_RADIO
};
@ -101,6 +102,7 @@ gtk_cell_renderer_toggle_get_type (void)
static void
gtk_cell_renderer_toggle_init (GtkCellRendererToggle *celltoggle)
{
celltoggle->activatable = TRUE;
celltoggle->active = FALSE;
celltoggle->radio = FALSE;
GTK_CELL_RENDERER (celltoggle)->mode = GTK_CELL_RENDERER_MODE_ACTIVATABLE;
@ -130,6 +132,15 @@ gtk_cell_renderer_toggle_class_init (GtkCellRendererToggleClass *class)
G_PARAM_READABLE |
G_PARAM_WRITABLE));
g_object_class_install_property (object_class,
PROP_ACTIVATABLE,
g_param_spec_boolean ("activatable",
_("Activatable"),
_("The toggle button can be activated"),
TRUE,
G_PARAM_READABLE |
G_PARAM_WRITABLE));
g_object_class_install_property (object_class,
PROP_RADIO,
g_param_spec_boolean ("radio",
@ -163,6 +174,9 @@ gtk_cell_renderer_toggle_get_property (GObject *object,
case PROP_ACTIVE:
g_value_set_boolean (value, celltoggle->active);
break;
case PROP_ACTIVATABLE:
g_value_set_boolean (value, celltoggle->activatable);
break;
case PROP_RADIO:
g_value_set_boolean (value, celltoggle->radio);
break;
@ -187,6 +201,10 @@ gtk_cell_renderer_toggle_set_property (GObject *object,
celltoggle->active = g_value_get_boolean (value);
g_object_notify (G_OBJECT(object), "active");
break;
case PROP_ACTIVATABLE:
celltoggle->activatable = g_value_get_boolean (value);
g_object_notify (G_OBJECT(object), "activatable");
break;
case PROP_RADIO:
celltoggle->radio = g_value_get_boolean (value);
g_object_notify (G_OBJECT(object), "radio");
@ -241,13 +259,13 @@ gtk_cell_renderer_toggle_get_size (GtkCellRenderer *cell,
{
if (x_offset)
{
*x_offset = cell->xalign * (cell_area->width - calc_width - (2 * cell->xpad));
*x_offset = MAX (*x_offset, 0) + cell->xpad;
*x_offset = cell->xalign * (cell_area->width - calc_width);
*x_offset = MAX (*x_offset, 0);
}
if (y_offset)
{
*y_offset = cell->yalign * (cell_area->height - calc_height - (2 * cell->ypad));
*y_offset = MAX (*y_offset, 0) + cell->ypad;
*y_offset = cell->yalign * (cell_area->height - calc_height);
*y_offset = MAX (*y_offset, 0);
}
}
}
@ -281,21 +299,17 @@ gtk_cell_renderer_toggle_render (GtkCellRenderer *cell,
if ((flags & GTK_CELL_RENDERER_SELECTED) == GTK_CELL_RENDERER_SELECTED)
{
if (GTK_WIDGET_HAS_FOCUS (widget))
{
state = GTK_STATE_SELECTED;
}
state = GTK_STATE_SELECTED;
else
{
state = GTK_STATE_ACTIVE;
}
state = GTK_STATE_ACTIVE;
}
else if (cell->mode == GTK_CELL_RENDERER_MODE_INERT)
else if (celltoggle->activatable)
{
state = GTK_STATE_INSENSITIVE;
state = GTK_STATE_NORMAL;
}
else
{
state = GTK_STATE_NORMAL;
state = GTK_STATE_INSENSITIVE;
}
if (celltoggle->radio)
@ -306,7 +320,7 @@ gtk_cell_renderer_toggle_render (GtkCellRenderer *cell,
cell_area, widget, "cellradio",
cell_area->x + x_offset + cell->xpad,
cell_area->y + y_offset + cell->ypad,
width, height);
width - 1, height - 1);
}
else
{
@ -316,7 +330,7 @@ gtk_cell_renderer_toggle_render (GtkCellRenderer *cell,
cell_area, widget, "cellcheck",
cell_area->x + x_offset + cell->xpad,
cell_area->y + y_offset + cell->ypad,
width, height);
width - 1, height - 1);
}
}
@ -330,24 +344,15 @@ gtk_cell_renderer_toggle_activate (GtkCellRenderer *cell,
guint flags)
{
GtkCellRendererToggle *celltoggle;
gboolean retval = FALSE;
celltoggle = GTK_CELL_RENDERER_TOGGLE (cell);
switch (event->type)
if (celltoggle->activatable)
{
case GDK_BUTTON_PRESS:
{
gtk_signal_emit (GTK_OBJECT (cell), toggle_cell_signals[TOGGLED], path);
retval = TRUE;
}
break;
default:
break;
gtk_signal_emit (GTK_OBJECT (cell), toggle_cell_signals[TOGGLED], path);
return TRUE;
}
return retval;
return FALSE;
}
/**

View File

@ -43,6 +43,7 @@ struct _GtkCellRendererToggle
/*< private >*/
guint active : 1;
guint activatable : 1;
guint radio : 1;
};
@ -50,7 +51,7 @@ struct _GtkCellRendererToggleClass
{
GtkCellRendererClass parent_class;
void (* toggled) (GtkCellRendererToggle *celltoggle,
void (* toggled) (GtkCellRendererToggle *cell_renderer_toggle,
gchar *path);
};

View File

@ -30,6 +30,7 @@
#include "gdk/gdkkeysyms.h"
#include "gtkbindings.h"
#include "gtkcelleditable.h"
#include "gtkclipboard.h"
#include "gtkdnd.h"
#include "gtkentry.h"
@ -100,8 +101,9 @@ static GtkTargetEntry target_table[] = {
/* GObject, GtkObject methods
*/
static void gtk_entry_class_init (GtkEntryClass *klass);
static void gtk_entry_editable_init (GtkEditableClass *iface);
static void gtk_entry_class_init (GtkEntryClass *klass);
static void gtk_entry_editable_init (GtkEditableClass *iface);
static void gtk_entry_cell_editable_init (GtkCellEditableIface *iface);
static void gtk_entry_init (GtkEntry *entry);
static void gtk_entry_set_property (GObject *object,
guint prop_id,
@ -189,6 +191,11 @@ static gboolean gtk_entry_get_selection_bounds (GtkEditable *editable,
gint *start,
gint *end);
/* GtkCellEditable method implementations
*/
static void gtk_entry_start_editing (GtkCellEditable *cell_editable,
GdkEvent *event);
/* Default signal handlers
*/
static void gtk_entry_real_insert_text (GtkEntry *entry,
@ -298,10 +305,20 @@ gtk_entry_get_type (void)
NULL /* interface_data */
};
static const GInterfaceInfo cell_editable_info =
{
(GInterfaceInitFunc) gtk_entry_cell_editable_init, /* interface_init */
NULL, /* interface_finalize */
NULL /* interface_data */
};
entry_type = gtk_type_unique (GTK_TYPE_WIDGET, &entry_info);
g_type_add_interface_static (entry_type,
GTK_TYPE_EDITABLE,
&editable_info);
g_type_add_interface_static (entry_type,
GTK_TYPE_CELL_EDITABLE,
&cell_editable_info);
}
return entry_type;
@ -763,6 +780,12 @@ gtk_entry_editable_init (GtkEditableClass *iface)
iface->get_position = gtk_entry_get_position;
}
static void
gtk_entry_cell_editable_init (GtkCellEditableIface *iface)
{
iface->start_editing = gtk_entry_start_editing;
}
static void
gtk_entry_set_property (GObject *object,
guint prop_id,
@ -881,7 +904,7 @@ gtk_entry_init (GtkEntry *entry)
entry->invisible_char = '*';
entry->dnd_position = -1;
entry->width_chars = -1;
entry->is_cell_renderer = FALSE;
entry->has_frame = TRUE;
gtk_drag_dest_set (GTK_WIDGET (entry),
@ -1179,13 +1202,23 @@ get_widget_window_size (GtkEntry *entry,
*x = widget->allocation.x;
if (y)
*y = widget->allocation.y + (widget->allocation.height - requisition.height) / 2;
{
if (entry->is_cell_renderer)
*y = widget->allocation.y;
else
*y = widget->allocation.y + (widget->allocation.height - requisition.height) / 2;
}
if (width)
*width = widget->allocation.width;
if (height)
*height = requisition.height;
{
if (entry->is_cell_renderer)
*height = widget->allocation.height;
else
*height = requisition.height;
}
}
static void
@ -1777,6 +1810,43 @@ gtk_entry_style_set (GtkWidget *widget,
}
}
/* GtkCellEditable method implementations
*/
static void
gtk_cell_editable_entry_activated (GtkEntry *entry, gpointer data)
{
gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
}
static gboolean
gtk_cell_editable_key_press_event (GtkEntry *entry,
GdkEventKey *key_event,
gpointer data)
{
if (key_event->keyval == GDK_Escape)
{
gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
return TRUE;
}
return FALSE;
}
static void
gtk_entry_start_editing (GtkCellEditable *cell_editable,
GdkEvent *event)
{
GTK_ENTRY (cell_editable)->is_cell_renderer = TRUE;
g_signal_connect (G_OBJECT (cell_editable), "activate",
G_CALLBACK (gtk_cell_editable_entry_activated), NULL);
g_signal_connect (G_OBJECT (cell_editable), "key_press_event",
G_CALLBACK (gtk_cell_editable_key_press_event), NULL);
}
/* Default signal handlers
*/
static void

View File

@ -84,7 +84,9 @@ struct _GtkEntry
guint cursor_visible : 1;
guint in_click : 1; /* Flag so we don't select all when clicking in entry to focus in */
guint is_cell_renderer : 1;
guint button;
guint blink_timeout;
guint recompute_idle;

View File

@ -77,6 +77,7 @@ VOID:POINTER,INT
VOID:POINTER,POINTER,POINTER
VOID:POINTER,UINT
VOID:STRING
VOID:STRING,STRING
VOID:STRING,INT,POINTER
VOID:UINT,BOXED,UINT,FLAGS,FLAGS
VOID:UINT,OBJECT,UINT,FLAGS,FLAGS

View File

@ -77,6 +77,7 @@ VOID:POINTER,INT
VOID:POINTER,POINTER,POINTER
VOID:POINTER,UINT
VOID:STRING
VOID:STRING,STRING
VOID:STRING,INT,POINTER
VOID:UINT,BOXED,UINT,FLAGS,FLAGS
VOID:UINT,OBJECT,UINT,FLAGS,FLAGS

View File

@ -3018,19 +3018,12 @@ gtk_default_draw_check (GtkStyle *style,
x, y,
width, height);
x -= (1 + INDICATOR_PART_SIZE - width) / 2;
y -= (((1 + INDICATOR_PART_SIZE - height) / 2) - 1);
if (shadow_type == GTK_SHADOW_IN)
{
gdk_draw_line (window,
widget->style->fg_gc[state_type],
x, y,
x + width,
y + height);
gdk_draw_line (window,
widget->style->fg_gc[state_type],
x + width,
y,
x,
y + height);
draw_part (window, style->text_gc[state_type], area, x, y, CHECK_TEXT);
draw_part (window, style->text_aa_gc[state_type], area, x, y, CHECK_AA);
}
}
else

View File

@ -109,7 +109,6 @@ struct _GtkTreeViewPrivate
/* Focus code */
GtkTreeViewColumn *focus_column;
GtkTreeViewColumn *scroll_column;
/* Selection stuff */
GtkTreeRowReference *anchor;

File diff suppressed because it is too large Load Diff

View File

@ -96,6 +96,7 @@ struct _GtkTreeViewClass
gboolean expand,
gboolean open_all);
void (* select_cursor_parent) (GtkTreeView *tree_view);
void (* start_interactive_search) (GtkTreeView *tree_view);
};
@ -212,7 +213,9 @@ void gtk_tree_view_set_reorderable (GtkTreeView
gboolean reorderable);
gboolean gtk_tree_view_get_reorderable (GtkTreeView *tree_view);
void gtk_tree_view_set_cursor (GtkTreeView *tree_view,
GtkTreePath *path);
GtkTreePath *path,
GtkTreeViewColumn *focus_column,
gboolean start_editing);
/* Layout information */

View File

@ -2129,39 +2129,34 @@ gtk_tree_view_column_cell_get_size (GtkTreeViewColumn *tree_column,
}
}
/**
* gtk_tree_view_column_cell_render:
* @tree_column: A #GtkTreeViewColumn.
* @window: a #GdkDrawable to draw to
* @background_area: entire cell area (including tree expanders and maybe padding on the sides)
* @cell_area: area normally rendered by a cell renderer
* @expose_area: area that actually needs updating
* @flags: flags that affect rendering
*
* Renders the cell contained by #tree_column. This is used primarily by the
* GtkTreeView.
**/
void
gtk_tree_view_column_cell_render (GtkTreeViewColumn *tree_column,
GdkWindow *window,
GdkRectangle *background_area,
GdkRectangle *cell_area,
GdkRectangle *expose_area,
guint flags)
/* both rendering and rendering focus are somewhat complicated, and a bit of
* code. Rather than duplicate them, we put them together to keep the code in
* one place
*/
static void
gtk_tree_view_column_cell_render_or_focus (GtkTreeViewColumn *tree_column,
GdkWindow *window,
GdkRectangle *background_area,
GdkRectangle *cell_area,
GdkRectangle *expose_area,
guint flags,
gboolean render,
GdkRectangle *focus_rectangle)
{
GList *list;
GdkRectangle real_cell_area;
gint expand_cell_count = 0;
gint full_requested_width = 0;
gint extra_space;
gint min_x, min_y, max_x, max_y;
g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
g_return_if_fail (background_area != NULL);
g_return_if_fail (cell_area != NULL);
g_return_if_fail (expose_area != NULL);
min_x = G_MAXINT;
min_y = G_MAXINT;
max_x = 0;
max_y = 0;
real_cell_area = *cell_area;
/* Find out how my extra space we have to allocate */
for (list = tree_column->cell_list; list; list = list->next)
{
@ -2195,13 +2190,35 @@ gtk_tree_view_column_cell_render (GtkTreeViewColumn *tree_column,
real_cell_area.width = info->requested_width +
(info->expand?extra_space:0);
gtk_cell_renderer_render (info->cell,
window,
tree_column->tree_view,
background_area,
&real_cell_area,
expose_area,
flags);
if (render)
{
gtk_cell_renderer_render (info->cell,
window,
tree_column->tree_view,
background_area,
&real_cell_area,
expose_area,
flags);
}
else
{
gint x_offset, y_offset, width, height;
gtk_cell_renderer_get_size (info->cell,
tree_column->tree_view,
&real_cell_area,
&x_offset, &y_offset,
&width, &height);
if (min_x > (real_cell_area.x + x_offset))
min_x = real_cell_area.x + x_offset;
if (max_x < real_cell_area.x + x_offset + width)
max_x = real_cell_area.x + x_offset + width;
if (min_y > (real_cell_area.y + y_offset))
min_y = real_cell_area.y + y_offset;
if (max_y < real_cell_area.y + y_offset + height)
max_y = real_cell_area.y + y_offset + height;
}
real_cell_area.x += (info->requested_width + tree_column->spacing);
}
for (list = g_list_last (tree_column->cell_list); list; list = list->prev)
@ -2227,6 +2244,59 @@ gtk_tree_view_column_cell_render (GtkTreeViewColumn *tree_column,
flags);
real_cell_area.x += (info->requested_width + tree_column->spacing);
}
if (! render)
{
if (min_x >= max_x || min_y >= max_y)
{
*focus_rectangle = *cell_area;
focus_rectangle->x -= 1;
focus_rectangle->y -= 1;
focus_rectangle->width += 2;
focus_rectangle->height += 2;
}
else
{
focus_rectangle->x = min_x - 1;
focus_rectangle->y = min_y - 1;
focus_rectangle->width = (max_x - min_x) + 2;
focus_rectangle->height = (max_y - min_y) + 2;
}
}
}
/**
* gtk_tree_view_column_cell_render:
* @tree_column: A #GtkTreeViewColumn.
* @window: a #GdkDrawable to draw to
* @background_area: entire cell area (including tree expanders and maybe padding on the sides)
* @cell_area: area normally rendered by a cell renderer
* @expose_area: area that actually needs updating
* @flags: flags that affect rendering
*
* Renders the cell contained by #tree_column. This is used primarily by the
* GtkTreeView.
**/
void
gtk_tree_view_column_cell_render (GtkTreeViewColumn *tree_column,
GdkWindow *window,
GdkRectangle *background_area,
GdkRectangle *cell_area,
GdkRectangle *expose_area,
guint flags)
{
g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
g_return_if_fail (background_area != NULL);
g_return_if_fail (cell_area != NULL);
g_return_if_fail (expose_area != NULL);
gtk_tree_view_column_cell_render_or_focus (tree_column,
window,
background_area,
cell_area,
expose_area,
flags,
TRUE,
NULL);
}
gboolean
@ -2266,7 +2336,13 @@ _gtk_tree_view_column_cell_event (GtkTreeViewColumn *tree_column,
background_area,
cell_area,
flags);
return (*editable_widget != NULL);
if (*editable_widget != NULL)
{
g_return_val_if_fail (GTK_IS_CELL_EDITABLE (*editable_widget), FALSE);
return TRUE;
}
}
return FALSE;
}
@ -2274,13 +2350,10 @@ _gtk_tree_view_column_cell_event (GtkTreeViewColumn *tree_column,
gboolean
gtk_tree_view_column_cell_focus (GtkTreeViewColumn *tree_column,
gint direction,
gboolean unfocus)
gint direction)
{
if (unfocus)
GTK_TREE_VIEW (tree_column->tree_view)->priv->focus_column = NULL;
else
GTK_TREE_VIEW (tree_column->tree_view)->priv->focus_column = tree_column;
if (GTK_TREE_VIEW (tree_column->tree_view)->priv->focus_column == tree_column)
return FALSE;
return TRUE;
}
@ -2292,15 +2365,45 @@ gtk_tree_view_column_cell_draw_focus (GtkTreeViewColumn *tree_column,
GdkRectangle *expose_area,
guint flags)
{
gtk_paint_focus (tree_column->tree_view->style,
window,
NULL,
tree_column->tree_view,
"treeview",
cell_area->x,
cell_area->y,
cell_area->width-1,
cell_area->height);
g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
if (tree_column->editable_widget)
{
/* This function is only called on the editable row when editing.
*/
gtk_paint_focus (tree_column->tree_view->style,
window,
NULL,
tree_column->tree_view,
"treeview",
cell_area->x - 1,
cell_area->y - 1,
cell_area->width + 2 - 1,
cell_area->height + 2 - 1);
}
else
{
GdkRectangle focus_rectangle;
gtk_tree_view_column_cell_render_or_focus (tree_column,
window,
background_area,
cell_area,
expose_area,
flags,
FALSE,
&focus_rectangle);
gtk_paint_focus (tree_column->tree_view->style,
window,
NULL,
tree_column->tree_view,
"treeview",
focus_rectangle.x,
focus_rectangle.y,
focus_rectangle.width - 1,
focus_rectangle.height - 1);
}
}
gboolean

View File

@ -217,8 +217,7 @@ gboolean gtk_tree_view_column_cell_event (GtkTreeViewCol
GdkRectangle *cell_area,
guint flags);
gboolean gtk_tree_view_column_cell_focus (GtkTreeViewColumn *tree_column,
gint direction,
gboolean unfocus);
gint direction);
void gtk_tree_view_column_cell_draw_focus (GtkTreeViewColumn *tree_column,
GdkWindow *window,
GdkRectangle *background_area,

View File

@ -35,6 +35,7 @@ noinst_PROGRAMS = \
$(testsocket_programs) \
testtext \
testtextbuffer \
testtreeedit \
testtreeview \
testtreefocus \
testtreecolumns \
@ -52,6 +53,7 @@ testsocket_DEPENDENCIES = $(DEPS)
testsocket_child_DEPENDENCIES = $(DEPS)
testtext_DEPENDENCIES = $(TEST_DEPS)
testtextbuffer_DEPENDENCIES = $(TEST_DEPS)
testtreeedit_DEPENDENCIS = $(DEPS)
testtreeview_DEPENDENCIES = $(DEPS)
testtreefocus_DEPENDENCIES = $(DEPS)
testtreecolumns_DEPENDENCIES = $(DEPS)
@ -68,6 +70,7 @@ testselection_LDADD = $(LDADDS)
testsocket_LDADD = $(LDADDS)
testsocket_child_LDADD = $(LDADDS)
testtextbuffer_LDADD = $(LDADDS)
testtreeedit_LDADD = $(LDADDS)
testtreeview_LDADD = $(LDADDS)
testtreefocus_LDADD = $(LDADDS)
testtreecolumns_LDADD = $(LDADDS)
@ -79,6 +82,9 @@ testgtk_SOURCES = \
prop-editor.c \
testgtk.c
testtreeedit_SOURCES = \
testtreeedit.c
testtreeview_SOURCES = \
prop-editor.c \
testtreeview.c

View File

@ -620,14 +620,14 @@ main (int argc, char *argv[])
gtk_button_box_set_child_size (GTK_BUTTON_BOX (bbox), 0, 0);
gtk_box_pack_start (GTK_BOX (vbox2), bbox, TRUE, TRUE, 0);
button = gtk_button_new_with_label ("<<");
button = gtk_button_new_with_mnemonic ("<< (_Q)");
gtk_widget_set_sensitive (button, FALSE);
gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (add_left_clicked), top_right_tree_view);
g_signal_connect (G_OBJECT (gtk_tree_view_get_selection (GTK_TREE_VIEW (top_right_tree_view))),
"changed", GTK_SIGNAL_FUNC (selection_changed), button);
gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0);
button = gtk_button_new_with_label (">>");
button = gtk_button_new_with_mnemonic (">> (_W)");
gtk_widget_set_sensitive (button, FALSE);
gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (add_right_clicked), top_right_tree_view);
g_signal_connect (G_OBJECT (gtk_tree_view_get_selection (GTK_TREE_VIEW (left_tree_view))),
@ -639,14 +639,14 @@ main (int argc, char *argv[])
gtk_button_box_set_child_size (GTK_BUTTON_BOX (bbox), 0, 0);
gtk_box_pack_start (GTK_BOX (vbox2), bbox, TRUE, TRUE, 0);
button = gtk_button_new_with_label ("<<");
button = gtk_button_new_with_mnemonic ("<< (_E)");
gtk_widget_set_sensitive (button, FALSE);
gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (add_left_clicked), bottom_right_tree_view);
g_signal_connect (G_OBJECT (gtk_tree_view_get_selection (GTK_TREE_VIEW (bottom_right_tree_view))),
"changed", GTK_SIGNAL_FUNC (selection_changed), button);
gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0);
button = gtk_button_new_with_label (">>");
button = gtk_button_new_with_mnemonic (">> (_R)");
gtk_widget_set_sensitive (button, FALSE);
gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (add_right_clicked), bottom_right_tree_view);
g_signal_connect (G_OBJECT (gtk_tree_view_get_selection (GTK_TREE_VIEW (left_tree_view))),

140
tests/testtreeedit.c Normal file
View File

@ -0,0 +1,140 @@
#include <gtk/gtk.h>
typedef struct {
const gchar *string;
gboolean is_editable;
} ListEntry;
enum {
STRING_COLUMN,
IS_EDITABLE_COLUMN,
NUM_COLUMNS
};
static ListEntry model_strings[] =
{
{"A simple string", TRUE },
{"Another string!", TRUE },
{"Guess what, a third string. This one can't be edited", FALSE },
{"And then a fourth string. Neither can this", FALSE },
{"Multiline\nFun!", TRUE },
{ NULL }
};
static GtkTreeModel *
create_model (void)
{
GtkListStore *model;
GtkTreeIter iter;
gint i;
model = gtk_list_store_new (NUM_COLUMNS,
G_TYPE_STRING,
G_TYPE_BOOLEAN);
for (i = 0; model_strings[i].string != NULL; i++)
{
gtk_list_store_append (model, &iter);
gtk_list_store_set (model, &iter,
STRING_COLUMN, model_strings[i].string,
IS_EDITABLE_COLUMN, model_strings[i].is_editable,
-1);
}
return GTK_TREE_MODEL (model);
}
static void
toggled (GtkCellRendererToggle *cell,
gchar *path_string,
gpointer data)
{
GtkTreeModel *model = GTK_TREE_MODEL (data);
GtkTreeIter iter;
GtkTreePath *path = gtk_tree_path_new_from_string (path_string);
gboolean value;
gtk_tree_model_get_iter (model, &iter, path);
gtk_tree_model_get (model, &iter, IS_EDITABLE_COLUMN, &value, -1);
value = !value;
gtk_list_store_set (GTK_LIST_STORE (model), &iter, IS_EDITABLE_COLUMN, value, -1);
gtk_tree_path_free (path);
}
static void
edited (GtkCellRendererText *cell,
gchar *path_string,
gchar *new_text,
gpointer data)
{
GtkTreeModel *model = GTK_TREE_MODEL (data);
GtkTreeIter iter;
GtkTreePath *path = gtk_tree_path_new_from_string (path_string);
gtk_tree_model_get_iter (model, &iter, path);
gtk_list_store_set (GTK_LIST_STORE (model), &iter, STRING_COLUMN, new_text, -1);
gtk_tree_path_free (path);
}
gint
main (gint argc, gchar **argv)
{
GtkWidget *window;
GtkWidget *scrolled_window;
GtkWidget *tree_view;
GtkTreeModel *tree_model;
GtkCellRenderer *renderer;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "GtkTreeView editing sample");
gtk_signal_connect (GTK_OBJECT (window), "destroy", gtk_main_quit, NULL);
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window), GTK_SHADOW_ETCHED_IN);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_container_add (GTK_CONTAINER (window), scrolled_window);
tree_model = create_model ();
tree_view = gtk_tree_view_new_with_model (tree_model);
gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (tree_view), TRUE);
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (tree_view), FALSE);
renderer = gtk_cell_renderer_text_new ();
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
-1, "String",
renderer,
"text", STRING_COLUMN,
"editable", IS_EDITABLE_COLUMN,
NULL);
g_signal_connect (G_OBJECT (renderer), "edited",
G_CALLBACK (edited), tree_model);
renderer = gtk_cell_renderer_toggle_new ();
g_signal_connect (G_OBJECT (renderer), "toggled",
G_CALLBACK (toggled), tree_model);
g_object_set (G_OBJECT (renderer),
"xalign", 0.0,
"mode", GTK_CELL_RENDERER_MODE_ACTIVATABLE,
NULL);
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
-1, "Editable",
renderer,
"active", IS_EDITABLE_COLUMN,
NULL);
gtk_container_add (GTK_CONTAINER (scrolled_window), tree_view);
gtk_window_set_default_size (GTK_WINDOW (window),
650, 400);
gtk_widget_show_all (window);
gtk_main ();
return 0;
}

View File

@ -348,7 +348,7 @@ main (int argc, char *argv[])
renderer,
"active", ALEX_COLUMN,
"visible", VISIBLE_COLUMN,
"can_activate", WORLD_COLUMN,
"activatable", WORLD_COLUMN,
NULL);
column = gtk_tree_view_get_column (GTK_TREE_VIEW (tree_view), col_offset - 1);
gtk_tree_view_column_set_sizing (GTK_TREE_VIEW_COLUMN (column), GTK_TREE_VIEW_COLUMN_FIXED);
@ -381,7 +381,7 @@ main (int argc, char *argv[])
renderer,
"active", TIM_COLUMN,
"visible", VISIBLE_COLUMN,
"can_activate", WORLD_COLUMN,
"activatable", WORLD_COLUMN,
NULL);
column = gtk_tree_view_get_column (GTK_TREE_VIEW (tree_view), col_offset - 1);
gtk_tree_view_column_set_sizing (GTK_TREE_VIEW_COLUMN (column), GTK_TREE_VIEW_COLUMN_FIXED);

View File

@ -12,7 +12,7 @@ struct _ListSort
static ListSort data[] =
{
{ "Apples", "Transmorgrify long word to demonstrate weirdness", "Exculpatory", "Gesundheit"},
{ "Apples", "Transmogrify long word to demonstrate weirdness", "Exculpatory", "Gesundheit"},
{ "Oranges", "Wicker", "Adamantine", "Convivial" },
{ "Bovine Spongiform Encephilopathy", "Sleazebucket", "Mountaineer", "Pander" },
{ "Foot and Mouth", "Lampshade", "Skim Milk\nFull Milk", "Viewless" },