Ignore:
Timestamp:
Apr 23, 2003, 8:01:01 PM (23 years ago)
Author:
sandervl
Message:

KSO: Properties allocated from shared memory & Fake window updates & SW_SHOWDEFAULT update

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/user32/win32wfake.cpp

    r9941 r10031  
    1 /* $Id: win32wfake.cpp,v 1.2 2003-03-27 10:42:42 sandervl Exp $ */
     1/* $Id: win32wfake.cpp,v 1.3 2003-04-23 18:01:01 sandervl Exp $ */
    22/*
    33 * Win32 Fake Window Class for OS/2
     
    2424#include "dbglocal.h"
    2525
    26 //******************************************************************************
    27 //******************************************************************************
     26/** The Odin HWND Property - must be unique for this (custom)build. */
     27char Win32FakeWindow::szPropOdinHandle[64] = "OdinFakeHWND";
     28/** Flag which tells if we've inited or not. */
     29BOOL Win32FakeWindow::fInited = FALSE;
     30
     31/**
     32 * Creates a fake Odin window for an existing OS/2 window.
     33 *
     34 * @returns odin handle to the fake window.
     35 * @returns NULL on failure.
     36 * @param   hwndOS2     Window handle.
     37 * @param   classAtom   The atom of the Odin window class.
     38 * @author  Sander van Leeuwen <sandervl@innotek.de>
     39 * @author  knut st. osmundsen <bird@anduin.net>
     40 */
    2841HWND WIN32API CreateFakeWindowEx(HWND  hwndOS2, ATOM  classAtom)
    2942{
    3043    Win32FakeWindow *window;
    3144
     45    /*
     46     * Check if already faked - fail.
     47     */
     48    window = Win32FakeWindow::GetWindowFromOS2Handle(hwndOS2);
     49    if (window)
     50    {
     51        dprintf(("CreateFakeWindowEx: already faked!!! (hwndOS2=%x hwndOdin=%x)",
     52                 hwndOS2, window->getOS2WindowHandle()));
     53        return NULL;
     54    }
     55
     56    /*
     57     * Now proceed.
     58     */
    3259    window = new Win32FakeWindow(hwndOS2, classAtom);
    33     if(window == NULL)
    34     {
    35         dprintf(("Win32FakeWindow creation failed!!"));
     60    if (window == NULL)
     61    {
     62        dprintf(("Win32FakeWindow creation failed for %x!!!", hwndOS2));
    3663        return 0;
    3764    }
    3865    HWND hwnd = window->getWindowHandle();
    39  
     66
    4067    // set myself as last active popup / window
    4168    window->setLastActive( hwnd );
    42  
     69
    4370    RELEASE_WNDOBJ(window);
     71    dprintf(("CreateFakeWindowEx: created %x for %x", hwnd, hwndOS2));
    4472    return hwnd;
    4573}
     
    5179
    5280    window = Win32BaseWindow::GetWindowFromHandle(hwnd);
    53     if(!window) {
     81    if (!window) {
    5482        dprintf(("DestroyFakeWindow, window %x not found", hwnd));
    5583        SetLastError(ERROR_INVALID_WINDOW_HANDLE);
     
    6492                     : Win32BaseWindow()
    6593{
     94    if (!fInited)  init();
     95
    6696    OS2Hwnd = OS2HwndFrame = hwndOS2;
    6797
     
    93123    OSLibQueryWindowRectAbsolute (OS2Hwnd, &rectWindow);
    94124
     125    //Store the window handle as a property of the OS/2 window.
     126    if (!OSLibSetProperty(OS2Hwnd, szPropOdinHandle, (void*)getWindowHandle(), 0))
     127    {
     128        dprintf(("%s: f**k! WinSetProperty(%x,%s,%x,0) failed!!!", __FUNCTION__,
     129                 hwndOS2, szPropOdinHandle, getWindowHandle()));
     130    }
     131
     132    //See if parent window is either odin or fake window.
     133    Win32BaseWindow * pParent = NULL;
     134    HWND hwndParentOS2 = OSLibWinQueryWindow(OS2Hwnd, QWOS_PARENT);
     135    if (hwndParentOS2 != OSLIB_HWND_DESKTOP)
     136    {
     137        pParent = Win32FakeWindow::GetWindowFromOS2Handle(hwndParentOS2);
     138        if (!pParent)
     139            pParent = Win32BaseWindow::GetWindowFromOS2Handle(hwndParentOS2);
     140        if (pParent)
     141        {
     142            setParent(pParent);
     143            dprintf(("%s: hwndParentOS2=%x %s window, set as parent.", __FUNCTION__,
     144                     hwndParentOS2, pParent->isFakeWindow() ? "fake" : "odin"));
     145            dwStyle |= WS_CHILD;
     146        }
     147        else
     148        {
     149            dprintf(("%s: hwndParentOS2=%x but not a fake nor odin window.", __FUNCTION__, hwndParentOS2));
     150        }
     151    }
     152
     153    //See if owner widnow is either odin or fake window.
     154    HWND hwndOwnerOS2 = OSLibWinQueryWindow(OS2Hwnd, QWOS_OWNER);
     155    if (hwndOwnerOS2 != OSLIB_HWND_DESKTOP)
     156    {
     157        Win32BaseWindow * pOwner;
     158        if (hwndOwnerOS2 == hwndParentOS2)
     159            pOwner = pParent;
     160        else
     161        {
     162            pOwner = Win32FakeWindow::GetWindowFromOS2Handle(hwndOwnerOS2);
     163            if (!pOwner)
     164                pOwner = Win32BaseWindow::GetWindowFromOS2Handle(hwndOwnerOS2);
     165        }
     166        if (pOwner)
     167        {
     168            setOwner(pOwner);
     169            dprintf(("%s: hwndOwnerOS2=%x %s window, set as owner.", __FUNCTION__,
     170                     hwndOwnerOS2, pOwner->isFakeWindow() ? "fake" : "odin"));
     171            dwStyle |= WS_CHILD;
     172        }
     173        else
     174        {
     175            dprintf(("%s: hwndOwnerOS2=%x but not a fake nor odin window.", __FUNCTION__, hwndOwnerOS2));
     176        }
     177    }
     178
     179
    95180    setOldPMWindowProc(PMWinSubclassFakeWindow(OS2Hwnd));
    96181}
     
    99184Win32FakeWindow::~Win32FakeWindow()
    100185{
    101 
     186    OSLibRemoveProperty(OS2Hwnd, szPropOdinHandle);
    102187}
    103188//******************************************************************************
    104189//******************************************************************************
    105190PRECT Win32FakeWindow::getWindowRect()
    106 { 
     191{
    107192    //the coordinates can change without us being notified, so recheck every time
    108     OSLibQueryWindowRectAbsolute (OS2Hwnd, &rectWindow);
    109     return &rectWindow;
    110 }
    111 //******************************************************************************
    112 //******************************************************************************
    113 BOOL Win32FakeWindow::SetWindowPos(HWND hwndInsertAfter, int x, int y, int cx,
     193
     194    Win32BaseWindow * pParent = getParent();
     195    if (pParent)
     196    {
     197        SWP     swp;
     198        if (OSLibWinQueryWindowPos(OS2Hwnd, &swp))
     199        {
     200            ULONG y = pParent->getWindowHeight();
     201            rectWindow.left   = swp.x;
     202            rectWindow.right  = swp.x + swp.cx;
     203            rectWindow.top    = y - swp.y - swp.cy;
     204            rectWindow.bottom = y - swp.y;
     205        }
     206    }
     207    else
     208        OSLibQueryWindowRectAbsolute(OS2Hwnd, &rectWindow);
     209
     210    return &rectWindow;
     211}
     212//******************************************************************************
     213//******************************************************************************
     214BOOL Win32FakeWindow::SetWindowPos(HWND hwndInsertAfter, int x, int y, int cx,
    114215                                   int cy, UINT fuFlags, BOOL fShowWindow)
    115216{
     217    // we don't trust input either.
    116218    dprintf(("Win32FakeWindow::SetWindowPos; don't change window position, just update internal position"));
    117219
    118     //We pretend this window has no parent and its position is in screen coordinates
    119220    OSLibWinQueryWindowClientRect(OS2Hwnd, &rectClient);
    120     OSLibQueryWindowRectAbsolute (OS2Hwnd, &rectWindow);
    121 
     221    getWindowRect();
    122222    return TRUE;
    123223}
     
    130230//******************************************************************************
    131231//******************************************************************************
     232
     233/**
     234 * Locates window in linked list and increases reference count if found.
     235 * The window object msut be unreferenced after usage.
     236 *
     237 * @returns Pointer to fake window.
     238 * @returns NULL if not found.
     239 * @param   hwndOS2     OS/2 window handle of the fake window.
     240 */
     241Win32FakeWindow *Win32FakeWindow::GetWindowFromOS2Handle(HWND hwndOS2)
     242{
     243    if (fInited)    init();
     244
     245    HWND hwnd = (HWND)OSLibQueryProperty(hwndOS2, szPropOdinHandle);
     246    Win32BaseWindow *pWindow = GetWindowFromHandle(hwnd);
     247    if (pWindow)
     248    {
     249        if (pWindow->isFakeWindow())
     250            return (Win32FakeWindow*)pWindow;
     251        DebugInt3();
     252    }
     253    dprintf(("Win32FakeWindow::GetWindowFromOS2Handle(%x) -> null", hwndOS2));
     254    return NULL;
     255}
     256
     257
     258/**
     259 * Init the global(s).
     260 * It will make the name property unique among the odin instances.
     261 *
     262 * This will chagne szPropOdinHandle and fInited.
     263 */
     264void     Win32FakeWindow::init()
     265{
     266    if (fInited)
     267        return;
     268
     269    /*
     270     * Get the name of this dll.
     271     */
     272    extern int _System DosQueryModFromEIP(HMODULE *phMod, ULONG *pObjNum, ULONG BuffLen, PCHAR pBuff, ULONG *pOffset, ULONG Address);
     273    char        szModName[260];
     274    HMODULE     hmod;
     275    ULONG       iObj, offObj;
     276    USHORT      GetFS();
     277    int rc = DosQueryModFromEIP(&hmod, &iObj, sizeof(szModName), &szModName[0], &offObj, (ULONG)Win32FakeWindow::init);
     278    SetFS(rc);
     279    if (rc)
     280    {
     281        dprintf(("Win32FakeWindow::init: DosQueryModFromEIP failed!!!"));
     282        DebugInt3();
     283        return;
     284    }
     285    char *psz = strrchr(szModName, '\\');
     286    if (!psz)
     287        psz = szModName;
     288    if (strchr(szModName, '.'))
     289        *strchr(szModName, '.') = '\0';
     290
     291    fInited = 1;
     292    strcat(szPropOdinHandle, psz);
     293    dprintf(("Win32FakeWindow::init: szPropOdinHandle='%s'", szPropOdinHandle));
     294}
     295
Note: See TracChangeset for help on using the changeset viewer.