1 /////////////////////////////////////////////////////////////////////////////
2 // Name: generic/imaglist.cpp
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
11 #pragma implementation "imaglist.h"
14 // For compilers that support precompilation, includes "wx.h".
15 #include "wx/wxprec.h"
25 #include "wx/generic/imaglist.h"
31 //-----------------------------------------------------------------------------
33 //-----------------------------------------------------------------------------
35 IMPLEMENT_DYNAMIC_CLASS(wxGenericImageList
, wxObject
)
37 #if !defined(__WXMSW__) || defined(__WXUNIVERSAL__)
39 * wxImageList has to be a real class or we have problems with
40 * the run-time information.
43 IMPLEMENT_DYNAMIC_CLASS(wxImageList
, wxGenericImageList
)
46 wxGenericImageList::wxGenericImageList( int width
, int height
, bool mask
, int initialCount
)
48 (void)Create(width
, height
, mask
, initialCount
);
51 wxGenericImageList::~wxGenericImageList()
56 int wxGenericImageList::GetImageCount() const
58 return m_images
.GetCount();
61 bool wxGenericImageList::Create( int width
, int height
, bool WXUNUSED(mask
), int WXUNUSED(initialCount
) )
69 bool wxGenericImageList::Create()
74 int wxGenericImageList::Add( const wxBitmap
&bitmap
)
76 wxASSERT_MSG( (bitmap
.GetWidth() == m_width
&& bitmap
.GetHeight() == m_height
)
77 || (m_width
== 0 && m_height
== 0),
78 _T("invalid bitmap size in wxImageList: this might work ")
79 _T("on this platform but definitely won't under Windows.") );
81 if (bitmap
.IsKindOf(CLASSINFO(wxIcon
)))
82 m_images
.Append( new wxIcon( (const wxIcon
&) bitmap
) );
84 m_images
.Append( new wxBitmap(bitmap
) );
86 if (m_width
== 0 && m_height
== 0)
88 m_width
= bitmap
.GetWidth();
89 m_height
= bitmap
.GetHeight();
92 return m_images
.GetCount()-1;
95 int wxGenericImageList::Add( const wxBitmap
& bitmap
, const wxBitmap
& mask
)
99 bmp
.SetMask(new wxMask(mask
));
103 int wxGenericImageList::Add( const wxBitmap
& bitmap
, const wxColour
& maskColour
)
105 wxImage img
= bitmap
.ConvertToImage();
106 img
.SetMaskColour(maskColour
.Red(), maskColour
.Green(), maskColour
.Blue());
107 return Add(wxBitmap(img
));
110 const wxBitmap
*wxGenericImageList::GetBitmapPtr( int index
) const
112 wxList::compatibility_iterator node
= m_images
.Item( index
);
114 wxCHECK_MSG( node
, (wxBitmap
*) NULL
, wxT("wrong index in image list") );
116 return (wxBitmap
*)node
->GetData();
120 wxBitmap
wxGenericImageList::GetBitmap(int index
) const
122 const wxBitmap
* bmp
= GetBitmapPtr(index
);
130 wxIcon
wxGenericImageList::GetIcon(int index
) const
132 const wxBitmap
* bmp
= GetBitmapPtr(index
);
136 icon
.CopyFromBitmap(*bmp
);
143 bool wxGenericImageList::Replace( int index
, const wxBitmap
&bitmap
)
145 wxList::compatibility_iterator node
= m_images
.Item( index
);
147 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
149 wxBitmap
* newBitmap
= (bitmap
.IsKindOf(CLASSINFO(wxIcon
))) ?
150 #if defined(__VISAGECPP__)
151 //just can't do this in VisualAge now, with all this new Bitmap-Icon stuff
152 //so construct it from a bitmap object until I can figure this nonsense out. (DW)
155 new wxBitmap( (const wxIcon
&) bitmap
)
157 : new wxBitmap(bitmap
) ;
159 if (index
== (int) m_images
.GetCount() - 1)
161 delete node
->GetData();
162 m_images
.Erase( node
);
163 m_images
.Append( newBitmap
);
167 wxList::compatibility_iterator next
= node
->GetNext();
168 delete node
->GetData();
169 m_images
.Erase( node
);
170 m_images
.Insert( next
, newBitmap
);
176 bool wxGenericImageList::Remove( int index
)
178 wxList::compatibility_iterator node
= m_images
.Item( index
);
180 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
182 delete node
->GetData();
183 m_images
.Erase( node
);
188 bool wxGenericImageList::RemoveAll()
190 WX_CLEAR_LIST(wxList
, m_images
);
196 bool wxGenericImageList::GetSize( int index
, int &width
, int &height
) const
201 wxList::compatibility_iterator node
= m_images
.Item( index
);
203 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
205 wxBitmap
*bm
= (wxBitmap
*)node
->GetData();
206 width
= bm
->GetWidth();
207 height
= bm
->GetHeight();
212 bool wxGenericImageList::Draw( int index
, wxDC
&dc
, int x
, int y
,
213 int flags
, bool WXUNUSED(solidBackground
) )
215 wxList::compatibility_iterator node
= m_images
.Item( index
);
217 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
219 wxBitmap
*bm
= (wxBitmap
*)node
->GetData();
221 if (bm
->IsKindOf(CLASSINFO(wxIcon
)))
222 dc
.DrawIcon( * ((wxIcon
*) bm
), x
, y
);
224 dc
.DrawBitmap( *bm
, x
, y
, (flags
& wxIMAGELIST_DRAW_TRANSPARENT
) > 0 );
229 #endif // __WXPALMOS__