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();
95 int index
= ImageList_Add((HIMAGELIST
) GetHIMAGELIST(), hBitmap1
, hBitmap2
);
98 wxLogError(_("Couldn't add an image to the image list."));
104 // Adds a bitmap, using the specified colour to create the mask bitmap
105 // Note that wxImageList creates new bitmaps, so you may delete
107 int wxImageList::Add(const wxBitmap
& bitmap
, const wxColour
& maskColour
)
110 wxFAIL_MSG("ImageList_AddMasked not implemented in TWIN32");
113 HBITMAP hBitmap1
= (HBITMAP
) bitmap
.GetHBITMAP();
114 COLORREF colorRef
= PALETTERGB(maskColour
.Red(), maskColour
.Green(), maskColour
.Blue());
115 return ImageList_AddMasked((HIMAGELIST
) GetHIMAGELIST(), hBitmap1
, colorRef
);
119 // Adds a bitmap and mask from an icon.
120 int wxImageList::Add(const wxIcon
& icon
)
122 HICON hIcon
= (HICON
) icon
.GetHICON();
123 return ImageList_AddIcon((HIMAGELIST
) GetHIMAGELIST(), hIcon
);
126 // Replaces a bitmap, optionally passing a mask bitmap.
127 // Note that wxImageList creates new bitmaps, so you may delete
128 // 'bitmap' and 'mask'.
129 bool wxImageList::Replace(int index
, const wxBitmap
& bitmap
, const wxBitmap
& mask
)
132 wxFAIL_MSG("ImageList_Replace not implemented in TWIN32");
135 HBITMAP hBitmap1
= (HBITMAP
) bitmap
.GetHBITMAP();
136 HBITMAP hBitmap2
= 0;
138 hBitmap2
= (HBITMAP
) mask
.GetHBITMAP();
139 return (ImageList_Replace((HIMAGELIST
) GetHIMAGELIST(), index
, hBitmap1
, hBitmap2
) != 0);
143 /* Not supported by Win95
144 // Replacing a bitmap, using the specified colour to create the mask bitmap
145 // Note that wxImageList creates new bitmaps, so you may delete
147 bool wxImageList::Replace(int index, const wxBitmap& bitmap, const wxColour& maskColour)
149 HBITMAP hBitmap1 = (HBITMAP) bitmap.GetHBITMAP();
150 COLORREF colorRef = PALETTERGB(maskColour.Red(), maskColour.Green(), maskColour.Blue());
151 return (bool) ImageList_ReplaceMasked((HIMAGELIST) GetHIMAGELIST(), index, hBitmap1, colorRef);
155 // Replaces a bitmap and mask from an icon.
156 bool wxImageList::Replace(int index
, const wxIcon
& icon
)
158 HICON hIcon
= (HICON
) icon
.GetHICON();
159 return (ImageList_ReplaceIcon((HIMAGELIST
) GetHIMAGELIST(), index
, hIcon
) != 0);
162 // Removes the image at the given index.
163 bool wxImageList::Remove(int index
)
166 wxFAIL_MSG("ImageList_Replace not implemented in TWIN32");
169 return (ImageList_Remove((HIMAGELIST
) GetHIMAGELIST(), index
) != 0);
174 bool wxImageList::RemoveAll(void)
176 // TODO: Is this correct?
177 while ( GetImageCount() > 0 )
184 // Draws the given image on a dc at the specified position.
185 // If 'solidBackground' is TRUE, Draw sets the image list background
186 // colour to the background colour of the wxDC, to speed up
187 // drawing by eliminating masked drawing where possible.
188 bool wxImageList::Draw(int index
, wxDC
& dc
, int x
, int y
,
189 int flags
, bool solidBackground
)
192 wxFAIL_MSG("ImageList_Replace not implemented in TWIN32");
195 HDC hDC
= (HDC
) dc
.GetHDC();
199 if ( solidBackground
)
201 wxBrush
*brush
= & dc
.GetBackground();
202 if ( brush
&& brush
->Ok())
204 wxColour
col(brush
->GetColour());
205 ImageList_SetBkColor((HIMAGELIST
) GetHIMAGELIST(),
206 PALETTERGB(col
.Red(), col
.Green(), col
.Blue()));
209 ImageList_SetBkColor((HIMAGELIST
) GetHIMAGELIST(),
213 ImageList_SetBkColor((HIMAGELIST
) GetHIMAGELIST(),
217 if ( flags
& wxIMAGELIST_DRAW_NORMAL
)
219 if ( flags
& wxIMAGELIST_DRAW_TRANSPARENT
)
220 style
|= ILD_TRANSPARENT
;
221 if ( flags
& wxIMAGELIST_DRAW_SELECTED
)
222 style
|= ILD_SELECTED
;
223 if ( flags
& wxIMAGELIST_DRAW_FOCUSED
)
226 return (ImageList_Draw((HIMAGELIST
) GetHIMAGELIST(), index
, hDC
,