]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/imaglist.cpp
cleanup - fixed warnings, reformatting
[wxWidgets.git] / src / mac / carbon / imaglist.cpp
CommitLineData
6ce43ac9
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: generic/imaglist.cpp
3// Purpose:
4// Author: Robert Roebling
5// Id: $id$
6// Copyright: (c) 1998 Robert Roebling
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
6ce43ac9
SC
10#include "wx/wxprec.h"
11
12#if wxUSE_IMAGLIST
13
14#ifdef __BORLANDC__
274b7a40 15 #pragma hdrstop
6ce43ac9
SC
16#endif
17
18#include "wx/defs.h"
6ce43ac9 19#include "wx/imaglist.h"
6ce43ac9
SC
20#include "wx/icon.h"
21#include "wx/image.h"
22#include "wx/dc.h"
23
6ce43ac9
SC
24IMPLEMENT_DYNAMIC_CLASS(wxImageList, wxObject)
25
274b7a40 26
6ce43ac9
SC
27wxImageList::wxImageList( int width, int height, bool mask, int initialCount )
28{
29 (void)Create(width, height, mask, initialCount);
30}
31
32wxImageList::~wxImageList()
33{
34 (void)RemoveAll();
35}
36
37int wxImageList::GetImageCount() const
38{
39 return m_images.GetCount();
40}
41
42bool wxImageList::Create( int width, int height, bool WXUNUSED(mask), int WXUNUSED(initialCount) )
43{
44 m_width = width;
45 m_height = height;
46
47 return Create();
48}
49
50bool wxImageList::Create()
51{
52 return true;
53}
54
55int wxImageList::Add( const wxIcon &bitmap )
56{
57 wxASSERT_MSG( (bitmap.GetWidth() == m_width && bitmap.GetHeight() == m_height)
58 || (m_width == 0 && m_height == 0),
59 _T("invalid bitmap size in wxImageList: this might work ")
60 _T("on this platform but definitely won't under Windows.") );
61
62 m_images.Append( new wxIcon( bitmap ) );
63
64 if (m_width == 0 && m_height == 0)
65 {
66 m_width = bitmap.GetWidth();
67 m_height = bitmap.GetHeight();
68 }
274b7a40
DS
69
70 return m_images.GetCount() - 1;
6ce43ac9
SC
71}
72
73int wxImageList::Add( const wxBitmap &bitmap )
74{
75 wxASSERT_MSG( (bitmap.GetWidth() == m_width && bitmap.GetHeight() == m_height)
76 || (m_width == 0 && m_height == 0),
77 _T("invalid bitmap size in wxImageList: this might work ")
78 _T("on this platform but definitely won't under Windows.") );
79
274b7a40 80 m_images.Append( new wxBitmap( bitmap ) );
6ce43ac9
SC
81
82 if (m_width == 0 && m_height == 0)
83 {
84 m_width = bitmap.GetWidth();
85 m_height = bitmap.GetHeight();
86 }
274b7a40
DS
87
88 return m_images.GetCount() - 1;
6ce43ac9
SC
89}
90
91int wxImageList::Add( const wxBitmap& bitmap, const wxBitmap& mask )
92{
274b7a40 93 wxBitmap bmp( bitmap );
6ce43ac9 94 if (mask.Ok())
274b7a40
DS
95 bmp.SetMask( new wxMask( mask ) );
96
97 return Add( bmp );
6ce43ac9
SC
98}
99
100int wxImageList::Add( const wxBitmap& bitmap, const wxColour& maskColour )
101{
102 wxImage img = bitmap.ConvertToImage();
274b7a40
DS
103 img.SetMaskColour( maskColour.Red(), maskColour.Green(), maskColour.Blue() );
104
105 return Add( wxBitmap( img ) );
6ce43ac9
SC
106}
107
108// Get the bitmap
109wxBitmap wxImageList::GetBitmap(int index) const
110{
111 wxList::compatibility_iterator node = m_images.Item( index );
112
113 wxCHECK_MSG( node, wxNullBitmap , wxT("wrong index in image list") );
114
115 wxObject* obj = (wxObject*) node->GetData();
116 if ( obj == NULL )
117 return wxNullBitmap ;
118 else if ( obj->IsKindOf(CLASSINFO(wxIcon)) )
274b7a40
DS
119 return wxBitmap( *(wx_static_cast(wxIcon*, obj)) ) ;
120 else
121 return *(wx_static_cast(wxBitmap*, obj)) ;
6ce43ac9
SC
122}
123
124// Get the icon
125wxIcon wxImageList::GetIcon(int index) const
126{
127 wxList::compatibility_iterator node = m_images.Item( index );
128
129 wxCHECK_MSG( node, wxNullIcon , wxT("wrong index in image list") );
130
131 wxObject* obj = (wxObject*) node->GetData();
132 if ( obj == NULL )
133 return wxNullIcon ;
274b7a40 134 else if ( obj->IsKindOf(CLASSINFO(wxBitmap)) )
6ce43ac9
SC
135 {
136 wxFAIL_MSG( wxT("cannot convert from bitmap to icon") ) ;
137 return wxNullIcon ;
138 }
274b7a40
DS
139 else
140 return *(wx_static_cast(wxIcon*, obj)) ;
6ce43ac9
SC
141}
142
143bool wxImageList::Replace( int index, const wxBitmap &bitmap )
144{
145 wxList::compatibility_iterator node = m_images.Item( index );
146
147 wxCHECK_MSG( node, false, wxT("wrong index in image list") );
148
274b7a40 149 wxBitmap* newBitmap = new wxBitmap( bitmap );
6ce43ac9
SC
150
151 if (index == (int) m_images.GetCount() - 1)
152 {
153 delete node->GetData();
274b7a40 154
6ce43ac9
SC
155 m_images.Erase( node );
156 m_images.Append( newBitmap );
157 }
158 else
159 {
160 wxList::compatibility_iterator next = node->GetNext();
161 delete node->GetData();
274b7a40 162
6ce43ac9
SC
163 m_images.Erase( node );
164 m_images.Insert( next, newBitmap );
165 }
166
167 return true;
168}
169
170bool wxImageList::Replace( int index, const wxIcon &bitmap )
171{
172 wxList::compatibility_iterator node = m_images.Item( index );
173
174 wxCHECK_MSG( node, false, wxT("wrong index in image list") );
175
274b7a40 176 wxIcon* newBitmap = new wxIcon( bitmap );
6ce43ac9
SC
177
178 if (index == (int) m_images.GetCount() - 1)
179 {
180 delete node->GetData();
181 m_images.Erase( node );
182 m_images.Append( newBitmap );
183 }
184 else
185 {
186 wxList::compatibility_iterator next = node->GetNext();
187 delete node->GetData();
188 m_images.Erase( node );
189 m_images.Insert( next, newBitmap );
190 }
191
192 return true;
193}
194
195bool wxImageList::Remove( int index )
196{
197 wxList::compatibility_iterator node = m_images.Item( index );
198
199 wxCHECK_MSG( node, false, wxT("wrong index in image list") );
200
201 delete node->GetData();
202 m_images.Erase( node );
203
204 return true;
205}
206
207bool wxImageList::RemoveAll()
208{
209 WX_CLEAR_LIST(wxList, m_images);
210 m_images.Clear();
211
212 return true;
213}
214
215bool wxImageList::GetSize( int index, int &width, int &height ) const
216{
217 width = 0;
218 height = 0;
219
220 wxList::compatibility_iterator node = m_images.Item( index );
221
222 wxCHECK_MSG( node, false, wxT("wrong index in image list") );
223
224 wxObject *obj = (wxObject*)node->GetData();
274b7a40 225 if (obj->IsKindOf(CLASSINFO(wxIcon)))
6ce43ac9
SC
226 {
227 wxIcon *bm = wx_static_cast( wxIcon* , obj ) ;
228 width = bm->GetWidth();
229 height = bm->GetHeight();
230 }
231 else
232 {
233 wxBitmap *bm = wx_static_cast( wxBitmap* , obj ) ;
234 width = bm->GetWidth();
235 height = bm->GetHeight();
236 }
274b7a40 237
6ce43ac9
SC
238 return true;
239}
240
274b7a40
DS
241bool wxImageList::Draw(
242 int index, wxDC &dc, int x, int y,
243 int flags, bool WXUNUSED(solidBackground) )
6ce43ac9
SC
244{
245 wxList::compatibility_iterator node = m_images.Item( index );
246
247 wxCHECK_MSG( node, false, wxT("wrong index in image list") );
248
249 wxObject *obj = (wxObject*)node->GetData();
274b7a40 250 if (obj->IsKindOf(CLASSINFO(wxIcon)))
6ce43ac9
SC
251 {
252 wxIcon *bm = wx_static_cast( wxIcon* , obj ) ;
274b7a40 253 dc.DrawIcon( *bm , x, y );
6ce43ac9
SC
254 }
255 else
256 {
257 wxBitmap *bm = wx_static_cast( wxBitmap* , obj ) ;
258 dc.DrawBitmap( *bm, x, y, (flags & wxIMAGELIST_DRAW_TRANSPARENT) > 0 );
259 }
260
261 return true;
262}
263
264#endif // wxUSE_IMAGLIST
265