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