summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.van.berkom@gmail.com>2010-11-11 16:13:06 +0900
committerTristan Van Berkom <tristan.van.berkom@gmail.com>2010-11-11 16:13:06 +0900
commitf330b40521cf1f5b2b33b33bf7c5df0f59355838 (patch)
tree1c23f802c0879657fea533ac76077c8418d34fce /tests
parent524110f9025b149241747979003a3f243e907891 (diff)
downloadgtk+-f330b40521cf1f5b2b33b33bf7c5df0f59355838.tar.gz
GtkCellArea now paints focus on cells
Added concept of "Focus Siblings" to GtkCellArea so that some static text/icon may be included in the focus/click area of an activatable or editable cell, implemented focus drawing as well, updated testcellarea to reflect the changes.
Diffstat (limited to 'tests')
-rw-r--r--tests/cellareascaffold.c19
-rw-r--r--tests/testcellarea.c26
2 files changed, 33 insertions, 12 deletions
diff --git a/tests/cellareascaffold.c b/tests/cellareascaffold.c
index c0b72d7873..6d40be9edd 100644
--- a/tests/cellareascaffold.c
+++ b/tests/cellareascaffold.c
@@ -405,7 +405,9 @@ cell_area_scaffold_draw (GtkWidget *widget,
}
gtk_cell_area_apply_attributes (priv->area, priv->model, &iter, FALSE, FALSE);
- gtk_cell_area_render (priv->area, priv->iter, widget, cr, &render_area, flags);
+ gtk_cell_area_render (priv->area, priv->iter, widget, cr,
+ &render_area, &render_area, flags,
+ (have_focus && i == priv->focus_row));
if (orientation == GTK_ORIENTATION_HORIZONTAL)
{
@@ -726,13 +728,11 @@ cell_area_scaffold_focus (GtkWidget *widget,
/* If focus stays in the area we dont need to do any more */
if (gtk_cell_area_focus (priv->area, direction))
{
- GtkCellRenderer *renderer = gtk_cell_area_get_focus_cell (priv->area);
-
priv->focus_row = focus_row;
-
- g_print ("focusing in direction %s: focus set on a %s in row %d\n",
- DIRECTION_STR (direction), G_OBJECT_TYPE_NAME (renderer), priv->focus_row);
-
+
+ /* XXX A smarter implementation would only invalidate the rectangles where
+ * focus was removed from and new focus was placed */
+ gtk_widget_queue_draw (widget);
return TRUE;
}
else
@@ -802,8 +802,9 @@ cell_area_scaffold_focus (GtkWidget *widget,
}
}
- g_print ("focus leaving with no cells in focus (direction %s, focus_row %d)\n",
- DIRECTION_STR (direction), priv->focus_row);
+ /* XXX A smarter implementation would only invalidate the rectangles where
+ * focus was removed from and new focus was placed */
+ gtk_widget_queue_draw (widget);
return FALSE;
}
diff --git a/tests/testcellarea.c b/tests/testcellarea.c
index d547f71e3b..0acf2ebbb5 100644
--- a/tests/testcellarea.c
+++ b/tests/testcellarea.c
@@ -246,6 +246,8 @@ simple_cell_area (void)
/*******************************************************
* Focus Test *
*******************************************************/
+static GtkCellRenderer *focus_renderer, *sibling_renderer;
+
enum {
FOCUS_COLUMN_NAME,
FOCUS_COLUMN_CHECK,
@@ -328,7 +330,7 @@ focus_scaffold (void)
gtk_cell_area_attribute_connect (area, renderer, "text", FOCUS_COLUMN_NAME);
/* Catch signal ... */
- renderer = gtk_cell_renderer_toggle_new ();
+ focus_renderer = renderer = gtk_cell_renderer_toggle_new ();
g_object_set (G_OBJECT (renderer), "xalign", 0.0F, NULL);
gtk_cell_area_box_pack_start (GTK_CELL_AREA_BOX (area), renderer, FALSE, TRUE);
gtk_cell_area_attribute_connect (area, renderer, "active", FOCUS_COLUMN_CHECK);
@@ -336,7 +338,7 @@ focus_scaffold (void)
g_signal_connect (G_OBJECT (renderer), "toggled",
G_CALLBACK (cell_toggled), scaffold);
- renderer = gtk_cell_renderer_text_new ();
+ sibling_renderer = renderer = gtk_cell_renderer_text_new ();
g_object_set (G_OBJECT (renderer),
"wrap-mode", PANGO_WRAP_WORD,
"wrap-width", 150,
@@ -347,6 +349,21 @@ focus_scaffold (void)
return scaffold;
}
+static void
+focus_sibling_toggled (GtkToggleButton *toggle,
+ CellAreaScaffold *scaffold)
+{
+ GtkCellArea *area = cell_area_scaffold_get_area (scaffold);
+ gboolean active = gtk_toggle_button_get_active (toggle);
+
+ if (active)
+ gtk_cell_area_add_focus_sibling (area, focus_renderer, sibling_renderer);
+ else
+ gtk_cell_area_remove_focus_sibling (area, focus_renderer, sibling_renderer);
+
+ gtk_widget_queue_draw (GTK_WIDGET (scaffold));
+}
+
static void
focus_cell_area (void)
@@ -375,10 +392,13 @@ focus_cell_area (void)
gtk_widget_show (vbox);
gtk_box_pack_end (GTK_BOX (hbox), vbox, FALSE, FALSE, 0);
- widget = gtk_check_button_new_with_label ("check button");
+ widget = gtk_check_button_new_with_label ("Focus Sibling");
gtk_widget_show (widget);
gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0);
+ g_signal_connect (G_OBJECT (widget), "toggled",
+ G_CALLBACK (focus_sibling_toggled), scaffold);
+
gtk_container_add (GTK_CONTAINER (window), hbox);
gtk_widget_show (window);