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