gwenhywfar  4.3.3
fox16/libtest.cpp
Go to the documentation of this file.
1 
2 #ifdef HAVE_CONFIG_H
3 # include <config.h>
4 #endif
5 
6 #ifdef OS_WIN32
7 # include <windows.h>
8 # define sleep(x) Sleep(x)
9 #endif
10 
11 
12 #undef BUILDING_FOX16_GUI
13 
14 
15 #include <gwen-gui-fox16/fox16_gui.hpp>
16 #include "fox16_htmlctx.hpp"
17 #include "fox16_htmllabel.hpp"
18 #include "fox16_htmltext.hpp"
19 
20 #include "../testdialogs/dlg_test.h"
21 #include "../testdialogs/dlg_test2.h"
22 
23 #include <gwenhywfar/debug.h>
24 
25 #include <unistd.h>
26 
27 
28 
29 int test1(int argc, char **argv) {
30  FXApp a("libtest","Martin Preuss");
31  FOX16_Gui *gui;
32  //int rv;
33  const char testString[]=
34 #if 0
35 # if 0
36  "This is <b>a</b> test. "
37  "And this, is the second line: followed by something else."
38  "<table>"
39  " <tr>"
40  " <th>header1</th>"
41  " <th>header2</th>"
42  " </tr>"
43  " <tr>"
44  " <td>data1</td>"
45  " <td>data2</td>"
46  " </tr>"
47  "</table>"
48  "And this is after the table.<br>"
49  "and this <font color=\"red\">one</font> is red.";
50 # else
51  "This is before right"
52  "<right>RIGHT</right>"
53  "and this after right.";
54 # endif
55 #else
56  "word";
57 #endif
58 
59  a.init(argc,argv);
60  a.create();
61 
62  gui=new FOX16_Gui(&a);
64 
65  FOX16_HtmlCtx ctx(0);
66  ctx.setText(testString);
67  //rv=ctx.layout(300, 1024);
68  //fprintf(stderr, "Result of layout: %d\n", rv);
69  ctx.dump();
70 
72  delete gui;
73 
74  return 0;
75 }
76 
77 
78 
79 
80 int test2(int argc, char **argv) {
81  FXApp application("libtest","Martin Preuss");
82  FOX16_Gui *gui;
83  int rv;
84  uint32_t id1;
85  uint32_t id2;
86  uint64_t i1;
87  uint64_t i2;
88 
89  application.init(argc,argv);
90 
91  application.create();
92 
93  gui=new FOX16_Gui(&application);
95 
99  "Progress-Title",
100  "<html>"
101  "<p><b>This</b> is an example <i>text</i>..</p>"
102  "<p>As you can see <font color=red>colors</font> can "
103  "be used.</p>"
104  "</html>",
105  15,
106  0);
107  for (i1=1; i1<=15; i1++) {
109  "Step %d: This is a another step in the test of progress widgets",
110  (int) i1);
114  "2nd progress",
115  "Starting 2nd progress...",
116  5,
117  id1);
118  for (i2=1; i2<=3; i2++) {
119  sleep(1);
120  fprintf(stderr, "Advancing %d/%d\n", (int)i1, (int)i2);
121  rv=GWEN_Gui_ProgressAdvance(id2, i2);
122  if (rv==GWEN_ERROR_USER_ABORTED) {
123  fprintf(stderr, "Aborted by user\n");
124  break;
125  }
126  }
128 
129  rv=GWEN_Gui_ProgressAdvance(id1, i1);
130  if (rv==GWEN_ERROR_USER_ABORTED) {
131  fprintf(stderr, "Aborted by user\n");
132  break;
133  }
134  }
135 
137 
138  return 0;
139 }
140 
141 
142 
143 int test3(int argc, char **argv) {
144  FXApp a("libtest","Martin Preuss");
145  FOX16_HtmlLabel *label;
146  FOX16_Gui *gui;
147  FXDialogBox *dbox;
148  FXVerticalFrame *vf;
149  const char testString[]=
150 #if 1
151  "<h1>Title</h1>"
152  "<h2>Subtitle</h2>"
153  "This is <b>a</b> test. "
154  "And this, is the second line: followed by something else."
155  "<right>This should be right aligned</right>"
156  "<table>"
157  " <tr>"
158  " <th>header1</th>"
159  " <th>header2</th>"
160  " </tr>"
161  " <tr>"
162  " <td>data1</td>"
163  " <td>this is longer data (data2)</td>"
164  " </tr>"
165  "</table>"
166  "And this is after the table.<br>"
167  "and this <font color=\"red\">one</font> is red.";
168 #else
169  "This is before right"
170  "<right>Right</right>"
171  "and this after right.";
172 #endif
173  a.init(argc,argv);
174  a.create();
175 
176  gui=new FOX16_Gui(&a);
178 
179  dbox=new FXDialogBox(&a, "Test", DECOR_ALL);
180  vf=new FXVerticalFrame(dbox, LAYOUT_FILL_X | LAYOUT_FILL_Y,
181  0, 0, 0, 0, 1, 1, 1, 1);
182  label=new FOX16_HtmlLabel(vf, FXString(testString), LAYOUT_FILL_X|LAYOUT_FILL_Y);
183  new FXSpring(vf, LAYOUT_FILL_X | LAYOUT_FILL_Y);
184  new FXLabel(vf, "Normal Testlabel");
185 
186  dbox->create();
187  dbox->resize(300, 200);
188  dbox->show();
189  a.runModalFor(dbox);
190 
191  return 0;
192 }
193 
194 
195 
196 int test4(int argc, char **argv) {
197  FXApp application("libtest","Martin Preuss");
198  FOX16_Gui *gui;
199  int rv;
200  uint32_t id1;
201  uint32_t id2;
202  uint64_t i1;
203  uint64_t i2;
204 
205  application.init(argc,argv);
206 
207  application.create();
208 
209  gui=new FOX16_Gui(&application);
211 
215  "Progress-Title",
216  "<html>"
217  "<p><b>Test</b> f\xc3\xbcr Umlaute.</p>"
218  "</html>",
219  10,
220  0);
221  for (i1=1; i1<=10; i1++) {
222  char numbuf[128];
223 
224  snprintf(numbuf, sizeof(numbuf)-1, "Step %d", (int)i1);
229  "2nd progress",
230  "Starting 2nd progress...",
231  10,
232  id1);
233  for (i2=1; i2<=10; i2++) {
234  sleep(1);
235  fprintf(stderr, "Advancing %d/%d\n", (int)i1, (int)i2);
236  rv=GWEN_Gui_ProgressAdvance(id2, i2);
237  if (rv==GWEN_ERROR_USER_ABORTED) {
238  fprintf(stderr, "Aborted by user\n");
239  break;
240  }
241  }
243 
244  rv=GWEN_Gui_ProgressAdvance(id1, i1);
245  if (rv==GWEN_ERROR_USER_ABORTED) {
246  fprintf(stderr, "Aborted by user\n");
247  break;
248  }
249  }
250 
252 
253  return 0;
254 }
255 
256 
257 
258 int test5(int argc, char **argv) {
259  FXApp a("libtest","Martin Preuss");
260  FOX16_HtmlText *label;
261  FOX16_Gui *gui;
262  FXDialogBox *dbox;
263  FXVerticalFrame *vf;
264  const char testString[]=
265 #if 1
266  "<h1>Test5</h1>"
267  "<h2>Subtitle</h2>"
268  "This is <b>a</b> test. "
269  "And this, is the second line: followed by something else."
270  "<right>This should be right aligned</right>"
271  "<table>"
272  " <tr>"
273  " <th>header1</th>"
274  " <th>header2</th>"
275  " </tr>"
276  " <tr>"
277  " <td>data1</td>"
278  " <td>this is longer data (data2)</td>"
279  " </tr>"
280  "</table>"
281  "And this is after the table.<br>"
282  "and this <font color=\"red\">one</font> is red.";
283 #else
284  "This is before right"
285  "<right>Right</right>"
286  "and this after right.";
287 #endif
288  a.init(argc,argv);
289  a.create();
290 
291  gui=new FOX16_Gui(&a);
293 
294  dbox=new FXDialogBox(&a, "Test", DECOR_ALL);
295  vf=new FXVerticalFrame(dbox, LAYOUT_FILL_X | LAYOUT_FILL_Y,
296  0, 0, 0, 0, 1, 1, 1, 1);
297  label=new FOX16_HtmlText(vf, FXString(testString),
298  LAYOUT_FILL_X|LAYOUT_FILL_Y |
299  HSCROLLING_OFF | VSCROLLER_ALWAYS);
300  new FXSpring(vf, LAYOUT_FILL_X | LAYOUT_FILL_Y);
301  new FXLabel(vf, "Normal Testlabel");
302 
303  dbox->create();
304  dbox->resize(300, 200);
305  dbox->show();
306  a.runModalFor(dbox);
307 
308  return 0;
309 }
310 
311 
312 
313 int test6(int argc, char **argv) {
314  FXApp application("libtest","Martin Preuss");
315  FOX16_Gui *gui;
316  int rv;
317  uint32_t id1;
318  uint32_t id2;
319  uint64_t i1;
320  uint64_t i2;
321 
322  application.init(argc,argv);
323 
324  application.create();
325 
326  gui=new FOX16_Gui(&application);
328 
332  "Progress-Title",
333  "<html>"
334  "<p><b>Test</b> f\xc3\xbcr Umlaute.</p>"
335  "</html>",
336  10,
337  0);
338  for (i1=1; i1<=20; i1++) {
339  char numbuf[128];
340 
341  snprintf(numbuf, sizeof(numbuf)-1, "Step %d", (int)i1);
346  "2nd progress",
347  "Starting 2nd progress...",
348  5,
349  id1);
350  for (i2=1; i2<=5; i2++) {
351  sleep(1);
352  fprintf(stderr, "Advancing %d/%d\n", (int)i1, (int)i2);
353  GWEN_Gui_ProgressLog(id2, GWEN_LoggerLevel_Notice, "Advancing...");
354  rv=GWEN_Gui_ProgressAdvance(id2, i2);
355  if (rv==GWEN_ERROR_USER_ABORTED) {
356  fprintf(stderr, "Aborted by user\n");
357  break;
358  }
359  }
361 
362  rv=GWEN_Gui_ProgressAdvance(id1, i1);
363  if (rv==GWEN_ERROR_USER_ABORTED) {
364  fprintf(stderr, "Aborted by user\n");
365  break;
366  }
367  }
368 
370 
371  return 0;
372 }
373 
374 
375 
376 int test7(int argc, char **argv) {
377  FXApp application("libtest","Martin Preuss");
378  FOX16_Gui *gui;
379  char buffer[65];
380 
381  application.init(argc,argv);
382 
383  application.create();
384 
385  gui=new FOX16_Gui(&application);
387 
389  "This is the Title",
390  "<html>This is the text.</html>This is ASCII",
391  buffer,
392  1,
393  sizeof(buffer)-1,
394  0);
395 
396 
397  return 0;
398 }
399 
400 
401 
402 int test8(int argc, char **argv) {
403  FXApp application("libtest","Martin Preuss");
404  FOX16_Gui *gui;
405  int rv;
406  GWEN_DIALOG *dlg;
407 
408  application.init(argc,argv);
409 
410  application.create();
411 
412  gui=new FOX16_Gui(&application);
414 
415 
418 
419  dlg=Dlg_Test1_new();
420  if (dlg==NULL) {
421  fprintf(stderr, "Could not create dialog.\n");
422  return 2;
423  }
424 
425  rv=GWEN_Gui_ExecDialog(dlg, 0);
426  fprintf(stderr, "Result: %d\n", rv);
427 
428  return 0;
429 }
430 
431 
432 
433 int test9(int argc, char **argv) {
434  FXApp application("libtest","Martin Preuss");
435  FOX16_Gui *gui;
436  int rv;
437  GWEN_DIALOG *dlg;
438 
439  application.init(argc,argv);
440 
441  application.create();
442 
443  gui=new FOX16_Gui(&application);
445 
446 
449 
450  dlg=Dlg_Test2_new();
451  if (dlg==NULL) {
452  fprintf(stderr, "Could not create dialog.\n");
453  return 2;
454  }
455 
456  rv=GWEN_Gui_ExecDialog(dlg, 0);
457  fprintf(stderr, "Result: %d\n", rv);
458 
459  return 0;
460 }
461 
462 
463 
464 
465 int main(int argc, char **argv) {
466  if (argc>1) {
467  if (strcasecmp(argv[1], "1")==0)
468  return test1(argc, argv);
469  else if (strcasecmp(argv[1], "2")==0)
470  return test2(argc, argv);
471  else if (strcasecmp(argv[1], "3")==0)
472  return test3(argc, argv);
473  else if (strcasecmp(argv[1], "4")==0)
474  return test4(argc, argv);
475  else if (strcasecmp(argv[1], "5")==0)
476  return test5(argc, argv);
477  else if (strcasecmp(argv[1], "6")==0)
478  return test6(argc, argv);
479  else if (strcasecmp(argv[1], "7")==0)
480  return test7(argc, argv);
481  else if (strcasecmp(argv[1], "8")==0)
482  return test8(argc, argv);
483  else if (strcasecmp(argv[1], "9")==0)
484  return test9(argc, argv);
485  }
486  else
487  return test7(argc, argv);
488 }
489 
490 
491