home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 May / Pcwk5b98.iso / Borland / Cplus45 / BC45 / OWLINC.PAK / GDIOBJEC.H < prev    next >
C/C++ Source or Header  |  1995-08-29  |  26KB  |  749 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // (C) Copyright 1992, 1994 by Borland International, All Rights Reserved
  4. //
  5. //   Definition of abstract GDI object class and derived classes
  6. //----------------------------------------------------------------------------
  7. #if !defined(OWL_GDIOBJEC_H)
  8. #define OWL_GDIOBJEC_H
  9.  
  10. #if !defined(OWL_GDIBASE_H)
  11. # include <owl/gdibase.h>
  12. #endif
  13.  
  14. class _OWLCLASS TDC;
  15. class _BIDSCLASS TFile;
  16. class _OWLCLASS TBrush;
  17. class _OWLCLASS TBitmap;
  18. class _OWLCLASS TDib;
  19. class _OWLCLASS TPalette;
  20. class _OWLCLASS TClipboard;
  21. class _OWLCLASS TMetaFilePict;
  22.  
  23. //
  24. // GDI Orphan control - Object reference counting & orphan recovery
  25. // enabled by default unless NO_GDI_ORPHAN_CONTROL is defined.
  26. //
  27. #if !defined(NO_GDI_ORPHAN_CONTROL)
  28. # define OBJ_REF_ADD(handle,type) TGdiObject::RefAdd((handle), (type))
  29. # define OBJ_REF_REMOVE(handle) TGdiObject::RefRemove(handle)
  30. # define OBJ_REF_INC(handle) TGdiObject::RefInc(handle)
  31. # if defined(__TRACE)
  32. #   define OBJ_REF_DEC(handle, wantDelete) TGdiObject::RefDec((handle),\
  33.                                                                (wantDelete))
  34. # else
  35. #   define OBJ_REF_DEC(handle, wantDelete) TGdiObject::RefDec((handle))
  36. # endif
  37. # define OBJ_REF_COUNT(handle) TGdiObject::RefCount(handle)
  38.   struct TObjInfo;
  39. #else
  40. # define OBJ_REF_ADD(handle,type) handle
  41. # define OBJ_REF_REMOVE(handle) handle
  42. # define OBJ_REF_INC(handle) handle
  43. # define OBJ_REF_DEC(handle,wantDelete) handle
  44. # define OBJ_REF_COUNT(handle) -1
  45. #endif
  46.  
  47. //
  48. // class TGdiObject
  49. // ----- ----------
  50. //
  51. // Abstract class for Windows GDI objects. Provides base, destruction &
  52. // orphan control for true GDI objects
  53. //
  54. class _OWLCLASS TGdiObject : private TGdiBase {
  55.   public:
  56.     // virtual destructor--all GDI objects inherit this.
  57.     /*virtual*/    ~TGdiObject();
  58.  
  59.     operator    HGDIOBJ() const {return HGDIOBJ(Handle);}
  60.     int         GetObject(int count, void far* object) const;
  61.     bool        operator ==(const TGdiObject& other) const {return Handle == other.Handle;}
  62.  
  63.     #if !defined(NO_GDI_ORPHAN_CONTROL)
  64.       enum TType {
  65.         None, Pen, Brush, Font, Palette, Bitmap, TextBrush
  66.       };
  67.       static TObjInfo* RefFind(HANDLE object);
  68.       static void      RefAdd(HANDLE handle, TType type);
  69.       static void      RefRemove(HANDLE handle);
  70.       static void      RefInc(HANDLE handle);
  71.       #if defined(__TRACE)
  72.         static void    RefDec(HANDLE handle, bool wantDelete);
  73.       #else
  74.         static void    RefDec(HANDLE handle);
  75.       #endif
  76.       static int       RefCount(HANDLE handle);
  77.     #endif
  78.  
  79.   protected:
  80.     TGdiBase::CheckValid;  // make this function available to derivatives
  81.     TGdiBase::Handle;      // and these members too
  82.     TGdiBase::ShouldDelete;
  83.  
  84.     // constructors for use by derived classes only
  85.     TGdiObject();
  86.     TGdiObject(HANDLE handle, TAutoDelete autoDelete = NoAutoDelete);
  87.  
  88.   private:
  89.     TGdiObject(const TGdiObject&); // Protect against copying of GDI objects
  90.     TGdiObject& operator =(const TGdiObject&);
  91. };
  92.  
  93. //
  94. // class TPen
  95. // ----- ----
  96. //
  97. // GDI Pen class. Can construct a pen from explicit info, or indirectly
  98. //
  99. class _OWLCLASS TPen : public TGdiObject {
  100.   public:
  101.     // Constructors
  102.     TPen(HPEN handle, TAutoDelete autoDelete = NoAutoDelete);
  103.  
  104.     TPen(TColor color, int width=1, int style=PS_SOLID);
  105.     TPen(const LOGPEN far* logPen);
  106.     TPen(const TPen&);
  107. #if defined(BI_PLAT_WIN32)
  108.     TPen(uint32 penStyle, uint32 width, const TBrush& brush, uint32 styleCount,
  109.          uint32* style);
  110.     TPen(uint32 penStyle, uint32 width, const LOGBRUSH& logBrush,
  111.          uint32 styleCount, uint32* style);
  112. #endif
  113.  
  114.     operator HPEN() const {return HPEN(HGDIOBJ(*this));}
  115.  
  116.     // Get GDI Pen Object information
  117.     bool        GetObject(LOGPEN far& logPen) const;
  118.  
  119.   private:
  120.     TPen& operator =(const TPen&);
  121. };
  122.  
  123. //
  124. // class TBrush
  125. // ----- ------
  126. //
  127. // GDI Brush class. Can construct a brush from explicit info, creating a 
  128. // solid, styled, or patterned brush.  Can also create a brush indirectly.
  129. //
  130. class _OWLCLASS TBrush : public TGdiObject {
  131.   public:
  132.     // Constructors
  133.     TBrush(HBRUSH handle, TAutoDelete autoDelete = NoAutoDelete);
  134.  
  135.     TBrush(TColor color);
  136.     TBrush(TColor color, int style);
  137.     TBrush(const TBitmap& pattern);
  138.     TBrush(const TDib& pattern);
  139.     TBrush(const LOGBRUSH far* logBrush);
  140.     TBrush(const TBrush& src);
  141.  
  142.     operator HBRUSH() const {return HBRUSH(HGDIOBJ(*this));}
  143.  
  144.     // Get GDI Brush Object information
  145.     bool        GetObject(LOGBRUSH far& logBrush) const;
  146. #if defined(BI_PLAT_WIN16)
  147.     bool        UnrealizeObject();  // Use TDC::SetBrushOrg() for Win32
  148. #endif
  149.  
  150.   private:
  151.     TBrush& operator =(const TBrush&);
  152. };
  153.  
  154. //
  155. // class THatch8x8Brush
  156. // ----- --------------
  157. //
  158. // Mini 8x8 monochrome configurable hatch brush class, with predefined patterns
  159. //
  160. class _OWLCLASS THatch8x8Brush : public TBrush {
  161.   public:
  162.     THatch8x8Brush(const uint8 hatch[], TColor fgColor=TColor::White,
  163.                    TColor bgColor=TColor::Black);
  164.     void     Reconstruct(const uint8 hatch[], TColor fgColor, TColor bgColor);
  165.  
  166.     const static uint8 Hatch22F1[8];  // 2-on, 2-off, offset 1 per row forward
  167.     const static uint8 Hatch13F1[8];  // 1-on, 3-off, offset 1 per row forward
  168.     const static uint8 Hatch11F1[8];  // 1-on, 1-off, offset 1 per row
  169.     const static uint8 Hatch22B1[8];  // 2-on, 2-off, offset 1 per row backward
  170.     const static uint8 Hatch13B1[8];  // 1-on, 3-off, offset 1 per row backward
  171.  
  172.   private:
  173.     static HBRUSH Create(const uint8 hatch[], TColor fgColor, TColor bgColor);
  174. };
  175.  
  176. //
  177. // class TFont
  178. // ----- -----
  179. //
  180. // GDI Font class.  Can construct a font from explicit info, or indirectly.
  181. //
  182. class _OWLCLASS TFont : public TGdiObject {
  183.   public:
  184.     // Constructors
  185.     TFont(HFONT handle, TAutoDelete autoDelete = NoAutoDelete);
  186.   
  187.     // Convenient font ctor
  188.     TFont(const char far* facename=0,
  189.           int height=0, int width=0, int escapement=0, int orientation=0,
  190.           int weight=FW_NORMAL,
  191.           uint8 pitchAndFamily=DEFAULT_PITCH|FF_DONTCARE,
  192.           uint8 italic=false, uint8 underline=false, uint8 strikeout=false,
  193.           uint8 charSet=1,  // DEFAULT_CHARSET or UNICODE_CHARSET
  194.           uint8 outputPrecision=OUT_DEFAULT_PRECIS,
  195.           uint8 clipPrecision=CLIP_DEFAULT_PRECIS,
  196.           uint8 quality=DEFAULT_QUALITY);
  197.  
  198.     // CreateFont() matching font ctor
  199.     TFont(int height, int width, int escapement=0, int orientation=0,
  200.           int weight=FW_NORMAL,
  201.           uint8 italic=false, uint8 underline=false, uint8 strikeout=false,
  202.           uint8 charSet=1,  // DEFAULT_CHARSET or UNICODE_CHARSET
  203.           uint8 outputPrecision=OUT_DEFAULT_PRECIS,
  204.           uint8 clipPrecision=CLIP_DEFAULT_PRECIS,
  205.           uint8 quality=DEFAULT_QUALITY,
  206.           uint8 pitchAndFamily=DEFAULT_PITCH|FF_DONTCARE,
  207.           const char far* facename=0);
  208.     TFont(const LOGFONT far* logFont);
  209.     TFont(const TFont&);
  210.  
  211.     operator HFONT() const {return HFONT(HGDIOBJ(*this));}
  212.  
  213.     // Get GDI Font Object information
  214.     bool        GetObject(LOGFONT far& logFont) const;
  215.  
  216.   private:
  217.     TFont& operator =(const TFont&);
  218. };
  219.  
  220. //
  221. // class TPalette
  222. // ----- --------
  223. //
  224. // GDI Palette class.  Can construct a palette from explicit info, or
  225. // indirectly from various color table types that are used by DIBs.
  226. //
  227. class _OWLCLASS TPalette : public TGdiObject {
  228.   public:
  229.     // Constructors
  230.     TPalette(HPALETTE handle, TAutoDelete autoDelete = NoAutoDelete);
  231.  
  232.     TPalette(const TClipboard&);
  233.     TPalette(const TPalette& palette);          // Copy whole palette
  234.  
  235.     TPalette(const LOGPALETTE far* logPalette);
  236.     TPalette(const PALETTEENTRY far* entries, int count);
  237.     TPalette(const BITMAPINFO far* info, uint flags=0);    //Win 3.0 DIB hdr
  238.     TPalette(const BITMAPCOREINFO far* core, uint flags=0);//PM 1.0 DIB header
  239.     TPalette(const TDib& dib, uint flags=0);               // DIB object
  240.  
  241.     operator HPALETTE() const {return HPALETTE(HGDIOBJ(*this));}
  242.  
  243.     // Palette functions
  244.     bool        ResizePalette(uint numEntries);
  245.     void        AnimatePalette(uint start, uint count, const PALETTEENTRY far* entries);
  246.     uint        SetPaletteEntries(uint16 start, uint16 count, const PALETTEENTRY far* entries);
  247.     uint        SetPaletteEntry(uint16 index, const PALETTEENTRY far& entry);
  248.     uint        GetPaletteEntries(uint16 start, uint16 count, PALETTEENTRY far* entries) const;
  249.     uint        GetPaletteEntry(uint16 index, PALETTEENTRY far& entry) const;
  250.     uint        GetNearestPaletteIndex(TColor color) const;
  251.     bool        GetObject(uint16 far& numEntries) const;
  252.     uint16      GetNumEntries() const;
  253.  
  254.     // Put this palette onto the clipboard
  255.     void        ToClipboard(TClipboard& Clipboard);
  256.     bool        UnrealizeObject() {return ::UnrealizeObject(Handle);}
  257.  
  258.   protected:
  259.     void        Create(const BITMAPINFO far* info, uint flags);
  260.     void        Create(const BITMAPCOREINFO far* core, uint flags);
  261.  
  262.   private:
  263.     TPalette& operator =(const TPalette&);
  264. };
  265.  
  266. inline TClipboard& operator <<(TClipboard& clipboard, TPalette& palette)
  267.       {palette.ToClipboard(clipboard); return clipboard;}
  268.  
  269. //
  270. // class TBitmap
  271. // ----- -------
  272. //
  273. // GDI Bitmap class.  Can construct a bitmap from many sources.  This bitmap
  274. // is the lowest level object that is actually selected into a DC.
  275. //
  276. class _OWLCLASS TBitmap : public TGdiObject {
  277.   public:
  278.     // Constructors
  279.     TBitmap(HBITMAP handle, TAutoDelete autoDelete = NoAutoDelete);
  280.     TBitmap(const TClipboard& clipboard);
  281.     TBitmap(const TBitmap& bitmap);
  282.  
  283.     TBitmap(int width, int height, uint8 planes=1, uint8 bitCount=1, const void far* bits=0);
  284.     TBitmap(const BITMAP far* bitmap);
  285.     TBitmap(const TDC& Dc, int width, int height, bool discardable = false);
  286.     TBitmap(const TDC& Dc, const TDib& dib, uint32 usage=CBM_INIT);
  287.  
  288.     TBitmap(const TMetaFilePict& metaFile, TPalette& palette, const TSize& size);
  289.     TBitmap(const TDib& dib, const TPalette* palette = 0);
  290.  
  291.     TBitmap(HINSTANCE, TResId);
  292.  
  293.     operator HBITMAP() const {return HBITMAP(HGDIOBJ(*this));}
  294.  
  295.     // Get/set GDI Object information
  296.     bool        GetObject(BITMAP far& bitmap) const;
  297.     int         Width() const;
  298.     int         Height() const;
  299.     uint8       Planes() const;
  300.     uint8       BitsPixel() const;
  301.     uint32      GetBitmapBits(uint32 count, void far* bits) const;
  302.     uint32      SetBitmapBits(uint32 count, const void far* bits);
  303.     bool        GetBitmapDimension(TSize& size) const;
  304.     bool        SetBitmapDimension(const TSize& size, TSize far* oldSize=0);
  305.  
  306.     // Put this bitmap onto the clipboard
  307.     void  ToClipboard(TClipboard& clipboard);
  308.  
  309.   protected:
  310.     TBitmap();
  311.  
  312.     // Create a bitmap & fill in it's Handle
  313.     void Create(const TDib& dib, const TPalette& palette);
  314.     void Create(const TBitmap& src);
  315.  
  316.   private:
  317.     TBitmap& operator =(const TBitmap&);
  318. };
  319.  
  320. inline TClipboard& operator <<(TClipboard& clipboard, TBitmap& bitmap)
  321.       {bitmap.ToClipboard(clipboard); return clipboard;}
  322.  
  323. //
  324. // class TRegion
  325. // ----- -------
  326. //
  327. // GDI Region class. Can construct a region from various shapes
  328. //
  329. class _OWLCLASS TRegion : private TGdiBase {
  330.   public:
  331.     // Constructors
  332.     TRegion();
  333.     TRegion(HRGN handle, TAutoDelete autoDelete = NoAutoDelete);
  334.     TRegion(const TRegion& region);
  335.     TRegion(const TRect& rect);
  336.     enum TEllipse {Ellipse};
  337.     TRegion(const TRect& e, TEllipse);
  338.     TRegion(const TRect& rect, const TSize& corner);
  339.     TRegion(const TPoint* points, int count, int fillMode);
  340.     TRegion(const TPoint* points, const int* polyCounts, int count,
  341.             int fillMode);
  342.    ~TRegion();
  343.  
  344.     // Other initialization
  345.     void        SetRectRgn(const TRect& rect);
  346.  
  347.     // Type Conversion Operators
  348.     operator HRGN() const {return HRGN(Handle);}
  349.  
  350.     // Test and information functions/operators
  351.     bool        operator ==(const TRegion& other) const;
  352.     bool        operator !=(const TRegion& other) const;
  353.     bool        Contains(const TPoint& point) const;
  354.     bool        Touches(const TRect& rect) const;
  355.     int         GetRgnBox(TRect& box) const;
  356.     TRect       GetRgnBox() const;
  357.  
  358.     // Assignment operators
  359.     TRegion&    operator =(const TRegion& source);
  360.     TRegion&    operator +=(const TSize& delta);
  361.     TRegion&    operator -=(const TSize& delta);
  362.     TRegion&    operator -=(const TRegion& source);
  363.     TRegion&    operator &=(const TRegion& source);
  364.     TRegion&    operator &=(const TRect& source);
  365.     TRegion&    operator |=(const TRegion& source);
  366.     TRegion&    operator |=(const TRect& source);
  367.     TRegion&    operator ^=(const TRegion& source);
  368.     TRegion&    operator ^=(const TRect& source);
  369. };
  370.  
  371. //
  372. // class TIcon
  373. // ----- -----
  374. //
  375. // Pseudo-GDI object Icon class.  Can construct an icon from a resource or
  376. // explicit info.  Overloads the destructor since it is not a real GDI object.
  377. //
  378. class _OWLCLASS TIcon : private TGdiBase {
  379.   public:
  380.     // Constructors
  381.     TIcon(HICON handle, TAutoDelete autoDelete = NoAutoDelete);
  382.     TIcon(HINSTANCE, const TIcon& icon);
  383.     TIcon(HINSTANCE, TResId);
  384.     TIcon(HINSTANCE, const char far* filename, int index);
  385.     TIcon(HINSTANCE, const TSize& size, int planes, int bitsPixel, 
  386.           const void far* andBits, const void far* xorBits);
  387. #if defined(BI_PLAT_WIN32)
  388.     TIcon(const void* resBits, uint32 resSize);
  389.     TIcon(const ICONINFO* iconInfo);
  390. #endif
  391.    ~TIcon();
  392.  
  393.     operator HICON() const {return HICON(Handle);}
  394.     bool     operator ==(const TIcon& other) const {return Handle == other.Handle;}
  395.     
  396. #if defined(BI_PLAT_WIN32)
  397.     bool     GetIconInfo(ICONINFO* iconInfo) const;
  398. #endif
  399.  
  400.   private:
  401.     TIcon(const TIcon&); // Protect against copying of icons
  402.     TIcon& operator =(const TIcon&);
  403. };
  404.  
  405. //
  406. // class TCursor
  407. // ----- -------
  408. //
  409. // Pseudo-GDI object Cursor class.  Can construct an cursor from a resource or
  410. // explicit info.  Overloads the destructor since it is not a real GDI object.
  411. //
  412. class _OWLCLASS TCursor : public TGdiBase {
  413.   public:
  414.     // Constructors
  415.     TCursor(HCURSOR handle, TAutoDelete autoDelete = NoAutoDelete);
  416.     TCursor(HINSTANCE, const TCursor& cursor);
  417.     TCursor(HINSTANCE, TResId);
  418.     TCursor(HINSTANCE, const TPoint& hotSpot,
  419.             const TSize& size, void far* andBits, void far* xorBits);
  420. #if defined(BI_PLAT_WIN32)
  421.     TCursor(const void* resBits, uint32 resSize);
  422.     TCursor(const ICONINFO* iconInfo);
  423. #endif
  424.    ~TCursor();
  425.  
  426.     operator HCURSOR() const {return HCURSOR(Handle);}
  427.     bool     operator ==(const TCursor& other) const {return Handle == other.Handle;}
  428.  
  429. #if defined(BI_PLAT_WIN32)
  430.     bool     GetIconInfo(ICONINFO* iconInfo) const;
  431. #endif
  432.     
  433.   private:
  434.     TCursor(const TCursor&); // Protect against copying of cursors
  435.     TCursor& operator =(const TCursor&);
  436. };
  437.  
  438. //
  439. // class TDib
  440. // ----- ----
  441. //
  442. // Pseudo-GDI object Device Independent Bitmap (DIB) class.  DIBs really have
  443. // no Window's handle, they are just a structure containing format and palette
  444. // information and a collection of bits (pixels).  This class provides a very
  445. // convenient way to work with DIBs like any other GDI object.
  446. // The memory for the DIB is in one GlobalAlloc'd chunk so it can be passed to
  447. // the Clipboard, OLE, etc.
  448. // Overloads the destructor since it is not a real GDI object.
  449. //
  450. // This is what is really inside a .BMP file, what is in bitmap resources, and
  451. // what is put on the clipboard as a DIB.
  452. //
  453. class _OWLCLASS TDib : private TGdiBase {
  454.   public:
  455.     // Constructors and destructor
  456.     TDib(HGLOBAL handle, TAutoDelete autoDelete = NoAutoDelete);
  457.     TDib(const TClipboard& clipboard);
  458.     TDib(const TDib& dib);
  459.  
  460.     TDib(int width, int height, int nColors, uint16 mode=DIB_RGB_COLORS);
  461.     TDib(HINSTANCE, TResId);
  462.     TDib(const char* name);
  463. #if !defined(BI_DATA_NEAR)
  464.     TDib(istream& is, bool readFileHeader = false);
  465. #endif
  466.     TDib(const TBitmap& bitmap, const TPalette* pal = 0);
  467.    ~TDib();
  468.  
  469.     // Comparison operator
  470.     bool     operator ==(const TDib& other) const {return Handle == other.Handle;}
  471.  
  472.     // Access to the internal structures of the dib
  473.     const BITMAPINFO far*      GetInfo() const {return Info;}
  474.     BITMAPINFO far*            GetInfo() {return Info;}
  475.     const BITMAPINFOHEADER far*GetInfoHeader() const {return &Info->bmiHeader;}
  476.     BITMAPINFOHEADER far*      GetInfoHeader() {return &Info->bmiHeader;}
  477.     const TRgbQuad far*        GetColors() const {return (const TRgbQuad far*)Info->bmiColors;}
  478.     TRgbQuad far*              GetColors() {return (TRgbQuad far*)Info->bmiColors;}
  479.     const uint16 far*          GetIndices() const {return (uint16*)Info->bmiColors;}
  480.     uint16 far*                GetIndices() {return (uint16*)Info->bmiColors;}
  481.     const void HUGE*           GetBits() const {return Bits;}
  482.     void HUGE*                 GetBits() {return Bits;}
  483.  
  484.     // Type convert this dib by returning pointers to internal structures
  485.     operator HANDLE() const {return Handle;}
  486.     operator const BITMAPINFO far*() const {return GetInfo();}
  487.     operator BITMAPINFO far*() {return GetInfo();}
  488.     operator const BITMAPINFOHEADER far*() const {return GetInfoHeader();}
  489.     operator BITMAPINFOHEADER far*() {return GetInfoHeader();}
  490.     operator const TRgbQuad far*() const {return GetColors();}
  491.     operator TRgbQuad far*() {return GetColors();}
  492.  
  493.     // Put this Dib onto the clipboard
  494.     void      ToClipboard(TClipboard& clipboard);
  495.  
  496.     // Get info about this Dib
  497.     bool      IsOK() const {return Info != 0;}
  498.     bool      IsPM() const {return IsCore;}
  499.     int       Width() const {return W;}
  500.     int       Height() const {return H;}
  501.     TSize     Size() const {return TSize(W,H);}
  502.     long      NumColors() const {return NumClrs;}
  503.     uint16    StartScan() const {return 0;}
  504.     uint16    NumScans() const {return uint16(H);}
  505.     uint16    Usage() const {return Mode;}
  506.  
  507.     // Write this dib to a file by name, to file object or to an ostream
  508.     bool      WriteFile(const char* filename);
  509.     bool      Write(TFile& file, bool writeFileHeader = false);
  510. #if !defined(BI_DATA_NEAR)
  511.     bool      Write(ostream& os, bool writeFileHeader = false);
  512. #endif
  513.  
  514.     // Work with the dib in PAL or RGB mode
  515.     bool      ChangeModeToPal(const TPalette& pal);
  516.     bool      ChangeModeToRGB(const TPalette& pal);
  517.     TColor    GetColor(int entry) const;
  518.     void      SetColor(int entry, TColor color);
  519.     int       FindColor(TColor color);
  520.     int       MapColor(TColor fromColor, TColor toColor, bool doAll = false);
  521.     uint16    GetIndex(int entry) const;
  522.     void      SetIndex(int entry, uint16 index);
  523.     int       FindIndex(uint16 index);
  524.     int       MapIndex(uint16 fromIndex, uint16 toIndex, bool doAll = false);
  525.  
  526.     enum {
  527.       MapFace      = 0x01,  // Or these together to control colors to map
  528.       MapText      = 0x02,  // to current SysColor values 
  529.       MapShadow    = 0x04,
  530.       MapHighlight = 0x08,
  531.       MapFrame     = 0x10
  532.     };
  533.     void      MapUIColors(uint mapColors, TColor* bkColor = 0);
  534.     
  535.   protected:
  536.     TGdiBase::CheckValid;  // make this function available to derivatives
  537.     TGdiBase::Handle;      // and these members too
  538.     TGdiBase::ShouldDelete;
  539.  
  540.     BITMAPINFO far* Info;       // Locked global alloc'd block
  541.     void HUGE*      Bits;       // Pointer into above block at bits
  542.     long            NumClrs;
  543.     int             W;
  544.     int             H;
  545.     uint16          Mode;
  546.     bool            IsCore : 1;
  547.     bool            IsResHandle : 1;
  548.  
  549.     // Protected ctor- derived classes need to fillin handle & get info
  550.     TDib();
  551.  
  552.     void      InfoFromHandle();
  553.     bool      ReadFile(const char* name);
  554.     bool      Read(TFile& file, bool readFileHeader = false);
  555. #if !defined(BI_DATA_NEAR)
  556.     bool      Read(istream& is, bool readFileHeader = false);
  557. #endif
  558.  
  559.     bool      LoadResource(HINSTANCE, TResId);
  560.  
  561.     bool      LoadFile(const char* name) {return ReadFile(name);} // old name
  562.  
  563.   private:
  564.     TDib& operator =(const TDib&);
  565. };
  566.  
  567. inline TClipboard& operator <<(TClipboard& clipboard, TDib& dib)
  568.       {dib.ToClipboard(clipboard); return clipboard;}
  569.  
  570.  
  571. //----------------------------------------------------------------------------
  572. //   Inlines for abstract GDI object class and derived classes.
  573. //----------------------------------------------------------------------------
  574. #if !defined(OWL_DC_H)
  575. # include <owl/dc.h>
  576. #endif
  577. #if !defined(OWL_CLIPBOAR_H)
  578. # include <owl/clipboar.h>
  579. #endif
  580.  
  581. inline int TGdiObject::GetObject(int count, void far* object) const {
  582. #if defined(BI_PLAT_WIN32)
  583. # if defined(UNICODE)
  584.     return ::GetObjectW(Handle, count, object);
  585. #  else
  586.     return ::GetObjectA(Handle, count, object);
  587. #  endif
  588. #else
  589.   return ::GetObject(Handle, count, object);
  590. #endif
  591. }
  592.  
  593. inline bool TPen::GetObject(LOGPEN far& logPen) const {
  594.   return TGdiObject::GetObject(sizeof(logPen), &logPen) != 0;
  595. }
  596.  
  597. inline bool TBrush::GetObject(LOGBRUSH far& logBrush) const {
  598.   return TGdiObject::GetObject(sizeof(logBrush), &logBrush) != 0;
  599. }
  600.  
  601. #if defined(BI_PLAT_WIN16)
  602. inline bool TBrush:: UnrealizeObject() {
  603.   return ::UnrealizeObject(Handle);
  604. }
  605. #endif
  606.  
  607. inline bool TFont::GetObject(LOGFONT far& logFont) const {
  608.   return TGdiObject::GetObject(sizeof(logFont), &logFont) != 0;
  609. }
  610.  
  611.  
  612. inline bool TPalette::ResizePalette(uint numEntries) {
  613.   return ::ResizePalette((HPALETTE)Handle, numEntries);
  614. }
  615.  
  616. inline void TPalette::AnimatePalette(uint start, uint count, const PALETTEENTRY far* entries) {
  617.   ::AnimatePalette((HPALETTE)Handle, start, count, entries);
  618. }
  619.  
  620. inline uint TPalette::SetPaletteEntries(uint16 start, uint16 count, const PALETTEENTRY far* entries) {
  621.   return ::SetPaletteEntries((HPALETTE)Handle, start, count, entries);
  622. }
  623.  
  624. inline uint TPalette::SetPaletteEntry(uint16 index, const PALETTEENTRY far& entry) {
  625.   return ::SetPaletteEntries((HPALETTE)Handle, index, 1, &entry);
  626. }
  627.  
  628. inline uint TPalette::GetPaletteEntries(uint16 start, uint16 count, PALETTEENTRY far* entries) const {
  629.   return ::GetPaletteEntries((HPALETTE)Handle, start, count, entries);
  630. }
  631.  
  632. inline uint TPalette::GetPaletteEntry(uint16 index, PALETTEENTRY far& entry) const {
  633.   return ::GetPaletteEntries((HPALETTE)Handle, index, 1, &entry);
  634. }
  635.  
  636. inline uint TPalette::GetNearestPaletteIndex(TColor Color) const {
  637.   return ::GetNearestPaletteIndex((HPALETTE)Handle, Color);
  638. }
  639.  
  640. inline bool TPalette::GetObject(uint16 far& numEntries) const {
  641.   return TGdiObject::GetObject(sizeof(numEntries), &numEntries);
  642. }
  643.  
  644. inline uint16 TPalette::GetNumEntries() const {
  645.   uint16 numEntries;
  646.   if (TGdiObject::GetObject(sizeof(numEntries), &numEntries))
  647.     return numEntries;
  648.   return 0;
  649. }
  650.  
  651. inline uint32 TBitmap::GetBitmapBits(uint32 count, void far* bits) const {
  652.   return ::GetBitmapBits((HBITMAP)Handle, count, bits);
  653. }
  654.  
  655. inline uint32 TBitmap::SetBitmapBits(uint32 count, const void far* bits) {
  656.   return ::SetBitmapBits((HBITMAP)Handle, count, bits);
  657. }
  658.  
  659. inline bool TBitmap::GetBitmapDimension(TSize& size) const {
  660.   return ::GetBitmapDimensionEx((HBITMAP)Handle, &size);
  661. }
  662.  
  663. inline bool TBitmap::SetBitmapDimension(const TSize& size, TSize far* oldSize) {
  664.   return ::SetBitmapDimensionEx((HBITMAP)Handle, size.cx, size.cy, oldSize);
  665. }
  666.  
  667. inline bool TBitmap::GetObject(BITMAP far& Bitmap) const {
  668.   return TGdiObject::GetObject(sizeof(Bitmap), &Bitmap) != 0;
  669. }
  670.  
  671.  
  672. inline void TRegion::SetRectRgn(const TRect& rect) {
  673.   ::SetRectRgn((HRGN)Handle, rect.left, rect.top, rect.right, rect.bottom);
  674. }
  675.  
  676. inline bool TRegion::operator ==(const TRegion& other) const {
  677.   return ::EqualRgn((HRGN)Handle, other);
  678. }
  679.  
  680. inline bool TRegion::operator !=(const TRegion& other) const {
  681.   return !::EqualRgn((HRGN)Handle, other);
  682. }
  683.  
  684. inline bool TRegion::Contains(const TPoint& point) const {
  685.   return ::PtInRegion((HRGN)Handle, point.x, point.y);
  686. }
  687.  
  688. inline bool TRegion::Touches(const TRect& rect) const {
  689.   return ::RectInRegion((HRGN)Handle, (TRect*)&rect); // API <const> typecast 
  690. }
  691.  
  692. inline int TRegion::GetRgnBox(TRect& box) const {
  693.   return ::GetRgnBox((HRGN)Handle, &box);
  694. }
  695.  
  696. inline TRect TRegion::GetRgnBox() const {
  697.   TRect box;
  698.   ::GetRgnBox((HRGN)Handle, &box);
  699.   return box;
  700. }
  701.  
  702. inline TRegion& TRegion::operator =(const TRegion& source) {
  703.   ::CombineRgn((HRGN)Handle, source, 0, RGN_COPY);
  704.   return *this;
  705. }
  706.  
  707. inline TRegion& TRegion::operator +=(const TSize& delta) {
  708.   ::OffsetRgn((HRGN)Handle, delta.cx, delta.cy);
  709.   return *this;
  710. }
  711.  
  712. inline TRegion& TRegion::operator -=(const TSize& delta) {
  713.   ::OffsetRgn((HRGN)Handle, -delta.cx, -delta.cy);
  714.   return *this;
  715. }
  716.  
  717. inline TRegion& TRegion::operator -=(const TRegion& source) {
  718.   ::CombineRgn((HRGN)Handle, (HRGN)Handle, source, RGN_DIFF);
  719.   return *this;
  720. }
  721.  
  722. inline TRegion& TRegion::operator &=(const TRegion& source) {
  723.   ::CombineRgn((HRGN)Handle, (HRGN)Handle, source, RGN_AND);
  724.   return *this;
  725. }
  726.  
  727. inline TRegion& TRegion::operator |=(const TRegion& source) {
  728.   ::CombineRgn((HRGN)Handle, (HRGN)Handle, source, RGN_OR);
  729.   return *this;
  730. }
  731.  
  732. inline TRegion& TRegion::operator ^=(const TRegion& source) {
  733.   ::CombineRgn((HRGN)Handle, (HRGN)Handle, source, RGN_XOR);
  734.   return *this;
  735. }
  736.  
  737. #if defined(BI_PLAT_WIN32)
  738. inline bool TIcon::GetIconInfo(ICONINFO far* IconInfo) const {
  739.   return ::GetIconInfo((HICON)Handle, IconInfo);
  740. }
  741.  
  742. inline bool TCursor::GetIconInfo(ICONINFO far* IconInfo) const {
  743.   return ::GetIconInfo((HICON)(HCURSOR)Handle, IconInfo);
  744. }
  745. #endif
  746.  
  747.  
  748. #endif  // OWL_GDIOBJEC_H
  749.