gwenhywfar  4.99.8beta
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  fprintf(stderr,
31  "Received event %d from widget [%s]\n", t, sender);
32 
33  switch(t) {
35  fprintf(stderr, "Init\n");
36  GWEN_Dialog_SetCharProperty(dlg, "combo1",
38  0,
39  "Erster Text in Combo1",
40  0);
41  GWEN_Dialog_SetCharProperty(dlg, "combo1",
43  0,
44  "Zweiter Text in Combo1",
45  0);
46  GWEN_Dialog_SetIntProperty(dlg, "combo1",
48  0,
49  0,
50  0);
51 
52 
53  GWEN_Dialog_SetCharProperty(dlg, "combo2",
55  0,
56  "Erster Text in Combo2",
57  0);
58  GWEN_Dialog_SetCharProperty(dlg, "combo2",
60  0,
61  "Zweiter Text in Combo2",
62  0);
63  GWEN_Dialog_SetIntProperty(dlg, "combo2",
65  0,
66  0,
67  0);
68 
69  GWEN_Dialog_SetCharProperty(dlg, "listbox1",
71  0,
72  "Column1\tColumn2\tColumn3",
73  0);
74 
75  GWEN_Dialog_SetCharProperty(dlg, "listbox1",
77  0,
78  "Zeile 1 Spalte 1\tZeile 1 Spalte 2\tZeile 1 Spalte 3",
79  0);
80  GWEN_Dialog_SetCharProperty(dlg, "listbox1",
82  0,
83  "Zeile 2 Spalte 1\tZeile 2 Spalte 2\tZeile 2 Spalte 3",
84  0);
85  GWEN_Dialog_SetIntProperty(dlg, "listbox1",
87  0,
88  100,
89  0);
90  GWEN_Dialog_SetIntProperty(dlg, "listbox1",
92  1,
93  200,
94  0);
95 
96  GWEN_Dialog_SetCharProperty(dlg, "labelWithHtmlImage",
98  0,
99  "<html>This label contains text which should also contain an image:"
100  "<img src=\"chipcard.png\">"
101  "<p>And here the text should continue, followed by another image:"
102  "<img src=\"disk.png\"></p>"
103  "And again, this should be on the following line.</html>"
104  "This label would contain an image if it were able to use "
105  "HTML.",
106  0);
107 
108  GWEN_Dialog_SetCharProperty(dlg, "textBrowser1",
110  0,
111  "<html>"
112  "<p>This is <b>bold</b> text, while this one is <i>italic</i>.</p>"
113  "This is a list:"
114  "<ul>"
115  "<li>first item</li>"
116  "<li>second item</li>"
117  "<li>third item</li>"
118  "<li>fourth item</li>"
119  "</ul>"
120  "<p>This paragraph should follow the list.</p>"
121  "</html>"
122  "This is BOLD text, while this one is would be i t a l i c.\n"
123  "This is a list:\n"
124  "- first item\n"
125  "- second item\n"
126  "- third item\n"
127  "- fourth item\n"
128  "This paragraph should follow the list.",
129  0);
130 
131  GWEN_Dialog_SetIntProperty(dlg, "progressBar1",
133  0,
134  0,
135  0);
136  GWEN_Dialog_SetIntProperty(dlg, "progressBar1",
138  0,
139  10,
140  0);
141 
142 
145  0,
146  640,
147  0);
150  0,
151  480,
152  0);
153 
154  break;
155 
157  fprintf(stderr, "Fini\n");
158  break;
160  fprintf(stderr, "ValueChanged\n");
161  if (strcasecmp(sender, "listbox1")==0) {
162  fprintf(stderr, "Selected list entry %d\n",
163  GWEN_Dialog_GetIntProperty(dlg, "listbox1", GWEN_DialogProperty_Value, 0, -1));
164  }
165  else if (strcasecmp(sender, "editPass1")==0) {
166  const char *s;
167 
169  if (!(s && *s))
170  s="<empty>";
171  GWEN_Dialog_SetCharProperty(dlg, "editPass2", GWEN_DialogProperty_Value, 0, s, 0);
172  }
173  break;
174 
176  fprintf(stderr, "Activated\n");
177  if (strcasecmp(sender, "listbox1")==0) {
178  int idx;
179 
180  idx=GWEN_Dialog_GetIntProperty(dlg, "listbox1", GWEN_DialogProperty_Value, 0, -1);
181  fprintf(stderr, "Selected list entry %d\n", idx);
182  if (idx>=0) {
183  const char *s;
184 
186  if (s && *s) {
187  fprintf(stderr, "Text of selected list entry %d: [%s]\n", idx, s);
188  }
189  }
190  }
191  else if (strcasecmp(sender, "combo1")==0) {
192  int idx;
193 
194  idx=GWEN_Dialog_GetIntProperty(dlg, "combo1", GWEN_DialogProperty_Value, 0, -1);
195  fprintf(stderr, "Selected list entry %d\n", idx);
196  if (idx>=0) {
197  const char *s;
198 
200  if (s && *s) {
201  fprintf(stderr, "Text of selected list entry %d: [%s]\n", idx, s);
202  }
203  }
204 
205  }
206  else if (strcasecmp(sender, "okButton")==0)
208  else if (strcasecmp(sender, "abortButton")==0)
210  else if (strcasecmp(sender, "progressMinus")==0) {
211  int v;
212 
213  v=GWEN_Dialog_GetIntProperty(dlg, "progressBar1", GWEN_DialogProperty_Value, 0, -1);
214  if (v>0)
215  GWEN_Dialog_SetIntProperty(dlg, "progressBar1", GWEN_DialogProperty_Value, 0, v-1, 0);
217  }
218  else if (strcasecmp(sender, "progressPlus")==0) {
219  int v;
220 
221  v=GWEN_Dialog_GetIntProperty(dlg, "progressBar1", GWEN_DialogProperty_Value, 0, -1);
222  if (v<10)
223  GWEN_Dialog_SetIntProperty(dlg, "progressBar1", GWEN_DialogProperty_Value, 0, v+1, 0);
225  }
226  else if (strcasecmp(sender, "prevPageButton")==0) {
227  int v;
228 
229  v=GWEN_Dialog_GetIntProperty(dlg, "stack1", GWEN_DialogProperty_Value, 0, -1);
230  if (v>0)
231  GWEN_Dialog_SetIntProperty(dlg, "stack1", GWEN_DialogProperty_Value, 0, v-1, 0);
233  }
234  else if (strcasecmp(sender, "nextPageButton")==0) {
235  int v;
236 
237  v=GWEN_Dialog_GetIntProperty(dlg, "stack1", GWEN_DialogProperty_Value, 0, -1);
238  if (v<3)
239  GWEN_Dialog_SetIntProperty(dlg, "stack1", GWEN_DialogProperty_Value, 0, v+1, 0);
241  }
242  break;
243 
245  fprintf(stderr, "Enabled\n");
246  break;
248  fprintf(stderr, "Disabled\n");
249  break;
251  fprintf(stderr, "Close\n");
254  fprintf(stderr, "Last, ignored\n");
256  }
258 }
259 
260 
261 
263  GWEN_DIALOG *dlg;
264  int rv;
265  const char *s;
266  GWEN_BUFFER *tbuf;
267 
268  tbuf=GWEN_Buffer_new(0, 256, 0, 1);
269  s=getenv("DIALOG_DIR");
270  if (s && *s)
271  GWEN_Buffer_AppendString(tbuf, s);
272  else
273  GWEN_Buffer_AppendString(tbuf, MEDIAPATH);
274  dlg=GWEN_Dialog_new("dlg_test");
277 
278  /* read dialog from dialog description file */
279  GWEN_Buffer_AppendString(tbuf, GWEN_DIR_SEPARATOR_S "dlg_test.dlg");
281  GWEN_Buffer_free(tbuf);
282  if (rv<0) {
283  DBG_INFO(GWEN_LOGDOMAIN, "here (%d).", rv);
284  GWEN_Dialog_free(dlg);
285  return NULL;
286  }
287 
288  /* done */
289  return dlg;
290 }
291 
292 
293 
294 
295 
char * GWEN_Buffer_GetStart(const GWEN_BUFFER *bf)
Definition: buffer.c:223
#define GWEN_DIR_SEPARATOR_S
#define NULL
Definition: binreloc.c:290
GWEN_DIALOG_EVENTTYPE
Definition: dialog.h:90
GWEN_DIALOG_SIGNALHANDLER GWEN_Dialog_SetSignalHandler(GWEN_DIALOG *dlg, GWEN_DIALOG_SIGNALHANDLER fn)
Definition: dialog.c:243
#define GWEN_LOGDOMAIN
Definition: logger.h:35
GWEN_BUFFER * GWEN_Buffer_new(char *buffer, uint32_t size, uint32_t used, int take)
Definition: buffer.c:38
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:600
#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:83
struct GWEN_BUFFER GWEN_BUFFER
A dynamically resizeable text buffer.
Definition: buffer.h:41
const char * GWEN_Dialog_GetCharProperty(GWEN_DIALOG *dlg, const char *name, GWEN_DIALOG_PROPERTY prop, int index, const char *defaultProperty)
Definition: dialog.c:657
int GWEN_Dialog_SetIntProperty(GWEN_DIALOG *dlg, const char *name, GWEN_DIALOG_PROPERTY prop, int index, int value, int doSignal)
Definition: dialog.c:571
GWEN_DIALOG * GWEN_Dialog_new(const char *dialogId)
Definition: dialog.c:53
int GWEN_Dialog_SetCharProperty(GWEN_DIALOG *dlg, const char *name, GWEN_DIALOG_PROPERTY prop, int index, const char *value, int doSignal)
Definition: dialog.c:628
void GWEN_Dialog_AddMediaPath(GWEN_DIALOG *dlg, const char *s)
Definition: dialog.c:187
#define DBG_INFO(dbg_logger, format, args...)
Definition: debug.h:164
void GWEN_Dialog_free(GWEN_DIALOG *dlg)
Definition: dialog.c:88
int GWEN_Dialog_ReadXmlFile(GWEN_DIALOG *dlg, const char *fname)
Definition: dialog.c:407
GWEN_DIALOG * Dlg_Test1_new()
Definition: dlg_test.c:262
int GWEN_Buffer_AppendString(GWEN_BUFFER *bf, const char *buffer)
Definition: buffer.c:1014