]>
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 /////////////////////////////////////////////////////////////////////////////
11 //#pragma implementation "htmlhelp.h"
13 // --- already in htmlhelp.cpp
15 #include <wx/wxprec.h>
29 #include <wx/wxhtml.h>
30 #include <wx/busyinfo.h>
35 class HP_Parser
: public wxHtmlParser
38 void AddText(const char* text
) {}
39 wxObject
* GetProduct() {return NULL
;}
44 class HP_TagHandler
: public wxHtmlTagHandler
47 wxString m_Name
, m_Page
;
51 HtmlContentsItem
*m_Items
;
53 HtmlBookRecord
*m_Book
;
56 HP_TagHandler(HtmlBookRecord
*b
) : wxHtmlTagHandler() {m_Book
= b
; m_Items
= NULL
; m_ItemsCnt
= 0; m_Name
= m_Page
= wxEmptyString
; m_Level
= 0;}
57 wxString
GetSupportedTags() {return "UL,OBJECT,PARAM";}
58 bool HandleTag(const wxHtmlTag
& tag
);
59 void WriteOut(HtmlContentsItem
*& array
, int& size
);
60 void ReadIn(HtmlContentsItem
* array
, int size
);
64 bool HP_TagHandler::HandleTag(const wxHtmlTag
& tag
)
66 if (tag
.GetName() == "UL") {
73 else if (tag
.GetName() == "OBJECT") {
74 m_Name
= m_Page
= wxEmptyString
;
76 if (m_Page
!= wxEmptyString
) {
77 if (m_ItemsCnt
% HTML_REALLOC_STEP
== 0)
78 m_Items
= (HtmlContentsItem
*) realloc(m_Items
, (m_ItemsCnt
+ HTML_REALLOC_STEP
) * sizeof(HtmlContentsItem
));
79 m_Items
[m_ItemsCnt
].m_Level
= m_Level
;
80 m_Items
[m_ItemsCnt
].m_ID
= m_ID
;
81 m_Items
[m_ItemsCnt
].m_Page
= new char[m_Page
.Length() + 1];
82 strcpy(m_Items
[m_ItemsCnt
].m_Page
, m_Page
.c_str());
83 m_Items
[m_ItemsCnt
].m_Name
= new char [m_Name
.Length() + 1];
84 strcpy(m_Items
[m_ItemsCnt
].m_Name
, m_Name
.c_str());
85 m_Items
[m_ItemsCnt
].m_Book
= m_Book
;
92 if (m_Name
== wxEmptyString
&& tag
.GetParam("NAME") == "Name") m_Name
= tag
.GetParam("VALUE");
93 if (tag
.GetParam("NAME") == "Local") m_Page
= tag
.GetParam("VALUE");
94 if (tag
.GetParam("NAME") == "ID") tag
.ScanParam("VALUE", "%i", &m_ID
);
101 void HP_TagHandler::WriteOut(HtmlContentsItem
*& array
, int& size
)
109 void HP_TagHandler::ReadIn(HtmlContentsItem
* array
, int size
)
118 void wxHtmlHelpController::LoadMSProject(HtmlBookRecord
*book
, wxFileSystem
& fsys
, const wxString
& indexfile
, const wxString
& contentsfile
, bool show_wait_msg
)
124 wxBusyInfo
*busyinfo
= (show_wait_msg
) ? new wxBusyInfo(_("Importing help file : \n") + book
-> m_Title
) : NULL
;
127 HP_TagHandler
*handler
= new HP_TagHandler(book
);
128 parser
.AddTagHandler(handler
);
130 // Don't panic if no index or contensfile is supplied.
131 // (without contents is a bit useless, but leaving out the index is sometimes handy)
132 f
= ( contentsfile
.IsEmpty() ? NULL
: fsys
.OpenFile(contentsfile
) );
134 sz
= f
-> GetStream() -> GetSize();
135 buf
= new char[sz
+1];
137 f
-> GetStream() -> Read(buf
, sz
);
139 handler
-> ReadIn(m_Contents
, m_ContentsCnt
);
141 handler
-> WriteOut(m_Contents
, m_ContentsCnt
);
145 f
= ( indexfile
.IsEmpty() ? NULL
: fsys
.OpenFile(indexfile
) );
147 sz
= f
-> GetStream() -> GetSize();
148 buf
= new char[sz
+1];
150 f
-> GetStream() -> Read(buf
, sz
);
152 handler
-> ReadIn(m_Index
, m_IndexCnt
);
154 handler
-> WriteOut(m_Index
, m_IndexCnt
);
157 if (show_wait_msg
) delete busyinfo
;
165 void wxHtmlHelpController::LoadCachedBook(HtmlBookRecord
*book
, wxInputStream
*f
)
170 /* load contents : */
172 f
-> Read(&x
, sizeof(x
));
175 m_Contents
= (HtmlContentsItem
*) realloc(m_Contents
, (m_ContentsCnt
/ HTML_REALLOC_STEP
+ 1) * HTML_REALLOC_STEP
* sizeof(HtmlContentsItem
));
176 for (i
= st
; i
< m_ContentsCnt
; i
++) {
177 f
-> Read(&x
, sizeof(x
));
178 m_Contents
[i
].m_Level
= x
;
179 f
-> Read(&x
, sizeof(x
));
180 m_Contents
[i
].m_ID
= x
;
181 f
-> Read(&x
, sizeof(x
));
182 m_Contents
[i
].m_Name
= new char[x
];
183 f
-> Read(m_Contents
[i
].m_Name
, x
);
184 f
-> Read(&x
, sizeof(x
));
185 m_Contents
[i
].m_Page
= new char[x
];
186 f
-> Read(m_Contents
[i
].m_Page
, x
);
187 m_Contents
[i
].m_Book
= book
;
192 f
-> Read(&x
, sizeof(x
));
195 m_Index
= (HtmlContentsItem
*) realloc(m_Index
, (m_IndexCnt
/ HTML_REALLOC_STEP
+ 1) * HTML_REALLOC_STEP
* sizeof(HtmlContentsItem
));
196 for (i
= st
; i
< m_IndexCnt
; i
++) {
197 f
-> Read(&x
, sizeof(x
));
198 m_Index
[i
].m_Name
= new char[x
];
199 f
-> Read(m_Index
[i
].m_Name
, x
);
200 f
-> Read(&x
, sizeof(x
));
201 m_Index
[i
].m_Page
= new char[x
];
202 f
-> Read(m_Index
[i
].m_Page
, x
);
203 m_Index
[i
].m_Book
= book
;
212 void wxHtmlHelpController::SaveCachedBook(HtmlBookRecord
*book
, wxOutputStream
*f
)
217 /* save contents : */
220 for (i
= 0; i
< m_ContentsCnt
; i
++) if (m_Contents
[i
].m_Book
== book
&& m_Contents
[i
].m_Level
> 0) x
++;
221 f
-> Write(&x
, sizeof(x
));
222 for (i
= 0; i
< m_ContentsCnt
; i
++) {
223 if (m_Contents
[i
].m_Book
!= book
|| m_Contents
[i
].m_Level
== 0) continue;
224 x
= m_Contents
[i
].m_Level
;
225 f
-> Write(&x
, sizeof(x
));
226 x
= m_Contents
[i
].m_ID
;
227 f
-> Write(&x
, sizeof(x
));
228 x
= strlen(m_Contents
[i
].m_Name
) + 1;
229 f
-> Write(&x
, sizeof(x
));
230 f
-> Write(m_Contents
[i
].m_Name
, x
);
231 x
= strlen(m_Contents
[i
].m_Page
) + 1;
232 f
-> Write(&x
, sizeof(x
));
233 f
-> Write(m_Contents
[i
].m_Page
, x
);
239 for (i
= 0; i
< m_IndexCnt
; i
++) if (m_Index
[i
].m_Book
== book
&& m_Index
[i
].m_Level
> 0) x
++;
240 f
-> Write(&x
, sizeof(x
));
241 for (i
= 0; i
< m_IndexCnt
; i
++) {
242 if (m_Index
[i
].m_Book
!= book
|| m_Index
[i
].m_Level
== 0) continue;
243 x
= strlen(m_Index
[i
].m_Name
) + 1;
244 f
-> Write(&x
, sizeof(x
));
245 f
-> Write(m_Index
[i
].m_Name
, x
);
246 x
= strlen(m_Index
[i
].m_Page
) + 1;
247 f
-> Write(&x
, sizeof(x
));
248 f
-> Write(m_Index
[i
].m_Page
, x
);