]>
Commit | Line | Data |
---|---|---|
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" | |
24 | #include "wx/image.h" | |
25 | #include "wx/icon.h" | |
26 | #include "wx/log.h" | |
27 | #include "wx/intl.h" | |
28 | #endif | |
29 | ||
30 | #include "wx/iconbndl.h" | |
31 | #include "wx/arrimpl.cpp" | |
32 | ||
33 | WX_DEFINE_OBJARRAY(wxIconArray) | |
34 | ||
35 | const 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 | ||
48 | void wxIconBundle::DeleteIcons() | |
49 | { | |
50 | m_icons.Empty(); | |
51 | } | |
52 | ||
53 | void wxIconBundle::AddIcon( const wxString& file, long type ) | |
54 | { | |
55 | size_t count = wxImage::GetImageCount( file, type ); | |
56 | size_t i; | |
57 | wxImage image; | |
58 | wxIcon tmp; | |
59 | ||
60 | for( i = 0; i < count; ++i ) | |
61 | { | |
62 | if( !image.LoadFile( file, type, i ) ) | |
63 | { | |
64 | wxLogError( _("Failed to load image %d from file '%s'."), | |
65 | i, file.c_str() ); | |
66 | continue; | |
67 | } | |
68 | ||
69 | tmp.CopyFromBitmap( wxBitmap( image ) ); | |
70 | AddIcon( tmp ); | |
71 | } | |
72 | } | |
73 | ||
74 | const wxIcon& wxIconBundle::GetIcon( const wxSize& size ) const | |
75 | { | |
76 | size_t i, max = m_icons.GetCount(); | |
77 | wxCoord sysX = wxSystemSettings::GetMetric( wxSYS_ICON_X ), | |
78 | sysY = wxSystemSettings::GetMetric( wxSYS_ICON_Y ); | |
79 | wxIcon* sysIcon = 0; | |
80 | ||
81 | for( i = 0; i < max; ++i ) | |
82 | { | |
83 | wxCoord sx = m_icons[i].GetWidth(), sy = m_icons[i].GetHeight(); | |
84 | // requested size | |
85 | if( sx == size.x && sy == size.y ) | |
86 | return m_icons[i]; | |
87 | // keep track if there is a system-size icon | |
88 | if( sx == sysX && sy == sysY ) | |
89 | sysIcon = &m_icons[i]; | |
90 | } | |
91 | ||
92 | // return the system-sized icon if we've got one | |
93 | if( sysIcon ) return *sysIcon; | |
94 | // return the first icon, if we have one | |
95 | return max > 0 ? m_icons[0] : wxNullIcon; | |
96 | } | |
97 | ||
98 | void wxIconBundle::AddIcon( const wxIcon& icon ) | |
99 | { | |
100 | size_t i, max = m_icons.GetCount(); | |
101 | ||
102 | for( i = 0; i < max; ++i ) | |
103 | { | |
104 | wxIcon& tmp = m_icons[i]; | |
105 | if( tmp.GetWidth() == icon.GetWidth() && | |
106 | tmp.GetHeight() == icon.GetHeight() ) | |
107 | { | |
108 | tmp = icon; | |
109 | return; | |
110 | } | |
111 | } | |
112 | ||
113 | m_icons.Add( icon ); | |
114 | } |