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