home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 19 / CD_ASCQ_19_010295.iso / dos / prg / c / cwl30 / cwl3demo / dialog.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-10  |  9.9 KB  |  336 lines

  1. #define DLG_GLOBAL
  2. /* The following program displays and gets input in a dialog box in
  3.    conjunction with the mouse functions found in the C Mouse Lib Version 2.0.
  4.    The dialog box is created using CWL_RADIO, CWL_BUTTONS, and normal text
  5.    field.  You can use this source code as a guide in creating your
  6.    own dialog boxes using CWL_RADIO, CWL_RADIO and CWL_BUTTON fields.
  7.    */
  8. #if 0
  9. ╔═[■]═════════════Display options═══════════════════════════╗
  10. ║  Display swapping          Integer format  Files          ║
  11. ║   ( ) None                  ( ) Hex        ┌────────────┐ ║
  12. ║   () Smart                 ( ) Decimal    │FILE1.C      ║
  13. ║   ( ) Always                () Both       │FILE2.C     ▒ ║
  14. ║                                            │FILE3000.C  ▒ ║
  15. ║  Screen lines              Tab size        │NEWFILE.CPP ▒ ║
  16. ║   () 25    ( ) 43/50       8              │OLDFILE.CPP ▒ ║
  17. ║                                            │CURFILE.C    ║
  18. ║   OK ▄     Cancel ▄     Help ▄             └────────────┘ ║
  19. ║   ▀▀▀▀     ▀▀▀▀▀▀▀▀     ▀▀▀▀▀▀                            ║
  20. ╚═══════════════════════════════════════════════════════════╝
  21. #endif
  22.  
  23. #include "cwlwin.h"
  24. #include <string.h>
  25. #ifdef MSDOS
  26. #include <direct.h>
  27. #include <dos.h>
  28. #endif
  29.  
  30. #ifdef __TURBOC__
  31. #define FILENAME(f)   (f.ff_name)
  32. #endif
  33.  
  34. #ifdef MSC
  35. #define FILENAME(f)   (f.name)
  36. #endif
  37.  
  38. #ifdef COHERENT
  39. #include <stddef.h>
  40. #include <sys/types.h>
  41. #include <dirent.h>
  42. #endif
  43.  
  44. #ifdef MSDOS
  45. #define BLACKONWHITE CREATE_VIDEO_ATTRIBUTE(WHITE_, BLACK_)
  46. #define LIGHTONWHITE CREATE_VIDEO_ATTRIBUTE(WHITE_, LIGHTWHITE_)
  47. #define BLACKONCYAN  CREATE_VIDEO_ATTRIBUTE(CYAN_, BLACK_)
  48. #define WHITEONCYAN  CREATE_VIDEO_ATTRIBUTE(CYAN_, LIGHTWHITE_)
  49. #define YELLOWONCYAN CREATE_VIDEO_ATTRIBUTE(CYAN_, YELLOW_)
  50. #define WHITEONBLUE  CREATE_VIDEO_ATTRIBUTE(BLUE_, LIGHTWHITE_)
  51. #define BLACKONGREEN CREATE_VIDEO_ATTRIBUTE(GREEN_, BLACK_)
  52. #define WHITEONGREEN CREATE_VIDEO_ATTRIBUTE(GREEN_, LIGHTWHITE_)
  53. #define GRAYONCYAN   CREATE_VIDEO_ATTRIBUTE(CYAN_, GRAY_)
  54. #endif
  55.  
  56. #ifdef COHERENT
  57. #define BLACKONWHITE CREATE_VIDEO_ATTRIBUTE(WHITE_, BLACK_)
  58. #define LIGHTONWHITE CREATE_VIDEO_ATTRIBUTE(WHITE_, BLACK_)
  59. #define BLACKONCYAN  CREATE_VIDEO_ATTRIBUTE(WHITE_, BLACK_)
  60. #define WHITEONCYAN  BLACKONWHITE  /*CREATE_VIDEO_ATTRIBUTE(CYAN_, LIGHTWHITE_)
  61. */
  62. #define YELLOWONCYAN BLACKONWHITE /*CREATE_VIDEO_ATTRIBUTE(CYAN_, YELLOW_)*/
  63. #define WHITEONBLUE  BLACKONWHITE /*CREATE_VIDEO_ATTRIBUTE(BLUE_, LIGHTWHITE_)*/
  64. #define BLACKONGREEN BLACKONWHITE /*CREATE_VIDEO_ATTRIBUTE(GREEN_, BLACK_)*/
  65. #define WHITEONGREEN BLACKONWHITE /*CREATE_VIDEO_ATTRIBUTE(GREEN_, LIGHTWHITE_)*/
  66. #define GRAYONCYAN   BLACKONWHITE /*CREATE_VIDEO_ATTRIBUTE(CYAN_, GRAY_)*/
  67. #endif
  68.  
  69. #define IBMASCII(c)  ((c) > 32 && (c) < 255)
  70.  
  71. #include "dialog.h"
  72.  
  73.  
  74. CWL_VOID DialogDemo( )
  75. {
  76. #ifndef SHWARE
  77.   int attr[4];
  78.   int attr2[4];
  79.   int b;
  80.   int i;
  81.   unsigned formkeys[NUMFORMKEYS];
  82.   attr[NORMATTR] = BLACKONCYAN;
  83.   attr[HIATTR] = WHITEONCYAN;
  84.   attr[HOTATTR] = YELLOWONCYAN;
  85.   attr[UNAVAILATTR] = BLACKONWHITE;
  86.   attr2[NORMATTR] = BLACKONGREEN;
  87.   attr2[HIATTR] = WHITEONGREEN;
  88.  
  89.   /* initialize the list box colors */
  90.   menu_colors2[ENTRYCOLOR] =
  91.   menu_colors2[UNAVAILCOLOR] =
  92.   menu_colors2[BORDERCOLOR] = CREATE_VIDEO_ATTRIBUTE(CWLwhite,CWLblack);
  93.  
  94.   menu_colors2[HOTKEYCOLOR] =
  95.   menu_colors2[HIGHLIGHTCOLOR] = CREATE_VIDEO_ATTRIBUTE(CWLblack,CWLwhite);
  96.  
  97.  
  98.   /* Initialize opening screen */
  99.   opening_window = WindowInitialize(DESKTOP_WINDOW,BORDER,
  100.     8, 0,
  101.     77, 8,
  102.     CREATE_VIDEO_ATTRIBUTE(CWLblack, CWLwhite),
  103.     CREATE_VIDEO_ATTRIBUTE(CWLblack, CWLwhite),
  104.     "┌─┐││└─┘");
  105.   WindowPrintf(opening_window,opening_text);
  106.   WindowPrintf(opening_window,opening_text2);
  107.  
  108.   WindowWriteCenterStringAttr(opening_window,
  109.                          "Press a key to start the demo...", 7,
  110.                           CREATE_VIDEO_ATTRIBUTE(WHITE_ ,
  111.                                                  BLACK_));
  112.   WindowCenter(opening_window,VERTCENTER | HORIZCENTER);
  113.   WindowDisplay(opening_window,1,EXPLODE);
  114.   GET_KEY();
  115.   WindowClose(opening_window,CONTRACT);
  116.  
  117.  
  118.   /* Start the mouse event handler */
  119.   ProcessAllEvents(M_EVENT);
  120.  
  121.  
  122.   /* Initialize dialog window */
  123.   diagw = WindowInitialize(DESKTOP_WINDOW,BORDER, 0, 0, 70, 11, BLACKONWHITE, LIGHTONWHITE,
  124.     DOUBLEBOX);
  125.   WindowCenter(diagw, VERTCENTER | HORIZCENTER);
  126.   WindowMove(diagw, WINDOW_ROW(diagw) - 2, 0);
  127.  
  128.   /* Set the caption */
  129.   WindowSetEventStyle(diagw, CWL_CAPTION);
  130.   WindowSetCaption(diagw, "Dialog Box Demo");
  131.  
  132.   /* Initialize stats window */
  133.   statw = WindowInitialize(DESKTOP_WINDOW,BORDER, 17, 0, 50, 6, BLACKONWHITE, LIGHTONWHITE,
  134.     SINGLEBOX);
  135.  
  136.   /* define help window */
  137.   helpw = WindowInitialize(DESKTOP_WINDOW,BORDER, 0, 52, 25, 15, BLACKONWHITE, LIGHTONWHITE,
  138.     SINGLEBOX);
  139.   WindowChangeCursor(statw, INVISIBLE);
  140.   WindowDisplay(diagw,1,NOEFFECT);
  141.  
  142.   /* write the help info */
  143.   write_help();
  144.  
  145.   /* write title */
  146.   WindowTitleTop(diagw, "Display options", TITLECENTER);
  147.   WindowTitleTop(statw, "Current Stats", TITLECENTER);
  148.  
  149.   /* write other stuff to the dialog window */
  150.   WindowWriteString(diagw, "Display swapping", 0, 2);
  151.   WindowWriteString(diagw, "Integer format", 0, 28);
  152.   WindowWriteString(diagw, "Screen Size", 5, 2);
  153.   WindowWriteString(diagw, "Tab Size", 5, 28);
  154.   WindowWriteString(diagw, "Files",0,49);
  155.   CWLform_edit_key[FIELD_NEXTFIELD_KEY] = CWLKEY_TAB;
  156.   CWLform_edit_key[FIELD_PREVFIELD_KEY] = CWLKEY_BACKTAB;
  157.   CWLform_edit_key[FORM_EXIT_ACCEPT_KEY] = CWLKEY_RETURN;
  158.   CWLform_edit_key[BUTTON_NEXTFIELD_KEY] = CWLKEY_TAB;
  159.   CWLform_edit_key[BUTTON_PREVFIELD_KEY] = CWLKEY_BACKTAB;
  160.  
  161.   /* setup pop up menu */
  162.   pop = popup_init();
  163.  
  164.   /* Initialize form */
  165.   dbox = FormInitialize(diagw, fentry, FORM_WRAP | FORM_STATIC);
  166.  
  167.   /* Set the dialog help system */
  168.   vhelp_window = WindowInitialize(DESKTOP_WINDOW, BORDER, 0, 0, 78, 4,
  169.                                   0x7, 0x7, SINGLEBOX);
  170.   FormInitializeFieldHelp(dbox, vhelp_window, "dialog.txt", DISK_HELP,
  171.                           ONLINE_HELP);
  172.  
  173.   /* let field point to tabwidth variable */
  174.   FormSetFieldVariable(dbox, 4, &tabwidth, TRUE);
  175.  
  176.   /* change cursor mode */
  177.   FIELD_CURSORMODE(dbox, 4) = INSERTMODE;
  178.  
  179.   FormSetListField(dbox, 2, 1, 0, pop);
  180.  
  181.   /* let form know about CWL_RADIO fields */
  182.   FormSetRadioField(dbox, 0, r1, '*', 0, attr);
  183.   FormSetRadioField(dbox, 1, r2, '*', 2, attr);
  184.   FormSetRadioField(dbox, 3, r3, '*', 0, attr);
  185.  
  186.   /* let form know about CWL_BUTTON fields */
  187.   FormSetButtonField(dbox, 5, FORM_ACCEPT, " OK ", attr2,
  188.     NO_BUTTON_FUNC);
  189.   FormSetButtonField(dbox, 6, FORM_CANCEL, " Cancel ", attr2,
  190.     NO_BUTTON_FUNC);
  191.   FormSetButtonField(dbox, 7, FIELD_CONTINUE, " Help ", attr2,
  192.     show_help);
  193.  
  194.   /* write a shadow around buttons (nice effect) */
  195.   write_button_shadow(9, 3, 4);
  196.   write_button_shadow(9, 12, 8);
  197.   write_button_shadow(9, 25, 6);
  198.  
  199.   /* update stats when a field is exited */
  200.   for (i = 0;i < 8;i++)
  201.     FormSetFieldPostFunction(dbox, i, do_stats);
  202.  
  203.   FormSetFieldPreFunction(dbox, 2, focus_it);
  204.   FormSetFieldPostFunction(dbox, 2, unfocus_it);
  205.  
  206.   /* make form 'mouseable' */
  207.   FormSetMouse(dbox, TRUE);
  208.  
  209.   /* make cursor invisible */
  210.   WindowChangeCursor(statw, INVISIBLE);
  211.   do_stats(dbox, &i);
  212.  
  213.   /* display stats window */
  214.   WindowMove(statw, WINDOW_ROW(diagw) + WINDOW_HEIGHT(diagw) + 1, 0);
  215.   WindowDisplay(statw, 4, NOEFFECT);
  216.  
  217.   /* set radio field prefunc */
  218.   CWLradio_field_prefunc = change_stats;
  219.  
  220.   /* get the input in the form */
  221.   FormGetInput(dbox, 1, 0);
  222.  
  223.   /* print out the final stats */
  224.   WindowMoveCursor(statw, 0, 0);
  225.   WindowWriteCenterString(statw, "Press any key to continue...", 5);
  226.   GET_KEY();
  227.  
  228.   /* free the dialog and the array for the file list */
  229.   FormClose(dbox);
  230.   WindowClose(diagw,NOEFFECT);
  231.   WindowClose(statw,NOEFFECT);
  232.   WindowClose(helpw,NOEFFECT);
  233.   CWLQuitMessage( );
  234. #else
  235.   NotAvailable( );
  236. #endif
  237. }
  238.  
  239.  
  240.  
  241. /* place a 'focus' border on the list field */
  242. int focus_it(FORMPTR form, int *entry)
  243. {
  244.   WindowChangeBorderAttribute(POPUP_WINDOW(pop),LIGHTONWHITE);
  245.   return FIELD_CONTINUE_PROCESS;
  246. }
  247.  
  248.  
  249. /* place a 'focus' border on the list field */
  250. int unfocus_it(FORMPTR form, int *entry)
  251. {
  252.   WindowChangeBorderAttribute(POPUP_WINDOW(pop),menu_colors2[BORDERCOLOR]);
  253.   return FIELD_CONTINUE_PROCESS;
  254. }
  255.  
  256.  
  257. /* initialize the list field's contents */
  258. POPUP_MENU_PTR popup_init()
  259. {
  260. #ifndef SHWARE
  261.   POPUP_MENU_PTR p;
  262.  
  263. #ifdef MSC
  264.   struct find_t filedata;
  265. #else
  266.   struct ffblk filedata;
  267. #endif
  268.  
  269.   int i = 1,j;
  270.   int done;
  271.   char buf[100];
  272.  
  273.   p = PopupCreateMenu(DESKTOP_WINDOW,POPUPDEFOPTIONS,
  274.                       menu_colors2,0,0);
  275.   PopupSetDimensions(p,15,101,POPUP_SETALL);
  276.   PopupSetWinDimensions(p,13,7,POPUP_SETALL);
  277.  
  278.   buf[0] = ' ';
  279. /*  WindowDisplay(POPUP_WINDOW(p),1,NOEFFECT);*/
  280. #ifdef MSDOS
  281. #ifdef __TURBOC__
  282.   done = findfirst("*.c",&filedata,0);
  283. #endif
  284. #ifdef MSC
  285.   done = _dos_findfirst("*.c",0,&filedata);
  286. #endif
  287.   if (!done)
  288.   {
  289.     strncpy(buf,FILENAME(filedata),sizeof(FILENAME(filedata)));
  290.     buf[sizeof(FILENAME(filedata))] = '\0';
  291.     PopupAppendEntry(p,CWL_MSTRING,buf,0,
  292.                      (POPUPSELECTPROC)0);
  293.  
  294.     while (_dos_findnext(&filedata) == 0)
  295.     {
  296.       strncpy(buf,FILENAME(filedata),sizeof(FILENAME(filedata)));
  297.       buf[sizeof(FILENAME(filedata))] = '\0';
  298.       PopupAppendEntry(p,CWL_MSTRING ,buf,0,
  299.       (POPUPSELECTPROC)0);
  300.       i++;
  301.       if (i > 100)
  302.         break;
  303.     }
  304.   }
  305. #endif
  306.  
  307. #ifdef COHERENT
  308.   {
  309.     DIR *dirp;
  310.     struct dirent *dp;
  311.  
  312.     dirp = opendir(".");
  313.     while ((dp = readdir(dirp)) != NULL)
  314.     {
  315.       strcpy(buf,dp->d_name);
  316.       PopupAppendEntry(p,CWL_MSTRING ,buf,0,
  317.                        (POPUPSELECTPROC)0);
  318.     }
  319.     closedir(dirp);
  320.  
  321.  
  322.  
  323.   }
  324. #endif
  325.   /* Define pre function for list field menu */
  326.   CWLglobal_popup_prefunc = display_choice;
  327.   return p;
  328. #else
  329.   return (POPUP_MENU_PTR)0;
  330. #endif
  331. }
  332.  
  333.  
  334.  
  335.  
  336.