static gboolean
-rectangle_from_cell (GtkSheet *sheet, gint row, gint col, GdkRectangle *r)
+rectangle_from_range (GtkSheet *sheet, const GtkSheetRange *range,
+ GdkRectangle *r)
{
- g_return_val_if_fail (row >= 0, FALSE);
- g_return_val_if_fail (col >= 0, FALSE);
+ g_return_val_if_fail (range, FALSE);
- r->x = g_sheet_column_start_pixel (sheet->column_geometry, col);
+ r->x = g_sheet_column_start_pixel (sheet->column_geometry, range->col0);
r->x -= sheet->hadjustment->value;
if ( sheet->row_titles_visible)
r->x += sheet->row_title_area.width;
- r->y = g_sheet_row_start_pixel (sheet->row_geometry, row);
+ r->y = g_sheet_row_start_pixel (sheet->row_geometry, range->row0);
r->y -= sheet->vadjustment->value;
if ( sheet->column_titles_visible)
r->y += sheet->column_title_area.height;
- r->width = g_sheet_column_get_width (sheet->column_geometry, col);
+ r->width = g_sheet_column_start_pixel (sheet->column_geometry, range->coli) -
+ g_sheet_column_start_pixel (sheet->column_geometry, range->col0) +
+ g_sheet_column_get_width (sheet->column_geometry, range->coli);
- r->height = g_sheet_row_get_height (sheet->row_geometry, row);
+ r->height = g_sheet_row_start_pixel (sheet->row_geometry, range->rowi) -
+ g_sheet_row_start_pixel (sheet->row_geometry, range->row0) +
+ g_sheet_row_get_height (sheet->row_geometry, range->rowi);
return TRUE;
}
+static gboolean
+rectangle_from_cell (GtkSheet *sheet, gint row, gint col,
+ GdkRectangle *r)
+{
+ GtkSheetRange range;
+ g_return_val_if_fail (row >= 0, FALSE);
+ g_return_val_if_fail (col >= 0, FALSE);
+
+ range.row0 = range.rowi = row;
+ range.col0 = range.coli = col;
+ return rectangle_from_range (sheet, &range, r);
+}
static void gtk_sheet_class_init (GtkSheetClass *klass);
const GtkSheetButton *button,
GtkRequisition *requisition);
-/* Attributes routines */
-static void init_attributes (const GtkSheet *sheet,
- gint col,
- GtkSheetCellAttr *attributes);
-
-
/* Memory allocation routines */
static void gtk_sheet_real_cell_clear (GtkSheet *sheet,
gint row,
{
GtkWidget *widget;
GdkRectangle area;
- gint i;
- gint text_width, text_height, y;
- gint size, sizel, sizer;
- GdkGC *fg_gc, *bg_gc;
GtkSheetCellAttr attributes;
PangoLayout *layout;
- PangoRectangle rect;
- PangoRectangle logical_rect;
- PangoLayoutLine *line;
- PangoFontMetrics *metrics;
- PangoContext *context = gtk_widget_get_pango_context (GTK_WIDGET (sheet));
- gint ascent, descent, y_pos;
+ PangoRectangle text;
+ gint font_height;
gchar *label;
if (!label)
return;
- if (row < 0 || row >= g_sheet_row_get_row_count (sheet->row_geometry)) return;
- if (col < 0 || col >= g_sheet_column_get_column_count (sheet->column_geometry)) return;
+ if (row < 0 || row >= g_sheet_row_get_row_count (sheet->row_geometry))
+ return;
+
+ if (col < 0 ||
+ col >= g_sheet_column_get_column_count (sheet->column_geometry))
+ return;
widget = GTK_WIDGET (sheet);
gdk_gc_set_foreground (sheet->fg_gc, &attributes.foreground);
gdk_gc_set_foreground (sheet->bg_gc, &attributes.background);
- fg_gc = sheet->fg_gc;
- bg_gc = sheet->bg_gc;
-
- area.x = g_sheet_column_start_pixel (sheet->column_geometry, col);
- area.x -= sheet->hadjustment->value;
-
- area.y = g_sheet_row_start_pixel (sheet->row_geometry, row);
- area.y -= sheet->vadjustment->value;
-
- area.width = g_sheet_column_get_width (sheet->column_geometry, col);
- area.height = g_sheet_row_get_height (sheet->row_geometry, row);
-
+ rectangle_from_cell (sheet, row, col, &area);
layout = gtk_widget_create_pango_layout (GTK_WIDGET (sheet), label);
dispose_string (sheet, label);
pango_layout_set_font_description (layout, attributes.font_desc);
- pango_layout_get_pixel_extents (layout, NULL, &rect);
-
- line = pango_layout_get_lines (layout)->data;
- pango_layout_line_get_extents (line, NULL, &logical_rect);
-
- metrics = pango_context_get_metrics (context,
- attributes.font_desc,
- pango_context_get_language (context));
-
- ascent = pango_font_metrics_get_ascent (metrics) / PANGO_SCALE;
- descent = pango_font_metrics_get_descent (metrics) / PANGO_SCALE;
-
- pango_font_metrics_unref (metrics);
- /* Align primarily for locale's ascent / descent */
+ pango_layout_get_pixel_extents (layout, NULL, &text);
- logical_rect.height /= PANGO_SCALE;
- logical_rect.y /= PANGO_SCALE;
- y_pos = area.height - logical_rect.height;
+ gdk_gc_set_clip_rectangle (sheet->fg_gc, &area);
- if (logical_rect.height > area.height)
- y_pos = (logical_rect.height - area.height - 2 * COLUMN_TITLES_HEIGHT) / 2;
- else if (y_pos < 0)
- y_pos = 0;
- else if (y_pos + logical_rect.height > area.height)
- y_pos = area.height - logical_rect.height;
+ font_height = pango_font_description_get_size (attributes.font_desc);
+ if ( !pango_font_description_get_size_is_absolute (attributes.font_desc))
+ font_height /= PANGO_SCALE;
- text_width = rect.width;
- text_height = rect.height;
- y = area.y + y_pos - COLUMN_TITLES_HEIGHT;
+ /* Centre the text vertically */
+ area.y += (area.height - font_height) / 2.0;
switch (attributes.justification)
{
case GTK_JUSTIFY_RIGHT:
- size = area.width;
- area.x +=area.width;
- {
- for (i = col - 1; i >= min_visible_column (sheet); i--)
- {
- if ( !gtk_sheet_cell_empty (sheet, row, i)) break;
- if (size >= text_width + COLUMN_TITLES_HEIGHT) break;
- size += g_sheet_column_get_width (sheet->column_geometry, i);
- g_sheet_column_set_right_text_column (sheet->column_geometry, i,
- MAX (col,
- g_sheet_column_get_right_text_column (sheet->column_geometry, i)));
- }
- area.width = size;
- }
- area.x -= size;
+ area.x += area.width - text.width;
break;
case GTK_JUSTIFY_CENTER:
- sizel = area.width / 2;
- sizer = area.width / 2;
- area.x += area.width / 2;
- {
- for (i = col + 1; i <= max_visible_column (sheet); i++)
- {
- if ( ! gtk_sheet_cell_empty (sheet, row, i)) break;
- if (sizer >= text_width / 2) break;
- sizer += g_sheet_column_get_width (sheet->column_geometry, i);
- g_sheet_column_set_left_text_column (sheet->column_geometry, i,
- MIN (
- col,
- g_sheet_column_get_left_text_column (sheet->column_geometry, i)));
- }
- for (i = col - 1; i >= min_visible_column (sheet); i--)
- {
- if ( ! gtk_sheet_cell_empty (sheet, row, i)) break;
- if (sizel >= text_width / 2) break;
- sizel += g_sheet_column_get_width (sheet->column_geometry, i);
- g_sheet_column_set_right_text_column (sheet->column_geometry, i,
- MAX (col,
- g_sheet_column_get_right_text_column (sheet->column_geometry, i)));
- }
- size = MIN (sizel, sizer);
- }
- area.x -= sizel;
- area.width = sizel + sizer;
+ area.x += (area.width - text.width) / 2.0;
break;
case GTK_JUSTIFY_LEFT:
+ /* Do nothing */
+ break;
default:
- size = area.width;
- {
- for (i = col + 1; i <= max_visible_column (sheet); i++)
- {
- if (! gtk_sheet_cell_empty (sheet, row, i)) break;
- if (size >= text_width + COLUMN_TITLES_HEIGHT) break;
- size += g_sheet_column_get_width (sheet->column_geometry, i);
- g_sheet_column_set_left_text_column (sheet->column_geometry, i,
- MIN (
- col,
- g_sheet_column_get_left_text_column (sheet->column_geometry, i)));
-
- }
- area.width = size;
- }
+ g_critical ("Unhandled justification %d in column %d\n",
+ attributes.justification, col);
break;
}
- if (sheet->row_titles_visible)
- area.x += sheet->row_title_area.width;
- if (sheet->column_titles_visible)
- area.y += sheet->column_title_area.height;
-
- gdk_gc_set_clip_rectangle (fg_gc, &area);
-
- gdk_draw_layout (sheet->sheet_window, fg_gc,
+ gdk_draw_layout (sheet->sheet_window, sheet->fg_gc,
area.x,
area.y,
layout);
- gdk_gc_set_clip_rectangle (fg_gc, NULL);
+ gdk_gc_set_clip_rectangle (sheet->fg_gc, NULL);
g_object_unref (layout);
-
}
static void
drawing_range.rowi = MIN (range->rowi, max_visible_row (sheet));
drawing_range.coli = MIN (range->coli, max_visible_column (sheet));
- area.x = g_sheet_column_start_pixel (sheet->column_geometry,
- drawing_range.col0);
-
- area.y = g_sheet_row_start_pixel (sheet->row_geometry,
- drawing_range.row0);
-
- area.width =
- g_sheet_column_start_pixel (sheet->column_geometry,
- drawing_range.coli + 1) - area.x;
-
- area.height = g_sheet_row_start_pixel (sheet->row_geometry,
- drawing_range.rowi + 1) - area.y;
- if ( sheet->column_titles_visible)
- area.y += sheet->column_title_area.height;
-
- if ( sheet->row_titles_visible)
- area.x += sheet->row_title_area.width;
+ rectangle_from_range (sheet, &drawing_range, &area);
}
gdk_draw_rectangle (sheet->sheet_window,
{
GdkRectangle area;
- area.x = g_sheet_column_start_pixel (sheet->column_geometry, new_range.col0);
- area.y = g_sheet_row_start_pixel (sheet->row_geometry, new_range.row0);
-
- if ( sheet->row_titles_visible)
- area.x += sheet->row_title_area.width;
-
- area.x -= sheet->hadjustment->value;
-
- if ( sheet->column_titles_visible)
- area.y += sheet->column_title_area.height;
-
- area.y -= sheet->vadjustment->value;
-
- area.width =
- g_sheet_column_start_pixel (sheet->column_geometry, new_range.coli) -
- g_sheet_column_start_pixel (sheet->column_geometry, new_range.col0) +
- g_sheet_column_get_width (sheet->column_geometry, new_range.coli);
-
- area.height = g_sheet_row_start_pixel (sheet->row_geometry, new_range.rowi) -
- g_sheet_row_start_pixel (sheet->row_geometry, new_range.row0) +
- g_sheet_row_get_height (sheet->row_geometry, new_range.rowi);
+ rectangle_from_range (sheet, &new_range, &area);
gdk_draw_rectangle (sheet->sheet_window,
sheet->xor_gc,
area.y + 1,
area.width - 2,
area.height - 2);
-
}
g_signal_emit (sheet, sheet_signals[CHANGED], 0, row, - 1);
}
+
gboolean
gtk_sheet_get_attributes (const GtkSheet *sheet, gint row, gint col,
- GtkSheetCellAttr *attributes)
+ GtkSheetCellAttr *attr)
{
- const GdkColor *fg, *bg;
+ GdkColor *fg, *bg;
const GtkJustification *j ;
const PangoFontDescription *font_desc ;
const GtkSheetCellBorder *border ;
+ GdkColormap *colormap;
g_return_val_if_fail (sheet != NULL, FALSE);
g_return_val_if_fail (GTK_IS_SHEET (sheet), FALSE);
if (row < 0 || col < 0) return FALSE;
- init_attributes (sheet, col, attributes);
- if ( !sheet->model)
- return FALSE;
+ attr->foreground = GTK_WIDGET (sheet)->style->black;
+ attr->background = sheet->color[BG_COLOR];
+
+ attr->border.width = 0;
+ attr->border.line_style = GDK_LINE_SOLID;
+ attr->border.cap_style = GDK_CAP_NOT_LAST;
+ attr->border.join_style = GDK_JOIN_MITER;
+ attr->border.mask = 0;
+ attr->border.color = GTK_WIDGET (sheet)->style->black;
+ attr->font_desc = GTK_WIDGET (sheet)->style->font_desc;
+
+ attr->is_editable = g_sheet_model_is_editable (sheet->model, row, col);
+ attr->is_visible = g_sheet_model_is_visible (sheet->model, row, col);
- attributes->is_editable = g_sheet_model_is_editable (sheet->model, row, col);
- attributes->is_visible = g_sheet_model_is_visible (sheet->model, row, col);
+ colormap = gtk_widget_get_colormap (GTK_WIDGET (sheet));
fg = g_sheet_model_get_foreground (sheet->model, row, col);
if ( fg )
- attributes->foreground = *fg;
+ {
+ gdk_colormap_alloc_color (colormap, fg, TRUE, TRUE);
+ attr->foreground = *fg;
+ }
bg = g_sheet_model_get_background (sheet->model, row, col);
if ( bg )
- attributes->background = *bg;
+ {
+ gdk_colormap_alloc_color (colormap, bg, TRUE, TRUE);
+ attr->background = *bg;
+ }
+
+ attr->justification =
+ g_sheet_column_get_justification (sheet->column_geometry, col);
j = g_sheet_model_get_justification (sheet->model, row, col);
- if (j) attributes->justification = *j;
+ if (j)
+ attr->justification = *j;
font_desc = g_sheet_model_get_font_desc (sheet->model, row, col);
- if ( font_desc ) attributes->font_desc = font_desc;
+ if ( font_desc ) attr->font_desc = font_desc;
border = g_sheet_model_get_cell_border (sheet->model, row, col);
- if ( border ) attributes->border = *border;
+ if ( border ) attr->border = *border;
return TRUE;
}
-static void
-init_attributes (const GtkSheet *sheet, gint col, GtkSheetCellAttr *attributes)
-{
- /* DEFAULT VALUES */
- attributes->foreground = GTK_WIDGET (sheet)->style->black;
- attributes->background = sheet->color[BG_COLOR];
- if (!GTK_WIDGET_REALIZED (GTK_WIDGET (sheet)))
- {
- attributes->background = sheet->color[BG_COLOR];
- }
- attributes->justification = g_sheet_column_get_justification (sheet->column_geometry, col);
- attributes->border.width = 0;
- attributes->border.line_style = GDK_LINE_SOLID;
- attributes->border.cap_style = GDK_CAP_NOT_LAST;
- attributes->border.join_style = GDK_JOIN_MITER;
- attributes->border.mask = 0;
- attributes->border.color = GTK_WIDGET (sheet)->style->black;
- attributes->is_editable = TRUE;
- attributes->is_visible = TRUE;
- attributes->font_desc = GTK_WIDGET (sheet)->style->font_desc;
-}
-
-
static void
gtk_sheet_button_size_request (GtkSheet *sheet,
const GtkSheetButton *button,
gtk_clipboard_clear (clipboard);
}
}
-