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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
/** \file
* \brief GTK IupMessageDlg pre-defined dialog
*
* See Copyright Notice in "iup.h"
*/
#include <gtk/gtk.h>
#include "iup.h"
#include "iup_object.h"
#include "iup_attrib.h"
#include "iup_str.h"
#include "iup_dialog.h"
#include "iupgtk_drv.h"
/* Sometimes GTK decides to invert the buttons position because of the GNOME Guidelines.
To avoid that we define different Ids for the buttons. */
#define IUP_RESPONSE_1 -100
#define IUP_RESPONSE_2 -200
#define IUP_RESPONSE_HELP -300
#ifndef GTK_MESSAGE_OTHER
#define GTK_MESSAGE_OTHER GTK_MESSAGE_INFO
#endif
static int gtkMessageDlgPopup(Ihandle* ih, int x, int y)
{
InativeHandle* parent = iupDialogGetNativeParent(ih);
GtkMessageType type = GTK_MESSAGE_OTHER;
GtkWidget* dialog;
char *icon, *buttons, *title;
int response, num_but = 2;
iupAttribSetInt(ih, "_IUPDLG_X", x); /* used in iupDialogUpdatePosition */
iupAttribSetInt(ih, "_IUPDLG_Y", y);
icon = iupAttribGetStr(ih, "DIALOGTYPE");
if (iupStrEqualNoCase(icon, "ERROR"))
type = GTK_MESSAGE_ERROR;
else if (iupStrEqualNoCase(icon, "WARNING"))
type = GTK_MESSAGE_WARNING;
else if (iupStrEqualNoCase(icon, "INFORMATION"))
type = GTK_MESSAGE_INFO;
else if (iupStrEqualNoCase(icon, "QUESTION"))
type = GTK_MESSAGE_QUESTION;
dialog = gtk_message_dialog_new((GtkWindow*)parent,
0,
type,
GTK_BUTTONS_NONE,
iupgtkStrConvertToUTF8(iupAttribGet(ih, "VALUE")));
if (!dialog)
return IUP_ERROR;
title = iupAttribGet(ih, "TITLE");
if (title)
gtk_window_set_title(GTK_WINDOW(dialog), iupgtkStrConvertToUTF8(title));
buttons = iupAttribGetStr(ih, "BUTTONS");
if (iupStrEqualNoCase(buttons, "OKCANCEL"))
{
gtk_dialog_add_button(GTK_DIALOG(dialog),
GTK_STOCK_OK,
IUP_RESPONSE_1);
gtk_dialog_add_button(GTK_DIALOG(dialog),
GTK_STOCK_CANCEL,
IUP_RESPONSE_2);
}
else if (iupStrEqualNoCase(buttons, "YESNO"))
{
gtk_dialog_add_button(GTK_DIALOG(dialog),
GTK_STOCK_YES,
IUP_RESPONSE_1);
gtk_dialog_add_button(GTK_DIALOG(dialog),
GTK_STOCK_NO,
IUP_RESPONSE_2);
}
else /* OK */
{
gtk_dialog_add_button(GTK_DIALOG(dialog),
GTK_STOCK_OK,
IUP_RESPONSE_1);
num_but = 1;
}
if (IupGetCallback(ih, "HELP_CB"))
gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_HELP, IUP_RESPONSE_HELP);
if (num_but == 2 && iupAttribGetInt(ih, "BUTTONDEFAULT") == 2)
gtk_dialog_set_default_response(GTK_DIALOG(dialog), IUP_RESPONSE_2);
else
gtk_dialog_set_default_response(GTK_DIALOG(dialog), IUP_RESPONSE_1);
/* initialize the widget */
gtk_widget_realize(dialog);
ih->handle = dialog;
iupDialogUpdatePosition(ih);
ih->handle = NULL;
do
{
response = gtk_dialog_run(GTK_DIALOG(dialog));
if (response == IUP_RESPONSE_HELP)
{
Icallback cb = IupGetCallback(ih, "HELP_CB");
if (cb && cb(ih) == IUP_CLOSE)
response = (num_but == 2)? IUP_RESPONSE_2: IUP_RESPONSE_1;
}
} while (response == IUP_RESPONSE_HELP);
if (response == IUP_RESPONSE_1)
IupSetAttribute(ih, "BUTTONRESPONSE", "1");
else
IupSetAttribute(ih, "BUTTONRESPONSE", "2");
gtk_widget_destroy(dialog);
return IUP_NOERROR;
}
void iupdrvMessageDlgInitClass(Iclass* ic)
{
ic->DlgPopup = gtkMessageDlgPopup;
}
|