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"
26 //-----------------------------------------------------------------------------
28 //-----------------------------------------------------------------------------
30 IMPLEMENT_DYNAMIC_CLASS(wxGenericImageList
, wxObject
)
32 #if !defined(__WXMSW__) || defined(__WIN16__) || defined(__WXUNIVERSAL__)
34 * wxImageList has to be a real class or we have problems with
35 * the run-time information.
38 IMPLEMENT_DYNAMIC_CLASS(wxImageList
, wxGenericImageList
)
41 wxGenericImageList::wxGenericImageList( int width
, int height
, bool mask
, int initialCount
)
43 (void)Create(width
, height
, mask
, initialCount
);
46 wxGenericImageList::~wxGenericImageList()
50 int wxGenericImageList::GetImageCount() const
52 return m_images
.GetCount();
55 bool wxGenericImageList::Create( int width
, int height
, bool WXUNUSED(mask
), int WXUNUSED(initialCount
) )
63 bool wxGenericImageList::Create()
65 m_images
.DeleteContents( TRUE
);
69 int wxGenericImageList::Add( const wxBitmap
&bitmap
)
71 if (bitmap
.IsKindOf(CLASSINFO(wxIcon
)))
72 m_images
.Append( new wxIcon( (const wxIcon
&) bitmap
) );
74 m_images
.Append( new wxBitmap(bitmap
) );
75 return m_images
.GetCount()-1;
78 int wxGenericImageList::Add( const wxBitmap
& bitmap
, const wxBitmap
& mask
)
82 bmp
.SetMask(new wxMask(mask
));
86 int wxGenericImageList::Add( const wxBitmap
& bitmap
, const wxColour
& maskColour
)
88 wxImage img
= bitmap
.ConvertToImage();
89 img
.SetMaskColour(maskColour
.Red(), maskColour
.Green(), maskColour
.Blue());
90 return Add(wxBitmap(img
));
93 const wxBitmap
*wxGenericImageList::GetBitmap( int index
) const
95 wxNode
*node
= m_images
.Item( index
);
97 wxCHECK_MSG( node
, (wxBitmap
*) NULL
, wxT("wrong index in image list") );
99 return (wxBitmap
*)node
->GetData();
102 bool wxGenericImageList::Replace( int index
, const wxBitmap
&bitmap
)
104 wxNode
*node
= m_images
.Item( index
);
106 wxCHECK_MSG( node
, FALSE
, wxT("wrong index in image list") );
108 wxBitmap
* newBitmap
= NULL
;
109 if (bitmap
.IsKindOf(CLASSINFO(wxIcon
)))
110 #if defined(__VISAGECPP__)
111 //just can't do this in VisualAge now, with all this new Bitmap-Icon stuff
112 //so construct it from a bitmap object until I can figure this nonsense out. (DW)
113 newBitmap
= new wxBitmap(bitmap
) ;
115 newBitmap
= new wxBitmap( (const wxIcon
&) bitmap
);
118 newBitmap
= new wxBitmap(bitmap
) ;
120 if (index
== (int) m_images
.GetCount() - 1)
122 m_images
.DeleteNode( node
);
123 m_images
.Append( newBitmap
);
127 wxNode
*next
= node
->GetNext();
128 m_images
.DeleteNode( node
);
129 m_images
.Insert( next
, newBitmap
);
135 bool wxGenericImageList::Remove( int index
)
137 wxNode
*node
= m_images
.Item( index
);
139 wxCHECK_MSG( node
, FALSE
, wxT("wrong index in image list") );
141 m_images
.DeleteNode( node
);
146 bool wxGenericImageList::RemoveAll()
153 bool wxGenericImageList::GetSize( int index
, int &width
, int &height
) const
158 wxNode
*node
= m_images
.Item( index
);
160 wxCHECK_MSG( node
, FALSE
, wxT("wrong index in image list") );
162 wxBitmap
*bm
= (wxBitmap
*)node
->GetData();
163 width
= bm
->GetWidth();
164 height
= bm
->GetHeight();
169 bool wxGenericImageList::Draw( int index
, wxDC
&dc
, int x
, int y
,
170 int flags
, bool WXUNUSED(solidBackground
) )
172 wxNode
*node
= m_images
.Item( index
);
174 wxCHECK_MSG( node
, FALSE
, wxT("wrong index in image list") );
176 wxBitmap
*bm
= (wxBitmap
*)node
->GetData();
178 if (bm
->IsKindOf(CLASSINFO(wxIcon
)))
179 dc
.DrawIcon( * ((wxIcon
*) bm
), x
, y
);
181 dc
.DrawBitmap( *bm
, x
, y
, (flags
& wxIMAGELIST_DRAW_TRANSPARENT
) > 0 );