home *** CD-ROM | disk | FTP | other *** search
- // Zinc Interface Library - D_CTRL1.CPP
- // COPYRIGHT (C) 1990, 1991. All Rights Reserved.
- // Zinc Software Incorporated. Pleasant Grove, Utah USA
-
- #include "ui_dsn.hpp"
- #include "d_help.hlh"
- #include <dir.h>
- #include <dos.h>
- #include <stdio.h>
- #include <string.h>
- #include <fcntl.h>
- #include <sys\stat.h>
-
- static char *windowName = "File";
-
- static int CompareName(void *element1, void *element2)
- {
- return (strcmpi(((UIW_POP_UP_ITEM *)element1)->DataGet(TRUE), ((UIW_POP_UP_ITEM *)element2)->DataGet(TRUE)));
- }
-
- static int ChangePath(void *object, int ccode)
- {
- if (ccode != S_NON_CURRENT)
- return (0);
-
- UIW_STRING *stringField = (UIW_STRING *)object;
- char pathName[MAXPATH];
- UI_STORAGE::StripFullPath(stringField->DataGet(), pathName, 0);
- if (pathName[0] == '\0')
- ccode = 0;
- else if (chdir(pathName) == 0)
- {
- UI_EVENT event = {S_COMPUTE_DIRECTORY, 0, { NULL }};
- stringField->eventManager->Put(event, Q_BEGIN);
- ccode = 0;
- }
- else
- {
- _errorSystem->Beep();
- ccode = -1;
- }
- return(ccode);
- }
-
- void ComputeDirectory(UI_WINDOW_MANAGER *windowManager)
- {
- UIW_WINDOW *window = (UIW_WINDOW *)windowManager->Get(windowName);
-
- UIW_MATRIX *files = (UIW_MATRIX *)window->Get(FILE_FILES);
- files->DataClear();
- UIW_MATRIX *directories = (UIW_MATRIX *)window->Get(FILE_DIRECTORIES);
- directories->DataClear();
-
- UIW_STRING *stringField = (UIW_STRING *)window->Get(FILE_CURRENT_FILE);
- char pathName[MAXPATH], fileName[MAXPATH];
- UI_STORAGE::StripFullPath(stringField->DataGet(), 0, fileName);
- getcwd(pathName, MAXPATH);
- stringField->DataSet(fileName);
- stringField = (UIW_STRING *)window->Get(FILE_CURRENT_DIRECTORY);
- stringField->DataSet(pathName);
-
- struct ffblk fileBlock;
- int ccode = findfirst("*.*", &fileBlock, FA_DIREC);
- while (ccode == 0)
- {
- if (fileBlock.ff_attrib == FA_DIREC && strcmp(".", fileBlock.ff_name))
- *directories + new UIW_POP_UP_ITEM(fileBlock.ff_name,
- MNIF_NO_FLAGS, BTF_NO_FLAGS, WOF_NO_FLAGS,
- UI_DESIGN_MANAGER::FileControl, FILE_DIRECTORIES);
- else if (strstr(fileBlock.ff_name, ".DAT"))
- *files + new UIW_POP_UP_ITEM(fileBlock.ff_name,
- MNIF_NO_FLAGS, BTF_NO_FLAGS, WOF_NO_FLAGS,
- UI_DESIGN_MANAGER::FileControl, FILE_FILES);
- ccode = findnext(&fileBlock);
- }
-
- UI_EVENT event;
- event.type = S_CREATE;
- files->Event(event);
- directories->Event(event);
- event.type = S_DISPLAY_ACTIVE;
- event.region = window->true;
- files->Event(event);
- directories->Event(event);
- }
-
- void UI_DESIGN_MANAGER::FileControl(void *data, UI_EVENT &event)
- {
- int helpContext = 0;
- event.type = 0;
-
- // Switch on the item type.
- UIW_POP_UP_ITEM *item = (UIW_POP_UP_ITEM *)data;
- UIW_WINDOW *window = (UIW_WINDOW *)item->windowManager->Get(windowName);
- switch (item->value)
- {
- case FILE_SAVE_AS:
- if (!_storage)
- {
- event.type = S_CLOSE_TEMPORARY;
- _errorSystem->Beep();
- break;
- }
- // Continue to FILE_NEW and FILE_OPEN.
-
- case FILE_NEW:
- case FILE_OPEN:
- {
- UIW_STRING *file, *directory;
- UIW_MATRIX *files, *directories;
- UIW_BUTTON *ok, *cancel, *help;
- char pathName[MAXPATH];
- getcwd(pathName, MAXPATH);
- window = new UIW_WINDOW(2, 2, 51, 18, WOF_NO_FLAGS,
- WOAF_MODAL | WOAF_NO_SIZE, NO_HELP_CONTEXT);
- *window
- + new UIW_BORDER
- + new UIW_SYSTEM_BUTTON
- + new UIW_TITLE(((item->value == FILE_NEW) ? " New " :
- ((item->value == FILE_OPEN) ? " Open " : " Save As ")), WOF_JUSTIFY_CENTER)
- + new UIW_PROMPT(2, 1, "File name:", WOF_NO_FLAGS)
- + (file = new UIW_STRING(13, 1, 34, "", 100, STF_NO_FLAGS, WOF_BORDER | WOF_AUTO_CLEAR, ChangePath))
- + new UIW_PROMPT(2, 3, "Directory:", WOF_NO_FLAGS)
- + (directory = new UIW_STRING(13, 3, 34, pathName, 100, STF_NO_FLAGS, WOF_NON_SELECTABLE))
-
- + new UIW_PROMPT(2, 5, "Files", WOF_NO_FLAGS)
- + new UIW_SCROLL_BAR(22, 6, 1, 6, SBF_VERTICAL, WOF_NO_FLAGS)
- + (files = new UIW_MATRIX(2, 6, 20, 6, 1000, 20, 1, CompareName, MXF_ROWS_FILL, WOF_BORDER, WOAF_NO_FLAGS))
- + new UIW_PROMPT(26, 5, "Directories", WOF_NO_FLAGS)
- + new UIW_SCROLL_BAR(45, 6, 1, 6, SBF_VERTICAL, WOF_NO_FLAGS)
- + (directories = new UIW_MATRIX(26, 6, 19, 6, 1000, 19, 1, CompareName, MXF_ROWS_FILL, WOF_BORDER, WOAF_NO_FLAGS))
- + (ok = new UIW_BUTTON(7, 14, 10, "~OK",
- BTF_NO_TOGGLE | BTF_AUTO_SIZE, WOF_BORDER | WOF_JUSTIFY_CENTER,
- FileControl, item->value + 1))
- + (cancel = new UIW_BUTTON(20, 14, 10, "~Cancel",
- BTF_NO_TOGGLE | BTF_AUTO_SIZE, WOF_BORDER | WOF_JUSTIFY_CENTER,
- FileControl, FILE_CANCEL))
- + (help = new UIW_BUTTON(33, 14, 10, "~Help",
- BTF_NO_TOGGLE | BTF_AUTO_SIZE, WOF_BORDER | WOF_JUSTIFY_CENTER,
- FileControl, item->value + 2));
-
- window->StringID(windowName);
- file->NumberID(FILE_CURRENT_FILE);
- files->NumberID(FILE_FILES);
- directory->NumberID(FILE_CURRENT_DIRECTORY);
- directories->NumberID(FILE_DIRECTORIES);
-
- item->windowManager->Add(window);
- event.type = S_COMPUTE_DIRECTORY;
- break;
- }
-
- case FILE_SAVE:
- extern int _resourceRecompute;
- item->eventManager->Put(event, Q_BEGIN);
- event.type = S_SAVE_FILE;
- break;
-
- case FILE_SAVE_AS_ACTION:
- case FILE_NEW_ACTION:
- case FILE_OPEN_ACTION:
- {
- if (_storage && item->value != FILE_SAVE_AS_ACTION)
- delete _storage;
- UIW_STRING *fileField = (UIW_STRING *)window->Get(FILE_CURRENT_FILE);
- UIW_STRING *directoryField = (UIW_STRING *)window->Get(FILE_CURRENT_DIRECTORY);
- char pathName[MAXPATH];
- UI_STORAGE::AppendFullPath(pathName, directoryField->DataGet(), fileField->DataGet());
- UI_STORAGE::ChangeExtension(pathName, ".DAT");
- if ((item->value == FILE_OPEN_ACTION && !UI_STORAGE::ValidName(pathName, FALSE)) ||
- (item->value != FILE_OPEN_ACTION && !UI_STORAGE::ValidName(pathName, TRUE)))
- {
- _errorSystem->ReportError(item->windowManager, -1,
- "The path name %s is not valid. Either the directory or file name must be re-entered.",
- pathName);
- break;
- }
-
- if (item->value == FILE_NEW_ACTION)
- remove(pathName);
- if (item->value == FILE_SAVE_AS_ACTION)
- strcpy(_storage->name, pathName);
- else
- _storage = new UI_STORAGE(pathName, TRUE);
-
- extern char *controlWindowName;
- char title[MAXPATH], fileName[MAXPATH];
- UI_STORAGE::StripFullPath(fileField->DataGet(), 0, fileName);
- UI_STORAGE::ChangeExtension(fileName, ".DAT");
- sprintf(title, " %s - %s ", controlWindowName, fileName);
- window = (UIW_WINDOW *)item->windowManager->Get(controlWindowName);
- UIW_TITLE *titleField = (UIW_TITLE *)window->Get(NUMID_TITLE);
- titleField->DataSet(title);
-
- if (item->value == FILE_SAVE_AS_ACTION)
- {
- event.type = S_SAVE_FILE;
- item->eventManager->Put(event, Q_BEGIN);
- event.type = S_CLOSE;
- break;
- }
- extern int _resourceRecompute;
- _resourceRecompute = TRUE;
- event.type = S_CLOSE;
- }
- break;
-
- case FILE_FILES:
- {
- UIW_STRING *fileField = (UIW_STRING *)window->Get(FILE_CURRENT_FILE);
- fileField->DataSet((char *)item->DataGet(TRUE));
- }
- break;
-
- case FILE_DIRECTORIES:
- chdir(item->DataGet(TRUE));
- event.type = S_COMPUTE_DIRECTORY;
- break;
-
- case FILE_NEW_HELP:
- helpContext = HELP_NEW;
- break;
-
- case FILE_OPEN_HELP:
- helpContext = HELP_OPEN;
- break;
-
- case FILE_SAVE_AS_HELP:
- helpContext = HELP_SAVE_AS;
- break;
-
- case FILE_EXIT:
- event.type = L_EXIT;
- break;
-
- default:
- event.type = S_CLOSE;
- break;
- }
-
- if (event.type)
- item->eventManager->Put(event, Q_BEGIN);
- else if (helpContext)
- _helpSystem->DisplayHelp(item->windowManager, helpContext);
- }
-