]> git.saurik.com Git - wxWidgets.git/blob - include/wx/html/helpdata.h
Unicode support
[wxWidgets.git] / include / wx / html / helpdata.h
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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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 WXDLLIMPEXP_HTML wxHtmlHelpData;
30
31 //--------------------------------------------------------------------------------
32 // helper classes & structs
33 //--------------------------------------------------------------------------------
34
35 class WXDLLIMPEXP_HTML wxHtmlBookRecord
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_USER_EXPORTED_OBJARRAY(wxHtmlBookRecord, wxHtmlBookRecArray,
81 WXDLLIMPEXP_HTML);
82
83 struct WXDLLIMPEXP_HTML wxHtmlHelpDataItem
84 {
85 wxHtmlHelpDataItem() : level(0), parent(NULL), id(wxID_ANY), book(NULL) {}
86
87 int level;
88 wxHtmlHelpDataItem *parent;
89 int id;
90 wxString name;
91 wxString page;
92 wxHtmlBookRecord *book;
93
94 // returns full filename of m_Page, i.e. with book's basePath prepended
95 wxString GetFullPath() const { return book->GetFullPath(page); }
96
97 // returns item indented with spaces if it has level>1:
98 wxString GetIndentedName() const;
99 };
100
101 WX_DECLARE_USER_EXPORTED_OBJARRAY(wxHtmlHelpDataItem, wxHtmlHelpDataItems,
102 WXDLLIMPEXP_HTML);
103
104 #if WXWIN_COMPATIBILITY_2_4
105 // old interface to contents and index:
106 struct wxHtmlContentsItem
107 {
108 wxHtmlContentsItem();
109 wxHtmlContentsItem(const wxHtmlHelpDataItem& d);
110 wxHtmlContentsItem& operator=(const wxHtmlContentsItem& d);
111 ~wxHtmlContentsItem();
112
113 int m_Level;
114 int m_ID;
115 wxChar *m_Name;
116 wxChar *m_Page;
117 wxHtmlBookRecord *m_Book;
118
119 // returns full filename of m_Page, i.e. with book's basePath prepended
120 wxString GetFullPath() const { return m_Book->GetFullPath(m_Page); }
121
122 private:
123 bool m_autofree;
124 };
125 #endif
126
127
128 //------------------------------------------------------------------------------
129 // wxHtmlSearchEngine
130 // This class takes input streams and scans them for occurence
131 // of keyword(s)
132 //------------------------------------------------------------------------------
133
134 class WXDLLIMPEXP_HTML wxHtmlSearchEngine : public wxObject
135 {
136 public:
137 wxHtmlSearchEngine() : wxObject() {}
138 ~wxHtmlSearchEngine() {}
139
140 // Sets the keyword we will be searching for
141 virtual void LookFor(const wxString& keyword, bool case_sensitive, bool whole_words_only);
142
143 // Scans the stream for the keyword.
144 // Returns true if the stream contains keyword, fALSE otherwise
145 virtual bool Scan(const wxFSFile& file);
146
147 private:
148 wxString m_Keyword;
149 bool m_CaseSensitive;
150 bool m_WholeWords;
151
152 DECLARE_NO_COPY_CLASS(wxHtmlSearchEngine)
153 };
154
155
156 // State information of a search action. I'd have prefered to make this a nested
157 // class inside wxHtmlHelpData, but that's against coding standards :-(
158 // Never construct this class yourself, obtain a copy from
159 // wxHtmlHelpData::PrepareKeywordSearch(const wxString& key)
160 class WXDLLIMPEXP_HTML wxHtmlSearchStatus
161 {
162 public:
163 // constructor; supply wxHtmlHelpData ptr, the keyword and (optionally) the
164 // title of the book to search. By default, all books are searched.
165 wxHtmlSearchStatus(wxHtmlHelpData* base, const wxString& keyword,
166 bool case_sensitive, bool whole_words_only,
167 const wxString& book = wxEmptyString);
168 bool Search(); // do the next iteration
169 bool IsActive() { return m_Active; }
170 int GetCurIndex() { return m_CurIndex; }
171 int GetMaxIndex() { return m_MaxIndex; }
172 const wxString& GetName() { return m_Name; }
173
174 const wxHtmlHelpDataItem *GetCurItem() const { return m_CurItem; }
175 #if WXWIN_COMPATIBILITY_2_4
176 wxDEPRECATED( wxHtmlContentsItem* GetContentsItem() );
177 #endif
178
179 private:
180 wxHtmlHelpData* m_Data;
181 wxHtmlSearchEngine m_Engine;
182 wxString m_Keyword, m_Name;
183 wxString m_LastPage;
184 wxHtmlHelpDataItem* m_CurItem;
185 bool m_Active; // search is not finished
186 int m_CurIndex; // where we are now
187 int m_MaxIndex; // number of files we search
188 // For progress bar: 100*curindex/maxindex = % complete
189
190 DECLARE_NO_COPY_CLASS(wxHtmlSearchStatus)
191 };
192
193 class WXDLLIMPEXP_HTML wxHtmlHelpData : public wxObject
194 {
195 DECLARE_DYNAMIC_CLASS(wxHtmlHelpData)
196 friend class wxHtmlSearchStatus;
197
198 public:
199 wxHtmlHelpData();
200 ~wxHtmlHelpData();
201
202 // Sets directory where temporary files are stored.
203 // These temp files are index & contents file in binary (much faster to read)
204 // form. These files are NOT deleted on program's exit.
205 void SetTempDir(const wxString& path);
206
207 // Adds new book. 'book' is location of .htb file (stands for "html book").
208 // See documentation for details on its format.
209 // Returns success.
210 bool AddBook(const wxString& book);
211 bool AddBookParam(const wxFSFile& bookfile,
212 wxFontEncoding encoding,
213 const wxString& title, const wxString& contfile,
214 const wxString& indexfile = wxEmptyString,
215 const wxString& deftopic = wxEmptyString,
216 const wxString& path = wxEmptyString);
217
218 // Some accessing stuff:
219
220 // returns URL of page on basis of (file)name
221 wxString FindPageByName(const wxString& page);
222 // returns URL of page on basis of MS id
223 wxString FindPageById(int id);
224
225 const wxHtmlBookRecArray& GetBookRecArray() const { return m_bookRecords; }
226
227 const wxHtmlHelpDataItems& GetContentsArray() const { return m_contents; }
228 const wxHtmlHelpDataItems& GetIndexArray() const { return m_index; }
229
230 #if WXWIN_COMPATIBILITY_2_4
231 // deprecated interface, new interface is arrays-based (see above)
232 wxDEPRECATED( wxHtmlContentsItem* GetContents() );
233 wxDEPRECATED( int GetContentsCnt() );
234 wxDEPRECATED( wxHtmlContentsItem* GetIndex() );
235 wxDEPRECATED( int GetIndexCnt() );
236 #endif
237
238 protected:
239 wxString m_tempPath;
240
241 // each book has one record in this array:
242 wxHtmlBookRecArray m_bookRecords;
243
244 wxHtmlHelpDataItems m_contents; // list of all available books and pages
245 wxHtmlHelpDataItems m_index; // list of index itesm
246
247 #if WXWIN_COMPATIBILITY_2_4
248 // deprecated data structures, set only if GetContents(), GetIndex()
249 // called
250 wxHtmlContentsItem* m_cacheContents;
251 wxHtmlContentsItem* m_cacheIndex;
252 private:
253 void CleanCompatibilityData();
254 #endif
255
256 protected:
257 // Imports .hhp files (MS HTML Help Workshop)
258 bool LoadMSProject(wxHtmlBookRecord *book, wxFileSystem& fsys,
259 const wxString& indexfile, const wxString& contentsfile);
260 // Reads binary book
261 bool LoadCachedBook(wxHtmlBookRecord *book, wxInputStream *f);
262 // Writes binary book
263 bool SaveCachedBook(wxHtmlBookRecord *book, wxOutputStream *f);
264
265 DECLARE_NO_COPY_CLASS(wxHtmlHelpData)
266 };
267
268 #endif
269
270 #endif