]>
git.saurik.com Git - wxWidgets.git/blob - src/html/htmlhelp_io.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Help controller
4 // Author: Vaclav Slavik
5 // Copyright: (c) 1999 Vaclav Slavik
6 // Licence: wxWindows Licence
7 /////////////////////////////////////////////////////////////////////////////
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.
16 //#pragma implementation "htmlhelp.h"
18 // --- already in htmlhelp.cpp
20 #include <wx/wxprec.h>
34 #include <wx/wxhtml.h>
35 #include <wx/busyinfo.h>
40 class HP_Parser
: public wxHtmlParser
43 void AddText(const char* text
) {}
44 wxObject
* GetProduct() {return NULL
;}
49 class HP_TagHandler
: public wxHtmlTagHandler
52 wxString m_Name
, m_Page
;
56 HtmlContentsItem
*m_Items
;
58 HtmlBookRecord
*m_Book
;
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
);
69 bool HP_TagHandler::HandleTag(const wxHtmlTag
& tag
)
71 if (tag
.GetName() == "UL") {
78 else if (tag
.GetName() == "OBJECT") {
79 m_Name
= m_Page
= wxEmptyString
;
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
;
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
);
106 void HP_TagHandler::WriteOut(HtmlContentsItem
*& array
, int& size
)
114 void HP_TagHandler::ReadIn(HtmlContentsItem
* array
, int size
)
123 void wxHtmlHelpController::LoadMSProject(HtmlBookRecord
*book
, wxFileSystem
& fsys
, const wxString
& indexfile
, const wxString
& contentsfile
, bool show_wait_msg
)
129 wxBusyInfo
*busyinfo
= (show_wait_msg
) ? new wxBusyInfo(_("Importing help file : \n") + book
-> m_Title
) : NULL
;
132 HP_TagHandler
*handler
= new HP_TagHandler(book
);
133 parser
.AddTagHandler(handler
);
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
) );
139 sz
= f
-> GetStream() -> GetSize();
140 buf
= new char[sz
+1];
142 f
-> GetStream() -> Read(buf
, sz
);
144 handler
-> ReadIn(m_Contents
, m_ContentsCnt
);
146 handler
-> WriteOut(m_Contents
, m_ContentsCnt
);
150 f
= ( indexfile
.IsEmpty() ? NULL
: fsys
.OpenFile(indexfile
) );
152 sz
= f
-> GetStream() -> GetSize();
153 buf
= new char[sz
+1];
155 f
-> GetStream() -> Read(buf
, sz
);
157 handler
-> ReadIn(m_Index
, m_IndexCnt
);
159 handler
-> WriteOut(m_Index
, m_IndexCnt
);
162 if (show_wait_msg
) delete busyinfo
;
170 void wxHtmlHelpController::LoadCachedBook(HtmlBookRecord
*book
, wxInputStream
*f
)
175 /* load contents : */
177 f
-> Read(&x
, sizeof(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
;
197 f
-> Read(&x
, sizeof(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
;
217 void wxHtmlHelpController::SaveCachedBook(HtmlBookRecord
*book
, wxOutputStream
*f
)
222 /* save contents : */
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
);
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
);