]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/imaglist.cpp
uninitialized variable warning fixed (modified patch 1434065)
[wxWidgets.git] / src / mac / carbon / imaglist.cpp
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
10 #include "wx/wxprec.h"
11
12 #if wxUSE_IMAGLIST
13
14 #ifdef __BORLANDC__
15 #pragma hdrstop
16 #endif
17
18 #include "wx/defs.h"
19 #include "wx/imaglist.h"
20 #include "wx/icon.h"
21 #include "wx/image.h"
22 #include "wx/dc.h"
23
24 IMPLEMENT_DYNAMIC_CLASS(wxImageList, wxObject)
25
26
27 wxImageList::wxImageList( int width, int height, bool mask, int initialCount )
28 {
29 (void)Create(width, height, mask, initialCount);
30 }
31
32 wxImageList::~wxImageList()
33 {
34 (void)RemoveAll();
35 }
36
37 int wxImageList::GetImageCount() const
38 {
39 return m_images.GetCount();
40 }
41
42 bool 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
50 bool wxImageList::Create()
51 {
52 return true;
53 }
54
55 int 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 }
69
70 return m_images.GetCount() - 1;
71 }
72
73 int 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
80 m_images.Append( new wxBitmap( bitmap ) );
81
82 if (m_width == 0 && m_height == 0)
83 {
84 m_width = bitmap.GetWidth();
85 m_height = bitmap.GetHeight();
86 }
87
88 return m_images.GetCount() - 1;
89 }
90
91 int wxImageList::Add( const wxBitmap& bitmap, const wxBitmap& mask )
92 {
93 wxBitmap bmp( bitmap );
94 if (mask.Ok())
95 bmp.SetMask( new wxMask( mask ) );
96
97 return Add( bmp );
98 }
99
100 int wxImageList::Add( const wxBitmap& bitmap, const wxColour& maskColour )
101 {
102 wxImage img = bitmap.ConvertToImage();
103 img.SetMaskColour( maskColour.Red(), maskColour.Green(), maskColour.Blue() );
104
105 return Add( wxBitmap( img ) );
106 }
107
108 // Get the bitmap
109 wxBitmap 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)) )
119 return wxBitmap( *(wx_static_cast(wxIcon*, obj)) ) ;
120 else
121 return *(wx_static_cast(wxBitmap*, obj)) ;
122 }
123
124 // Get the icon
125 wxIcon 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 ;
134 else if ( obj->IsKindOf(CLASSINFO(wxBitmap)) )
135 {
136 wxFAIL_MSG( wxT("cannot convert from bitmap to icon") ) ;
137 return wxNullIcon ;
138 }
139 else
140 return *(wx_static_cast(wxIcon*, obj)) ;
141 }
142
143 bool 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
149 wxBitmap* newBitmap = new wxBitmap( bitmap );
150
151 if (index == (int) m_images.GetCount() - 1)
152 {
153 delete node->GetData();
154
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();
162
163 m_images.Erase( node );
164 m_images.Insert( next, newBitmap );
165 }
166
167 return true;
168 }
169
170 bool 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
176 wxIcon* newBitmap = new wxIcon( bitmap );
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
195 bool 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
207 bool wxImageList::RemoveAll()
208 {
209 WX_CLEAR_LIST(wxList, m_images);
210 m_images.Clear();
211
212 return true;
213 }
214
215 bool 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();
225 if (obj->IsKindOf(CLASSINFO(wxIcon)))
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 }
237
238 return true;
239 }
240
241 bool wxImageList::Draw(
242 int index, wxDC &dc, int x, int y,
243 int flags, bool WXUNUSED(solidBackground) )
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();
250 if (obj->IsKindOf(CLASSINFO(wxIcon)))
251 {
252 wxIcon *bm = wx_static_cast( wxIcon* , obj ) ;
253 dc.DrawIcon( *bm , x, y );
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