home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0040 - 0049 / ibm0040-0049 / ibm0040.tar / ibm0040 / ZINC_6.ZIP / DOSSRC.ZIP / D_CTRL1.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1991-06-01  |  7.4 KB  |  246 lines

  1. //    Zinc Interface Library - D_CTRL1.CPP
  2. //    COPYRIGHT (C) 1990, 1991.  All Rights Reserved.
  3. //    Zinc Software Incorporated.  Pleasant Grove, Utah  USA
  4.  
  5. #include "ui_dsn.hpp"
  6. #include "d_help.hlh"
  7. #include <dir.h>
  8. #include <dos.h>
  9. #include <stdio.h>
  10. #include <string.h>
  11. #include <fcntl.h>
  12. #include <sys\stat.h>
  13.  
  14. static char *windowName = "File";
  15.  
  16. static int CompareName(void *element1, void *element2)
  17. {
  18.     return (strcmpi(((UIW_POP_UP_ITEM *)element1)->DataGet(TRUE), ((UIW_POP_UP_ITEM *)element2)->DataGet(TRUE)));
  19. }
  20.  
  21. static int ChangePath(void *object, int ccode)
  22. {
  23.     if (ccode != S_NON_CURRENT)
  24.         return (0);
  25.  
  26.     UIW_STRING *stringField = (UIW_STRING *)object;
  27.     char pathName[MAXPATH];
  28.     UI_STORAGE::StripFullPath(stringField->DataGet(), pathName, 0);
  29.     if (pathName[0] == '\0')
  30.         ccode = 0;
  31.     else if (chdir(pathName) == 0)
  32.     {
  33.         UI_EVENT event = {S_COMPUTE_DIRECTORY, 0, { NULL }};
  34.         stringField->eventManager->Put(event, Q_BEGIN);
  35.         ccode = 0;
  36.     }
  37.     else
  38.     {
  39.         _errorSystem->Beep();
  40.         ccode = -1;
  41.     }
  42.     return(ccode);
  43. }
  44.  
  45. void ComputeDirectory(UI_WINDOW_MANAGER *windowManager)
  46. {
  47.     UIW_WINDOW *window = (UIW_WINDOW *)windowManager->Get(windowName);
  48.  
  49.     UIW_MATRIX *files = (UIW_MATRIX *)window->Get(FILE_FILES);
  50.     files->DataClear();
  51.     UIW_MATRIX *directories = (UIW_MATRIX *)window->Get(FILE_DIRECTORIES);
  52.     directories->DataClear();
  53.  
  54.     UIW_STRING *stringField = (UIW_STRING *)window->Get(FILE_CURRENT_FILE);
  55.     char pathName[MAXPATH], fileName[MAXPATH];
  56.     UI_STORAGE::StripFullPath(stringField->DataGet(), 0, fileName);
  57.     getcwd(pathName, MAXPATH);
  58.     stringField->DataSet(fileName);
  59.     stringField = (UIW_STRING *)window->Get(FILE_CURRENT_DIRECTORY);
  60.     stringField->DataSet(pathName);
  61.  
  62.     struct ffblk fileBlock;
  63.     int ccode = findfirst("*.*", &fileBlock, FA_DIREC);
  64.     while (ccode == 0)
  65.     {
  66.         if (fileBlock.ff_attrib == FA_DIREC && strcmp(".", fileBlock.ff_name))
  67.             *directories + new UIW_POP_UP_ITEM(fileBlock.ff_name,
  68.                 MNIF_NO_FLAGS, BTF_NO_FLAGS, WOF_NO_FLAGS,
  69.                 UI_DESIGN_MANAGER::FileControl, FILE_DIRECTORIES);
  70.         else if (strstr(fileBlock.ff_name, ".DAT"))
  71.             *files + new UIW_POP_UP_ITEM(fileBlock.ff_name,
  72.                 MNIF_NO_FLAGS, BTF_NO_FLAGS, WOF_NO_FLAGS,
  73.                 UI_DESIGN_MANAGER::FileControl, FILE_FILES);
  74.         ccode = findnext(&fileBlock);
  75.     }
  76.  
  77.     UI_EVENT event;
  78.     event.type = S_CREATE;
  79.     files->Event(event);
  80.     directories->Event(event);
  81.     event.type = S_DISPLAY_ACTIVE;
  82.     event.region = window->true;
  83.     files->Event(event);
  84.     directories->Event(event);
  85. }
  86.  
  87. void UI_DESIGN_MANAGER::FileControl(void *data, UI_EVENT &event)
  88. {
  89.     int helpContext = 0;
  90.     event.type = 0;
  91.  
  92.     // Switch on the item type.
  93.     UIW_POP_UP_ITEM *item = (UIW_POP_UP_ITEM *)data;
  94.     UIW_WINDOW *window = (UIW_WINDOW *)item->windowManager->Get(windowName);
  95.     switch (item->value)
  96.     {
  97.     case FILE_SAVE_AS:
  98.         if (!_storage)
  99.         {
  100.              event.type = S_CLOSE_TEMPORARY;
  101.             _errorSystem->Beep();
  102.             break;
  103.         }
  104.         // Continue to FILE_NEW and FILE_OPEN.
  105.  
  106.     case FILE_NEW:
  107.     case FILE_OPEN:
  108.         {
  109.         UIW_STRING *file, *directory;
  110.         UIW_MATRIX *files, *directories;
  111.         UIW_BUTTON *ok, *cancel, *help;
  112.         char pathName[MAXPATH];
  113.         getcwd(pathName, MAXPATH);
  114.         window = new UIW_WINDOW(2, 2, 51, 18, WOF_NO_FLAGS,
  115.             WOAF_MODAL | WOAF_NO_SIZE, NO_HELP_CONTEXT);
  116.         *window
  117.             + new UIW_BORDER
  118.             + new UIW_SYSTEM_BUTTON
  119.             + new UIW_TITLE(((item->value == FILE_NEW) ? " New " :
  120.                 ((item->value == FILE_OPEN) ? " Open " : " Save As ")), WOF_JUSTIFY_CENTER)
  121.             + new UIW_PROMPT(2, 1, "File name:", WOF_NO_FLAGS)
  122.             + (file = new UIW_STRING(13, 1, 34, "", 100, STF_NO_FLAGS, WOF_BORDER | WOF_AUTO_CLEAR, ChangePath))
  123.             + new UIW_PROMPT(2, 3, "Directory:", WOF_NO_FLAGS)
  124.             + (directory = new UIW_STRING(13, 3, 34, pathName, 100, STF_NO_FLAGS, WOF_NON_SELECTABLE))
  125.  
  126.             + new UIW_PROMPT(2, 5, "Files", WOF_NO_FLAGS)
  127.             + new UIW_SCROLL_BAR(22, 6, 1, 6, SBF_VERTICAL, WOF_NO_FLAGS)
  128.             + (files = new UIW_MATRIX(2, 6, 20, 6, 1000, 20, 1, CompareName, MXF_ROWS_FILL, WOF_BORDER, WOAF_NO_FLAGS))
  129.             + new UIW_PROMPT(26, 5, "Directories", WOF_NO_FLAGS)
  130.             + new UIW_SCROLL_BAR(45, 6, 1, 6, SBF_VERTICAL, WOF_NO_FLAGS)
  131.             + (directories = new UIW_MATRIX(26, 6, 19, 6, 1000, 19, 1, CompareName, MXF_ROWS_FILL, WOF_BORDER, WOAF_NO_FLAGS))
  132.             + (ok = new UIW_BUTTON(7, 14, 10, "~OK",
  133.                 BTF_NO_TOGGLE | BTF_AUTO_SIZE, WOF_BORDER | WOF_JUSTIFY_CENTER,
  134.                 FileControl, item->value + 1))
  135.             + (cancel = new UIW_BUTTON(20, 14, 10, "~Cancel",
  136.                 BTF_NO_TOGGLE | BTF_AUTO_SIZE, WOF_BORDER | WOF_JUSTIFY_CENTER,
  137.                 FileControl, FILE_CANCEL))
  138.             + (help = new UIW_BUTTON(33, 14, 10, "~Help",
  139.                 BTF_NO_TOGGLE | BTF_AUTO_SIZE, WOF_BORDER | WOF_JUSTIFY_CENTER,
  140.                 FileControl, item->value + 2));
  141.  
  142.         window->StringID(windowName);
  143.         file->NumberID(FILE_CURRENT_FILE);
  144.         files->NumberID(FILE_FILES);
  145.         directory->NumberID(FILE_CURRENT_DIRECTORY);
  146.         directories->NumberID(FILE_DIRECTORIES);
  147.  
  148.         item->windowManager->Add(window);
  149.         event.type = S_COMPUTE_DIRECTORY;
  150.         break;
  151.         }
  152.  
  153.     case FILE_SAVE:
  154.         extern int _resourceRecompute;
  155.          item->eventManager->Put(event, Q_BEGIN);
  156.          event.type = S_SAVE_FILE;
  157.         break;
  158.  
  159.     case FILE_SAVE_AS_ACTION:
  160.     case FILE_NEW_ACTION:
  161.     case FILE_OPEN_ACTION:
  162.         {
  163.         if (_storage && item->value != FILE_SAVE_AS_ACTION)
  164.             delete _storage;
  165.         UIW_STRING *fileField = (UIW_STRING *)window->Get(FILE_CURRENT_FILE);
  166.         UIW_STRING *directoryField = (UIW_STRING *)window->Get(FILE_CURRENT_DIRECTORY);
  167.         char pathName[MAXPATH];
  168.         UI_STORAGE::AppendFullPath(pathName, directoryField->DataGet(), fileField->DataGet());
  169.         UI_STORAGE::ChangeExtension(pathName, ".DAT");
  170.         if ((item->value == FILE_OPEN_ACTION && !UI_STORAGE::ValidName(pathName, FALSE)) ||
  171.             (item->value != FILE_OPEN_ACTION && !UI_STORAGE::ValidName(pathName, TRUE)))
  172.         {
  173.             _errorSystem->ReportError(item->windowManager, -1,
  174.                 "The path name %s is not valid.  Either the directory or file name must be re-entered.",
  175.                 pathName);
  176.             break;
  177.         }
  178.  
  179.         if (item->value == FILE_NEW_ACTION)
  180.             remove(pathName);
  181.         if (item->value == FILE_SAVE_AS_ACTION)
  182.             strcpy(_storage->name, pathName);
  183.         else
  184.             _storage = new UI_STORAGE(pathName, TRUE);
  185.  
  186.         extern char *controlWindowName;
  187.         char title[MAXPATH], fileName[MAXPATH];
  188.         UI_STORAGE::StripFullPath(fileField->DataGet(), 0, fileName);
  189.         UI_STORAGE::ChangeExtension(fileName, ".DAT");
  190.         sprintf(title, " %s - %s ", controlWindowName, fileName);
  191.         window = (UIW_WINDOW *)item->windowManager->Get(controlWindowName);
  192.         UIW_TITLE *titleField = (UIW_TITLE *)window->Get(NUMID_TITLE);
  193.         titleField->DataSet(title);
  194.  
  195.         if (item->value == FILE_SAVE_AS_ACTION)
  196.         {
  197.              event.type = S_SAVE_FILE;
  198.              item->eventManager->Put(event, Q_BEGIN);
  199.              event.type = S_CLOSE;
  200.             break;
  201.         }
  202.         extern int _resourceRecompute;
  203.         _resourceRecompute = TRUE;
  204.          event.type = S_CLOSE;
  205.         }
  206.         break;
  207.  
  208.     case FILE_FILES:
  209.         {
  210.         UIW_STRING *fileField = (UIW_STRING *)window->Get(FILE_CURRENT_FILE);
  211.         fileField->DataSet((char *)item->DataGet(TRUE));
  212.         }
  213.         break;
  214.  
  215.     case FILE_DIRECTORIES:
  216.         chdir(item->DataGet(TRUE));
  217.         event.type = S_COMPUTE_DIRECTORY;
  218.         break;
  219.  
  220.     case FILE_NEW_HELP:
  221.         helpContext = HELP_NEW;
  222.         break;
  223.  
  224.     case FILE_OPEN_HELP:
  225.         helpContext = HELP_OPEN;
  226.         break;
  227.  
  228.     case FILE_SAVE_AS_HELP:
  229.         helpContext = HELP_SAVE_AS;
  230.         break;
  231.  
  232.     case FILE_EXIT:
  233.          event.type = L_EXIT;
  234.         break;
  235.  
  236.     default:
  237.          event.type = S_CLOSE;
  238.         break;
  239.     }
  240.  
  241.     if (event.type)
  242.          item->eventManager->Put(event, Q_BEGIN);
  243.     else if (helpContext)
  244.         _helpSystem->DisplayHelp(item->windowManager, helpContext);
  245. }
  246.