]> git.saurik.com Git - wxWidgets.git/blob - src/common/iconbndl.cpp
unused win_gtk stuff
[wxWidgets.git] / src / common / iconbndl.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/iconbndl.cpp
3 // Purpose: wxIconBundle
4 // Author: Mattia Barbon
5 // Created: 23.03.2002
6 // RCS-ID: $Id$
7 // Copyright: (c) Mattia barbon
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
13
14 #ifdef __BORLANDC__
15 #pragma hdrstop
16 #endif
17
18 #include "wx/iconbndl.h"
19
20 #ifndef WX_PRECOMP
21 #include "wx/settings.h"
22 #include "wx/icon.h"
23 #include "wx/log.h"
24 #include "wx/intl.h"
25 #include "wx/bitmap.h"
26 #endif
27
28 #if wxUSE_IMAGE && !defined(_WX_IMAGE_H_)
29 #include "wx/image.h"
30 #endif
31
32 #include "wx/arrimpl.cpp"
33
34 WX_DEFINE_OBJARRAY(wxIconArray)
35
36 const wxIconBundle& wxIconBundle::operator =( const wxIconBundle& ic )
37 {
38 if( this == &ic ) return *this;
39
40 size_t i, max = ic.m_icons.GetCount();
41
42 DeleteIcons();
43 for( i = 0; i < max; ++i )
44 m_icons.Add( ic.m_icons[i] );
45
46 return *this;
47 }
48
49 void wxIconBundle::DeleteIcons()
50 {
51 m_icons.Empty();
52 }
53
54 #if wxUSE_IMAGE
55 void wxIconBundle::AddIcon( const wxString& file, long type )
56 #else
57 void wxIconBundle::AddIcon( const wxString& WXUNUSED(file), long WXUNUSED(type) )
58 #endif
59 {
60 #if wxUSE_IMAGE && (!defined(__WXMSW__) || wxUSE_WXDIB)
61 size_t count = wxImage::GetImageCount( file, type );
62 size_t i;
63 wxImage image;
64
65 for( i = 0; i < count; ++i )
66 {
67 if( !image.LoadFile( file, type, i ) )
68 {
69 wxLogError( _("Failed to load image %d from file '%s'."),
70 i, file.c_str() );
71 continue;
72 }
73
74 wxIcon* tmp = new wxIcon();
75 tmp->CopyFromBitmap( wxBitmap( image ) );
76 AddIcon( *tmp );
77 delete tmp;
78 }
79 #endif
80 }
81
82 const wxIcon& wxIconBundle::GetIcon( const wxSize& size ) const
83 {
84 size_t i, max = m_icons.GetCount();
85 wxCoord sysX = wxSystemSettings::GetMetric( wxSYS_ICON_X ),
86 sysY = wxSystemSettings::GetMetric( wxSYS_ICON_Y );
87
88 wxIcon *sysIcon = 0;
89 // temp. variable needed to fix Borland C++ 5.5.1 problem
90 // with passing a return value through two functions
91 wxIcon *tmp;
92
93 for( i = 0; i < max; i++ )
94 {
95 if( !m_icons[i].Ok() )
96 continue;
97 wxCoord sx = m_icons[i].GetWidth(), sy = m_icons[i].GetHeight();
98 // requested size
99 if( sx == size.x && sy == size.y )
100 {
101 tmp = &m_icons[i]; // fix for broken BCC
102 return *tmp;
103 }
104 // keep track if there is a system-size icon
105 if( sx == sysX && sy == sysY )
106 sysIcon = &m_icons[i];
107 }
108
109 // return the system-sized icon if we've got one
110 if( sysIcon ) return *sysIcon;
111 // return the first icon, if we have one
112 if( max > 0 ) // fix for broken BCC
113 tmp = &m_icons[0];
114 else
115 tmp = &wxNullIcon;
116 return *tmp;
117 }
118
119 void wxIconBundle::AddIcon( const wxIcon& icon )
120 {
121 size_t i, max = m_icons.GetCount();
122
123 for( i = 0; i < max; ++i )
124 {
125 wxIcon& tmp = m_icons[i];
126 if( tmp.Ok() && tmp.GetWidth() == icon.GetWidth() &&
127 tmp.GetHeight() == icon.GetHeight() )
128 {
129 tmp = icon;
130 return;
131 }
132 }
133
134 m_icons.Add( icon );
135 }