home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_GEN / FACETV.ZIP / ANNOUNCE.H < prev    next >
C/C++ Source or Header  |  1993-12-09  |  6KB  |  178 lines

  1. /************************************************************************
  2. **
  3. ** @(#)announce.h    04/16/93    Chris Ahlstrom
  4. **
  5. **    C++ version
  6. **
  7. **    Various banner-presentations and error-message displays.
  8. **
  9. **    At attempt to create an extensible class for handling errors.
  10. ** This class provides basic start-up, close-out, and display facilities.
  11. ** The new application then provides more messages.
  12. **
  13. *************************************************************************/
  14.  
  15. #if !defined(ANNOUNCE_h)                // { ANNOUNCE_h
  16. #define ANNOUNCE_h
  17.  
  18. #define Uses_TButton
  19. #define Uses_TDeskTop
  20. #define Uses_TDialog
  21. #define Uses_TInputLine
  22. #define Uses_TLabel
  23. #define Uses_TPoint
  24. #define Uses_TRadioButtons
  25. #define Uses_TRect
  26. #define Uses_TView
  27. #include <tv.h>            // Turbo Vision functionality
  28.  
  29. #include "tvyesno.h"        // FACE_TV Yes-No radio button and types
  30.  
  31.  
  32. #define ERR_STRING_SIZE    82    // for the size of static buffers
  33.  
  34.  
  35. /************************************************************************
  36. ** ErrorCode
  37. **
  38. **    A base list of the more common error messages.
  39. **
  40. *************************************************************************/
  41.  
  42. typedef enum
  43. {
  44.     ERR_SHOW_NO_MESSAGE    = -2,    // behavior needs no flagging to user
  45.     ERR_USER        = -1,    // the user (caller) provided the message
  46.     ERR_NONE        =  0,    // not an error message
  47.  
  48.     ERR_BAD_MESSAGE,        // programmer error
  49.     ERR_BAD_MESSAGECODE,    // programmer error
  50.     ERR_COMMAND_UNIMPLEMENTED,    // un-implemented command
  51.     ERR_NULL_POINTER,        // routine was passed a NULL pointer
  52.     ERR_OBJECT_NOT_CREATED,    // an instantiation failed
  53.     ERR_TESTCODE,        // function is altered because of test mode
  54.     ERR_TOO_MANY_WINDOWS,    // too many windows created
  55.     ERR_NO_MEMORY,        // couldn't allocate the buffer
  56.     ERR_TINY_BUFFER,        // need to allocate more for this purpose
  57.     ERR_NO_MATCHING_FILES,    // no files match the wild-card filespec
  58.     ERR_FILE_NOT_FOUND,        // desired file was not found
  59.     ERR_FILE_OPEN,        // could not open it
  60.     ERR_FILE_WRITE,        // could not write it
  61.     ERR_FILE_READ,        // could not read it
  62.     ERR_USER_ABORT,        // user terminated the action by hand
  63.     ERR_DATA_ABORT,        // data problem terminated the action by hand
  64.     ERR_RECEIVING_DATA,        // an error in receiving data
  65.     ERR_SENDING_DATA,        // an error in sending data
  66.     ERR_DIALOG,            // bad dialog box setup
  67.  
  68.     ERR_LAST_GENERIC_ERROR    // a sop to much older programs, not used
  69.  
  70. } ErrorCode;
  71.  
  72. #if defined(USE_GEN_ERRORS)            // { USE_GEN_ERRORS
  73.  
  74. static char *genErrors[] =
  75. {
  76.     "%%Programmer: Bad message%%",
  77.     "%%Programmer: Message-code too high!%%",
  78.     "%%Programmer: Command unimplemented",
  79.     "%%Programmer: Passed a NULL pointer",
  80.     "An object could not be created",
  81.     "Executing test code only",
  82.     "Too many windows",
  83.     "Not enough memory for buffer",
  84.     "You need to allocate more memory",
  85.     "No matching files",
  86.     "File not found",
  87.     "Can't open file",
  88.     "Can't write file",
  89.     "Can't read file",
  90.     "User break; action aborted",
  91.     "Date error; action aborted",
  92.     "Error receiving data; action aborted",
  93.     "Error sending data; action aborted",
  94.     "Bad dialog box setup"
  95. };
  96. #define genErrorsLength ((unsigned) (sizeof(genErrors) / sizeof(char *)))
  97.  
  98. #endif                        // } USE_GEN_ERRORS
  99.  
  100.  
  101. /************************************************************************
  102. ** UserMessages
  103. **
  104. **    This class supports messages that are somewhat ad hoc... the
  105. ** messages are passed as an argument, rather than being defined in
  106. ** a long list of messages read in (or created) when the message object
  107. ** is being created.
  108. **
  109. **    The xBox annunciators below all have similar parameter schemes.
  110. ** See announce.cpp for a complete discussion.
  111. **
  112. *************************************************************************/
  113.  
  114. class UserMessages
  115. {
  116. public:
  117.  
  118.     UserMessages            // assume no message exist
  119.     (
  120.     TDeskTop *desk            // the desktop for display
  121.     );
  122.     UserMessages            // construct messages from memory
  123.     (
  124.     TDeskTop *desk,            // the desktop for display
  125.     char **msg_buffer,        // pointer to array of messages
  126.     unsigned length            // the number of pointers
  127.     );
  128.     UserMessages            // construct messages from a file
  129.     (                    // NOT READY YET
  130.     TDeskTop *desk,
  131.     char *msg_file_name
  132.     );
  133.  
  134.     // ~Usermessages();            // CREATE WHEN FILE CONSTRUCTOR EXISTS
  135.  
  136.     // Note the following overloaded functions (this is fun!)
  137.  
  138.     virtual void errorHandler        // a message is provided
  139.     (
  140.     char *message
  141.     );
  142.     virtual void errorHandler        // a message code is provided
  143.     (
  144.     int messagecode
  145.     );
  146.     virtual void errorBox        // Turbo Vision message box
  147.     (
  148.     char *message,            // normal string or printf string
  149.     unsigned value            // optional value to put in message
  150.     );
  151.     void msgHandler(char *msg);        // displays quick information
  152.     ErrorCode bannerHandler(char *msg);    // displays banners (not so quick)
  153.     YesNoType confirmation        // asks for confirmation
  154.     (
  155.     char *string
  156.     );
  157.     int prompt(char *string);        // prompts for continuing
  158.     ErrorCode lastError();        // gets the last error-code
  159.  
  160. private:
  161.  
  162.     TDeskTop *deskTop;            // which desktop to paste it on
  163.     char **userMessages;        // object's possible messages
  164.     unsigned userMessagesLength;    // number of messages stored
  165.     ErrorCode Error;            // last error code that occurred
  166.     int usedErrorFile;            // 1 if the file constructor was used
  167.  
  168.     static char errorString[ERR_STRING_SIZE];    // for errorBox() formatting
  169. };
  170.  
  171. #if defined(USE_GEN_ERRORS)            // { USE_GEN_ERRORS
  172.  
  173. char UserMessages::errorString[ERR_STRING_SIZE];    // static defined
  174.  
  175. #endif                        // } USE_GEN_ERRORS
  176.  
  177. #endif                            // } ANNOUNCE_h
  178.