+ return true;
+}
+
+#ifndef __WXWINCE__
+
+bool wxTopLevelWindowMSW::SetShape(const wxRegion& region)
+{
+ wxCHECK_MSG( HasFlag(wxFRAME_SHAPED), false,
+ _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
+
+ // The empty region signifies that the shape should be removed from the
+ // window.
+ if ( region.IsEmpty() )
+ {
+ if (::SetWindowRgn(GetHwnd(), NULL, TRUE) == 0)
+ {
+ wxLogLastError(_T("SetWindowRgn"));
+ return false;
+ }
+ return true;
+ }
+
+ // Windows takes ownership of the region, so
+ // we'll have to make a copy of the region to give to it.
+ DWORD noBytes = ::GetRegionData(GetHrgnOf(region), 0, NULL);
+ RGNDATA *rgnData = (RGNDATA*) new char[noBytes];
+ ::GetRegionData(GetHrgnOf(region), noBytes, rgnData);
+ HRGN hrgn = ::ExtCreateRegion(NULL, noBytes, rgnData);
+ delete[] (char*) rgnData;
+
+ // SetWindowRgn expects the region to be in coordinants
+ // relative to the window, not the client area. Figure
+ // out the offset, if any.
+ RECT rect;
+ DWORD dwStyle = ::GetWindowLong(GetHwnd(), GWL_STYLE);
+ DWORD dwExStyle = ::GetWindowLong(GetHwnd(), GWL_EXSTYLE);
+ ::GetClientRect(GetHwnd(), &rect);
+ ::AdjustWindowRectEx(&rect, dwStyle, FALSE, dwExStyle);
+ ::OffsetRgn(hrgn, -rect.left, -rect.top);
+
+ // Now call the shape API with the new region.
+ if (::SetWindowRgn(GetHwnd(), hrgn, TRUE) == 0)
+ {
+ wxLogLastError(_T("SetWindowRgn"));
+ return false;
+ }
+ return true;
+}
+
+#endif // !__WXWINCE__
+
+void wxTopLevelWindowMSW::RequestUserAttention(int flags)
+{
+ // check if we can use FlashWindowEx(): unfortunately an explicit test for
+ // FLASHW_STOP, for example, doesn't work because MSVC6 headers do #define
+ // it but don't provide FlashWindowEx() declaration
+#if (WINVER >= 0x0500 && (defined FLASHW_STOP))
+ // available in the headers, check if it is supported by the system
+ typedef BOOL (WINAPI *FlashWindowEx_t)(FLASHWINFO *pfwi);
+ FlashWindowEx_t s_pfnFlashWindowEx = NULL;
+ if ( !s_pfnFlashWindowEx )
+ {
+ wxDynamicLibrary dllUser32(_T("user32.dll"));
+ s_pfnFlashWindowEx = (FlashWindowEx_t)
+ dllUser32.GetSymbol(_T("FlashWindowEx"));
+
+ // we can safely unload user32.dll here, it's goign to remain loaded as
+ // long as the program is running anyhow
+ }
+
+ if ( s_pfnFlashWindowEx )
+ {
+ WinStruct<FLASHWINFO> fwi;
+ fwi.hwnd = GetHwnd();
+ fwi.dwFlags = FLASHW_ALL;
+ if ( flags & wxUSER_ATTENTION_INFO )
+ {
+ // just flash a few times
+ fwi.uCount = 3;
+ }
+ else // wxUSER_ATTENTION_ERROR
+ {
+ // flash until the user notices it
+ fwi.dwFlags |= FLASHW_TIMERNOFG;
+ }
+
+ s_pfnFlashWindowEx(&fwi);
+ }
+ else // FlashWindowEx() not available
+#endif // FlashWindowEx() defined
+ {
+ wxUnusedVar(flags);
+#ifndef __WXWINCE__
+ ::FlashWindow(GetHwnd(), TRUE);
+#endif // __WXWINCE__
+ }
+}
+
+// ----------------------------------------------------------------------------
+// wxTopLevelWindow event handling
+// ----------------------------------------------------------------------------
+
+// Default activation behaviour - set the focus for the first child
+// subwindow found.
+void wxTopLevelWindowMSW::OnActivate(wxActivateEvent& event)
+{
+ if ( event.GetActive() )
+ {
+ // restore focus to the child which was last focused unless we already
+ // have it
+ wxLogTrace(_T("focus"), _T("wxTLW %08x activated."), (int) m_hWnd);
+
+ wxWindow *winFocus = FindFocus();
+ if ( !winFocus || wxGetTopLevelParent(winFocus) != this )
+ {
+ wxWindow *parent = m_winLastFocused ? m_winLastFocused->GetParent()
+ : NULL;
+ if ( !parent )
+ {
+ parent = this;
+ }
+
+ wxSetFocusToChild(parent, &m_winLastFocused);
+ }
+ }
+ else // deactivating
+ {
+ // remember the last focused child if it is our child
+ m_winLastFocused = FindFocus();
+
+ if ( m_winLastFocused )
+ {
+ // let it know that it doesn't have focus any more
+ m_winLastFocused->HandleKillFocus((WXHWND)NULL);
+
+ // and don't remember it if it's a child from some other frame
+ if ( wxGetTopLevelParent(m_winLastFocused) != this )
+ {
+ m_winLastFocused = NULL;
+ }
+ }
+
+ wxLogTrace(_T("focus"),
+ _T("wxTLW %08x deactivated, last focused: %08x."),
+ (int) m_hWnd,
+ (int) (m_winLastFocused ? GetHwndOf(m_winLastFocused)
+ : NULL));
+
+ event.Skip();
+ }