Commit 4cfea5d6 authored by Morten Welinder's avatar Morten Welinder Committed by Morten Welinder

Use wb_view_detach_from_workbook. (workbook_detach_view,

2006-11-13  Morten Welinder  <terra@gnome.org>

	* src/workbook.c (workbook_dispose): Use
	wb_view_detach_from_workbook.
	(workbook_detach_view, workbook_attach_view): Don't set wbv->wb
	here.  Set in caller.

	* src/workbook-view.c (workbook_view_class_init): Install new
	property: auto-expr-text.
	(wb_view_get_property, wb_view_set_property,
	wb_view_auto_expr_text): Handle auto-expr-text.
	(wb_view_detach_from_workbook): New function.
	(wb_view_finalize): Use wb_view_detach_from_workbook.

	* src/workbook-control-priv.h (WorkbookControlClass): Remove
	auto_expr_value member.

	* src/workbook-control-gui.c (wbcg_auto_expr_text_changed): New
	function hooked up to WorkbookView::auto-expr-text.
	(wbcg_auto_expr_value): Removed.
parent d532e209
2006-11-13 Morten Welinder <terra@gnome.org>
* src/workbook.c (workbook_dispose): Use
wb_view_detach_from_workbook.
(workbook_detach_view, workbook_attach_view): Don't set wbv->wb
here. Set in caller.
* src/workbook-view.c (workbook_view_class_init): Install new
property: auto-expr-text.
(wb_view_get_property, wb_view_set_property,
wb_view_auto_expr_text): Handle auto-expr-text.
(wb_view_detach_from_workbook): New function.
(wb_view_finalize): Use wb_view_detach_from_workbook.
* src/workbook-control-priv.h (WorkbookControlClass): Remove
auto_expr_value member.
* src/workbook-control-gui.c (wbcg_auto_expr_text_changed): New
function hooked up to WorkbookView::auto-expr-text.
(wbcg_auto_expr_value): Removed.
2006-11-12 Morten Welinder <terra@gnome.org>
* src/workbook-control-gui.c (cb_auto_expr_changed): Control
......
......@@ -44,6 +44,7 @@ Morten:
* Fix undo for sheet object copy. [#308300]
* Fix redo for sheet object copy. [#308300]
* Add a bugzilla component for bug-buddy. [#348829]
* Make WorkbookView is more proper gobject.
--------------------------------------------------------------------------
......
......@@ -3,7 +3,7 @@
PKG_NAME="Gnumeric"
REQUIRED_AUTOMAKE_VERSION=1.7.2
REQUIRED_AUTOMAKE_VERSION=1.9.0
REQUIRED_LIBTOOL_VERSION=1.4.3
# We use the XGETTEXT_KEYWORDS variable, thus we require:
......
......@@ -77,7 +77,9 @@ struct _WorkbookControlGUI {
GOFileSaver *current_saver;
gulong sig_view_changed, sig_sheet_order, sig_notify_uri, sig_notify_dirty;
gulong sig_view_changed;
gulong sig_auto_expr_text;
gulong sig_sheet_order, sig_notify_uri, sig_notify_dirty;
};
typedef struct {
......
......@@ -1085,21 +1085,12 @@ wbcg_sheet_remove_all (WorkbookControl *wbc)
}
static void
wbcg_auto_expr_value (WorkbookControl *wbc)
wbcg_auto_expr_text_changed (WorkbookView *wbv,
G_GNUC_UNUSED GParamSpec *pspec,
WorkbookControlGUI *wbcg)
{
WorkbookControlGUI *wbcg = WORKBOOK_CONTROL_GUI (wbc);
WorkbookView *wbv = wb_control_view (wbc);
g_return_if_fail (wbcg != NULL);
g_return_if_fail (wbv != NULL);
g_return_if_fail (wbv->auto_expr_value_as_string != NULL);
if (wbcg_ui_update_begin (wbcg)) {
gtk_label_set_text(
GTK_LABEL (wbcg->auto_expr_label),
wbv->auto_expr_value_as_string);
wbcg_ui_update_end (wbcg);
}
gtk_label_set_text (GTK_LABEL (wbcg->auto_expr_label),
wbv->auto_expr_text ? wbv->auto_expr_text : "");
}
static void
......@@ -2450,35 +2441,47 @@ wbcg_progress_message_set (GOCmdContext *cc, gchar const *msg)
gtk_progress_bar_set_text (GTK_PROGRESS_BAR (wbcg->progress_bar), msg);
}
#define DISCONNECT(field) \
if (wbcg->field) { \
g_signal_handler_disconnect (old_wb, wbcg->field); \
wbcg->field = 0; \
#define DISCONNECT(obj,field) \
if (wbcg->field) { \
g_signal_handler_disconnect (obj, wbcg->field); \
wbcg->field = 0; \
}
static void
wbcg_view_changed (WorkbookControlGUI *wbcg,
G_GNUC_UNUSED GParamSpec *pspec,
Workbook *old_wb)
WorkbookView *old_wbv)
{
WorkbookControl *wbc = WORKBOOK_CONTROL (wbcg);
Workbook *wb = wb_control_get_workbook (wbc);
Workbook *old_wb = old_wbv ? wb_view_get_workbook (old_wbv) : NULL;
WorkbookView *wbv = wb_control_view (wbc);
/* Reconnect self because we need to change data. */
if (wbcg->sig_view_changed)
g_signal_handler_disconnect (wbc, wbcg->sig_view_changed);
DISCONNECT (wbc, sig_view_changed);
wbcg->sig_view_changed =
g_signal_connect_object
(G_OBJECT (wbc),
"notify::view",
G_CALLBACK (wbcg_view_changed),
wb,
wbv,
0);
if (wbcg->sig_auto_expr_text)
DISCONNECT (old_wbv, sig_auto_expr_text);
wbcg->sig_auto_expr_text =
g_signal_connect_object
(G_OBJECT (wbv),
"notify::auto-expr-text",
G_CALLBACK (wbcg_auto_expr_text_changed),
wbcg,
0);
wbcg_auto_expr_text_changed (wbv, NULL, wbcg);
if (old_wb) {
DISCONNECT (sig_sheet_order);
DISCONNECT (sig_notify_uri);
DISCONNECT (sig_notify_dirty);
DISCONNECT (old_wb, sig_sheet_order);
DISCONNECT (old_wb, sig_notify_uri);
DISCONNECT (old_wb, sig_notify_dirty);
}
if (wb) {
......@@ -2700,7 +2703,6 @@ workbook_control_gui_class_init (GObjectClass *object_class)
wbc_class->edit_line_set = wbcg_edit_line_set;
wbc_class->selection_descr_set = wbcg_edit_selection_descr_set;
wbc_class->auto_expr_value = wbcg_auto_expr_value;
wbc_class->update_action_sensitivity = wbcg_update_action_sensitivity;
wbc_class->sheet.add = wbcg_sheet_add;
......
......@@ -29,7 +29,6 @@ typedef struct {
void (*edit_line_set) (WorkbookControl *wbc, char const *text);
void (*edit_finish) (WorkbookControl *wbc, gboolean accept);
void (*selection_descr_set) (WorkbookControl *wbc, char const *text);
void (*auto_expr_value) (WorkbookControl *wbc);
void (*update_action_sensitivity) (WorkbookControl *wbc);
struct {
void (*add) (WorkbookControl *wbc, SheetView *sv);
......
......@@ -75,7 +75,6 @@ WBC_VIRTUAL (edit_line_set,
(WorkbookControl *wbc, char const *text), (wbc, text))
WBC_VIRTUAL (selection_descr_set,
(WorkbookControl *wbc, char const *text), (wbc, text))
WBC_VIRTUAL (auto_expr_value, (WorkbookControl *wbc), (wbc))
WBC_VIRTUAL_FULL (sheet_remove, sheet.remove,
(WorkbookControl *wbc, Sheet *sheet), (wbc, sheet))
......@@ -123,7 +122,6 @@ wb_control_sheet_add (WorkbookControl *wbc, SheetView *sv)
wb_control_sheet_focus (wbc, new_sheet);
wb_view_selection_desc (wbv, TRUE, wbc);
wb_view_edit_line_set (wbv, wbc);
wb_control_auto_expr_value (wbc);
wb_control_style_feedback (wbc, NULL);
wb_control_menu_state_update (wbc, MS_ALL);
wb_control_update_action_sensitivity (wbc);
......
......@@ -23,7 +23,6 @@ WorkbookControl *wb_control_wrapper_new (WorkbookControl *wbc,
void wb_control_style_feedback (WorkbookControl *wbc, GnmStyle const *changes);
void wb_control_edit_line_set (WorkbookControl *wbc, char const *text);
void wb_control_selection_descr_set (WorkbookControl *wbc, char const *text);
void wb_control_auto_expr_value (WorkbookControl *wbc);
void wb_control_sheet_add (WorkbookControl *wbc, SheetView *sv);
void wb_control_sheet_remove (WorkbookControl *wbc, Sheet *sheet);
......
......@@ -67,7 +67,8 @@ enum {
PROP_0,
PROP_AUTO_EXPR_FUNC,
PROP_AUTO_EXPR_DESCR,
PROP_AUTO_EXPR_MAX_PRECISION
PROP_AUTO_EXPR_MAX_PRECISION,
PROP_AUTO_EXPR_TEXT
};
/* WorkbookView signals */
......@@ -398,13 +399,6 @@ wb_view_edit_line_set (WorkbookView *wbv, WorkbookControl *optional_wbc)
}
}
static void
wb_view_auto_expr_value_display (WorkbookView *wbv)
{
WORKBOOK_VIEW_FOREACH_CONTROL (wbv, control,
wb_control_auto_expr_value (control););
}
static void
accumulate_regions (SheetView *sv, GnmRange const *r, gpointer closure)
{
......@@ -451,8 +445,6 @@ wb_view_auto_expr_recalc (WorkbookView *wbv)
ei.func_call->argv,
0);
g_free (wbv->auto_expr_value_as_string);
if (v) {
GString *str = g_string_new (wbv->auto_expr_descr);
GOFormat const *format = NULL;
......@@ -480,14 +472,16 @@ wb_view_auto_expr_recalc (WorkbookView *wbv)
g_string_append (str, value_peek_string (v));
}
wbv->auto_expr_value_as_string = g_string_free (str, FALSE);
g_object_set (wbv, "auto-expr-text", str->str, NULL);
g_string_free (str, TRUE);
value_release (v);
} else
wbv->auto_expr_value_as_string = g_strdup (_("Internal ERROR"));
} else {
g_object_set (wbv, "auto-expr-text", "Internal ERROR", NULL);
}
if (expr)
gnm_expr_free (expr);
wb_view_auto_expr_value_display (wbv);
}
/* perform whatever initialization of a control that is necessary when it
......@@ -573,6 +567,19 @@ wb_view_auto_expr_precision (WorkbookView *wbv, gboolean use_max_precision)
wb_view_auto_expr_recalc (wbv);
}
static void
wb_view_auto_expr_text (WorkbookView *wbv, const char *text)
{
char *s;
if (go_str_compare (text, wbv->auto_expr_text) == 0)
return;
s = g_strdup (text);
g_free (wbv->auto_expr_text);
wbv->auto_expr_text = s;
}
static void
wb_view_set_property (GObject *object, guint property_id,
const GValue *value, GParamSpec *pspec)
......@@ -589,6 +596,9 @@ wb_view_set_property (GObject *object, guint property_id,
case PROP_AUTO_EXPR_MAX_PRECISION:
wb_view_auto_expr_precision (wbv, g_value_get_boolean (value));
break;
case PROP_AUTO_EXPR_TEXT:
wb_view_auto_expr_text (wbv, g_value_get_string (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
......@@ -611,12 +621,26 @@ wb_view_get_property (GObject *object, guint property_id,
case PROP_AUTO_EXPR_MAX_PRECISION:
g_value_set_boolean (value, wbv->auto_expr_use_max_precision);
break;
case PROP_AUTO_EXPR_TEXT:
g_value_set_string (value, wbv->auto_expr_text);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
void
wb_view_detach_from_workbook (WorkbookView *wbv)
{
g_return_if_fail (IS_WORKBOOK_VIEW (wbv));
if (wbv->wb) {
workbook_detach_view (wbv);
wbv->wb = NULL;
}
}
static void
wb_view_finalize (GObject *object)
{
......@@ -632,8 +656,7 @@ wb_view_finalize (GObject *object)
g_warning ("Unexpected left-over controls");
}
if (wbv->wb != NULL)
workbook_detach_view (wbv);
wb_view_detach_from_workbook (wbv);
if (wbv->auto_expr_func) {
gnm_func_unref (wbv->auto_expr_func);
......@@ -643,8 +666,8 @@ wb_view_finalize (GObject *object)
g_free (wbv->auto_expr_descr);
wbv->auto_expr_descr = NULL;
g_free (wbv->auto_expr_value_as_string);
wbv->auto_expr_value_as_string = NULL;
g_free (wbv->auto_expr_text);
wbv->auto_expr_text = NULL;
if (wbv->current_format != NULL) {
gnm_style_unref (wbv->current_format);
......@@ -690,6 +713,15 @@ workbook_view_class_init (GObjectClass *gobject_class)
FALSE,
GSF_PARAM_STATIC |
G_PARAM_READWRITE));
g_object_class_install_property
(gobject_class,
PROP_AUTO_EXPR_TEXT,
g_param_spec_string ("auto-expr-text",
_("Auto-expression text"),
_("Displayed text for the automatically computed sheet function."),
NULL,
GSF_PARAM_STATIC |
G_PARAM_READWRITE));
parent_class = g_type_class_peek_parent (gobject_class);
}
......@@ -708,7 +740,8 @@ workbook_view_new (Workbook *wb)
g_return_val_if_fail (wb != NULL, NULL);
workbook_attach_view (wb, wbv);
wbv->wb = wb;
workbook_attach_view (wbv);
wbv->show_horizontal_scrollbar = TRUE;
wbv->show_vertical_scrollbar = TRUE;
......@@ -725,7 +758,7 @@ workbook_view_new (Workbook *wb)
if (wbv->auto_expr_func)
gnm_func_ref (wbv->auto_expr_func);
wbv->auto_expr_descr = g_strdup (_("Sum"));
wbv->auto_expr_value_as_string = NULL;
wbv->auto_expr_text = NULL;
wbv->auto_expr_use_max_precision = FALSE;
for (i = 0 ; i < workbook_sheet_count (wb); i++)
......
......@@ -27,7 +27,7 @@ struct _WorkbookView {
/* The auto-expression */
GnmFunc *auto_expr_func;
char *auto_expr_descr;
char *auto_expr_value_as_string;
char *auto_expr_text;
gboolean auto_expr_use_max_precision;
/* selection */
......@@ -52,6 +52,7 @@ GType workbook_view_get_type (void);
WorkbookView *workbook_view_new (Workbook *optional_workbook);
void wb_view_attach_control (WorkbookView *wbv, WorkbookControl *wbc);
void wb_view_detach_control (WorkbookControl *wbc);
void wb_view_detach_from_workbook (WorkbookView *wbv);
/* Information */
GODoc *wb_view_get_doc (WorkbookView const *wbv);
......
......@@ -119,9 +119,9 @@ workbook_dispose (GObject *wb_object)
*/
/* Get rid of all the views */
if (wb->wb_views != NULL) {
WORKBOOK_FOREACH_VIEW (wb, view, {
workbook_detach_view (view);
g_object_unref (view);
WORKBOOK_FOREACH_VIEW (wb, wbv, {
wb_view_detach_from_workbook (wbv);
g_object_unref (wbv);
});
if (wb->wb_views != NULL)
g_warning ("Unexpected left over views");
......@@ -578,16 +578,18 @@ workbook_iteration_tolerance (Workbook *wb, double tolerance)
}
void
workbook_attach_view (Workbook *wb, WorkbookView *wbv)
workbook_attach_view (WorkbookView *wbv)
{
g_return_if_fail (IS_WORKBOOK (wb));
Workbook *wb;
g_return_if_fail (IS_WORKBOOK_VIEW (wbv));
g_return_if_fail (wb_view_get_workbook (wbv) == NULL);
wb = wb_view_get_workbook (wbv);
g_return_if_fail (IS_WORKBOOK (wb));
if (wb->wb_views == NULL)
wb->wb_views = g_ptr_array_new ();
g_ptr_array_add (wb->wb_views, wbv);
wbv->wb = wb;
}
void
......@@ -606,7 +608,6 @@ workbook_detach_view (WorkbookView *wbv)
g_ptr_array_free (wbv->wb->wb_views, TRUE);
wbv->wb->wb_views = NULL;
}
wbv->wb = NULL;
}
/*****************************************************************************/
......
......@@ -66,7 +66,7 @@ void workbook_iteration_tolerance (Workbook *wb, double tolerance);
GODateConventions const *workbook_date_conv (Workbook const *wb);
gboolean workbook_set_1904 (Workbook *wb, gboolean flag);
void workbook_attach_view (Workbook *wb, WorkbookView *wbv);
void workbook_attach_view (WorkbookView *wbv);
void workbook_detach_view (WorkbookView *wbv);
WorkbookSheetState *workbook_sheet_state_new (Workbook const *wb);
......
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