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  break;
180 
182  fprintf(stderr, "Fini\n");
183  break;
185  fprintf(stderr, "ValueChanged\n");
186  if (strcasecmp(sender, "listbox1")==0) {
187  fprintf(stderr, "Selected list entry %d\n",
188  GWEN_Dialog_GetIntProperty(dlg, "listbox1", GWEN_DialogProperty_Value, 0, -1));
189  }
190  else if (strcasecmp(sender, "editPass1")==0) {
191  const char *s;
192 
194  if (!(s && *s))
195  s="<empty>";
196  GWEN_Dialog_SetCharProperty(dlg, "editPass2", GWEN_DialogProperty_Value, 0, s, 0);
197  }
198  break;
199 
201  fprintf(stderr, "Activated\n");
202  if (strcasecmp(sender, "listbox1")==0) {
203  int idx;
204 
205  idx=GWEN_Dialog_GetIntProperty(dlg, "listbox1", GWEN_DialogProperty_Value, 0, -1);
206  fprintf(stderr, "Selected list entry %d\n", idx);
207  if (idx>=0) {
208  const char *s;
209 
211  if (s && *s) {
212  fprintf(stderr, "Text of selected list entry %d: [%s]\n", idx, s);
213  }
214  }
215  }
216  else if (strcasecmp(sender, "combo1")==0) {
217  int idx;
218 
219  idx=GWEN_Dialog_GetIntProperty(dlg, "combo1", GWEN_DialogProperty_Value, 0, -1);
220  fprintf(stderr, "Selected list entry %d\n", idx);
221  if (idx>=0) {
222  const char *s;
223 
225  if (s && *s) {
226  fprintf(stderr, "Text of selected list entry %d: [%s]\n", idx, s);
227  }
228  }
229 
230  }
231  else if (strcasecmp(sender, "okButton")==0)
233  else if (strcasecmp(sender, "abortButton")==0)
235  else if (strcasecmp(sender, "progressMinus")==0) {
236  int v;
237 
238  v=GWEN_Dialog_GetIntProperty(dlg, "progressBar1", GWEN_DialogProperty_Value, 0, -1);
239  if (v>0)
240  GWEN_Dialog_SetIntProperty(dlg, "progressBar1", GWEN_DialogProperty_Value, 0, v-1, 0);
242  }
243  else if (strcasecmp(sender, "progressPlus")==0) {
244  int v;
245 
246  v=GWEN_Dialog_GetIntProperty(dlg, "progressBar1", GWEN_DialogProperty_Value, 0, -1);
247  if (v<10)
248  GWEN_Dialog_SetIntProperty(dlg, "progressBar1", GWEN_DialogProperty_Value, 0, v+1, 0);
250  }
251  else if (strcasecmp(sender, "prevPageButton")==0) {
252  int v;
253 
254  v=GWEN_Dialog_GetIntProperty(dlg, "stack1", GWEN_DialogProperty_Value, 0, -1);
255  if (v>0)
256  GWEN_Dialog_SetIntProperty(dlg, "stack1", GWEN_DialogProperty_Value, 0, v-1, 0);
258  }
259  else if (strcasecmp(sender, "nextPageButton")==0) {
260  int v;
261 
262  v=GWEN_Dialog_GetIntProperty(dlg, "stack1", GWEN_DialogProperty_Value, 0, -1);
263  if (v<3)
264  GWEN_Dialog_SetIntProperty(dlg, "stack1", GWEN_DialogProperty_Value, 0, v+1, 0);
266  }
267  break;
268 
270  fprintf(stderr, "Enabled\n");
271  break;
273  fprintf(stderr, "Disabled\n");
274  break;
276  fprintf(stderr, "Close\n");
279  fprintf(stderr, "Last, ignored\n");
281 
284  fprintf(stderr, "Key events ignored\n");
286 
287  }
289 }
290 
291 
292 
294 {
295  GWEN_DIALOG *dlg;
296  int rv;
297  const char *s;
298  GWEN_BUFFER *tbuf;
299 
300  tbuf=GWEN_Buffer_new(0, 256, 0, 1);
301  s=getenv("DIALOG_DIR");
302  if (s && *s)
303  GWEN_Buffer_AppendString(tbuf, s);
304  else
305  GWEN_Buffer_AppendString(tbuf, MEDIAPATH);
306  dlg=GWEN_Dialog_new("dlg_test");
309 
310  /* read dialog from dialog description file */
311  GWEN_Buffer_AppendString(tbuf, GWEN_DIR_SEPARATOR_S "dlg_test.dlg");
313  GWEN_Buffer_free(tbuf);
314  if (rv<0) {
315  DBG_INFO(GWEN_LOGDOMAIN, "here (%d).", rv);
316  GWEN_Dialog_free(dlg);
317  return NULL;
318  }
319 
320  /* done */
321  return dlg;
322 }
323 
324 
325 
326 
327 
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:293
#define DBG_INFO(dbg_logger, format,...)
Definition: debug.h:181
int GWEN_Buffer_AppendString(GWEN_BUFFER *bf, const char *buffer)
Definition: buffer.c:992