home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / windows / dflat.zip / DFLAT.H < prev    next >
Text File  |  1991-02-18  |  11KB  |  270 lines

  1. /* ------------- dflat.h ----------- */
  2.  
  3. #ifndef WINDOW_H
  4. #define WINDOW_H
  5.  
  6. #define TRUE 1
  7. #define FALSE 0
  8.  
  9. #include "system.h"
  10. #include "config.h"
  11. #include "rect.h"
  12. #include "menu.h"
  13. #include "keys.h"
  14. #include "commands.h"
  15. #include "config.h"
  16. #include "dialbox.h"
  17.  
  18. /* ------ integer type for message parameters ----- */
  19. typedef long PARAM;
  20. typedef enum window_class    {
  21.     NORMAL,
  22.     APPLICATION,
  23.     TEXTBOX,
  24.     LISTBOX,
  25.     EDITBOX,
  26.     MENUBAR,
  27.     POPDOWNMENU,
  28.     BUTTON,
  29.     DIALOG,
  30.     ERRORBOX,
  31.     MESSAGEBOX,
  32.     HELPBOX,
  33.     TEXT,
  34.     RADIOBUTTON,
  35.     DUMMY
  36. } CLASS;
  37. typedef struct window {
  38.     CLASS class;           /* window class                  */
  39.     char *title;           /* window title                  */
  40.     struct window *parent; /* parent window                 */
  41.     int (*wndproc)
  42.         (struct window *, enum messages, PARAM, PARAM);
  43.     /* ---------------- window dimensions ----------------- */
  44.     RECT rc;               /* window coordinates
  45.                                             (0/0 to 79/24)  */
  46.     int ht, wd;            /* window height and width       */
  47.     RECT RestoredRC;       /* restored condition rect       */
  48.     /* -------------- linked list pointers ---------------- */
  49.     struct window *next;        /* next window on screen    */
  50.     struct window *prev;        /* previous window on screen*/
  51.     struct window *nextbuilt;   /* next window built        */
  52.     struct window *prevbuilt;   /* previous window built    */
  53.  
  54.     int attrib;                 /* Window attributes        */
  55.     char *videosave;            /* video save buffer        */
  56.     int condition;              /* Restored, Maximized,
  57.                                            Minimized        */
  58.     void *extension;            /* -> menus, dialog box, etc*/
  59.     struct window *PrevMouse;
  60.     struct window *PrevKeyboard;
  61.     /* ----------------- text box fields ------------------ */
  62.     int wlines;     /* number of lines of text              */
  63.     int wtop;       /* text line that is on the top display */
  64.     char *text;     /* window text                          */
  65.     int textlen;    /* text length                          */
  66.     int wleft;      /* left position in window viewport     */
  67.     int textwidth;  /* width of longest line in textbox     */
  68.     int BlkBegLine; /* beginning line of marked block       */
  69.     int BlkBegCol;  /* beginning column of marked block     */
  70.     int BlkEndLine; /* ending line of marked block          */
  71.     int BlkEndCol;  /* ending column of marked block        */
  72.     int HScrollBox; /* position of horizontal scroll box    */
  73.     int VScrollBox; /* position of vertical scroll box      */
  74.     /* ------------------ list box field ------------------ */
  75.     int selection;  /* current selection                    */
  76.     /* ----------------- edit box fields ------------------ */
  77.     int CurrCol;    /* Current column                       */
  78.     char *CurrLine; /* Current line                         */
  79.     int WndRow;     /* Current window row                   */
  80.     int TextChanged; /* TRUE if text has changed            */
  81.     char *DeletedText; /* for undo                          */
  82.     int DeletedLength; /*  "   "                            */
  83.     /* ---------------- dialog box fields ----------------- */
  84.     struct window *dFocus; /* control that has the focus    */
  85.     int ReturnCode;        /* return code from a dialog box */
  86. } * WINDOW;
  87.  
  88. #include "message.h"
  89. #include "classdef.h"
  90. #include "video.h"
  91.  
  92. enum Condition     {
  93.     ISRESTORED, ISMINIMIZED, ISMAXIMIZED
  94. };
  95. /* ------- window methods ----------- */
  96. #define WindowHeight(w)      ((w)->ht)
  97. #define WindowWidth(w)       ((w)->wd)
  98. #define BorderAdj(w,n)       (TestAttribute(w,HASBORDER)?n:0)
  99. #define ClientWidth(w)       (WindowWidth(w)-BorderAdj(w,2))
  100. #define ClientHeight(w)      (WindowHeight(w)-BorderAdj(w,2))
  101. #define WindowRect(w)        ((w)->rc)
  102. #define GetTop(w)            (RectTop(WindowRect(w)))
  103. #define GetBottom(w)         (RectBottom(WindowRect(w)))
  104. #define GetLeft(w)           (RectLeft(WindowRect(w)))
  105. #define GetRight(w)          (RectRight(WindowRect(w)))
  106. #define GetClientTop(w)      (GetTop(w)+BorderAdj(w,1))
  107. #define GetClientBottom(w)   (GetBottom(w)-BorderAdj(w,1))
  108. #define GetClientLeft(w)     (GetLeft(w)+BorderAdj(w,1))
  109. #define GetClientRight(w)    (GetRight(w)-BorderAdj(w,1))
  110. #define GetParent(w)         ((w)->parent)
  111. #define GetTitle(w)          ((w)->title)
  112. #define NextWindow(w)        ((w)->next)
  113. #define PrevWindow(w)        ((w)->prev)
  114. #define NextWindowBuilt(w)   ((w)->nextbuilt)
  115. #define PrevWindowBuilt(w)   ((w)->prevbuilt)
  116. #define GetClass(w)          ((w)->class)
  117. #define GetAttribute(w)      ((w)->attrib)
  118. #define AddAttribute(w,a)    (GetAttribute(w) |= a)
  119. #define ClearAttribute(w,a)  (GetAttribute(w) &= ~(a))
  120. #define TestAttribute(w,a)   (GetAttribute(w) & (a))
  121. #define isVisible(w)         (GetAttribute(w) & VISIBLE)
  122. #define SetVisible(w)        (GetAttribute(w) |= VISIBLE)
  123. #define ClearVisible(w)      (GetAttribute(w) &= ~VISIBLE)
  124. #define gotoxy(w,x,y) cursor(w->rc.lf+(x)+1,w->rc.tp+(y)+1)
  125. WINDOW CreateWindow(CLASS,char *,int,int,int,int,void*,WINDOW,
  126.         int (*)(struct window *,enum messages,PARAM,PARAM),int);
  127. void AddTitle(WINDOW, char *);
  128. void RepaintBorder(WINDOW, RECT *);
  129. void ClearWindow(WINDOW, RECT *, int);
  130. void clipline(WINDOW, int, char *);
  131. void writeline(WINDOW, char *, int, int, int);
  132. void writefull(WINDOW, char *, int);
  133. void SetNextFocus(WINDOW,int);
  134. void PutWindowChar(WINDOW, int, int, int);
  135. void GetVideoBuffer(WINDOW);
  136. void RestoreVideoBuffer(WINDOW);
  137. int LineLength(char *);
  138. #define DisplayBorder(wnd) RepaintBorder(wnd, NULL)
  139. #define DefaultWndProc(wnd,msg,p1,p2)    \
  140.     classdefs[FindClass(wnd->class)].wndproc(wnd,msg,p1,p2)
  141. #define BaseWndProc(class,wnd,msg,p1,p2)    \
  142.     classdefs[DerivedClass(class)].wndproc(wnd,msg,p1,p2)
  143. #define NULLWND ((WINDOW) 0)
  144. struct LinkedList    {
  145.     WINDOW FirstWindow;
  146.     WINDOW LastWindow;
  147. };
  148. extern struct LinkedList Focus;
  149. extern struct LinkedList Built;
  150. extern WINDOW inFocus;
  151. extern WINDOW CaptureMouse;
  152. extern WINDOW CaptureKeyboard;
  153. extern int foreground, background;
  154. extern int WindowMoving;
  155. extern int WindowSizing;
  156. extern int TextMarking;
  157. extern char *Clipboard;
  158. extern WINDOW SystemMenuWnd;
  159. /* --------------- border characters ------------- */
  160. #define FOCUS_NW       '\xc9'
  161. #define FOCUS_NE       '\xbb'
  162. #define FOCUS_SE       '\xbc'
  163. #define FOCUS_SW       '\xc8'
  164. #define FOCUS_SIDE     '\xba'
  165. #define FOCUS_LINE     '\xcd'
  166. #define NW             '\xda'
  167. #define NE             '\xbf'
  168. #define SE             '\xd9'
  169. #define SW             '\xc0'
  170. #define SIDE           '\xb3'
  171. #define LINE           '\xc4'
  172. #define LEDGE          '\xc3'
  173. #define REDGE          '\xb4'
  174. #define SHADOWFG       DARKGRAY
  175. /* ------------- scroll bar characters ------------ */
  176. #define UPSCROLLBOX    '\x1e'
  177. #define DOWNSCROLLBOX  '\x1f'
  178. #define LEFTSCROLLBOX  '\x11'
  179. #define RIGHTSCROLLBOX '\x10'
  180. #define SCROLLBARCHAR  176 
  181. #define SCROLLBOXCHAR  178
  182. #define CHECKMARK      251      /* menu item toggle         */
  183. /* ----------------- title bar characters ----------------- */
  184. #define CONTROLBOXCHAR '\xf0'
  185. #define MAXPOINTER     24      /* maximize token            */
  186. #define MINPOINTER     25      /* minimize token            */
  187. #define RESTOREPOINTER 18      /* restore token             */
  188. /* --------------- text control characters ---------------- */
  189. #define APPLCHAR     176    /* fills application window     */
  190. #define SHORTCUTCHAR '~'    /* prefix: shortcut key display */
  191. #define CHANGECOLOR  174    /* prefix to change colors      */
  192. #define RESETCOLOR   175    /* reset colors to default      */
  193. /* ---- standard window message processing prototypes ----- */
  194. int ApplicationProc(WINDOW, MESSAGE, PARAM, PARAM);
  195. int NormalProc(WINDOW, MESSAGE, PARAM, PARAM);
  196. int TextBoxProc(WINDOW, MESSAGE, PARAM, PARAM);
  197. int ListBoxProc(WINDOW, MESSAGE, PARAM, PARAM);
  198. int EditBoxProc(WINDOW, MESSAGE, PARAM, PARAM);
  199. int MenuBarProc(WINDOW, MESSAGE, PARAM, PARAM);
  200. int PopDownProc(WINDOW, MESSAGE, PARAM, PARAM);
  201. int ButtonProc(WINDOW, MESSAGE, PARAM, PARAM);
  202. int DialogProc(WINDOW, MESSAGE, PARAM, PARAM);
  203. int SystemMenuProc(WINDOW, MESSAGE, PARAM, PARAM);
  204. int HelpBoxProc(WINDOW, MESSAGE, PARAM, PARAM);
  205. int MessageBoxProc(WINDOW, MESSAGE, PARAM, PARAM);
  206. /* ------------- normal box prototypes ------------- */
  207. int isWindow(WINDOW);
  208. WINDOW inWindow(int, int);
  209. int WndForeground(WINDOW);
  210. int WndBackground(WINDOW);
  211. int FrameForeground(WINDOW);
  212. int FrameBackground(WINDOW);
  213. int SelectForeground(WINDOW);
  214. int SelectBackground(WINDOW);
  215. void SetStandardColor(WINDOW);
  216. void SetReverseColor(WINDOW);
  217. void SetClassColors(CLASS);
  218. WINDOW GetFirstChild(WINDOW);
  219. WINDOW GetNextChild(WINDOW);
  220. WINDOW GetLastChild(WINDOW);
  221. WINDOW GetPrevChild(WINDOW);
  222. #define HitControlBox(wnd, p1, p2)     \
  223.     (TestAttribute(wnd, TITLEBAR)   && \
  224.      TestAttribute(wnd, CONTROLBOX) && \
  225.      p1 == 2 && p2 == 0)
  226. /* -------- text box prototypes ---------- */
  227. char *TextLine(WINDOW, int);
  228. void WriteTextLine(WINDOW, RECT *, int, int);
  229. void SetTextBlock(WINDOW, int, int, int, int);
  230. #define BlockMarked(wnd) (  wnd->BlkBegLine ||    \
  231.                             wnd->BlkEndLine ||    \
  232.                             wnd->BlkBegCol  ||    \
  233.                             wnd->BlkEndCol)
  234. #define ClearBlock(wnd) wnd->BlkBegLine = wnd->BlkEndLine =  \
  235.                         wnd->BlkBegCol  = wnd->BlkEndCol = 0;
  236. #define GetText(w)        ((w)->text)
  237. /* --------- menu prototypes ---------- */
  238. int CopyCommand(char *, char *, int, int);
  239. void PrepOptionsMenu(void *, struct Menu *);
  240. void PrepEditMenu(void *, struct Menu *);
  241. void PrepWindowMenu(void *, struct Menu *);
  242. void BuildSystemMenu(WINDOW);
  243. /* ------------- edit box prototypes ----------- */
  244. #define isMultiLine(wnd)     TestAttribute(wnd, MULTILINE)
  245. /* --------- message box prototypes -------- */
  246. void MessageBox(char *, char *);
  247. void ErrorMessage(char *);
  248. int TestErrorMessage(char *);
  249. int YesNoBox(char *);
  250. int MsgHeight(char *);
  251. int MsgWidth(char *);
  252. /* ------------- dialog box prototypes -------------- */
  253. int DialogBox(DBOX *, int (*)(struct window *,
  254.                         enum messages, PARAM, PARAM));
  255. int DlgOpenFile(char *, char *);
  256. int DlgSaveAs(char *);
  257. void GetDlgListText(WINDOW, char *, enum commands);
  258. int DlgDirList(WINDOW, char *, enum commands,
  259.                             enum commands, unsigned);
  260. int RadioButtonSetting(DBOX *, enum commands);
  261. void PushRadioButton(DBOX *, enum commands);
  262. void PutItemText(WINDOW, enum commands, char *);
  263. void GetItemText(WINDOW, enum commands, char *, int);
  264. /* ------------- help box prototypes ------------- */
  265. void HelpFunction(void);
  266. void LoadHelpFile(void);
  267. #define swap(a,b){int x=a;a=b;b=x;}
  268.  
  269. #endif
  270.