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