helpwnd.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/html/helpwnd.h
  3. // Purpose: wxHtmlHelpWindow
  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. #ifndef _WX_HELPWND_H_
  11. #define _WX_HELPWND_H_
  12. #include "wx/defs.h"
  13. #if wxUSE_WXHTML_HELP
  14. #include "wx/helpbase.h"
  15. #include "wx/html/helpdata.h"
  16. #include "wx/window.h"
  17. #include "wx/frame.h"
  18. #include "wx/config.h"
  19. #include "wx/splitter.h"
  20. #include "wx/notebook.h"
  21. #include "wx/listbox.h"
  22. #include "wx/choice.h"
  23. #include "wx/combobox.h"
  24. #include "wx/checkbox.h"
  25. #include "wx/stattext.h"
  26. #include "wx/hash.h"
  27. #include "wx/html/htmlwin.h"
  28. #include "wx/html/htmprint.h"
  29. class WXDLLIMPEXP_FWD_CORE wxButton;
  30. class WXDLLIMPEXP_FWD_CORE wxTextCtrl;
  31. class WXDLLIMPEXP_FWD_CORE wxTreeEvent;
  32. class WXDLLIMPEXP_FWD_CORE wxTreeCtrl;
  33. // style flags for the Help Frame
  34. #define wxHF_TOOLBAR 0x0001
  35. #define wxHF_CONTENTS 0x0002
  36. #define wxHF_INDEX 0x0004
  37. #define wxHF_SEARCH 0x0008
  38. #define wxHF_BOOKMARKS 0x0010
  39. #define wxHF_OPEN_FILES 0x0020
  40. #define wxHF_PRINT 0x0040
  41. #define wxHF_FLAT_TOOLBAR 0x0080
  42. #define wxHF_MERGE_BOOKS 0x0100
  43. #define wxHF_ICONS_BOOK 0x0200
  44. #define wxHF_ICONS_BOOK_CHAPTER 0x0400
  45. #define wxHF_ICONS_FOLDER 0x0000 // this is 0 since it is default
  46. #define wxHF_DEFAULT_STYLE (wxHF_TOOLBAR | wxHF_CONTENTS | \
  47. wxHF_INDEX | wxHF_SEARCH | \
  48. wxHF_BOOKMARKS | wxHF_PRINT)
  49. //compatibility:
  50. #define wxHF_OPENFILES wxHF_OPEN_FILES
  51. #define wxHF_FLATTOOLBAR wxHF_FLAT_TOOLBAR
  52. #define wxHF_DEFAULTSTYLE wxHF_DEFAULT_STYLE
  53. struct wxHtmlHelpFrameCfg
  54. {
  55. int x, y, w, h;
  56. long sashpos;
  57. bool navig_on;
  58. };
  59. struct wxHtmlHelpMergedIndexItem;
  60. class wxHtmlHelpMergedIndex;
  61. class WXDLLIMPEXP_FWD_CORE wxHelpControllerBase;
  62. class WXDLLIMPEXP_FWD_HTML wxHtmlHelpController;
  63. /*!
  64. * Help window
  65. */
  66. class WXDLLIMPEXP_HTML wxHtmlHelpWindow : public wxWindow
  67. {
  68. DECLARE_DYNAMIC_CLASS(wxHtmlHelpWindow)
  69. public:
  70. wxHtmlHelpWindow(wxHtmlHelpData* data = NULL) { Init(data); }
  71. wxHtmlHelpWindow(wxWindow* parent, wxWindowID wxWindowID,
  72. const wxPoint& pos = wxDefaultPosition,
  73. const wxSize& size = wxDefaultSize,
  74. int style = wxTAB_TRAVERSAL|wxNO_BORDER,
  75. int helpStyle = wxHF_DEFAULT_STYLE,
  76. wxHtmlHelpData* data = NULL);
  77. bool Create(wxWindow* parent, wxWindowID id,
  78. const wxPoint& pos = wxDefaultPosition,
  79. const wxSize& size = wxDefaultSize,
  80. int style = wxTAB_TRAVERSAL|wxNO_BORDER,
  81. int helpStyle = wxHF_DEFAULT_STYLE);
  82. virtual ~wxHtmlHelpWindow();
  83. wxHtmlHelpData* GetData() { return m_Data; }
  84. wxHtmlHelpController* GetController() const { return m_helpController; }
  85. void SetController(wxHtmlHelpController* controller);
  86. // Displays page x. If not found it will offect the user a choice of
  87. // searching books.
  88. // Looking for the page runs in these steps:
  89. // 1. try to locate file named x (if x is for example "doc/howto.htm")
  90. // 2. try to open starting page of book x
  91. // 3. try to find x in contents (if x is for example "How To ...")
  92. // 4. try to find x in index (if x is for example "How To ...")
  93. bool Display(const wxString& x);
  94. // Alternative version that works with numeric ID.
  95. // (uses extension to MS format, <param name="ID" value=id>, see docs)
  96. bool Display(const int id);
  97. // Displays help window and focuses contents.
  98. bool DisplayContents();
  99. // Displays help window and focuses index.
  100. bool DisplayIndex();
  101. // Searches for keyword. Returns true and display page if found, return
  102. // false otherwise
  103. // Syntax of keyword is Altavista-like:
  104. // * words are separated by spaces
  105. // (but "\"hello world\"" is only one world "hello world")
  106. // * word may be pretended by + or -
  107. // (+ : page must contain the word ; - : page can't contain the word)
  108. // * if there is no + or - before the word, + is default
  109. bool KeywordSearch(const wxString& keyword,
  110. wxHelpSearchMode mode = wxHELP_SEARCH_ALL);
  111. #if wxUSE_CONFIG
  112. void UseConfig(wxConfigBase *config, const wxString& rootpath = wxEmptyString)
  113. {
  114. m_Config = config;
  115. m_ConfigRoot = rootpath;
  116. ReadCustomization(config, rootpath);
  117. }
  118. // Saves custom settings into cfg config. it will use the path 'path'
  119. // if given, otherwise it will save info into currently selected path.
  120. // saved values : things set by SetFonts, SetBorders.
  121. void ReadCustomization(wxConfigBase *cfg, const wxString& path = wxEmptyString);
  122. void WriteCustomization(wxConfigBase *cfg, const wxString& path = wxEmptyString);
  123. #endif // wxUSE_CONFIG
  124. // call this to let wxHtmlHelpWindow know page changed
  125. void NotifyPageChanged();
  126. // Refreshes Contents and Index tabs
  127. void RefreshLists();
  128. // Gets the HTML window
  129. wxHtmlWindow* GetHtmlWindow() const { return m_HtmlWin; }
  130. // Gets the splitter window
  131. wxSplitterWindow* GetSplitterWindow() const { return m_Splitter; }
  132. // Gets the toolbar
  133. wxToolBar* GetToolBar() const { return m_toolBar; }
  134. // Gets the configuration data
  135. wxHtmlHelpFrameCfg& GetCfgData() { return m_Cfg; }
  136. // Gets the tree control
  137. wxTreeCtrl *GetTreeCtrl() const { return m_ContentsBox; }
  138. protected:
  139. void Init(wxHtmlHelpData* data = NULL);
  140. // Adds items to m_Contents tree control
  141. void CreateContents();
  142. // Adds items to m_IndexList
  143. void CreateIndex();
  144. // Add books to search choice panel
  145. void CreateSearch();
  146. // Updates "merged index" structure that combines indexes of all books
  147. // into better searchable structure
  148. void UpdateMergedIndex();
  149. // Add custom buttons to toolbar
  150. virtual void AddToolbarButtons(wxToolBar *toolBar, int style);
  151. // Displays options dialog (fonts etc.)
  152. virtual void OptionsDialog();
  153. void OnToolbar(wxCommandEvent& event);
  154. void OnContentsSel(wxTreeEvent& event);
  155. void OnIndexSel(wxCommandEvent& event);
  156. void OnIndexFind(wxCommandEvent& event);
  157. void OnIndexAll(wxCommandEvent& event);
  158. void OnSearchSel(wxCommandEvent& event);
  159. void OnSearch(wxCommandEvent& event);
  160. void OnBookmarksSel(wxCommandEvent& event);
  161. void OnSize(wxSizeEvent& event);
  162. // Images:
  163. enum {
  164. IMG_Book = 0,
  165. IMG_Folder,
  166. IMG_Page
  167. };
  168. protected:
  169. wxHtmlHelpData* m_Data;
  170. bool m_DataCreated; // m_Data created by frame, or supplied?
  171. wxString m_TitleFormat; // title of the help frame
  172. // below are various pointers to GUI components
  173. wxHtmlWindow *m_HtmlWin;
  174. wxSplitterWindow *m_Splitter;
  175. wxPanel *m_NavigPan;
  176. wxNotebook *m_NavigNotebook;
  177. wxTreeCtrl *m_ContentsBox;
  178. wxTextCtrl *m_IndexText;
  179. wxButton *m_IndexButton;
  180. wxButton *m_IndexButtonAll;
  181. wxListBox *m_IndexList;
  182. wxTextCtrl *m_SearchText;
  183. wxButton *m_SearchButton;
  184. wxListBox *m_SearchList;
  185. wxChoice *m_SearchChoice;
  186. wxStaticText *m_IndexCountInfo;
  187. wxCheckBox *m_SearchCaseSensitive;
  188. wxCheckBox *m_SearchWholeWords;
  189. wxToolBar* m_toolBar;
  190. wxComboBox *m_Bookmarks;
  191. wxArrayString m_BookmarksNames, m_BookmarksPages;
  192. wxHtmlHelpFrameCfg m_Cfg;
  193. #if wxUSE_CONFIG
  194. wxConfigBase *m_Config;
  195. wxString m_ConfigRoot;
  196. #endif // wxUSE_CONFIG
  197. // pagenumbers of controls in notebook (usually 0,1,2)
  198. int m_ContentsPage;
  199. int m_IndexPage;
  200. int m_SearchPage;
  201. // lists of available fonts (used in options dialog)
  202. wxArrayString *m_NormalFonts, *m_FixedFonts;
  203. int m_FontSize; // 0,1,2 = small,medium,big
  204. wxString m_NormalFace, m_FixedFace;
  205. bool m_UpdateContents;
  206. #if wxUSE_PRINTING_ARCHITECTURE
  207. wxHtmlEasyPrinting *m_Printer;
  208. #endif
  209. wxHashTable *m_PagesHash;
  210. wxHtmlHelpController* m_helpController;
  211. int m_hfStyle;
  212. private:
  213. void DoIndexFind();
  214. void DoIndexAll();
  215. void DisplayIndexItem(const wxHtmlHelpMergedIndexItem *it);
  216. wxHtmlHelpMergedIndex *m_mergedIndex;
  217. DECLARE_EVENT_TABLE()
  218. wxDECLARE_NO_COPY_CLASS(wxHtmlHelpWindow);
  219. };
  220. /*!
  221. * Command IDs
  222. */
  223. enum
  224. {
  225. //wxID_HTML_HELPFRAME = wxID_HIGHEST + 1,
  226. wxID_HTML_PANEL = wxID_HIGHEST + 10,
  227. wxID_HTML_BACK,
  228. wxID_HTML_FORWARD,
  229. wxID_HTML_UPNODE,
  230. wxID_HTML_UP,
  231. wxID_HTML_DOWN,
  232. wxID_HTML_PRINT,
  233. wxID_HTML_OPENFILE,
  234. wxID_HTML_OPTIONS,
  235. wxID_HTML_BOOKMARKSLIST,
  236. wxID_HTML_BOOKMARKSADD,
  237. wxID_HTML_BOOKMARKSREMOVE,
  238. wxID_HTML_TREECTRL,
  239. wxID_HTML_INDEXPAGE,
  240. wxID_HTML_INDEXLIST,
  241. wxID_HTML_INDEXTEXT,
  242. wxID_HTML_INDEXBUTTON,
  243. wxID_HTML_INDEXBUTTONALL,
  244. wxID_HTML_NOTEBOOK,
  245. wxID_HTML_SEARCHPAGE,
  246. wxID_HTML_SEARCHTEXT,
  247. wxID_HTML_SEARCHLIST,
  248. wxID_HTML_SEARCHBUTTON,
  249. wxID_HTML_SEARCHCHOICE,
  250. wxID_HTML_COUNTINFO
  251. };
  252. #endif // wxUSE_WXHTML_HELP
  253. #endif