]>
Commit | Line | Data |
---|---|---|
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 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) | |
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/icon.h" | |
25 | #include "wx/log.h" | |
26 | #include "wx/intl.h" | |
27 | #include "wx/bitmap.h" | |
28 | #endif | |
29 | ||
30 | #if wxUSE_IMAGE && !defined(_WX_IMAGE_H_) | |
31 | #include "wx/image.h" | |
32 | #endif | |
33 | ||
34 | #include "wx/iconbndl.h" | |
35 | #include "wx/arrimpl.cpp" | |
36 | ||
37 | WX_DEFINE_OBJARRAY(wxIconArray) | |
38 | ||
39 | const 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 | ||
52 | void wxIconBundle::DeleteIcons() | |
53 | { | |
54 | m_icons.Empty(); | |
55 | } | |
56 | ||
57 | void wxIconBundle::AddIcon( const wxString& file, long type ) | |
58 | { | |
59 | #if wxUSE_IMAGE | |
60 | size_t count = wxImage::GetImageCount( file, type ); | |
61 | size_t i; | |
62 | wxImage image; | |
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 | ||
73 | wxIcon* tmp = new wxIcon(); | |
74 | tmp->CopyFromBitmap( wxBitmap( image ) ); | |
75 | AddIcon( *tmp ); | |
76 | delete tmp; | |
77 | } | |
78 | #endif | |
79 | } | |
80 | ||
81 | const 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 ); | |
86 | ||
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++ ) | |
93 | { | |
94 | if( !m_icons[i].Ok() ) | |
95 | continue; | |
96 | wxCoord sx = m_icons[i].GetWidth(), sy = m_icons[i].GetHeight(); | |
97 | // requested size | |
98 | if( sx == size.x && sy == size.y ) | |
99 | { | |
100 | tmp = &m_icons[i]; // fix for broken BCC | |
101 | return *tmp; | |
102 | } | |
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 | |
111 | if( max > 0 ) // fix for broken BCC | |
112 | tmp = &m_icons[0]; | |
113 | else | |
114 | tmp = &wxNullIcon; | |
115 | return *tmp; | |
116 | } | |
117 | ||
118 | void 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]; | |
125 | if( tmp.Ok() && tmp.GetWidth() == icon.GetWidth() && | |
126 | tmp.GetHeight() == icon.GetHeight() ) | |
127 | { | |
128 | tmp = icon; | |
129 | return; | |
130 | } | |
131 | } | |
132 | ||
133 | m_icons.Add( icon ); | |
134 | } |