1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/msw/imaglist.h
3 // Purpose: wxImageList class
4 // Author: Julian Smart
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_IMAGLIST_H_
12 #define _WX_IMAGLIST_H_
14 #include "wx/bitmap.h"
16 // Eventually we'll make this a reference-counted wxGDIObject. For
17 // now, the app must take care of ownership issues. That is, the
18 // image lists must be explicitly deleted after the control(s) that uses them
19 // is (are) deleted, or when the app exits.
20 class WXDLLIMPEXP_CORE wxImageList
: public wxObject
29 // Creates an image list.
30 // Specify the width and height of the images in the list,
31 // whether there are masks associated with them (e.g. if creating images
32 // from icons), and the initial size of the list.
33 wxImageList(int width
, int height
, bool mask
= true, int initialCount
= 1)
35 Create(width
, height
, mask
, initialCount
);
37 virtual ~wxImageList();
41 ////////////////////////////////////////////////////////////////////////////
43 // Returns the number of images in the image list.
44 int GetImageCount() const;
46 // Returns the size (same for all images) of the images in the list
47 bool GetSize(int index
, int &width
, int &height
) const;
50 ////////////////////////////////////////////////////////////////////////////
52 // Creates an image list
53 // width, height specify the size of the images in the list (all the same).
54 // mask specifies whether the images have masks or not.
55 // initialNumber is the initial number of images to reserve.
56 bool Create(int width
, int height
, bool mask
= true, int initialNumber
= 1);
58 // Adds a bitmap, and optionally a mask bitmap.
59 // Note that wxImageList creates *new* bitmaps, so you may delete
60 // 'bitmap' and 'mask' after calling Add.
61 int Add(const wxBitmap
& bitmap
, const wxBitmap
& mask
= wxNullBitmap
);
63 // Adds a bitmap, using the specified colour to create the mask bitmap
64 // Note that wxImageList creates *new* bitmaps, so you may delete
65 // 'bitmap' after calling Add.
66 int Add(const wxBitmap
& bitmap
, const wxColour
& maskColour
);
68 // Adds a bitmap and mask from an icon.
69 int Add(const wxIcon
& icon
);
71 // Replaces a bitmap, optionally passing a mask bitmap.
72 // Note that wxImageList creates new bitmaps, so you may delete
73 // 'bitmap' and 'mask' after calling Replace.
74 bool Replace(int index
, const wxBitmap
& bitmap
, const wxBitmap
& mask
= wxNullBitmap
);
76 /* Not supported by Win95
77 // Replacing a bitmap, using the specified colour to create the mask bitmap
78 // Note that wxImageList creates new bitmaps, so you may delete
80 bool Replace(int index, const wxBitmap& bitmap, const wxColour& maskColour);
83 // Replaces a bitmap and mask from an icon.
84 // You can delete 'icon' after calling Replace.
85 bool Replace(int index
, const wxIcon
& icon
);
87 // Removes the image at the given index.
88 bool Remove(int index
);
93 // Draws the given image on a dc at the specified position.
94 // If 'solidBackground' is true, Draw sets the image list background
95 // colour to the background colour of the wxDC, to speed up
96 // drawing by eliminating masked drawing where possible.
97 bool Draw(int index
, wxDC
& dc
, int x
, int y
,
98 int flags
= wxIMAGELIST_DRAW_NORMAL
,
99 bool solidBackground
= false);
102 wxBitmap
GetBitmap(int index
) const;
105 wxIcon
GetIcon(int index
) const;
107 // TODO: miscellaneous functionality
109 wxIcon *MakeIcon(int index);
110 bool SetOverlayImage(int index, int overlayMask);
114 // TODO: Drag-and-drop related functionality.
117 // Creates a new drag image by combining the given image (typically a mouse cursor image)
118 // with the current drag image.
119 bool SetDragCursorImage(int index
, const wxPoint
& hotSpot
);
121 // If successful, returns a pointer to the temporary image list that is used for dragging;
123 // dragPos: receives the current drag position.
124 // hotSpot: receives the offset of the drag image relative to the drag position.
125 static wxImageList
*GetDragImageList(wxPoint
& dragPos
, wxPoint
& hotSpot
);
127 // Call this function to begin dragging an image. This function creates a temporary image list
128 // that is used for dragging. The image combines the specified image and its mask with the
129 // current cursor. In response to subsequent mouse move messages, you can move the drag image
130 // by using the DragMove member function. To end the drag operation, you can use the EndDrag
132 bool BeginDrag(int index
, const wxPoint
& hotSpot
);
134 // Ends a drag operation.
137 // Call this function to move the image that is being dragged during a drag-and-drop operation.
138 // This function is typically called in response to a mouse move message. To begin a drag
139 // operation, use the BeginDrag member function.
140 static bool DragMove(const wxPoint
& point
);
142 // During a drag operation, locks updates to the window specified by lockWindow and displays
143 // the drag image at the position specified by point.
144 // The coordinates are relative to the window's upper left corner, so you must compensate
145 // for the widths of window elements, such as the border, title bar, and menu bar, when
146 // specifying the coordinates.
147 // If lockWindow is NULL, this function draws the image in the display context associated
148 // with the desktop window, and coordinates are relative to the upper left corner of the screen.
149 // This function locks all other updates to the given window during the drag operation.
150 // If you need to do any drawing during a drag operation, such as highlighting the target
151 // of a drag-and-drop operation, you can temporarily hide the dragged image by using the
152 // wxImageList::DragLeave function.
154 // lockWindow: pointer to the window that owns the drag image.
155 // point: position at which to display the drag image. Coordinates are relative to the
156 // upper left corner of the window (not the client area).
158 static bool DragEnter( wxWindow
*lockWindow
, const wxPoint
& point
);
160 // Unlocks the window specified by pWndLock and hides the drag image, allowing the
161 // window to be updated.
162 static bool DragLeave( wxWindow
*lockWindow
);
164 /* Here's roughly how you'd use these functions if implemented in this Win95-like way:
168 wxImageList *dragImageList = new wxImageList(16, 16, true);
169 dragImageList->Add(myDragImage); // Provide an image to combine with the current cursor
170 dragImageList->BeginDrag(0, wxPoint(0, 0));
171 wxShowCursor(false); // wxShowCursor not yet implemented in wxWin
172 myWindow->CaptureMouse();
176 // Called within mouse move event. Could also use dragImageList instead of assuming
177 // these are static functions.
178 // These two functions could possibly be combined into one, since DragEnter is
180 wxImageList::DragMove(wxPoint(x, y)); // x, y are current cursor position
181 wxImageList::DragEnter(NULL, wxPoint(x, y)); // NULL assumes dragging across whole screen
183 3) Finishing dragging:
185 dragImageList->EndDrag();
186 myWindow->ReleaseMouse();
193 ////////////////////////////////////////////////////////////////////////////
195 // Returns the native image list handle
196 WXHIMAGELIST
GetHIMAGELIST() const { return m_hImageList
; }
199 WXHIMAGELIST m_hImageList
;
201 DECLARE_DYNAMIC_CLASS_NO_COPY(wxImageList
)