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

  1. #include <cflib.h>
  2. #include <gemx.h>
  3.  
  4. #include    "demo.h"
  5.  
  6. /* Event-Routine der MDials */
  7. extern void handle_mdial_msg(int *msg);
  8.  
  9. extern OBJECT    *popups;
  10.     
  11. /*
  12.  * Callbacks für Sub-Dialog
  13. */
  14. long __CDECL init_qed_sub(PRN_SETTINGS *settings, PDLG_SUB *sub_dialog)
  15. {
  16.     OBJECT    *tree;
  17.     int        offset;
  18.  
  19.     tree = sub_dialog->tree;
  20.     offset = sub_dialog->index_offset;
  21.  
  22.     set_string(tree, PS_WPNAME + offset, "<unbekannt>");
  23.     set_int(tree, PS_WPSL + offset, 65);
  24.     set_int(tree, PS_WPZL + offset, 80);
  25.  
  26.     set_string(tree, PS_GFNAME + offset, "6x6 system font");
  27.     set_int(tree, PS_GFPTS + offset, 10);
  28.  
  29.     return 1;
  30. }
  31.  
  32. long __CDECL do_qed_sub(PRN_SETTINGS *settings, PDLG_SUB *sub_dialog, short exit_obj)
  33. {
  34.     OBJECT    *tree;
  35.     int        offset;
  36.     int        id = 1, pts = 10;
  37.  
  38.     tree = sub_dialog->tree;
  39.     offset = sub_dialog->index_offset;
  40.     switch (exit_obj - offset)
  41.     {
  42.         case PS_WPDSTR :
  43.         case PS_WPDPOP :
  44.             if ((exit_obj - offset) == PS_WPDPOP)
  45.                 handle_popup(tree, PS_WPDPOP + offset, popups, DICHTEPOP, POP_OPEN);
  46.             else
  47.                 handle_popup(tree, PS_WPDPOP + offset, popups, DICHTEPOP, POP_CYCLE);
  48.             break;
  49.  
  50.         case PS_WPSEL :
  51.             set_state(tree, exit_obj, SELECTED, FALSE);
  52.             redraw_obj(tree, exit_obj);
  53.             break;
  54.     
  55.         case PS_GFSEL :
  56.             do_fontsel((FS_M_XFSL|FS_M_MAGX), "Druckerfont wählen", &id, &pts);
  57.             set_state(tree, exit_obj, SELECTED, FALSE);
  58.             redraw_obj(tree, exit_obj);
  59.             break;
  60.     }
  61.     return 1;
  62. }
  63.  
  64. long __CDECL reset_qed_sub(PRN_SETTINGS *settings, PDLG_SUB *sub_dialog)
  65. {
  66. /*
  67.     OBJECT    *tree;
  68.     int        offset;
  69.  
  70.     tree = sub_dialog->tree;
  71.     offset = sub_dialog->index_offset;
  72. */
  73.     return 1;
  74. }
  75.  
  76.  
  77. PDLG_SUB    *create_sub_dialog(void)
  78. {
  79.     PDLG_SUB    *sub = NULL;
  80.     OBJECT    *tree;
  81.  
  82.     sub = malloc(sizeof(PDLG_SUB));
  83.     if (sub)
  84.     {
  85.         sub->next = 0L;
  86.         sub->option_flags = 0;
  87.         sub->sub_id = -1;
  88.  
  89.         rsrc_gaddr(R_TREE, PDLGICON, &tree);
  90.         sub->sub_icon = tree + PRN_ICON;        /* Zeiger auf das Icon */
  91.  
  92.         rsrc_gaddr(R_TREE, PRN_SUB, &tree);
  93.         sub->sub_tree = tree;                    /* Zeiger auf den Unterdialogs */
  94.  
  95.         sub->dialog = 0L;                            /* Zeiger auf die Struktur des Fensterdialogs oder 0L */
  96.         sub->tree = 0L;                            /* Zeiger auf den zusammengesetzen Objektbaum */
  97.         sub->index_offset = 0;                    /* Indexverschiebung des Unterdialogs */
  98.         sub->reserved1 = 0;
  99.         sub->reserved2 = 0;
  100.  
  101.         sub->init_dlg = init_qed_sub;            /* Initialisierungsfunktion */
  102.         sub->do_dlg = do_qed_sub;                /* Behandlungsfunktion */
  103.         sub->reset_dlg = reset_qed_sub;        /* Zurücksetzfunktion */
  104.         sub->reserved3 = 0;
  105.     }
  106.     return sub;
  107. }
  108.  
  109.  
  110. int wlfp_available( void )
  111. {
  112.     int    ag1, ag2, ag3, ag4;
  113.  
  114.     if (appl_xgetinfo(7, &ag1, &ag2, &ag3, &ag4))
  115.     {
  116.         if ((ag1 & 0x17 ) == 0x17)
  117.             return 1;
  118.     }
  119.     return 0;
  120. }
  121.  
  122. /* --------------------------------------------------------------------------- */
  123. static void save_settings(PRN_SETTINGS *settings)
  124. {
  125. /*
  126.     fd = fopen("i:\\pdlg.set", "wb");
  127.     if (fd)
  128.     {
  129.         fwrite(settings, 1, sizeof(PRN_SETTINGS), fd);
  130.         fclose(fd);
  131.     }
  132. */
  133. }
  134.  
  135. static PRN_SETTINGS *load_settings(PRN_DIALOG *prn_dialog)
  136. {
  137.     PRN_SETTINGS     *set = NULL;
  138.  
  139.     set = pdlg_new_settings(prn_dialog);
  140.     if (set)
  141.     {
  142. /*
  143.         fd = fopen("i:\\pdlg.set", "rb");
  144.         if (fd)
  145.         {
  146.             fread(set, 1, sizeof(PRN_SETTINGS), fd);
  147.             fclose(fd);
  148.         }
  149.         else
  150. */
  151.             pdlg_dflt_settings(prn_dialog, set);
  152.     }
  153.     return set;
  154. }
  155.  
  156. /* --------------------------------------------------------------------------- */
  157. void test_pdlg(bool in_win)
  158. {
  159. #if defined(__GNUC__) && !defined(__MSHORT__)
  160.     do_alert(1, 0, "[3][pdlg und GNU geht nicht, da ich nicht|weiss, wie ich ohne -mshort eine 16bit|Parameterübergabe realisiere!][schade]");
  161.     return;
  162. #else
  163.     if (wlfp_available())
  164.     {
  165.         PRN_SETTINGS    *prn_settings;
  166.         PRN_DIALOG        *prn_dialog;
  167.         int                d, button, ret, handle;
  168.         EVNT                ev;
  169.         
  170.         prn_dialog = pdlg_create(PDLG_3D);
  171.         if (prn_dialog)
  172.         {
  173.             PDLG_SUB    *sub_dialog;
  174.     
  175.             if (in_win)
  176.                 disable_menu();
  177.     
  178.             /* Settings holen */
  179.             prn_settings = load_settings(prn_dialog);
  180.     
  181.             /* Unterdialoge einhängen */
  182.             sub_dialog = create_sub_dialog();
  183.             if (sub_dialog)
  184.                 pdlg_add_sub_dialogs(prn_dialog, sub_dialog);
  185.     
  186.             if (in_win)
  187.             {
  188.                 /* Fenster-Dialog durchführen */
  189.  
  190.                 handle = pdlg_open(prn_dialog, prn_settings, "qed", 0x0000, -1, -1);
  191.                 wind_set_str(handle, WF_NAME, " Drucker-Konfiguration ");
  192.                 do
  193.                 {
  194.                     ev.mwhich = (short)evnt_multi(MU_KEYBD|MU_MESAG|MU_BUTTON, 2, 1, 1, 
  195.                                                         0, 0, 0, 0, 0,    0, 0, 0, 0, 0,
  196.                                                         (int*)ev.msg, 0, 
  197.                                                         (int*)&ev.mx, (int*)&ev.my, 
  198.                                                         (int*)&ev.mbutton, 
  199.                                                         (int*)&ev.kstate,    (int*)&ev.key, 
  200.                                                         (int*)&ev.mclicks);
  201.                     if (ev.mwhich & MU_MESAG)
  202.                     {
  203.                         switch (ev.msg[0])
  204.                         {
  205.                             case WM_REDRAW :
  206.                             case WM_MOVED :
  207.                             case WM_SIZED:
  208.                                 if (ev.msg[3] != handle)    /* für fremdes Fenster */
  209.                                 {
  210.                                     handle_mdial_msg((int *)ev.msg);
  211.                                 }
  212.                                 break;
  213.             
  214.                             case WM_BOTTOMED:                    /* nicht erlaubt! */
  215.                                 break;
  216.                             
  217.                             case WM_TOPPED :
  218.                             case WM_NEWTOP :
  219.                             case WM_ONTOP :        
  220.                                 ev.msg[0] = WM_TOPPED;        /* immer Druckerbox toppen! */
  221.                                 ev.msg[3] = handle;
  222.                                 break;
  223.                         }
  224.             
  225.                     }
  226.                     ret = pdlg_evnt(prn_dialog, prn_settings, &ev, &button);
  227.                 } 
  228.                 while (ret == 1);
  229.                 
  230.                 pdlg_close(prn_dialog, &d, &d);
  231.             }
  232.             else
  233.             {
  234.                 /* normalen Dialog durchführen */
  235.                 button = pdlg_do(prn_dialog, prn_settings, "document name", 0x0000);
  236.                 debug("pdlg_do(): %d\n", button);
  237.             }
  238.             
  239.             if (button == PDLG_OK)
  240.                 save_settings(prn_settings);
  241.     
  242.             if (sub_dialog)
  243.             {
  244.                 pdlg_remove_sub_dialogs(prn_dialog);
  245.                 free(sub_dialog);
  246.             }
  247.     
  248.             pdlg_free_settings(prn_settings);
  249.             pdlg_delete(prn_dialog);
  250.     
  251.             if (in_win)
  252.                 enable_menu();
  253.         }
  254.     }
  255.     else
  256.         form_alert( 1, "[1][WDialog ist nicht installiert!][Schade]");
  257. #endif
  258. }
  259.