gwenhywfar
4.8.0beta
Main Page
Related Pages
Modules
Data Structures
Files
File List
Globals
src
gui
dlg_message.c
Go to the documentation of this file.
1
/***************************************************************************
2
begin : Wed Feb 17 2010
3
copyright : (C) 2010 by Martin Preuss
4
email : martin@libchipcard.de
5
6
***************************************************************************
7
* Please see toplevel file COPYING for license details *
8
***************************************************************************/
9
10
11
#ifdef HAVE_CONFIG_H
12
# include <config.h>
13
#endif
14
15
#define DISABLE_DEBUGLOG
16
17
18
#include "dlg_message_p.h"
19
20
#include <gwenhywfar/gwenhywfar.h>
21
#include <gwenhywfar/pathmanager.h>
22
#include <gwenhywfar/gui.h>
23
#include <gwenhywfar/debug.h>
24
25
26
27
28
GWEN_INHERIT
(
GWEN_DIALOG
, GWEN_DLGMSG)
29
30
31
32
33
34
GWEN_DIALOG
*
GWEN_DlgMessage_new
(uint32_t flags,
35
const
char
*title,
36
const
char
*text,
37
const
char
*b1,
38
const
char
*b2,
39
const
char
*b3) {
40
GWEN_DIALOG
*dlg;
41
GWEN_DLGMSG *xdlg;
42
GWEN_BUFFER
*fbuf;
43
int
rv;
44
int
confirmButton;
45
46
dlg=
GWEN_Dialog_new
(
"dlg_gwen_message"
);
47
GWEN_NEW_OBJECT
(GWEN_DLGMSG, xdlg);
48
49
GWEN_INHERIT_SETDATA
(
GWEN_DIALOG
, GWEN_DLGMSG, dlg, xdlg,
50
GWEN_DlgMessage_FreeData
);
51
52
GWEN_Dialog_SetSignalHandler
(dlg,
GWEN_DlgMessage_SignalHandler
);
53
54
/* get path of dialog description file */
55
fbuf=
GWEN_Buffer_new
(0, 256, 0, 1);
56
rv=
GWEN_PathManager_FindFile
(
GWEN_PM_LIBNAME
,
GWEN_PM_SYSDATADIR
,
57
"gwenhywfar/dialogs/dlg_message.dlg"
,
58
fbuf);
59
if
(rv<0) {
60
DBG_INFO
(
GWEN_LOGDOMAIN
,
"Dialog description file not found (%d)."
, rv);
61
GWEN_Buffer_free
(fbuf);
62
GWEN_Dialog_free
(dlg);
63
return
NULL
;
64
}
65
66
/* read dialog from dialog description file */
67
rv=
GWEN_Dialog_ReadXmlFile
(dlg,
GWEN_Buffer_GetStart
(fbuf));
68
if
(rv<0) {
69
DBG_INFO
(
GWEN_LOGDOMAIN
,
"here (%d)."
, rv);
70
GWEN_Buffer_free
(fbuf);
71
GWEN_Dialog_free
(dlg);
72
return
NULL
;
73
}
74
GWEN_Buffer_free
(fbuf);
75
76
confirmButton=
GWEN_GUI_MSG_FLAGS_CONFIRM_BUTTON
(flags);
77
78
79
xdlg->flags=flags;
80
if
(title)
81
xdlg->title=strdup(title);
82
if
(text)
83
xdlg->text=strdup(text);
84
85
if
(b1 && *b1) {
86
GWEN_Dialog_SetWidgetText
(dlg,
"button1"
, b1);
87
if
(confirmButton==1)
88
GWEN_Dialog_AddWidgetFlags
(dlg,
"button1"
,
GWEN_WIDGET_FLAGS_DEFAULT_WIDGET
);
89
}
90
else
91
GWEN_Dialog_RemoveWidget
(dlg,
"button1"
);
92
93
94
if
(b2 && *b2) {
95
GWEN_Dialog_SetWidgetText
(dlg,
"button2"
, b2);
96
if
(confirmButton==2)
97
GWEN_Dialog_AddWidgetFlags
(dlg,
"button2"
,
GWEN_WIDGET_FLAGS_DEFAULT_WIDGET
);
98
}
99
else
100
GWEN_Dialog_RemoveWidget
(dlg,
"button2"
);
101
102
if
(b3 && *b3) {
103
GWEN_Dialog_SetWidgetText
(dlg,
"button3"
, b3);
104
if
(confirmButton==3)
105
GWEN_Dialog_AddWidgetFlags
(dlg,
"button3"
,
GWEN_WIDGET_FLAGS_DEFAULT_WIDGET
);
106
}
107
else
108
GWEN_Dialog_RemoveWidget
(dlg,
"button3"
);
109
110
return
dlg;
111
}
112
113
114
115
void
GWENHYWFAR_CB
GWEN_DlgMessage_FreeData
(
void
*bp,
void
*p) {
116
GWEN_DLGMSG *xdlg;
117
118
xdlg=(GWEN_DLGMSG*) p;
119
120
free(xdlg->title);
121
free(xdlg->text);
122
123
GWEN_FREE_OBJECT
(xdlg);
124
}
125
126
127
128
int
GWEN_DlgMessage_GetResponse
(
const
GWEN_DIALOG
*dlg) {
129
GWEN_DLGMSG *xdlg;
130
131
assert(dlg);
132
xdlg=
GWEN_INHERIT_GETDATA
(
GWEN_DIALOG
, GWEN_DLGMSG, dlg);
133
assert(xdlg);
134
135
return
xdlg->response;
136
}
137
138
139
140
void
GWEN_DlgMessage_Init
(
GWEN_DIALOG
*dlg) {
141
GWEN_DLGMSG *xdlg;
142
GWEN_DB_NODE
*dbParams;
143
144
assert(dlg);
145
xdlg=
GWEN_INHERIT_GETDATA
(
GWEN_DIALOG
, GWEN_DLGMSG, dlg);
146
assert(xdlg);
147
148
dbParams=
GWEN_Dialog_GetPreferences
(dlg);
149
assert(dbParams);
150
151
#if 0
152
/* read width */
153
i=
GWEN_DB_GetIntValue
(dbParams,
"dialog_width"
, 0, -1);
154
if
(i>=
DIALOG_MINWIDTH
)
155
GWEN_Dialog_SetIntProperty
(dlg,
""
,
GWEN_DialogProperty_Width
, 0, i, 0);
156
157
/* read height */
158
i=
GWEN_DB_GetIntValue
(dbParams,
"dialog_height"
, 0, -1);
159
if
(i>=
DIALOG_MINHEIGHT
)
160
GWEN_Dialog_SetIntProperty
(dlg,
""
,
GWEN_DialogProperty_Height
, 0, i, 0);
161
#endif
162
163
/* special stuff */
164
if
(xdlg->title)
165
GWEN_Dialog_SetCharProperty
(dlg,
""
,
GWEN_DialogProperty_Title
, 0, xdlg->title, 0);
166
167
if
(xdlg->text)
168
GWEN_Dialog_SetCharProperty
(dlg,
"descrLabel"
,
GWEN_DialogProperty_Title
, 0, xdlg->text, 0);
169
170
171
xdlg->wasInit=1;
172
}
173
174
175
176
void
GWEN_DlgMessage_Fini
(
GWEN_DIALOG
*dlg) {
177
GWEN_DLGMSG *xdlg;
178
GWEN_DB_NODE
*dbParams;
179
180
assert(dlg);
181
xdlg=
GWEN_INHERIT_GETDATA
(
GWEN_DIALOG
, GWEN_DLGMSG, dlg);
182
assert(xdlg);
183
184
dbParams=
GWEN_Dialog_GetPreferences
(dlg);
185
assert(dbParams);
186
187
#if 0
188
/* store dialog width */
189
i=
GWEN_Dialog_GetIntProperty
(dlg,
""
,
GWEN_DialogProperty_Width
, 0, -1);
190
if
(i<
DIALOG_MINWIDTH
)
191
i=
DIALOG_MINWIDTH
;
192
GWEN_DB_SetIntValue
(dbParams,
193
GWEN_DB_FLAGS_OVERWRITE_VARS
,
194
"dialog_width"
,
195
i);
196
197
/* store dialog height */
198
i=
GWEN_Dialog_GetIntProperty
(dlg,
""
,
GWEN_DialogProperty_Height
, 0, -1);
199
if
(i<
DIALOG_MINHEIGHT
)
200
i=
DIALOG_MINHEIGHT
;
201
GWEN_DB_SetIntValue
(dbParams,
202
GWEN_DB_FLAGS_OVERWRITE_VARS
,
203
"dialog_height"
,
204
i);
205
#endif
206
}
207
208
209
210
211
int
GWEN_DlgMessage_HandleActivated
(
GWEN_DIALOG
*dlg,
const
char
*sender) {
212
GWEN_DLGMSG *xdlg;
213
214
assert(dlg);
215
xdlg=
GWEN_INHERIT_GETDATA
(
GWEN_DIALOG
, GWEN_DLGMSG, dlg);
216
assert(xdlg);
217
218
if
(strcasecmp(sender,
"button1"
)==0) {
219
xdlg->response=1;
220
return
GWEN_DialogEvent_ResultAccept
;
221
}
222
else
if
(strcasecmp(sender,
"button2"
)==0) {
223
xdlg->response=2;
224
return
GWEN_DialogEvent_ResultAccept
;
225
}
226
else
if
(strcasecmp(sender,
"button3"
)==0) {
227
xdlg->response=3;
228
return
GWEN_DialogEvent_ResultAccept
;
229
}
230
231
return
GWEN_DialogEvent_ResultNotHandled
;
232
}
233
234
235
236
237
int
GWENHYWFAR_CB
GWEN_DlgMessage_SignalHandler
(
GWEN_DIALOG
*dlg,
238
GWEN_DIALOG_EVENTTYPE
t,
239
const
char
*sender) {
240
GWEN_DLGMSG *xdlg;
241
242
assert(dlg);
243
xdlg=
GWEN_INHERIT_GETDATA
(
GWEN_DIALOG
, GWEN_DLGMSG, dlg);
244
assert(xdlg);
245
246
switch
(t) {
247
case
GWEN_DialogEvent_TypeInit
:
248
GWEN_DlgMessage_Init
(dlg);
249
return
GWEN_DialogEvent_ResultHandled
;;
250
251
case
GWEN_DialogEvent_TypeFini
:
252
GWEN_DlgMessage_Fini
(dlg);
253
return
GWEN_DialogEvent_ResultHandled
;;
254
255
case
GWEN_DialogEvent_TypeActivated
:
256
return
GWEN_DlgMessage_HandleActivated
(dlg, sender);
257
258
case
GWEN_DialogEvent_TypeValueChanged
:
259
case
GWEN_DialogEvent_TypeEnabled
:
260
case
GWEN_DialogEvent_TypeDisabled
:
261
262
case
GWEN_DialogEvent_TypeClose
:
263
return
GWEN_DialogEvent_ResultAccept
;
264
265
case
GWEN_DialogEvent_TypeLast
:
266
return
GWEN_DialogEvent_ResultNotHandled
;
267
}
268
269
return
GWEN_DialogEvent_ResultNotHandled
;
270
271
}
272
273
274
275
Generated on Sun Oct 27 2013 09:43:37 for gwenhywfar by
1.8.4