]> git.saurik.com Git - wxWidgets.git/commitdiff
finally applied the helpbest patch
authorVáclav Slavík <vslavik@fastmail.fm>
Sat, 1 Sep 2001 12:59:08 +0000 (12:59 +0000)
committerVáclav Slavík <vslavik@fastmail.fm>
Sat, 1 Sep 2001 12:59:08 +0000 (12:59 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@11534 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

distrib/msw/tmake/filelist.txt
include/wx/msw/helpbest.h [new file with mode: 0644]
samples/help/demo.cpp
src/msw/helpbest.cpp [new file with mode: 0644]

index c78294b42cebb2571dce596c1dd965e15da8a641..feb720f70cc880216dc4400e309b69fd2ec5ff0b 100644 (file)
@@ -262,6 +262,7 @@ dragimag.cpp        MSW
 dropsrc.cpp    MSW     OLE
 droptgt.cpp    MSW     OLE
 enhmeta.cpp    MSW     Win32Only
 dropsrc.cpp    MSW     OLE
 droptgt.cpp    MSW     OLE
 enhmeta.cpp    MSW     Win32Only
+helpbest.cpp   MSW     Win32Only
 evtloop.cpp    MSW     LowLevel
 fdrepdlg.cpp   MSW     Win32Only
 filedlg.cpp    MSW
 evtloop.cpp    MSW     LowLevel
 fdrepdlg.cpp   MSW     Win32Only
 filedlg.cpp    MSW
@@ -922,6 +923,7 @@ minifram.h  MotifH
 msgdlg.h       MotifH
 palette.h      MotifH
 pen.h  MotifH
 msgdlg.h       MotifH
 palette.h      MotifH
 pen.h  MotifH
+helpbest.h     MSWH
 print.h        MotifH
 printdlg.h     MotifH
 private.h      MotifH
 print.h        MotifH
 printdlg.h     MotifH
 private.h      MotifH
diff --git a/include/wx/msw/helpbest.h b/include/wx/msw/helpbest.h
new file mode 100644 (file)
index 0000000..cc3e41b
--- /dev/null
@@ -0,0 +1,128 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name:        helpbest.h
+// Purpose:     Tries to load MS HTML Help, falls back to wxHTML upon failure
+// Author:      Mattia Barbon
+// Modified by:
+// Created:     02/04/2001
+// RCS-ID:      $Id$
+// Copyright:   (c) Mattia Barbon
+// Licence:    wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef _WX_HELPBEST_H_
+#define _WX_HELPBEST_H_
+
+#ifdef __GNUG__
+#pragma interface "helpbest.h"
+#endif
+
+#include "wx/wx.h"
+
+#if wxUSE_HELP && wxUSE_MS_HTML_HELP && defined(__WIN95__) && wxUSE_WXHTML_HELP
+
+#include "wx/helpbase.h"
+
+class WXDLLEXPORT wxBestHelpController: public wxHelpControllerBase
+{
+    DECLARE_DYNAMIC_CLASS(wxBestHelpController)
+        
+public:
+    wxBestHelpController():m_helpControllerType( wxUseNone ),
+        m_helpController( 0 ) {}
+    ~wxBestHelpController() { delete m_helpController; }
+    
+    // Must call this to set the filename
+    virtual bool Initialize(const wxString& file);
+    
+    // If file is "", reloads file given in Initialize
+    virtual bool LoadFile(const wxString& file = wxEmptyString)
+    {
+        wxASSERT( m_helpController );
+        return m_helpController->LoadFile( GetValidFilename( file ) );
+    }
+
+    virtual bool DisplayContents()
+    {
+        wxASSERT( m_helpController );
+        return m_helpController->DisplayContents();
+    }
+
+    virtual bool DisplaySection(int sectionNo)
+    {
+        wxASSERT( m_helpController );
+        return m_helpController->DisplaySection( sectionNo );
+    }
+
+    virtual bool DisplaySection(const wxString& section)
+    {
+        wxASSERT( m_helpController );
+        return m_helpController->DisplaySection( section );
+    }
+
+    virtual bool DisplayBlock(long blockNo)
+    {
+        wxASSERT( m_helpController );
+        return m_helpController->DisplayBlock( blockNo );
+    }
+
+    virtual bool DisplayContextPopup(int contextId)
+    {
+        wxASSERT( m_helpController );
+        return m_helpController->DisplayContextPopup( contextId );
+    }
+
+    virtual bool DisplayTextPopup(const wxString& text, const wxPoint& pos)
+    {
+        wxASSERT( m_helpController );
+        return m_helpController->DisplayTextPopup( text, pos );
+    }
+
+    virtual bool KeywordSearch(const wxString& k)
+    {
+        wxASSERT( m_helpController );
+        return m_helpController->KeywordSearch( k );
+    }
+
+    virtual bool Quit()
+    {
+        wxASSERT( m_helpController );
+        return m_helpController->Quit();
+    }
+
+    /// Allows one to override the default settings for the help frame.
+    virtual void SetFrameParameters(const wxString& title,
+        const wxSize& size,
+        const wxPoint& pos = wxDefaultPosition,
+        bool newFrameEachTime = FALSE)
+    {
+        wxASSERT( m_helpController );
+        m_helpController->SetFrameParameters( title, size, pos,
+                                              newFrameEachTime );
+    }
+
+    /// Obtains the latest settings used by the help frame and the help 
+    /// frame.
+    virtual wxFrame *GetFrameParameters(wxSize *size = NULL,
+        wxPoint *pos = NULL,
+        bool *newFrameEachTime = NULL)
+    {
+        wxASSERT( m_helpController );
+        return m_helpController->GetFrameParameters( size, pos,
+                                                     newFrameEachTime );
+    }
+
+protected:
+    // Append/change extension if necessary.
+    wxString GetValidFilename(const wxString& file) const;
+    
+protected:
+    enum HelpControllerType { wxUseNone, wxUseHtmlHelp, wxUseChmHelp };
+
+    HelpControllerType m_helpControllerType;
+    wxHelpControllerBase* m_helpController;
+};
+
+#endif // wxUSE_HELP && wxUSE_MS_HTML_HELP && defined(__WIN95__) && wxUSE_WXHTML_HELP
+
+#endif
+    // _WX_HELPBEST_H_
index 3c430026592f55cd0023852038c1941e1ff809f0..f97e551d2496bc94dcb593be85decae15971f396 100644 (file)
 #include "wx/msw/helpchm.h"
 #endif
 
 #include "wx/msw/helpchm.h"
 #endif
 
+#if wxUSE_MS_HTML_HELP && wxUSE_WXHTML_HELP
+#include "wx/msw/helpbest.h"
+#endif
+
 // ----------------------------------------------------------------------------
 // ressources
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
 // ressources
 // ----------------------------------------------------------------------------
@@ -113,6 +117,9 @@ public:
 #if wxUSE_MS_HTML_HELP
     wxCHMHelpController& GetMSHtmlHelpController() { return m_msHtmlHelp; }
 #endif
 #if wxUSE_MS_HTML_HELP
     wxCHMHelpController& GetMSHtmlHelpController() { return m_msHtmlHelp; }
 #endif
+#if wxUSE_MS_HTML_HELP && wxUSE_WXHTML_HELP
+    wxBestHelpController& GetBestHelpController() { return m_bestHelp; }
+#endif
 
     // event handlers (these functions should _not_ be virtual)
     void OnQuit(wxCommandEvent& event);
 
     // event handlers (these functions should _not_ be virtual)
     void OnQuit(wxCommandEvent& event);
@@ -120,6 +127,7 @@ public:
     void OnHtmlHelp(wxCommandEvent& event);
     void OnAdvancedHtmlHelp(wxCommandEvent& event);
     void OnMSHtmlHelp(wxCommandEvent& event);
     void OnHtmlHelp(wxCommandEvent& event);
     void OnAdvancedHtmlHelp(wxCommandEvent& event);
     void OnMSHtmlHelp(wxCommandEvent& event);
+    void OnBestHelp(wxCommandEvent& event);
 
     void OnShowContextHelp(wxCommandEvent& event);
     void OnShowDialogContextHelp(wxCommandEvent& event);
 
     void OnShowContextHelp(wxCommandEvent& event);
     void OnShowDialogContextHelp(wxCommandEvent& event);
@@ -140,6 +148,10 @@ private:
     wxCHMHelpController     m_msHtmlHelp;
 #endif
 
     wxCHMHelpController     m_msHtmlHelp;
 #endif
 
+#if wxUSE_MS_HTML_HELP && wxUSE_WXHTML_HELP
+    wxBestHelpController    m_bestHelp;
+#endif
+
     // any class wishing to process wxWindows events must use this macro
    DECLARE_EVENT_TABLE()
 };
     // any class wishing to process wxWindows events must use this macro
    DECLARE_EVENT_TABLE()
 };
@@ -190,6 +202,12 @@ enum
     HelpDemo_MS_Html_Help_Help,
     HelpDemo_MS_Html_Help_Search,
 
     HelpDemo_MS_Html_Help_Help,
     HelpDemo_MS_Html_Help_Search,
 
+    HelpDemo_Best_Help_Index,
+    HelpDemo_Best_Help_Classes,
+    HelpDemo_Best_Help_Functions,
+    HelpDemo_Best_Help_Help,
+    HelpDemo_Best_Help_Search,
+
     HelpDemo_Help_KDE,
     HelpDemo_Help_GNOME,
     HelpDemo_Help_Netscape,
     HelpDemo_Help_KDE,
     HelpDemo_Help_GNOME,
     HelpDemo_Help_Netscape,
@@ -232,6 +250,8 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
     EVT_MENU(HelpDemo_MS_Html_Help_Help, MyFrame::OnMSHtmlHelp)
     EVT_MENU(HelpDemo_MS_Html_Help_Search, MyFrame::OnMSHtmlHelp)
 
     EVT_MENU(HelpDemo_MS_Html_Help_Help, MyFrame::OnMSHtmlHelp)
     EVT_MENU(HelpDemo_MS_Html_Help_Search, MyFrame::OnMSHtmlHelp)
 
+    EVT_MENU(HelpDemo_Best_Help_Index, MyFrame::OnBestHelp)
+
     EVT_MENU(HelpDemo_Help_KDE, MyFrame::OnHelp)
     EVT_MENU(HelpDemo_Help_GNOME, MyFrame::OnHelp)
     EVT_MENU(HelpDemo_Help_Netscape, MyFrame::OnHelp)
     EVT_MENU(HelpDemo_Help_KDE, MyFrame::OnHelp)
     EVT_MENU(HelpDemo_Help_GNOME, MyFrame::OnHelp)
     EVT_MENU(HelpDemo_Help_Netscape, MyFrame::OnHelp)
@@ -297,6 +317,21 @@ bool MyApp::OnInit()
         return FALSE;
     }
 
         return FALSE;
     }
 
+#if wxUSE_MS_HTML_HELP
+    if( !frame->GetMSHtmlHelpController().Initialize("doc") )
+    {
+        wxLogError("Cannot initialize the MS HTML Help system.");
+    }
+#endif
+
+#if wxUSE_MS_HTML_HELP && wxUSE_WXHTML_HELP
+    // you need to call Initialize in order to use wxBestHelpController
+    if( !frame->GetBestHelpController().Initialize("doc") )
+    {
+        wxLogError("Cannot initialize the best help system, aborting.");
+    }
+#endif
+
 #if USE_HTML_HELP
     // initialise the standard HTML help system: this means that the HTML docs are in the
     // subdirectory doc for platforms using HTML help
 #if USE_HTML_HELP
     // initialise the standard HTML help system: this means that the HTML docs are in the
     // subdirectory doc for platforms using HTML help
@@ -319,7 +354,8 @@ bool MyApp::OnInit()
     }
 #endif
 
     }
 #endif
 
-#if defined(__WXMSW__) && wxUSE_MS_HTML_HELP
+#if 0
+    // defined(__WXMSW__) && wxUSE_MS_HTML_HELP
     wxString path(wxGetCwd());
     if ( !frame->GetMSHtmlHelpController().Initialize(path + "\\doc.chm") )
     {
     wxString path(wxGetCwd());
     if ( !frame->GetMSHtmlHelpController().Initialize(path + "\\doc.chm") )
     {
@@ -387,6 +423,11 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
     menuFile->Append(HelpDemo_MS_Html_Help_Search, "MS HTML &Search help...");
 #endif
 
     menuFile->Append(HelpDemo_MS_Html_Help_Search, "MS HTML &Search help...");
 #endif
 
+#if wxUSE_MS_HTML_HELP && wxUSE_WXHTML_HELP
+    menuFile->AppendSeparator();
+    menuFile->Append(HelpDemo_Best_Help_Index, "Best &Help Index...");
+#endif
+
 #ifndef __WXMSW__
 #if !wxUSE_HTML
     menuFile->AppendSeparator();
 #ifndef __WXMSW__
 #if !wxUSE_HTML
     menuFile->AppendSeparator();
@@ -470,6 +511,13 @@ void MyFrame::OnMSHtmlHelp(wxCommandEvent& event)
 #endif
 }
 
 #endif
 }
 
+void MyFrame::OnBestHelp(wxCommandEvent& event)
+{
+#if wxUSE_MS_HTML_HELP && wxUSE_HTML
+    ShowHelp(event.GetId(), m_bestHelp);
+#endif
+}
+
 /*
  Notes: ShowHelp uses section ids for displaying particular topics,
  but you might want to use a unique keyword to display a topic, instead.
 /*
  Notes: ShowHelp uses section ids for displaying particular topics,
  but you might want to use a unique keyword to display a topic, instead.
@@ -545,6 +593,7 @@ void MyFrame::ShowHelp(int commandId, wxHelpControllerBase& helpController)
    case HelpDemo_Html_Help_Classes:
    case HelpDemo_Advanced_Html_Help_Classes:
    case HelpDemo_MS_Html_Help_Classes:
    case HelpDemo_Html_Help_Classes:
    case HelpDemo_Advanced_Html_Help_Classes:
    case HelpDemo_MS_Html_Help_Classes:
+   case HelpDemo_Best_Help_Classes:
       helpController.DisplaySection(2);
       //helpController.DisplaySection("Classes"); // An alternative form for most controllers
 
       helpController.DisplaySection(2);
       //helpController.DisplaySection("Classes"); // An alternative form for most controllers
 
@@ -560,6 +609,7 @@ void MyFrame::ShowHelp(int commandId, wxHelpControllerBase& helpController)
    case HelpDemo_Html_Help_Help:
    case HelpDemo_Advanced_Html_Help_Help:
    case HelpDemo_MS_Html_Help_Help:
    case HelpDemo_Html_Help_Help:
    case HelpDemo_Advanced_Html_Help_Help:
    case HelpDemo_MS_Html_Help_Help:
+   case HelpDemo_Best_Help_Help:
       helpController.DisplaySection(3);
       //helpController.DisplaySection("About"); // An alternative form for most controllers
       break;
       helpController.DisplaySection(3);
       //helpController.DisplaySection("About"); // An alternative form for most controllers
       break;
@@ -568,6 +618,7 @@ void MyFrame::ShowHelp(int commandId, wxHelpControllerBase& helpController)
    case HelpDemo_Html_Help_Search:
    case HelpDemo_Advanced_Html_Help_Search:
    case HelpDemo_MS_Html_Help_Search:
    case HelpDemo_Html_Help_Search:
    case HelpDemo_Advanced_Html_Help_Search:
    case HelpDemo_MS_Html_Help_Search:
+   case HelpDemo_Best_Help_Search:
    {
       wxString key = wxGetTextFromUser("Search for?",
                                        "Search help for keyword",
    {
       wxString key = wxGetTextFromUser("Search for?",
                                        "Search help for keyword",
@@ -582,6 +633,7 @@ void MyFrame::ShowHelp(int commandId, wxHelpControllerBase& helpController)
    case HelpDemo_Html_Help_Index:
    case HelpDemo_Advanced_Html_Help_Index:
    case HelpDemo_MS_Html_Help_Index:
    case HelpDemo_Html_Help_Index:
    case HelpDemo_Advanced_Html_Help_Index:
    case HelpDemo_MS_Html_Help_Index:
+   case HelpDemo_Best_Help_Index:
       helpController.DisplayContents();
       break;
 
       helpController.DisplayContents();
       break;
 
diff --git a/src/msw/helpbest.cpp b/src/msw/helpbest.cpp
new file mode 100644 (file)
index 0000000..8de443a
--- /dev/null
@@ -0,0 +1,102 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name:        helpbest.cpp
+// Purpose:     Tries to load MS HTML Help, falls back to wxHTML upon failure
+// Author:      Mattia Barbon
+// Modified by:
+// Created:     02/04/2001
+// RCS-ID:      $Id$
+// Copyright:   (c) Mattia Barbon
+// Licence:    wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifdef __GNUG__
+#pragma implementation "helpbest.h"
+#endif
+
+// For compilers that support precompilation, includes "wx.h".
+#include "wx/wxprec.h"
+
+#ifdef __BORLANDC__
+#pragma hdrstop
+#endif
+
+#ifndef WX_PRECOMP
+#include "wx/defs.h"
+#endif
+
+#include "wx/filefn.h"
+
+#if wxUSE_HELP && wxUSE_MS_HTML_HELP && defined(__WIN95__) && wxUSE_WXHTML_HELP
+#include "wx/msw/helpchm.h"
+#include "wx/html/helpctrl.h"
+#include "wx/msw/helpbest.h"
+
+IMPLEMENT_DYNAMIC_CLASS( wxBestHelpController, wxHelpControllerBase );
+
+bool wxBestHelpController::Initialize( const wxString& filename )
+{
+    // try wxCHMHelpController
+    wxCHMHelpController* chm = new wxCHMHelpController;
+
+    m_helpControllerType = wxUseChmHelp;
+    // do not warn upon failure
+    wxLogNull dontWarnOnFailure;
+
+    if( chm->Initialize( GetValidFilename( filename ) ) )
+    {
+        m_helpController = chm;
+        return TRUE;
+    }
+
+    // failed
+    delete chm;
+
+    // try wxHtmlHelpController
+    wxHtmlHelpController* html = new wxHtmlHelpController;
+
+    m_helpControllerType = wxUseHtmlHelp;
+    if( html->Initialize( GetValidFilename( filename ) ) )
+    {
+        m_helpController = html;
+        return TRUE;
+    }
+
+    // failed
+    delete html;
+
+    return FALSE;
+}
+
+wxString wxBestHelpController::GetValidFilename( const wxString& filename ) const
+{
+    wxString tmp = filename;
+    ::wxStripExtension( tmp );
+
+    switch( m_helpControllerType )
+    {
+    case wxUseChmHelp:
+        if( ::wxFileExists( tmp + ".chm" ) )
+            return tmp + ".chm";
+
+        return filename;
+        break;
+    case wxUseHtmlHelp:
+        if( ::wxFileExists( tmp + ".htb" ) )
+            return tmp + ".htb";
+        if( ::wxFileExists( tmp + ".zip" ) )
+            return tmp + ".zip";
+        if( ::wxFileExists( tmp + ".hhp" ) )
+            return tmp + ".hhp";
+
+        return filename;
+        break;
+    default:
+        // we CAN'T get here
+        wxFAIL_MSG( "wxBestHelpController: Must call Initialize, first!" );
+        return wxEmptyString;
+        break;
+    }
+}
+
+#endif
+    // wxUSE_HELP && wxUSE_MS_HTML_HELP && defined(__WIN95__) && wxUSE_WXHTML_HELP