home *** CD-ROM | disk | FTP | other *** search
/ ST-Computer Leser 1998 October / STC_CD_10_1998.iso / BASE / CFLIB / DEMO / DEMO.C < prev    next >
Encoding:
C/C++ Source or Header  |  1998-09-26  |  8.8 KB  |  421 lines

  1. /*
  2.  * Demo-Programm für die CF-Lib
  3.  */
  4. #include <cflib.h>
  5.  
  6. #include "demo.h"
  7.  
  8. /* in pdlg.c */
  9. extern void test_pdlg(bool win);
  10.  
  11. /* --------------------------------------------------------------------------- */
  12. OBJECT    *menu, *objdial, *popdial, *wicon, *popups, *about;
  13. WDIALOG    *wdial;
  14. bool        quit;
  15. int        msg[8], vdi_handle;
  16. int        event, msx, msy, mbutton, kstate, mclick, kreturn, win_handle;
  17. bool        modal = FALSE;
  18. int        id = 1, pts = 10;
  19.  
  20. static void handle_msg(int *msg);
  21.  
  22. /* --------------------------------------------------------------------------- */
  23. /* 
  24.  * Ein Dummy-Fenster, da₧ einfach nur da ist, damit man sieht, da₧ bei 
  25.  * app-modalen Dialogen Redraw-, Move- und Size-Aktionen ausgewertet 
  26.  * werden.
  27. */
  28. void redraw_win(int handle, int xc, int yc, int wc, int hc)
  29. {
  30.     GRECT    t1,t2;
  31.     int    temp[4];
  32.     
  33.     hide_mouse();
  34.     wind_update(TRUE);
  35.     t2.g_x = xc; t2.g_y = yc; t2.g_w = wc; t2.g_h = hc;
  36.     wind_get_grect(handle, WF_FIRSTXYWH, &t1);
  37.     vsf_color(vdi_handle, 0);
  38.  
  39.     wind_get(handle, WF_WORKXYWH, &temp[0], &temp[1], &temp[2], &temp[3]);
  40.     temp[2] += temp[0] - 1;
  41.     temp[3] += temp[1] - 1;
  42.  
  43.     while (t1.g_w && t1.g_h)
  44.     {
  45.         if (rc_intersect(&t2, &t1))
  46.         {
  47.             set_clipping(vdi_handle, t1.g_x, t1.g_y, t1.g_w, t1.g_h, TRUE);
  48.             v_bar(vdi_handle, temp);
  49.         }
  50.         wind_get(handle, WF_NEXTXYWH, &t1.g_x, &t1.g_y, &t1.g_w, &t1.g_h);
  51.     }
  52.     wind_update(FALSE);
  53.     show_mouse();
  54. }
  55.  
  56. void open_win(void)
  57. {
  58.     int    work_out[57];
  59.     
  60.     vdi_handle = open_vwork(work_out);
  61.     win_handle = wind_create((NAME|MOVER|CLOSER|SIZER), gl_desk.g_x, gl_desk.g_y, gl_desk.g_w, gl_desk.g_h);
  62.     wind_set_str(win_handle, WF_NAME, " Fenster ");
  63.     wind_open(win_handle, 100, 100, 350, 150);
  64. }
  65.  
  66. void win_msg(int *msg)
  67. {
  68.     if (msg[3] == win_handle)
  69.     {
  70.         switch (msg[0])
  71.         {
  72.             case WM_CLOSED :
  73.                 wind_close(win_handle);
  74.                 break;
  75.             case WM_BOTTOMED:
  76.                 wind_set(win_handle, WF_BOTTOM, 0, 0, 0, 0);
  77.                 break;
  78.             case WM_REDRAW:
  79.                 redraw_win(win_handle, msg[4], msg[5], msg[6], msg[7]);
  80.                 break;
  81.             case WM_NEWTOP:
  82.             case WM_TOPPED:
  83.                 wind_set(win_handle, WF_TOP, 0, 0, 0, 0);
  84.                 break;
  85.             case WM_MOVED:
  86.                 wind_set(win_handle, WF_CURRXYWH, msg[4], msg[5], msg[6], msg[7]);
  87.                 break;
  88.             case WM_SIZED:
  89.                 wind_set(win_handle, WF_CURRXYWH, msg[4], msg[5], msg[6], msg[7]);
  90.                 break;
  91.         }
  92.     }
  93. }
  94.  
  95. /* --------------------------------------------------------------------------- */
  96.  
  97. void modal_dial(void)
  98. {
  99.     int    x, y, w, h, antw, edit;
  100.  
  101.     wind_update(BEG_UPDATE);
  102.     form_center(objdial, &x, &y, &w, &h);
  103.     form_dial(FMD_START, x, y, w, h, x, y, w, h);
  104.  
  105.     objc_draw(objdial, ROOT, MAX_DEPTH, x, y, w, h);
  106.     edit = EDIT1;
  107.     do
  108.     {
  109.         antw = cf_form_do(objdial, &edit);
  110.     }
  111.     while (antw != ENDE && antw != UNDO);
  112.     set_state(objdial, antw, SELECTED, FALSE);
  113.     form_dial(FMD_FINISH, x, y, w, h, x, y, w, h);
  114.     wind_update(END_UPDATE);
  115.     if (antw == ENDE)
  116.         quit = TRUE;
  117. }
  118.  
  119. /* --------------------------------------------------------------------------- */
  120.  
  121. void appmodal_dial(void)
  122. {
  123.     void    *mdial;
  124.     bool    close = FALSE;
  125.     int    id, exit_obj;
  126.     
  127.     mdial = open_mdial(objdial, EDIT1);
  128.     while (!close)
  129.     {
  130.         exit_obj = do_mdial(mdial);
  131.         switch (exit_obj)
  132.         {
  133.             case EXITBUT :
  134.                 do_walert(1, 2, "[1][Mdial ist re-entrant!][Toll]", "Alert");
  135.                 break;
  136.             
  137.             case ENDE :
  138.                 quit = TRUE;
  139.                 close = TRUE;
  140.                 break;
  141.     
  142.             case HELP :
  143.                 id = appl_find("ST-GUIDE");
  144.                 if (id > 0)
  145.                     send_vastart(id, "*:\\cf-lib.hyp");
  146.                 break;
  147.                 
  148.             case UNDO :
  149.                 close = TRUE;
  150.                 break;
  151.         }
  152.         if (get_flag(objdial, exit_obj, EXIT))
  153.             set_state(objdial, exit_obj, SELECTED, FALSE);
  154.         if (!close)
  155.             redraw_mdobj(mdial, exit_obj);
  156.     }
  157.     close_mdial(mdial);
  158. }
  159.  
  160. /* --------------------------------------------------------------------------- */
  161.  
  162. POPUP    pop;
  163.  
  164. void nonmodal_open_cb(WDIALOG *wd)
  165. {
  166.     char    str[10];
  167.  
  168.     /* dynamisches Popup anlegen */
  169.     set_string(wd->tree, P1TEXT, "bla");
  170.     create_popup(&pop, 5, 23, " zeile1");
  171.     append_popup(&pop, " zeile2zeile2");
  172.     append_popup(&pop, " zeile3zeile3zeile3");
  173.  
  174.     get_string(popups, 20/*POPF1*/, str);
  175.     set_string(wd->tree, P2BOX, str);
  176. }
  177.  
  178. bool nonmodal_exit_cb(WDIALOG *wd, int obj)
  179. {
  180.     bool    close = FALSE;
  181.     int    y;
  182.     char    s[30];
  183.     
  184.     switch (obj)
  185.     {
  186.         case P1STR :
  187.             break;
  188.             
  189.         case P1BOX :
  190.             y = handle_popup(wd->tree, P1BOX, pop.tree, 0, POP_OPEN);
  191.             if (y > 0)
  192.             {
  193.                 get_string(pop.tree, y, s);
  194.                 set_string(wd->tree, P1TEXT, s+1);
  195.                 redraw_wdobj(wd, P1TEXT);
  196.             }
  197.             break;
  198.             
  199.         case P2STR :
  200.         case P2BOX :
  201.             if (obj == P2STR)
  202.                 handle_popup(wd->tree, P2BOX, popups, FUNCPOP, POP_CYCLE);
  203.             else
  204.                 handle_popup(wd->tree, P2BOX, popups, FUNCPOP, POP_OPEN);
  205.             break;
  206.             
  207.         case WD_CLOSER :
  208.             close = TRUE;
  209.             debug("Closer ohne UNDO-Button!\n");
  210.             break;
  211.         
  212.     }
  213.     if (close)
  214.         free_popup(&pop);
  215.     return close;
  216. }
  217.  
  218. /* --------------------------------------------------------------------------- */
  219. void fsel_cb(char *path, char *name)
  220. {
  221. /* hier laufen die Dateinamen/Pfade bei einer Mehrfach-Dateiselektion auf */
  222. }
  223.  
  224. /* --------------------------------------------------------------------------- */
  225. void handle_menu(int title, int item)
  226. {
  227.     switch (item)
  228.     {
  229.         case MABOUT :
  230.             simple_mdial(about, 0);
  231.             break;
  232.  
  233.  
  234.         case MFSEL :
  235.             {
  236.                 char    path[50] = "",
  237.                         name[50] = "";
  238.  
  239.                 if (select_file(path, name, "", "Dateiauswahl im Fenster", fsel_cb) && 
  240.                         (path[0] != EOS))
  241.                     debug("    %s%s\n", path, name);
  242.             }
  243.             break;
  244.  
  245.         case MENDE :
  246.             quit = TRUE;
  247.             break;
  248.  
  249.  
  250.         case MDIAL1 :
  251.             if (modal)
  252.                 modal_dial();
  253.             else
  254.                 appmodal_dial();
  255.             break;
  256.  
  257.         case MDIAL2 :
  258.             open_wdial(wdial, -1, -1);
  259.             break;
  260.  
  261.         case MALERT :
  262.             if (modal)
  263.                 do_alert(1, 2, "[1][Dies ist ein modaler Alert.][OK|UNDO]");
  264.             else
  265.                 do_walert(1, 3, "[3][Dies ist ein Alert im Fenster.|Mit Text in der zweiten Zeile|und drei Buttons.|Und UNDO auf Abbruch!][Ja|Nein|Abbruch]",  " Fenster-Alert ");
  266.             break;
  267.             
  268.         case MFONTSEL :
  269.             if (!do_fontsel((FS_M_MAGX|FS_M_XFSL), "Im Fenster", &id, &pts) && (id == -1))
  270.             {
  271.                 do_walert(1, 0, "[3][Keine Fontauswahl verfügbar!][OK]", "Alert");
  272.                 id = 1;
  273.                 pts = 10;
  274.             }
  275.             break;
  276.             
  277.         case MPDLG :
  278.             test_pdlg(!modal);
  279.             break;
  280.             
  281.         case MASCII :
  282.             set_asciitable_strings("Aktueller Font", "");
  283.             ascii_table(id, 10);
  284.             break;
  285.  
  286.  
  287.         case MMODAL :
  288.         case MFENSTER :
  289.             if (!modal && item == MMODAL)
  290.                 modal = TRUE;
  291.             else if (modal && item == MFENSTER)
  292.                 modal = FALSE;
  293.             menu_icheck(menu, MMODAL, modal);
  294.             menu_icheck(menu, MFENSTER, !modal);
  295.             if (modal)
  296.                 set_mdial_wincb(0L);
  297.             else
  298.                 set_mdial_wincb(handle_msg);
  299.             break;
  300.  
  301.  
  302.         default:
  303.             if (title == TSCUT)
  304.             {
  305.                 char str[50], s2[50];
  306.  
  307.                 get_string(menu, item, str);
  308.                 sprintf(s2, "[1][%s][OK]", str);
  309.                 do_walert(1, 0, s2, "Menü: Shortcuts");
  310.             }
  311.             break;
  312.     }
  313.     menu_tnormal(menu, title, 1);
  314. }
  315.  
  316. static void handle_msg(int *msg)
  317. {
  318.     if (!message_wdial(msg))
  319.     {
  320.         switch (msg[0])
  321.         {
  322.             case MN_SELECTED:
  323.                 handle_menu(msg[3], msg[4]);
  324.                 break;
  325.  
  326.             case WM_CLOSED :
  327.             case WM_BOTTOMED:
  328.             case WM_REDRAW:
  329.             case WM_NEWTOP:
  330.             case WM_TOPPED:
  331.             case WM_MOVED:
  332.             case WM_SIZED :
  333.                 win_msg(msg);
  334.                 break;
  335.  
  336.             case AP_TERM :
  337.                 quit = TRUE;
  338.                 break;
  339.         }
  340.     }
  341. }
  342.  
  343. /* --------------------------------------------------------------------------- */
  344. extern void cf_use_all_userdefs(bool all);
  345.  
  346. void main(void)
  347. {
  348.     OBJECT    *tree;
  349.     
  350.     init_app("demo.rsc");
  351.  
  352.     rsrc_gaddr(R_TREE, MENUTREE, &menu);
  353.     create_menu(menu);
  354.     menu_icheck(menu, MMODAL, modal);
  355.     menu_icheck(menu, MFENSTER, !modal);
  356.  
  357.     rsrc_gaddr(R_TREE, OBJDIAL, &objdial);
  358.     fix_dial(objdial);
  359.     
  360.     rsrc_gaddr(R_TREE, POPDIAL, &tree);
  361.     fix_dial(tree);
  362.     rsrc_gaddr(R_TREE, WINICON, &wicon);
  363.     wdial = create_wdial(tree, wicon, P1TEXT, nonmodal_open_cb, nonmodal_exit_cb);
  364.  
  365.     rsrc_gaddr(R_TREE, POPUPS, &popups);
  366.     fix_menu(popups);
  367.  
  368.     rsrc_gaddr(R_TREE, ABOUT, &about);
  369.     fix_menu(about);
  370.     set_string(about, A_PL, CFLIB_PATCHLEVEL);
  371.  
  372.     rsrc_gaddr(R_TREE, PRN_SUB, &tree);
  373.     fix_dial(tree);
  374.  
  375.     if (!modal)
  376.         set_mdial_wincb(handle_msg);
  377.  
  378.     open_win();
  379.  
  380.     quit = FALSE;
  381.  
  382.     while (!quit)
  383.     {
  384.         mbutton = 0;
  385.         event = evnt_multi(MU_MESAG|MU_BUTTON|MU_KEYBD,
  386.                                     1, 1, 1, 
  387.                                     0, 0, 0, 0, 0,
  388.                                     0, 0, 0, 0, 0,
  389.                                     msg,
  390.                                     0,
  391.                                     &msx, &msy, &mbutton, &kstate,
  392.                                     &kreturn, &mclick);
  393.  
  394.         if (event & MU_MESAG) 
  395.             handle_msg(msg);
  396.  
  397.         if (event & MU_BUTTON) 
  398.         {
  399.             if (!click_wdial(mclick, msx, msy, kstate, mbutton))
  400.                 ;
  401.         }        
  402.         if (event & MU_KEYBD)
  403.         {
  404.             if (!key_wdial(kreturn, kstate))
  405.             {
  406.                 int    title, item;
  407.                 
  408.                 if (is_menu_key(kreturn, kstate, &title, &item))
  409.                     handle_menu(title, item);
  410.             }
  411.         }
  412.     } 
  413.     delete_wdial(wdial);    
  414.     wind_close(win_handle);
  415.     wind_delete(win_handle);
  416.     v_clsvwk(vdi_handle);
  417.     
  418.     delete_menu();
  419.     exit_app(0);
  420. }
  421.