gwenhywfar  5.14.1
dlg_test.c
Go to the documentation of this file.
1 /***************************************************************************
2  begin : Sun May 16 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 #ifdef HAVE_CONFIG_H
11 # include <config.h>
12 #endif
13 
14 #include <gwenhywfar/gwenhywfar.h>
15 #include <gwenhywfar/gui.h>
16 #include <gwenhywfar/dialog.h>
17 #include <gwenhywfar/debug.h>
18 #include <gwenhywfar/pathmanager.h>
19 
20 
21 #include <unistd.h>
22 
23 
24 
25 
26 
29  const char *sender)
30 {
31  fprintf(stderr,
32  "Received event %d from widget [%s]\n", t, sender);
33 
34  switch (t) {
36  fprintf(stderr, "Init\n");
37  GWEN_Dialog_SetCharProperty(dlg, "combo1",
39  0,
40  "Erster Text in Combo1",
41  0);
42  GWEN_Dialog_SetCharProperty(dlg, "combo1",
44  0,
45  "Zweiter Text in Combo1",
46  0);
47  GWEN_Dialog_SetIntProperty(dlg, "combo1",
49  0,
50  0,
51  0);
52 
53 
54  GWEN_Dialog_SetCharProperty(dlg, "combo2",
56  0,
57  "Erster Text in Combo2",
58  0);
59  GWEN_Dialog_SetCharProperty(dlg, "combo2",
61  0,
62  "Zweiter Text in Combo2",
63  0);
64  GWEN_Dialog_SetIntProperty(dlg, "combo2",
66  0,
67  0,
68  0);
69 
70  GWEN_Dialog_SetCharProperty(dlg, "listbox1",
72  0,
73  "Column1\tColumn2\tColumn3",
74  0);
75 
76  GWEN_Dialog_SetCharProperty(dlg, "listbox1",
78  0,
79  "Zeile 1 Spalte 1\tZeile 1 Spalte 2\tZeile 1 Spalte 3",
80  0);
81  GWEN_Dialog_SetCharProperty(dlg, "listbox1",
83  0,
84  "Zeile 2 Spalte 1\tZeile 2 Spalte 2\tZeile 2 Spalte 3",
85  0);
86  GWEN_Dialog_SetIntProperty(dlg, "listbox1",
88  0,
89  100,
90  0);
91  GWEN_Dialog_SetIntProperty(dlg, "listbox1",
93  1,
94  200,
95  0);
96 
97  GWEN_Dialog_SetCharProperty(dlg, "labelWithHtmlImage",
99  0,
100  "<html>This label contains text which should also contain an image:"
101  "<img src=\"chipcard.png\">"
102  "<p>And here the text should continue, followed by another image:"
103  "<img src=\"disk.png\"></p>"
104  "And again, this should be on the following line.</html>"
105  "This label would contain an image if it were able to use "
106  "HTML.",
107  0);
108 
109  GWEN_Dialog_SetCharProperty(dlg, "textBrowser1",
111  0,
112  "<html>"
113  "<p>This is <b>bold</b> text, while this one is <i>italic</i>.</p>"
114  "This is a list:"
115  "<ul>"
116  "<li>first item</li>"
117  "<li>second item</li>"
118  "<li>third item</li>"
119  "<li>fourth item</li>"
120  "</ul>"
121  "<p>This paragraph should follow the list.</p>"
122  "</html>"
123  "This is BOLD text, while this one is would be i t a l i c.\n"
124  "This is a list:\n"
125  "- first item\n"
126  "- second item\n"
127  "- third item\n"
128  "- fourth item\n"
129  "This paragraph should follow the list.",
130  0);
131 
132  GWEN_Dialog_SetIntProperty(dlg, "progressBar1",
134  0,
135  0,
136  0);
137  GWEN_Dialog_SetIntProperty(dlg, "progressBar1",
139  0,
140  10,
141  0);
142 
143  /* page 9 */
144  GWEN_Dialog_SetCharProperty(dlg, "textBrowser9.1",
146  0,
147  "This is BOLD text, while this one is would be i t a l i c.\n"
148  "This is a list:\n"
149  "- first item\n"
150  "- second item\n"
151  "- third item\n"
152  "- fourth item\n"
153  "This paragraph should follow the list."
154  "<html>"
155  "<p>This is <b>bold</b> text, while this one is <i>italic</i>.</p>"
156  "This is a list:"
157  "<ul>"
158  "<li>first item</li>"
159  "<li>second item</li>"
160  "<li>third item</li>"
161  "<li>fourth item</li>"
162  "</ul>"
163  "<p>This paragraph should follow the list.</p>"
164  "</html>",
165  0);
166 
167 
170  0,
171  640,
172  0);
175  0,
176  480,
177  0);
178 
179  GWEN_Dialog_SetIntProperty(dlg, "vsplitter9.1",
181  0,
182  200,
183  0);
184  break;
185 
187  fprintf(stderr, "Fini\n");
188  break;
190  fprintf(stderr, "ValueChanged\n");
191  if (strcasecmp(sender, "listbox1")==0) {
192  fprintf(stderr, "Selected list entry %d\n",
193  GWEN_Dialog_GetIntProperty(dlg, "listbox1", GWEN_DialogProperty_Value, 0, -1));
194  }
195  else if (strcasecmp(sender, "editPass1")==0) {
196  const char *s;
197 
199  if (!(s && *s))
200  s="<empty>";
201  GWEN_Dialog_SetCharProperty(dlg, "editPass2", GWEN_DialogProperty_Value, 0, s, 0);
202  }
203  break;
204 
206  fprintf(stderr, "Activated\n");
207  if (strcasecmp(sender, "listbox1")==0) {
208  int idx;
209 
210  idx=GWEN_Dialog_GetIntProperty(dlg, "listbox1", GWEN_DialogProperty_Value, 0, -1);
211  fprintf(stderr, "Selected list entry %d\n", idx);
212  if (idx>=0) {
213  const char *s;
214 
216  if (s && *s) {
217  fprintf(stderr, "Text of selected list entry %d: [%s]\n", idx, s);
218  }
219  }
220  }
221  else if (strcasecmp(sender, "combo1")==0) {
222  int idx;
223 
224  idx=GWEN_Dialog_GetIntProperty(dlg, "combo1", GWEN_DialogProperty_Value, 0, -1);
225  fprintf(stderr, "Selected list entry %d\n", idx);
226  if (idx>=0) {
227  const char *s;
228 
230  if (s && *s) {
231  fprintf(stderr, "Text of selected list entry %d: [%s]\n", idx, s);
232  }
233  }
234 
235  }
236  else if (strcasecmp(sender, "okButton")==0)
238  else if (strcasecmp(sender, "abortButton")==0)
240  else if (strcasecmp(sender, "progressMinus")==0) {
241  int v;
242 
243  v=GWEN_Dialog_GetIntProperty(dlg, "progressBar1", GWEN_DialogProperty_Value, 0, -1);
244  if (v>0)
245  GWEN_Dialog_SetIntProperty(dlg, "progressBar1", GWEN_DialogProperty_Value, 0, v-1, 0);
247  }
248  else if (strcasecmp(sender, "progressPlus")==0) {
249  int v;
250 
251  v=GWEN_Dialog_GetIntProperty(dlg, "progressBar1", GWEN_DialogProperty_Value, 0, -1);
252  if (v<10)
253  GWEN_Dialog_SetIntProperty(dlg, "progressBar1", GWEN_DialogProperty_Value, 0, v+1, 0);
255  }
256  else if (strcasecmp(sender, "prevPageButton")==0) {
257  int v;
258 
259  v=GWEN_Dialog_GetIntProperty(dlg, "stack1", GWEN_DialogProperty_Value, 0, -1);
260  if (v>0)
261  GWEN_Dialog_SetIntProperty(dlg, "stack1", GWEN_DialogProperty_Value, 0, v-1, 0);
263  }
264  else if (strcasecmp(sender, "nextPageButton")==0) {
265  int v;
266 
267  v=GWEN_Dialog_GetIntProperty(dlg, "stack1", GWEN_DialogProperty_Value, 0, -1);
268  if (v<3)
269  GWEN_Dialog_SetIntProperty(dlg, "stack1", GWEN_DialogProperty_Value, 0, v+1, 0);
271  }
272  break;
273 
275  fprintf(stderr, "Enabled\n");
276  break;
278  fprintf(stderr, "Disabled\n");
279  break;
281  fprintf(stderr, "Close\n");
284  fprintf(stderr, "Last, ignored\n");
286 
289  fprintf(stderr, "Key events ignored\n");
291 
292  }
294 }
295 
296 
297 
299 {
300  GWEN_DIALOG *dlg;
301  int rv;
302  const char *s;
303  GWEN_BUFFER *tbuf;
304 
305  tbuf=GWEN_Buffer_new(0, 256, 0, 1);
306  s=getenv("DIALOG_DIR");
307  if (s && *s)
308  GWEN_Buffer_AppendString(tbuf, s);
309  else
310  GWEN_Buffer_AppendString(tbuf, MEDIAPATH);
311  dlg=GWEN_Dialog_new("dlg_test");
314 
315  /* read dialog from dialog description file */
316  GWEN_Buffer_AppendString(tbuf, GWEN_DIR_SEPARATOR_S "dlg_test.dlg");
318  GWEN_Buffer_free(tbuf);
319  if (rv<0) {
320  DBG_INFO(GWEN_LOGDOMAIN, "here (%d).", rv);
321  GWEN_Dialog_free(dlg);
322  return NULL;
323  }
324 
325  /* done */
326  return dlg;
327 }
328 
329 
330 
331 
332 
char * GWEN_Buffer_GetStart(const GWEN_BUFFER *bf)
Definition: buffer.c:235
#define GWEN_DIR_SEPARATOR_S
#define NULL
Definition: binreloc.c:300
GWEN_DIALOG_EVENTTYPE
Definition: dialog.h:98
GWEN_DIALOG_SIGNALHANDLER GWEN_Dialog_SetSignalHandler(GWEN_DIALOG *dlg, GWEN_DIALOG_SIGNALHANDLER fn)
Definition: dialog.c:305
#define GWEN_LOGDOMAIN
Definition: logger.h:32
GWEN_BUFFER * GWEN_Buffer_new(char *buffer, uint32_t size, uint32_t used, int take)
Definition: buffer.c:42
struct GWEN_DIALOG GWEN_DIALOG
Definition: dialog.h:54
int GWEN_Dialog_GetIntProperty(GWEN_DIALOG *dlg, const char *name, GWEN_DIALOG_PROPERTY prop, int index, int defaultProperty)
Definition: dialog.c:733
#define GWENHYWFAR_CB
Definition: gwenhywfarapi.h:89
static int GWENHYWFAR_CB _gwenGuiSignalHandler(GWEN_DIALOG *dlg, GWEN_DIALOG_EVENTTYPE t, const char *sender)
Definition: dlg_test.c:27
void GWEN_Buffer_free(GWEN_BUFFER *bf)
Definition: buffer.c:89
struct GWEN_BUFFER GWEN_BUFFER
A dynamically resizeable text buffer.
Definition: buffer.h:38
const char * GWEN_Dialog_GetCharProperty(GWEN_DIALOG *dlg, const char *name, GWEN_DIALOG_PROPERTY prop, int index, const char *defaultProperty)
Definition: dialog.c:792
int GWEN_Dialog_SetIntProperty(GWEN_DIALOG *dlg, const char *name, GWEN_DIALOG_PROPERTY prop, int index, int value, int doSignal)
Definition: dialog.c:703
GWEN_DIALOG * GWEN_Dialog_new(const char *dialogId)
Definition: dialog.c:54
int GWEN_Dialog_SetCharProperty(GWEN_DIALOG *dlg, const char *name, GWEN_DIALOG_PROPERTY prop, int index, const char *value, int doSignal)
Definition: dialog.c:762
void GWEN_Dialog_AddMediaPath(GWEN_DIALOG *dlg, const char *s)
Definition: dialog.c:246
void GWEN_Dialog_free(GWEN_DIALOG *dlg)
Definition: dialog.c:137
int GWEN_Dialog_ReadXmlFile(GWEN_DIALOG *dlg, const char *fname)
Definition: dialog.c:531
GWEN_DIALOG * Dlg_Test1_new()
Definition: dlg_test.c:298
#define DBG_INFO(dbg_logger, format,...)
Definition: debug.h:181
int GWEN_Buffer_AppendString(GWEN_BUFFER *bf, const char *buffer)
Definition: buffer.c:992