]>
git.saurik.com Git - wxWidgets.git/blob - src/common/iconbndl.cpp
e15376f5bb2bc8f8307c7ad72c02d5f46bc4d1bd
   1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        src/common/iconbndl.cpp 
   3 // Purpose:     wxIconBundle 
   4 // Author:      Mattia Barbon 
   7 // Copyright:   (c) Mattia barbon 
   8 // Licence:     wxWindows licence 
   9 ///////////////////////////////////////////////////////////////////////////// 
  11 // For compilers that support precompilation, includes "wx.h". 
  12 #include "wx/wxprec.h" 
  18 #include "wx/iconbndl.h" 
  21     #include "wx/settings.h" 
  25     #include "wx/bitmap.h" 
  29 #include "wx/arrimpl.cpp" 
  31 WX_DEFINE_OBJARRAY(wxIconArray
) 
  33 const wxIconBundle
& wxIconBundle::operator =( const wxIconBundle
& ic 
) 
  35     if( this == &ic 
) return *this; 
  37     size_t i
, max 
= ic
.m_icons
.GetCount(); 
  40     for( i 
= 0; i 
< max
; ++i 
) 
  41         m_icons
.Add( ic
.m_icons
[i
] ); 
  46 void wxIconBundle::DeleteIcons() 
  52 void wxIconBundle::AddIcon( const wxString
& file
, long type 
) 
  54 void wxIconBundle::AddIcon( const wxString
& WXUNUSED(file
), long WXUNUSED(type
) ) 
  57 #if wxUSE_IMAGE && (!defined(__WXMSW__) || wxUSE_WXDIB) 
  58     size_t count 
= wxImage::GetImageCount( file
, type 
); 
  62     for( i 
= 0; i 
< count
; ++i 
) 
  64         if( !image
.LoadFile( file
, type
, i 
) ) 
  66             wxLogError( _("Failed to load image %d from file '%s'."), 
  71         wxIcon
* tmp 
= new wxIcon(); 
  72         tmp
->CopyFromBitmap( wxBitmap( image 
) ); 
  79 const wxIcon
& wxIconBundle::GetIcon( const wxSize
& size 
) const 
  81     // temp. variable needed to fix Borland C++ 5.5.1 problem 
  82     // with passing a return value through two functions 
  85     size_t max 
= m_icons
.GetCount(); 
  87     // if we have one or no icon, we can return now without doing more work: 
  90         if ( max 
== 1 ) // fix for broken BCC 
  97     // there are more icons, find the best match: 
  98     wxCoord sysX 
= wxSystemSettings::GetMetric( wxSYS_ICON_X 
), 
  99             sysY 
= wxSystemSettings::GetMetric( wxSYS_ICON_Y 
); 
 103     for( size_t i 
= 0; i 
< max
; i
++ ) 
 105         if( !m_icons
[i
].Ok() ) 
 107         wxCoord sx 
= m_icons
[i
].GetWidth(), sy 
= m_icons
[i
].GetHeight(); 
 109         if( sx 
== size
.x 
&& sy 
== size
.y 
) 
 111             tmp 
= &m_icons
[i
]; // fix for broken BCC 
 114         // keep track if there is a system-size icon 
 115         if( sx 
== sysX 
&& sy 
== sysY 
) 
 116             sysIcon 
= &m_icons
[i
]; 
 119     // return the system-sized icon if we've got one 
 120     if( sysIcon 
) return *sysIcon
; 
 121     // we certainly have at least one icon thanks to the <=1 check above 
 126 void wxIconBundle::AddIcon( const wxIcon
& icon 
) 
 128     size_t i
, max 
= m_icons
.GetCount(); 
 130     for( i 
= 0; i 
< max
; ++i 
) 
 132         wxIcon
& tmp 
= m_icons
[i
]; 
 133         if( tmp
.Ok() && tmp
.GetWidth() == icon
.GetWidth() && 
 134             tmp
.GetHeight() == icon
.GetHeight() )