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