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 #if !USE_SHARED_LIBRARY
45 IMPLEMENT_DYNAMIC_CLASS(wxImageList
, wxObject
)
48 wxImageList::wxImageList(void)
53 wxImageList::~wxImageList(void)
56 ImageList_Destroy((HIMAGELIST
) m_hImageList
);
62 ////////////////////////////////////////////////////////////////////////////
64 // Returns the number of images in the image list.
65 int wxImageList::GetImageCount(void) const
67 return ImageList_GetImageCount((HIMAGELIST
) m_hImageList
);
71 ////////////////////////////////////////////////////////////////////////////
73 // Creates an image list
74 bool wxImageList::Create(int width
, int height
, bool mask
, int initial
)
80 // Grow by 1, I guess this is reasonable behaviour most of the time
81 m_hImageList
= (WXHIMAGELIST
) ImageList_Create(width
, height
, flags
, initial
, 1);
82 return (m_hImageList
!= 0);
85 // Adds a bitmap, and optionally a mask bitmap.
86 // Note that wxImageList creates new bitmaps, so you may delete
87 // 'bitmap' and 'mask'.
88 int wxImageList::Add(const wxBitmap
& bitmap
, const wxBitmap
& mask
)
90 HBITMAP hBitmap1
= (HBITMAP
) bitmap
.GetHBITMAP();
93 hBitmap2
= (HBITMAP
) mask
.GetHBITMAP();
94 else if (bitmap
.GetMask())
95 hBitmap2
= (HBITMAP
) bitmap
.GetMask()->GetMaskBitmap();
99 // Microsoft imagelist masks are inverted from wxWindows mask standard (white is mask color)
101 ::GetObject(hBitmap2
,sizeof(BITMAP
),(LPVOID
)&bm
);
104 HDC hdc
= ::CreateCompatibleDC(NULL
);
105 HDC hdci
= ::CreateCompatibleDC(NULL
);
106 hBitmapI
= ::CreateCompatibleBitmap(hdci
, w
, h
);
107 ::SelectObject(hdc
, hBitmap2
);
108 ::SelectObject(hdci
, hBitmapI
);
109 ::BitBlt(hdci
, 0, 0, w
, h
, hdc
, 0, 0, NOTSRCCOPY
);
114 int index
= ImageList_Add((HIMAGELIST
) GetHIMAGELIST(), hBitmap1
, hBitmapI
);
117 wxLogError(_("Couldn't add an image to the image list."));
120 // Clean up inverted mask
122 ::DeleteObject(hBitmapI
);
127 // Adds a bitmap, using the specified colour to create the mask bitmap
128 // Note that wxImageList creates new bitmaps, so you may delete
130 int wxImageList::Add(const wxBitmap
& bitmap
, const wxColour
& maskColour
)
133 wxFAIL_MSG("ImageList_AddMasked not implemented in TWIN32");
136 HBITMAP hBitmap1
= (HBITMAP
) bitmap
.GetHBITMAP();
137 COLORREF colorRef
= PALETTERGB(maskColour
.Red(), maskColour
.Green(), maskColour
.Blue());
138 return ImageList_AddMasked((HIMAGELIST
) GetHIMAGELIST(), hBitmap1
, colorRef
);
142 // Adds a bitmap and mask from an icon.
143 int wxImageList::Add(const wxIcon
& icon
)
145 HICON hIcon
= (HICON
) icon
.GetHICON();
146 return ImageList_AddIcon((HIMAGELIST
) GetHIMAGELIST(), hIcon
);
149 // Replaces a bitmap, optionally passing a mask bitmap.
150 // Note that wxImageList creates new bitmaps, so you may delete
151 // 'bitmap' and 'mask'.
152 bool wxImageList::Replace(int index
, const wxBitmap
& bitmap
, const wxBitmap
& mask
)
155 wxFAIL_MSG("ImageList_Replace not implemented in TWIN32");
158 HBITMAP hBitmap1
= (HBITMAP
) bitmap
.GetHBITMAP();
159 HBITMAP hBitmap2
= 0;
161 hBitmap2
= (HBITMAP
) mask
.GetHBITMAP();
162 return (ImageList_Replace((HIMAGELIST
) GetHIMAGELIST(), index
, hBitmap1
, hBitmap2
) != 0);
166 /* Not supported by Win95
167 // Replacing a bitmap, using the specified colour to create the mask bitmap
168 // Note that wxImageList creates new bitmaps, so you may delete
170 bool wxImageList::Replace(int index, const wxBitmap& bitmap, const wxColour& maskColour)
172 HBITMAP hBitmap1 = (HBITMAP) bitmap.GetHBITMAP();
173 COLORREF colorRef = PALETTERGB(maskColour.Red(), maskColour.Green(), maskColour.Blue());
174 return (bool) ImageList_ReplaceMasked((HIMAGELIST) GetHIMAGELIST(), index, hBitmap1, colorRef);
178 // Replaces a bitmap and mask from an icon.
179 bool wxImageList::Replace(int index
, const wxIcon
& icon
)
181 HICON hIcon
= (HICON
) icon
.GetHICON();
182 return (ImageList_ReplaceIcon((HIMAGELIST
) GetHIMAGELIST(), index
, hIcon
) != 0);
185 // Removes the image at the given index.
186 bool wxImageList::Remove(int index
)
189 wxFAIL_MSG("ImageList_Replace not implemented in TWIN32");
192 return (ImageList_Remove((HIMAGELIST
) GetHIMAGELIST(), index
) != 0);
197 bool wxImageList::RemoveAll(void)
199 // TODO: Is this correct?
200 while ( GetImageCount() > 0 )
207 // Draws the given image on a dc at the specified position.
208 // If 'solidBackground' is TRUE, Draw sets the image list background
209 // colour to the background colour of the wxDC, to speed up
210 // drawing by eliminating masked drawing where possible.
211 bool wxImageList::Draw(int index
, wxDC
& dc
, int x
, int y
,
212 int flags
, bool solidBackground
)
215 wxFAIL_MSG("ImageList_Replace not implemented in TWIN32");
218 HDC hDC
= (HDC
) dc
.GetHDC();
222 if ( solidBackground
)
224 wxBrush
*brush
= & dc
.GetBackground();
225 if ( brush
&& brush
->Ok())
227 wxColour
col(brush
->GetColour());
228 ImageList_SetBkColor((HIMAGELIST
) GetHIMAGELIST(),
229 PALETTERGB(col
.Red(), col
.Green(), col
.Blue()));
232 ImageList_SetBkColor((HIMAGELIST
) GetHIMAGELIST(),
236 ImageList_SetBkColor((HIMAGELIST
) GetHIMAGELIST(),
240 if ( flags
& wxIMAGELIST_DRAW_NORMAL
)
242 if ( flags
& wxIMAGELIST_DRAW_TRANSPARENT
)
243 style
|= ILD_TRANSPARENT
;
244 if ( flags
& wxIMAGELIST_DRAW_SELECTED
)
245 style
|= ILD_SELECTED
;
246 if ( flags
& wxIMAGELIST_DRAW_FOCUSED
)
249 return (ImageList_Draw((HIMAGELIST
) GetHIMAGELIST(), index
, hDC
,