]>
Commit | Line | Data |
---|---|---|
8ec2b484 HH |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: helpdata.cpp | |
3 | // Purpose: wxHtmlHelpData | |
f42b1601 | 4 | // Notes: Based on htmlhelp.cpp, implementing a monolithic |
8ec2b484 HH |
5 | // HTML Help controller class, by Vaclav Slavik |
6 | // Author: Harm van der Heijden and Vaclav Slavik | |
69941f05 | 7 | // RCS-ID: $Id$ |
8ec2b484 HH |
8 | // Copyright: (c) Harm van der Heijden and Vaclav Slavik |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
69941f05 | 13 | #pragma implementation |
8ec2b484 HH |
14 | #endif |
15 | ||
16 | // For compilers that support precompilation, includes "wx.h". | |
17 | #include "wx/wxprec.h" | |
18 | ||
19 | #ifdef __BORLANDC__ | |
20 | #pragma hdrstop | |
21 | #endif | |
22 | ||
23 | #include "wx/defs.h" | |
24 | ||
f6bcfd97 | 25 | #if wxUSE_HTML && wxUSE_STREAMS |
8ec2b484 HH |
26 | |
27 | #ifndef WXPRECOMP | |
28 | #include "wx/wx.h" | |
29 | #endif | |
30 | ||
31 | #include "wx/html/helpdata.h" | |
32 | #include "wx/tokenzr.h" | |
33 | #include "wx/wfstream.h" | |
34 | #include "wx/busyinfo.h" | |
f890e2d4 VS |
35 | #include "wx/encconv.h" |
36 | #include "wx/fontmap.h" | |
f3c82859 | 37 | #include "wx/log.h" |
69941f05 | 38 | #include "wx/html/htmlpars.h" |
8ec2b484 HH |
39 | #include "wx/html/htmldefs.h" |
40 | ||
41 | #include "wx/arrimpl.cpp" | |
42 | WX_DEFINE_OBJARRAY(wxHtmlBookRecArray) | |
43 | ||
44 | //----------------------------------------------------------------------------- | |
45 | // static helper functions | |
46 | //----------------------------------------------------------------------------- | |
47 | ||
48 | // Reads one line, stores it into buf and returns pointer to new line or NULL. | |
49 | static char* ReadLine(char *line, char *buf) | |
50 | { | |
51 | char *writeptr = buf, *readptr = line; | |
52 | ||
53 | while (*readptr != 0 && *readptr != '\r' && *readptr != '\n') *(writeptr++) = *(readptr++); | |
54 | *writeptr = 0; | |
55 | while (*readptr == '\r' || *readptr == '\n') readptr++; | |
56 | if (*readptr == 0) return NULL; | |
57 | else return readptr; | |
58 | } | |
59 | ||
60 | ||
8ec2b484 | 61 | |
16a12a3d | 62 | static int LINKAGEMODE IndexCompareFunc(const void *a, const void *b) |
8ec2b484 | 63 | { |
4f9297b0 | 64 | return wxStrcmp(((wxHtmlContentsItem*)a)->m_Name, ((wxHtmlContentsItem*)b)->m_Name); |
8ec2b484 HH |
65 | } |
66 | ||
67 | ||
68 | //----------------------------------------------------------------------------- | |
69 | // HP_Parser | |
70 | //----------------------------------------------------------------------------- | |
71 | ||
72 | class HP_Parser : public wxHtmlParser | |
73 | { | |
74 | public: | |
0c5d3e1c VZ |
75 | void AddText(const char* WXUNUSED(text)) { } |
76 | wxObject* GetProduct() { return NULL; } | |
8ec2b484 HH |
77 | }; |
78 | ||
79 | ||
80 | //----------------------------------------------------------------------------- | |
81 | // HP_TagHandler | |
82 | //----------------------------------------------------------------------------- | |
83 | ||
84 | class HP_TagHandler : public wxHtmlTagHandler | |
85 | { | |
86 | private: | |
87 | wxString m_Name, m_Page; | |
88 | int m_Level; | |
d5bb85a0 | 89 | int m_ID; |
8ec2b484 HH |
90 | int m_Index; |
91 | wxHtmlContentsItem *m_Items; | |
92 | int m_ItemsCnt; | |
93 | wxHtmlBookRecord *m_Book; | |
94 | ||
95 | public: | |
4f9297b0 VS |
96 | HP_TagHandler(wxHtmlBookRecord *b) : wxHtmlTagHandler() |
97 | { m_Book = b; m_Items = NULL; m_ItemsCnt = 0; m_Name = m_Page = wxEmptyString; | |
98 | m_Level = 0; m_ID = -1; } | |
66a77a74 | 99 | wxString GetSupportedTags() { return wxT("UL,OBJECT,PARAM"); } |
8ec2b484 HH |
100 | bool HandleTag(const wxHtmlTag& tag); |
101 | void WriteOut(wxHtmlContentsItem*& array, int& size); | |
102 | void ReadIn(wxHtmlContentsItem* array, int size); | |
103 | }; | |
104 | ||
105 | ||
106 | bool HP_TagHandler::HandleTag(const wxHtmlTag& tag) | |
107 | { | |
4f9297b0 VS |
108 | if (tag.GetName() == wxT("UL")) |
109 | { | |
8ec2b484 HH |
110 | m_Level++; |
111 | ParseInner(tag); | |
112 | m_Level--; | |
113 | return TRUE; | |
114 | } | |
4f9297b0 VS |
115 | else if (tag.GetName() == wxT("OBJECT")) |
116 | { | |
8ec2b484 HH |
117 | m_Name = m_Page = wxEmptyString; |
118 | ParseInner(tag); | |
50494a55 | 119 | |
4157f43f VS |
120 | if (!m_Page.IsEmpty()) |
121 | /* should be 'if (tag.GetParam("TYPE") == "text/sitemap")' | |
122 | but this works fine. Valid HHW's file may contain only two | |
123 | object tags: | |
124 | ||
125 | <OBJECT type="text/site properties"> | |
126 | <param name="ImageType" value="Folder"> | |
127 | </OBJECT> | |
128 | ||
129 | or | |
130 | ||
131 | <OBJECT type="text/sitemap"> | |
132 | <param name="Name" value="main page"> | |
133 | <param name="Local" value="another.htm"> | |
134 | </OBJECT> | |
135 | ||
136 | We're interested in the latter. !m_Page.IsEmpty() is valid | |
137 | condition because text/site properties does not contain Local param | |
138 | */ | |
139 | { | |
140 | if (m_ItemsCnt % wxHTML_REALLOC_STEP == 0) | |
141 | m_Items = (wxHtmlContentsItem*) realloc(m_Items, (m_ItemsCnt + wxHTML_REALLOC_STEP) * sizeof(wxHtmlContentsItem)); | |
142 | m_Items[m_ItemsCnt].m_Level = m_Level; | |
143 | m_Items[m_ItemsCnt].m_ID = m_ID; | |
144 | m_Items[m_ItemsCnt].m_Page = new wxChar[m_Page.Length() + 1]; | |
145 | wxStrcpy(m_Items[m_ItemsCnt].m_Page, m_Page.c_str()); | |
146 | m_Items[m_ItemsCnt].m_Name = new wxChar [m_Name.Length() + 1]; | |
147 | wxStrcpy(m_Items[m_ItemsCnt].m_Name, m_Name.c_str()); | |
148 | m_Items[m_ItemsCnt].m_Book = m_Book; | |
149 | m_ItemsCnt++; | |
150 | } | |
50494a55 | 151 | |
8ec2b484 HH |
152 | return TRUE; |
153 | } | |
4f9297b0 VS |
154 | else |
155 | { // "PARAM" | |
f6bcfd97 BP |
156 | if (m_Name == wxEmptyString && tag.GetParam(wxT("NAME")) == wxT("Name")) |
157 | { | |
158 | m_Name = tag.GetParam(wxT("VALUE")); | |
159 | if (m_Name.Find(wxT('&')) != -1) | |
160 | { | |
161 | #define ESCSEQ(escape, subst) \ | |
162 | { _T("&") _T(escape) _T(";"), _T("&") _T(escape) _T(" "), _T(subst) } | |
163 | static wxChar* substitutions[][3] = | |
164 | { | |
165 | ESCSEQ("quot", "\""), | |
166 | ESCSEQ("lt", "<"), | |
167 | ESCSEQ("gt", ">"), | |
168 | ||
169 | ESCSEQ("nbsp", " "), | |
170 | ESCSEQ("iexcl", "!"), | |
171 |