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