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"
30 //-----------------------------------------------------------------------------
32 //-----------------------------------------------------------------------------
34 IMPLEMENT_DYNAMIC_CLASS(wxGenericImageList
, wxObject
)
36 #if !defined(__WXMSW__) || defined(__WXUNIVERSAL__)
38 * wxImageList has to be a real class or we have problems with
39 * the run-time information.
42 IMPLEMENT_DYNAMIC_CLASS(wxImageList
, wxGenericImageList
)
45 wxGenericImageList::wxGenericImageList( int width
, int height
, bool mask
, int initialCount
)
47 (void)Create(width
, height
, mask
, initialCount
);
50 wxGenericImageList::~wxGenericImageList()
55 int wxGenericImageList::GetImageCount() const
57 return m_images
.GetCount();
60 bool wxGenericImageList::Create( int width
, int height
, bool WXUNUSED(mask
), int WXUNUSED(initialCount
) )
68 bool wxGenericImageList::Create()
73 int wxGenericImageList::Add( const wxBitmap
&bitmap
)
75 wxASSERT_MSG( (bitmap
.GetWidth() >= m_width
&& bitmap
.GetHeight() == m_height
)
76 || (m_width
== 0 && m_height
== 0),
77 _T("invalid bitmap size in wxImageList: this might work ")
78 _T("on this platform but definitely won't under Windows.") );
80 if (bitmap
.IsKindOf(CLASSINFO(wxIcon
)))
82 m_images
.Append( new wxIcon( (const wxIcon
&) bitmap
) );
86 // Mimic behavior of Windows ImageList_Add that automatically breaks up the added
87 // bitmap into sub-images of the correct size
88 if (m_width
> 0 && bitmap
.GetWidth() > m_width
&& bitmap
.GetHeight() >= m_height
)
90 int numImages
= bitmap
.GetWidth() / m_width
;
91 for (int subIndex
= 0; subIndex
< numImages
; subIndex
++)
93 wxRect
rect(m_width
* subIndex
, 0, m_width
, m_height
);
94 wxBitmap tmpBmp
= bitmap
.GetSubBitmap(rect
);
95 m_images
.Append( new wxBitmap(tmpBmp
) );
100 m_images
.Append( new wxBitmap(bitmap
) );
104 if (m_width
== 0 && m_height
== 0)
106 m_width
= bitmap
.GetWidth();
107 m_height
= bitmap
.GetHeight();
110 return m_images
.GetCount()-1;
113 int wxGenericImageList::Add( const wxBitmap
& bitmap
, const wxBitmap
& mask
)
115 wxBitmap
bmp(bitmap
);
117 bmp
.SetMask(new wxMask(mask
));
121 int wxGenericImageList::Add( const wxBitmap
& bitmap
, const wxColour
& maskColour
)
123 wxImage img
= bitmap
.ConvertToImage();
124 img
.SetMaskColour(maskColour
.Red(), maskColour
.Green(), maskColour
.Blue());
125 return Add(wxBitmap(img
));
128 const wxBitmap
*wxGenericImageList::GetBitmapPtr( int index
) const
130 wxList::compatibility_iterator node
= m_images
.Item( index
);
132 wxCHECK_MSG( node
, (wxBitmap
*) NULL
, wxT("wrong index in image list") );
134 return (wxBitmap
*)node
->GetData();
138 wxBitmap
wxGenericImageList::GetBitmap(int index
) const
140 const wxBitmap
* bmp
= GetBitmapPtr(index
);
148 wxIcon
wxGenericImageList::GetIcon(int index
) const
150 const wxBitmap
* bmp
= GetBitmapPtr(index
);
154 icon
.CopyFromBitmap(*bmp
);
161 bool wxGenericImageList::Replace( int index
, const wxBitmap
&bitmap
)
163 wxList::compatibility_iterator node
= m_images
.Item( index
);
165 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
167 wxBitmap
* newBitmap
= (bitmap
.IsKindOf(CLASSINFO(wxIcon
))) ?
168 #if defined(__VISAGECPP__)
169 //just can't do this in VisualAge now, with all this new Bitmap-Icon stuff
170 //so construct it from a bitmap object until I can figure this nonsense out. (DW)
173 new wxBitmap( (const wxIcon
&) bitmap
)
175 : new wxBitmap(bitmap
) ;
177 if (index
== (int) m_images
.GetCount() - 1)
179 delete node
->GetData();
180 m_images
.Erase( node
);
181 m_images
.Append( newBitmap
);
185 wxList::compatibility_iterator next
= node
->GetNext();
186 delete node
->GetData();
187 m_images
.Erase( node
);
188 m_images
.Insert( next
, newBitmap
);
194 bool wxGenericImageList::Replace( int index
, const wxBitmap
&bitmap
, const wxBitmap
&mask
)
196 wxList::compatibility_iterator node
= m_images
.Item( index
);
198 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
200 wxBitmap
* newBitmap
= (bitmap
.IsKindOf(CLASSINFO(wxIcon
))) ?
201 #if defined(__VISAGECPP__)
202 //just can't do this in VisualAge now, with all this new Bitmap-Icon stuff
203 //so construct it from a bitmap object until I can figure this nonsense out. (DW)
206 new wxBitmap( (const wxIcon
&) bitmap
)
208 : new wxBitmap(bitmap
) ;
210 if (index
== (int) m_images
.GetCount() - 1)
212 delete node
->GetData();
213 m_images
.Erase( node
);
214 m_images
.Append( newBitmap
);
218 wxList::compatibility_iterator next
= node
->GetNext();
219 delete node
->GetData();
220 m_images
.Erase( node
);
221 m_images
.Insert( next
, newBitmap
);
225 newBitmap
->SetMask(new wxMask(mask
));
230 bool wxGenericImageList::Remove( int index
)
232 wxList::compatibility_iterator node
= m_images
.Item( index
);
234 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
236 delete node
->GetData();
237 m_images
.Erase( node
);
242 bool wxGenericImageList::RemoveAll()
244 WX_CLEAR_LIST(wxList
, m_images
);
250 bool wxGenericImageList::GetSize( int index
, int &width
, int &height
) const
255 wxList::compatibility_iterator node
= m_images
.Item( index
);
257 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
259 wxBitmap
*bm
= (wxBitmap
*)node
->GetData();
260 width
= bm
->GetWidth();
261 height
= bm
->GetHeight();
266 bool wxGenericImageList::Draw( int index
, wxDC
&dc
, int x
, int y
,
267 int flags
, bool WXUNUSED(solidBackground
) )
269 wxList::compatibility_iterator node
= m_images
.Item( index
);
271 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
273 wxBitmap
*bm
= (wxBitmap
*)node
->GetData();
275 if (bm
->IsKindOf(CLASSINFO(wxIcon
)))
276 dc
.DrawIcon( * ((wxIcon
*) bm
), x
, y
);
278 dc
.DrawBitmap( *bm
, x
, y
, (flags
& wxIMAGELIST_DRAW_TRANSPARENT
) > 0 );
283 #endif // __WXPALMOS__
285 #endif // wxUSE_IMAGLIST