1 /////////////////////////////////////////////////////////////////////////////
2 // Name: generic/imaglist.cpp
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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(__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()
51 int wxGenericImageList::GetImageCount() const
53 return m_images
.GetCount();
56 bool wxGenericImageList::Create( int width
, int height
, bool WXUNUSED(mask
), int WXUNUSED(initialCount
) )
64 bool wxGenericImageList::Create()
69 int wxGenericImageList::Add( const wxBitmap
&bitmap
)
71 wxASSERT_MSG( bitmap
.GetWidth() == m_width
&&
72 bitmap
.GetHeight() == m_height
,
73 _T("invalid bitmap size in wxImageList: this might work ")
74 _T("on this platform but definitely won't under Windows.") );
76 if (bitmap
.IsKindOf(CLASSINFO(wxIcon
)))
77 m_images
.Append( new wxIcon( (const wxIcon
&) bitmap
) );
79 m_images
.Append( new wxBitmap(bitmap
) );
80 return m_images
.GetCount()-1;
83 int wxGenericImageList::Add( const wxBitmap
& bitmap
, const wxBitmap
& mask
)
87 bmp
.SetMask(new wxMask(mask
));
91 int wxGenericImageList::Add( const wxBitmap
& bitmap
, const wxColour
& maskColour
)
93 wxImage img
= bitmap
.ConvertToImage();
94 img
.SetMaskColour(maskColour
.Red(), maskColour
.Green(), maskColour
.Blue());
95 return Add(wxBitmap(img
));
98 const wxBitmap
*wxGenericImageList::GetBitmap( int index
) const
100 wxList::compatibility_iterator node
= m_images
.Item( index
);
102 wxCHECK_MSG( node
, (wxBitmap
*) NULL
, wxT("wrong index in image list") );
104 return (wxBitmap
*)node
->GetData();
107 bool wxGenericImageList::Replace( int index
, const wxBitmap
&bitmap
)
109 wxList::compatibility_iterator node
= m_images
.Item( index
);
111 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
113 wxBitmap
* newBitmap
= (bitmap
.IsKindOf(CLASSINFO(wxIcon
))) ?
114 #if defined(__VISAGECPP__)
115 //just can't do this in VisualAge now, with all this new Bitmap-Icon stuff
116 //so construct it from a bitmap object until I can figure this nonsense out. (DW)
119 new wxBitmap( (const wxIcon
&) bitmap
)
121 : new wxBitmap(bitmap
) ;
123 if (index
== (int) m_images
.GetCount() - 1)
125 delete node
->GetData();
126 m_images
.Erase( node
);
127 m_images
.Append( newBitmap
);
131 wxList::compatibility_iterator next
= node
->GetNext();
132 delete node
->GetData();
133 m_images
.Erase( node
);
134 m_images
.Insert( next
, newBitmap
);
140 bool wxGenericImageList::Remove( int index
)
142 wxList::compatibility_iterator node
= m_images
.Item( index
);
144 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
146 delete node
->GetData();
147 m_images
.Erase( node
);
152 bool wxGenericImageList::RemoveAll()
154 WX_CLEAR_LIST(wxList
, m_images
);
160 bool wxGenericImageList::GetSize( int index
, int &width
, int &height
) const
165 wxList::compatibility_iterator node
= m_images
.Item( index
);
167 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
169 wxBitmap
*bm
= (wxBitmap
*)node
->GetData();
170 width
= bm
->GetWidth();
171 height
= bm
->GetHeight();
176 bool wxGenericImageList::Draw( int index
, wxDC
&dc
, int x
, int y
,
177 int flags
, bool WXUNUSED(solidBackground
) )
179 wxList::compatibility_iterator node
= m_images
.Item( index
);
181 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
183 wxBitmap
*bm
= (wxBitmap
*)node
->GetData();
185 if (bm
->IsKindOf(CLASSINFO(wxIcon
)))
186 dc
.DrawIcon( * ((wxIcon
*) bm
), x
, y
);
188 dc
.DrawBitmap( *bm
, x
, y
, (flags
& wxIMAGELIST_DRAW_TRANSPARENT
) > 0 );