]> git.saurik.com Git - wxWidgets.git/blame - src/generic/imaglist.cpp
Fixed GetIcon to keep up with return type change on all other platforms.
[wxWidgets.git] / src / generic / imaglist.cpp
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
f6bcfd97 2// Name: generic/imaglist.cpp
c801d85f
KB
3// Purpose:
4// Author: Robert Roebling
01111366
RR
5// Id: $id$
6// Copyright: (c) 1998 Robert Roebling
65571936 7// Licence: wxWindows licence
c801d85f
KB
8/////////////////////////////////////////////////////////////////////////////
9
1e6d9499
JS
10// For compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
12
58c5c7ec
RN
13#if wxUSE_IMAGLIST
14
1e6d9499
JS
15#ifdef __BORLANDC__
16#pragma hdrstop
17#endif
18
9de05dfd
RN
19#include "wx/defs.h"
20
4055ed82 21#ifndef __WXPALMOS__
9de05dfd 22
f60d0f94 23#include "wx/generic/imaglist.h"
9de05dfd 24
64698f9a 25#include "wx/icon.h"
4d449473 26#include "wx/image.h"
00dd3b18 27#include "wx/dc.h"
c801d85f
KB
28
29//-----------------------------------------------------------------------------
30// wxImageList
31//-----------------------------------------------------------------------------
32
3cd94a0d 33IMPLEMENT_DYNAMIC_CLASS(wxGenericImageList, wxObject)
c801d85f 34
3a5bcc4d 35#if !defined(__WXMSW__) || defined(__WXUNIVERSAL__)
b31989e2
JS
36/*
37 * wxImageList has to be a real class or we have problems with
38 * the run-time information.
39 */
40
41IMPLEMENT_DYNAMIC_CLASS(wxImageList, wxGenericImageList)
42#endif
43
3cd94a0d 44wxGenericImageList::wxGenericImageList( int width, int height, bool mask, int initialCount )
c801d85f 45{
f6bcfd97 46 (void)Create(width, height, mask, initialCount);
e1e955e1 47}
c801d85f 48
3cd94a0d 49wxGenericImageList::~wxGenericImageList()
c801d85f 50{
3fc93ebd 51 (void)RemoveAll();
e1e955e1 52}
c801d85f 53
3cd94a0d 54int wxGenericImageList::GetImageCount() const
c801d85f 55{
b1d4dd7a 56 return m_images.GetCount();
e1e955e1 57}
c801d85f 58
3cd94a0d 59bool wxGenericImageList::Create( int width, int height, bool WXUNUSED(mask), int WXUNUSED(initialCount) )
f6bcfd97
BP
60{
61 m_width = width;
62 m_height = height;
63
64 return Create();
65}
66
3cd94a0d 67bool wxGenericImageList::Create()
c801d85f 68{
ca65c044 69 return true;
e1e955e1 70}
c801d85f 71
3cd94a0d 72int wxGenericImageList::Add( const wxBitmap &bitmap )
c801d85f 73{
b931414d
RD
74 wxASSERT_MSG( (bitmap.GetWidth() == m_width && bitmap.GetHeight() == m_height)
75 || (m_width == 0 && m_height == 0),
9bd41907
VZ
76 _T("invalid bitmap size in wxImageList: this might work ")
77 _T("on this platform but definitely won't under Windows.") );
78
f60d0f94
JS
79 if (bitmap.IsKindOf(CLASSINFO(wxIcon)))
80 m_images.Append( new wxIcon( (const wxIcon&) bitmap ) );
81 else
82 m_images.Append( new wxBitmap(bitmap) );
b931414d
RD
83
84 if (m_width == 0 && m_height == 0)
85 {
86 m_width = bitmap.GetWidth();
87 m_height = bitmap.GetHeight();
88 }
89
b1d4dd7a 90 return m_images.GetCount()-1;
e1e955e1 91}
c801d85f 92
3cd94a0d 93int wxGenericImageList::Add( const wxBitmap& bitmap, const wxBitmap& mask )
4d449473
VS
94{
95 wxBitmap bmp(bitmap);
a7f1fbf6
RD
96 if (mask.Ok())
97 bmp.SetMask(new wxMask(mask));
4d449473
VS
98 return Add(bmp);
99}
100
3cd94a0d 101int wxGenericImageList::Add( const wxBitmap& bitmap, const wxColour& maskColour )
4d449473 102{
368d59f0 103 wxImage img = bitmap.ConvertToImage();
4d449473 104 img.SetMaskColour(maskColour.Red(), maskColour.Green(), maskColour.Blue());
368d59f0 105 return Add(wxBitmap(img));
4d449473
VS
106}
107
49bf4e3e 108const wxBitmap *wxGenericImageList::GetBitmapPtr( int index ) const
b46e8696 109{
222ed1d6 110 wxList::compatibility_iterator node = m_images.Item( index );
43543d98 111
223d09f6 112 wxCHECK_MSG( node, (wxBitmap *) NULL, wxT("wrong index in image list") );
43543d98 113
b1d4dd7a 114 return (wxBitmap*)node->GetData();
40413a5b 115}
43543d98 116
49bf4e3e 117// Get the bitmap
f45fac95 118wxBitmap wxGenericImageList::GetBitmap(int index) const
49bf4e3e
JS
119{
120 const wxBitmap* bmp = GetBitmapPtr(index);
121 if (bmp)
122 return *bmp;
123 else
124 return wxNullBitmap;
125}
126
127// Get the icon
f45fac95 128wxIcon wxGenericImageList::GetIcon(int index) const
49bf4e3e
JS
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
3cd94a0d 141bool wxGenericImageList::Replace( int index, const wxBitmap &bitmap )
c801d85f 142{
222ed1d6 143 wxList::compatibility_iterator node = m_images.Item( index );
43543d98 144
ca65c044 145 wxCHECK_MSG( node, false, wxT("wrong index in image list") );
f60d0f94 146
999836aa
VZ
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) ;
f60d0f94 156
b1d4dd7a 157 if (index == (int) m_images.GetCount() - 1)
b46e8696 158 {
222ed1d6
MB
159 delete node->GetData();
160 m_images.Erase( node );
f60d0f94 161 m_images.Append( newBitmap );
b46e8696
RR
162 }
163 else
164 {
222ed1d6
MB
165 wxList::compatibility_iterator next = node->GetNext();
166 delete node->GetData();
167 m_images.Erase( node );
f60d0f94 168 m_images.Insert( next, newBitmap );
b46e8696 169 }
43543d98 170
ca65c044 171 return true;
e1e955e1 172}
c801d85f 173
3cd94a0d 174bool wxGenericImageList::Remove( int index )
c801d85f 175{
222ed1d6 176 wxList::compatibility_iterator node = m_images.Item( index );
43543d98 177
ca65c044 178 wxCHECK_MSG( node, false, wxT("wrong index in image list") );
43543d98 179
222ed1d6
MB
180 delete node->GetData();
181 m_images.Erase( node );
43543d98 182
ca65c044 183 return true;
e1e955e1 184}
c801d85f 185
3cd94a0d 186bool wxGenericImageList::RemoveAll()
c801d85f 187{
222ed1d6 188 WX_CLEAR_LIST(wxList, m_images);
b46e8696 189 m_images.Clear();
43543d98 190
ca65c044 191 return true;
e1e955e1 192}
c801d85f 193
3cd94a0d 194bool wxGenericImageList::GetSize( int index, int &width, int &height ) const
c801d85f 195{
b46e8696
RR
196 width = 0;
197 height = 0;
43543d98 198
222ed1d6 199 wxList::compatibility_iterator node = m_images.Item( index );
43543d98 200
ca65c044 201 wxCHECK_MSG( node, false, wxT("wrong index in image list") );
43543d98 202
b1d4dd7a 203 wxBitmap *bm = (wxBitmap*)node->GetData();
c801d85f
KB
204 width = bm->GetWidth();
205 height = bm->GetHeight();
43543d98 206
ca65c044 207 return true;
e1e955e1 208}
c801d85f 209
3cd94a0d 210bool wxGenericImageList::Draw( int index, wxDC &dc, int x, int y,
219f895a 211 int flags, bool WXUNUSED(solidBackground) )
c801d85f 212{
222ed1d6 213 wxList::compatibility_iterator node = m_images.Item( index );
43543d98 214
ca65c044 215 wxCHECK_MSG( node, false, wxT("wrong index in image list") );
43543d98 216
b1d4dd7a 217 wxBitmap *bm = (wxBitmap*)node->GetData();
f60d0f94
JS
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 );
219f895a 223
ca65c044 224 return true;
e1e955e1 225}
c801d85f 226
58c5c7ec 227#endif // wxUSE_IMAGLIST
4055ed82 228#endif // __WXPALMOS__