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