1 /////////////////////////////////////////////////////////////////////////////
2 // Name:        wx/html/helpctrl.h
3 // Purpose:     wxHtmlHelpController
4 // Notes:       Based on htmlhelp.cpp, implementing a monolithic
5 //              HTML Help controller class,  by Vaclav Slavik
6 // Author:      Harm van der Heijden and Vaclav Slavik
7 // Copyright:   (c) Harm van der Heijden and Vaclav Slavik
8 // Licence:     wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10 
11 #ifndef _WX_HELPCTRL_H_
12 #define _WX_HELPCTRL_H_
13 
14 #include "wx/defs.h"
15 
16 #if wxUSE_WXHTML_HELP
17 
18 #include "wx/helpbase.h"
19 #include "wx/html/helpfrm.h"
20 
21 #define wxID_HTML_HELPFRAME   (wxID_HIGHEST + 1)
22 
23 // This style indicates that the window is
24 // embedded in the application and must not be
25 // destroyed by the help controller.
26 #define wxHF_EMBEDDED                0x00008000
27 
28 // Create a dialog for the help window.
29 #define wxHF_DIALOG                  0x00010000
30 
31 // Create a frame for the help window.
32 #define wxHF_FRAME                   0x00020000
33 
34 // Make the dialog modal when displaying help.
35 #define wxHF_MODAL                   0x00040000
36 
37 class WXDLLIMPEXP_FWD_HTML wxHtmlHelpDialog;
38 class WXDLLIMPEXP_FWD_HTML wxHtmlHelpWindow;
39 class WXDLLIMPEXP_FWD_HTML wxHtmlHelpFrame;
40 class WXDLLIMPEXP_FWD_HTML wxHtmlHelpDialog;
41 
42 class WXDLLIMPEXP_HTML wxHtmlHelpController : public wxHelpControllerBase // wxEvtHandler
43 {
44     wxDECLARE_DYNAMIC_CLASS(wxHtmlHelpController);
45 
46 public:
47     wxHtmlHelpController(int style = wxHF_DEFAULT_STYLE, wxWindow* parentWindow = NULL);
48     wxHtmlHelpController(wxWindow* parentWindow, int style = wxHF_DEFAULT_STYLE);
49 
50     virtual ~wxHtmlHelpController();
51 
52     void SetShouldPreventAppExit(bool enable);
53 
54     void SetTitleFormat(const wxString& format);
SetTempDir(const wxString & path)55     void SetTempDir(const wxString& path) { m_helpData.SetTempDir(path); }
56     bool AddBook(const wxString& book_url, bool show_wait_msg = false);
57     bool AddBook(const wxFileName& book_file, bool show_wait_msg = false);
58 
59     bool Display(const wxString& x);
60     bool Display(int id);
61     bool DisplayContents() wxOVERRIDE;
62     bool DisplayIndex();
63     bool KeywordSearch(const wxString& keyword,
64                        wxHelpSearchMode mode = wxHELP_SEARCH_ALL) wxOVERRIDE;
65 
GetHelpWindow()66     wxHtmlHelpWindow* GetHelpWindow() { return m_helpWindow; }
67     void SetHelpWindow(wxHtmlHelpWindow* helpWindow);
68 
GetFrame()69     wxHtmlHelpFrame* GetFrame() { return m_helpFrame; }
GetDialog()70     wxHtmlHelpDialog* GetDialog() { return m_helpDialog; }
71 
72 #if wxUSE_CONFIG
73     void UseConfig(wxConfigBase *config, const wxString& rootpath = wxEmptyString);
74 
75     // Assigns config object to the Ctrl. This config is then
76     // used in subsequent calls to Read/WriteCustomization of both help
77     // Ctrl and it's wxHtmlWindow
78     virtual void ReadCustomization(wxConfigBase *cfg, const wxString& path = wxEmptyString);
79     virtual void WriteCustomization(wxConfigBase *cfg, const wxString& path = wxEmptyString);
80 #endif // wxUSE_CONFIG
81 
82     //// Backward compatibility with wxHelpController API
83 
Initialize(const wxString & file,int WXUNUSED (server))84     virtual bool Initialize(const wxString& file, int WXUNUSED(server) ) wxOVERRIDE { return Initialize(file); }
85     virtual bool Initialize(const wxString& file) wxOVERRIDE;
86     virtual void SetViewer(const wxString& WXUNUSED(viewer), long WXUNUSED(flags) = 0) wxOVERRIDE {}
87     virtual bool LoadFile(const wxString& file = wxT("")) wxOVERRIDE;
88     virtual bool DisplaySection(int sectionNo) wxOVERRIDE;
DisplaySection(const wxString & section)89     virtual bool DisplaySection(const wxString& section) wxOVERRIDE { return Display(section); }
DisplayBlock(long blockNo)90     virtual bool DisplayBlock(long blockNo) wxOVERRIDE { return DisplaySection(blockNo); }
91     virtual bool DisplayTextPopup(const wxString& text, const wxPoint& pos) wxOVERRIDE;
92 
93     virtual void SetFrameParameters(const wxString& titleFormat,
94                                const wxSize& size,
95                                const wxPoint& pos = wxDefaultPosition,
96                                bool newFrameEachTime = false) wxOVERRIDE;
97     /// Obtains the latest settings used by the help frame and the help
98     /// frame.
99     virtual wxFrame *GetFrameParameters(wxSize *size = NULL,
100                                wxPoint *pos = NULL,
101                                bool *newFrameEachTime = NULL) wxOVERRIDE;
102 
103     // Get direct access to help data:
GetHelpData()104     wxHtmlHelpData *GetHelpData() { return &m_helpData; }
105 
106     virtual bool Quit() wxOVERRIDE ;
OnQuit()107     virtual void OnQuit() wxOVERRIDE {}
108 
109     void OnCloseFrame(wxCloseEvent& evt);
110 
111     // Make the help controller's frame 'modal' if
112     // needed
113     void MakeModalIfNeeded();
114 
115     // Find the top-most parent window
116     wxWindow* FindTopLevelWindow();
117 
118 protected:
119     void Init(int style);
120 
121     virtual wxWindow* CreateHelpWindow();
122     virtual wxHtmlHelpFrame* CreateHelpFrame(wxHtmlHelpData *data);
123     virtual wxHtmlHelpDialog* CreateHelpDialog(wxHtmlHelpData *data);
124     virtual void DestroyHelpWindow();
125 
126     wxHtmlHelpData      m_helpData;
127     wxHtmlHelpWindow*   m_helpWindow;
128 #if wxUSE_CONFIG
129     wxConfigBase *      m_Config;
130     wxString            m_ConfigRoot;
131 #endif // wxUSE_CONFIG
132     wxString            m_titleFormat;
133     int                 m_FrameStyle;
134     wxHtmlHelpFrame*    m_helpFrame;
135     wxHtmlHelpDialog*   m_helpDialog;
136 
137     bool                m_shouldPreventAppExit;
138 
139     wxDECLARE_NO_COPY_CLASS(wxHtmlHelpController);
140 };
141 
142 /*
143  * wxHtmlModalHelp
144  * A convenience class particularly for use on wxMac,
145  * where you can only show modal dialogs from a modal
146  * dialog.
147  *
148  * Use like this:
149  *
150  * wxHtmlModalHelp help(parent, filename, topic);
151  *
152  * If topic is empty, the help contents is displayed.
153  */
154 
155 class WXDLLIMPEXP_HTML wxHtmlModalHelp
156 {
157 public:
158     wxHtmlModalHelp(wxWindow* parent, const wxString& helpFile, const wxString& topic = wxEmptyString,
159         int style = wxHF_DEFAULT_STYLE | wxHF_DIALOG | wxHF_MODAL);
160 };
161 
162 #endif // wxUSE_WXHTML_HELP
163 
164 #endif // _WX_HELPCTRL_H_
165