]>
Commit | Line | Data |
---|---|---|
2bda0e17 KB |
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 | |
8ed57d93 | 9 | // Licence: wxWindows license |
2bda0e17 KB |
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 | ||
47d67540 | 35 | #if wxUSE_XPM_IN_MSW |
2bda0e17 | 36 | #define FOR_MSW 1 |
4fabb575 | 37 | #include "../src/xpm/xpm34.h" |
2bda0e17 KB |
38 | #endif |
39 | ||
47d67540 | 40 | #if wxUSE_RESOURCE_LOADING_IN_MSW |
2bda0e17 KB |
41 | #include "wx/msw/curico.h" |
42 | #include "wx/msw/curicop.h" | |
43 | #endif | |
44 | ||
45 | #if !USE_SHARED_LIBRARIES | |
46 | IMPLEMENT_DYNAMIC_CLASS(wxIcon, wxBitmap) | |
47 | IMPLEMENT_DYNAMIC_CLASS(wxICOFileHandler, wxBitmapHandler) | |
48 | IMPLEMENT_DYNAMIC_CLASS(wxICOResourceHandler, wxBitmapHandler) | |
49 | #endif | |
50 | ||
51 | /* | |
52 | * Icons | |
53 | */ | |
54 | ||
55 | ||
56 | wxIconRefData::wxIconRefData(void) | |
57 | { | |
58 | m_hIcon = (WXHICON) NULL ; | |
59 | } | |
60 | ||
61 | wxIconRefData::~wxIconRefData(void) | |
62 | { | |
8ed57d93 VZ |
63 | if ( m_hIcon ) |
64 | ::DestroyIcon((HICON) m_hIcon); | |
2bda0e17 KB |
65 | } |
66 | ||
67 | wxIcon::wxIcon(void) | |
68 | { | |
69 | } | |
70 | ||
debe6624 | 71 | wxIcon::wxIcon(const char WXUNUSED(bits)[], int WXUNUSED(width), int WXUNUSED(height)) |
2bda0e17 KB |
72 | { |
73 | } | |
74 | ||
debe6624 | 75 | wxIcon::wxIcon(const wxString& icon_file, long flags, |
2bda0e17 KB |
76 | int desiredWidth, int desiredHeight) |
77 | ||
78 | { | |
79 | LoadFile(icon_file, flags, desiredWidth, desiredHeight); | |
80 | } | |
81 | ||
82 | wxIcon::~wxIcon(void) | |
83 | { | |
84 | } | |
85 | ||
86 | bool wxIcon::FreeResource(bool force) | |
87 | { | |
88 | if (M_ICONDATA && M_ICONDATA->m_hIcon) | |
89 | { | |
90 | DestroyIcon((HICON) M_ICONDATA->m_hIcon); | |
8ed57d93 | 91 | M_ICONDATA->m_hIcon = (WXHICON) NULL; |
2bda0e17 KB |
92 | } |
93 | return TRUE; | |
94 | } | |
95 | ||
debe6624 | 96 | bool wxIcon::LoadFile(const wxString& filename, long type, |
2bda0e17 KB |
97 | int desiredWidth, int desiredHeight) |
98 | { | |
99 | UnRef(); | |
100 | ||
101 | m_refData = new wxIconRefData; | |
102 | ||
103 | wxBitmapHandler *handler = FindHandler(type); | |
104 | ||
105 | if ( handler ) | |
8ed57d93 | 106 | return handler->LoadFile(this, filename, type, desiredWidth, desiredHeight); |
2bda0e17 | 107 | else |
8ed57d93 | 108 | return FALSE; |
2bda0e17 KB |
109 | } |
110 | ||
111 | void wxIcon::SetHICON(WXHICON ico) | |
112 | { | |
113 | if ( !M_ICONDATA ) | |
8ed57d93 | 114 | m_refData = new wxIconRefData; |
2bda0e17 KB |
115 | |
116 | M_ICONDATA->m_hIcon = ico; | |
117 | } | |
118 | ||
debe6624 | 119 | bool wxICOFileHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long flags, |
2bda0e17 KB |
120 | int desiredWidth, int desiredHeight) |
121 | { | |
47d67540 | 122 | #if wxUSE_RESOURCE_LOADING_IN_MSW |
8ed57d93 VZ |
123 | if ( bitmap->IsKindOf(CLASSINFO(wxIcon)) ) |
124 | { | |
125 | wxIcon *icon = (wxIcon *)bitmap; | |
126 | wxIconRefData *data = (wxIconRefData *)icon->GetRefData(); | |
127 | data->m_hIcon = (WXHICON)ReadIconFile((char *)name.c_str(), wxGetInstance(), | |
128 | &data->m_width, &data->m_height); | |
129 | ||
130 | data->m_ok = data->m_hIcon != 0; | |
131 | return data->m_ok; | |
132 | } | |
133 | else | |
134 | return FALSE; | |
2bda0e17 | 135 | #else |
8ed57d93 | 136 | return FALSE; |
2bda0e17 KB |
137 | #endif |
138 | } | |
139 | ||
debe6624 | 140 | bool wxICOResourceHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long flags, |
2bda0e17 KB |
141 | int desiredWidth, int desiredHeight) |
142 | { | |
8ed57d93 VZ |
143 | if ( bitmap->IsKindOf(CLASSINFO(wxIcon)) ) |
144 | { | |
2432b92d | 145 | #if defined(__WIN32__) && !defined(__SC__) |
2bda0e17 KB |
146 | if (desiredWidth > -1 && desiredHeight > -1) |
147 | { | |
148 | M_ICONHANDLERDATA->m_hIcon = (WXHICON) ::LoadImage(wxGetInstance(), name, IMAGE_ICON, desiredWidth, desiredHeight, LR_DEFAULTCOLOR); | |
149 | } | |
150 | else | |
151 | #endif | |
152 | { | |
8ed57d93 | 153 | M_ICONHANDLERDATA->m_hIcon = (WXHICON) ::LoadIcon(wxGetInstance(), name); |
2bda0e17 KB |
154 | } |
155 | ||
156 | #ifdef __WIN32__ | |
8ed57d93 VZ |
157 | // Win32s doesn't have GetIconInfo function... |
158 | if (M_ICONHANDLERDATA->m_hIcon && wxGetOsVersion()!=wxWIN32S) | |
159 | { | |
160 | ICONINFO info ; | |
161 | if (::GetIconInfo((HICON) M_ICONHANDLERDATA->m_hIcon, &info)) | |
162 | { | |
163 | HBITMAP ms_bitmap = info.hbmMask ; | |
164 | if (ms_bitmap) | |
165 | { | |
166 | BITMAP bm; | |
167 | ::GetObject(ms_bitmap, sizeof(BITMAP), (LPSTR) &bm); | |
168 | M_ICONHANDLERDATA->m_width = bm.bmWidth; | |
169 | M_ICONHANDLERDATA->m_height = bm.bmHeight; | |
170 | } | |
171 | if (info.hbmMask) | |
172 | ::DeleteObject(info.hbmMask) ; | |
173 | if (info.hbmColor) | |
174 | ::DeleteObject(info.hbmColor) ; | |
175 | } | |
176 | } | |
2bda0e17 | 177 | #else |
8ed57d93 VZ |
178 | M_ICONHANDLERDATA->m_width = 32; |
179 | M_ICONHANDLERDATA->m_height = 32; | |
2bda0e17 | 180 | #endif |
f60d0f94 JS |
181 | // Override the found values with desired values |
182 | if (desiredWidth > -1 && desiredHeight > -1) | |
183 | { | |
184 | M_ICONHANDLERDATA->m_width = desiredWidth; | |
185 | M_ICONHANDLERDATA->m_height = desiredHeight; | |
186 | } | |
187 | ||
8ed57d93 VZ |
188 | M_ICONHANDLERDATA->m_ok = (M_ICONHANDLERDATA->m_hIcon != 0); |
189 | return M_ICONHANDLERDATA->m_ok; | |
190 | } | |
191 | else | |
192 | return FALSE; | |
2bda0e17 KB |
193 | } |
194 |