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(__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()
68 int wxGenericImageList::Add( const wxBitmap
&bitmap
)
70 wxASSERT_MSG( bitmap
.GetWidth() == m_width
&&
71 bitmap
.GetHeight() == m_height
,
72 _T("invalid bitmap size in wxImageList: this might work ")
73 _T("on this platform but definitely won't under Windows.") );
75 if (bitmap
.IsKindOf(CLASSINFO(wxIcon
)))
76 m_images
.Append( new wxIcon( (const wxIcon
&) bitmap
) );
78 m_images
.Append( new wxBitmap(bitmap
) );
79 return m_images
.GetCount()-1;
82 int wxGenericImageList::Add( const wxBitmap
& bitmap
, const wxBitmap
& mask
)
86 bmp
.SetMask(new wxMask(mask
));
90 int wxGenericImageList::Add( const wxBitmap
& bitmap
, const wxColour
& maskColour
)
92 wxImage img
= bitmap
.ConvertToImage();
93 img
.SetMaskColour(maskColour
.Red(), maskColour
.Green(), maskColour
.Blue());
94 return Add(wxBitmap(img
));
97 const wxBitmap
*wxGenericImageList::GetBitmap( int index
) const
99 wxList::compatibility_iterator node
= m_images
.Item( index
);
101 wxCHECK_MSG( node
, (wxBitmap
*) NULL
, wxT("wrong index in image list") );
103 return (wxBitmap
*)node
->GetData();
106 bool wxGenericImageList::Replace( int index
, const wxBitmap
&bitmap
)
108 wxList::compatibility_iterator node
= m_images
.Item( index
);
110 wxCHECK_MSG( node
, FALSE
, wxT("wrong index in image list") );
112 wxBitmap
* newBitmap
= NULL
;
113 if (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)
117 newBitmap
= new wxBitmap(bitmap
) ;
119 newBitmap
= new wxBitmap( (const wxIcon
&) bitmap
);
122 newBitmap
= new wxBitmap(bitmap
) ;
124 if (index
== (int) m_images
.GetCount() - 1)
126 delete node
->GetData();
127 m_images
.Erase( node
);
128 m_images
.Append( newBitmap
);
132 wxList::compatibility_iterator next
= node
->GetNext();
133 delete node
->GetData();
134 m_images
.Erase( node
);
135 m_images
.Insert( next
, newBitmap
);
141 bool wxGenericImageList::Remove( int index
)
143 wxList::compatibility_iterator node
= m_images
.Item( index
);
145 wxCHECK_MSG( node
, FALSE
, wxT("wrong index in image list") );
147 delete node
->GetData();
148 m_images
.Erase( node
);
153 bool wxGenericImageList::RemoveAll()
155 WX_CLEAR_LIST(wxList
, m_images
);
161 bool wxGenericImageList::GetSize( int index
, int &width
, int &height
) const
166 wxList::compatibility_iterator node
= m_images
.Item( index
);
168 wxCHECK_MSG( node
, FALSE
, wxT("wrong index in image list") );
170 wxBitmap
*bm
= (wxBitmap
*)node
->GetData();
171 width
= bm
->GetWidth();
172 height
= bm
->GetHeight();
177 bool wxGenericImageList::Draw( int index
, wxDC
&dc
, int x
, int y
,
178 int flags
, bool WXUNUSED(solidBackground
) )
180 wxList::compatibility_iterator node
= m_images
.Item( index
);
182 wxCHECK_MSG( node
, FALSE
, wxT("wrong index in image list") );
184 wxBitmap
*bm
= (wxBitmap
*)node
->GetData();
186 if (bm
->IsKindOf(CLASSINFO(wxIcon
)))
187 dc
.DrawIcon( * ((wxIcon
*) bm
), x
, y
);
189 dc
.DrawBitmap( *bm
, x
, y
, (flags
& wxIMAGELIST_DRAW_TRANSPARENT
) > 0 );