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(__APPLE__)
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 WXDLLEXPORT wxHtmlHelpData
;
31 //--------------------------------------------------------------------------------
32 // helper classes & structs
33 //--------------------------------------------------------------------------------
35 class WXDLLEXPORT 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_EXPORTED_OBJARRAY(wxHtmlBookRecord
, wxHtmlBookRecArray
);
83 struct wxHtmlContentsItem
89 wxHtmlBookRecord
*m_Book
;
91 // returns full filename of m_Page, i.e. with book's basePath prepended
92 wxString
GetFullPath() const { return m_Book
->GetFullPath(m_Page
); }
95 //------------------------------------------------------------------------------
97 // This class takes input streams and scans them for occurence
99 //------------------------------------------------------------------------------
101 class WXDLLEXPORT wxHtmlSearchEngine
: public wxObject
104 wxHtmlSearchEngine() : wxObject() {m_Keyword
= NULL
; }
105 ~wxHtmlSearchEngine() {if (m_Keyword
) delete[] m_Keyword
; }
107 // Sets the keyword we will be searching for
108 virtual void LookFor(const wxString
& keyword
, bool case_sensitive
, bool whole_words_only
);
110 // Scans the stream for the keyword.
111 // Returns TRUE if the stream contains keyword, fALSE otherwise
112 virtual bool Scan(const wxFSFile
& file
);
116 bool m_CaseSensitive
;
119 DECLARE_NO_COPY_CLASS(wxHtmlSearchEngine
)
123 // State information of a search action. I'd have prefered to make this a nested
124 // class inside wxHtmlHelpData, but that's against coding standards :-(
125 // Never construct this class yourself, obtain a copy from
126 // wxHtmlHelpData::PrepareKeywordSearch(const wxString& key)
127 class WXDLLEXPORT wxHtmlSearchStatus
130 // constructor; supply wxHtmlHelpData ptr, the keyword and (optionally) the
131 // title of the book to search. By default, all books are searched.
132 wxHtmlSearchStatus(wxHtmlHelpData
* base
, const wxString
& keyword
,
133 bool case_sensitive
, bool whole_words_only
,
134 const wxString
& book
= wxEmptyString
);
135 bool Search(); // do the next iteration
136 bool IsActive() { return m_Active
; }
137 int GetCurIndex() { return m_CurIndex
; }
138 int GetMaxIndex() { return m_MaxIndex
; }
139 const wxString
& GetName() { return m_Name
; }
140 wxHtmlContentsItem
* GetContentsItem() { return m_ContentsItem
; }
143 wxHtmlHelpData
* m_Data
;
144 wxHtmlSearchEngine m_Engine
;
145 wxString m_Keyword
, m_Name
;
147 wxHtmlContentsItem
* m_ContentsItem
;
148 bool m_Active
; // search is not finished
149 int m_CurIndex
; // where we are now
150 int m_MaxIndex
; // number of files we search
151 // For progress bar: 100*curindex/maxindex = % complete
153 DECLARE_NO_COPY_CLASS(wxHtmlSearchStatus
)
156 class WXDLLEXPORT wxHtmlHelpData
: public wxObject
158 DECLARE_DYNAMIC_CLASS(wxHtmlHelpData
)
159 friend class wxHtmlSearchStatus
;
165 // Sets directory where temporary files are stored.
166 // These temp files are index & contents file in binary (much faster to read)
167 // form. These files are NOT deleted on program's exit.
168 void SetTempDir(const wxString
& path
);
170 // Adds new book. 'book' is location of .htb file (stands for "html book").
171 // See documentation for details on its format.
173 bool AddBook(const wxString
& book
);
174 bool AddBookParam(const wxFSFile
& bookfile
,
175 wxFontEncoding encoding
,
176 const wxString
& title
, const wxString
& contfile
,
177 const wxString
& indexfile
= wxEmptyString
,
178 const wxString
& deftopic
= wxEmptyString
,
179 const wxString
& path
= wxEmptyString
);
181 // Some accessing stuff:
183 // returns URL of page on basis of (file)name
184 wxString
FindPageByName(const wxString
& page
);
185 // returns URL of page on basis of MS id
186 wxString
FindPageById(int id
);
188 const wxHtmlBookRecArray
& GetBookRecArray() { return m_BookRecords
; }
189 wxHtmlContentsItem
* GetContents() { return m_Contents
; }
190 int GetContentsCnt() { return m_ContentsCnt
; }
191 wxHtmlContentsItem
* GetIndex() { return m_Index
; }
192 int GetIndexCnt() { return m_IndexCnt
; }
197 wxHtmlBookRecArray m_BookRecords
;
198 // each book has one record in this array:
199 wxHtmlContentsItem
* m_Contents
;
201 wxHtmlContentsItem
* m_Index
; // list of all available books and pages.
202 int m_IndexCnt
; // list of index items
205 // Imports .hhp files (MS HTML Help Workshop)
206 bool LoadMSProject(wxHtmlBookRecord
*book
, wxFileSystem
& fsys
,
207 const wxString
& indexfile
, const wxString
& contentsfile
);
209 bool LoadCachedBook(wxHtmlBookRecord
*book
, wxInputStream
*f
);
210 // Writes binary book
211 bool SaveCachedBook(wxHtmlBookRecord
*book
, wxOutputStream
*f
);
213 DECLARE_NO_COPY_CLASS(wxHtmlHelpData
)