]> git.saurik.com Git - wxWidgets.git/blob - src/html/htmlhelp_io.cpp
More stubs
[wxWidgets.git] / src / html / htmlhelp_io.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: htmlhelp.cpp
3 // Purpose: Help controller
4 // Author: Vaclav Slavik
5 // Copyright: (c) 1999 Vaclav Slavik
6 // Licence: wxWindows Licence
7 /////////////////////////////////////////////////////////////////////////////
8
9 #error This file should not be compiled! Update your build system! \
10 (configure users, rerun configure to get a new Makefile) \
11 Instead of htmlhelp[_io], use helpdata, helpfrm and helpctrl. This \
12 file is only left to point out the problem and will be removed r.s.n.
13
14
15 //#ifdef __GNUG__
16 //#pragma implementation "htmlhelp.h"
17 //#endif
18 // --- already in htmlhelp.cpp
19
20 #include <wx/wxprec.h>
21
22 #include "wx/defs.h"
23 #if wxUSE_HTML
24
25 #ifdef __BORDLANDC__
26 #pragma hdrstop
27 #endif
28
29 #ifndef WXPRECOMP
30 #include <wx/wx.h>
31 #endif
32
33
34 #include <wx/wxhtml.h>
35 #include <wx/busyinfo.h>
36
37
38
39
40 class HP_Parser : public wxHtmlParser
41 {
42 public:
43 void AddText(const char* text) {}
44 wxObject* GetProduct() {return NULL;}
45 };
46
47
48
49 class HP_TagHandler : public wxHtmlTagHandler
50 {
51 private:
52 wxString m_Name, m_Page;
53 int m_Level;
54 int m_ID;
55 int m_Index;
56 HtmlContentsItem *m_Items;
57 int m_ItemsCnt;
58 HtmlBookRecord *m_Book;
59
60 public:
61 HP_TagHandler(HtmlBookRecord *b) : wxHtmlTagHandler() {m_Book = b; m_Items = NULL; m_ItemsCnt = 0; m_Name = m_Page = wxEmptyString; m_Level = 0;}
62 wxString GetSupportedTags() {return "UL,OBJECT,PARAM";}
63 bool HandleTag(const wxHtmlTag& tag);
64 void WriteOut(HtmlContentsItem*& array, int& size);
65 void ReadIn(HtmlContentsItem* array, int size);
66 };
67
68
69 bool HP_TagHandler::HandleTag(const wxHtmlTag& tag)
70 {
71 if (tag.GetName() == "UL") {
72 m_Level++;
73 ParseInner(tag);
74 m_Level--;
75 return TRUE;
76 }
77
78 else if (tag.GetName() == "OBJECT") {
79 m_Name = m_Page = wxEmptyString;
80 ParseInner(tag);
81 if (m_Page != wxEmptyString) {
82 if (m_ItemsCnt % HTML_REALLOC_STEP == 0)
83 m_Items = (HtmlContentsItem*) realloc(m_Items, (m_ItemsCnt + HTML_REALLOC_STEP) * sizeof(HtmlContentsItem));
84 m_Items[m_ItemsCnt].m_Level = m_Level;
85 m_Items[m_ItemsCnt].m_ID = m_ID;
86 m_Items[m_ItemsCnt].m_Page = new char[m_Page.Length() + 1];
87 strcpy(m_Items[m_ItemsCnt].m_Page, m_Page.c_str());
88 m_Items[m_ItemsCnt].m_Name = new char [m_Name.Length() + 1];
89 strcpy(m_Items[m_ItemsCnt].m_Name, m_Name.c_str());
90 m_Items[m_ItemsCnt].m_Book = m_Book;
91 m_ItemsCnt++;
92 }
93 return TRUE;
94 }
95
96 else { // "PARAM"
97 if (m_Name == wxEmptyString && tag.GetParam("NAME") == "Name") m_Name = tag.GetParam("VALUE");
98 if (tag.GetParam("NAME") == "Local") m_Page = tag.GetParam("VALUE");
99 if (tag.GetParam("NAME") == "ID") tag.ScanParam("VALUE", "%i", &m_ID);
100 return FALSE;
101 }
102 }
103
104
105
106 void HP_TagHandler::WriteOut(HtmlContentsItem*& array, int& size)
107 {
108 array = m_Items;
109 size = m_ItemsCnt;
110 m_Items = NULL;
111 m_ItemsCnt = 0;
112 }
113
114 void HP_TagHandler::ReadIn(HtmlContentsItem* array, int size)
115 {
116 m_Items = array;
117 m_ItemsCnt = size;
118 }
119
120
121
122
123 void wxHtmlHelpController::LoadMSProject(HtmlBookRecord *book, wxFileSystem& fsys, const wxString& indexfile, const wxString& contentsfile, bool show_wait_msg)
124 {
125 wxFSFile *f;
126 char *buf;
127 int sz;
128 wxString string;
129 wxBusyInfo *busyinfo = (show_wait_msg) ? new wxBusyInfo(_("Importing help file : \n") + book -> m_Title) : NULL;
130
131 HP_Parser parser;
132 HP_TagHandler *handler = new HP_TagHandler(book);
133 parser.AddTagHandler(handler);
134
135 // Don't panic if no index or contensfile is supplied.
136 // (without contents is a bit useless, but leaving out the index is sometimes handy)
137 f = ( contentsfile.IsEmpty() ? NULL : fsys.OpenFile(contentsfile) );
138 if (f) {
139 sz = f -> GetStream() -> GetSize();
140 buf = new char[sz+1];
141 buf[sz] = 0;
142 f -> GetStream() -> Read(buf, sz);
143 delete f;
144 handler -> ReadIn(m_Contents, m_ContentsCnt);
145 parser.Parse(buf);
146 handler -> WriteOut(m_Contents, m_ContentsCnt);
147 delete[] buf;
148 }
149
150 f = ( indexfile.IsEmpty() ? NULL : fsys.OpenFile(indexfile) );
151 if (f) {
152 sz = f -> GetStream() -> GetSize();
153 buf = new char[sz+1];
154 buf[sz] = 0;
155 f -> GetStream() -> Read(buf, sz);
156 delete f;
157 handler -> ReadIn(m_Index, m_IndexCnt);
158 parser.Parse(buf);
159 handler -> WriteOut(m_Index, m_IndexCnt);
160 delete[] buf;
161 }
162 if (show_wait_msg) delete busyinfo;
163 }
164
165
166
167
168
169
170 void wxHtmlHelpController::LoadCachedBook(HtmlBookRecord *book, wxInputStream *f)
171 {
172 int i, st;
173 int x;
174
175 /* load contents : */
176
177 f -> Read(&x, sizeof(x));
178 st = m_ContentsCnt;
179 m_ContentsCnt += x;
180 m_Contents = (HtmlContentsItem*) realloc(m_Contents, (m_ContentsCnt / HTML_REALLOC_STEP + 1) * HTML_REALLOC_STEP * sizeof(HtmlContentsItem));
181 for (i = st; i < m_ContentsCnt; i++) {
182 f -> Read(&x, sizeof(x));
183 m_Contents[i].m_Level = x;
184 f -> Read(&x, sizeof(x));
185 m_Contents[i].m_ID = x;
186 f -> Read(&x, sizeof(x));
187 m_Contents[i].m_Name = new char[x];
188 f -> Read(m_Contents[i].m_Name, x);
189 f -> Read(&x, sizeof(x));
190 m_Contents[i].m_Page = new char[x];
191 f -> Read(m_Contents[i].m_Page, x);
192 m_Contents[i].m_Book = book;
193 }
194
195 /* load index : */
196
197 f -> Read(&x, sizeof(x));
198 st = m_IndexCnt;
199 m_IndexCnt += x;
200 m_Index = (HtmlContentsItem*) realloc(m_Index, (m_IndexCnt / HTML_REALLOC_STEP + 1) * HTML_REALLOC_STEP * sizeof(HtmlContentsItem));
201 for (i = st; i < m_IndexCnt; i++) {
202 f -> Read(&x, sizeof(x));
203 m_Index[i].m_Name = new char[x];
204 f -> Read(m_Index[i].m_Name, x);
205 f -> Read(&x, sizeof(x));
206 m_Index[i].m_Page = new char[x];
207 f -> Read(m_Index[i].m_Page, x);
208 m_Index[i].m_Book = book;
209 }
210 }
211
212
213
214
215
216
217 void wxHtmlHelpController::SaveCachedBook(HtmlBookRecord *book, wxOutputStream *f)
218 {
219 int i;
220 int x;
221
222 /* save contents : */
223
224 x = 0;
225 for (i = 0; i < m_ContentsCnt; i++) if (m_Contents[i].m_Book == book && m_Contents[i].m_Level > 0) x++;
226 f -> Write(&x, sizeof(x));
227 for (i = 0; i < m_ContentsCnt; i++) {
228 if (m_Contents[i].m_Book != book || m_Contents[i].m_Level == 0) continue;
229 x = m_Contents[i].m_Level;
230 f -> Write(&x, sizeof(x));
231 x = m_Contents[i].m_ID;
232 f -> Write(&x, sizeof(x));
233 x = strlen(m_Contents[i].m_Name) + 1;
234 f -> Write(&x, sizeof(x));
235 f -> Write(m_Contents[i].m_Name, x);
236 x = strlen(m_Contents[i].m_Page) + 1;
237 f -> Write(&x, sizeof(x));
238 f -> Write(m_Contents[i].m_Page, x);
239 }
240
241 /* save index : */
242
243 x = 0;
244 for (i = 0; i < m_IndexCnt; i++) if (m_Index[i].m_Book == book && m_Index[i].m_Level > 0) x++;
245 f -> Write(&x, sizeof(x));
246 for (i = 0; i < m_IndexCnt; i++) {
247 if (m_Index[i].m_Book != book || m_Index[i].m_Level == 0) continue;
248 x = strlen(m_Index[i].m_Name) + 1;
249 f -> Write(&x, sizeof(x));
250 f -> Write(m_Index[i].m_Name, x);
251 x = strlen(m_Index[i].m_Page) + 1;
252 f -> Write(&x, sizeof(x));
253 f -> Write(m_Index[i].m_Page, x);
254 }
255 }
256
257 #endif