gnumeric-util.c 2.46 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
/*
 * gnumeric-util.c:  Various GUI utility functions. 
 *
 * Author:
 *  Miguel de Icaza (miguel@gnu.org)
 *
 */
#include <config.h>
#include <gnome.h>
#include "gnumeric.h"
#include "gnumeric-util.h"

void
gnumeric_notice (char *str)
{
	GtkWidget *dialog;
	GtkWidget *label;

	label = gtk_label_new (str);
	dialog = gnome_dialog_new (_("Notice"), GNOME_STOCK_BUTTON_OK, NULL);
	gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (dialog)->vbox), label, TRUE, TRUE, 0);
	gtk_widget_show (label);
	gnome_dialog_run_modal (GNOME_DIALOG (dialog));
	gtk_object_destroy (GTK_OBJECT (dialog));
}

27 28 29
int
gtk_radio_group_get_selected (GSList *radio_group)
{
30 31
	GSList *l;
	int i, c;
32 33 34

	g_return_val_if_fail (radio_group != NULL, 0);
	
35 36 37
	c = g_slist_length (radio_group);
		
	for (i = 0, l = radio_group; l; l = l->next, i++){
38
		GtkRadioButton *button = l->data;
39

40
		if (GTK_TOGGLE_BUTTON (button)->active)
41
			return c - i - 1;
42
	}
43 44

	return 0;
45
}
46 47 48 49 50 51 52

void
gtk_radio_button_select (GSList *group, int n)
{
	GSList *l;
	int len = g_slist_length (group);
	
Arturo Espinosa's avatar
Arturo Espinosa committed
53 54
	l = g_slist_nth (group, len - n - 1);
	gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (l->data), 1);
55
}
56 57 58 59 60 61 62 63 64 65 66

static void
popup_menu_item_activated (GtkWidget *item, void *value)
{
	int *dest = gtk_object_get_user_data (GTK_OBJECT (item));

	*dest = GPOINTER_TO_INT (value);
	gtk_main_quit ();
}

int
67
run_popup_menu (GdkEvent *event, int button, char **strings)
68 69 70 71
{
	GtkWidget *menu;
	int i;

72 73 74
	g_return_val_if_fail (event != NULL, -1);
	g_return_val_if_fail (strings != NULL, -1);

75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
	/* Create the popup menu */
	menu = gtk_menu_new ();
	for (i = 0;*strings; strings++, i++){
		GtkWidget *item;

		item = gtk_menu_item_new_with_label (_(*strings));
		
		gtk_widget_show (item);
		gtk_signal_connect (
			GTK_OBJECT (item), "activate",
			GTK_SIGNAL_FUNC (popup_menu_item_activated), GINT_TO_POINTER (i));

		/* Pass a pointer where we want the result stored */
		gtk_object_set_user_data (GTK_OBJECT (item), &i);
		
		gtk_menu_append (GTK_MENU (menu), item);
	}

	i = -1;
	
	/* Configure it: */
	gtk_signal_connect (GTK_OBJECT (menu), "deactivate",
			    GTK_SIGNAL_FUNC (gtk_main_quit), NULL);

	/* popup the menu */
	gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
			event->button.button, event->button.time);
	gtk_main ();

	gtk_widget_destroy (menu);
	
	return i;
}
108 109 110 111 112 113 114 115 116 117 118 119

gboolean
range_contains (Range *range, int col, int row)
{
	if ((col >= range->start_col) &&
	    (col <= range->end_col)   &&
	    (row >= range->start_row) &&
	    (row <= range->end_row))
		return TRUE;

	return FALSE;
}