diff --git a/samples/html/helpview/helpview.cpp b/samples/html/helpview/helpview.cpp index ba4c62925d..584ba00e97 100644 --- a/samples/html/helpview/helpview.cpp +++ b/samples/html/helpview/helpview.cpp @@ -43,20 +43,34 @@ class MyApp : public wxApp virtual bool OnInit(); virtual int OnExit(); - private: - wxHtmlHelpController *help; + /// Respond to idle event + void OnIdle(wxIdleEvent& event); + +private: + bool m_exitIfNoMainWindow; + wxHtmlHelpController * help; +DECLARE_EVENT_TABLE() }; IMPLEMENT_APP(MyApp) +BEGIN_EVENT_TABLE(MyApp, wxApp) + EVT_IDLE(MyApp::OnIdle) +END_EVENT_TABLE() bool MyApp::OnInit() { + m_exitIfNoMainWindow = false; #ifdef __WXMOTIF__ delete wxLog::SetActiveTarget(new wxLogStderr); // So dialog boxes aren't used #endif + // Don't exit on frame deletion, since the help window is programmed + // to cause the app to exit even if it is still open. We need to have the app + // close by other means. + SetExitOnFrameDelete(false); + wxInitAllImageHandlers(); wxFileSystem::AddHandler(new wxZipFSHandler); @@ -80,10 +94,17 @@ bool MyApp::OnInit() #endif help -> DisplayContents(); + SetTopWindow(help->GetFrame()); + m_exitIfNoMainWindow = true; return true; } +void MyApp::OnIdle(wxIdleEvent& event) +{ + if (m_exitIfNoMainWindow && !GetTopWindow()) + ExitMainLoop(); +} int MyApp::OnExit() { diff --git a/utils/helpview/src/helpview.cpp b/utils/helpview/src/helpview.cpp index 72b3daa6a3..b5bfbf813e 100644 --- a/utils/helpview/src/helpview.cpp +++ b/utils/helpview/src/helpview.cpp @@ -42,11 +42,16 @@ protected: IMPLEMENT_APP(hvApp) +BEGIN_EVENT_TABLE(hvApp, wxApp) + EVT_IDLE(hvApp::OnIdle) +END_EVENT_TABLE() + hvApp::hvApp() { #if wxUSE_IPC m_server = NULL; #endif + m_exitIfNoMainWindow = false; } bool hvApp::OnInit() @@ -55,6 +60,11 @@ bool hvApp::OnInit() delete wxLog::SetActiveTarget(new wxLogStderr); // So dialog boxes aren't used #endif + // Don't exit on frame deletion, since the help window is programmed + // to cause the app to exit even if it is still open. We need to have the app + // close by other means. + SetExitOnFrameDelete(false); + wxArtProvider::Push(new AlternateArtProvider); #ifdef __WXMAC__ @@ -218,10 +228,17 @@ bool hvApp::OnInit() #endif m_helpController->DisplayContents(); + SetTopWindow(m_helpController->GetFrame()); + m_exitIfNoMainWindow = true; return true; } +void hvApp::OnIdle(wxIdleEvent& event) +{ + if (m_exitIfNoMainWindow && !GetTopWindow()) + ExitMainLoop(); +} int hvApp::OnExit() { diff --git a/utils/helpview/src/helpview.h b/utils/helpview/src/helpview.h index bd1de5fd6c..b77599b438 100644 --- a/utils/helpview/src/helpview.h +++ b/utils/helpview/src/helpview.h @@ -50,14 +50,19 @@ public: wxList& GetConnections() { return m_connections; } #endif + /// Respond to idle event + void OnIdle(wxIdleEvent& event); + private: wxHtmlHelpController* m_helpController; + bool m_exitIfNoMainWindow; #if wxUSE_IPC wxList m_connections; hvServer* m_server; #endif +DECLARE_EVENT_TABLE() }; #if wxUSE_IPC