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