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

window.cpp

Go to the documentation of this file.
00001 /* $Id: window.cpp,v 1.115 2002/01/12 14:09:32 sandervl Exp $ */
00002 /*
00003  * Win32 window apis for OS/2
00004  *
00005  * Copyright 1999-2001 Sander van Leeuwen (sandervl@xs4all.nl)
00006  * Copyright 1999 Daniela Engert (dani@ngrt.de)
00007  * Copyright 2000 Christoph Bratschi (cbratschi@datacomm.ch)
00008  *
00009  * Parts based on Wine Windows code (windows\win.c, windows\property.c, windows\winpos.c)
00010  *
00011  * Copyright 1993, 1994, 1995 Alexandre Julliard
00012  *           1995, 1996, 1999 Alex Korobka
00013  *
00014  * Project Odin Software License can be found in LICENSE.TXT
00015  *
00016  *
00017  * TODO: Decide what to do about commands for OS/2 windows (non-Win32 apps)
00018  * TODO: ShowOwnedPopups needs to be tested
00019  *       GetLastActivePopup needs to be rewritten
00020  *
00021  */
00022 
00023 #include <odin.h>
00024 #include <odinwrap.h>
00025 #include <os2sel.h>
00026 
00027 #include <os2win.h>
00028 #include <misc.h>
00029 #include <string.h>
00030 #include <stdio.h>
00031 #include <win32wbase.h>
00032 #include <win32wmdiclient.h>
00033 #include <win32wdesktop.h>
00034 #include "win32dlg.h"
00035 #include <oslibwin.h>
00036 #include <oslibgdi.h>
00037 #include "user32.h"
00038 #include "winicon.h"
00039 #include "oslibmsg.h"
00040 #include <win\winpos.h>
00041 #include <win\win.h>
00042 #include <heapstring.h>
00043 #include <winuser32.h>
00044 #include "hook.h"
00045 
00046 #define DBG_LOCALLOG    DBG_window
00047 #include "dbglocal.h"
00048 
00049 ODINDEBUGCHANNEL(USER32-WINDOW)
00050 
00051 
00052 //******************************************************************************
00053 //******************************************************************************
00054 ODINFUNCTION12(HWND,      CreateWindowExA,
00055                DWORD,     exStyle,
00056                LPCSTR,    className,
00057                LPCSTR,    windowName,
00058                DWORD,     style,
00059                INT,       x,
00060                INT,       y,
00061                INT,       width,
00062                INT,       height,
00063                HWND,      parent,
00064                HMENU,     menu,
00065                HINSTANCE, instance,
00066                LPVOID,    data )
00067 {
00068   Win32BaseWindow *window;
00069   ATOM classAtom;
00070   CREATESTRUCTA cs;
00071   char tmpClass[20];
00072 
00073     if(exStyle & WS_EX_MDICHILD)
00074         return CreateMDIWindowA(className, windowName, style, x, y, width, height, parent, instance, (LPARAM)data);
00075 
00076     /* Find the class atom */
00077     if (!(classAtom = GlobalFindAtomA(className)))
00078     {
00079        if (!HIWORD(className))
00080            dprintf(("CreateWindowEx32A: bad class name %04x\n",LOWORD(className)));
00081        else
00082            dprintf(("CreateWindowEx32A: bad class name '%s'\n", className));
00083 
00084        SetLastError(ERROR_INVALID_PARAMETER);
00085        return 0;
00086     }
00087 
00088     if (!HIWORD(className))
00089     {
00090       sprintf(tmpClass,"#%d", (int) className);
00091       className = tmpClass;
00092     }
00093 
00094     /* Create the window */
00095     cs.lpCreateParams = data;
00096     cs.hInstance      = instance;
00097     cs.hMenu          = menu;
00098     cs.hwndParent     = parent;
00099     cs.x              = x;
00100     cs.y              = y;
00101     cs.cx             = width;
00102     cs.cy             = height;
00103     cs.style          = style;
00104     cs.lpszName       = windowName;
00105     cs.lpszClass      = className;
00106     cs.dwExStyle      = exStyle;
00107     if(HIWORD(className)) {
00108          dprintf(("CreateWindowExA: class %s parent %x (%d,%d) (%d,%d), %x %x menu=%x", className, parent, x, y, width, height, style, exStyle, menu));
00109     }
00110     else dprintf(("CreateWindowExA: class %d parent %x (%d,%d) (%d,%d), %x %x menu=%x", className, parent, x, y, width, height, style, exStyle, menu));
00111 
00112     if(!strcmpi(className, MDICLIENTCLASSNAMEA)) {
00113         window = (Win32BaseWindow *) new Win32MDIClientWindow(&cs, classAtom, FALSE);
00114     }
00115     else
00116     if(!strcmpi((char *) className, DIALOG_CLASS_NAMEA))
00117     {
00118       DLG_TEMPLATE dlgTemplate = {0};
00119       dlgTemplate.style = cs.style;
00120       dlgTemplate.exStyle = cs.dwExStyle;
00121       dlgTemplate.x = cs.x;
00122       dlgTemplate.y = cs.y;
00123       dlgTemplate.cx = cs.cx;
00124       dlgTemplate.cy = cs.cy;
00125       dlgTemplate.className = cs.lpszClass;
00126       dlgTemplate.caption = cs.lpszName;
00127       window = (Win32BaseWindow *) new Win32Dialog(cs.hInstance,
00128                                                    (LPCSTR) &dlgTemplate,
00129                                                    cs.hwndParent,
00130                                                    NULL,
00131                                                    (LPARAM) data,
00132                                                    FALSE);
00133     }
00134     else {
00135         window = new Win32BaseWindow( &cs, classAtom, FALSE );
00136     }
00137     if(window == NULL)
00138     {
00139         dprintf(("Win32BaseWindow creation failed!!"));
00140         return 0;
00141     }
00142     if(GetLastError() != 0)
00143     {
00144         dprintf(("Win32BaseWindow error found!!"));
00145         RELEASE_WNDOBJ(window);
00146         delete window;
00147         return 0;
00148     }
00149     HWND hwnd = window->getWindowHandle();
00150   
00151     // set myself as last active popup / window
00152     window->setLastActive( hwnd );
00153   
00154     RELEASE_WNDOBJ(window);
00155     return hwnd;
00156 }
00157 //******************************************************************************
00158 //******************************************************************************
00159 ODINFUNCTION12(HWND,      CreateWindowExW,
00160                DWORD,     exStyle,
00161                LPCWSTR,   className,
00162                LPCWSTR,   windowName,
00163                DWORD,     style,
00164                INT,       x,
00165                INT,       y,
00166                INT,       width,
00167                INT,       height,
00168                HWND,      parent,
00169                HMENU,     menu,
00170                HINSTANCE, instance,
00171                LPVOID,    data )
00172 {
00173   Win32BaseWindow *window;
00174   ATOM classAtom;
00175   CREATESTRUCTA cs;
00176   WCHAR tmpClassW[20];
00177 
00178     if(exStyle & WS_EX_MDICHILD)
00179         return CreateMDIWindowW(className, windowName, style, x, y, width, height, parent, instance, (LPARAM)data);
00180 
00181     /* Find the class atom */
00182     if (!(classAtom = GlobalFindAtomW(className)))
00183     {
00184        if (!HIWORD(className))
00185            dprintf(("CreateWindowEx32W: bad class name %04x",LOWORD(className)));
00186        else
00187            dprintf(("CreateWindowEx32W: bad class name '%ls'", className));
00188 
00189        SetLastError(ERROR_INVALID_PARAMETER);
00190        return 0;
00191     }
00192 #ifdef DEBUG
00193     if(HIWORD(className)) {
00194          dprintf(("CreateWindowExW: class %ls name %ls parent %x (%d,%d) (%d,%d), %x %x menu=%x", className, HIWORD(windowName) ? windowName : NULL, parent, x, y, width, height, style, exStyle, menu));
00195     }
00196     else dprintf(("CreateWindowExW: class %d name %ls parent %x (%d,%d) (%d,%d), %x %x menu=%x", className, HIWORD(windowName) ? windowName : NULL, parent, x, y, width, height, style, exStyle, menu));
00197 #endif
00198     if (!HIWORD(className))
00199     {
00200       wsprintfW(tmpClassW, (LPCWSTR)L"#%d", (int) className);
00201       className = tmpClassW;
00202     }
00203 
00204     /* Create the window */
00205     cs.lpCreateParams = data;
00206     cs.hInstance      = instance;
00207     cs.hMenu          = menu;
00208     cs.hwndParent     = parent;
00209     cs.x              = x;
00210     cs.y              = y;
00211     cs.cx             = width;
00212     cs.cy             = height;
00213     cs.style          = style;
00214     cs.lpszName       = (LPSTR)windowName;
00215     cs.lpszClass      = (LPSTR)className;
00216     cs.dwExStyle      = exStyle;
00217 
00218     if(!lstrcmpiW(className, (LPWSTR)MDICLIENTCLASSNAMEW)) {
00219         window = (Win32BaseWindow *) new Win32MDIClientWindow(&cs, classAtom, TRUE);
00220     }
00221     else
00222     if(!lstrcmpiW(className, (LPWSTR)DIALOG_CLASS_NAMEW))
00223     {
00224       DLG_TEMPLATE dlgTemplate = {0};
00225       dlgTemplate.style = cs.style;
00226       dlgTemplate.exStyle = cs.dwExStyle;
00227       dlgTemplate.x = cs.x;
00228       dlgTemplate.y = cs.y;
00229       dlgTemplate.cx = cs.cx;
00230       dlgTemplate.cy = cs.cy;
00231       dlgTemplate.className = cs.lpszClass;
00232       dlgTemplate.caption = cs.lpszName;
00233       window = (Win32BaseWindow *) new Win32Dialog(cs.hInstance,
00234                                                    (LPCSTR) &dlgTemplate,
00235                                                    cs.hwndParent,
00236                                                    NULL,
00237                                                    (LPARAM) data,
00238                                                    TRUE);
00239     }
00240     else {
00241         window = new Win32BaseWindow( &cs, classAtom, TRUE );
00242     }
00243     if(window == NULL)
00244     {
00245         dprintf(("Win32BaseWindow creation failed!!"));
00246         return 0;
00247     }
00248     if(GetLastError() != 0)
00249     {
00250         dprintf(("Win32BaseWindow error found!!"));
00251         RELEASE_WNDOBJ(window);
00252         delete window;
00253         return 0;
00254     }
00255     HWND hwnd = window->getWindowHandle();
00256   
00257     // set myself as last active popup / window
00258     window->setLastActive( hwnd );
00259   
00260     RELEASE_WNDOBJ(window);
00261     return hwnd;
00262 }
00263 //******************************************************************************
00264 //******************************************************************************
00265 ODINFUNCTION2(HWND, CreateFakeWindowEx,
00266               HWND, hwndOS2, ATOM, classAtom)
00267 {
00268  Win32BaseWindow *window;
00269 
00270     window = new Win32BaseWindow(hwndOS2, classAtom);
00271     if(window == NULL)
00272     {
00273         dprintf(("Win32BaseWindow creation failed!!"));
00274         return 0;
00275     }
00276     HWND hwnd = window->getWindowHandle();
00277   
00278     // set myself as last active popup / window
00279     window->setLastActive( hwnd );
00280   
00281     RELEASE_WNDOBJ(window);
00282     return hwnd;
00283 }
00284 //******************************************************************************
00285 //******************************************************************************
00286 ODINFUNCTION1(BOOL, DestroyFakeWindow,
00287               HWND, hwnd)
00288 {
00289   Win32BaseWindow *window;
00290 
00291     window = Win32BaseWindow::GetWindowFromHandle(hwnd);
00292     if(!window) {
00293         dprintf(("DestroyFakeWindow, window %x not found", hwnd));
00294         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
00295         return 0;
00296     }
00297     delete window;
00298     return TRUE;
00299 }
00300 //******************************************************************************
00301 //******************************************************************************
00302 ODINFUNCTION1(BOOL, DestroyWindow,
00303               HWND, hwnd)
00304 {
00305   Win32BaseWindow *window;
00306   BOOL             ret;
00307 
00308     window = Win32BaseWindow::GetWindowFromHandle(hwnd);
00309     if(!window) {
00310         dprintf(("DestroyWindow, window %x not found", hwnd));
00311         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
00312         return 0;
00313     }
00314     ret = window->DestroyWindow();
00315     RELEASE_WNDOBJ(window);
00316     return ret;
00317 }
00318 //******************************************************************************
00319 //******************************************************************************
00320 ODINFUNCTION1(HWND, SetActiveWindow,
00321               HWND, hwnd)
00322 {
00323   Win32BaseWindow *window;
00324   HWND             hwndActive;
00325 
00326     window = Win32BaseWindow::GetWindowFromHandle(hwnd);
00327     if(!window) {
00328         dprintf(("SetActiveWindow, window %x not found", hwnd));
00329         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
00330         return 0;
00331     }
00332     hwndActive = window->SetActiveWindow();
00333   
00334     // check last active popup window
00335     if (hwndActive)
00336     {
00337       // TODO:
00338       // set last active popup window to the ancestor window
00339       dprintf(("support for last active popup incorrectly implemented"));
00340     }
00341   
00342     RELEASE_WNDOBJ(window);
00343     return hwndActive;
00344 }
00345 //******************************************************************************
00346 //Note: does not set last error if no parent (verified in NT4, SP6)
00347 //******************************************************************************
00348 HWND WIN32API GetParent(HWND hwnd)
00349 {
00350   Win32BaseWindow *window;
00351   HWND             hwndParent;
00352 
00353     window = Win32BaseWindow::GetWindowFromHandle(hwnd);
00354     if(!window) {
00355         dprintf(("GetParent, window %x not found", hwnd));
00356         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
00357         return 0;
00358     }
00359     dprintf2(("GetParent %x", hwnd));
00360     hwndParent = window->GetParent();
00361     RELEASE_WNDOBJ(window);
00362     return hwndParent;
00363 }
00364 //******************************************************************************
00365 //******************************************************************************
00366 ODINFUNCTION2(HWND, SetParent,
00367               HWND, hwndChild,
00368               HWND, hwndNewParent)
00369 {
00370   Win32BaseWindow *window;
00371   HWND             hwndOldParent;
00372 
00373     window = Win32BaseWindow::GetWindowFromHandle(hwndChild);
00374     if(!window) {
00375         dprintf(("SetParent, window %x not found", hwndChild));
00376         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
00377         return 0;
00378     }
00379     if(hwndNewParent == HWND_DESKTOP) {
00380         hwndNewParent = GetDesktopWindow();
00381     }
00382     else {
00383         if(!IsWindow(hwndNewParent)) {
00384             RELEASE_WNDOBJ(window);
00385             dprintf(("SetParent, parent %x not found", hwndNewParent));
00386             SetLastError(ERROR_INVALID_WINDOW_HANDLE);
00387             return 0;
00388     }
00389     }
00390     dprintf(("SetParent %x %x", hwndChild, hwndNewParent));
00391     hwndOldParent = window->SetParent(hwndNewParent);
00392     RELEASE_WNDOBJ(window);
00393     return hwndOldParent;
00394 }
00395 //******************************************************************************
00396 //******************************************************************************
00397 ODINFUNCTION2(BOOL, IsChild,
00398               HWND, hwndParent,
00399               HWND, hwnd)
00400 {
00401   Win32BaseWindow *window;
00402   BOOL             fIsChild;
00403 
00404     window = Win32BaseWindow::GetWindowFromHandle(hwnd);
00405     if(!window) {
00406         dprintf(("IsChild %x, window %x not found", hwndParent, hwnd));
00407         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
00408         return 0;
00409     }
00410     dprintf(("IsChild %x %x", hwndParent, hwnd));
00411     fIsChild = window->IsChild(hwndParent);
00412     RELEASE_WNDOBJ(window);
00413     return fIsChild;
00414 }
00415 //******************************************************************************
00416 //******************************************************************************
00417 ODINFUNCTION1(HWND, GetTopWindow,
00418               HWND, hwnd)
00419 {
00420   Win32BaseWindow *window;
00421   HWND hwndTop;
00422 
00423     if(hwnd == HWND_DESKTOP) {
00424         windowDesktop->addRef();
00425         window = windowDesktop;
00426     }
00427     else {
00428         window = Win32BaseWindow::GetWindowFromHandle(hwnd);
00429         if(!window) {
00430             dprintf(("GetTopWindow, window %x not found", hwnd));
00431             SetLastError(ERROR_INVALID_WINDOW_HANDLE);
00432             return 0;
00433         }
00434     }
00435     hwndTop = window->GetTopWindow();
00436     dprintf2(("GetTopWindow %x returned %x", hwnd, hwndTop));
00437     RELEASE_WNDOBJ(window);
00438     return hwndTop;
00439 }
00440 //******************************************************************************
00441 //******************************************************************************
00442 ODINFUNCTION1(BOOL, IsIconic,
00443               HWND, hwnd)
00444 {
00445   Win32BaseWindow *window;
00446   BOOL fIsIconic;
00447 
00448     window = Win32BaseWindow::GetWindowFromHandle(hwnd);
00449     if(!window) {
00450         dprintf(("IsIconic, window %x not found", hwnd));
00451         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
00452         return FALSE;
00453     }
00454     fIsIconic = window->IsWindowIconic();
00455     dprintf(("IsIconic %x returned %d", hwnd, fIsIconic));
00456     RELEASE_WNDOBJ(window);
00457     return fIsIconic;
00458 }
00459 //******************************************************************************
00460 //******************************************************************************
00461 ODINFUNCTION2(HWND, GetWindow,
00462               HWND, hwnd,
00463               UINT, uCmd)
00464 {
00465   Win32BaseWindow *window;
00466   HWND hwndRelated;
00467 
00468     window = Win32BaseWindow::GetWindowFromHandle(hwnd);
00469     if(!window) {
00470         dprintf(("GetWindow, window %x not found", hwnd));
00471         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
00472         return 0;
00473     }
00474     hwndRelated = window->GetWindow(uCmd);
00475     RELEASE_WNDOBJ(window);
00476     return hwndRelated;
00477 }
00478 //******************************************************************************
00479 //******************************************************************************
00480 ODINFUNCTION2(BOOL, EnableWindow,
00481               HWND, hwnd,
00482               BOOL, fEnable)
00483 {
00484   Win32BaseWindow *window;
00485   BOOL             fEnabled;
00486 
00487     window = Win32BaseWindow::GetWindowFromHandle(hwnd);
00488     if(!window) {
00489         dprintf(("EnableWindow, window %x not found", hwnd));
00490         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
00491         return 0;
00492     }
00493     dprintf(("EnableWindow %x %d", hwnd, fEnable));
00494     fEnabled = window->EnableWindow(fEnable);
00495     RELEASE_WNDOBJ(window);
00496     return fEnabled;
00497 }
00498 //******************************************************************************
00499 //******************************************************************************
00500 ODINFUNCTION1(BOOL, BringWindowToTop,
00501               HWND, hwnd)
00502 {
00503     dprintf(("BringWindowToTop %x", hwnd));
00504     return SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE );
00505 }
00506 /***********************************************************************
00507  *           SetInternalWindowPos   (USER32.483)
00508  */
00509 ODINPROCEDURE4(SetInternalWindowPos,
00510                HWND,    hwnd,
00511                UINT,    showCmd,
00512                LPRECT,  lpRect,
00513                LPPOINT, lpPoint )
00514 {
00515     if( IsWindow(hwnd) )
00516     {
00517         WINDOWPLACEMENT wndpl;
00518         UINT flags;
00519 
00520         GetWindowPlacement(hwnd, &wndpl);
00521         wndpl.length  = sizeof(wndpl);
00522         wndpl.showCmd = showCmd;
00523         wndpl.flags = 0;
00524 
00525         if(lpPoint)
00526         {
00527             wndpl.flags |= WPF_SETMINPOSITION;
00528             wndpl.ptMinPosition = *lpPoint;
00529         }
00530         if(lpRect)
00531         {
00532             wndpl.rcNormalPosition = *lpRect;
00533         }
00534         SetWindowPlacement( hwnd, &wndpl);
00535     }
00536 
00537 }
00538 /***********************************************************************
00539  *           GetInternalWindowPos   (USER32.245)
00540  */
00541 ODINFUNCTION3(UINT,    GetInternalWindowPos,
00542               HWND,    hwnd,
00543               LPRECT,  rectWnd,
00544               LPPOINT, ptIcon )
00545 {
00546     WINDOWPLACEMENT wndpl;
00547 
00548     if(GetWindowPlacement( hwnd, &wndpl ))
00549     {
00550         if (rectWnd) *rectWnd = wndpl.rcNormalPosition;
00551         if (ptIcon)  *ptIcon = wndpl.ptMinPosition;
00552         return wndpl.showCmd;
00553     }
00554     return 0;
00555 }
00556 //******************************************************************************
00557 //******************************************************************************
00558 ODINFUNCTION0(HWND, GetActiveWindow)
00559 {
00560     return Win32BaseWindow::GetActiveWindow();
00561 }
00562 //******************************************************************************
00563 //******************************************************************************
00564 ODINFUNCTION2(BOOL, ShowWindow,
00565               HWND, hwnd,
00566               int,  nCmdShow)
00567 {
00568   Win32BaseWindow *window;
00569   BOOL             ret;
00570 
00571     window = Win32BaseWindow::GetWindowFromHandle(hwnd);
00572     if(!window) {
00573         dprintf(("ShowWindow, window %x not found", hwnd));
00574         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
00575         return 0;
00576     }
00577     ret = window->ShowWindow(nCmdShow);
00578     RELEASE_WNDOBJ(window);
00579     return ret;
00580 }
00581 /*****************************************************************************
00582  * Name      : BOOL WIN32API ShowWindowAsync
00583  * Purpose   : The ShowWindowAsync function sets the show state of a window
00584  *             created by a different thread.
00585  * Parameters: HWND hwnd     handle of window
00586  *             int  nCmdShow show state of window
00587  * Variables :
00588  * Result    : If the window was previously visible, the return value is TRUE.
00589  *             If the window was previously hidden, the return value is FALSE.
00590  * Remark    :
00591  * Status    : UNTESTED STUB
00592  *
00593  * Author    : Patrick Haller [Thu, 1998/02/26 11:55]
00594  *****************************************************************************/
00595 ODINFUNCTION2(BOOL, ShowWindowAsync,
00596               HWND, hwnd,
00597               int,  nCmdShow)
00598 {
00599   dprintf(("USER32:ShowWindowAsync (%08xh,%08x) not correctly implemented.\n",
00600          hwnd,
00601          nCmdShow));
00602 
00603   return ShowWindow(hwnd, nCmdShow);
00604 }
00605 //******************************************************************************
00606 //******************************************************************************
00607 ODINFUNCTION7(BOOL, SetWindowPos,
00608               HWND, hwnd,
00609               HWND, hwndInsertAfter,
00610               int,  x,
00611               int,  y,
00612               int,  cx,
00613               int,  cy,
00614               UINT, fuFlags)
00615 {
00616   Win32BaseWindow *window;
00617 
00618     if (!hwnd)
00619     {
00620       dprintf(("SetWindowPos: Can't move desktop!"));
00621       return TRUE;
00622     }
00623     window = Win32BaseWindow::GetWindowFromHandle(hwnd);
00624     if(!window) {
00625         dprintf(("SetWindowPos, window %x not found", hwnd));
00626         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
00627         return FALSE;
00628     }
00629     dprintf(("SetWindowPos %x %x x=%d y=%d cx=%d cy=%d %x", hwnd, hwndInsertAfter, x, y, cx, cy, fuFlags));
00630     BOOL ret = window->SetWindowPos(hwndInsertAfter, x, y, cx, cy, fuFlags);
00631     RELEASE_WNDOBJ(window);
00632     return ret;
00633 }
00634 //******************************************************************************
00635 //NOTE: length must equal structure size or else api fails (verified in NT4, SP6)
00636 //******************************************************************************
00637 ODINFUNCTION2(BOOL, SetWindowPlacement,
00638               HWND, hwnd,
00639               const WINDOWPLACEMENT *, winpos)
00640 {
00641   Win32BaseWindow *window;
00642 
00643     if(!winpos || winpos->length != sizeof(WINDOWPLACEMENT)) {
00644         dprintf(("SetWindowPlacement %x invalid parameter", hwnd));
00645         SetLastError(ERROR_INVALID_PARAMETER);
00646         return FALSE;
00647     }
00648     window = Win32BaseWindow::GetWindowFromHandle(hwnd);
00649     if(!window) {
00650         dprintf(("SetWindowPlacement, window %x not found", hwnd));
00651         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
00652         return FALSE;
00653     }
00654     dprintf(("USER32: SetWindowPlacement %x %x", hwnd, winpos));
00655     BOOL ret = window->SetWindowPlacement((WINDOWPLACEMENT *)winpos);
00656     RELEASE_WNDOBJ(window);
00657     return ret;
00658 }
00659 //******************************************************************************
00660 //NOTE: Length does not need to be correct (even though the SDK docs claim otherwise)
00661 //      (Verified in NT4, SP6)
00662 //******************************************************************************
00663 ODINFUNCTION2(BOOL, GetWindowPlacement,
00664               HWND, hwnd,
00665               LPWINDOWPLACEMENT, winpos)
00666 {
00667   Win32BaseWindow *window;
00668 
00669     if(!winpos) {
00670         dprintf(("GetWindowPlacement %x invalid parameter", hwnd));
00671         SetLastError(ERROR_INVALID_PARAMETER);
00672         return FALSE;
00673     }
00674     window = Win32BaseWindow::GetWindowFromHandle(hwnd);
00675     if(!window) {
00676         dprintf(("GetWindowPlacement, window %x not found", hwnd));
00677         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
00678         return FALSE;
00679     }
00680     dprintf(("USER32: GetWindowPlacement %x %x", hwnd, winpos));
00681     BOOL ret = window->GetWindowPlacement(winpos);
00682     RELEASE_WNDOBJ(window);
00683     return ret;
00684 }
00685 //******************************************************************************
00686 //******************************************************************************
00687 BOOL WIN32API IsWindow(HWND hwnd)
00688 {
00689   Win32BaseWindow *window;
00690 
00691     window = Win32BaseWindow::GetWindowFromHandle(hwnd);
00692     if(!window) {
00693         dprintf(("IsWindow, window %x not found", hwnd));
00694         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
00695         return FALSE;
00696     }
00697     dprintf2(("IsWindow %x", hwnd));
00698     BOOL fIsWindow = window->IsWindow();
00699     RELEASE_WNDOBJ(window);
00700     return fIsWindow;
00701 }
00702 //******************************************************************************
00703 //******************************************************************************
00704 ODINFUNCTION1(BOOL, IsWindowEnabled,
00705               HWND, hwnd)
00706 {
00707   DWORD            dwStyle;
00708 
00709     if(!IsWindow(hwnd)) {
00710         dprintf(("IsWindowEnabled, window %x not found", hwnd));
00711         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
00712         return 0;
00713     }
00714     dprintf(("IsWindowEnabled %x", hwnd));
00715     dwStyle = GetWindowLongA(hwnd, GWL_STYLE);
00716     if(dwStyle & WS_DISABLED) {
00717         return FALSE;
00718     }
00719     return TRUE;
00720 }
00721 //******************************************************************************
00722 //******************************************************************************
00723 BOOL WIN32API IsWindowVisible(HWND hwnd)
00724 {
00725   BOOL             ret;
00726   HWND             hwndParent;
00727   DWORD            dwStyle;
00728 
00729     if(hwnd == HWND_DESKTOP) {//TODO: verify in NT!
00730         dprintf(("IsWindowVisible DESKTOP returned TRUE"));
00731         return TRUE;    //desktop is always visible
00732     }
00733     if(!IsWindow(hwnd)) {
00734         dprintf(("IsWindowVisible, window %x not found", hwnd));
00735         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
00736         return 0;
00737     }
00738     //check visibility of this window
00739     dwStyle = GetWindowLongA(hwnd, GWL_STYLE);
00740     if(!(dwStyle & WS_VISIBLE)) {
00741         ret = FALSE;
00742         goto end;
00743     }
00744     ret = TRUE;
00745 
00746     if(dwStyle & WS_CHILD) 
00747     {
00748         //check visibility of parents
00749         hwndParent = GetParent(hwnd);
00750         while(hwndParent) {
00751             dwStyle = GetWindowLongA(hwndParent, GWL_STYLE);
00752             if(!(dwStyle & WS_VISIBLE)) {
00753                 dprintf(("IsWindowVisible %x returned FALSE (parent %x invisible)", hwnd, hwndParent));
00754                 return FALSE;
00755             }
00756             if(!(dwStyle & WS_CHILD)) {
00757                 break; //GetParent can also return the owner
00758             }
00759             hwndParent = GetParent(hwndParent);
00760         }
00761     }
00762 end:
00763     dprintf(("IsWindowVisible %x returned %d", hwnd, ret));
00764     return ret;
00765 }
00766 //******************************************************************************
00767 //******************************************************************************
00768 ODINFUNCTION1(HWND, SetFocus,
00769               HWND, hwnd)
00770 {
00771  Win32BaseWindow *window;
00772  Win32BaseWindow *oldfocuswnd;
00773  HWND lastFocus, lastFocus_W, hwnd_O, hwndTopParent;
00774  BOOL activate;
00775  TEB *teb;
00776 
00777     teb = GetThreadTEB();
00778     if(teb == NULL) {
00779         DebugInt3();
00780         return 0;
00781     }
00782 
00783     window = Win32BaseWindow::GetWindowFromHandle(hwnd);
00784     if(!window) {
00785         dprintf(("SetFocus, window %x not found", hwnd));
00786         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
00787         return 0;
00788     }
00789 
00790     hwnd_O = window->getOS2WindowHandle();
00791     if(teb->o.odin.hwndFocus) {
00792          lastFocus = teb->o.odin.hwndFocus;
00793     }
00794     else lastFocus = OSLibWinQueryFocus (OSLIB_HWND_DESKTOP);
00795 
00796     hwndTopParent = window->GetTopParent();
00797     activate = FALSE;
00798     lastFocus_W = OS2ToWin32Handle(lastFocus);
00799     if(lastFocus_W) {
00800          oldfocuswnd = Win32BaseWindow::GetWindowFromHandle(lastFocus_W);
00801          if(lastFocus_W != hwnd && hwndTopParent != oldfocuswnd->GetTopParent()) {
00802             activate = TRUE;
00803          }
00804          RELEASE_WNDOBJ(oldfocuswnd);
00805     }
00806     else activate = TRUE;
00807 
00808     dprintf(("SetFocus %x (%x) -> %x (%x) act %d", lastFocus_W, lastFocus, hwnd, hwnd_O, activate));
00809 
00810     if(HOOK_CallHooksA(WH_CBT, HCBT_SETFOCUS, hwnd, (LPARAM)lastFocus_W)) {
00811         dprintf(("hook cancelled SetFocus call!"));
00812         return 0;
00813     }
00814 
00815     //PM doesn't allow SetFocus calls during WM_SETFOCUS message processing;
00816     //must delay this function call
00817     if(teb->o.odin.fWM_SETFOCUS) {
00818         dprintf(("USER32: Delay SetFocus call!"));
00819         teb->o.odin.hwndFocus = hwnd;
00820         //mp1 = win32 window handle
00821         //mp2 = top parent if activation required
00822         OSLibPostMessageDirect(hwnd_O, WIN32APP_SETFOCUSMSG, hwnd, (activate) ? hwndTopParent : 0);
00823         return lastFocus_W;
00824     }
00825     teb->o.odin.hwndFocus = 0;
00826     if(!IsWindow(hwnd)) return FALSE;       //abort if window destroyed
00827 
00828     //NOTE: Don't always activate the window or else the z-order will be changed!!
00829     return (OSLibWinSetFocus(OSLIB_HWND_DESKTOP, hwnd_O, activate)) ? lastFocus_W : 0;
00830 }
00831 //******************************************************************************
00832 //******************************************************************************
00833 ODINFUNCTION0(HWND, GetFocus)
00834 {
00835  TEB *teb;
00836  HWND hwnd;
00837 
00838     teb = GetThreadTEB();
00839     if(teb == NULL) {
00840         DebugInt3();
00841         return 0;
00842     }
00843     //PM doesn't allow SetFocus calls during WM_SETFOCUS message processing;
00844     //If focus was changed during WM_SETFOCUS, the focus window handle is
00845     //stored in teb->o.odin.hwndFocus (set back to 0 when delayed SetFocus
00846     //is activated)
00847     if(teb->o.odin.hwndFocus) {
00848         dprintf(("USER32: GetFocus %x (DURING WM_SETFOCUS PROCESSING)", teb->o.odin.hwndFocus));
00849         return teb->o.odin.hwndFocus;
00850     }
00851 
00852     hwnd = OSLibWinQueryFocus(OSLIB_HWND_DESKTOP);
00853     hwnd = OS2ToWin32Handle(hwnd);
00854     dprintf(("USER32: GetFocus %x\n", hwnd));
00855     return hwnd;
00856 }
00857 //******************************************************************************
00858 //******************************************************************************
00859 ODINFUNCTION1(BOOL, IsZoomed,
00860               HWND, hwnd)
00861 {
00862  DWORD style;
00863 
00864     style = GetWindowLongA(hwnd, GWL_STYLE);
00865     dprintf(("USER32: IsZoomed %x returned %d", hwnd, ((style & WS_MAXIMIZE) != 0)));
00866 
00867     return (style & WS_MAXIMIZE) != 0;
00868 }
00869 //******************************************************************************
00870 //******************************************************************************
00871 ODINFUNCTION1(BOOL, LockWindowUpdate,
00872               HWND, hwnd)
00873 {
00874   return OSLibWinLockWindowUpdate(Win32ToOS2Handle(hwnd));
00875 }
00876 //******************************************************************************
00877 //******************************************************************************
00878 ODINFUNCTION2(BOOL,  GetWindowRect,
00879               HWND,  hwnd,
00880               PRECT, pRect)
00881 {
00882   Win32BaseWindow *window;
00883 
00884     if(pRect == NULL) {
00885         dprintf(("GetWindowRect %x invalid parameter!", hwnd));
00886         SetLastError(ERROR_INVALID_PARAMETER);
00887         return FALSE;
00888     }
00889 
00890     if(hwnd == HWND_DESKTOP) {
00891          windowDesktop->addRef();
00892          window = windowDesktop;
00893     }     
00894     else window = Win32BaseWindow::GetWindowFromHandle(hwnd);
00895       
00896     if(!window) {
00897         dprintf(("GetWindowRect, window %x not found", hwnd));
00898         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
00899         return FALSE;
00900     }
00901     *pRect = *window->getWindowRect();
00902 
00903     //convert from parent coordinates to screen (if necessary)
00904     if(window->getParent()) {
00905          MapWindowPoints(window->getParent()->getWindowHandle(), 0, (PPOINT)pRect, 2);
00906     }
00907     RELEASE_WNDOBJ(window);
00908     dprintf(("GetWindowRect %x (%d,%d) (%d,%d)", hwnd, pRect->left, pRect->top, pRect->right, pRect->bottom));
00909     return TRUE;
00910 }
00911 //******************************************************************************
00912 //******************************************************************************
00913 ODINFUNCTION1(int,  GetWindowTextLengthA,
00914               HWND, hwnd)
00915 {
00916    Win32BaseWindow *window;
00917 
00918     window = Win32BaseWindow::GetWindowFromHandle(hwnd);
00919     if(!window) {
00920         dprintf(("GetWindowTextLengthA, window %x not found", hwnd));
00921         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
00922         return 0;
00923     }
00924     dprintf(("GetWindowTextLengthA %x", hwnd));
00925     int ret = window->GetWindowTextLengthA();
00926     RELEASE_WNDOBJ(window);
00927     return ret;
00928 }
00929 //******************************************************************************
00930 //******************************************************************************
00931 int WIN32API GetWindowTextA( HWND hwnd, LPSTR lpsz, int cch)
00932 {
00933    Win32BaseWindow *window;
00934    int rc;
00935 
00936     window = Win32BaseWindow::GetWindowFromHandle(hwnd);
00937     if(!window) {
00938         dprintf(("GetWindowTextA, window %x not found", hwnd));
00939         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
00940         return 0;
00941     }
00942     rc = window->GetWindowTextA(lpsz, cch);
00943     dprintf(("GetWindowTextA %x %s", hwnd, lpsz));
00944     RELEASE_WNDOBJ(window);
00945     return rc;
00946 }
00947 //******************************************************************************
00948 //******************************************************************************
00949 int WIN32API GetWindowTextLengthW( HWND hwnd)
00950 {
00951    Win32BaseWindow *window;
00952 
00953     window = Win32BaseWindow::GetWindowFromHandle(hwnd);
00954     if(!window) {
00955         dprintf(("GetWindowTextLengthW, window %x not found", hwnd));
00956         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
00957         return 0;
00958     }
00959     dprintf(("GetWindowTextLengthW %x", hwnd));
00960     int ret = window->GetWindowTextLengthW();
00961     RELEASE_WNDOBJ(window);
00962     return ret;
00963 }
00964 //******************************************************************************
00965 //******************************************************************************
00966 int WIN32API GetWindowTextW(HWND hwnd, LPWSTR lpsz, int cch)
00967 {
00968    Win32BaseWindow *window;
00969 
00970     window = Win32BaseWindow::GetWindowFromHandle(hwnd);
00971     if(!window) {
00972         dprintf(("GetWindowTextW, window %x not found", hwnd));
00973         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
00974         return 0;
00975     }
00976     int rc = window->GetWindowTextW(lpsz, cch);
00977     RELEASE_WNDOBJ(window);
00978     dprintf(("GetWindowTextW %x %ls", hwnd, lpsz));
00979     return rc;
00980 }
00981 //******************************************************************************
00982 //******************************************************************************
00983 BOOL WIN32API SetWindowTextA(HWND hwnd, LPCSTR lpsz)
00984 {
00985    Win32BaseWindow *window;
00986 
00987     window = Win32BaseWindow::GetWindowFromHandle(hwnd);
00988     if(!window) {
00989         dprintf(("SetWindowTextA, window %x not found", hwnd));
00990         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
00991         return 0;
00992     }
00993     dprintf(("SetWindowTextA %x %s", hwnd, lpsz));
00994     BOOL ret = window->SetWindowTextA((LPSTR)lpsz);
00995     RELEASE_WNDOBJ(window);
00996     return ret;
00997 }
00998 //******************************************************************************
00999 //******************************************************************************
01000 BOOL WIN32API SetWindowTextW( HWND hwnd, LPCWSTR lpsz)
01001 {
01002    Win32BaseWindow *window;
01003 
01004     window = Win32BaseWindow::GetWindowFromHandle(hwnd);
01005     if(!window) {
01006         dprintf(("SetWindowTextA, window %x not found", hwnd));
01007         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
01008         return 0;
01009     }
01010     dprintf(("SetWindowTextW %x %ls", hwnd, lpsz));
01011     BOOL ret = window->SetWindowTextW((LPWSTR)lpsz);
01012     RELEASE_WNDOBJ(window);
01013     return ret;
01014 }
01015 /*******************************************************************
01016  *      InternalGetWindowText    (USER32.326)
01017  */
01018 int WIN32API InternalGetWindowText(HWND   hwnd,
01019                                    LPWSTR lpString,
01020                                    INT    nMaxCount )
01021 {
01022     dprintf(("USER32: InternalGetWindowText(%08xh,%08xh,%08xh) not properly implemented.\n",
01023              hwnd,
01024              lpString,
01025              nMaxCount));
01026 
01027     return GetWindowTextW(hwnd,lpString,nMaxCount);
01028 }
01029 //******************************************************************************
01030 //TODO: Correct?
01031 //******************************************************************************
01032 BOOL WIN32API SetForegroundWindow(HWND hwnd)
01033 {
01034     dprintf((" SetForegroundWindow %x", hwnd));
01035 
01036     return SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
01037 }
01038 //******************************************************************************
01039 //******************************************************************************
01040 BOOL WIN32API GetClientRect( HWND hwnd, PRECT pRect)
01041 {
01042  HWND hwndWin32 = hwnd;
01043  Win32BaseWindow *window;
01044 
01045     if (!pRect)
01046     {
01047         SetLastError(ERROR_INVALID_PARAMETER);
01048         return FALSE;
01049     }
01050     window = Win32BaseWindow::GetWindowFromHandle(hwnd);
01051     if(!window) {
01052         dprintf(("GetClientRect, window %x not found", hwnd));
01053         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
01054         return FALSE;
01055     }
01056     window->getClientRect(pRect);
01057     dprintf(("GetClientRect of %X returned (%d,%d) (%d,%d)\n", hwndWin32, pRect->left, pRect->top, pRect->right, pRect->bottom));
01058     RELEASE_WNDOBJ(window);
01059     return TRUE;
01060 }
01061 //******************************************************************************
01062 //******************************************************************************
01063 BOOL WIN32API AdjustWindowRect(PRECT rect, DWORD style, BOOL menu)
01064 {
01065     return AdjustWindowRectEx(rect, style, menu, 0);
01066 }
01067 //******************************************************************************
01068 //Calculate window rectangle based on given client rectangle, style, menu and extended style
01069 //******************************************************************************
01070 BOOL WIN32API AdjustWindowRectEx( PRECT rect, DWORD style, BOOL menu, DWORD exStyle)
01071 {
01072     if(style == 0 && menu == FALSE && exStyle == 0) {
01073         dprintf(("AdjustWindowRectEx %x %x %d (%d,%d)(%d,%d) -> no change required", style, exStyle, menu, rect->left, rect->top, rect->right, rect->bottom));
01074         return TRUE;    //nothing needs to be changed (VERIFIED in NT 4)
01075     }
01076     dprintf(("AdjustWindowRectEx %x %x %d (%d,%d)(%d,%d)\n", style, exStyle, menu, rect->left, rect->top, rect->right, rect->bottom));
01077     /* Correct the window style */
01078     if (!(style & (WS_POPUP | WS_CHILD)))  /* Overlapped window */
01079         style |= WS_CAPTION;
01080 
01081     //SvL: Include WS_POPUP -> otherwise HAS_THINFRAME is true for popup windows
01082     //     Also include WS_CHILD -> otherwise HAS_THICKFRAME doesn't work correctly
01083     style &= (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME | WS_CHILD | WS_VSCROLL | WS_HSCROLL | WS_POPUP);
01084     exStyle &= (WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE | WS_EX_TOOLWINDOW);
01085     if (exStyle & WS_EX_DLGMODALFRAME) style &= ~WS_THICKFRAME;
01086 
01087     //Adjust rect outer (Win32BaseWindow::AdjustRectOuter)
01088     if (HAS_THICKFRAME(style,exStyle))
01089         InflateRect( rect, GetSystemMetrics(SM_CXFRAME), GetSystemMetrics(SM_CYFRAME) );
01090     else
01091     if (HAS_DLGFRAME(style,exStyle))
01092         InflateRect(rect, GetSystemMetrics(SM_CXDLGFRAME), GetSystemMetrics(SM_CYDLGFRAME) );
01093     else
01094     if (HAS_THINFRAME(style))
01095         InflateRect( rect, GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER));
01096 
01097     if ((style & WS_CAPTION) == WS_CAPTION)
01098     {
01099         if (exStyle & WS_EX_TOOLWINDOW)
01100             rect->top -= GetSystemMetrics(SM_CYSMCAPTION);
01101         else
01102             rect->top -= GetSystemMetrics(SM_CYCAPTION);
01103     }
01104 
01105     if (menu)
01106         rect->top -= GetSystemMetrics(SM_CYMENU);
01107 
01108     //Adjust rect inner (Win32BaseWindow::AdjustRectInner)
01109     if(!(style & WS_ICONIC)) {
01110         if (exStyle & WS_EX_CLIENTEDGE)
01111             InflateRect (rect, GetSystemMetrics(SM_CXEDGE), GetSystemMetrics(SM_CYEDGE));
01112 
01113         if (exStyle & WS_EX_STATICEDGE)
01114             InflateRect (rect, GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER));
01115 
01116         //SvL: scrollbars aren't checked *UNLESS* the style includes a border (any border)
01117         //     --> VERIFIED IN NT4, SP6 (fixes MFC apps with scrollbars + bar controls)
01118         if(style & (WS_THICKFRAME|WS_BORDER|WS_DLGFRAME)) {
01119             if (style & WS_VSCROLL) rect->right  += GetSystemMetrics(SM_CXVSCROLL);
01120             if (style & WS_HSCROLL) rect->bottom += GetSystemMetrics(SM_CYHSCROLL);
01121         }
01122     }
01123 
01124     dprintf(("AdjustWindowRectEx returned (%d,%d)(%d,%d)\n", rect->left, rect->top, rect->right, rect->bottom));
01125 
01126     return TRUE;
01127 }
01128 //******************************************************************************
01129 /* Coordinate Space and Transformation Functions */
01130 //******************************************************************************
01131 /*******************************************************************
01132  *         WINPOS_GetWinOffset
01133  *
01134  * Calculate the offset between the origin of the two windows. Used
01135  * to implement MapWindowPoints.
01136  */
01137 static void WINPOS_GetWinOffset( Win32BaseWindow *wndFrom, Win32BaseWindow *wndTo,
01138                                  POINT *offset )
01139 {
01140  Win32BaseWindow *window;
01141 
01142     offset->x = offset->y = 0;
01143 
01144     /* Translate source window origin to screen coords */
01145     if(wndFrom != windowDesktop)
01146     {
01147     window = wndFrom;
01148         while(window)
01149         {
01150             offset->x += window->getClientRectPtr()->left + window->getWindowRect()->left;
01151             offset->y += window->getClientRectPtr()->top + window->getWindowRect()->top;
01152             window = window->getParent();
01153         }
01154     }
01155 
01156     /* Translate origin to destination window coords */
01157     if(wndTo != windowDesktop)
01158     {
01159     window = wndTo;
01160         while(window)
01161         {
01162             offset->x -= window->getClientRectPtr()->left + window->getWindowRect()->left;
01163             offset->y -= window->getClientRectPtr()->top + window->getWindowRect()->top;
01164             window = window->getParent();
01165         }
01166     }
01167 }
01168 //******************************************************************************
01169 //******************************************************************************
01170 int WIN32API MapWindowPoints(HWND hwndFrom, HWND hwndTo, LPPOINT lpPoints,
01171                              UINT cPoints)
01172 {
01173  Win32BaseWindow *wndfrom, *wndto;
01174  int retval = 0;
01175  POINT offset;
01176 
01177     SetLastError(0);
01178     if(lpPoints == NULL || cPoints == 0) {
01179         SetLastError(ERROR_INVALID_PARAMETER);
01180         return 0;
01181     }
01182     if(hwndTo == hwndFrom)
01183         return 0; //nothing to do
01184 
01185     if(hwndFrom == HWND_DESKTOP)
01186     {
01187         windowDesktop->addRef();
01188         wndfrom = windowDesktop;
01189     } 
01190     else {
01191         wndfrom = Win32BaseWindow::GetWindowFromHandle(hwndFrom);
01192         if(!wndfrom) {
01193             dprintf(("MapWindowPoints, window %x not found", hwndFrom));
01194             SetLastError(ERROR_INVALID_WINDOW_HANDLE);
01195             return 0;
01196         }
01197     }
01198 
01199     if(hwndTo == HWND_DESKTOP)
01200     {
01201         windowDesktop->addRef();
01202         wndto = windowDesktop;
01203     } 
01204     else {
01205         wndto = Win32BaseWindow::GetWindowFromHandle(hwndTo);
01206         if(!wndto) {
01207             dprintf(("MapWindowPoints, window %x not found", hwndTo));
01208             SetLastError(ERROR_INVALID_WINDOW_HANDLE);
01209             return 0;
01210         }
01211     }
01212 
01213     dprintf2(("USER32: MapWindowPoints %x to %x (%d,%d) (%d)", hwndFrom, hwndTo, lpPoints->x, lpPoints->y, cPoints));
01214     WINPOS_GetWinOffset(wndfrom, wndto, &offset);
01215 
01216     RELEASE_WNDOBJ(wndto);
01217     RELEASE_WNDOBJ(wndfrom);
01218     for(int i=0;i<cPoints;i++)
01219     {
01220         lpPoints[i].x += offset.x;
01221         lpPoints[i].y += offset.y;
01222     }
01223     retval = ((LONG)offset.y << 16) | offset.x;
01224     return retval;
01225 }
01226 //******************************************************************************
01227 //******************************************************************************
01228 BOOL WIN32API ScreenToClient(HWND hwnd, LPPOINT pt)
01229 {
01230     PRECT rcl;
01231     BOOL rc;
01232 
01233     if(hwnd == HWND_DESKTOP) {
01234         return (TRUE); //nothing to do
01235     }
01236     if (!IsWindow(hwnd)) {
01237         dprintf(("warning: ScreenToClient: window %x not found!", hwnd));
01238         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
01239         return FALSE;
01240     }
01241     SetLastError(0);
01242 #ifdef DEBUG
01243     POINT tmp = *pt;
01244 #endif
01245     MapWindowPoints(0, hwnd, pt, 1);
01246     dprintf2(("ScreenToClient %x (%d,%d) -> (%d,%d)", hwnd, tmp.x, tmp.y, pt->x, pt->y));
01247     return TRUE;
01248 }
01249 //******************************************************************************
01250 //******************************************************************************
01251 HWND WIN32API GetDesktopWindow(void)
01252 {
01253     HWND DesktopWindow = windowDesktop->getWindowHandle();
01254     dprintf2(("USER32: GetDesktopWindow, returned %x\n", DesktopWindow));
01255     return DesktopWindow;
01256 }
01257 //******************************************************************************
01258 //******************************************************************************
01259 HWND WIN32API FindWindowA(LPCSTR lpszClass, LPCSTR lpszWindow)
01260 {
01261     return FindWindowExA( NULL, NULL, lpszClass, lpszWindow );
01262 }
01263 //******************************************************************************
01264 //******************************************************************************
01265 HWND WIN32API FindWindowW( LPCWSTR lpClassName, LPCWSTR lpWindowName)
01266 {
01267     return FindWindowExW( NULL, NULL, lpClassName, lpWindowName );
01268 }
01269 //******************************************************************************
01270 //******************************************************************************
01271 HWND WIN32API FindWindowExA(HWND hwndParent, HWND hwndChildAfter, LPCSTR lpszClass, LPCSTR lpszWindow)
01272 {
01273     ATOM atom = 0;
01274 
01275     if (lpszClass)
01276     {
01277         /* If the atom doesn't exist, then no class */
01278         /* with this name exists either. */
01279         if (!(atom = GlobalFindAtomA( lpszClass )))
01280         {
01281             SetLastError(ERROR_CANNOT_FIND_WND_CLASS);
01282             return 0;
01283         }
01284     }
01285     return Win32BaseWindow::FindWindowEx(hwndParent, hwndChildAfter, atom, (LPSTR)lpszWindow);
01286 }
01287 /*****************************************************************************
01288  * Name      : HWND WIN32API FindWindowExW
01289  * Purpose   : The FindWindowEx function retrieves the handle of a window whose
01290  *             class name and window name match the specified strings. The
01291  *             function searches child windows, beginning with the one following
01292  *             the given child window.
01293  * Parameters: HWND    hwndParent     handle of parent window
01294  *             HWND    hwndChildAfter handle of a child window
01295  *             LPCTSTR lpszClass      address of class name
01296  *             LPCTSTR lpszWindow     address of window name
01297  * Variables :
01298  * Result    : If the function succeeds, the return value is the handle of the
01299  *               window that has the specified class and window names.
01300  *             If the function fails, the return value is NULL. To get extended
01301  *               error information, call GetLastError.
01302  * Remark    :
01303  *
01304  *****************************************************************************/
01305 
01306 HWND WIN32API FindWindowExW(HWND    hwndParent,
01307                             HWND    hwndChildAfter,
01308                             LPCWSTR lpszClass,
01309                             LPCWSTR lpszWindow)
01310 {
01311     ATOM atom = 0;
01312     char *buffer;
01313     HWND hwnd;
01314 
01315     if (lpszClass)
01316     {
01317         /* If the atom doesn't exist, then no class */
01318         /* with this name exists either. */
01319         if (!(atom = GlobalFindAtomW( lpszClass )))
01320         {
01321             SetLastError(ERROR_CANNOT_FIND_WND_CLASS);
01322             return 0;
01323         }
01324     }
01325     buffer = HEAP_strdupWtoA( GetProcessHeap(), 0, lpszWindow );
01326     hwnd = Win32BaseWindow::FindWindowEx(hwndParent, hwndChildAfter, atom, buffer);
01327     HeapFree( GetProcessHeap(), 0, buffer );
01328     return hwnd;
01329 }
01330 //******************************************************************************
01331 //******************************************************************************
01332 BOOL WIN32API FlashWindow(HWND hwnd, BOOL fFlash)
01333 {
01334     dprintf(("FlashWindow %x %d\n", hwnd, fFlash));
01335 //    return OSLibWinFlashWindow(Win32ToOS2Handle(hwnd), fFlash);
01336     return 1;
01337 }
01338 //******************************************************************************
01339 //******************************************************************************
01340 BOOL WIN32API MoveWindow( HWND hwnd, INT x, INT y, INT cx, INT cy,
01341                           BOOL repaint )
01342 {
01343     int flags = SWP_NOZORDER | SWP_NOACTIVATE;
01344 
01345     if (!repaint) flags |= SWP_NOREDRAW;
01346     dprintf(("MoveWindow: %x %d,%d %dx%d %d\n", hwnd, x, y, cx, cy, repaint ));
01347 
01348     return SetWindowPos( hwnd, 0, x, y, cx, cy, flags );
01349 }
01350 //******************************************************************************
01351 //******************************************************************************
01352 BOOL WIN32API ClientToScreen (HWND hwnd, PPOINT pt)
01353 {
01354     PRECT rcl;
01355 
01356     if(hwnd == HWND_DESKTOP) {
01357         return(TRUE); //nothing to do
01358     }
01359     if(!IsWindow(hwnd)) {
01360         dprintf(("warning: ClientToScreen window %x not found!", hwnd));
01361         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
01362         return (FALSE);
01363     }
01364 #ifdef DEBUG
01365     POINT tmp = *pt;
01366 #endif
01367     MapWindowPoints(hwnd, 0, pt, 1);
01368     dprintf2(("ClientToScreen %x (%d,%d) -> (%d,%d)", hwnd, tmp.x, tmp.y, pt->x, pt->y));
01369 
01370     return TRUE;
01371 }
01372 //******************************************************************************
01373 //Note: count 0 is a legal parameter (verified in NT4)
01374 //******************************************************************************
01375 HDWP WIN32API BeginDeferWindowPos(int count)
01376 {
01377     HDWP handle;
01378     DWP *pDWP;
01379 
01380     if (count < 0)
01381     {
01382         dprintf(("USER32: BeginDeferWindowPos invalid param %d", count));
01383         SetLastError(ERROR_INVALID_PARAMETER);
01384         return 0;
01385     }
01386     dprintf(("USER32: BeginDeferWindowPos %d", count));
01387     if(count == 0)
01388         count = 8;  // change to any non-zero value
01389 
01390     handle = (HDWP)HeapAlloc(GetProcessHeap(), 0, sizeof(DWP) + (count-1)*sizeof(WINDOWPOS));
01391     if (!handle)
01392         return 0;
01393 
01394     pDWP = (DWP *) handle;
01395     pDWP->actualCount    = 0;
01396     pDWP->suggestedCount = count;
01397     pDWP->valid          = TRUE;
01398     pDWP->wMagic         = DWP_MAGIC;
01399     pDWP->hwndParent     = 0;
01400     return handle;
01401 }
01402 /***********************************************************************
01403  *           DeferWindowPos   (USER32.128)
01404  *
01405  * TODO: SvL: Does this need to be thread safe?
01406  *
01407  */
01408 HDWP WIN32API DeferWindowPos( HDWP hdwp, HWND hwnd, HWND hwndAfter,
01409                               INT x, INT y, INT cx, INT cy,
01410                               UINT flags )
01411 {
01412   DWP *pDWP;
01413   int i;
01414   HDWP newhdwp = hdwp,retvalue;
01415 
01416     pDWP = (DWP *)hdwp;
01417     if (!pDWP) {
01418         SetLastError(ERROR_INVALID_PARAMETER);
01419         return 0;
01420     }
01421 
01422     if (hwnd == GetDesktopWindow())
01423         return 0;
01424 
01425     if(!IsWindow(hwnd)) {
01426         dprintf(("DeferWindowPos, window %x not found", hwnd));
01427         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
01428         HeapFree(GetProcessHeap(), 0, (LPVOID)hdwp);
01429         return 0;
01430     }
01431 
01432     dprintf(("USER32: DeferWindowPos hdwp %x hwnd %x hwndAfter %x (%d,%d)(%d,%d) %x", hdwp, hwnd, hwndAfter,
01433               x, y, cx, cy, flags));
01434 
01435 /* Numega Bounds Checker Demo dislikes the following code.
01436    In fact, I've not been able to find any "same parent" requirement in any docu
01437    [AM 980509]
01438  */
01439 #if 0
01440     /* All the windows of a DeferWindowPos() must have the same parent */
01441     parent = pWnd->parent->hwndSelf;
01442     if (pDWP->actualCount == 0) pDWP->hwndParent = parent;
01443     else if (parent != pDWP->hwndParent)
01444     {
01445         USER_HEAP_FREE( hdwp );
01446         retvalue = 0;
01447         goto END;
01448     }
01449 #endif
01450 
01451     for (i = 0; i < pDWP->actualCount; i++)
01452     {
01453         if (pDWP->winPos[i].hwnd == hwnd)
01454         {
01455               /* Merge with the other changes */
01456             if (!(flags & SWP_NOZORDER))
01457             {
01458                 pDWP->winPos[i].hwndInsertAfter = hwndAfter;
01459             }
01460             if (!(flags & SWP_NOMOVE))
01461             {
01462                 pDWP->winPos[i].x = x;
01463                 pDWP->winPos[i].y = y;
01464             }
01465             if (!(flags & SWP_NOSIZE))
01466             {
01467                 pDWP->winPos[i].cx = cx;
01468                 pDWP->winPos[i].cy = cy;
01469             }
01470             pDWP->winPos[i].flags &= flags | ~(SWP_NOSIZE | SWP_NOMOVE |
01471                                                SWP_NOZORDER | SWP_NOREDRAW |
01472                                                SWP_NOACTIVATE | SWP_NOCOPYBITS|
01473                                                SWP_NOOWNERZORDER);
01474             pDWP->winPos[i].flags |= flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW |
01475                                               SWP_FRAMECHANGED);
01476             retvalue = hdwp;
01477             goto END;
01478         }
01479     }
01480     if (pDWP->actualCount >= pDWP->suggestedCount)
01481     {
01482         //DWP structure already contains WINDOWPOS, allocated with (count-1)
01483         //in BeginDeferWindowPos; pDWP->suggestedCount alloc increases it by one
01484         newhdwp = (HDWP)HeapReAlloc(GetProcessHeap(), 0, (LPVOID)hdwp,
01485                                     sizeof(DWP) + pDWP->suggestedCount*sizeof(WINDOWPOS));
01486         if (!newhdwp)
01487         {
01488             retvalue = 0;
01489             goto END;
01490         }
01491         pDWP = (DWP *) newhdwp;
01492         pDWP->suggestedCount++;
01493     }
01494     pDWP->winPos[pDWP->actualCount].hwnd = hwnd;
01495     pDWP->winPos[pDWP->actualCount].hwndInsertAfter = hwndAfter;
01496     pDWP->winPos[pDWP->actualCount].x = x;
01497     pDWP->winPos[pDWP->actualCount].y = y;
01498     pDWP->winPos[pDWP->actualCount].cx = cx;
01499     pDWP->winPos[pDWP->actualCount].cy = cy;
01500     pDWP->winPos[pDWP->actualCount].flags = flags;
01501     pDWP->actualCount++;
01502     retvalue = newhdwp;
01503 END:
01504     return retvalue;
01505 }
01506 //******************************************************************************
01507 //******************************************************************************
01508 BOOL WIN32API EndDeferWindowPos( HDWP hdwp)
01509 {
01510     DWP *pDWP;
01511     WINDOWPOS *winpos;
01512     BOOL res = TRUE;
01513     int i;
01514 
01515     pDWP = (DWP *) hdwp;
01516     if (!pDWP) {
01517         dprintf(("**EndDeferWindowPos invalid parameter\n"));
01518         SetLastError(ERROR_INVALID_PARAMETER);
01519         return FALSE;
01520     }
01521     dprintf(("**EndDeferWindowPos for %d windows", pDWP->actualCount));
01522     for (i = 0, winpos = pDWP->winPos; i < pDWP->actualCount; i++, winpos++)
01523     {
01524         dprintf(("**EndDeferWindowPos %x (%d,%d) (%d,%d) %x", winpos->hwnd, winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags));
01525         if (!(res = SetWindowPos(winpos->hwnd, winpos->hwndInsertAfter,
01526                                  winpos->x, winpos->y, winpos->cx,
01527                                  winpos->cy, winpos->flags )))
01528             break;
01529     }
01530     dprintf(("**EndDeferWindowPos DONE"));
01531     HeapFree(GetProcessHeap(), 0, (LPVOID)hdwp);
01532     return res;
01533 }
01534 //******************************************************************************
01535 //******************************************************************************
01536 HWND WIN32API ChildWindowFromPoint( HWND hwnd, POINT pt)
01537 {
01538     dprintf(("USER32:  ChildWindowFromPoint\n"));
01539     return ChildWindowFromPointEx(hwnd, pt, 0);
01540 }
01541 /*****************************************************************************
01542  * Name      : HWND WIN32API ChildWindowFromPointEx
01543  * Purpose   : pt: client coordinates
01544  * Parameters:
01545  * Variables :
01546  * Result    : If the function succeeds, the return value is the window handle.
01547  *             If the function fails, the return value is zero
01548  * Remark    :
01549  * Status    : COMPLETELY IMPLEMENTED AND TESTED
01550  *
01551  * Author    : Rene Pronk [Sun, 1999/08/08 23:30]
01552  *****************************************************************************/
01553 HWND WIN32API ChildWindowFromPointEx (HWND hwndParent, POINT pt, UINT uFlags)
01554 {
01555   RECT rect;
01556   HWND hWnd;
01557 
01558         dprintf(("ChildWindowFromPointEx(%08xh,%08xh,%08xh).\n",
01559                  hwndParent, pt, uFlags));
01560 
01561         if (GetWindowRect (hwndParent, &rect) == 0) {
01562                 // oops, invalid handle
01563                 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
01564                 return NULL;
01565         }
01566 
01567         ClientToScreen(hwndParent, &pt);
01568         if (PtInRect (&rect, pt) == 0) {
01569                 // point is outside window
01570                 return NULL;
01571         }
01572 
01573         // get first child
01574         hWnd = GetWindow (hwndParent, GW_CHILD);
01575 
01576         while (hWnd != NULL)
01577         {
01578                 // do I need to skip this window?
01579                 if (((uFlags & CWP_SKIPINVISIBLE) &&
01580                      (IsWindowVisible (hWnd) == FALSE)) ||
01581                     ((uFlags & CWP_SKIPDISABLED) &&
01582                      (IsWindowEnabled (hWnd) == FALSE)) ||
01583                     ((uFlags & CWP_SKIPTRANSPARENT) &&
01584                      (GetWindowLongA (hWnd, GWL_EXSTYLE) & WS_EX_TRANSPARENT)))
01585                 {
01586                         hWnd = GetWindow (hWnd, GW_HWNDNEXT);
01587                         continue;
01588                 }
01589 
01590                 // is the point in this window's rect?
01591                 GetWindowRect (hWnd, &rect);
01592                 if (PtInRect (&rect,pt) == FALSE) {
01593                         hWnd = GetWindow (hWnd, GW_HWNDNEXT);
01594                         continue;
01595                 }
01596 
01597                 dprintf(("ChildWindowFromPointEx returned %x", hWnd));
01598                 // found it!
01599                 return hWnd;
01600         }
01601         // the point is in the parentwindow but the parentwindow has no child
01602         // at this coordinate
01603         dprintf(("ChildWindowFromPointEx returned parent %x", hwndParent));
01604         return hwndParent;
01605 }
01606 //******************************************************************************
01607 //******************************************************************************
01608 BOOL WIN32API CloseWindow(HWND hwnd)
01609 {
01610    Win32BaseWindow *window;
01611 
01612     window = Win32BaseWindow::GetWindowFromHandle(hwnd);
01613     if(!window) {
01614         dprintf(("CloseWindow, window %x not found", hwnd));
01615         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
01616         return 0;
01617     }
01618     dprintf(("CloseWindow %x\n", hwnd));
01619     BOOL ret = window->CloseWindow();
01620     RELEASE_WNDOBJ(window);
01621     return ret;
01622 }
01623 //******************************************************************************
01624 //******************************************************************************
01625 static BOOL IsPointInWindow(HWND hwnd, POINT point)
01626 {
01627     RECT  rectWindow;
01628     DWORD hittest, dwStyle, dwExStyle;
01629 
01630     dwStyle   = GetWindowLongA(hwnd, GWL_STYLE);
01631     dwExStyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
01632 
01633     GetWindowRect(hwnd, &rectWindow);
01634 
01635     /* If point is in window, and window is visible, and it  */
01636     /* is enabled (or it's a top-level window), then explore */
01637     /* its children. Otherwise, go to the next window.       */
01638 
01639     if( (dwStyle & WS_VISIBLE) &&
01640         ((dwExStyle & (WS_EX_LAYERED | WS_EX_TRANSPARENT)) != (WS_EX_LAYERED | WS_EX_TRANSPARENT)) &&
01641         (!(dwStyle & WS_DISABLED) || ((dwStyle & (WS_POPUP | WS_CHILD)) != WS_CHILD)) &&
01642         ((point.x >= rectWindow.left) && (point.x <  rectWindow.right) &&
01643          (point.y >= rectWindow.top) && (point.y <  rectWindow.bottom))
01644 #if 1
01645         )
01646 #else
01647         &&
01648         (wndPtr->hrgnWnd ?  PtInRegion(wndPtr->hrgnWnd, 1))
01649 #endif
01650     {
01651         hittest = SendMessageA(hwnd, WM_NCHITTEST, 0, MAKELONG(point.x, point.y));
01652         if(hittest != HTTRANSPARENT) {
01653             return TRUE;
01654         }
01655     }
01656     return FALSE;
01657 }
01658 //******************************************************************************
01659 //TODO: Does this return handles of hidden or disabled windows?
01660 //******************************************************************************
01661 HWND WIN32API WindowFromPoint( POINT point)
01662 {
01663     HWND  hwndOS2, hwnd;
01664     POINT wPoint;
01665 
01666     wPoint.x = point.x;
01667     wPoint.y = mapScreenY(point.y);
01668 
01669     hwndOS2 = OSLibWinWindowFromPoint(OSLIB_HWND_DESKTOP, (PVOID)&wPoint);
01670     if(hwndOS2)
01671     {
01672         hwnd = OS2ToWin32Handle(hwndOS2);
01673         while(hwnd)
01674         {
01675                 if(IsPointInWindow(hwnd, point)) {
01676                     dprintf(("WindowFromPoint (%d,%d) %x->%x\n", point.x, point.y, hwndOS2, hwnd));
01677                     return hwnd;
01678                 }
01679                 //try siblings
01680                 HWND hwndSibling;
01681                 HWND hwndParent = GetParent(hwnd);
01682 
01683                 if(hwndParent) {
01684                     hwndSibling = GetWindow(hwndParent, GW_CHILD);
01685                     while(hwndSibling) {
01686                         if(hwndSibling != hwnd) {
01687                             if(IsPointInWindow(hwndSibling, point)) {
01688                                 dprintf(("WindowFromPoint (%d,%d) %x->%x\n", point.x, point.y, hwndOS2, hwndSibling));
01689                                 return hwndSibling;
01690                             }
01691                         }
01692                         hwndSibling = GetWindow(hwndSibling, GW_HWNDNEXT);
01693                     }
01694                 }
01695                 hwnd = hwndParent;
01696         }
01697     }
01698     dprintf(("WindowFromPoint (%d,%d) %x->1\n", point.x, point.y, hwndOS2));
01699     return windowDesktop->getWindowHandle();
01700 }
01701 //******************************************************************************
01702 //******************************************************************************
01703 BOOL WIN32API IsWindowUnicode(HWND hwnd)
01704 {
01705    Win32BaseWindow *window;
01706 
01707     window = Win32BaseWindow::GetWindowFromHandle(hwnd);
01708     if(!window) {
01709         dprintf(("IsWindowUnicode, window %x not found", hwnd));
01710         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
01711         return 0;
01712     }
01713     BOOL ret = window->IsWindowUnicode();
01714     RELEASE_WNDOBJ(window);
01715     return ret;
01716 }
01717 /***********************************************************************
01718  *             SwitchToThisWindow   (USER32.539)
01719  */
01720 DWORD WINAPI SwitchToThisWindow( HWND hwnd, BOOL restore )
01721 {
01722     return ShowWindow( hwnd, restore ? SW_RESTORE : SW_SHOWMINIMIZED );
01723 }
01724 //******************************************************************************
01725 //******************************************************************************
01726 BOOL WIN32API EnumThreadWindows(DWORD dwThreadId, WNDENUMPROC lpfn, LPARAM lParam)
01727 {
01728     return windowDesktop->EnumThreadWindows(dwThreadId, lpfn, lParam);
01729 }
01730 //******************************************************************************
01731 //******************************************************************************
01732 BOOL WIN32API EnumChildWindows(HWND hwnd, WNDENUMPROC lpfn, LPARAM lParam)
01733 {
01734     Win32BaseWindow *window;
01735     BOOL   ret = TRUE;
01736     ULONG  henum;
01737     HWND   hwndNext;
01738 
01739     if(lpfn == NULL) {
01740         dprintf(("EnumChildWindows invalid parameter %x %x\n", hwnd, lParam));
01741         SetLastError(ERROR_INVALID_PARAMETER);
01742         return FALSE;
01743     }
01744     window = Win32BaseWindow::GetWindowFromHandle(hwnd);
01745     if(!window) {
01746         dprintf(("EnumChildWindows, window %x not found", hwnd));
01747         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
01748         return FALSE;
01749     }
01750     ret = window->EnumChildWindows(lpfn, lParam);
01751     RELEASE_WNDOBJ(window);
01752     return ret;
01753 }
01754 //******************************************************************************
01755 //******************************************************************************
01756 BOOL WIN32API EnumWindows(WNDENUMPROC lpfn, LPARAM lParam)
01757 {
01758     return windowDesktop->EnumWindows(lpfn, lParam);
01759 }
01760 //******************************************************************************
01761 //******************************************************************************
01762 UINT WIN32API ArrangeIconicWindows( HWND parent)
01763 {
01764     RECT rectParent;
01765     HWND hwndChild;
01766     INT x, y, xspacing, yspacing;
01767 
01768     dprintf(("USER32: ArrangeIconicWindows %x", parent));
01769     dprintf(("USER32: TODO: icon title!!"));
01770 
01771     GetClientRect(parent, &rectParent);
01772     x = rectParent.left;
01773     y = rectParent.bottom;
01774     xspacing = GetSystemMetrics(SM_CXICONSPACING);
01775     yspacing = GetSystemMetrics(SM_CYICONSPACING);
01776 
01777     hwndChild = GetWindow( parent, GW_CHILD );
01778     while (hwndChild)
01779     {
01780         if( IsIconic( hwndChild ) )
01781         {
01782 //            WND *wndPtr = WIN_FindWndPtr(hwndChild);
01783             
01784 //            WINPOS_ShowIconTitle( wndPtr, FALSE );
01785                
01786             SetWindowPos( hwndChild, 0, x + (xspacing - GetSystemMetrics(SM_CXICON)) / 2,
01787                             y - yspacing - GetSystemMetrics(SM_CYICON)/2, 0, 0,
01788                             SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
01789 //          if( IsWindow(hwndChild) )
01790 //                WINPOS_ShowIconTitle(wndPtr , TRUE );
01791 //            WIN_ReleaseWndPtr(wndPtr);
01792 
01793             if (x <= rectParent.right - xspacing) x += xspacing;
01794             else
01795             {
01796                 x = rectParent.left;
01797                 y -= yspacing;
01798             }
01799         }
01800         hwndChild = GetWindow( hwndChild, GW_HWNDNEXT );
01801     }
01802     return yspacing;
01803 }
01804 //******************************************************************************
01805 //restores iconized window to previous size/position
01806 //******************************************************************************
01807 BOOL WIN32API OpenIcon(HWND hwnd)
01808 {
01809     dprintf(("USER32: OpenIcon %x", hwnd));
01810 
01811     if(!IsIconic(hwnd))
01812         return FALSE;
01813     ShowWindow(hwnd, SW_SHOWNORMAL);
01814     return TRUE;
01815 }
01816 //******************************************************************************
01817 //SDK: Windows can only be shown with ShowOwnedPopups if they were previously
01818 //     hidden with the same api
01819 //TODO: -> needs testing
01820 //******************************************************************************
01821 ODINFUNCTION2(BOOL, ShowOwnedPopups,
01822               HWND, hwndOwner,
01823               BOOL, fShow)
01824 {
01825     Win32BaseWindow *window, *owner;
01826     HWND hwnd;
01827 
01828     owner = Win32BaseWindow::GetWindowFromHandle(hwndOwner);
01829     if(!owner) {
01830         dprintf(("ShowOwnedPopups, window %x not found", hwndOwner));
01831         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
01832         return FALSE;
01833     }
01834     dprintf(("USER32: ShowOwnedPopups %x %d", hwndOwner, fShow));
01835 
01836     hwnd = GetWindow(GetDesktopWindow(), GW_CHILD);
01837     while(hwnd) {
01838         window = Win32BaseWindow::GetWindowFromHandle(hwnd);
01839         if(window) {
01840             if(window == owner && (window->getStyle() & WS_POPUP))
01841             {
01842                 if(fShow) {
01843                     if(window->getFlags() & WIN_NEEDS_SHOW_OWNEDPOPUP)
01844                     {
01845                         /*
01846                         * In Windows, ShowOwnedPopups(TRUE) generates WM_SHOWWINDOW messages with SW_PARENTOPENING,
01847                         * regardless of the state of the owner
01848                         */
01849                         SendMessageA(hwnd, WM_SHOWWINDOW, SW_SHOW, SW_PARENTOPENING);
01850                         window->setFlags(window->getFlags() & ~WIN_NEEDS_SHOW_OWNEDPOPUP);
01851                     }
01852                 }
01853                 else
01854                 {
01855                     if(IsWindowVisible(hwnd))
01856                     {
01857                         /*
01858                          * In Windows, ShowOwnedPopups(FALSE) generates WM_SHOWWINDOW messages with SW_PARENTCLOSING,
01859                          * regardless of the state of the owner
01860                          */
01861                         SendMessageA(hwnd, WM_SHOWWINDOW, SW_HIDE, SW_PARENTCLOSING);
01862                         window->setFlags(window->getFlags() | WIN_NEEDS_SHOW_OWNEDPOPUP);
01863                     }
01864                 }
01865             }
01866             RELEASE_WNDOBJ(window);
01867         }
01868         else dprintf(("WARNING: window %x is not valid", hwnd));
01869 
01870         hwnd = GetWindow(hwnd, GW_HWNDNEXT);
01871     }
01872     RELEASE_WNDOBJ(owner);
01873     return TRUE;
01874 }
01875 //******************************************************************************
01876 //******************************************************************************
01877 ODINFUNCTION0(HWND, GetForegroundWindow)
01878 {
01879   HWND hwnd;
01880 
01881   hwnd = OS2ToWin32Handle(OSLibWinQueryActiveWindow());
01882   return hwnd;
01883 }
01884 //******************************************************************************
01885 
01886 /******************************************************************************
01887  * The return value identifies the most recently active pop-up window.
01888  * The return value is the same as the hWnd parameter, if any of the
01889  * following conditions are met:
01890  *
01891  * - The window identified by hWnd was most recently active.
01892  * - The window identified by hWnd does not own any pop-up windows.
01893  * - The window identified by hWnd is not a top-level window or it is
01894  *   owned by another window.
01895  */
01896 ODINFUNCTION1(HWND, GetLastActivePopup,
01897               HWND, hWnd)
01898 {
01899   Win32BaseWindow *owner;
01900 
01901   owner = Win32BaseWindow::GetWindowFromHandle(hWnd);
01902   if(!owner) 
01903   {
01904     dprintf(("GetLastActivePopup, window %x not found", hWnd));
01905     SetLastError(ERROR_INVALID_WINDOW_HANDLE);
01906     return hWnd;
01907   }
01908 
01909   HWND hwndRetVal = owner->getLastActive();
01910   if (!IsWindow( hwndRetVal ))
01911     hwndRetVal = owner->getWindowHandle();
01912   
01913   RELEASE_WNDOBJ(owner);
01914   
01915   return hwndRetVal;
01916 }
01917 //******************************************************************************
01918 //******************************************************************************
01919 ODINFUNCTION2(DWORD,   GetWindowThreadProcessId,
01920               HWND,    hWnd,
01921               PDWORD,  lpdwProcessId)
01922 {
01923   hWnd = Win32ToOS2Handle(hWnd);
01924   return O32_GetWindowThreadProcessId(hWnd,lpdwProcessId);
01925 }
01926 //******************************************************************************
01927 //******************************************************************************
01928 ODINFUNCTION1(DWORD, GetWindowContextHelpId,
01929               HWND,  hwnd)
01930 {
01931   Win32BaseWindow *window;
01932 
01933     window = Win32BaseWindow::GetWindowFromHandle(hwnd);
01934     if(!window) {
01935         dprintf(("GetWindowContextHelpId, window %x not found", hwnd));
01936         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
01937         return 0;
01938     }
01939     dprintf(("GetWindowContextHelpId %x", hwnd));
01940     DWORD ret = window->getWindowContextHelpId();
01941     RELEASE_WNDOBJ(window);
01942     return ret;
01943 }
01944 //******************************************************************************
01945 //******************************************************************************
01946 ODINFUNCTION2(BOOL,  SetWindowContextHelpId,
01947               HWND,  hwnd,
01948               DWORD, dwContextHelpId)
01949 {
01950   Win32BaseWindow *window;
01951 
01952     window = Win32BaseWindow::GetWindowFromHandle(hwnd);
01953     if(!window) {
01954         dprintf(("SetWindowContextHelpId, window %x not found", hwnd));
01955         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
01956         return 0;
01957     }
01958     dprintf(("SetWindowContextHelpId %x %d", hwnd, dwContextHelpId));
01959     window->setWindowContextHelpId(dwContextHelpId);
01960     RELEASE_WNDOBJ(window);
01961     return(TRUE);
01962 }
01963 //******************************************************************************
01964 //******************************************************************************
01965 ODINFUNCTION2(HANDLE, GetPropA,
01966               HWND,   hwnd,
01967               LPCSTR, str )
01968 {
01969   Win32BaseWindow *window;
01970 
01971     window = Win32BaseWindow::GetWindowFromHandle(hwnd);
01972     if(!window) {
01973         dprintf(("GetPropA, window %x not found", hwnd));
01974         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
01975         return 0;
01976     }
01977     HANDLE ret = window->getProp(str);
01978     RELEASE_WNDOBJ(window);
01979     return ret;
01980 }
01981 //******************************************************************************
01982 //******************************************************************************
01983 ODINFUNCTION2(HANDLE,  GetPropW,
01984               HWND,    hwnd,
01985               LPCWSTR, str )
01986 {
01987   Win32BaseWindow *window;
01988   LPSTR strA;
01989   HANDLE ret;
01990 
01991     window = Win32BaseWindow::GetWindowFromHandle(hwnd);
01992     if(!window) {
01993         dprintf(("GetPropW, window %x not found", hwnd));
01994         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
01995         return 0;
01996     }
01997 
01998     if(HIWORD(str)) {
01999          strA = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
02000     }
02001     else strA = (LPSTR)str;
02002 
02003     ret = window->getProp(strA);
02004 
02005     RELEASE_WNDOBJ(window);
02006     if(HIWORD(str)) HeapFree( GetProcessHeap(), 0, strA );
02007     return ret;
02008 }
02009 //******************************************************************************
02010 //******************************************************************************
02011 ODINFUNCTION3(BOOL,   SetPropA,
02012               HWND,   hwnd,
02013               LPCSTR, str,
02014               HANDLE, handle )
02015 {
02016   Win32BaseWindow *window;
02017 
02018     window = Win32BaseWindow::GetWindowFromHandle(hwnd);
02019     if(!window) {
02020         dprintf(("SetPropA, window %x not found", hwnd));
02021         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
02022         return FALSE;
02023     }
02024     BOOL ret = window->setProp(str, handle);
02025     RELEASE_WNDOBJ(window);
02026     return ret;
02027 }
02028 //******************************************************************************
02029 //******************************************************************************
02030 ODINFUNCTION3(BOOL,    SetPropW,
02031               HWND,    hwnd,
02032               LPCWSTR, str,
02033               HANDLE,  handle )
02034 {
02035     BOOL ret;
02036     LPSTR strA;
02037 
02038     if (!HIWORD(str))
02039         return SetPropA( hwnd, (LPCSTR)(UINT)LOWORD(str), handle );
02040     strA = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
02041     ret = SetPropA( hwnd, strA, handle );
02042     HeapFree( GetProcessHeap(), 0, strA );
02043     return ret;
02044 }
02045 //******************************************************************************
02046 //******************************************************************************
02047 ODINFUNCTION2(HANDLE, RemovePropA,
02048               HWND,   hwnd,
02049               LPCSTR, str )
02050 {
02051   Win32BaseWindow *window;
02052 
02053     window = Win32BaseWindow::GetWindowFromHandle(hwnd);
02054     if(!window) {
02055         dprintf(("RemovePropA, window %x not found", hwnd));
02056         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
02057         return 0;
02058     }
02059     HANDLE ret = window->removeProp(str);
02060     RELEASE_WNDOBJ(window);
02061     return ret;
02062 }
02063 //******************************************************************************
02064 //******************************************************************************
02065 ODINFUNCTION2(HANDLE,  RemovePropW,
02066               HWND,    hwnd,
02067               LPCWSTR, str )
02068 {
02069     LPSTR strA;
02070     HANDLE ret;
02071 
02072     if (!HIWORD(str))
02073         return RemovePropA( hwnd, (LPCSTR)(UINT)LOWORD(str) );
02074     strA = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
02075     ret = RemovePropA( hwnd, strA );
02076     HeapFree( GetProcessHeap(), 0, strA );
02077     return ret;
02078 }
02079 //******************************************************************************
02080 //******************************************************************************
02081 ODINFUNCTION2(INT, EnumPropsA,
02082               HWND, hwnd,
02083               PROPENUMPROCA, func )
02084 {
02085     return EnumPropsExA( hwnd, (PROPENUMPROCEXA)func, 0 );
02086 }
02087 //******************************************************************************
02088 //******************************************************************************
02089 ODINFUNCTION2(INT, EnumPropsW,
02090               HWND, hwnd,
02091               PROPENUMPROCW, func )
02092 {
02093     return EnumPropsExW( hwnd, (PROPENUMPROCEXW)func, 0 );
02094 }
02095 //******************************************************************************
02096 //******************************************************************************
02097 ODINFUNCTION3(INT, EnumPropsExA,
02098               HWND, hwnd,
02099               PROPENUMPROCEXA, func,
02100               LPARAM, lParam)
02101 {
02102   Win32BaseWindow *window;
02103 
02104     window = Win32BaseWindow::GetWindowFromHandle(hwnd);
02105     if(!window) {
02106         dprintf(("EnumPropsExA, window %x not found", hwnd));
02107         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
02108         return -1;
02109     }
02110     INT ret = window->enumPropsExA(func, lParam);
02111     RELEASE_WNDOBJ(window);
02112     return ret;
02113 }
02114 //******************************************************************************
02115 //******************************************************************************
02116 ODINFUNCTION3(INT, EnumPropsExW,
02117               HWND, hwnd,
02118               PROPENUMPROCEXW, func,
02119               LPARAM, lParam)
02120 {
02121   Win32BaseWindow *window;
02122 
02123     window = Win32BaseWindow::GetWindowFromHandle(hwnd);
02124     if(!window) {
02125         dprintf(("EnumPropsExA, window %x not found", hwnd));
02126         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
02127         return -1;
02128     }
02129     INT ret = window->enumPropsExW(func, lParam);
02130     RELEASE_WNDOBJ(window);
02131     return ret;
02132 }
02133 //******************************************************************************
02134 //******************************************************************************
02135 
02136 
02137 /*****************************************************************************
02138  * Name      : BOOL WIN32API AnyPopup
02139  * Purpose   : The AnyPopup function indicates whether an owned, visible,
02140  *             top-level pop-up, or overlapped window exists on the screen. The
02141  *             function searches the entire Windows screen, not just the calling
02142  *             application's client area.
02143  * Parameters: VOID
02144  * Variables :
02145  * Result    : If a pop-up window exists, the return value is TRUE even if the
02146  *             pop-up window is completely covered by other windows. Otherwise,
02147  *             it is FALSE.
02148  * Remark    : AnyPopup is a Windows version 1.x function and is retained for
02149  *             compatibility purposes. It is generally not useful.
02150  * Status    : UNTESTED STUB
02151  *
02152  * Author    : Patrick Haller [Thu, 1998/02/26 11:55]
02153  *****************************************************************************/
02154 ODINFUNCTION0(BOOL, AnyPopup)
02155 {
02156   dprintf(("USER32:AnyPopup() not implemented.\n"));
02157 
02158   return (FALSE);
02159 }

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