From 69b5cec2b0993ce4cd56f2e50ab94e5ebd20069c Mon Sep 17 00:00:00 2001
From: =?utf8?q?V=C3=A1clav=20Slav=C3=ADk?= <vslavik@fastmail.fm>
Date: Tue, 9 Sep 2003 17:29:11 +0000
Subject: [PATCH] applied Otto Wyss' patch to extend
 wxHelpController::KeywordSearch with mode argument (modified to the point of
 reimplementation)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@23450 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---
 docs/latex/wx/helpinst.tex  |   9 ++-
 docs/latex/wx/hthelpct.tex  |   7 ++-
 docs/latex/wx/hthlpfrm.tex  |   5 +-
 include/wx/helpbase.h       |  10 +++-
 include/wx/html/helpctrl.h  |   5 +-
 include/wx/html/helpfrm.h   |   4 +-
 include/wx/mac/helpxxxx.h   |   3 +-
 include/wx/msw/helpbest.h   |   5 +-
 include/wx/msw/helpchm.h    |   3 +-
 include/wx/msw/helpwin.h    |   3 +-
 include/wx/os2/helpwin.h    |   3 +-
 src/html/helpctrl.cpp       |   5 +-
 src/html/helpfrm.cpp        | 106 +++++++++++++++++++++++++-----------
 src/mac/carbon/helpxxxx.cpp |   3 +-
 src/mac/helpxxxx.cpp        |   3 +-
 src/msw/helpchm.cpp         |   3 +-
 src/msw/helpwin.cpp         |   3 +-
 src/os2/helpwin.cpp         |   3 +-
 18 files changed, 126 insertions(+), 57 deletions(-)

diff --git a/docs/latex/wx/helpinst.tex b/docs/latex/wx/helpinst.tex
index d550dcad41..758105130c 100644
--- a/docs/latex/wx/helpinst.tex
+++ b/docs/latex/wx/helpinst.tex
@@ -184,10 +184,13 @@ that the viewer is a variant of Netscape Navigator.}
 
 \membersection{wxHelpController::KeywordSearch}\label{wxhelpcontrollerkeywordsearch}
 
-\func{virtual bool}{KeywordSearch}{\param{const wxString\& }{keyWord}}
+\func{virtual bool}{KeywordSearch}{\param{const wxString\& }{keyWord}, \param{wxHelpSearchMode }{mode = wxHELP\_SEARCH\_ALL}}
 
-If the help viewer is not running, runs it, and searches for sections matching the given keyword. If one
-match is found, the file is displayed at this section.
+If the help viewer is not running, runs it, and searches for sections matching
+the given keyword. If one match is found, the file is displayed at this
+section. The optional parameter allows the search the index
+(wxHELP\_SEARCH\_INDEX) but this currently only supported by the
+wxHtmlHelpController.
 
 {\it WinHelp, MS HTML Help:} If more than one match is found, 
 the first topic is displayed.
diff --git a/docs/latex/wx/hthelpct.tex b/docs/latex/wx/hthelpct.tex
index e7230bb8e2..2ba72cebfb 100644
--- a/docs/latex/wx/hthelpct.tex
+++ b/docs/latex/wx/hthelpct.tex
@@ -163,10 +163,11 @@ Displays help window and focuses index panel.
 
 \membersection{wxHtmlHelpController::KeywordSearch}\label{wxhtmlhelpcontrollerkeywordsearch}
 
-\func{bool}{KeywordSearch}{\param{const wxString\& }{keyword}}
+\func{bool}{KeywordSearch}{\param{const wxString\& }{keyword}, \param{wxHelpSearchMode }{mode = wxHELP\_SEARCH\_ALL}}
 
-Displays help window, focuses search panel and starts searching.
-Returns true if the keyword was found.
+Displays help window, focuses search panel and starts searching.  Returns true
+if the keyword was found. Optionally it searches through the index (mode =
+wxHELP\_SEARCH\_INDEX), default the content (mode = wxHELP\_SEARCH\_ALL).
 
 {\bf Important:} KeywordSearch searches only pages listed in .hhc file(s).
 You should list all pages in the contents file.
diff --git a/docs/latex/wx/hthlpfrm.tex b/docs/latex/wx/hthlpfrm.tex
index 324264b8a8..bdf512fed1 100644
--- a/docs/latex/wx/hthlpfrm.tex
+++ b/docs/latex/wx/hthlpfrm.tex
@@ -121,9 +121,10 @@ Return wxHtmlHelpData object.
 
 \membersection{wxHtmlHelpFrame::KeywordSearch}\label{wxhtmlhelpframekeywordsearch}
 
-\func{bool}{KeywordSearch}{\param{const wxString\& }{keyword}}
+\func{bool}{KeywordSearch}{\param{const wxString\& }{keyword}, \param{wxHelpSearchMode }{mode = wxHELP\_SEARCH\_ALL}}
 
-Search for given keyword.
+Search for given keyword. Optionally it searches through the index (mode =
+wxHELP\_SEARCH\_INDEX), default the content (mode = wxHELP\_SEARCH\_ALL).
 
 \membersection{wxHtmlHelpFrame::ReadCustomization}\label{wxhtmlhelpframereadcustomization}
 
diff --git a/include/wx/helpbase.h b/include/wx/helpbase.h
index 3d1d60965c..dc7da84c07 100644
--- a/include/wx/helpbase.h
+++ b/include/wx/helpbase.h
@@ -28,6 +28,13 @@
 // Flags for SetViewer
 #define wxHELP_NETSCAPE     1
 
+// Search modes:
+enum wxHelpSearchMode
+{
+    wxHELP_SEARCH_INDEX,
+    wxHELP_SEARCH_ALL
+};
+
 // Defines the API for help controllers
 class WXDLLEXPORT wxHelpControllerBase: public wxObject
 {
@@ -63,7 +70,8 @@ public:
     // may override this for more specific behaviour.
     virtual bool DisplaySection(const wxString& section) { return KeywordSearch(section); }
     virtual bool DisplayBlock(long blockNo) = 0;
-    virtual bool KeywordSearch(const wxString& k) = 0;
+    virtual bool KeywordSearch(const wxString& k,
+                               wxHelpSearchMode mode = wxHELP_SEARCH_ALL) = 0;
     /// Allows one to override the default settings for the help frame.
     virtual void SetFrameParameters(const wxString& WXUNUSED(title),
         const wxSize& WXUNUSED(size),
diff --git a/include/wx/html/helpctrl.h b/include/wx/html/helpctrl.h
index d0b8691ca1..06e6bdc7ee 100644
--- a/include/wx/html/helpctrl.h
+++ b/include/wx/html/helpctrl.h
@@ -20,8 +20,8 @@
 
 #if wxUSE_WXHTML_HELP
 
-#include "wx/html/helpfrm.h"
 #include "wx/helpbase.h"
+#include "wx/html/helpfrm.h"
 
 #define wxID_HTML_HELPFRAME   (wxID_HIGHEST + 1)
 
@@ -42,7 +42,8 @@ public:
     bool Display(int id);
     bool DisplayContents();
     bool DisplayIndex();
-    bool KeywordSearch(const wxString& keyword);
+    bool KeywordSearch(const wxString& keyword,
+                       wxHelpSearchMode mode = wxHELP_SEARCH_ALL);
 
     wxHtmlHelpFrame* GetFrame() { return m_helpFrame; }
     void UseConfig(wxConfigBase *config, const wxString& rootpath = wxEmptyString);
diff --git a/include/wx/html/helpfrm.h b/include/wx/html/helpfrm.h
index 7912e48af9..0b18da854e 100644
--- a/include/wx/html/helpfrm.h
+++ b/include/wx/html/helpfrm.h
@@ -20,6 +20,7 @@
 
 #if wxUSE_WXHTML_HELP
 
+#include "wx/helpbase.h"
 #include "wx/html/helpdata.h"
 #include "wx/window.h"
 #include "wx/frame.h"
@@ -120,7 +121,8 @@ public:
     // * word may be pretended by + or -
     //   (+ : page must contain the word ; - : page can't contain the word)
     // * if there is no + or - before the word, + is default
-    bool KeywordSearch(const wxString& keyword);
+    bool KeywordSearch(const wxString& keyword,
+                       wxHelpSearchMode mode = wxHELP_SEARCH_ALL);
 
     void UseConfig(wxConfigBase *config, const wxString& rootpath = wxEmptyString)
         {
diff --git a/include/wx/mac/helpxxxx.h b/include/wx/mac/helpxxxx.h
index 1511557c78..a33c0737a5 100644
--- a/include/wx/mac/helpxxxx.h
+++ b/include/wx/mac/helpxxxx.h
@@ -37,7 +37,8 @@ class WXDLLEXPORT wxXXXXHelpController: public wxHelpControllerBase
   virtual bool DisplayContents();
   virtual bool DisplaySection(int sectionNo);
   virtual bool DisplayBlock(long blockNo);
-  virtual bool KeywordSearch(const wxString& k);
+  virtual bool KeywordSearch(const wxString& k,
+                             wxHelpSearchMode mode = wxHELP_SEARCH_ALL);
 
   virtual bool Quit();
   virtual void OnQuit();
diff --git a/include/wx/msw/helpbest.h b/include/wx/msw/helpbest.h
index c5a6d72f7e..f176eaa893 100644
--- a/include/wx/msw/helpbest.h
+++ b/include/wx/msw/helpbest.h
@@ -70,9 +70,10 @@ public:
         return m_helpController->DisplayTextPopup( text, pos );
     }
 
-    virtual bool KeywordSearch(const wxString& k)
+    virtual bool KeywordSearch(const wxString& k,
+                               wxHelpSearchMode mode = wxHELP_SEARCH_ALL);
     {
-        return m_helpController->KeywordSearch( k );
+        return m_helpController->KeywordSearch( k, mode );
     }
 
     virtual bool Quit()
diff --git a/include/wx/msw/helpchm.h b/include/wx/msw/helpchm.h
index 6c3cb03747..f6dfebf704 100644
--- a/include/wx/msw/helpchm.h
+++ b/include/wx/msw/helpchm.h
@@ -37,7 +37,8 @@ public:
     virtual bool DisplayBlock(long blockNo);
     virtual bool DisplayContextPopup(int contextId);
     virtual bool DisplayTextPopup(const wxString& text, const wxPoint& pos);
-    virtual bool KeywordSearch(const wxString& k);
+    virtual bool KeywordSearch(const wxString& k,
+                               wxHelpSearchMode mode = wxHELP_SEARCH_ALL);
     virtual bool Quit();
 
     wxString GetHelpFile() const { return m_helpFile; }
diff --git a/include/wx/msw/helpwin.h b/include/wx/msw/helpwin.h
index d0203d57e6..0e1a67541b 100644
--- a/include/wx/msw/helpwin.h
+++ b/include/wx/msw/helpwin.h
@@ -39,7 +39,8 @@ public:
     virtual bool DisplaySection(int sectionNo);
     virtual bool DisplayBlock(long blockNo);
     virtual bool DisplayContextPopup(int contextId);
-    virtual bool KeywordSearch(const wxString& k);
+    virtual bool KeywordSearch(const wxString& k,
+                               wxHelpSearchMode mode = wxHELP_SEARCH_ALL);
     virtual bool Quit();
 
     inline wxString GetHelpFile() const { return m_helpFile; }
diff --git a/include/wx/os2/helpwin.h b/include/wx/os2/helpwin.h
index 974ec9c38c..c38ea9f657 100644
--- a/include/wx/os2/helpwin.h
+++ b/include/wx/os2/helpwin.h
@@ -34,7 +34,8 @@ class WXDLLEXPORT wxWinHelpController: public wxHelpControllerBase
   virtual bool DisplayContents();
   virtual bool DisplaySection(int sectionNo);
   virtual bool DisplayBlock(long blockNo);
-  virtual bool KeywordSearch(const wxString& k);
+  virtual bool KeywordSearch(const wxString& k,
+                             wxHelpSearchMode mode = wxHELP_SEARCH_ALL);
 
   virtual bool Quit();
   virtual void OnQuit();
diff --git a/src/html/helpctrl.cpp b/src/html/helpctrl.cpp
index 1a7b41339b..9f1de8e409 100644
--- a/src/html/helpctrl.cpp
+++ b/src/html/helpctrl.cpp
@@ -319,10 +319,11 @@ bool wxHtmlHelpController::DisplayIndex()
     return success;
 }
 
-bool wxHtmlHelpController::KeywordSearch(const wxString& keyword)
+bool wxHtmlHelpController::KeywordSearch(const wxString& keyword,
+                                         wxHelpSearchMode mode)
 {
     CreateHelpWindow();
-    bool success = m_helpFrame->KeywordSearch(keyword);
+    bool success = m_helpFrame->KeywordSearch(keyword, mode);
     AddGrabIfNeeded();
     return success;
 }
diff --git a/src/html/helpfrm.cpp b/src/html/helpfrm.cpp
index b2487b2928..5c1dffd66e 100644
--- a/src/html/helpfrm.cpp
+++ b/src/html/helpfrm.cpp
@@ -657,12 +657,23 @@ bool wxHtmlHelpFrame::DisplayIndex()
 
 
 
-bool wxHtmlHelpFrame::KeywordSearch(const wxString& keyword)
+bool wxHtmlHelpFrame::KeywordSearch(const wxString& keyword,
+                                    wxHelpSearchMode mode)
 {
-    if (! (m_SearchList && m_SearchButton && m_SearchText && m_SearchChoice))
-        return FALSE;
+    if (mode == wxHELP_SEARCH_ALL)
+    {
+        if ( !(m_SearchList &&
+               m_SearchButton && m_SearchText && m_SearchChoice) )
+            return false;
+    }
+    else if (mode == wxHELP_SEARCH_INDEX)
+    {
+        if ( !(m_IndexList &&
+               m_IndexButton && m_IndexButtonAll && m_IndexText) )
+            return false;
+    }
 
-    int foundcnt = 0, curi;
+    int foundcnt = 0;
     wxString foundstr;
     wxString book = wxEmptyString;
 
@@ -672,41 +683,71 @@ bool wxHtmlHelpFrame::KeywordSearch(const wxString& keyword)
         m_HtmlWin->Show(TRUE);
         m_Splitter->SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
     }
-    m_NavigNotebook->SetSelection(m_SearchPage);
-    m_SearchList->Clear();
-    m_SearchText->SetValue(keyword);
-    m_SearchButton->Enable(FALSE);
-
-    if (m_SearchChoice->GetSelection() != 0)
-        book = m_SearchChoice->GetStringSelection();
-
-    wxHtmlSearchStatus status(m_Data, keyword,
-                              m_SearchCaseSensitive->GetValue(), m_SearchWholeWords->GetValue(),
-                              book);
 
-    wxProgressDialog progress(_("Searching..."), _("No matching page found yet"),
-                              status.GetMaxIndex(), this,
-                              wxPD_APP_MODAL | wxPD_CAN_ABORT | wxPD_AUTO_HIDE);
-
-    while (status.IsActive())
+    if (mode == wxHELP_SEARCH_ALL)
     {
-        curi = status.GetCurIndex();
-        if (curi % 32 == 0 && progress.Update(curi) == FALSE)
-            break;
-        if (status.Search())
+        m_NavigNotebook->SetSelection(m_SearchPage);
+        m_SearchList->Clear();
+        m_SearchText->SetValue(keyword);
+        m_SearchButton->Enable(false);
+
+        if (m_SearchChoice->GetSelection() != 0)
+            book = m_SearchChoice->GetStringSelection();
+
+        wxHtmlSearchStatus status(m_Data, keyword,
+                                  m_SearchCaseSensitive->GetValue(),
+                                  m_SearchWholeWords->GetValue(),
+                                  book);
+
+        wxProgressDialog progress(_("Searching..."),
+                                  _("No matching page found yet"),
+                                  status.GetMaxIndex(), this,
+                                  wxPD_APP_MODAL | wxPD_CAN_ABORT | wxPD_AUTO_HIDE);
+
+        int curi;
+        while (status.IsActive())
         {
-            foundstr.Printf(_("Found %i matches"), ++foundcnt);
-            progress.Update(status.GetCurIndex(), foundstr);
-            m_SearchList->Append(status.GetName(), status.GetContentsItem());
+            curi = status.GetCurIndex();
+            if (curi % 32 == 0 && progress.Update(curi) == FALSE)
+                break;
+            if (status.Search())
+            {
+                foundstr.Printf(_("Found %i matches"), ++foundcnt);
+                progress.Update(status.GetCurIndex(), foundstr);
+                m_SearchList->Append(status.GetName(), status.GetContentsItem());
+            }
         }
+
+        m_SearchButton->Enable(TRUE);
+        m_SearchText->SetSelection(0, keyword.Length());
+        m_SearchText->SetFocus();
+    }
+    else if (mode == wxHELP_SEARCH_INDEX)
+    {
+        m_NavigNotebook->SetSelection(m_IndexPage);
+        m_IndexList->Clear();
+        m_IndexButton->Enable(false);
+        m_IndexButtonAll->Enable(false);
+        m_IndexText->SetValue(keyword);
+
+        wxCommandEvent dummy;
+        OnIndexFind(dummy); // what a hack...
+        m_IndexButton->Enable(true);
+        m_IndexButtonAll->Enable(true);
+        foundcnt = m_IndexList->GetCount();
     }
 
-    m_SearchButton->Enable(TRUE);
-    m_SearchText->SetSelection(0, keyword.Length());
-    m_SearchText->SetFocus();
     if (foundcnt)
     {
-        wxHtmlContentsItem *it = (wxHtmlContentsItem*) m_SearchList->GetClientData(0);
+        wxHtmlContentsItem *it;
+        if (mode == wxHELP_SEARCH_ALL)
+        {
+            it = (wxHtmlContentsItem*) m_SearchList->GetClientData(0);
+        }
+        else if (mode == wxHELP_SEARCH_INDEX)
+        {
+            it = (wxHtmlContentsItem*) m_IndexList->GetClientData(0);
+        }
         if (it)
         {
             m_HtmlWin->LoadPage(it->GetFullPath());
@@ -1489,7 +1530,8 @@ void wxHtmlHelpFrame::OnSearch(wxCommandEvent& WXUNUSED(event))
 {
     wxString sr = m_SearchText->GetLineText(0);
 
-    if (sr != wxEmptyString) KeywordSearch(sr);
+    if (!sr.empty())
+        KeywordSearch(sr, wxHELP_SEARCH_ALL);
 }
 
 void wxHtmlHelpFrame::OnBookmarksSel(wxCommandEvent& WXUNUSED(event))
diff --git a/src/mac/carbon/helpxxxx.cpp b/src/mac/carbon/helpxxxx.cpp
index f41727e61b..7d0e4d1531 100644
--- a/src/mac/carbon/helpxxxx.cpp
+++ b/src/mac/carbon/helpxxxx.cpp
@@ -62,7 +62,8 @@ bool wxXXXXHelpController::DisplayBlock(long block)
     return FALSE;
 }
 
-bool wxXXXXHelpController::KeywordSearch(const wxString& k)
+bool wxXXXXHelpController::KeywordSearch(const wxString& k,
+                                         wxHelpSearchMode WXUNUSED(mode))
 {
     if (m_helpFile == "") return FALSE;
 
diff --git a/src/mac/helpxxxx.cpp b/src/mac/helpxxxx.cpp
index f41727e61b..7d0e4d1531 100644
--- a/src/mac/helpxxxx.cpp
+++ b/src/mac/helpxxxx.cpp
@@ -62,7 +62,8 @@ bool wxXXXXHelpController::DisplayBlock(long block)
     return FALSE;
 }
 
-bool wxXXXXHelpController::KeywordSearch(const wxString& k)
+bool wxXXXXHelpController::KeywordSearch(const wxString& k,
+                                         wxHelpSearchMode WXUNUSED(mode))
 {
     if (m_helpFile == "") return FALSE;
 
diff --git a/src/msw/helpchm.cpp b/src/msw/helpchm.cpp
index 902829aca0..7ad6367747 100644
--- a/src/msw/helpchm.cpp
+++ b/src/msw/helpchm.cpp
@@ -197,7 +197,8 @@ bool wxCHMHelpController::DisplayBlock(long block)
     return DisplaySection(block);
 }
 
-bool wxCHMHelpController::KeywordSearch(const wxString& k)
+bool wxCHMHelpController::KeywordSearch(const wxString& k,
+                                        wxHelpSearchMode WXUNUSED(mode))
 {
     if (m_helpFile.IsEmpty()) return FALSE;
 
diff --git a/src/msw/helpwin.cpp b/src/msw/helpwin.cpp
index b2d5613556..abaa425609 100644
--- a/src/msw/helpwin.cpp
+++ b/src/msw/helpwin.cpp
@@ -98,7 +98,8 @@ bool wxWinHelpController::DisplayBlock(long block)
     return TRUE;
 }
 
-bool wxWinHelpController::KeywordSearch(const wxString& k)
+bool wxWinHelpController::KeywordSearch(const wxString& k,
+                                        wxHelpSearchMode WXUNUSED(mode))
 {
     if (m_helpFile.IsEmpty()) return FALSE;
     
diff --git a/src/os2/helpwin.cpp b/src/os2/helpwin.cpp
index 9e84bbf129..9c398cc185 100644
--- a/src/os2/helpwin.cpp
+++ b/src/os2/helpwin.cpp
@@ -108,7 +108,8 @@ bool wxWinHelpController::DisplayBlock(long block)
     return FALSE;
 }
 
-bool wxWinHelpController::KeywordSearch(const wxString& k)
+bool wxWinHelpController::KeywordSearch(const wxString& k,
+                                        wxHelpSearchMode WXUNUSED(mode))
 {
     if (m_helpFile == "") return FALSE;
 
-- 
2.49.0