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_
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
: public wxObject
38 wxHtmlBookRecord(const wxString
& basepath
, const wxString
& title
,
39 const wxString
& start
)
41 m_BasePath
= basepath
;
44 // for debugging, give the contents index obvious default values
45 m_ContentsStart
= m_ContentsEnd
= -1;
47 wxString
GetTitle() const { return m_Title
; }
48 wxString
GetStart() const { return m_Start
; }
49 wxString
GetBasePath() const { return m_BasePath
; }
50 /* SetContentsRange: store in the bookrecord where in the index/contents lists the
51 * book's records are stored. This to facilitate searching in a specific book.
52 * This code will have to be revised when loading/removing books becomes dynamic.
53 * (as opposed to appending only)
54 * Note that storing index range is pointless, because the index is alphab. sorted. */
55 void SetContentsRange(int start
, int end
) { m_ContentsStart
= start
; m_ContentsEnd
= end
; }
56 int GetContentsStart() const { return m_ContentsStart
; }
57 int GetContentsEnd() const { return m_ContentsEnd
; }
59 void SetTitle(const wxString
& title
) { m_Title
= title
; }
60 void SetBasePath(const wxString
& path
) { m_BasePath
= path
; }
61 void SetStart(const wxString
& start
) { m_Start
= start
; }
72 WX_DECLARE_EXPORTED_OBJARRAY(wxHtmlBookRecord
, wxHtmlBookRecArray
);
75 struct wxHtmlContentsItem
81 wxHtmlBookRecord
*m_Book
;
84 //------------------------------------------------------------------------------
86 // This class takes input streams and scans them for occurence
88 //------------------------------------------------------------------------------
90 class WXDLLEXPORT wxSearchEngine
: public wxObject
93 wxSearchEngine() : wxObject() {m_Keyword
= NULL
; }
94 ~wxSearchEngine() {if (m_Keyword
) delete[] m_Keyword
; }
96 // Sets the keyword we will be searching for
97 virtual void LookFor(const wxString
& keyword
, bool case_sensitive
, bool whole_words_only
);
99 // Scans the stream for the keyword.
100 // Returns TRUE if the stream contains keyword, fALSE otherwise
101 virtual bool Scan(wxInputStream
*stream
);
105 bool m_CaseSensitive
;
110 // State information of a search action. I'd have prefered to make this a nested
111 // class inside wxHtmlHelpData, but that's against coding standards :-(
112 // Never construct this class yourself, obtain a copy from
113 // wxHtmlHelpData::PrepareKeywordSearch(const wxString& key)
114 class WXDLLEXPORT wxHtmlSearchStatus
117 // constructor; supply wxHtmlHelpData ptr, the keyword and (optionally) the
118 // title of the book to search. By default, all books are searched.
119 wxHtmlSearchStatus(wxHtmlHelpData
* base
, const wxString
& keyword
,
120 bool case_sensitive
, bool whole_words_only
,
121 const wxString
& book
= wxEmptyString
);
122 bool Search(); // do the next iteration
123 bool IsActive() { return m_Active
; }
124 int GetCurIndex() { return m_CurIndex
; }
125 int GetMaxIndex() { return m_MaxIndex
; }
126 const wxString
& GetName() { return m_Name
; }
127 wxHtmlContentsItem
* GetContentsItem() { return m_ContentsItem
; }
130 wxHtmlHelpData
* m_Data
;
131 wxSearchEngine m_Engine
;
132 wxString m_Keyword
, m_Name
;
134 wxHtmlContentsItem
* m_ContentsItem
;
135 bool m_Active
; // search is not finished
136 int m_CurIndex
; // where we are now
137 int m_MaxIndex
; // number of files we search
138 // For progress bar: 100*curindex/maxindex = % complete
141 class WXDLLEXPORT wxHtmlHelpData
: public wxObject
143 DECLARE_DYNAMIC_CLASS(wxHtmlHelpData
)
144 friend class wxHtmlSearchStatus
;
150 // Sets directory where temporary files are stored.
151 // These temp files are index & contents file in binary (much faster to read)
152 // form. These files are NOT deleted on program's exit.
153 void SetTempDir(const wxString
& path
);
155 // Adds new book. 'book' is location of .htb file (stands for "html book").
156 // See documentation for details on its format.
158 bool AddBook(const wxString
& book
);
159 bool AddBookParam(const wxFSFile
& bookfile
,
160 wxFontEncoding encoding
,
161 const wxString
& title
, const wxString
& contfile
,
162 const wxString
& indexfile
= wxEmptyString
,
163 const wxString
& deftopic
= wxEmptyString
,
164 const wxString
& path
= wxEmptyString
);
166 // Some accessing stuff:
168 // returns URL of page on basis of (file)name
169 wxString
FindPageByName(const wxString
& page
);
170 // returns URL of page on basis of MS id
171 wxString
FindPageById(int id
);
173 const wxHtmlBookRecArray
& GetBookRecArray() { return m_BookRecords
; }
174 wxHtmlContentsItem
* GetContents() { return m_Contents
; }
175 int GetContentsCnt() { return m_ContentsCnt
; }
176 wxHtmlContentsItem
* GetIndex() { return m_Index
; }
177 int GetIndexCnt() { return m_IndexCnt
; }
182 wxHtmlBookRecArray m_BookRecords
;
183 // each book has one record in this array:
184 wxHtmlContentsItem
* m_Contents
;
186 wxHtmlContentsItem
* m_Index
; // list of all available books and pages.
187 int m_IndexCnt
; // list of index items
190 // Imports .hhp files (MS HTML Help Workshop)
191 bool LoadMSProject(wxHtmlBookRecord
*book
, wxFileSystem
& fsys
,
192 const wxString
& indexfile
, const wxString
& contentsfile
);
194 bool LoadCachedBook(wxHtmlBookRecord
*book
, wxInputStream
*f
);
195 // Writes binary book
196 bool SaveCachedBook(wxHtmlBookRecord
*book
, wxOutputStream
*f
);
200 wxString
wxAddBasePath(const wxString
& basePath
, const wxString
& path
) ;