]> git.saurik.com Git - wxWidgets.git/blame - src/msw/icon.cpp
wxRTC: save and load the 'shown' status in case there's a situation where layout...
[wxWidgets.git] / src / msw / icon.cpp
CommitLineData
2bda0e17 1/////////////////////////////////////////////////////////////////////////////
7520f3da 2// Name: src/msw/icon.cpp
2bda0e17
KB
3// Purpose: wxIcon class
4// Author: Julian Smart
0d0512bd 5// Modified by: 20.11.99 (VZ): don't derive from wxBitmap any more
2bda0e17 6// Created: 04/01/98
6c9a19aa 7// Copyright: (c) Julian Smart
65571936 8// Licence: wxWindows licence
2bda0e17
KB
9/////////////////////////////////////////////////////////////////////////////
10
0d0512bd
VZ
11// ============================================================================
12// declarations
13// ============================================================================
14
15// ----------------------------------------------------------------------------
16// headers
17// ----------------------------------------------------------------------------
18
2bda0e17
KB
19// For compilers that support precompilation, includes "wx.h".
20#include "wx/wxprec.h"
21
22#ifdef __BORLANDC__
0d0512bd 23 #pragma hdrstop
2bda0e17
KB
24#endif
25
26#ifndef WX_PRECOMP
0d0512bd
VZ
27 #include "wx/list.h"
28 #include "wx/utils.h"
29 #include "wx/app.h"
30 #include "wx/icon.h"
f02b73c4 31 #include "wx/bitmap.h"
f94dfb38 32 #include "wx/log.h"
2bda0e17
KB
33#endif
34
35#include "wx/msw/private.h"
2bda0e17 36
0d0512bd
VZ
37// ----------------------------------------------------------------------------
38// wxWin macros
39// ----------------------------------------------------------------------------
40
621b3e21 41IMPLEMENT_DYNAMIC_CLASS(wxIcon, wxGDIObject)
2bda0e17 42
0d0512bd
VZ
43// ============================================================================
44// implementation
45// ============================================================================
2bda0e17 46
0d0512bd
VZ
47// ----------------------------------------------------------------------------
48// wxIconRefData
49// ----------------------------------------------------------------------------
2bda0e17 50
0d0512bd 51void wxIconRefData::Free()
2bda0e17 52{
0d0512bd 53 if ( m_hIcon )
032af30f 54 {
04ef50df 55#ifndef __WXMICROWIN__
0d0512bd 56 ::DestroyIcon((HICON) m_hIcon);
04ef50df 57#endif
032af30f
VZ
58
59 m_hIcon = 0;
60 }
2bda0e17
KB
61}
62
0d0512bd
VZ
63// ----------------------------------------------------------------------------
64// wxIcon
65// ----------------------------------------------------------------------------
2bda0e17 66
4b7f2165 67wxIcon::wxIcon(const char bits[], int width, int height)
2bda0e17 68{
4b7f2165
VZ
69 wxBitmap bmp(bits, width, height);
70 CopyFromBitmap(bmp);
2bda0e17
KB
71}
72
0d0512bd 73wxIcon::wxIcon(const wxString& iconfile,
e86f2cc8 74 wxBitmapType type,
0d0512bd
VZ
75 int desiredWidth,
76 int desiredHeight)
2bda0e17
KB
77
78{
e86f2cc8 79 LoadFile(iconfile, type, desiredWidth, desiredHeight);
2bda0e17
KB
80}
81
aaf7ab43
VZ
82wxIcon::wxIcon(const wxIconLocation& loc)
83{
84 // wxICOFileHandler accepts names in the format "filename;index"
85 wxString fullname = loc.GetFileName();
86 if ( loc.GetIndex() )
87 {
9a83f860 88 fullname << wxT(';') << loc.GetIndex();
aaf7ab43
VZ
89 }
90 //else: 0 is default
91
81ba2662 92 LoadFile(fullname, wxBITMAP_TYPE_ICO);
aaf7ab43
VZ
93}
94
0d0512bd 95wxIcon::~wxIcon()
2bda0e17
KB
96{
97}
98
9d769508
VZ
99wxObjectRefData *wxIcon::CloneRefData(const wxObjectRefData *dataOrig) const
100{
101 const wxIconRefData *
5c33522f 102 data = static_cast<const wxIconRefData *>(dataOrig);
9d769508
VZ
103 if ( !data )
104 return NULL;
105
d79c8ea9
VZ
106 // we don't have to copy m_hIcon because we're only called from SetHICON()
107 // which overwrites m_hIcon anyhow currently
108 //
109 // and if we're called from SetWidth/Height/Depth(), it doesn't make sense
110 // to copy it neither as the handle would be inconsistent with the new size
111 return new wxIconRefData(*data);
9d769508
VZ
112}
113
4b7f2165
VZ
114void wxIcon::CopyFromBitmap(const wxBitmap& bmp)
115{
04ef50df 116#ifndef __WXMICROWIN__
7fd328a3 117 HICON hicon = wxBitmapToHICON(bmp);
4b7f2165
VZ
118 if ( !hicon )
119 {
f6bcfd97 120 wxLogLastError(wxT("CreateIconIndirect"));
4b7f2165
VZ
121 }
122 else
123 {
124 SetHICON((WXHICON)hicon);
125 SetSize(bmp.GetWidth(), bmp.GetHeight());
126 }
7fd328a3 127#endif // __WXMICROWIN__
4b7f2165
VZ
128}
129
e45080c1 130void wxIcon::CreateIconFromXpm(const char* const* data)
4b7f2165
VZ
131{
132 wxBitmap bmp(data);
133 CopyFromBitmap(bmp);
134}
135
0d0512bd 136bool wxIcon::LoadFile(const wxString& filename,
e86f2cc8 137 wxBitmapType type,
0d0512bd 138 int desiredWidth, int desiredHeight)
2bda0e17 139{
0d0512bd 140 UnRef();
2bda0e17 141
0d0512bd 142 wxGDIImageHandler *handler = FindHandler(type);
2bda0e17 143
0d0512bd 144 if ( !handler )
2bda0e17 145 {
3e0630be
VZ
146 // load via wxBitmap which, in turn, uses wxImage allowing us to
147 // support more formats
148 wxBitmap bmp;
149 if ( !bmp.LoadFile(filename, type) )
150 return false;
151
152 CopyFromBitmap(bmp);
153 return true;
2bda0e17
KB
154 }
155
0d0512bd 156 return handler->Load(this, filename, type, desiredWidth, desiredHeight);
2bda0e17 157}
973abcbb
VZ
158
159bool wxIcon::CreateFromHICON(WXHICON icon)
160{
161 SetHICON(icon);
162 if ( !IsOk() )
163 return false;
164
165 SetSize(wxGetHiconSize(icon));
166
167 return true;
168}