Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

windowclass.cpp

Go to the documentation of this file.
00001 /* $Id: windowclass.cpp,v 1.24 2001/12/20 20:45:56 sandervl Exp $ */
00002 /*
00003  * Win32 Window Class Code for OS/2
00004  *
00005  *
00006  * Copyright 1998-1999 Sander van Leeuwen (sandervl@xs4all.nl)
00007  *
00008  *
00009  * Project Odin Software License can be found in LICENSE.TXT
00010  *
00011  */
00012 #include <os2win.h>
00013 #include <stdio.h>
00014 #include <stdlib.h>
00015 #include <string.h>
00016 #include <stdarg.h>
00017 #include <assert.h>
00018 #include <misc.h>
00019 #include <unicode.h>
00020 #include <win32class.h>
00021 #include <win32wbase.h>
00022 #include <controls.h>
00023 
00024 #define DBG_LOCALLOG    DBG_windowclass
00025 #include "dbglocal.h"
00026 
00027 
00028 #include <odin.h>
00029 #include <odinwrap.h>
00030 #include <os2sel.h>
00031 
00032 ODINDEBUGCHANNEL(USER32-CLASS)
00033 
00034 
00035 //******************************************************************************
00036 //******************************************************************************
00037 void RegisterSystemClasses(ULONG hModule)
00038 {
00039     dprintf(("RegisterSystemClasses\n"));
00040     CONTROLS_Register();
00041 }
00042 //******************************************************************************
00043 //******************************************************************************
00044 void UnregisterSystemClasses()
00045 {
00046     dprintf(("UnregisterSystemClasses\n"));
00047     CONTROLS_Unregister();
00048 }
00049 //******************************************************************************
00050 //Note: RegisterClassA does NOT change the last error if successful! (verified in NT 4, SP6)
00051 //******************************************************************************
00052 
00053 ODINFUNCTION1(ATOM,              RegisterClassA,
00054               CONST WNDCLASSA *, lpWndClass)
00055 {
00056  WNDCLASSEXA wc;
00057  Win32WndClass *wclass;
00058 
00059     //CB: size new in ex structure
00060     wc.cbSize = sizeof(wc);
00061     memcpy(&wc.style, lpWndClass, sizeof(WNDCLASSA));
00062     wc.hIconSm = 0;
00063  
00064     wclass = Win32WndClass::FindClass(wc.hInstance, (LPSTR)wc.lpszClassName);
00065     if(wclass) {
00066         RELEASE_CLASSOBJ(wclass);
00067         if(HIWORD(wc.lpszClassName)) {
00068                 dprintf(("RegisterClassA %x %s already exists", wc.hInstance, wc.lpszClassName));
00069         }
00070         else    dprintf(("RegisterClassA %x %x already exists", wc.hInstance, wc.lpszClassName));
00071         SetLastError(ERROR_CLASS_ALREADY_EXISTS);
00072         return 0;
00073     }
00074 
00075     //TODO: not destroyed when class is unregistered (neither does Wine, but that might be a bug)
00076     dprintf(("RegisterClassA"));
00077     int iSmIconWidth  = GetSystemMetrics(SM_CXSMICON);
00078     int iSmIconHeight = GetSystemMetrics(SM_CYSMICON);
00079 
00080     if(wc.hIcon)
00081         wc.hIconSm = CopyImage(wc.hIcon, IMAGE_ICON, iSmIconWidth, iSmIconHeight,
00082                                LR_COPYFROMRESOURCE);
00083 
00084     wclass = new Win32WndClass(&wc,FALSE);
00085     if(wclass == NULL) {
00086         dprintf(("ERROR: RegisterClassA winclass == NULL!"));
00087         DebugInt3();
00088         return(0);
00089     }
00090     ATOM atom = wclass->getAtom();
00091     RELEASE_CLASSOBJ(wclass);
00092     return atom;
00093 }
00094 //******************************************************************************
00095 //Note: RegisterClassA does NOT change the last error if successful! (verified in NT 4, SP6)
00096 //******************************************************************************
00097 ODINFUNCTION1(ATOM,                RegisterClassExA,
00098               CONST WNDCLASSEXA *, lpWndClass)
00099 {
00100  Win32WndClass *wclass;
00101 
00102     wclass = Win32WndClass::FindClass(lpWndClass->hInstance, (LPSTR)lpWndClass->lpszClassName);
00103     if(wclass) {
00104         RELEASE_CLASSOBJ(wclass);
00105         if(HIWORD(lpWndClass->lpszClassName)) {
00106                 dprintf(("RegisterClassExA %x %s already exists", lpWndClass->hInstance, lpWndClass->lpszClassName));
00107         }
00108         else    dprintf(("RegisterClassExA %x %x already exists", lpWndClass->hInstance, lpWndClass->lpszClassName));
00109         SetLastError(ERROR_CLASS_ALREADY_EXISTS);
00110         return 0;
00111     }
00112 
00113     dprintf(("RegisterClassExA"));
00114     wclass = new Win32WndClass((WNDCLASSEXA *)lpWndClass,FALSE);
00115     if(wclass == NULL) {
00116         dprintf(("ERROR: RegisterClassExA winclass == NULL!"));
00117         DebugInt3();
00118         return(0);
00119     }
00120     ATOM atom = wclass->getAtom();
00121     RELEASE_CLASSOBJ(wclass);
00122     return atom;
00123 }
00124 //******************************************************************************
00125 //Note: RegisterClassA does NOT change the last error if successful! (verified in NT 4, SP6)
00126 //******************************************************************************
00127 ODINFUNCTION1(ATOM,              RegisterClassW,
00128               CONST WNDCLASSW *, lpwc)
00129 {
00130  ATOM rc;
00131  WNDCLASSEXA wc;
00132  Win32WndClass *winclass;
00133 
00134     //CB: size new in ex structure
00135     wc.cbSize = sizeof(wc);
00136     memcpy(&wc.style, lpwc, sizeof(WNDCLASSA));
00137 
00138     winclass = Win32WndClass::FindClass(wc.hInstance, (LPWSTR)wc.lpszClassName);
00139     if(winclass) {
00140         RELEASE_CLASSOBJ(winclass);
00141         if(HIWORD(wc.lpszClassName)) {
00142                 dprintf(("RegisterClassW %x %ls already exists", wc.hInstance, wc.lpszClassName));
00143         }
00144         else    dprintf(("RegisterClassW %x %x already exists", wc.hInstance, wc.lpszClassName));
00145         SetLastError(ERROR_CLASS_ALREADY_EXISTS);
00146         return 0;
00147     }
00148 
00149     //TODO: not destroyed when class is unregistered (neither does Wine, but that might be a bug)
00150     int iSmIconWidth  = GetSystemMetrics(SM_CXSMICON);
00151     int iSmIconHeight = GetSystemMetrics(SM_CYSMICON);
00152 
00153     if(wc.hIcon)
00154         wc.hIconSm = CopyImage(wc.hIcon, IMAGE_ICON, iSmIconWidth, iSmIconHeight,
00155                                LR_COPYFROMRESOURCE);
00156 
00157     dprintf(("RegisterClassW"));
00158     winclass = new Win32WndClass((WNDCLASSEXA *)&wc, TRUE);
00159     if(winclass == NULL) {
00160         dprintf(("ERROR: RegisterClassW winclass == NULL!"));
00161         DebugInt3();
00162         return 0;
00163     }
00164     rc = winclass->getAtom();
00165     RELEASE_CLASSOBJ(winclass);
00166     return(rc);
00167 }
00168 //******************************************************************************
00169 //Note: RegisterClassA does NOT change the last error if successful! (verified in NT 4, SP6)
00170 //******************************************************************************
00171 ODINFUNCTION1(ATOM,                RegisterClassExW,
00172               CONST WNDCLASSEXW *, lpwc)
00173 {
00174  ATOM rc;
00175  WNDCLASSEXA wc;
00176  Win32WndClass *winclass;
00177 
00178     memcpy(&wc, lpwc, sizeof(WNDCLASSEXA));
00179 
00180     winclass = Win32WndClass::FindClass(wc.hInstance, (LPWSTR)wc.lpszClassName);
00181     if(winclass) {
00182         RELEASE_CLASSOBJ(winclass);
00183         if(HIWORD(wc.lpszClassName)) {
00184                 dprintf(("RegisterClassExW %x %ls already exists", wc.hInstance, wc.lpszClassName));
00185         }
00186         else    dprintf(("RegisterClassExW %x %x already exists", wc.hInstance, wc.lpszClassName));
00187         SetLastError(ERROR_CLASS_ALREADY_EXISTS);
00188         return 0;
00189     }
00190 
00191     dprintf(("RegisterClassExW"));
00192     winclass = new Win32WndClass((WNDCLASSEXA *)&wc, TRUE);
00193     if(winclass == NULL) {
00194         dprintf(("ERROR: RegisterClassExW winclass == NULL!"));
00195         DebugInt3();
00196         return(0);
00197     }
00198     rc = winclass->getAtom();
00199     RELEASE_CLASSOBJ(winclass);
00200 
00201     return(rc);
00202 }
00203 //******************************************************************************
00204 //******************************************************************************
00205 ODINFUNCTION2(BOOL,      UnregisterClassA,
00206               LPCSTR,    lpszClassName,
00207               HINSTANCE, hinst)
00208 {
00209  BOOL ret;
00210 
00211    ret = Win32WndClass::UnregisterClassA(hinst, (LPSTR)lpszClassName);
00212    return ret;
00213 }
00214 //******************************************************************************
00215 //******************************************************************************
00216 ODINFUNCTION2(BOOL,      UnregisterClassW,
00217               LPCWSTR,   lpszClassName,
00218               HINSTANCE, hinst)
00219 {
00220  char *astring = NULL;
00221  BOOL  ret;
00222 
00223   dprintf(("USER32:  UnregisterClassW\n"));
00224   if(HIWORD(lpszClassName) != 0) {
00225         astring = UnicodeToAsciiString((LPWSTR)lpszClassName);
00226   }
00227   else  astring = (char *)lpszClassName;
00228 
00229   ret = Win32WndClass::UnregisterClassA(hinst, (LPSTR)astring);
00230   if(HIWORD(astring) != 0)
00231         FreeAsciiString((char *)astring);
00232 
00233   return ret;
00234 }
00235 //******************************************************************************
00236 //******************************************************************************
00237 ODINFUNCTION3(BOOL,        GetClassInfoA,
00238               HINSTANCE,   hInstance,
00239               LPCSTR,      lpszClass,
00240               WNDCLASSA *, lpwc)
00241 {
00242  WNDCLASSEXA    wc;
00243  BOOL           rc;
00244  Win32WndClass *wndclass;
00245 
00246   if(HIWORD(lpszClass) != 0) {
00247         dprintf(("USER32: GetClassInfoA %x %s %x", hInstance, lpszClass, lpwc));
00248   }
00249   else  dprintf(("USER32: GetClassInfoA %x %x %x", hInstance, lpszClass, lpwc));
00250 
00251   wndclass = Win32WndClass::FindClass(hInstance, (LPSTR)lpszClass);
00252   if(wndclass) {
00253         wndclass->getClassInfo(&wc);
00254         RELEASE_CLASSOBJ(wndclass);
00255         memcpy(lpwc, &wc.style, sizeof(WNDCLASSA));
00256         SetLastError(ERROR_SUCCESS);
00257         return(TRUE);
00258   }
00259   SetLastError(ERROR_CLASS_DOES_NOT_EXIST);
00260   return(FALSE);
00261 }
00262 //******************************************************************************
00263 //******************************************************************************
00264 ODINFUNCTION3(BOOL,        GetClassInfoW,
00265               HINSTANCE,   hinst,
00266               LPCWSTR,     lpszClass,
00267               WNDCLASSW *, lpwc)
00268 {
00269  WNDCLASSEXW    wc;
00270  BOOL           rc;
00271  Win32WndClass *wndclass;
00272  char          *astring = NULL;
00273 
00274   dprintf(("USER32:  GetClassInfoW\n"));
00275 
00276   if(HIWORD(lpszClass) != 0) {
00277         astring = UnicodeToAsciiString((LPWSTR)lpszClass);
00278   }
00279   else  astring = (char *)lpszClass;
00280 
00281   wndclass = Win32WndClass::FindClass(hinst, astring);
00282   if(HIWORD(astring) != 0)
00283         FreeAsciiString((char *)astring);
00284 
00285   if(wndclass) {
00286         wndclass->getClassInfo(&wc);
00287         RELEASE_CLASSOBJ(wndclass);
00288         memcpy(lpwc, &wc.style, sizeof(WNDCLASSW));
00289         SetLastError(ERROR_SUCCESS);
00290         return(TRUE);
00291   }
00292   SetLastError(ERROR_CLASS_DOES_NOT_EXIST);
00293   return(FALSE);
00294 }
00295 /****************************************************************************
00296  * Name      : BOOL WIN32API GetClassInfoExA
00297  * Purpose   : The GetClassInfoEx function retrieves information about a window
00298  *             class, including the handle of the small icon associated with the
00299  *             window class. GetClassInfo does not retrieve the handle of the small icon.
00300  * Parameters: HINSTANCE    hinst     handle of application instance
00301  *             LPCTSTR      lpszClass address of class name string
00302  *             LPWNDCLASSEX lpwcx     address of structure for class data
00303  * Variables :
00304  * Result    : If the function finds a matching class and successfully copies
00305  *             the data, the return value is TRUE;
00306  *             otherwise, it is FALSE.
00307  *             To get extended error information, call GetLastError.
00308  * Remark    : PH: does not obtain handle of the small icon
00309  *****************************************************************************/
00310 ODINFUNCTION3(BOOL,          GetClassInfoExA,
00311               HINSTANCE,     hInstance,
00312               LPCTSTR,       lpszClass,
00313               LPWNDCLASSEXA, lpwcx)
00314 {
00315  BOOL           rc;
00316  Win32WndClass *wndclass;
00317 
00318   if(HIWORD(lpszClass)) {
00319        dprintf(("USER32:GetClassInfoExA (%08xh,%s,%08x)",
00320                  hInstance, lpszClass, lpwcx));
00321   }
00322   else dprintf(("USER32:GetClassInfoExA (%08xh,%x,%08x)",
00323                  hInstance, lpszClass, lpwcx));
00324 
00325   wndclass = Win32WndClass::FindClass(hInstance, (LPSTR)lpszClass);
00326   if(wndclass) {
00327         wndclass->getClassInfo(lpwcx);
00328         RELEASE_CLASSOBJ(wndclass);
00329         lpwcx->cbSize = sizeof(WNDCLASSEXA);
00330         SetLastError(ERROR_SUCCESS);
00331         return(TRUE);
00332   }
00333   SetLastError(ERROR_CLASS_DOES_NOT_EXIST);
00334   return(FALSE);
00335 }
00336 
00337 
00338 /*****************************************************************************
00339  * Name      : BOOL WIN32API GetClassInfoExW
00340  * Purpose   : The GetClassInfoEx function retrieves information about a window
00341  *             class, including the handle of the small icon associated with the
00342  *             window class. GetClassInfo does not retrieve the handle of the small icon.
00343  * Parameters: HINSTANCE    hinst     handle of application instance
00344  *             LPCWSTR      lpszClass address of class name string
00345  *             LPWNDCLASSEX lpwcx     address of structure for class data
00346  * Variables :
00347  * Result    : If the function finds a matching class and successfully copies
00348  *               the data, the return value is TRUE;
00349  *             otherwise, it is FALSE.
00350  *             To get extended error information, call GetLastError.
00351  * Remark    : does not obtain handle of the small icon
00352  *
00353  *****************************************************************************/
00354 
00355 ODINFUNCTION3(BOOL,          GetClassInfoExW,
00356               HINSTANCE,     hInstance,
00357               LPCWSTR,       lpszClass,
00358               LPWNDCLASSEXW, lpwcx)
00359 {
00360  BOOL           rc;
00361  Win32WndClass *wndclass;
00362  char          *astring = NULL;
00363 
00364   if(HIWORD(lpszClass)) {
00365        dprintf(("USER32:GetClassInfoExW (%08xh,%ls,%08x)",
00366                  hInstance, lpszClass, lpwcx));
00367   }
00368   else dprintf(("USER32:GetClassInfoExW (%08xh,%x,%08x)",
00369                  hInstance, lpszClass, lpwcx));
00370 
00371   if(HIWORD(lpszClass) != 0) {
00372         astring = UnicodeToAsciiString((LPWSTR)lpszClass);
00373   }
00374   else  astring = (char *)lpszClass;
00375 
00376   wndclass = Win32WndClass::FindClass(hInstance, astring);
00377   if(HIWORD(astring) != 0)
00378         FreeAsciiString((char *)astring);
00379 
00380   if(wndclass) {
00381         wndclass->getClassInfo(lpwcx);
00382         RELEASE_CLASSOBJ(wndclass);
00383         lpwcx->cbSize = sizeof(WNDCLASSEXW);
00384         SetLastError(ERROR_SUCCESS);
00385         return(TRUE);
00386   }
00387   SetLastError(ERROR_CLASS_DOES_NOT_EXIST);
00388   return(FALSE);
00389 }
00390 //******************************************************************************
00391 //******************************************************************************
00392 ODINFUNCTION3(int,   GetClassNameA,
00393               HWND,  hwnd,
00394               LPSTR, lpszClassName,
00395               int,   cchClassName)
00396 {
00397  Win32BaseWindow *wnd;
00398  int rc;
00399 
00400     wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
00401     if(!wnd) {
00402         dprintf(("GetClassNameA wnd == NULL"));
00403         return(0);
00404     }
00405     *lpszClassName = 0;
00406     rc = (wnd->getClass())->getClassName(lpszClassName, cchClassName);
00407     RELEASE_WNDOBJ(wnd);
00408     if(HIWORD(lpszClassName)) {
00409          dprintf(("USER32: GetClassNameA %x %s", hwnd, lpszClassName));
00410     }
00411     else dprintf(("USER32: GetClassNameA %x %x", hwnd, lpszClassName));
00412     return rc;
00413 }
00414 //******************************************************************************
00415 //******************************************************************************
00416 ODINFUNCTION3(int,    GetClassNameW,
00417               HWND,   hwnd,
00418               LPWSTR, lpszClassName,
00419               int,    cchClassName)
00420 {
00421  Win32BaseWindow *wnd;
00422  int              ret;
00423 
00424     wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
00425     if(!wnd) {
00426         dprintf(("GetClassNameA wnd == NULL"));
00427         return(0);
00428     }
00429     ret = (wnd->getClass())->getClassName(lpszClassName, cchClassName);
00430     RELEASE_WNDOBJ(wnd);
00431     if(HIWORD(lpszClassName)) {
00432          dprintf(("USER32: GetClassNameW %x %ls", hwnd, lpszClassName));
00433     }
00434     else dprintf(("USER32: GetClassNameW %x %x", hwnd, lpszClassName));
00435     return ret;
00436 }
00437 //******************************************************************************
00438 //******************************************************************************
00439 ODINFUNCTION3(LONG, SetClassLongA,
00440                           HWND, hwnd, 
00441                           int,  nIndex, 
00442                           LONG, lNewVal)
00443 {
00444  Win32BaseWindow *wnd;
00445  LONG             ret;
00446 
00447     wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
00448     if(!wnd) {
00449         dprintf(("SetClassLongA %x %d %x wnd == NULL", hwnd, nIndex, lNewVal));
00450         return(0);
00451     }
00452     ret = (wnd->getClass())->setClassLongA(nIndex, lNewVal);
00453     RELEASE_WNDOBJ(wnd);
00454     return ret;
00455 }
00456 //******************************************************************************
00457 //******************************************************************************
00458 ODINFUNCTION3(LONG,   SetClassLongW,
00459               HWND,   hwnd,
00460               int,    nIndex,
00461               LONG,   lNewVal)
00462 {
00463  Win32BaseWindow *wnd;
00464  LONG             ret;
00465 
00466     wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
00467     if(!wnd) {
00468         dprintf(("SetClassLongW %x %d %x wnd == NULL", hwnd, nIndex, lNewVal));
00469         return(0);
00470     }
00471     ret = (wnd->getClass())->setClassLongW(nIndex, lNewVal);
00472     RELEASE_WNDOBJ(wnd);
00473     return ret;
00474 }
00475 //******************************************************************************
00476 //******************************************************************************
00477 ODINFUNCTION3(WORD,  SetClassWord,
00478               HWND,  hwnd,
00479               int,   nIndex,
00480               WORD,  wNewVal)
00481 {
00482  Win32BaseWindow *wnd;
00483  LONG             ret;
00484 
00485     dprintf(("USER32: SetClassWord %x %d %x", hwnd, nIndex, (ULONG)wNewVal));
00486     wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
00487     if(!wnd) {
00488         dprintf(("SetClassWordA %x %d %x wnd == NULL", hwnd, nIndex, wNewVal));
00489         return(0);
00490     }
00491     ret = (wnd->getClass())->setClassWord(nIndex, wNewVal);
00492     RELEASE_WNDOBJ(wnd);
00493     return ret;
00494 }
00495 //******************************************************************************
00496 //******************************************************************************
00497 ODINFUNCTION2(WORD, GetClassWord,
00498               HWND, hwnd,
00499               int,  nIndex)
00500 {
00501  Win32BaseWindow *wnd;
00502  WORD             ret;
00503 
00504     wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
00505     if(!wnd) {
00506         dprintf(("GetClassWordA %x %d wnd == NULL", hwnd, nIndex));
00507         return(0);
00508     }
00509     ret = (wnd->getClass())->getClassWord(nIndex);
00510     RELEASE_WNDOBJ(wnd);
00511     dprintf(("USER32: GetClassWord %x %d returned %x", hwnd, nIndex, (ULONG)ret));
00512     return ret;
00513 }
00514 //******************************************************************************
00515 //******************************************************************************
00516 ODINFUNCTION2(LONG, GetClassLongA,
00517               HWND, hwnd,
00518               int,  nIndex)
00519 {
00520  Win32BaseWindow *wnd;
00521  LONG ret;
00522 
00523     wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
00524     if(!wnd) {
00525         dprintf(("GetClassLongA %x %d wnd == NULL", hwnd, nIndex));
00526         return(0);
00527     }
00528     ret = (wnd->getClass())->getClassLongA(nIndex);
00529     RELEASE_WNDOBJ(wnd);
00530     dprintf(("USER32: GetClassLongA %x %d returned %x", hwnd, nIndex, ret));
00531     return ret;
00532 }
00533 //******************************************************************************
00534 //******************************************************************************
00535 ODINFUNCTION2(LONG, GetClassLongW,
00536               HWND, hwnd,
00537               int,  nIndex)
00538 {
00539  Win32BaseWindow *wnd;
00540  LONG ret;
00541 
00542     wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
00543     if(!wnd) {
00544         dprintf(("GetClassLongW %x %d wnd == NULL", hwnd, nIndex));
00545         return(0);
00546     }
00547     ret = (wnd->getClass())->getClassLongW(nIndex);
00548     RELEASE_WNDOBJ(wnd);
00549     dprintf(("USER32: GetClassLongW %x %d returned %x", hwnd, nIndex, ret));
00550     return ret;
00551 }
00552 //******************************************************************************
00553 //******************************************************************************

Generated on Wed Jan 23 23:17:51 2002 for ODIN-user32 by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001