source: trunk/src/user32/new/win32class.cpp@ 300

Last change on this file since 300 was 300, checked in by sandervl, 26 years ago

Very preliminary code for Open32 replacement

File size: 12.2 KB
Line 
1/* $Id: win32class.cpp,v 1.2 1999-07-14 08:35:36 sandervl Exp $ */
2/*
3 * Win32 Window Class Managment Code for OS/2
4 *
5 *
6 * Copyright 1998-1999 Sander van Leeuwen (sandervl@xs4all.nl)
7 *
8 */
9#include <os2win.h>
10#include <stdio.h>
11#include <stdlib.h>
12#include <string.h>
13#include <stdarg.h>
14#include <assert.h>
15#include <misc.h>
16#include <win32class.h>
17#include <win32wnd.h>
18
19//******************************************************************************
20//Win32WndClass methods:
21//******************************************************************************
22Win32WndClass::Win32WndClass(WNDCLASSEXA *wndclass, BOOL isUnicode) : GenericObject(&wndclasses, OBJTYPE_CLASS)
23{
24 if(HIWORD(wndclass->lpszClassName)) {
25 if(isUnicode) {
26 classNameA = (PCHAR)malloc(lstrlenW((LPWSTR)wndclass->lpszClassName)+1);
27 classNameW = (WCHAR *)malloc((lstrlenW((LPWSTR)wndclass->lpszClassName)+1)*sizeof(WCHAR));
28 }
29 else {
30 classNameA = (PCHAR)malloc(strlen(wndclass->lpszClassName)+1);
31 classNameW = (WCHAR *)malloc((strlen(wndclass->lpszClassName)+1)*sizeof(WCHAR));
32 }
33 if(classNameA == NULL || classNameW == NULL) {
34 dprintf(("Win32Class ctr; classNameA/classNameW == NULL"));
35 exit(1);
36 }
37 if(isUnicode) {
38 lstrcpyW(classNameW, (LPWSTR)wndclass->lpszClassName);
39 UnicodeToAscii(classNameW, classNameA);
40 }
41 else {
42 strcpy((char *)classNameA, wndclass->lpszClassName);
43 AsciiToUnicode(classNameA, classNameW);
44 }
45 classAtom = GlobalAddAtomA(classNameA);
46 }
47 else {
48 classNameA = NULL;
49 classNameW = NULL;
50 classAtom = (DWORD)wndclass->lpszClassName;
51 }
52 this->isUnicode = isUnicode;
53
54 dprintf(("USER32: Win32Class ctor\n"));
55 dprintf(("USER32: wndclass->style %X\n", wndclass->style));
56 dprintf(("USER32: wndclass->lpfnWndProc %X\n", wndclass->lpfnWndProc));
57 dprintf(("USER32: wndclass->cbClsExtra %X\n", wndclass->cbClsExtra));
58 dprintf(("USER32: wndclass->cbWndExtra %X\n", wndclass->cbWndExtra));
59 dprintf(("USER32: wndclass->hInstance %X\n", wndclass->hInstance));
60 dprintf(("USER32: wndclass->hIcon %X\n", wndclass->hIcon));
61 dprintf(("USER32: wndclass->hCursor %X\n", wndclass->hCursor));
62 dprintf(("USER32: wndclass->hbrBackground %X\n", wndclass->hbrBackground));
63 if(HIWORD(wndclass->lpszClassName))
64 dprintf(("USER32: wndclass->lpszClassName %X\n", wndclass->lpszClassName));
65 else dprintf(("USER32: wndclass->lpszClassName %s\n", wndclass->lpszClassName));
66
67 if(HIWORD(wndclass->lpszMenuName)) {//convert string name identifier to numeric id
68 dprintf(("USER32: lpszMenuName %s\n", wndclass->lpszMenuName));
69 }
70 else dprintf(("USER32: wndclass->lpszMenuName %X\n", wndclass->lpszMenuName));
71
72 nrExtraClassWords = wndclass->cbClsExtra;
73 nrExtraWindowWords = wndclass->cbWndExtra;
74 backgroundBrush = wndclass->hbrBackground; //TODO: fErase of PAINSTRUCT in WM_PAINT if == NULL
75 hCursor = wndclass->hCursor;
76 hIcon = wndclass->hIcon;
77 hInstance = wndclass->hInstance;
78
79 menuNameA = 0;
80 menuNameW = 0;
81 setMenuName((LPSTR)wndclass->lpszMenuName);
82
83 windowStyle = wndclass->style;
84 windowProc = wndclass->lpfnWndProc;
85
86 //User data class words/longs
87 if(nrExtraClassWords) {
88 userClassLong = (ULONG *)malloc(nrExtraClassWords);
89 if(userClassLong == NULL) {
90 dprintf(("Win32Class ctr: userClassLong == NULL!"));
91 exit(1);
92 }
93 memset(userClassLong, 0, nrExtraClassWords);
94 }
95 else userClassLong = NULL;
96
97 cWindows = 0;
98 hIconSm = wndclass->hIconSm;
99}
100//******************************************************************************
101//******************************************************************************
102Win32WndClass::~Win32WndClass()
103{
104 if(userClassLong) free(userClassLong);
105 if(classNameA) free(classNameA);
106 if(classNameW) free(classNameW);
107 if(menuNameA && HIWORD(menuNameA)) {
108 free(menuNameA);
109 assert(menuNameW);
110 free(menuNameW);
111 }
112}
113//******************************************************************************
114//******************************************************************************
115Win32WndClass *Win32WndClass::FindClass(HINSTANCE hInstance, LPSTR id)
116{
117 Win32WndClass *wndclass = (Win32WndClass *)wndclasses;
118
119 if(wndclass == NULL) return(NULL);
120
121 if(HIWORD(id) != 0) {
122 if(stricmp(wndclass->classNameA, id) == 0 && wndclass->hInstance == hInstance) {
123 return(wndclass);
124 }
125 else {
126 wndclass = (Win32WndClass *)wndclass->GetNext();
127 while(wndclass != NULL) {
128 if(stricmp(wndclass->classNameA, id) == 0 && wndclass->hInstance == hInstance) {
129 return(wndclass);
130 }
131 wndclass = (Win32WndClass *)wndclass->GetNext();
132 }
133 }
134 }
135 else {
136 if(wndclass->classAtom == (DWORD)id && wndclass->hInstance == hInstance) {
137 return(wndclass);
138 }
139 else {
140 wndclass = (Win32WndClass *)wndclass->GetNext();
141 while(wndclass != NULL) {
142 if(wndclass->classAtom == (DWORD)id && wndclass->hInstance == hInstance) {
143 return(wndclass);
144 }
145 wndclass = (Win32WndClass *)wndclass->GetNext();
146 }
147 }
148 }
149 dprintf(("Class %X (inst %X) not found!", id, hInstance));
150 return(NULL);
151}
152//******************************************************************************
153//******************************************************************************
154BOOL Win32WndClass::getClassInfo(WNDCLASSEXA *wndclass)
155{
156 wndclass->cbClsExtra = nrExtraClassWords;
157 wndclass->cbWndExtra = nrExtraWindowWords;
158 wndclass->hbrBackground = backgroundBrush;
159 wndclass->hCursor = hCursor;
160 wndclass->hIcon = hIcon;
161 wndclass->hInstance = hInstance;
162 wndclass->lpszMenuName = (LPCTSTR)menuNameA;
163 wndclass->lpszClassName = (classNameA) ? (LPCTSTR)classNameA : (LPCTSTR)classAtom;
164 wndclass->style = windowStyle;
165 wndclass->lpfnWndProc = windowProc;
166 wndclass->hIconSm = hIconSm;
167 return(TRUE);
168}
169//******************************************************************************
170//******************************************************************************
171BOOL Win32WndClass::getClassInfo(WNDCLASSEXW *wndclass)
172{
173 wndclass->cbClsExtra = nrExtraClassWords;
174 wndclass->cbWndExtra = nrExtraWindowWords;
175 wndclass->hbrBackground = backgroundBrush;
176 wndclass->hCursor = hCursor;
177 wndclass->hIcon = hIcon;
178 wndclass->hInstance = hInstance;
179 wndclass->lpszMenuName = (LPCWSTR)menuNameW;
180 wndclass->lpszClassName = (classNameW) ? (LPCWSTR)classNameW : (LPCWSTR)classAtom;
181 wndclass->style = windowStyle;
182 wndclass->lpfnWndProc = windowProc;
183 wndclass->hIconSm = hIconSm;
184 return(TRUE);
185}
186//******************************************************************************
187//******************************************************************************
188ULONG Win32WndClass::getClassName(LPSTR lpszClassName, ULONG cchClassName)
189{
190 if(HIWORD(classNameA)) {
191 strncpy(lpszClassName, classNameA, cchClassName-1);
192 return strlen(lpszClassName);
193 }
194 *(ULONG *)lpszClassName = classAtom;
195 return(sizeof(ULONG));
196}
197//******************************************************************************
198//******************************************************************************
199ULONG Win32WndClass::getClassName(LPWSTR lpszClassName, ULONG cchClassName)
200{
201 ULONG len;
202
203 if(HIWORD(classNameW)) {
204 lstrcpyW(lpszClassName, classNameW);
205 return lstrlenW(lpszClassName)*sizeof(WCHAR);
206 }
207 *(ULONG *)lpszClassName = classAtom;
208 return(sizeof(ULONG));
209}
210//******************************************************************************
211//******************************************************************************
212void Win32WndClass::setMenuName(LPSTR newMenuName)
213{
214 if(HIWORD(menuNameA)) {
215 free(menuNameA);
216 free(menuNameW);
217 menuNameA = 0;
218 menuNameW = 0;
219 }
220 if(HIWORD(newMenuName)) {
221 if(isUnicode) {
222 menuNameA = (PCHAR)malloc(lstrlenW((LPWSTR)newMenuName)+1);
223 menuNameW = (WCHAR *)malloc((lstrlenW((LPWSTR)newMenuName)+1)*sizeof(WCHAR));
224 }
225 else {
226 menuNameA = (PCHAR)malloc(strlen(newMenuName)+1);
227 menuNameW = (WCHAR *)malloc((strlen(newMenuName)+1)*sizeof(WCHAR));
228 }
229 if(menuNameA == NULL || menuNameW == NULL) {
230 dprintf(("Win32Class ctr; menuName/menuNameW == NULL"));
231 exit(1);
232 }
233 if(isUnicode) {
234 lstrcpyW(menuNameW, (LPWSTR)newMenuName);
235 UnicodeToAscii(menuNameW, menuNameA);
236 }
237 else {
238 strcpy((char *)menuNameA, newMenuName);
239 AsciiToUnicode(menuNameA, menuNameW);
240 }
241 }
242 else {//id
243 menuNameA = (PCHAR)newMenuName;
244 menuNameW = (WCHAR *)newMenuName;
245 }
246}
247//******************************************************************************
248//******************************************************************************
249ULONG Win32WndClass::getClassLongA(int index, BOOL isUnicode)
250{
251 switch(index) {
252 case GCL_CBCLSEXTRA:
253 return nrExtraClassWords;
254 case GCL_CBWNDEXTRA:
255 return nrExtraWindowWords;
256 case GCL_HBRBACKGROUND:
257 return backgroundBrush;
258 case GCL_HCURSOR:
259 return hCursor;
260 case GCL_HICON:
261 return hIcon;
262 case GCL_HMODULE:
263 return hInstance;
264 case GCL_MENUNAME:
265 return (isUnicode) ? (ULONG)menuNameW : (ULONG)menuNameA;
266 case GCL_STYLE:
267 return windowStyle;
268 case GCL_WNDPROC:
269 return (ULONG)windowProc;
270 case GCW_ATOM: //TODO: does this really happen in windows?
271 SetLastError(ERROR_INVALID_PARAMETER);
272 return 0;
273 default:
274 if(index > 0 && index < nrExtraClassWords - sizeof(ULONG)) {
275 return userClassLong[index];
276 }
277 SetLastError(ERROR_INVALID_PARAMETER);
278 return 0;
279 }
280}
281//******************************************************************************
282//******************************************************************************
283WORD Win32WndClass::getClassWord(int index)
284{
285 switch(index) {
286 case GCW_ATOM:
287 return (WORD)classAtom;
288 default:
289 if(index > 0 && index < nrExtraClassWords - sizeof(WORD)) {
290 return ((WORD *)userClassLong)[index];
291 }
292 SetLastError(ERROR_INVALID_PARAMETER);
293 return 0;
294 }
295}
296//******************************************************************************
297//TODO: What effects what immediately?
298//******************************************************************************
299ULONG Win32WndClass::setClassLongA(int index, LONG lNewVal, BOOL isUnicode)
300{
301 ULONG rc;
302
303 switch(index) {
304 case GCL_CBCLSEXTRA: //TODO (doesn't affect allocated classes, so what does it do?)
305 rc = nrExtraClassWords;
306// nrExtraClassWords = lNewVal;
307 break;
308 case GCL_CBWNDEXTRA:
309 rc = nrExtraWindowWords;
310 nrExtraWindowWords = lNewVal;
311 break;
312 case GCL_HBRBACKGROUND:
313 rc = backgroundBrush;
314 backgroundBrush = lNewVal;
315 break;
316 case GCL_HCURSOR:
317 rc = hCursor;
318 hCursor = lNewVal;
319 break;
320 case GCL_HICON:
321 rc = hIcon;
322 hIcon = lNewVal;
323 break;
324 case GCL_HMODULE:
325 rc = hInstance;
326 hInstance = lNewVal;
327 break;
328 case GCL_MENUNAME:
329 rc = 0; //old value is meaningless (according to Wine)
330 setMenuName((LPSTR)lNewVal);
331 break;
332 case GCL_STYLE:
333 rc = windowStyle;
334 windowStyle = lNewVal;
335 break;
336 case GCL_WNDPROC:
337 rc = (ULONG)windowProc;
338 windowProc = (WNDPROC)lNewVal;
339 break;
340 case GCW_ATOM: //TODO: does this really happen in windows?
341 SetLastError(ERROR_INVALID_PARAMETER);
342 return 0;
343 default:
344 if(index > 0 && index < nrExtraClassWords - sizeof(ULONG)) {
345 rc = userClassLong[index];
346 userClassLong[index] = lNewVal;
347 return(rc);
348 }
349 SetLastError(ERROR_INVALID_PARAMETER);
350 return 0;
351 }
352 return(rc);
353}
354//******************************************************************************
355//******************************************************************************
356WORD Win32WndClass::setClassWord(int index, WORD wNewVal)
357{
358 WORD rc;
359
360 switch(index) {
361 case GCW_ATOM:
362 rc = (WORD)classAtom;
363 classAtom = wNewVal;
364 return(rc);
365 default:
366 if(index > 0 && index < nrExtraClassWords - sizeof(WORD)) {
367 rc = ((WORD *)userClassLong)[index];
368 ((WORD *)userClassLong)[index] = wNewVal;
369 return(rc);
370 }
371 SetLastError(ERROR_INVALID_PARAMETER);
372 return 0;
373 }
374}
375//******************************************************************************
376//FIXME: Windows that still exists with this class
377//******************************************************************************
378void Win32WndClass::UnregisterClassA(HINSTANCE hinst, LPSTR id)
379{
380 Win32WndClass *wndclass;
381
382 dprintf(("::UnregisterClass, destroy class %X!!\n", id));
383 wndclass = FindClass(hinst, id);
384 if(wndclass) {
385 delete wndclass;
386 return;
387 }
388 dprintf(("::UnregisterClass, couldn't find class %X!!\n", id));
389}
390//******************************************************************************
391//******************************************************************************
392GenericObject *Win32WndClass::wndclasses = NULL;
393
Note: See TracBrowser for help on using the repository browser.