]> git.saurik.com Git - wxWidgets.git/blame - include/wx/html/helpdata.h
added wxHTML
[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
7// Created:
8// RCS-ID:
9// Copyright: (c) Harm van der Heijden and Vaclav Slavik
10// Licence: wxWindows licence
11/////////////////////////////////////////////////////////////////////////////
12
13#ifndef _WX_HELPDATA_H_
14#define _WX_HELPDATA_H_
15
16#ifdef __GNUG__
17#pragma interface "helpdata.h"
18#endif
19
20#include "wx/defs.h"
21
22#if wxUSE_HTML
23
24#include "wx/object.h"
25#include "wx/string.h"
26#include "wx/filesys.h"
27#include "wx/dynarray.h"
28
29//--------------------------------------------------------------------------------
30// helper classes & structs
31//--------------------------------------------------------------------------------
32
33class WXDLLEXPORT wxHtmlBookRecord : public wxObject
34{
35public:
f42b1601 36 wxHtmlBookRecord(const wxString& basepath, const wxString& title,
8ec2b484
HH
37 const wxString& start) {
38 m_BasePath = basepath; m_Title = title; m_Start = start;
39 // for debugging, give the contents index obvious default values
40 contents_start = contents_end = -1;
41 }
42 wxString GetTitle() const {return m_Title;}
43 wxString GetStart() const {return m_Start;}
44 wxString GetBasePath() const {return m_BasePath;}
45 /* SetContentsRange: store in the bookrecord where in the index/contents lists the
46 * book's records are stored. This to facilitate searching in a specific book.
47 * This code will have to be revised when loading/removing books becomes dynamic.
f42b1601 48 * (as opposed to appending only)
8ec2b484
HH
49 * Note that storing index range is pointless, because the index is alphab. sorted. */
50 void SetContentsRange(int start, int end) { contents_start = start; contents_end = end; }
f42b1601
RD
51 int GetContentsStart() const { return contents_start; }
52 int GetContentsEnd() const { return contents_end; }
8ec2b484
HH
53protected:
54 wxString m_BasePath;
55 wxString m_Title;
56 wxString m_Start;
57 int contents_start;
58 int contents_end;
59};
60
61
62#undef WXDLLEXPORTLOCAL
63#define WXDLLEXPORTLOCAL WXDLLEXPORT
64 // ?? Don't know why - but Allen Van Sickel reported it to fix problems with DLL
65WX_DECLARE_OBJARRAY(wxHtmlBookRecord, wxHtmlBookRecArray);
66
67#undef WXDLLEXPORTLOCAL
68#define WXDLLEXPORTLOCAL
69
70
71typedef struct
72{
73 short int m_Level;
74 int m_ID;
75 char* m_Name;
76 char* m_Page;
77 wxHtmlBookRecord *m_Book;
78} wxHtmlContentsItem;
79
80//------------------------------------------------------------------------------
81// wxSearchEngine
82// This class takes input streams and scans them for occurence
83// of keyword(s)
84//------------------------------------------------------------------------------
f42b1601 85class WXDLLEXPORT wxSearchEngine : public wxObject
8ec2b484
HH
86{
87private:
88 char *m_Keyword;
89
90public:
91 wxSearchEngine() : wxObject() {m_Keyword = NULL;}
92 ~wxSearchEngine() {if (m_Keyword) free(m_Keyword);}
f42b1601 93
8ec2b484
HH
94 virtual void LookFor(const wxString& keyword);
95 // Sets the keyword we will be searching for
96
97 virtual bool Scan(wxInputStream *stream);
98 // Scans the stream for the keyword.
99 // Returns TRUE if the stream contains keyword, fALSE otherwise
100};
101
102class wxHtmlHelpData;
103
104// State information of a search action. I'd have prefered to make this a nested
105// class inside wxHtmlHelpData, but that's against coding standards :-(
f42b1601 106// Never construct this class yourself, obtain a copy from
8ec2b484
HH
107// wxHtmlHelpData::PrepareKeywordSearch(const wxString& key)
108class WXDLLEXPORT wxHtmlSearchStatus
109{
110public:
111 // constructor; supply wxHtmlHelpData ptr, the keyword and (optionally) the
112 // title of the book to search. By default, all books are searched.
113 wxHtmlSearchStatus(wxHtmlHelpData* base, const wxString& keyword,
114 const wxString& book = wxEmptyString);
115 bool Search(); // do the next iteration
116 bool IsActive() { return m_Active; }
117 int GetCurIndex() { return m_CurIndex; }
118 int GetMaxIndex() { return m_MaxIndex; }
119 const wxString& GetName() { return m_Name; }
120 wxHtmlContentsItem* GetContentsItem() { return m_ContentsItem; }
121private:
122 wxHtmlHelpData* m_Data;
123 wxSearchEngine m_Engine;
124 wxString m_Keyword, m_Name, m_LastPage;
f42b1601 125 wxHtmlContentsItem* m_ContentsItem;
8ec2b484
HH
126 bool m_Active; // search is not finished
127 int m_CurIndex; // where we are now
f42b1601 128 int m_MaxIndex; // number of files we search
8ec2b484
HH
129 // For progress bar: 100*curindex/maxindex = % complete
130};
131
132class WXDLLEXPORT wxHtmlHelpData : public wxObject
133{
134 DECLARE_DYNAMIC_CLASS(wxHtmlHelpData)
135
136 friend class wxHtmlSearchStatus;
137
138public:
139 wxHtmlHelpData();
140 ~wxHtmlHelpData();
f42b1601 141
8ec2b484
HH
142 void SetTempDir(const wxString& path);
143 // Sets directory where temporary files are stored.
144 // These temp files are index & contents file in binary (much faster to read)
145 // form. These files are NOT deleted on program's exit.
f42b1601 146
8ec2b484
HH
147 bool AddBook(const wxString& book);
148 // Adds new book. 'book' is location of .htb file (stands for "html book").
149 // See documentation for details on its format.
150 // Returns success.
f42b1601
RD
151 bool AddBookParam(const wxString& title, const wxString& contfile,
152 const wxString& indexfile=wxEmptyString,
153 const wxString& deftopic=wxEmptyString,
8ec2b484 154 const wxString& path=wxEmptyString);
f42b1601 155
8ec2b484
HH
156 // Some accessing stuff
157 wxString FindPageByName(const wxString& page);
158 // returns URL of page on basis of (file)name
159 wxString FindPageById(int id);
160 // returns URL of page on basis of MS id
161
162 const wxHtmlBookRecArray& GetBookRecArray() { return m_BookRecords; }
163 wxHtmlContentsItem* GetContents() { return m_Contents; }
164 int GetContentsCnt() { return m_ContentsCnt; }
165 wxHtmlContentsItem* GetIndex() { return m_Index; }
166 int GetIndexCnt() { return m_IndexCnt; }
f42b1601 167
8ec2b484
HH
168protected:
169 wxString m_TempPath;
f42b1601 170
8ec2b484
HH
171 wxHtmlBookRecArray m_BookRecords;
172 // each book has one record in this array
173 wxHtmlContentsItem* m_Contents;
174 int m_ContentsCnt;
175 // list of all available books and pages.
176 wxHtmlContentsItem* m_Index;
177 int m_IndexCnt;
178 // list of index items
f42b1601 179
8ec2b484 180protected:
f42b1601 181 bool LoadMSProject(wxHtmlBookRecord *book, wxFileSystem& fsys,
8ec2b484
HH
182 const wxString& indexfile, const wxString& contentsfile);
183 // Imports .hhp files (MS HTML Help Workshop)
184 bool LoadCachedBook(wxHtmlBookRecord *book, wxInputStream *f);
185 // Reads binary book
186 bool SaveCachedBook(wxHtmlBookRecord *book, wxOutputStream *f);
187 // Writes binary book
188};
189
190#endif
191
192#endif