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