]>
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"
27 #include "wx/bitmap.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()
57 void wxIconBundle::AddIcon( const wxString
& file
, long type
)
59 size_t count
= wxImage::GetImageCount( file
, type
);
63 for( i
= 0; i
< count
; ++i
)
65 if( !image
.LoadFile( file
, type
, i
) )
67 wxLogError( _("Failed to load image %d from file '%s'."),
72 wxIcon
* tmp
= new wxIcon();
73 tmp
->CopyFromBitmap( wxBitmap( image
) );
79 const wxIcon
& wxIconBundle::GetIcon( const wxSize
& size
) const
81 size_t i
, max
= m_icons
.GetCount();
82 wxCoord sysX
= wxSystemSettings::GetMetric( wxSYS_ICON_X
),
83 sysY
= wxSystemSettings::GetMetric( wxSYS_ICON_Y
);
86 // temp. variable needed to fix Borland C++ 5.5.1 problem
87 // with passing a return value through two functions
90 for( i
= 0; i
< max
; i
++ )
92 if( !m_icons
[i
].Ok() )
94 wxCoord sx
= m_icons
[i
].GetWidth(), sy
= m_icons
[i
].GetHeight();
96 if( sx
== size
.x
&& sy
== size
.y
)
98 tmp
= &m_icons
[i
]; // fix for broken BCC
101 // keep track if there is a system-size icon
102 if( sx
== sysX
&& sy
== sysY
)
103 sysIcon
= &m_icons
[i
];
106 // return the system-sized icon if we've got one
107 if( sysIcon
) return *sysIcon
;
108 // return the first icon, if we have one
109 if( max
> 0 ) // fix for broken BCC
116 void wxIconBundle::AddIcon( const wxIcon
& icon
)
118 size_t i
, max
= m_icons
.GetCount();
120 for( i
= 0; i
< max
; ++i
)
122 wxIcon
& tmp
= m_icons
[i
];
123 if( tmp
.Ok() && tmp
.GetWidth() == icon
.GetWidth() &&
124 tmp
.GetHeight() == icon
.GetHeight() )