gwenhywfar
4.7.0beta
Main Page
Related Pages
Modules
Data Structures
Files
File List
Globals
src
gui
dlg_showbox.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_showbox_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
#define DIALOG_MINWIDTH 200
28
#define DIALOG_MINHEIGHT 50
29
30
31
32
GWEN_INHERIT
(
GWEN_DIALOG
, GWEN_DLGSHOWBOX)
33
34
35
36
37
38
GWEN_DIALOG
*
GWEN_DlgShowBox_new
(uint32_t flags,
39
const
char
*title,
40
const
char
*text) {
41
GWEN_DIALOG
*dlg;
42
GWEN_DLGSHOWBOX *xdlg;
43
GWEN_BUFFER
*fbuf;
44
int
rv;
45
46
dlg=
GWEN_Dialog_new
(
"dlg_gwen_showbox"
);
47
GWEN_NEW_OBJECT
(GWEN_DLGSHOWBOX, xdlg);
48
49
GWEN_INHERIT_SETDATA
(
GWEN_DIALOG
, GWEN_DLGSHOWBOX, dlg, xdlg,
50
GWEN_DlgShowBox_FreeData
);
51
52
GWEN_Dialog_SetSignalHandler
(dlg,
GWEN_DlgShowBox_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_showbox.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
xdlg->flags=flags;
77
if
(title)
78
xdlg->title=strdup(title);
79
if
(text)
80
xdlg->text=strdup(text);
81
82
return
dlg;
83
}
84
85
86
87
void
GWENHYWFAR_CB
GWEN_DlgShowBox_FreeData
(
void
*bp,
void
*p) {
88
GWEN_DLGSHOWBOX *xdlg;
89
90
xdlg=(GWEN_DLGSHOWBOX*) p;
91
92
free(xdlg->title);
93
free(xdlg->text);
94
95
GWEN_FREE_OBJECT
(xdlg);
96
}
97
98
99
100
void
GWEN_DlgShowBox_Init
(
GWEN_DIALOG
*dlg) {
101
GWEN_DLGSHOWBOX *xdlg;
102
int
i;
103
GWEN_DB_NODE
*dbParams;
104
105
assert(dlg);
106
xdlg=
GWEN_INHERIT_GETDATA
(
GWEN_DIALOG
, GWEN_DLGSHOWBOX, dlg);
107
assert(xdlg);
108
109
dbParams=
GWEN_Dialog_GetPreferences
(dlg);
110
assert(dbParams);
111
112
/* read width */
113
i=
GWEN_DB_GetIntValue
(dbParams,
"dialog_width"
, 0, -1);
114
if
(i>=
DIALOG_MINWIDTH
)
115
GWEN_Dialog_SetIntProperty
(dlg,
""
,
GWEN_DialogProperty_Width
, 0, i, 0);
116
117
/* read height */
118
i=
GWEN_DB_GetIntValue
(dbParams,
"dialog_height"
, 0, -1);
119
if
(i>=
DIALOG_MINHEIGHT
)
120
GWEN_Dialog_SetIntProperty
(dlg,
""
,
GWEN_DialogProperty_Height
, 0, i, 0);
121
122
/* special stuff */
123
if
(xdlg->title)
124
GWEN_Dialog_SetCharProperty
(dlg,
""
,
GWEN_DialogProperty_Title
, 0, xdlg->title, 0);
125
126
if
(xdlg->text)
127
GWEN_Dialog_SetCharProperty
(dlg,
"descrLabel"
,
GWEN_DialogProperty_Title
, 0, xdlg->text, 0);
128
129
130
xdlg->wasInit=1;
131
}
132
133
134
135
void
GWEN_DlgShowBox_Fini
(
GWEN_DIALOG
*dlg) {
136
GWEN_DLGSHOWBOX *xdlg;
137
int
i;
138
GWEN_DB_NODE
*dbParams;
139
140
assert(dlg);
141
xdlg=
GWEN_INHERIT_GETDATA
(
GWEN_DIALOG
, GWEN_DLGSHOWBOX, dlg);
142
assert(xdlg);
143
144
dbParams=
GWEN_Dialog_GetPreferences
(dlg);
145
assert(dbParams);
146
147
/* store dialog width */
148
i=
GWEN_Dialog_GetIntProperty
(dlg,
""
,
GWEN_DialogProperty_Width
, 0, -1);
149
if
(i<
DIALOG_MINWIDTH
)
150
i=
DIALOG_MINWIDTH
;
151
GWEN_DB_SetIntValue
(dbParams,
152
GWEN_DB_FLAGS_OVERWRITE_VARS
,
153
"dialog_width"
,
154
i);
155
156
/* store dialog height */
157
i=
GWEN_Dialog_GetIntProperty
(dlg,
""
,
GWEN_DialogProperty_Height
, 0, -1);
158
if
(i<
DIALOG_MINHEIGHT
)
159
i=
DIALOG_MINHEIGHT
;
160
GWEN_DB_SetIntValue
(dbParams,
161
GWEN_DB_FLAGS_OVERWRITE_VARS
,
162
"dialog_height"
,
163
i);
164
}
165
166
167
168
169
int
GWENHYWFAR_CB
GWEN_DlgShowBox_SignalHandler
(
GWEN_DIALOG
*dlg,
170
GWEN_DIALOG_EVENTTYPE
t,
171
const
char
*sender) {
172
GWEN_DLGSHOWBOX *xdlg;
173
174
assert(dlg);
175
xdlg=
GWEN_INHERIT_GETDATA
(
GWEN_DIALOG
, GWEN_DLGSHOWBOX, dlg);
176
assert(xdlg);
177
178
switch
(t) {
179
case
GWEN_DialogEvent_TypeInit
:
180
GWEN_DlgShowBox_Init
(dlg);
181
return
GWEN_DialogEvent_ResultHandled
;;
182
183
case
GWEN_DialogEvent_TypeFini
:
184
GWEN_DlgShowBox_Fini
(dlg);
185
return
GWEN_DialogEvent_ResultHandled
;;
186
187
case
GWEN_DialogEvent_TypeActivated
:
188
case
GWEN_DialogEvent_TypeValueChanged
:
189
case
GWEN_DialogEvent_TypeEnabled
:
190
case
GWEN_DialogEvent_TypeDisabled
:
191
192
case
GWEN_DialogEvent_TypeClose
:
193
return
GWEN_DialogEvent_ResultAccept
;
194
195
case
GWEN_DialogEvent_TypeLast
:
196
return
GWEN_DialogEvent_ResultNotHandled
;
197
}
198
199
return
GWEN_DialogEvent_ResultNotHandled
;
200
201
}
202
203
204
205
Generated on Wed Aug 21 2013 18:32:09 for gwenhywfar by
1.8.4