[gtk+/native-layout] Refactored gtk_tree_view_column_cell_process_action() and removed much redundant code.
- From: Tristan Van Berkom <tvb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/native-layout] Refactored gtk_tree_view_column_cell_process_action() and removed much redundant code.
- Date: Wed, 23 Jun 2010 22:03:32 +0000 (UTC)
commit 9f6c01c6656f2032a525e8044475965c1fa2b57e
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date: Tue Jun 22 13:43:21 2010 -0400
Refactored gtk_tree_view_column_cell_process_action() and removed
much redundant code.
gtk/gtktreeviewcolumn.c | 454 +++++++++++++++--------------------------------
1 files changed, 147 insertions(+), 307 deletions(-)
---
diff --git a/gtk/gtktreeviewcolumn.c b/gtk/gtktreeviewcolumn.c
index c428835..a49be62 100644
--- a/gtk/gtktreeviewcolumn.c
+++ b/gtk/gtktreeviewcolumn.c
@@ -2738,6 +2738,7 @@ gtk_tree_view_column_cell_process_action (GtkTreeViewColumn *tree_column,
/* If we have rtl text, we need to transform our areas */
GdkRectangle rtl_cell_area;
GdkRectangle rtl_background_area;
+ GtkPackType packing;
min_x = G_MAXINT;
min_y = G_MAXINT;
@@ -2815,349 +2816,188 @@ gtk_tree_view_column_cell_process_action (GtkTreeViewColumn *tree_column,
else if (extra_space > 0 && expand_cell_count > 0)
extra_space /= expand_cell_count;
- /* iterate list for GTK_PACK_START cells */
- for (list = tree_column->cell_list; list; list = list->next)
- {
- GtkTreeViewColumnCellInfo *info = (GtkTreeViewColumnCellInfo *) list->data;
-
- if (info->pack == GTK_PACK_END)
- continue;
-
- if (! info->cell->visible)
- continue;
-
- if ((info->has_focus || special_cells == 1) && cursor_row)
- flags |= GTK_CELL_RENDERER_FOCUSED;
- else
- flags &= ~GTK_CELL_RENDERER_FOCUSED;
- info->real_width = info->requested_width + (info->expand?extra_space:0);
+ for (packing = GTK_PACK_START; packing <= GTK_PACK_END; ++packing)
+ {
- /* We constrain ourselves to only the width available */
- if (real_cell_area.x - focus_line_width + info->real_width > cell_area->x + cell_area->width)
+ for (list = tree_column->cell_list; list; list = list->next)
{
- info->real_width = cell_area->x + cell_area->width - real_cell_area.x;
- }
-
- if (real_cell_area.x > cell_area->x + cell_area->width)
- break;
-
- real_cell_area.width = info->real_width;
- real_cell_area.width -= 2 * focus_line_width;
+ GtkTreeViewColumnCellInfo *info = (GtkTreeViewColumnCellInfo *) list->data;
- if (list->next)
- {
- real_background_area.width = info->real_width + depth;
- }
- else
- {
- /* fill the rest of background for the last cell */
- real_background_area.width = background_area->x + background_area->width - real_background_area.x;
- }
+ if (info->pack != packing)
+ continue;
- rtl_cell_area = real_cell_area;
- rtl_background_area = real_background_area;
-
- if (rtl)
- {
- rtl_cell_area.x = cell_area->x + cell_area->width - (real_cell_area.x - cell_area->x) - real_cell_area.width;
- rtl_background_area.x = background_area->x + background_area->width - (real_background_area.x - background_area->x) - real_background_area.width;
- }
+ if (! info->cell->visible)
+ continue;
- /* RENDER */
- if (action == CELL_ACTION_RENDER)
- {
- gtk_cell_renderer_render (info->cell,
- window,
- tree_column->tree_view,
- &rtl_background_area,
- &rtl_cell_area,
- &real_expose_area,
- flags);
- }
- /* FOCUS */
- else if (action == CELL_ACTION_FOCUS)
- {
- gint x_offset, y_offset;
- GtkRequisition min_size;
+ if ((info->has_focus || special_cells == 1) && cursor_row)
+ flags |= GTK_CELL_RENDERER_FOCUSED;
+ else
+ flags &= ~GTK_CELL_RENDERER_FOCUSED;
- gtk_cell_size_request_get_size (GTK_CELL_SIZE_REQUEST (info->cell),
- tree_column->tree_view,
- &min_size, NULL);
+ info->real_width = info->requested_width + (info->expand?extra_space:0);
+
+ /* We constrain ourselves to only the width available */
+ if (real_cell_area.x - focus_line_width + info->real_width > cell_area->x + cell_area->width)
+ {
+ info->real_width = cell_area->x + cell_area->width - real_cell_area.x;
+ }
+
+ /* Break out of the inner loop once we itterate out of our allocation
+ * (and possibly start the other packing direction) */
+ if (real_cell_area.x > cell_area->x + cell_area->width)
+ break;
- _gtk_cell_renderer_calc_offset (info->cell, &rtl_cell_area,
- gtk_widget_get_direction (tree_column->tree_view),
- min_size.width, min_size.height, &x_offset, &y_offset);
+ real_cell_area.width = info->real_width;
+ real_cell_area.width -= 2 * focus_line_width;
- if (special_cells > 1)
+ if (list->next)
{
- if (info->has_focus)
- {
- min_x = rtl_cell_area.x + x_offset;
- max_x = min_x + min_size.width;
- min_y = rtl_cell_area.y + y_offset;
- max_y = min_y + min_size.height;
- }
+ real_background_area.width = info->real_width + depth;
}
else
{
- if (min_x > (rtl_cell_area.x + x_offset))
- min_x = rtl_cell_area.x + x_offset;
- if (max_x < rtl_cell_area.x + x_offset + min_size.width)
- max_x = rtl_cell_area.x + x_offset + min_size.width;
- if (min_y > (rtl_cell_area.y + y_offset))
- min_y = rtl_cell_area.y + y_offset;
- if (max_y < rtl_cell_area.y + y_offset + min_size.height)
- max_y = rtl_cell_area.y + y_offset + min_size.height;
+ /* fill the rest of background for the last cell */
+ real_background_area.width = background_area->x + background_area->width - real_background_area.x;
}
- }
- /* EVENT */
- else if (action == CELL_ACTION_EVENT)
- {
- gboolean try_event = FALSE;
-
- if (event)
+
+ rtl_cell_area = real_cell_area;
+ rtl_background_area = real_background_area;
+
+ if (rtl)
{
- if (special_cells == 1)
- {
- /* only 1 activatable cell -> whole column can activate */
- if (cell_area->x <= ((GdkEventButton *)event)->x &&
- cell_area->x + cell_area->width > ((GdkEventButton *)event)->x)
- try_event = TRUE;
- }
- else if (rtl_cell_area.x <= ((GdkEventButton *)event)->x &&
- rtl_cell_area.x + rtl_cell_area.width > ((GdkEventButton *)event)->x)
- /* only activate cell if the user clicked on an individual
- * cell
- */
- try_event = TRUE;
+ rtl_cell_area.x = cell_area->x + cell_area->width - (real_cell_area.x - cell_area->x) - real_cell_area.width;
+ rtl_background_area.x = background_area->x + background_area->width - (real_background_area.x - background_area->x) - real_background_area.width;
}
- else if (special_cells > 1 && info->has_focus)
- try_event = TRUE;
- else if (special_cells == 1)
- try_event = TRUE;
- if (try_event)
+ /* RENDER */
+ if (action == CELL_ACTION_RENDER)
{
- gboolean visible, mode;
-
- g_object_get (info->cell,
- "visible", &visible,
- "mode", &mode,
- NULL);
- if (visible && mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
+ gtk_cell_renderer_render (info->cell,
+ window,
+ tree_column->tree_view,
+ &rtl_background_area,
+ &rtl_cell_area,
+ &real_expose_area,
+ flags);
+ }
+ /* FOCUS */
+ else if (action == CELL_ACTION_FOCUS)
+ {
+ gint x_offset, y_offset;
+ GtkRequisition min_size;
+
+ gtk_cell_size_request_get_size (GTK_CELL_SIZE_REQUEST (info->cell),
+ tree_column->tree_view,
+ &min_size, NULL);
+
+ _gtk_cell_renderer_calc_offset (info->cell, &rtl_cell_area,
+ gtk_widget_get_direction (tree_column->tree_view),
+ min_size.width, min_size.height, &x_offset, &y_offset);
+
+ if (special_cells > 1)
{
- if (gtk_cell_renderer_activate (info->cell,
- event,
- tree_column->tree_view,
- path_string,
- &rtl_background_area,
- &rtl_cell_area,
- flags))
+ if (info->has_focus)
{
- flags &= ~GTK_CELL_RENDERER_FOCUSED;
- return TRUE;
+ min_x = rtl_cell_area.x + x_offset;
+ max_x = min_x + min_size.width;
+ min_y = rtl_cell_area.y + y_offset;
+ max_y = min_y + min_size.height;
}
}
- else if (visible && mode == GTK_CELL_RENDERER_MODE_EDITABLE)
+ else
{
- *editable_widget =
- gtk_cell_renderer_start_editing (info->cell,
- event,
- tree_column->tree_view,
- path_string,
- &rtl_background_area,
- &rtl_cell_area,
- flags);
-
- if (*editable_widget != NULL)
- {
- g_return_val_if_fail (GTK_IS_CELL_EDITABLE (*editable_widget), FALSE);
- info->in_editing_mode = TRUE;
- gtk_tree_view_column_focus_cell (tree_column, info->cell);
-
- flags &= ~GTK_CELL_RENDERER_FOCUSED;
-
- return TRUE;
- }
+ if (min_x > (rtl_cell_area.x + x_offset))
+ min_x = rtl_cell_area.x + x_offset;
+ if (max_x < rtl_cell_area.x + x_offset + min_size.width)
+ max_x = rtl_cell_area.x + x_offset + min_size.width;
+ if (min_y > (rtl_cell_area.y + y_offset))
+ min_y = rtl_cell_area.y + y_offset;
+ if (max_y < rtl_cell_area.y + y_offset + min_size.height)
+ max_y = rtl_cell_area.y + y_offset + min_size.height;
}
}
- }
-
- flags &= ~GTK_CELL_RENDERER_FOCUSED;
-
- real_cell_area.x += (real_cell_area.width + 2 * focus_line_width + tree_column->spacing);
- real_background_area.x += real_background_area.width + tree_column->spacing;
-
- /* Only needed for first cell */
- depth = 0;
- }
-
- /* iterate list for PACK_END cells */
- for (list = g_list_last (tree_column->cell_list); list; list = list->prev)
- {
- GtkTreeViewColumnCellInfo *info = (GtkTreeViewColumnCellInfo *) list->data;
-
- if (info->pack == GTK_PACK_START)
- continue;
-
- if (! info->cell->visible)
- continue;
-
- if ((info->has_focus || special_cells == 1) && cursor_row)
- flags |= GTK_CELL_RENDERER_FOCUSED;
- else
- flags &= ~GTK_CELL_RENDERER_FOCUSED;
-
- info->real_width = info->requested_width + (info->expand?extra_space:0);
-
- /* We constrain ourselves to only the width available */
- if (real_cell_area.x - focus_line_width + info->real_width > cell_area->x + cell_area->width)
- {
- info->real_width = cell_area->x + cell_area->width - real_cell_area.x;
- }
-
- if (real_cell_area.x > cell_area->x + cell_area->width)
- break;
-
- real_cell_area.width = info->real_width;
- real_cell_area.width -= 2 * focus_line_width;
- real_background_area.width = info->real_width + depth;
-
- rtl_cell_area = real_cell_area;
- rtl_background_area = real_background_area;
- if (rtl)
- {
- rtl_cell_area.x = cell_area->x + cell_area->width - (real_cell_area.x - cell_area->x) - real_cell_area.width;
- rtl_background_area.x = background_area->x + background_area->width - (real_background_area.x - background_area->x) - real_background_area.width;
- }
-
- /* RENDER */
- if (action == CELL_ACTION_RENDER)
- {
- gtk_cell_renderer_render (info->cell,
- window,
- tree_column->tree_view,
- &rtl_background_area,
- &rtl_cell_area,
- &real_expose_area,
- flags);
- }
- /* FOCUS */
- else if (action == CELL_ACTION_FOCUS)
- {
- gint x_offset, y_offset;
- GtkRequisition min_size;
-
- gtk_cell_size_request_get_size (GTK_CELL_SIZE_REQUEST (info->cell),
- tree_column->tree_view,
- &min_size, NULL);
-
- _gtk_cell_renderer_calc_offset (info->cell, &rtl_cell_area,
- gtk_widget_get_direction (tree_column->tree_view),
- min_size.width, min_size.height, &x_offset, &y_offset);
-
- if (special_cells > 1)
- {
- if (info->has_focus)
- {
- min_x = rtl_cell_area.x + x_offset;
- max_x = min_x + min_size.width;
- min_y = rtl_cell_area.y + y_offset;
- max_y = min_y + min_size.height;
- }
- }
- else
- {
- if (min_x > (rtl_cell_area.x + x_offset))
- min_x = rtl_cell_area.x + x_offset;
- if (max_x < rtl_cell_area.x + x_offset + min_size.width)
- max_x = rtl_cell_area.x + x_offset + min_size.width;
- if (min_y > (rtl_cell_area.y + y_offset))
- min_y = rtl_cell_area.y + y_offset;
- if (max_y < rtl_cell_area.y + y_offset + min_size.height)
- max_y = rtl_cell_area.y + y_offset + min_size.height;
- }
- }
- /* EVENT */
- else if (action == CELL_ACTION_EVENT)
- {
- gboolean try_event = FALSE;
-
- if (event)
+ /* EVENT */
+ else if (action == CELL_ACTION_EVENT)
{
- if (special_cells == 1)
- {
- /* only 1 activatable cell -> whole column can activate */
- if (cell_area->x <= ((GdkEventButton *)event)->x &&
- cell_area->x + cell_area->width > ((GdkEventButton *)event)->x)
+ gboolean try_event = FALSE;
+
+ if (event)
+ {
+ if (special_cells == 1)
+ {
+ /* only 1 activatable cell -> whole column can activate */
+ if (cell_area->x <= ((GdkEventButton *)event)->x &&
+ cell_area->x + cell_area->width > ((GdkEventButton *)event)->x)
+ try_event = TRUE;
+ }
+ else if (rtl_cell_area.x <= ((GdkEventButton *)event)->x &&
+ rtl_cell_area.x + rtl_cell_area.width > ((GdkEventButton *)event)->x)
+ /* only activate cell if the user clicked on an individual
+ * cell
+ */
try_event = TRUE;
}
- else if (rtl_cell_area.x <= ((GdkEventButton *)event)->x &&
- rtl_cell_area.x + rtl_cell_area.width > ((GdkEventButton *)event)->x)
- /* only activate cell if the user clicked on an individual
- * cell
- */
+ else if (special_cells > 1 && info->has_focus)
try_event = TRUE;
- }
- else if (special_cells > 1 && info->has_focus)
- try_event = TRUE;
- else if (special_cells == 1)
- try_event = TRUE;
-
- if (try_event)
- {
- gboolean visible, mode;
-
- g_object_get (info->cell,
- "visible", &visible,
- "mode", &mode,
- NULL);
- if (visible && mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
- {
- if (gtk_cell_renderer_activate (info->cell,
- event,
- tree_column->tree_view,
- path_string,
- &rtl_background_area,
- &rtl_cell_area,
- flags))
+ else if (special_cells == 1)
+ try_event = TRUE;
+
+ if (try_event)
+ {
+ gboolean visible, mode;
+
+ g_object_get (info->cell,
+ "visible", &visible,
+ "mode", &mode,
+ NULL);
+ if (visible && mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
{
- flags &= ~GTK_CELL_RENDERER_FOCUSED;
- return TRUE;
+ if (gtk_cell_renderer_activate (info->cell,
+ event,
+ tree_column->tree_view,
+ path_string,
+ &rtl_background_area,
+ &rtl_cell_area,
+ flags))
+ {
+ flags &= ~GTK_CELL_RENDERER_FOCUSED;
+ return TRUE;
+ }
}
- }
- else if (visible && mode == GTK_CELL_RENDERER_MODE_EDITABLE)
- {
- *editable_widget =
- gtk_cell_renderer_start_editing (info->cell,
- event,
- tree_column->tree_view,
- path_string,
- &rtl_background_area,
- &rtl_cell_area,
- flags);
-
- if (*editable_widget != NULL)
+ else if (visible && mode == GTK_CELL_RENDERER_MODE_EDITABLE)
{
- g_return_val_if_fail (GTK_IS_CELL_EDITABLE (*editable_widget), FALSE);
- info->in_editing_mode = TRUE;
- gtk_tree_view_column_focus_cell (tree_column, info->cell);
-
- flags &= ~GTK_CELL_RENDERER_FOCUSED;
- return TRUE;
+ *editable_widget =
+ gtk_cell_renderer_start_editing (info->cell,
+ event,
+ tree_column->tree_view,
+ path_string,
+ &rtl_background_area,
+ &rtl_cell_area,
+ flags);
+
+ if (*editable_widget != NULL)
+ {
+ g_return_val_if_fail (GTK_IS_CELL_EDITABLE (*editable_widget), FALSE);
+ info->in_editing_mode = TRUE;
+ gtk_tree_view_column_focus_cell (tree_column, info->cell);
+
+ flags &= ~GTK_CELL_RENDERER_FOCUSED;
+
+ return TRUE;
+ }
}
}
}
- }
- flags &= ~GTK_CELL_RENDERER_FOCUSED;
-
- real_cell_area.x += (real_cell_area.width + 2 * focus_line_width + tree_column->spacing);
- real_background_area.x += (real_background_area.width + tree_column->spacing);
-
- /* Only needed for first cell */
- depth = 0;
+ flags &= ~GTK_CELL_RENDERER_FOCUSED;
+
+ real_cell_area.x += (real_cell_area.width + 2 * focus_line_width + tree_column->spacing);
+ real_background_area.x += real_background_area.width + tree_column->spacing;
+
+ /* Only needed for first cell */
+ depth = 0;
+ }
}
/* fill focus_rectangle when required */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]