1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxImageList
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "imaglist.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
23 #if defined(__WIN95__)
28 #include "wx/window.h"
29 #include "wx/dcclient.h"
35 #include "wx/msw/imaglist.h"
36 #include "wx/msw/private.h"
38 #if (defined(__WIN95__) && !defined(__GNUWIN32__)) || defined(__TWIN32__)
42 #if !USE_SHARED_LIBRARY
43 IMPLEMENT_DYNAMIC_CLASS(wxImageList
, wxObject
)
46 wxImageList::wxImageList(void)
51 wxImageList::~wxImageList(void)
54 ImageList_Destroy((HIMAGELIST
) m_hImageList
);
60 ////////////////////////////////////////////////////////////////////////////
62 // Returns the number of images in the image list.
63 int wxImageList::GetImageCount(void) const
65 return ImageList_GetImageCount((HIMAGELIST
) m_hImageList
);
69 ////////////////////////////////////////////////////////////////////////////
71 // Creates an image list
72 bool wxImageList::Create(int width
, int height
, bool mask
, int initial
)
78 // Grow by 1, I guess this is reasonable behaviour most of the time
79 m_hImageList
= (WXHIMAGELIST
) ImageList_Create(width
, height
, flags
, initial
, 1);
80 return (m_hImageList
!= 0);
83 // Adds a bitmap, and optionally a mask bitmap.
84 // Note that wxImageList creates new bitmaps, so you may delete
85 // 'bitmap' and 'mask'.
86 int wxImageList::Add(const wxBitmap
& bitmap
, const wxBitmap
& mask
)
88 HBITMAP hBitmap1
= (HBITMAP
) bitmap
.GetHBITMAP();
91 hBitmap2
= (HBITMAP
) mask
.GetHBITMAP();
93 int index
= ImageList_Add((HIMAGELIST
) GetHIMAGELIST(), hBitmap1
, hBitmap2
);
96 wxLogError(_("Couldn't add an image to the image list."));
102 // Adds a bitmap, using the specified colour to create the mask bitmap
103 // Note that wxImageList creates new bitmaps, so you may delete
105 int wxImageList::Add(const wxBitmap
& bitmap
, const wxColour
& maskColour
)
108 wxFAIL_MSG("ImageList_AddMasked not implemented in TWIN32");
111 HBITMAP hBitmap1
= (HBITMAP
) bitmap
.GetHBITMAP();
112 COLORREF colorRef
= PALETTERGB(maskColour
.Red(), maskColour
.Green(), maskColour
.Blue());
113 return ImageList_AddMasked((HIMAGELIST
) GetHIMAGELIST(), hBitmap1
, colorRef
);
117 // Adds a bitmap and mask from an icon.
118 int wxImageList::Add(const wxIcon
& icon
)
120 HICON hIcon
= (HICON
) icon
.GetHICON();
121 return ImageList_AddIcon((HIMAGELIST
) GetHIMAGELIST(), hIcon
);
124 // Replaces a bitmap, optionally passing a mask bitmap.
125 // Note that wxImageList creates new bitmaps, so you may delete
126 // 'bitmap' and 'mask'.
127 bool wxImageList::Replace(int index
, const wxBitmap
& bitmap
, const wxBitmap
& mask
)
130 wxFAIL_MSG("ImageList_Replace not implemented in TWIN32");
133 HBITMAP hBitmap1
= (HBITMAP
) bitmap
.GetHBITMAP();
134 HBITMAP hBitmap2
= 0;
136 hBitmap2
= (HBITMAP
) mask
.GetHBITMAP();
137 return (ImageList_Replace((HIMAGELIST
) GetHIMAGELIST(), index
, hBitmap1
, hBitmap2
) != 0);
141 /* Not supported by Win95
142 // Replacing a bitmap, using the specified colour to create the mask bitmap
143 // Note that wxImageList creates new bitmaps, so you may delete
145 bool wxImageList::Replace(int index, const wxBitmap& bitmap, const wxColour& maskColour)
147 HBITMAP hBitmap1 = (HBITMAP) bitmap.GetHBITMAP();
148 COLORREF colorRef = PALETTERGB(maskColour.Red(), maskColour.Green(), maskColour.Blue());
149 return (bool) ImageList_ReplaceMasked((HIMAGELIST) GetHIMAGELIST(), index, hBitmap1, colorRef);
153 // Replaces a bitmap and mask from an icon.
154 bool wxImageList::Replace(int index
, const wxIcon
& icon
)
156 HICON hIcon
= (HICON
) icon
.GetHICON();
157 return (ImageList_ReplaceIcon((HIMAGELIST
) GetHIMAGELIST(), index
, hIcon
) != 0);
160 // Removes the image at the given index.
161 bool wxImageList::Remove(int index
)
164 wxFAIL_MSG("ImageList_Replace not implemented in TWIN32");
167 return (ImageList_Remove((HIMAGELIST
) GetHIMAGELIST(), index
) != 0);
172 bool wxImageList::RemoveAll(void)
174 // TODO: Is this correct?
175 while ( GetImageCount() > 0 )
182 // Draws the given image on a dc at the specified position.
183 // If 'solidBackground' is TRUE, Draw sets the image list background
184 // colour to the background colour of the wxDC, to speed up
185 // drawing by eliminating masked drawing where possible.
186 bool wxImageList::Draw(int index
, wxDC
& dc
, int x
, int y
,
187 int flags
, bool solidBackground
)
190 wxFAIL_MSG("ImageList_Replace not implemented in TWIN32");
193 HDC hDC
= (HDC
) dc
.GetHDC();
197 if ( solidBackground
)
199 wxBrush
*brush
= & dc
.GetBackground();
200 if ( brush
&& brush
->Ok())
202 wxColour
col(brush
->GetColour());
203 ImageList_SetBkColor((HIMAGELIST
) GetHIMAGELIST(),
204 PALETTERGB(col
.Red(), col
.Green(), col
.Blue()));
207 ImageList_SetBkColor((HIMAGELIST
) GetHIMAGELIST(),
211 ImageList_SetBkColor((HIMAGELIST
) GetHIMAGELIST(),
215 if ( flags
& wxIMAGELIST_DRAW_NORMAL
)
217 if ( flags
& wxIMAGELIST_DRAW_TRANSPARENT
)
218 style
|= ILD_TRANSPARENT
;
219 if ( flags
& wxIMAGELIST_DRAW_SELECTED
)
220 style
|= ILD_SELECTED
;
221 if ( flags
& wxIMAGELIST_DRAW_FOCUSED
)
224 return (ImageList_Draw((HIMAGELIST
) GetHIMAGELIST(), index
, hDC
,