]> git.saurik.com Git - wxWidgets.git/blame - include/wx/html/helpdata.h
adding scroll wheel support
[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
8ec2b484
HH
15#include "wx/defs.h"
16
17#if wxUSE_HTML
18
19#include "wx/object.h"
20#include "wx/string.h"
21#include "wx/filesys.h"
22#include "wx/dynarray.h"
f890e2d4 23#include "wx/font.h"
8ec2b484 24
b5dbe15d 25class WXDLLIMPEXP_FWD_HTML wxHtmlHelpData;
97494971 26
8ec2b484
HH
27//--------------------------------------------------------------------------------
28// helper classes & structs
29//--------------------------------------------------------------------------------
30
6acba9a7 31class WXDLLIMPEXP_HTML wxHtmlBookRecord
8ec2b484 32{
97494971 33public:
6953da00 34 wxHtmlBookRecord(const wxString& bookfile, const wxString& basepath,
5ecdcaa7 35 const wxString& title, const wxString& start)
97494971 36 {
5ecdcaa7 37 m_BookFile = bookfile;
97494971
VS
38 m_BasePath = basepath;
39 m_Title = title;
40 m_Start = start;
41 // for debugging, give the contents index obvious default values
42 m_ContentsStart = m_ContentsEnd = -1;
43 }
5ecdcaa7 44 wxString GetBookFile() const { return m_BookFile; }
97494971
VS
45 wxString GetTitle() const { return m_Title; }
46 wxString GetStart() const { return m_Start; }
47 wxString GetBasePath() const { return m_BasePath; }
48 /* SetContentsRange: store in the bookrecord where in the index/contents lists the
49 * book's records are stored. This to facilitate searching in a specific book.
50 * This code will have to be revised when loading/removing books becomes dynamic.
51 * (as opposed to appending only)
52 * Note that storing index range is pointless, because the index is alphab. sorted. */
53 void SetContentsRange(int start, int end) { m_ContentsStart = start; m_ContentsEnd = end; }
54 int GetContentsStart() const { return m_ContentsStart; }
55 int GetContentsEnd() const { return m_ContentsEnd; }
56
57 void SetTitle(const wxString& title) { m_Title = title; }
58 void SetBasePath(const wxString& path) { m_BasePath = path; }
59 void SetStart(const wxString& start) { m_Start = start; }
60
6953da00
WS
61 // returns full filename of page (which is part of the book),
62 // i.e. with book's basePath prepended. If page is already absolute
468ae730
VS
63 // path, basePath is _not_ prepended.
64 wxString GetFullPath(const wxString &page) const;
65
97494971 66protected:
5ecdcaa7 67 wxString m_BookFile;
97494971
VS
68 wxString m_BasePath;
69 wxString m_Title;
70 wxString m_Start;
71 int m_ContentsStart;
72 int m_ContentsEnd;
8ec2b484
HH
73};
74
75
4460b6c4
VS
76WX_DECLARE_USER_EXPORTED_OBJARRAY(wxHtmlBookRecord, wxHtmlBookRecArray,
77 WXDLLIMPEXP_HTML);
8ec2b484 78
91fa114d
VS
79struct WXDLLIMPEXP_HTML wxHtmlHelpDataItem
80{
6953da00 81 wxHtmlHelpDataItem() : level(0), parent(NULL), id(wxID_ANY), book(NULL) {}
91fa114d 82
42841dfc 83 int level;
91fa114d
VS
84 wxHtmlHelpDataItem *parent;
85 int id;
86 wxString name;
87 wxString page;
88 wxHtmlBookRecord *book;
6953da00 89
91fa114d
VS
90 // returns full filename of m_Page, i.e. with book's basePath prepended
91 wxString GetFullPath() const { return book->GetFullPath(page); }
8ec2b484 92
91fa114d
VS
93 // returns item indented with spaces if it has level>1:
94 wxString GetIndentedName() const;
95};
96
97WX_DECLARE_USER_EXPORTED_OBJARRAY(wxHtmlHelpDataItem, wxHtmlHelpDataItems,
98 WXDLLIMPEXP_HTML);
99
8ec2b484
HH
100
101//------------------------------------------------------------------------------
2b5f62a0 102// wxHtmlSearchEngine
7929902d 103// This class takes input streams and scans them for occurrence
8ec2b484
HH
104// of keyword(s)
105//------------------------------------------------------------------------------
97494971 106
6acba9a7 107class WXDLLIMPEXP_HTML wxHtmlSearchEngine : public wxObject
8ec2b484 108{
97494971 109public:
3912b3f8 110 wxHtmlSearchEngine() : wxObject() {}
d3c7fc99 111 virtual ~wxHtmlSearchEngine() {}
f42b1601 112
97494971
VS
113 // Sets the keyword we will be searching for
114 virtual void LookFor(const wxString& keyword, bool case_sensitive, bool whole_words_only);
8ec2b484 115
97494971 116 // Scans the stream for the keyword.
6953da00 117 // Returns true if the stream contains keyword, fALSE otherwise
2b5f62a0 118 virtual bool Scan(const wxFSFile& file);
c4971147 119
97494971 120private:
3912b3f8 121 wxString m_Keyword;
97494971
VS
122 bool m_CaseSensitive;
123 bool m_WholeWords;
22f3361e 124
00e7a427 125 DECLARE_NO_COPY_CLASS(wxHtmlSearchEngine)
c4971147 126};
8ec2b484 127
8ec2b484 128
3103e8a9
JS
129// State information of a search action. I'd have preferred to make this a
130// nested class inside wxHtmlHelpData, but that's against coding standards :-(
f42b1601 131// Never construct this class yourself, obtain a copy from
8ec2b484 132// wxHtmlHelpData::PrepareKeywordSearch(const wxString& key)
6acba9a7 133class WXDLLIMPEXP_HTML wxHtmlSearchStatus
8ec2b484 134{
97494971
VS
135public:
136 // constructor; supply wxHtmlHelpData ptr, the keyword and (optionally) the
137 // title of the book to search. By default, all books are searched.
138 wxHtmlSearchStatus(wxHtmlHelpData* base, const wxString& keyword,
139 bool case_sensitive, bool whole_words_only,
140 const wxString& book = wxEmptyString);
141 bool Search(); // do the next iteration
142 bool IsActive() { return m_Active; }
143 int GetCurIndex() { return m_CurIndex; }
144 int GetMaxIndex() { return m_MaxIndex; }
145 const wxString& GetName() { return m_Name; }
91fa114d
VS
146
147 const wxHtmlHelpDataItem *GetCurItem() const { return m_CurItem; }
97494971
VS
148
149private:
150 wxHtmlHelpData* m_Data;
2b5f62a0 151 wxHtmlSearchEngine m_Engine;
97494971 152 wxString m_Keyword, m_Name;
3912b3f8 153 wxString m_LastPage;
91fa114d 154 wxHtmlHelpDataItem* m_CurItem;
97494971
VS
155 bool m_Active; // search is not finished
156 int m_CurIndex; // where we are now
157 int m_MaxIndex; // number of files we search
158 // For progress bar: 100*curindex/maxindex = % complete
22f3361e
VZ
159
160 DECLARE_NO_COPY_CLASS(wxHtmlSearchStatus)
f35822af 161};
8ec2b484 162
6acba9a7 163class WXDLLIMPEXP_HTML wxHtmlHelpData : public wxObject
8ec2b484 164{
97494971
VS
165 DECLARE_DYNAMIC_CLASS(wxHtmlHelpData)
166 friend class wxHtmlSearchStatus;
167
168public:
169 wxHtmlHelpData();
d3c7fc99 170 virtual ~wxHtmlHelpData();
97494971
VS
171
172 // Sets directory where temporary files are stored.
173 // These temp files are index & contents file in binary (much faster to read)
174 // form. These files are NOT deleted on program's exit.
175 void SetTempDir(const wxString& path);
176
177 // Adds new book. 'book' is location of .htb file (stands for "html book").
178 // See documentation for details on its format.
179 // Returns success.
180 bool AddBook(const wxString& book);
181 bool AddBookParam(const wxFSFile& bookfile,
182 wxFontEncoding encoding,
183 const wxString& title, const wxString& contfile,
184 const wxString& indexfile = wxEmptyString,
185 const wxString& deftopic = wxEmptyString,
67c276bd 186 const wxString& path = wxEmptyString);
97494971
VS
187
188 // Some accessing stuff:
189
190 // returns URL of page on basis of (file)name
191 wxString FindPageByName(const wxString& page);
192 // returns URL of page on basis of MS id
193 wxString FindPageById(int id);
194
91fa114d
VS
195 const wxHtmlBookRecArray& GetBookRecArray() const { return m_bookRecords; }
196
197 const wxHtmlHelpDataItems& GetContentsArray() const { return m_contents; }
198 const wxHtmlHelpDataItems& GetIndexArray() const { return m_index; }
199
97494971 200protected:
91fa114d 201 wxString m_tempPath;
97494971 202
97494971 203 // each book has one record in this array:
91fa114d
VS
204 wxHtmlBookRecArray m_bookRecords;
205
206 wxHtmlHelpDataItems m_contents; // list of all available books and pages
207 wxHtmlHelpDataItems m_index; // list of index itesm
6953da00 208
97494971
VS
209protected:
210 // Imports .hhp files (MS HTML Help Workshop)
211 bool LoadMSProject(wxHtmlBookRecord *book, wxFileSystem& fsys,
212 const wxString& indexfile, const wxString& contentsfile);
213 // Reads binary book
214 bool LoadCachedBook(wxHtmlBookRecord *book, wxInputStream *f);
215 // Writes binary book
216 bool SaveCachedBook(wxHtmlBookRecord *book, wxOutputStream *f);
22f3361e
VZ
217
218 DECLARE_NO_COPY_CLASS(wxHtmlHelpData)
f35822af 219};
8ec2b484
HH
220
221#endif
222
223#endif