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