warning fixes for BCC and OW (heavily modified patch 819146)
[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 #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 wxASSERT_MSG( bitmap.GetWidth() == m_width &&
71 bitmap.GetHeight() == m_height,
72 _T("invalid bitmap size in wxImageList: this might work ")
73 _T("on this platform but definitely won't under Windows.") );
74
75 if (bitmap.IsKindOf(CLASSINFO(wxIcon)))
76 m_images.Append( new wxIcon( (const wxIcon&) bitmap ) );
77 else
78 m_images.Append( new wxBitmap(bitmap) );
79 return m_images.GetCount()-1;
80 }
81
82 int wxGenericImageList::Add( const wxBitmap& bitmap, const wxBitmap& mask )
83 {
84 wxBitmap bmp(bitmap);
85 if (mask.Ok())
86 bmp.SetMask(new wxMask(mask));
87 return Add(bmp);
88 }
89
90 int wxGenericImageList::Add( const wxBitmap& bitmap, const wxColour& maskColour )
91 {
92 wxImage img = bitmap.ConvertToImage();
93 img.SetMaskColour(maskColour.Red(), maskColour.Green(), maskColour.Blue());
94 return Add(wxBitmap(img));
95 }
96
97 const wxBitmap *wxGenericImageList::GetBitmap( int index ) const
98 {
99 wxList::compatibility_iterator node = m_images.Item( index );
100
101 wxCHECK_MSG( node, (wxBitmap *) NULL, wxT("wrong index in image list") );
102
103 return (wxBitmap*)node->GetData();
104 }
105
106 bool wxGenericImageList::Replace( int index, const wxBitmap &bitmap )
107 {
108 wxList::compatibility_iterator node = m_images.Item( index );
109
110 wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") );
111
112 wxBitmap* newBitmap = (bitmap.IsKindOf(CLASSINFO(wxIcon))) ?
113 #if defined(__VISAGECPP__)
114 //just can't do this in VisualAge now, with all this new Bitmap-Icon stuff
115 //so construct it from a bitmap object until I can figure this nonsense out. (DW)
116 new wxBitmap(bitmap)
117 #else
118 new wxBitmap( (const wxIcon&) bitmap )
119 #endif
120 : new wxBitmap(bitmap) ;
121
122 if (index == (int) m_images.GetCount() - 1)
123 {
124 delete node->GetData();
125 m_images.Erase( node );
126 m_images.Append( newBitmap );
127 }
128 else
129 {
130 wxList::compatibility_iterator next = node->GetNext();
131 delete node->GetData();
132 m_images.Erase( node );
133 m_images.Insert( next, newBitmap );
134 }
135
136 return TRUE;
137 }
138
139 bool wxGenericImageList::Remove( int index )
140 {
141 wxList::compatibility_iterator node = m_images.Item( index );
142
143 wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") );
144
145 delete node->GetData();
146 m_images.Erase( node );
147
148 return TRUE;
149 }
150
151 bool wxGenericImageList::RemoveAll()
152 {
153 WX_CLEAR_LIST(wxList, m_images);
154 m_images.Clear();
155
156 return TRUE;
157 }
158
159 bool wxGenericImageList::GetSize( int index, int &width, int &height ) const
160 {
161 width = 0;
162 height = 0;
163
164 wxList::compatibility_iterator node = m_images.Item( index );
165
166 wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") );
167
168 wxBitmap *bm = (wxBitmap*)node->GetData();
169 width = bm->GetWidth();
170 height = bm->GetHeight();
171
172 return TRUE;
173 }
174
175 bool wxGenericImageList::Draw( int index, wxDC &dc, int x, int y,
176 int flags, bool WXUNUSED(solidBackground) )
177 {
178 wxList::compatibility_iterator node = m_images.Item( index );
179
180 wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") );
181
182 wxBitmap *bm = (wxBitmap*)node->GetData();
183
184 if (bm->IsKindOf(CLASSINFO(wxIcon)))
185 dc.DrawIcon( * ((wxIcon*) bm), x, y);
186 else
187 dc.DrawBitmap( *bm, x, y, (flags & wxIMAGELIST_DRAW_TRANSPARENT) > 0 );
188
189 return TRUE;
190 }
191
192