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