]> git.saurik.com Git - wxWidgets.git/blame - include/wx/html/helpdata.h
Don't use wxUSE_POCKETPC_UI, determine appropriate UI from
[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
HH
8// Copyright: (c) Harm van der Heijden and Vaclav Slavik
9// Licence: wxWindows licence
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:
5ecdcaa7
VS
38 wxHtmlBookRecord(const wxString& bookfile, const wxString& basepath,
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
468ae730
VS
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
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
8ec2b484 83
97494971 84struct wxHtmlContentsItem
8ec2b484
HH
85{
86 short int m_Level;
87 int m_ID;
0e361044
OK
88 wxChar* m_Name;
89 wxChar* m_Page;
8ec2b484 90 wxHtmlBookRecord *m_Book;
468ae730
VS
91
92 // returns full filename of m_Page, i.e. with book's basePath prepended
93 wxString GetFullPath() const { return m_Book->GetFullPath(m_Page); }
97494971 94};
8ec2b484
HH
95
96//------------------------------------------------------------------------------
2b5f62a0 97// wxHtmlSearchEngine
8ec2b484
HH
98// This class takes input streams and scans them for occurence
99// of keyword(s)
100//------------------------------------------------------------------------------
97494971 101
6acba9a7 102class WXDLLIMPEXP_HTML wxHtmlSearchEngine : public wxObject
8ec2b484 103{
97494971 104public:
2b5f62a0
VZ
105 wxHtmlSearchEngine() : wxObject() {m_Keyword = NULL; }
106 ~wxHtmlSearchEngine() {if (m_Keyword) delete[] m_Keyword; }
f42b1601 107
97494971
VS
108 // Sets the keyword we will be searching for
109 virtual void LookFor(const wxString& keyword, bool case_sensitive, bool whole_words_only);
8ec2b484 110
97494971
VS
111 // Scans the stream for the keyword.
112 // Returns TRUE if the stream contains keyword, fALSE otherwise
2b5f62a0 113 virtual bool Scan(const wxFSFile& file);
c4971147 114
97494971
VS
115private:
116 wxChar *m_Keyword;
117 bool m_CaseSensitive;
118 bool m_WholeWords;
22f3361e 119
00e7a427 120 DECLARE_NO_COPY_CLASS(wxHtmlSearchEngine)
c4971147 121};
8ec2b484 122
8ec2b484
HH
123
124// State information of a search action. I'd have prefered to make this a nested
125// class inside wxHtmlHelpData, but that's against coding standards :-(
f42b1601 126// Never construct this class yourself, obtain a copy from
8ec2b484 127// wxHtmlHelpData::PrepareKeywordSearch(const wxString& key)
6acba9a7 128class WXDLLIMPEXP_HTML wxHtmlSearchStatus
8ec2b484 129{
97494971
VS
130public:
131 // constructor; supply wxHtmlHelpData ptr, the keyword and (optionally) the
132 // title of the book to search. By default, all books are searched.
133 wxHtmlSearchStatus(wxHtmlHelpData* base, const wxString& keyword,
134 bool case_sensitive, bool whole_words_only,
135 const wxString& book = wxEmptyString);
136 bool Search(); // do the next iteration
137 bool IsActive() { return m_Active; }
138 int GetCurIndex() { return m_CurIndex; }
139 int GetMaxIndex() { return m_MaxIndex; }
140 const wxString& GetName() { return m_Name; }
141 wxHtmlContentsItem* GetContentsItem() { return m_ContentsItem; }
142
143private:
144 wxHtmlHelpData* m_Data;
2b5f62a0 145 wxHtmlSearchEngine m_Engine;
97494971
VS
146 wxString m_Keyword, m_Name;
147 wxChar *m_LastPage;
148 wxHtmlContentsItem* m_ContentsItem;
149 bool m_Active; // search is not finished
150 int m_CurIndex; // where we are now
151 int m_MaxIndex; // number of files we search
152 // For progress bar: 100*curindex/maxindex = % complete
22f3361e
VZ
153
154 DECLARE_NO_COPY_CLASS(wxHtmlSearchStatus)
f35822af 155};
8ec2b484 156
6acba9a7 157class WXDLLIMPEXP_HTML wxHtmlHelpData : public wxObject
8ec2b484 158{
97494971
VS
159 DECLARE_DYNAMIC_CLASS(wxHtmlHelpData)
160 friend class wxHtmlSearchStatus;
161
162public:
163 wxHtmlHelpData();
164 ~wxHtmlHelpData();
165
166 // Sets directory where temporary files are stored.
167 // These temp files are index & contents file in binary (much faster to read)
168 // form. These files are NOT deleted on program's exit.
169 void SetTempDir(const wxString& path);
170
171 // Adds new book. 'book' is location of .htb file (stands for "html book").
172 // See documentation for details on its format.
173 // Returns success.
174 bool AddBook(const wxString& book);
175 bool AddBookParam(const wxFSFile& bookfile,
176 wxFontEncoding encoding,
177 const wxString& title, const wxString& contfile,
178 const wxString& indexfile = wxEmptyString,
179 const wxString& deftopic = wxEmptyString,
180 const wxString& path = wxEmptyString);
181
182 // Some accessing stuff:
183
184 // returns URL of page on basis of (file)name
185 wxString FindPageByName(const wxString& page);
186 // returns URL of page on basis of MS id
187 wxString FindPageById(int id);
188
189 const wxHtmlBookRecArray& GetBookRecArray() { return m_BookRecords; }
190 wxHtmlContentsItem* GetContents() { return m_Contents; }
191 int GetContentsCnt() { return m_ContentsCnt; }
192 wxHtmlContentsItem* GetIndex() { return m_Index; }
193 int GetIndexCnt() { return m_IndexCnt; }
194
195protected:
196 wxString m_TempPath;
197
198 wxHtmlBookRecArray m_BookRecords;
199 // each book has one record in this array:
200 wxHtmlContentsItem* m_Contents;
201 int m_ContentsCnt;
202 wxHtmlContentsItem* m_Index; // list of all available books and pages.
203 int m_IndexCnt; // list of index items
204
205protected:
206 // Imports .hhp files (MS HTML Help Workshop)
207 bool LoadMSProject(wxHtmlBookRecord *book, wxFileSystem& fsys,
208 const wxString& indexfile, const wxString& contentsfile);
209 // Reads binary book
210 bool LoadCachedBook(wxHtmlBookRecord *book, wxInputStream *f);
211 // Writes binary book
212 bool SaveCachedBook(wxHtmlBookRecord *book, wxOutputStream *f);
22f3361e
VZ
213
214 DECLARE_NO_COPY_CLASS(wxHtmlHelpData)
f35822af 215};
8ec2b484
HH
216
217#endif
218
219#endif