32
32
#include "setting.h"
35
static void msg_box_class_init (MsgBoxClass *class);
36
static void msg_box_init (MsgBox *mb);
38
static void msg_box_show (GtkWidget *widget);
39
static gint msg_box_delete_event (GtkWidget *widget, GdkEventAny *event);
40
static void msg_box_button_clicked (GtkButton *button, gpointer data);
41
void check_button_toggled (GtkCheckButton *checkbutton, gpointer data);
44
static GtkDialogClass *parent_klass = NULL;
47
GType msg_box_get_type(void)
49
static GType mb_type = 0;
58
(GClassInitFunc) msg_box_class_init,
63
(GInstanceInitFunc) msg_box_init
65
mb_type = g_type_register_static(GTK_TYPE_DIALOG, "MsgBox", &mb_info, 0);
71
static void msg_box_button_clicked (GtkButton *button, gpointer data)
75
g_return_if_fail( (mb = MSG_BOX(data)) );
77
mb->button_clicked = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(button),"button_value"));
79
if (gtk_main_level()>1)
84
static void msg_box_class_init (MsgBoxClass *class)
86
GtkObjectClass *object_class;
87
GtkWidgetClass *widget_class;
88
GtkDialogClass *dialog_class;
90
object_class = (GtkObjectClass*) class;
91
widget_class = (GtkWidgetClass*) class;
92
dialog_class = (GtkDialogClass*) class;
94
parent_klass = gtk_type_class(gtk_dialog_get_type());
96
object_class->destroy = msg_box_destroy;
97
widget_class->delete_event = msg_box_delete_event;
98
widget_class->show = msg_box_show;
102
static void msg_box_init (MsgBox *mb)
104
g_return_if_fail(mb != NULL);
105
g_return_if_fail(IS_MSG_BOX(mb));
108
mb->check_button = NULL;
109
mb->check_button_state = 0;
35
GtkWidget *msg_box_new (gchar *title, GtkWindow *parent, GtkWidget **check_button, GtkDialogFlags flags, gchar *message, const gchar *icon, ...);
115
* Create a new message box
40
* Create a new message box to display a message and a check button (for some actions).
41
* The first button passed as parameter will have the focus
117
GtkWidget *msg_box_new (gchar *title, gchar *message, const gchar *stock_id,
118
/* Put all the buttons to display, and terminate by 0 */
43
GtkWidget *msg_box_new (gchar *title,
45
GtkWidget **check_button,
48
const gchar *stock_id,
49
/* Put all the buttons to display, and terminate by 0 */
123
54
GtkWidget *Pixmap;
125
GtkWidget *ButtonBox;
126
GtkWidget *Button = NULL;
57
gboolean first_button = TRUE;
131
61
g_return_val_if_fail(message!=NULL, NULL);
133
mb = MSG_BOX(g_object_new(TYPE_MSG_BOX, NULL));
135
mb->check_button = gtk_check_button_new_with_label(_("Repeat action for the rest of the files")); /* Can save or cancel all files */
137
/* Window configuration */
138
gtk_window_set_title(GTK_WINDOW(mb),title);
139
gtk_window_set_transient_for(GTK_WINDOW(mb),GTK_WINDOW(MainWindow));
140
gtk_window_set_modal(GTK_WINDOW(mb),TRUE);
63
//dialog = GTK_DIALOG(gtk_dialog_new_empty (title, parent, flags));
64
dialog = gtk_dialog_new_with_buttons(title,parent,flags,NULL);
66
// Position of the dialog window
142
67
if (MESSAGE_BOX_POSITION_NONE)
143
gtk_window_set_position(GTK_WINDOW(mb),GTK_WIN_POS_NONE);
68
gtk_window_set_position(GTK_WINDOW(dialog),GTK_WIN_POS_NONE);
144
69
else if (MESSAGE_BOX_POSITION_CENTER)
145
gtk_window_set_position(GTK_WINDOW(mb),GTK_WIN_POS_CENTER);
70
gtk_window_set_position(GTK_WINDOW(dialog),GTK_WIN_POS_CENTER);
146
71
else if (MESSAGE_BOX_POSITION_MOUSE)
147
gtk_window_set_position(GTK_WINDOW(mb),GTK_WIN_POS_MOUSE);
72
gtk_window_set_position(GTK_WINDOW(dialog),GTK_WIN_POS_MOUSE);
148
73
else if (MESSAGE_BOX_POSITION_CENTER_ON_PARENT)
149
gtk_window_set_position(GTK_WINDOW(mb),GTK_WIN_POS_CENTER_ON_PARENT);
152
/* Table to put: the pixmap, the message and the check button */
74
gtk_window_set_position(GTK_WINDOW(dialog),GTK_WIN_POS_CENTER_ON_PARENT);
77
// Table to insert: the pixmap, the message and the check button
153
78
Table = gtk_table_new(2,2,FALSE);
154
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(mb)->vbox),Table,TRUE,TRUE,0);
79
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),Table,TRUE,TRUE,0);
155
80
gtk_container_set_border_width(GTK_CONTAINER(Table),4);
156
81
gtk_widget_show(Table);
159
84
Pixmap = gtk_image_new_from_stock(stock_id, GTK_ICON_SIZE_DIALOG);
160
85
gtk_table_attach_defaults(GTK_TABLE(Table),Pixmap,0,1,0,1);
161
86
//gtk_table_attach(GTK_TABLE(Table),Pixmap,0,1,0,1,GTK_FILL,GTK_FILL,0,0);
162
87
gtk_misc_set_padding(GTK_MISC(Pixmap),6,6);
163
88
gtk_widget_show(Pixmap);
166
Label = gtk_label_new (message);
91
Label = gtk_label_new(message);
167
92
gtk_table_attach_defaults(GTK_TABLE(Table),Label,1,2,0,1);
168
93
gtk_misc_set_padding(GTK_MISC(Label),6,6);
169
94
gtk_label_set_justify(GTK_LABEL(Label),GTK_JUSTIFY_CENTER);
170
95
//gtk_label_set_line_wrap(GTK_LABEL(Label),TRUE);
171
96
gtk_widget_show(Label);
173
/* The Check Button */
174
gtk_table_attach_defaults(GTK_TABLE(Table),mb->check_button,0,2,1,2);
175
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mb->check_button),mb->check_button_state);
176
g_signal_connect(G_OBJECT(mb->check_button),"toggled",G_CALLBACK(check_button_toggled),mb);
177
gtk_widget_show(mb->check_button);
181
ButtonBox = gtk_hbutton_box_new();
182
gtk_box_set_spacing(GTK_BOX(ButtonBox), 15);
183
gtk_button_box_set_layout(GTK_BUTTON_BOX(ButtonBox), GTK_BUTTONBOX_END);
184
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(mb)->action_area),ButtonBox);
186
/* Read buttons from variable arguments */
187
va_start (cursor,stock_id);
188
while ( (cursor_value = va_arg(cursor,gint)) != 0 )
190
Button = Create_Button_With_Pixmap(cursor_value);
191
gtk_container_add(GTK_CONTAINER(ButtonBox),Button);
101
*check_button = gtk_check_button_new_with_label(_("Repeat action for the rest of the files")); // Can save or cancel all files
102
gtk_table_attach_defaults(GTK_TABLE(Table),*check_button,0,2,1,2);
105
// Read buttons from variable arguments
106
va_start(args, stock_id);
109
const gchar *button_text = NULL;
110
gint response_id = 0;
112
button_text = va_arg (args, const gchar *);
113
if (button_text == NULL)
115
response_id = va_arg (args, gint);
116
if (response_id == 0)
119
Button = gtk_dialog_add_button(GTK_DIALOG(dialog),button_text,response_id);
192
120
GTK_WIDGET_SET_FLAGS(Button,GTK_CAN_DEFAULT);
193
g_signal_connect(G_OBJECT(Button),"destroy", G_CALLBACK(gtk_widget_destroyed),&Button);
194
g_signal_connect(G_OBJECT(Button),"clicked", G_CALLBACK(msg_box_button_clicked),mb);
195
g_object_set_data(G_OBJECT(Button),"button_value", GINT_TO_POINTER(cursor_value));
122
// To focus to the first button
124
gtk_widget_grab_default(Button);
125
first_button = FALSE;
198
gtk_widget_grab_default(Button);
199
gtk_widget_show_all(ButtonBox);
201
return GTK_WIDGET(mb);
205
void msg_box_destroy (GtkObject *object)
209
g_return_if_fail( (mb = MSG_BOX(object)) );
211
if (mb->check_button)
212
gtk_widget_destroy(mb->check_button);
214
/* FIXME: causes segfault in some cases (when callin gtk_widget_destroy(msgbox) ) */
215
/* if (GTK_OBJECT_CLASS(parent_klass)->destroy)
216
* (* GTK_OBJECT_CLASS(parent_klass)->destroy) (object);
221
static gint msg_box_delete_event (GtkWidget *widget, GdkEventAny *event)
225
g_return_val_if_fail((mb = MSG_BOX(widget)), FALSE);
227
/* If the window is closed whitout pressing a button, we return -1 */
228
mb->button_clicked = -1;
230
if (gtk_main_level()>1)
238
* "Run" and show the msgbox, and send which button was pressed (or not a button)
240
gint msg_box_run (MsgBox *msgbox)
244
g_return_val_if_fail((mb = MSG_BOX(msgbox)),0);
246
gtk_widget_show(GTK_WIDGET(mb));
248
gtk_widget_hide(GTK_WIDGET(mb));
249
gtk_window_set_modal(GTK_WINDOW(mb),FALSE);
251
return (MSG_BOX(mb)->button_clicked);
255
static void msg_box_show (GtkWidget *widget)
257
if (GTK_WIDGET_CLASS(parent_klass)->show)
258
(* (GTK_WIDGET_CLASS(parent_klass)->show))(widget);
263
* Callback when the check_button is pressed
265
void check_button_toggled (GtkCheckButton *checkbutton, gpointer data)
269
g_return_if_fail((mb = MSG_BOX(data)));
271
mb->check_button_state = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbutton));
276
* Set the check_button to the 'is_active' state
278
void msg_box_check_button_set_active (MsgBox *msgbox, gboolean is_active)
282
g_return_if_fail((mb = MSG_BOX(msgbox)));
284
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mb->check_button),is_active);
285
mb->check_button_state = is_active;
290
* Hide the check_button.
292
void msg_box_hide_check_button (MsgBox *msgbox)
296
g_return_if_fail((mb = MSG_BOX(msgbox)));
298
gtk_widget_hide(mb->check_button);
129
gtk_widget_show_all(dialog);
131
return GTK_WIDGET(dialog);