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

  1. //    Program name..    Zinc Interface Library
  2. //    Filename......    D_DEMO.CPP
  3. //    
  4. //    COPYRIGHT (C) 1990.  All Rights Reserved.
  5. //    Zinc Software Incorporated.  Pleasant Grove, Utah  USA
  6.  
  7. #include <stdlib.h>        // for abort()
  8. #include <stdio.h>        // for printf()
  9. #include <graphics.h>    // for bgi calls
  10. #include <ui_win.hpp>
  11. #include "d_demo.hpp"
  12. #include "d_help.hlh"
  13.  
  14. UI_DISPLAY *_display = 0;
  15. UI_EVENT_MANAGER *_eventManager = 0;
  16. UI_WINDOW_MANAGER *_windowManager = 0;
  17. TEXT_DISPLAY_MODE _currentMode = TDM_AUTO;
  18. UIW_PULL_DOWN_MENU *_controlMenu;
  19.  
  20. static UI_LIST _deviceList;
  21. static UI_LIST _objectList;
  22.  
  23. void InitializeSystem(TEXT_DISPLAY_MODE mode)
  24. {
  25.     // Initialize the screen display, trying for graphics mode first.
  26.     // The graphics overlay files are linked into the application program.
  27.     if (mode == TDM_AUTO)
  28.     {
  29.         int mode;
  30.         int driver = DETECT;
  31.         detectgraph(&driver, &mode);
  32.         switch(driver)
  33.         {
  34.         case EGA:
  35.         case EGAMONO:
  36.         case VGA:
  37.             registerbgidriver(EGAVGA_driver);
  38.             break;
  39.  
  40.         case CGA:
  41.             registerbgidriver(CGA_driver);
  42.             break;
  43.  
  44.         case HERCMONO:
  45.             registerbgidriver(Herc_driver);
  46.             break;
  47.         }
  48.         _display = new UI_DOS_BGI_DISPLAY;
  49.         if (!_display->installed)
  50.         {
  51.             delete _display;
  52.             _display = 0;
  53.         }
  54.     }
  55.  
  56.     // Graphics mode failed.  Try for a specified text mode.
  57.     if (!_display)
  58.     {
  59.         _display = new UI_DOS_TEXT_DISPLAY(mode);
  60.         if (!_display->installed)
  61.         {
  62.             delete _display;
  63.             _display = 0;
  64.         }
  65.     }
  66.  
  67.     // The specified text mode failed.  Get the default text mode.
  68.     if (!_display)
  69.     {
  70.         mode = _currentMode;
  71.         _display = new UI_DOS_TEXT_DISPLAY(mode);
  72.     }
  73.  
  74.     // Reset the text mode.
  75.     if (!_display->isText)
  76.         _currentMode = TDM_AUTO;
  77.     else if (_display->columns == 40)
  78.         _currentMode = TDM_25x40;
  79.     else if (_display->lines == 25)
  80.         _currentMode = TDM_25x80;
  81.     else
  82.         _currentMode = TDM_43x80;
  83.  
  84.     // Initialize the event manager.
  85.     _eventManager = new UI_EVENT_MANAGER(100, _display);
  86.     UI_DEVICE *device, *tDevice;
  87.     for (device = (UI_DEVICE *)_deviceList.last; device; device = tDevice)
  88.     {
  89.         tDevice = device->Previous();
  90.         *_eventManager + device;
  91.     }
  92.     _deviceList.first = _deviceList.last = 0;
  93.  
  94.     // Initialize the window manager.
  95.     _windowManager = new UI_WINDOW_MANAGER(_display, _eventManager);
  96.     UI_WINDOW_OBJECT *object, *tObject;
  97.     for (object = (UI_WINDOW_OBJECT *)_objectList.last; object; object = tObject)
  98.     {
  99.         tObject = object->Previous();
  100.         *_windowManager + object;
  101.     }
  102.     _objectList.first = _objectList.last = 0;
  103. }
  104.  
  105. void RestoreSystem(int finish)
  106. {
  107.     // Restore the window manager.
  108.     if (!finish)
  109.     {
  110.         _objectList.first = _objectList.last = 0;
  111.         for (UI_WINDOW_OBJECT *object = _windowManager->First(); object; 
  112.             object = _windowManager->First())
  113.         {
  114.             *_windowManager - object;    // Order is important here.
  115.             _objectList + object;
  116.         }
  117.     }
  118.     delete _windowManager;
  119.     _windowManager = 0;
  120.  
  121.     // Restore the event manager.
  122.     if (!finish)
  123.     {
  124.         _deviceList.first = _deviceList.last = 0;
  125.         for (UI_DEVICE *device = _eventManager->First(); device; 
  126.             device = _eventManager->First())
  127.         {
  128.             *_eventManager - device;    // Order is important here.
  129.             _deviceList + device;
  130.         }
  131.     }
  132.     delete _eventManager;
  133.     _eventManager = 0;
  134.  
  135.     // Restore the screen display.
  136.     delete _display;
  137.     _display = 0;
  138.     _currentMode = TDM_AUTO;
  139. }
  140.  
  141. void cdecl FreeStoreException(void)
  142. {
  143.     // The program failed on all attempts to get memory.
  144.     printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nDEMO: Out of memory!\n");
  145.     abort();
  146. }
  147.  
  148. #pragma argsused
  149. main(int argc, char *argv[])
  150. {
  151.     // Reset the free store exception handler.
  152.     extern void (*_new_handler)();
  153.     _new_handler  = FreeStoreException;
  154.  
  155.     // Initialize the Zinc Interface Library.
  156.     _path = new UI_PATH(argv[0], TRUE);
  157.     InitializeSystem(TDM_AUTO);
  158.     *_eventManager + new UI_BIOS_KEYBOARD + new UI_MS_MOUSE + new UI_CURSOR;
  159.  
  160.     // Reset the default error and help systems.
  161.     UI_ERROR_WINDOW_SYSTEM *errorSystem = new UI_ERROR_WINDOW_SYSTEM;
  162.     _errorSystem = errorSystem;
  163.     UI_HELP_WINDOW_SYSTEM *helpSystem = new UI_HELP_WINDOW_SYSTEM("d_help.hlp", _windowManager, HELP_GENERAL);
  164.     _helpSystem = helpSystem;
  165.  
  166.     // Create the control menu.
  167.     extern void InitializeControlMenu(void);
  168.     InitializeControlMenu();
  169.  
  170.     // Display a general help message then process the events.
  171.     _helpSystem->DisplayHelp(_windowManager, HELP_INTRO);
  172.     int ccode;
  173.     UI_EVENT event;
  174.     do
  175.     {
  176.         // Get a new event.
  177.         _eventManager->Get(event, Q_NORMAL);
  178.         ccode = _windowManager->Event(event);
  179.     } while (ccode != L_EXIT);
  180.  
  181.     // Restore the Zinc Interface Library, unlocking the control menu
  182.     // so the window manager will clean it up.
  183.     DIRECTORY_WINDOW::Cleanup();    // Cleanup static variables from the demo.
  184.     delete _errorSystem;
  185.     delete _helpSystem;
  186.     _controlMenu->woAdvancedFlags &= ~WOAF_LOCKED;
  187.     RestoreSystem(TRUE);                          
  188.     return (0);
  189. }
  190.