]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: helpdata.cpp | |
3 | // Purpose: wxHtmlHelpData | |
4 | // Notes: Based on htmlhelp.cpp, implementing a monolithic | |
5 | // HTML Help controller class, by Vaclav Slavik | |
6 | // Author: Harm van der Heijden and Vaclav Slavik | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Harm van der Heijden and Vaclav Slavik | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation | |
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 | ||
25 | #if wxUSE_HTML && wxUSE_STREAMS | |
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" | |
35 | #include "wx/encconv.h" | |
36 | #include "wx/fontmap.h" | |
37 | #include "wx/log.h" | |
38 | #include "wx/html/htmlpars.h" | |
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 | ||
61 | ||
62 | static int LINKAGEMODE IndexCompareFunc(const void *a, const void *b) | |
63 | { | |
64 | return wxStrcmp(((wxHtmlContentsItem*)a)->m_Name, ((wxHtmlContentsItem*)b)->m_Name); | |
65 | } | |
66 | ||
67 | ||
68 | //----------------------------------------------------------------------------- | |
69 | // HP_Parser | |
70 | //----------------------------------------------------------------------------- | |
71 | ||
72 | class HP_Parser : public wxHtmlParser | |
73 | { | |
74 | public: | |
75 | void AddText(const char* WXUNUSED(text)) { } | |
76 | wxObject* GetProduct() { return NULL; } | |
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; | |
89 | int m_ID; | |
90 | int m_Index; | |
91 | wxHtmlContentsItem *m_Items; | |
92 | int m_ItemsCnt; | |
93 | wxHtmlBookRecord *m_Book; | |
94 | bool m_firstTime; // For checking if we're adding sections at level zero, so we 'delete' the first one | |
95 | ||
96 | public: | |
97 | HP_TagHandler(wxHtmlBookRecord *b) : wxHtmlTagHandler() | |
98 | { m_Book = b; m_Items = NULL; m_ItemsCnt = 0; m_Name = m_Page = wxEmptyString; | |
99 | m_Level = 0; m_ID = -1; m_firstTime = TRUE; } | |
100 | wxString GetSupportedTags() { return wxT("UL,OBJECT,PARAM"); } | |
101 | bool HandleTag(const wxHtmlTag& tag); | |
102 | void WriteOut(wxHtmlContentsItem*& array, int& size); | |
103 | void ReadIn(wxHtmlContentsItem* array, int size); | |
104 | }; | |
105 | ||
106 | ||
107 | bool HP_TagHandler::HandleTag(const wxHtmlTag& tag) | |
108 | { | |
109 | if (tag.GetName() == wxT("UL")) | |
110 | { | |
111 | m_Level++; | |
112 | ParseInner(tag); | |
113 | m_Level--; | |
114 | return TRUE; | |
115 | } | |
116 | else if (tag.GetName() == wxT("OBJECT")) | |
117 | { | |
118 | m_Name = m_Page = wxEmptyString; | |
119 | ParseInner(tag); | |
120 | ||
121 | if (tag.GetParam("TYPE") == "text/sitemap") | |
122 | ||
123 | // if (!m_Page.IsEmpty()) | |
124 | /* Valid HHW's file may contain only two object tags: | |
125 | ||
126 | <OBJECT type="text/site properties"> | |
127 | <param name="ImageType" value="Folder"> | |
128 | </OBJECT> | |
129 | ||
130 | or | |
131 | ||
132 | <OBJECT type="text/sitemap"> | |
133 | <param name="Name" value="main page"> | |
134 | <param name="Local" value="another.htm"> | |
135 | </OBJECT> | |
136 | ||
137 | We're interested in the latter. !m_Page.IsEmpty() is valid | |
138 | condition because text/site properties does not contain Local param | |
139 | */ | |
140 | { | |
141 | // We're reading in items at level zero, which must mean we want to specify | |
142 | // our own 'books', so chuck out the first (empty) one that AddBook already | |
143 | // created | |
144 | if (m_firstTime && (m_Level == 0) && (m_ItemsCnt > 0)) | |
145 | { | |
146 | m_ItemsCnt --; | |
147 | } | |
148 | else | |
149 | { | |
150 | if (m_ItemsCnt % wxHTML_REALLOC_STEP == 0) | |
151 | m_Items = (wxHtmlContentsItem*) realloc(m_Items, (m_ItemsCnt + wxHTML_REALLOC_STEP) * sizeof(wxHtmlContentsItem)); | |
152 | } | |
153 | m_Items[m_ItemsCnt].m_Level = m_Level; | |
154 | m_Items[m_ItemsCnt].m_ID = m_ID; | |
155 | m_Items[m_ItemsCnt].m_Page = new wxChar[m_Page.Length() + 1]; | |
156 | wxStrcpy(m_Items[m_ItemsCnt].m_Page, m_Page.c_str()); | |
157 | m_Items[m_ItemsCnt].m_Name = new wxChar [m_Name.Length() + 1]; | |
158 | wxStrcpy(m_Items[m_ItemsCnt].m_Name, m_Name.c_str()); | |
159 | m_Items[m_ItemsCnt].m_Book = m_Book; | |
160 | m_ItemsCnt++; | |
161 | ||
162 | m_firstTime = FALSE; | |
163 | } | |
164 | ||
165 | return TRUE; | |
166 | } | |
167 | else | |
168 | { // "PARAM" | |
169 | if (m_Name == wxEmptyString && tag.GetParam(wxT("NAME")) == wxT("Name")) | |
170 | { | |
171 | m_Name = tag.GetParam(wxT("VALUE")); | |
172 | if (m_Name.Find(wxT('&')) != -1) | |
173 | { | |
174 | #define ESCSEQ(escape, subst) \ | |
175 | { _T("&") _T(escape) _T(";"), _T("&") _T(escape) _T(" "), _T("&") _T(escape), _T(subst) } | |
176 | static wxChar* substitutions[][4] = | |
177 | { | |
178 | ESCSEQ("quot", "\""), | |
179 | ESCSEQ("#34", "\""), | |
180 | ESCSEQ("lt", "<"), | |
181 | ESCSEQ("#60", "<"), | |
182 | ESCSEQ("gt", ">"), | |
183 | ESCSEQ("#62", ">"), | |
184 | ||
185 | ESCSEQ("#94", "^"), /* ^ */ | |
186 | ||
187 | ESCSEQ("nbsp", " "), | |
188 | ESCSEQ("#32", " "), | |
189 | ESCSEQ("iexcl", "!"), | |
190 | ESCSEQ("#33", "!"), | |
191 |