Ignore:
Timestamp:
Jun 9, 2001, 4:50:26 PM (24 years ago)
Author:
sandervl
Message:

reference count (window + class objects) rewrite

File:
1 edited

Legend:

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

    r5258 r5935  
    1 /* $Id: win32wmdiclient.cpp,v 1.34 2001-02-23 14:52:42 sandervl Exp $ */
     1/* $Id: win32wmdiclient.cpp,v 1.35 2001-06-09 14:50:23 sandervl Exp $ */
    22/*
    33 * Win32 MDI Client Window Class for OS/2
     
    4646                  frameTitle(NULL), mdiFlags(0), idFirstChild(0), hWindowMenu(0),
    4747                  sbRecalc(0),
    48                   Win32BaseWindow(OBJTYPE_WINDOW)
     48                  Win32BaseWindow()
    4949{
    5050  Init();
     
    125125
    126126    case WM_MDIACTIVATE:
    127         if( activeChild && activeChild->getWindowHandle() != (HWND)wParam )
     127        if(activeChild != (HWND)wParam )
    128128        {
    129129            mdichild = (Win32MDIChildWindow *)GetWindowFromHandle((HWND)wParam);
    130130            if(mdichild) {
    131131                mdichild->SetWindowPos(0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE);
     132                RELEASE_WNDOBJ(mdichild);
    132133            }
    133134        }
     
    150151        if(mdichild) {
    151152            retvalue = destroyChild(mdichild, TRUE );
     153            RELEASE_WNDOBJ(mdichild);
    152154        }
    153155        goto END;
    154156
    155157    case WM_MDIGETACTIVE:
    156         dprintf(("WM_MDIGETACTIVE: %x %x", this, (activeChild) ? activeChild->getWindowHandle() : 0));
     158        dprintf(("WM_MDIGETACTIVE: %x %x", this, activeChild));
    157159        if (lParam)
    158160            *(BOOL *)lParam = (maximizedChild != 0);
    159161
    160         retvalue = (activeChild) ? activeChild->getWindowHandle() : 0;
     162        retvalue = activeChild;
    161163        goto END;
    162164
     
    178180        if(mdichild) {
    179181            switchActiveChild(mdichild, (lParam)? FALSE : TRUE );
     182            RELEASE_WNDOBJ(mdichild);
    180183        }
    181184        break;
     
    212215        if( activeChild )
    213216        {
    214             if( !(activeChild->getStyle() & WS_MINIMIZE) )
    215                 ::SetFocus(activeChild->getWindowHandle());
     217            if( !(GetWindowLongA(activeChild, GWL_STYLE) & WS_MINIMIZE) )
     218                ::SetFocus(activeChild);
    216219        }
    217220        retvalue = 0;
     
    220223    case WM_NCACTIVATE:
    221224        if( activeChild )
    222             activeChild->SendInternalMessageA(message, wParam, lParam);
     225            ::SendMessageA(activeChild, message, wParam, lParam);
    223226        break;
    224227
     
    234237            HWND child = ChildWindowFromPoint(getWindowHandle(), point);
    235238
    236             if( child && child != getWindowHandle() && (!activeChild || activeChild->getWindowHandle() != child) )
     239            if( child && child != getWindowHandle() && (activeChild != child) )
    237240                ::SetWindowPos(child, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE );
    238241        }
     
    241244
    242245    case WM_SIZE:
    243         if( maximizedChild && maximizedChild->IsWindow() )
     246        if( ::IsWindow(maximizedChild) )
    244247        {
    245248            RECT    rect;
     
    250253            rect.bottom = HIWORD(lParam);
    251254
    252             AdjustWindowRectEx(&rect, maximizedChild->getStyle(), 0, maximizedChild->getExStyle());
    253             ::MoveWindow(maximizedChild->getWindowHandle(), rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, 1);
     255            AdjustWindowRectEx(&rect, GetWindowLongA(maximizedChild, GWL_STYLE), 0, GetWindowLongA(maximizedChild, GWL_EXSTYLE));
     256            ::MoveWindow(maximizedChild, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, 1);
    254257        }
    255258        else postUpdate(SB_BOTH+1);
     
    285288        return 0;
    286289    }
    287     return window->MDIClientWndProc(message, wParam, lParam);
     290    LRESULT ret = window->MDIClientWndProc(message, wParam, lParam);
     291    RELEASE_WNDOBJ(window);
     292    return ret;
    288293}
    289294/**********************************************************************
     
    299304    dwStyleMask |= WS_DISABLED | WS_VISIBLE;
    300305
    301     if( !actchild ) actchild = getActiveChild();
     306    if( !actchild ) {
     307         actchild = (Win32MDIChildWindow *)GetWindowFromHandle(getActiveChild());
     308    }
     309    else actchild->addRef();
     310
    302311    if( !actchild)  return 0;
    303312
     313    lock();
    304314    for ( curchild = (Win32MDIChildWindow *)actchild->getNextChild(); ; curchild = (Win32MDIChildWindow *)curchild->getNextChild())
    305315    {
     
    314324        }
    315325    }
     326    unlock();
     327    RELEASE_WNDOBJ(actchild);
    316328    return lastchild;
    317329}
     
    325337    BOOL                  isActiveFrameWnd = 0;
    326338    LONG                  retvalue;
    327     Win32MDIChildWindow  *prevActive = activeChild;
     339    Win32MDIChildWindow  *prevActive = (Win32MDIChildWindow *)GetWindowFromHandle(activeChild);
    328340
    329341    if( child && child->getStyle() & WS_DISABLED )
    330342    {
     343        if(prevActive) RELEASE_WNDOBJ(prevActive);
    331344        return 0;
    332345    }
     
    334347    /* Don't activate if it is already active. Might happen
    335348       since ShowWindow DOES activate MDI children */
    336     if(activeChild == child)
    337     {
     349    if(activeChild == child->getWindowHandle())
     350    {
     351        if(prevActive) RELEASE_WNDOBJ(prevActive);
    338352        return 0;
    339353    }
     
    358372    if( maximizedChild)
    359373    {
    360         if( maximizedChild != child) {
     374        if( maximizedChild != child->getWindowHandle()) {
    361375            if( child ) {
    362                 activeChild = child;
     376                activeChild = child->getWindowHandle();
    363377                child->ShowWindow(SW_SHOWMAXIMIZED);
    364378            }
    365379            else
    366             if(activeChild) activeChild->ShowWindow( SW_SHOWNORMAL );
     380            if(activeChild) ::ShowWindow(activeChild, SW_SHOWNORMAL );
    367381        }
    368382    }
    369383
    370384    dprintf(("childActivate: %x %x", this, (child) ? child->getWindowHandle() : 0));
    371     activeChild = child;
     385    activeChild = child->getWindowHandle();
    372386
    373387    /* check if we have any children left */
     
    377391            SetFocus(getWindowHandle());
    378392
     393        if(prevActive) RELEASE_WNDOBJ(prevActive);
    379394        return 0;
    380395    }
     
    400415                         prevActive ? (WPARAM)prevActive->getWindowHandle() : 0,
    401416                         child->getWindowHandle());
     417
     418    if(prevActive) RELEASE_WNDOBJ(prevActive);
    402419    return TRUE;
    403420}
     
    410427void Win32MDIClientWindow::switchActiveChild(Win32MDIChildWindow *nextActiveChild, BOOL bNextWindow )
    411428{
    412     Win32MDIChildWindow *prevActiveChild  = 0;
     429    HWND prevActiveChild  = 0;
    413430
    414431    if ( !nextActiveChild) return; /* no window to switch to */
     
    416433    prevActiveChild = getActiveChild();
    417434
    418     if ( prevActiveChild !=  nextActiveChild)
     435    if ( prevActiveChild !=  nextActiveChild->getWindowHandle())
    419436    {
    420437        BOOL bOptimize = 0;
     
    429446
    430447        if( bNextWindow && prevActiveChild )
    431             prevActiveChild->SetWindowPos(HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE );
     448            ::SetWindowPos(prevActiveChild, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE );
    432449
    433450        if( bOptimize )
     
    442459LRESULT Win32MDIClientWindow::destroyChild(Win32MDIChildWindow *child, BOOL flagDestroy )
    443460{
    444     if( child == getActiveChild())
     461    if( child->getWindowHandle() == getActiveChild())
    445462    {
    446463        switchActiveChild(child, TRUE);
    447464
    448         if( child == getActiveChild() )
     465        if( child->getWindowHandle() == getActiveChild() )
    449466        {
    450467            ::ShowWindow(child->getWindowHandle(),SW_HIDE);
    451             if( child == getMaximizedChild() )
     468            if( child->getWindowHandle() == getMaximizedChild() )
    452469            {
    453470                restoreFrameMenu(child);
     
    492509    if (frameTitle)
    493510    {
    494         Win32MDIChildWindow *childWnd = getMaximizedChild();
     511        Win32MDIChildWindow *childWnd = (Win32MDIChildWindow *)GetWindowFromHandle(getMaximizedChild());
    495512
    496513        if( childWnd && childWnd->getWindowNameA() )
     
    526543            lpBuffer[MDI_MAXTITLELENGTH]='\0';
    527544        }
     545        if(childWnd) RELEASE_WNDOBJ(childWnd);
    528546    }
    529547    else
     
    800818
    801819  if (getMaximizedChild())
    802     SendInternalMessageA(WM_MDIRESTORE, (WPARAM)getMaximizedChild()->getWindowHandle(), 0);
     820    SendInternalMessageA(WM_MDIRESTORE, (WPARAM)getMaximizedChild(), 0);
    803821
    804822  if (nActiveChildren == 0) return 0;
     
    845863
    846864  if (getMaximizedChild())
    847     SendInternalMessageA(WM_MDIRESTORE, (WPARAM)getMaximizedChild()->getWindowHandle(), 0);
     865    SendInternalMessageA(WM_MDIRESTORE, (WPARAM)getMaximizedChild(), 0);
    848866
    849867  if (nActiveChildren == 0) return TRUE;
     
    914932 *                  MDI_AugmentFrameMenu
    915933 */
    916 BOOL Win32MDIClientWindow::augmentFrameMenu(Win32MDIChildWindow *child)
    917 {
     934BOOL Win32MDIClientWindow::augmentFrameMenu(HWND hwndChild)
     935{
     936  Win32MDIChildWindow *child = (Win32MDIChildWindow *)GetWindowFromHandle(hwndChild);
    918937  HMENU   hSysPopup = 0,hFrameMenu = ::GetMenu(getParent()->getWindowHandle()),hSysMenu = ::GetSystemMenu(child->getWindowHandle(),FALSE);
    919938  HBITMAP hSysMenuBitmap = 0;
    920939
    921   if (!hFrameMenu || !hSysMenu)
     940  if (!hFrameMenu || !hSysMenu) {
     941    RELEASE_WNDOBJ(child);
    922942    return 0;
    923 
     943  }
    924944  // create a copy of sysmenu popup and insert it into frame menu bar
    925945
    926   if (!(hSysPopup = LoadMenuA(GetModuleHandleA("USER32"), "SYSMENU")))
     946  if (!(hSysPopup = LoadMenuA(GetModuleHandleA("USER32"), "SYSMENU"))) {
     947    RELEASE_WNDOBJ(child);
    927948    return 0;
     949  }
    928950
    929951  //TRACE("\tgot popup %04x in sysmenu %04x\n",
     
    936958
    937959  // In Win 95 look, the system menu is replaced by the child icon
    938 
     960 
    939961  /* Find icon */
    940962  HICON hIcon = child->IconForWindow(ICON_SMALL);
     
    966988    }
    967989  }
     990  RELEASE_WNDOBJ(child);
    968991
    969992  if( !InsertMenuA(hFrameMenu,0,MF_BYPOSITION | MF_BITMAP | MF_POPUP,
     
    9941017 *                  MDI_RestoreFrameMenu
    9951018 */
    996 BOOL Win32MDIClientWindow::restoreFrameMenu(Win32MDIChildWindow *child)
     1019BOOL Win32MDIClientWindow::restoreFrameMenu(HWND hwndChild)
    9971020{
    9981021    MENUITEMINFOA menuInfo;
     
    10041027
    10051028    if(!(iId == SC_RESTORE || iId == SC_CLOSE) )
    1006     return 0;
     1029        return 0;
    10071030
    10081031    /*
     
    10491072{
    10501073    Win32BaseWindow *win32wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
     1074    Win32BaseWindow *child;
    10511075    SCROLLINFO info;
    10521076    RECT childRect, clientRect;
     
    10591083
    10601084    //TODO: Check if this goes correctly
    1061     for (win32wnd = (Win32BaseWindow*)win32wnd->getFirstChild();win32wnd;win32wnd = (Win32BaseWindow*)win32wnd->getNextChild())
    1062     {
    1063           if( win32wnd->getStyle() & WS_MAXIMIZE )
     1085    win32wnd->lock();
     1086    for (child = (Win32BaseWindow*)win32wnd->getFirstChild();child;child = (Win32BaseWindow*)child->getNextChild())
     1087    {
     1088          if( child->getStyle() & WS_MAXIMIZE )
    10641089          {
     1090              win32wnd->unlock();
     1091              RELEASE_WNDOBJ(win32wnd);
    10651092              ShowScrollBar(hwnd, SB_BOTH, FALSE);
    10661093              return;
    10671094          }
    1068           UnionRect(&childRect,win32wnd->getWindowRect(),&childRect);
    1069     }
     1095          UnionRect(&childRect,child->getWindowRect(),&childRect);
     1096    }
     1097    win32wnd->unlock();
     1098    RELEASE_WNDOBJ(win32wnd);
     1099
    10701100    UnionRect( &childRect, &clientRect, &childRect );
    10711101
     
    11211151    length = win32wnd->getClientWidth()/2;
    11221152    shift = GetSystemMetrics(SM_CYHSCROLL);
    1123   } else if (uMsg == WM_VSCROLL)
     1153  }
     1154  else if (uMsg == WM_VSCROLL)
    11241155  {
    11251156    GetScrollRange(hWnd,SB_VERT,&minPos,&maxPos);
     
    11271158    length = win32wnd->getClientHeight()/2;
    11281159    shift = GetSystemMetrics(SM_CXVSCROLL);
    1129   } else return;
     1160  }
     1161  else
     1162  {
     1163    RELEASE_WNDOBJ(win32wnd);
     1164    return;
     1165  }
     1166  RELEASE_WNDOBJ(win32wnd);
    11301167
    11311168  switch( wParam )
     
    12921329}
    12931330
    1294 /* -------- Miscellaneous service functions ----------
    1295  *
    1296  *          MDI_GetChildByID
    1297  */
    1298 Win32MDIChildWindow *Win32MDIClientWindow::getChildByID(INT id)
    1299 {
    1300  Win32MDIChildWindow *child;
    1301 
    1302     for (child = (Win32MDIChildWindow *)getFirstChild() ; child; child = (Win32MDIChildWindow *)child->getNextChild())
    1303         if (child->getWindowId() == id) return child;
    1304 
    1305     return 0;
    1306 }
     1331/* -------- Miscellaneous service functions ---------- */
    13071332
    13081333void Win32MDIClientWindow::postUpdate(WORD recalc)
Note: See TracChangeset for help on using the changeset viewer.