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 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_HELPDATA_H_
12 #define _WX_HELPDATA_H_
18 #include "wx/object.h"
19 #include "wx/string.h"
20 #include "wx/filesys.h"
21 #include "wx/dynarray.h"
24 class WXDLLIMPEXP_FWD_HTML wxHtmlHelpData
;
26 //--------------------------------------------------------------------------------
27 // helper classes & structs
28 //--------------------------------------------------------------------------------
30 class WXDLLIMPEXP_HTML wxHtmlBookRecord
33 wxHtmlBookRecord(const wxString
& bookfile
, const wxString
& basepath
,
34 const wxString
& title
, const wxString
& start
)
36 m_BookFile
= bookfile
;
37 m_BasePath
= basepath
;
40 // for debugging, give the contents index obvious default values
41 m_ContentsStart
= m_ContentsEnd
= -1;
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
; }
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
; }
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;
75 WX_DECLARE_USER_EXPORTED_OBJARRAY(wxHtmlBookRecord
, wxHtmlBookRecArray
,
78 struct WXDLLIMPEXP_HTML wxHtmlHelpDataItem
80 wxHtmlHelpDataItem() : level(0), parent(NULL
), id(wxID_ANY
), book(NULL
) {}
83 wxHtmlHelpDataItem
*parent
;
87 wxHtmlBookRecord
*book
;
89 // returns full filename of m_Page, i.e. with book's basePath prepended
90 wxString
GetFullPath() const { return book
->GetFullPath(page
); }
92 // returns item indented with spaces if it has level>1:
93 wxString
GetIndentedName() const;
96 WX_DECLARE_USER_EXPORTED_OBJARRAY(wxHtmlHelpDataItem
, wxHtmlHelpDataItems
,
100 //------------------------------------------------------------------------------
101 // wxHtmlSearchEngine
102 // This class takes input streams and scans them for occurrence
104 //------------------------------------------------------------------------------
106 class WXDLLIMPEXP_HTML wxHtmlSearchEngine
: public wxObject
109 wxHtmlSearchEngine() : wxObject() {}
110 virtual ~wxHtmlSearchEngine() {}
112 // Sets the keyword we will be searching for
113 virtual void LookFor(const wxString
& keyword
, bool case_sensitive
, bool whole_words_only
);
115 // Scans the stream for the keyword.
116 // Returns true if the stream contains keyword, fALSE otherwise
117 virtual bool Scan(const wxFSFile
& file
);
121 bool m_CaseSensitive
;
124 wxDECLARE_NO_COPY_CLASS(wxHtmlSearchEngine
);
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
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
; }
146 const wxHtmlHelpDataItem
*GetCurItem() const { return m_CurItem
; }
149 wxHtmlHelpData
* m_Data
;
150 wxHtmlSearchEngine m_Engine
;
151 wxString m_Keyword
, m_Name
;
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
159 wxDECLARE_NO_COPY_CLASS(wxHtmlSearchStatus
);
162 class WXDLLIMPEXP_HTML wxHtmlHelpData
: public wxObject
164 DECLARE_DYNAMIC_CLASS(wxHtmlHelpData
)
165 friend class wxHtmlSearchStatus
;
169 virtual ~wxHtmlHelpData();
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
);
176 // Adds new book. 'book' is location of .htb file (stands for "html book").
177 // See documentation for details on its format.
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
);
187 // Some accessing stuff:
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
);
194 const wxHtmlBookRecArray
& GetBookRecArray() const { return m_bookRecords
; }
196 const wxHtmlHelpDataItems
& GetContentsArray() const { return m_contents
; }
197 const wxHtmlHelpDataItems
& GetIndexArray() const { return m_index
; }
202 // each book has one record in this array:
203 wxHtmlBookRecArray m_bookRecords
;
205 wxHtmlHelpDataItems m_contents
; // list of all available books and pages
206 wxHtmlHelpDataItems m_index
; // list of index itesm
209 // Imports .hhp files (MS HTML Help Workshop)
210 bool LoadMSProject(wxHtmlBookRecord
*book
, wxFileSystem
& fsys
,
211 const wxString
& indexfile
, const wxString
& contentsfile
);
213 bool LoadCachedBook(wxHtmlBookRecord
*book
, wxInputStream
*f
);
214 // Writes binary book
215 bool SaveCachedBook(wxHtmlBookRecord
*book
, wxOutputStream
*f
);
217 wxDECLARE_NO_COPY_CLASS(wxHtmlHelpData
);