Commit 08fb3a7b authored by Morten Welinder's avatar Morten Welinder Committed by Morten Welinder

New function defining the type as a boxed type.

2005-05-02  Morten Welinder  <terra@gnome.org>

	* src/style-color.c (gnm_style_color_get_type): New function
	defining the type as a boxed type.

	* src/sheet.c: Add "name", "tab-foreground", and "tab-background"
	properties.
	(sheet_set_tab_color): Remove.  All callers changed to use
	g_object_set.
	(sheet_rename): Make static.  All callers changed to use
	g_object_set.
parent fd71504f
2005-05-02 Morten Welinder <terra@gnome.org>
* src/style-color.c (gnm_style_color_get_type): New function
defining the type as a boxed type.
* src/sheet.c: Add "name", "tab-foreground", and "tab-background"
properties.
(sheet_set_tab_color): Remove. All callers changed to use
g_object_set.
(sheet_rename): Make static. All callers changed to use
g_object_set.
2005-04-21 Jon K Hellan <hellan@acm.org>
* src/sheet-object.[ch]: Add sheet_object_get_target_list.
......
2005-05-02 Morten Welinder <terra@gnome.org>
* src/style-color.c (gnm_style_color_get_type): New function
defining the type as a boxed type.
* src/sheet.c: Add "name", "tab-foreground", and "tab-background"
properties.
(sheet_set_tab_color): Remove. All callers changed to use
g_object_set.
(sheet_rename): Make static. All callers changed to use
g_object_set.
2005-04-21 Jon K Hellan <hellan@acm.org>
* src/sheet-object.[ch]: Add sheet_object_get_target_list.
......
......@@ -3459,12 +3459,17 @@ excel_read_TAB_COLOR (BiffQuery *q, ExcelReadSheet *esheet)
text_color = style_color_black ();
else
text_color = style_color_white ();
sheet_set_tab_color (esheet->sheet, color, text_color);
g_object_set (esheet->sheet,
"tab-foreground", text_color,
"tab-background", color,
NULL);
if (color != NULL) {
d (1, fprintf (stderr,"%s tab colour = %04hx:%04hx:%04hx\n",
esheet->sheet->name_unquoted,
color->gdk_color.red, color->gdk_color.green, color->gdk_color.blue););
}
style_color_unref (text_color);
style_color_unref (color);
}
static void
......
......@@ -1550,7 +1550,7 @@ py_sheet_rename_method (py_Sheet_object *self, PyObject *args)
return NULL;
}
sheet_rename (self->sheet, new_name);
g_object_set (self->sheet, "name", new_name, NULL);
Py_INCREF (Py_None);
return Py_None;
......@@ -1699,7 +1699,7 @@ py_Workbook_sheet_add (py_Workbook_object *self, PyObject *args)
sheet = workbook_sheet_by_index (self->wb, insert_before);
sheet = workbook_sheet_add (self->wb, sheet, TRUE);
if (sheet != NULL && name != NULL)
sheet_rename (sheet, name);
g_object_set (sheet, "name", name, NULL);
return py_new_Sheet_object (sheet);
}
......
......@@ -731,8 +731,8 @@ qpro_read_sheet (QProReadState *state)
g_convert_with_iconv (data, -1,
state->converter,
NULL, NULL, NULL);
#warning this is wrong, but the workbook interface is confused and needs a control.
sheet_rename (sheet, utf8name);
#warning "This is wrong, but the workbook interface is confused and needs a control."
g_object_set (sheet, "name", utf8name, NULL);
g_free (utf8name);
}
break;
......@@ -761,9 +761,14 @@ qpro_read_sheet (QProReadState *state)
break;
case QPRO_PAGE_TAB_COLOR :
if (validate (QPRO_PAGE_TAB_COLOR, 4))
sheet_set_tab_color (sheet, style_color_new_i8 (
data[0], data[1], data[2]), NULL);
if (validate (QPRO_PAGE_TAB_COLOR, 4)) {
GnmColor *bc = style_color_new_i8 (
data[0], data[1], data[2]);
g_object_set (sheet,
"tab-background", bc,
NULL);
style_color_unref (bc);
}
break;
case QPRO_PAGE_ZOOM_FACTOR :
......
......@@ -82,6 +82,7 @@ typedef Sheet GnmSheet;
enum {
PROP_0,
PROP_NAME,
PROP_RTL,
PROP_VISIBLE,
PROP_PROTECTED,
......@@ -90,7 +91,9 @@ enum {
PROP_DISPLAY_GRID,
PROP_DISPLAY_COLUMN_HEADER,
PROP_DISPLAY_ROW_HEADER,
PROP_DISPLAY_OUTLINES
PROP_DISPLAY_OUTLINES,
PROP_TAB_FOREGROUND,
PROP_TAB_BACKGROUND
};
static void sheet_finalize (GObject *obj);
......@@ -223,6 +226,60 @@ sheet_set_display_outlines (Sheet *sheet, gboolean display)
sheet_adjust_preferences (sheet, TRUE, TRUE);
}
static void
sheet_set_name (Sheet *sheet, char const *new_name)
{
Workbook *wb = sheet->workbook;
gboolean attached;
Sheet *sucker;
char *new_name_unquoted;
g_return_if_fail (new_name != NULL);
/* No change whatsoever. */
if (sheet->name_unquoted && strcmp (sheet->name_unquoted, new_name) == 0)
return;
/* Mark the sheet dirty unless this is the initial name. */
if (sheet->name_unquoted)
sheet_set_dirty (sheet, TRUE);
sucker = wb ? workbook_sheet_by_name (wb, new_name) : NULL;
if (sucker && sucker != sheet) {
/* Prevent a name clash. */
char *sucker_name = workbook_sheet_get_free_name (wb, new_name, TRUE, FALSE);
g_object_set (sucker, "name", sucker_name, NULL);
g_free (sucker_name);
}
attached = wb && sheet->name_case_insensitive;
/* FIXME: maybe have workbook_sheet_detach_internal for this. */
if (attached)
g_hash_table_remove (wb->sheet_hash_private,
sheet->name_case_insensitive);
/* Copy before free. */
new_name_unquoted = g_strdup (new_name);
g_free (sheet->name_unquoted);
g_free (sheet->name_quoted);
g_free (sheet->name_unquoted_collate_key);
g_free (sheet->name_case_insensitive);
sheet->name_unquoted = new_name_unquoted;
sheet->name_quoted = sheet_name_quote (new_name_unquoted);
sheet->name_unquoted_collate_key = g_utf8_collate_key (new_name_unquoted, -1);
sheet->name_case_insensitive = g_utf8_casefold (new_name_unquoted, -1);
/* FIXME: maybe have workbook_sheet_attach_internal for this. */
if (attached)
g_hash_table_insert (wb->sheet_hash_private,
sheet->name_case_insensitive,
sheet);
SHEET_FOREACH_VIEW (sheet, sv,
sv->edit_pos_changed.content = TRUE;);
}
static void
gnm_sheet_set_property (GObject *object, guint property_id,
const GValue *value, GParamSpec *pspec)
......@@ -230,6 +287,9 @@ gnm_sheet_set_property (GObject *object, guint property_id,
Sheet *sheet = (Sheet *)object;
switch (property_id) {
case PROP_NAME:
sheet_set_name (sheet, g_value_get_string (value));
break;
case PROP_RTL:
sheet_set_direction (sheet, g_value_get_boolean (value));
break;
......@@ -257,6 +317,28 @@ gnm_sheet_set_property (GObject *object, guint property_id,
case PROP_DISPLAY_OUTLINES:
sheet_set_display_outlines (sheet, g_value_get_boolean (value));
break;
case PROP_TAB_FOREGROUND: {
GnmColor *color = g_value_dup_boxed (value);
style_color_unref (sheet->tab_text_color);
sheet->tab_text_color = color;
/* FIXME: solve this with notification handler. */
WORKBOOK_FOREACH_CONTROL (sheet->workbook, view, control,
wb_control_sheet_rename (control,
sheet););
break;
}
case PROP_TAB_BACKGROUND: {
GnmColor *color = g_value_dup_boxed (value);
style_color_unref (sheet->tab_color);
sheet->tab_color = color;
/* FIXME: solve this with notification handler. */
WORKBOOK_FOREACH_CONTROL (sheet->workbook, view, control,
wb_control_sheet_rename (control,
sheet););
break;
}
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
......@@ -270,6 +352,9 @@ gnm_sheet_get_property (GObject *object, guint property_id,
Sheet *sheet = (Sheet *)object;
switch (property_id) {
case PROP_NAME:
g_value_set_string (value, sheet->name_unquoted);
break;
case PROP_RTL:
g_value_set_boolean (value, sheet->text_is_rtl);
break;
......@@ -297,6 +382,12 @@ gnm_sheet_get_property (GObject *object, guint property_id,
case PROP_DISPLAY_OUTLINES:
g_value_set_boolean (value, sheet->display_outlines);
break;
case PROP_TAB_FOREGROUND:
g_value_set_boxed (value, sheet->tab_text_color);
break;
case PROP_TAB_BACKGROUND:
g_value_set_boxed (value, sheet->tab_color);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
......@@ -387,6 +478,15 @@ gnm_sheet_class_init (GObjectClass *gobject_class)
gobject_class->get_property = gnm_sheet_get_property;
gobject_class->finalize = sheet_finalize;
g_object_class_install_property
(gobject_class,
PROP_NAME,
g_param_spec_string ("name",
_("Name"),
_("The name of the sheet."),
NULL,
GSF_PARAM_STATIC |
G_PARAM_READWRITE));
g_object_class_install_property
(gobject_class,
PROP_RTL,
......@@ -468,6 +568,24 @@ gnm_sheet_class_init (GObjectClass *gobject_class)
FALSE,
GSF_PARAM_STATIC |
G_PARAM_READWRITE));
g_object_class_install_property
(gobject_class,
PROP_TAB_FOREGROUND,
g_param_spec_boxed ("tab-foreground",
_("Tab Foreground"),
_("The foreground color of the tab."),
GNM_STYLE_COLOR_TYPE,
GSF_PARAM_STATIC |
G_PARAM_READWRITE));
g_object_class_install_property
(gobject_class,
PROP_TAB_BACKGROUND,
g_param_spec_boxed ("tab-background",
_("Tab Background"),
_("The background color of the tab."),
GNM_STYLE_COLOR_TYPE,
GSF_PARAM_STATIC |
G_PARAM_READWRITE));
signals[DETACHED_FROM_WORKBOOK] = g_signal_new
("detached_from_workbook",
......@@ -490,42 +608,6 @@ sheet_redraw_all (Sheet const *sheet, gboolean headers)
sc_redraw_all (control, headers););
}
void
sheet_rename (Sheet *sheet, char const *new_name)
{
Workbook *wb;
g_return_if_fail (IS_SHEET (sheet));
g_return_if_fail (new_name != NULL);
wb = sheet->workbook;
/* FIXME: maybe have workbook_sheet_detach_internal for this. */
if (wb)
g_hash_table_remove (wb->sheet_hash_private,
sheet->name_case_insensitive);
g_free (sheet->name_quoted);
g_free (sheet->name_unquoted);
g_free (sheet->name_unquoted_collate_key);
g_free (sheet->name_case_insensitive);
sheet->name_quoted = sheet_name_quote (new_name);
sheet->name_unquoted = g_strdup (new_name);
sheet->name_unquoted_collate_key =
g_utf8_collate_key (sheet->name_unquoted, -1);
sheet->name_case_insensitive =
g_utf8_casefold (sheet->name_unquoted, -1);
/* FIXME: maybe have workbook_sheet_attach_internal for this. */
if (wb)
g_hash_table_insert (wb->sheet_hash_private,
sheet->name_case_insensitive,
sheet);
SHEET_FOREACH_VIEW (sheet, sv,
sv->edit_pos_changed.content = TRUE;);
}
void
sheet_attach_view (Sheet *sheet, SheetView *sv)
{
......@@ -3118,15 +3200,10 @@ sheet_destroy (Sheet *sheet)
g_warning ("There is a problem with sheet objects");
}
if (sheet->tab_color != NULL) {
style_color_unref (sheet->tab_color);
sheet->tab_color = NULL;
}
if (sheet->tab_text_color != NULL) {
style_color_unref (sheet->tab_text_color);
sheet->tab_text_color = NULL;
}
style_color_unref (sheet->tab_color);
sheet->tab_color = NULL;
style_color_unref (sheet->tab_text_color);
sheet->tab_text_color = NULL;
/* Clear the cliboard to avoid dangling references to the deleted sheet */
if (sheet == gnm_app_clipboard_sheet_get ())
......@@ -4467,11 +4544,9 @@ sheet_set_tab_color (Sheet *sheet, GnmColor *tab_color, GnmColor *text_color)
{
g_return_if_fail (IS_SHEET (sheet));
if (sheet->tab_color != NULL)
style_color_unref (sheet->tab_color);
if (sheet->tab_text_color != NULL)
style_color_unref (sheet->tab_text_color);
style_color_unref (sheet->tab_color);
sheet->tab_color = tab_color;
style_color_unref (sheet->tab_text_color);
sheet->tab_text_color = text_color;
WORKBOOK_FOREACH_CONTROL (sheet->workbook, view, control,
......
......@@ -92,9 +92,6 @@ Sheet *sheet_new_with_type (Workbook *wb, char const *name,
Sheet *sheet_dup (Sheet const *source_sheet);
void sheet_destroy (Sheet *sheet);
void sheet_destroy_contents (Sheet *sheet);
void sheet_rename (Sheet *sheet, char const *new_name);
void sheet_set_tab_color (Sheet *sheet, GnmColor *tab_color,
GnmColor *text_color);
void sheet_set_zoom_factor (Sheet *sheet, double factor,
gboolean force, gboolean respan);
......
......@@ -295,3 +295,16 @@ gnumeric_color_shutdown (void)
g_hash_table_destroy (style_color_hash);
style_color_hash = NULL;
}
GType
gnm_style_color_get_type (void)
{
static GType our_type = 0;
if (our_type == 0)
our_type = g_boxed_type_register_static
("GnmStyleColor",
(GBoxedCopyFunc)style_color_ref,
(GBoxedFreeFunc)style_color_unref);
return our_type;
}
......@@ -5,6 +5,9 @@
#include <goffice/utils/go-color.h>
#include <gdk/gdkcolor.h>
#define GNM_STYLE_COLOR_TYPE (gnm_style_color_get_type ())
GType gnm_style_color_get_type (void);
struct _GnmColor {
GdkColor gdk_color, gdk_selected_color;
GOColor go_color;
......@@ -25,8 +28,8 @@ GnmColor *style_color_auto_font (void);
GnmColor *style_color_auto_back (void);
GnmColor *style_color_auto_pattern (void);
GnmColor *style_color_ref (GnmColor *sc);
void style_color_unref (GnmColor *sc);
gint style_color_equal (const GnmColor *k1, const GnmColor *k2);
void style_color_unref (GnmColor *sc);
gint style_color_equal (const GnmColor *k1, const GnmColor *k2);
GnmColor *style_color_black (void);
GnmColor *style_color_white (void);
GnmColor *style_color_grid (void);
......
......@@ -1385,11 +1385,7 @@ workbook_sheet_rename (Workbook *wb,
if (-1 != GPOINTER_TO_INT (sheet_index->data)) {
Sheet *sheet = workbook_sheet_by_index
(wb, GPOINTER_TO_INT (sheet_index->data));
sheet_rename (sheet, new_name->data);
g_hash_table_insert (wb->sheet_hash_private,
sheet->name_case_insensitive,
sheet);
sheet_set_dirty (sheet, TRUE);
g_object_set (sheet, "name", new_name->data, NULL);
WORKBOOK_FOREACH_CONTROL (wb, view, control,
wb_control_sheet_rename (control, sheet););
......@@ -1530,7 +1526,12 @@ workbook_sheet_recolor (Workbook *wb,
GnmColor *back_color = bc ?
style_color_new (bc->red, bc->green,
bc->blue) : NULL;
sheet_set_tab_color (sheet, back_color, fore_color);
g_object_set (sheet,
"tab-foreground", fore_color,
"tab-background", back_color,
NULL);
style_color_unref (fore_color);
style_color_unref (back_color);
}
sheets = sheets->next;
fore = fore->next;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment