1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
7 // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
12 #pragma implementation "imaglist.h"
15 #include "wx/imaglist.h"
17 //-----------------------------------------------------------------------------
19 //-----------------------------------------------------------------------------
21 IMPLEMENT_DYNAMIC_CLASS(wxImageList
, wxObject
)
23 wxImageList::wxImageList( int width
, int height
, bool WXUNUSED(mask
), int WXUNUSED(initialCount
) )
30 wxImageList::~wxImageList()
34 int wxImageList::GetImageCount() const
36 return m_images
.Number();
39 bool wxImageList::Create()
41 m_images
.DeleteContents( TRUE
);
45 int wxImageList::Add( const wxBitmap
&bitmap
)
47 m_images
.Append( new wxBitmap(bitmap
) );
48 return m_images
.Number();
51 wxBitmap
*wxImageList::GetBitmap(int index
) {
52 wxNode
*node
= m_images
.Nth( index
);
53 return (wxBitmap
*)node
->Data();
56 bool wxImageList::Replace( int index
, const wxBitmap
&bitmap
)
58 wxNode
*node
= m_images
.Nth( index
);
59 if (!node
) return FALSE
;
61 if (index
== m_images
.Number()-1)
63 m_images
.DeleteNode( node
);
64 m_images
.Append( new wxBitmap(bitmap
) );
68 wxNode
*next
= node
->Next();
69 m_images
.DeleteNode( node
);
70 m_images
.Insert( next
, new wxBitmap(bitmap
) );
76 bool wxImageList::Remove( int index
)
78 wxNode
*node
= m_images
.Nth( index
);
79 if (node
) m_images
.DeleteNode( node
);
80 return (node
!= NULL
);
83 bool wxImageList::RemoveAll()
89 bool wxImageList::GetSize( int index
, int &width
, int &height
) const
96 return (m_images
.Nth( index
) != NULL
);
100 wxNode
*node
= m_images
.Nth( index
);
103 wxBitmap
*bm
= (wxBitmap
*)node
->Data();
104 width
= bm
->GetWidth();
105 height
= bm
->GetHeight();
118 bool wxImageList::Draw( int index
, wxDC
&dc
, int x
, int y
,
119 int flags
, bool WXUNUSED(solidBackground
) )
121 wxNode
*node
= m_images
.Nth( index
);
122 if (!node
) return FALSE
;
123 wxBitmap
*bm
= (wxBitmap
*)node
->Data();
127 // As X doesn't have a standard size for icons, we resize here.
128 // Otherwise we'd simply have to forbid different bitmap sizes.
130 if ((m_width
!= bm
->GetWidth()) ||
131 (m_height
!= bm
->GetHeight()))
133 bm
->Resize( m_width
, m_height
);
138 wxIcon
*icon
= (wxIcon
*)bm
;
139 dc
.DrawIcon( *icon
, x
, y
, (flags
& wxIMAGELIST_DRAW_TRANSPARENT
) > 0 );