gui-util.h 6.52 KB
Newer Older
1 2 3
/* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
#ifndef _GNM_GUI_UTIL_H_
# define _GNM_GUI_UTIL_H_
4

5
#include "gnumeric-fwd.h"
6
#include <goffice/goffice.h>
Morten Welinder's avatar
Morten Welinder committed
7
#include "numbers.h"
8

9 10
G_BEGIN_DECLS

11
#define GNM_ACTION_DEF(name)			\
12
	void name (GtkAction *a, WBCGtk *wbcg)
Jody Goldberg's avatar
Jody Goldberg committed
13

Morten Welinder's avatar
Morten Welinder committed
14 15
GtkWidget* gnm_go_error_info_dialog_create (GOErrorInfo *error);
void       gnm_go_error_info_dialog_show (GtkWindow *parent,
16
					       GOErrorInfo *error);
Morten Welinder's avatar
Morten Welinder committed
17
void       gnm_go_error_info_list_dialog_show (GtkWindow *parent,
18
						    GSList *errs);
Morten Welinder's avatar
Morten Welinder committed
19
void       gnm_restore_window_geometry (GtkWindow *dialog,
20
					     const char *key);
Morten Welinder's avatar
Morten Welinder committed
21
void       gnm_keyed_dialog (WBCGtk *wbcg,
Morten Welinder's avatar
Morten Welinder committed
22
				  GtkWindow *dialog,
23
				  char const *key);
Morten Welinder's avatar
Morten Welinder committed
24
gpointer   gnm_dialog_raise_if_exists (WBCGtk *wbcg,
25
					    char const *key);
Morten Welinder's avatar
Morten Welinder committed
26
void       gnm_editable_enters	(GtkWindow *window, GtkWidget *editable);
27

28
/* Utility routine as Gtk does not have any decent routine to do this */
29
int gnm_gtk_radio_group_get_selected (GSList *radio_group);
30
/* Utility routine as libglade does not have any decent routine to do this */
31
int gnm_gui_group_value (gpointer gui, char const * const group[]);
32

Jody Goldberg's avatar
Jody Goldberg committed
33
/* Use this on menus that are popped up */
34
void gnumeric_popup_menu (GtkMenu *menu, GdkEvent *event);
35

36
/*
37
 * Pseudo-tooltip support code.
38
 */
Morten Welinder's avatar
Morten Welinder committed
39
void        gnm_position_tooltip (GtkWidget *tip, int px, int py,
40
				       gboolean horizontal);
Morten Welinder's avatar
Morten Welinder committed
41 42
GtkWidget  *gnm_create_tooltip (GtkWidget *ref_widget);
GtkWidget  *gnm_convert_to_tooltip (GtkWidget *ref_widget,
43
					 GtkWidget *widget);
44

45
GtkBuilder *gnm_gtk_builder_load (char const *uifile, char const *domain,
46
				 GOCmdContext *cc);
47

48
typedef struct {
49 50
	char const *name;
	char const *pixmap;
51 52 53 54
	int display_filter;
	int sensitive_filter;

	int index;
55 56

	char *allocated_name;
Morten Welinder's avatar
Morten Welinder committed
57
} GnmPopupMenuElement;
58

Morten Welinder's avatar
Morten Welinder committed
59
typedef void (*GnmPopupMenuHandler) (GnmPopupMenuElement const *e,
60
					  gpointer user_data);
61

Morten Welinder's avatar
Morten Welinder committed
62 63
void gnm_create_popup_menu (GnmPopupMenuElement const *elements,
				 GnmPopupMenuHandler handler,
64 65 66
				 gpointer user_data,
				 int display_filter,
				 int sensitive_filter,
67
				 GdkEvent *event);
68

Morten Welinder's avatar
Morten Welinder committed
69
#define gnm_filter_modifiers(a) ((a) & (GDK_MODIFIER_MASK & (~(GDK_LOCK_MASK|GDK_MOD2_MASK|GDK_MOD5_MASK))))
70

71
void gnm_init_help_button	(GtkWidget *w, char const *lnk);
72

Morten Welinder's avatar
Morten Welinder committed
73 74 75
char *gnm_textbuffer_get_text (GtkTextBuffer *buf);
char *gnm_textview_get_text (GtkTextView *text_view);
void  gnm_textview_set_text (GtkTextView *text_view, char const *txt);
Morten Welinder's avatar
Morten Welinder committed
76
void  gnm_load_pango_attributes_into_buffer (PangoAttrList  *markup,
77 78
					     GtkTextBuffer *buffer,
					     gchar const *str);
79
PangoAttrList *gnm_get_pango_attributes_from_buffer (GtkTextBuffer *buffer);
Jody Goldberg's avatar
Jody Goldberg committed
80

81 82
void focus_on_entry (GtkEntry *entry);

83 84
/* WARNING : These do not handle dates correctly
 * We should be passing in a DateConvention */
85 86
#define entry_to_float(entry, the_float, update)	\
	entry_to_float_with_format (entry, the_float, update, NULL)
87 88 89 90 91 92 93 94 95
gboolean entry_to_float_with_format (GtkEntry *entry,
				     gnm_float *the_float,
				     gboolean update,
				     GOFormat const *format);
gboolean entry_to_float_with_format_default (GtkEntry *entry,
					     gnm_float *the_float,
					     gboolean update,
					     GOFormat const *format,
					     gnm_float num);
96
gboolean entry_to_int	(GtkEntry *entry, gint *the_int, gboolean update);
97
void	 float_to_entry	(GtkEntry *entry, gnm_float the_float);
98
void	 int_to_entry	(GtkEntry *entry, gint the_int);
99

Morten Welinder's avatar
Morten Welinder committed
100 101
void gnm_link_button_and_entry (GtkWidget *button, GtkWidget *entry);

Morten Welinder's avatar
Morten Welinder committed
102 103
void gnm_widget_set_cursor_type (GtkWidget *w, GdkCursorType ct);
void gnm_widget_set_cursor (GtkWidget *w, GdkCursor *ct);
104

Morten Welinder's avatar
Morten Welinder committed
105 106
int gnm_widget_measure_string (GtkWidget *w, const char *s);

Morten Welinder's avatar
Morten Welinder committed
107
GtkWidget * gnm_message_dialog_create (GtkWindow * parent,
108 109 110 111
                                            GtkDialogFlags flags,
                                            GtkMessageType type,
                                            char const *primary_message,
                                            char const *secondary_message);
112

113
typedef gboolean (*gnm_iter_search_t) (GtkTreeModel *model, GtkTreeIter* iter);
114

115 116 117 118 119 120
typedef enum {
	GNM_DIALOG_DESTROY_SHEET_ADDED = 0x01,
	GNM_DIALOG_DESTROY_SHEET_REMOVED = 0x02,
	GNM_DIALOG_DESTROY_SHEET_RENAMED = 0x04,
	GNM_DIALOG_DESTROY_SHEETS_REORDERED = 0x08,
	GNM_DIALOG_DESTROY_CURRENT_SHEET_REMOVED = 0x100,
121
	GNM_DIALOG_DESTROY_CURRENT_SHEET_RENAMED = 0x200
122 123 124
} GnmDialogDestroyOptions;

void gnm_dialog_setup_destroy_handlers (GtkDialog *dialog,
125
					WBCGtk *wbcg,
126
					GnmDialogDestroyOptions what);
127

128 129
void gnm_canvas_get_position (GocCanvas *canvas, int *x, int *y,
			      gint64 px, gint64 py);
130 131 132
void gnm_canvas_get_screen_position (GocCanvas *canvas,
				     double x, double y,
				     int *ix, int *iy);
133

134 135
gboolean gnm_check_for_plugins_missing (char const **ids, GtkWindow *parent);

136 137 138 139
void
gnm_cell_renderer_text_copy_background_to_cairo (GtkCellRendererText *crt,
						 cairo_t *cr);

140 141 142 143 144 145 146

/*
 * These macros exist to replace the old gtk+ stock items.  Note, that these only
 * cover strings with mnemonics.  I.e., you must handle icons and accelerators
 * in some other way.  (So why do we have them in the first place?  To ensure
 * the user interface is as consistent as possible.)
 */
147 148
#define GNM_STOCK_LABEL_CONTEXT "Stock label"

149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
#define GNM_STOCK_OPEN g_dpgettext2(GETTEXT_PACKAGE, "Stock label", GNM_N_STOCK_OPEN)
#define GNM_N_STOCK_OPEN NC_("Stock label", "_Open")

#define GNM_STOCK_SAVE g_dpgettext2(GETTEXT_PACKAGE, "Stock label", GNM_N_STOCK_SAVE)
#define GNM_N_STOCK_SAVE NC_("Stock label", "_Save")

#define GNM_STOCK_SAVE_AS g_dpgettext2(GETTEXT_PACKAGE, "Stock label", GNM_N_STOCK_SAVE_AS)
#define GNM_N_STOCK_SAVE_AS NC_("Stock label", "Save _As")

#define GNM_STOCK_CANCEL g_dpgettext2(GETTEXT_PACKAGE, "Stock label", GNM_N_STOCK_CANCEL)
#define GNM_N_STOCK_CANCEL NC_("Stock label", "_Cancel")

#define GNM_STOCK_OK g_dpgettext2(GETTEXT_PACKAGE, "Stock label", GNM_N_STOCK_OK)
#define GNM_N_STOCK_OK NC_("Stock label", "_OK")

164 165 166 167 168 169

typedef struct
{
	const gchar *name;
	const gchar *icon;
	const gchar *label;
170
	const gchar *label_context;
171 172 173 174
	const gchar *accelerator;
	const gchar *tooltip;
	GCallback callback;

175 176 177
	/* Fields for toggles.  */
	guint toggle : 1;
	guint is_active : 1;
178 179 180
} GnmActionEntry;

void gnm_action_group_add_actions (GtkActionGroup *group,
181
				   GnmActionEntry const *actions, size_t n,
182
				   gpointer user);
183
void gnm_action_group_add_action (GtkActionGroup *group, GtkAction *act);
184

Morten Welinder's avatar
Morten Welinder committed
185 186 187
void gnm_style_context_get_color (GtkStyleContext *context,
				  GtkStateFlags state,
				  GdkRGBA *color);
188

Morten Welinder's avatar
Morten Welinder committed
189 190
void gnm_get_link_color (GtkWidget *widget, GdkRGBA *res);

191 192 193
G_END_DECLS

#endif /* _GNM_GUI_UTIL_H_ */