+/* Computes 'cell_area' from 'background_area', which must be the background
+ area for a cell. Set 'subtract_focus_rect' to TRUE to compute the cell area
+ as passed to a GtkCellRenderer's "render" function, or to FALSE to compute
+ the cell area as passed to _pspp_sheet_view_column_cell_render().
+
+ 'column' is required to properly adjust 'cell_area->x' and
+ 'cell_area->width'. It may be set to NULL if these values are not of
+ interest. In this case 'cell_area->x' and 'cell_area->width' will be
+ returned as 0. */
+static void
+pspp_sheet_view_adjust_cell_area (PsppSheetView *tree_view,
+ PsppSheetViewColumn *column,
+ const GdkRectangle *background_area,
+ gboolean subtract_focus_rect,
+ GdkRectangle *cell_area)
+{
+ gint vertical_separator;
+ gint horizontal_separator;
+
+ *cell_area = *background_area;
+
+ gtk_widget_style_get (GTK_WIDGET (tree_view),
+ "vertical-separator", &vertical_separator,
+ "horizontal-separator", &horizontal_separator,
+ NULL);
+ cell_area->x += horizontal_separator / 2;
+ cell_area->y += vertical_separator / 2;
+ cell_area->width -= horizontal_separator;
+ cell_area->height -= vertical_separator;
+
+ if (subtract_focus_rect)
+ {
+ int focus_line_width;
+
+ gtk_widget_style_get (GTK_WIDGET (tree_view),
+ "focus-line-width", &focus_line_width,
+ NULL);
+ cell_area->x += focus_line_width;
+ cell_area->y += focus_line_width;
+ cell_area->width -= 2 * focus_line_width;
+ cell_area->height -= 2 * focus_line_width;
+ }
+
+ if (tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_NONE)
+ {
+ gint grid_line_width;
+ gtk_widget_style_get (GTK_WIDGET (tree_view),
+ "grid-line-width", &grid_line_width,
+ NULL);
+
+ if ((tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
+ || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH)
+ && column != NULL)
+ {
+ PsppSheetViewColumn *first_column, *last_column;
+ GList *list;
+
+ /* Find the last visible column. */
+ last_column = NULL;
+ for (list = g_list_last (tree_view->priv->columns);
+ list;
+ list = list->prev)
+ {
+ PsppSheetViewColumn *c = list->data;
+ if (c->visible)
+ {
+ last_column = c;
+ break;
+ }
+ }
+
+ /* Find the first visible column. */
+ first_column = NULL;
+ for (list = g_list_first (tree_view->priv->columns);
+ list;
+ list = list->next)
+ {
+ PsppSheetViewColumn *c = list->data;
+ if (c->visible)
+ {
+ first_column = c;
+ break;
+ }
+ }
+
+ if (column == first_column)
+ {
+ cell_area->width -= grid_line_width / 2;
+ }
+ else if (column == last_column)
+ {
+ cell_area->x += grid_line_width / 2;
+ cell_area->width -= grid_line_width / 2;
+ }
+ else
+ {
+ cell_area->x += grid_line_width / 2;
+ cell_area->width -= grid_line_width;
+ }
+ }
+
+ if (tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
+ || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH)
+ {
+ cell_area->y += grid_line_width / 2;
+ cell_area->height -= grid_line_width;
+ }
+ }
+
+ if (column == NULL)
+ {
+ cell_area->x = 0;
+ cell_area->width = 0;
+ }
+}