From 3db5226517a63bcdc983e638f1a312764fe1312f Mon Sep 17 00:00:00 2001
From: Julian Smart <julian@anthemion.co.uk>
Date: Wed, 26 Oct 2005 09:32:10 +0000
Subject: [PATCH] Added parent window parameter to wxHelpController constructor
 and added SetParentWindow/GetParentWindow.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@36017 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---
 docs/changes.txt               |  2 ++
 docs/latex/wx/helpinst.tex     | 21 ++++++++++++++++++++-
 include/wx/generic/helpext.h   |  2 +-
 include/wx/helpbase.h          | 10 +++++++++-
 include/wx/html/helpctrl.h     |  2 +-
 include/wx/msw/helpbest.h      | 10 ++++++++--
 include/wx/msw/helpchm.h       |  2 +-
 include/wx/msw/helpwin.h       |  2 +-
 include/wx/msw/wince/helpwce.h |  2 +-
 src/generic/helpext.cpp        |  3 ++-
 src/html/helpctrl.cpp          |  5 +++--
 src/msw/helpbest.cpp           |  6 ++++--
 src/msw/helpchm.cpp            | 20 +++++++++++---------
 src/msw/helpwin.cpp            | 18 ++++++++++--------
 14 files changed, 74 insertions(+), 31 deletions(-)

diff --git a/docs/changes.txt b/docs/changes.txt
index 1145156eb9..262d9f5b6e 100644
--- a/docs/changes.txt
+++ b/docs/changes.txt
@@ -22,6 +22,8 @@ All (GUI):
 - All book based controls (notebook, treebook etc.) share now the same
   options for orientation (wxBK_TOP, wxBK_DEFAULT, ...) instead of duplicated
   wxLB_TOP, wxNB_TOP, wxCHB_TOP, wxTBK_TOP.
+- Added parent window parameter to wxHelpController constructor
+  and added SetParentWindow/GetParentWindow.
 
 wxMSW:
 
diff --git a/docs/latex/wx/helpinst.tex b/docs/latex/wx/helpinst.tex
index 3aa871d06b..9e660aab5d 100644
--- a/docs/latex/wx/helpinst.tex
+++ b/docs/latex/wx/helpinst.tex
@@ -73,10 +73,15 @@ wxHelpControllerBase\\
 
 \membersection{wxHelpController::wxHelpController}\label{wxhelpcontrollerctor}
 
-\func{}{wxHelpController}{\void}
+\func{}{wxHelpController}{\param{wxWindow*}{ parentWindow = NULL}}
 
 Constructs a help instance object, but does not invoke the help viewer.
 
+If you provide a window, it will be used by some help controller classes, such as
+wxCHMHelpController, wxWinHelpController and wxHtmlHelpController, as the
+parent for the help window instead of the value of \helpref{wxApp::GetTopWindow}{wxappgettopwindow}. You can also change the parent window later with 
+\helpref{wxHelpController::SetParentWindow}{wxhelpcontrollersetparentwindow}.
+
 \membersection{wxHelpController::\destruct{wxHelpController}}\label{wxhelpcontrollerdtor}
 
 \func{}{\destruct{wxHelpController}}{\void}
@@ -184,6 +189,13 @@ and just returns NULL.
 \docparam{flags}{This defaults to wxHELP\_NETSCAPE for wxExtHelpController, indicating
 that the viewer is a variant of Netscape Navigator.}
 
+\membersection{wxHelpController::GetParentWindow}\label{wxhelpcontrollergetparentwindow}
+
+\constfunc{virtual bool}{GetParentWindow}{\void}
+
+Returns the window to be used as the parent for the help window. This window is used
+by wxCHMHelpController, wxWinHelpController and wxHtmlHelpController.
+
 \membersection{wxHelpController::KeywordSearch}\label{wxhelpcontrollerkeywordsearch}
 
 \func{virtual bool}{KeywordSearch}{\param{const wxString\& }{keyWord}, \param{wxHelpSearchMode }{mode = wxHELP\_SEARCH\_ALL}}
@@ -235,6 +247,13 @@ open. {\it newFrameEachTime} is ignored.
 
 For all other help controllers this function has no effect.
 
+\membersection{wxHelpController::SetParentWindow}\label{wxhelpcontrollersetparentwindow}
+
+\func{virtual void}{SetParentWindow}{\param{wxWindow* }{parentWindow}}
+
+Sets the window to be used as the parent for the help window. This is used
+by wxCHMHelpController, wxWinHelpController and wxHtmlHelpController.
+
 \membersection{wxHelpController::SetViewer}\label{wxhelpcontrollersetviewer}
 
 \func{virtual void}{SetViewer}{\param{const wxString\& }{viewer}, \param{long}{ flags}}
diff --git a/include/wx/generic/helpext.h b/include/wx/generic/helpext.h
index 107ad52b2f..aaad7d3ff3 100644
--- a/include/wx/generic/helpext.h
+++ b/include/wx/generic/helpext.h
@@ -55,7 +55,7 @@ class WXDLLIMPEXP_ADV wxExtHelpController : public wxHelpControllerBase
 {
 DECLARE_CLASS(wxExtHelpController)
    public:
-   wxExtHelpController();
+   wxExtHelpController(wxWindow* parentWindow = NULL);
    ~wxExtHelpController();
 
    /** Tell it which browser to use.
diff --git a/include/wx/helpbase.h b/include/wx/helpbase.h
index 295088d4dd..613a87477c 100644
--- a/include/wx/helpbase.h
+++ b/include/wx/helpbase.h
@@ -35,7 +35,7 @@ enum wxHelpSearchMode
 class WXDLLEXPORT wxHelpControllerBase: public wxObject
 {
 public:
-    inline wxHelpControllerBase() {}
+    inline wxHelpControllerBase(wxWindow* parentWindow = NULL) { m_parentWindow = parentWindow; }
     inline ~wxHelpControllerBase() {}
 
     // Must call this to set the filename and server name.
@@ -88,6 +88,14 @@ public:
     virtual bool Quit() = 0;
     virtual void OnQuit() {}
 
+    /// Set the window that can optionally be used for the help window's parent.
+    virtual void SetParentWindow(wxWindow* win) { m_parentWindow = win; }
+
+    /// Get the window that can optionally be used for the help window's parent.
+    virtual wxWindow* GetParentWindow() const { return m_parentWindow; }
+
+protected:
+    wxWindow* m_parentWindow;
 private:
     DECLARE_CLASS(wxHelpControllerBase)
 };
diff --git a/include/wx/html/helpctrl.h b/include/wx/html/helpctrl.h
index e4efdcbbc6..a82c411e53 100644
--- a/include/wx/html/helpctrl.h
+++ b/include/wx/html/helpctrl.h
@@ -26,7 +26,7 @@ class WXDLLIMPEXP_HTML wxHtmlHelpController : public wxHelpControllerBase // wxE
     DECLARE_DYNAMIC_CLASS(wxHtmlHelpController)
 
 public:
-    wxHtmlHelpController(int style = wxHF_DEFAULT_STYLE);
+    wxHtmlHelpController(int style = wxHF_DEFAULT_STYLE, wxWindow* parentWindow = NULL);
     virtual ~wxHtmlHelpController();
 
     void SetTitleFormat(const wxString& format);
diff --git a/include/wx/msw/helpbest.h b/include/wx/msw/helpbest.h
index b5e7d83a44..a05c4e14de 100644
--- a/include/wx/msw/helpbest.h
+++ b/include/wx/msw/helpbest.h
@@ -20,8 +20,8 @@
 class WXDLLIMPEXP_HTML wxBestHelpController: public wxHelpControllerBase
 {
 public:
-    wxBestHelpController()
-        : m_helpControllerType( wxUseNone ),
+    wxBestHelpController(wxWindow* parentWindow = NULL)
+        : wxHelpControllerBase( parentWindow ), m_helpControllerType( wxUseNone ),
           m_helpController( NULL )
     {
     }
@@ -98,6 +98,12 @@ public:
                                                      newFrameEachTime );
     }
 
+    /// Set the window that can optionally be used for the help window's parent.
+    virtual void SetParentWindow(wxWindow* win) { m_helpController->SetParentWindow(win); }
+
+    /// Get the window that can optionally be used for the help window's parent.
+    virtual wxWindow* GetParentWindow() const { return m_helpController->GetParentWindow(); }
+
 protected:
     // Append/change extension if necessary.
     wxString GetValidFilename(const wxString& file) const;
diff --git a/include/wx/msw/helpchm.h b/include/wx/msw/helpchm.h
index 4a9fd55a85..72afc643dc 100644
--- a/include/wx/msw/helpchm.h
+++ b/include/wx/msw/helpchm.h
@@ -19,7 +19,7 @@
 class WXDLLEXPORT wxCHMHelpController : public wxHelpControllerBase
 {
 public:
-    wxCHMHelpController() { }
+    wxCHMHelpController(wxWindow* parentWindow = NULL): wxHelpControllerBase(parentWindow) { }
     virtual ~wxCHMHelpController();
 
     // Must call this to set the filename
diff --git a/include/wx/msw/helpwin.h b/include/wx/msw/helpwin.h
index d5f1a2626d..2bb0716395 100644
--- a/include/wx/msw/helpwin.h
+++ b/include/wx/msw/helpwin.h
@@ -23,7 +23,7 @@ class WXDLLEXPORT wxWinHelpController: public wxHelpControllerBase
     DECLARE_CLASS(wxWinHelpController)
 
 public:
-    wxWinHelpController() {}
+    wxWinHelpController(wxWindow* parentWindow = NULL): wxHelpControllerBase(parentWindow) {}
     ~wxWinHelpController() {}
 
     // Must call this to set the filename
diff --git a/include/wx/msw/wince/helpwce.h b/include/wx/msw/wince/helpwce.h
index c8fb31a2e3..735a6cbc1d 100644
--- a/include/wx/msw/wince/helpwce.h
+++ b/include/wx/msw/wince/helpwce.h
@@ -19,7 +19,7 @@
 class WXDLLEXPORT wxWinceHelpController : public wxHelpControllerBase
 {
 public:
-    wxWinceHelpController() {}
+    wxWinceHelpController(wxWindow* parentWindow): wxHelpControllerBase(parentWindow) {}
     virtual ~wxWinceHelpController() {}
 
     // Must call this to set the filename
diff --git a/src/generic/helpext.cpp b/src/generic/helpext.cpp
index f52d28f367..0b498470a0 100644
--- a/src/generic/helpext.cpp
+++ b/src/generic/helpext.cpp
@@ -70,7 +70,8 @@ IMPLEMENT_CLASS(wxExtHelpController, wxHelpControllerBase)
    and a file mapping numerical Section numbers to relative URLS.
 */
 
-wxExtHelpController::wxExtHelpController()
+wxExtHelpController::wxExtHelpController(wxWindow* parentWindow):
+    wxHelpControllerBase(parentWindow)
 {
    m_MapList = (wxList*) NULL;
    m_NumOfEntries = 0;
diff --git a/src/html/helpctrl.cpp b/src/html/helpctrl.cpp
index 5ec371074d..c52512ab36 100644
--- a/src/html/helpctrl.cpp
+++ b/src/html/helpctrl.cpp
@@ -43,7 +43,8 @@ FORCE_LINK(wxhtml_chm_support)
 
 IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpController, wxHelpControllerBase)
 
-wxHtmlHelpController::wxHtmlHelpController(int style)
+wxHtmlHelpController::wxHtmlHelpController(int style, wxWindow* parentWindow):
+    wxHelpControllerBase(parentWindow)
 {
     m_helpFrame = NULL;
     m_Config = NULL;
@@ -144,7 +145,7 @@ void wxHtmlHelpController::CreateHelpWindow()
     if (m_Config)
         m_helpFrame->UseConfig(m_Config, m_ConfigRoot);
 
-    m_helpFrame->Create(NULL, wxID_HTML_HELPFRAME, wxEmptyString, m_FrameStyle);
+    m_helpFrame->Create(GetParentWindow(), wxID_HTML_HELPFRAME, wxEmptyString, m_FrameStyle);
     m_helpFrame->SetTitleFormat(m_titleFormat);
 
     m_helpFrame->Show(true);
diff --git a/src/msw/helpbest.cpp b/src/msw/helpbest.cpp
index 4f656a752e..53244390bd 100644
--- a/src/msw/helpbest.cpp
+++ b/src/msw/helpbest.cpp
@@ -35,7 +35,7 @@ IMPLEMENT_DYNAMIC_CLASS( wxBestHelpController, wxHelpControllerBase )
 bool wxBestHelpController::Initialize( const wxString& filename )
 {
     // try wxCHMHelpController
-    wxCHMHelpController* chm = new wxCHMHelpController;
+    wxCHMHelpController* chm = new wxCHMHelpController(m_parentWindow);
 
     m_helpControllerType = wxUseChmHelp;
     // do not warn upon failure
@@ -44,6 +44,7 @@ bool wxBestHelpController::Initialize( const wxString& filename )
     if( chm->Initialize( GetValidFilename( filename ) ) )
     {
         m_helpController = chm;
+        m_parentWindow = NULL;
         return true;
     }
 
@@ -51,12 +52,13 @@ bool wxBestHelpController::Initialize( const wxString& filename )
     delete chm;
 
     // try wxHtmlHelpController
-    wxHtmlHelpController* html = new wxHtmlHelpController;
+    wxHtmlHelpController* html = new wxHtmlHelpController(wxHF_DEFAULT_STYLE, m_parentWindow);
 
     m_helpControllerType = wxUseHtmlHelp;
     if( html->Initialize( GetValidFilename( filename ) ) )
     {
         m_helpController = html;
+        m_parentWindow = NULL;
         return true;
     }
 
diff --git a/src/msw/helpchm.cpp b/src/msw/helpchm.cpp
index a34d2069c3..4bd7467b28 100644
--- a/src/msw/helpchm.cpp
+++ b/src/msw/helpchm.cpp
@@ -81,9 +81,11 @@ static void UnloadHtmlHelpLibrary()
     }
 }
 
-static HWND GetSuitableHWND()
+static HWND GetSuitableHWND(wxCHMHelpController* controller)
 {
-    if (wxTheApp->GetTopWindow())
+    if (controller->GetParentWindow())
+        return (HWND) controller->GetParentWindow()->GetHWND();
+    else if (wxTheApp->GetTopWindow())
         return (HWND) wxTheApp->GetTopWindow()->GetHWND();
     else
         return GetDesktopWindow();
@@ -114,7 +116,7 @@ bool wxCHMHelpController::DisplayContents()
 
     wxString str = GetValidFilename(m_helpFile);
 
-    gs_htmlHelp(GetSuitableHWND(), (const wxChar*) str, HH_DISPLAY_TOPIC, 0L);
+    gs_htmlHelp(GetSuitableHWND(this), (const wxChar*) str, HH_DISPLAY_TOPIC, 0L);
     return true;
 }
 
@@ -129,7 +131,7 @@ bool wxCHMHelpController::DisplaySection(const wxString& section)
     bool isFilename = (section.Find(wxT(".htm")) != wxNOT_FOUND);
 
     if (isFilename)
-        gs_htmlHelp(GetSuitableHWND(), (const wxChar*) str, HH_DISPLAY_TOPIC, (DWORD) (const wxChar*) section);
+        gs_htmlHelp(GetSuitableHWND(this), (const wxChar*) str, HH_DISPLAY_TOPIC, (DWORD) (const wxChar*) section);
     else
         KeywordSearch(section);
     return true;
@@ -142,7 +144,7 @@ bool wxCHMHelpController::DisplaySection(int section)
 
     wxString str = GetValidFilename(m_helpFile);
 
-    gs_htmlHelp(GetSuitableHWND(), (const wxChar*) str, HH_HELP_CONTEXT, (DWORD)section);
+    gs_htmlHelp(GetSuitableHWND(this), (const wxChar*) str, HH_HELP_CONTEXT, (DWORD)section);
     return true;
 }
 
@@ -167,7 +169,7 @@ bool wxCHMHelpController::DisplayContextPopup(int contextId)
     popup.pszFont = NULL;
     popup.pszText = NULL;
 
-    gs_htmlHelp(GetSuitableHWND(), (const wxChar*) str, HH_DISPLAY_TEXT_POPUP, (DWORD) & popup);
+    gs_htmlHelp(GetSuitableHWND(this), (const wxChar*) str, HH_DISPLAY_TEXT_POPUP, (DWORD) & popup);
     return true;
 }
 
@@ -184,7 +186,7 @@ bool wxCHMHelpController::DisplayTextPopup(const wxString& text, const wxPoint&
     popup.pszFont = NULL;
     popup.pszText = (const wxChar*) text;
 
-    gs_htmlHelp(GetSuitableHWND(), NULL, HH_DISPLAY_TEXT_POPUP, (DWORD) & popup);
+    gs_htmlHelp(GetSuitableHWND(this), NULL, HH_DISPLAY_TEXT_POPUP, (DWORD) & popup);
     return true;
 }
 
@@ -210,13 +212,13 @@ bool wxCHMHelpController::KeywordSearch(const wxString& k,
     link.pszWindow =    NULL ;
     link.fIndexOnFail = TRUE ;
 
-    gs_htmlHelp(GetSuitableHWND(), (const wxChar*) str, HH_KEYWORD_LOOKUP, (DWORD)& link);
+    gs_htmlHelp(GetSuitableHWND(this), (const wxChar*) str, HH_KEYWORD_LOOKUP, (DWORD)& link);
     return true;
 }
 
 bool wxCHMHelpController::Quit()
 {
-    gs_htmlHelp(GetSuitableHWND(), 0, HH_CLOSE_ALL, 0L);
+    gs_htmlHelp(GetSuitableHWND(this), 0, HH_CLOSE_ALL, 0L);
 
     return true;
 }
diff --git a/src/msw/helpwin.cpp b/src/msw/helpwin.cpp
index a65b579e4c..1fa93f0fe6 100644
--- a/src/msw/helpwin.cpp
+++ b/src/msw/helpwin.cpp
@@ -33,9 +33,11 @@
 
 #include <string.h>
 
-static HWND GetSuitableHWND()
+static HWND GetSuitableHWND(wxWinHelpController* controller)
 {
-    if (wxTheApp->GetTopWindow())
+    if (controller->GetParentWindow())
+        return (HWND) controller->GetParentWindow()->GetHWND();
+    else if (wxTheApp->GetTopWindow())
         return (HWND) wxTheApp->GetTopWindow()->GetHWND();
     else
         return GetDesktopWindow();
@@ -63,9 +65,9 @@ bool wxWinHelpController::DisplayContents(void)
     wxString str = GetValidFilename(m_helpFile);
 
 #if defined(__WIN95__)
-    return (WinHelp(GetSuitableHWND(), (const wxChar*) str, HELP_FINDER, 0L) != 0);
+    return (WinHelp(GetSuitableHWND(this), (const wxChar*) str, HELP_FINDER, 0L) != 0);
 #else
-    return (WinHelp(GetSuitableHWND(), (const wxChar*) str, HELP_CONTENTS, 0L) != 0);
+    return (WinHelp(GetSuitableHWND(this), (const wxChar*) str, HELP_CONTENTS, 0L) != 0);
 #endif
 }
 
@@ -76,7 +78,7 @@ bool wxWinHelpController::DisplaySection(int section)
 
     wxString str = GetValidFilename(m_helpFile);
 
-    return (WinHelp((HWND) wxTheApp->GetTopWindow()->GetHWND(), (const wxChar*) str, HELP_CONTEXT, (DWORD)section) != 0);
+    return (WinHelp(GetSuitableHWND(this), (const wxChar*) str, HELP_CONTEXT, (DWORD)section) != 0);
 }
 
 bool wxWinHelpController::DisplayContextPopup(int contextId)
@@ -85,7 +87,7 @@ bool wxWinHelpController::DisplayContextPopup(int contextId)
 
     wxString str = GetValidFilename(m_helpFile);
 
-    return (WinHelp((HWND) wxTheApp->GetTopWindow()->GetHWND(), (const wxChar*) str, HELP_CONTEXTPOPUP, (DWORD) contextId) != 0);
+    return (WinHelp(GetSuitableHWND(this), (const wxChar*) str, HELP_CONTEXTPOPUP, (DWORD) contextId) != 0);
 }
 
 bool wxWinHelpController::DisplayBlock(long block)
@@ -101,13 +103,13 @@ bool wxWinHelpController::KeywordSearch(const wxString& k,
 
     wxString str = GetValidFilename(m_helpFile);
 
-    return (WinHelp(GetSuitableHWND(), (const wxChar*) str, HELP_PARTIALKEY, (DWORD)(const wxChar*) k) != 0);
+    return (WinHelp(GetSuitableHWND(this), (const wxChar*) str, HELP_PARTIALKEY, (DWORD)(const wxChar*) k) != 0);
 }
 
 // Can't close the help window explicitly in WinHelp
 bool wxWinHelpController::Quit(void)
 {
-    return (WinHelp(GetSuitableHWND(), 0, HELP_QUIT, 0L) != 0);
+    return (WinHelp(GetSuitableHWND(this), 0, HELP_QUIT, 0L) != 0);
 }
 
 // Append extension if necessary.
-- 
2.50.0

