home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v92.tgz / v92.tar / v92 / src / h / pmwin.h < prev    next >
C/C++ Source or Header  |  1996-03-22  |  14KB  |  447 lines

  1. /*
  2.  * pmwin.h - macros and types used in PresentationManager graphics interface.
  3.  */
  4. #ifdef PresentationManager
  5. #include <os2.h>
  6. /*
  7.  * id's for various PM resources
  8.  */
  9. #define IDD_RUNERR            400
  10. #define DID_TEXT            401
  11. #define DID_ERRNO            402
  12. #define DID_FILE            403
  13. #define DID_LINE            404
  14. #define DID_MSG             405
  15. #define DID_OFFEND            406
  16. #define DID_TRACE            407
  17.  
  18. /* pointer shapes */
  19. #define PTR_XARROW            500
  20. #define PTR_BASE_ARROW_DOWN        501
  21. #define PTR_BASE_ARROW_UP        502
  22. #define PTR_BOTTOM_LEFT_CORNER        503
  23. #define PTR_BOAT            504
  24. #define PTR_BOGOSITY            505
  25. #define PTR_BOTTOM_SIDE         506
  26. #define PTR_BOTTOM_TEE            507
  27. #define PTR_BOTTOM_RIGHT_CORNER     508
  28. #define PTR_BOX_SPIRAL            509
  29. #define PTR_CENTER_PTR            510
  30. #define PTR_CIRCLE            511
  31. #define PTR_CLOCK            512
  32. #define PTR_CROSS            513
  33. #define PTR_CROSSHAIR            514
  34. #define PTR_CROSS_REVERSE        515
  35. #define PTR_SB_DOWN_ARROW        516
  36. #define PTR_DOUBLE_ARROW        517
  37. #define PTR_SB_H_DOUBLE_ARROW        518
  38. #define PTR_DIAMOND_CROSS        519
  39. #define PTR_DOT             520
  40. #define PTR_DOTBOX            521
  41. #define PTR_DRAFT_LARGE         522
  42. #define PTR_DRAFT_SMALL         523
  43. #define PTR_DRAPED_BOX            524
  44. #define PTR_EXCHANGE            525
  45. #define PTR_FLEUR            526
  46. #define PTR_GOBBLER            527
  47. #define PTR_GUMBY            528
  48. #define PTR_HAND1            529
  49. #define PTR_HAND2            530
  50. #define PTR_HEART            531
  51. #define PTR_ICON            532
  52. #define PTR_IRON_CROSS            533
  53. #define PTR_SB_LEFT_ARROW        534
  54. #define PTR_LEFTBUTTON            535
  55. #define PTR_LEFT_PTR            536
  56. #define PTR_LEFT_SIDE            537
  57. #define PTR_LEFT_TEE            538
  58. #define PTR_LL_ANGLE            539
  59. #define PTR_LR_ANGLE            540
  60. #define PTR_MAN             541
  61. #define PTR_MIDDLEBUTTON        542
  62. #define PTR_MOUSE            543
  63. #define PTR_COFFEE_MUG            544
  64. #define PTR_PENCIL            545
  65. #define PTR_PIRATE            546
  66. #define PTR_PLUS            547
  67. #define PTR_QUESTION_ARROW        548
  68. #define PTR_SB_RIGHT_ARROW        549
  69. #define PTR_RIGHTBUTTON         550
  70. #define PTR_RIGHT_PTR            551
  71. #define PTR_RIGHT_SIDE            552
  72. #define PTR_RIGHT_TEE            553
  73. #define PTR_RTLLOGO            554
  74. #define PTR_SAILBOAT            555
  75. #define PTR_SHUTTLE            556
  76. #define PTR_SIZING            557
  77. #define PTR_SPIDER            558
  78. #define PTR_SPRAYCAN            559
  79. #define PTR_STAR            560
  80. #define PTR_TARGET            561
  81. #define PTR_TCROSS            562
  82. #define PTR_TOP_LEFT_ARROW        563
  83. #define PTR_TOP_LEFT_CORNER        564
  84. #define PTR_TOP_TEE            565
  85. #define PTR_TOP_RIGHT_CORNER        566
  86. #define PTR_TREK            567
  87. #define PTR_TOP_SIDE            568
  88. #define PTR_SB_UP_ARROW         569
  89. #define PTR_UL_ANGLE            570
  90. #define PTR_UMBRELLA            571
  91. #define PTR_UR_ANGLE            572
  92. #define PTR_SB_V_DOUBLE_ARROW        573
  93. #define PTR_XWATCH            574
  94. #define PTR_X_CURSOR            575
  95. #define PTR_XTERM            576
  96.  
  97. #define GammaCorrection 1.0
  98.  
  99. #define TEXTWIDTH(w,s,n) GetTextWidth(w, s, n)
  100. #define SCREENDEPTH(w) (ScreenBitsPerPel)
  101. #define ASCENT(w) (w->context->font->metrics.lMaxAscender)
  102. #define DESCENT(w) (w->context->font->metrics.lMaxDescender)
  103. #define LEADING(w) (w->context->fntLeading)
  104. #define FHEIGHT(w) (w->context->font->metrics.lMaxBaselineExt)
  105. #define FWIDTH(w) (w->context->font->metrics.lMaxCharInc)
  106. #define LINEWIDTH(w) (w->context->lineBundle.lGeomWidth + 1)
  107. #define DISPLAYHEIGHT(w) (ScreenHeight)
  108. #define DISPLAYWIDTH(w) (ScreenWidth)
  109. #define wflush(w) /* noop */
  110. #define wsync(w) /* noop */
  111. #define SysColor int
  112. #define RED(x) (((x) >> 16) & 0xFF)
  113. #define GREEN(x) (((x) >> 8) & 0xFF)
  114. #define BLUE(x) ((x) & 0xFF)
  115. #define ARCWIDTH(arc) ((arc).arcp.lP)
  116. #define ARCHEIGHT(arc) ((arc).arcp.lQ)
  117. /*
  118.  * These get fixed up in the window-system-specific code
  119.  */
  120. #define RECX(rec) ((rec).xLeft)
  121. #define RECY(rec) ((rec).yTop)
  122. #define RECWIDTH(rec) ((rec).xRight)
  123. #define RECHEIGHT(rec) ((rec).yBottom)
  124. /*
  125.  * convert from radians (was 1/64 of degrees) to 1/65536 of degrees
  126.  */
  127. deliberate syntax error - needs converting for OS/2
  128. #define ANGLE(ang) (ang)
  129. #define EXTENT(ang)(ang)
  130. #define FULLARC (23040)
  131.  
  132. #define ISICONIC(w) ((w)->window->winState & WS_MIN)
  133. #define ISFULLSCREEN(w) ((w)->window->winState & WS_MAX)
  134. #define ISNORMALWINDOW(w) (!(ISICONIC(w) || ISFULLSCREEN(w)))
  135.  
  136. #define ISROOTWIN(w) (0)
  137.  
  138. #define ICONFILENAME(w) ((w)->window->iconimage)
  139. #define ICONLABEL(w) ((w)->window->iconlabel)
  140. #define WINDOWLABEL(w) ((w)->window->windowlabel)
  141.  
  142. #define MAXLABEL    128
  143.  
  144. /*
  145.  * don't want to include this if we are making the translator
  146.  */
  147.  
  148. #define MAXDESCENDER(w) (w->context->font->metrics.lMaxDescender)
  149.  
  150. #define STDLOCALS(w) \
  151.    wcp wc = (w)->context; \
  152.    wsp ws = (w)->window; \
  153.    HPS stdwin = ws->hpsWin; \
  154.    HPS stdbit = ws->hpsBitmap;
  155.  
  156. /*
  157.  * the interpreter thread stack size - make it really big since this will
  158.  * grow up to this max dynamically
  159.  */
  160. #define THREADSTACKSIZE      512000
  161.  
  162. /*
  163.  * special events for window creation/communication between threads
  164.  */
  165. #define REQUEST_DESTROY      (WM_USER)
  166. #define REQUEST_WINDOW         (WM_USER + 1)
  167. #define DESTROYED_WINDOW     (WM_USER + 2)
  168. #define NEW_WINDOW         (WM_USER + 3)
  169. #define REQUEST_SHUTDOWN     (WM_USER + 4)
  170. #define WINDOW_SIZED         (WM_USER + 5)
  171. #define KEY_PRESS         (WM_USER + 6)
  172. #define MOUSE_EVENT         (WM_USER + 7)
  173.  
  174. /*
  175.  * these are the bounds for the events that we want the interp thread
  176.  * to pick up for the
  177.  */
  178. #define INTERP_EVENT_START     REQUEST_SHUTDOWN
  179. #define INTERP_EVENT_END       MOUSE_EVENT
  180. /*
  181.  * whether you should block waiting for an event or not
  182.  */
  183. #define WAIT_EVT         1
  184. #define NO_WAIT_EVT         0
  185. /*
  186.  * gemeotry bitmasks
  187.  */
  188. #define GEOM_WIDTH         1
  189. #define GEOM_HEIGHT         2
  190. #define GEOM_POSX         4
  191. #define GEOM_POSY         8
  192. /*
  193.  * wonderful define to get around RTT
  194.  */
  195. #define MRESULT_N_EXPENTRY   MRESULT EXPENTRY
  196. #define VOID_APIENTRY         void APIENTRY
  197. /*
  198.  * mutual exclusion
  199.  */
  200. /* 2 seconds */
  201. #define MAXWAIT          2000
  202. #define INFINITE_WAIT         -1
  203. /*
  204.  * initial dependants allocated for context/window bundles
  205.  */
  206. #define INITDEPS         32
  207. /*
  208.  * fill styles
  209.  */
  210. #define FS_SOLID         1
  211. #define FS_STIPPLE         2
  212. #define FS_OPAQUESTIPPLE     4
  213. /*
  214.  * the special ROP code for mode reverse
  215.  */
  216. #define ROP_USER1         (ROP_ONE << 1)
  217. /*
  218.  * window states
  219.  */
  220. #define WS_NORMAL        0x01
  221. #define WS_MIN            0x02
  222. #define WS_MAX            0x04
  223. #define WS_HIDDEN        0x80
  224.  
  225. /*
  226.  * something I think should be #defined
  227.  */
  228. #define EOS             '\0'
  229.  
  230. /* size of the working buffer, used for dialog messages and such */
  231. #define PMSTRBUFSIZE         2048
  232. /*
  233.  * the bitmasks for the modifier keys
  234.  */
  235. #define ControlMask         (1 << 16)
  236. #define Mod1Mask         (2 << 16)
  237. #define ShiftMask         (4 << 16)
  238. #define VirtKeyMask         (8 << 16)
  239.  
  240. /* some macros for PresentationManager */
  241. #define TimedMutexOn(ws, place) {  \
  242.      if (ws->mutex && DosRequestMutexSem(ws->mutex, MAXWAIT) == ERROR_TIMEOUT) \
  243.        Bomb("Waiting for mutex in ", place); \
  244.      }
  245. #define MutexOn(ws) {if (ws->mutex) DosRequestMutexSem(ws->mutex, INFINITE_WAIT); }
  246. #define MutexOff(ws) {if (ws->mutex) DosReleaseMutexSem(ws->mutex); }
  247. #define MAKERGB(r,g,b) ((ULONG)(((r) << 16) | ((g) << 8) | (b)))
  248. #define RGB16TO8(x) if ((x) > 0xff) (x) = (((x) >> 8) & 0xff)
  249. #define AddPatternDependant(id)  AddLocalIdDependant((id))
  250. #define ReleasePattern(id)  ReleaseLocalId((id))
  251. #define AddFontDependant(id)  AddLocalIdDependant((id))
  252. #define ReleaseFont(id)  ReleaseLocalId((id))
  253. #define AddFontToWindow(ws, id) AddLocalIdToWindow((ws), (id))
  254. #define AddPatternToWindow(ws, id) AddLocalIdToWindow((ws), (id))
  255. #define hidecrsr(ws) { if ((ws)->hpsWin && ISCURSORONW(ws) &&  \
  256.                  ws->hwnd == WinQueryFocus(HWND_DESKTOP)) \
  257.                WinShowCursor((ws)->hwnd, 0); \
  258.             }
  259. #define showcrsr(ws) { if ((ws)->hpsWin && ISCURSORONW(ws) && \
  260.                  ws->hwnd == WinQueryFocus(HWND_DESKTOP)) \
  261.                WinShowCursor((ws)->hwnd, 1); \
  262.                }
  263. #define FNTWIDTH(size) ((size) & 0xFFFF)
  264. #define FNTHEIGHT(size) ((size) >> 16)
  265. #define MAKEFNTSIZE(height, width) (((height) << 16) | (width))
  266. #define WaitForEvent(msgnum, msgstruc) ObtainEvents(NULL, WAIT_EVT, msgnum, msgstruc)
  267. #define pollevent() (ObtainEvents(NULL, NO_WAIT_EVT, 0, NULL), 400)
  268. #define PMErrInit() { ConsoleFlags |= OutputToBuf; ConsoleStringBufPtr = ConsoleStringBuf; }
  269.  
  270. /*
  271.  * "get" means remove them from the Icon list and put them on the ghost queue
  272.  */
  273. #define EVQUEGET(ws,d) { \
  274.   int i;\
  275.   if (!c_get((struct b_list *)BlkLoc((ws)->listp),&d)) fatalerr(0,NULL); \
  276.   if (Qual(d)) {\
  277.       ws->eventQueue[(ws)->eQfront++] = *StrLoc(d); \
  278.       if ((ws)->eQfront >= EQUEUELEN) (ws)->eQfront = 0; \
  279.       (ws)->eQback = (ws)->eQfront; \
  280.       } \
  281.   }
  282. #define EVQUEEMPTY(ws) (BlkLoc((ws)->listp)->list.size == 0)
  283. /*
  284.  * the maximum number of messages to be queued by PM
  285.  */
  286. #define MAXMSGS  25
  287.  
  288. /*
  289.  * Colors...
  290.  */
  291. #define CLR_LOCKED    1
  292. #define CLR_USED    2
  293. #define CLR_BASE    4
  294. #define MAXCOLORNAME    64
  295. #define DMAXCOLORS    256
  296.  
  297. /*
  298.  * constant used to offset entries in global table *over* the standard colors
  299.  */
  300. typedef struct _CNODE {
  301.   UCHAR     bits;             /* flags */
  302.   int        refcount;         /* reference count */
  303.   ULONG     rgb;             /* the rgb component */
  304.   char*     name;             /* color name */
  305.   struct _CNODE *next, *previous;
  306.   } colorEntry;
  307.  
  308. /*
  309.  * we make the segment structure look like this so that we can
  310.  * cast it to POINTL structures that can be passed to GpiPolyLineDisjoint
  311.  */
  312. typedef struct {
  313.    LONG x1, y1;
  314.    LONG x2, y2;
  315.    } XSegment;
  316.  
  317. typedef POINTL XPoint;
  318. typedef RECTL XRectangle;
  319.  
  320. typedef struct {
  321.   LONG x, y;
  322.   ARCPARAMS arcp;
  323.   double angle1, angle2;
  324.   } XArc;
  325.  
  326. /*
  327.  * some macros that used to be functions
  328.  */
  329. #define AddColorDependant(indx) \
  330.    if (indx >= 0 && indx < MaxPSColors && (ColorTable[indx].bits & CLR_USED))\
  331.       ColorTable[indx].refcount++;
  332.  
  333. /* don't map 0 cause that is LCID_DEFAULT */
  334. #define AddLocalIdDependant(id) { \
  335.    LONG newid = id - 1; \
  336.    if (newid >= 0 && newid < MAXLOCALS) LocalIds[newid].refcount++; \
  337.    }
  338.  
  339. /*
  340.  * Macros to ease coding in which every X call must be done twice.
  341.  */
  342. #define RENDER1(func,v1) {\
  343.    if (ws->hpsWin) func(ws->hpsWin, v1); \
  344.    func(ws->hpsBitmap, v1);}
  345. #define RENDER2(func,v1,v2) {\
  346.    if (ws->hpsWin) func(ws->hpsWin, v1, v2); \
  347.    func(ws->hpsBitmap, v1, v2);}
  348. #define RENDER3(func,v1,v2,v3) {\
  349.    if (ws->hpsWin) func(ws->hpsWin, v1, v2, v3); \
  350.    func(ws->hpsBitmap, v1, v2, v3);}
  351. #define RENDER4(func,v1,v2,v3,v4) {\
  352.    if (ws->hpsWin) func(ws->hpsWin, v1, v2, v3, v4); \
  353.    func(ws->hpsBitmap, v1, v2, v3, v4);}
  354. #define RENDER5(func,v1,v2,v3,v4,v5) {\
  355.    if (ws->hpsWin) func(ws->hpsWin, v1, v2, v3, v4, v5); \
  356.    func(ws->hpsBitmap, v1, v2, v3, v4, v5);}
  357.  
  358. /* Try to speed some things up */
  359. #define SetAreaContext(wb, ws, wc) { \
  360.    SetClipContext((wb), (ws), (wc)); \
  361.    if ((ws)->areaContext != wc) { \
  362.      if ((ws)->hpsWin) \
  363.        GpiSetAttrs((ws)->hpsWin, PRIM_AREA, areaAttrs, 0UL, &((wc)->areaBundle)); \
  364.       GpiSetAttrs((ws)->hpsBitmap, PRIM_AREA, areaAttrs, 0UL, &((wc)->areaBundle)); \
  365.       (ws)->areaContext = wc; \
  366.       } /* End of if - we are not already loaded */ \
  367.    }
  368.  
  369. #define SetLineContext(wb, ws, wc) { \
  370.    SetClipContext((wb), (ws), (wc)); \
  371.    if (ws->lineContext != wc) { \
  372.      if ((ws)->hpsWin) \
  373.        GpiSetAttrs((ws)->hpsWin, PRIM_LINE, lineAttrs, 0UL, &((wc)->lineBundle)); \
  374.       GpiSetAttrs((ws)->hpsBitmap, PRIM_LINE, lineAttrs, 0UL, &((wc)->lineBundle)); \
  375.       (ws)->lineContext = wc; \
  376.       } /* End of if - we are not already loaded */ \
  377.    }
  378.  
  379. #define SetImageContext(wb, ws, wc) { \
  380.    SetClipContext((wb), (ws), (wc)); \
  381.    if (ws->imageContext != wc) { \
  382.      if ((ws)->hpsWin) \
  383.        GpiSetAttrs((ws)->hpsWin, PRIM_IMAGE, imageAttrs, 0UL, &((wc)->imageBundle)); \
  384.       GpiSetAttrs((ws)->hpsBitmap, PRIM_IMAGE, imageAttrs, 0UL, &((wc)->imageBundle)); \
  385.       (ws)->imageContext = wc; \
  386.       } /* End of if - we are not already loaded */ \
  387.    }
  388.  
  389. #define SetCharContext(wb, ws, wc) { \
  390.    PCURSORINFO _ptr; \
  391.    SetClipContext((wb), (ws), (wc)); \
  392.    if (ws->charContext != wc) { \
  393.      if ((ws)->hpsWin) { \
  394.        GpiSetAttrs((ws)->hpsWin, PRIM_CHAR, charAttrs, 0UL, &((wc)->charBundle)); \
  395.        /* update the cursor */ \
  396.        _ptr = &(ws->cursInfo); \
  397.        _ptr->cx = wc->font->metrics.lAveCharWidth; \
  398.        _ptr->x = ws->x + wc->dx; \
  399.        _ptr->y = ws->height - (ws->y + wc->dy); \
  400.        if (ISCURSORONW(ws) && ws->hwnd == WinQueryFocus(HWND_DESKTOP)) \
  401.      WinCreateCursor(ws->hwnd, _ptr->x, _ptr->y, _ptr->cx, \
  402.              _ptr->cy, CURSOR_SETPOS|CURSOR_FLASH, NULL); \
  403.        } /* End of if - ws has a window */ \
  404.       GpiSetAttrs((ws)->hpsBitmap, PRIM_CHAR, charAttrs, 0UL, &((wc)->charBundle)); \
  405.       (ws)->charContext = wc; \
  406.       /* set the font descender value used when the window is resized */ \
  407.       (ws)->lastDescender = (wc)->font->metrics.lMaxDescender; \
  408.       } /* End of if - we are not already loaded */ \
  409.    }
  410.  
  411. /*
  412. #undef SetAreaContext
  413. #undef SetLineContext
  414. #undef SetImageContext
  415. #undef SetCharContext
  416.  
  417. #define SetAreaContext(a,b,c)
  418. #define SetLineContext(a,b,c)
  419. #define SetImageContext(a,b,c)
  420. #define SetCharContext(a,b,c)
  421. */
  422.  
  423. #define UnsetCharContext(wc)  UnsetContext(wc, UCharContext);
  424. #define UnsetLineContext(wc)  UnsetContext(wc, ULineContext);
  425. #define UnsetImageContext(wc) UnsetContext(wc, UImageContext);
  426. #define UnsetAreaContext(wc) UnsetContext(wc, UAreaContext);
  427. #define UnsetClipContext(wc) UnsetContext(wc, UClipContext);
  428. #define UnsetAllContext(wc) UnsetContext(wc, UAllContext);
  429.  
  430. /*
  431.  * macros performing row/column to pixel y,x translations
  432.  * computation is 1-based and depends on the current font's size.
  433.  * exception: XTOCOL as defined is 0-based, because that's what its
  434.  * clients seem to need.
  435.  */
  436. #define ROWTOY(wb, row)  ((row - 1) * (LEADING(wb) + FHEIGHT(wb)) + ASCENT(wb))
  437. #define COLTOX(wb, col)  ((col - 1) * FWIDTH(wb))
  438. #define YTOROW(wb, y)     ((y) /  (LEADING(wb) + FHEIGHT(wb)) + 1)
  439. #define XTOCOL(wb, x)     ((x) / FWIDTH(wb))
  440. /*
  441.  * system size values
  442.  */
  443. #define BORDERWIDTH     (WinQuerySysValue(HWND_DESKTOP, SV_CXSIZEBORDER))
  444. #define BORDERHEIGHT     (WinQuerySysValue(HWND_DESKTOP, SV_CYSIZEBORDER))
  445. #define TITLEHEIGHT     (WinQuerySysValue(HWND_DESKTOP, SV_CYTITLEBAR))
  446. #endif                    /* PresentationManager */
  447.