home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / CTECHAPP.ZIP / WINDOWS.ZIP / WDW_ERR.CPP < prev    next >
C/C++ Source or Header  |  1990-03-26  |  1KB  |  60 lines

  1. //  Module:     Wdw_Err  (Window Class main routines)
  2. //  Version:    2.11
  3. //
  4. //  Language:   C++ 2.0
  5. //  Environ:    IBM-PC MS-DOS
  6. //
  7. //  Purpose:    Error handler and first-time initialization
  8. //
  9. //  Written by: Scott Robert Ladd
  10.  
  11. #include "Screen.hpp"
  12. #include "Window.hpp"
  13.  
  14. extern "C"
  15.     {
  16.     #include "stdio.h"
  17.     #include "stdlib.h"
  18.     }
  19.  
  20. // internal prototype
  21. static void DefaultHandler();
  22.  
  23. void (* Window::ErrorHandler)() = DefaultHandler;
  24.  
  25. // default exception handler
  26. static void DefaultHandler()
  27.     {
  28.     puts("\aWindow Error: allocation failure\n");
  29.     }
  30.  
  31. // assign an exception handler
  32. void Window::SetErrorHandler(void (* userHandler)())
  33.     {
  34.     ErrorHandler = userHandler;
  35.     }
  36.  
  37. // first time initialization function
  38. void Window::FirstTime()
  39.     {
  40.     Initialized = 1;
  41.  
  42.     // obtain screen dimensions
  43.     Screen::Dimensions(MaxWidth, MaxLength);
  44.  
  45.     unsigned int area = MaxLength * MaxWidth;
  46.  
  47.     // using malloc due to bug in cfront
  48.     ScrnOwner = (Window **)malloc(area * sizeof(Window *));
  49.  
  50.     if (ScrnOwner == NULL)
  51.         ErrorHandler();
  52.  
  53.     // clear the ownership array
  54.     for (unsigned int l = 0; l < MaxLength; ++l)
  55.         {
  56.         for (unsigned int c = 0; c < MaxWidth; ++c)
  57.             ScrnOwner[l * MaxWidth + c] = NULL;
  58.         }
  59.     }
  60.