summaryrefslogtreecommitdiff
path: root/tests/testtreefocus.c
diff options
context:
space:
mode:
authorJonathan Blandford <jrb@redhat.com>2001-03-15 23:21:39 +0000
committerJonathan Blandford <jrb@src.gnome.org>2001-03-15 23:21:39 +0000
commite4d1660042a437b041422ac442ee4845fbf7e6b6 (patch)
tree10b09bc64b280eb911725d9060d0e721419b961d /tests/testtreefocus.c
parent872efdd9a527e472e5f2724138344fdef3839df4 (diff)
downloadgtk+-e4d1660042a437b041422ac442ee4845fbf7e6b6.tar.gz
Changed prototype to allow for getting the location of the cell relative
Thu Mar 15 18:22:44 2001 Jonathan Blandford <jrb@redhat.com> * gtk/gtkcellrenderer.h: Changed prototype to allow for getting the location of the cell relative to its area. * gtk/gtkcell*: modified for above change * gtk/gtktreeview.c: modified for above change. Wed Mar 14 13:58:32 2001 Jonathan Blandford <jrb@redhat.com> * gtk/gtktreeview.c (gtk_tree_view_set_model): Ref the model. (gtk_tree_view_finalize): actually unref the model. Thanks to Jamie Strachan <frostfreek@yahoo.com> for noticing this error.
Diffstat (limited to 'tests/testtreefocus.c')
-rw-r--r--tests/testtreefocus.c223
1 files changed, 161 insertions, 62 deletions
diff --git a/tests/testtreefocus.c b/tests/testtreefocus.c
index f46d6992e4..c768a70d54 100644
--- a/tests/testtreefocus.c
+++ b/tests/testtreefocus.c
@@ -4,127 +4,130 @@ typedef struct _TreeStruct TreeStruct;
struct _TreeStruct
{
const gchar *label;
+ gboolean alex;
gboolean havoc;
+ gboolean tim;
gboolean owen;
+ gboolean world_holiday; /* shared by the european hackers */
TreeStruct *children;
};
static TreeStruct january[] =
{
- {"New Years Day", TRUE, TRUE, NULL},
- {"Presidential Inauguration", TRUE, TRUE, NULL},
- {"Martin Luther King Jr. day", TRUE, TRUE, NULL},
+ {"New Years Day", TRUE, TRUE, TRUE, TRUE, TRUE, NULL},
+ {"Presidential Inauguration", FALSE, TRUE, FALSE, TRUE, FALSE, NULL},
+ {"Martin Luther King Jr. day", FALSE, TRUE, FALSE, TRUE, FALSE, NULL},
{ NULL }
};
static TreeStruct february[] =
{
- { "Presidents' Day", TRUE, TRUE, NULL },
- { "Groundhog Day", FALSE, FALSE, NULL },
- { "Valentine's Day", FALSE, FALSE, NULL },
+ { "Presidents' Day", FALSE, TRUE, FALSE, TRUE, FALSE, NULL },
+ { "Groundhog Day", FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
+ { "Valentine's Day", FALSE, FALSE, FALSE, FALSE, TRUE, NULL },
{ NULL }
};
static TreeStruct march[] =
{
- { "National Tree Planting Day", FALSE, FALSE, NULL },
- { "St Patrick's Day", FALSE, FALSE, NULL },
+ { "National Tree Planting Day", FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
+ { "St Patrick's Day", FALSE, FALSE, FALSE, FALSE, TRUE, NULL },
{ NULL }
};
static TreeStruct april[] =
{
- { "April Fools' Day", FALSE, FALSE, NULL },
- { "Army Day", FALSE, FALSE, NULL },
- { "Earth Day", FALSE, FALSE, NULL },
- { "Administrative Professionals' Day", FALSE, FALSE, NULL },
+ { "April Fools' Day", FALSE, FALSE, FALSE, FALSE, TRUE, NULL },
+ { "Army Day", FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
+ { "Earth Day", FALSE, FALSE, FALSE, FALSE, TRUE, NULL },
+ { "Administrative Professionals' Day", FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
{ NULL }
};
static TreeStruct may[] =
{
- { "Nurses' Day", FALSE, FALSE, NULL },
- { "National Day of Prayer", FALSE, FALSE, NULL },
- { "Mothers' Day", FALSE, FALSE, NULL },
- { "Armed Forces Day", FALSE, FALSE, NULL },
- { "Memorial Day", TRUE, TRUE, NULL },
+ { "Nurses' Day", FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
+ { "National Day of Prayer", FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
+ { "Mothers' Day", FALSE, FALSE, FALSE, FALSE, TRUE, NULL },
+ { "Armed Forces Day", FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
+ { "Memorial Day", TRUE, TRUE, TRUE, TRUE, TRUE, NULL },
{ NULL }
};
static TreeStruct june[] =
{
- { "June Fathers' Day", FALSE, FALSE, NULL },
- { "Juneteenth (Liberation of Slaves)", FALSE, FALSE, NULL },
- { "Flag Day", TRUE, TRUE, NULL },
+ { "June Fathers' Day", FALSE, FALSE, FALSE, FALSE, TRUE, NULL },
+ { "Juneteenth (Liberation of Slaves)", FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
+ { "Flag Day", FALSE, TRUE, FALSE, TRUE, FALSE, NULL },
{ NULL }
};
static TreeStruct july[] =
{
- { "Parents' Day", FALSE, FALSE, NULL },
- { "Independence Day", TRUE, TRUE, NULL },
+ { "Parents' Day", FALSE, FALSE, FALSE, FALSE, TRUE, NULL },
+ { "Independence Day", FALSE, TRUE, FALSE, TRUE, FALSE, NULL },
{ NULL }
};
static TreeStruct august[] =
{
- { "Air Force Day", FALSE, FALSE, NULL },
- { "Coast Guard Day", FALSE, FALSE, NULL },
- { "Friendship Day", FALSE, FALSE, NULL },
+ { "Air Force Day", FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
+ { "Coast Guard Day", FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
+ { "Friendship Day", FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
{ NULL }
};
static TreeStruct september[] =
{
- { "Grandparents' Day", FALSE, FALSE, NULL },
- { "Citizenship Day or Constitution Day", FALSE, FALSE, NULL },
- { "Labor Day", TRUE, TRUE, NULL },
+ { "Grandparents' Day", FALSE, FALSE, FALSE, FALSE, TRUE, NULL },
+ { "Citizenship Day or Constitution Day", FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
+ { "Labor Day", TRUE, TRUE, TRUE, TRUE, TRUE, NULL },
{ NULL }
};
static TreeStruct october[] =
{
- { "National Children's Day", FALSE, FALSE, NULL },
- { "Bosses' Day", FALSE, FALSE, NULL },
- { "Sweetest Day", FALSE, FALSE, NULL },
- { "Mother-in-Law's Day", FALSE, FALSE, NULL },
- { "Navy Day", FALSE, FALSE, NULL },
- { "Columbus Day", TRUE, TRUE, NULL },
- { "Halloween", FALSE, FALSE, NULL },
+ { "National Children's Day", FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
+ { "Bosses' Day", FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
+ { "Sweetest Day", FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
+ { "Mother-in-Law's Day", FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
+ { "Navy Day", FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
+ { "Columbus Day", FALSE, TRUE, FALSE, TRUE, FALSE, NULL },
+ { "Halloween", FALSE, FALSE, FALSE, FALSE, TRUE, NULL },
{ NULL }
};
static TreeStruct november[] =
{
- { "Marine Corps Day", FALSE, FALSE, NULL },
- { "Veterans' Day", TRUE, TRUE, NULL },
- { "Thanksgiving", TRUE, TRUE, NULL },
+ { "Marine Corps Day", FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
+ { "Veterans' Day", TRUE, TRUE, TRUE, TRUE, TRUE, NULL },
+ { "Thanksgiving", FALSE, TRUE, FALSE, TRUE, FALSE, NULL },
{ NULL }
};
static TreeStruct december[] =
{
- { "Pearl Harbor Remembrance Day", FALSE, FALSE, NULL },
- { "Christmas", TRUE, TRUE, NULL },
- { "Kwanzaa", FALSE, FALSE, NULL },
+ { "Pearl Harbor Remembrance Day", FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
+ { "Christmas", TRUE, TRUE, TRUE, TRUE, TRUE, NULL },
+ { "Kwanzaa", FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
{ NULL }
};
static TreeStruct toplevel[] =
{
- {"January", FALSE, FALSE, january},
- {"February", FALSE, FALSE, february},
- {"March", FALSE, FALSE, march},
- {"April", FALSE, FALSE, april},
- {"May", FALSE, FALSE, may},
- {"June", FALSE, FALSE, june},
- {"July", FALSE, FALSE, july},
- {"August", FALSE, FALSE, august},
- {"September", FALSE, FALSE, september},
- {"October", FALSE, FALSE, october},
- {"November", FALSE, FALSE, november},
- {"December", FALSE, FALSE, december},
+ {"January", FALSE, FALSE, FALSE, FALSE, FALSE, january},
+ {"February", FALSE, FALSE, FALSE, FALSE, FALSE, february},
+ {"March", FALSE, FALSE, FALSE, FALSE, FALSE, march},
+ {"April", FALSE, FALSE, FALSE, FALSE, FALSE, april},
+ {"May", FALSE, FALSE, FALSE, FALSE, FALSE, may},
+ {"June", FALSE, FALSE, FALSE, FALSE, FALSE, june},
+ {"July", FALSE, FALSE, FALSE, FALSE, FALSE, july},
+ {"August", FALSE, FALSE, FALSE, FALSE, FALSE, august},
+ {"September", FALSE, FALSE, FALSE, FALSE, FALSE, september},
+ {"October", FALSE, FALSE, FALSE, FALSE, FALSE, october},
+ {"November", FALSE, FALSE, FALSE, FALSE, FALSE, november},
+ {"December", FALSE, FALSE, FALSE, FALSE, FALSE, december},
{NULL}
};
@@ -132,9 +135,12 @@ static TreeStruct toplevel[] =
enum
{
HOLIDAY_COLUMN = 0,
+ ALEX_COLUMN,
HAVOC_COLUMN,
+ TIM_COLUMN,
OWEN_COLUMN,
VISIBLE_COLUMN,
+ WORLD_COLUMN,
NUM_COLUMNS
};
@@ -145,7 +151,7 @@ make_model (void)
TreeStruct *month = toplevel;
GtkTreeIter iter;
- model = gtk_tree_store_new_with_types (NUM_COLUMNS, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN);
+ model = gtk_tree_store_new_with_types (NUM_COLUMNS, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN);
while (month->label)
{
@@ -154,9 +160,12 @@ make_model (void)
gtk_tree_store_append (model, &iter, NULL);
gtk_tree_store_set (model, &iter,
HOLIDAY_COLUMN, month->label,
+ ALEX_COLUMN, FALSE,
HAVOC_COLUMN, FALSE,
+ TIM_COLUMN, FALSE,
OWEN_COLUMN, FALSE,
VISIBLE_COLUMN, FALSE,
+ WORLD_COLUMN, FALSE,
-1);
while (holiday->label)
{
@@ -165,9 +174,12 @@ make_model (void)
gtk_tree_store_append (model, &child_iter, &iter);
gtk_tree_store_set (model, &child_iter,
HOLIDAY_COLUMN, holiday->label,
+ ALEX_COLUMN, holiday->alex,
HAVOC_COLUMN, holiday->havoc,
+ TIM_COLUMN, holiday->tim,
OWEN_COLUMN, holiday->owen,
VISIBLE_COLUMN, TRUE,
+ WORLD_COLUMN, holiday->world_holiday,
-1);
holiday ++;
@@ -179,6 +191,25 @@ make_model (void)
}
static void
+alex_toggled (GtkCellRendererToggle *cell,
+ gchar *path_str,
+ gpointer data)
+{
+ GtkTreeModel *model = (GtkTreeModel *) data;
+ GtkTreeIter iter;
+ GtkTreePath *path = gtk_tree_path_new_from_string (path_str);
+ gboolean alex;
+
+ gtk_tree_model_get_iter (model, &iter, path);
+ gtk_tree_model_get (model, &iter, ALEX_COLUMN, &alex, -1);
+
+ alex = !alex;
+ gtk_tree_store_set (GTK_TREE_STORE (model), &iter, ALEX_COLUMN, alex, -1);
+
+ gtk_tree_path_free (path);
+}
+
+static void
havoc_toggled (GtkCellRendererToggle *cell,
gchar *path_str,
gpointer data)
@@ -199,8 +230,8 @@ havoc_toggled (GtkCellRendererToggle *cell,
static void
owen_toggled (GtkCellRendererToggle *cell,
- gchar *path_str,
- gpointer data)
+ gchar *path_str,
+ gpointer data)
{
GtkTreeModel *model = (GtkTreeModel *) data;
GtkTreeIter iter;
@@ -216,6 +247,26 @@ owen_toggled (GtkCellRendererToggle *cell,
gtk_tree_path_free (path);
}
+static void
+tim_toggled (GtkCellRendererToggle *cell,
+ gchar *path_str,
+ gpointer data)
+{
+ GtkTreeModel *model = (GtkTreeModel *) data;
+ GtkTreeIter iter;
+ GtkTreePath *path = gtk_tree_path_new_from_string (path_str);
+ gboolean tim;
+
+ gtk_tree_model_get_iter (model, &iter, path);
+ gtk_tree_model_get (model, &iter, TIM_COLUMN, &tim, -1);
+
+ tim = !tim;
+ gtk_tree_store_set (GTK_TREE_STORE (model), &iter, TIM_COLUMN, tim, -1);
+
+ gtk_tree_path_free (path);
+}
+
+
int
main (int argc, char *argv[])
{
@@ -225,6 +276,8 @@ main (int argc, char *argv[])
GtkWidget *tree_view;
GtkTreeModel *model;
GtkCellRenderer *renderer;
+ gint col_offset;
+ GtkTreeViewColumn *column;
gtk_init (&argc, &argv);
@@ -242,39 +295,85 @@ main (int argc, char *argv[])
model = make_model ();
tree_view = gtk_tree_view_new_with_model (model);
- // g_object_set (G_OBJECT (tree_view), "model", model, NULL);
+ g_object_unref (G_OBJECT (model));
gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (tree_view), TRUE);
+
renderer = gtk_cell_renderer_text_new ();
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
-1, "Holiday",
renderer,
"text", HOLIDAY_COLUMN, NULL);
g_object_unref (renderer);
+
+ /* Alex Column */
+ renderer = gtk_cell_renderer_toggle_new ();
+ g_signal_connect_data (G_OBJECT (renderer), "toggled", alex_toggled, model, NULL, FALSE, FALSE);
+
+ g_object_set (G_OBJECT (renderer), "xalign", 0.0, NULL);
+ col_offset = gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
+ -1, "Alex",
+ renderer,
+ "active", ALEX_COLUMN,
+ "visible", VISIBLE_COLUMN,
+ "can_activate", 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);
+ gtk_tree_view_column_set_width (GTK_TREE_VIEW_COLUMN (column), 50);
+ g_object_unref (renderer);
+
+ /* Havoc Column */
renderer = gtk_cell_renderer_toggle_new ();
g_signal_connect_data (G_OBJECT (renderer), "toggled", havoc_toggled, model, NULL, FALSE, FALSE);
g_object_set (G_OBJECT (renderer), "xalign", 0.0, NULL);
- gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
- -1, "Havoc",
+ col_offset = gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
+ -1, "Havoc",
+ renderer,
+ "active", HAVOC_COLUMN,
+ "visible", VISIBLE_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);
+ gtk_tree_view_column_set_width (GTK_TREE_VIEW_COLUMN (column), 50);
+ g_object_unref (renderer);
+
+ /* Tim Column */
+ renderer = gtk_cell_renderer_toggle_new ();
+ g_signal_connect_data (G_OBJECT (renderer), "toggled", tim_toggled, model, NULL, FALSE, FALSE);
+
+ g_object_set (G_OBJECT (renderer), "xalign", 0.0, NULL);
+ col_offset = gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
+ -1, "Tim",
renderer,
- "active", HAVOC_COLUMN,
+ "active", TIM_COLUMN,
"visible", VISIBLE_COLUMN,
+ "can_activate", 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);
+ gtk_tree_view_column_set_width (GTK_TREE_VIEW_COLUMN (column), 50);
g_object_unref (renderer);
+
+ /* Owen Column */
renderer = gtk_cell_renderer_toggle_new ();
g_signal_connect_data (G_OBJECT (renderer), "toggled", owen_toggled, model, NULL, FALSE, FALSE);
g_object_set (G_OBJECT (renderer), "xalign", 0.0, NULL);
- gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
+ col_offset = gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
-1, "Owen",
renderer,
"active", OWEN_COLUMN,
"visible", VISIBLE_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);
+ gtk_tree_view_column_set_width (GTK_TREE_VIEW_COLUMN (column), 50);
g_object_unref (renderer);
- gtk_container_add (GTK_CONTAINER (scrolled_window), tree_view);
+ gtk_container_add (GTK_CONTAINER (scrolled_window), tree_view);
gtk_widget_show_all (window);
+
gtk_main ();
return 0;