]>
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 f
= fsys
.OpenFile(contentsfile
);
132 sz
= f
-> GetStream() -> GetSize();
133 buf
= new char[sz
+1];
135 f
-> GetStream() -> Read(buf
, sz
);
137 handler
-> ReadIn(m_Contents
, m_ContentsCnt
);
139 handler
-> WriteOut(m_Contents
, m_ContentsCnt
);
143 f
= fsys
.OpenFile(indexfile
);
145 sz
= f
-> GetStream() -> GetSize();
146 buf
= new char[sz
+1];
148 f
-> GetStream() -> Read(buf
, sz
);
150 handler
-> ReadIn(m_Index
, m_IndexCnt
);
152 handler
-> WriteOut(m_Index
, m_IndexCnt
);
155 if (show_wait_msg
) delete busyinfo
;
163 void wxHtmlHelpController::LoadCachedBook(HtmlBookRecord
*book
, wxInputStream
*f
)
168 /* load contents : */
170 f
-> Read(&x
, sizeof(x
));
173 m_Contents
= (HtmlContentsItem
*) realloc(m_Contents
, (m_ContentsCnt
/ HTML_REALLOC_STEP
+ 1) * HTML_REALLOC_STEP
* sizeof(HtmlContentsItem
));
174 for (i
= st
; i
< m_ContentsCnt
; i
++) {
175 f
-> Read(&x
, sizeof(x
));
176 m_Contents
[i
].m_Level
= x
;
177 f
-> Read(&x
, sizeof(x
));
178 m_Contents
[i
].m_ID
= x
;
179 f
-> Read(&x
, sizeof(x
));
180 m_Contents
[i
].m_Name
= new char[x
];
181 f
-> Read(m_Contents
[i
].m_Name
, x
);
182 f
-> Read(&x
, sizeof(x
));
183 m_Contents
[i
].m_Page
= new char[x
];
184 f
-> Read(m_Contents
[i
].m_Page
, x
);
185 m_Contents
[i
].m_Book
= book
;
190 f
-> Read(&x
, sizeof(x
));
193 m_Index
= (HtmlContentsItem
*) realloc(m_Index
, (m_IndexCnt
/ HTML_REALLOC_STEP
+ 1) * HTML_REALLOC_STEP
* sizeof(HtmlContentsItem
));
194 for (i
= st
; i
< m_IndexCnt
; i
++) {
195 f
-> Read(&x
, sizeof(x
));
196 m_Index
[i
].m_Name
= new char[x
];
197 f
-> Read(m_Index
[i
].m_Name
, x
);
198 f
-> Read(&x
, sizeof(x
));
199 m_Index
[i
].m_Page
= new char[x
];
200 f
-> Read(m_Index
[i
].m_Page
, x
);
201 m_Index
[i
].m_Book
= book
;
210 void wxHtmlHelpController::SaveCachedBook(HtmlBookRecord
*book
, wxOutputStream
*f
)
215 /* save contents : */
218 for (i
= 0; i
< m_ContentsCnt
; i
++) if (m_Contents
[i
].m_Book
== book
&& m_Contents
[i
].m_Level
> 0) x
++;
219 f
-> Write(&x
, sizeof(x
));
220 for (i
= 0; i
< m_ContentsCnt
; i
++) {
221 if (m_Contents
[i
].m_Book
!= book
|| m_Contents
[i
].m_Level
== 0) continue;
222 x
= m_Contents
[i
].m_Level
;
223 f
-> Write(&x
, sizeof(x
));
224 x
= m_Contents
[i
].m_ID
;
225 f
-> Write(&x
, sizeof(x
));
226 x
= strlen(m_Contents
[i
].m_Name
) + 1;
227 f
-> Write(&x
, sizeof(x
));
228 f
-> Write(m_Contents
[i
].m_Name
, x
);
229 x
= strlen(m_Contents
[i
].m_Page
) + 1;
230 f
-> Write(&x
, sizeof(x
));
231 f
-> Write(m_Contents
[i
].m_Page
, x
);
237 for (i
= 0; i
< m_IndexCnt
; i
++) if (m_Index
[i
].m_Book
== book
&& m_Index
[i
].m_Level
> 0) x
++;
238 f
-> Write(&x
, sizeof(x
));
239 for (i
= 0; i
< m_IndexCnt
; i
++) {
240 if (m_Index
[i
].m_Book
!= book
|| m_Index
[i
].m_Level
== 0) continue;
241 x
= strlen(m_Index
[i
].m_Name
) + 1;
242 f
-> Write(&x
, sizeof(x
));
243 f
-> Write(m_Index
[i
].m_Name
, x
);
244 x
= strlen(m_Index
[i
].m_Page
) + 1;
245 f
-> Write(&x
, sizeof(x
));
246 f
-> Write(m_Index
[i
].m_Page
, x
);