home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 10 / ioProg_10.iso / soft / optima / hpp.z / WIMGLIST.HPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-22  |  11.4 KB  |  351 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. /*************************************************************************
  12.  *
  13.  * WImageList -- Wrapper for the Windows 95 Image List control.
  14.  *
  15.  *************************************************************************/
  16.  
  17. #ifndef _WIMAGELIST_HPP_INCLUDED
  18. #define _WIMAGELIST_HPP_INCLUDED
  19.  
  20. #ifndef _WNO_PRAGMA_PUSH
  21. #pragma pack(push,4);
  22. #pragma enum int;
  23. #endif
  24.  
  25. #ifndef _WIMGLIST_HPP_INCLUDED
  26. #  include "wimglist.hpp"
  27. #endif
  28. #ifndef _WOBJECT_HPP_INCLUDED
  29. #  include "wobject.hpp"
  30. #endif
  31. #ifndef _WRESID_HPP_INCLUDED
  32. #  include "wresid.hpp"
  33. #endif
  34. #ifndef _WPOINT_HPP_INCLUDED
  35. #  include "wpoint.hpp"
  36. #endif
  37. #ifndef _WRECT_HPP_INCLUDED
  38. #  include "wrect.hpp"
  39. #endif
  40. #ifndef _WCANVAS_HPP_INCLUDED
  41. #  include "wcanvas.hpp"
  42. #endif
  43. #ifndef _WBITMAP_HPP_INCLUDED
  44. #  include "wbitmap.hpp"
  45. #endif
  46.  
  47. class WIcon;
  48. class WColor;
  49. class WWindow;
  50. class WImageListReference;
  51.  
  52. enum WILDrawingStyle {
  53.     WILDSNormal      = 0x0000,
  54.     WILDSTransparent = 0x0001,
  55.     WILDSFocus       = 0x0002,
  56.     WILDSSelected    = 0x0004,
  57.     WILDSMask        = 0x0010,
  58.     WILDSImage       = 0x0020,
  59.  
  60.     WILDSBlend25 = WILDSFocus,
  61.     WILDSBlend50 = WILDSSelected
  62. };
  63.  
  64. struct WImageInformation {
  65.     WBitmap     image;
  66.     WBitmap     mask;
  67.     WRect       imageBounds;
  68. };
  69.  
  70. #undef ExtractIcon
  71. #if defined( _UNICODE )
  72.     #define ExtractIcon                 ExtractIconW
  73. #else
  74.     #define ExtractIcon                 ExtractIconA
  75. #endif
  76.  
  77. #define WILStyleDefault   (0x0000)
  78. #define WILStyleMasked    (0x0001)
  79.  
  80. #define WIIndexToOverlayMask(i) ((i)<<8)
  81.  
  82. class WCMCLASS WImageList : public WObject {
  83.     WDeclareSubclass( WImageList, WObject );
  84.  
  85.     public:
  86.  
  87.         /**********************************************************
  88.          * Constructors and destructors
  89.          *********************************************************/
  90.  
  91.         // Constructors
  92.         //
  93.         
  94.         WImageList( const WResourceID & id, WInt width, WInt grow,
  95.                     const WColor & maskColor, WModuleHandle module=_ApplicationModule );
  96.         WImageList( WInt width, WInt height, WULong flags=WILStyleMasked,
  97.                     WInt initial=10, WInt grow=5 );
  98.         WImageList( const WImageList & source, WBool makeCopy=FALSE );
  99.         WImageList( WImageListHandle handle=NULLHIMAGELIST,
  100.                     WBool destroyImageList=TRUE );
  101.  
  102.         ~WImageList();
  103.  
  104.         /**********************************************************
  105.          * Operators
  106.          *********************************************************/
  107.  
  108.         WImageList & operator=( const WImageList & );
  109.  
  110.         int operator==( const WImageList & ) const;
  111.         int operator!=( const WImageList & ) const;
  112.  
  113.         /**********************************************************
  114.          * Properties
  115.          *********************************************************/
  116.  
  117.         // BackColor
  118.         //
  119.         //    Gets/sets the background color of the image list.
  120.  
  121.         WColor GetBackColor() const;
  122.         WBool  SetBackColor( const WColor & color );
  123.  
  124.         // Count
  125.         //
  126.         //    Return the number of images in the list.
  127.  
  128.         WInt GetCount() const;
  129.  
  130.         // DragImageList
  131.         //
  132.         //    Return the (temporary) image list used for dragging.
  133.         //    A valid image list is only returned after a call to
  134.         //    BeginDrag, and the image list is invalid after EndDrag.
  135.         //    A null image list is returned otherwise.
  136.  
  137.         WImageList GetDragImageList() const;
  138.  
  139.         // DragOffset
  140.         //
  141.         //    Return the offset of the drag image relative to the current
  142.         //    drag position.  Only valid between calls to BeginDrag
  143.         //    and EndDrag.
  144.  
  145.         WPoint GetDragOffset() const;
  146.  
  147.         // DragPosition
  148.         //
  149.         //    Return the current drag position.  Only valid between
  150.         //    calls to BeginDrag and EndDrag.
  151.  
  152.         WPoint GetDragPosition() const;
  153.  
  154.         // Handle
  155.         //
  156.         //    Return the image list handle.
  157.  
  158.         WImageListHandle GetHandle() const;
  159.  
  160.         // Height
  161.         //
  162.         //    Return the height in pixels of a single image in the
  163.         //    image list.  Setting the height clears the list of all
  164.         //    images.
  165.  
  166.         WInt  GetHeight() const;
  167.         WBool SetHeight( WInt height );
  168.  
  169.         // Width
  170.         //
  171.         //    Return the width in pixels of a single image in the
  172.         //    image list.  Setting the width clears the list of all
  173.         //    images.
  174.  
  175.         WInt  GetWidth() const;
  176.         WBool SetWidth( WInt width );
  177.  
  178.         /**********************************************************
  179.          * Methods
  180.          *********************************************************/
  181.  
  182.         // Add
  183.         //
  184.         //     Adds a bitmap or icon to the image list.  
  185.         //     Returns the index of the new item, or -1 on error.
  186.  
  187.         WLong Add( const WIcon & icon );
  188.         WLong Add( const WBitmap & nonMaskedImage );
  189.         WLong Add( const WBitmap & nonMaskedImage,
  190.                    const WBitmap & maskedImage );
  191.         WLong Add( const WBitmap & image, const WColor & color );
  192.  
  193.         // BeginDrag
  194.         //
  195.         //     Begin a drag operation.  An image is prepared for use
  196.         //     in drawing as a cursor.  If no hotspot
  197.         //     is given, default to 0, 0.
  198.  
  199.         WBool BeginDrag( WLong imageIndex, const WPoint *hotspot=NULL ) const;
  200.  
  201.         // Clear
  202.         //
  203.         //     Destroy or free the imagelist.
  204.  
  205.         WBool Clear( WBool destroy=TRUE );
  206.  
  207.         // Create
  208.  
  209.         WBool Create( const WResourceID & id, WInt width, WInt grow,
  210.                       const WColor & maskColor, WModuleHandle module=_ApplicationModule );
  211.         WBool Create( WInt width, WInt height, WULong flags=WILStyleMasked,
  212.                       WInt initial=10, WInt grow=5 );
  213.         WBool Create( const WImageList & source, WBool makeCopy=FALSE );
  214.         WBool Create( WImageListHandle handle=NULLHIMAGELIST,
  215.                       WBool destroyIt=TRUE );
  216.  
  217.         // Delete
  218.  
  219.         WBool Delete( WLong imageIndex );
  220.  
  221.         // DeleteAll
  222.         //
  223.         //     Deletes all the images from the imagelist, but does not
  224.         //     destroy or free the imagelist itself.  (Use Clear for that.)
  225.  
  226.         WBool DeleteAll();
  227.  
  228.         // DragEnter
  229.         //
  230.         //     Use to actually start drawing the drag image.  If no
  231.         //     position is given, default to current mouse position.
  232.         //     If no object/window is given, default to desktop.
  233.         //     Fails if BeginDrag was not called first.  Mouse coordinates
  234.         //     can be either absolute or relative to the window.
  235.  
  236.         WBool DragEnter( WWindowHandle window=NULLHWND,
  237.                          const WPoint * atPosition=NULL,
  238.                          WBool absolutePosition=TRUE ) const;
  239.         WBool DragEnter( const WWindow * inWindow,
  240.                          const WPoint * atPosition=NULL,
  241.                          WBool absolutePosition=TRUE ) const;
  242.  
  243.         // DragLeave
  244.         //
  245.         //    Use to unlock the window and hide the drag image.  If no
  246.         //    window specified, unlocks what was locked by DragEnter.
  247.  
  248.         WBool DragLeave( WWindowHandle window=NULLHWND ) const;
  249.         WBool DragLeave( const WWindow * window ) const;
  250.  
  251.         // DragMove
  252.         //
  253.         //    Use to move the cursor while dragging.  Returns FALSE
  254.         //    if BeginDrag and DragEnter were not called first.  If
  255.         //    no position is given, uses current mouse position.
  256.  
  257.         WBool DragMove( const WPoint * atPostion=NULL,
  258.                         WBool absolutePosition=TRUE ) const;
  259.  
  260.         // DragShow
  261.         //
  262.         //    Use when dragging to show/hide the drag image.
  263.         //    Returns FALSE if BeginDrag was not called.
  264.  
  265.         WBool DragShow( WBool showImage ) const;
  266.  
  267.         // Draw
  268.         //
  269.         //    Draw an image from the image list into the given port
  270.         //    at the given position.
  271.  
  272.         WBool Draw( WLong imageIndex, const WCanvas & port,
  273.                     const WPoint & atPosition,
  274.                     WILDrawingStyle style=WILDSNormal ) const;
  275.         WBool Draw( WLong imageIndex, const WCanvas & port,
  276.                     const WPoint & atPosition,
  277.                     const WSize & size,
  278.                     const WColor & backColor, const WColor & foreColor,
  279.                     WILDrawingStyle style ) const;
  280.  
  281.         // EndDrag
  282.         //
  283.         //    Use to end a dragging operation.  Calls DragLeave if
  284.         //    necessary.
  285.  
  286.         WBool EndDrag() const;
  287.  
  288.         // ExtractIcon
  289.         //
  290.         //    Create an icon out of an imagelist item.
  291.  
  292.         WIcon ExtractIcon( WLong imageIndex,
  293.                            WILDrawingStyle style=WILDSNormal ) const;
  294.  
  295.         // ExtractImageInformation
  296.         //
  297.         //    Retrieve the image information for a specific image.
  298.         //    Fills in the WImageInformation structure.
  299.  
  300.         WBool ExtractImageInformation( WLong imageIndex,
  301.                                        WImageInformation *info ) const;
  302.  
  303.         // Merge
  304.         //
  305.         //    Creates a new image list by merging together two images
  306.         //    from existing lists.  The second image is drawn
  307.         //    transparently over the first and can also be offset.
  308.  
  309.         WImageList Merge( const WImageList & list1, WLong index1,
  310.                           const WImageList & list2, WLong index2,
  311.                           WInt dx=0, WInt dy=0 ) const;
  312.  
  313.         // Overlay
  314.         //
  315.         //    Define an image as an overlay image.  Up to four images
  316.         //    in a list can be defined as overlay images.
  317.  
  318.         WBool Overlay( WLong imageIndex, WLong whichOverlay );
  319.  
  320.         // Replace
  321.         //
  322.         //    Replace an image with another.
  323.  
  324.         WBool Replace( WLong imageIndex, const WBitmap & newImage,
  325.                        const WBitmap & newMask=WBitmap::GetNullBitmap() );
  326.         WBool Replace( WLong imageIndex, const WIcon & newIcon );
  327.  
  328.         /**********************************************************
  329.          * Other
  330.          *********************************************************/
  331.  
  332.         WLong AddIcon( const WIcon & icon );
  333.         WLong AddBitmap( const WBitmap & nonMasked );
  334.         WLong AddBitmap( const WBitmap & nonMasked, const WBitmap & mask );
  335.         WLong AddMaskedBitmap( const WBitmap & nonMasked, const WColor & c );
  336.  
  337.         /**********************************************************
  338.          * Data members
  339.          *********************************************************/
  340.  
  341.     private:
  342.         WImageListReference *_ref;
  343. };
  344.  
  345. #ifndef _WNO_PRAGMA_PUSH
  346. #pragma enum pop;
  347. #pragma pack(pop);
  348. #endif
  349.  
  350. #endif // _WIMAGELIST_HPP_INCLUDED
  351.