+// ----------------------------------------------------------------------------
+// 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
+ wxLogTrace(_T("focus"), _T("wxTLW %08x activated."), (int) m_hWnd);
+
+ 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);
+ }
+
+ // so we NULL it out if it's a child from some other frame
+ wxWindow *win = m_winLastFocused;
+ while ( win )
+ {
+ if ( win->IsTopLevel() )
+ {
+ if ( win != this )
+ {
+ m_winLastFocused = NULL;
+ }
+
+ break;
+ }
+
+ win = win->GetParent();
+ }
+
+ wxLogTrace(_T("focus"),
+ _T("wxTLW %08x deactivated, last focused: %08x."),
+ (int) m_hWnd,
+ (int) (m_winLastFocused ? GetHwndOf(m_winLastFocused)
+ : NULL));
+
+ event.Skip();
+ }
+}
+
+// the DialogProc for all wxWindows dialogs
+LONG APIENTRY _EXPORT
+wxDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
+{
+ switch ( message )
+ {
+ case WM_INITDIALOG:
+ // for this message, returning TRUE tells system to set focus to
+ // the first control in the dialog box, but as we set the focus
+ // ourselves, we return FALSE from here as well, so fall through
+
+ default:
+ // for all the other ones, FALSE means that we didn't process the
+ // message
+ return FALSE;
+ }
+}
+
+// ============================================================================
+// wxTLWHiddenParentModule implementation
+// ============================================================================
+
+HWND wxTLWHiddenParentModule::ms_hwnd = NULL;
+
+const wxChar *wxTLWHiddenParentModule::ms_className = NULL;
+
+bool wxTLWHiddenParentModule::OnInit()
+{
+ ms_hwnd = NULL;
+ ms_className = NULL;
+
+ return TRUE;
+}
+
+void wxTLWHiddenParentModule::OnExit()
+{
+ if ( ms_hwnd )
+ {
+ if ( !::DestroyWindow(ms_hwnd) )
+ {
+ wxLogLastError(_T("DestroyWindow(hidden TLW parent)"));
+ }
+
+ ms_hwnd = NULL;
+ }
+
+ if ( ms_className )
+ {
+ if ( !::UnregisterClass(ms_className, wxGetInstance()) )
+ {
+ wxLogLastError(_T("UnregisterClass(\"wxTLWHiddenParent\")"));
+ }
+
+ ms_className = NULL;
+ }
+}
+
+/* static */
+HWND wxTLWHiddenParentModule::GetHWND()
+{
+ if ( !ms_hwnd )
+ {
+ if ( !ms_className )
+ {
+ static const wxChar *HIDDEN_PARENT_CLASS = _T("wxTLWHiddenParent");
+
+ WNDCLASS wndclass;
+ wxZeroMemory(wndclass);
+
+ wndclass.lpfnWndProc = DefWindowProc;
+ wndclass.hInstance = wxGetInstance();
+ wndclass.lpszClassName = HIDDEN_PARENT_CLASS;
+
+ if ( !::RegisterClass(&wndclass) )
+ {
+ wxLogLastError(_T("RegisterClass(\"wxTLWHiddenParent\")"));
+ }
+ else
+ {
+ ms_className = HIDDEN_PARENT_CLASS;
+ }
+ }
+
+ ms_hwnd = ::CreateWindow(ms_className, _T(""), 0, 0, 0, 0, 0, NULL,
+ (HMENU)NULL, wxGetInstance(), NULL);
+ if ( !ms_hwnd )
+ {
+ wxLogLastError(_T("CreateWindow(hidden TLW parent)"));
+ }
+ }
+
+ return ms_hwnd;
+}
+