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();
89 return ImageList_Add((HIMAGELIST
) GetHIMAGELIST(), hBitmap1
, hBitmap2
);
92 // Adds a bitmap, using the specified colour to create the mask bitmap
93 // Note that wxImageList creates new bitmaps, so you may delete
95 int wxImageList::Add(const wxBitmap
& bitmap
, const wxColour
& maskColour
)
97 HBITMAP hBitmap1
= (HBITMAP
) bitmap
.GetHBITMAP();
98 COLORREF colorRef
= PALETTERGB(maskColour
.Red(), maskColour
.Green(), maskColour
.Blue());
99 return ImageList_AddMasked((HIMAGELIST
) GetHIMAGELIST(), hBitmap1
, colorRef
);
102 // Adds a bitmap and mask from an icon.
103 int wxImageList::Add(const wxIcon
& icon
)
105 HICON hIcon
= (HICON
) icon
.GetHICON();
106 return ImageList_AddIcon((HIMAGELIST
) GetHIMAGELIST(), hIcon
);
109 // Replaces a bitmap, optionally passing a mask bitmap.
110 // Note that wxImageList creates new bitmaps, so you may delete
111 // 'bitmap' and 'mask'.
112 bool wxImageList::Replace(int index
, const wxBitmap
& bitmap
, const wxBitmap
& mask
)
114 HBITMAP hBitmap1
= (HBITMAP
) bitmap
.GetHBITMAP();
115 HBITMAP hBitmap2
= 0;
117 hBitmap2
= (HBITMAP
) mask
.GetHBITMAP();
118 return (ImageList_Replace((HIMAGELIST
) GetHIMAGELIST(), index
, hBitmap1
, hBitmap2
) != 0);
121 /* Not supported by Win95
122 // Replacing a bitmap, using the specified colour to create the mask bitmap
123 // Note that wxImageList creates new bitmaps, so you may delete
125 bool wxImageList::Replace(int index, const wxBitmap& bitmap, const wxColour& maskColour)
127 HBITMAP hBitmap1 = (HBITMAP) bitmap.GetHBITMAP();
128 COLORREF colorRef = PALETTERGB(maskColour.Red(), maskColour.Green(), maskColour.Blue());
129 return (bool) ImageList_ReplaceMasked((HIMAGELIST) GetHIMAGELIST(), index, hBitmap1, colorRef);
133 // Replaces a bitmap and mask from an icon.
134 bool wxImageList::Replace(int index
, const wxIcon
& icon
)
136 HICON hIcon
= (HICON
) icon
.GetHICON();
137 return (ImageList_ReplaceIcon((HIMAGELIST
) GetHIMAGELIST(), index
, hIcon
) != 0);
140 // Removes the image at the given index.
141 bool wxImageList::Remove(int index
)
143 return (ImageList_Remove((HIMAGELIST
) GetHIMAGELIST(), index
) != 0);
147 bool wxImageList::RemoveAll(void)
149 // TODO: Is this correct?
150 while ( GetImageCount() > 0 )
157 // Draws the given image on a dc at the specified position.
158 // If 'solidBackground' is TRUE, Draw sets the image list background
159 // colour to the background colour of the wxDC, to speed up
160 // drawing by eliminating masked drawing where possible.
161 bool wxImageList::Draw(int index
, wxDC
& dc
, int x
, int y
,
162 int flags
, bool solidBackground
)
164 HDC hDC
= (HDC
) dc
.GetHDC();
168 if ( solidBackground
)
170 wxBrush
*brush
= & dc
.GetBackground();
171 if ( brush
&& brush
->Ok())
173 wxColour
col(brush
->GetColour());
174 ImageList_SetBkColor((HIMAGELIST
) GetHIMAGELIST(),
175 PALETTERGB(col
.Red(), col
.Green(), col
.Blue()));
178 ImageList_SetBkColor((HIMAGELIST
) GetHIMAGELIST(),
182 ImageList_SetBkColor((HIMAGELIST
) GetHIMAGELIST(),
186 if ( flags
& wxIMAGELIST_DRAW_NORMAL
)
188 if ( flags
& wxIMAGELIST_DRAW_TRANSPARENT
)
189 style
|= ILD_TRANSPARENT
;
190 if ( flags
& wxIMAGELIST_DRAW_SELECTED
)
191 style
|= ILD_SELECTED
;
192 if ( flags
& wxIMAGELIST_DRAW_FOCUSED
)
195 return (ImageList_Draw((HIMAGELIST
) GetHIMAGELIST(), index
, hDC
,