1 /////////////////////////////////////////////////////////////////////////////
2 // Name: generic/imaglist.cpp
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 mask
, int initialCount
)
33 (void)Create(width
, height
, mask
, initialCount
);
36 wxImageList::~wxImageList()
40 int wxImageList::GetImageCount() const
42 return m_images
.Number();
45 bool wxImageList::Create( int width
, int height
, bool WXUNUSED(mask
), int WXUNUSED(initialCount
) )
53 bool wxImageList::Create()
55 m_images
.DeleteContents( TRUE
);
59 int wxImageList::Add( const wxBitmap
&bitmap
)
61 if (bitmap
.IsKindOf(CLASSINFO(wxIcon
)))
62 m_images
.Append( new wxIcon( (const wxIcon
&) bitmap
) );
64 m_images
.Append( new wxBitmap(bitmap
) );
65 return m_images
.Number()-1;
68 int wxImageList::Add( const wxBitmap
& bitmap
, const wxBitmap
& mask
)
71 bmp
.SetMask(new wxMask(mask
));
75 int wxImageList::Add( const wxBitmap
& bitmap
, const wxColour
& maskColour
)
78 img
.SetMaskColour(maskColour
.Red(), maskColour
.Green(), maskColour
.Blue());
79 return Add(img
.ConvertToBitmap());
82 const wxBitmap
*wxImageList::GetBitmap( int index
) const
84 wxNode
*node
= m_images
.Nth( index
);
86 wxCHECK_MSG( node
, (wxBitmap
*) NULL
, wxT("wrong index in image list") );
88 return (wxBitmap
*)node
->Data();
91 bool wxImageList::Replace( int index
, const wxBitmap
&bitmap
)
93 wxNode
*node
= m_images
.Nth( index
);
95 wxCHECK_MSG( node
, FALSE
, wxT("wrong index in image list") );
97 wxBitmap
* newBitmap
= NULL
;
98 if (bitmap
.IsKindOf(CLASSINFO(wxIcon
)))
99 #if defined(__VISAGECPP__)
100 //just can't do this in VisualAge now, with all this new Bitmap-Icon stuff
101 //so construct it from a bitmap object until I can figure this nonsense out. (DW)
102 newBitmap
= new wxBitmap(bitmap
) ;
104 newBitmap
= new wxBitmap( (const wxIcon
&) bitmap
);
107 newBitmap
= new wxBitmap(bitmap
) ;
109 if (index
== m_images
.Number()-1)
111 m_images
.DeleteNode( node
);
112 m_images
.Append( newBitmap
);
116 wxNode
*next
= node
->Next();
117 m_images
.DeleteNode( node
);
118 m_images
.Insert( next
, newBitmap
);
124 bool wxImageList::Remove( int index
)
126 wxNode
*node
= m_images
.Nth( index
);
128 wxCHECK_MSG( node
, FALSE
, wxT("wrong index in image list") );
130 m_images
.DeleteNode( node
);
135 bool wxImageList::RemoveAll()
142 bool wxImageList::GetSize( int index
, int &width
, int &height
) const
147 wxNode
*node
= m_images
.Nth( index
);
149 wxCHECK_MSG( node
, FALSE
, wxT("wrong index in image list") );
151 wxBitmap
*bm
= (wxBitmap
*)node
->Data();
152 width
= bm
->GetWidth();
153 height
= bm
->GetHeight();
158 bool wxImageList::Draw( int index
, wxDC
&dc
, int x
, int y
,
159 int flags
, bool WXUNUSED(solidBackground
) )
161 wxNode
*node
= m_images
.Nth( index
);
163 wxCHECK_MSG( node
, FALSE
, wxT("wrong index in image list") );
165 wxBitmap
*bm
= (wxBitmap
*)node
->Data();
167 if (bm
->IsKindOf(CLASSINFO(wxIcon
)))
168 dc
.DrawIcon( * ((wxIcon
*) bm
), x
, y
);
170 dc
.DrawBitmap( *bm
, x
, y
, (flags
& wxIMAGELIST_DRAW_TRANSPARENT
) > 0 );