]> git.saurik.com Git - wxWidgets.git/blame - include/wx/html/helpdata.h
Various fixes for wxMotif
[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
15#ifdef __GNUG__
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
97494971
VS
29class WXDLLEXPORT wxHtmlHelpData;
30
8ec2b484
HH
31//--------------------------------------------------------------------------------
32// helper classes & structs
33//--------------------------------------------------------------------------------
34
35class WXDLLEXPORT wxHtmlBookRecord : public wxObject
36{
97494971
VS
37public:
38 wxHtmlBookRecord(const wxString& basepath, const wxString& title,
39 const wxString& start)
40 {
41 m_BasePath = basepath;
42 m_Title = title;
43 m_Start = start;
44 // for debugging, give the contents index obvious default values
45 m_ContentsStart = m_ContentsEnd = -1;
46 }
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; }
58
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; }
62
468ae730
VS
63 // returns full filename of page (which is part of the book),
64 // i.e. with book's basePath prepended. If page is already absolute
65 // path, basePath is _not_ prepended.
66 wxString GetFullPath(const wxString &page) const;
67
97494971
VS
68protected:
69 wxString m_BasePath;
70 wxString m_Title;
71 wxString m_Start;
72 int m_ContentsStart;
73 int m_ContentsEnd;
8ec2b484
HH
74};
75
76
c4d83d0a 77WX_DECLARE_EXPORTED_OBJARRAY(wxHtmlBookRecord, wxHtmlBookRecArray);
8ec2b484 78
8ec2b484 79
97494971 80struct wxHtmlContentsItem
8ec2b484
HH
81{
82 short int m_Level;
83 int m_ID;
0e361044
OK
84 wxChar* m_Name;
85 wxChar* m_Page;
8ec2b484 86 wxHtmlBookRecord *m_Book;
468ae730
VS
87
88 // returns full filename of m_Page, i.e. with book's basePath prepended
89 wxString GetFullPath() const { return m_Book->GetFullPath(m_Page); }
97494971 90};
8ec2b484
HH
91
92//------------------------------------------------------------------------------
93// wxSearchEngine
94// This class takes input streams and scans them for occurence
95// of keyword(s)
96//------------------------------------------------------------------------------
97494971 97
f42b1601 98class WXDLLEXPORT wxSearchEngine : public wxObject
8ec2b484 99{
97494971
VS
100public:
101 wxSearchEngine() : wxObject() {m_Keyword = NULL; }
102 ~wxSearchEngine() {if (m_Keyword) delete[] m_Keyword; }
f42b1601 103
97494971
VS
104 // Sets the keyword we will be searching for
105 virtual void LookFor(const wxString& keyword, bool case_sensitive, bool whole_words_only);
8ec2b484 106
97494971
VS
107 // Scans the stream for the keyword.
108 // Returns TRUE if the stream contains keyword, fALSE otherwise
109 virtual bool Scan(wxInputStream *stream);
c4971147 110
97494971
VS
111private:
112 wxChar *m_Keyword;
113 bool m_CaseSensitive;
114 bool m_WholeWords;
c4971147 115};
8ec2b484 116
8ec2b484
HH
117
118// State information of a search action. I'd have prefered to make this a nested
119// class inside wxHtmlHelpData, but that's against coding standards :-(
f42b1601 120// Never construct this class yourself, obtain a copy from
8ec2b484
HH
121// wxHtmlHelpData::PrepareKeywordSearch(const wxString& key)
122class WXDLLEXPORT wxHtmlSearchStatus
123{
97494971
VS
124public:
125 // constructor; supply wxHtmlHelpData ptr, the keyword and (optionally) the
126 // title of the book to search. By default, all books are searched.
127 wxHtmlSearchStatus(wxHtmlHelpData* base, const wxString& keyword,
128 bool case_sensitive, bool whole_words_only,
129 const wxString& book = wxEmptyString);
130 bool Search(); // do the next iteration
131 bool IsActive() { return m_Active; }
132 int GetCurIndex() { return m_CurIndex; }
133 int GetMaxIndex() { return m_MaxIndex; }
134 const wxString& GetName() { return m_Name; }
135 wxHtmlContentsItem* GetContentsItem() { return m_ContentsItem; }
136
137private:
138 wxHtmlHelpData* m_Data;
139 wxSearchEngine m_Engine;
140 wxString m_Keyword, m_Name;
141 wxChar *m_LastPage;
142 wxHtmlContentsItem* m_ContentsItem;
143 bool m_Active; // search is not finished
144 int m_CurIndex; // where we are now
145 int m_MaxIndex; // number of files we search
146 // For progress bar: 100*curindex/maxindex = % complete
f35822af 147};
8ec2b484
HH
148
149class WXDLLEXPORT wxHtmlHelpData : public wxObject
150{
97494971
VS
151 DECLARE_DYNAMIC_CLASS(wxHtmlHelpData)
152 friend class wxHtmlSearchStatus;
153
154public:
155 wxHtmlHelpData();
156 ~wxHtmlHelpData();
157
158 // Sets directory where temporary files are stored.
159 // These temp files are index & contents file in binary (much faster to read)
160 // form. These files are NOT deleted on program's exit.
161 void SetTempDir(const wxString& path);
162
163 // Adds new book. 'book' is location of .htb file (stands for "html book").
164 // See documentation for details on its format.
165 // Returns success.
166 bool AddBook(const wxString& book);
167 bool AddBookParam(const wxFSFile& bookfile,
168 wxFontEncoding encoding,
169 const wxString& title, const wxString& contfile,
170 const wxString& indexfile = wxEmptyString,
171 const wxString& deftopic = wxEmptyString,
172 const wxString& path = wxEmptyString);
173
174 // Some accessing stuff:
175
176 // returns URL of page on basis of (file)name
177 wxString FindPageByName(const wxString& page);
178 // returns URL of page on basis of MS id
179 wxString FindPageById(int id);
180
181 const wxHtmlBookRecArray& GetBookRecArray() { return m_BookRecords; }
182 wxHtmlContentsItem* GetContents() { return m_Contents; }
183 int GetContentsCnt() { return m_ContentsCnt; }
184 wxHtmlContentsItem* GetIndex() { return m_Index; }
185 int GetIndexCnt() { return m_IndexCnt; }
186
187protected:
188 wxString m_TempPath;
189
190 wxHtmlBookRecArray m_BookRecords;
191 // each book has one record in this array:
192 wxHtmlContentsItem* m_Contents;
193 int m_ContentsCnt;
194 wxHtmlContentsItem* m_Index; // list of all available books and pages.
195 int m_IndexCnt; // list of index items
196
197protected:
198 // Imports .hhp files (MS HTML Help Workshop)
199 bool LoadMSProject(wxHtmlBookRecord *book, wxFileSystem& fsys,
200 const wxString& indexfile, const wxString& contentsfile);
201 // Reads binary book
202 bool LoadCachedBook(wxHtmlBookRecord *book, wxInputStream *f);
203 // Writes binary book
204 bool SaveCachedBook(wxHtmlBookRecord *book, wxOutputStream *f);
f35822af 205};
8ec2b484
HH
206
207#endif
208
209#endif