aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/msgbox.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/msgbox.c')
-rwxr-xr-x[-rw-r--r--]src/msgbox.c300
1 files changed, 60 insertions, 240 deletions
diff --git a/src/msgbox.c b/src/msgbox.c
index f9a8cb7..82953f9 100644..100755
--- a/src/msgbox.c
+++ b/src/msgbox.c
@@ -32,281 +32,101 @@
#include "setting.h"
-static void msg_box_class_init (MsgBoxClass *class);
-static void msg_box_init (MsgBox *mb);
+GtkWidget *msg_box_new (gchar *title, GtkWindow *parent, GtkWidget **check_button, GtkDialogFlags flags, gchar *message, const gchar *icon, ...);
-static void msg_box_show (GtkWidget *widget);
-static gint msg_box_delete_event (GtkWidget *widget, GdkEventAny *event);
-static void msg_box_button_clicked (GtkButton *button, gpointer data);
-void check_button_toggled (GtkCheckButton *checkbutton, gpointer data);
-
-
-static GtkDialogClass *parent_klass = NULL;
-
-
-GType msg_box_get_type(void)
-{
- static GType mb_type = 0;
-
- if (!mb_type)
- {
- GTypeInfo mb_info =
- {
- sizeof(MsgBoxClass),
- NULL,
- NULL,
- (GClassInitFunc) msg_box_class_init,
- NULL,
- NULL,
- sizeof(MsgBox),
- 0,
- (GInstanceInitFunc) msg_box_init
- };
- mb_type = g_type_register_static(GTK_TYPE_DIALOG, "MsgBox", &mb_info, 0);
- }
- return mb_type;
-}
-
-
-static void msg_box_button_clicked (GtkButton *button, gpointer data)
-{
- MsgBox *mb;
-
- g_return_if_fail( (mb = MSG_BOX(data)) );
-
- mb->button_clicked = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(button),"button_value"));
-
- if (gtk_main_level()>1)
- gtk_main_quit();
-}
-
-
-static void msg_box_class_init (MsgBoxClass *class)
-{
- GtkObjectClass *object_class;
- GtkWidgetClass *widget_class;
- GtkDialogClass *dialog_class;
-
- object_class = (GtkObjectClass*) class;
- widget_class = (GtkWidgetClass*) class;
- dialog_class = (GtkDialogClass*) class;
-
- parent_klass = gtk_type_class(gtk_dialog_get_type());
-
- object_class->destroy = msg_box_destroy;
- widget_class->delete_event = msg_box_delete_event;
- widget_class->show = msg_box_show;
-}
-
-
-static void msg_box_init (MsgBox *mb)
-{
- g_return_if_fail(mb != NULL);
- g_return_if_fail(IS_MSG_BOX(mb));
-
- mb->icon = -1;
- mb->check_button = NULL;
- mb->check_button_state = 0;
-
-}
/*
- * Create a new message box
+ * Create a new message box to display a message and a check button (for some actions).
+ * The first button passed as parameter will have the focus
*/
-GtkWidget *msg_box_new (gchar *title, gchar *message, const gchar *stock_id,
- /* Put all the buttons to display, and terminate by 0 */
- ...)
+GtkWidget *msg_box_new (gchar *title,
+ GtkWindow *parent,
+ GtkWidget **check_button,
+ GtkDialogFlags flags,
+ gchar *message,
+ const gchar *stock_id,
+ /* Put all the buttons to display, and terminate by 0 */
+ ...)
{
- MsgBox *mb;
+ GtkWidget *dialog;
GtkWidget *Table;
GtkWidget *Pixmap;
GtkWidget *Label;
- GtkWidget *ButtonBox;
- GtkWidget *Button = NULL;
- va_list cursor;
- gint cursor_value;
-
+ GtkWidget *Button;
+ gboolean first_button = TRUE;
+ va_list args;
+
g_return_val_if_fail(message!=NULL, NULL);
+
+ //dialog = GTK_DIALOG(gtk_dialog_new_empty (title, parent, flags));
+ dialog = gtk_dialog_new_with_buttons(title,parent,flags,NULL);
- mb = MSG_BOX(g_object_new(TYPE_MSG_BOX, NULL));
- //mb->icon = icon;
- mb->check_button = gtk_check_button_new_with_label(_("Repeat action for the rest of the files")); /* Can save or cancel all files */
-
- /* Window configuration */
- gtk_window_set_title(GTK_WINDOW(mb),title);
- gtk_window_set_transient_for(GTK_WINDOW(mb),GTK_WINDOW(MainWindow));
- gtk_window_set_modal(GTK_WINDOW(mb),TRUE);
-
+ // Position of the dialog window
if (MESSAGE_BOX_POSITION_NONE)
- gtk_window_set_position(GTK_WINDOW(mb),GTK_WIN_POS_NONE);
+ gtk_window_set_position(GTK_WINDOW(dialog),GTK_WIN_POS_NONE);
else if (MESSAGE_BOX_POSITION_CENTER)
- gtk_window_set_position(GTK_WINDOW(mb),GTK_WIN_POS_CENTER);
+ gtk_window_set_position(GTK_WINDOW(dialog),GTK_WIN_POS_CENTER);
else if (MESSAGE_BOX_POSITION_MOUSE)
- gtk_window_set_position(GTK_WINDOW(mb),GTK_WIN_POS_MOUSE);
+ gtk_window_set_position(GTK_WINDOW(dialog),GTK_WIN_POS_MOUSE);
else if (MESSAGE_BOX_POSITION_CENTER_ON_PARENT)
- gtk_window_set_position(GTK_WINDOW(mb),GTK_WIN_POS_CENTER_ON_PARENT);
+ gtk_window_set_position(GTK_WINDOW(dialog),GTK_WIN_POS_CENTER_ON_PARENT);
+
-
- /* Table to put: the pixmap, the message and the check button */
+ // Table to insert: the pixmap, the message and the check button
Table = gtk_table_new(2,2,FALSE);
- gtk_box_pack_start(GTK_BOX(GTK_DIALOG(mb)->vbox),Table,TRUE,TRUE,0);
+ gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),Table,TRUE,TRUE,0);
gtk_container_set_border_width(GTK_CONTAINER(Table),4);
gtk_widget_show(Table);
- /* The Pixmap */
+ // The pixmap
Pixmap = gtk_image_new_from_stock(stock_id, GTK_ICON_SIZE_DIALOG);
gtk_table_attach_defaults(GTK_TABLE(Table),Pixmap,0,1,0,1);
//gtk_table_attach(GTK_TABLE(Table),Pixmap,0,1,0,1,GTK_FILL,GTK_FILL,0,0);
gtk_misc_set_padding(GTK_MISC(Pixmap),6,6);
gtk_widget_show(Pixmap);
- /* The Message */
- Label = gtk_label_new (message);
+ // The message
+ Label = gtk_label_new(message);
gtk_table_attach_defaults(GTK_TABLE(Table),Label,1,2,0,1);
gtk_misc_set_padding(GTK_MISC(Label),6,6);
gtk_label_set_justify(GTK_LABEL(Label),GTK_JUSTIFY_CENTER);
//gtk_label_set_line_wrap(GTK_LABEL(Label),TRUE);
gtk_widget_show(Label);
- /* The Check Button */
- gtk_table_attach_defaults(GTK_TABLE(Table),mb->check_button,0,2,1,2);
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mb->check_button),mb->check_button_state);
- g_signal_connect(G_OBJECT(mb->check_button),"toggled",G_CALLBACK(check_button_toggled),mb);
- gtk_widget_show(mb->check_button);
-
-
- /* Buttons */
- ButtonBox = gtk_hbutton_box_new();
- gtk_box_set_spacing(GTK_BOX(ButtonBox), 15);
- gtk_button_box_set_layout(GTK_BUTTON_BOX(ButtonBox), GTK_BUTTONBOX_END);
- gtk_container_add(GTK_CONTAINER(GTK_DIALOG(mb)->action_area),ButtonBox);
+ // The check button
+ if (check_button)
+ {
+ *check_button = gtk_check_button_new_with_label(_("Repeat action for the rest of the files")); // Can save or cancel all files
+ gtk_table_attach_defaults(GTK_TABLE(Table),*check_button,0,2,1,2);
+ }
- /* Read buttons from variable arguments */
- va_start(cursor,stock_id);
- while ( (cursor_value = va_arg(cursor,gint)) != 0 )
+ // Read buttons from variable arguments
+ va_start(args, stock_id);
+ for (;;)
{
- Button = Create_Button_With_Pixmap(cursor_value);
- gtk_container_add(GTK_CONTAINER(ButtonBox),Button);
+ const gchar *button_text = NULL;
+ gint response_id = 0;
+
+ button_text = va_arg (args, const gchar *);
+ if (button_text == NULL)
+ break;
+ response_id = va_arg (args, gint);
+ if (response_id == 0)
+ break;
+
+ Button = gtk_dialog_add_button(GTK_DIALOG(dialog),button_text,response_id);
GTK_WIDGET_SET_FLAGS(Button,GTK_CAN_DEFAULT);
- g_signal_connect(G_OBJECT(Button),"destroy", G_CALLBACK(gtk_widget_destroyed),&Button);
- g_signal_connect(G_OBJECT(Button),"clicked", G_CALLBACK(msg_box_button_clicked),mb);
- g_object_set_data(G_OBJECT(Button),"button_value", GINT_TO_POINTER(cursor_value));
+
+ // To focus to the first button
+ if (first_button)
+ gtk_widget_grab_default(Button);
+ first_button = FALSE;
}
- va_end(cursor);
- gtk_widget_grab_default(Button);
- gtk_widget_show_all(ButtonBox);
-
- return GTK_WIDGET(mb);
-}
-
-
-void msg_box_destroy (GtkObject *object)
-{
- MsgBox *mb;
-
- g_return_if_fail( (mb = MSG_BOX(object)) );
-
- if (mb->check_button)
- gtk_widget_destroy(mb->check_button);
-
-/* FIXME: causes segfault in some cases (when callin gtk_widget_destroy(msgbox) ) */
-/* if (GTK_OBJECT_CLASS(parent_klass)->destroy)
- * (* GTK_OBJECT_CLASS(parent_klass)->destroy) (object);
- */
-}
-
-
-static gint msg_box_delete_event (GtkWidget *widget, GdkEventAny *event)
-{
- MsgBox *mb;
-
- g_return_val_if_fail((mb = MSG_BOX(widget)), FALSE);
-
- /* If the window is closed whitout pressing a button, we return -1 */
- mb->button_clicked = -1;
-
- if (gtk_main_level()>1)
- gtk_main_quit();
-
- return TRUE;
-}
-
-
-/*
- * "Run" and show the msgbox, and send which button was pressed (or not a button)
- */
-gint msg_box_run (MsgBox *msgbox)
-{
- MsgBox *mb;
-
- g_return_val_if_fail((mb = MSG_BOX(msgbox)),0);
-
- gtk_widget_show(GTK_WIDGET(mb));
- gtk_main();
- gtk_widget_hide(GTK_WIDGET(mb));
- gtk_window_set_modal(GTK_WINDOW(mb),FALSE);
-
- return (MSG_BOX(mb)->button_clicked);
-}
-
-
-static void msg_box_show (GtkWidget *widget)
-{
- if (GTK_WIDGET_CLASS(parent_klass)->show)
- (* (GTK_WIDGET_CLASS(parent_klass)->show))(widget);
-}
-
-
-/*
- * Callback when the check_button is pressed
- */
-void check_button_toggled (GtkCheckButton *checkbutton, gpointer data)
-{
- MsgBox *mb;
-
- g_return_if_fail((mb = MSG_BOX(data)));
-
- mb->check_button_state = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbutton));
-}
-
-
-/*
- * Set the check_button to the 'is_active' state
- */
-void msg_box_check_button_set_active (MsgBox *msgbox, gboolean is_active)
-{
- MsgBox *mb;
-
- g_return_if_fail((mb = MSG_BOX(msgbox)));
-
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mb->check_button),is_active);
- mb->check_button_state = is_active;
-}
-
-
-/*
- * Get state of the check_button
- */
-gboolean msg_box_check_button_get_active (MsgBox *msgbox)
-{
- MsgBox *mb;
-
- g_return_val_if_fail((mb = MSG_BOX(msgbox)),FALSE);
-
- return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(mb->check_button));
-}
-
-
-/*
- * Hide the check_button.
- */
-void msg_box_hide_check_button (MsgBox *msgbox)
-{
- MsgBox *mb;
-
- g_return_if_fail((mb = MSG_BOX(msgbox)));
-
- gtk_widget_hide(mb->check_button);
+ va_end(args);
+
+ gtk_widget_show_all(dialog);
+
+ return GTK_WIDGET(dialog);
}