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