1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/imaglist.cpp
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
21 #include "wx/generic/imaglist.h"
27 //-----------------------------------------------------------------------------
29 //-----------------------------------------------------------------------------
31 IMPLEMENT_DYNAMIC_CLASS(wxGenericImageList
, wxObject
)
33 #if !defined(__WXMSW__) || defined(__WXUNIVERSAL__)
35 * wxImageList has to be a real class or we have problems with
36 * the run-time information.
39 IMPLEMENT_DYNAMIC_CLASS(wxImageList
, wxGenericImageList
)
42 wxGenericImageList::wxGenericImageList( int width
, int height
, bool mask
, int initialCount
)
44 (void)Create(width
, height
, mask
, initialCount
);
47 wxGenericImageList::~wxGenericImageList()
52 int wxGenericImageList::GetImageCount() const
54 return m_images
.GetCount();
57 bool wxGenericImageList::Create( int width
, int height
, bool WXUNUSED(mask
), int WXUNUSED(initialCount
) )
65 bool wxGenericImageList::Create()
70 int wxGenericImageList::Add( const wxBitmap
&bitmap
)
72 wxASSERT_MSG( (bitmap
.GetWidth() == m_width
&& bitmap
.GetHeight() == m_height
)
73 || (m_width
== 0 && m_height
== 0),
74 _T("invalid bitmap size in wxImageList: this might work ")
75 _T("on this platform but definitely won't under Windows.") );
77 if (bitmap
.IsKindOf(CLASSINFO(wxIcon
)))
78 m_images
.Append( new wxIcon( (const wxIcon
&) bitmap
) );
80 m_images
.Append( new wxBitmap(bitmap
) );
82 if (m_width
== 0 && m_height
== 0)
84 m_width
= bitmap
.GetWidth();
85 m_height
= bitmap
.GetHeight();
88 return m_images
.GetCount()-1;
91 int wxGenericImageList::Add( const wxBitmap
& bitmap
, const wxBitmap
& mask
)
95 bmp
.SetMask(new wxMask(mask
));
99 int wxGenericImageList::Add( const wxBitmap
& bitmap
, const wxColour
& maskColour
)
101 wxImage img
= bitmap
.ConvertToImage();
102 img
.SetMaskColour(maskColour
.Red(), maskColour
.Green(), maskColour
.Blue());
103 return Add(wxBitmap(img
));
106 const wxBitmap
*wxGenericImageList::GetBitmapPtr( int index
) const
108 wxList::compatibility_iterator node
= m_images
.Item( index
);
110 wxCHECK_MSG( node
, (wxBitmap
*) NULL
, wxT("wrong index in image list") );
112 return (wxBitmap
*)node
->GetData();
116 wxBitmap
wxGenericImageList::GetBitmap(int index
) const
118 const wxBitmap
* bmp
= GetBitmapPtr(index
);
126 wxIcon
wxGenericImageList::GetIcon(int index
) const
128 const wxBitmap
* bmp
= GetBitmapPtr(index
);
132 icon
.CopyFromBitmap(*bmp
);
139 bool wxGenericImageList::Replace( int index
, const wxBitmap
&bitmap
)
141 wxList::compatibility_iterator node
= m_images
.Item( index
);
143 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
145 wxBitmap
* newBitmap
= (bitmap
.IsKindOf(CLASSINFO(wxIcon
))) ?
146 #if defined(__VISAGECPP__)
147 //just can't do this in VisualAge now, with all this new Bitmap-Icon stuff
148 //so construct it from a bitmap object until I can figure this nonsense out. (DW)
151 new wxBitmap( (const wxIcon
&) bitmap
)
153 : new wxBitmap(bitmap
) ;
155 if (index
== (int) m_images
.GetCount() - 1)
157 delete node
->GetData();
158 m_images
.Erase( node
);
159 m_images
.Append( newBitmap
);
163 wxList::compatibility_iterator next
= node
->GetNext();
164 delete node
->GetData();
165 m_images
.Erase( node
);
166 m_images
.Insert( next
, newBitmap
);
172 bool wxGenericImageList::Remove( int index
)
174 wxList::compatibility_iterator node
= m_images
.Item( index
);
176 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
178 delete node
->GetData();
179 m_images
.Erase( node
);
184 bool wxGenericImageList::RemoveAll()
186 WX_CLEAR_LIST(wxList
, m_images
);
192 bool wxGenericImageList::GetSize( int index
, int &width
, int &height
) const
197 wxList::compatibility_iterator node
= m_images
.Item( index
);
199 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
201 wxBitmap
*bm
= (wxBitmap
*)node
->GetData();
202 width
= bm
->GetWidth();
203 height
= bm
->GetHeight();
208 bool wxGenericImageList::Draw( int index
, wxDC
&dc
, int x
, int y
,
209 int flags
, bool WXUNUSED(solidBackground
) )
211 wxList::compatibility_iterator node
= m_images
.Item( index
);
213 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
215 wxBitmap
*bm
= (wxBitmap
*)node
->GetData();
217 if (bm
->IsKindOf(CLASSINFO(wxIcon
)))
218 dc
.DrawIcon( * ((wxIcon
*) bm
), x
, y
);
220 dc
.DrawBitmap( *bm
, x
, y
, (flags
& wxIMAGELIST_DRAW_TRANSPARENT
) > 0 );
225 #endif // wxUSE_IMAGLIST
226 #endif // __WXPALMOS__