]> git.saurik.com Git - wxWidgets.git/blob - src/msw/icon.cpp
Make it LPNM_UPDOWN, not LPNMUPDOWN, in Borland C++
[wxWidgets.git] / src / msw / icon.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: icon.cpp
3 // Purpose: wxIcon class
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "icon.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
24 #include <stdio.h>
25 #include "wx/setup.h"
26 #include "wx/list.h"
27 #include "wx/utils.h"
28 #include "wx/app.h"
29 #include "wx/icon.h"
30 #endif
31
32 #include "wx/msw/private.h"
33 #include "assert.h"
34
35 #if wxUSE_RESOURCE_LOADING_IN_MSW
36 #include "wx/msw/curico.h"
37 #include "wx/msw/curicop.h"
38 #endif
39
40 #if !USE_SHARED_LIBRARIES
41 IMPLEMENT_DYNAMIC_CLASS(wxIcon, wxBitmap)
42 IMPLEMENT_DYNAMIC_CLASS(wxICOFileHandler, wxBitmapHandler)
43 IMPLEMENT_DYNAMIC_CLASS(wxICOResourceHandler, wxBitmapHandler)
44 #endif
45
46 /*
47 * Icons
48 */
49
50
51 wxIconRefData::wxIconRefData(void)
52 {
53 m_hIcon = (WXHICON) NULL ;
54 }
55
56 wxIconRefData::~wxIconRefData(void)
57 {
58 if ( m_hIcon )
59 ::DestroyIcon((HICON) m_hIcon);
60 }
61
62 wxIcon::wxIcon(void)
63 {
64 }
65
66 wxIcon::wxIcon(const char WXUNUSED(bits)[], int WXUNUSED(width), int WXUNUSED(height))
67 {
68 }
69
70 wxIcon::wxIcon(const wxString& icon_file, long flags,
71 int desiredWidth, int desiredHeight)
72
73 {
74 LoadFile(icon_file, flags, desiredWidth, desiredHeight);
75 }
76
77 wxIcon::~wxIcon(void)
78 {
79 }
80
81 bool wxIcon::FreeResource(bool force)
82 {
83 if (M_ICONDATA && M_ICONDATA->m_hIcon)
84 {
85 DestroyIcon((HICON) M_ICONDATA->m_hIcon);
86 M_ICONDATA->m_hIcon = (WXHICON) NULL;
87 }
88 return TRUE;
89 }
90
91 bool wxIcon::LoadFile(const wxString& filename, long type,
92 int desiredWidth, int desiredHeight)
93 {
94 UnRef();
95
96 m_refData = new wxIconRefData;
97
98 wxBitmapHandler *handler = FindHandler(type);
99
100 if ( handler )
101 return handler->LoadFile(this, filename, type, desiredWidth, desiredHeight);
102 else
103 return FALSE;
104 }
105
106 void wxIcon::SetHICON(WXHICON ico)
107 {
108 if ( !M_ICONDATA )
109 m_refData = new wxIconRefData;
110
111 M_ICONDATA->m_hIcon = ico;
112 }
113
114 bool wxICOFileHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
115 int desiredWidth, int desiredHeight)
116 {
117 #if wxUSE_RESOURCE_LOADING_IN_MSW
118 if ( bitmap->IsKindOf(CLASSINFO(wxIcon)) )
119 {
120 wxIcon *icon = (wxIcon *)bitmap;
121 wxIconRefData *data = (wxIconRefData *)icon->GetRefData();
122 data->m_hIcon = (WXHICON)ReadIconFile((wxChar *)name.c_str(), wxGetInstance(),
123 &data->m_width, &data->m_height);
124
125 data->m_ok = data->m_hIcon != 0;
126 return data->m_ok;
127 }
128 else
129 return FALSE;
130 #else
131 return FALSE;
132 #endif
133 }
134
135 bool wxICOResourceHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
136 int desiredWidth, int desiredHeight)
137 {
138 if ( bitmap->IsKindOf(CLASSINFO(wxIcon)) )
139 {
140 #if defined(__WIN32__) && !defined(__SC__)
141 if (desiredWidth > -1 && desiredHeight > -1)
142 {
143 M_ICONHANDLERDATA->m_hIcon = (WXHICON) ::LoadImage(wxGetInstance(), name, IMAGE_ICON, desiredWidth, desiredHeight, LR_DEFAULTCOLOR);
144 }
145 else
146 #endif
147 {
148 M_ICONHANDLERDATA->m_hIcon = (WXHICON) ::LoadIcon(wxGetInstance(), name);
149 }
150
151 #ifdef __WIN32__
152 // Win32s doesn't have GetIconInfo function...
153 if (M_ICONHANDLERDATA->m_hIcon && wxGetOsVersion()!=wxWIN32S)
154 {
155 ICONINFO info ;
156 if (::GetIconInfo((HICON) M_ICONHANDLERDATA->m_hIcon, &info))
157 {
158 HBITMAP ms_bitmap = info.hbmMask ;
159 if (ms_bitmap)
160 {
161 BITMAP bm;
162 ::GetObject(ms_bitmap, sizeof(BITMAP), (LPSTR) &bm);
163 M_ICONHANDLERDATA->m_width = bm.bmWidth;
164 M_ICONHANDLERDATA->m_height = bm.bmHeight;
165 }
166 if (info.hbmMask)
167 ::DeleteObject(info.hbmMask) ;
168 if (info.hbmColor)
169 ::DeleteObject(info.hbmColor) ;
170 }
171 }
172 #else
173 M_ICONHANDLERDATA->m_width = 32;
174 M_ICONHANDLERDATA->m_height = 32;
175 #endif
176 // Override the found values with desired values
177 if (desiredWidth > -1 && desiredHeight > -1)
178 {
179 M_ICONHANDLERDATA->m_width = desiredWidth;
180 M_ICONHANDLERDATA->m_height = desiredHeight;
181 }
182
183 M_ICONHANDLERDATA->m_ok = (M_ICONHANDLERDATA->m_hIcon != 0);
184 return M_ICONHANDLERDATA->m_ok;
185 }
186 else
187 return FALSE;
188 }
189