gwenhywfar  4.8.0beta
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 #ifdef OS_WIN32
22 # include <windows.h>
23 # define sleep(x) Sleep(x)
24 #endif
25 
26 #include <unistd.h>
27 
28 
29 
30 
31 
34  const char *sender) {
35  fprintf(stderr,
36  "Received event %d from widget [%s]\n", t, sender);
37 
38  switch(t) {
40  fprintf(stderr, "Init\n");
41  GWEN_Dialog_SetCharProperty(dlg, "combo1",
43  0,
44  "Erster Text in Combo1",
45  0);
46  GWEN_Dialog_SetCharProperty(dlg, "combo1",
48  0,
49  "Zweiter Text in Combo1",
50  0);
51  GWEN_Dialog_SetIntProperty(dlg, "combo1",
53  0,
54  0,
55  0);
56 
57 
58  GWEN_Dialog_SetCharProperty(dlg, "combo2",
60  0,
61  "Erster Text in Combo2",
62  0);
63  GWEN_Dialog_SetCharProperty(dlg, "combo2",
65  0,
66  "Zweiter Text in Combo2",
67  0);
68  GWEN_Dialog_SetIntProperty(dlg, "combo2",
70  0,
71  0,
72  0);
73 
74  GWEN_Dialog_SetCharProperty(dlg, "listbox1",
76  0,
77  "Column1\tColumn2\tColumn3",
78  0);
79 
80  GWEN_Dialog_SetCharProperty(dlg, "listbox1",
82  0,
83  "Zeile 1 Spalte 1\tZeile 1 Spalte 2\tZeile 1 Spalte 3",
84  0);
85  GWEN_Dialog_SetCharProperty(dlg, "listbox1",
87  0,
88  "Zeile 2 Spalte 1\tZeile 2 Spalte 2\tZeile 2 Spalte 3",
89  0);
90  GWEN_Dialog_SetIntProperty(dlg, "listbox1",
92  0,
93  100,
94  0);
95  GWEN_Dialog_SetIntProperty(dlg, "listbox1",
97  1,
98  200,
99  0);
100 
101  GWEN_Dialog_SetCharProperty(dlg, "labelWithHtmlImage",
103  0,
104  "<html>This label contains text which should also contain an image:"
105  "<img src=\"chipcard.png\">"
106  "<p>And here the text should continue, followed by another image:"
107  "<img src=\"disk.png\"></p>"
108  "And again, this should be on the following line.</html>"
109  "This label would contain an image if it were able to use "
110  "HTML.",
111  0);
112 
113  GWEN_Dialog_SetCharProperty(dlg, "textBrowser1",
115  0,
116  "<html>"
117  "<p>This is <b>bold</b> text, while this one is <i>italic</i>.</p>"
118  "This is a list:"
119  "<ul>"
120  "<li>first item</li>"
121  "<li>second item</li>"
122  "<li>third item</li>"
123  "<li>fourth item</li>"
124  "</ul>"
125  "<p>This paragraph should follow the list.</p>"
126  "</html>"
127  "This is BOLD text, while this one is would be i t a l i c.\n"
128  "This is a list:\n"
129  "- first item\n"
130  "- second item\n"
131  "- third item\n"
132  "- fourth item\n"
133  "This paragraph should follow the list.",
134  0);
135 
136  GWEN_Dialog_SetIntProperty(dlg, "progressBar1",
138  0,
139  0,
140  0);
141  GWEN_Dialog_SetIntProperty(dlg, "progressBar1",
143  0,
144  10,
145  0);
146 
147 
150  0,
151  640,
152  0);
155  0,
156  480,
157  0);
158 
159  break;
160 
162  fprintf(stderr, "Fini\n");
163  break;
165  fprintf(stderr, "ValueChanged\n");
166  if (strcasecmp(sender, "listbox1")==0) {
167  fprintf(stderr, "Selected list entry %d\n",
168  GWEN_Dialog_GetIntProperty(dlg, "listbox1", GWEN_DialogProperty_Value, 0, -1));
169  }
170  else if (strcasecmp(sender, "editPass1")==0) {
171  const char *s;
172 
174  if (!(s && *s))
175  s="<empty>";
176  GWEN_Dialog_SetCharProperty(dlg, "editPass2", GWEN_DialogProperty_Value, 0, s, 0);
177  }
178  break;
179 
181  fprintf(stderr, "Activated\n");
182  if (strcasecmp(sender, "listbox1")==0) {
183  int idx;
184 
185  idx=GWEN_Dialog_GetIntProperty(dlg, "listbox1", GWEN_DialogProperty_Value, 0, -1);
186  fprintf(stderr, "Selected list entry %d\n", idx);
187  if (idx>=0) {
188  const char *s;
189 
191  if (s && *s) {
192  fprintf(stderr, "Text of selected list entry %d: [%s]\n", idx, s);
193  }
194  }
195  }
196  else if (strcasecmp(sender, "combo1")==0) {
197  int idx;
198 
199  idx=GWEN_Dialog_GetIntProperty(dlg, "combo1", GWEN_DialogProperty_Value, 0, -1);
200  fprintf(stderr, "Selected list entry %d\n", idx);
201  if (idx>=0) {
202  const char *s;
203 
205  if (s && *s) {
206  fprintf(stderr, "Text of selected list entry %d: [%s]\n", idx, s);
207  }
208  }
209 
210  }
211  else if (strcasecmp(sender, "okButton")==0)
213  else if (strcasecmp(sender, "abortButton")==0)
215  else if (strcasecmp(sender, "progressMinus")==0) {
216  int v;
217 
218  v=GWEN_Dialog_GetIntProperty(dlg, "progressBar1", GWEN_DialogProperty_Value, 0, -1);
219  if (v>0)
220  GWEN_Dialog_SetIntProperty(dlg, "progressBar1", GWEN_DialogProperty_Value, 0, v-1, 0);
222  }
223  else if (strcasecmp(sender, "progressPlus")==0) {
224  int v;
225 
226  v=GWEN_Dialog_GetIntProperty(dlg, "progressBar1", GWEN_DialogProperty_Value, 0, -1);
227  if (v<10)
228  GWEN_Dialog_SetIntProperty(dlg, "progressBar1", GWEN_DialogProperty_Value, 0, v+1, 0);
230  }
231  else if (strcasecmp(sender, "prevPageButton")==0) {
232  int v;
233 
234  v=GWEN_Dialog_GetIntProperty(dlg, "stack1", GWEN_DialogProperty_Value, 0, -1);
235  if (v>0)
236  GWEN_Dialog_SetIntProperty(dlg, "stack1", GWEN_DialogProperty_Value, 0, v-1, 0);
238  }
239  else if (strcasecmp(sender, "nextPageButton")==0) {
240  int v;
241 
242  v=GWEN_Dialog_GetIntProperty(dlg, "stack1", GWEN_DialogProperty_Value, 0, -1);
243  if (v<3)
244  GWEN_Dialog_SetIntProperty(dlg, "stack1", GWEN_DialogProperty_Value, 0, v+1, 0);
246  }
247  break;
248 
250  fprintf(stderr, "Enabled\n");
251  break;
253  fprintf(stderr, "Disabled\n");
254  break;
256  fprintf(stderr, "Close\n");
259  fprintf(stderr, "Last, ignored\n");
261  }
263 }
264 
265 
266 
268  GWEN_DIALOG *dlg;
269  int rv;
270  const char *s;
271  GWEN_BUFFER *tbuf;
272 
273  tbuf=GWEN_Buffer_new(0, 256, 0, 1);
274  s=getenv("DIALOG_DIR");
275  if (s && *s)
276  GWEN_Buffer_AppendString(tbuf, s);
277  else
278  GWEN_Buffer_AppendString(tbuf, MEDIAPATH);
279  dlg=GWEN_Dialog_new("dlg_test");
282 
283  /* read dialog from dialog description file */
284  GWEN_Buffer_AppendString(tbuf, GWEN_DIR_SEPARATOR_S "dlg_test.dlg");
286  GWEN_Buffer_free(tbuf);
287  if (rv<0) {
288  DBG_INFO(GWEN_LOGDOMAIN, "here (%d).", rv);
289  GWEN_Dialog_free(dlg);
290  return NULL;
291  }
292 
293  /* done */
294  return dlg;
295 }
296 
297 
298 
299 
300