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