]>
Commit | Line | Data |
---|---|---|
5526e819 VS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: htmlwin.cpp | |
3 | // Purpose: wxHtmlWindow class for parsing & displaying HTML (implementation) | |
4 | // Author: Vaclav Slavik | |
69941f05 | 5 | // RCS-ID: $Id$ |
5526e819 VS |
6 | // Copyright: (c) 1999 Vaclav Slavik |
7 | // Licence: wxWindows Licence | |
8 | ///////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | ||
11 | #ifdef __GNUG__ | |
892aeafc VS |
12 | #pragma implementation "htmlwin.h" |
13 | #pragma implementation "htmlproc.h" | |
5526e819 VS |
14 | #endif |
15 | ||
3096bd2f | 16 | #include "wx/wxprec.h" |
5526e819 VS |
17 | |
18 | #include "wx/defs.h" | |
f6bcfd97 | 19 | #if wxUSE_HTML && wxUSE_STREAMS |
5526e819 VS |
20 | |
21 | #ifdef __BORDLANDC__ | |
22 | #pragma hdrstop | |
23 | #endif | |
24 | ||
25 | #ifndef WXPRECOMP | |
3096bd2f | 26 | #include "wx/wx.h" |
5526e819 VS |
27 | #endif |
28 | ||
69941f05 | 29 | #include "wx/html/htmlwin.h" |
69941f05 | 30 | #include "wx/html/forcelnk.h" |
892aeafc | 31 | #include "wx/html/htmlproc.h" |
f3c82859 | 32 | #include "wx/log.h" |
892aeafc VS |
33 | #include "wx/arrimpl.cpp" |
34 | #include "wx/list.h" | |
35 | #include "wx/listimpl.cpp" | |
36 | ||
37 | //----------------------------------------------------------------------------- | |
38 | // wxHtmlHistoryItem | |
39 | //----------------------------------------------------------------------------- | |
40 | ||
41 | // item of history list | |
42 | class WXDLLEXPORT wxHtmlHistoryItem : public wxObject | |
43 | { | |
44 | public: | |
45 | wxHtmlHistoryItem(const wxString& p, const wxString& a) {m_Page = p, m_Anchor = a, m_Pos = 0;} | |
46 | int GetPos() const {return m_Pos;} | |
47 | void SetPos(int p) {m_Pos = p;} | |
48 | const wxString& GetPage() const {return m_Page;} | |
49 | const wxString& GetAnchor() const {return m_Anchor;} | |
50 | ||
51 | private: | |
52 | wxString m_Page; | |
53 | wxString m_Anchor; | |
54 | int m_Pos; | |
55 | }; | |
5526e819 | 56 | |
5526e819 VS |
57 | |
58 | //----------------------------------------------------------------------------- | |
892aeafc | 59 | // our private arrays: |
5526e819 VS |
60 | //----------------------------------------------------------------------------- |
61 | ||
892aeafc VS |
62 | WX_DECLARE_OBJARRAY(wxHtmlHistoryItem, wxHtmlHistoryArray); |
63 | WX_DEFINE_OBJARRAY(wxHtmlHistoryArray); | |
5526e819 | 64 | |
892aeafc VS |
65 | WX_DECLARE_LIST(wxHtmlProcessor, wxHtmlProcessorList); |
66 | WX_DEFINE_LIST(wxHtmlProcessorList); | |
5526e819 | 67 | |
892aeafc VS |
68 | //----------------------------------------------------------------------------- |
69 | // wxHtmlWindow | |
70 | //----------------------------------------------------------------------------- | |
5526e819 VS |
71 | |
72 | ||
269e8200 | 73 | wxHtmlWindow::wxHtmlWindow(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, |
f6bcfd97 | 74 | long style, const wxString& name) : wxScrolledWindow(parent, id, pos, size, style | wxVSCROLL | wxHSCROLL, name) |
5526e819 VS |
75 | { |
76 | m_tmpMouseMoved = FALSE; | |
846914d1 | 77 | m_tmpLastLink = NULL; |
89de9af3 | 78 | m_tmpCanDrawLocks = 0; |
5526e819 VS |
79 | m_FS = new wxFileSystem(); |
80 | m_RelatedStatusBar = -1; | |
81 | m_RelatedFrame = NULL; | |
892aeafc | 82 | m_TitleFormat = wxT("%s"); |
d5db80c2 | 83 | m_OpenedPage = m_OpenedAnchor = m_OpenedPageTitle = wxEmptyString; |
5526e819 VS |
84 | m_Cell = NULL; |
85 | m_Parser = new wxHtmlWinParser(this); | |
4f9297b0 | 86 | m_Parser->SetFS(m_FS); |
5526e819 VS |
87 | SetBorders(10); |
88 | m_HistoryPos = -1; | |
89 | m_HistoryOn = TRUE; | |
892aeafc VS |
90 | m_History = new wxHtmlHistoryArray; |
91 | m_Processors = NULL; | |
a547ebff | 92 | m_Style = style; |
4f9297b0 | 93 | SetPage(wxT("<html><body></body></html>")); |
5526e819 VS |
94 | } |
95 | ||
96 | ||
97 | ||
98 | wxHtmlWindow::~wxHtmlWindow() | |
99 | { | |
100 | HistoryClear(); | |
101 | ||
102 | if (m_Cell) delete m_Cell; | |
103 | ||
5526e819 VS |
104 | delete m_Parser; |
105 | delete m_FS; | |
892aeafc VS |
106 | delete m_History; |
107 | delete m_Processors; | |
5526e819 VS |
108 | } |
109 | ||
110 | ||
111 | ||
112 | void wxHtmlWindow::SetRelatedFrame(wxFrame* frame, const wxString& format) | |
113 | { | |
114 | m_RelatedFrame = frame; | |
115 | m_TitleFormat = format; | |
116 | } | |
117 | ||
118 | ||
119 | ||
120 | void wxHtmlWindow::SetRelatedStatusBar(int bar) | |
121 | { | |
122 | m_RelatedStatusBar = bar; | |
123 | } | |
269e8200 RD |
124 | |
125 | ||
126 | ||
8eb2940f | 127 | void wxHtmlWindow::SetFonts(wxString normal_face, wxString fixed_face, const int *sizes) |
5526e819 | 128 | { |
d5db80c2 VS |
129 | wxString op = m_OpenedPage; |
130 | ||
4f9297b0 | 131 | m_Parser->SetFonts(normal_face, fixed_face, sizes); |
892aeafc | 132 | // fonts changed => contents invalid, so reload the page: |
bfb9ee96 | 133 | SetPage(wxT("<html><body></body></html>")); |
d5db80c2 | 134 | if (!op.IsEmpty()) LoadPage(op); |
5526e819 VS |
135 | } |
136 | ||
137 | ||
138 | ||
139 | bool wxHtmlWindow::SetPage(const wxString& source) | |
140 | { | |
892aeafc VS |
141 | wxString newsrc(source); |
142 | ||
143 | // pass HTML through registered processors: | |
144 | if (m_Processors || m_SharedProcessors) | |
145 | { | |
146 | wxHtmlProcessorList::Node *nodeL, *nodeS; | |
147 | int prL, prS; | |
148 | ||
149 | nodeL = (m_Processors) ? m_Processors->GetFirst() : NULL; | |
150 | nodeS = (m_SharedProcessors) ? m_SharedProcessors->GetFirst() : NULL; | |
151 | ||
152 | while (nodeL || nodeS) | |
153 | { | |
154 | prL = (nodeL) ? nodeL->GetData()->GetPriority() : -1; | |
155 | prS = (nodeS) ? nodeS->GetData()->GetPriority() : -1; | |
156 | if (prL > prS) | |
157 | { | |
158 | newsrc = nodeL->GetData()->Process(newsrc); | |
159 | nodeL = nodeL->GetNext(); | |
160 | } | |
161 | else // prL <= prS | |
162 | { | |
163 | newsrc = nodeS->GetData()->Process(newsrc); | |
164 | nodeS = nodeS->GetNext(); | |
165 | } | |
166 | } | |
167 | } | |
5526e819 | 168 | |
892aeafc VS |
169 | // ...and run the parser on it: |
170 | wxClientDC *dc = new wxClientDC(this); | |
4f9297b0 | 171 | dc->SetMapMode(wxMM_TEXT); |
5526e819 | 172 | SetBackgroundColour(wxColour(0xFF, 0xFF, 0xFF)); |
d5db80c2 | 173 | m_OpenedPage = m_OpenedAnchor = m_OpenedPageTitle = wxEmptyString; |
4f9297b0 | 174 | m_Parser->SetDC(dc); |
33ac7e6f | 175 | if (m_Cell) |
4f9297b0 | 176 | { |
89de9af3 VS |
177 | delete m_Cell; |
178 | m_Cell = NULL; | |
f61815af | 179 | } |
892aeafc | 180 | m_Cell = (wxHtmlContainerCell*) m_Parser->Parse(newsrc); |
5526e819 | 181 | delete dc; |
4f9297b0 VS |
182 | m_Cell->SetIndent(m_Borders, wxHTML_INDENT_ALL, wxHTML_UNITS_PIXELS); |
183 | m_Cell->SetAlignHor(wxHTML_ALIGN_CENTER); | |
5526e819 | 184 | CreateLayout(); |
bfb9ee96 | 185 | if (m_tmpCanDrawLocks == 0) |
892aeafc | 186 | Refresh(); |
5526e819 VS |
187 | return TRUE; |
188 | } | |
189 | ||
190 | ||
191 | bool wxHtmlWindow::LoadPage(const wxString& location) | |
192 | { | |
193 | wxFSFile *f; | |
194 | bool rt_val; | |
fc7dfaf8 | 195 | bool needs_refresh = FALSE; |
33ac7e6f | 196 | |
169ee06c | 197 | SetCursor(*wxHOURGLASS_CURSOR); |
fc7dfaf8 | 198 | wxYield(); Refresh(FALSE); |
5526e819 | 199 | |
89de9af3 | 200 | m_tmpCanDrawLocks++; |
4f9297b0 VS |
201 | if (m_HistoryOn && (m_HistoryPos != -1)) // store scroll position into history item |
202 | { | |
5526e819 VS |
203 | int x, y; |
204 | ViewStart(&x, &y); | |
892aeafc | 205 | (*m_History)[m_HistoryPos].SetPos(y); |
5526e819 VS |
206 | } |
207 | ||
4f9297b0 VS |
208 | if (location[0] == wxT('#')) // local anchor |
209 | { | |
5526e819 | 210 | wxString anch = location.Mid(1) /*1 to end*/; |
89de9af3 | 211 | m_tmpCanDrawLocks--; |
5526e819 | 212 | rt_val = ScrollToAnchor(anch); |
fc7dfaf8 VS |
213 | m_tmpCanDrawLocks++; |
214 | } | |
33ac7e6f | 215 | else if (location.Find(wxT('#')) != wxNOT_FOUND && location.BeforeFirst(wxT('#')) == m_OpenedPage) |
4f9297b0 | 216 | { |
fc7dfaf8 VS |
217 | wxString anch = location.AfterFirst(wxT('#')); |
218 | m_tmpCanDrawLocks--; | |
219 | rt_val = ScrollToAnchor(anch); | |
220 | m_tmpCanDrawLocks++; | |
221 | } | |
33ac7e6f KB |
222 | else if (location.Find(wxT('#')) != wxNOT_FOUND && |
223 | (m_FS->GetPath() + location.BeforeFirst(wxT('#'))) == m_OpenedPage) | |
4f9297b0 | 224 | { |
fc7dfaf8 VS |
225 | wxString anch = location.AfterFirst(wxT('#')); |
226 | m_tmpCanDrawLocks--; | |
227 | rt_val = ScrollToAnchor(anch); | |
228 | m_tmpCanDrawLocks++; | |
5526e819 VS |
229 | } |
230 | ||
33ac7e6f | 231 | else |
4f9297b0 | 232 | { |
fc7dfaf8 | 233 | needs_refresh = TRUE; |
5526e819 | 234 | // load&display it: |
33ac7e6f | 235 | if (m_RelatedStatusBar != -1) |
4f9297b0 VS |
236 | { |
237 | m_RelatedFrame->SetStatusText(_("Connecting..."), m_RelatedStatusBar); | |
fc7dfaf8 | 238 | Refresh(FALSE); |
5526e819 VS |
239 | } |
240 | ||
4f9297b0 | 241 | f = m_FS->OpenFile(location); |
33ac7e6f KB |
242 | |
243 | if (f == NULL) | |
4f9297b0 | 244 | { |
5526e819 VS |
245 | wxString err; |
246 | ||
f6bcfd97 | 247 | wxLogError(_("Unable to open requested HTML document: %s"), location.c_str()); |
89de9af3 | 248 | m_tmpCanDrawLocks--; |
169ee06c VS |
249 | |
250 | SetCursor(*wxSTANDARD_CURSOR); | |
5526e819 VS |
251 | return FALSE; |
252 | } | |
253 | ||
33ac7e6f | 254 | else |
4f9297b0 | 255 | { |
5526e819 VS |
256 | wxNode *node; |
257 | wxString src = wxEmptyString; | |
258 | ||
33ac7e6f | 259 | if (m_RelatedStatusBar != -1) |
4f9297b0 | 260 | { |
5526e819 | 261 | wxString msg = _("Loading : ") + location; |
4f9297b0 | 262 | m_RelatedFrame->SetStatusText(msg, m_RelatedStatusBar); |
fc7dfaf8 | 263 | Refresh(FALSE); |
5526e819 VS |
264 | } |
265 | ||
266 | node = m_Filters.GetFirst(); | |
4f9297b0 VS |
267 | while (node) |
268 | { | |
269 | wxHtmlFilter *h = (wxHtmlFilter*) node->GetData(); | |
270 | if (h->CanRead(*f)) | |
271 | { | |
272 | src = h->ReadFile(*f); | |
5526e819 VS |
273 | break; |
274 | } | |
4f9297b0 | 275 | node = node->GetNext(); |
5526e819 | 276 | } |
33ac7e6f | 277 | if (src == wxEmptyString) |
4f9297b0 | 278 | { |
89de9af3 | 279 | if (m_DefaultFilter == NULL) m_DefaultFilter = GetDefaultFilter(); |
4f9297b0 | 280 | src = m_DefaultFilter->ReadFile(*f); |
89de9af3 | 281 | } |
5526e819 | 282 | |
4f9297b0 | 283 | m_FS->ChangePathTo(f->GetLocation()); |
5526e819 | 284 | rt_val = SetPage(src); |
4f9297b0 | 285 | m_OpenedPage = f->GetLocation(); |
33ac7e6f | 286 | if (f->GetAnchor() != wxEmptyString) |
4f9297b0 | 287 | { |
fc7dfaf8 | 288 | wxYield(); |
4f9297b0 | 289 | ScrollToAnchor(f->GetAnchor()); |
5526e819 VS |
290 | } |
291 | ||
292 | delete f; | |
293 | ||
4f9297b0 | 294 | if (m_RelatedStatusBar != -1) m_RelatedFrame->SetStatusText(_("Done"), m_RelatedStatusBar); |
5526e819 VS |
295 | } |
296 | } | |
297 | ||
4f9297b0 VS |
298 | if (m_HistoryOn) // add this page to history there: |
299 | { | |
892aeafc | 300 | int c = m_History->GetCount() - (m_HistoryPos + 1); |
5526e819 VS |
301 | |
302 | m_HistoryPos++; | |
303 | for (int i = 0; i < c; i++) | |
892aeafc VS |
304 | m_History->Remove(m_HistoryPos); |
305 | m_History->Add(new wxHtmlHistoryItem(m_OpenedPage, m_OpenedAnchor)); | |
5526e819 VS |
306 | } |
307 | ||
096824d7 VS |
308 | if (m_OpenedPageTitle == wxEmptyString) |
309 | OnSetTitle(wxFileNameFromPath(m_OpenedPage)); | |
169ee06c | 310 | SetCursor(*wxSTANDARD_CURSOR); |
fc7dfaf8 | 311 | |
33ac7e6f | 312 | if (needs_refresh) |
4f9297b0 | 313 | { |
fc7dfaf8 VS |
314 | wxYield(); |
315 | m_tmpCanDrawLocks--; | |
316 | Refresh(); | |
317 | } | |
318 | else | |
319 | m_tmpCanDrawLocks--; | |
320 | ||
5526e819 VS |
321 | return rt_val; |
322 | } | |
323 | ||
324 | ||
325 | ||
326 | bool wxHtmlWindow::ScrollToAnchor(const wxString& anchor) | |
327 | { | |
4f9297b0 | 328 | const wxHtmlCell *c = m_Cell->Find(wxHTML_COND_ISANCHOR, &anchor); |
f3c82859 VS |
329 | if (!c) |
330 | { | |
f6bcfd97 | 331 | wxLogWarning(_("HTML anchor %s does not exist."), anchor.c_str()); |
f3c82859 VS |
332 | return FALSE; |
333 | } | |
33ac7e6f | 334 | else |
4f9297b0 | 335 | { |
5526e819 | 336 | int y; |
269e8200 | 337 | |
4f9297b0 | 338 | for (y = 0; c != NULL; c = c->GetParent()) y += c->GetPosY(); |
efba2b89 | 339 | Scroll(-1, y / wxHTML_SCROLL_STEP); |
5526e819 VS |
340 | m_OpenedAnchor = anchor; |
341 | return TRUE; | |
342 | } | |
343 | } | |
344 | ||
345 | ||
d5db80c2 | 346 | void wxHtmlWindow::OnSetTitle(const wxString& title) |
5526e819 | 347 | { |
33ac7e6f | 348 | if (m_RelatedFrame) |
4f9297b0 | 349 | { |
5526e819 VS |
350 | wxString tit; |
351 | tit.Printf(m_TitleFormat, title.c_str()); | |
4f9297b0 | 352 | m_RelatedFrame->SetTitle(tit); |
5526e819 | 353 | } |
d5db80c2 | 354 | m_OpenedPageTitle = title; |
5526e819 VS |
355 | } |
356 | ||
357 | ||
358 | ||
359 | ||
360 | ||
361 | void wxHtmlWindow::CreateLayout() | |
362 | { | |
363 | int ClientWidth, ClientHeight; | |
364 | ||
365 | if (!m_Cell) return; | |
a547ebff | 366 | |
33ac7e6f | 367 | if (m_Style & wxHW_SCROLLBAR_NEVER) |
4f9297b0 VS |
368 | { |
369 | SetScrollbars(wxHTML_SCROLL_STEP, 1, m_Cell->GetWidth() / wxHTML_SCROLL_STEP, 0); // always off | |
a547ebff | 370 | GetClientSize(&ClientWidth, &ClientHeight); |
4f9297b0 | 371 | m_Cell->Layout(ClientWidth); |
a547ebff VS |
372 | } |
373 | ||
374 | else { | |
375 | GetClientSize(&ClientWidth, &ClientHeight); | |
4f9297b0 | 376 | m_Cell->Layout(ClientWidth); |
33ac7e6f | 377 | if (ClientHeight < m_Cell->GetHeight() + GetCharHeight()) |
4f9297b0 | 378 | { |
f3bcfd9b VS |
379 | SetScrollbars( |
380 | wxHTML_SCROLL_STEP, wxHTML_SCROLL_STEP, | |
4f9297b0 VS |
381 | m_Cell->GetWidth() / wxHTML_SCROLL_STEP, |
382 | (m_Cell->GetHeight() + GetCharHeight()) / wxHTML_SCROLL_STEP | |
f3bcfd9b | 383 | /*cheat: top-level frag is always container*/); |
a547ebff | 384 | } |
4f9297b0 VS |
385 | else /* we fit into window, no need for scrollbars */ |
386 | { | |
387 | SetScrollbars(wxHTML_SCROLL_STEP, 1, m_Cell->GetWidth() / wxHTML_SCROLL_STEP, 0); // disable... | |
89de9af3 | 388 | GetClientSize(&ClientWidth, &ClientHeight); |
4f9297b0 | 389 | m_Cell->Layout(ClientWidth); // ...and relayout |
89de9af3 | 390 | } |
a547ebff | 391 | } |
5526e819 VS |
392 | } |
393 | ||
269e8200 | 394 | |
5526e819 VS |
395 | |
396 | void wxHtmlWindow::ReadCustomization(wxConfigBase *cfg, wxString path) | |
397 | { | |
398 | wxString oldpath; | |
399 | wxString tmp; | |
d5db80c2 VS |
400 | int p_fontsizes[7]; |
401 | wxString p_fff, p_ffn; | |
5526e819 | 402 | |
33ac7e6f | 403 | if (path != wxEmptyString) |
4f9297b0 VS |
404 | { |
405 | oldpath = cfg->GetPath(); | |
406 | cfg->SetPath(path); | |
5526e819 VS |
407 | } |
408 | ||
892aeafc VS |
409 | m_Borders = cfg->Read(wxT("wxHtmlWindow/Borders"), m_Borders); |
410 | p_fff = cfg->Read(wxT("wxHtmlWindow/FontFaceFixed"), m_Parser->m_FontFaceFixed); | |
411 | p_ffn = cfg->Read(wxT("wxHtmlWindow/FontFaceNormal"), m_Parser->m_FontFaceNormal); | |
bfb9ee96 | 412 | for (int i = 0; i < 7; i++) |
4f9297b0 | 413 | { |
66a77a74 | 414 | tmp.Printf(wxT("wxHtmlWindow/FontsSize%i"), i); |
4f9297b0 | 415 | p_fontsizes[i] = cfg->Read(tmp, m_Parser->m_FontsSizes[i]); |
5526e819 | 416 | } |
8eb2940f | 417 | SetFonts(p_ffn, p_fff, p_fontsizes); |
5526e819 VS |
418 | |
419 | if (path != wxEmptyString) | |
4f9297b0 | 420 | cfg->SetPath(oldpath); |
5526e819 VS |
421 | } |
422 | ||
423 | ||
424 | ||
425 | void wxHtmlWindow::WriteCustomization(wxConfigBase *cfg, wxString path) | |
426 | { | |
427 | wxString oldpath; | |
428 | wxString tmp; | |
429 | ||
33ac7e6f | 430 | if (path != wxEmptyString) |
4f9297b0 VS |
431 | { |
432 | oldpath = cfg->GetPath(); | |
433 | cfg->SetPath(path); | |
5526e819 VS |
434 | } |
435 | ||
892aeafc VS |
436 | cfg->Write(wxT("wxHtmlWindow/Borders"), (long) m_Borders); |
437 | cfg->Write(wxT("wxHtmlWindow/FontFaceFixed"), m_Parser->m_FontFaceFixed); | |
438 | cfg->Write(wxT("wxHtmlWindow/FontFaceNormal"), m_Parser->m_FontFaceNormal); | |
bfb9ee96 | 439 | for (int i = 0; i < 7; i++) |
4f9297b0 | 440 | { |
66a77a74 | 441 | tmp.Printf(wxT("wxHtmlWindow/FontsSize%i"), i); |
4f9297b0 | 442 | cfg->Write(tmp, (long) m_Parser->m_FontsSizes[i]); |
5526e819 VS |
443 | } |
444 | ||
445 | if (path != wxEmptyString) | |
4f9297b0 | 446 | cfg->SetPath(oldpath); |
5526e819 VS |
447 | } |
448 | ||
449 | ||
450 | ||
451 | bool wxHtmlWindow::HistoryBack() | |
452 | { | |
453 | wxString a, l; | |
454 | ||
455 | if (m_HistoryPos < 1) return FALSE; | |
456 | ||
bbda1088 VS |
457 | // store scroll position into history item: |
458 | int x, y; | |
459 | ViewStart(&x, &y); | |
892aeafc | 460 | (*m_History)[m_HistoryPos].SetPos(y); |
bbda1088 VS |
461 | |
462 | // go to previous position: | |
5526e819 VS |
463 | m_HistoryPos--; |
464 | ||
892aeafc VS |
465 | l = (*m_History)[m_HistoryPos].GetPage(); |
466 | a = (*m_History)[m_HistoryPos].GetAnchor(); | |
5526e819 | 467 | m_HistoryOn = FALSE; |
89de9af3 | 468 | m_tmpCanDrawLocks++; |
5526e819 | 469 | if (a == wxEmptyString) LoadPage(l); |
fc7dfaf8 | 470 | else LoadPage(l + wxT("#") + a); |
5526e819 | 471 | m_HistoryOn = TRUE; |
c88293a4 | 472 | wxYield(); |
89de9af3 | 473 | m_tmpCanDrawLocks--; |
892aeafc | 474 | Scroll(0, (*m_History)[m_HistoryPos].GetPos()); |
5526e819 VS |
475 | Refresh(); |
476 | return TRUE; | |
477 | } | |
478 | ||
1b113a81 VS |
479 | bool wxHtmlWindow::HistoryCanBack() |
480 | { | |
481 | if (m_HistoryPos < 1) return FALSE; | |
482 | return TRUE ; | |
483 | } | |
5526e819 VS |
484 | |
485 | ||
486 | bool wxHtmlWindow::HistoryForward() | |
487 | { | |
488 | wxString a, l; | |
489 | ||
490 | if (m_HistoryPos == -1) return FALSE; | |
892aeafc | 491 | if (m_HistoryPos >= (int)m_History->GetCount() - 1)return FALSE; |
5526e819 VS |
492 | |
493 | m_OpenedPage = wxEmptyString; // this will disable adding new entry into history in LoadPage() | |
494 | ||
495 | m_HistoryPos++; | |
892aeafc VS |
496 | l = (*m_History)[m_HistoryPos].GetPage(); |
497 | a = (*m_History)[m_HistoryPos].GetAnchor(); | |
5526e819 | 498 | m_HistoryOn = FALSE; |
89de9af3 | 499 | m_tmpCanDrawLocks++; |
5526e819 | 500 | if (a == wxEmptyString) LoadPage(l); |
fc7dfaf8 | 501 | else LoadPage(l + wxT("#") + a); |
5526e819 | 502 | m_HistoryOn = TRUE; |
c88293a4 | 503 | wxYield(); |
89de9af3 | 504 | m_tmpCanDrawLocks--; |
892aeafc | 505 | Scroll(0, (*m_History)[m_HistoryPos].GetPos()); |
5526e819 VS |
506 | Refresh(); |
507 | return TRUE; | |
508 | } | |
509 | ||
1b113a81 VS |
510 | bool wxHtmlWindow::HistoryCanForward() |
511 | { | |
512 | if (m_HistoryPos == -1) return FALSE; | |
892aeafc | 513 | if (m_HistoryPos >= (int)m_History->GetCount() - 1)return FALSE; |
1b113a81 VS |
514 | return TRUE ; |
515 | } | |
5526e819 VS |
516 | |
517 | ||
518 | void wxHtmlWindow::HistoryClear() | |
519 | { | |
892aeafc | 520 | m_History->Empty(); |
5526e819 VS |
521 | m_HistoryPos = -1; |
522 | } | |
523 | ||
892aeafc VS |
524 | void wxHtmlWindow::AddProcessor(wxHtmlProcessor *processor) |
525 | { | |
526 | if (!m_Processors) | |
527 | { | |
528 | m_Processors = new wxHtmlProcessorList; | |
529 | m_Processors->DeleteContents(TRUE); | |
530 | } | |
531 | wxHtmlProcessorList::Node *node; | |
bfb9ee96 | 532 | |
892aeafc VS |
533 | for (node = m_Processors->GetFirst(); node; node = node->GetNext()) |
534 | { | |
bfb9ee96 | 535 | if (processor->GetPriority() > node->GetData()->GetPriority()) |
892aeafc VS |
536 | { |
537 | m_Processors->Insert(node, processor); | |
538 | break; | |
539 | } | |
540 | } | |
541 | } | |
542 | ||
543 | /*static */ void wxHtmlWindow::AddSharedProcessor(wxHtmlProcessor *processor) | |
544 | { | |
545 | if (!m_SharedProcessors) | |
546 | { | |
547 | m_SharedProcessors = new wxHtmlProcessorList; | |
548 | m_SharedProcessors->DeleteContents(TRUE); | |
549 | } | |
550 | wxHtmlProcessorList::Node *node; | |
bfb9ee96 | 551 | |
892aeafc VS |
552 | for (node = m_SharedProcessors->GetFirst(); node; node = node->GetNext()) |
553 | { | |
bfb9ee96 | 554 | if (processor->GetPriority() > node->GetData()->GetPriority()) |
892aeafc VS |
555 | { |
556 | m_SharedProcessors->Insert(node, processor); | |
557 | break; | |
558 | } | |
559 | } | |
560 | } | |
561 | ||
5526e819 VS |
562 | |
563 | ||
564 | wxList wxHtmlWindow::m_Filters; | |
a76015e6 | 565 | wxHtmlFilter *wxHtmlWindow::m_DefaultFilter = NULL; |
66806a0b VS |
566 | wxCursor *wxHtmlWindow::s_cur_hand = NULL; |
567 | wxCursor *wxHtmlWindow::s_cur_arrow = NULL; | |
892aeafc | 568 | wxHtmlProcessorList *wxHtmlWindow::m_SharedProcessors = NULL; |
a76015e6 VS |
569 | |
570 | void wxHtmlWindow::CleanUpStatics() | |
571 | { | |
892aeafc | 572 | delete m_DefaultFilter; |
a76015e6 | 573 | m_DefaultFilter = NULL; |
269e8200 RD |
574 | m_Filters.DeleteContents(TRUE); |
575 | m_Filters.Clear(); | |
bfb9ee96 | 576 | |
892aeafc VS |
577 | delete m_SharedProcessors; |
578 | m_SharedProcessors = NULL; | |
bfb9ee96 | 579 | |
892aeafc VS |
580 | delete s_cur_hand; |
581 | delete s_cur_arrow; | |
a76015e6 VS |
582 | } |
583 | ||
584 | ||
5526e819 VS |
585 | |
586 | void wxHtmlWindow::AddFilter(wxHtmlFilter *filter) | |
587 | { | |
5526e819 VS |
588 | m_Filters.Append(filter); |
589 | } | |
590 | ||
591 | ||
592 | ||
593 | ||
0b2dadd3 | 594 | void wxHtmlWindow::OnLinkClicked(const wxHtmlLinkInfo& link) |
5526e819 | 595 | { |
0b2dadd3 | 596 | LoadPage(link.GetHref()); |
5526e819 VS |
597 | } |
598 | ||
599 | ||
600 | ||
601 | void wxHtmlWindow::OnDraw(wxDC& dc) | |
602 | { | |
603 | int x, y; | |
604 | wxRegionIterator upd(GetUpdateRegion()); // get the update rect list | |
605 | int v_y, v_h; | |
606 | ||
89de9af3 | 607 | if (m_tmpCanDrawLocks > 0) return; |
33ac7e6f | 608 | |
5526e819 | 609 | dc.SetMapMode(wxMM_TEXT); |
2faa3a6b | 610 | #if 0 |
33ac7e6f | 611 | /* VS - I don't think this is neccessary any longer |
2faa3a6b | 612 | MSC_VER 1200 means MSVC 6.0 and it works fine */ |
5526e819 VS |
613 | #if defined(_MSC_VER) && (_MSC_VER == 1200) |
614 | ::SetMapMode((HDC)dc.GetHDC(), MM_TEXT); | |
2faa3a6b | 615 | #endif |
5526e819 VS |
616 | #endif |
617 | dc.SetBackgroundMode(wxTRANSPARENT); | |
618 | ViewStart(&x, &y); | |
619 | ||
33ac7e6f | 620 | while (upd) |
4f9297b0 | 621 | { |
5526e819 VS |
622 | v_y = upd.GetY(); |
623 | v_h = upd.GetH(); | |
4f9297b0 | 624 | if (m_Cell) m_Cell->Draw(dc, 0, 0, y * wxHTML_SCROLL_STEP + v_y, y * wxHTML_SCROLL_STEP + v_h + v_y); |
5526e819 VS |
625 | upd++; |
626 | } | |
627 | } | |
628 | ||
629 | ||
630 | ||
631 | ||
632 | void wxHtmlWindow::OnSize(wxSizeEvent& event) | |
633 | { | |
634 | wxScrolledWindow::OnSize(event); | |
635 | CreateLayout(); | |
f6bcfd97 | 636 | Refresh(); |
5526e819 VS |
637 | } |
638 | ||
639 | ||
5526e819 VS |
640 | void wxHtmlWindow::OnMouseEvent(wxMouseEvent& event) |
641 | { | |
642 | m_tmpMouseMoved = TRUE; | |
643 | ||
33ac7e6f | 644 | if (event.ButtonDown()) |
4f9297b0 | 645 | { |
5526e819 VS |
646 | int sx, sy; |
647 | wxPoint pos; | |
648 | wxString lnk; | |
649 | ||
efba2b89 | 650 | ViewStart(&sx, &sy); sx *= wxHTML_SCROLL_STEP; sy *= wxHTML_SCROLL_STEP; |
5526e819 VS |
651 | pos = event.GetPosition(); |
652 | ||
653 | if (m_Cell) | |
4f9297b0 | 654 | m_Cell->OnMouseClick(this, sx + pos.x, sy + pos.y, event); |
5526e819 VS |
655 | } |
656 | } | |
657 | ||
658 | ||
659 | ||
33ac7e6f | 660 | void wxHtmlWindow::OnIdle(wxIdleEvent& WXUNUSED(event)) |
5526e819 | 661 | { |
33ac7e6f | 662 | if (s_cur_hand == NULL) |
66806a0b VS |
663 | { |
664 | s_cur_hand = new wxCursor(wxCURSOR_HAND); | |
665 | s_cur_arrow = new wxCursor(wxCURSOR_ARROW); | |
666 | } | |
5526e819 | 667 | |
33ac7e6f | 668 | if (m_tmpMouseMoved && (m_Cell != NULL)) |
4f9297b0 | 669 | { |
5526e819 VS |
670 | int sx, sy; |
671 | int x, y; | |
846914d1 | 672 | wxHtmlLinkInfo *lnk; |
5526e819 | 673 | |
efba2b89 | 674 | ViewStart(&sx, &sy); sx *= wxHTML_SCROLL_STEP; sy *= wxHTML_SCROLL_STEP; |
5526e819 VS |
675 | wxGetMousePosition(&x, &y); |
676 | ScreenToClient(&x, &y); | |
4f9297b0 | 677 | lnk = m_Cell->GetLink(sx + x, sy + y); |
5526e819 | 678 | |
33ac7e6f | 679 | if (lnk != m_tmpLastLink) |
4f9297b0 | 680 | { |
33ac7e6f | 681 | if (lnk == NULL) |
4f9297b0 | 682 | { |
66806a0b | 683 | SetCursor(*s_cur_arrow); |
4f9297b0 | 684 | if (m_RelatedStatusBar != -1) m_RelatedFrame->SetStatusText(wxEmptyString, m_RelatedStatusBar); |
622ea783 | 685 | } |
33ac7e6f | 686 | else |
4f9297b0 | 687 | { |
66806a0b | 688 | SetCursor(*s_cur_hand); |
33ac7e6f | 689 | if (m_RelatedStatusBar != -1) |
4f9297b0 | 690 | m_RelatedFrame->SetStatusText(lnk->GetHref(), m_RelatedStatusBar); |
622ea783 VS |
691 | } |
692 | m_tmpLastLink = lnk; | |
5526e819 VS |
693 | } |
694 | m_tmpMouseMoved = FALSE; | |
695 | } | |
696 | } | |
697 | ||
698 | ||
bfb9ee96 | 699 | IMPLEMENT_ABSTRACT_CLASS(wxHtmlProcessor,wxObject) |
5526e819 VS |
700 | |
701 | IMPLEMENT_DYNAMIC_CLASS(wxHtmlWindow,wxScrolledWindow) | |
702 | ||
703 | BEGIN_EVENT_TABLE(wxHtmlWindow, wxScrolledWindow) | |
704 | EVT_SIZE(wxHtmlWindow::OnSize) | |
705 | EVT_LEFT_DOWN(wxHtmlWindow::OnMouseEvent) | |
706 | EVT_MOTION(wxHtmlWindow::OnMouseEvent) | |
707 | EVT_IDLE(wxHtmlWindow::OnIdle) | |
5526e819 VS |
708 | END_EVENT_TABLE() |
709 | ||
710 | ||
711 | ||
712 | ||
713 | ||
a76015e6 VS |
714 | // A module to allow initialization/cleanup |
715 | // without calling these functions from app.cpp or from | |
716 | // the user's application. | |
717 | ||
718 | class wxHtmlWinModule: public wxModule | |
719 | { | |
720 | DECLARE_DYNAMIC_CLASS(wxHtmlWinModule) | |
721 | public: | |
722 | wxHtmlWinModule() : wxModule() {} | |
723 | bool OnInit() { return TRUE; } | |
724 | void OnExit() { wxHtmlWindow::CleanUpStatics(); } | |
725 | }; | |
726 | ||
727 | IMPLEMENT_DYNAMIC_CLASS(wxHtmlWinModule, wxModule) | |
728 | ||
5526e819 VS |
729 | |
730 | ||
731 | ||
732 | ///// default mod handlers are forced there: | |
733 | ||
c88293a4 VS |
734 | FORCE_LINK(m_layout) |
735 | FORCE_LINK(m_fonts) | |
736 | FORCE_LINK(m_image) | |
737 | FORCE_LINK(m_list) | |
738 | FORCE_LINK(m_dflist) | |
739 | FORCE_LINK(m_pre) | |
740 | FORCE_LINK(m_hline) | |
741 | FORCE_LINK(m_links) | |
742 | FORCE_LINK(m_tables) | |
fa146dd7 | 743 | FORCE_LINK(m_meta) |
5526e819 VS |
744 | |
745 | ||
483ff5a5 | 746 | #endif |