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

Last change on this file since 372 was 372, checked in by cbratschi, 26 years ago

atom updates

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