]> git.saurik.com Git - wxWidgets.git/blame - src/common/iconbndl.cpp
added wxMemoryInputStream(wxInputStream&, size_t) ctor (modified patch 1680108)
[wxWidgets.git] / src / common / iconbndl.cpp
CommitLineData
f618020a 1/////////////////////////////////////////////////////////////////////////////
923d28da 2// Name: src/common/iconbndl.cpp
f618020a
MB
3// Purpose: wxIconBundle
4// Author: Mattia Barbon
5// Created: 23.03.2002
6// RCS-ID: $Id$
7// Copyright: (c) Mattia barbon
65571936 8// Licence: wxWindows licence
f618020a
MB
9/////////////////////////////////////////////////////////////////////////////
10
f618020a
MB
11// For compilers that support precompilation, includes "wx.h".
12#include "wx/wxprec.h"
13
14#ifdef __BORLANDC__
15 #pragma hdrstop
16#endif
17
923d28da
WS
18#include "wx/iconbndl.h"
19
f618020a
MB
20#ifndef WX_PRECOMP
21 #include "wx/settings.h"
f618020a
MB
22 #include "wx/icon.h"
23 #include "wx/log.h"
24 #include "wx/intl.h"
ed39ff57 25 #include "wx/bitmap.h"
d5309f58
SC
26 #include "wx/image.h"
27#endif
28
f618020a
MB
29#include "wx/arrimpl.cpp"
30
31WX_DEFINE_OBJARRAY(wxIconArray)
32
33const 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
46void wxIconBundle::DeleteIcons()
47{
48 m_icons.Empty();
49}
50
1904aa72 51#if wxUSE_IMAGE
f618020a 52void wxIconBundle::AddIcon( const wxString& file, long type )
1904aa72
DS
53#else
54void wxIconBundle::AddIcon( const wxString& WXUNUSED(file), long WXUNUSED(type) )
55#endif
f618020a 56{
64c288fa 57#if wxUSE_IMAGE && (!defined(__WXMSW__) || wxUSE_WXDIB)
f618020a
MB
58 size_t count = wxImage::GetImageCount( file, type );
59 size_t i;
60 wxImage image;
f618020a
MB
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
ab71cedf
MB
71 wxIcon* tmp = new wxIcon();
72 tmp->CopyFromBitmap( wxBitmap( image ) );
73 AddIcon( *tmp );
74 delete tmp;
f618020a 75 }
7da6ab6e 76#endif
f618020a
MB
77}
78
79const wxIcon& wxIconBundle::GetIcon( const wxSize& size ) const
80{
2fd85ab3
VS
81 // temp. variable needed to fix Borland C++ 5.5.1 problem
82 // with passing a return value through two functions
83 wxIcon *tmp;
84
85 size_t max = m_icons.GetCount();
86
87 // if we have one or no icon, we can return now without doing more work:
88 if ( max <= 1 )
89 {
90 if ( max == 1 ) // fix for broken BCC
91 tmp = &m_icons[0];
92 else // max == 0
93 tmp = &wxNullIcon;
94 return *tmp;
95 }
96
97 // there are more icons, find the best match:
f618020a
MB
98 wxCoord sysX = wxSystemSettings::GetMetric( wxSYS_ICON_X ),
99 sysY = wxSystemSettings::GetMetric( wxSYS_ICON_Y );
f618020a 100
8f696653 101 wxIcon *sysIcon = 0;
8f696653 102
2fd85ab3 103 for( size_t i = 0; i < max; i++ )
f618020a 104 {
7efaed4d
MB
105 if( !m_icons[i].Ok() )
106 continue;
f618020a
MB
107 wxCoord sx = m_icons[i].GetWidth(), sy = m_icons[i].GetHeight();
108 // requested size
109 if( sx == size.x && sy == size.y )
8f696653
MB
110 {
111 tmp = &m_icons[i]; // fix for broken BCC
112 return *tmp;
113 }
f618020a
MB
114 // keep track if there is a system-size icon
115 if( sx == sysX && sy == sysY )
116 sysIcon = &m_icons[i];
117 }
118
119 // return the system-sized icon if we've got one
120 if( sysIcon ) return *sysIcon;
2fd85ab3
VS
121 // we certainly have at least one icon thanks to the <=1 check above
122 tmp = &m_icons[0];
8f696653 123 return *tmp;
f618020a
MB
124}
125
126void wxIconBundle::AddIcon( const wxIcon& icon )
127{
128 size_t i, max = m_icons.GetCount();
129
130 for( i = 0; i < max; ++i )
131 {
132 wxIcon& tmp = m_icons[i];
7efaed4d 133 if( tmp.Ok() && tmp.GetWidth() == icon.GetWidth() &&
f618020a
MB
134 tmp.GetHeight() == icon.GetHeight() )
135 {
136 tmp = icon;
137 return;
138 }
139 }
140
141 m_icons.Add( icon );
142}