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"
24 //-----------------------------------------------------------------------------
26 //-----------------------------------------------------------------------------
28 IMPLEMENT_DYNAMIC_CLASS(wxImageList
, wxObject
)
30 wxImageList::wxImageList( int width
, int height
, bool WXUNUSED(mask
), int WXUNUSED(initialCount
) )
37 wxImageList::~wxImageList()
41 int wxImageList::GetImageCount() const
43 return m_images
.Number();
46 bool wxImageList::Create()
48 m_images
.DeleteContents( TRUE
);
52 int wxImageList::Add( const wxBitmap
&bitmap
)
54 if (bitmap
.IsKindOf(CLASSINFO(wxIcon
)))
55 m_images
.Append( new wxIcon( (const wxIcon
&) bitmap
) );
57 m_images
.Append( new wxBitmap(bitmap
) );
58 return m_images
.Number()-1;
61 const wxBitmap
*wxImageList::GetBitmap( int index
) const
63 wxNode
*node
= m_images
.Nth( index
);
65 wxCHECK_MSG( node
, (wxBitmap
*) NULL
, wxT("wrong index in image list") );
67 return (wxBitmap
*)node
->Data();
70 bool wxImageList::Replace( int index
, const wxBitmap
&bitmap
)
72 wxNode
*node
= m_images
.Nth( index
);
74 wxCHECK_MSG( node
, FALSE
, wxT("wrong index in image list") );
76 wxBitmap
* newBitmap
= NULL
;
77 if (bitmap
.IsKindOf(CLASSINFO(wxIcon
)))
78 newBitmap
= new wxIcon( (const wxIcon
&) bitmap
);
80 newBitmap
= new wxBitmap(bitmap
) ;
82 if (index
== m_images
.Number()-1)
84 m_images
.DeleteNode( node
);
85 m_images
.Append( newBitmap
);
89 wxNode
*next
= node
->Next();
90 m_images
.DeleteNode( node
);
91 m_images
.Insert( next
, newBitmap
);
97 bool wxImageList::Remove( int index
)
99 wxNode
*node
= m_images
.Nth( index
);
101 wxCHECK_MSG( node
, FALSE
, wxT("wrong index in image list") );
103 m_images
.DeleteNode( node
);
108 bool wxImageList::RemoveAll()
115 bool wxImageList::GetSize( int index
, int &width
, int &height
) const
120 wxNode
*node
= m_images
.Nth( index
);
122 wxCHECK_MSG( node
, FALSE
, wxT("wrong index in image list") );
124 wxBitmap
*bm
= (wxBitmap
*)node
->Data();
125 width
= bm
->GetWidth();
126 height
= bm
->GetHeight();
131 bool wxImageList::Draw( int index
, wxDC
&dc
, int x
, int y
,
132 int flags
, bool WXUNUSED(solidBackground
) )
134 wxNode
*node
= m_images
.Nth( index
);
136 wxCHECK_MSG( node
, FALSE
, wxT("wrong index in image list") );
138 wxBitmap
*bm
= (wxBitmap
*)node
->Data();
140 if (bm
->IsKindOf(CLASSINFO(wxIcon
)))
141 dc
.DrawIcon( * ((wxIcon
*) bm
), x
, y
);
143 dc
.DrawBitmap( *bm
, x
, y
, (flags
& wxIMAGELIST_DRAW_TRANSPARENT
) > 0 );