home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 14 / CDACTUAL.iso / cdactual / demobin / share / program / c / ZINC.ZIP / D_DIRECT.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-23  |  7.0 KB  |  241 lines

  1. //    Program name..    Zinc Interface Library
  2. //    Filename......    D_DIRECT.CPP
  3. //    
  4. //    COPYRIGHT (C) 1990.  All Rights Reserved.
  5. //    Zinc Software Incorporated.  Pleasant Grove, Utah  USA
  6.  
  7. #include <dir.h>
  8. #include <dos.h>
  9. #include <time.h>
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include <ui_win.hpp>
  14. #include "d_demo.hpp"
  15.  
  16. // Window File demonstration.
  17.  
  18. UIW_WINDOW *DIRECTORY_WINDOW::fileWindow = 0;
  19.  
  20. DIRECTORY_WINDOW::DIRECTORY_WINDOW(void) :
  21.     UIW_WINDOW(3, 3, -3, 10, WOF_NO_FLAGS, WOAF_NO_FLAGS, NO_HELP_CONTEXT)
  22. {
  23.     // See if the file window has already been initialized.
  24.     if (fileWindow)
  25.         return;
  26.  
  27.     // Initialize the file window.
  28.     extern void ExitButton(void *object, UI_EVENT &event);
  29.     UI_DATE date;
  30.     UI_TIME time;
  31.     long size = 0;
  32.     fileWindow = new UIW_WINDOW(20, 15, -20, 9, WOF_NO_FLAGS, WOAF_MODAL | WOAF_NO_SIZE | WOAF_NO_DESTROY, NO_HELP_CONTEXT);
  33.     fileTitle = new UIW_TITLE("", WOF_JUSTIFY_CENTER);
  34.     fileDate = new UIW_DATE(14, 1, 15, &date, 0, DTF_SYSTEM, WOF_VIEW_ONLY, 0);
  35.     fileTime = new UIW_TIME(14, 2, 15, &time, 0, TMF_NO_FLAGS, WOF_VIEW_ONLY, 0);
  36.     fileSize = new UIW_NUMBER(14, 3, 15, &size, 0, NMF_COMMAS, WOF_VIEW_ONLY, 0);
  37.     *fileWindow
  38.         + new UIW_BORDER
  39.         + new UIW_MAXIMIZE_BUTTON
  40.         + new UIW_MINIMIZE_BUTTON
  41.         + new UIW_SYSTEM_BUTTON
  42.         + fileTitle
  43.         + new UIW_PROMPT(2, 1, "~Date........", WOF_NO_FLAGS)
  44.         + fileDate
  45.         + new UIW_PROMPT(2, 2, "~Time........", WOF_NO_FLAGS)
  46.         + fileTime
  47.         + new UIW_PROMPT(2, 3, "~Size........", WOF_NO_FLAGS)
  48.         + fileSize
  49.         + new UIW_BUTTON(2, 5, 10, "Esc=Exit", BTF_NO_FLAGS, WOF_JUSTIFY_CENTER, ExitButton);
  50. }
  51.  
  52. void DIRECTORY_WINDOW::Cleanup(void)
  53. {
  54.     if (fileWindow)
  55.         delete fileWindow;
  56. }
  57.  
  58. int DIRECTORY_WINDOW::CompareFunction(void *file1, void *file2)
  59. {
  60.     return (strcmp(((UIW_POP_UP_ITEM *)file1)->DataGet(),
  61.         ((UIW_POP_UP_ITEM *)file2)->DataGet()));
  62. }
  63.  
  64. #pragma argsused
  65. void DIRECTORY_WINDOW::D_DirectoryUserFunction(void *data, UI_EVENT &event)
  66. {
  67.     UIW_POP_UP_ITEM *item = (UIW_POP_UP_ITEM *)data;
  68.     DIRECTORY_WINDOW *directoryWindow = (DIRECTORY_WINDOW *)item->parent;
  69.     while (directoryWindow->parent)
  70.         directoryWindow = (DIRECTORY_WINDOW *)directoryWindow->parent;
  71.     directoryWindow->DirectoryUserFunction(item);
  72. }
  73. void DIRECTORY_WINDOW::DirectoryUserFunction(UIW_POP_UP_ITEM *item)
  74. {
  75.     // Create a new pulldown directory.
  76.     PullDownMenu((UIW_PULL_DOWN_ITEM *)item->parent->parent, item->DataGet());
  77.     Matrix();
  78.  
  79.     // Redraw the information by adding the object back to the window manager.
  80.     windowManager->Add(this);
  81. }
  82.  
  83. #pragma argsused
  84. void DIRECTORY_WINDOW::D_FileUserFunction(void *data, UI_EVENT &event)
  85. {
  86.     UIW_POP_UP_ITEM *item = (UIW_POP_UP_ITEM *)data;
  87.     DIRECTORY_WINDOW *directoryWindow = (DIRECTORY_WINDOW *)item->parent;
  88.     while (directoryWindow->parent)
  89.         directoryWindow = (DIRECTORY_WINDOW *)directoryWindow->parent;
  90.     directoryWindow->FileUserFunction(item);
  91. }
  92. void DIRECTORY_WINDOW::FileUserFunction(UIW_POP_UP_ITEM *item)
  93. {
  94.     // Determine the file path.
  95.     char path[128];
  96.     path[0] = '\0';
  97.     for (UIW_PULL_DOWN_ITEM *tItem = pullDownMenu->First(); tItem; tItem = tItem->Next())
  98.         strcat(path, tItem->DataGet());
  99.     strcat(path, item->DataGet());
  100.     for (int i = 0; path[i]; )
  101.         if (path[i] == ' ')
  102.             strcpy(&path[i], &path[i+1]);
  103.         else
  104.             i++;
  105.  
  106.     // Set the file information.
  107.     char title[64];
  108.     struct ffblk fileBlock;
  109.     findfirst(path, &fileBlock, FA_DIREC);
  110.     strcpy(title, item->DataGet());
  111.     fileTitle->DataSet(title);
  112.     UI_DATE date(fileBlock.ff_fdate);
  113.     fileDate->DataSet(&date);
  114.     UI_TIME time(fileBlock.ff_ftime);
  115.     fileTime->DataSet(&time);
  116.     fileSize->DataSet(&fileBlock.ff_fsize);
  117.     windowManager->Add(fileWindow);
  118. }
  119.  
  120. void DIRECTORY_WINDOW::Matrix(void)
  121. {
  122.     // Clear the old matrix.
  123.     for (UI_WINDOW_OBJECT *button = matrix->First(); button; button = matrix->First())
  124.     {
  125.         matrix->Subtract(button);
  126.         delete button;
  127.     }
  128.  
  129.     // Determine the new path.
  130.     char path[128];
  131.     path[0] = '\0';
  132.     for (UIW_PULL_DOWN_ITEM *item = pullDownMenu->First(); item; item = item->Next())
  133.         strcat(path, item->DataGet());
  134.     strcat(path, "*.*");
  135.     for (int i = 0; path[i]; )
  136.         if (path[i] == ' ')
  137.             strcpy(&path[i], &path[i+1]);
  138.         else
  139.             i++;
  140.  
  141.     // Get the new files.
  142.     struct ffblk fileBlock;
  143.     int ccode = findfirst(path, &fileBlock, FA_DIREC);
  144.     while (ccode == 0)
  145.     {
  146.         if (strcmp("..", fileBlock.ff_name) &&
  147.             strcmp(".", fileBlock.ff_name) &&
  148.             fileBlock.ff_attrib != FA_DIREC)
  149.             matrix->Add(new UIW_POP_UP_ITEM(fileBlock.ff_name,
  150.                 MNIF_NO_FLAGS, BTF_NO_FLAGS, WOF_NO_FLAGS,
  151.                 DIRECTORY_WINDOW::D_FileUserFunction));
  152.         ccode = findnext(&fileBlock);
  153.     }
  154. }
  155.  
  156. void DIRECTORY_WINDOW::PullDownMenu(UIW_PULL_DOWN_ITEM *tItem,
  157.     const char *directory)
  158. {
  159.     struct ffblk fileBlock;
  160.  
  161.     // Clear the old pull-down menu.
  162.     for (UIW_PULL_DOWN_ITEM *item = pullDownMenu->Last(); item; item = pullDownMenu->Last())
  163.         if (item != tItem)
  164.         {
  165.             pullDownMenu->Subtract(item);
  166.             delete item;
  167.         }
  168.         else
  169.             break;
  170.  
  171.     // Create a new pull-down item.
  172.     if (!directory)
  173.         return;
  174.     char path[128];
  175.     strcpy(path, directory);
  176.     for (int i = 0; path[i]; )
  177.         if (path[i] == ' ')
  178.             strcpy(&path[i], &path[i+1]);
  179.         else
  180.             i++;
  181.     if (!strcmp(path, "."))        // The item directory was specified.
  182.         return;
  183.     strcat(path, "\\");
  184.     item = new UIW_PULL_DOWN_ITEM(path, MNF_NO_FLAGS, 0);
  185.     pullDownMenu->Add(item);
  186.  
  187.     // Determine the new path.
  188.     path[0] = '\0';
  189.     for (tItem = pullDownMenu->First(); tItem; tItem = tItem->Next())
  190.     {
  191.         tItem->woStatus &= ~WOS_CURRENT;
  192.         strcat(path, tItem->DataGet());
  193.     }
  194.     strcat(path, "*.*");
  195.     item->woStatus |= WOS_CURRENT;
  196.  
  197.     // Determine the sub-directory items.
  198.     item->Add(new UIW_POP_UP_ITEM(".", MNIF_NO_FLAGS, BTF_NO_TOGGLE,
  199.         WOF_NO_FLAGS, DIRECTORY_WINDOW::D_DirectoryUserFunction));
  200.     int ccode = findfirst(path, &fileBlock, FA_DIREC);
  201.     while (ccode == 0)
  202.     {
  203.         if (strcmp("..", fileBlock.ff_name) &&
  204.             strcmp(".", fileBlock.ff_name) &&
  205.             fileBlock.ff_attrib == FA_DIREC)
  206.             item->Add(new UIW_POP_UP_ITEM(fileBlock.ff_name, MNIF_NO_FLAGS,
  207.                 BTF_NO_TOGGLE, WOF_NO_FLAGS, DIRECTORY_WINDOW::D_DirectoryUserFunction));
  208.         ccode = findnext(&fileBlock);
  209.     }
  210. }
  211.  
  212. #pragma argsused
  213. void WindowDirectory(void *item, UI_EVENT &event)
  214. {
  215.     // Create the DIRECTORY_WINDOW object.
  216.     DIRECTORY_WINDOW *directoryWindow = new DIRECTORY_WINDOW;
  217.     *directoryWindow
  218.         + new UIW_BORDER
  219.         + new UIW_MAXIMIZE_BUTTON
  220.         + new UIW_MINIMIZE_BUTTON
  221.         + UIW_SYSTEM_BUTTON::GENERIC()
  222.         + new UIW_TITLE("File Directory", WOF_JUSTIFY_CENTER);
  223.  
  224.     // Create the pull-down menu.
  225.     directoryWindow->pullDownMenu = new UIW_PULL_DOWN_MENU(1, WOF_NO_FLAGS, WOAF_NO_FLAGS);
  226.     directoryWindow->PullDownMenu(0, "");
  227.     *directoryWindow + directoryWindow->pullDownMenu;
  228.  
  229.     // Create the file matrix.
  230.     directoryWindow->matrix = new UIW_MATRIX(0, 0, 0, 0, 5, 14, 1,
  231.         DIRECTORY_WINDOW::CompareFunction, MXF_COLUMNS_FILL,
  232.         WOF_NON_FIELD_REGION, WOAF_NO_FLAGS);
  233.     directoryWindow->Matrix();
  234.     *directoryWindow
  235.         + new UIW_SCROLL_BAR(0, 0, 0, 0, SBF_VERTICAL, WOF_NON_FIELD_REGION)
  236.         + directoryWindow->matrix;
  237.  
  238.     *_windowManager + directoryWindow;
  239. }
  240.  
  241.