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 #if defined(__VISAGECPP__)
79 //just can't do this in VisualAge now, with all this new Bitmap-Icon stuff
80 //so construct it from a bitmap object until I can figure this nonsense out. (DW)
81 newBitmap
= new wxBitmap(bitmap
) ;
83 newBitmap
= new wxBitmap( (const wxIcon
&) bitmap
);
86 newBitmap
= new wxBitmap(bitmap
) ;
88 if (index
== m_images
.Number()-1)
90 m_images
.DeleteNode( node
);
91 m_images
.Append( newBitmap
);
95 wxNode
*next
= node
->Next();
96 m_images
.DeleteNode( node
);
97 m_images
.Insert( next
, newBitmap
);
103 bool wxImageList::Remove( int index
)
105 wxNode
*node
= m_images
.Nth( index
);
107 wxCHECK_MSG( node
, FALSE
, wxT("wrong index in image list") );
109 m_images
.DeleteNode( node
);
114 bool wxImageList::RemoveAll()
121 bool wxImageList::GetSize( int index
, int &width
, int &height
) const
126 wxNode
*node
= m_images
.Nth( index
);
128 wxCHECK_MSG( node
, FALSE
, wxT("wrong index in image list") );
130 wxBitmap
*bm
= (wxBitmap
*)node
->Data();
131 width
= bm
->GetWidth();
132 height
= bm
->GetHeight();
137 bool wxImageList::Draw( int index
, wxDC
&dc
, int x
, int y
,
138 int flags
, bool WXUNUSED(solidBackground
) )
140 wxNode
*node
= m_images
.Nth( index
);
142 wxCHECK_MSG( node
, FALSE
, wxT("wrong index in image list") );
144 wxBitmap
*bm
= (wxBitmap
*)node
->Data();
146 if (bm
->IsKindOf(CLASSINFO(wxIcon
)))
147 dc
.DrawIcon( * ((wxIcon
*) bm
), x
, y
);
149 dc
.DrawBitmap( *bm
, x
, y
, (flags
& wxIMAGELIST_DRAW_TRANSPARENT
) > 0 );