workbook-control-gui.c 118 KB
Newer Older
1
2
/* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */

3
4
5
/*
 * workbook-control-gui.c: GUI specific routines for a workbook-control.
 *
Jody Goldberg's avatar
Jody Goldberg committed
6
 * Copyright (C) 2000 Jody Goldberg (jody@gnome.org)
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA
 */
#include <config.h>
#include "workbook-control-gui-priv.h"
#include "application.h"
#include "workbook-object-toolbar.h"
#include "workbook-format-toolbar.h"
#include "workbook-view.h"
#include "workbook-edit.h"
#include "workbook.h"
#include "sheet.h"
32
#include "sheet-private.h"
33
#include "sheet-control-gui-priv.h"
34
#include "gnumeric-canvas.h"
Jody Goldberg's avatar
Jody Goldberg committed
35
#include "sheet-object.h"
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "dialogs.h"
#include "commands.h"
#include "cmd-edit.h"
#include "workbook-cmd-format.h"
#include "selection.h"
#include "clipboard.h"
#include "print.h"
#include "gui-clipboard.h"
#include "workbook-edit.h"
#include "main.h"
#include "eval.h"
#include "position.h"
#include "parse-util.h"
#include "ranges.h"
Morten Welinder's avatar
Morten Welinder committed
50
#include "value.h"
Jody Goldberg's avatar
Jody Goldberg committed
51
52
#include "history.h"
#include "str.h"
Jody Goldberg's avatar
Jody Goldberg committed
53
#include "cell.h"
54
#include "gui-file.h"
55
#include "search.h"
56
#include "error-info.h"
Jody Goldberg's avatar
fix.    
Jody Goldberg committed
57
#include "pixmaps/equal-sign.xpm"
58
#include "gui-util.h"
Jody Goldberg's avatar
fix.    
Jody Goldberg committed
59
60
#include "widgets/gnumeric-toolbar.h"
#include "widgets/widget-editable-label.h"
61
#include "widgets/gnumeric-combo-text.h"
62

Jody Goldberg's avatar
update    
Jody Goldberg committed
63
64
#ifdef ENABLE_BONOBO
#include "sheet-object-container.h"
65
#ifdef ENABLE_EVOLUTION
Jody Goldberg's avatar
Jody Goldberg committed
66
#include <idl/Evolution-Composer.h>
67
68
#include <bonobo/bonobo-stream-memory.h>
#endif
Jody Goldberg's avatar
update    
Jody Goldberg committed
69
#endif
70

71
#include <gal/util/e-util.h>
Jody Goldberg's avatar
fix.    
Jody Goldberg committed
72
#include <gal/widgets/widget-color-combo.h>
73
#include <gal/widgets/gtk-combo-stack.h>
Jody Goldberg's avatar
fix.    
Jody Goldberg committed
74
75
76
77
78

#include <libgnome/gnome-defs.h>
#include <libgnome/gnome-i18n.h>
#include <libgnome/gnome-config.h>

79
#include <ctype.h>
80
#include <stdarg.h>
81
#include <stdio.h>
82
#include <errno.h>
83

84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
gboolean
wbcg_ui_update_begin (WorkbookControlGUI *wbcg)
{
	g_return_val_if_fail (IS_WORKBOOK_CONTROL_GUI (wbcg), FALSE);
	g_return_val_if_fail (!wbcg->updating_ui, FALSE);

	return (wbcg->updating_ui = TRUE);
}

void
wbcg_ui_update_end (WorkbookControlGUI *wbcg)
{
	g_return_if_fail (IS_WORKBOOK_CONTROL_GUI (wbcg));
	g_return_if_fail (wbcg->updating_ui);

	wbcg->updating_ui = FALSE;
}

102
103
104
105
106
107
108
109
110
111
112
static int
sheet_to_page_index (WorkbookControlGUI *wbcg, Sheet *sheet, SheetControlGUI **res)
{
	int i = 0;
	GtkWidget *w;

	if (res)
		*res = NULL;
	g_return_val_if_fail (IS_SHEET (sheet), -1);

	for ( ; NULL != (w = gtk_notebook_get_nth_page (wbcg->notebook, i)) ; i++) {
113
114
115
		GtkObject *obj = gtk_object_get_data (GTK_OBJECT (w),
						      SHEET_CONTROL_KEY);
		SheetControlGUI *scg = SHEET_CONTROL_GUI (obj);
116
		SheetControl *sc = (SheetControl *) scg;
Morten Welinder's avatar
Morten Welinder committed
117

118
		if (scg != NULL && sc->sheet == sheet) {
119
			if (res)
120
				*res = scg;
121
122
123
124
125
126
			return i;
		}
	}
	return -1;
}

Jody Goldberg's avatar
Jody Goldberg committed
127
128
129
GtkWindow *
wb_control_gui_toplevel (WorkbookControlGUI *wbcg)
{
130
131
	g_return_val_if_fail (IS_WORKBOOK_CONTROL_GUI (wbcg), NULL);

Jody Goldberg's avatar
be safe    
Jody Goldberg committed
132
	return wbcg->toplevel;
Jody Goldberg's avatar
Jody Goldberg committed
133
134
}

135
136
137
138
139
140
141
142
143
144
/**
 * wb_control_gui_focus_cur_sheet :
 * @wbcg : The workbook control to operate on.
 *
 * A utility routine to safely ensure that the keyboard focus
 * is attached to the item-grid.  This is required when a user
 * edits a combo-box or and entry-line which grab focus.
 *
 * It is called for zoom, font name/size, and accept/cancel for the editline.
 */
Jody Goldberg's avatar
Jody Goldberg committed
145
146
147
Sheet *
wb_control_gui_focus_cur_sheet (WorkbookControlGUI *wbcg)
{
Jody Goldberg's avatar
Jody Goldberg committed
148
	GtkWidget *table;
149
	GtkObject *obj;
150
	SheetControlGUI *scg;
Jody Goldberg's avatar
Jody Goldberg committed
151

152
	g_return_val_if_fail (IS_WORKBOOK_CONTROL_GUI (wbcg), NULL);
Jody Goldberg's avatar
Jody Goldberg committed
153

Jody Goldberg's avatar
Jody Goldberg committed
154
155
156
	table = gtk_notebook_get_nth_page (wbcg->notebook,
		gtk_notebook_get_current_page (wbcg->notebook));
	obj = gtk_object_get_data (GTK_OBJECT (table), SHEET_CONTROL_KEY);
157
	scg = SHEET_CONTROL_GUI (obj);
158
159
160

	g_return_val_if_fail (scg != NULL, NULL);

161
	scg_take_focus (scg);
162

163
	return ((SheetControl *) scg)->sheet;
164
}
Jody Goldberg's avatar
Jody Goldberg committed
165

166
167
168
169
SheetControlGUI *
wb_control_gui_cur_sheet (WorkbookControlGUI *wbcg)
{
	SheetControlGUI *scg;
Jody Goldberg's avatar
Jody Goldberg committed
170

171
172
	sheet_to_page_index (wbcg,
		wb_control_cur_sheet (WORKBOOK_CONTROL (wbcg)), &scg);
Jody Goldberg's avatar
Jody Goldberg committed
173

174
	return scg;
Jody Goldberg's avatar
Jody Goldberg committed
175
176
}

177
178
179
180
181
182
183
184
/****************************************************************************/
/* Autosave */
static gboolean
cb_autosave (gpointer *data)
{
	WorkbookView *wb_view;
        WorkbookControlGUI *wbcg = (WorkbookControlGUI *)data;

185
	g_return_val_if_fail (IS_WORKBOOK_CONTROL_GUI (wbcg), FALSE);
186
187
188
189
190
191
192
193
194

	wb_view = wb_control_view (WORKBOOK_CONTROL (wbcg));

	if (wb_view == NULL)
		return FALSE;

	if (wbcg->autosave && workbook_is_dirty (wb_view_workbook (wb_view))) {
	        if (wbcg->autosave_prompt && !dialog_autosave_prompt (wbcg))
			return TRUE;
195
		gui_file_save (wbcg, wb_view);
196
197
198
199
	}
	return TRUE;
}

200
201
202
203
204
205
206
207
208
209
210
211
212
/**
 * wbcg_rangesel_possible
 * @wbcg : the workbook control gui
 *
 * Returns true if the cursor keys should be used to select
 * a cell range (if the cursor is in a spot in the expression
 * where it makes sense to have a cell reference), false if not.
 */
gboolean
wbcg_rangesel_possible (WorkbookControlGUI const *wbcg)
{
	g_return_val_if_fail (IS_WORKBOOK_CONTROL_GUI (wbcg), FALSE);

213
214
	/* Already range selecting */
	if (wbcg->rangesel != NULL)
215
216
		return TRUE;

217
	/* Rangesel requires that we be editing somthing */
218
	if (!wbcg_is_editing (wbcg) && !wbcg_edit_entry_redirect_p (wbcg))
219
220
		return FALSE;

221
	return gnumeric_expr_entry_rangesel_meaningful (wbcg_get_entry_logical (wbcg));
222
223
}

Jody Goldberg's avatar
Jody Goldberg committed
224
gboolean
225
wbcg_is_editing (WorkbookControlGUI const *wbcg)
Jody Goldberg's avatar
Jody Goldberg committed
226
227
228
229
230
{
	g_return_val_if_fail (IS_WORKBOOK_CONTROL_GUI (wbcg), FALSE);
	return wbcg->editing;
}

231
void
232
wbcg_autosave_cancel (WorkbookControlGUI *wbcg)
233
{
Jody Goldberg's avatar
Jody Goldberg committed
234
235
	g_return_if_fail (IS_WORKBOOK_CONTROL_GUI (wbcg));

236
237
238
239
240
241
242
	if (wbcg->autosave_timer != 0) {
		gtk_timeout_remove (wbcg->autosave_timer);
		wbcg->autosave_timer = 0;
	}
}

void
243
wbcg_autosave_set (WorkbookControlGUI *wbcg, int minutes, gboolean prompt)
244
{
Jody Goldberg's avatar
Jody Goldberg committed
245
246
	g_return_if_fail (IS_WORKBOOK_CONTROL_GUI (wbcg));

247
	wbcg_autosave_cancel (wbcg);
248
249
250
251
252
253
254
255
256
257
258

	wbcg->autosave = (minutes != 0);
	wbcg->autosave_minutes = minutes;
	wbcg->autosave_prompt = prompt;

	if (wbcg->autosave)
		wbcg->autosave_timer = gtk_timeout_add (minutes * 60000,
			(GtkFunction) cb_autosave, wbcg);
}
/****************************************************************************/

Jody Goldberg's avatar
Jody Goldberg committed
259
260
261
262
263
264
static WorkbookControl *
wbcg_control_new (WorkbookControl *wbc, WorkbookView *wbv, Workbook *wb)
{
	return workbook_control_gui_new (wbv, wb);
}

Jody Goldberg's avatar
Jody Goldberg committed
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
static void
wbcg_init_state (WorkbookControl *wbc)
{
	WorkbookView	   *wbv = wb_control_view (wbc);
	WorkbookControlGUI *wbcg = WORKBOOK_CONTROL_GUI (wbc);
	ColorCombo *combo;

	/* Associate the combos with the view */
	combo = COLOR_COMBO (wbcg->back_color);
	color_palette_set_group (combo->palette,
		color_group_fetch ("back_color_group", wbv));
	combo = COLOR_COMBO (wbcg->fore_color);
	color_palette_set_group (combo->palette,
		color_group_fetch ("fore_color_group", wbv));
}

281
282
283
284
285
286
287
288
289
290
291
static void
wbcg_title_set (WorkbookControl *wbc, char const *title)
{
	WorkbookControlGUI *wbcg = (WorkbookControlGUI *)wbc;
	char *full_title;

	g_return_if_fail (wbcg != NULL);
	g_return_if_fail (title != NULL);

	full_title = g_strconcat (title, _(" : Gnumeric"), NULL);

Jody Goldberg's avatar
Jody Goldberg committed
292
 	gtk_window_set_title (wb_control_gui_toplevel (wbcg), full_title);
293
294
295
296
297
298
299
	g_free (full_title);
}

static void
cb_prefs_update (gpointer key, gpointer value, gpointer user_data)
{
	Sheet *sheet = value;
300
	sheet_adjust_preferences (sheet, FALSE, FALSE);
301
302
303
304
305
306
307
}

static void
wbcg_prefs_update (WorkbookControl *wbc)
{
	WorkbookControlGUI *wbcg = (WorkbookControlGUI *)wbc;
	Workbook	*wb  = wb_control_workbook (wbc);
Jody Goldberg's avatar
Jody Goldberg committed
308
	WorkbookView	*wbv = wb_control_view (wbc);
309
310

	g_hash_table_foreach (wb->sheet_hash_private, cb_prefs_update, NULL);
Jody Goldberg's avatar
be safe    
Jody Goldberg committed
311
	gtk_notebook_set_show_tabs (wbcg->notebook,
312
313
314
315
				    wbv->show_notebook_tabs);
}

static void
Jody Goldberg's avatar
Jody Goldberg committed
316
wbcg_format_feedback (WorkbookControl *wbc)
317
{
Jody Goldberg's avatar
Jody Goldberg committed
318
	workbook_feedback_set ((WorkbookControlGUI *)wbc);
319
320
321
}

static void
Jody Goldberg's avatar
Jody Goldberg committed
322
zoom_changed (WorkbookControlGUI *wbcg, Sheet* sheet)
323
324
325
{
	gchar buffer [25];

Jody Goldberg's avatar
delete.    
Jody Goldberg committed
326
	g_return_if_fail (IS_SHEET (sheet));
327
328
329
	g_return_if_fail (wbcg->zoom_entry != NULL);

	snprintf (buffer, sizeof (buffer), "%d%%",
330
		  (int) (sheet->last_zoom_factor_used * 100 + .5));
Jody Goldberg's avatar
delete.    
Jody Goldberg committed
331

332
	if (wbcg_ui_update_begin (wbcg)) {
333
334
		gnm_combo_text_set_text (GNM_COMBO_TEXT (wbcg->zoom_entry),
			buffer, GNM_COMBO_TEXT_CURRENT);
335
336
		wbcg_ui_update_end (wbcg);
	}
Jody Goldberg's avatar
delete.    
Jody Goldberg committed
337
338

	scg_object_update_bbox (wb_control_gui_cur_sheet (wbcg),
339
				NULL, NULL);
340
341
342
343
344
345
346
}

static void
wbcg_zoom_feedback (WorkbookControl *wbc)
{
	WorkbookControlGUI *wbcg = (WorkbookControlGUI *)wbc;
	Sheet *sheet = wb_control_cur_sheet (wbc);
Jody Goldberg's avatar
Jody Goldberg committed
347
	zoom_changed (wbcg, sheet);
348
349
350
351
352
}

static void
wbcg_edit_line_set (WorkbookControl *wbc, char const *text)
{
353
354
	GtkEntry *entry;

355
	entry = GTK_ENTRY (wbcg_get_entry ((WorkbookControlGUI*)wbc));
356
357
358
	gtk_entry_set_text (entry, text);
}

Jody Goldberg's avatar
Jody Goldberg committed
359
360
361
362
363
364
365
static void
wbcg_edit_selection_descr_set (WorkbookControl *wbc, char const *text)
{
	WorkbookControlGUI *wbcg = (WorkbookControlGUI *)wbc;
	gtk_entry_set_text (GTK_ENTRY (wbcg->selection_descriptor), text);
}

Jody Goldberg's avatar
be safe    
Jody Goldberg committed
366
367
368
369
370
371
372
373
374
375
376
377
378
/*
 * Signal handler for EditableLabel's text_changed signal.
 */
static gboolean
cb_sheet_label_changed (EditableLabel *el,
			const char *new_name, WorkbookControlGUI *wbcg)
{
	gboolean ans = !cmd_rename_sheet (WORKBOOK_CONTROL (wbcg),
					  el->text, new_name);
	wb_control_gui_focus_cur_sheet (wbcg);
	return ans;
}

Jody Goldberg's avatar
Jody Goldberg committed
379
380
381
382
383
384
static void
cb_sheet_label_edit_stopped (EditableLabel *el, WorkbookControlGUI *wbcg)
{
	wb_control_gui_focus_cur_sheet (wbcg);
}

Jody Goldberg's avatar
be safe    
Jody Goldberg committed
385
static void
386
sheet_action_add_sheet (GtkWidget *widget, SheetControlGUI *scg)
Jody Goldberg's avatar
be safe    
Jody Goldberg committed
387
{
388
389
390
	SheetControl *sc = (SheetControl *) scg;

	workbook_sheet_add (wb_control_workbook (sc->wbc), sc->sheet, TRUE);
391
	wb_control_gui_focus_cur_sheet (scg->wbcg);
Jody Goldberg's avatar
be safe    
Jody Goldberg committed
392
}
Jody Goldberg's avatar
Jody Goldberg committed
393

Jody Goldberg's avatar
be safe    
Jody Goldberg committed
394
static void
395
delete_sheet_if_possible (GtkWidget *ignored, SheetControlGUI *scg)
Jody Goldberg's avatar
be safe    
Jody Goldberg committed
396
{
397
398
	SheetControl *sc = (SheetControl *) scg;
	Workbook *wb = wb_control_workbook (sc->wbc);
Jody Goldberg's avatar
be safe    
Jody Goldberg committed
399
400
401
402
403
404
405
406
407
408
409
410
	GtkWidget *d, *button_no;
	char *message;
	int r;

	/*
	 * If this is the last sheet left, ignore the request
	 */
	if (workbook_sheet_count (wb) == 1)
		return;

	message = g_strdup_printf (
		_("Are you sure you want to remove the sheet called `%s'?"),
411
		sc->sheet->name_unquoted);
Jody Goldberg's avatar
be safe    
Jody Goldberg committed
412
413
414
415
416
417
418
419
420
421

	d = gnome_message_box_new (
		message, GNOME_MESSAGE_BOX_QUESTION,
		GNOME_STOCK_BUTTON_YES,
		GNOME_STOCK_BUTTON_NO,
		NULL);
	g_free (message);
	button_no = g_list_last (GNOME_DIALOG (d)->buttons)->data;
	gtk_widget_grab_focus (button_no);

422
	r = gnumeric_dialog_run (scg->wbcg, GNOME_DIALOG (d));
Jody Goldberg's avatar
be safe    
Jody Goldberg committed
423
424
425
426

	if (r != 0)
		return;

427
	workbook_sheet_delete (sc->sheet);
Jody Goldberg's avatar
be safe    
Jody Goldberg committed
428
429
430
	workbook_recalc_all (wb);
}

Jody Goldberg's avatar
update    
Jody Goldberg committed
431
static void
432
sheet_action_rename_sheet (GtkWidget *widget, SheetControlGUI *scg)
Jody Goldberg's avatar
update    
Jody Goldberg committed
433
{
434
435
	SheetControl *sc = (SheetControl *) scg;
	Sheet *sheet = sc->sheet;
436
	char *new_name = dialog_get_sheet_name (scg->wbcg, sheet->name_unquoted);
Jody Goldberg's avatar
update    
Jody Goldberg committed
437
438
439
440
	if (!new_name)
		return;

	/* We do not care if it fails */
441
	cmd_rename_sheet (sc->wbc, sheet->name_unquoted, new_name);
Jody Goldberg's avatar
update    
Jody Goldberg committed
442
443
444
445
	g_free (new_name);
}

static void
446
sheet_action_clone_sheet (GtkWidget *widget, SheetControlGUI *scg)
Jody Goldberg's avatar
update    
Jody Goldberg committed
447
{
448
449
	SheetControl *sc = (SheetControl *) scg;
     	Sheet *new_sheet = sheet_duplicate (sc->sheet);
Morten Welinder's avatar
Morten Welinder committed
450

451
	workbook_sheet_attach (sc->sheet->workbook, new_sheet, sc->sheet);
Jody Goldberg's avatar
update    
Jody Goldberg committed
452
	sheet_set_dirty (new_sheet, TRUE);
453
	wb_control_gui_focus_cur_sheet (scg->wbcg);
Jody Goldberg's avatar
update    
Jody Goldberg committed
454
455
456
}

static void
457
sheet_action_reorder_sheet (GtkWidget *widget, SheetControlGUI *scg)
Jody Goldberg's avatar
update    
Jody Goldberg committed
458
{
459
	dialog_sheet_order (scg->wbcg);
Jody Goldberg's avatar
update    
Jody Goldberg committed
460
461
}

Jody Goldberg's avatar
be safe    
Jody Goldberg committed
462
463
464
465
/**
 * sheet_menu_label_run:
 */
static void
466
sheet_menu_label_run (SheetControlGUI *scg, GdkEventButton *event)
Jody Goldberg's avatar
be safe    
Jody Goldberg committed
467
468
{
#define SHEET_CONTEXT_TEST_SIZE 1
469
	SheetControl *sc = (SheetControl *) scg;
Morten Welinder's avatar
Morten Welinder committed
470

Jody Goldberg's avatar
be safe    
Jody Goldberg committed
471
472
	struct {
		const char *text;
473
		void (*function) (GtkWidget *widget, SheetControlGUI *scg);
Jody Goldberg's avatar
be safe    
Jody Goldberg committed
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
		int  flags;
	} const sheet_label_context_actions [] = {
		{ N_("Add another sheet"), &sheet_action_add_sheet, 0 },
		{ N_("Remove this sheet"), &delete_sheet_if_possible, SHEET_CONTEXT_TEST_SIZE },
		{ N_("Rename this sheet"), &sheet_action_rename_sheet, 0 },
		{ N_("Duplicate this sheet"), &sheet_action_clone_sheet, 0 },
		{ N_("Re-order sheets"), &sheet_action_reorder_sheet, SHEET_CONTEXT_TEST_SIZE },
		{ NULL, NULL }
	};

	GtkWidget *menu;
	GtkWidget *item;
	int i;

	menu = gtk_menu_new ();

	for (i = 0; sheet_label_context_actions [i].text != NULL; i++){
		int flags = sheet_label_context_actions [i].flags;

Jody Goldberg's avatar
update    
Jody Goldberg committed
493
		if (flags & SHEET_CONTEXT_TEST_SIZE &&
494
		    workbook_sheet_count (sc->sheet->workbook) < 2)
Jody Goldberg's avatar
be safe    
Jody Goldberg committed
495
				continue;
Jody Goldberg's avatar
update    
Jody Goldberg committed
496

Jody Goldberg's avatar
be safe    
Jody Goldberg committed
497
498
499
500
501
502
503
504
		item = gtk_menu_item_new_with_label (
			_(sheet_label_context_actions [i].text));
		gtk_menu_append (GTK_MENU (menu), item);
		gtk_widget_show (item);

		gtk_signal_connect (
			GTK_OBJECT (item), "activate",
			GTK_SIGNAL_FUNC (sheet_label_context_actions [i].function),
505
			scg);
Jody Goldberg's avatar
be safe    
Jody Goldberg committed
506
507
508
509
510
511
512
513
514
515
516
	}

	gnumeric_popup_menu (GTK_MENU (menu), event);
}

/**
 * cb_sheet_label_button_press:
 *
 * Invoked when the user has clicked on the EditableLabel widget.
 * This takes care of switching to the notebook that contains the label
 */
Jody Goldberg's avatar
Jody Goldberg committed
517
static gboolean
Jody Goldberg's avatar
update    
Jody Goldberg committed
518
519
cb_sheet_label_button_press (GtkWidget *widget, GdkEventButton *event,
			     GtkWidget *child)
Jody Goldberg's avatar
be safe    
Jody Goldberg committed
520
521
522
{
	GtkWidget *notebook;
	gint page_number;
523
524
525
526
527
	GtkObject *obj = gtk_object_get_data (GTK_OBJECT (child),
					      SHEET_CONTROL_KEY);
	SheetControlGUI *scg = SHEET_CONTROL_GUI (obj);

	g_return_val_if_fail (scg != NULL, FALSE);
Jody Goldberg's avatar
be safe    
Jody Goldberg committed
528
529
530
531
532
533
534

	if (event->type != GDK_BUTTON_PRESS)
		return FALSE;

	notebook = child->parent;
	page_number = gtk_notebook_page_num (GTK_NOTEBOOK (notebook), child);

535
	if (event->button == 1 || NULL != scg->wbcg->rangesel) {
Jody Goldberg's avatar
be safe    
Jody Goldberg committed
536
537
538
539
540
		gtk_notebook_set_page (GTK_NOTEBOOK (notebook), page_number);
		return TRUE;
	}

	if (event->button == 3) {
541
542
543

		sheet_menu_label_run (SHEET_CONTROL_GUI (obj), event);
		scg_take_focus (SHEET_CONTROL_GUI (obj));
Jody Goldberg's avatar
be safe    
Jody Goldberg committed
544
545
546
547
548
549
		return TRUE;
	}

	return FALSE;
}

Jody Goldberg's avatar
update    
Jody Goldberg committed
550
static void workbook_setup_sheets (WorkbookControlGUI *wbcg);
551
static void wbcg_menu_state_sheet_count (WorkbookControl *wbc);
Jody Goldberg's avatar
update    
Jody Goldberg committed
552

Jody Goldberg's avatar
be safe    
Jody Goldberg committed
553
554
555
556
/**
 * wbcg_sheet_add:
 * @sheet: a sheet
 *
557
 * Creates a new SheetControlGUI for the sheet and adds it to the workbook-control-gui.
Jody Goldberg's avatar
be safe    
Jody Goldberg committed
558
559
560
561
562
 */
static void
wbcg_sheet_add (WorkbookControl *wbc, Sheet *sheet)
{
	WorkbookControlGUI *wbcg = (WorkbookControlGUI *)wbc;
563
	SheetControlGUI *scg;
564
	SheetControl *sc;
Jody Goldberg's avatar
be safe    
Jody Goldberg committed
565
	GtkWidget *sheet_label;
Jody Goldberg's avatar
Jody Goldberg committed
566
	GList     *ptr;
Jody Goldberg's avatar
be safe    
Jody Goldberg committed
567
568

	g_return_if_fail (wbcg != NULL);
Jody Goldberg's avatar
update    
Jody Goldberg committed
569
570
571

	if (wbcg->notebook == NULL)
		workbook_setup_sheets (wbcg);
Jody Goldberg's avatar
be safe    
Jody Goldberg committed
572

573
	scg = sheet_control_gui_new (sheet);
574
575
	sc = (SheetControl *) scg;
	sc->wbc = wbc;
576
	scg->wbcg = wbcg;
Jody Goldberg's avatar
be safe    
Jody Goldberg committed
577
578
579
580
581
582
583
584
585
586
587
588
589
590

	/*
	 * NB. this is so we can use editable_label_set_text since
	 * gtk_notebook_set_tab_label kills our widget & replaces with a label.
	 */
	sheet_label = editable_label_new (sheet->name_unquoted);
	gtk_signal_connect_after (
		GTK_OBJECT (sheet_label), "text_changed",
		GTK_SIGNAL_FUNC (cb_sheet_label_changed), wbcg);
	gtk_signal_connect (
		GTK_OBJECT (sheet_label), "editing_stopped",
		GTK_SIGNAL_FUNC (cb_sheet_label_edit_stopped), wbcg);
	gtk_signal_connect (
		GTK_OBJECT (sheet_label), "button_press_event",
591
		GTK_SIGNAL_FUNC (cb_sheet_label_button_press), scg->table);
Jody Goldberg's avatar
be safe    
Jody Goldberg committed
592
593

	gtk_widget_show (sheet_label);
594
	gtk_widget_show_all (GTK_WIDGET (scg->table));
Jody Goldberg's avatar
be safe    
Jody Goldberg committed
595

596
597
	if (wbcg_ui_update_begin (wbcg)) {
		gtk_notebook_insert_page (wbcg->notebook,
598
			GTK_WIDGET (scg->table), sheet_label,
599
600
601
			workbook_sheet_index_get (wb_control_workbook (wbc), sheet));
		wbcg_ui_update_end (wbcg);
	}
Jody Goldberg's avatar
be safe    
Jody Goldberg committed
602

603
	wbcg_menu_state_sheet_count (wbc);
Jody Goldberg's avatar
Jody Goldberg committed
604
605
606

	/* create views for the sheet objects */
	for (ptr = sheet->sheet_objects; ptr != NULL ; ptr = ptr->next)
607
		sheet_object_new_view (ptr->data, scg);
608
609
	scg_adjust_preferences (sc);
	scg_set_zoom_factor (sc);
610
	scg_take_focus (scg);
Jody Goldberg's avatar
be safe    
Jody Goldberg committed
611
612
613
614
615
616
}

static void
wbcg_sheet_remove (WorkbookControl *wbc, Sheet *sheet)
{
	WorkbookControlGUI *wbcg = (WorkbookControlGUI *)wbc;
617
	SheetControlGUI *scg;
Jody Goldberg's avatar
update    
Jody Goldberg committed
618
619
620
621
622
623
	int i;

	/* During destruction we may have already removed the notebook */
	if (wbcg->notebook == NULL)
		return;

624
	i = sheet_to_page_index (wbcg, sheet, &scg);
Jody Goldberg's avatar
be safe    
Jody Goldberg committed
625

Jody Goldberg's avatar
Jody Goldberg committed
626
	g_return_if_fail (i >= 0);
Jody Goldberg's avatar
be safe    
Jody Goldberg committed
627

Jody Goldberg's avatar
Jody Goldberg committed
628
	gtk_notebook_remove_page (wbcg->notebook, i);
Jody Goldberg's avatar
be safe    
Jody Goldberg committed
629

630
	wbcg_menu_state_sheet_count (wbc);
Jody Goldberg's avatar
be safe    
Jody Goldberg committed
631
632
}

Jody Goldberg's avatar
Jody Goldberg committed
633
634
635
636
637
static void
wbcg_sheet_rename (WorkbookControl *wbc, Sheet *sheet)
{
	WorkbookControlGUI *wbcg = (WorkbookControlGUI *)wbc;
	GtkWidget *label;
638
639
	SheetControlGUI *scg;
	int i = sheet_to_page_index (wbcg, sheet, &scg);
Jody Goldberg's avatar
Jody Goldberg committed
640
641
642

	g_return_if_fail (i >= 0);

643
	label = gtk_notebook_get_tab_label (wbcg->notebook, GTK_WIDGET (scg->table));
Jody Goldberg's avatar
Jody Goldberg committed
644
645
	editable_label_set_text (EDITABLE_LABEL (label), sheet->name_unquoted);
}
Jody Goldberg's avatar
be safe    
Jody Goldberg committed
646

Jody Goldberg's avatar
Jody Goldberg committed
647
static void
Jody Goldberg's avatar
Jody Goldberg committed
648
wbcg_sheet_focus (WorkbookControl *wbc, Sheet *sheet)
Jody Goldberg's avatar
Jody Goldberg committed
649
650
{
	WorkbookControlGUI *wbcg = (WorkbookControlGUI *)wbc;
651
652
	SheetControlGUI *scg;
	int i = sheet_to_page_index (wbcg, sheet, &scg);
Jody Goldberg's avatar
Jody Goldberg committed
653
654
655
656
657
658
659
660
661

	/* A sheet added in another view may not yet have a view */
	if (i >= 0) {
		gtk_notebook_set_page (wbcg->notebook, i);
		zoom_changed (wbcg, sheet);
	}
}

static void
Jody Goldberg's avatar
Jody Goldberg committed
662
wbcg_sheet_move (WorkbookControl *wbc, Sheet *sheet, int new_pos)
Jody Goldberg's avatar
Jody Goldberg committed
663
{
Jody Goldberg's avatar
Jody Goldberg committed
664
	WorkbookControlGUI *wbcg = (WorkbookControlGUI *)wbc;
665
	SheetControlGUI *scg;
Jody Goldberg's avatar
Jody Goldberg committed
666
667
668
669

	g_return_if_fail (IS_SHEET (sheet));

	/* No need for sanity checking, the workbook did that */
670
        if (sheet_to_page_index (wbcg, sheet, &scg) >= 0)
Jody Goldberg's avatar
Jody Goldberg committed
671
		gtk_notebook_reorder_child (wbcg->notebook,
672
			GTK_WIDGET (scg->table), new_pos);
Jody Goldberg's avatar
Jody Goldberg committed
673
674
}

Jody Goldberg's avatar
update    
Jody Goldberg committed
675
676
677
678
679
680
static void
wbcg_sheet_remove_all (WorkbookControl *wbc)
{
	WorkbookControlGUI *wbcg = (WorkbookControlGUI *)wbc;

	if (wbcg->notebook != NULL) {
681
682
		GtkWidget *tmp = GTK_WIDGET (wbcg->notebook);

683
		/* Be sure we are no longer editing */
684
		wbcg_edit_finish (wbcg, FALSE);
685

686
687
688
		/* Clear notebook to disable updates as focus changes for pages
		 * during destruction
		 */
Jody Goldberg's avatar
update    
Jody Goldberg committed
689
		wbcg->notebook = NULL;
690
		gtk_container_remove (GTK_CONTAINER (wbcg->table), tmp);
Jody Goldberg's avatar
update    
Jody Goldberg committed
691
692
693
	}
}

Jody Goldberg's avatar
Jody Goldberg committed
694
695
696
697
698
699
700
701
static void
wbcg_history_setup (WorkbookControlGUI *wbcg)
{
	GList *hl = application_history_get_list ();
	if (hl)
		history_menu_setup (wbcg, hl);
}

702
703
static gboolean
cb_change_zoom (GtkWidget *caller, char *new_zoom, WorkbookControlGUI *wbcg)
Jody Goldberg's avatar
Jody Goldberg committed
704
705
706
{
	Sheet *sheet = wb_control_cur_sheet (WORKBOOK_CONTROL (wbcg));
	int factor;
707
	char *end;
Jody Goldberg's avatar
Jody Goldberg committed
708

Jody Goldberg's avatar
delete.    
Jody Goldberg committed
709
	if (sheet == NULL || wbcg->updating_ui)
710
		return TRUE;
Jody Goldberg's avatar
Jody Goldberg committed
711

712
713
714
715
716
717
718
719
720
721
722
	errno = 0; /* strtod sets errno, but does not clear it.  */
	factor = strtol (new_zoom, &end, 10);
	if (new_zoom != end && errno != ERANGE && factor == (gnum_float)factor)
		/* The GSList of sheet passed to cmd_zoom will be freed by cmd_zoom,
		 * and the sheet will fore an updat eof the zoom combo to keep the
		 * display consistent
		 */
		cmd_zoom (WORKBOOK_CONTROL (wbcg), g_slist_append (NULL, sheet),
			  (double) factor / 100);
	else
		zoom_changed (wbcg, sheet);
Jody Goldberg's avatar
Jody Goldberg committed
723
724

	wb_control_gui_focus_cur_sheet (wbcg);
725

726
727
	/* because we are updating it there is no need to apply it now */
	return FALSE;
Jody Goldberg's avatar
Jody Goldberg committed
728
729
730
}

static void
Jody Goldberg's avatar
Jody Goldberg committed
731
wbcg_auto_expr_value (WorkbookControl *wbc)
Jody Goldberg's avatar
Jody Goldberg committed
732
{
733
	WorkbookControlGUI *wbcg = WORKBOOK_CONTROL_GUI (wbc);
Jody Goldberg's avatar
Jody Goldberg committed
734
	WorkbookView *wbv = wb_control_view (wbc);
Jody Goldberg's avatar
Jody Goldberg committed
735

Jody Goldberg's avatar
Jody Goldberg committed
736
737
738
	g_return_if_fail (wbcg != NULL);
	g_return_if_fail (wbv != NULL);
	g_return_if_fail (wbv->auto_expr_value_as_string != NULL);
Jody Goldberg's avatar
Jody Goldberg committed
739

740
	if (wbcg_ui_update_begin (wbcg)) {
741
742
743
		gtk_label_set_text(
			 GTK_LABEL (GTK_BIN (wbcg->auto_expr_label)->child),
			 wbv->auto_expr_value_as_string);
744
745
		wbcg_ui_update_end (wbcg);
	}
Jody Goldberg's avatar
Jody Goldberg committed
746
747
}

748
749
750
751
752
753
754
755
756
757
758
759
760
static GtkComboStack *
ur_stack (WorkbookControl *wbc, gboolean is_undo)
{
	WorkbookControlGUI *wbcg = (WorkbookControlGUI *)wbc;
	return GTK_COMBO_STACK (is_undo ? wbcg->undo_combo : wbcg->redo_combo);
}

static void
wbcg_undo_redo_clear (WorkbookControl *wbc, gboolean is_undo)
{
	gtk_combo_stack_clear (ur_stack (wbc, is_undo));
}

761
762
763
764
765
766
static void
wbcg_undo_redo_truncate (WorkbookControl *wbc, int n, gboolean is_undo)
{
	gtk_combo_stack_truncate (ur_stack (wbc, is_undo), n);
}

767
768
769
770
771
772
773
774
775
776
777
778
static void
wbcg_undo_redo_pop (WorkbookControl *wbc, gboolean is_undo)
{
	gtk_combo_stack_remove_top (ur_stack (wbc, is_undo), 1);
}

static void
wbcg_undo_redo_push (WorkbookControl *wbc, char const *text, gboolean is_undo)
{
	gtk_combo_stack_push_item (ur_stack (wbc, is_undo), text);
}

Almer S. Tigelaar's avatar
Almer S. Tigelaar committed
779
#ifndef ENABLE_BONOBO
780
781
static void
change_menu_state (GtkWidget *menu_item, gboolean state)
Almer S. Tigelaar's avatar
Almer S. Tigelaar committed
782
783
784
{
	g_return_if_fail (menu_item != NULL);

785
	gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_item), state);
Jody Goldberg's avatar
enable.    
Jody Goldberg committed
786
}
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806

static void
change_menu_sensitivity (GtkWidget *menu_item, gboolean sensitive)
{
	g_return_if_fail (menu_item != NULL);

	gtk_widget_set_sensitive (menu_item, sensitive);
}

static void
change_menu_label (GtkWidget *menu_item, char const *prefix, char const *suffix)
{
	gchar    *text;
	GtkBin   *bin = GTK_BIN (menu_item);
	GtkLabel *label = GTK_LABEL (bin->child);
	gboolean  sensitive = TRUE;

	g_return_if_fail (label != NULL);

	if (prefix == NULL) {
807
		gtk_label_parse_uline (label, suffix);
808
809
810
811
812
813
814
815
816
817
		return;
	}

	if (suffix == NULL) {
		suffix = _("Nothing");
		sensitive = FALSE;
	}

	text = g_strdup_printf ("%s : %s", prefix, suffix);

818
	gtk_label_parse_uline (label, text);
819
820
821
	gtk_widget_set_sensitive (menu_item, sensitive);
	g_free (text);
}
Almer S. Tigelaar's avatar
Almer S. Tigelaar committed
822
#else
823
824
static void
change_menu_state (WorkbookControlGUI const *wbcg,
Jody Goldberg's avatar
enable.    
Jody Goldberg committed
825
826
		  char const *verb_path, gboolean state)
{
Almer S. Tigelaar's avatar
Almer S. Tigelaar committed
827
828
	CORBA_Environment  ev;

Jody Goldberg's avatar
enable.    
Jody Goldberg committed
829
	g_return_if_fail (IS_WORKBOOK_CONTROL_GUI (wbcg));
Almer S. Tigelaar's avatar
Almer S. Tigelaar committed
830
831
832

	CORBA_exception_init (&ev);
	bonobo_ui_component_set_prop (wbcg->uic, verb_path,
Jody Goldberg's avatar
delete.    
Jody Goldberg committed
833
				      "state", state ? "1" : "0", &ev);
Morten Welinder's avatar
Morten Welinder committed
834
	CORBA_exception_free (&ev);
Almer S. Tigelaar's avatar
Almer S. Tigelaar committed
835
}
Jody Goldberg's avatar
enable.    
Jody Goldberg committed
836

Almer S. Tigelaar's avatar
Almer S. Tigelaar committed
837
static void
Jody Goldberg's avatar
enable.    
Jody Goldberg committed
838
839
840
change_menu_sensitivity (WorkbookControlGUI const *wbcg,
			 char const *verb_path, gboolean sensitive)
{
841
842
	CORBA_Environment  ev;

Jody Goldberg's avatar
enable.    
Jody Goldberg committed
843
	g_return_if_fail (IS_WORKBOOK_CONTROL_GUI (wbcg));
844
845
846
847

	CORBA_exception_init (&ev);
	bonobo_ui_component_set_prop (wbcg->uic, verb_path,
				      "sensitive", sensitive ? "1" : "0", &ev);
Morten Welinder's avatar
Morten Welinder committed
848
	CORBA_exception_free (&ev);
Almer S. Tigelaar's avatar
Almer S. Tigelaar committed
849
}
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865

static void
change_menu_label (WorkbookControlGUI const *wbcg,
		   char const *verb_path,
		   char const *prefix,
		   char const *suffix)
{
	gboolean  sensitive = TRUE;
	gchar    *text;
	CORBA_Environment  ev;

	g_return_if_fail (IS_WORKBOOK_CONTROL_GUI (wbcg));

	CORBA_exception_init (&ev);

	if (prefix == NULL) {
866
		bonobo_ui_component_set_prop (wbcg->uic, verb_path, "label",
867
868
869
870
871
872
873
874
875
					      suffix, &ev);
	} else {
		if (suffix == NULL) {
			suffix = _("Nothing");
			sensitive = FALSE;
		}

		text = g_strdup_printf ("%s : %s", prefix, suffix);

876
		bonobo_ui_component_set_prop (wbcg->uic, verb_path,
877
878
879
880
881
882
883
					      "label", text, &ev);
		bonobo_ui_component_set_prop (wbcg->uic, verb_path,
					      "sensitive", sensitive ? "1" : "0", &ev);
		g_free (text);
	}
	CORBA_exception_free (&ev);
}
Jody Goldberg's avatar
enable.    
Jody Goldberg committed
884
#endif
Almer S. Tigelaar's avatar
Almer S. Tigelaar committed
885

Almer S. Tigelaar's avatar
Almer S. Tigelaar committed
886
static void
887
wbcg_menu_state_update (WorkbookControl *wbc, Sheet const *sheet, int flags)
Almer S. Tigelaar's avatar
Almer S. Tigelaar committed
888
889
{
	WorkbookControlGUI *wbcg = (WorkbookControlGUI *)wbc;
Morten Welinder's avatar
Morten Welinder committed
890

Almer S. Tigelaar's avatar
Almer S. Tigelaar committed
891
892
893
	g_return_if_fail (wbcg != NULL);

#ifndef ENABLE_BONOBO
Morten Welinder's avatar
Morten Welinder committed
894
	if (MS_INSERT_COLS & flags)
Jody Goldberg's avatar
Jody Goldberg committed
895
896
		change_menu_sensitivity (wbcg->menu_item_insert_cols,
					 sheet->priv->enable_insert_cols);
897
	if (MS_INSERT_ROWS & flags)
Jody Goldberg's avatar
Jody Goldberg committed
898
899
		change_menu_sensitivity (wbcg->menu_item_insert_rows,
					 sheet->priv->enable_insert_rows);
900
	if (MS_INSERT_CELLS & flags)
Jody Goldberg's avatar
Jody Goldberg committed
901
902
		change_menu_sensitivity (wbcg->menu_item_insert_cells,
					 sheet->priv->enable_insert_cells);
903
	if (MS_SHOWHIDE_DETAIL & flags) {
904
905
906
907
908
		change_menu_sensitivity (wbcg->menu_item_show_detail,
					 sheet->priv->enable_showhide_detail);
		change_menu_sensitivity (wbcg->menu_item_hide_detail,
					 sheet->priv->enable_showhide_detail);
	}
909
	if (MS_PASTE_SPECIAL & flags)
910
911
		change_menu_sensitivity (wbcg->menu_item_paste_special,
					 sheet->priv->enable_paste_special);
912
	if (MS_PRINT_SETUP & flags)
913
		change_menu_sensitivity (wbcg->menu_item_print_setup,
914
					 !wbcg_edit_has_guru (wbcg));
915
	if (MS_SEARCH_REPLACE & flags)
916
		change_menu_sensitivity (wbcg->menu_item_search_replace,
917
					 !wbcg_edit_has_guru (wbcg));
918
	if (MS_DEFINE_NAME & flags)
919
		change_menu_sensitivity (wbcg->menu_item_define_name,
920
					 !wbcg_edit_has_guru (wbcg));
921
	if (MS_CONSOLIDATE & flags)
Almer S. Tigelaar's avatar
Almer S. Tigelaar committed
922
923
		change_menu_sensitivity (wbcg->menu_item_consolidate,
					 !wbcg_edit_has_guru (wbcg));
Almer S. Tigelaar's avatar
Almer S. Tigelaar committed
924
#else
925
	if (MS_INSERT_COLS & flags)
Jody Goldberg's avatar
Jody Goldberg committed
926
927
		change_menu_sensitivity (wbcg, "/commands/InsertColumns",
					 sheet->priv->enable_insert_cols);
928
	if (MS_INSERT_ROWS & flags)
Jody Goldberg's avatar
Jody Goldberg committed
929
930
		change_menu_sensitivity (wbcg, "/commands/InsertRows",
					 sheet->priv->enable_insert_rows);
931
	if (MS_INSERT_CELLS & flags)
Jody Goldberg's avatar
Jody Goldberg committed
932
933
		change_menu_sensitivity (wbcg, "/commands/InsertCells",
					 sheet->priv->enable_insert_cells);
934
	if (MS_SHOWHIDE_DETAIL & flags) {
935
936
937
938
939
		change_menu_sensitivity (wbcg, "/commands/DataOutlineShowDetail",
					 sheet->priv->enable_showhide_detail);
		change_menu_sensitivity (wbcg, "/commands/DataOutlineHideDetail",
					 sheet->priv->enable_showhide_detail);
	}
940
	if (MS_PASTE_SPECIAL & flags)
941
942
		change_menu_sensitivity (wbcg, "/commands/EditPasteSpecial",
					 sheet->priv->enable_paste_special);
943
	if (MS_PRINT_SETUP & flags)
944
		change_menu_sensitivity (wbcg, "/commands/FilePrintSetup",
945
					 !wbcg_edit_has_guru (wbcg));
946
	if (MS_SEARCH_REPLACE & flags)
947
		change_menu_sensitivity (wbcg, "/commands/EditSearchReplace",
948
					 !wbcg_edit_has_guru (wbcg));
949
	if (MS_DEFINE_NAME & flags)
950
		change_menu_sensitivity (wbcg, "/commands/EditNames",
951
					 !wbcg_edit_has_guru (wbcg));
952
	if (MS_CONSOLIDATE & flags)
Almer S. Tigelaar's avatar
Almer S. Tigelaar committed
953
954
		change_menu_sensitivity (wbcg, "/commands/DataConsolidate",
					 !wbcg_edit_has_guru (wbcg));
Almer S. Tigelaar's avatar
Almer S. Tigelaar committed
955
#endif
956

957
958
	if (MS_FREEZE_VS_THAW & flags) {
		Sheet *sheet = wb_control_cur_sheet (WORKBOOK_CONTROL (wbcg));
959
960
		/* Cheat and use the same accelerator for both states because
		 * we don't reset it when the label changes */
961
		char const* label = sheet_is_frozen (sheet)
962
			? _("Un_freeze Panes") : _("_Freeze Panes");
963
#ifndef ENABLE_BONOBO
964
965
		change_menu_label (wbcg->menu_item_freeze_panes,
				   NULL, label);
966
#else
967
		change_menu_label (wbcg, "/commands/ViewFreezeThawPanes",
968
		                   NULL, label);
969
970
971
972
#endif
	}
}

973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
static void
wbcg_menu_state_sensitivity (WorkbookControl *wbc, gboolean sensitive)
{
 	WorkbookControlGUI *wbcg = (WorkbookControlGUI *)wbc;
#ifdef ENABLE_BONOBO
	CORBA_Environment ev;
#endif

	/* Don't disable/enable again (prevent toolbar flickering) */
	if (wbcg->toolbar_is_sensitive != sensitive)
		wbcg->toolbar_is_sensitive = sensitive;
	else
		return;

#ifdef ENABLE_BONOBO
	CORBA_exception_init (&ev);
	bonobo_ui_component_set_prop (wbcg->uic, "/commands/MenuBar",
				      "sensitive", sensitive ? "1" : "0", &ev);
	bonobo_ui_component_set_prop (wbcg->uic, "/commands/StandardToolbar",
				      "sensitive", sensitive ? "1" : "0", &ev);
	bonobo_ui_component_set_prop (wbcg->uic, "/commands/FormatToolbar",
				      "sensitive", sensitive ? "1" : "0", &ev);
	bonobo_ui_component_set_prop (wbcg->uic, "/commands/ObjectToolbar",
				      "sensitive", sensitive ? "1" : "0", &ev);
	CORBA_exception_free (&ev);
	/* TODO : Ugly hack to work around strange bonobo semantics for
	 * sensitivity of containers.  Bonono likes to recursively set the state
	 * rather than just setting the container.
	 */
	if (sensitive) {
		Workbook *wb = wb_control_workbook (WORKBOOK_CONTROL (wbcg));
		if (wb->undo_commands == NULL)
			gtk_widget_set_sensitive (wbcg->undo_combo, FALSE);
		if (wb->redo_commands == NULL)
			gtk_widget_set_sensitive (wbcg->redo_combo, FALSE);
	}
#else
	gtk_widget_set_sensitive (GNOME_APP (wbcg->toplevel)->menubar, sensitive);
	gtk_widget_set_sensitive (wbcg->standard_toolbar, sensitive);
	gtk_widget_set_sensitive (wbcg->format_toolbar, sensitive);
	gtk_widget_set_sensitive (wbcg->object_toolbar, sensitive);
#endif

}

1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
static void
wbcg_undo_redo_labels (WorkbookControl *wbc, char const *undo, char const *redo)
{
	WorkbookControlGUI *wbcg = (WorkbookControlGUI *)wbc;
	g_return_if_fail (wbcg != NULL);

#ifndef ENABLE_BONOBO
	change_menu_label (wbcg->menu_item_undo, _("Undo"), undo);
	change_menu_label (wbcg->menu_item_redo, _("Redo"), redo);
#else
1028
1029
	change_menu_label (wbcg, "/commands/EditUndo", _("_Undo"), undo);
	change_menu_label (wbcg, "/commands/EditRedo", _("_Redo"), redo);
1030
1031
1032
#endif
}

1033
1034
1035
1036
static void
wbcg_menu_state_sheet_prefs (WorkbookControl *wbc, Sheet const *sheet)
{
 	WorkbookControlGUI *wbcg = (WorkbookControlGUI *)wbc;
Morten Welinder's avatar
Morten Welinder committed
1037

1038
1039
	if (!wbcg_ui_update_begin (wbcg))
		return;
1040
1041

#ifndef ENABLE_BONOBO
1042
	change_menu_state (wbcg->menu_item_sheet_display_formulas,
1043
		sheet->display_formulas);
1044
	change_menu_state (wbcg->menu_item_sheet_hide_zero,
1045
		sheet->hide_zero);
1046
	change_menu_state (wbcg->menu_item_sheet_hide_grid,
1047
		sheet->hide_grid);
1048
	change_menu_state (wbcg->menu_item_sheet_hide_col_header,
1049
		sheet->hide_col_header);
1050
	change_menu_state (wbcg->menu_item_sheet_hide_row_header,
1051
		sheet->hide_row_header);
1052
	change_menu_state (wbcg->menu_item_sheet_display_outlines,
1053
		sheet->display_outlines);
1054
	change_menu_state (wbcg->menu_item_sheet_outline_symbols_below,
1055
		sheet->outline_symbols_below);
1056
	change_menu_state (wbcg->menu_item_sheet_outline_symbols_right,
1057
		sheet->outline_symbols_right);
1058
#else
1059
	change_menu_state (wbcg,
Jody Goldberg's avatar
enable.    
Jody Goldberg committed
1060
		"/commands/SheetDisplayFormulas", sheet->display_formulas);
1061
	change_menu_state (wbcg,
Jody Goldberg's avatar
enable.    
Jody Goldberg committed
1062
		"/commands/SheetHideZeros", sheet->hide_zero);
1063
	change_menu_state (wbcg,
Jody Goldberg's avatar
enable.    
Jody Goldberg committed
1064
		"/commands/SheetHideGridlines", sheet->hide_grid);
1065
	change_menu_state (wbcg,
Jody Goldberg's avatar
enable.    
Jody Goldberg committed
1066
		"/commands/SheetHideColHeader", sheet->hide_col_header);
1067
	change_menu_state (wbcg,
Jody Goldberg's avatar
enable.    
Jody Goldberg committed
1068
		"/commands/SheetHideRowHeader", sheet->hide_row_header);
1069
	change_menu_state (wbcg,
1070
		"/commands/SheetDisplayOutlines", sheet->display_outlines);
1071
	change_menu_state (wbcg,
1072
		"/commands/SheetOutlineBelow", sheet->outline_symbols_below);
1073
	change_menu_state (wbcg,
1074
		"/commands/SheetOutlineRight", sheet->outline_symbols_right);
1075
#endif
1076
	wbcg_ui_update_end (wbcg);
1077
1078
}

1079
1080
1081
1082
static void
wbcg_menu_state_sheet_count (WorkbookControl *wbc)
{
 	WorkbookControlGUI *wbcg = (WorkbookControlGUI *)wbc;
1083
1084
1085
	int const sheet_count = g_list_length (wbcg->notebook->children);
	/* Should we anble commands requiring multiple sheets */
	gboolean const multi_sheet = (sheet_count > 1);
1086

1087
1088
	/* Scrollable if there are more than 3 tabs */
	gtk_notebook_set_scrollable (wbcg->notebook, sheet_count > 3);
Morten Welinder's avatar
Morten Welinder committed
1089

1090
#ifndef ENABLE_BONOBO
1091
1092
1093
	change_menu_sensitivity (wbcg->menu_item_sheet_remove, multi_sheet);
	change_menu_sensitivity (wbcg->menu_item_sheets_edit_reorder, multi_sheet);
	change_menu_sensitivity (wbcg->menu_item_sheets_format_reorder, multi_sheet);
1094
#else
1095
1096
	change_menu_sensitivity (wbcg, "/commands/SheetRemove", multi_sheet);
	change_menu_sensitivity (wbcg, "/commands/SheetReorder", multi_sheet);
1097
1098
1099
#endif
}

1100
1101
1102
1103
1104
1105
static void
wbcg_paste_from_selection (WorkbookControl *wbc, PasteTarget const *pt, guint32 time)
{