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"
29 //-----------------------------------------------------------------------------
31 //-----------------------------------------------------------------------------
33 IMPLEMENT_DYNAMIC_CLASS(wxGenericImageList
, wxObject
)
35 #if !defined(__WXMSW__) || defined(__WXUNIVERSAL__)
37 * wxImageList has to be a real class or we have problems with
38 * the run-time information.
41 IMPLEMENT_DYNAMIC_CLASS(wxImageList
, wxGenericImageList
)
44 wxGenericImageList::wxGenericImageList( int width
, int height
, bool mask
, int initialCount
)
46 (void)Create(width
, height
, mask
, initialCount
);
49 wxGenericImageList::~wxGenericImageList()
54 int wxGenericImageList::GetImageCount() const
56 return m_images
.GetCount();
59 bool wxGenericImageList::Create( int width
, int height
, bool WXUNUSED(mask
), int WXUNUSED(initialCount
) )
67 bool wxGenericImageList::Create()
72 int wxGenericImageList::Add( const wxBitmap
&bitmap
)
74 wxASSERT_MSG( (bitmap
.GetWidth() >= m_width
&& bitmap
.GetHeight() == m_height
)
75 || (m_width
== 0 && m_height
== 0),
76 _T("invalid bitmap size in wxImageList: this might work ")
77 _T("on this platform but definitely won't under Windows.") );
79 if (bitmap
.IsKindOf(CLASSINFO(wxIcon
)))
81 m_images
.Append( new wxIcon( (const wxIcon
&) bitmap
) );
85 // Mimic behavior of Windows ImageList_Add that automatically breaks up the added
86 // bitmap into sub-images of the correct size
87 if (m_width
> 0 && bitmap
.GetWidth() > m_width
&& bitmap
.GetHeight() >= m_height
)
89 int numImages
= bitmap
.GetWidth() / m_width
;
90 for (int subIndex
= 0; subIndex
< numImages
; subIndex
++)
92 wxRect
rect(m_width
* subIndex
, 0, m_width
, m_height
);
93 wxBitmap tmpBmp
= bitmap
.GetSubBitmap(rect
);
94 m_images
.Append( new wxBitmap(tmpBmp
) );
99 m_images
.Append( new wxBitmap(bitmap
) );
103 if (m_width
== 0 && m_height
== 0)
105 m_width
= bitmap
.GetWidth();
106 m_height
= bitmap
.GetHeight();
109 return m_images
.GetCount()-1;
112 int wxGenericImageList::Add( const wxBitmap
& bitmap
, const wxBitmap
& mask
)
114 wxBitmap
bmp(bitmap
);
116 bmp
.SetMask(new wxMask(mask
));
120 int wxGenericImageList::Add( const wxBitmap
& bitmap
, const wxColour
& maskColour
)
122 wxImage img
= bitmap
.ConvertToImage();
123 img
.SetMaskColour(maskColour
.Red(), maskColour
.Green(), maskColour
.Blue());
124 return Add(wxBitmap(img
));
127 const wxBitmap
*wxGenericImageList::GetBitmapPtr( int index
) const
129 wxList::compatibility_iterator node
= m_images
.Item( index
);
131 wxCHECK_MSG( node
, (wxBitmap
*) NULL
, wxT("wrong index in image list") );
133 return (wxBitmap
*)node
->GetData();
137 wxBitmap
wxGenericImageList::GetBitmap(int index
) const
139 const wxBitmap
* bmp
= GetBitmapPtr(index
);
147 wxIcon
wxGenericImageList::GetIcon(int index
) const
149 const wxBitmap
* bmp
= GetBitmapPtr(index
);
153 icon
.CopyFromBitmap(*bmp
);
160 bool wxGenericImageList::Replace( int index
, const wxBitmap
&bitmap
)
162 wxList::compatibility_iterator node
= m_images
.Item( index
);
164 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
166 wxBitmap
* newBitmap
= (bitmap
.IsKindOf(CLASSINFO(wxIcon
))) ?
167 #if defined(__VISAGECPP__)
168 //just can't do this in VisualAge now, with all this new Bitmap-Icon stuff
169 //so construct it from a bitmap object until I can figure this nonsense out. (DW)
172 new wxBitmap( (const wxIcon
&) bitmap
)
174 : new wxBitmap(bitmap
) ;
176 if (index
== (int) m_images
.GetCount() - 1)
178 delete node
->GetData();
179 m_images
.Erase( node
);
180 m_images
.Append( newBitmap
);
184 wxList::compatibility_iterator next
= node
->GetNext();
185 delete node
->GetData();
186 m_images
.Erase( node
);
187 m_images
.Insert( next
, newBitmap
);
193 bool wxGenericImageList::Replace( int index
, const wxBitmap
&bitmap
, const wxBitmap
&mask
)
195 wxList::compatibility_iterator node
= m_images
.Item( index
);
197 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
199 wxBitmap
* newBitmap
= (bitmap
.IsKindOf(CLASSINFO(wxIcon
))) ?
200 #if defined(__VISAGECPP__)
201 //just can't do this in VisualAge now, with all this new Bitmap-Icon stuff
202 //so construct it from a bitmap object until I can figure this nonsense out. (DW)
205 new wxBitmap( (const wxIcon
&) bitmap
)
207 : new wxBitmap(bitmap
) ;
209 if (index
== (int) m_images
.GetCount() - 1)
211 delete node
->GetData();
212 m_images
.Erase( node
);
213 m_images
.Append( newBitmap
);
217 wxList::compatibility_iterator next
= node
->GetNext();
218 delete node
->GetData();
219 m_images
.Erase( node
);
220 m_images
.Insert( next
, newBitmap
);
224 newBitmap
->SetMask(new wxMask(mask
));
229 bool wxGenericImageList::Remove( int index
)
231 wxList::compatibility_iterator node
= m_images
.Item( index
);
233 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
235 delete node
->GetData();
236 m_images
.Erase( node
);
241 bool wxGenericImageList::RemoveAll()
243 WX_CLEAR_LIST(wxList
, m_images
);
249 bool wxGenericImageList::GetSize( int index
, int &width
, int &height
) const
254 wxList::compatibility_iterator node
= m_images
.Item( index
);
256 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
258 wxBitmap
*bm
= (wxBitmap
*)node
->GetData();
259 width
= bm
->GetWidth();
260 height
= bm
->GetHeight();
265 bool wxGenericImageList::Draw( int index
, wxDC
&dc
, int x
, int y
,
266 int flags
, bool WXUNUSED(solidBackground
) )
268 wxList::compatibility_iterator node
= m_images
.Item( index
);
270 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
272 wxBitmap
*bm
= (wxBitmap
*)node
->GetData();
274 if (bm
->IsKindOf(CLASSINFO(wxIcon
)))
275 dc
.DrawIcon( * ((wxIcon
*) bm
), x
, y
);
277 dc
.DrawBitmap( *bm
, x
, y
, (flags
& wxIMAGELIST_DRAW_TRANSPARENT
) > 0 );
282 #endif // __WXPALMOS__
284 #endif // wxUSE_IMAGLIST