]>
git.saurik.com Git - wxWidgets.git/blob - src/common/iconbndl.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxIconBundle
4 // Author: Mattia Barbon
7 // Copyright: (c) Mattia barbon
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
12 #pragma implementation "iconbndl.h"
15 // For compilers that support precompilation, includes "wx.h".
16 #include "wx/wxprec.h"
23 #include "wx/settings.h"
27 #include "wx/bitmap.h"
30 #if wxUSE_IMAGE && !defined(_WX_IMAGE_H_)
34 #include "wx/iconbndl.h"
35 #include "wx/arrimpl.cpp"
37 WX_DEFINE_OBJARRAY(wxIconArray
)
39 const wxIconBundle
& wxIconBundle::operator =( const wxIconBundle
& ic
)
41 if( this == &ic
) return *this;
43 size_t i
, max
= ic
.m_icons
.GetCount();
46 for( i
= 0; i
< max
; ++i
)
47 m_icons
.Add( ic
.m_icons
[i
] );
52 void wxIconBundle::DeleteIcons()
58 void wxIconBundle::AddIcon( const wxString
& file
, long type
)
60 void wxIconBundle::AddIcon( const wxString
& WXUNUSED(file
), long WXUNUSED(type
) )
64 size_t count
= wxImage::GetImageCount( file
, type
);
68 for( i
= 0; i
< count
; ++i
)
70 if( !image
.LoadFile( file
, type
, i
) )
72 wxLogError( _("Failed to load image %d from file '%s'."),
77 wxIcon
* tmp
= new wxIcon();
78 tmp
->CopyFromBitmap( wxBitmap( image
) );
85 const wxIcon
& wxIconBundle::GetIcon( const wxSize
& size
) const
87 size_t i
, max
= m_icons
.GetCount();
88 wxCoord sysX
= wxSystemSettings::GetMetric( wxSYS_ICON_X
),
89 sysY
= wxSystemSettings::GetMetric( wxSYS_ICON_Y
);
92 // temp. variable needed to fix Borland C++ 5.5.1 problem
93 // with passing a return value through two functions
96 for( i
= 0; i
< max
; i
++ )
98 if( !m_icons
[i
].Ok() )
100 wxCoord sx
= m_icons
[i
].GetWidth(), sy
= m_icons
[i
].GetHeight();
102 if( sx
== size
.x
&& sy
== size
.y
)
104 tmp
= &m_icons
[i
]; // fix for broken BCC
107 // keep track if there is a system-size icon
108 if( sx
== sysX
&& sy
== sysY
)
109 sysIcon
= &m_icons
[i
];
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
115 if( max
> 0 ) // fix for broken BCC
122 void wxIconBundle::AddIcon( const wxIcon
& icon
)
124 size_t i
, max
= m_icons
.GetCount();
126 for( i
= 0; i
< max
; ++i
)
128 wxIcon
& tmp
= m_icons
[i
];
129 if( tmp
.Ok() && tmp
.GetWidth() == icon
.GetWidth() &&
130 tmp
.GetHeight() == icon
.GetHeight() )