]> git.saurik.com Git - wxWidgets.git/blame - include/wx/html/helpdata.h
Fix compilation of generic message dialog.
[wxWidgets.git] / include / wx / html / helpdata.h
CommitLineData
8ec2b484
HH
1/////////////////////////////////////////////////////////////////////////////
2// Name: helpdata.h
3// Purpose: wxHtmlHelpData
f42b1601 4// Notes: Based on htmlhelp.cpp, implementing a monolithic
8ec2b484
HH
5// HTML Help controller class, by Vaclav Slavik
6// Author: Harm van der Heijden and Vaclav Slavik
69941f05 7// RCS-ID: $Id$
8ec2b484 8// Copyright: (c) Harm van der Heijden and Vaclav Slavik
65571936 9// Licence: wxWindows licence
8ec2b484
HH
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_HELPDATA_H_
13#define _WX_HELPDATA_H_
14
12028905 15#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
97494971 16#pragma interface "helpdata.h"
8ec2b484
HH
17#endif
18
19#include "wx/defs.h"
20
21#if wxUSE_HTML
22
23#include "wx/object.h"
24#include "wx/string.h"
25#include "wx/filesys.h"
26#include "wx/dynarray.h"
f890e2d4 27#include "wx/font.h"
8ec2b484 28
6acba9a7 29class WXDLLIMPEXP_HTML wxHtmlHelpData;
97494971 30
8ec2b484
HH
31//--------------------------------------------------------------------------------
32// helper classes & structs
33//--------------------------------------------------------------------------------
34
6acba9a7 35class WXDLLIMPEXP_HTML wxHtmlBookRecord
8ec2b484 36{
97494971 37public:
6953da00 38 wxHtmlBookRecord(const wxString& bookfile, const wxString& basepath,
5ecdcaa7 39 const wxString& title, const wxString& start)
97494971 40 {
5ecdcaa7 41 m_BookFile = bookfile;
97494971
VS
42 m_BasePath = basepath;
43 m_Title = title;
44 m_Start = start;
45 // for debugging, give the contents index obvious default values
46 m_ContentsStart = m_ContentsEnd = -1;
47 }
5ecdcaa7 48 wxString GetBookFile() const { return m_BookFile; }
97494971
VS
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; }
60
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; }
64
6953da00
WS
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
468ae730
VS
67 // path, basePath is _not_ prepended.
68 wxString GetFullPath(const wxString &page) const;
69
97494971 70protected:
5ecdcaa7 71 wxString m_BookFile;
97494971
VS
72 wxString m_BasePath;
73 wxString m_Title;
74 wxString m_Start;
75 int m_ContentsStart;
76 int m_ContentsEnd;
8ec2b484
HH
77};
78
79
4460b6c4
VS
80WX_DECLARE_USER_EXPORTED_OBJARRAY(wxHtmlBookRecord, wxHtmlBookRecArray,
81 WXDLLIMPEXP_HTML);
8ec2b484 82
91fa114d
VS
83struct WXDLLIMPEXP_HTML wxHtmlHelpDataItem
84{
6953da00 85 wxHtmlHelpDataItem() : level(0), parent(NULL), id(wxID_ANY), book(NULL) {}
91fa114d 86
42841dfc 87 int level;
91fa114d
VS
88 wxHtmlHelpDataItem *parent;
89 int id;
90 wxString name;
91 wxString page;
92 wxHtmlBookRecord *book;
6953da00 93
91fa114d
VS
94 // returns full filename of m_Page, i.e. with book's basePath prepended
95 wxString GetFullPath() const { return book->GetFullPath(page); }
8ec2b484 96
91fa114d
VS
97 // returns item indented with spaces if it has level>1:
98 wxString GetIndentedName() const;
99};
100
101WX_DECLARE_USER_EXPORTED_OBJARRAY(wxHtmlHelpDataItem, wxHtmlHelpDataItems,
102 WXDLLIMPEXP_HTML);
103
104#if WXWIN_COMPATIBILITY_2_4
105// old interface to contents and index:
97494971 106struct wxHtmlContentsItem
8ec2b484 107{
91fa114d
VS
108 wxHtmlContentsItem();
109 wxHtmlContentsItem(const wxHtmlHelpDataItem& d);
110 wxHtmlContentsItem& operator=(const wxHtmlContentsItem& d);
111 ~wxHtmlContentsItem();
112
42841dfc 113 int m_Level;
8ec2b484 114 int m_ID;
91fa114d
VS
115 wxChar *m_Name;
116 wxChar *m_Page;
8ec2b484 117 wxHtmlBookRecord *m_Book;
6953da00 118
468ae730
VS
119 // returns full filename of m_Page, i.e. with book's basePath prepended
120 wxString GetFullPath() const { return m_Book->GetFullPath(m_Page); }
91fa114d
VS
121
122private:
123 bool m_autofree;
97494971 124};
91fa114d
VS
125#endif
126
8ec2b484
HH
127
128//------------------------------------------------------------------------------
2b5f62a0 129// wxHtmlSearchEngine
8ec2b484
HH
130// This class takes input streams and scans them for occurence
131// of keyword(s)
132//------------------------------------------------------------------------------
97494971 133
6acba9a7 134class WXDLLIMPEXP_HTML wxHtmlSearchEngine : public wxObject
8ec2b484 135{
97494971 136public:
3912b3f8
VS
137 wxHtmlSearchEngine() : wxObject() {}
138 ~wxHtmlSearchEngine() {}
f42b1601 139
97494971
VS
140 // Sets the keyword we will be searching for
141 virtual void LookFor(const wxString& keyword, bool case_sensitive, bool whole_words_only);
8ec2b484 142
97494971 143 // Scans the stream for the keyword.
6953da00 144 // Returns true if the stream contains keyword, fALSE otherwise
2b5f62a0 145 virtual bool Scan(const wxFSFile& file);
c4971147 146
97494971 147private:
3912b3f8 148 wxString m_Keyword;
97494971
VS
149 bool m_CaseSensitive;
150 bool m_WholeWords;
22f3361e 151
00e7a427 152 DECLARE_NO_COPY_CLASS(wxHtmlSearchEngine)
c4971147 153};
8ec2b484 154
8ec2b484
HH
155
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 :-(
f42b1601 158// Never construct this class yourself, obtain a copy from
8ec2b484 159// wxHtmlHelpData::PrepareKeywordSearch(const wxString& key)
6acba9a7 160class WXDLLIMPEXP_HTML wxHtmlSearchStatus
8ec2b484 161{
97494971
VS
162public:
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; }
91fa114d
VS
173
174 const wxHtmlHelpDataItem *GetCurItem() const { return m_CurItem; }
175#if WXWIN_COMPATIBILITY_2_4
176 wxDEPRECATED( wxHtmlContentsItem* GetContentsItem() );
177#endif
97494971
VS
178
179private:
180 wxHtmlHelpData* m_Data;
2b5f62a0 181 wxHtmlSearchEngine m_Engine;
97494971 182 wxString m_Keyword, m_Name;
3912b3f8 183 wxString m_LastPage;
91fa114d 184 wxHtmlHelpDataItem* m_CurItem;
97494971
VS
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
22f3361e
VZ
189
190 DECLARE_NO_COPY_CLASS(wxHtmlSearchStatus)
f35822af 191};
8ec2b484 192
6acba9a7 193class WXDLLIMPEXP_HTML wxHtmlHelpData : public wxObject
8ec2b484 194{
97494971
VS
195 DECLARE_DYNAMIC_CLASS(wxHtmlHelpData)
196 friend class wxHtmlSearchStatus;
197
198public:
199 wxHtmlHelpData();
200 ~wxHtmlHelpData();
201
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);
206
207 // Adds new book. 'book' is location of .htb file (stands for "html book").
208 // See documentation for details on its format.
209 // Returns success.
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,
67c276bd 216 const wxString& path = wxEmptyString);
97494971
VS
217
218 // Some accessing stuff:
219
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);
224
91fa114d
VS
225 const wxHtmlBookRecArray& GetBookRecArray() const { return m_bookRecords; }
226
227 const wxHtmlHelpDataItems& GetContentsArray() const { return m_contents; }
228 const wxHtmlHelpDataItems& GetIndexArray() const { return m_index; }
229
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() );
236#endif
97494971
VS
237
238protected:
91fa114d 239 wxString m_tempPath;
97494971 240
97494971 241 // each book has one record in this array:
91fa114d
VS
242 wxHtmlBookRecArray m_bookRecords;
243
244 wxHtmlHelpDataItems m_contents; // list of all available books and pages
245 wxHtmlHelpDataItems m_index; // list of index itesm
6953da00 246
91fa114d
VS
247#if WXWIN_COMPATIBILITY_2_4
248 // deprecated data structures, set only if GetContents(), GetIndex()
249 // called
250 wxHtmlContentsItem* m_cacheContents;
251 wxHtmlContentsItem* m_cacheIndex;
252private:
253 void CleanCompatibilityData();
254#endif
97494971
VS
255
256protected:
257 // Imports .hhp files (MS HTML Help Workshop)
258 bool LoadMSProject(wxHtmlBookRecord *book, wxFileSystem& fsys,
259 const wxString& indexfile, const wxString& contentsfile);
260 // Reads binary book
261 bool LoadCachedBook(wxHtmlBookRecord *book, wxInputStream *f);
262 // Writes binary book
263 bool SaveCachedBook(wxHtmlBookRecord *book, wxOutputStream *f);
22f3361e
VZ
264
265 DECLARE_NO_COPY_CLASS(wxHtmlHelpData)
f35822af 266};
8ec2b484
HH
267
268#endif
269
270#endif