1 /////////////////////////////////////////////////////////////////////////////
2 // Name: generic/imaglist.cpp
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "imaglist.h"
14 // For compilers that support precompilation, includes "wx.h".
15 #include "wx/wxprec.h"
21 #include "wx/generic/imaglist.h"
26 //-----------------------------------------------------------------------------
28 //-----------------------------------------------------------------------------
30 IMPLEMENT_DYNAMIC_CLASS(wxGenericImageList
, wxObject
)
32 #if !defined(__WXMSW__) || defined(__WIN16__) || defined(__WXUNIVERSAL__)
34 * wxImageList has to be a real class or we have problems with
35 * the run-time information.
38 IMPLEMENT_DYNAMIC_CLASS(wxImageList
, wxGenericImageList
)
41 wxGenericImageList::wxGenericImageList( int width
, int height
, bool mask
, int initialCount
)
43 (void)Create(width
, height
, mask
, initialCount
);
46 wxGenericImageList::~wxGenericImageList()
50 int wxGenericImageList::GetImageCount() const
52 return m_images
.GetCount();
55 bool wxGenericImageList::Create( int width
, int height
, bool WXUNUSED(mask
), int WXUNUSED(initialCount
) )
63 bool wxGenericImageList::Create()
68 int wxGenericImageList::Add( const wxBitmap
&bitmap
)
70 if (bitmap
.IsKindOf(CLASSINFO(wxIcon
)))
71 m_images
.Append( new wxIcon( (const wxIcon
&) bitmap
) );
73 m_images
.Append( new wxBitmap(bitmap
) );
74 return m_images
.GetCount()-1;
77 int wxGenericImageList::Add( const wxBitmap
& bitmap
, const wxBitmap
& mask
)
81 bmp
.SetMask(new wxMask(mask
));
85 int wxGenericImageList::Add( const wxBitmap
& bitmap
, const wxColour
& maskColour
)
87 wxImage img
= bitmap
.ConvertToImage();
88 img
.SetMaskColour(maskColour
.Red(), maskColour
.Green(), maskColour
.Blue());
89 return Add(wxBitmap(img
));
92 const wxBitmap
*wxGenericImageList::GetBitmap( int index
) const
94 wxList::compatibility_iterator node
= m_images
.Item( index
);
96 wxCHECK_MSG( node
, (wxBitmap
*) NULL
, wxT("wrong index in image list") );
98 return (wxBitmap
*)node
->GetData();
101 bool wxGenericImageList::Replace( int index
, const wxBitmap
&bitmap
)
103 wxList::compatibility_iterator node
= m_images
.Item( index
);
105 wxCHECK_MSG( node
, FALSE
, wxT("wrong index in image list") );
107 wxBitmap
* newBitmap
= NULL
;
108 if (bitmap
.IsKindOf(CLASSINFO(wxIcon
)))
109 #if defined(__VISAGECPP__)
110 //just can't do this in VisualAge now, with all this new Bitmap-Icon stuff
111 //so construct it from a bitmap object until I can figure this nonsense out. (DW)
112 newBitmap
= new wxBitmap(bitmap
) ;
114 newBitmap
= new wxBitmap( (const wxIcon
&) bitmap
);
117 newBitmap
= new wxBitmap(bitmap
) ;
119 if (index
== (int) m_images
.GetCount() - 1)
121 delete node
->GetData();
122 m_images
.Erase( node
);
123 m_images
.Append( newBitmap
);
127 wxList::compatibility_iterator next
= node
->GetNext();
128 delete node
->GetData();
129 m_images
.Erase( node
);
130 m_images
.Insert( next
, newBitmap
);
136 bool wxGenericImageList::Remove( int index
)
138 wxList::compatibility_iterator node
= m_images
.Item( index
);
140 wxCHECK_MSG( node
, FALSE
, wxT("wrong index in image list") );
142 delete node
->GetData();
143 m_images
.Erase( node
);
148 bool wxGenericImageList::RemoveAll()
150 WX_CLEAR_LIST(wxList
, m_images
);
156 bool wxGenericImageList::GetSize( int index
, int &width
, int &height
) const
161 wxList::compatibility_iterator node
= m_images
.Item( index
);
163 wxCHECK_MSG( node
, FALSE
, wxT("wrong index in image list") );
165 wxBitmap
*bm
= (wxBitmap
*)node
->GetData();
166 width
= bm
->GetWidth();
167 height
= bm
->GetHeight();
172 bool wxGenericImageList::Draw( int index
, wxDC
&dc
, int x
, int y
,
173 int flags
, bool WXUNUSED(solidBackground
) )
175 wxList::compatibility_iterator node
= m_images
.Item( index
);
177 wxCHECK_MSG( node
, FALSE
, wxT("wrong index in image list") );
179 wxBitmap
*bm
= (wxBitmap
*)node
->GetData();
181 if (bm
->IsKindOf(CLASSINFO(wxIcon
)))
182 dc
.DrawIcon( * ((wxIcon
*) bm
), x
, y
);
184 dc
.DrawBitmap( *bm
, x
, y
, (flags
& wxIMAGELIST_DRAW_TRANSPARENT
) > 0 );