1 /////////////////////////////////////////////////////////////////////////////
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
8 // Copyright: (c) Harm van der Heijden and Vaclav Slavik
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_HELPDATA_H_
13 #define _WX_HELPDATA_H_
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "helpdata.h"
23 #include "wx/object.h"
24 #include "wx/string.h"
25 #include "wx/filesys.h"
26 #include "wx/dynarray.h"
29 class WXDLLIMPEXP_HTML wxHtmlHelpData
;
31 //--------------------------------------------------------------------------------
32 // helper classes & structs
33 //--------------------------------------------------------------------------------
35 class WXDLLIMPEXP_HTML wxHtmlBookRecord
38 wxHtmlBookRecord(const wxString
& bookfile
, const wxString
& basepath
,
39 const wxString
& title
, const wxString
& start
)
41 m_BookFile
= bookfile
;
42 m_BasePath
= basepath
;
45 // for debugging, give the contents index obvious default values
46 m_ContentsStart
= m_ContentsEnd
= -1;
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
; }
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
; }
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;
80 WX_DECLARE_USER_EXPORTED_OBJARRAY(wxHtmlBookRecord
, wxHtmlBookRecArray
,
83 struct WXDLLIMPEXP_HTML wxHtmlHelpDataItem
85 wxHtmlHelpDataItem() : level(0), parent(NULL
), id(wxID_ANY
), book(NULL
) {}
88 wxHtmlHelpDataItem
*parent
;
92 wxHtmlBookRecord
*book
;
94 // returns full filename of m_Page, i.e. with book's basePath prepended
95 wxString
GetFullPath() const { return book
->GetFullPath(page
); }
97 // returns item indented with spaces if it has level>1:
98 wxString
GetIndentedName() const;
101 WX_DECLARE_USER_EXPORTED_OBJARRAY(wxHtmlHelpDataItem
, wxHtmlHelpDataItems
,
104 #if WXWIN_COMPATIBILITY_2_4
105 // old interface to contents and index:
106 struct wxHtmlContentsItem
108 wxHtmlContentsItem();
109 wxHtmlContentsItem(const wxHtmlHelpDataItem
& d
);
110 wxHtmlContentsItem
& operator=(const wxHtmlContentsItem
& d
);
111 ~wxHtmlContentsItem();
117 wxHtmlBookRecord
*m_Book
;
119 // returns full filename of m_Page, i.e. with book's basePath prepended
120 wxString
GetFullPath() const { return m_Book
->GetFullPath(m_Page
); }
128 //------------------------------------------------------------------------------
129 // wxHtmlSearchEngine
130 // This class takes input streams and scans them for occurence
132 //------------------------------------------------------------------------------
134 class WXDLLIMPEXP_HTML wxHtmlSearchEngine
: public wxObject
137 wxHtmlSearchEngine() : wxObject() {}
138 ~wxHtmlSearchEngine() {}
140 // Sets the keyword we will be searching for
141 virtual void LookFor(const wxString
& keyword
, bool case_sensitive
, bool whole_words_only
);
143 // Scans the stream for the keyword.
144 // Returns true if the stream contains keyword, fALSE otherwise
145 virtual bool Scan(const wxFSFile
& file
);
149 bool m_CaseSensitive
;
152 DECLARE_NO_COPY_CLASS(wxHtmlSearchEngine
)
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
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
; }
174 const wxHtmlHelpDataItem
*GetCurItem() const { return m_CurItem
; }
175 #if WXWIN_COMPATIBILITY_2_4
176 wxDEPRECATED( wxHtmlContentsItem
* GetContentsItem() );
180 wxHtmlHelpData
* m_Data
;
181 wxHtmlSearchEngine m_Engine
;
182 wxString m_Keyword
, m_Name
;
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
190 DECLARE_NO_COPY_CLASS(wxHtmlSearchStatus
)
193 class WXDLLIMPEXP_HTML wxHtmlHelpData
: public wxObject
195 DECLARE_DYNAMIC_CLASS(wxHtmlHelpData
)
196 friend class wxHtmlSearchStatus
;
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
);
207 // Adds new book. 'book' is location of .htb file (stands for "html book").
208 // See documentation for details on its format.
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
);
218 // Some accessing stuff:
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
);
225 const wxHtmlBookRecArray
& GetBookRecArray() const { return m_bookRecords
; }
227 const wxHtmlHelpDataItems
& GetContentsArray() const { return m_contents
; }
228 const wxHtmlHelpDataItems
& GetIndexArray() const { return m_index
; }
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() );
241 // each book has one record in this array:
242 wxHtmlBookRecArray m_bookRecords
;
244 wxHtmlHelpDataItems m_contents
; // list of all available books and pages
245 wxHtmlHelpDataItems m_index
; // list of index itesm
247 #if WXWIN_COMPATIBILITY_2_4
248 // deprecated data structures, set only if GetContents(), GetIndex()
250 wxHtmlContentsItem
* m_cacheContents
;
251 wxHtmlContentsItem
* m_cacheIndex
;
253 void CleanCompatibilityData();
257 // Imports .hhp files (MS HTML Help Workshop)
258 bool LoadMSProject(wxHtmlBookRecord
*book
, wxFileSystem
& fsys
,
259 const wxString
& indexfile
, const wxString
& contentsfile
);
261 bool LoadCachedBook(wxHtmlBookRecord
*book
, wxInputStream
*f
);
262 // Writes binary book
263 bool SaveCachedBook(wxHtmlBookRecord
*book
, wxOutputStream
*f
);
265 DECLARE_NO_COPY_CLASS(wxHtmlHelpData
)