/** * gnm_style_border_fetch : * * @line_type : dash style * @color : colour * @orientation : Not currently used. * * Fetches a GnmBorder from the cache, creating one if necessary. Absorbs * the colour reference. In the future we may have different dash styles for * the same pattern depending on whether this is a horizontal or vertical line. */ GnmBorder * gnm_style_border_fetch (GnmStyleBorderType line_type, GnmColor *color, GnmStyleBorderOrientation orientation) { GnmBorder *border; GnmBorder key; if (line_type < GNM_STYLE_BORDER_NONE || line_type > GNM_STYLE_BORDER_MAX) { g_warning ("Invalid border type: %d", line_type); line_type = GNM_STYLE_BORDER_NONE; } if (line_type == GNM_STYLE_BORDER_NONE) { if (color) style_color_unref (color); return gnm_style_border_ref (gnm_style_border_none ()); } g_return_val_if_fail (color != NULL, NULL); key.line_type = line_type; key.color = color; if (border_hash) { border = g_hash_table_lookup (border_hash, &key); if (border != NULL) { if (color) style_color_unref (color); return gnm_style_border_ref (border); } } else border_hash = g_hash_table_new (style_border_hash, style_border_equal); border = g_new0 (GnmBorder, 1); *border = key; g_hash_table_insert (border_hash, border, border); border->ref_count = 1; border->gc = NULL; border->gc_screen = NULL; border->width = gnm_style_border_get_width (line_type); if (border->line_type == GNM_STYLE_BORDER_DOUBLE) { border->begin_margin = 1; border->end_margin = 1; } else { border->begin_margin = (border->width) > 1 ? 1 : 0; border->end_margin = (border->width) > 2 ? 1 : 0; } return border; }
/** * gnm_style_border_none_set_color: * @color : * * This function updates the color of gnm_style_border_none when the wanted grid * color is known. gnm_style_border_none tells how to render the grid. Because * the grid color may be different for different sheets, the functions which * render the grid call this function first. The rule for selecting the * grid color, which is the same as in Excel, is: - if the auto pattern * color is default (which is black), the grid color is gray, as returned by * style_color_grid (). - otherwise, the auto pattern color is used for the * grid. * NOTE : Absorbs a reference to @color. */ void gnm_style_border_none_set_color (GnmColor *color) { GnmBorder *none = gnm_style_border_none (); GnmColor *nc; if (color == none->color) { style_color_unref (color); return; } nc = none->color; none->color = color; style_color_unref (nc); if (none->gc) { GdkColor c; gdk_gc_set_rgb_fg_color (none->gc, go_color_to_gdk (none->color->go_color, &c)); } }
static void cb_color_changed_back (G_GNUC_UNUSED GOComboColor *go_combo_color, GOColor color, G_GNUC_UNUSED gboolean custom, G_GNUC_UNUSED gboolean by_user, G_GNUC_UNUSED gboolean is_default, SheetManager *state) { GList *selected_rows, *l; GtkTreeSelection *selection = gtk_tree_view_get_selection (state->sheet_list); WorkbookSheetState *old_state; WorkbookControl *wbc = GNM_WBC (state->wbcg); Workbook *wb = wb_control_get_workbook (wbc); GdkRGBA gdk_color; GdkRGBA *p_gdk_color; GnmColor *gnm_color; g_return_if_fail (selection != NULL); selected_rows = gtk_tree_selection_get_selected_rows (selection, NULL); p_gdk_color = (color == 0) ? NULL : go_color_to_gdk_rgba (color, &gdk_color); gnm_color = (color == 0) ? NULL : gnm_color_new_gdk (&gdk_color); old_state = workbook_sheet_state_new (wb); for (l = selected_rows; l != NULL; l = l->next) { Sheet *this_sheet; GtkTreeIter sel_iter; GtkTreePath *path = l->data; gtk_tree_model_get_iter (GTK_TREE_MODEL (state->model), &sel_iter, path); gtk_tree_model_get (GTK_TREE_MODEL (state->model), &sel_iter, SHEET_POINTER, &this_sheet, -1); if (color_equal (p_gdk_color, this_sheet->tab_color)) continue; gtk_list_store_set (state->model, &sel_iter, BACKGROUND_COLOUR, p_gdk_color, -1); g_object_set (this_sheet, "tab-background", gnm_color, NULL); } style_color_unref (gnm_color); cmd_reorganize_sheets (wbc, old_state, NULL); update_undo (state, wbc); g_list_free_full (selected_rows, (GDestroyNotify) gtk_tree_path_free); }
void gnm_style_border_unref (GnmBorder *border) { if (border == NULL) return; g_return_if_fail (border->ref_count > 0); border->ref_count--; if (border->ref_count != 0) return; /* Just to be on the safe side. * We are allowed to deref the border_none, * but not to free it. */ g_return_if_fail (border != gnm_style_border_none ()); /* Remove here, before we mess with the hashed fields. */ g_hash_table_remove (border_hash, border); if (border->color) { style_color_unref (border->color); border->color = NULL; } if (border->gc) { g_object_unref (G_OBJECT (border->gc)); border->gc = NULL; } if (border->gc_screen) { g_object_unref (G_OBJECT (border->gc_screen)); border->gc_screen = NULL; } g_free (border); }
void gnm_color_shutdown (void) { if (sc_black) { style_color_unref (sc_black); sc_black = NULL; } if (sc_white) { style_color_unref (sc_white); sc_white = NULL; } if (sc_grid) { style_color_unref (sc_grid); sc_grid = NULL; } if (sc_auto_back) { style_color_unref (sc_auto_back); sc_auto_back = NULL; } if (sc_auto_font) { style_color_unref (sc_auto_font); sc_auto_font = NULL; } if (sc_auto_pattern) { style_color_unref (sc_auto_pattern); sc_auto_pattern = NULL; } g_hash_table_foreach (style_color_hash, cb_color_leak, NULL); g_hash_table_destroy (style_color_hash); style_color_hash = NULL; }