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
)))
79 m_images
.Append( new wxIcon( (const wxIcon
&) bitmap
) );
83 // Mimic behavior of Windows ImageList_Add that automatically breaks up the added
84 // bitmap into sub-images of the correct size
85 if (m_width
> 0 && bitmap
.GetWidth() > m_width
&& bitmap
.GetHeight() >= m_height
)
87 int numImages
= bitmap
.GetWidth() / m_width
;
88 for (int subIndex
= 0; subIndex
< numImages
; subIndex
++)
90 wxRect
rect(m_width
* subIndex
, 0, m_width
, m_height
);
91 wxBitmap tmpBmp
= bitmap
.GetSubBitmap(rect
);
92 m_images
.Append( new wxBitmap(tmpBmp
) );
97 m_images
.Append( new wxBitmap(bitmap
) );
101 if (m_width
== 0 && m_height
== 0)
103 m_width
= bitmap
.GetWidth();
104 m_height
= bitmap
.GetHeight();
107 return m_images
.GetCount()-1;
110 int wxGenericImageList::Add( const wxBitmap
& bitmap
, const wxBitmap
& mask
)
112 wxBitmap
bmp(bitmap
);
114 bmp
.SetMask(new wxMask(mask
));
118 int wxGenericImageList::Add( const wxBitmap
& bitmap
, const wxColour
& maskColour
)
120 wxImage img
= bitmap
.ConvertToImage();
121 img
.SetMaskColour(maskColour
.Red(), maskColour
.Green(), maskColour
.Blue());
122 return Add(wxBitmap(img
));
125 const wxBitmap
*wxGenericImageList::GetBitmapPtr( int index
) const
127 wxList::compatibility_iterator node
= m_images
.Item( index
);
129 wxCHECK_MSG( node
, (wxBitmap
*) NULL
, wxT("wrong index in image list") );
131 return (wxBitmap
*)node
->GetData();
135 wxBitmap
wxGenericImageList::GetBitmap(int index
) const
137 const wxBitmap
* bmp
= GetBitmapPtr(index
);
145 wxIcon
wxGenericImageList::GetIcon(int index
) const
147 const wxBitmap
* bmp
= GetBitmapPtr(index
);
151 icon
.CopyFromBitmap(*bmp
);
158 bool wxGenericImageList::Replace( int index
, const wxBitmap
&bitmap
)
160 wxList::compatibility_iterator node
= m_images
.Item( index
);
162 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
164 wxBitmap
* newBitmap
= (bitmap
.IsKindOf(CLASSINFO(wxIcon
))) ?
165 #if defined(__VISAGECPP__)
166 //just can't do this in VisualAge now, with all this new Bitmap-Icon stuff
167 //so construct it from a bitmap object until I can figure this nonsense out. (DW)
170 new wxBitmap( (const wxIcon
&) bitmap
)
172 : new wxBitmap(bitmap
) ;
174 if (index
== (int) m_images
.GetCount() - 1)
176 delete node
->GetData();
177 m_images
.Erase( node
);
178 m_images
.Append( newBitmap
);
182 wxList::compatibility_iterator next
= node
->GetNext();
183 delete node
->GetData();
184 m_images
.Erase( node
);
185 m_images
.Insert( next
, newBitmap
);
191 bool wxGenericImageList::Replace( int index
, const wxBitmap
&bitmap
, const wxBitmap
&mask
)
193 wxList::compatibility_iterator node
= m_images
.Item( index
);
195 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
197 wxBitmap
* newBitmap
= (bitmap
.IsKindOf(CLASSINFO(wxIcon
))) ?
198 #if defined(__VISAGECPP__)
199 //just can't do this in VisualAge now, with all this new Bitmap-Icon stuff
200 //so construct it from a bitmap object until I can figure this nonsense out. (DW)
203 new wxBitmap( (const wxIcon
&) bitmap
)
205 : new wxBitmap(bitmap
) ;
207 if (index
== (int) m_images
.GetCount() - 1)
209 delete node
->GetData();
210 m_images
.Erase( node
);
211 m_images
.Append( newBitmap
);
215 wxList::compatibility_iterator next
= node
->GetNext();
216 delete node
->GetData();
217 m_images
.Erase( node
);
218 m_images
.Insert( next
, newBitmap
);
222 newBitmap
->SetMask(new wxMask(mask
));
227 bool wxGenericImageList::Remove( int index
)
229 wxList::compatibility_iterator node
= m_images
.Item( index
);
231 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
233 delete node
->GetData();
234 m_images
.Erase( node
);
239 bool wxGenericImageList::RemoveAll()
241 WX_CLEAR_LIST(wxList
, m_images
);
247 bool wxGenericImageList::GetSize( int index
, int &width
, int &height
) const
252 wxList::compatibility_iterator node
= m_images
.Item( index
);
254 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
256 wxBitmap
*bm
= (wxBitmap
*)node
->GetData();
257 width
= bm
->GetWidth();
258 height
= bm
->GetHeight();
263 bool wxGenericImageList::Draw( int index
, wxDC
&dc
, int x
, int y
,
264 int flags
, bool WXUNUSED(solidBackground
) )
266 wxList::compatibility_iterator node
= m_images
.Item( index
);
268 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
270 wxBitmap
*bm
= (wxBitmap
*)node
->GetData();
272 if (bm
->IsKindOf(CLASSINFO(wxIcon
)))
273 dc
.DrawIcon( * ((wxIcon
*) bm
), x
, y
);
275 dc
.DrawBitmap( *bm
, x
, y
, (flags
& wxIMAGELIST_DRAW_TRANSPARENT
) > 0 );
280 #endif // wxUSE_IMAGLIST
281 #endif // __WXPALMOS__