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