From: John Darrington Date: Mon, 1 Dec 2008 01:07:48 +0000 (+0900) Subject: Remove font information from cell attributes and sheet model. X-Git-Tag: v0.7.1~91^2~5 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bc632e6f82af2edb7e1c3f9feb9901deaa5038c0;p=pspp-builds.git Remove font information from cell attributes and sheet model. Deleted the font_desc member from the GtkSheetCellAttr struct and also all font related stuff from the GSheetModel interface. Instead, fonts are now considered strictly a parameter of the viewing widget instead of data in the model. --- diff --git a/lib/gtksheet/gsheetmodel.c b/lib/gtksheet/gsheetmodel.c index 88e4e603..23aca590 100644 --- a/lib/gtksheet/gsheetmodel.c +++ b/lib/gtksheet/gsheetmodel.c @@ -415,27 +415,6 @@ g_sheet_model_get_justification (const GSheetModel *model, row, column); } -/** - * g_sheet_model_get_font_desc: - * @sheet_model: A #GSheetModel - * @row: The row - * @column: The column - * - * Returns the font description of the cell at @row, @column - * Returns: the font description, or NULL on error. - **/ -const PangoFontDescription * -g_sheet_model_get_font_desc(const GSheetModel *model, - glong row, glong column) -{ - g_return_val_if_fail (G_IS_SHEET_MODEL (model), NULL); - if ( ! G_SHEET_MODEL_GET_IFACE (model)->get_font_desc) - return NULL; - - return G_SHEET_MODEL_GET_IFACE (model)->get_font_desc (model, - row, column); -} - /** * g_sheet_model_get_cell_border: * @sheet_model: A #GSheetModel diff --git a/lib/gtksheet/gsheetmodel.h b/lib/gtksheet/gsheetmodel.h index 510c92e9..cd7f1d33 100644 --- a/lib/gtksheet/gsheetmodel.h +++ b/lib/gtksheet/gsheetmodel.h @@ -117,9 +117,6 @@ struct _GSheetModelIface const GtkJustification * (* get_justification) (const GSheetModel *sheet_model, glong row, glong column); - const PangoFontDescription * (* get_font_desc) (const GSheetModel *sheet_model, - glong row, glong column); - const GtkSheetCellBorder * (* get_cell_border) (const GSheetModel *sheet_model, glong row, glong column); @@ -189,14 +186,9 @@ GdkColor *g_sheet_model_get_foreground GdkColor *g_sheet_model_get_background (const GSheetModel *model, glong row, glong column); - const GtkJustification *g_sheet_model_get_justification (const GSheetModel *model, glong row, glong column); - -const PangoFontDescription *g_sheet_model_get_font_desc - (const GSheetModel *model, glong row, glong column); - const GtkSheetCellBorder * g_sheet_model_get_cell_border (const GSheetModel *model, glong row, glong column); diff --git a/lib/gtksheet/gtksheet.c b/lib/gtksheet/gtksheet.c index 010778c7..3c1f3225 100644 --- a/lib/gtksheet/gtksheet.c +++ b/lib/gtksheet/gtksheet.c @@ -86,6 +86,8 @@ enum #define DEFAULT_COLUMN_WIDTH 80 #define DEFAULT_ROW_HEIGHT 25 +static void set_entry_widget_font (GtkSheet *sheet); + static void gtk_sheet_update_primary_selection (GtkSheet *sheet); static void draw_column_title_buttons_range (GtkSheet *sheet, gint first, gint n); static void draw_row_title_buttons_range (GtkSheet *sheet, gint first, gint n); @@ -392,6 +394,7 @@ static void gtk_sheet_map (GtkWidget *widget); static void gtk_sheet_unmap (GtkWidget *widget); static gint gtk_sheet_expose (GtkWidget *widget, GdkEventExpose *event); + static void gtk_sheet_forall (GtkContainer *container, gboolean include_internals, GtkCallback callback, @@ -1707,6 +1710,7 @@ gtk_sheet_style_set (GtkWidget *widget, gtk_style_set_background (widget->style, widget->window, widget->state); } + set_entry_widget_font (sheet); } #define BORDER_WIDTH 2 @@ -2009,6 +2013,7 @@ gtk_sheet_cell_draw (GtkSheet *sheet, gint row, gint col) { PangoLayout *layout; PangoRectangle text; + PangoFontDescription *font_desc = GTK_WIDGET (sheet)->style->font_desc; gint font_height; gchar *label; @@ -2058,15 +2063,16 @@ gtk_sheet_cell_draw (GtkSheet *sheet, gint row, gint col) 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_set_font_description (layout, font_desc); + pango_layout_get_pixel_extents (layout, NULL, &text); gdk_gc_set_clip_rectangle (sheet->fg_gc, &area); - font_height = pango_font_description_get_size (attributes.font_desc); - if ( !pango_font_description_get_size_is_absolute (attributes.font_desc)) + font_height = pango_font_description_get_size (font_desc); + if ( !pango_font_description_get_size_is_absolute (font_desc)) font_height /= PANGO_SCALE; /* Centre the text vertically */ @@ -4547,6 +4553,20 @@ gtk_sheet_size_allocate_entry (GtkSheet *sheet) } +/* Copy the sheet's font to the entry widget */ +static void +set_entry_widget_font (GtkSheet *sheet) +{ + GtkRcStyle *style = gtk_widget_get_modifier_style (sheet->entry_widget); + + pango_font_description_free (style->font_desc); + style->font_desc = pango_font_description_copy (GTK_WIDGET (sheet)->style->font_desc); + + gtk_widget_modify_style (sheet->entry_widget, style); +} + + + static void create_sheet_entry (GtkSheet *sheet) { @@ -4584,6 +4604,8 @@ create_sheet_entry (GtkSheet *sheet) G_CALLBACK (gtk_sheet_entry_changed), sheet); + set_entry_widget_font (sheet); + gtk_widget_show (sheet->entry_widget); } @@ -5193,7 +5215,6 @@ gtk_sheet_get_attributes (const GtkSheet *sheet, gint row, gint col, { GdkColor *fg, *bg; const GtkJustification *j ; - const PangoFontDescription *font_desc ; const GtkSheetCellBorder *border ; GdkColormap *colormap; @@ -5211,7 +5232,6 @@ gtk_sheet_get_attributes (const GtkSheet *sheet, gint row, gint col, 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); @@ -5237,9 +5257,6 @@ gtk_sheet_get_attributes (const GtkSheet *sheet, gint row, gint col, if (j) attr->justification = *j; - font_desc = g_sheet_model_get_font_desc (sheet->model, row, col); - if ( font_desc ) attr->font_desc = font_desc; - border = g_sheet_model_get_cell_border (sheet->model, row, col); if ( border ) attr->border = *border; diff --git a/lib/gtksheet/gtksheet.h b/lib/gtksheet/gtksheet.h index 75e21c98..92c4248e 100644 --- a/lib/gtksheet/gtksheet.h +++ b/lib/gtksheet/gtksheet.h @@ -62,7 +62,6 @@ typedef struct _GtkSheetHoverTitle GtkSheetHoverTitle; struct _GtkSheetCellAttr { GtkJustification justification; - const PangoFontDescription *font_desc; GdkColor foreground; GdkColor background; GtkSheetCellBorder border; diff --git a/src/ui/gui/data-editor.c b/src/ui/gui/data-editor.c index d4cbae1e..c242f764 100644 --- a/src/ui/gui/data-editor.c +++ b/src/ui/gui/data-editor.c @@ -1038,9 +1038,19 @@ static void fonts_activate (GtkMenuItem *menuitem, gpointer data) { struct data_editor *de = data; + PangoFontDescription *current_font; + gchar *font_name; GtkWidget *dialog = gtk_font_selection_dialog_new (_("Font Selection")); + + current_font = GTK_WIDGET(de->data_editor)->style->font_desc; + font_name = pango_font_description_to_string (current_font); + + gtk_font_selection_dialog_set_font_name (dialog, font_name); + + g_free (font_name); + gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (get_widget_assert (de->xml, "data_editor"))); diff --git a/src/ui/gui/psppire-data-editor.c b/src/ui/gui/psppire-data-editor.c index 592e8aaa..02130f69 100644 --- a/src/ui/gui/psppire-data-editor.c +++ b/src/ui/gui/psppire-data-editor.c @@ -1263,11 +1263,27 @@ psppire_data_editor_show_grid (PsppireDataEditor *de, gboolean grid_visible) gtk_sheet_show_grid (GTK_SHEET (de->data_sheet[0]), grid_visible); } + +static void +set_font (GtkWidget *w, gpointer data) +{ + PangoFontDescription *font_desc = data; + GtkRcStyle *style = gtk_widget_get_modifier_style (w); + + pango_font_description_free (style->font_desc); + style->font_desc = pango_font_description_copy (font_desc); + + gtk_widget_modify_style (w, style); + + if ( GTK_IS_CONTAINER (w)) + gtk_container_foreach (w, set_font, font_desc); +} + void psppire_data_editor_set_font (PsppireDataEditor *de, PangoFontDescription *font_desc) { - psppire_data_store_set_font (de->data_store, font_desc); - psppire_var_store_set_font (de->var_store, font_desc); + set_font (de, font_desc); + gtk_container_foreach (GTK_CONTAINER (de), set_font, font_desc); } diff --git a/src/ui/gui/psppire-data-store.c b/src/ui/gui/psppire-data-store.c index 03e6e4c0..0152d3f6 100644 --- a/src/ui/gui/psppire-data-store.c +++ b/src/ui/gui/psppire-data-store.c @@ -54,7 +54,7 @@ static gboolean psppire_data_store_clear_datum (GSheetModel *model, static GObjectClass *parent_class = NULL; -enum {FONT_CHANGED, +enum { BACKEND_CHANGED, n_SIGNALS}; @@ -113,17 +113,6 @@ psppire_data_store_class_init (PsppireDataStoreClass *class) object_class->finalize = psppire_data_store_finalize; object_class->dispose = psppire_data_store_dispose; - signals [FONT_CHANGED] = - g_signal_new ("font_changed", - G_TYPE_FROM_CLASS (class), - G_SIGNAL_RUN_FIRST, - 0, - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, - 0); - - signals [BACKEND_CHANGED] = g_signal_new ("backend-changed", G_TYPE_FROM_CLASS (class), @@ -173,15 +162,6 @@ psppire_data_store_init (PsppireDataStore *data_store) data_store->dispose_has_run = FALSE; } -const PangoFontDescription * -psppire_data_store_get_font_desc (const GSheetModel *model, - glong row, glong column) -{ - PsppireDataStore *store = PSPPIRE_DATA_STORE (model); - - return store->font_desc; -} - static inline gchar * psppire_data_store_get_string_wrapper (const GSheetModel *model, glong row, glong column) @@ -220,7 +200,6 @@ psppire_data_store_sheet_model_init (GSheetModelIface *iface) iface->is_editable = NULL; iface->get_foreground = NULL; iface->get_background = NULL; - iface->get_font_desc = psppire_data_store_get_font_desc; iface->get_cell_border = NULL; iface->get_column_count = psppire_data_store_get_var_count; iface->get_row_count = psppire_data_store_get_case_count_wrapper; @@ -695,24 +674,6 @@ psppire_data_store_set_string (PsppireDataStore *store, } -void -psppire_data_store_set_font (PsppireDataStore *store, - const PangoFontDescription *fd) -{ - g_return_if_fail (store); - g_return_if_fail (PSPPIRE_IS_DATA_STORE (store)); - - store->font_desc = fd; -#if 0 - store->width_of_m = calc_m_width (fd); -#endif - g_signal_emit (store, signals [FONT_CHANGED], 0); - - - g_sheet_model_range_changed (G_SHEET_MODEL (store), - -1, -1, -1, -1); -} - void psppire_data_store_show_labels (PsppireDataStore *store, gboolean show_labels) diff --git a/src/ui/gui/psppire-data-store.h b/src/ui/gui/psppire-data-store.h index 8f30afa4..4000e25b 100644 --- a/src/ui/gui/psppire-data-store.h +++ b/src/ui/gui/psppire-data-store.h @@ -83,7 +83,7 @@ struct _PsppireDataStore gboolean dispose_has_run ; PsppireDict *dict; PsppireCaseFile *case_file; - const PangoFontDescription *font_desc; + /* The width of an upper case 'M' rendered in the current font */ gint width_of_m ; @@ -118,9 +118,6 @@ void psppire_data_store_set_case_file (PsppireDataStore *data_store, void psppire_data_store_set_dictionary (PsppireDataStore *data_store, PsppireDict *dict); -void psppire_data_store_set_font (PsppireDataStore *store, - const PangoFontDescription *fd); - void psppire_data_store_show_labels (PsppireDataStore *store, gboolean show_labels); diff --git a/src/ui/gui/psppire-var-store.c b/src/ui/gui/psppire-var-store.c index 7e005e39..904ac39d 100644 --- a/src/ui/gui/psppire-var-store.c +++ b/src/ui/gui/psppire-var-store.c @@ -301,15 +301,6 @@ psppire_var_store_get_foreground (const GSheetModel *model, glong row, glong col } -const PangoFontDescription * -psppire_var_store_get_font_desc (const GSheetModel *model, - glong row, glong column) -{ - PsppireVarStore *store = PSPPIRE_VAR_STORE (model); - - return store->font_desc; -} - static gchar *get_column_title (const GSheetModel *model, gint col); static gchar *get_row_title (const GSheetModel *model, gint row); static gboolean get_row_sensitivity (const GSheetModel *model, gint row); @@ -326,7 +317,6 @@ psppire_var_store_sheet_model_init (GSheetModelIface *iface) iface->is_editable = psppire_var_store_is_editable; iface->get_foreground = psppire_var_store_get_foreground; iface->get_background = NULL; - iface->get_font_desc = psppire_var_store_get_font_desc; iface->get_cell_border = NULL; iface->get_justification = NULL; @@ -748,18 +738,6 @@ psppire_var_store_get_var_cnt (PsppireVarStore *store) } -void -psppire_var_store_set_font (PsppireVarStore *store, const PangoFontDescription *fd) -{ - g_return_if_fail (store); - g_return_if_fail (PSPPIRE_IS_VAR_STORE (store)); - - store->font_desc = fd; - - g_sheet_model_range_changed (G_SHEET_MODEL (store), -1, -1, -1, -1); -} - - static glong psppire_var_store_get_row_count (const GSheetModel * model) { diff --git a/src/ui/gui/psppire-var-store.h b/src/ui/gui/psppire-var-store.h index 72c9192c..160812ca 100644 --- a/src/ui/gui/psppire-var-store.h +++ b/src/ui/gui/psppire-var-store.h @@ -65,7 +65,6 @@ struct _PsppireVarStore /*< private >*/ PsppireDict *dict; GdkColor disabled; - const PangoFontDescription *font_desc; gint trailing_rows; PsppireVarStoreFormatType format_type; };