]> git.saurik.com Git - wxWidgets.git/blame - src/generic/imaglist.cpp
return the index of the inserted/appended item
[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
f6bcfd97 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
f60d0f94 21#include "wx/generic/imaglist.h"
64698f9a 22#include "wx/icon.h"
4d449473 23#include "wx/image.h"
00dd3b18 24#include "wx/dc.h"
c801d85f
KB
25
26//-----------------------------------------------------------------------------
27// wxImageList
28//-----------------------------------------------------------------------------
29
3cd94a0d 30IMPLEMENT_DYNAMIC_CLASS(wxGenericImageList, wxObject)
c801d85f 31
b31989e2
JS
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
38IMPLEMENT_DYNAMIC_CLASS(wxImageList, wxGenericImageList)
39#endif
40
3cd94a0d 41wxGenericImageList::wxGenericImageList( int width, int height, bool mask, int initialCount )
c801d85f 42{
f6bcfd97 43 (void)Create(width, height, mask, initialCount);
e1e955e1 44}
c801d85f 45
3cd94a0d 46wxGenericImageList::~wxGenericImageList()
c801d85f 47{
e1e955e1 48}
c801d85f 49
3cd94a0d 50int wxGenericImageList::GetImageCount() const
c801d85f 51{
b1d4dd7a 52 return m_images.GetCount();
e1e955e1 53}
c801d85f 54
3cd94a0d 55bool wxGenericImageList::Create( int width, int height, bool WXUNUSED(mask), int WXUNUSED(initialCount) )
f6bcfd97
BP
56{
57 m_width = width;
58 m_height = height;
59
60 return Create();
61}
62
3cd94a0d 63bool wxGenericImageList::Create()
c801d85f 64{
b46e8696 65 return TRUE;
e1e955e1 66}
c801d85f 67
3cd94a0d 68int wxGenericImageList::Add( const wxBitmap &bitmap )
c801d85f 69{
9bd41907
VZ
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
f60d0f94
JS
75 if (bitmap.IsKindOf(CLASSINFO(wxIcon)))
76 m_images.Append( new wxIcon( (const wxIcon&) bitmap ) );
77 else
78 m_images.Append( new wxBitmap(bitmap) );
b1d4dd7a 79 return m_images.GetCount()-1;
e1e955e1 80}
c801d85f 81
3cd94a0d 82int wxGenericImageList::Add( const wxBitmap& bitmap, const wxBitmap& mask )
4d449473
VS
83{
84 wxBitmap bmp(bitmap);
a7f1fbf6
RD
85 if (mask.Ok())
86 bmp.SetMask(new wxMask(mask));
4d449473
VS
87 return Add(bmp);
88}
89
3cd94a0d 90int wxGenericImageList::Add( const wxBitmap& bitmap, const wxColour& maskColour )
4d449473 91{
368d59f0 92 wxImage img = bitmap.ConvertToImage();
4d449473 93 img.SetMaskColour(maskColour.Red(), maskColour.Green(), maskColour.Blue());
368d59f0 94 return Add(wxBitmap(img));
4d449473
VS
95}
96
3cd94a0d 97const wxBitmap *wxGenericImageList::GetBitmap( int index ) const
b46e8696 98{
222ed1d6 99 wxList::compatibility_iterator node = m_images.Item( index );
43543d98 100
223d09f6 101 wxCHECK_MSG( node, (wxBitmap *) NULL, wxT("wrong index in image list") );
43543d98 102
b1d4dd7a 103 return (wxBitmap*)node->GetData();
40413a5b 104}
43543d98 105
3cd94a0d 106bool wxGenericImageList::Replace( int index, const wxBitmap &bitmap )
c801d85f 107{
222ed1d6 108 wxList::compatibility_iterator node = m_images.Item( index );
43543d98 109
223d09f6 110 wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") );
f60d0f94
JS
111
112 wxBitmap* newBitmap = NULL;
113 if (bitmap.IsKindOf(CLASSINFO(wxIcon)))
43543d98
DW
114#if defined(__VISAGECPP__)
115//just can't do this in VisualAge now, with all this new Bitmap-Icon stuff
116//so construct it from a bitmap object until I can figure this nonsense out. (DW)
117 newBitmap = new wxBitmap(bitmap) ;
118#else
8f177c8e 119 newBitmap = new wxBitmap( (const wxIcon&) bitmap );
43543d98 120#endif
f60d0f94
JS
121 else
122 newBitmap = new wxBitmap(bitmap) ;
123
b1d4dd7a 124 if (index == (int) m_images.GetCount() - 1)
b46e8696 125 {
222ed1d6
MB
126 delete node->GetData();
127 m_images.Erase( node );
f60d0f94 128 m_images.Append( newBitmap );
b46e8696
RR
129 }
130 else
131 {
222ed1d6
MB
132 wxList::compatibility_iterator next = node->GetNext();
133 delete node->GetData();
134 m_images.Erase( node );
f60d0f94 135 m_images.Insert( next, newBitmap );
b46e8696 136 }
43543d98 137
b46e8696 138 return TRUE;
e1e955e1 139}
c801d85f 140
3cd94a0d 141bool wxGenericImageList::Remove( int index )
c801d85f 142{
222ed1d6 143 wxList::compatibility_iterator node = m_images.Item( index );
43543d98 144
223d09f6 145 wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") );
43543d98 146
222ed1d6
MB
147 delete node->GetData();
148 m_images.Erase( node );
43543d98 149
b46e8696 150 return TRUE;
e1e955e1 151}
c801d85f 152
3cd94a0d 153bool wxGenericImageList::RemoveAll()
c801d85f 154{
222ed1d6 155 WX_CLEAR_LIST(wxList, m_images);
b46e8696 156 m_images.Clear();
43543d98 157
b46e8696 158 return TRUE;
e1e955e1 159}
c801d85f 160
3cd94a0d 161bool wxGenericImageList::GetSize( int index, int &width, int &height ) const
c801d85f 162{
b46e8696
RR
163 width = 0;
164 height = 0;
43543d98 165
222ed1d6 166 wxList::compatibility_iterator node = m_images.Item( index );
43543d98 167
223d09f6 168 wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") );
43543d98 169
b1d4dd7a 170 wxBitmap *bm = (wxBitmap*)node->GetData();
c801d85f
KB
171 width = bm->GetWidth();
172 height = bm->GetHeight();
43543d98 173
c801d85f 174 return TRUE;
e1e955e1 175}
c801d85f 176
3cd94a0d 177bool wxGenericImageList::Draw( int index, wxDC &dc, int x, int y,
219f895a 178 int flags, bool WXUNUSED(solidBackground) )
c801d85f 179{
222ed1d6 180 wxList::compatibility_iterator node = m_images.Item( index );
43543d98 181
223d09f6 182 wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") );
43543d98 183
b1d4dd7a 184 wxBitmap *bm = (wxBitmap*)node->GetData();
f60d0f94
JS
185
186 if (bm->IsKindOf(CLASSINFO(wxIcon)))
187 dc.DrawIcon( * ((wxIcon*) bm), x, y);
188 else
189 dc.DrawBitmap( *bm, x, y, (flags & wxIMAGELIST_DRAW_TRANSPARENT) > 0 );
219f895a 190
b46e8696 191 return TRUE;
e1e955e1 192}
c801d85f
KB
193
194