home *** CD-ROM | disk | FTP | other *** search
/ Chip 1997 October / Chip_1997-10_cd.bin / tema / sybase / powerj / hpp.z / WBITMAP.HPP < prev    next >
C/C++ Source or Header  |  1997-01-14  |  8KB  |  251 lines

  1. /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2.    %     Copyright (C) 1994, by WATCOM International Inc.  All rights    %
  3.    %     reserved.  No part of this software may be reproduced or        %
  4.    %     used in any form or by any means - graphic, electronic or       %
  5.    %     mechanical, including photocopying, recording, taping or        %
  6.    %     information storage and retrieval systems - except with the     %
  7.    %     written permission of WATCOM International Inc.                 %
  8.    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  9. */
  10.  
  11. #ifndef _WBITMAP_HPP_INCLUDED
  12. #define _WBITMAP_HPP_INCLUDED
  13.  
  14. #ifndef _WNO_PRAGMA_PUSH
  15. #pragma pack(push,8);
  16. #pragma enum int;
  17. #endif
  18.  
  19. #ifndef _WOBJECT_HPP_INCLUDED
  20. #  include "wobject.hpp"
  21. #endif
  22. #ifndef _WARRAY_HPP_INCLUDED
  23. #  include "warray.hpp"
  24. #endif
  25. #ifndef _WCOLOR_HPP_INCLUDED
  26. #  include "wcolor.hpp"
  27. #endif
  28. #ifndef _WRESID_HPP_INCLUDED
  29. #  include "wresid.hpp"
  30. #endif
  31. #ifndef _WICON_HPP_INCLUDED
  32. #  include "wicon.hpp"
  33. #endif
  34. #ifndef _WPALETTE_HPP_INCLUDED
  35. #  include "wpalette.hpp"
  36. #endif
  37. #ifndef _WBUFFER_HPP_INCLUDED
  38. #  include "wbuffer.hpp"
  39. #endif
  40. #ifndef _WFILPATH_HPP_INCLUDED
  41. #  include "wfilpath.hpp"
  42. #endif
  43.  
  44. class WPoint;
  45. class WCanvas;
  46. class WBitmapReference;
  47.  
  48. enum WStockBitmap {
  49.     WSBitmapFirst,
  50.     WSBitmapClose = WSBitmapFirst,
  51.     WSBitmapUpArrow,
  52.     WSBitmapDownArrow,          WSBitmapDnArrow = WSBitmapDownArrow,
  53.     WSBitmapLeftArrow,          WSBitmapLfArrow = WSBitmapLeftArrow,
  54.     WSBitmapRightArrow,         WSBitmapRgArrow = WSBitmapRightArrow,
  55.     WSBitmapReduce,
  56.     WSBitmapZoom,
  57.     WSBitmapRestore,
  58.     WSBitmapCombo,
  59.     WSBitmapMNArrow,
  60.     WSBitmapSize,
  61.     WSBitmapCheck,
  62.     WSBitmapCheckBoxes,
  63.     WSBitmapBtnCorners,
  64.     WSBitmapBTSize,
  65.     WSBitmapUpArrowD,
  66.     WSBitmapDownArrowD,         WSBitmapDnArrowD = WSBitmapDownArrowD,
  67.     WSBitmapLeftArrowD,         WSBitmapLfArrowD = WSBitmapLeftArrowD,
  68.     WSBitmapRightArrowD,        WSBitmapRgArrowD = WSBitmapRightArrowD,
  69.     WSBitmapReduceD,
  70.     WSBitmapZoomD,
  71.     WSBitmapRestoreD,
  72.     WSBitmapUpArrowI,
  73.     WSBitmapDownArrowI,         WSBitmapDnArrowI = WSBitmapDownArrowI,
  74.     WSBitmapLeftArrowI,         WSBitmapLfArrowI = WSBitmapLeftArrowI,
  75.     WSBitmapRightArrowI,        WSBitmapRgArrowI = WSBitmapRightArrowI,
  76.  
  77.     WSBitmapLastPlusOne,
  78.     WSBitmapLast = WSBitmapLastPlusOne - 1,
  79. };
  80.  
  81. class WCMCLASS WBitmap : public WObject {
  82.     WDeclareSubclass( WBitmap, WObject );
  83.  
  84.     public:
  85.  
  86.         /**********************************************************
  87.          * Constructors and Destructors
  88.          *********************************************************/
  89.  
  90.         // Construct
  91.  
  92.         WBitmap();
  93.         WBitmap( WStockBitmap bitmap );
  94.         WBitmap( const WBitmap & src, WUInt newWidth=0, WUInt newHeight=0,
  95.                  WBool forceCreateNew=FALSE );
  96.         WBitmap( const WResourceID & id, WModuleHandle module=_ApplicationModule );
  97.         WBitmap( const WChar *file, const WResourceID & id,
  98.                  WBool loadLibraryAsDataOnly=FALSE );
  99.         WBitmap( const WChar *file, WBool monochrome );
  100.         WBitmap( WBitmapHandle hdl, WBool deleteHandle=FALSE );
  101.         WBitmap( WDeviceHandle hdc, WUInt width, WUInt height );
  102.         WBitmap( WUInt width, WUInt height, WUInt planes, WUInt bitsPerPel );
  103.         WBitmap( const WIcon & icon, const WColor * backColor=NULL );
  104.         WBitmap( const WIcon & icon, WCanvas * port, const WPoint & pt );
  105.         WBitmap( const WIcon & icon, WCanvas * port );
  106.         WBitmap( const WBuffer & buffer );
  107.  
  108.         // Destruct
  109.  
  110.         ~WBitmap();
  111.  
  112.         // Assignment
  113.  
  114.         WBitmap & operator=( const WBitmap & bitmap );
  115.         WBitmap & operator=( WStockBitmap bitmap );
  116.  
  117.         // Equality
  118.  
  119.         int operator==( const WBitmap & bmp ) const;
  120.         int operator!=( const WBitmap & bmp ) const;
  121.  
  122.         /************************************************************
  123.          * Properties
  124.          ************************************************************/
  125.  
  126.         // Handle
  127.  
  128.         WBitmapHandle GetHandle() const;
  129.  
  130.         // HandleDetached
  131.  
  132.         WBool GetHandleDetached() const;
  133.  
  134.         // Height
  135.  
  136.         WUInt GetHeight() const;
  137.  
  138.         // Palette
  139.  
  140.         WPalette GetPalette() const;
  141.  
  142.         // Valid
  143.  
  144.         WBool GetValid() const;
  145.  
  146.         // Width
  147.  
  148.         WUInt GetWidth() const;
  149.  
  150.         /************************************************************
  151.          * Methods
  152.          ************************************************************/
  153.  
  154.         // Clear
  155.         //
  156.         //     Prepare the object for re-use.  Deletes old bitmap
  157.         //     handle if appropriate.
  158.  
  159.         WBool Clear();
  160.  
  161.         // Create
  162.         //
  163.         //     Create a new bitmap.  Clears old one first.
  164.  
  165.         WBool Create( WStockBitmap bitmap );
  166.         WBool Create( const WBitmap & src, WUInt newWidth=0,
  167.                       WUInt newHeight=0, WBool forceCreateNew=FALSE );
  168.         WBool Create( const WResourceID & id, WModuleHandle module=_ApplicationModule );
  169.         WBool Create( const WChar *file, const WResourceID & id,
  170.                       WBool loadLibraryAsDataOnly=FALSE );
  171.         WBool Create( const WChar *file, WBool monochrome );
  172.         WBool Create( WBitmapHandle hdl, WBool deleteHandle=FALSE );
  173.         WBool Create( WDeviceHandle hdc, WUInt width, WUInt height );
  174.         WBool Create( WUInt width, WUInt height, WUInt planes,
  175.                       WUInt bitsPerPel );
  176.         WBool Create( const WIcon & icon, const WColor * backColor=NULL );
  177.         WBool Create( const WIcon & icon, WCanvas * port, const WPoint & pt );
  178.         WBool Create( const WIcon & icon, WCanvas * port );
  179.         WBool Create( const WBuffer & buffer );
  180.  
  181.         // MakePalette
  182.  
  183.         WBool MakePalette();
  184.  
  185.         // DetachHandle
  186.  
  187.         WBool DetachHandle();
  188.     
  189.         // MapColor
  190.  
  191.         WBool MapColor( const WColor & mapFrom, const WColor & mapTo );
  192.  
  193.         // Save
  194.         //
  195.         //     Save the bitmap out as a .BMP file.
  196.  
  197.         WBool Save( const WFilePath & filename, WUInt bitsPerPixel=0 ) const;
  198.         WBool Save( WBuffer & buffer, WUInt bitsPerPixel=0 ) const;
  199.     
  200.         /***********************************************************
  201.          * Static Properties
  202.          ***********************************************************/
  203.  
  204.         // NullBitmap
  205.  
  206.         static const WBitmap & GetNullBitmap(); // not an empty bitmap...
  207.  
  208.         /************************************************************
  209.          * Static Methods
  210.          ************************************************************/
  211.  
  212.         // IsValidHandle
  213.         //
  214.         //     Returns TRUE if the given handle is valid.  Can
  215.         //     optionally specify whether or not a null handle
  216.         //     is "valid".
  217.  
  218.         static WBool IsValidHandle( WBitmapHandle handle,
  219.                                     WBool nullValid=FALSE );
  220.  
  221.  
  222.         /***********************************************************
  223.          * Internal
  224.          ***********************************************************/
  225.  
  226.         WUShort GetOriginalBitCount() const;
  227.  
  228.     protected:
  229.         WBool GetWidthHeight();
  230.     
  231.     private:
  232.         WBitmapReference *      _bitmapRef;
  233. };
  234.  
  235. extern template WArrayReference<WBitmap>;
  236. extern template WArray<WBitmap>;
  237. typedef WArray<WBitmap>                 WBitmapArray;
  238.  
  239. #ifdef _DEBUG
  240. #define W_ISBITMAPHANDLE(h) CHECKGDI(WBitmap::IsValidHandle((WBitmapHandle)h))
  241. #else
  242. #define W_ISBITMAPHANDLE(h)
  243. #endif
  244.  
  245. #ifndef _WNO_PRAGMA_PUSH
  246. #pragma enum pop;
  247. #pragma pack(pop);
  248. #endif
  249.  
  250. #endif // _WBITMAP_HPP_INCLUDED
  251.