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" 
  25 //----------------------------------------------------------------------------- 
  27 //----------------------------------------------------------------------------- 
  29 IMPLEMENT_DYNAMIC_CLASS(wxGenericImageList
, wxObject
) 
  31 #if !defined(__WXMSW__) || defined(__WIN16__) || defined(__WXUNIVERSAL__) 
  33  * wxImageList has to be a real class or we have problems with 
  34  * the run-time information. 
  37 IMPLEMENT_DYNAMIC_CLASS(wxImageList
, wxGenericImageList
) 
  40 wxGenericImageList::wxGenericImageList( int width
, int height
, bool mask
, int initialCount 
) 
  42     (void)Create(width
, height
, mask
, initialCount
); 
  45 wxGenericImageList::~wxGenericImageList() 
  49 int wxGenericImageList::GetImageCount() const 
  51     return m_images
.Number(); 
  54 bool wxGenericImageList::Create( int width
, int height
, bool WXUNUSED(mask
), int WXUNUSED(initialCount
) ) 
  62 bool wxGenericImageList::Create() 
  64     m_images
.DeleteContents( TRUE 
); 
  68 int wxGenericImageList::Add( const wxBitmap 
&bitmap 
) 
  70     if (bitmap
.IsKindOf(CLASSINFO(wxIcon
))) 
  71         m_images
.Append( new wxIcon( (const wxIcon
&) bitmap 
) ); 
  73         m_images
.Append( new wxBitmap(bitmap
) ); 
  74     return m_images
.Number()-1; 
  77 int wxGenericImageList::Add( const wxBitmap
& bitmap
, const wxBitmap
& mask 
) 
  81         bmp
.SetMask(new wxMask(mask
)); 
  85 int wxGenericImageList::Add( const wxBitmap
& bitmap
, const wxColour
& maskColour 
) 
  87     wxImage img 
= bitmap
.ConvertToImage(); 
  88     img
.SetMaskColour(maskColour
.Red(), maskColour
.Green(), maskColour
.Blue()); 
  89     return Add(wxBitmap(img
)); 
  92 const wxBitmap 
*wxGenericImageList::GetBitmap( int index 
) const 
  94     wxNode 
*node 
= m_images
.Nth( index 
); 
  96     wxCHECK_MSG( node
, (wxBitmap 
*) NULL
, wxT("wrong index in image list") ); 
  98     return (wxBitmap
*)node
->Data(); 
 101 bool wxGenericImageList::Replace( int index
, const wxBitmap 
&bitmap 
) 
 103     wxNode 
*node 
= m_images
.Nth( index 
); 
 105     wxCHECK_MSG( node
, FALSE
, wxT("wrong index in image list") ); 
 107     wxBitmap
* newBitmap 
= NULL
; 
 108     if (bitmap
.IsKindOf(CLASSINFO(wxIcon
))) 
 109 #if defined(__VISAGECPP__) 
 110 //just can't do this in VisualAge now, with all this new Bitmap-Icon stuff 
 111 //so construct it from a bitmap object until I can figure this nonsense out. (DW) 
 112         newBitmap 
= new wxBitmap(bitmap
) ; 
 114         newBitmap 
= new wxBitmap( (const wxIcon
&) bitmap 
); 
 117         newBitmap 
= new wxBitmap(bitmap
) ; 
 119     if (index 
== m_images
.Number()-1) 
 121         m_images
.DeleteNode( node 
); 
 122         m_images
.Append( newBitmap 
); 
 126         wxNode 
*next 
= node
->Next(); 
 127         m_images
.DeleteNode( node 
); 
 128         m_images
.Insert( next
, newBitmap 
); 
 134 bool wxGenericImageList::Remove( int index 
) 
 136     wxNode 
*node 
= m_images
.Nth( index 
); 
 138     wxCHECK_MSG( node
, FALSE
, wxT("wrong index in image list") ); 
 140     m_images
.DeleteNode( node 
); 
 145 bool wxGenericImageList::RemoveAll() 
 152 bool wxGenericImageList::GetSize( int index
, int &width
, int &height 
) const 
 157     wxNode 
*node 
= m_images
.Nth( index 
); 
 159     wxCHECK_MSG( node
, FALSE
, wxT("wrong index in image list") ); 
 161     wxBitmap 
*bm 
= (wxBitmap
*)node
->Data(); 
 162     width 
= bm
->GetWidth(); 
 163     height 
= bm
->GetHeight(); 
 168 bool wxGenericImageList::Draw( int index
, wxDC 
&dc
, int x
, int y
, 
 169                         int flags
, bool WXUNUSED(solidBackground
) ) 
 171     wxNode 
*node 
= m_images
.Nth( index 
); 
 173     wxCHECK_MSG( node
, FALSE
, wxT("wrong index in image list") ); 
 175     wxBitmap 
*bm 
= (wxBitmap
*)node
->Data(); 
 177     if (bm
->IsKindOf(CLASSINFO(wxIcon
))) 
 178         dc
.DrawIcon( * ((wxIcon
*) bm
), x
, y
); 
 180         dc
.DrawBitmap( *bm
, x
, y
, (flags 
& wxIMAGELIST_DRAW_TRANSPARENT
) > 0 );