]> git.saurik.com Git - wxWidgets.git/blame - src/common/iconbndl.cpp
added support for gcc precompiled headers
[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
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"
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
d5309f58
SC
30#ifndef _WX_IMAGE_H_
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
57void wxIconBundle::AddIcon( const wxString& file, long type )
58{
59 size_t count = wxImage::GetImageCount( file, type );
60 size_t i;
61 wxImage image;
f618020a
MB
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
ab71cedf
MB
72 wxIcon* tmp = new wxIcon();
73 tmp->CopyFromBitmap( wxBitmap( image ) );
74 AddIcon( *tmp );
75 delete tmp;
f618020a
MB
76 }
77}
78
79const 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 );
f618020a 84
8f696653
MB
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++ )
f618020a 91 {
7efaed4d
MB
92 if( !m_icons[i].Ok() )
93 continue;
f618020a
MB
94 wxCoord sx = m_icons[i].GetWidth(), sy = m_icons[i].GetHeight();
95 // requested size
96 if( sx == size.x && sy == size.y )
8f696653
MB
97 {
98 tmp = &m_icons[i]; // fix for broken BCC
99 return *tmp;
100 }
f618020a
MB
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
8f696653
MB
109 if( max > 0 ) // fix for broken BCC
110 tmp = &m_icons[0];
111 else
112 tmp = &wxNullIcon;
113 return *tmp;
f618020a
MB
114}
115
116void 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];
7efaed4d 123 if( tmp.Ok() && tmp.GetWidth() == icon.GetWidth() &&
f618020a
MB
124 tmp.GetHeight() == icon.GetHeight() )
125 {
126 tmp = icon;
127 return;
128 }
129 }
130
131 m_icons.Add( icon );
132}