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