]> git.saurik.com Git - wxWidgets.git/blob - src/msw/icon.cpp
compilation fix after last commit
[wxWidgets.git] / src / msw / icon.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msw/icon.cpp
3 // Purpose: wxIcon class
4 // Author: Julian Smart
5 // Modified by: 20.11.99 (VZ): don't derive from wxBitmap any more
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #ifndef WX_PRECOMP
28 #include "wx/defs.h"
29 #include "wx/list.h"
30 #include "wx/utils.h"
31 #include "wx/app.h"
32 #include "wx/icon.h"
33 #include "wx/bitmap.h"
34 #include "wx/log.h"
35 #endif
36
37 #include "wx/msw/private.h"
38
39 // ----------------------------------------------------------------------------
40 // wxWin macros
41 // ----------------------------------------------------------------------------
42
43 IMPLEMENT_DYNAMIC_CLASS(wxIcon, wxGDIObject)
44
45 // ============================================================================
46 // implementation
47 // ============================================================================
48
49 // ----------------------------------------------------------------------------
50 // wxIconRefData
51 // ----------------------------------------------------------------------------
52
53 void wxIconRefData::Free()
54 {
55 if ( m_hIcon )
56 {
57 #ifndef __WXMICROWIN__
58 ::DestroyIcon((HICON) m_hIcon);
59 #endif
60
61 m_hIcon = 0;
62 }
63 }
64
65 // ----------------------------------------------------------------------------
66 // wxIcon
67 // ----------------------------------------------------------------------------
68
69 wxIcon::wxIcon(const char bits[], int width, int height)
70 {
71 wxBitmap bmp(bits, width, height);
72 CopyFromBitmap(bmp);
73 }
74
75 wxIcon::wxIcon(const wxString& iconfile,
76 long flags,
77 int desiredWidth,
78 int desiredHeight)
79
80 {
81 LoadFile(iconfile, flags, desiredWidth, desiredHeight);
82 }
83
84 wxIcon::wxIcon(const wxIconLocation& loc)
85 {
86 // wxICOFileHandler accepts names in the format "filename;index"
87 wxString fullname = loc.GetFileName();
88 if ( loc.GetIndex() )
89 {
90 fullname << _T(';') << loc.GetIndex();
91 }
92 //else: 0 is default
93
94 LoadFile(fullname, wxBITMAP_TYPE_ICO);
95 }
96
97 wxIcon::~wxIcon()
98 {
99 }
100
101 wxObjectRefData *wxIcon::CloneRefData(const wxObjectRefData *dataOrig) const
102 {
103 const wxIconRefData *
104 data = wx_static_cast(const wxIconRefData *, dataOrig);
105 if ( !data )
106 return NULL;
107
108 // we don't have to copy m_hIcon because we're only called from SetHICON()
109 // which overwrites m_hIcon anyhow currently
110 //
111 // and if we're called from SetWidth/Height/Depth(), it doesn't make sense
112 // to copy it neither as the handle would be inconsistent with the new size
113 return new wxIconRefData(*data);
114 }
115
116 void wxIcon::CopyFromBitmap(const wxBitmap& bmp)
117 {
118 #ifndef __WXMICROWIN__
119 HICON hicon = wxBitmapToHICON(bmp);
120 if ( !hicon )
121 {
122 wxLogLastError(wxT("CreateIconIndirect"));
123 }
124 else
125 {
126 SetHICON((WXHICON)hicon);
127 SetSize(bmp.GetWidth(), bmp.GetHeight());
128 }
129 #endif // __WXMICROWIN__
130 }
131
132 void wxIcon::CreateIconFromXpm(const char **data)
133 {
134 wxBitmap bmp(data);
135 CopyFromBitmap(bmp);
136 }
137
138 bool wxIcon::LoadFile(const wxString& filename,
139 long type,
140 int desiredWidth, int desiredHeight)
141 {
142 UnRef();
143
144 wxGDIImageHandler *handler = FindHandler(type);
145
146 if ( !handler )
147 {
148 // say something?
149 return false;
150 }
151
152 return handler->Load(this, filename, type, desiredWidth, desiredHeight);
153 }
154