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