Ignore:
Timestamp:
Aug 28, 1999, 4:09:58 PM (26 years ago)
Author:
sandervl
Message:

Use shared memory for class & window objects

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/user32/new/win32wnd.cpp

    r715 r724  
    1 /* $Id: win32wnd.cpp,v 1.31 1999-08-27 17:50:56 dengert Exp $ */
     1/* $Id: win32wnd.cpp,v 1.32 1999-08-28 14:09:30 sandervl Exp $ */
    22/*
    33 * Win32 Window Code for OS/2
     
    1111 * Copyright 1993, 1994 Alexandre Julliard
    1212 *
     13 * TODO: Not thread/process safe
    1314 *
    1415 * Project Odin Software License can be found in LICENSE.TXT
     
    2324#include <misc.h>
    2425#include <handlemanager.h>
     26#include <heapstring.h>
    2527#include <win32wnd.h>
    2628#include <spy.h>
     
    7173  fFirstShow       = TRUE;
    7274
    73   memset(windowNameA, 0, MAX_WINDOW_NAMELENGTH);
    74   memset(windowNameW, 0, MAX_WINDOW_NAMELENGTH*sizeof(WCHAR));
     75  windowNameA      = NULL;
     76  windowNameW      = NULL;
    7577  wndNameLength    = 0;
    7678
     
    125127  if(userWindowLong)
    126128        free(userWindowLong);
     129  if(windowNameA) {
     130        free(windowNameA);
     131        windowNameA = NULL;
     132  }
     133  if(windowNameW) {
     134        free(windowNameW);
     135        windowNameW = NULL;
     136  }
    127137}
    128138//******************************************************************************
     
    249259  nrUserWindowLong = windowClass->getExtraWndWords();
    250260  if(nrUserWindowLong) {
    251         userWindowLong = (ULONG *)malloc(nrUserWindowLong);
     261        userWindowLong = (ULONG *)_smalloc(nrUserWindowLong);
    252262        memset(userWindowLong, 0, nrUserWindowLong);
    253263  }
     
    371381#endif
    372382
     383  if(cs->lpszName)
     384        SetWindowText((LPSTR)cs->lpszName);
     385
    373386  OS2Hwnd = OSLibWinCreateWindow((getParent()) ? getParent()->getOS2WindowHandle() : OSLIB_HWND_DESKTOP,
    374                                  dwOSWinStyle, dwOSFrameStyle, (char *)cs->lpszName,
     387                                 dwOSWinStyle, dwOSFrameStyle, (char *)windowNameA,
    375388                                 (owner) ? owner->getOS2WindowHandle() : OSLIB_HWND_DESKTOP,
    376389                                 (hwndLinkAfter == HWND_BOTTOM) ? TRUE : FALSE,
     
    985998{
    986999    if(isUnicode) {
    987         SendInternalMessageW(WM_GETTEXT, MAX_WINDOW_NAMELENGTH, (LPARAM)windowNameW);
     1000        SendInternalMessageW(WM_GETTEXT, wndNameLength, (LPARAM)windowNameW);
    9881001    }
    9891002    else {
    990         SendInternalMessageA(WM_GETTEXT, MAX_WINDOW_NAMELENGTH, (LPARAM)windowNameA);
     1003        SendInternalMessageA(WM_GETTEXT, wndNameLength, (LPARAM)windowNameA);
    9911004    }
    9921005    return windowNameA;
     
    16561669}
    16571670//******************************************************************************
    1658 //TODO: not complete nor correct (distinction between top-level, top-most & child windows)
     1671//TODO:
     1672//We assume (for now) that if hwndParent or hwndChildAfter are real window handles, that
     1673//the current process owns them.
     1674//******************************************************************************
     1675HWND Win32Window::FindWindowEx(HWND hwndParent, HWND hwndChildAfter, LPSTR lpszClass, LPSTR lpszWindow,
     1676                               BOOL fUnicode)
     1677{
     1678 Win32Window *parent = GetWindowFromHandle(hwndParent);
     1679 Win32Window *child  = GetWindowFromHandle(hwndChildAfter);
     1680
     1681    if((hwndParent != OSLIB_HWND_DESKTOP && !parent) ||
     1682       (hwndChildAfter != 0 && !child) ||
     1683       (hwndParent == OSLIB_HWND_DESKTOP && hwndChildAfter != 0))
     1684    {
     1685        dprintf(("Win32Window::FindWindowEx: parent or child not found %x %x", hwndParent, hwndChildAfter));
     1686        SetLastError(ERROR_INVALID_WINDOW_HANDLE);
     1687        return 0;
     1688    }
     1689    if(hwndParent != OSLIB_HWND_DESKTOP)
     1690    {//if the current process owns the window, just do a quick search
     1691        child = (Win32Window *)parent->GetFirstChild();
     1692        if(hwndChildAfter != 0)
     1693        {
     1694            while(child)
     1695            {
     1696                if(child->getWindowHandle() == hwndChildAfter)
     1697                {
     1698                    child = (Win32Window *)child->GetNextChild();
     1699                    break;
     1700                }
     1701                child = (Win32Window *)child->GetNextChild();
     1702            }
     1703        }
     1704        while(child)
     1705        {
     1706            if(child->getWindowClass()->hasClassName(lpszClass, fUnicode) &&
     1707               (!lpszWindow || child->hasWindowName(lpszWindow, fUnicode)))
     1708            {
     1709                dprintf(("FindWindowEx: Found window %x", child->getWindowHandle()));
     1710                return child->getWindowHandle();
     1711            }
     1712            child = (Win32Window *)child->GetNextChild();
     1713        }
     1714    }
     1715    else {
     1716        Win32Window *wnd;
     1717        HWND henum, hwnd;
     1718
     1719        henum = OSLibWinBeginEnumWindows(OSLIB_HWND_DESKTOP);
     1720        hwnd = OSLibWinGetNextWindow(henum);
     1721
     1722        while(hwnd)
     1723        {
     1724            HWND hwndClient;
     1725
     1726            wnd = GetWindowFromOS2Handle(hwnd);
     1727            if(wnd == NULL) {
     1728                hwndClient = OSLibWinQueryClientWindow(hwnd);
     1729                if(hwndClient)  wnd = GetWindowFromOS2Handle(hwndClient);
     1730            }
     1731
     1732            if(wnd && wnd->getWindowClass()->hasClassName(lpszClass, fUnicode) &&
     1733               (!lpszWindow || wnd->hasWindowName(lpszWindow, fUnicode)))
     1734            {
     1735                OSLibWinEndEnumWindows(henum);
     1736                dprintf(("FindWindowEx: Found window %x", wnd->getWindowHandle()));
     1737                return wnd->getWindowHandle();
     1738            }
     1739            hwnd = OSLibWinGetNextWindow(henum);
     1740        }
     1741        OSLibWinEndEnumWindows(henum);
     1742    }
     1743    SetLastError(ERROR_CANNOT_FIND_WND_CLASS); //TODO: not always correct
     1744    return 0;
     1745}
     1746//******************************************************************************
     1747//TODO: not complete nor correct (distinction be    tween top-level, top-most & child windows)
    16591748//******************************************************************************
    16601749HWND Win32Window::GetWindow(UINT uCmd)
     
    17701859//******************************************************************************
    17711860//******************************************************************************
     1861BOOL Win32Window::hasWindowName(LPSTR wndname, BOOL fUnicode)
     1862{
     1863    if(fUnicode) {
     1864            return (lstrcmpW(windowNameW, (LPWSTR)wndname) == 0);
     1865    }
     1866    else    return (strcmp(windowNameA, wndname) == 0);
     1867}
     1868//******************************************************************************
     1869//******************************************************************************
    17721870int Win32Window::GetWindowTextLengthA()
    17731871{
     
    17821880//******************************************************************************
    17831881//******************************************************************************
    1784 BOOL Win32Window::SetWindowTextA(LPCSTR lpsz)
    1785 {
    1786   return OSLibWinSetWindowText(OS2Hwnd, (LPSTR)lpsz);
     1882BOOL Win32Window::SetWindowText(LPSTR lpsz)
     1883{
     1884    if(lpsz == NULL)
     1885        return FALSE;
     1886
     1887    if(isUnicode == FALSE) {
     1888        windowNameA = (LPSTR)_smalloc(strlen(lpsz)+1);
     1889        strcpy(windowNameA, lpsz);
     1890        windowNameW = (LPWSTR)_smalloc((strlen(lpsz)+1)*sizeof(WCHAR));
     1891        lstrcpyAtoW(windowNameW, windowNameA);
     1892    }
     1893    else {
     1894        windowNameW = (LPWSTR)_smalloc((lstrlenW((LPWSTR)lpsz)+1)*sizeof(WCHAR));
     1895        lstrcpyW(windowNameW, (LPWSTR)lpsz);
     1896        windowNameA = (LPSTR)_smalloc(lstrlenW((LPWSTR)lpsz)+1);
     1897        lstrcpyWtoA(windowNameA, windowNameW);
     1898    }
     1899    wndNameLength = strlen(windowNameA)+1; //including 0 terminator
     1900
     1901    if(OS2Hwnd)
     1902        return OSLibWinSetWindowText(OS2Hwnd, (LPSTR)windowNameA);
     1903
     1904    return TRUE;
    17871905}
    17881906//******************************************************************************
     
    18101928                return oldval;
    18111929        case GWL_HWNDPARENT:
    1812         return SetParent((HWND)value);
     1930                return SetParent((HWND)value);
    18131931
    18141932        case GWL_ID:
     
    18952013
    18962014   if(HIWORD(hwnd) != 0x6800) {
    1897     return NULL;
     2015        return NULL;
    18982016   }
    18992017
    19002018   if(HMHandleTranslateToOS2(LOWORD(hwnd), (PULONG)&window) == NO_ERROR) {
    1901     return window;
     2019        return window;
    19022020   }
    19032021   else return NULL;
     
    19142032
    19152033  if(win32wnd && CheckMagicDword(magic)) {
    1916     return win32wnd;
     2034        return win32wnd;
    19172035  }
    19182036  return 0;
Note: See TracChangeset for help on using the changeset viewer.