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"
27 #include "wx/generic/imaglist.h"
33 //-----------------------------------------------------------------------------
35 //-----------------------------------------------------------------------------
37 IMPLEMENT_DYNAMIC_CLASS(wxGenericImageList
, wxObject
)
39 #if !defined(__WXMSW__) || defined(__WXUNIVERSAL__)
41 * wxImageList has to be a real class or we have problems with
42 * the run-time information.
45 IMPLEMENT_DYNAMIC_CLASS(wxImageList
, wxGenericImageList
)
48 wxGenericImageList::wxGenericImageList( int width
, int height
, bool mask
, int initialCount
)
50 (void)Create(width
, height
, mask
, initialCount
);
53 wxGenericImageList::~wxGenericImageList()
58 int wxGenericImageList::GetImageCount() const
60 return m_images
.GetCount();
63 bool wxGenericImageList::Create( int width
, int height
, bool WXUNUSED(mask
), int WXUNUSED(initialCount
) )
71 bool wxGenericImageList::Create()
76 int wxGenericImageList::Add( const wxBitmap
&bitmap
)
78 wxASSERT_MSG( (bitmap
.GetWidth() == m_width
&& bitmap
.GetHeight() == m_height
)
79 || (m_width
== 0 && m_height
== 0),
80 _T("invalid bitmap size in wxImageList: this might work ")
81 _T("on this platform but definitely won't under Windows.") );
83 if (bitmap
.IsKindOf(CLASSINFO(wxIcon
)))
84 m_images
.Append( new wxIcon( (const wxIcon
&) bitmap
) );
86 m_images
.Append( new wxBitmap(bitmap
) );
88 if (m_width
== 0 && m_height
== 0)
90 m_width
= bitmap
.GetWidth();
91 m_height
= bitmap
.GetHeight();
94 return m_images
.GetCount()-1;
97 int wxGenericImageList::Add( const wxBitmap
& bitmap
, const wxBitmap
& mask
)
101 bmp
.SetMask(new wxMask(mask
));
105 int wxGenericImageList::Add( const wxBitmap
& bitmap
, const wxColour
& maskColour
)
107 wxImage img
= bitmap
.ConvertToImage();
108 img
.SetMaskColour(maskColour
.Red(), maskColour
.Green(), maskColour
.Blue());
109 return Add(wxBitmap(img
));
112 const wxBitmap
*wxGenericImageList::GetBitmapPtr( int index
) const
114 wxList::compatibility_iterator node
= m_images
.Item( index
);
116 wxCHECK_MSG( node
, (wxBitmap
*) NULL
, wxT("wrong index in image list") );
118 return (wxBitmap
*)node
->GetData();
122 wxBitmap
wxGenericImageList::GetBitmap(int index
) const
124 const wxBitmap
* bmp
= GetBitmapPtr(index
);
132 wxIcon
wxGenericImageList::GetIcon(int index
) const
134 const wxBitmap
* bmp
= GetBitmapPtr(index
);
138 icon
.CopyFromBitmap(*bmp
);
145 bool wxGenericImageList::Replace( int index
, const wxBitmap
&bitmap
)
147 wxList::compatibility_iterator node
= m_images
.Item( index
);
149 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
151 wxBitmap
* newBitmap
= (bitmap
.IsKindOf(CLASSINFO(wxIcon
))) ?
152 #if defined(__VISAGECPP__)
153 //just can't do this in VisualAge now, with all this new Bitmap-Icon stuff
154 //so construct it from a bitmap object until I can figure this nonsense out. (DW)
157 new wxBitmap( (const wxIcon
&) bitmap
)
159 : new wxBitmap(bitmap
) ;
161 if (index
== (int) m_images
.GetCount() - 1)
163 delete node
->GetData();
164 m_images
.Erase( node
);
165 m_images
.Append( newBitmap
);
169 wxList::compatibility_iterator next
= node
->GetNext();
170 delete node
->GetData();
171 m_images
.Erase( node
);
172 m_images
.Insert( next
, newBitmap
);
178 bool wxGenericImageList::Remove( int index
)
180 wxList::compatibility_iterator node
= m_images
.Item( index
);
182 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
184 delete node
->GetData();
185 m_images
.Erase( node
);
190 bool wxGenericImageList::RemoveAll()
192 WX_CLEAR_LIST(wxList
, m_images
);
198 bool wxGenericImageList::GetSize( int index
, int &width
, int &height
) const
203 wxList::compatibility_iterator node
= m_images
.Item( index
);
205 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
207 wxBitmap
*bm
= (wxBitmap
*)node
->GetData();
208 width
= bm
->GetWidth();
209 height
= bm
->GetHeight();
214 bool wxGenericImageList::Draw( int index
, wxDC
&dc
, int x
, int y
,
215 int flags
, bool WXUNUSED(solidBackground
) )
217 wxList::compatibility_iterator node
= m_images
.Item( index
);
219 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
221 wxBitmap
*bm
= (wxBitmap
*)node
->GetData();
223 if (bm
->IsKindOf(CLASSINFO(wxIcon
)))
224 dc
.DrawIcon( * ((wxIcon
*) bm
), x
, y
);
226 dc
.DrawBitmap( *bm
, x
, y
, (flags
& wxIMAGELIST_DRAW_TRANSPARENT
) > 0 );
231 #endif // wxUSE_IMAGLIST
232 #endif // __WXPALMOS__