gwenhywfar  4.3.3
fox16/libtest.cpp
Go to the documentation of this file.
00001 
00002 #ifdef HAVE_CONFIG_H
00003 # include <config.h>
00004 #endif
00005 
00006 #ifdef OS_WIN32
00007 # include <windows.h>
00008 # define sleep(x) Sleep(x)
00009 #endif
00010 
00011 
00012 #undef BUILDING_FOX16_GUI
00013 
00014 
00015 #include <gwen-gui-fox16/fox16_gui.hpp>
00016 #include "fox16_htmlctx.hpp"
00017 #include "fox16_htmllabel.hpp"
00018 #include "fox16_htmltext.hpp"
00019 
00020 #include "../testdialogs/dlg_test.h"
00021 #include "../testdialogs/dlg_test2.h"
00022 
00023 #include <gwenhywfar/debug.h>
00024 
00025 #include <unistd.h>
00026 
00027 
00028 
00029 int test1(int argc, char **argv) {
00030   FXApp a("libtest","Martin Preuss");
00031   FOX16_Gui *gui;
00032   //int rv;
00033   const char testString[]=
00034 #if 0
00035 # if 0
00036     "This is <b>a</b> test. "
00037     "And this, is the second line: followed by something else."
00038     "<table>"
00039     "  <tr>"
00040     "    <th>header1</th>"
00041     "    <th>header2</th>"
00042     "  </tr>"
00043     "  <tr>"
00044     "    <td>data1</td>"
00045     "    <td>data2</td>"
00046     "  </tr>"
00047     "</table>"
00048     "And   this is   after the table.<br>"
00049     "and this <font color=\"red\">one</font> is red.";
00050 # else
00051     "This is before right"
00052     "<right>RIGHT</right>"
00053     "and this after right.";
00054 # endif
00055 #else
00056     "word";
00057 #endif
00058 
00059   a.init(argc,argv);
00060   a.create();
00061 
00062   gui=new FOX16_Gui(&a);
00063   GWEN_Gui_SetGui(gui->getCInterface());
00064 
00065   FOX16_HtmlCtx ctx(0);
00066   ctx.setText(testString);
00067   //rv=ctx.layout(300, 1024);
00068   //fprintf(stderr, "Result of layout: %d\n", rv);
00069   ctx.dump();
00070 
00071   GWEN_Gui_SetGui(NULL);
00072   delete gui;
00073 
00074   return 0;
00075 }
00076 
00077 
00078 
00079 
00080 int test2(int argc, char **argv) {
00081   FXApp application("libtest","Martin Preuss");
00082   FOX16_Gui *gui;
00083   int rv;
00084   uint32_t id1;
00085   uint32_t id2;
00086   uint64_t i1;
00087   uint64_t i2;
00088 
00089   application.init(argc,argv);
00090 
00091   application.create();
00092 
00093   gui=new FOX16_Gui(&application);
00094   GWEN_Gui_SetGui(gui->getCInterface());
00095 
00096   id1=GWEN_Gui_ProgressStart(GWEN_GUI_PROGRESS_SHOW_LOG |
00097                              GWEN_GUI_PROGRESS_SHOW_ABORT |
00098                              GWEN_GUI_PROGRESS_KEEP_OPEN,
00099                              "Progress-Title",
00100                              "<html>"
00101                              "<p><b>This</b> is an example <i>text</i>..</p>"
00102                              "<p>As you can see <font color=red>colors</font> can "
00103                              "be used.</p>"
00104                              "</html>",
00105                              15,
00106                              0);
00107   for (i1=1; i1<=15; i1++) {
00108     GWEN_Gui_ProgressLog2(id1, GWEN_LoggerLevel_Notice,
00109                           "Step %d: This is a another step in the test of progress widgets",
00110                           (int) i1);
00111     id2=GWEN_Gui_ProgressStart(GWEN_GUI_PROGRESS_SHOW_LOG |
00112                                GWEN_GUI_PROGRESS_DELAY |
00113                                GWEN_GUI_PROGRESS_SHOW_ABORT,
00114                                "2nd progress",
00115                                "Starting 2nd progress...",
00116                                5,
00117                                id1);
00118     for (i2=1; i2<=3; i2++) {
00119       sleep(1);
00120       fprintf(stderr, "Advancing %d/%d\n", (int)i1, (int)i2);
00121       rv=GWEN_Gui_ProgressAdvance(id2, i2);
00122       if (rv==GWEN_ERROR_USER_ABORTED) {
00123         fprintf(stderr, "Aborted by user\n");
00124         break;
00125       }
00126     }
00127     GWEN_Gui_ProgressEnd(id2);
00128 
00129     rv=GWEN_Gui_ProgressAdvance(id1, i1);
00130     if (rv==GWEN_ERROR_USER_ABORTED) {
00131       fprintf(stderr, "Aborted by user\n");
00132       break;
00133     }
00134   }
00135 
00136   GWEN_Gui_ProgressEnd(id1);
00137 
00138   return 0;
00139 }
00140 
00141 
00142 
00143 int test3(int argc, char **argv) {
00144   FXApp a("libtest","Martin Preuss");
00145   FOX16_HtmlLabel *label;
00146   FOX16_Gui *gui;
00147   FXDialogBox *dbox;
00148   FXVerticalFrame *vf;
00149   const char testString[]=
00150 #if 1
00151     "<h1>Title</h1>"
00152     "<h2>Subtitle</h2>"
00153     "This is <b>a</b> test. "
00154     "And this, is the second line: followed by something else."
00155     "<right>This should be right aligned</right>"
00156     "<table>"
00157     "  <tr>"
00158     "    <th>header1</th>"
00159     "    <th>header2</th>"
00160     "  </tr>"
00161     "  <tr>"
00162     "    <td>data1</td>"
00163     "    <td>this is longer data (data2)</td>"
00164     "  </tr>"
00165     "</table>"
00166     "And   this is   after the table.<br>"
00167     "and this <font color=\"red\">one</font> is red.";
00168 #else
00169     "This is before right"
00170     "<right>Right</right>"
00171     "and this after right.";
00172 #endif
00173   a.init(argc,argv);
00174   a.create();
00175 
00176   gui=new FOX16_Gui(&a);
00177   GWEN_Gui_SetGui(gui->getCInterface());
00178 
00179   dbox=new FXDialogBox(&a, "Test", DECOR_ALL);
00180   vf=new FXVerticalFrame(dbox, LAYOUT_FILL_X | LAYOUT_FILL_Y,
00181                          0, 0, 0, 0, 1, 1, 1, 1);
00182   label=new FOX16_HtmlLabel(vf, FXString(testString), LAYOUT_FILL_X|LAYOUT_FILL_Y);
00183   new FXSpring(vf, LAYOUT_FILL_X | LAYOUT_FILL_Y);
00184   new FXLabel(vf, "Normal Testlabel");
00185 
00186   dbox->create();
00187   dbox->resize(300, 200);
00188   dbox->show();
00189   a.runModalFor(dbox);
00190 
00191   return 0;
00192 }
00193 
00194 
00195 
00196 int test4(int argc, char **argv) {
00197   FXApp application("libtest","Martin Preuss");
00198   FOX16_Gui *gui;
00199   int rv;
00200   uint32_t id1;
00201   uint32_t id2;
00202   uint64_t i1;
00203   uint64_t i2;
00204 
00205   application.init(argc,argv);
00206 
00207   application.create();
00208 
00209   gui=new FOX16_Gui(&application);
00210   GWEN_Gui_SetGui(gui->getCInterface());
00211 
00212   id1=GWEN_Gui_ProgressStart(GWEN_GUI_PROGRESS_SHOW_LOG |
00213                              GWEN_GUI_PROGRESS_SHOW_ABORT |
00214                              GWEN_GUI_PROGRESS_KEEP_OPEN,
00215                              "Progress-Title",
00216                              "<html>"
00217                              "<p><b>Test</b> f\xc3\xbcr Umlaute.</p>"
00218                              "</html>",
00219                              10,
00220                              0);
00221   for (i1=1; i1<=10; i1++) {
00222     char numbuf[128];
00223 
00224     snprintf(numbuf, sizeof(numbuf)-1, "Step %d", (int)i1);
00225     GWEN_Gui_ProgressLog(id1, GWEN_LoggerLevel_Notice, numbuf);
00226     id2=GWEN_Gui_ProgressStart(GWEN_GUI_PROGRESS_SHOW_LOG |
00227                                GWEN_GUI_PROGRESS_DELAY |
00228                                GWEN_GUI_PROGRESS_SHOW_ABORT,
00229                                "2nd progress",
00230                                "Starting 2nd progress...",
00231                                10,
00232                                id1);
00233     for (i2=1; i2<=10; i2++) {
00234       sleep(1);
00235       fprintf(stderr, "Advancing %d/%d\n", (int)i1, (int)i2);
00236       rv=GWEN_Gui_ProgressAdvance(id2, i2);
00237       if (rv==GWEN_ERROR_USER_ABORTED) {
00238         fprintf(stderr, "Aborted by user\n");
00239         break;
00240       }
00241     }
00242     GWEN_Gui_ProgressEnd(id2);
00243 
00244     rv=GWEN_Gui_ProgressAdvance(id1, i1);
00245     if (rv==GWEN_ERROR_USER_ABORTED) {
00246       fprintf(stderr, "Aborted by user\n");
00247       break;
00248     }
00249   }
00250 
00251   GWEN_Gui_ProgressEnd(id1);
00252 
00253   return 0;
00254 }
00255 
00256 
00257 
00258 int test5(int argc, char **argv) {
00259   FXApp a("libtest","Martin Preuss");
00260   FOX16_HtmlText *label;
00261   FOX16_Gui *gui;
00262   FXDialogBox *dbox;
00263   FXVerticalFrame *vf;
00264   const char testString[]=
00265 #if 1
00266     "<h1>Test5</h1>"
00267     "<h2>Subtitle</h2>"
00268     "This is <b>a</b> test. "
00269     "And this, is the second line: followed by something else."
00270     "<right>This should be right aligned</right>"
00271     "<table>"
00272     "  <tr>"
00273     "    <th>header1</th>"
00274     "    <th>header2</th>"
00275     "  </tr>"
00276     "  <tr>"
00277     "    <td>data1</td>"
00278     "    <td>this is longer data (data2)</td>"
00279     "  </tr>"
00280     "</table>"
00281     "And   this is   after the table.<br>"
00282     "and this <font color=\"red\">one</font> is red.";
00283 #else
00284     "This is before right"
00285     "<right>Right</right>"
00286     "and this after right.";
00287 #endif
00288   a.init(argc,argv);
00289   a.create();
00290 
00291   gui=new FOX16_Gui(&a);
00292   GWEN_Gui_SetGui(gui->getCInterface());
00293 
00294   dbox=new FXDialogBox(&a, "Test", DECOR_ALL);
00295   vf=new FXVerticalFrame(dbox, LAYOUT_FILL_X | LAYOUT_FILL_Y,
00296                          0, 0, 0, 0, 1, 1, 1, 1);
00297   label=new FOX16_HtmlText(vf, FXString(testString),
00298                            LAYOUT_FILL_X|LAYOUT_FILL_Y |
00299                            HSCROLLING_OFF | VSCROLLER_ALWAYS);
00300   new FXSpring(vf, LAYOUT_FILL_X | LAYOUT_FILL_Y);
00301   new FXLabel(vf, "Normal Testlabel");
00302 
00303   dbox->create();
00304   dbox->resize(300, 200);
00305   dbox->show();
00306   a.runModalFor(dbox);
00307 
00308   return 0;
00309 }
00310 
00311 
00312 
00313 int test6(int argc, char **argv) {
00314   FXApp application("libtest","Martin Preuss");
00315   FOX16_Gui *gui;
00316   int rv;
00317   uint32_t id1;
00318   uint32_t id2;
00319   uint64_t i1;
00320   uint64_t i2;
00321 
00322   application.init(argc,argv);
00323 
00324   application.create();
00325 
00326   gui=new FOX16_Gui(&application);
00327   GWEN_Gui_SetGui(gui->getCInterface());
00328 
00329   id1=GWEN_Gui_ProgressStart(GWEN_GUI_PROGRESS_SHOW_LOG |
00330                              GWEN_GUI_PROGRESS_SHOW_ABORT |
00331                              GWEN_GUI_PROGRESS_KEEP_OPEN,
00332                              "Progress-Title",
00333                              "<html>"
00334                              "<p><b>Test</b> f\xc3\xbcr Umlaute.</p>"
00335                              "</html>",
00336                              10,
00337                              0);
00338   for (i1=1; i1<=20; i1++) {
00339     char numbuf[128];
00340 
00341     snprintf(numbuf, sizeof(numbuf)-1, "Step %d", (int)i1);
00342     GWEN_Gui_ProgressLog(id1, GWEN_LoggerLevel_Notice, numbuf);
00343     id2=GWEN_Gui_ProgressStart(GWEN_GUI_PROGRESS_SHOW_LOG |
00344                                GWEN_GUI_PROGRESS_DELAY |
00345                                GWEN_GUI_PROGRESS_SHOW_ABORT,
00346                                "2nd progress",
00347                                "Starting 2nd progress...",
00348                                5,
00349                                id1);
00350     for (i2=1; i2<=5; i2++) {
00351       sleep(1);
00352       fprintf(stderr, "Advancing %d/%d\n", (int)i1, (int)i2);
00353       GWEN_Gui_ProgressLog(id2, GWEN_LoggerLevel_Notice, "Advancing...");
00354       rv=GWEN_Gui_ProgressAdvance(id2, i2);
00355       if (rv==GWEN_ERROR_USER_ABORTED) {
00356         fprintf(stderr, "Aborted by user\n");
00357         break;
00358       }
00359     }
00360     GWEN_Gui_ProgressEnd(id2);
00361 
00362     rv=GWEN_Gui_ProgressAdvance(id1, i1);
00363     if (rv==GWEN_ERROR_USER_ABORTED) {
00364       fprintf(stderr, "Aborted by user\n");
00365       break;
00366     }
00367   }
00368 
00369   GWEN_Gui_ProgressEnd(id1);
00370 
00371   return 0;
00372 }
00373 
00374 
00375 
00376 int test7(int argc, char **argv) {
00377   FXApp application("libtest","Martin Preuss");
00378   FOX16_Gui *gui;
00379   char buffer[65];
00380 
00381   application.init(argc,argv);
00382 
00383   application.create();
00384 
00385   gui=new FOX16_Gui(&application);
00386   GWEN_Gui_SetGui(gui->getCInterface());
00387 
00388   GWEN_Gui_InputBox(GWEN_GUI_INPUT_FLAGS_SHOW,
00389                     "This is the Title",
00390                     "<html>This is the text.</html>This is ASCII",
00391                     buffer,
00392                     1,
00393                     sizeof(buffer)-1,
00394                     0);
00395 
00396 
00397   return 0;
00398 }
00399 
00400 
00401 
00402 int test8(int argc, char **argv) {
00403   FXApp application("libtest","Martin Preuss");
00404   FOX16_Gui *gui;
00405   int rv;
00406   GWEN_DIALOG *dlg;
00407 
00408   application.init(argc,argv);
00409 
00410   application.create();
00411 
00412   gui=new FOX16_Gui(&application);
00413   GWEN_Gui_SetGui(gui->getCInterface());
00414 
00415 
00416   GWEN_Logger_SetLevel(0, GWEN_LoggerLevel_Debug);
00417   GWEN_Logger_SetLevel(GWEN_LOGDOMAIN, GWEN_LoggerLevel_Verbous);
00418 
00419   dlg=Dlg_Test1_new();
00420   if (dlg==NULL) {
00421     fprintf(stderr, "Could not create dialog.\n");
00422     return 2;
00423   }
00424 
00425   rv=GWEN_Gui_ExecDialog(dlg, 0);
00426   fprintf(stderr, "Result: %d\n", rv);
00427 
00428   return 0;
00429 }
00430 
00431 
00432 
00433 int test9(int argc, char **argv) {
00434   FXApp application("libtest","Martin Preuss");
00435   FOX16_Gui *gui;
00436   int rv;
00437   GWEN_DIALOG *dlg;
00438 
00439   application.init(argc,argv);
00440 
00441   application.create();
00442 
00443   gui=new FOX16_Gui(&application);
00444   GWEN_Gui_SetGui(gui->getCInterface());
00445 
00446 
00447   GWEN_Logger_SetLevel(0, GWEN_LoggerLevel_Debug);
00448   GWEN_Logger_SetLevel(GWEN_LOGDOMAIN, GWEN_LoggerLevel_Verbous);
00449 
00450   dlg=Dlg_Test2_new();
00451   if (dlg==NULL) {
00452     fprintf(stderr, "Could not create dialog.\n");
00453     return 2;
00454   }
00455 
00456   rv=GWEN_Gui_ExecDialog(dlg, 0);
00457   fprintf(stderr, "Result: %d\n", rv);
00458 
00459   return 0;
00460 }
00461 
00462 
00463 
00464 
00465 int main(int argc, char **argv) {
00466   if (argc>1) {
00467     if (strcasecmp(argv[1], "1")==0)
00468       return test1(argc, argv);
00469     else if (strcasecmp(argv[1], "2")==0)
00470       return test2(argc, argv);
00471     else if (strcasecmp(argv[1], "3")==0)
00472       return test3(argc, argv);
00473     else if (strcasecmp(argv[1], "4")==0)
00474       return test4(argc, argv);
00475     else if (strcasecmp(argv[1], "5")==0)
00476       return test5(argc, argv);
00477     else if (strcasecmp(argv[1], "6")==0)
00478       return test6(argc, argv);
00479     else if (strcasecmp(argv[1], "7")==0)
00480       return test7(argc, argv);
00481     else if (strcasecmp(argv[1], "8")==0)
00482       return test8(argc, argv);
00483     else if (strcasecmp(argv[1], "9")==0)
00484       return test9(argc, argv);
00485   }
00486   else
00487     return test7(argc, argv);
00488 }
00489 
00490 
00491