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
)
72 bmp
.SetMask(new wxMask(mask
));
76 int wxImageList::Add( const wxBitmap
& bitmap
, const wxColour
& maskColour
)
79 img
.SetMaskColour(maskColour
.Red(), maskColour
.Green(), maskColour
.Blue());
80 return Add(img
.ConvertToBitmap());
83 const wxBitmap
*wxImageList::GetBitmap( int index
) const
85 wxNode
*node
= m_images
.Nth( index
);
87 wxCHECK_MSG( node
, (wxBitmap
*) NULL
, wxT("wrong index in image list") );
89 return (wxBitmap
*)node
->Data();
92 bool wxImageList::Replace( int index
, const wxBitmap
&bitmap
)
94 wxNode
*node
= m_images
.Nth( index
);
96 wxCHECK_MSG( node
, FALSE
, wxT("wrong index in image list") );
98 wxBitmap
* newBitmap
= NULL
;
99 if (bitmap
.IsKindOf(CLASSINFO(wxIcon
)))
100 #if defined(__VISAGECPP__)
101 //just can't do this in VisualAge now, with all this new Bitmap-Icon stuff
102 //so construct it from a bitmap object until I can figure this nonsense out. (DW)
103 newBitmap
= new wxBitmap(bitmap
) ;
105 newBitmap
= new wxBitmap( (const wxIcon
&) bitmap
);
108 newBitmap
= new wxBitmap(bitmap
) ;
110 if (index
== m_images
.Number()-1)
112 m_images
.DeleteNode( node
);
113 m_images
.Append( newBitmap
);
117 wxNode
*next
= node
->Next();
118 m_images
.DeleteNode( node
);
119 m_images
.Insert( next
, newBitmap
);
125 bool wxImageList::Remove( int index
)
127 wxNode
*node
= m_images
.Nth( index
);
129 wxCHECK_MSG( node
, FALSE
, wxT("wrong index in image list") );
131 m_images
.DeleteNode( node
);
136 bool wxImageList::RemoveAll()
143 bool wxImageList::GetSize( int index
, int &width
, int &height
) const
148 wxNode
*node
= m_images
.Nth( index
);
150 wxCHECK_MSG( node
, FALSE
, wxT("wrong index in image list") );
152 wxBitmap
*bm
= (wxBitmap
*)node
->Data();
153 width
= bm
->GetWidth();
154 height
= bm
->GetHeight();
159 bool wxImageList::Draw( int index
, wxDC
&dc
, int x
, int y
,
160 int flags
, bool WXUNUSED(solidBackground
) )
162 wxNode
*node
= m_images
.Nth( index
);
164 wxCHECK_MSG( node
, FALSE
, wxT("wrong index in image list") );
166 wxBitmap
*bm
= (wxBitmap
*)node
->Data();
168 if (bm
->IsKindOf(CLASSINFO(wxIcon
)))
169 dc
.DrawIcon( * ((wxIcon
*) bm
), x
, y
);
171 dc
.DrawBitmap( *bm
, x
, y
, (flags
& wxIMAGELIST_DRAW_TRANSPARENT
) > 0 );