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"
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
)
107 HBITMAP hBitmap1
= (HBITMAP
) bitmap
.GetHBITMAP();
108 COLORREF colorRef
= PALETTERGB(maskColour
.Red(), maskColour
.Green(), maskColour
.Blue());
109 return ImageList_AddMasked((HIMAGELIST
) GetHIMAGELIST(), hBitmap1
, colorRef
);
112 // Adds a bitmap and mask from an icon.
113 int wxImageList
::Add(const wxIcon
& icon
)
115 HICON hIcon
= (HICON
) icon
.GetHICON();
116 return ImageList_AddIcon((HIMAGELIST
) GetHIMAGELIST(), hIcon
);
119 // Replaces a bitmap, optionally passing a mask bitmap.
120 // Note that wxImageList creates new bitmaps, so you may delete
121 // 'bitmap' and 'mask'.
122 bool wxImageList
::Replace(int index
, const wxBitmap
& bitmap
, const wxBitmap
& mask
)
124 HBITMAP hBitmap1
= (HBITMAP
) bitmap
.GetHBITMAP();
125 HBITMAP hBitmap2
= 0;
127 hBitmap2
= (HBITMAP
) mask
.GetHBITMAP();
128 return (ImageList_Replace((HIMAGELIST
) GetHIMAGELIST(), index
, hBitmap1
, hBitmap2
) != 0);
131 /* Not supported by Win95
132 // Replacing a bitmap, using the specified colour to create the mask bitmap
133 // Note that wxImageList creates new bitmaps, so you may delete
135 bool wxImageList::Replace(int index, const wxBitmap& bitmap, const wxColour& maskColour)
137 HBITMAP hBitmap1 = (HBITMAP) bitmap.GetHBITMAP();
138 COLORREF colorRef = PALETTERGB(maskColour.Red(), maskColour.Green(), maskColour.Blue());
139 return (bool) ImageList_ReplaceMasked((HIMAGELIST) GetHIMAGELIST(), index, hBitmap1, colorRef);
143 // Replaces a bitmap and mask from an icon.
144 bool wxImageList
::Replace(int index
, const wxIcon
& icon
)
146 HICON hIcon
= (HICON
) icon
.GetHICON();
147 return (ImageList_ReplaceIcon((HIMAGELIST
) GetHIMAGELIST(), index
, hIcon
) != 0);
150 // Removes the image at the given index.
151 bool wxImageList
::Remove(int index
)
153 return (ImageList_Remove((HIMAGELIST
) GetHIMAGELIST(), index
) != 0);
157 bool wxImageList
::RemoveAll(void)
159 // TODO: Is this correct?
160 while ( GetImageCount() > 0 )
167 // Draws the given image on a dc at the specified position.
168 // If 'solidBackground' is TRUE, Draw sets the image list background
169 // colour to the background colour of the wxDC, to speed up
170 // drawing by eliminating masked drawing where possible.
171 bool wxImageList
::Draw(int index
, wxDC
& dc
, int x
, int y
,
172 int flags
, bool solidBackground
)
174 HDC hDC
= (HDC
) dc
.GetHDC();
178 if ( solidBackground
)
180 wxBrush
*brush
= & dc
.GetBackground();
181 if ( brush
&& brush
->Ok())
183 wxColour
col(brush
->GetColour());
184 ImageList_SetBkColor((HIMAGELIST
) GetHIMAGELIST(),
185 PALETTERGB(col
.Red(), col
.Green(), col
.Blue()));
188 ImageList_SetBkColor((HIMAGELIST
) GetHIMAGELIST(),
192 ImageList_SetBkColor((HIMAGELIST
) GetHIMAGELIST(),
196 if ( flags
& wxIMAGELIST_DRAW_NORMAL
)
198 if ( flags
& wxIMAGELIST_DRAW_TRANSPARENT
)
199 style
|= ILD_TRANSPARENT
;
200 if ( flags
& wxIMAGELIST_DRAW_SELECTED
)
201 style
|= ILD_SELECTED
;
202 if ( flags
& wxIMAGELIST_DRAW_FOCUSED
)
205 return (ImageList_Draw((HIMAGELIST
) GetHIMAGELIST(), index
, hDC
,