1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/imaglist.cpp
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 #include "wx/wxprec.h"
18 #include "wx/imaglist.h"
23 IMPLEMENT_DYNAMIC_CLASS(wxImageList
, wxObject
)
26 wxImageList::wxImageList( int width
, int height
, bool mask
, int initialCount
)
28 (void)Create(width
, height
, mask
, initialCount
);
31 wxImageList::~wxImageList()
36 int wxImageList::GetImageCount() const
38 return m_images
.GetCount();
41 bool wxImageList::Create( int width
, int height
, bool WXUNUSED(mask
), int WXUNUSED(initialCount
) )
49 bool wxImageList::Create()
54 int wxImageList::Add( const wxIcon
&bitmap
)
56 wxASSERT_MSG( (bitmap
.GetWidth() == m_width
&& bitmap
.GetHeight() == m_height
)
57 || (m_width
== 0 && m_height
== 0),
58 _T("invalid bitmap size in wxImageList: this might work ")
59 _T("on this platform but definitely won't under Windows.") );
61 m_images
.Append( new wxIcon( bitmap
) );
63 if (m_width
== 0 && m_height
== 0)
65 m_width
= bitmap
.GetWidth();
66 m_height
= bitmap
.GetHeight();
69 return m_images
.GetCount() - 1;
72 int wxImageList::Add( const wxBitmap
&bitmap
)
74 wxASSERT_MSG( (bitmap
.GetWidth() == m_width
&& bitmap
.GetHeight() == m_height
)
75 || (m_width
== 0 && m_height
== 0),
76 _T("invalid bitmap size in wxImageList: this might work ")
77 _T("on this platform but definitely won't under Windows.") );
79 m_images
.Append( new wxBitmap( bitmap
) );
81 if (m_width
== 0 && m_height
== 0)
83 m_width
= bitmap
.GetWidth();
84 m_height
= bitmap
.GetHeight();
87 return m_images
.GetCount() - 1;
90 int wxImageList::Add( const wxBitmap
& bitmap
, const wxBitmap
& mask
)
92 wxBitmap
bmp( bitmap
);
94 bmp
.SetMask( new wxMask( mask
) );
99 int wxImageList::Add( const wxBitmap
& bitmap
, const wxColour
& maskColour
)
101 wxImage img
= bitmap
.ConvertToImage();
102 img
.SetMaskColour( maskColour
.Red(), maskColour
.Green(), maskColour
.Blue() );
104 return Add( wxBitmap( img
) );
108 wxBitmap
wxImageList::GetBitmap(int index
) const
110 wxList::compatibility_iterator node
= m_images
.Item( index
);
112 wxCHECK_MSG( node
, wxNullBitmap
, wxT("wrong index in image list") );
114 wxObject
* obj
= (wxObject
*) node
->GetData();
116 return wxNullBitmap
;
117 else if ( obj
->IsKindOf(CLASSINFO(wxIcon
)) )
118 return wxBitmap( *(wx_static_cast(wxIcon
*, obj
)) ) ;
120 return *(wx_static_cast(wxBitmap
*, obj
)) ;
124 wxIcon
wxImageList::GetIcon(int index
) const
126 wxList::compatibility_iterator node
= m_images
.Item( index
);
128 wxCHECK_MSG( node
, wxNullIcon
, wxT("wrong index in image list") );
130 wxObject
* obj
= (wxObject
*) node
->GetData();
133 else if ( obj
->IsKindOf(CLASSINFO(wxBitmap
)) )
135 wxFAIL_MSG( wxT("cannot convert from bitmap to icon") ) ;
139 return *(wx_static_cast(wxIcon
*, obj
)) ;
142 bool wxImageList::Replace( int index
, const wxBitmap
&bitmap
)
144 wxList::compatibility_iterator node
= m_images
.Item( index
);
146 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
148 wxBitmap
* newBitmap
= new wxBitmap( bitmap
);
150 if (index
== (int) m_images
.GetCount() - 1)
152 delete node
->GetData();
154 m_images
.Erase( node
);
155 m_images
.Append( newBitmap
);
159 wxList::compatibility_iterator next
= node
->GetNext();
160 delete node
->GetData();
162 m_images
.Erase( node
);
163 m_images
.Insert( next
, newBitmap
);
169 bool wxImageList::Replace( int index
, const wxIcon
&bitmap
)
171 wxList::compatibility_iterator node
= m_images
.Item( index
);
173 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
175 wxIcon
* newBitmap
= new wxIcon( bitmap
);
177 if (index
== (int) m_images
.GetCount() - 1)
179 delete node
->GetData();
180 m_images
.Erase( node
);
181 m_images
.Append( newBitmap
);
185 wxList::compatibility_iterator next
= node
->GetNext();
186 delete node
->GetData();
187 m_images
.Erase( node
);
188 m_images
.Insert( next
, newBitmap
);
194 bool wxImageList::Remove( int index
)
196 wxList::compatibility_iterator node
= m_images
.Item( index
);
198 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
200 delete node
->GetData();
201 m_images
.Erase( node
);
206 bool wxImageList::RemoveAll()
208 WX_CLEAR_LIST(wxList
, m_images
);
214 bool wxImageList::GetSize( int index
, int &width
, int &height
) const
219 wxList::compatibility_iterator node
= m_images
.Item( index
);
221 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
223 wxObject
*obj
= (wxObject
*)node
->GetData();
224 if (obj
->IsKindOf(CLASSINFO(wxIcon
)))
226 wxIcon
*bm
= wx_static_cast( wxIcon
* , obj
) ;
227 width
= bm
->GetWidth();
228 height
= bm
->GetHeight();
232 wxBitmap
*bm
= wx_static_cast( wxBitmap
* , obj
) ;
233 width
= bm
->GetWidth();
234 height
= bm
->GetHeight();
240 bool wxImageList::Draw(
241 int index
, wxDC
&dc
, int x
, int y
,
242 int flags
, bool WXUNUSED(solidBackground
) )
244 wxList::compatibility_iterator node
= m_images
.Item( index
);
246 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
248 wxObject
*obj
= (wxObject
*)node
->GetData();
249 if (obj
->IsKindOf(CLASSINFO(wxIcon
)))
251 wxIcon
*bm
= wx_static_cast( wxIcon
* , obj
) ;
252 dc
.DrawIcon( *bm
, x
, y
);
256 wxBitmap
*bm
= wx_static_cast( wxBitmap
* , obj
) ;
257 dc
.DrawBitmap( *bm
, x
, y
, (flags
& wxIMAGELIST_DRAW_TRANSPARENT
) > 0 );
263 #endif // wxUSE_IMAGLIST