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"
31 #include "wx/string.h"
37 #include "wx/msw/imaglist.h"
38 #include "wx/msw/private.h"
40 #if (defined(__WIN95__) && !defined(__GNUWIN32__)) || defined(__TWIN32__) || defined(wxUSE_NORLANDER_HEADERS)
44 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();
92 else if (bitmap
.GetMask())
93 hBitmap2
= (HBITMAP
) bitmap
.GetMask()->GetMaskBitmap();
97 // Microsoft imagelist masks are inverted from wxWindows mask standard (white is mask color)
99 ::GetObject(hBitmap2
,sizeof(BITMAP
),(LPVOID
)&bm
);
102 HDC hdc
= ::CreateCompatibleDC(NULL
);
103 HDC hdci
= ::CreateCompatibleDC(NULL
);
104 hBitmapI
= ::CreateCompatibleBitmap(hdci
, w
, h
);
105 ::SelectObject(hdc
, hBitmap2
);
106 ::SelectObject(hdci
, hBitmapI
);
107 ::BitBlt(hdci
, 0, 0, w
, h
, hdc
, 0, 0, NOTSRCCOPY
);
112 int index
= ImageList_Add((HIMAGELIST
) GetHIMAGELIST(), hBitmap1
, hBitmapI
);
115 wxLogError(_("Couldn't add an image to the image list."));
118 // Clean up inverted mask
120 ::DeleteObject(hBitmapI
);
125 // Adds a bitmap, using the specified colour to create the mask bitmap
126 // Note that wxImageList creates new bitmaps, so you may delete
128 int wxImageList::Add(const wxBitmap
& bitmap
, const wxColour
& maskColour
)
131 wxFAIL_MSG("ImageList_AddMasked not implemented in TWIN32");
134 HBITMAP hBitmap1
= (HBITMAP
) bitmap
.GetHBITMAP();
135 COLORREF colorRef
= PALETTERGB(maskColour
.Red(), maskColour
.Green(), maskColour
.Blue());
136 return ImageList_AddMasked((HIMAGELIST
) GetHIMAGELIST(), hBitmap1
, colorRef
);
140 // Adds a bitmap and mask from an icon.
141 int wxImageList::Add(const wxIcon
& icon
)
143 HICON hIcon
= (HICON
) icon
.GetHICON();
144 return ImageList_AddIcon((HIMAGELIST
) GetHIMAGELIST(), hIcon
);
147 // Replaces a bitmap, optionally passing a mask bitmap.
148 // Note that wxImageList creates new bitmaps, so you may delete
149 // 'bitmap' and 'mask'.
150 bool wxImageList::Replace(int index
, const wxBitmap
& bitmap
, const wxBitmap
& mask
)
153 wxFAIL_MSG("ImageList_Replace not implemented in TWIN32");
156 HBITMAP hBitmap1
= (HBITMAP
) bitmap
.GetHBITMAP();
157 HBITMAP hBitmap2
= 0;
159 hBitmap2
= (HBITMAP
) mask
.GetHBITMAP();
160 return (ImageList_Replace((HIMAGELIST
) GetHIMAGELIST(), index
, hBitmap1
, hBitmap2
) != 0);
164 /* Not supported by Win95
165 // Replacing a bitmap, using the specified colour to create the mask bitmap
166 // Note that wxImageList creates new bitmaps, so you may delete
168 bool wxImageList::Replace(int index, const wxBitmap& bitmap, const wxColour& maskColour)
170 HBITMAP hBitmap1 = (HBITMAP) bitmap.GetHBITMAP();
171 COLORREF colorRef = PALETTERGB(maskColour.Red(), maskColour.Green(), maskColour.Blue());
172 return (bool) ImageList_ReplaceMasked((HIMAGELIST) GetHIMAGELIST(), index, hBitmap1, colorRef);
176 // Replaces a bitmap and mask from an icon.
177 bool wxImageList::Replace(int index
, const wxIcon
& icon
)
179 HICON hIcon
= (HICON
) icon
.GetHICON();
180 return (ImageList_ReplaceIcon((HIMAGELIST
) GetHIMAGELIST(), index
, hIcon
) != 0);
183 // Removes the image at the given index.
184 bool wxImageList::Remove(int index
)
187 wxFAIL_MSG("ImageList_Replace not implemented in TWIN32");
190 return (ImageList_Remove((HIMAGELIST
) GetHIMAGELIST(), index
) != 0);
195 bool wxImageList::RemoveAll(void)
197 // TODO: Is this correct?
198 while ( GetImageCount() > 0 )
205 // Draws the given image on a dc at the specified position.
206 // If 'solidBackground' is TRUE, Draw sets the image list background
207 // colour to the background colour of the wxDC, to speed up
208 // drawing by eliminating masked drawing where possible.
209 bool wxImageList::Draw(int index
, wxDC
& dc
, int x
, int y
,
210 int flags
, bool solidBackground
)
213 wxFAIL_MSG("ImageList_Replace not implemented in TWIN32");
216 HDC hDC
= (HDC
) dc
.GetHDC();
220 if ( solidBackground
)
222 wxBrush
*brush
= & dc
.GetBackground();
223 if ( brush
&& brush
->Ok())
225 wxColour
col(brush
->GetColour());
226 ImageList_SetBkColor((HIMAGELIST
) GetHIMAGELIST(),
227 PALETTERGB(col
.Red(), col
.Green(), col
.Blue()));
230 ImageList_SetBkColor((HIMAGELIST
) GetHIMAGELIST(),
234 ImageList_SetBkColor((HIMAGELIST
) GetHIMAGELIST(),
238 if ( flags
& wxIMAGELIST_DRAW_NORMAL
)
240 if ( flags
& wxIMAGELIST_DRAW_TRANSPARENT
)
241 style
|= ILD_TRANSPARENT
;
242 if ( flags
& wxIMAGELIST_DRAW_SELECTED
)
243 style
|= ILD_SELECTED
;
244 if ( flags
& wxIMAGELIST_DRAW_FOCUSED
)
247 return (ImageList_Draw((HIMAGELIST
) GetHIMAGELIST(), index
, hDC
,