home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_11_08 / weber / gui.h < prev    next >
Text File  |  1993-03-13  |  17KB  |  357 lines

  1. /***************************************************************
  2.  * file: GUI.H
  3.  * purpose: simple gui prototypes, defines and data structures
  4.  * copyright: 1991 by David Weber.  All rights reserved.
  5.  *  This software can be used for any purpose as object, library or executable.
  6.  *  It cannot be sold for profit as source code.
  7.  * history:
  8.  *  12-17-91 - initial code
  9.  *  01-31-93 - this code is now obsolete, see the CPP gui package
  10.  **************************************************************/
  11.  
  12. #ifndef _GUI
  13. #define _GUI
  14.  
  15. #ifdef DEBUG
  16. #define FG_SYNCHRONIZED         /* allow zdb to check heap buffers */
  17. #endif
  18. #include <fg.h>
  19.  
  20. #include "keys.h"
  21.  
  22. /* --------- SYSTEM DEFAULTS --------- */
  23.  
  24. /* standard colors */
  25. #define COLOR_SYSTEM_BACKGROUND FG_BLACK
  26. #define COLOR_MESSAGE_BACKGROUND FG_RED
  27. #define COLOR_MESSAGE_FOREGROUND FG_WHITE
  28. #define COLOR_MENU_FOREGROUND FG_WHITE
  29. #define COLOR_MENU_BACKGROUND FG_BLUE
  30. #define COLOR_MENU_GRAY FG_GRAY
  31. #define COLOR_MENU_HIGHLIGHT FG_LIGHT_CYAN
  32. #define COLOR_MENU_FOCUS FG_LIGHT_GREEN
  33. #define COLOR_DIALOG_FOREGROUND FG_LIGHT_WHITE
  34. #define COLOR_DIALOG_BACKGROUND FG_CYAN
  35. #define COLOR_DIALOG_HIGHLIGHT FG_LIGHT_CYAN
  36. #define COLOR_DIALOG_SELECTION FG_LIGHT_GREEN
  37. #define COLOR_DIALOG_GRAY FG_GRAY
  38. #define COLOR_DIALOG_FOCUS FG_YELLOW
  39.  
  40.  
  41.  
  42. /* --------- GUI.C, MESSAGES AND OBJECTS --------- */
  43.  
  44. /* message box info */
  45. #define MESSAGE_MAX_STR 80      /* maximum size of a message string */
  46. #define MESSAGE_YN " Y/N?"      /* Y/N appendage */
  47. #define MESSAGE_YES 'y'         /* Yes, lower case */
  48. #define MESSAGE_NO 'n'          /* No, lower case */
  49.  
  50. /* message id defines */
  51.  
  52. /* system messages */
  53. #define M_MIN_SYSTEM 0          /* minimum system message */
  54. #define M_NONE 0                /* null message */
  55. #define M_START 1               /* startup message */
  56. #define M_QUIT 2                /* quit message */
  57. #define M_MAX_SYSTEM 99         /* maximum system message */
  58.  
  59. /* input messages */
  60. #define M_MIN_INPUT 100         /* minimum input message */
  61. #define M_KEY 100               /* keyboard hit, key value in short_data.x */
  62. #define M_MOUSE_LEFT 101        /* mouse left button went down, x,y coordinates in short_data */
  63. #define M_MOUSE_CENTER 102      /* mouse center button went down, x,y coordinates in short_data */
  64. #define M_MOUSE_RIGHT 103       /* mouse right button went down, x,y coordinates in short_data */
  65. #define M_MAX_INPUT 199         /* maximum input message */
  66.  
  67. /* error messages, address of function causing error is found in message->data.ptr_data */
  68. #define M_MIN_ERROR 200         /* minimum error message */
  69. #define M_NULL_ERROR 200        /* an undefined error occurred */
  70. #define M_NOMEM 201             /* memory allocation failed */
  71. #define M_MESSAGE_OVERFLOW 202  /* message queue overflowed and messages were lost */
  72. #define M_INVALID_PARMS 203     /* invalid parameters passed to a function */
  73. #define M_NOT_OPEN 204          /* attempt to access an unopened object */
  74. #define M_MAX_ERROR 255         /* maximum error message */
  75.  
  76. /* all messages 256 and greater are user defined for dialog controls etc. */
  77.  
  78. /* message structure */
  79. struct two_shorts { short x,y;  };
  80. union data_list
  81.     {
  82.     long long_data;
  83.     void *ptr_data;
  84.     struct two_shorts short_data;
  85.     };
  86. typedef struct
  87.     {
  88.     short id;               /* message id from list above or user defined */
  89.     union data_list data;   /* message data can be a long, pointer or two shorts */
  90.     } MESSAGE;
  91.  
  92. /* graphical objects */
  93. #define OBJECT_NULL 0           /* object types */
  94. #define OBJECT_MENU 1
  95. #define OBJECT_POPUP 2
  96. #define OBJECT_MESSAGEBOX 3
  97. #define OBJECT_DIALOG 4
  98. typedef struct object_list
  99.     {
  100.     short id;                   /* object type from defines above */
  101.     void (*message_handler)(MESSAGE *,void *);  /* object message handler */
  102.     void *data;                 /* pointer to object data */
  103.     fg_box_t screen;            /* object screen extent */
  104.     fg_handle_t save_area;      /* handle of area saved under object */
  105.     struct object_list *next;   /* next object in list or NULL */
  106.     } GOB;
  107. typedef void (*GENERIC_MESSAGE_HANDLER)(MESSAGE *message,void *);
  108.  
  109.  
  110. /* global data */
  111. extern short gui_errno;         /* last error message */
  112. #ifndef GUI_SOURCE
  113. extern const short gui_screen_width,gui_screen_height;  /* gui screen dimensions */
  114. extern const short gui_char_width,gui_char_height;      /* gui text cell dimensions */
  115. #endif
  116.  
  117. /* prototypes */
  118. short gui_open(void);           /* must be called before using gui */
  119. void gui_close(void);           /* called after finished with gui */
  120. short object_add(short id,void (*message_handler)(MESSAGE *message,void *data),void *data,fg_pbox_t screen);    /* add object to active list */
  121. short object_remove(void *data);        /* removes object from active list */
  122. GOB *object_exists(void *data);         /* returns pointer to object or NULL if none */
  123. short message_get(MESSAGE *message);    /* gets next message from input devices or system */
  124. void message_send(MESSAGE *message);    /* send a message down the list */
  125. short message_send_object(MESSAGE *message,void *data); /* send a message to a particular object */
  126. short message_box(char *str);   /* puts a message box on the screen */
  127. short error_box(short id);      /* displays a box for errors */
  128. short yn_box(char *str);        /* displays a message box and waits for y/n response */
  129. short exclusive_focus_set(void *data);  /* sets focus to a particular object */
  130. short exclusive_focus_clear(void *data);/* clears focus restriction */
  131. void input_handler_set_default(void (*message_handler)(MESSAGE *message));  /* message handler to be invoked when no other objects want message */
  132. void screen_clear(void);        /* clears screen to system background color */
  133.  
  134.  
  135.  
  136. /* --------- MENU.C, MENUS AND POPUPS --------- */
  137.  
  138. /* sizes */
  139. #define MENU_MAX_ITEMS 64
  140. #define POPUP_MAX_ITEMS 64
  141.  
  142. /* popup submenus */
  143. typedef struct popup_item
  144.     {
  145.     short id;               /* associated message id */
  146.     char *name;             /* name of item, note: use of '&' will highlight next character */
  147.     short accelerator;      /* accelerator key or 0 if none */
  148.     unsigned short status;  /* see status defines below */
  149.     /* end of initialized data */
  150.     fg_box_t screen;        /* hotspot on screen, filled in when menu is opened */
  151.     struct popup_item *next;/* pointer to next item in list or NULL if end, filled in when menu is opened */
  152.     } POPUP_ITEM;
  153.  
  154.  
  155. /* menu status */
  156. #define MENU_ACTIVE 1
  157. #define MENU_GRAY 2
  158. #define MENU_HIDDEN 4
  159. #define MENU_STATUS_MASK (MENU_ACTIVE | MENU_GRAY | MENU_HIDDEN)
  160. #define MENU_SELECTED 8
  161. #define MENU_BITS 0x000f
  162.  
  163. /* menu bars are linked lists of this struct */
  164. typedef struct menu_item
  165.     {
  166.     short id;               /* associated message id */
  167.     char *name;             /* name of item, note: use of '&' will highlight next character */
  168.     short accelerator;      /* accelerator key or 0 if none */
  169.     POPUP_ITEM *popup;      /* pop up associated with menu item, or NULL if none */
  170.     short number_of_popup_items;    /* number of items in associated popup or 0 if none */
  171.     unsigned short status;  /* see status defines above */
  172.     /* end of initialized data */
  173.     fg_box_t screen;        /* hotspot on screen, filled in when menu is opened */
  174.     struct menu_item *next; /* pointer to next item in list or NULL if end, filled in when menu is opened */
  175.     } MENU_ITEM;
  176.  
  177. /* menu prototypes */
  178. short menu_open(MENU_ITEM menubar[],short number_of_items);     /* draws a menubar */
  179. void menu_message_handler(MESSAGE *message,MENU_ITEM *menu);    /* handles messages for menus */
  180. short menu_close(MENU_ITEM menubar[]);                          /* erases a menubar */
  181. short menu_modify(MENU_ITEM menubar[],short menu_id,unsigned short status); /* modifies the status of a menu item, ACTIVE, GRAY or HIDDEN */
  182. short menu_clear(MENU_ITEM menubar[]);                          /* clear any open popups */
  183. short popup_open(POPUP_ITEM popup[],short number_of_items,short x,short y);     /* draws a popup */
  184. void popup_message_handler(MESSAGE *message,POPUP_ITEM *popup); /* handles messages for popups */
  185. short popup_close(POPUP_ITEM popup[]);                          /* erases a popup */
  186. short popup_modify(POPUP_ITEM popup[],short popup_id,unsigned short status);/* modifies the status of a popup item, ACTIVE, GRAY or HIDDEN */
  187.  
  188.  
  189.  
  190. /* --------- DIALOG.C, DIALOG BOXES --------- */
  191.  
  192. /* sizes */
  193. #define DIALOG_MAX_ITEMS 256
  194.  
  195. /* measurement units of a dialog box are in quarter text cells */
  196. #define DIALOG_UNITS 4
  197.  
  198. /* dialog types */
  199. #define DIALOG_MIN_TYPE 1
  200. #define DIALOG_TEXT 1
  201. #define DIALOG_BUTTON 2
  202. #define DIALOG_RADIOBUTTON 3
  203. #define DIALOG_CHECKBOX 4
  204. #define DIALOG_LISTBOX 5
  205. #define DIALOG_EDITBOX 6
  206. #define DIALOG_MAX_TYPE 6
  207.  
  208. /* DIALOG_ITEM state */
  209. #define DIALOG_ALLOCATED 1      /* dialog memory state */
  210. #define DIALOG_FIXED 2
  211. #define DIALOG_FOCUS_SKIP 4     /* dialog focus state */
  212. #define DIALOG_FOCUS_HERE 8
  213.  
  214. /* dialog object status */
  215. #define DIALOG_ACTIVE 1
  216. #define DIALOG_INACTIVE 2
  217. #define DIALOG_ACTIVE_MASK (DIALOG_ACTIVE | DIALOG_INACTIVE)
  218. #define DIALOG_SELECTED 4
  219. #define DIALOG_GRAY_BIT 8
  220. #define DIALOG_GRAY (DIALOG_GRAY_BIT | DIALOG_INACTIVE)
  221. #define DIALOG_COMPLETED 16
  222. #define DIALOG_OPENED 32
  223. #define DIALOG_BITS 0x003f
  224.  
  225. /* dialog structure, one for each item or collection of items in the dialog box */
  226. typedef struct dialog_item
  227.     {
  228.     short type;                 /* dialog type from defines above */
  229.     void *data;                 /* dialog data */
  230.     /* end of initialized data */
  231.     unsigned short dialog_state;/* memory and focus state of dialog */
  232.     fg_box_t focus;             /* box drawn when focusing in dialog */
  233.     struct dialog_item *next;   /* next dialog item in the linked list */
  234.     } DIALOG_ITEM;
  235.  
  236. /** DIALOG TEXT STRUCTURE **/
  237. typedef struct
  238.     {
  239.     char *name;         /* character string of text */
  240.     short loc_x,loc_y;  /* location of text relative to dialog box lower left corner, values are in units of quarter text cells */
  241.     unsigned short status;  /* text status from defines above */
  242.     /* end of initialized data */
  243.     } TEXT;
  244.  
  245. /** DIALOG BUTTON STRUCTURE **/
  246. typedef struct
  247.     {
  248.     short id;               /* associated message id */
  249.     char *name;             /* name on button */
  250.     short accelerator;      /* accelerator key or 0 if none */
  251.     short loc_x,loc_y;      /* location of button relative to dialog box lower left corner, values are in units of quarter text cells */
  252.     unsigned short status;  /* button status from defines above */
  253.     /* end of initialized data */
  254.     fg_box_t screen;        /* button hotspot in screen coordinates, filled when dialog is opened */
  255.     } BUTTON;
  256.  
  257. /** DIALOG RADIO BUTTON STRUCTURE **/
  258. typedef struct
  259.     {
  260.     short id;                   /* id of radio button set */
  261.     short number_of_buttons;    /* number of buttons in radio collection */
  262.     BUTTON *buttons;            /* array of buttons in radio collection */
  263.     unsigned short status;      /* radio button status from defines above */
  264.     /* end of initialized data */
  265.     DIALOG_ITEM *dialog;        /* parent dialog */
  266.     } RADIOBUTTON;
  267.  
  268. /** DIALOG LISTBOX STRUCTURE **/
  269. /* allocation sizes and allocation sequencing */
  270. #define LISTBOX_MEM_PAGE_SIZE 64
  271. #define LISTBOX_FIRST_PAGE 0
  272. #define LISTBOX_SUCCEEDING_PAGES 1
  273. /* listbox displayed characters */
  274. #define LIST_UPARROW 24
  275. #define LIST_DOWNARROW 25
  276. #define LIST_RIGHTARROW 16
  277. typedef struct listbox_page
  278.     {
  279.     char *listbox_items;                /* data for listbox */
  280.     short number_of_items;              /* number of items in listbox */
  281.     struct listbox_page *previous_page; /* previous page in doubly linked list of pages */
  282.     struct listbox_page *next_page;     /* next page in doubly linked list of pages */
  283.     } LISTBOX_PAGE;
  284. typedef struct
  285.     {
  286.     short id;               /* associated message id */
  287.     short loc_x,loc_y;      /* location of listbox relative to dialog box lower left corner, values are in units of quarter text cells */
  288.     short width,height;     /* listbox dimensions in quarter text cells, the displayed listbox will be rounded down in full text cells */
  289.     short (*first_item)(char *str);     /* function which returns first item in listbox or NULL if none */
  290.     short (*next_item)(char *str);      /* function which returns next item in listbox or NULL if none */
  291.     unsigned short status;  /* whether or not list box is active, see dialog status defines above */
  292.     /* end of initialized data */
  293.     fg_box_t screen;        /* listbox hotspot in screen coordinates, filled when dialog is opened */
  294.     fg_box_t marker;        /* hotspots for marker area */
  295.     fg_box_t listbox;       /* hotspots for list area */
  296.     fg_box_t up;            /* up arrow hotspots */
  297.     fg_box_t down;          /* down arrow hotspots */
  298.     LISTBOX_PAGE *first_page;   /* pointer to start of linked list of pages in listbox */
  299.     LISTBOX_PAGE *current_page; /* pointer to current page in list of pages */
  300.     short page_offset;          /* offset in current page for first item on screen */
  301.     short screen_offset;        /* offset on screen for current place marker */
  302.     } LISTBOX;
  303.  
  304. /** DIALOG EDITBOX STRUCTURE **/
  305. /* EDITBOX message modifiers */
  306. #define EDITBOX_CHANGE 0            /* a change occurred in the editbox */
  307. #define EDITBOX_ACCEPT 1            /* the RETURN key was pressed in the editbox */
  308. /* special keys used in editbox */
  309. #define EDITBOX_HOME HOME           /* move to start of edit */
  310. #define EDITBOX_END END             /* move to end of edit */
  311. #define EDITBOX_DELETE_EOL CTRLEND  /* delete to end of line */
  312. #define isprint_ibm(c) ((c<256&&isprint(c))||((c)>=128&&(c)<=175)||((c)>=224&&(c)<=239))    /* ibm extended character set for foreign language characters only */
  313. /* other editbox control keys are: LEFTARROW,RIGHTARROW,INS,DELETE and BKSP */
  314. /* editbox displayed characters */
  315. #define EDITBOX_CURSOR_INSERT 22    /* cursor displayed when inserting */
  316. #define EDITBOX_CURSOR_OVERWRITE '_'/* cursor displayed when overwriting */
  317. typedef struct
  318.     {
  319.     short id;               /* associated message id */
  320.     short loc_x,loc_y;      /* location of editbox relative to dialog box lower left corner, values are in units of quarter text cells */
  321.     short screen_width;     /* displayed editbox width in quarter text cells, the displayed editbox will be rounded down in full text cells */
  322.     short edit_width;       /* width of editable string in FULL text cells.
  323.                              * If this is greater than the screen_width, the text is scrolled.
  324.                              * Note storage space in edit_string must be edit_width+1
  325.                              * The screen width should never be greater than the
  326.                              * edit width */
  327.     char *edit_string;      /* storage for string in editbox */
  328.     unsigned short status;  /* whether or not edit box is active, see dialog status defines above */
  329.     /* end of initialized data */
  330.     fg_box_t screen;        /* editbox hotspot in screen coordinates, filled when dialog is opened */
  331.     short curtype,curpos,xpos,scroll_offset,insert; /* editbox static data */
  332.     } EDITBOX;
  333.  
  334. /** DIALOG PROTOTYPES **/
  335. short dialog_open(DIALOG_ITEM dialog[],short number_of_items,short loc_x,short loc_y,short width,short height);     /* draws a dialog box */
  336. void dialog_message_handler(MESSAGE *message,DIALOG_ITEM *dialog);  /* handles dialog box messages */
  337. short dialog_close(DIALOG_ITEM dialog[]);                           /* erases a dialog box */
  338. short dialog_add_item(short type,void *data,DIALOG_ITEM dialog[]);  /* add an item to an open dialog */
  339. short editbox_initialize(EDITBOX *edit);                            /* initialize an editbox with a new string */
  340. short listbox_initialize(LISTBOX *list);                            /* initialize a listbox with a new list */
  341. short radiobutton_set(RADIOBUTTON *radio,short id);                 /* sets a particular radiobutton */
  342. short checkbox_set(BUTTON *button,short id);                        /* sets a checkbox */
  343. short checkbox_clear(BUTTON *button,short id);                      /* clears a checkbox */
  344.  
  345. /** DIALOG MACROS **/
  346. /* change the status of a dialog item to DIALOG_ACTIVE or DIALOG_INACTIVE, this should not be done while the dialog is displayed */
  347. #define dialog_status_set(dialog,newstat) ((dialog).status = ((dialog).status & ~DIALOG_ACTIVE_MASK) | ((newstat) & DIALOG_ACTIVE_MASK))
  348. #define is_active(dialog) ((dialog).status & DIALOG_ACTIVE)
  349. #define is_inactive(dialog) (((dialog).status & DIALOG_ACTIVE) == 0)
  350. #define is_selected(dialog) ((dialog).status & DIALOG_SELECTED)
  351. #define is_gray(dialog) ((dialog).status & DIALOG_GRAY_BIT)
  352.  
  353.  
  354.  
  355.  
  356. #endif  /* _GUI */
  357.