gui-util.c 30.2 KB
Newer Older
1
/* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
/*
Morten Welinder's avatar
Morten Welinder committed
3
 * gnumeric-util.c:  Various GUI utility functions.
4 5 6 7
 *
 * Author:
 *  Miguel de Icaza (miguel@gnu.org)
 */
8 9
#include <gnumeric-config.h>
#include "gnumeric.h"
10
#include "gui-util.h"
11 12

#include "workbook-control-gui-priv.h"
13
#include "gutils.h"
14
#include "parse-util.h"
15
#include "style.h"
16
#include "style-color.h"
Chyla Zbigniew's avatar
Chyla Zbigniew committed
17
#include "error-info.h"
18
#include "value.h"
19 20
#include "number-match.h"
#include "format.h"
21 22

#include <string.h>
Jody Goldberg's avatar
Jody Goldberg committed
23
#include <gal/widgets/e-colors.h>
24
#include <gal/widgets/widget-color-combo.h>
25
#include <glade/glade.h>
26

Michael Meeks's avatar
Michael Meeks committed
27 28
#ifdef ENABLE_BONOBO
#	include <bonobo.h>
29
#	include "workbook-private.h"
Michael Meeks's avatar
Michael Meeks committed
30
#endif
31

Jody Goldberg's avatar
fix.  
Jody Goldberg committed
32 33
#include <libgnome/gnome-util.h>
#include <libgnome/gnome-i18n.h>
34
#include <libgnome/gnome-help.h>
Jody Goldberg's avatar
fix.  
Jody Goldberg committed
35

Chyla Zbigniew's avatar
Chyla Zbigniew committed
36 37
gboolean
gnumeric_dialog_question_yes_no (WorkbookControlGUI *wbcg,
Jody Goldberg's avatar
Jody Goldberg committed
38
                                 gchar const *message,
Chyla Zbigniew's avatar
Chyla Zbigniew committed
39 40
                                 gboolean default_answer)
{
Jody Goldberg's avatar
Jody Goldberg committed
41 42
	GtkWidget *dialog = gtk_message_dialog_new (wbcg_toplevel (wbcg),
		GTK_DIALOG_DESTROY_WITH_PARENT,
Jody Goldberg's avatar
Jody Goldberg committed
43 44 45 46 47 48 49
		GTK_MESSAGE_QUESTION,
		GTK_BUTTONS_YES_NO,
		message);
	gtk_dialog_set_default_response (GTK_DIALOG (dialog),
		default_answer ? GTK_RESPONSE_YES : GTK_RESPONSE_NO);

	return gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_YES;
Chyla Zbigniew's avatar
Chyla Zbigniew committed
50
}
Jody Goldberg's avatar
Jody Goldberg committed
51 52 53 54 55
/*
 * TODO:
 * Get rid of trailing newlines /whitespace.
 */
void
56
gnumeric_notice (WorkbookControlGUI *wbcg, GtkMessageType type, char const *str)
Jody Goldberg's avatar
Jody Goldberg committed
57 58 59
{
	GtkWidget *dialog;

60 61 62
	dialog = gtk_message_dialog_new (wbcg == NULL ? NULL : wbcg_toplevel (wbcg),
                                         GTK_DIALOG_DESTROY_WITH_PARENT, type,
					 GTK_BUTTONS_OK, str);
Jody Goldberg's avatar
Jody Goldberg committed
63 64 65 66

	gnumeric_dialog_run (wbcg, GTK_DIALOG (dialog));
}

67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
/**
 * gnumeric_destroy_dialog:
 * @window:
 * @state:
 *
 * NULL the reference before.
 * This is used to have small keyed-dialog style dialogs whose
 * parent is just another dialog
 *
 **/
static gboolean
gnumeric_destroy_dialog (GtkObject *w, GtkWindow **ref)
{
	g_return_val_if_fail (w != NULL, FALSE);

	*ref = NULL;
	return FALSE;
}


void
gnumeric_notice_nonmodal (GtkWindow *parent, GtkWidget **ref, GtkMessageType type, char const *str)
89 90 91
{
	GtkWidget *dialog;

92 93 94
	if (*ref != NULL)
		gtk_widget_destroy (*ref);

95 96 97 98 99 100
	dialog = gtk_message_dialog_new (parent, GTK_DIALOG_DESTROY_WITH_PARENT, type,
					 GTK_BUTTONS_OK, str);

	gtk_signal_connect_object (GTK_OBJECT (dialog), "response",
				   GTK_SIGNAL_FUNC (gtk_widget_destroy), 
				   GTK_OBJECT (dialog));
101 102
	gtk_signal_connect (GTK_OBJECT (dialog), "destroy",
			    GTK_SIGNAL_FUNC (gnumeric_destroy_dialog), ref);
103 104

	gtk_widget_show (dialog);
105
	*ref = dialog;
106

107
	return;
108 109
}

Chyla Zbigniew's avatar
Chyla Zbigniew committed
110

111 112 113 114 115 116 117 118 119 120 121
static void
fsel_dialog_finish (GtkWidget *widget)
{
	gtk_widget_hide (widget);
	gtk_main_quit ();
}

static void
fsel_handle_ok (GtkWidget *widget, gboolean *result)
{
	GtkFileSelection *fsel;
Jody Goldberg's avatar
Jody Goldberg committed
122
	gchar const *file_name;
123 124 125

	fsel = GTK_FILE_SELECTION (gtk_widget_get_ancestor (widget, GTK_TYPE_FILE_SELECTION));
	file_name = gtk_file_selection_get_filename (fsel);
Morten Welinder's avatar
Morten Welinder committed
126

127
	/* Change into directory if that's what user selected */
Jody Goldberg's avatar
Jody Goldberg committed
128
	if (g_file_test (file_name, G_FILE_TEST_IS_DIR)) {
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
		gint name_len;
		gchar *dir_name;

		name_len = strlen (file_name);
		if (name_len < 1 || file_name [name_len - 1] != '/') {
			/* The file selector needs a '/' at the end of a directory name */
			dir_name = g_strconcat (file_name, "/", NULL);
		} else {
			dir_name = g_strdup (file_name);
		}
		gtk_file_selection_set_filename (fsel, dir_name);
		g_free (dir_name);
	} else {
		fsel_dialog_finish (GTK_WIDGET (fsel));
		*result = TRUE;
	}
}

static void
fsel_handle_cancel (GtkWidget *widget, gpointer user_data)
{
	GtkWidget *fsel;

	fsel = gtk_widget_get_ancestor (widget, GTK_TYPE_FILE_SELECTION);
	fsel_dialog_finish (fsel);
}

static gint
fsel_delete_event (GtkWidget *widget, GdkEventAny *event)
{
	fsel_dialog_finish (widget);
	return TRUE;
}

static gint
fsel_key_event (GtkWidget *widget, GdkEventKey *event, gpointer user_data)
{
	if (event->keyval == GDK_Escape) {
		gtk_signal_emit_stop_by_name (GTK_OBJECT (widget), "key_press_event");
		fsel_dialog_finish (widget);
		return TRUE;
	}

	return FALSE;
}

gboolean
gnumeric_dialog_file_selection (WorkbookControlGUI *wbcg, GtkFileSelection *fsel)
{
	gboolean result = FALSE;

	gtk_window_set_modal (GTK_WINDOW (fsel), TRUE);
	gnumeric_set_transient (wbcg, GTK_WINDOW (fsel));
	gtk_signal_connect (GTK_OBJECT (fsel->ok_button), "clicked",
	                    GTK_SIGNAL_FUNC (fsel_handle_ok), &result);
	gtk_signal_connect (GTK_OBJECT (fsel->cancel_button), "clicked",
	                    GTK_SIGNAL_FUNC (fsel_handle_cancel), NULL);
	gtk_signal_connect (GTK_OBJECT (fsel), "key_press_event",
	                    GTK_SIGNAL_FUNC (fsel_key_event), NULL);
	gtk_signal_connect (GTK_OBJECT (fsel), "delete_event",
	                    GTK_SIGNAL_FUNC (fsel_delete_event), NULL);
	gtk_widget_show_all (GTK_WIDGET (fsel));
	gtk_grab_add (GTK_WIDGET (fsel));
	gtk_main ();

	return result;
}

197
/**
Jon K Hellan's avatar
Jon K Hellan committed
198 199 200
 * gnumeric_dialog_run
 *
 * Pop up a dialog as child of a workbook.
201 202
 */
gint
Jody Goldberg's avatar
Jody Goldberg committed
203
gnumeric_dialog_run (WorkbookControlGUI *wbcg, GtkDialog *dialog)
204
{
205
	GtkWindow *toplevel;
206
	gint      result;
207

208
	g_return_val_if_fail (GTK_IS_DIALOG (dialog), GTK_RESPONSE_NONE);
209 210

	if (wbcg) {
211
		g_return_val_if_fail (IS_WORKBOOK_CONTROL_GUI (wbcg), GTK_RESPONSE_NONE);
212

Jody Goldberg's avatar
Jody Goldberg committed
213
		toplevel = wbcg_toplevel (wbcg);
214
		if (GTK_WINDOW (dialog)->transient_parent != toplevel)
Jody Goldberg's avatar
Jody Goldberg committed
215
			gtk_window_set_transient_for (GTK_WINDOW (dialog), toplevel);
216
	}
217 218

	result = gtk_dialog_run (dialog);
219
	gtk_widget_destroy (GTK_WIDGET (dialog));	
220
	return result;
Jon K Hellan's avatar
Jon K Hellan committed
221 222 223 224 225 226 227
}

/**
 * gnumeric_dialog_show
 * @parent             parent widget
 * @dialog             dialog
 * @click_closes       close on click
228
 * @close_with_parent  close when parent closes
Jon K Hellan's avatar
Jon K Hellan committed
229 230 231 232 233 234 235 236
 *
 * Pop up a dialog without a recursive main loop
 *
 * Attach a handler to close if the parent closes.
 * The parent widget does not have to be a toplevel shell - we look it
 * up here.
 */
void
Jody Goldberg's avatar
Jody Goldberg committed
237
gnumeric_dialog_show (WorkbookControlGUI *wbcg, GtkDialog *dialog,
Jon K Hellan's avatar
Jon K Hellan committed
238 239
		      gboolean click_closes, gboolean close_with_parent)
{
Jody Goldberg's avatar
Jody Goldberg committed
240
#if 0
Jody Goldberg's avatar
Jody Goldberg committed
241
	GtkWindow *parent = wbcg_toplevel (wbcg);
Jon K Hellan's avatar
Jon K Hellan committed
242
	DialogRunInfo *run_info = NULL;
Jody Goldberg's avatar
Jody Goldberg committed
243
	g_return_if_fail (GNOME_IS_DIALOG (dialog));
244
	if (parent != NULL) {
Jon K Hellan's avatar
Jon K Hellan committed
245
		run_info = g_new0 (DialogRunInfo, 1);
Jody Goldberg's avatar
Jody Goldberg committed
246 247
		run_info->parent_toplevel =
			gtk_widget_get_toplevel (GTK_WIDGET (parent));
Michael Meeks's avatar
Michael Meeks committed
248

Jon K Hellan's avatar
Jon K Hellan committed
249 250 251
		gnome_dialog_set_parent
			(GNOME_DIALOG (dialog),
			 GTK_WINDOW (run_info->parent_toplevel));
Jody Goldberg's avatar
Jody Goldberg committed
252 253
		gtk_window_set_destroy_with_parent  (GTK_WINDOW (dialog),
			close_with_parent);
Jon K Hellan's avatar
Jon K Hellan committed
254
	}
Jody Goldberg's avatar
Jody Goldberg committed
255
#endif
Jon K Hellan's avatar
Jon K Hellan committed
256 257 258

	gnome_dialog_set_close (GNOME_DIALOG (dialog), click_closes);

Jody Goldberg's avatar
Jody Goldberg committed
259 260
	if (!GTK_WIDGET_VISIBLE (GTK_WIDGET (dialog)))	/* Pop up the dialog */
		gtk_widget_show (GTK_WIDGET (dialog));
Jon K Hellan's avatar
Jon K Hellan committed
261 262
}

Chyla Zbigniew's avatar
Chyla Zbigniew committed
263
static GtkCTreeNode *
264 265 266
ctree_insert_error_info (GtkCTree *ctree, GtkCTreeNode *parent,
                         GtkCTreeNode *sibling, ErrorInfo *error,
                         gboolean expand)
Chyla Zbigniew's avatar
Chyla Zbigniew committed
267 268 269
{
	GtkCTreeNode *my_node, *last_child_node;
	gchar *message;
270
	gboolean child_expand;
Chyla Zbigniew's avatar
Chyla Zbigniew committed
271 272
	GList *details_list, *l;

273
	message = (gchar *) error_info_peek_message (error);
Chyla Zbigniew's avatar
Chyla Zbigniew committed
274
	if (message == NULL) {
275
		message = _("Multiple errors");
Chyla Zbigniew's avatar
Chyla Zbigniew committed
276 277
	}
	details_list = error_info_peek_details (error);
278 279 280
	my_node = gtk_ctree_insert_node (ctree, parent, sibling, &message, 0, NULL, NULL, NULL, NULL, details_list == NULL, expand);

	child_expand = details_list == NULL || details_list->next == NULL;
Chyla Zbigniew's avatar
Chyla Zbigniew committed
281 282
	last_child_node = NULL;
	for (l = details_list; l != NULL; l = l->next) {
283
		ErrorInfo *detail_error = l->data;
Chyla Zbigniew's avatar
Chyla Zbigniew committed
284

285 286
		last_child_node = ctree_insert_error_info (ctree, my_node, last_child_node,
		                                           detail_error, child_expand);
Chyla Zbigniew's avatar
Chyla Zbigniew committed
287 288 289 290 291 292
	}

	return my_node;
}

/**
293
 * gnumeric_error_info_dialog_show_full
Chyla Zbigniew's avatar
Chyla Zbigniew committed
294 295
 *
 */
296 297
static void
gnumeric_error_info_dialog_show_full (WorkbookControlGUI *wbcg, ErrorInfo *error)
Chyla Zbigniew's avatar
Chyla Zbigniew committed
298 299 300 301 302 303 304 305
{
	GtkWidget *dialog;
	GtkWidget *scrolled_window, *ctree;
	GtkCTreeNode *main_ctree_node;
	GtkWidget *button_close;

	g_return_if_fail (error != NULL);

306 307
	dialog = gnome_dialog_new (_("Detailed error message"), NULL);
	gtk_widget_set_usize (dialog, 600, 300);
Chyla Zbigniew's avatar
Chyla Zbigniew committed
308 309 310
	gtk_window_set_policy (GTK_WINDOW (dialog), FALSE, TRUE, FALSE);

	scrolled_window = gtk_scrolled_window_new (NULL, NULL);
311
	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
Chyla Zbigniew's avatar
Chyla Zbigniew committed
312
	ctree = gtk_ctree_new (1, 0);
313 314 315 316
	gtk_ctree_set_line_style (GTK_CTREE (ctree), GTK_CTREE_LINES_NONE);
	gtk_ctree_set_expander_style (GTK_CTREE (ctree), GTK_CTREE_EXPANDER_TRIANGLE);
	main_ctree_node = ctree_insert_error_info (GTK_CTREE (ctree), NULL, NULL, error, TRUE);
	gtk_clist_set_column_auto_resize (GTK_CLIST (ctree), 0, TRUE);
Chyla Zbigniew's avatar
Chyla Zbigniew committed
317
	gtk_container_add (GTK_CONTAINER (scrolled_window), ctree);
318 319
	gtk_widget_show_all (GTK_WIDGET (scrolled_window));
	gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (dialog)->vbox), scrolled_window, TRUE, TRUE, 0);
Chyla Zbigniew's avatar
Chyla Zbigniew committed
320 321 322 323 324 325

	gnome_dialog_append_button (GNOME_DIALOG (dialog), GNOME_STOCK_BUTTON_CLOSE);
	button_close = GTK_WIDGET (g_list_last (GNOME_DIALOG (dialog)->buttons)->data);
	GTK_WIDGET_SET_FLAGS (button_close, GTK_CAN_DEFAULT);

	gnome_dialog_set_close (GNOME_DIALOG (dialog), TRUE);
Jody Goldberg's avatar
Jody Goldberg committed
326
	gnumeric_dialog_run (wbcg, GTK_DIALOG (dialog));
Chyla Zbigniew's avatar
Chyla Zbigniew committed
327 328
}

Jody Goldberg's avatar
Jody Goldberg committed
329 330
#define GNUMERIC_RESPONSE_DETAILS	1

331 332 333 334 335 336 337 338 339 340
/**
 * gnumeric_error_info_dialog_show
 *
 */
void
gnumeric_error_info_dialog_show (WorkbookControlGUI *wbcg, ErrorInfo *error)
{
	GString *str;
	GList *details;
	gboolean has_extra_details;
Jody Goldberg's avatar
Jody Goldberg committed
341
	GtkWidget *dialog;
Morten Welinder's avatar
Morten Welinder committed
342

343 344 345 346
	str = g_string_new (error_info_peek_message (error));
	details = error_info_peek_details (error);
	if (g_list_length (details) == 1) {
		ErrorInfo *details_error = details->data;
Jody Goldberg's avatar
Jody Goldberg committed
347
		gchar const *s;
348 349 350 351 352 353 354

		s = error_info_peek_message (details_error);
		if (s != NULL) {
			g_string_append (str, "\n\n");
			g_string_append (str, s);
		}
		has_extra_details = error_info_peek_details (details_error) != NULL;
Jody Goldberg's avatar
Jody Goldberg committed
355
	} else
356
		has_extra_details = details != NULL;
Jody Goldberg's avatar
Jody Goldberg committed
357 358 359 360 361 362

	dialog = gtk_message_dialog_new (wbcg_toplevel (wbcg),
			GTK_DIALOG_DESTROY_WITH_PARENT,
			GTK_MESSAGE_ERROR,
			GTK_BUTTONS_NONE,
			str->str);
363 364
	g_string_free (str, TRUE);

Jody Goldberg's avatar
Jody Goldberg committed
365 366 367 368 369 370
	if (has_extra_details)
		gtk_dialog_add_button (GTK_DIALOG (dialog),
			_("Show details"), GNUMERIC_RESPONSE_DETAILS);
	gtk_dialog_add_button (GTK_DIALOG (dialog),
		GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
	gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CLOSE);
371 372 373 374 375

#warning FIXME : not needed when set_transient is finished
	gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE);
	gnumeric_set_transient (wbcg, GTK_WINDOW (dialog));

Jody Goldberg's avatar
Jody Goldberg committed
376
	if (gnumeric_dialog_run (wbcg, GTK_DIALOG (dialog)) == GNUMERIC_RESPONSE_DETAILS)
377 378 379
		gnumeric_error_info_dialog_show_full (wbcg, error);
}

380 381
/**
 * gnumeric_set_transient
382 383
 * @wbcg	: The calling window
 * @window      : the transient window
384 385
 *
 * Make the window a child of the workbook in the command context, if there is
386
 * one.
387 388
 * The function duplicates the positioning functionality in
 * gnome_dialog_set_parent, but does not require the transient window to be
Morten Welinder's avatar
Morten Welinder committed
389
 * a GnomeDialog.
390
 */
391
void
392
gnumeric_set_transient (WorkbookControlGUI *wbcg, GtkWindow *window)
393
{
394
	GtkWindow *toplevel;
Morten Welinder's avatar
Morten Welinder committed
395

396 397 398
	g_return_if_fail (IS_WORKBOOK_CONTROL_GUI (wbcg));
	g_return_if_fail (GTK_IS_WINDOW (window));

Jody Goldberg's avatar
Jody Goldberg committed
399
	toplevel = wbcg_toplevel (wbcg);
400 401
	gtk_window_set_transient_for (window, toplevel);

Jody Goldberg's avatar
Jody Goldberg committed
402 403
#warning what replaces these ?
#if 0
Morten Welinder's avatar
Morten Welinder committed
404
	gtk_window_set_position(window,
405 406
				gnome_preferences_get_dialog_position());
	if (gnome_preferences_get_dialog_centered()) {
Morten Welinder's avatar
Morten Welinder committed
407

408
		/* User wants us to center over toplevel */
Morten Welinder's avatar
Morten Welinder committed
409

410
		gint x, y, w, h, dialog_x, dialog_y;
Morten Welinder's avatar
Morten Welinder committed
411

412 413 414 415 416
		if ( ! GTK_WIDGET_VISIBLE(toplevel)) return; /* Can't get its
								size/pos */

		/* Throw out other positioning */
		gtk_window_set_position(toplevel, GTK_WIN_POS_NONE);
Morten Welinder's avatar
Morten Welinder committed
417

418 419
		gdk_window_get_origin (GTK_WIDGET(toplevel)->window, &x, &y);
		gdk_window_get_size   (GTK_WIDGET(toplevel)->window, &w, &h);
Morten Welinder's avatar
Morten Welinder committed
420

421
		/* The problem here is we don't know how big the dialog is.
Morten Welinder's avatar
Morten Welinder committed
422
		   So "centered" isn't really true. We'll go with
423
		   "kind of more or less on top" */
Morten Welinder's avatar
Morten Welinder committed
424

425 426
		dialog_x = x + w/4;
		dialog_y = y + h/4;
Morten Welinder's avatar
Morten Welinder committed
427 428

		gtk_widget_set_uposition(GTK_WIDGET(window), dialog_x, dialog_y);
429
	}
Jody Goldberg's avatar
Jody Goldberg committed
430
#endif
431 432
}

433 434
typedef struct {
	WorkbookControlGUI *wbcg;
435
	char const *key;
436 437 438 439 440
} KeyedDialogContext;

static void
cb_remove_object_data (GtkWidget *w, KeyedDialogContext *ctxt)
{
Jody Goldberg's avatar
Jody Goldberg committed
441
	g_return_if_fail (g_object_get_data (G_OBJECT (ctxt->wbcg), ctxt->key));
442

Jody Goldberg's avatar
Jody Goldberg committed
443
	g_object_set_data (G_OBJECT (ctxt->wbcg), ctxt->key, NULL);
444 445 446 447 448 449 450 451 452 453 454 455 456 457 458
	g_free (ctxt);
}

/**
 * gnumeric_keyed_dialog
 *
 * @wbcg    A WorkbookControlGUI
 * @dialog  A transient window
 * @key     A key to identify the dialog
 *
 * Make dialog a transient child of wbcg, attaching to wbcg object data to
 * identify the dialog. The object data makes it possible to ensure that
 * only one dialog of a kind can be displayed for a wbcg. Deallocation of
 * the object data is managed here.  */
void
Morten Welinder's avatar
Morten Welinder committed
459
gnumeric_keyed_dialog (WorkbookControlGUI *wbcg, GtkWindow *dialog, const char *key)
460 461
{
	KeyedDialogContext *ctxt;
Morten Welinder's avatar
Morten Welinder committed
462

463 464 465
	g_return_if_fail (IS_WORKBOOK_CONTROL_GUI (wbcg));
	g_return_if_fail (GTK_IS_WINDOW (dialog));
	g_return_if_fail (key != NULL);
Morten Welinder's avatar
Morten Welinder committed
466

467 468 469 470 471
	gnumeric_set_transient (wbcg, dialog);

	ctxt = g_new (KeyedDialogContext, 1);
	ctxt->wbcg = wbcg;
	ctxt->key  = key;
Jody Goldberg's avatar
Jody Goldberg committed
472
	g_object_set_data (G_OBJECT (wbcg), key, dialog);
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491

	gtk_signal_connect (
		GTK_OBJECT (dialog), "destroy",
		GTK_SIGNAL_FUNC (cb_remove_object_data), ctxt);
}

/**
 * gnumeric_dialog_raise_if_exists
 *
 * @wbcg    A WorkbookControlGUI
 * @key     A key to identify the dialog
 *
 * Raise the dialog identified by key if it is registered on the wbcg.
 * Returns TRUE if dialog found, FALSE if not.
 */
gboolean
gnumeric_dialog_raise_if_exists (WorkbookControlGUI *wbcg, char *key)
{
	GtkWidget *dialog;
Morten Welinder's avatar
Morten Welinder committed
492

493 494 495 496
	g_return_val_if_fail (wbcg != NULL, FALSE);
	g_return_val_if_fail (key != NULL, FALSE);

	/* Ensure we only pop up one copy per workbook */
Jody Goldberg's avatar
Jody Goldberg committed
497
	dialog = g_object_get_data (G_OBJECT (wbcg), key);
498 499 500 501 502 503 504
	if (dialog && GTK_IS_WINDOW (dialog)) {
		gdk_window_raise (dialog->window);
		return TRUE;
	} else
		return FALSE;
}

505 506
/**
 * gnumeric_editable_enters: Make the "activate" signal of an editable click
Jody Goldberg's avatar
Jody Goldberg committed
507
 * the default dialog button.
508 509 510 511 512 513 514 515 516
 * @window: dialog to affect.
 * @editable: Editable to affect.
 *
 * This is a literal copy of gnome_dialog_editable_enters, but not restricted
 * to GnomeDialogs.
 *
 * Normally if there's an editable widget (such as #GtkEntry) in your
 * dialog, pressing Enter will activate the editable rather than the
 * default dialog button. However, in most cases, the user expects to
Jody Goldberg's avatar
Jody Goldberg committed
517
 * type something in and then press enter to close the dialog. This
518
 * function enables that behavior.
Jody Goldberg's avatar
Jody Goldberg committed
519
 *
520
 **/
521 522
void
gnumeric_editable_enters (GtkWindow *window, GtkEditable *editable)
523 524 525 526 527
{
	g_return_if_fail(window != NULL);
	g_return_if_fail(editable != NULL);
	g_return_if_fail(GTK_IS_WINDOW(window));
	g_return_if_fail(GTK_IS_EDITABLE(editable));
Jody Goldberg's avatar
Jody Goldberg committed
528

529 530
	gtk_signal_connect_object
		(GTK_OBJECT(editable), "activate",
Jody Goldberg's avatar
Jody Goldberg committed
531
		 GTK_SIGNAL_FUNC(gtk_window_activate_default),
532 533 534
		 GTK_OBJECT(window));
}

535 536 537 538
/**
 * gnumeric_combo_enters:
 * @window: dialog to affect
 * @combo: Combo to affect
Jody Goldberg's avatar
Jody Goldberg committed
539
 *
540 541 542 543 544 545 546 547 548 549 550 551 552 553 554
 * This calls upon gnumeric_editable_enters so the dialog
 * is closed instead of the list with options popping up
 * when enter is pressed
 **/
void
gnumeric_combo_enters (GtkWindow *window, GtkCombo *combo)
{
	g_return_if_fail (window != NULL);
	g_return_if_fail (combo != NULL);

	gtk_combo_disable_activate (combo);
	gnumeric_editable_enters (window,
				  GTK_EDITABLE (combo->entry));
}

555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581
/**
 * gnumeric_toolbar_insert_with_eventbox
 * @toolbar               toolbar
 * @widget                widget to insert
 * @tooltip_text          tooltip text
 * @tooltip_private_text  longer tooltip text
 * @position              widget position in toolbar
 *
 * Packs widget in an eventbox and adds the eventbox to toolbar.
 * This lets a windowless widget (e.g. combo box) have tooltips.
 **/
void
gnumeric_toolbar_insert_with_eventbox (GtkToolbar *toolbar, GtkWidget  *widget,
				       const char *tooltip_text,
				       const char *tooltip_private_text,
				       gint        position)
{
	GtkWidget *eventbox;

	g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
	g_return_if_fail (widget != NULL);
	g_return_if_fail (position >= 0);
	g_return_if_fail (position <= toolbar->num_children);

	/* An event box to receive events - this is a requirement for having
           tooltips */
	eventbox = gtk_event_box_new ();
582
	gtk_widget_show (widget);
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612
	gtk_container_add (GTK_CONTAINER (eventbox), widget);
	gtk_widget_show (eventbox);
	gtk_toolbar_insert_widget (GTK_TOOLBAR (toolbar), eventbox,
				   tooltip_text, tooltip_private_text,
				   position);
}

/**
 * gnumeric_toolbar_append_with_eventbox
 * @toolbar               toolbar
 * @widget                widget to insert
 * @tooltip_text          tooltip text
 * @tooltip_private_text  longer tooltip text
 *
 * Packs widget in an eventbox and adds the eventbox to toolbar.
 * This lets a windowless widget (e.g. combo box) have tooltips.
 **/
void
gnumeric_toolbar_append_with_eventbox (GtkToolbar *toolbar, GtkWidget  *widget,
				       const char *tooltip_text,
				       const char *tooltip_private_text)
{
	GtkWidget *eventbox;

	g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
	g_return_if_fail (widget != NULL);

	/* An event box to receive events - this is a requirement for having
           tooltips */
	eventbox = gtk_event_box_new ();
613
	gtk_widget_show (widget);
614 615 616 617 618 619
	gtk_container_add (GTK_CONTAINER (eventbox), widget);
	gtk_widget_show (eventbox);
	gtk_toolbar_append_widget (GTK_TOOLBAR (toolbar), eventbox,
				   tooltip_text, tooltip_private_text);
}

620 621 622
int
gtk_radio_group_get_selected (GSList *radio_group)
{
623 624
	GSList *l;
	int i, c;
625 626

	g_return_val_if_fail (radio_group != NULL, 0);
Morten Welinder's avatar
Morten Welinder committed
627

628
	c = g_slist_length (radio_group);
Morten Welinder's avatar
Morten Welinder committed
629

630
	for (i = 0, l = radio_group; l; l = l->next, i++){
Arturo Espinosa's avatar
Arturo Espinosa committed
631
		GtkRadioButton *button = l->data;
632

Arturo Espinosa's avatar
Arturo Espinosa committed
633
		if (GTK_TOGGLE_BUTTON (button)->active)
634
			return c - i - 1;
635
	}
636 637

	return 0;
638
}
639

640 641 642 643 644 645 646 647 648 649 650 651 652

int
gnumeric_glade_group_value (GladeXML *gui, const char *group[])
{
	int i;
	for (i = 0; group[i]; i++) {
		GtkWidget *w = glade_xml_get_widget (gui, group[i]);
		if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (w)))
			return i;
	}
	return -1;
}

653 654 655 656 657 658
static void
kill_popup_menu (GtkWidget *widget, GtkMenu *menu)
{
	g_return_if_fail (menu != NULL);
	g_return_if_fail (GTK_IS_MENU (menu));

Morten Welinder's avatar
Morten Welinder committed
659
	gtk_object_unref (GTK_OBJECT (menu));
660 661 662 663 664 665 666
}

void
gnumeric_popup_menu (GtkMenu *menu, GdkEventButton *event)
{
	g_return_if_fail (menu != NULL);
	g_return_if_fail (GTK_IS_MENU (menu));
Morten Welinder's avatar
Morten Welinder committed
667

Jody Goldberg's avatar
Jody Goldberg committed
668 669 670
	gtk_object_ref (GTK_OBJECT (menu));
	gtk_object_sink (GTK_OBJECT (menu));

Jody Goldberg's avatar
Jody Goldberg committed
671 672
	gtk_signal_connect (GTK_OBJECT (menu), "hide",
		GTK_SIGNAL_FUNC (kill_popup_menu), menu);
673 674 675 676 677 678

	/* Do NOT pass the button used to create the menu.
	 * instead pass 0.  Otherwise bringing up a menu with
	 * the right button will disable clicking on the menu with the left.
	 */
	gtk_menu_popup (menu, NULL, NULL, 0, NULL, 0, event->time);
679
}
680

681 682 683
/*
 * Helper for gnumeric_clist_moveto. Ensures that we move in the same way
 * whether direct or from a callback.
Jody Goldberg's avatar
Jody Goldberg committed
684
 */
685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712
static void
clist_moveto (GtkCList *clist, gint row)
{
	gtk_clist_moveto (clist, row, 0, 0.1, 0.0);
	clist->focus_row = row;
}

/*
 * map handler. Disconnects itself and moves the list.
 */
static void
cb_clist_moveto (GtkWidget *clist, gpointer row)
{
	gtk_signal_disconnect_by_func (GTK_OBJECT (clist),
				       GTK_SIGNAL_FUNC (cb_clist_moveto),
				       row);

	clist_moveto (GTK_CLIST (clist), GPOINTER_TO_INT (row));
}

/*
 * gnumeric_clist_moveto
 * @clist   clist
 * @row     row

 *
 * Scroll the viewing area of the list to the given row.
 * We do it this way because gtk_clist_moveto only works if the list is
Jody Goldberg's avatar
Jody Goldberg committed
713
 * mapped.
714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735
 */
void
gnumeric_clist_moveto (GtkCList *clist, gint row)
{
	if (GTK_WIDGET_DRAWABLE (clist))
		clist_moveto (clist, row);
	else
		gtk_signal_connect (GTK_OBJECT (clist), "map",
				    GTK_SIGNAL_FUNC (cb_clist_moveto),
				    GINT_TO_POINTER (row));
}

/*
 * gnumeric_clist_make_selection_visible
 * @clist   clist
 *
 * Scroll the viewing area of the list to the first selected row.
 */
void
gnumeric_clist_make_selection_visible (GtkCList *clist)
{
	guint selection_length;
Jody Goldberg's avatar
Jody Goldberg committed
736

737 738 739 740 741 742 743 744 745
	g_return_if_fail(GTK_IS_CLIST(clist));

	selection_length = g_list_length (clist->selection);
	if (selection_length > 0) {
		gint row = (gint) clist->selection->data;
		gnumeric_clist_moveto (clist, row);
	}
}

746 747 748
/**
 * gnumeric_option_menu_get_selected_index:
 * @optionmenu: a gtkoptionmenu
Jody Goldberg's avatar
Jody Goldberg committed
749
 *
750 751
 * Tries to find out (in an ugly way) the selected
 * item in @optionsmenu
Jody Goldberg's avatar
Jody Goldberg committed
752
 *
753 754 755 756 757 758 759 760 761 762 763 764
 * Return value: the selected index or -1 on error (or no selection?)
 **/
int
gnumeric_option_menu_get_selected_index (GtkOptionMenu *optionmenu)
{
	GtkMenu *menu;
	GtkMenuItem *selected;
	GList *iterator;
	int index = -1;
	int i = 0;

	g_return_val_if_fail (optionmenu != NULL, -1);
Jody Goldberg's avatar
Jody Goldberg committed
765

766 767 768
	menu = (GtkMenu *) gtk_option_menu_get_menu (optionmenu);
	iterator = GTK_MENU_SHELL (menu)->children;
	selected = (GtkMenuItem *) gtk_menu_get_active (menu);
Jody Goldberg's avatar
Jody Goldberg committed
769

770
	while (iterator) {
Jody Goldberg's avatar
Jody Goldberg committed
771

772
		if (iterator->data == selected) {
Jody Goldberg's avatar
Jody Goldberg committed
773

774 775 776
			index = i;
			break;
		}
Jody Goldberg's avatar
Jody Goldberg committed
777

778 779 780 781 782 783 784
		iterator = iterator->next;
		i++;
	}

	return index;
}

785 786 787 788 789
GtkWidget *
gnumeric_create_tooltip (void)
{
	GtkWidget *tip, *label, *frame;
	static GtkRcStyle*rc_style = NULL;
Jody Goldberg's avatar
Jody Goldberg committed
790

791 792
	if (rc_style == NULL) {
		int i;
Arturo Espinosa's avatar
Arturo Espinosa committed
793
		rc_style = gtk_rc_style_new ();
794 795 796

		for (i = 5; --i >= 0 ; ) {
			rc_style->color_flags[i] = GTK_RC_BG;
Jody Goldberg's avatar
Jody Goldberg committed
797
			e_color_alloc_name (NULL, "LightYellow",  &rc_style->bg[i]);
798 799 800 801 802 803 804 805 806 807 808 809 810
		}
	}

	tip = gtk_window_new (GTK_WINDOW_POPUP);
	if (rc_style != NULL)
		gtk_widget_modify_style (tip, rc_style);

	frame = gtk_frame_new (NULL);
	gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT);
	label = gtk_label_new ("");

	gtk_container_add (GTK_CONTAINER (tip), frame);
	gtk_container_add (GTK_CONTAINER (frame), label);
Jody Goldberg's avatar
Jody Goldberg committed
811

812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829
	return label;
}

void
gnumeric_position_tooltip (GtkWidget *tip, int horizontal)
{
	GtkRequisition req;
	int  x, y;

	gtk_widget_size_request (tip, &req);
	gdk_window_get_pointer (NULL, &x, &y, NULL);
	if (horizontal){
		x = x - req.width/2;
		y = y - req.height - 20;
	} else {
		x = x - req.width - 20;
		y = y - req.height/2;
	}
Jody Goldberg's avatar
Jody Goldberg committed
830 831 832 833 834

	if (x < 0)
		x = 0;
	if (y < 0)
		y = 0;
835 836 837
	gtk_widget_set_uposition (gtk_widget_get_toplevel (tip), x, y);
}

838
GladeXML *
839
gnumeric_glade_xml_new (WorkbookControlGUI *wbcg, char const * gladefile)
840 841
{
	GladeXML *gui;
842 843
	char *d = gnumeric_sys_glade_dir ();
	char *f = g_concat_dir_and_file (d, gladefile);
Jody Goldberg's avatar
Jody Goldberg committed
844
	gui = glade_xml_new (f, NULL, "gnumeric");
845 846

	/* Onlt report errors if the context is non-null */
847
	if (gui == NULL && wbcg != NULL) {
848
		char *msg = g_strdup_printf (_("Unable to open file '%s'"), f);
849
		gnumeric_error_system (COMMAND_CONTEXT (wbcg), msg);
850 851 852
		g_free (msg);
	}
	g_free (f);
853
	g_free (d);
854 855 856

	return gui;
}
857 858 859 860 861 862 863

static gint
cb_non_modal_dialog_keypress (GtkWidget *w, GdkEventKey *e)
{
	if(e->keyval == GDK_Escape) {
		gtk_widget_destroy (w);
		return TRUE;
Jody Goldberg's avatar
Jody Goldberg committed
864
	}
865 866 867 868 869

	return FALSE;
}

void
870
gnumeric_non_modal_dialog (WorkbookControlGUI *wbcg, GtkWindow *dialog)
871
{
872 873
	gnumeric_set_transient (wbcg, dialog);

874 875 876
	gtk_signal_connect (GTK_OBJECT (dialog), "key-press-event",
			    (GtkSignalFunc) cb_non_modal_dialog_keypress, NULL);
}
877 878 879 880 881 882 883 884

#ifdef ENABLE_BONOBO
/*
 * gnumeric_inject_widget_into_bonoboui :
 *
 * A quick utility routine to inject a widget into a menu/toolbar.
 */
void
885
gnumeric_inject_widget_into_bonoboui (WorkbookControlGUI *wbcg, GtkWidget *widget, char const *path)
886 887 888 889 890
{
	BonoboControl *control;

	gtk_widget_show_all (widget);
	control = bonobo_control_new (widget);
Michael Meeks's avatar
Michael Meeks committed
891
	bonobo_ui_component_object_set (
892
		wbcg->uic, path,
Jody Goldberg's avatar
Jody Goldberg committed
893
		BONOBO_OBJREF (control),
894
		NULL);
895 896
}
#endif
897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913

static void
popup_item_activate (GtkWidget *item, gpointer *user_data)
{
	GnumericPopupMenuElement const *elem =
		gtk_object_get_data (GTK_OBJECT (item), "descriptor");
	GnumericPopupMenuHandler handler =
		gtk_object_get_data (GTK_OBJECT (item), "handler");

	g_return_if_fail (elem != NULL);
	g_return_if_fail (handler != NULL);

	if (handler (elem, user_data))
		gtk_widget_destroy (gtk_widget_get_toplevel (item));
}

void
Jody Goldberg's avatar
Jody Goldberg committed
914 915 916 917 918 919
gnumeric_create_popup_menu_list (GSList *elements,
				 GnumericPopupMenuHandler handler,
				 gpointer user_data,
				 int display_filter,
				 int sensitive_filter,
				 GdkEventButton *event)
920 921 922 923 924
{
	GtkWidget *menu, *item;

	menu = gtk_menu_new ();

Jody Goldberg's avatar
Jody Goldberg committed
925 926 927 928
	for (; elements != NULL ; elements = elements->next) {
		GnumericPopupMenuElement const *element = elements->data;
		char const * const name = element->name;
		char const * const pix_name = element->pixmap;
929 930 931

		item = NULL;

Jody Goldberg's avatar
Jody Goldberg committed
932 933
		if (element->display_filter != 0 &&
		    !(element->display_filter & display_filter))
934 935 936
			continue;

		if (name != NULL && *name != '\0') {
Jody Goldberg's avatar
Jody Goldberg committed
937
			item = gtk_image_menu_item_new_with_mnemonic (_(name));
Jody Goldberg's avatar
Jody Goldberg committed
938 939
			if (element->sensitive_filter != 0 &&
			    (element->sensitive_filter & sensitive_filter))
940
				gtk_widget_set_sensitive (GTK_WIDGET (item), FALSE);
Jody Goldberg's avatar
Jody Goldberg committed
941 942 943 944 945 946 947 948
			if (pix_name != NULL) {
				GtkWidget *image = gtk_image_new_from_stock (pix_name,
                                        GTK_ICON_SIZE_MENU);
				gtk_widget_show (image);
				gtk_image_menu_item_set_image (
					GTK_IMAGE_MENU_ITEM (item),
					image);
			}
949
		} else {
Jody Goldberg's avatar
Jody Goldberg committed
950
			/* seperator */
951
			item = gtk_menu_item_new ();
952 953
			gtk_widget_set_sensitive (item, FALSE);
		}
954

Jody Goldberg's avatar
Jody Goldberg committed
955
		if (element->index != 0) {
956 957 958 959 960
			gtk_signal_connect (
				GTK_OBJECT (item), "activate",
				GTK_SIGNAL_FUNC (&popup_item_activate),
				user_data);
			gtk_object_set_data (
Jody Goldberg's avatar
Jody Goldberg committed
961
				GTK_OBJECT (item), "descriptor", (gpointer)(element));
962 963 964 965 966 967 968 969 970 971
			gtk_object_set_data (
				GTK_OBJECT (item), "handler", (gpointer)handler);
		}

		gtk_widget_show (item);
		gtk_menu_append (GTK_MENU (menu), item);
	}

	gnumeric_popup_menu (GTK_MENU (menu), event);
}
972

Jody Goldberg's avatar
Jody Goldberg committed
973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991
void
gnumeric_create_popup_menu (GnumericPopupMenuElement const *elements,
			    GnumericPopupMenuHandler handler,
			    gpointer user_data,
			    int display_filter, int sensitive_filter,
			    GdkEventButton *event)
{
	int i;
	GSList *tmp = NULL;

	for (i = 0; elements [i].name != NULL; i++)
		tmp = g_slist_prepend (tmp, (gpointer)(elements + i));

	tmp = g_slist_reverse (tmp);
	gnumeric_create_popup_menu_list (tmp, handler, user_data,
		display_filter, sensitive_filter, event);
	g_slist_free (tmp);
}

992 993 994 995 996 997 998 999 1000 1001 1002 1003
/**
 * color_combo_get_style_color :
 *
 * A utility wrapper to map between gal's colour combo and gnumeric's StyleColors.
 */
StyleColor *
color_combo_get_style_color (GtkWidget *color_combo)
{
	GdkColor *gdk = color_combo_get_color (COLOR_COMBO (color_combo));
	return (gdk == NULL) ? NULL
		    : style_color_new (gdk->red, gdk->green, gdk->blue);
}
1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017

GtkWidget *
gnumeric_toolbar_new (WorkbookControlGUI *wbcg,
		      GnomeUIInfo *info,
		      char const *name,
		      gint band_num,
		      gint band_position,
		      gint offset)
{
	GnomeApp *app = GNOME_APP (wbcg->toplevel);
	GtkWidget *tbar;

	g_return_val_if_fail (info != NULL, NULL);

Jody Goldberg's avatar
Jody Goldberg committed
1018 1019
	tbar = gtk_toolbar_new ();
	gtk_toolbar_set_orientation (GTK_TOOLBAR (tbar), GTK_ORIENTATION_HORIZONTAL);
1020 1021 1022 1023
	gnome_app_fill_toolbar_with_data (GTK_TOOLBAR (tbar), info,
		app->accel_group, wbcg);

	gnome_app_add_toolbar (GNOME_APP (wbcg->toplevel), GTK_TOOLBAR (tbar),
Jody Goldberg's avatar
Jody Goldberg committed
1024
		name, BONOBO_DOCK_ITEM_BEH_NORMAL, BONOBO_DOCK_TOP,
1025
		band_num, band_position, offset);
Jody Goldberg's avatar
Jody Goldberg committed
1026
	gtk_toolbar_set_style (GTK_TOOLBAR (tbar), GTK_TOOLBAR_ICONS);
1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060

	return tbar;
}

GtkWidget *
gnumeric_toolbar_get_widget (GtkToolbar *toolbar, int pos)
{
	GtkToolbarChild *child;
	GList *children;
	int i;

	g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), NULL);
	g_return_val_if_fail (pos > 0, NULL);

	children = GTK_TOOLBAR (toolbar)->children;

	if (!children)
		return NULL;

	i = 0;
	do {
		child = children->data;
		children = children->next;

		if (child->type == GTK_TOOLBAR_CHILD_SPACE)
			continue;

		if (i == pos)
			return child->widget;
		i++;
	} while (children);

	return NULL;
}
1061 1062 1063 1064 1065

void
gnumeric_help_display (char const *link)
{
        g_return_if_fail (link != NULL);
Jody Goldberg's avatar
Jody Goldberg committed
1066
	gnome_help_display ("gnumeric", link, NULL);
1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080
}

static void
gnumeric_help_pbox_goto (void *ignore, int ignore2, char const *link)
{
	gnumeric_help_display (link);
}

void
gnumeric_pbox_init_help (GtkWidget *dialog, char const *link)
{
	gtk_signal_connect (GTK_OBJECT (dialog), "help",
		GTK_SIGNAL_FUNC (gnumeric_help_pbox_goto), (gpointer)link);
}
Jody Goldberg's avatar
Jody Goldberg committed
1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101

char *
gnumeric_textview_get_text (GtkTextView *text_view)
{
	GtkTextIter    start, end;
	GtkTextBuffer *buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));

	g_return_val_if_fail (buf != NULL, NULL);

	gtk_text_buffer_get_start_iter (buf, &start);
	gtk_text_buffer_get_end_iter (buf, &end);
	return gtk_text_buffer_get_text (buf, &start, &end, FALSE);
}

void
gnumeric_textview_set_text (GtkTextView *text_view, char const *txt)
{
	gtk_text_buffer_set_text (
		gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view)),
		txt, -1);
}
1102 1103 1104 1105 1106 1107 1108 1109 1110 <