]> git.saurik.com Git - wxWidgets.git/blob - src/generic/imaglist.cpp
WinCE fixes
[wxWidgets.git] / src / generic / 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 #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 #ifndef __WXPALMOS__
26
27 #include "wx/generic/imaglist.h"
28
29 #include "wx/icon.h"
30 #include "wx/image.h"
31 #include "wx/dc.h"
32
33 //-----------------------------------------------------------------------------
34 // wxImageList
35 //-----------------------------------------------------------------------------
36
37 IMPLEMENT_DYNAMIC_CLASS(wxGenericImageList, wxObject)
38
39 #if !defined(__WXMSW__) || defined(__WXUNIVERSAL__)
40 /*
41 * wxImageList has to be a real class or we have problems with
42 * the run-time information.
43 */
44
45 IMPLEMENT_DYNAMIC_CLASS(wxImageList, wxGenericImageList)
46 #endif
47
48 wxGenericImageList::wxGenericImageList( int width, int height, bool mask, int initialCount )
49 {
50 (void)Create(width, height, mask, initialCount);
51 }
52
53 wxGenericImageList::~wxGenericImageList()
54 {
55 (void)RemoveAll();
56 }
57
58 int wxGenericImageList::GetImageCount() const
59 {
60 return m_images.GetCount();
61 }
62
63 bool wxGenericImageList::Create( int width, int height, bool WXUNUSED(mask), int WXUNUSED(initialCount) )
64 {
65 m_width = width;
66 m_height = height;
67
68 return Create();
69 }
70
71 bool wxGenericImageList::Create()
72 {
73 return true;
74 }
75
76 int wxGenericImageList::Add( const wxBitmap &bitmap )
77 {
78 wxASSERT_MSG( (bitmap.GetWidth() == m_width && bitmap.GetHeight() == m_height)
79 || (m_width == 0 && m_height == 0),
80 _T("invalid bitmap size in wxImageList: this might work ")
81 _T("on this platform but definitely won't under Windows.") );
82
83 if (bitmap.IsKindOf(CLASSINFO(wxIcon)))
84 m_images.Append( new wxIcon( (const wxIcon&) bitmap ) );
85 else
86 m_images.Append( new wxBitmap(bitmap) );
87
88 if (m_width == 0 && m_height == 0)
89 {
90 m_width = bitmap.GetWidth();
91 m_height = bitmap.GetHeight();
92 }
93
94 return m_images.GetCount()-1;
95 }
96
97 int wxGenericImageList::Add( const wxBitmap& bitmap, const wxBitmap& mask )
98 {
99 wxBitmap bmp(bitmap);
100 if (mask.Ok())
101 bmp.SetMask(new wxMask(mask));
102 return Add(bmp);
103 }
104
105 int wxGenericImageList::Add( const wxBitmap& bitmap, const wxColour& maskColour )
106 {
107 wxImage img = bitmap.ConvertToImage();
108 img.SetMaskColour(maskColour.Red(), maskColour.Green(), maskColour.Blue());
109 return Add(wxBitmap(img));
110 }
111
112 const wxBitmap *wxGenericImageList::GetBitmapPtr( int index ) const
113 {
114 wxList::compatibility_iterator node = m_images.Item( index );
115
116 wxCHECK_MSG( node, (wxBitmap *) NULL, wxT("wrong index in image list") );
117
118 return (wxBitmap*)node->GetData();
119 }
120
121 // Get the bitmap
122 wxBitmap wxGenericImageList::GetBitmap(int index) const
123 {
124 const wxBitmap* bmp = GetBitmapPtr(index);
125 if (bmp)
126 return *bmp;
127 else
128 return wxNullBitmap;
129 }
130
131 // Get the icon
132 wxIcon wxGenericImageList::GetIcon(int index) const
133 {
134 const wxBitmap* bmp = GetBitmapPtr(index);
135 if (bmp)
136 {
137 wxIcon icon;
138 icon.CopyFromBitmap(*bmp);
139 return icon;
140 }
141 else
142 return wxNullIcon;
143 }
144
145 bool wxGenericImageList::Replace( int index, const wxBitmap &bitmap )
146 {
147 wxList::compatibility_iterator node = m_images.Item( index );
148
149 wxCHECK_MSG( node, false, wxT("wrong index in image list") );
150
151 wxBitmap* newBitmap = (bitmap.IsKindOf(CLASSINFO(wxIcon))) ?
152 #if defined(__VISAGECPP__)
153 //just can't do this in VisualAge now, with all this new Bitmap-Icon stuff
154 //so construct it from a bitmap object until I can figure this nonsense out. (DW)
155 new wxBitmap(bitmap)
156 #else
157 new wxBitmap( (const wxIcon&) bitmap )
158 #endif
159 : new wxBitmap(bitmap) ;
160
161 if (index == (int) m_images.GetCount() - 1)
162 {
163 delete node->GetData();
164 m_images.Erase( node );
165 m_images.Append( newBitmap );
166 }
167 else
168 {
169 wxList::compatibility_iterator next = node->GetNext();
170 delete node->GetData();
171 m_images.Erase( node );
172 m_images.Insert( next, newBitmap );
173 }
174
175 return true;
176 }
177
178 bool wxGenericImageList::Remove( int index )
179 {
180 wxList::compatibility_iterator node = m_images.Item( index );
181
182 wxCHECK_MSG( node, false, wxT("wrong index in image list") );
183
184 delete node->GetData();
185 m_images.Erase( node );
186
187 return true;
188 }
189
190 bool wxGenericImageList::RemoveAll()
191 {
192 WX_CLEAR_LIST(wxList, m_images);
193 m_images.Clear();
194
195 return true;
196 }
197
198 bool wxGenericImageList::GetSize( int index, int &width, int &height ) const
199 {
200 width = 0;
201 height = 0;
202
203 wxList::compatibility_iterator node = m_images.Item( index );
204
205 wxCHECK_MSG( node, false, wxT("wrong index in image list") );
206
207 wxBitmap *bm = (wxBitmap*)node->GetData();
208 width = bm->GetWidth();
209 height = bm->GetHeight();
210
211 return true;
212 }
213
214 bool wxGenericImageList::Draw( int index, wxDC &dc, int x, int y,
215 int flags, bool WXUNUSED(solidBackground) )
216 {
217 wxList::compatibility_iterator node = m_images.Item( index );
218
219 wxCHECK_MSG( node, false, wxT("wrong index in image list") );
220
221 wxBitmap *bm = (wxBitmap*)node->GetData();
222
223 if (bm->IsKindOf(CLASSINFO(wxIcon)))
224 dc.DrawIcon( * ((wxIcon*) bm), x, y);
225 else
226 dc.DrawBitmap( *bm, x, y, (flags & wxIMAGELIST_DRAW_TRANSPARENT) > 0 );
227
228 return true;
229 }
230
231 #endif // wxUSE_IMAGLIST
232 #endif // __WXPALMOS__