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"
32 #include "wx/msw/imaglist.h"
33 #include "wx/msw/private.h"
39 #if !USE_SHARED_LIBRARY
40 IMPLEMENT_DYNAMIC_CLASS(wxImageList
, wxObject
)
43 wxImageList::wxImageList(void)
48 wxImageList::~wxImageList(void)
51 ImageList_Destroy((HIMAGELIST
) m_hImageList
);
57 ////////////////////////////////////////////////////////////////////////////
59 // Returns the number of images in the image list.
60 int wxImageList::GetImageCount(void) const
62 return ImageList_GetImageCount((HIMAGELIST
) m_hImageList
);
66 ////////////////////////////////////////////////////////////////////////////
68 // Creates an image list
69 bool wxImageList::Create(int width
, int height
, bool mask
, int initial
)
75 // Grow by 1, I guess this is reasonable behaviour most of the time
76 m_hImageList
= (WXHIMAGELIST
) ImageList_Create(width
, height
, flags
, initial
, 1);
77 return (m_hImageList
!= 0);
80 // Adds a bitmap, and optionally a mask bitmap.
81 // Note that wxImageList creates new bitmaps, so you may delete
82 // 'bitmap' and 'mask'.
83 int wxImageList::Add(const wxBitmap
& bitmap
, const wxBitmap
& mask
)
85 HBITMAP hBitmap1
= (HBITMAP
) bitmap
.GetHBITMAP();
88 hBitmap2
= (HBITMAP
) mask
.GetHBITMAP();
90 int index
= ImageList_Add((HIMAGELIST
) GetHIMAGELIST(), hBitmap1
, hBitmap2
);
93 wxLogError(_("Couldn't add an image to the image list."));
99 // Adds a bitmap, using the specified colour to create the mask bitmap
100 // Note that wxImageList creates new bitmaps, so you may delete
102 int wxImageList::Add(const wxBitmap
& bitmap
, const wxColour
& maskColour
)
104 HBITMAP hBitmap1
= (HBITMAP
) bitmap
.GetHBITMAP();
105 COLORREF colorRef
= PALETTERGB(maskColour
.Red(), maskColour
.Green(), maskColour
.Blue());
106 return ImageList_AddMasked((HIMAGELIST
) GetHIMAGELIST(), hBitmap1
, colorRef
);
109 // Adds a bitmap and mask from an icon.
110 int wxImageList::Add(const wxIcon
& icon
)
112 HICON hIcon
= (HICON
) icon
.GetHICON();
113 return ImageList_AddIcon((HIMAGELIST
) GetHIMAGELIST(), hIcon
);
116 // Replaces a bitmap, optionally passing a mask bitmap.
117 // Note that wxImageList creates new bitmaps, so you may delete
118 // 'bitmap' and 'mask'.
119 bool wxImageList::Replace(int index
, const wxBitmap
& bitmap
, const wxBitmap
& mask
)
121 HBITMAP hBitmap1
= (HBITMAP
) bitmap
.GetHBITMAP();
122 HBITMAP hBitmap2
= 0;
124 hBitmap2
= (HBITMAP
) mask
.GetHBITMAP();
125 return (ImageList_Replace((HIMAGELIST
) GetHIMAGELIST(), index
, hBitmap1
, hBitmap2
) != 0);
128 /* Not supported by Win95
129 // Replacing a bitmap, using the specified colour to create the mask bitmap
130 // Note that wxImageList creates new bitmaps, so you may delete
132 bool wxImageList::Replace(int index, const wxBitmap& bitmap, const wxColour& maskColour)
134 HBITMAP hBitmap1 = (HBITMAP) bitmap.GetHBITMAP();
135 COLORREF colorRef = PALETTERGB(maskColour.Red(), maskColour.Green(), maskColour.Blue());
136 return (bool) ImageList_ReplaceMasked((HIMAGELIST) GetHIMAGELIST(), index, hBitmap1, colorRef);
140 // Replaces a bitmap and mask from an icon.
141 bool wxImageList::Replace(int index
, const wxIcon
& icon
)
143 HICON hIcon
= (HICON
) icon
.GetHICON();
144 return (ImageList_ReplaceIcon((HIMAGELIST
) GetHIMAGELIST(), index
, hIcon
) != 0);
147 // Removes the image at the given index.
148 bool wxImageList::Remove(int index
)
150 return (ImageList_Remove((HIMAGELIST
) GetHIMAGELIST(), index
) != 0);
154 bool wxImageList::RemoveAll(void)
156 // TODO: Is this correct?
157 while ( GetImageCount() > 0 )
164 // Draws the given image on a dc at the specified position.
165 // If 'solidBackground' is TRUE, Draw sets the image list background
166 // colour to the background colour of the wxDC, to speed up
167 // drawing by eliminating masked drawing where possible.
168 bool wxImageList::Draw(int index
, wxDC
& dc
, int x
, int y
,
169 int flags
, bool solidBackground
)
171 HDC hDC
= (HDC
) dc
.GetHDC();
175 if ( solidBackground
)
177 wxBrush
*brush
= & dc
.GetBackground();
178 if ( brush
&& brush
->Ok())
180 wxColour
col(brush
->GetColour());
181 ImageList_SetBkColor((HIMAGELIST
) GetHIMAGELIST(),
182 PALETTERGB(col
.Red(), col
.Green(), col
.Blue()));
185 ImageList_SetBkColor((HIMAGELIST
) GetHIMAGELIST(),
189 ImageList_SetBkColor((HIMAGELIST
) GetHIMAGELIST(),
193 if ( flags
& wxIMAGELIST_DRAW_NORMAL
)
195 if ( flags
& wxIMAGELIST_DRAW_TRANSPARENT
)
196 style
|= ILD_TRANSPARENT
;
197 if ( flags
& wxIMAGELIST_DRAW_SELECTED
)
198 style
|= ILD_SELECTED
;
199 if ( flags
& wxIMAGELIST_DRAW_FOCUSED
)
202 return (ImageList_Draw((HIMAGELIST
) GetHIMAGELIST(), index
, hDC
,