Changeset 5935 for trunk/src/user32/win32wbase.cpp
- Timestamp:
- Jun 9, 2001, 4:50:26 PM (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/user32/win32wbase.cpp
r5810 r5935 1 /* $Id: win32wbase.cpp,v 1.2 59 2001-05-27 19:01:35sandervl Exp $ */1 /* $Id: win32wbase.cpp,v 1.260 2001-06-09 14:50:21 sandervl Exp $ */ 2 2 /* 3 3 * Win32 Window Base Class for OS/2 … … 14 14 * 15 15 * TODO: Not thread/process safe 16 * 17 * NOTE: To access a window object, you must call GetWindowFromOS2Handle or 18 * GetWindowFromHandle. Both these methods increase the reference count 19 * of the object. When you're done with the object, you MUST call 20 * the release method! 21 * This mechanism prevents premature destruction of objects when there 22 * are still clients using it. 16 23 * 17 24 * NOTE: Client rectangle always relative to frame window … … 66 73 //****************************************************************************** 67 74 //****************************************************************************** 68 Win32BaseWindow::Win32BaseWindow(DWORD objType) : GenericObject(&windows, objType) 75 Win32BaseWindow::Win32BaseWindow() 76 : GenericObject(&windows, &critsect), ChildWindow(&critsect) 69 77 { 70 78 Init(); … … 72 80 //****************************************************************************** 73 81 //****************************************************************************** 74 Win32BaseWindow::Win32BaseWindow(HWND hwndOS2, ULONG reserved) : GenericObject(&windows, OBJTYPE_WINDOW), ChildWindow() 82 Win32BaseWindow::Win32BaseWindow(HWND hwndOS2, ULONG reserved) 83 : GenericObject(&windows, &critsect), ChildWindow(&critsect) 75 84 { 76 85 Init(); … … 80 89 //****************************************************************************** 81 90 Win32BaseWindow::Win32BaseWindow(CREATESTRUCTA *lpCreateStructA, ATOM classAtom, BOOL isUnicode) 82 : GenericObject(&windows, OBJTYPE_WINDOW), ChildWindow()91 : GenericObject(&windows, &critsect), ChildWindow(&critsect) 83 92 { 84 93 Init(); … … 115 124 nrUserWindowBytes= 0; 116 125 117 magic = WIN32PM_MAGIC;118 126 OS2Hwnd = 0; 119 127 OS2HwndFrame = 0; … … 179 187 Win32BaseWindow::~Win32BaseWindow() 180 188 { 189 if(getRefCount() < 0) { 190 DebugInt3(); 191 } 192 181 193 if(hTaskList) { 182 194 OSLibWinRemoveFromTasklist(hTaskList); … … 187 199 OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_MAGIC, 0); 188 200 189 if(!fDestroyAll && getParent() && getParent()->getFirstChild() == this && getNextChild() == NULL)190 {191 //if we're the last child that's being destroyed and our192 //parent window was also destroyed, then we delete the parent object193 if(getParent()->IsWindowDestroyed())194 {195 dprintf(("Last Child (%x) destroyed, get rid of our parent window (%x)", getWindowHandle(), getParent()->getWindowHandle()));196 delete getParent();197 setParent(NULL); //or else we'll crash in the dtor of the ChildWindow class198 }199 }200 else201 201 if(fDestroyAll) { 202 202 dprintf(("Destroying window %x %s", getWindowHandle(), windowNameA)); … … 206 206 /* Decrement class window counter */ 207 207 if(windowClass) { 208 windowClass->DecreaseWindowCount();208 RELEASE_CLASSOBJ(windowClass); 209 209 } 210 210 … … 236 236 if(propertyList) { 237 237 removeWindowProps(); 238 } 239 Win32BaseWindow *wndparent = (Win32BaseWindow *)ChildWindow::getParentOfChild(); 240 if(wndparent) { 241 RELEASE_WNDOBJ(wndparent); 242 } 243 if(windowClass) { 244 RELEASE_CLASSOBJ(windowClass); 238 245 } 239 246 } … … 287 294 if (!window->IsWindow() ) 288 295 { 296 RELEASE_WNDOBJ(window); 289 297 dprintf(("Bad parent %04x\n", cs->hwndParent )); 290 298 SetLastError(ERROR_INVALID_PARAMETER); 291 299 return FALSE; 292 300 } 301 RELEASE_WNDOBJ(window); 293 302 /* Windows does this for overlapped windows 294 303 * (I don't know about other styles.) */ … … 314 323 return 0; 315 324 } 316 /* Increment class window counter */317 windowClass->IncreaseWindowCount();318 325 319 326 #ifdef DEBUG … … 417 424 else 418 425 { 419 owner = GetWindowFromHandle( cs->hwndParent)->GetTopParent();426 owner = GetWindowFromHandle(GetWindowFromHandle(cs->hwndParent)->GetTopParent()); 420 427 if(owner == NULL) 421 428 { … … 491 498 fNoSizeMsg = TRUE; 492 499 493 if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32WNDPTR, (ULONG)this) == FALSE) {500 if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32WNDPTR, getWindowHandle()) == FALSE) { 494 501 dprintf(("WM_CREATE: WinSetWindowULong %X failed!!", OS2Hwnd)); 495 502 SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error … … 827 834 SendInternalMessageA(WM_NCDESTROY, 0, 0); 828 835 829 TIMER_KillTimerFromWindow( OS2Hwnd);830 831 if(get FirstChild() == NULL && fCreationFinished) {836 TIMER_KillTimerFromWindow(getWindowHandle()); 837 838 if(getRefCount() == 0 && getFirstChild() == NULL && fCreationFinished) { 832 839 delete this; 833 840 } 834 841 else { 835 842 //make sure no message can ever arrive for this window again (PM or from other win32 windows) 843 dprintf(("Mark window %x (%x) as deleted", getWindowHandle(), this)); 844 markDeleted(); 836 845 OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32WNDPTR, 0); 837 846 OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_MAGIC, 0); … … 1028 1037 1029 1038 /* Activate the window if needed */ 1030 hwndTop = (GetTopParent()) ? GetTopParent()->getWindowHandle() : 0;1039 hwndTop = GetTopParent(); 1031 1040 1032 1041 HWND hwndActive = GetActiveWindow(); … … 1673 1682 if(wParam == VK_F4) /* try to close the window */ 1674 1683 { 1675 Win32BaseWindow *window = Get TopParent();1684 Win32BaseWindow *window = GetWindowFromHandle(GetTopParent()); 1676 1685 if(window && !(window->getClass()->getStyle() & CS_NOCLOSE)) 1677 1686 PostMessageA(window->getWindowHandle(), WM_SYSCOMMAND, SC_CLOSE, 0); 1687 if(window) RELEASE_WNDOBJ(window); 1678 1688 return 0; 1679 1689 } … … 2749 2759 OSLibWinSetParent(getOS2FrameWindowHandle(), OSLIB_HWND_DESKTOP); 2750 2760 2751 //TODO: Send WM_STYLECHANGED msg?2761 //TODO: Send WM_STYLECHANGED msg? 2752 2762 setStyle(getStyle() & ~WS_CHILD); 2753 2763 setWindowId(0); … … 2790 2800 topwindow = GetWindowFromOS2FrameHandle(hwndTop); 2791 2801 if(topwindow) { 2792 return topwindow->getWindowHandle(); 2802 hwndTop = topwindow->getWindowHandle(); 2803 RELEASE_WNDOBJ(topwindow); 2804 return hwndTop; 2793 2805 } 2794 2806 return 0; … … 2797 2809 topwindow = GetWindowFromOS2FrameHandle(hwndTop); 2798 2810 if(topwindow) { 2799 return topwindow->getWindowHandle(); 2811 hwndTop = topwindow->getWindowHandle(); 2812 RELEASE_WNDOBJ(topwindow); 2813 return hwndTop; 2800 2814 } 2801 2815 hwndTop = OSLibWinQueryWindow(hwndTop, QWOS_NEXT); … … 2807 2821 // Get the top-level parent for a child window. 2808 2822 //****************************************************************************** 2809 Win32BaseWindow *Win32BaseWindow::GetTopParent()2823 HWND Win32BaseWindow::GetTopParent() 2810 2824 { 2811 2825 Win32BaseWindow *window = this; 2812 2826 HWND hwndTopParent = 0; 2827 2828 lock(); 2813 2829 while(window && (window->getStyle() & WS_CHILD)) 2814 2830 { 2815 2831 window = window->getParent(); 2816 2832 } 2817 return window; 2833 if(window) { 2834 hwndTopParent = window->getWindowHandle(); 2835 } 2836 unlock(); 2837 return hwndTopParent; 2818 2838 } 2819 2839 //****************************************************************************** … … 2907 2927 //****************************************************************************** 2908 2928 //****************************************************************************** 2909 Win32BaseWindow *Win32BaseWindow::FindWindowById(int id) 2910 { 2929 HWND Win32BaseWindow::FindWindowById(int id) 2930 { 2931 lock(); 2911 2932 for (Win32BaseWindow *child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild()) 2912 2933 { 2913 2934 if (child->getWindowId() == id) 2914 2935 { 2915 return child; 2916 } 2917 } 2936 unlock(); 2937 return child->getWindowHandle(); 2938 } 2939 } 2940 unlock(); 2918 2941 return 0; 2919 2942 } … … 2987 3010 OSLibWinEndEnumWindows(henum); 2988 3011 dprintf(("FindWindowEx: Found window %x", wnd->getWindowHandle())); 2989 return wnd->getWindowHandle(); 3012 HWND hwndret = wnd->getWindowHandle(); 3013 RELEASE_WNDOBJ(wnd); 3014 return hwndret; 2990 3015 } 3016 RELEASE_WNDOBJ(wnd); 2991 3017 } 2992 3018 hwnd = OSLibWinGetNextWindow(henum); … … 3014 3040 if(window) { 3015 3041 hwndRelated = window->getWindowHandle(); 3042 RELEASE_WNDOBJ(window); 3016 3043 } 3017 3044 else hwndRelated = 0; … … 3031 3058 if(window) { 3032 3059 hwndRelated = window->getWindowHandle(); 3060 RELEASE_WNDOBJ(window); 3033 3061 } 3034 3062 else hwndRelated = 0; … … 3046 3074 if(window) { 3047 3075 hwndRelated = window->getWindowHandle(); 3076 RELEASE_WNDOBJ(window); 3048 3077 } 3049 3078 else hwndRelated = 0; … … 3061 3090 if(window) { 3062 3091 hwndRelated = window->getWindowHandle(); 3092 RELEASE_WNDOBJ(window); 3063 3093 } 3064 3094 else hwndRelated = 0; … … 3081 3111 if(window) { 3082 3112 hwndRelated = window->getWindowHandle(); 3113 RELEASE_WNDOBJ(window); 3083 3114 } 3084 3115 else hwndRelated = 0; … … 3174 3205 { 3175 3206 HWND hwndActive; 3176 Win32BaseWindow *win32wnd;3177 ULONG magic;3178 3207 3179 3208 hwndActive = OSLibWinQueryActiveWindow(); … … 3377 3406 } 3378 3407 oldval = (LONG)WINPROC_GetProc(win32wndproc, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A); 3408 dprintf(("SetWindowLong GWL_WNDPROC %x old %x new style %x", getWindowHandle(), oldval, value)); 3379 3409 WINPROC_SetProc((HWINDOWPROC *)&win32wndproc, (WNDPROC)value, type, WIN_PROC_WINDOW); 3380 3410 break; … … 3500 3530 //****************************************************************************** 3501 3531 //****************************************************************************** 3502 Win32BaseWindow *Win32BaseWindow::GetWindowFromHandle(HWND hwnd)3503 {3504 Win32BaseWindow *window;3505 3506 if(HwGetWindowHandleData(hwnd, (DWORD *)&window) == TRUE) {3507 return window;3508 }3509 // dprintf2(("Win32BaseWindow::GetWindowFromHandle: not a win32 window %x", hwnd));3510 return NULL;3511 }3512 //******************************************************************************3513 //******************************************************************************3514 Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2Handle(HWND hwnd)3515 {3516 Win32BaseWindow *win32wnd;3517 DWORD magic;3518 3519 if(hwnd == OSLIB_HWND_DESKTOP)3520 {3521 return windowDesktop;3522 }3523 3524 win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwnd, OFFSET_WIN32WNDPTR);3525 magic = OSLibWinGetWindowULong(hwnd, OFFSET_WIN32PM_MAGIC);3526 3527 if(win32wnd && CheckMagicDword(magic)) {3528 return win32wnd;3529 }3530 // dprintf2(("Win32BaseWindow::GetWindowFromOS2Handle: not an Odin os2 window %x", hwnd));3531 return 0;3532 }3533 //******************************************************************************3534 //******************************************************************************3535 Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2FrameHandle(HWND hwnd)3536 {3537 return GetWindowFromOS2Handle(OSLibWinWindowFromID(hwnd,OSLIB_FID_CLIENT));3538 }3539 //******************************************************************************3540 //******************************************************************************3541 3532 HWND Win32BaseWindow::getNextDlgGroupItem(HWND hwndCtrl, BOOL fPrevious) 3542 3533 { … … 3622 3613 return retvalue; 3623 3614 } 3615 //****************************************************************************** 3616 //Locates window in linked list and increases reference count (if found) 3617 //Window object must be unreferenced after usage 3618 //****************************************************************************** 3619 Win32BaseWindow *Win32BaseWindow::GetWindowFromHandle(HWND hwnd) 3620 { 3621 Win32BaseWindow *window; 3622 3623 lock(&critsect); 3624 if(HwGetWindowHandleData(hwnd, (DWORD *)&window) == TRUE) { 3625 if(window) { 3626 //// dprintf(("addRef %x; refcount %d", hwnd, window->getRefCount()+1)); 3627 window->addRef(); 3628 } 3629 unlock(&critsect); 3630 return window; 3631 } 3632 unlock(&critsect); 3633 // dprintf2(("Win32BaseWindow::GetWindowFromHandle: not a win32 window %x", hwnd)); 3634 return NULL; 3635 } 3636 //****************************************************************************** 3637 //Locates window in linked list and increases reference count (if found) 3638 //Window object must be unreferenced after usage 3639 //****************************************************************************** 3640 Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2Handle(HWND hwndOS2) 3641 { 3642 DWORD magic; 3643 HWND hwnd; 3644 3645 if(hwndOS2 == OSLIB_HWND_DESKTOP) 3646 { 3647 windowDesktop->addRef(); 3648 return windowDesktop; 3649 } 3650 3651 hwnd = (HWND)OSLibWinGetWindowULong(hwndOS2, OFFSET_WIN32WNDPTR); 3652 magic = OSLibWinGetWindowULong(hwndOS2, OFFSET_WIN32PM_MAGIC); 3653 3654 if(hwnd && CheckMagicDword(magic)) { 3655 return GetWindowFromHandle(hwnd); 3656 } 3657 // dprintf2(("Win32BaseWindow::GetWindowFromOS2Handle: not an Odin os2 window %x", hwndOS2)); 3658 return 0; 3659 } 3660 //****************************************************************************** 3661 //Locates window in linked list and increases reference count (if found) 3662 //Window object must be unreferenced after usage 3663 //****************************************************************************** 3664 Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2FrameHandle(HWND hwnd) 3665 { 3666 return GetWindowFromOS2Handle(OSLibWinWindowFromID(hwnd,OSLIB_FID_CLIENT)); 3667 } 3668 //****************************************************************************** 3669 //****************************************************************************** 3670 HWND WIN32API Win32ToOS2Handle(HWND hwnd) 3671 { 3672 HWND hwndOS2; 3673 3674 Win32BaseWindow *window = Win32BaseWindow::GetWindowFromHandle(hwnd); 3675 3676 if(window) { 3677 hwndOS2 = window->getOS2WindowHandle(); 3678 RELEASE_WNDOBJ(window); 3679 return hwndOS2; 3680 } 3681 // dprintf2(("Win32BaseWindow::Win32ToOS2Handle: not a win32 window %x", hwnd)); 3682 return hwnd; 3683 } 3684 //****************************************************************************** 3685 //****************************************************************************** 3686 HWND WIN32API OS2ToWin32Handle(HWND hwnd) 3687 { 3688 Win32BaseWindow *window = Win32BaseWindow::GetWindowFromOS2Handle(hwnd); 3689 HWND hwndWin32; 3690 3691 if(window) { 3692 hwndWin32 = window->getWindowHandle(); 3693 RELEASE_WNDOBJ(window); 3694 return hwndWin32; 3695 } 3696 window = Win32BaseWindow::GetWindowFromOS2FrameHandle(hwnd); 3697 if(window) { 3698 hwndWin32 = window->getWindowHandle(); 3699 RELEASE_WNDOBJ(window); 3700 return hwndWin32; 3701 } 3702 3703 // dprintf2(("Win32BaseWindow::OS2ToWin32Handle: not a win32 window %x", hwnd)); 3704 return 0; 3705 // else return hwnd; //OS/2 window handle 3706 } 3707 //****************************************************************************** 3708 //****************************************************************************** 3709 GenericObject *Win32BaseWindow::windows = NULL; 3710 CRITICAL_SECTION Win32BaseWindow::critsect = {0}; 3711 3624 3712 //****************************************************************************** 3625 3713 //****************************************************************************** … … 3718 3806 //****************************************************************************** 3719 3807 //****************************************************************************** 3720 HWND WIN32API Win32ToOS2Handle(HWND hwnd)3721 {3722 Win32BaseWindow *window = Win32BaseWindow::GetWindowFromHandle(hwnd);3723 3724 if(window) {3725 return window->getOS2WindowHandle();3726 }3727 // dprintf2(("Win32BaseWindow::Win32ToOS2Handle: not a win32 window %x", hwnd));3728 return hwnd;3729 }3730 //******************************************************************************3731 //******************************************************************************3732 HWND WIN32API OS2ToWin32Handle(HWND hwnd)3733 {3734 Win32BaseWindow *window = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);3735 3736 if(window) {3737 return window->getWindowHandle();3738 }3739 window = Win32BaseWindow::GetWindowFromOS2FrameHandle(hwnd);3740 if(window) {3741 return window->getWindowHandle();3742 }3743 3744 // dprintf2(("Win32BaseWindow::OS2ToWin32Handle: not a win32 window %x", hwnd));3745 return 0;3746 // else return hwnd; //OS/2 window handle3747 }3748 //******************************************************************************3749 //******************************************************************************3750 3751 GenericObject *Win32BaseWindow::windows = NULL;
Note:
See TracChangeset
for help on using the changeset viewer.