home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / drdobbs / 1991 / 06 / dflat3 / dflat.h < prev    next >
Text File  |  1991-05-19  |  13KB  |  309 lines

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