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_
23 #include "wx/object.h"
24 #include "wx/string.h"
25 #include "wx/filesys.h"
26 #include "wx/dynarray.h"
28 //--------------------------------------------------------------------------------
29 // helper classes & structs
30 //--------------------------------------------------------------------------------
32 class WXDLLEXPORT wxHtmlBookRecord
: public wxObject
35 wxHtmlBookRecord(const wxString
& basepath
, const wxString
& title
,
36 const wxString
& start
)
38 m_BasePath
= basepath
;
41 // for debugging, give the contents index obvious default values
42 m_ContentsStart
= m_ContentsEnd
= -1;
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
; }
65 WX_DECLARE_EXPORTED_OBJARRAY(wxHtmlBookRecord
, wxHtmlBookRecArray
);
74 wxHtmlBookRecord
*m_Book
;
78 //------------------------------------------------------------------------------
80 // This class takes input streams and scans them for occurence
82 //------------------------------------------------------------------------------
83 class WXDLLEXPORT wxSearchEngine
: public wxObject
89 wxSearchEngine() : wxObject() {m_Keyword
= NULL
; }
90 ~wxSearchEngine() {if (m_Keyword
) free(m_Keyword
); }
92 virtual void LookFor(const wxString
& keyword
);
93 // Sets the keyword we will be searching for
95 virtual bool Scan(wxInputStream
*stream
);
96 // Scans the stream for the keyword.
97 // Returns TRUE if the stream contains keyword, fALSE otherwise
101 class wxHtmlHelpData
;
103 // State information of a search action. I'd have prefered to make this a nested
104 // class inside wxHtmlHelpData, but that's against coding standards :-(
105 // Never construct this class yourself, obtain a copy from
106 // wxHtmlHelpData::PrepareKeywordSearch(const wxString& key)
107 class WXDLLEXPORT wxHtmlSearchStatus
110 // constructor; supply wxHtmlHelpData ptr, the keyword and (optionally) the
111 // title of the book to search. By default, all books are searched.
113 wxHtmlSearchStatus(wxHtmlHelpData
* base
, const wxString
& keyword
,
114 const wxString
& book
= wxEmptyString
);
115 bool Search(); // do the next iteration
116 bool IsActive() { return m_Active
; }
117 int GetCurIndex() { return m_CurIndex
; }
118 int GetMaxIndex() { return m_MaxIndex
; }
119 const wxString
& GetName() { return m_Name
; }
120 wxHtmlContentsItem
* GetContentsItem() { return m_ContentsItem
; }
123 wxHtmlHelpData
* m_Data
;
124 wxSearchEngine m_Engine
;
125 wxString m_Keyword
, m_Name
, m_LastPage
;
126 wxHtmlContentsItem
* m_ContentsItem
;
127 bool m_Active
; // search is not finished
128 int m_CurIndex
; // where we are now
129 int m_MaxIndex
; // number of files we search
130 // For progress bar: 100*curindex/maxindex = % complete
134 class WXDLLEXPORT wxHtmlHelpData
: public wxObject
136 DECLARE_DYNAMIC_CLASS(wxHtmlHelpData
)
138 friend class wxHtmlSearchStatus
;
144 void SetTempDir(const wxString
& path
);
145 // Sets directory where temporary files are stored.
146 // These temp files are index & contents file in binary (much faster to read)
147 // form. These files are NOT deleted on program's exit.
149 bool AddBook(const wxString
& book
);
150 // Adds new book. 'book' is location of .htb file (stands for "html book").
151 // See documentation for details on its format.
153 bool AddBookParam(const wxString
& title
, const wxString
& contfile
,
154 const wxString
& indexfile
= wxEmptyString
,
155 const wxString
& deftopic
= wxEmptyString
,
156 const wxString
& path
= wxEmptyString
);
158 // Some accessing stuff
159 wxString
FindPageByName(const wxString
& page
);
160 // returns URL of page on basis of (file)name
161 wxString
FindPageById(int id
);
162 // returns URL of page on basis of MS id
164 const wxHtmlBookRecArray
& GetBookRecArray() { return m_BookRecords
; }
165 wxHtmlContentsItem
* GetContents() { return m_Contents
; }
166 int GetContentsCnt() { return m_ContentsCnt
; }
167 wxHtmlContentsItem
* GetIndex() { return m_Index
; }
168 int GetIndexCnt() { return m_IndexCnt
; }
173 wxHtmlBookRecArray m_BookRecords
;
174 // each book has one record in this array
175 wxHtmlContentsItem
* m_Contents
;
177 // list of all available books and pages.
178 wxHtmlContentsItem
* m_Index
;
180 // list of index items
183 bool LoadMSProject(wxHtmlBookRecord
*book
, wxFileSystem
& fsys
,
184 const wxString
& indexfile
, const wxString
& contentsfile
);
185 // Imports .hhp files (MS HTML Help Workshop)
186 bool LoadCachedBook(wxHtmlBookRecord
*book
, wxInputStream
*f
);
188 bool SaveCachedBook(wxHtmlBookRecord
*book
, wxOutputStream
*f
);
189 // Writes binary book