1 /////////////////////////////////////////////////////////////////////////////
2 // Name: generic/imaglist.cpp
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
11 #pragma implementation "imaglist.h"
14 // For compilers that support precompilation, includes "wx.h".
15 #include "wx/wxprec.h"
25 #include "wx/imaglist.h"
31 //-----------------------------------------------------------------------------
33 //-----------------------------------------------------------------------------
35 IMPLEMENT_DYNAMIC_CLASS(wxImageList
, wxObject
)
37 wxImageList::wxImageList( int width
, int height
, bool mask
, int initialCount
)
39 (void)Create(width
, height
, mask
, initialCount
);
42 wxImageList::~wxImageList()
47 int wxImageList::GetImageCount() const
49 return m_images
.GetCount();
52 bool wxImageList::Create( int width
, int height
, bool WXUNUSED(mask
), int WXUNUSED(initialCount
) )
60 bool wxImageList::Create()
65 int wxImageList::Add( const wxIcon
&bitmap
)
67 wxASSERT_MSG( (bitmap
.GetWidth() == m_width
&& bitmap
.GetHeight() == m_height
)
68 || (m_width
== 0 && m_height
== 0),
69 _T("invalid bitmap size in wxImageList: this might work ")
70 _T("on this platform but definitely won't under Windows.") );
72 m_images
.Append( new wxIcon( bitmap
) );
74 if (m_width
== 0 && m_height
== 0)
76 m_width
= bitmap
.GetWidth();
77 m_height
= bitmap
.GetHeight();
80 return m_images
.GetCount()-1;
83 int wxImageList::Add( const wxBitmap
&bitmap
)
85 wxASSERT_MSG( (bitmap
.GetWidth() == m_width
&& bitmap
.GetHeight() == m_height
)
86 || (m_width
== 0 && m_height
== 0),
87 _T("invalid bitmap size in wxImageList: this might work ")
88 _T("on this platform but definitely won't under Windows.") );
90 m_images
.Append( new wxBitmap(bitmap
) );
92 if (m_width
== 0 && m_height
== 0)
94 m_width
= bitmap
.GetWidth();
95 m_height
= bitmap
.GetHeight();
98 return m_images
.GetCount()-1;
101 int wxImageList::Add( const wxBitmap
& bitmap
, const wxBitmap
& mask
)
103 wxBitmap
bmp(bitmap
);
105 bmp
.SetMask(new wxMask(mask
));
109 int wxImageList::Add( const wxBitmap
& bitmap
, const wxColour
& maskColour
)
111 wxImage img
= bitmap
.ConvertToImage();
112 img
.SetMaskColour(maskColour
.Red(), maskColour
.Green(), maskColour
.Blue());
113 return Add(wxBitmap(img
));
117 wxBitmap
wxImageList::GetBitmap(int index
) const
119 wxList::compatibility_iterator node
= m_images
.Item( index
);
121 wxCHECK_MSG( node
, wxNullBitmap
, wxT("wrong index in image list") );
123 wxObject
* obj
= (wxObject
*) node
->GetData();
125 return wxNullBitmap
;
126 else if ( obj
->IsKindOf(CLASSINFO(wxIcon
)) )
127 return wxBitmap( *(wx_static_cast(wxIcon
*,obj
)) ) ;
129 return *(wx_static_cast(wxBitmap
*,obj
)) ;
133 wxIcon
wxImageList::GetIcon(int index
) const
135 wxList::compatibility_iterator node
= m_images
.Item( index
);
137 wxCHECK_MSG( node
, wxNullIcon
, wxT("wrong index in image list") );
139 wxObject
* obj
= (wxObject
*) node
->GetData();
142 else if( obj
->IsKindOf(CLASSINFO(wxBitmap
)) )
144 wxFAIL_MSG( wxT("cannot convert from bitmap to icon") ) ;
148 return *(wx_static_cast(wxIcon
*,obj
)) ;
151 bool wxImageList::Replace( int index
, const wxBitmap
&bitmap
)
153 wxList::compatibility_iterator node
= m_images
.Item( index
);
155 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
157 wxBitmap
* newBitmap
= new wxBitmap(bitmap
) ;
159 if (index
== (int) m_images
.GetCount() - 1)
161 delete node
->GetData();
162 m_images
.Erase( node
);
163 m_images
.Append( newBitmap
);
167 wxList::compatibility_iterator next
= node
->GetNext();
168 delete node
->GetData();
169 m_images
.Erase( node
);
170 m_images
.Insert( next
, newBitmap
);
176 bool wxImageList::Replace( int index
, const wxIcon
&bitmap
)
178 wxList::compatibility_iterator node
= m_images
.Item( index
);
180 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
182 wxIcon
* newBitmap
= new wxIcon(bitmap
) ;
184 if (index
== (int) m_images
.GetCount() - 1)
186 delete node
->GetData();
187 m_images
.Erase( node
);
188 m_images
.Append( newBitmap
);
192 wxList::compatibility_iterator next
= node
->GetNext();
193 delete node
->GetData();
194 m_images
.Erase( node
);
195 m_images
.Insert( next
, newBitmap
);
201 bool wxImageList::Remove( int index
)
203 wxList::compatibility_iterator node
= m_images
.Item( index
);
205 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
207 delete node
->GetData();
208 m_images
.Erase( node
);
213 bool wxImageList::RemoveAll()
215 WX_CLEAR_LIST(wxList
, m_images
);
221 bool wxImageList::GetSize( int index
, int &width
, int &height
) const
226 wxList::compatibility_iterator node
= m_images
.Item( index
);
228 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
230 wxObject
*obj
= (wxObject
*)node
->GetData();
231 if( obj
->IsKindOf(CLASSINFO(wxIcon
)))
233 wxIcon
*bm
= wx_static_cast( wxIcon
* , obj
) ;
234 width
= bm
->GetWidth();
235 height
= bm
->GetHeight();
239 wxBitmap
*bm
= wx_static_cast( wxBitmap
* , obj
) ;
240 width
= bm
->GetWidth();
241 height
= bm
->GetHeight();
246 bool wxImageList::Draw( int index
, wxDC
&dc
, int x
, int y
,
247 int flags
, bool WXUNUSED(solidBackground
) )
249 wxList::compatibility_iterator node
= m_images
.Item( index
);
251 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
253 wxObject
*obj
= (wxObject
*)node
->GetData();
254 if( obj
->IsKindOf(CLASSINFO(wxIcon
)))
256 wxIcon
*bm
= wx_static_cast( wxIcon
* , obj
) ;
257 dc
.DrawIcon( *bm
, x
, y
);
261 wxBitmap
*bm
= wx_static_cast( wxBitmap
* , obj
) ;
262 dc
.DrawBitmap( *bm
, x
, y
, (flags
& wxIMAGELIST_DRAW_TRANSPARENT
) > 0 );
268 #endif // wxUSE_IMAGLIST