1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        generic/imaglist.cpp 
   4 // Author:      Robert Roebling 
   6 // Copyright:   (c) 1998 Robert Roebling 
   7 // Licence:     wxWindows licence 
   8 ///////////////////////////////////////////////////////////////////////////// 
  10 // For compilers that support precompilation, includes "wx.h". 
  11 #include "wx/wxprec.h" 
  23 #include "wx/generic/imaglist.h" 
  29 //----------------------------------------------------------------------------- 
  31 //----------------------------------------------------------------------------- 
  33 IMPLEMENT_DYNAMIC_CLASS(wxGenericImageList
, wxObject
) 
  35 #if !defined(__WXMSW__) || defined(__WXUNIVERSAL__) 
  37  * wxImageList has to be a real class or we have problems with 
  38  * the run-time information. 
  41 IMPLEMENT_DYNAMIC_CLASS(wxImageList
, wxGenericImageList
) 
  44 wxGenericImageList::wxGenericImageList( int width
, int height
, bool mask
, int initialCount 
) 
  46     (void)Create(width
, height
, mask
, initialCount
); 
  49 wxGenericImageList::~wxGenericImageList() 
  54 int wxGenericImageList::GetImageCount() const 
  56     return m_images
.GetCount(); 
  59 bool wxGenericImageList::Create( int width
, int height
, bool WXUNUSED(mask
), int WXUNUSED(initialCount
) ) 
  67 bool wxGenericImageList::Create() 
  72 int wxGenericImageList::Add( const wxBitmap 
&bitmap 
) 
  74     wxASSERT_MSG( (bitmap
.GetWidth() == m_width 
&& bitmap
.GetHeight() == m_height
) 
  75                   || (m_width 
== 0 && m_height 
== 0), 
  76                   _T("invalid bitmap size in wxImageList: this might work ") 
  77                   _T("on this platform but definitely won't under Windows.") ); 
  79     if (bitmap
.IsKindOf(CLASSINFO(wxIcon
))) 
  80         m_images
.Append( new wxIcon( (const wxIcon
&) bitmap 
) ); 
  82         m_images
.Append( new wxBitmap(bitmap
) ); 
  84     if (m_width 
== 0 && m_height 
== 0) 
  86         m_width 
= bitmap
.GetWidth(); 
  87         m_height 
= bitmap
.GetHeight(); 
  90     return m_images
.GetCount()-1; 
  93 int wxGenericImageList::Add( const wxBitmap
& bitmap
, const wxBitmap
& mask 
) 
  97         bmp
.SetMask(new wxMask(mask
)); 
 101 int wxGenericImageList::Add( const wxBitmap
& bitmap
, const wxColour
& maskColour 
) 
 103     wxImage img 
= bitmap
.ConvertToImage(); 
 104     img
.SetMaskColour(maskColour
.Red(), maskColour
.Green(), maskColour
.Blue()); 
 105     return Add(wxBitmap(img
)); 
 108 const wxBitmap 
*wxGenericImageList::GetBitmapPtr( int index 
) const 
 110     wxList::compatibility_iterator node 
= m_images
.Item( index 
); 
 112     wxCHECK_MSG( node
, (wxBitmap 
*) NULL
, wxT("wrong index in image list") ); 
 114     return (wxBitmap
*)node
->GetData(); 
 118 wxBitmap 
wxGenericImageList::GetBitmap(int index
) const 
 120     const wxBitmap
* bmp 
= GetBitmapPtr(index
); 
 128 wxIcon 
wxGenericImageList::GetIcon(int index
) const 
 130     const wxBitmap
* bmp 
= GetBitmapPtr(index
); 
 134         icon
.CopyFromBitmap(*bmp
); 
 141 bool wxGenericImageList::Replace( int index
, const wxBitmap 
&bitmap 
) 
 143     wxList::compatibility_iterator node 
= m_images
.Item( index 
); 
 145     wxCHECK_MSG( node
, false, wxT("wrong index in image list") ); 
 147     wxBitmap
* newBitmap 
= (bitmap
.IsKindOf(CLASSINFO(wxIcon
))) ? 
 148                              #if defined(__VISAGECPP__) 
 149                                //just can't do this in VisualAge now, with all this new Bitmap-Icon stuff 
 150                                //so construct it from a bitmap object until I can figure this nonsense out. (DW) 
 153                                new wxBitmap( (const wxIcon
&) bitmap 
) 
 155                                : new wxBitmap(bitmap
) ; 
 157     if (index 
== (int) m_images
.GetCount() - 1) 
 159         delete node
->GetData(); 
 160         m_images
.Erase( node 
); 
 161         m_images
.Append( newBitmap 
); 
 165         wxList::compatibility_iterator next 
= node
->GetNext(); 
 166         delete node
->GetData(); 
 167         m_images
.Erase( node 
); 
 168         m_images
.Insert( next
, newBitmap 
); 
 174 bool wxGenericImageList::Remove( int index 
) 
 176     wxList::compatibility_iterator node 
= m_images
.Item( index 
); 
 178     wxCHECK_MSG( node
, false, wxT("wrong index in image list") ); 
 180     delete node
->GetData(); 
 181     m_images
.Erase( node 
); 
 186 bool wxGenericImageList::RemoveAll() 
 188     WX_CLEAR_LIST(wxList
, m_images
); 
 194 bool wxGenericImageList::GetSize( int index
, int &width
, int &height 
) const 
 199     wxList::compatibility_iterator node 
= m_images
.Item( index 
); 
 201     wxCHECK_MSG( node
, false, wxT("wrong index in image list") ); 
 203     wxBitmap 
*bm 
= (wxBitmap
*)node
->GetData(); 
 204     width 
= bm
->GetWidth(); 
 205     height 
= bm
->GetHeight(); 
 210 bool wxGenericImageList::Draw( int index
, wxDC 
&dc
, int x
, int y
, 
 211                         int flags
, bool WXUNUSED(solidBackground
) ) 
 213     wxList::compatibility_iterator node 
= m_images
.Item( index 
); 
 215     wxCHECK_MSG( node
, false, wxT("wrong index in image list") ); 
 217     wxBitmap 
*bm 
= (wxBitmap
*)node
->GetData(); 
 219     if (bm
->IsKindOf(CLASSINFO(wxIcon
))) 
 220         dc
.DrawIcon( * ((wxIcon
*) bm
), x
, y
); 
 222         dc
.DrawBitmap( *bm
, x
, y
, (flags 
& wxIMAGELIST_DRAW_TRANSPARENT
) > 0 ); 
 227 #endif // wxUSE_IMAGLIST 
 228 #endif // __WXPALMOS__