]>
Commit | Line | Data |
---|---|---|
8ec2b484 | 1 | ///////////////////////////////////////////////////////////////////////////// |
80fdcdb9 | 2 | // Name: wx/html/helpdata.h |
8ec2b484 | 3 | // Purpose: wxHtmlHelpData |
f42b1601 | 4 | // Notes: Based on htmlhelp.cpp, implementing a monolithic |
8ec2b484 HH |
5 | // HTML Help controller class, by Vaclav Slavik |
6 | // Author: Harm van der Heijden and Vaclav Slavik | |
8ec2b484 | 7 | // Copyright: (c) Harm van der Heijden and Vaclav Slavik |
65571936 | 8 | // Licence: wxWindows licence |
8ec2b484 HH |
9 | ///////////////////////////////////////////////////////////////////////////// |
10 | ||
11 | #ifndef _WX_HELPDATA_H_ | |
12 | #define _WX_HELPDATA_H_ | |
13 | ||
8ec2b484 HH |
14 | #include "wx/defs.h" |
15 | ||
16 | #if wxUSE_HTML | |
17 | ||
18 | #include "wx/object.h" | |
19 | #include "wx/string.h" | |
20 | #include "wx/filesys.h" | |
21 | #include "wx/dynarray.h" | |
f890e2d4 | 22 | #include "wx/font.h" |
8ec2b484 | 23 | |
b5dbe15d | 24 | class WXDLLIMPEXP_FWD_HTML wxHtmlHelpData; |
97494971 | 25 | |
8ec2b484 HH |
26 | //-------------------------------------------------------------------------------- |
27 | // helper classes & structs | |
28 | //-------------------------------------------------------------------------------- | |
29 | ||
6acba9a7 | 30 | class WXDLLIMPEXP_HTML wxHtmlBookRecord |
8ec2b484 | 31 | { |
97494971 | 32 | public: |
6953da00 | 33 | wxHtmlBookRecord(const wxString& bookfile, const wxString& basepath, |
5ecdcaa7 | 34 | const wxString& title, const wxString& start) |
97494971 | 35 | { |
5ecdcaa7 | 36 | m_BookFile = bookfile; |
97494971 VS |
37 | m_BasePath = basepath; |
38 | m_Title = title; | |
39 | m_Start = start; | |
40 | // for debugging, give the contents index obvious default values | |
41 | m_ContentsStart = m_ContentsEnd = -1; | |
42 | } | |
5ecdcaa7 | 43 | wxString GetBookFile() const { return m_BookFile; } |
97494971 VS |
44 | wxString GetTitle() const { return m_Title; } |
45 | wxString GetStart() const { return m_Start; } | |
46 | wxString GetBasePath() const { return m_BasePath; } | |
47 | /* SetContentsRange: store in the bookrecord where in the index/contents lists the | |
48 | * book's records are stored. This to facilitate searching in a specific book. | |
49 | * This code will have to be revised when loading/removing books becomes dynamic. | |
50 | * (as opposed to appending only) | |
51 | * Note that storing index range is pointless, because the index is alphab. sorted. */ | |
52 | void SetContentsRange(int start, int end) { m_ContentsStart = start; m_ContentsEnd = end; } | |
53 | int GetContentsStart() const { return m_ContentsStart; } | |
54 | int GetContentsEnd() const { return m_ContentsEnd; } | |
55 | ||
56 | void SetTitle(const wxString& title) { m_Title = title; } | |
57 | void SetBasePath(const wxString& path) { m_BasePath = path; } | |
58 | void SetStart(const wxString& start) { m_Start = start; } | |
59 | ||
6953da00 WS |
60 | // returns full filename of page (which is part of the book), |
61 | // i.e. with book's basePath prepended. If page is already absolute | |
468ae730 VS |
62 | // path, basePath is _not_ prepended. |
63 | wxString GetFullPath(const wxString &page) const; | |
64 | ||
97494971 | 65 | protected: |
5ecdcaa7 | 66 | wxString m_BookFile; |
97494971 VS |
67 | wxString m_BasePath; |
68 | wxString m_Title; | |
69 | wxString m_Start; | |
70 | int m_ContentsStart; | |
71 | int m_ContentsEnd; | |
8ec2b484 HH |
72 | }; |
73 | ||
74 | ||
4460b6c4 VS |
75 | WX_DECLARE_USER_EXPORTED_OBJARRAY(wxHtmlBookRecord, wxHtmlBookRecArray, |
76 | WXDLLIMPEXP_HTML); | |
8ec2b484 | 77 | |
91fa114d VS |
78 | struct WXDLLIMPEXP_HTML wxHtmlHelpDataItem |
79 | { | |
6953da00 | 80 | wxHtmlHelpDataItem() : level(0), parent(NULL), id(wxID_ANY), book(NULL) {} |
91fa114d | 81 | |
42841dfc | 82 | int level; |
91fa114d VS |
83 | wxHtmlHelpDataItem *parent; |
84 | int id; | |
85 | wxString name; | |
86 | wxString page; | |
87 | wxHtmlBookRecord *book; | |
6953da00 | 88 | |
91fa114d VS |
89 | // returns full filename of m_Page, i.e. with book's basePath prepended |
90 | wxString GetFullPath() const { return book->GetFullPath(page); } | |
8ec2b484 | 91 | |
91fa114d VS |
92 | // returns item indented with spaces if it has level>1: |
93 | wxString GetIndentedName() const; | |
94 | }; | |
95 | ||
96 | WX_DECLARE_USER_EXPORTED_OBJARRAY(wxHtmlHelpDataItem, wxHtmlHelpDataItems, | |
97 | WXDLLIMPEXP_HTML); | |
98 | ||
8ec2b484 HH |
99 | |
100 | //------------------------------------------------------------------------------ | |
2b5f62a0 | 101 | // wxHtmlSearchEngine |
7929902d | 102 | // This class takes input streams and scans them for occurrence |
8ec2b484 HH |
103 | // of keyword(s) |
104 | //------------------------------------------------------------------------------ | |
97494971 | 105 | |
6acba9a7 | 106 | class WXDLLIMPEXP_HTML wxHtmlSearchEngine : public wxObject |
8ec2b484 | 107 | { |
97494971 | 108 | public: |
3912b3f8 | 109 | wxHtmlSearchEngine() : wxObject() {} |
d3c7fc99 | 110 | virtual ~wxHtmlSearchEngine() {} |
f42b1601 | 111 | |
97494971 VS |
112 | // Sets the keyword we will be searching for |
113 | virtual void LookFor(const wxString& keyword, bool case_sensitive, bool whole_words_only); | |
8ec2b484 | 114 | |
97494971 | 115 | // Scans the stream for the keyword. |
6953da00 | 116 | // Returns true if the stream contains keyword, fALSE otherwise |
2b5f62a0 | 117 | virtual bool Scan(const wxFSFile& file); |
c4971147 | 118 | |
97494971 | 119 | private: |
3912b3f8 | 120 | wxString m_Keyword; |
97494971 VS |
121 | bool m_CaseSensitive; |
122 | bool m_WholeWords; | |
22f3361e | 123 | |
c0c133e1 | 124 | wxDECLARE_NO_COPY_CLASS(wxHtmlSearchEngine); |
c4971147 | 125 | }; |
8ec2b484 | 126 | |
8ec2b484 | 127 | |
3103e8a9 JS |
128 | // State information of a search action. I'd have preferred to make this a |
129 | // nested class inside wxHtmlHelpData, but that's against coding standards :-( | |
f42b1601 | 130 | // Never construct this class yourself, obtain a copy from |
8ec2b484 | 131 | // wxHtmlHelpData::PrepareKeywordSearch(const wxString& key) |
6acba9a7 | 132 | class WXDLLIMPEXP_HTML wxHtmlSearchStatus |
8ec2b484 | 133 | { |
97494971 VS |
134 | public: |
135 | // constructor; supply wxHtmlHelpData ptr, the keyword and (optionally) the | |
136 | // title of the book to search. By default, all books are searched. | |
137 | wxHtmlSearchStatus(wxHtmlHelpData* base, const wxString& keyword, | |
138 | bool case_sensitive, bool whole_words_only, | |
139 | const wxString& book = wxEmptyString); | |
140 | bool Search(); // do the next iteration | |
141 | bool IsActive() { return m_Active; } | |
142 | int GetCurIndex() { return m_CurIndex; } | |
143 | int GetMaxIndex() { return m_MaxIndex; } | |
144 | const wxString& GetName() { return m_Name; } | |
91fa114d VS |
145 | |
146 | const wxHtmlHelpDataItem *GetCurItem() const { return m_CurItem; } | |
97494971 VS |
147 | |
148 | private: | |
149 | wxHtmlHelpData* m_Data; | |
2b5f62a0 | 150 | wxHtmlSearchEngine m_Engine; |
97494971 | 151 | wxString m_Keyword, m_Name; |
3912b3f8 | 152 | wxString m_LastPage; |
91fa114d | 153 | wxHtmlHelpDataItem* m_CurItem; |
97494971 VS |
154 | bool m_Active; // search is not finished |
155 | int m_CurIndex; // where we are now | |
156 | int m_MaxIndex; // number of files we search | |
157 | // For progress bar: 100*curindex/maxindex = % complete | |
22f3361e | 158 | |
c0c133e1 | 159 | wxDECLARE_NO_COPY_CLASS(wxHtmlSearchStatus); |
f35822af | 160 | }; |
8ec2b484 | 161 | |
6acba9a7 | 162 | class WXDLLIMPEXP_HTML wxHtmlHelpData : public wxObject |
8ec2b484 | 163 | { |
97494971 VS |
164 | DECLARE_DYNAMIC_CLASS(wxHtmlHelpData) |
165 | friend class wxHtmlSearchStatus; | |
166 | ||
167 | public: | |
168 | wxHtmlHelpData(); | |
d3c7fc99 | 169 | virtual ~wxHtmlHelpData(); |
97494971 VS |
170 | |
171 | // Sets directory where temporary files are stored. | |
172 | // These temp files are index & contents file in binary (much faster to read) | |
173 | // form. These files are NOT deleted on program's exit. | |
174 | void SetTempDir(const wxString& path); | |
175 | ||
176 | // Adds new book. 'book' is location of .htb file (stands for "html book"). | |
177 | // See documentation for details on its format. | |
178 | // Returns success. | |
179 | bool AddBook(const wxString& book); | |
180 | bool AddBookParam(const wxFSFile& bookfile, | |
181 | wxFontEncoding encoding, | |
182 | const wxString& title, const wxString& contfile, | |
183 | const wxString& indexfile = wxEmptyString, | |
184 | const wxString& deftopic = wxEmptyString, | |
67c276bd | 185 | const wxString& path = wxEmptyString); |
97494971 VS |
186 | |
187 | // Some accessing stuff: | |
188 | ||
189 | // returns URL of page on basis of (file)name | |
190 | wxString FindPageByName(const wxString& page); | |
191 | // returns URL of page on basis of MS id | |
192 | wxString FindPageById(int id); | |
193 | ||
91fa114d VS |
194 | const wxHtmlBookRecArray& GetBookRecArray() const { return m_bookRecords; } |
195 | ||
196 | const wxHtmlHelpDataItems& GetContentsArray() const { return m_contents; } | |
197 | const wxHtmlHelpDataItems& GetIndexArray() const { return m_index; } | |
198 | ||
97494971 | 199 | protected: |
91fa114d | 200 | wxString m_tempPath; |
97494971 | 201 | |
97494971 | 202 | // each book has one record in this array: |
91fa114d VS |
203 | wxHtmlBookRecArray m_bookRecords; |
204 | ||
205 | wxHtmlHelpDataItems m_contents; // list of all available books and pages | |
206 | wxHtmlHelpDataItems m_index; // list of index itesm | |
6953da00 | 207 | |
97494971 VS |
208 | protected: |
209 | // Imports .hhp files (MS HTML Help Workshop) | |
210 | bool LoadMSProject(wxHtmlBookRecord *book, wxFileSystem& fsys, | |
211 | const wxString& indexfile, const wxString& contentsfile); | |
212 | // Reads binary book | |
213 | bool LoadCachedBook(wxHtmlBookRecord *book, wxInputStream *f); | |
214 | // Writes binary book | |
215 | bool SaveCachedBook(wxHtmlBookRecord *book, wxOutputStream *f); | |
22f3361e | 216 | |
c0c133e1 | 217 | wxDECLARE_NO_COPY_CLASS(wxHtmlHelpData); |
f35822af | 218 | }; |
8ec2b484 HH |
219 | |
220 | #endif | |
221 | ||
222 | #endif |