]> git.saurik.com Git - wxWidgets.git/blame - src/generic/imaglist.cpp
implementation of wxRendererXP::DrawComboBoxDropButton() (patch 1144845)
[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{
b931414d
RD
76 wxASSERT_MSG( (bitmap.GetWidth() == m_width && bitmap.GetHeight() == m_height)
77 || (m_width == 0 && m_height == 0),
9bd41907
VZ
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) );
b931414d
RD
85
86 if (m_width == 0 && m_height == 0)
87 {
88 m_width = bitmap.GetWidth();
89 m_height = bitmap.GetHeight();
90 }
91
b1d4dd7a 92 return m_images.GetCount()-1;
e1e955e1 93}
c801d85f 94
3cd94a0d 95int wxGenericImageList::Add( const wxBitmap& bitmap, const wxBitmap& mask )
4d449473
VS
96{
97 wxBitmap bmp(bitmap);
a7f1fbf6
RD
98 if (mask.Ok())
99 bmp.SetMask(new wxMask(mask));
4d449473
VS
100 return Add(bmp);
101}
102
3cd94a0d 103int wxGenericImageList::Add( const wxBitmap& bitmap, const wxColour& maskColour )
4d449473 104{
368d59f0 105 wxImage img = bitmap.ConvertToImage();
4d449473 106 img.SetMaskColour(maskColour.Red(), maskColour.Green(), maskColour.Blue());
368d59f0 107 return Add(wxBitmap(img));
4d449473
VS
108}
109
3cd94a0d 110const wxBitmap *wxGenericImageList::GetBitmap( int index ) const
b46e8696 111{
222ed1d6 112 wxList::compatibility_iterator node = m_images.Item( index );
43543d98 113
223d09f6 114 wxCHECK_MSG( node, (wxBitmap *) NULL, wxT("wrong index in image list") );
43543d98 115
b1d4dd7a 116 return (wxBitmap*)node->GetData();
40413a5b 117}
43543d98 118
3cd94a0d 119bool wxGenericImageList::Replace( int index, const wxBitmap &bitmap )
c801d85f 120{
222ed1d6 121 wxList::compatibility_iterator node = m_images.Item( index );
43543d98 122
ca65c044 123 wxCHECK_MSG( node, false, wxT("wrong index in image list") );
f60d0f94 124
999836aa
VZ
125 wxBitmap* newBitmap = (bitmap.IsKindOf(CLASSINFO(wxIcon))) ?
126 #if defined(__VISAGECPP__)
127 //just can't do this in VisualAge now, with all this new Bitmap-Icon stuff
128 //so construct it from a bitmap object until I can figure this nonsense out. (DW)
129 new wxBitmap(bitmap)
130 #else
131 new wxBitmap( (const wxIcon&) bitmap )
132 #endif
133 : new wxBitmap(bitmap) ;
f60d0f94 134
b1d4dd7a 135 if (index == (int) m_images.GetCount() - 1)
b46e8696 136 {
222ed1d6
MB
137 delete node->GetData();
138 m_images.Erase( node );
f60d0f94 139 m_images.Append( newBitmap );
b46e8696
RR
140 }
141 else
142 {
222ed1d6
MB
143 wxList::compatibility_iterator next = node->GetNext();
144 delete node->GetData();
145 m_images.Erase( node );
f60d0f94 146 m_images.Insert( next, newBitmap );
b46e8696 147 }
43543d98 148
ca65c044 149 return true;
e1e955e1 150}
c801d85f 151
3cd94a0d 152bool wxGenericImageList::Remove( int index )
c801d85f 153{
222ed1d6 154 wxList::compatibility_iterator node = m_images.Item( index );
43543d98 155
ca65c044 156 wxCHECK_MSG( node, false, wxT("wrong index in image list") );
43543d98 157
222ed1d6
MB
158 delete node->GetData();
159 m_images.Erase( node );
43543d98 160
ca65c044 161 return true;
e1e955e1 162}
c801d85f 163
3cd94a0d 164bool wxGenericImageList::RemoveAll()
c801d85f 165{
222ed1d6 166 WX_CLEAR_LIST(wxList, m_images);
b46e8696 167 m_images.Clear();
43543d98 168
ca65c044 169 return true;
e1e955e1 170}
c801d85f 171
3cd94a0d 172bool wxGenericImageList::GetSize( int index, int &width, int &height ) const
c801d85f 173{
b46e8696
RR
174 width = 0;
175 height = 0;
43543d98 176
222ed1d6 177 wxList::compatibility_iterator node = m_images.Item( index );
43543d98 178
ca65c044 179 wxCHECK_MSG( node, false, wxT("wrong index in image list") );
43543d98 180
b1d4dd7a 181 wxBitmap *bm = (wxBitmap*)node->GetData();
c801d85f
KB
182 width = bm->GetWidth();
183 height = bm->GetHeight();
43543d98 184
ca65c044 185 return true;
e1e955e1 186}
c801d85f 187
3cd94a0d 188bool wxGenericImageList::Draw( int index, wxDC &dc, int x, int y,
219f895a 189 int flags, bool WXUNUSED(solidBackground) )
c801d85f 190{
222ed1d6 191 wxList::compatibility_iterator node = m_images.Item( index );
43543d98 192
ca65c044 193 wxCHECK_MSG( node, false, wxT("wrong index in image list") );
43543d98 194
b1d4dd7a 195 wxBitmap *bm = (wxBitmap*)node->GetData();
f60d0f94
JS
196
197 if (bm->IsKindOf(CLASSINFO(wxIcon)))
198 dc.DrawIcon( * ((wxIcon*) bm), x, y);
199 else
200 dc.DrawBitmap( *bm, x, y, (flags & wxIMAGELIST_DRAW_TRANSPARENT) > 0 );
219f895a 201
ca65c044 202 return true;
e1e955e1 203}
c801d85f 204
4055ed82 205#endif // __WXPALMOS__