]> git.saurik.com Git - wxWidgets.git/blame - src/generic/imaglist.cpp
submenu preparation in two methods encapsulated
[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"
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
RR
65 m_images.DeleteContents( TRUE );
66 return TRUE;
e1e955e1 67}
c801d85f 68
3cd94a0d 69int wxGenericImageList::Add( const wxBitmap &bitmap )
c801d85f 70{
f60d0f94
JS
71 if (bitmap.IsKindOf(CLASSINFO(wxIcon)))
72 m_images.Append( new wxIcon( (const wxIcon&) bitmap ) );
73 else
74 m_images.Append( new wxBitmap(bitmap) );
b1d4dd7a 75 return m_images.GetCount()-1;
e1e955e1 76}
c801d85f 77
3cd94a0d 78int wxGenericImageList::Add( const wxBitmap& bitmap, const wxBitmap& mask )
4d449473
VS
79{
80 wxBitmap bmp(bitmap);
a7f1fbf6
RD
81 if (mask.Ok())
82 bmp.SetMask(new wxMask(mask));
4d449473
VS
83 return Add(bmp);
84}
85
3cd94a0d 86int wxGenericImageList::Add( const wxBitmap& bitmap, const wxColour& maskColour )
4d449473 87{
368d59f0 88 wxImage img = bitmap.ConvertToImage();
4d449473 89 img.SetMaskColour(maskColour.Red(), maskColour.Green(), maskColour.Blue());
368d59f0 90 return Add(wxBitmap(img));
4d449473
VS
91}
92
3cd94a0d 93const wxBitmap *wxGenericImageList::GetBitmap( int index ) const
b46e8696 94{
b1d4dd7a 95 wxNode *node = m_images.Item( index );
43543d98 96
223d09f6 97 wxCHECK_MSG( node, (wxBitmap *) NULL, wxT("wrong index in image list") );
43543d98 98
b1d4dd7a 99 return (wxBitmap*)node->GetData();
40413a5b 100}
43543d98 101
3cd94a0d 102bool wxGenericImageList::Replace( int index, const wxBitmap &bitmap )
c801d85f 103{
b1d4dd7a 104 wxNode *node = m_images.Item( index );
43543d98 105
223d09f6 106 wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") );
f60d0f94
JS
107
108 wxBitmap* newBitmap = NULL;
109 if (bitmap.IsKindOf(CLASSINFO(wxIcon)))
43543d98
DW
110#if defined(__VISAGECPP__)
111//just can't do this in VisualAge now, with all this new Bitmap-Icon stuff
112//so construct it from a bitmap object until I can figure this nonsense out. (DW)
113 newBitmap = new wxBitmap(bitmap) ;
114#else
8f177c8e 115 newBitmap = new wxBitmap( (const wxIcon&) bitmap );
43543d98 116#endif
f60d0f94
JS
117 else
118 newBitmap = new wxBitmap(bitmap) ;
119
b1d4dd7a 120 if (index == (int) m_images.GetCount() - 1)
b46e8696
RR
121 {
122 m_images.DeleteNode( node );
f60d0f94 123 m_images.Append( newBitmap );
b46e8696
RR
124 }
125 else
126 {
b1d4dd7a 127 wxNode *next = node->GetNext();
b46e8696 128 m_images.DeleteNode( node );
f60d0f94 129 m_images.Insert( next, newBitmap );
b46e8696 130 }
43543d98 131
b46e8696 132 return TRUE;
e1e955e1 133}
c801d85f 134
3cd94a0d 135bool wxGenericImageList::Remove( int index )
c801d85f 136{
b1d4dd7a 137 wxNode *node = m_images.Item( index );
43543d98 138
223d09f6 139 wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") );
43543d98 140
b46e8696 141 m_images.DeleteNode( node );
43543d98 142
b46e8696 143 return TRUE;
e1e955e1 144}
c801d85f 145
3cd94a0d 146bool wxGenericImageList::RemoveAll()
c801d85f 147{
b46e8696 148 m_images.Clear();
43543d98 149
b46e8696 150 return TRUE;
e1e955e1 151}
c801d85f 152
3cd94a0d 153bool wxGenericImageList::GetSize( int index, int &width, int &height ) const
c801d85f 154{
b46e8696
RR
155 width = 0;
156 height = 0;
43543d98 157
b1d4dd7a 158 wxNode *node = m_images.Item( index );
43543d98 159
223d09f6 160 wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") );
43543d98 161
b1d4dd7a 162 wxBitmap *bm = (wxBitmap*)node->GetData();
c801d85f
KB
163 width = bm->GetWidth();
164 height = bm->GetHeight();
43543d98 165
c801d85f 166 return TRUE;
e1e955e1 167}
c801d85f 168
3cd94a0d 169bool wxGenericImageList::Draw( int index, wxDC &dc, int x, int y,
219f895a 170 int flags, bool WXUNUSED(solidBackground) )
c801d85f 171{
b1d4dd7a 172 wxNode *node = m_images.Item( index );
43543d98 173
223d09f6 174 wxCHECK_MSG( node, FALSE, wxT("wrong index in image list") );
43543d98 175
b1d4dd7a 176 wxBitmap *bm = (wxBitmap*)node->GetData();
f60d0f94
JS
177
178 if (bm->IsKindOf(CLASSINFO(wxIcon)))
179 dc.DrawIcon( * ((wxIcon*) bm), x, y);
180 else
181 dc.DrawBitmap( *bm, x, y, (flags & wxIMAGELIST_DRAW_TRANSPARENT) > 0 );
219f895a 182
b46e8696 183 return TRUE;
e1e955e1 184}
c801d85f
KB
185
186