]> git.saurik.com Git - wxWidgets.git/blob - include/wx/html/helpdata.h
wxMessageBox off the main thread lost result code.
[wxWidgets.git] / include / wx / html / helpdata.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/html/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 // Copyright: (c) Harm van der Heijden and Vaclav Slavik
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_HELPDATA_H_
12 #define _WX_HELPDATA_H_
13
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"
22 #include "wx/font.h"
23
24 class WXDLLIMPEXP_FWD_HTML wxHtmlHelpData;
25
26 //--------------------------------------------------------------------------------
27 // helper classes & structs
28 //--------------------------------------------------------------------------------
29
30 class WXDLLIMPEXP_HTML wxHtmlBookRecord
31 {
32 public:
33 wxHtmlBookRecord(const wxString& bookfile, const wxString& basepath,
34 const wxString& title, const wxString& start)
35 {
36 m_BookFile = bookfile;
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 }
43 wxString GetBookFile() const { return m_BookFile; }
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
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
62 // path, basePath is _not_ prepended.
63 wxString GetFullPath(const wxString &page) const;
64
65 protected:
66 wxString m_BookFile;
67 wxString m_BasePath;
68 wxString m_Title;
69 wxString m_Start;
70 int m_ContentsStart;
71 int m_ContentsEnd;
72 };
73
74
75 WX_DECLARE_USER_EXPORTED_OBJARRAY(wxHtmlBookRecord, wxHtmlBookRecArray,
76 WXDLLIMPEXP_HTML);
77
78 struct WXDLLIMPEXP_HTML wxHtmlHelpDataItem
79 {
80 wxHtmlHelpDataItem() : level(0), parent(NULL), id(wxID_ANY), book(NULL) {}
81
82 int level;
83 wxHtmlHelpDataItem *parent;
84 int id;
85 wxString name;
86 wxString page;
87 wxHtmlBookRecord *book;
88
89 // returns full filename of m_Page, i.e. with book's basePath prepended
90 wxString GetFullPath() const { return book->GetFullPath(page); }
91
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
99
100 //------------------------------------------------------------------------------
101 // wxHtmlSearchEngine
102 // This class takes input streams and scans them for occurrence
103 // of keyword(s)
104 //------------------------------------------------------------------------------
105
106 class WXDLLIMPEXP_HTML wxHtmlSearchEngine : public wxObject
107 {
108 public:
109 wxHtmlSearchEngine() : wxObject() {}
110 virtual ~wxHtmlSearchEngine() {}
111
112 // Sets the keyword we will be searching for
113 virtual void LookFor(const wxString& keyword, bool case_sensitive, bool whole_words_only);
114
115 // Scans the stream for the keyword.
116 // Returns true if the stream contains keyword, fALSE otherwise
117 virtual bool Scan(const wxFSFile& file);
118
119 private:
120 wxString m_Keyword;
121 bool m_CaseSensitive;
122 bool m_WholeWords;
123
124 wxDECLARE_NO_COPY_CLASS(wxHtmlSearchEngine);
125 };
126
127
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 :-(
130 // Never construct this class yourself, obtain a copy from
131 // wxHtmlHelpData::PrepareKeywordSearch(const wxString& key)
132 class WXDLLIMPEXP_HTML wxHtmlSearchStatus
133 {
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; }
145
146 const wxHtmlHelpDataItem *GetCurItem() const { return m_CurItem; }
147
148 private:
149 wxHtmlHelpData* m_Data;
150 wxHtmlSearchEngine m_Engine;
151 wxString m_Keyword, m_Name;
152 wxString m_LastPage;
153 wxHtmlHelpDataItem* m_CurItem;
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
158
159 wxDECLARE_NO_COPY_CLASS(wxHtmlSearchStatus);
160 };
161
162 class WXDLLIMPEXP_HTML wxHtmlHelpData : public wxObject
163 {
164 DECLARE_DYNAMIC_CLASS(wxHtmlHelpData)
165 friend class wxHtmlSearchStatus;
166
167 public:
168 wxHtmlHelpData();
169 virtual ~wxHtmlHelpData();
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,
185 const wxString& path = wxEmptyString);
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
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
199 protected:
200 wxString m_tempPath;
201
202 // each book has one record in this array:
203 wxHtmlBookRecArray m_bookRecords;
204
205 wxHtmlHelpDataItems m_contents; // list of all available books and pages
206 wxHtmlHelpDataItems m_index; // list of index itesm
207
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);
216
217 wxDECLARE_NO_COPY_CLASS(wxHtmlHelpData);
218 };
219
220 #endif
221
222 #endif