1 /////////////////////////////////////////////////////////////////////////////
2 // Name: generic/imaglist.cpp
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
21 #include "wx/imaglist.h"
27 //-----------------------------------------------------------------------------
29 //-----------------------------------------------------------------------------
31 IMPLEMENT_DYNAMIC_CLASS(wxImageList
, wxObject
)
33 wxImageList::wxImageList( int width
, int height
, bool mask
, int initialCount
)
35 (void)Create(width
, height
, mask
, initialCount
);
38 wxImageList::~wxImageList()
43 int wxImageList::GetImageCount() const
45 return m_images
.GetCount();
48 bool wxImageList::Create( int width
, int height
, bool WXUNUSED(mask
), int WXUNUSED(initialCount
) )
56 bool wxImageList::Create()
61 int wxImageList::Add( const wxIcon
&bitmap
)
63 wxASSERT_MSG( (bitmap
.GetWidth() == m_width
&& bitmap
.GetHeight() == m_height
)
64 || (m_width
== 0 && m_height
== 0),
65 _T("invalid bitmap size in wxImageList: this might work ")
66 _T("on this platform but definitely won't under Windows.") );
68 m_images
.Append( new wxIcon( bitmap
) );
70 if (m_width
== 0 && m_height
== 0)
72 m_width
= bitmap
.GetWidth();
73 m_height
= bitmap
.GetHeight();
76 return m_images
.GetCount()-1;
79 int wxImageList::Add( const wxBitmap
&bitmap
)
81 wxASSERT_MSG( (bitmap
.GetWidth() == m_width
&& bitmap
.GetHeight() == m_height
)
82 || (m_width
== 0 && m_height
== 0),
83 _T("invalid bitmap size in wxImageList: this might work ")
84 _T("on this platform but definitely won't under Windows.") );
86 m_images
.Append( new wxBitmap(bitmap
) );
88 if (m_width
== 0 && m_height
== 0)
90 m_width
= bitmap
.GetWidth();
91 m_height
= bitmap
.GetHeight();
94 return m_images
.GetCount()-1;
97 int wxImageList::Add( const wxBitmap
& bitmap
, const wxBitmap
& mask
)
101 bmp
.SetMask(new wxMask(mask
));
105 int wxImageList::Add( const wxBitmap
& bitmap
, const wxColour
& maskColour
)
107 wxImage img
= bitmap
.ConvertToImage();
108 img
.SetMaskColour(maskColour
.Red(), maskColour
.Green(), maskColour
.Blue());
109 return Add(wxBitmap(img
));
113 wxBitmap
wxImageList::GetBitmap(int index
) const
115 wxList::compatibility_iterator node
= m_images
.Item( index
);
117 wxCHECK_MSG( node
, wxNullBitmap
, wxT("wrong index in image list") );
119 wxObject
* obj
= (wxObject
*) node
->GetData();
121 return wxNullBitmap
;
122 else if ( obj
->IsKindOf(CLASSINFO(wxIcon
)) )
123 return wxBitmap( *(wx_static_cast(wxIcon
*,obj
)) ) ;
125 return *(wx_static_cast(wxBitmap
*,obj
)) ;
129 wxIcon
wxImageList::GetIcon(int index
) const
131 wxList::compatibility_iterator node
= m_images
.Item( index
);
133 wxCHECK_MSG( node
, wxNullIcon
, wxT("wrong index in image list") );
135 wxObject
* obj
= (wxObject
*) node
->GetData();
138 else if( obj
->IsKindOf(CLASSINFO(wxBitmap
)) )
140 wxFAIL_MSG( wxT("cannot convert from bitmap to icon") ) ;
144 return *(wx_static_cast(wxIcon
*,obj
)) ;
147 bool wxImageList::Replace( int index
, const wxBitmap
&bitmap
)
149 wxList::compatibility_iterator node
= m_images
.Item( index
);
151 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
153 wxBitmap
* newBitmap
= new wxBitmap(bitmap
) ;
155 if (index
== (int) m_images
.GetCount() - 1)
157 delete node
->GetData();
158 m_images
.Erase( node
);
159 m_images
.Append( newBitmap
);
163 wxList::compatibility_iterator next
= node
->GetNext();
164 delete node
->GetData();
165 m_images
.Erase( node
);
166 m_images
.Insert( next
, newBitmap
);
172 bool wxImageList::Replace( int index
, const wxIcon
&bitmap
)
174 wxList::compatibility_iterator node
= m_images
.Item( index
);
176 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
178 wxIcon
* newBitmap
= new wxIcon(bitmap
) ;
180 if (index
== (int) m_images
.GetCount() - 1)
182 delete node
->GetData();
183 m_images
.Erase( node
);
184 m_images
.Append( newBitmap
);
188 wxList::compatibility_iterator next
= node
->GetNext();
189 delete node
->GetData();
190 m_images
.Erase( node
);
191 m_images
.Insert( next
, newBitmap
);
197 bool wxImageList::Remove( int index
)
199 wxList::compatibility_iterator node
= m_images
.Item( index
);
201 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
203 delete node
->GetData();
204 m_images
.Erase( node
);
209 bool wxImageList::RemoveAll()
211 WX_CLEAR_LIST(wxList
, m_images
);
217 bool wxImageList::GetSize( int index
, int &width
, int &height
) const
222 wxList::compatibility_iterator node
= m_images
.Item( index
);
224 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
226 wxObject
*obj
= (wxObject
*)node
->GetData();
227 if( obj
->IsKindOf(CLASSINFO(wxIcon
)))
229 wxIcon
*bm
= wx_static_cast( wxIcon
* , obj
) ;
230 width
= bm
->GetWidth();
231 height
= bm
->GetHeight();
235 wxBitmap
*bm
= wx_static_cast( wxBitmap
* , obj
) ;
236 width
= bm
->GetWidth();
237 height
= bm
->GetHeight();
242 bool wxImageList::Draw( int index
, wxDC
&dc
, int x
, int y
,
243 int flags
, bool WXUNUSED(solidBackground
) )
245 wxList::compatibility_iterator node
= m_images
.Item( index
);
247 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
249 wxObject
*obj
= (wxObject
*)node
->GetData();
250 if( obj
->IsKindOf(CLASSINFO(wxIcon
)))
252 wxIcon
*bm
= wx_static_cast( wxIcon
* , obj
) ;
253 dc
.DrawIcon( *bm
, x
, y
);
257 wxBitmap
*bm
= wx_static_cast( wxBitmap
* , obj
) ;
258 dc
.DrawBitmap( *bm
, x
, y
, (flags
& wxIMAGELIST_DRAW_TRANSPARENT
) > 0 );
264 #endif // wxUSE_IMAGLIST