]>
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 | |
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 USE_XPM_IN_MSW | |
36 | #define FOR_MSW 1 | |
37 | #include "..\..\contrib\wxxpm\libxpm.34b\lib\xpm34.h" | |
38 | #endif | |
39 | ||
40 | #if USE_RESOURCE_LOADING_IN_MSW | |
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 | { | |
63 | if ( m_hIcon ) | |
64 | ::DestroyIcon((HICON) m_hIcon); | |
65 | } | |
66 | ||
67 | wxIcon::wxIcon(void) | |
68 | { | |
69 | } | |
70 | ||
71 | wxIcon::wxIcon(const char WXUNUSED(bits)[], const int WXUNUSED(width), const int WXUNUSED(height)) | |
72 | { | |
73 | } | |
74 | ||
75 | wxIcon::wxIcon(const wxString& icon_file, const long flags, | |
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); | |
91 | M_ICONDATA->m_hIcon = (WXHICON) NULL; | |
92 | } | |
93 | return TRUE; | |
94 | } | |
95 | ||
96 | bool wxIcon::LoadFile(const wxString& filename, const long type, | |
97 | int desiredWidth, int desiredHeight) | |
98 | { | |
99 | UnRef(); | |
100 | ||
101 | m_refData = new wxIconRefData; | |
102 | ||
103 | wxBitmapHandler *handler = FindHandler(type); | |
104 | ||
105 | if ( handler ) | |
106 | return handler->LoadFile(this, filename, type, desiredWidth, desiredHeight); | |
107 | else | |
108 | return FALSE; | |
109 | } | |
110 | ||
111 | void wxIcon::SetHICON(WXHICON ico) | |
112 | { | |
113 | if ( !M_ICONDATA ) | |
114 | m_refData = new wxIconRefData; | |
115 | ||
116 | M_ICONDATA->m_hIcon = ico; | |
117 | } | |
118 | ||
119 | bool wxICOFileHandler::LoadFile(wxBitmap *bitmap, const wxString& name, const long flags, | |
120 | int desiredWidth, int desiredHeight) | |
121 | { | |
122 | #if USE_RESOURCE_LOADING_IN_MSW | |
123 | if ( bitmap->IsKindOf(CLASSINFO(wxIcon)) ) | |
124 | { | |
125 | wxIcon *icon = (wxIcon *)bitmap; | |
126 | int width, height; | |
127 | WXHICON hIcon = (WXHICON) ReadIconFile((char *)(const char *)name, wxGetInstance(), &width, &height); | |
128 | ||
129 | ((wxIconRefData *)icon->GetRefData())->m_hIcon = hIcon; | |
130 | ((wxIconRefData *)icon->GetRefData())->m_ok = (((wxIconRefData *)icon->GetRefData())->m_hIcon != 0); | |
131 | return ((wxIconRefData *)icon->GetRefData())->m_ok; | |
132 | } | |
133 | else | |
134 | return FALSE; | |
135 | #else | |
136 | return FALSE; | |
137 | #endif | |
138 | } | |
139 | ||
140 | bool wxICOResourceHandler::LoadFile(wxBitmap *bitmap, const wxString& name, const long flags, | |
141 | int desiredWidth, int desiredHeight) | |
142 | { | |
143 | if ( bitmap->IsKindOf(CLASSINFO(wxIcon)) ) | |
144 | { | |
145 | #if defined(__WIN32__) | |
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 | { | |
153 | M_ICONHANDLERDATA->m_hIcon = (WXHICON) ::LoadIcon(wxGetInstance(), name); | |
154 | } | |
155 | ||
156 | #ifdef __WIN32__ | |
157 | /*** | |
158 | DWORD vers = GetVersion() ; | |
159 | WORD high = HIWORD(vers) ; // high bit=0 for NT, 1 for Win32s | |
160 | // Win32s doesn't have GetIconInfo function... | |
161 | if (M_ICONHANDLERDATA->m_hIcon && (high&0x8000)==0 ) | |
162 | ***/ | |
163 | if (M_ICONHANDLERDATA->m_hIcon && wxGetOsVersion()==wxWINDOWS_NT) | |
164 | { | |
165 | ICONINFO info ; | |
166 | if (::GetIconInfo((HICON) M_ICONHANDLERDATA->m_hIcon, &info)) | |
167 | { | |
168 | HBITMAP ms_bitmap = info.hbmMask ; | |
169 | if (ms_bitmap) | |
170 | { | |
171 | BITMAP bm; | |
172 | ::GetObject(ms_bitmap, sizeof(BITMAP), (LPSTR) &bm); | |
173 | M_ICONHANDLERDATA->m_width = bm.bmWidth; | |
174 | M_ICONHANDLERDATA->m_height = bm.bmHeight; | |
175 | } | |
176 | if (info.hbmMask) | |
177 | ::DeleteObject(info.hbmMask) ; | |
178 | if (info.hbmColor) | |
179 | ::DeleteObject(info.hbmColor) ; | |
180 | } | |
181 | } | |
182 | #else | |
183 | M_ICONHANDLERDATA->m_width = 32; | |
184 | M_ICONHANDLERDATA->m_height = 32; | |
185 | #endif | |
186 | M_ICONHANDLERDATA->m_ok = (M_ICONHANDLERDATA->m_hIcon != 0); | |
187 | return M_ICONHANDLERDATA->m_ok; | |
188 | } | |
189 | else | |
190 | return FALSE; | |
191 | } | |
192 |