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