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"
25 //-----------------------------------------------------------------------------
27 //-----------------------------------------------------------------------------
29 IMPLEMENT_DYNAMIC_CLASS(wxImageList
, wxObject
)
31 wxImageList::wxImageList( int width
, int height
, bool WXUNUSED(mask
), int WXUNUSED(initialCount
) )
38 wxImageList::~wxImageList()
42 int wxImageList::GetImageCount() const
44 return m_images
.Number();
47 bool wxImageList::Create()
49 m_images
.DeleteContents( TRUE
);
53 int wxImageList::Add( const wxBitmap
&bitmap
)
55 if (bitmap
.IsKindOf(CLASSINFO(wxIcon
)))
56 m_images
.Append( new wxIcon( (const wxIcon
&) bitmap
) );
58 m_images
.Append( new wxBitmap(bitmap
) );
59 return m_images
.Number()-1;
62 int wxImageList::Add( const wxBitmap
& bitmap
, const wxBitmap
& mask
)
65 bmp
.SetMask(new wxMask(mask
));
69 int wxImageList::Add( const wxBitmap
& bitmap
, const wxColour
& maskColour
)
72 img
.SetMaskColour(maskColour
.Red(), maskColour
.Green(), maskColour
.Blue());
73 return Add(img
.ConvertToBitmap());
76 const wxBitmap
*wxImageList::GetBitmap( int index
) const
78 wxNode
*node
= m_images
.Nth( index
);
80 wxCHECK_MSG( node
, (wxBitmap
*) NULL
, wxT("wrong index in image list") );
82 return (wxBitmap
*)node
->Data();
85 bool wxImageList::Replace( int index
, const wxBitmap
&bitmap
)
87 wxNode
*node
= m_images
.Nth( index
);
89 wxCHECK_MSG( node
, FALSE
, wxT("wrong index in image list") );
91 wxBitmap
* newBitmap
= NULL
;
92 if (bitmap
.IsKindOf(CLASSINFO(wxIcon
)))
93 #if defined(__VISAGECPP__)
94 //just can't do this in VisualAge now, with all this new Bitmap-Icon stuff
95 //so construct it from a bitmap object until I can figure this nonsense out. (DW)
96 newBitmap
= new wxBitmap(bitmap
) ;
98 newBitmap
= new wxBitmap( (const wxIcon
&) bitmap
);
101 newBitmap
= new wxBitmap(bitmap
) ;
103 if (index
== m_images
.Number()-1)
105 m_images
.DeleteNode( node
);
106 m_images
.Append( newBitmap
);
110 wxNode
*next
= node
->Next();
111 m_images
.DeleteNode( node
);
112 m_images
.Insert( next
, newBitmap
);
118 bool wxImageList::Remove( int index
)
120 wxNode
*node
= m_images
.Nth( index
);
122 wxCHECK_MSG( node
, FALSE
, wxT("wrong index in image list") );
124 m_images
.DeleteNode( node
);
129 bool wxImageList::RemoveAll()
136 bool wxImageList::GetSize( int index
, int &width
, int &height
) const
141 wxNode
*node
= m_images
.Nth( index
);
143 wxCHECK_MSG( node
, FALSE
, wxT("wrong index in image list") );
145 wxBitmap
*bm
= (wxBitmap
*)node
->Data();
146 width
= bm
->GetWidth();
147 height
= bm
->GetHeight();
152 bool wxImageList::Draw( int index
, wxDC
&dc
, int x
, int y
,
153 int flags
, bool WXUNUSED(solidBackground
) )
155 wxNode
*node
= m_images
.Nth( index
);
157 wxCHECK_MSG( node
, FALSE
, wxT("wrong index in image list") );
159 wxBitmap
*bm
= (wxBitmap
*)node
->Data();
161 if (bm
->IsKindOf(CLASSINFO(wxIcon
)))
162 dc
.DrawIcon( * ((wxIcon
*) bm
), x
, y
);
164 dc
.DrawBitmap( *bm
, x
, y
, (flags
& wxIMAGELIST_DRAW_TRANSPARENT
) > 0 );