25 #include <glib/gi18n.h>
27 #include "dialog-utils.h"
29 #include "gnc-gui-query.h"
32 #define INDEX_LABEL "index"
53 gnc_ok_cancel_dialog(GtkWidget *parent,
55 const gchar *format, ...)
57 GtkWidget *dialog = NULL;
65 va_start(args, format);
66 buffer = g_strdup_vprintf(format, args);
67 dialog = gtk_message_dialog_new (GTK_WINDOW(parent),
68 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
70 GTK_BUTTONS_OK_CANCEL,
77 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(dialog), FALSE);
79 gtk_dialog_set_default_response (GTK_DIALOG(dialog), default_result);
80 result = gtk_dialog_run(GTK_DIALOG(dialog));
81 gtk_widget_destroy (dialog);
102 gnc_verify_dialog(GtkWidget *parent, gboolean yes_is_default,
103 const gchar *format, ...)
113 va_start(args, format);
114 buffer = g_strdup_vprintf(format, args);
115 dialog = gtk_message_dialog_new (GTK_WINDOW(parent),
116 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
117 GTK_MESSAGE_QUESTION,
125 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(dialog), FALSE);
127 gtk_dialog_set_default_response(GTK_DIALOG(dialog),
128 (yes_is_default ? GTK_RESPONSE_YES : GTK_RESPONSE_NO));
129 result = gtk_dialog_run(GTK_DIALOG(dialog));
130 gtk_widget_destroy (dialog);
131 return (result == GTK_RESPONSE_YES);
147 gnc_info_dialog(GtkWidget *parent,
const gchar *format, ...)
156 va_start(args, format);
157 buffer = g_strdup_vprintf(format, args);
158 dialog = gtk_message_dialog_new (GTK_WINDOW(parent),
159 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
167 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(dialog), FALSE);
169 gtk_dialog_run(GTK_DIALOG(dialog));
170 gtk_widget_destroy (dialog);
187 gnc_warning_dialog_common(GtkWidget *parent,
const gchar *format, va_list args)
189 GtkWidget *dialog = NULL;
195 buffer = g_strdup_vprintf(format, args);
196 dialog = gtk_message_dialog_new (GTK_WINDOW(parent),
197 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
205 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(dialog), FALSE);
207 gtk_dialog_run (GTK_DIALOG (dialog));
208 gtk_widget_destroy (dialog);
212 gnc_warning_dialog(GtkWidget *parent,
const gchar *format, ...)
216 va_start(args, format);
217 gnc_warning_dialog_common(parent, format, args);
234 gnc_error_dialog_common(GtkWidget *parent,
const gchar *format, va_list args)
242 buffer = g_strdup_vprintf(format, args);
243 dialog = gtk_message_dialog_new (GTK_WINDOW(parent),
244 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
252 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(dialog), FALSE);
254 gtk_dialog_run(GTK_DIALOG(dialog));
255 gtk_widget_destroy (dialog);
259 gnc_error_dialog(GtkWidget *parent,
const gchar *format, ...)
263 va_start(args, format);
264 gnc_error_dialog_common(parent, format, args);
269 gnc_choose_radio_button_cb(GtkWidget *w, gpointer data)
273 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w)))
274 *result = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(w), INDEX_LABEL));
285 gnc_choose_radio_option_dialog(GtkWidget *parent,
288 const char *button_name,
292 int radio_result = 0;
294 GtkWidget *main_vbox;
296 GtkWidget *alignment;
297 GtkWidget *radio_button;
300 GSList *group = NULL;
304 main_vbox = gtk_vbox_new(FALSE, 3);
305 gtk_container_set_border_width(GTK_CONTAINER(main_vbox), 6);
306 gtk_widget_show(main_vbox);
308 label = gtk_label_new(msg);
309 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
310 gtk_box_pack_start(GTK_BOX(main_vbox), label, FALSE, FALSE, 0);
311 gtk_widget_show(label);
313 alignment = gtk_alignment_new(0.0, 0.0, 1.0, 1.0);
314 gtk_alignment_set_padding (GTK_ALIGNMENT(alignment), 0, 0, 12, 0);
315 gtk_box_pack_start(GTK_BOX(main_vbox), alignment, FALSE, FALSE, 0);
316 gtk_widget_show(alignment);
318 vbox = gtk_vbox_new(TRUE, 3);
319 gtk_container_set_border_width(GTK_CONTAINER(vbox), 6);
320 gtk_container_add(GTK_CONTAINER(alignment), vbox);
321 gtk_widget_show(vbox);
323 for (node = radio_list, i = 0; node; node = node->next, i++)
325 radio_button = gtk_radio_button_new_with_mnemonic(group, node->data);
326 group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(radio_button));
328 if (i == default_value)
330 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio_button), TRUE);
331 radio_result = default_value;
334 gtk_widget_show(radio_button);
335 gtk_box_pack_start(GTK_BOX(vbox), radio_button, FALSE, FALSE, 0);
336 g_object_set_data(G_OBJECT(radio_button), INDEX_LABEL, GINT_TO_POINTER(i));
337 g_signal_connect(radio_button,
"clicked",
338 G_CALLBACK(gnc_choose_radio_button_cb),
343 button_name = GTK_STOCK_OK;
344 dialog = gtk_dialog_new_with_buttons (title, GTK_WINDOW(parent),
345 GTK_DIALOG_DESTROY_WITH_PARENT,
346 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
347 button_name, GTK_RESPONSE_OK,
351 gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK);
353 dvbox = GTK_DIALOG(dialog)->vbox;
355 gtk_box_pack_start(GTK_BOX(dvbox), main_vbox, TRUE, TRUE, 0);
357 if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_OK)
360 gtk_widget_destroy (dialog);
GtkWidget * gnc_ui_get_toplevel(void)