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