]>
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 /////////////////////////////////////////////////////////////////////////////
12 #pragma implementation "iconbndl.h"
15 // For compilers that support precompilation, includes "wx.h".
16 #include "wx/wxprec.h"
23 #include "wx/settings.h"
30 #include "wx/iconbndl.h"
31 #include "wx/arrimpl.cpp"
33 WX_DEFINE_OBJARRAY(wxIconArray
)
35 const wxIconBundle
& wxIconBundle::operator =( const wxIconBundle
& ic
)
37 if( this == &ic
) return *this;
39 size_t i
, max
= ic
.m_icons
.GetCount();
42 for( i
= 0; i
< max
; ++i
)
43 m_icons
.Add( ic
.m_icons
[i
] );
48 void wxIconBundle::DeleteIcons()
53 void wxIconBundle::AddIcon( const wxString
& file
, long type
)
55 size_t count
= wxImage::GetImageCount( file
, type
);
60 for( i
= 0; i
< count
; ++i
)
62 if( !image
.LoadFile( file
, type
, i
) )
64 wxLogError( _("Failed to load image %d from file '%s'."),
69 tmp
.CopyFromBitmap( wxBitmap( image
) );
74 const wxIcon
& wxIconBundle::GetIcon( const wxSize
& size
) const
76 size_t i
, max
= m_icons
.GetCount();
77 wxCoord sysX
= wxSystemSettings::GetMetric( wxSYS_ICON_X
),
78 sysY
= wxSystemSettings::GetMetric( wxSYS_ICON_Y
);
81 for( i
= 0; i
< max
; ++i
)
83 wxCoord sx
= m_icons
[i
].GetWidth(), sy
= m_icons
[i
].GetHeight();
85 if( sx
== size
.x
&& sy
== size
.y
)
87 // keep track if there is a system-size icon
88 if( sx
== sysX
&& sy
== sysY
)
89 sysIcon
= &m_icons
[i
];
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
;
98 void wxIconBundle::AddIcon( const wxIcon
& icon
)
100 size_t i
, max
= m_icons
.GetCount();
102 for( i
= 0; i
< max
; ++i
)
104 wxIcon
& tmp
= m_icons
[i
];
105 if( tmp
.GetWidth() == icon
.GetWidth() &&
106 tmp
.GetHeight() == icon
.GetHeight() )