1 /////////////////////////////////////////////////////////////////////////////
2 // Name: generic/imaglist.cpp
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "imaglist.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
23 #include "wx/generic/imaglist.h"
28 //-----------------------------------------------------------------------------
30 //-----------------------------------------------------------------------------
32 IMPLEMENT_DYNAMIC_CLASS(wxGenericImageList
, wxObject
)
34 #if !defined(__WXMSW__) || defined(__WXUNIVERSAL__)
36 * wxImageList has to be a real class or we have problems with
37 * the run-time information.
40 IMPLEMENT_DYNAMIC_CLASS(wxImageList
, wxGenericImageList
)
43 wxGenericImageList::wxGenericImageList( int width
, int height
, bool mask
, int initialCount
)
45 (void)Create(width
, height
, mask
, initialCount
);
48 wxGenericImageList::~wxGenericImageList()
53 int wxGenericImageList::GetImageCount() const
55 return m_images
.GetCount();
58 bool wxGenericImageList::Create( int width
, int height
, bool WXUNUSED(mask
), int WXUNUSED(initialCount
) )
66 bool wxGenericImageList::Create()
71 int wxGenericImageList::Add( const wxBitmap
&bitmap
)
73 wxASSERT_MSG( bitmap
.GetWidth() == m_width
&&
74 bitmap
.GetHeight() == m_height
,
75 _T("invalid bitmap size in wxImageList: this might work ")
76 _T("on this platform but definitely won't under Windows.") );
78 if (bitmap
.IsKindOf(CLASSINFO(wxIcon
)))
79 m_images
.Append( new wxIcon( (const wxIcon
&) bitmap
) );
81 m_images
.Append( new wxBitmap(bitmap
) );
82 return m_images
.GetCount()-1;
85 int wxGenericImageList::Add( const wxBitmap
& bitmap
, const wxBitmap
& mask
)
89 bmp
.SetMask(new wxMask(mask
));
93 int wxGenericImageList::Add( const wxBitmap
& bitmap
, const wxColour
& maskColour
)
95 wxImage img
= bitmap
.ConvertToImage();
96 img
.SetMaskColour(maskColour
.Red(), maskColour
.Green(), maskColour
.Blue());
97 return Add(wxBitmap(img
));
100 const wxBitmap
*wxGenericImageList::GetBitmap( int index
) const
102 wxList::compatibility_iterator node
= m_images
.Item( index
);
104 wxCHECK_MSG( node
, (wxBitmap
*) NULL
, wxT("wrong index in image list") );
106 return (wxBitmap
*)node
->GetData();
109 bool wxGenericImageList::Replace( int index
, const wxBitmap
&bitmap
)
111 wxList::compatibility_iterator node
= m_images
.Item( index
);
113 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
115 wxBitmap
* newBitmap
= (bitmap
.IsKindOf(CLASSINFO(wxIcon
))) ?
116 #if defined(__VISAGECPP__)
117 //just can't do this in VisualAge now, with all this new Bitmap-Icon stuff
118 //so construct it from a bitmap object until I can figure this nonsense out. (DW)
121 new wxBitmap( (const wxIcon
&) bitmap
)
123 : new wxBitmap(bitmap
) ;
125 if (index
== (int) m_images
.GetCount() - 1)
127 delete node
->GetData();
128 m_images
.Erase( node
);
129 m_images
.Append( newBitmap
);
133 wxList::compatibility_iterator next
= node
->GetNext();
134 delete node
->GetData();
135 m_images
.Erase( node
);
136 m_images
.Insert( next
, newBitmap
);
142 bool wxGenericImageList::Remove( int index
)
144 wxList::compatibility_iterator node
= m_images
.Item( index
);
146 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
148 delete node
->GetData();
149 m_images
.Erase( node
);
154 bool wxGenericImageList::RemoveAll()
156 WX_CLEAR_LIST(wxList
, m_images
);
162 bool wxGenericImageList::GetSize( int index
, int &width
, int &height
) const
167 wxList::compatibility_iterator node
= m_images
.Item( index
);
169 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
171 wxBitmap
*bm
= (wxBitmap
*)node
->GetData();
172 width
= bm
->GetWidth();
173 height
= bm
->GetHeight();
178 bool wxGenericImageList::Draw( int index
, wxDC
&dc
, int x
, int y
,
179 int flags
, bool WXUNUSED(solidBackground
) )
181 wxList::compatibility_iterator node
= m_images
.Item( index
);
183 wxCHECK_MSG( node
, false, wxT("wrong index in image list") );
185 wxBitmap
*bm
= (wxBitmap
*)node
->GetData();
187 if (bm
->IsKindOf(CLASSINFO(wxIcon
)))
188 dc
.DrawIcon( * ((wxIcon
*) bm
), x
, y
);
190 dc
.DrawBitmap( *bm
, x
, y
, (flags
& wxIMAGELIST_DRAW_TRANSPARENT
) > 0 );