Ignore:
Timestamp:
Oct 17, 1999, 5:46:10 PM (26 years ago)
Author:
sandervl
Message:

Dialog fixes + ported Wine apis

File:
1 edited

Legend:

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

    r1307 r1336  
    1 /* $Id: window.cpp,v 1.16 1999-10-15 10:03:16 sandervl Exp $ */
     1/* $Id: window.cpp,v 1.17 1999-10-17 15:46:10 sandervl Exp $ */
    22/*
    33 * Win32 window apis for OS/2
     
    2929#include "user32.h"
    3030#include "winicon.h"
     31#include <win\winpos.h>
    3132
    3233//******************************************************************************
     
    5859        {
    5960          if (!HIWORD(className)) {
    60                   dprintf(("CreateWindowEx32W: bad class name %04x\n", LOWORD(className)));
     61                  dprintf(("CreateWindowEx32A: bad class name %04x\n", LOWORD(className)));
    6162          }
    62           else    dprintf(("CreateWindowEx32W: bad class name '%s'\n", className ));
     63          else    dprintf(("CreateWindowEx32A: bad class name '%s'\n", className ));
    6364
    6465          SetLastError(ERROR_INVALID_PARAMETER);
     
    8182    cs.dwExStyle      = exStyle;
    8283    if(HIWORD(className)) {
    83         dprintf(("CreateWindowExA: class %s parent %x (%d,%d) (%d,%d), %x %x", className, parent, x, y, width, height, style, exStyle));
     84        dprintf(("CreateWindowExA: class %s parent %x (%d,%d) (%d,%d), %x %x", className, parent, x, y, width, height, style, exStyle));
    8485    }
    8586    else dprintf(("CreateWindowExA: class %d parent %x (%d,%d) (%d,%d), %x %x", className, parent, x, y, width, height, style, exStyle));
     
    8889        window = (Win32BaseWindow *) new Win32MDIClientWindow(&cs, classAtom, FALSE);
    8990    }
    90     else 
    91     if(!strcmpi((char *) className, DIALOG_CLASS_NAMEA)) 
     91    else
     92    if(!strcmpi((char *) className, DIALOG_CLASS_NAMEA))
    9293    {
    9394      DLG_TEMPLATE dlgTemplate = {0};
     
    146147        {
    147148          sprintf(tmpClassA,"#%d", (int) className);
    148           AsciiToUnicode(tmpClassA, tmpClassW);
     149          AsciiToUnicode(tmpClassA, tmpClassW);
    149150          classAtom = GlobalFindAtomW(tmpClassW);
    150151          className = (LPCWSTR)tmpClassW;
     
    155156                  dprintf(("CreateWindowEx32W: bad class name %04x\n", LOWORD(className)));
    156157          }
    157           else    dprintf(("CreateWindowEx32W: bad class name "));
     158      else    dprintf(("CreateWindowEx32W: bad class name "));
    158159
    159160          SetLastError(ERROR_INVALID_PARAMETER);
     
    180181    }
    181182    else
    182     if(!lstrcmpiW(className, (LPWSTR)DIALOG_CLASS_NAMEW)) 
     183    if(!lstrcmpiW(className, (LPWSTR)DIALOG_CLASS_NAMEW))
    183184    {
    184185      DLG_TEMPLATE dlgTemplate = {0};
     
    258259    if(!window) {
    259260        dprintf(("CreateMDIWindowW, window %x not found", hwndParent));
    260         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
     261    SetLastError(ERROR_INVALID_WINDOW_HANDLE);
    261262        return 0;
    262263    }
     
    284285    if(!window) {
    285286        dprintf(("DestroyWindow, window %x not found", hwnd));
    286         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
     287    SetLastError(ERROR_INVALID_WINDOW_HANDLE);
    287288        return 0;
    288289    }
     
    299300    if(!window) {
    300301        dprintf(("SetActiveWindow, window %x not found", hwnd));
    301         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
     302    SetLastError(ERROR_INVALID_WINDOW_HANDLE);
    302303        return 0;
    303304    }
     
    314315    if(!window) {
    315316        dprintf(("GetParent, window %x not found", hwnd));
    316         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
     317    SetLastError(ERROR_INVALID_WINDOW_HANDLE);
    317318        return 0;
    318319    }
     
    329330    if(!window) {
    330331        dprintf(("SetParent, window %x not found", hwndChild));
    331         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
     332    SetLastError(ERROR_INVALID_WINDOW_HANDLE);
    332333        return 0;
    333334    }
     
    344345    if(!window) {
    345346        dprintf(("IsChild, window %x not found", hwnd));
    346         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
     347    SetLastError(ERROR_INVALID_WINDOW_HANDLE);
    347348        return 0;
    348349    }
     
    359360    if(!window) {
    360361        dprintf(("GetTopWindow, window %x not found", hwnd));
    361         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
     362    SetLastError(ERROR_INVALID_WINDOW_HANDLE);
    362363        return 0;
    363364    }
     
    389390    if(!window) {
    390391        dprintf(("IsIconic, window %x not found", hwnd));
    391         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
     392    SetLastError(ERROR_INVALID_WINDOW_HANDLE);
    392393        return 0;
    393394    }
     
    405406    if(!window) {
    406407        dprintf(("GetWindow, window %x not found", hwnd));
    407         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
     408    SetLastError(ERROR_INVALID_WINDOW_HANDLE);
    408409        return 0;
    409410    }
    410411    rc = window->GetWindow(uCmd);
    411     dprintf(("GetWindow %x %d returned %x", hwnd, uCmd, rc));
    412412    return rc;
    413413}
     
    421421    if(!window) {
    422422        dprintf(("EnableWindow, window %x not found", hwnd));
    423         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
     423    SetLastError(ERROR_INVALID_WINDOW_HANDLE);
    424424        return 0;
    425425    }
     
    448448    if(!window) {
    449449        dprintf(("ShowWindow, window %x not found", hwnd));
    450         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
     450    SetLastError(ERROR_INVALID_WINDOW_HANDLE);
    451451        return 0;
    452452    }
     
    463463    if(!window) {
    464464        dprintf(("SetWindowPos, window %x not found", hwnd));
    465         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
     465    SetLastError(ERROR_INVALID_WINDOW_HANDLE);
    466466        return 0;
    467467    }
     
    522522    if(!window) {
    523523        dprintf(("IsWindowVisible, window %x not found", hwnd));
    524         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
     524    SetLastError(ERROR_INVALID_WINDOW_HANDLE);
    525525        return 0;
    526526    }
     
    553553    dprintf(("USER32: GetFocus %x\n", hwnd));
    554554    hwnd = Win32BaseWindow::OS2ToWin32Handle(hwnd);
    555     return hwnd;   
     555    return hwnd;
    556556}
    557557//******************************************************************************
     
    625625    if(!window) {
    626626        dprintf(("GetWindowRect, window %x not found", hwnd));
    627         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
     627    SetLastError(ERROR_INVALID_WINDOW_HANDLE);
    628628        return 0;
    629629    }
     
    641641    if(!window) {
    642642        dprintf(("GetWindowTextLength, window %x not found", hwnd));
    643         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
     643    SetLastError(ERROR_INVALID_WINDOW_HANDLE);
    644644        return 0;
    645645    }
     
    657657    if(!window) {
    658658        dprintf(("GetWindowTextA, window %x not found", hwnd));
    659         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
     659    SetLastError(ERROR_INVALID_WINDOW_HANDLE);
    660660        return 0;
    661661    }
     
    680680    if(!window) {
    681681        dprintf(("GetWindowTextW, window %x not found", hwnd));
    682         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
     682    SetLastError(ERROR_INVALID_WINDOW_HANDLE);
    683683        return 0;
    684684    }
     
    695695    if(!window) {
    696696        dprintf(("SetWindowTextA, window %x not found", hwnd));
    697         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
     697    SetLastError(ERROR_INVALID_WINDOW_HANDLE);
    698698        return 0;
    699699    }
     
    710710    if(!window) {
    711711        dprintf(("SetWindowTextA, window %x not found", hwnd));
    712         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
     712    SetLastError(ERROR_INVALID_WINDOW_HANDLE);
    713713        return 0;
    714714    }
     
    746746 HWND hwndWin32 = hwnd;
    747747
     748#if 1
     749 Win32BaseWindow *window;
     750
     751    window = Win32BaseWindow::GetWindowFromHandle(hwnd);
     752    if(!window) {
     753        dprintf(("GetClientRect, window %x not found", hwnd));
     754    SetLastError(ERROR_INVALID_WINDOW_HANDLE);
     755        return 0;
     756    }
     757    *pRect = *window->getClientRect();
     758    OffsetRect(pRect, -pRect->left, -pRect->top);
     759    dprintf(("GetClientRect of %X returned (%d,%d) (%d,%d)\n", hwndWin32, pRect->left, pRect->top, pRect->right, pRect->bottom));
     760    return TRUE;
     761#else
    748762    hwnd = Win32BaseWindow::Win32ToOS2Handle(hwnd);
    749763    rc = OSLibWinQueryWindowRect(hwnd, pRect);
    750764    dprintf(("GetClientRect of %X returned (%d,%d) (%d,%d)\n", hwndWin32, pRect->left, pRect->top, pRect->right, pRect->bottom));
    751765    return rc;
    752 }
    753 //******************************************************************************
    754 //******************************************************************************
    755 BOOL WIN32API AdjustWindowRect( PRECT arg1, DWORD arg2, BOOL  arg3)
    756 {
    757 #ifdef DEBUG
    758     WriteLog("USER32:  AdjustWindowRect\n");
    759766#endif
    760     return O32_AdjustWindowRect(arg1, arg2, arg3);
    761 }
    762 //******************************************************************************
    763 //******************************************************************************
    764 BOOL WIN32API AdjustWindowRectEx( PRECT arg1, DWORD arg2, BOOL arg3, DWORD  arg4)
    765 {
    766 #ifdef DEBUG
    767     WriteLog("USER32:  AdjustWindowRectEx\n");
     767}
     768//******************************************************************************
     769//******************************************************************************
     770BOOL WIN32API AdjustWindowRect(PRECT rect, DWORD style, BOOL menu)
     771{
     772    return AdjustWindowRectEx(rect, style, menu, 0);
     773}
     774//******************************************************************************
     775//******************************************************************************
     776BOOL WIN32API AdjustWindowRectEx( PRECT rect, DWORD style, BOOL menu, DWORD exStyle)
     777{
     778    dprintf(("AdjustWindowRectEx %x %x %d (%d,%d)(%d,%d)\n", style, exStyle, menu, rect->right, rect->top, rect->left, rect->bottom));
     779
     780#if 0
     781    O32_AdjustWindowRectEx(rect, style, menu, exStyle);
     782#else
     783    /* Correct the window style */
     784    if (!(style & (WS_POPUP | WS_CHILD)))  /* Overlapped window */
     785    style |= WS_CAPTION;
     786
     787    style &= (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME | WS_CHILD | WS_VSCROLL | WS_HSCROLL);
     788    exStyle &= (WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE |
     789        WS_EX_STATICEDGE | WS_EX_TOOLWINDOW);
     790    if (exStyle & WS_EX_DLGMODALFRAME) style &= ~WS_THICKFRAME;
     791
     792    Win32BaseWindow::NC_AdjustRectOuter( rect, style, menu, exStyle );
     793    Win32BaseWindow::NC_AdjustRectInner( rect, style, exStyle );
    768794#endif
    769     return O32_AdjustWindowRectEx(arg1, arg2, arg3, arg4);
     795
     796    dprintf(("AdjustWindowRectEx returned (%d,%d)(%d,%d)\n", rect->right, rect->top, rect->left, rect->bottom));
     797    return TRUE;
    770798}
    771799//******************************************************************************
     
    781809{
    782810    if(!lpszClass) {
    783         SetLastError(ERROR_INVALID_PARAMETER);
    784         return 0;
     811        SetLastError(ERROR_INVALID_PARAMETER);
     812        return 0;
    785813    }
    786814    if(HIWORD(lpszClass)) {
     
    793821//******************************************************************************
    794822//******************************************************************************
     823HWND WIN32API FindWindowW( LPCWSTR lpClassName, LPCWSTR lpWindowName)
     824{
     825 char *astring1 = UnicodeToAsciiString((LPWSTR)lpClassName);
     826 char *astring2 = UnicodeToAsciiString((LPWSTR)lpWindowName);
     827 HWND rc;
     828
     829    rc = FindWindowA(astring1, astring2);
     830    FreeAsciiString(astring1);
     831    FreeAsciiString(astring2);
     832    return rc;
     833}
     834//******************************************************************************
     835//******************************************************************************
    795836HWND WIN32API FindWindowExA(HWND hwndParent, HWND hwndChildAfter, LPCSTR lpszClass, LPCSTR lpszWindow)
    796837{
    797838    if(!lpszClass) {
    798         SetLastError(ERROR_INVALID_PARAMETER);
    799         return 0;
     839        SetLastError(ERROR_INVALID_PARAMETER);
     840        return 0;
    800841    }
    801842    if(HIWORD(lpszClass)) {
     
    833874{
    834875    if(!lpszClass) {
    835         SetLastError(ERROR_INVALID_PARAMETER);
    836         return 0;
     876        SetLastError(ERROR_INVALID_PARAMETER);
     877        return 0;
    837878    }
    838879    dprintf(("USER32:  FindWindowExW (%x,%x) %x %s\n", hwndParent, hwndChildAfter, lpszClass, lpszWindow));
     
    870911
    871912    if (!hwnd) {
    872         SetLastError(ERROR_INVALID_PARAMETER);
    873         return (FALSE);
     913    SetLastError(ERROR_INVALID_PARAMETER);
     914    return (FALSE);
    874915    }
    875916    wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
    876917    if (!wnd) {
    877         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
    878         return (FALSE);
     918    SetLastError(ERROR_INVALID_WINDOW_HANDLE);
     919    return (FALSE);
    879920    }
    880921
     
    887928//******************************************************************************
    888929//******************************************************************************
    889 HDWP WIN32API BeginDeferWindowPos( int arg1)
    890 {
    891 #ifdef DEBUG
    892     WriteLog("USER32:  BeginDeferWindowPos\n");
     930HDWP WIN32API BeginDeferWindowPos(int count)
     931{
     932    HDWP handle;
     933    DWP *pDWP;
     934
     935    dprintf(("USER32:  BeginDeferWindowPos\n"));
     936    if (count <= 0)
     937    {
     938        SetLastError(ERROR_INVALID_PARAMETER);
     939        return 0;
     940    }
     941    handle = (HDWP)HeapAlloc(GetProcessHeap(), 0, sizeof(DWP) + (count-1)*sizeof(WINDOWPOS) );
     942    if (!handle)
     943        return 0;
     944
     945    pDWP = (DWP *) handle;
     946    pDWP->actualCount    = 0;
     947    pDWP->suggestedCount = count;
     948    pDWP->valid          = TRUE;
     949    pDWP->wMagic         = DWP_MAGIC;
     950    pDWP->hwndParent     = 0;
     951    return handle;
     952}
     953/***********************************************************************
     954 *           DeferWindowPos   (USER32.128)
     955 */
     956HDWP WIN32API DeferWindowPos( HDWP hdwp, HWND hwnd, HWND hwndAfter,
     957                              INT x, INT y, INT cx, INT cy,
     958                              UINT flags )
     959{
     960  DWP *pDWP;
     961  int i;
     962  HDWP newhdwp = hdwp,retvalue;
     963  Win32BaseWindow *window;
     964
     965    pDWP = (DWP *)hdwp;
     966    if (!pDWP) {
     967        SetLastError(ERROR_INVALID_PARAMETER);
     968        return 0;
     969    }
     970
     971    if (hwnd == GetDesktopWindow())
     972        return 0;
     973
     974    window = Win32BaseWindow::GetWindowFromHandle(hwnd);
     975    if(!window) {
     976        dprintf(("DeferWindowPos, window %x not found", hwnd));
     977        SetLastError(ERROR_INVALID_WINDOW_HANDLE);
     978        HeapFree(GetProcessHeap(), 0, (LPVOID)hdwp);
     979        return 0;
     980    }
     981
     982
     983/* Numega Bounds Checker Demo dislikes the following code.
     984   In fact, I've not been able to find any "same parent" requirement in any docu
     985   [AM 980509]
     986 */
     987#if 0
     988    /* All the windows of a DeferWindowPos() must have the same parent */
     989    parent = pWnd->parent->hwndSelf;
     990    if (pDWP->actualCount == 0) pDWP->hwndParent = parent;
     991    else if (parent != pDWP->hwndParent)
     992    {
     993        USER_HEAP_FREE( hdwp );
     994        retvalue = 0;
     995        goto END;
     996    }
    893997#endif
    894     return O32_BeginDeferWindowPos(arg1);
    895 }
    896 //******************************************************************************
    897 //******************************************************************************
    898 HDWP WIN32API DeferWindowPos( HDWP arg1, HWND arg2, HWND  arg3, int arg4, int arg5, int arg6, int arg7, UINT  arg8)
    899 {
    900 #ifdef DEBUG
    901     WriteLog("USER32:  DeferWindowPos\n");
    902 #endif
    903     return O32_DeferWindowPos(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
     998
     999    for (i = 0; i < pDWP->actualCount; i++)
     1000    {
     1001        if (pDWP->winPos[i].hwnd == hwnd)
     1002        {
     1003              /* Merge with the other changes */
     1004            if (!(flags & SWP_NOZORDER))
     1005            {
     1006                pDWP->winPos[i].hwndInsertAfter = hwndAfter;
     1007            }
     1008            if (!(flags & SWP_NOMOVE))
     1009            {
     1010                pDWP->winPos[i].x = x;
     1011                pDWP->winPos[i].y = y;
     1012            }
     1013            if (!(flags & SWP_NOSIZE))
     1014            {
     1015                pDWP->winPos[i].cx = cx;
     1016                pDWP->winPos[i].cy = cy;
     1017            }
     1018            pDWP->winPos[i].flags &= flags | ~(SWP_NOSIZE | SWP_NOMOVE |
     1019                                               SWP_NOZORDER | SWP_NOREDRAW |
     1020                                               SWP_NOACTIVATE | SWP_NOCOPYBITS|
     1021                                               SWP_NOOWNERZORDER);
     1022            pDWP->winPos[i].flags |= flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW |
     1023                                              SWP_FRAMECHANGED);
     1024            retvalue = hdwp;
     1025            goto END;
     1026        }
     1027    }
     1028    if (pDWP->actualCount >= pDWP->suggestedCount)
     1029    {
     1030        newhdwp = (HDWP)HeapReAlloc(GetProcessHeap(), 0, (LPVOID)hdwp,
     1031                                    sizeof(DWP) + pDWP->suggestedCount*sizeof(WINDOWPOS));
     1032        if (!newhdwp)
     1033        {
     1034            retvalue = 0;
     1035            goto END;
     1036        }
     1037        pDWP = (DWP *) newhdwp;
     1038        pDWP->suggestedCount++;
     1039    }
     1040    pDWP->winPos[pDWP->actualCount].hwnd = hwnd;
     1041    pDWP->winPos[pDWP->actualCount].hwndInsertAfter = hwndAfter;
     1042    pDWP->winPos[pDWP->actualCount].x = x;
     1043    pDWP->winPos[pDWP->actualCount].y = y;
     1044    pDWP->winPos[pDWP->actualCount].cx = cx;
     1045    pDWP->winPos[pDWP->actualCount].cy = cy;
     1046    pDWP->winPos[pDWP->actualCount].flags = flags;
     1047    pDWP->actualCount++;
     1048    retvalue = newhdwp;
     1049END:
     1050    return retvalue;
     1051}
     1052//******************************************************************************
     1053//******************************************************************************
     1054BOOL WIN32API EndDeferWindowPos( HDWP hdwp)
     1055{
     1056    DWP *pDWP;
     1057    WINDOWPOS *winpos;
     1058    BOOL res = TRUE;
     1059    int i;
     1060
     1061    dprintf(("EndDeferWindowPos\n"));
     1062    pDWP = (DWP *) hdwp;
     1063    if (!pDWP) {
     1064        SetLastError(ERROR_INVALID_PARAMETER);
     1065        return FALSE;
     1066    }
     1067    for (i = 0, winpos = pDWP->winPos; i < pDWP->actualCount; i++, winpos++)
     1068    {
     1069        if (!(res = SetWindowPos(winpos->hwnd, winpos->hwndInsertAfter,
     1070                                 winpos->x, winpos->y, winpos->cx,
     1071                                 winpos->cy, winpos->flags )))
     1072            break;
     1073    }
     1074    HeapFree(GetProcessHeap(), 0, (LPVOID)hdwp);
     1075    return res;
    9041076}
    9051077//******************************************************************************
     
    9401112        if (GetWindowRect (hwndParent, &rect) == 0) {
    9411113                // oops, invalid handle
    942                 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
     1114        SetLastError(ERROR_INVALID_WINDOW_HANDLE);
    9431115                return NULL;
    9441116        }
     
    9851157                }
    9861158
    987                 dprintf(("ChildWindowFromPointEx returned %x", hWnd));
     1159        dprintf(("ChildWindowFromPointEx returned %x", hWnd));
    9881160                // found it!
    9891161                return hWnd;
     
    9921164        // the point is in the parentwindow but the parentwindow has no child
    9931165        // at this coordinate
    994         dprintf(("ChildWindowFromPointEx returned parent %x", hwndParent));
     1166    dprintf(("ChildWindowFromPointEx returned parent %x", hwndParent));
    9951167        return hwndParent;
    9961168}
     
    10041176    if(!window) {
    10051177        dprintf(("CloseWindow, window %x not found", hwnd));
    1006         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
     1178    SetLastError(ERROR_INVALID_WINDOW_HANDLE);
    10071179        return 0;
    10081180    }
     
    10331205    if(!window) {
    10341206        dprintf(("IsWindowUnicode, window %x not found", hwnd));
    1035         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
     1207    SetLastError(ERROR_INVALID_WINDOW_HANDLE);
    10361208        return 0;
    10371209    }
     
    11391311  if(!parentwindow) {
    11401312        dprintf(("EnumChildWindows, window %x not found", hwnd));
    1141         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
     1313    SetLastError(ERROR_INVALID_WINDOW_HANDLE);
    11421314        return FALSE;
    11431315  }
Note: See TracChangeset for help on using the changeset viewer.