1 /////////////////////////////////////////////////////////////////////////////
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"
23 //-----------------------------------------------------------------------------
25 //-----------------------------------------------------------------------------
27 IMPLEMENT_DYNAMIC_CLASS(wxImageList
, wxObject
)
29 wxImageList::wxImageList( int width
, int height
, bool WXUNUSED(mask
), int WXUNUSED(initialCount
) )
36 wxImageList::~wxImageList()
40 int wxImageList::GetImageCount() const
42 return m_images
.Number();
45 bool wxImageList::Create()
47 m_images
.DeleteContents( TRUE
);
51 int wxImageList::Add( const wxBitmap
&bitmap
)
53 if (bitmap
.IsKindOf(CLASSINFO(wxIcon
)))
54 m_images
.Append( new wxIcon( (const wxIcon
&) bitmap
) );
56 m_images
.Append( new wxBitmap(bitmap
) );
57 return m_images
.Number();
60 const wxBitmap
*wxImageList::GetBitmap( int index
) const
62 wxNode
*node
= m_images
.Nth( index
);
64 wxCHECK_MSG( node
, (wxBitmap
*) NULL
, _T("wrong index in image list") );
66 return (wxBitmap
*)node
->Data();
69 bool wxImageList::Replace( int index
, const wxBitmap
&bitmap
)
71 wxNode
*node
= m_images
.Nth( index
);
73 wxCHECK_MSG( node
, FALSE
, _T("wrong index in image list") );
75 wxBitmap
* newBitmap
= NULL
;
76 if (bitmap
.IsKindOf(CLASSINFO(wxIcon
)))
77 newBitmap
= new wxIcon( (const wxIcon
&) bitmap
);
79 newBitmap
= new wxBitmap(bitmap
) ;
81 if (index
== m_images
.Number()-1)
83 m_images
.DeleteNode( node
);
84 m_images
.Append( newBitmap
);
88 wxNode
*next
= node
->Next();
89 m_images
.DeleteNode( node
);
90 m_images
.Insert( next
, newBitmap
);
96 bool wxImageList::Remove( int index
)
98 wxNode
*node
= m_images
.Nth( index
);
100 wxCHECK_MSG( node
, FALSE
, _T("wrong index in image list") );
102 m_images
.DeleteNode( node
);
107 bool wxImageList::RemoveAll()
114 bool wxImageList::GetSize( int index
, int &width
, int &height
) const
119 wxNode
*node
= m_images
.Nth( index
);
121 wxCHECK_MSG( node
, FALSE
, _T("wrong index in image list") );
123 wxBitmap
*bm
= (wxBitmap
*)node
->Data();
124 width
= bm
->GetWidth();
125 height
= bm
->GetHeight();
130 bool wxImageList::Draw( int index
, wxDC
&dc
, int x
, int y
,
131 int flags
, bool WXUNUSED(solidBackground
) )
133 wxNode
*node
= m_images
.Nth( index
);
135 wxCHECK_MSG( node
, FALSE
, _T("wrong index in image list") );
137 wxBitmap
*bm
= (wxBitmap
*)node
->Data();
139 if (bm
->IsKindOf(CLASSINFO(wxIcon
)))
140 dc
.DrawIcon( * ((wxIcon
*) bm
), x
, y
);
142 dc
.DrawBitmap( *bm
, x
, y
, (flags
& wxIMAGELIST_DRAW_TRANSPARENT
) > 0 );