--- old/glass-mat-lib-windows/src/BaseWnd.cpp 2011-09-01 19:00:24.000000000 +0400 +++ new/glass-mat-lib-windows/src/BaseWnd.cpp 2011-09-01 19:00:23.000000000 +0400 @@ -6,7 +6,9 @@ static LPCTSTR szBaseWndProp = TEXT("BaseWndProp"); -BaseWnd::BaseWnd() : m_hWnd(NULL) +BaseWnd::BaseWnd(HWND ancestor) : + m_hWnd(NULL), + m_ancestor(ancestor) { } --- old/glass-mat-lib-windows/src/BaseWnd.h 2011-09-01 19:00:24.000000000 +0400 +++ new/glass-mat-lib-windows/src/BaseWnd.h 2011-09-01 19:00:24.000000000 +0400 @@ -8,9 +8,10 @@ class BaseWnd { public: - BaseWnd(); + BaseWnd(HWND ancestor = NULL); virtual ~BaseWnd(); + //XXX: might eliminate hParent and use m_ancestor instead HWND Create(HWND hParent, int x, int y, int width, int height, LPCTSTR lpWindowName, DWORD dwExStyle, DWORD dwStyle, HBRUSH hbrBackground); @@ -28,12 +29,16 @@ virtual BOOL EnterFullScreenMode(GlassView * view, BOOL animate, BOOL keepRatio) { return FALSE; } virtual void ExitFullScreenMode(BOOL animate) {} + HWND GetAncestor() const { return m_ancestor; } + void SetAncestor(HWND ancestor) { m_ancestor = ancestor; } + private: HWND m_hWnd; static LRESULT CALLBACK StaticWindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); static unsigned int sm_classNameCounter; + HWND m_ancestor; // either owner or parent. a window can't have both at once anyway protected: virtual LRESULT WindowProc(UINT msg, WPARAM wParam, LPARAM lParam) = 0; --- old/glass-mat-lib-windows/src/GlassWindow.cpp 2011-09-01 19:00:25.000000000 +0400 +++ new/glass-mat-lib-windows/src/GlassWindow.cpp 2011-09-01 19:00:25.000000000 +0400 @@ -32,8 +32,8 @@ HHOOK GlassWindow::sm_hCBTFilter = NULL; HWND GlassWindow::sm_grabWindow = NULL; -GlassWindow::GlassWindow(jobject jrefThis, bool isTransparent, bool isDecorated, HWND parent) - : BaseWnd(), +GlassWindow::GlassWindow(jobject jrefThis, bool isTransparent, bool isDecorated, bool isChild, HWND parentOrOwner) + : BaseWnd(parentOrOwner), ViewContainer(), m_state(Normal), m_isFocusable(true), @@ -45,7 +45,7 @@ m_hMenu(NULL), m_alpha(255), m_isEnabled(true), - m_parent(parent), + m_parent(isChild ? parentOrOwner : NULL), m_delegateWindow(NULL), m_isInFullScreen(false), m_beforeFullScreenStyle(0), @@ -639,9 +639,9 @@ // If this window doesn't belong to an owned windows hierarchy that // holds the grab currently, then the grab should be released. - for (HWND hwnd = GetHWND(); hwnd != NULL; hwnd = ::GetParent(hwnd)) - { - if (hwnd == sm_grabWindow) { + // Fix RT-16490: use GetAncestor() instead of ::GetParent() to support embedded windows + for (BaseWnd * window = this; window != NULL; window = BaseWnd::FromHandle(window->GetAncestor())) { + if (window->GetHWND() == sm_grabWindow) { return; } } @@ -687,6 +687,11 @@ ::SetParent(hwnd, hwnds[1]); + BaseWnd * window = BaseWnd::FromHandle(hwnd); + if (window) { + window->SetAncestor(hwnds[1]); + } + return TRUE; } @@ -694,8 +699,10 @@ { HWND * hwnds = (HWND*)lParam; - if ((HWND)::GetWindowLongPtr(hwnd, GWLP_HWNDPARENT) == hwnds[0] && GlassWindow::FromHandle(hwnd)) { + GlassWindow * window = NULL; + if ((HWND)::GetWindowLongPtr(hwnd, GWLP_HWNDPARENT) == hwnds[0] && (window = GlassWindow::FromHandle(hwnd)) != NULL) { ::SetWindowLongPtr(hwnd, GWLP_HWNDPARENT, (LONG_PTR)hwnds[1]); + window->SetAncestor(hwnds[1]); ::SetWindowPos(hwnd, hwnds[1], 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED | SWP_NOACTIVATE); } @@ -905,7 +912,7 @@ } GlassWindow *pWindow = - new GlassWindow(jThis, (mask & com_sun_glass_ui_Window_TRANSPARENT) != 0, (mask & com_sun_glass_ui_Window_TITLED) != 0); + new GlassWindow(jThis, (mask & com_sun_glass_ui_Window_TRANSPARENT) != 0, (mask & com_sun_glass_ui_Window_TITLED) != 0, false, owner); HWND hWnd = pWindow->Create(dwStyle, dwExStyle, hMonitor, owner); @@ -954,7 +961,7 @@ dwExStyle = 0; GlassWindow *pWindow = - new GlassWindow(jThis, false, false, parent); + new GlassWindow(jThis, false, false, true, parent); HWND hWnd = pWindow->Create(dwStyle, dwExStyle, NULL, parent); --- old/glass-mat-lib-windows/src/GlassWindow.h 2011-09-01 19:00:26.000000000 +0400 +++ new/glass-mat-lib-windows/src/GlassWindow.h 2011-09-01 19:00:26.000000000 +0400 @@ -8,7 +8,7 @@ class GlassWindow : public BaseWnd, public ViewContainer { public: - GlassWindow(jobject jrefThis, bool isTransparent, bool isDecorated, HWND parent = NULL); + GlassWindow(jobject jrefThis, bool isTransparent, bool isDecorated, bool isChild, HWND parentOrOwner); virtual ~GlassWindow(); static GlassWindow* FromHandle(HWND hWnd) {