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