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