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"
17 #if wxUSE_IMAGLIST && !defined(wxHAS_NATIVE_IMAGELIST)
21 #include "wx/imaglist.h"
29 //-----------------------------------------------------------------------------
31 //-----------------------------------------------------------------------------
33 IMPLEMENT_DYNAMIC_CLASS(wxGenericImageList
, wxObject
)
34 IMPLEMENT_DYNAMIC_CLASS(wxImageList
, wxGenericImageList
)
36 wxGenericImageList::wxGenericImageList( int width
, int height
, bool mask
, int initialCount
)
38 (void)Create(width
, height
, mask
, initialCount
);
41 wxGenericImageList::~wxGenericImageList()
46 int wxGenericImageList::GetImageCount() const
48 return m_images
.GetCount();
51 bool wxGenericImageList::Create( int width
, int height
, bool WXUNUSED(mask
), int WXUNUSED(initialCount
) )
59 bool wxGenericImageList::Create()
64 int wxGenericImageList::Add( const wxBitmap
&bitmap
)
66 wxASSERT_MSG( (bitmap
.GetWidth() >= m_width
&& bitmap
.GetHeight() == m_height
)
67 || (m_width
== 0 && m_height
== 0),
68 wxT("invalid bitmap size in wxImageList: this might work ")
69 wxT("on this platform but definitely won't under Windows.") );
71 const int index
= int(m_images
.GetCount());
73 if (bitmap
.IsKindOf(CLASSINFO(wxIcon
)))
75 m_images
.Append( new wxIcon( (const wxIcon
&) bitmap
) );
79 // Mimic behavior of Windows ImageList_Add that automatically breaks up the added
80 // bitmap into sub-images of the correct size
81 if (m_width
> 0 && bitmap
.GetWidth() > m_width
&& bitmap
.GetHeight() >= m_height
)
83 int numImages
= bitmap
.GetWidth() / m_width
;
84 for (int subIndex
= 0; subIndex
< numImages
; subIndex
++)
86 wxRect
rect(m_width
* subIndex
, 0, m_width
, m_height
);
87 wxBitmap tmpBmp
= bitmap
.GetSubBitmap(rect
);
88 m_images
.Append( new wxBitmap(tmpBmp
) );
93 m_images
.Append( new wxBitmap(bitmap
) );
97 if (m_width
== 0 && m_height
== 0)
99 m_width
= bitmap
.GetWidth();
100 m_height
= bitmap
.GetHeight();
106 int wxGenericImageList::Add( const wxBitmap
& bitmap
, const wxBitmap
& mask
)
108 wxBitmap
bmp(bitmap
);
110 bmp
.SetMask(new wxMask(mask
));
114 int wxGenericImageList::Add( const wxBitmap
& bitmap
, const wxColour
& maskColour
)
116 wxImage img
= bitmap
.ConvertToImage();
117 img
.SetMaskColour(maskColour
.Red(), maskColour
.Green(), maskColour
.Blue());
118 return Add(wxBitmap(img
));
121 const wxBitmap
*wxGenericImageList::GetBitmapPtr( int index
) const
123 wxObjectList::compatibility_iterator node
= m_images
.Item( index
);
125 wxCHECK_MSG( node
, NULL
, wxT("wrong index in image list") );
127 return (wxBitmap
*)node
->GetData();
131 wxBitmap
wxGenericImageList::GetBitmap(int index
) const
133 const wxBitmap
* bmp
= GetBitmapPtr(index
);
141 wxIcon
wxGenericImageList::GetIcon(int index
) const
143 const wxBitmap
* bmp
= GetBitmapPtr(index
);
147 icon
.CopyFromBitmap(*bmp
);
154 bool wxGenericImageList::Replace( int index
, const wxBitmap
&bitmap
)
156 wxObjectList::compatibility_iterator node
= m_images
.Item( index
);
158 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
160 wxBitmap
* newBitmap
= (bitmap
.IsKindOf(CLASSINFO(wxIcon
))) ?
161 #if defined(__VISAGECPP__)
162 //just can't do this in VisualAge now, with all this new Bitmap-Icon stuff
163 //so construct it from a bitmap object until I can figure this nonsense out. (DW)
166 new wxBitmap( (const wxIcon
&) bitmap
)
168 : new wxBitmap(bitmap
) ;
170 if (index
== (int) m_images
.GetCount() - 1)
172 delete node
->GetData();
173 m_images
.Erase( node
);
174 m_images
.Append( newBitmap
);
178 wxObjectList::compatibility_iterator next
= node
->GetNext();
179 delete node
->GetData();
180 m_images
.Erase( node
);
181 m_images
.Insert( next
, newBitmap
);
187 bool wxGenericImageList::Replace( int index
, const wxBitmap
&bitmap
, const wxBitmap
&mask
)
189 wxObjectList::compatibility_iterator node
= m_images
.Item( index
);
191 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
193 wxBitmap
* newBitmap
= (bitmap
.IsKindOf(CLASSINFO(wxIcon
))) ?
194 #if defined(__VISAGECPP__)
195 //just can't do this in VisualAge now, with all this new Bitmap-Icon stuff
196 //so construct it from a bitmap object until I can figure this nonsense out. (DW)
199 new wxBitmap( (const wxIcon
&) bitmap
)
201 : new wxBitmap(bitmap
) ;
203 if (index
== (int) m_images
.GetCount() - 1)
205 delete node
->GetData();
206 m_images
.Erase( node
);
207 m_images
.Append( newBitmap
);
211 wxObjectList::compatibility_iterator next
= node
->GetNext();
212 delete node
->GetData();
213 m_images
.Erase( node
);
214 m_images
.Insert( next
, newBitmap
);
218 newBitmap
->SetMask(new wxMask(mask
));
223 bool wxGenericImageList::Remove( int index
)
225 wxObjectList::compatibility_iterator node
= m_images
.Item( index
);
227 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
229 delete node
->GetData();
230 m_images
.Erase( node
);
235 bool wxGenericImageList::RemoveAll()
237 WX_CLEAR_LIST(wxObjectList
, m_images
);
243 bool wxGenericImageList::GetSize( int index
, int &width
, int &height
) const
248 wxObjectList::compatibility_iterator node
= m_images
.Item( index
);
250 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
252 wxBitmap
*bm
= (wxBitmap
*)node
->GetData();
253 width
= bm
->GetWidth();
254 height
= bm
->GetHeight();
259 bool wxGenericImageList::Draw( int index
, wxDC
&dc
, int x
, int y
,
260 int flags
, bool WXUNUSED(solidBackground
) )
262 wxObjectList::compatibility_iterator node
= m_images
.Item( index
);
264 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
266 wxBitmap
*bm
= (wxBitmap
*)node
->GetData();
268 if (bm
->IsKindOf(CLASSINFO(wxIcon
)))
269 dc
.DrawIcon( * ((wxIcon
*) bm
), x
, y
);
271 dc
.DrawBitmap( *bm
, x
, y
, (flags
& wxIMAGELIST_DRAW_TRANSPARENT
) > 0 );
276 #endif // __WXPALMOS__
278 #endif // wxUSE_IMAGLIST