1 | /*
|
---|
2 | * Win32 Window Class Managment Code for OS/2
|
---|
3 | *
|
---|
4 | * 18-07-1998 SvL: Merged all class code into this file + bug fixes
|
---|
5 | * Register all system classes at dll init
|
---|
6 | * Rewrote incorrect callback code
|
---|
7 | *
|
---|
8 | * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
|
---|
9 | *
|
---|
10 | *
|
---|
11 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
12 | *
|
---|
13 | */
|
---|
14 | #include <os2win.h>
|
---|
15 | #include <stdarg.h>
|
---|
16 | #include <assert.h>
|
---|
17 | #include "misc.h"
|
---|
18 | #include "user32.h"
|
---|
19 | #include "wndproc.h"
|
---|
20 | #include "wndclass.h"
|
---|
21 | #include "hooks.h"
|
---|
22 |
|
---|
23 | //default window handlers that are registered by RegisterClass are called
|
---|
24 | //in this callback handler
|
---|
25 | LRESULT EXPENTRY_O32 OS2ToWinCallback(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam);
|
---|
26 | //default window handlers that are queried by GetClassInfo/GetClassLong is really
|
---|
27 | //this callback handler
|
---|
28 | LRESULT WIN32API WinToOS2Callback(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam);
|
---|
29 |
|
---|
30 | #ifdef DEBUG
|
---|
31 | char *GetMsgText(int Msg);
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | DWORD MapOEMToRealKey(DWORD wParam, DWORD lParam);
|
---|
35 |
|
---|
36 | WNDPROC_O32 ButtonHandler = 0;
|
---|
37 | WNDPROC_O32 ListboxHandler = 0;
|
---|
38 | WNDPROC_O32 ComboboxHandler = 0;
|
---|
39 | WNDPROC_O32 EditHandler = 0;
|
---|
40 | WNDPROC_O32 MdiClientHandler = 0;
|
---|
41 | WNDPROC_O32 ScrollbarHandler = 0;
|
---|
42 | WNDPROC_O32 StaticHandler = 0;
|
---|
43 | //******************************************************************************
|
---|
44 | //******************************************************************************
|
---|
45 | LRESULT WIN32API ButtonCallback(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
|
---|
46 | {
|
---|
47 | return ButtonHandler(hwnd, Msg, wParam, lParam);
|
---|
48 | }
|
---|
49 | //******************************************************************************
|
---|
50 | //******************************************************************************
|
---|
51 | LRESULT WIN32API ListboxCallback(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
|
---|
52 | {
|
---|
53 | return ListboxHandler(hwnd, Msg, wParam, lParam);
|
---|
54 | }
|
---|
55 | //******************************************************************************
|
---|
56 | //******************************************************************************
|
---|
57 | LRESULT WIN32API ComboboxCallback(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
|
---|
58 | {
|
---|
59 | return ComboboxHandler(hwnd, Msg, wParam, lParam);
|
---|
60 | }
|
---|
61 | //******************************************************************************
|
---|
62 | //******************************************************************************
|
---|
63 | LRESULT WIN32API MdiClientCallback(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
|
---|
64 | {
|
---|
65 | return MdiClientHandler(hwnd, Msg, wParam, lParam);
|
---|
66 | }
|
---|
67 | //******************************************************************************
|
---|
68 | //******************************************************************************
|
---|
69 | LRESULT WIN32API EditCallback(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
|
---|
70 | {
|
---|
71 | return EditHandler(hwnd, Msg, wParam, lParam);
|
---|
72 | }
|
---|
73 | //******************************************************************************
|
---|
74 | //******************************************************************************
|
---|
75 | LRESULT WIN32API ScrollbarCallback(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
|
---|
76 | {
|
---|
77 | return ScrollbarHandler(hwnd, Msg, wParam, lParam);
|
---|
78 | }
|
---|
79 | //******************************************************************************
|
---|
80 | //******************************************************************************
|
---|
81 | LRESULT WIN32API StaticCallback(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
|
---|
82 | {
|
---|
83 | return StaticHandler(hwnd, Msg, wParam, lParam);
|
---|
84 | }
|
---|
85 | //******************************************************************************
|
---|
86 | //SvL: 18-7-'98, Registers system window classes (button, listbox etc etc)
|
---|
87 | //******************************************************************************
|
---|
88 | void RegisterSystemClasses(ULONG hModule)
|
---|
89 | {
|
---|
90 | WNDCLASSA wndclass;
|
---|
91 |
|
---|
92 | if(O32_GetClassInfo(NULL, "BUTTON", &wndclass)) {
|
---|
93 | new Win32WindowClass(ButtonCallback, "BUTTON", hModule);
|
---|
94 | ButtonHandler = (WNDPROC_O32)wndclass.lpfnWndProc;
|
---|
95 | }
|
---|
96 | if(O32_GetClassInfo(NULL, "LISTBOX", &wndclass)) {
|
---|
97 | new Win32WindowClass(ListboxCallback, "LISTBOX", hModule);
|
---|
98 | ListboxHandler = (WNDPROC_O32)wndclass.lpfnWndProc;
|
---|
99 | }
|
---|
100 | if(O32_GetClassInfo(NULL, "COMBOBOX", &wndclass)) {
|
---|
101 | new Win32WindowClass(ComboboxCallback, "COMBOBOX", hModule);
|
---|
102 | ComboboxHandler = (WNDPROC_O32)wndclass.lpfnWndProc;
|
---|
103 | }
|
---|
104 | if(O32_GetClassInfo(NULL, "EDIT", &wndclass)) {
|
---|
105 | new Win32WindowClass(EditCallback, "EDIT", hModule);
|
---|
106 | EditHandler = (WNDPROC_O32)wndclass.lpfnWndProc;
|
---|
107 | }
|
---|
108 | if(O32_GetClassInfo(NULL, "MDICLIENT", &wndclass)) {
|
---|
109 | new Win32WindowClass(MdiClientCallback, "MDICLIENT", hModule);
|
---|
110 | MdiClientHandler = (WNDPROC_O32)wndclass.lpfnWndProc;
|
---|
111 | }
|
---|
112 | if(O32_GetClassInfo(NULL, "SCROLLBAR", &wndclass)) {
|
---|
113 | new Win32WindowClass(ScrollbarCallback, "SCROLLBAR", hModule);
|
---|
114 | ScrollbarHandler = (WNDPROC_O32)wndclass.lpfnWndProc;
|
---|
115 | }
|
---|
116 | if(O32_GetClassInfo(NULL, "STATIC", &wndclass)) {
|
---|
117 | new Win32WindowClass(StaticCallback, "STATIC", hModule);
|
---|
118 | StaticHandler = (WNDPROC_O32)wndclass.lpfnWndProc;
|
---|
119 | }
|
---|
120 | //TODO: More standard classes in win95/NT4?
|
---|
121 | }
|
---|
122 | //******************************************************************************
|
---|
123 | //SvL: 18-7-'98: Moved here from user32.cpp
|
---|
124 | //******************************************************************************
|
---|
125 | ATOM WIN32API RegisterClassA(const WNDCLASSA *lpWndClass)
|
---|
126 | {
|
---|
127 | ATOM rc;
|
---|
128 | WNDCLASSA wc;
|
---|
129 |
|
---|
130 | #ifdef DEBUG
|
---|
131 | WriteLog("USER32: RegisterClassA\n");
|
---|
132 | WriteLog("USER32: lpWndClass->style %X\n", lpWndClass->style);
|
---|
133 | WriteLog("USER32: lpWndClass->lpfnWndProc %X\n", lpWndClass->lpfnWndProc);
|
---|
134 | WriteLog("USER32: lpWndClass->cbClsExtra %X\n", lpWndClass->cbClsExtra);
|
---|
135 | WriteLog("USER32: lpWndClass->cbWndExtra %X\n", lpWndClass->cbWndExtra);
|
---|
136 | WriteLog("USER32: lpWndClass->hInstance %X\n", lpWndClass->hInstance);
|
---|
137 | WriteLog("USER32: lpWndClass->hIcon %X\n", lpWndClass->hIcon);
|
---|
138 | WriteLog("USER32: lpWndClass->hCursor %X\n", lpWndClass->hCursor);
|
---|
139 | WriteLog("USER32: lpWndClass->hbrBackground %X\n", lpWndClass->hbrBackground);
|
---|
140 | WriteLog("USER32: lpWndClass->lpszMenuName %X\n", lpWndClass->lpszMenuName);
|
---|
141 | if((int)lpWndClass->lpszClassName >> 16 == 0)
|
---|
142 | WriteLog("USER32: lpWndClass->lpszClassName %X\n", lpWndClass->lpszClassName);
|
---|
143 | else WriteLog("USER32: lpWndClass->lpszClassName %s\n", lpWndClass->lpszClassName);
|
---|
144 | #endif
|
---|
145 | memcpy(&wc, lpWndClass, sizeof(WNDCLASSA));
|
---|
146 |
|
---|
147 | if((int)wc.lpszMenuName >> 16 != 0) {//convert string name identifier to numeric id
|
---|
148 | dprintf(("USER32: lpszMenuName %s\n", wc.lpszMenuName));
|
---|
149 | *(int *)&wc.lpszMenuName = ConvertNameId(0, (char *)wc.lpszMenuName);
|
---|
150 | dprintf(("USER32: Menu id = %d\n", (int)wc.lpszMenuName));
|
---|
151 | }
|
---|
152 | #ifdef DEBUG
|
---|
153 | if(wc.style & (CS_PARENTDC | CS_CLASSDC)) {
|
---|
154 | dprintf(("USER32: Class uses an unsupported style!!!\n"));
|
---|
155 | }
|
---|
156 | #endif
|
---|
157 | //These are not supported by Open32
|
---|
158 | wc.style &= ~(CS_PARENTDC | CS_CLASSDC);
|
---|
159 |
|
---|
160 | //SvL: 18-7-'98 Breaks apps (solitaire, rasmol..)
|
---|
161 | #if 0
|
---|
162 | /* @@@PH 98/06/21 experimental fix for WInhlp32 */
|
---|
163 | #ifndef CS_SYNCPAINT
|
---|
164 | #define CS_SYNCPAINT 0x02000000L
|
---|
165 | #endif
|
---|
166 |
|
---|
167 | wc.style |= CS_SYNCPAINT;
|
---|
168 | #endif
|
---|
169 |
|
---|
170 | wc.lpfnWndProc = (WNDPROC)Win32WindowClass::GetOS2ClassCallback();
|
---|
171 | rc = O32_RegisterClass(&wc);
|
---|
172 | if(rc) {
|
---|
173 | Win32WindowClass *wndclass = new Win32WindowClass((WNDPROC)lpWndClass->lpfnWndProc, (LPSTR)wc.lpszClassName, wc.hInstance);
|
---|
174 | }
|
---|
175 | dprintf(("USER32: RegisterClass returned %d (%d)\n", rc, GetLastError()));
|
---|
176 | return(rc);
|
---|
177 | }
|
---|
178 | //******************************************************************************
|
---|
179 | //SvL: 18-7-'98: Moved here from user32.cpp
|
---|
180 | //******************************************************************************
|
---|
181 | ATOM WIN32API RegisterClassExA(const WNDCLASSEXA *lpWndClass)
|
---|
182 | {
|
---|
183 | ATOM rc;
|
---|
184 | WNDCLASSEXA wc;
|
---|
185 |
|
---|
186 | #ifdef DEBUG
|
---|
187 | WriteLog("USER32: lpWndClass->cbSize %X\n", lpWndClass->cbSize);
|
---|
188 | WriteLog("USER32: lpWndClass->style %X\n", lpWndClass->style);
|
---|
189 | WriteLog("USER32: lpWndClass->lpfnWndProc %X\n", lpWndClass->lpfnWndProc);
|
---|
190 | WriteLog("USER32: lpWndClass->cbClsExtra %X\n", lpWndClass->cbClsExtra);
|
---|
191 | WriteLog("USER32: lpWndClass->cbWndExtra %X\n", lpWndClass->cbWndExtra);
|
---|
192 | WriteLog("USER32: lpWndClass->hInstance %X\n", lpWndClass->hInstance);
|
---|
193 | WriteLog("USER32: lpWndClass->hIcon %X\n", lpWndClass->hIcon);
|
---|
194 | WriteLog("USER32: lpWndClass->hCursor %X\n", lpWndClass->hCursor);
|
---|
195 | WriteLog("USER32: lpWndClass->hbrBackground %X\n", lpWndClass->hbrBackground);
|
---|
196 | WriteLog("USER32: lpWndClass->lpszMenuName %X\n", lpWndClass->lpszMenuName);
|
---|
197 | if((int)lpWndClass->lpszClassName >> 16 == 0)
|
---|
198 | WriteLog("USER32: lpWndClass->lpszClassName %X\n", lpWndClass->lpszClassName);
|
---|
199 | else WriteLog("USER32: lpWndClass->lpszClassName %s\n", lpWndClass->lpszClassName);
|
---|
200 | #endif
|
---|
201 | memcpy(&wc, lpWndClass, sizeof(WNDCLASSEXA));
|
---|
202 |
|
---|
203 | if((int)wc.lpszMenuName >> 16 != 0) {//convert string name identifier to numeric id
|
---|
204 | dprintf(("USER32: lpszMenuName %s\n", wc.lpszMenuName));
|
---|
205 | *(int *)&wc.lpszMenuName = ConvertNameId(0, (char *)wc.lpszMenuName);
|
---|
206 | dprintf(("USER32: Menu id = %d\n", (int)wc.lpszMenuName));
|
---|
207 | }
|
---|
208 | if(wc.cbSize != sizeof(WNDCLASSEXA))
|
---|
209 | return(0);
|
---|
210 |
|
---|
211 | #ifdef DEBUG
|
---|
212 | if(wc.style & (CS_PARENTDC | CS_CLASSDC)) {
|
---|
213 | dprintf(("USER32: Class uses an unsupported style!!!\n"));
|
---|
214 | }
|
---|
215 | #endif
|
---|
216 | //These are not supported by Open32
|
---|
217 | wc.style &= ~(CS_PARENTDC | CS_CLASSDC);
|
---|
218 |
|
---|
219 | //SvL: 18-7-'98 Breaks apps (solitaire, rasmol..)
|
---|
220 | #if 0
|
---|
221 | /* @@@PH 98/06/21 experimental fix for WInhlp32 */
|
---|
222 | #ifndef CS_SYNCPAINT
|
---|
223 | #define CS_SYNCPAINT 0x02000000L
|
---|
224 | #endif
|
---|
225 |
|
---|
226 | wc.style |= CS_SYNCPAINT;
|
---|
227 | #endif
|
---|
228 |
|
---|
229 | wc.lpfnWndProc = (WNDPROC)Win32WindowClass::GetOS2ClassCallback();
|
---|
230 |
|
---|
231 | rc = O32_RegisterClass((WNDCLASSA *)&wc.style);
|
---|
232 | if(rc) {
|
---|
233 | Win32WindowClass *wndclass = new Win32WindowClass((WNDPROC)lpWndClass->lpfnWndProc, (LPSTR)wc.lpszClassName, wc.hInstance);
|
---|
234 | }
|
---|
235 | #ifdef DEBUG
|
---|
236 | WriteLog("USER32: RegisterClassExA, not completely supported, returned %d\n", rc);
|
---|
237 | if(rc == 0)
|
---|
238 | WriteLog("USER32: GetLastError returned %X\n", GetLastError());
|
---|
239 |
|
---|
240 | #endif
|
---|
241 | return(rc);
|
---|
242 | }
|
---|
243 | //******************************************************************************
|
---|
244 | //******************************************************************************
|
---|
245 | WORD WIN32API RegisterClassW(const WNDCLASSW *lpwc)
|
---|
246 | {
|
---|
247 | ATOM rc;
|
---|
248 | WNDCLASSA wclass;
|
---|
249 |
|
---|
250 | dprintf(("RegisterClassW\n"));
|
---|
251 | memcpy(&wclass, lpwc, sizeof(WNDCLASSA));
|
---|
252 | if(wclass.lpszMenuName && ((int)wclass.lpszMenuName >> 16 != 0)) {
|
---|
253 | wclass.lpszMenuName = UnicodeToAsciiString((LPWSTR)lpwc->lpszMenuName);
|
---|
254 | }
|
---|
255 | if(wclass.lpszClassName && ((int)wclass.lpszClassName >> 16 != 0)) {
|
---|
256 | wclass.lpszClassName = UnicodeToAsciiString((LPWSTR)lpwc->lpszClassName);
|
---|
257 | }
|
---|
258 |
|
---|
259 | rc = RegisterClassA(&wclass);
|
---|
260 |
|
---|
261 | //TODO: Assuming RegisterClass doesn't mess up our structure
|
---|
262 | if(lpwc->lpszMenuName && ((int)lpwc->lpszMenuName >> 16 != 0)) {
|
---|
263 | FreeAsciiString((char *)wclass.lpszMenuName);
|
---|
264 | }
|
---|
265 | if(lpwc->lpszClassName && ((int)lpwc->lpszClassName >> 16 != 0)) {
|
---|
266 | FreeAsciiString((char *)wclass.lpszClassName);
|
---|
267 | }
|
---|
268 | return(rc);
|
---|
269 | }
|
---|
270 | //******************************************************************************
|
---|
271 | //******************************************************************************
|
---|
272 | ATOM WIN32API RegisterClassExW(CONST WNDCLASSEXW *lpwc)
|
---|
273 | {
|
---|
274 | ATOM rc;
|
---|
275 | WNDCLASSEXA wclass;
|
---|
276 |
|
---|
277 | dprintf(("RegisterClassExW\n"));
|
---|
278 | memcpy(&wclass, lpwc, sizeof(WNDCLASSEXA));
|
---|
279 | if(wclass.lpszMenuName && ((int)wclass.lpszMenuName >> 16 != 0)) {
|
---|
280 | wclass.lpszMenuName = UnicodeToAsciiString((LPWSTR)lpwc->lpszMenuName);
|
---|
281 | }
|
---|
282 | if(wclass.lpszClassName && ((int)wclass.lpszClassName >> 16 != 0)) {
|
---|
283 | wclass.lpszClassName = UnicodeToAsciiString((LPWSTR)lpwc->lpszClassName);
|
---|
284 | }
|
---|
285 |
|
---|
286 | rc = RegisterClassExA(&wclass);
|
---|
287 |
|
---|
288 | //TODO: Assuming RegisterClassEx doesn't mess up our structure
|
---|
289 | if(lpwc->lpszMenuName && ((int)lpwc->lpszMenuName >> 16 != 0)) {
|
---|
290 | FreeAsciiString((char *)wclass.lpszMenuName);
|
---|
291 | }
|
---|
292 | if(lpwc->lpszClassName && ((int)lpwc->lpszClassName >> 16 != 0)) {
|
---|
293 | FreeAsciiString((char *)wclass.lpszClassName);
|
---|
294 | }
|
---|
295 | return(rc);
|
---|
296 | }
|
---|
297 | //******************************************************************************
|
---|
298 | //******************************************************************************
|
---|
299 | BOOL WIN32API UnregisterClassA(LPCSTR lpszClassName, HINSTANCE hinst)
|
---|
300 | {
|
---|
301 | BOOL rc;
|
---|
302 |
|
---|
303 | Win32WindowClass::UnregisterClass(hinst, (LPSTR)lpszClassName);
|
---|
304 | rc = O32_UnregisterClass(lpszClassName, hinst);
|
---|
305 | dprintf(("USER32: OS2UnregisterClassA returned %d\n", rc));
|
---|
306 |
|
---|
307 | //Spintest returns FALSE in dll termination, so pretend it succeeded
|
---|
308 | return(TRUE);
|
---|
309 | }
|
---|
310 | //******************************************************************************
|
---|
311 | //******************************************************************************
|
---|
312 | BOOL WIN32API UnregisterClassW(LPCWSTR lpszClassName, HINSTANCE hinst)
|
---|
313 | {
|
---|
314 | char *astring = NULL;
|
---|
315 | BOOL rc;
|
---|
316 |
|
---|
317 | dprintf(("USER32: OS2UnregisterClassW\n"));
|
---|
318 | if((int)lpszClassName >> 16 != 0) {
|
---|
319 | astring = UnicodeToAsciiString((LPWSTR)lpszClassName);
|
---|
320 | }
|
---|
321 | else astring = (char *)lpszClassName;
|
---|
322 |
|
---|
323 | Win32WindowClass::UnregisterClass(hinst, (LPSTR)astring);
|
---|
324 | rc = O32_UnregisterClass(astring, hinst);
|
---|
325 | if((int)astring >> 16 != 0) {
|
---|
326 | FreeAsciiString(astring);
|
---|
327 | }
|
---|
328 | //Spintest returns FALSE in dll termination, so pretend it succeeded
|
---|
329 | return(TRUE);
|
---|
330 | }
|
---|
331 | //******************************************************************************
|
---|
332 | //******************************************************************************
|
---|
333 | BOOL WIN32API GetClassInfoA(HINSTANCE arg1, LPCSTR arg2, WNDCLASSA * arg3)
|
---|
334 | {
|
---|
335 | BOOL rc;
|
---|
336 |
|
---|
337 | dprintf(("USER32: OS2GetClassInfoA\n"));
|
---|
338 | rc = O32_GetClassInfo(arg1, arg2, (WNDCLASSA *)arg3);
|
---|
339 | if(rc == TRUE) {
|
---|
340 | arg3->lpfnWndProc = (WNDPROC)Win32WindowClass::GetClassCallback((LPSTR)arg2);
|
---|
341 | }
|
---|
342 | return(rc);
|
---|
343 | }
|
---|
344 | //******************************************************************************
|
---|
345 | //******************************************************************************
|
---|
346 | BOOL WIN32API GetClassInfoW(HINSTANCE hinst,
|
---|
347 | LPCWSTR lpszClass,
|
---|
348 | WNDCLASSW *lpwc)
|
---|
349 | {
|
---|
350 | WNDCLASSA wclass;
|
---|
351 | BOOL rc;
|
---|
352 | char *szClass = NULL;
|
---|
353 |
|
---|
354 | dprintf(("USER32: OS2GetClassInfoW\n"));
|
---|
355 | if((int)lpszClass >> 16 != 0) {
|
---|
356 | szClass = UnicodeToAsciiString((LPWSTR)lpszClass);
|
---|
357 | dprintf(("USER32: OS2GetClassInfoW %s\n", szClass));
|
---|
358 | }
|
---|
359 | else szClass = (char *)lpszClass;
|
---|
360 |
|
---|
361 | rc = GetClassInfoA(hinst, szClass, &wclass);
|
---|
362 | if(rc == TRUE) {
|
---|
363 | memcpy(lpwc, &wclass, sizeof(WNDCLASSA));
|
---|
364 | //TODO: Memory leak (create class object at RegisterClass and delete it at UnregisterClass)
|
---|
365 | if(lpwc->lpszMenuName && ((int)lpwc->lpszMenuName >> 16 != 0)) {
|
---|
366 | lpwc->lpszMenuName = (LPCWSTR)malloc(strlen(wclass.lpszMenuName)*sizeof(WCHAR)+2);
|
---|
367 | AsciiToUnicode((char *)wclass.lpszMenuName, (LPWSTR)lpwc->lpszMenuName);
|
---|
368 | }
|
---|
369 | if(lpwc->lpszClassName && ((int)lpwc->lpszClassName >> 16 != 0)) {
|
---|
370 | lpwc->lpszClassName = (LPCWSTR)malloc(strlen(wclass.lpszClassName)*sizeof(WCHAR)+2);
|
---|
371 | AsciiToUnicode((char *)wclass.lpszClassName, (LPWSTR)lpwc->lpszClassName);
|
---|
372 | }
|
---|
373 | }
|
---|
374 | dprintf(("USER32: OS2GetClassInfoW returned %d\n", rc));
|
---|
375 | return(rc);
|
---|
376 | }
|
---|
377 | /****************************************************************************
|
---|
378 | * Name : BOOL WIN32API GetClassInfoExA
|
---|
379 | * Purpose : The GetClassInfoEx function retrieves information about a window
|
---|
380 | * class, including the handle of the small icon associated with the
|
---|
381 | * window class. GetClassInfo does not retrieve the handle of the small icon.
|
---|
382 | * Parameters: HINSTANCE hinst handle of application instance
|
---|
383 | * LPCTSTR lpszClass address of class name string
|
---|
384 | * LPWNDCLASSEX lpwcx address of structure for class data
|
---|
385 | * Variables :
|
---|
386 | * Result : If the function finds a matching class and successfully copies
|
---|
387 | * the data, the return value is TRUE;
|
---|
388 | * otherwise, it is FALSE.
|
---|
389 | * To get extended error information, call GetLastError.
|
---|
390 | * Remark : PH: does not obtain handle of the small icon
|
---|
391 | * Status : UNTESTED STUB
|
---|
392 | *
|
---|
393 | * Author : Patrick Haller [Thu, 1998/02/26 11:55]
|
---|
394 | *****************************************************************************/
|
---|
395 | BOOL WIN32API GetClassInfoExA(HINSTANCE hInstance,
|
---|
396 | LPCTSTR lpszClass,
|
---|
397 | LPWNDCLASSEXA lpwcx)
|
---|
398 | {
|
---|
399 | WNDCLASSA WndClass; /* structure for data transformation */
|
---|
400 | BOOL bResult; /* result of subsequent function calls */
|
---|
401 |
|
---|
402 | dprintf(("USER32:GetClassInfoExA (%08xh,%s,%08x).\n",
|
---|
403 | hInstance,
|
---|
404 | lpszClass,
|
---|
405 | lpwcx));
|
---|
406 |
|
---|
407 | /* convert the structures */
|
---|
408 | memcpy((PVOID)&WndClass,
|
---|
409 | (PVOID)&lpwcx->style,
|
---|
410 | sizeof(WndClass) );
|
---|
411 |
|
---|
412 | bResult = GetClassInfoA(hInstance,
|
---|
413 | lpszClass,
|
---|
414 | (WNDCLASSA *)&WndClass);
|
---|
415 | if (bResult == TRUE)
|
---|
416 | {
|
---|
417 | /* convert data back to original structure */
|
---|
418 | memcpy((PVOID)&lpwcx->style,
|
---|
419 | (PVOID)&WndClass,
|
---|
420 | sizeof(WndClass) );
|
---|
421 | lpwcx->cbSize = sizeof(WNDCLASSEXA);
|
---|
422 | lpwcx->hIconSm = 0;
|
---|
423 | }
|
---|
424 |
|
---|
425 | return (bResult);
|
---|
426 | }
|
---|
427 | /*****************************************************************************
|
---|
428 | * Name : BOOL WIN32API GetClassInfoExW
|
---|
429 | * Purpose : The GetClassInfoEx function retrieves information about a window
|
---|
430 | * class, including the handle of the small icon associated with the
|
---|
431 | * window class. GetClassInfo does not retrieve the handle of the small icon.
|
---|
432 | * Parameters: HINSTANCE hinst handle of application instance
|
---|
433 | * LPCWSTR lpszClass address of class name string
|
---|
434 | * LPWNDCLASSEX lpwcx address of structure for class data
|
---|
435 | * Variables :
|
---|
436 | * Result : If the function finds a matching class and successfully copies
|
---|
437 | * the data, the return value is TRUE;
|
---|
438 | * otherwise, it is FALSE.
|
---|
439 | * To get extended error information, call GetLastError.
|
---|
440 | * Remark : does not obtain handle of the small icon
|
---|
441 | * Status : UNTESTED STUB
|
---|
442 | *
|
---|
443 | * Author : Patrick Haller [Thu, 1998/02/26 11:55]
|
---|
444 | *****************************************************************************/
|
---|
445 | BOOL WIN32API GetClassInfoExW(HINSTANCE hInstance,
|
---|
446 | LPCWSTR lpszClass,
|
---|
447 | LPWNDCLASSEXW lpwcx)
|
---|
448 | {
|
---|
449 | WNDCLASSW WndClass; /* structure for data transformation */
|
---|
450 | BOOL bResult; /* result of subsequent function calls */
|
---|
451 |
|
---|
452 | dprintf(("USER32:GetClassInfoExW (%08xh,%s,%08x).\n",
|
---|
453 | hInstance,
|
---|
454 | lpszClass,
|
---|
455 | lpwcx));
|
---|
456 |
|
---|
457 | /* convert the structures */
|
---|
458 | memcpy((PVOID)&WndClass,
|
---|
459 | (PVOID)&lpwcx->style,
|
---|
460 | sizeof(WndClass) );
|
---|
461 |
|
---|
462 | bResult = GetClassInfoW(hInstance,
|
---|
463 | (LPWSTR)lpszClass,
|
---|
464 | (WNDCLASSW *)&WndClass);
|
---|
465 | if (bResult == TRUE)
|
---|
466 | {
|
---|
467 | /* convert data back to original structure */
|
---|
468 | memcpy((PVOID)&lpwcx->style,
|
---|
469 | (PVOID)&WndClass,
|
---|
470 | sizeof(WndClass) );
|
---|
471 | lpwcx->cbSize = sizeof(WNDCLASSEXW);
|
---|
472 | lpwcx->hIconSm = 0;
|
---|
473 | }
|
---|
474 |
|
---|
475 | return (bResult);
|
---|
476 | }
|
---|
477 | //******************************************************************************
|
---|
478 | //TODO: Not complete (unsupported extension in WNDCLASSEXA/W, unsupported styles etc)
|
---|
479 | //******************************************************************************
|
---|
480 | LONG WIN32API GetClassLongA(HWND hwnd, int nIndex)
|
---|
481 | {
|
---|
482 | DWORD rc;
|
---|
483 |
|
---|
484 | dprintf(("USER32: OS2GetClassLongA\n"));
|
---|
485 | rc = O32_GetClassLong(hwnd, nIndex);
|
---|
486 | if(nIndex == GCL_WNDPROC) {
|
---|
487 | char szClass[128];
|
---|
488 | Win32WindowClass *wclass;
|
---|
489 |
|
---|
490 | if(GetClassNameA(hwnd, szClass, sizeof(szClass))) {
|
---|
491 | wclass = Win32WindowClass::FindClass(szClass);
|
---|
492 | if(wclass) {
|
---|
493 | return (LONG)wclass->GetWinCallback();
|
---|
494 | }
|
---|
495 | }
|
---|
496 | dprintf(("GetClassLongA, class of window %X not found\n", hwnd));
|
---|
497 | return 0; //TODO: set last error
|
---|
498 | }
|
---|
499 | return rc;
|
---|
500 | }
|
---|
501 | //******************************************************************************
|
---|
502 | //******************************************************************************
|
---|
503 | LONG WIN32API GetClassLongW(HWND hwnd, int nIndex)
|
---|
504 | {
|
---|
505 | dprintf(("USER32: OS2GetClassLongW\n"));
|
---|
506 | if(nIndex == GCL_MENUNAME) { //TODO
|
---|
507 | dprintf(("USER32: Class Menu name not implemented yet\n"));
|
---|
508 | }
|
---|
509 | // NOTE: This will not work as is (needs UNICODE support)
|
---|
510 | return GetClassLongA(hwnd, nIndex);
|
---|
511 | }
|
---|
512 | //******************************************************************************
|
---|
513 | //******************************************************************************
|
---|
514 | int WIN32API GetClassNameA( HWND arg1, LPSTR arg2, int arg3)
|
---|
515 | {
|
---|
516 | dprintf(("USER32: OS2GetClassNameA\n"));
|
---|
517 | return O32_GetClassName(arg1, arg2, arg3);
|
---|
518 | }
|
---|
519 | //******************************************************************************
|
---|
520 | //******************************************************************************
|
---|
521 | int WIN32API GetClassNameW(HWND hwnd, LPWSTR lpClassName, int nMaxCount)
|
---|
522 | {
|
---|
523 | char *astring = (char *)malloc(nMaxCount);
|
---|
524 | int rc;
|
---|
525 |
|
---|
526 | dprintf(("USER32: OS2GetClassNameW\n"));
|
---|
527 | rc = GetClassNameA(hwnd, astring, nMaxCount);
|
---|
528 | AsciiToUnicode(astring, lpClassName);
|
---|
529 | free(astring);
|
---|
530 | return(rc);
|
---|
531 | }
|
---|
532 | //******************************************************************************
|
---|
533 | //******************************************************************************
|
---|
534 | WORD WIN32API GetClassWord( HWND arg1, int arg2)
|
---|
535 | {
|
---|
536 | dprintf(("USER32: OS2GetClassWord\n"));
|
---|
537 | return O32_GetClassWord(arg1, arg2);
|
---|
538 | }
|
---|
539 | //******************************************************************************
|
---|
540 | //******************************************************************************
|
---|
541 | LONG WIN32API SetClassLongA(HWND hwnd, int nIndex, LONG lNewVal)
|
---|
542 | {
|
---|
543 | DWORD rc;
|
---|
544 |
|
---|
545 | dprintf(("USER32: OS2SetClassLongA\n"));
|
---|
546 | if(nIndex == GCL_WNDPROC) {
|
---|
547 | char szClass[128];
|
---|
548 | Win32WindowClass *wclass;
|
---|
549 |
|
---|
550 | if(GetClassNameA(hwnd, szClass, sizeof(szClass))) {
|
---|
551 | wclass = Win32WindowClass::FindClass(szClass);
|
---|
552 | if(wclass) {
|
---|
553 | rc = (DWORD)wclass->GetWinCallback();
|
---|
554 | wclass->SetWinCallback((WNDPROC)lNewVal);
|
---|
555 | return rc;
|
---|
556 | }
|
---|
557 | }
|
---|
558 | dprintf(("SetClassLongA, class of window %X not found\n", hwnd));
|
---|
559 | return 0; //TODO: set last error
|
---|
560 | }
|
---|
561 | return O32_SetClassLong(hwnd, nIndex, lNewVal);
|
---|
562 | }
|
---|
563 | //******************************************************************************
|
---|
564 | //******************************************************************************
|
---|
565 | LONG WIN32API SetClassLongW( HWND arg1, int arg2, LONG arg3)
|
---|
566 | {
|
---|
567 | dprintf(("USER32: OS2SetClassLongW\n"));
|
---|
568 | // NOTE: This will not work as is (needs UNICODE support)
|
---|
569 | return O32_SetClassLong(arg1, arg2, arg3);
|
---|
570 | }
|
---|
571 | //******************************************************************************
|
---|
572 | //******************************************************************************
|
---|
573 | WORD WIN32API SetClassWord( HWND arg1, int arg2, WORD arg3)
|
---|
574 | {
|
---|
575 | dprintf(("USER32: OS2SetClassWord\n"));
|
---|
576 | return O32_SetClassWord(arg1, arg2, arg3);
|
---|
577 | }
|
---|
578 | //******************************************************************************
|
---|
579 | //Win32WindowClass methods:
|
---|
580 | //******************************************************************************
|
---|
581 | Win32WindowClass::Win32WindowClass(WNDPROC pUserCallback, LPSTR id, HINSTANCE hinst)
|
---|
582 | {
|
---|
583 | //Insert it in front of the rest
|
---|
584 | next = wndclasses;
|
---|
585 | wndclasses = this;
|
---|
586 | if((int)id >> 16 != 0) {
|
---|
587 | strcpy(className, id);
|
---|
588 | classAtom = 0;
|
---|
589 | }
|
---|
590 | else {
|
---|
591 | className[0] = 0;
|
---|
592 | classAtom = (DWORD)id;
|
---|
593 | }
|
---|
594 | this->hinst = hinst;
|
---|
595 |
|
---|
596 | pWinCallback = pUserCallback;
|
---|
597 | dprintf(("Win32WindowClass::Win32WindowClass %d\n", id));
|
---|
598 | }
|
---|
599 | //******************************************************************************
|
---|
600 | //******************************************************************************
|
---|
601 | Win32WindowClass::~Win32WindowClass()
|
---|
602 | {
|
---|
603 | Win32WindowClass *wndclass = Win32WindowClass::wndclasses;
|
---|
604 |
|
---|
605 | if(wndclass == this) {
|
---|
606 | wndclasses = next;
|
---|
607 | }
|
---|
608 | else {
|
---|
609 | while(wndclass->next != NULL) {
|
---|
610 | if(wndclass->next == this) {
|
---|
611 | wndclass->next = next;
|
---|
612 | break;
|
---|
613 | }
|
---|
614 | wndclass = wndclass->next;
|
---|
615 | }
|
---|
616 | }
|
---|
617 | }
|
---|
618 | //******************************************************************************
|
---|
619 | //******************************************************************************
|
---|
620 | Win32WindowClass *Win32WindowClass::FindClass(LPSTR id)
|
---|
621 | {
|
---|
622 | Win32WindowClass *wndclass = wndclasses;
|
---|
623 |
|
---|
624 | if(wndclass == NULL) return(NULL);
|
---|
625 |
|
---|
626 | if((int)id >> 16 != 0) {
|
---|
627 | if(stricmp(wndclass->className, id) == 0) {
|
---|
628 | return(wndclass);
|
---|
629 | }
|
---|
630 | else {
|
---|
631 | wndclass = wndclass->next;
|
---|
632 | while(wndclass != NULL) {
|
---|
633 | if(stricmp(wndclass->className, id) == 0) {
|
---|
634 | return(wndclass);
|
---|
635 | }
|
---|
636 | wndclass = wndclass->next;
|
---|
637 | }
|
---|
638 | }
|
---|
639 | }
|
---|
640 | else {
|
---|
641 | if(wndclass->classAtom == (DWORD)id) {
|
---|
642 | return(wndclass);
|
---|
643 | }
|
---|
644 | else {
|
---|
645 | wndclass = wndclass->next;
|
---|
646 | while(wndclass != NULL) {
|
---|
647 | if(wndclass->classAtom == (DWORD)id) {
|
---|
648 | return(wndclass);
|
---|
649 | }
|
---|
650 | wndclass = wndclass->next;
|
---|
651 | }
|
---|
652 | }
|
---|
653 | }
|
---|
654 | return(NULL);
|
---|
655 | }
|
---|
656 | //******************************************************************************
|
---|
657 | //******************************************************************************
|
---|
658 | void Win32WindowClass::UnregisterClass(HINSTANCE hinst, LPSTR id)
|
---|
659 | {
|
---|
660 | Win32WindowClass *wndclass;
|
---|
661 |
|
---|
662 | dprintf(("::UnregisterClass, destroy class %X!!\n", id));
|
---|
663 | wndclass = FindClass(id);
|
---|
664 | if(wndclass && wndclass->hinst == hinst) {
|
---|
665 | delete wndclass;
|
---|
666 | return;
|
---|
667 | }
|
---|
668 | dprintf(("::UnregisterClass, couldn't find class %X!!\n", id));
|
---|
669 | }
|
---|
670 | //******************************************************************************
|
---|
671 | //******************************************************************************
|
---|
672 | WNDPROC Win32WindowClass::GetClassCallback(HINSTANCE hinst, LPSTR id)
|
---|
673 | {
|
---|
674 | Win32WindowClass *wndclass;
|
---|
675 |
|
---|
676 | wndclass = FindClass(id);
|
---|
677 | if(wndclass && wndclass->hinst == hinst) {
|
---|
678 | return wndclass->pWinCallback;
|
---|
679 | }
|
---|
680 | dprintf(("::GetClassCallback, couldn't find class %X!!\n", id));
|
---|
681 | return(NULL);
|
---|
682 | }
|
---|
683 | //******************************************************************************
|
---|
684 | //******************************************************************************
|
---|
685 | WNDPROC Win32WindowClass::GetClassCallback(LPSTR id)
|
---|
686 | {
|
---|
687 | Win32WindowClass *wndclass;
|
---|
688 |
|
---|
689 | wndclass = FindClass(id);
|
---|
690 | if(wndclass) {
|
---|
691 | return wndclass->pWinCallback;
|
---|
692 | }
|
---|
693 | dprintf(("::GetClassCallback2, couldn't find class %X!!\n", id));
|
---|
694 | return(NULL);
|
---|
695 | }
|
---|
696 | //******************************************************************************
|
---|
697 | //******************************************************************************
|
---|
698 | WNDPROC_O32 Win32WindowClass::GetOS2ClassCallback()
|
---|
699 | {
|
---|
700 | return OS2ToWinCallback;
|
---|
701 | }
|
---|
702 | //******************************************************************************
|
---|
703 | //******************************************************************************
|
---|
704 | LRESULT EXPENTRY_O32 OS2ToWinCallback(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
|
---|
705 | {
|
---|
706 | char szClass[128];
|
---|
707 | Win32WindowClass *wclass;
|
---|
708 |
|
---|
709 | #ifdef DEBUG1
|
---|
710 | dprintf(("OS2ToWinCallback for message %s", GetMsgText(Msg)));
|
---|
711 | #endif
|
---|
712 |
|
---|
713 | if(HkCBT::OS2HkCBTProc(hwnd, Msg, wParam, lParam) == TRUE) {//hook swallowed msg
|
---|
714 | return(0);
|
---|
715 | }
|
---|
716 |
|
---|
717 | if(O32_GetClassName(hwnd, szClass, sizeof(szClass))) {
|
---|
718 | wclass = Win32WindowClass::FindClass(szClass);
|
---|
719 | if(wclass) {
|
---|
720 | //SvL: Correct Open32 key mapping bug
|
---|
721 | if(Msg == WM_KEYDOWN || Msg == WM_KEYUP || Msg == WM_CHAR) {
|
---|
722 | // dprintf(("WM_KEYDOWN %X %08X\n", wParam, lParam));
|
---|
723 | lParam = MapOEMToRealKey(wParam, lParam);
|
---|
724 | }
|
---|
725 |
|
---|
726 | if(Msg == WM_CREATE) {//Open32 isn't sending WM_NCCREATE messages!!
|
---|
727 | if(wclass->GetWinCallback()(hwnd, WM_NCCREATE, 0, lParam) == 0) {
|
---|
728 | dprintf(("WM_NCCREATE returned FALSE\n"));
|
---|
729 | return(-1); //don't create window
|
---|
730 | }
|
---|
731 | }
|
---|
732 | if(Msg == WM_ACTIVATE && LOWORD(wParam) != WA_INACTIVE)
|
---|
733 | {//SvL: Bugfix, Open32 is NOT sending this to the window (messes up Solitaire)
|
---|
734 | HDC hdc = GetDC(hwnd);
|
---|
735 |
|
---|
736 | wclass->GetWinCallback()(hwnd, WM_ERASEBKGND, hdc, 0);
|
---|
737 | ReleaseDC(hwnd, hdc);
|
---|
738 | }
|
---|
739 | return wclass->GetWinCallback()(hwnd, Msg, wParam, lParam);
|
---|
740 | }
|
---|
741 | }
|
---|
742 | dprintf(("OS2ToWinCallback: couldn't find class procedure of window %X\n", hwnd));
|
---|
743 | return(0);
|
---|
744 | }
|
---|
745 | //******************************************************************************
|
---|
746 | //******************************************************************************
|
---|
747 | LRESULT WIN32API WinToOS2Callback(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
|
---|
748 | {
|
---|
749 | WNDPROC_O32 os2callback;
|
---|
750 |
|
---|
751 | os2callback = (WNDPROC_O32)GetClassLongA(hwnd, GCL_WNDPROC);
|
---|
752 | if(os2callback) {
|
---|
753 | return os2callback(hwnd, Msg, wParam, lParam);
|
---|
754 | }
|
---|
755 | dprintf(("OS2ToWinCallback: window procedure == NULL!!\n"));
|
---|
756 | return(0);
|
---|
757 | }
|
---|
758 | //******************************************************************************
|
---|
759 | //******************************************************************************
|
---|
760 | Win32WindowClass *Win32WindowClass::wndclasses = NULL;
|
---|