home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ibmodf.zip / ODFRK.ZIP / COMMON.HPP next >
Text File  |  1995-03-09  |  3KB  |  106 lines

  1. /*
  2.  *      File:           Common.hpp
  3.  *
  4.  *   Contains: In-line helper functions, macros and classes for 
  5.  *             sample parts.
  6.  *
  7.  *   Written by:        Jason Crawford
  8.  *
  9.  *   Copyright: (c) 1994 by IBM Corp., all rights reserved.
  10.  *
  11.  *   Change History (most recent first):
  12.  *
  13.  *       <1>      7/6/94        jlc             first checked in
  14.  *
  15.  *
  16.  *   Copyright: (c) 1993-1994 by IBM Corp., all rights reserved.
  17.  *
  18.  */
  19. #ifndef _COMMON_
  20. #define _COMMON_
  21.  
  22. #if ODDebug
  23.    #define NOTDONE() beepprintf("not done in %s", __FILE__)
  24.    #define NOTDONE2(a) beepprintf("%s not done in %s", a, __FILE__)
  25. #else
  26.    #define NOTDONE()
  27.    #define NOTDONE2(a)
  28. #endif
  29.  
  30.    void inline InflateRect( PRECTL prectl, long dx, long dy )
  31.    {
  32.       prectl->xLeft   -= dx;
  33.       prectl->xRight  += dx;
  34.       prectl->yBottom -= dy;
  35.       prectl->yTop    += dy;
  36.    }
  37.  
  38.    void inline OffsetRect( PRECTL prectl, long dx, long dy)
  39.    {
  40.       prectl->xLeft   += dx;
  41.       prectl->xRight  += dx;
  42.       prectl->yBottom += dy;
  43.       prectl->yTop    += dy;
  44.    }
  45.  
  46.    #define THROW(a) throw a
  47.    #define  ODDeleteObject(object)  \
  48.      do{              \
  49.        if (object!=kODNULL) {  \
  50.          delete object;    \
  51.          object = kODNULL;  \
  52.        }            \
  53.      }while(0)
  54. // mcs   #define  ODReleaseObject(ev, object) \
  55. // mcs     do{                \
  56. // mcs       if (object!=kODNULL) {    \
  57. // mcs         object->Release(ev);  \
  58. // mcs         object = kODNULL;    \
  59. // mcs       }              \
  60. // mcs     }while(0)
  61.  
  62.    /*
  63.     * The following classes aid in moving between ODPoint and ODRect 
  64.     * coordinates which are expressed using 16.16 fixed values to POINTL 
  65.     * and RECTL coordinates which are expressed using long ints.
  66.     */
  67.  
  68.    #define FIXED2LONG(f) (((f) + 0x8000) >> 16)
  69.    class ODPOINTL : public POINTL
  70.    {
  71.       public:
  72.       operator ODPoint() const { ODPoint pt = {MAKEFIXED(x,0),MAKEFIXED(y,0)}; return pt; } ;
  73.       ODPOINTL( ODPoint pt) {x = FIXED2LONG(pt.x); y = FIXED2LONG(pt.y); };
  74.       ODPOINTL( int x1, int y1) { x = x1; y = y1; };
  75.       ODPOINTL( ) { x = y = 0; };
  76.       //ODPOINTL( POINTL & pt) { } ;
  77.    };
  78.  
  79.    inline ODPOINTL & downcastToODPOINTL( POINTL & pt ) { return  (*(ODPOINTL*)&pt); }
  80.    class ODRECTL : public RECTL
  81.    {
  82.       public:
  83.       operator ODRect() const { ODRect rct = {
  84.                                     MAKEFIXED(xLeft,0),
  85.                                     MAKEFIXED(yTop,0),
  86.                                     MAKEFIXED(xRight,0),
  87.                                     MAKEFIXED(yBottom,0)
  88.                                              }; return rct; } ;
  89.       ODRECTL( ODRect rct) {
  90.               xLeft   = FIXED2LONG(rct.left);
  91.               yBottom = FIXED2LONG(rct.bottom);
  92.               xRight  = FIXED2LONG(rct.right);
  93.               yTop    = FIXED2LONG(rct.top);
  94.                            };
  95.       ODRECTL( ODPoint botLeft, ODPoint topRight) {
  96.               xLeft   = FIXED2LONG(botLeft.x);
  97.               yBottom = FIXED2LONG(botLeft.y);
  98.               xRight  = FIXED2LONG(topRight.x);
  99.               yTop    = FIXED2LONG(topRight.y);
  100.                            };
  101.       ODRECTL( ) { xLeft = yBottom = xRight = yTop = 0; };
  102.       ODRECTL( RECTL & rct)  { *this = *(ODRECTL *)&rct ;}
  103.    };
  104.    inline ODRECTL & downcastToODRECTL( RECTL & rct ) { return  *(ODRECTL*)&rct; }
  105. #endif
  106.