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