]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: htmlwin.cpp | |
3 | // Purpose: wxHtmlWindow class for parsing & displaying HTML (implementation) | |
4 | // Author: Vaclav Slavik | |
5 | // RCS-ID: $Id$ | |
6 | // Copyright: (c) 1999 Vaclav Slavik | |
7 | // Licence: wxWindows Licence | |
8 | ///////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | ||
11 | #ifdef __GNUG__ | |
12 | #pragma implementation "htmlwin.h" | |
13 | #pragma implementation "htmlproc.h" | |
14 | #endif | |
15 | ||
16 | #include "wx/wxprec.h" | |
17 | ||
18 | #include "wx/defs.h" | |
19 | #if wxUSE_HTML && wxUSE_STREAMS | |
20 | ||
21 | #ifdef __BORDLANDC__ | |
22 | #pragma hdrstop | |
23 | #endif | |
24 | ||
25 | #ifndef WXPRECOMP | |
26 | #include "wx/wx.h" | |
27 | #endif | |
28 | ||
29 | #include "wx/html/htmlwin.h" | |
30 | #include "wx/html/forcelnk.h" | |
31 | #include "wx/html/htmlproc.h" | |
32 | #include "wx/log.h" | |
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 | }; | |
56 | ||
57 | ||
58 | //----------------------------------------------------------------------------- | |
59 | // our private arrays: | |
60 | //----------------------------------------------------------------------------- | |
61 | ||
62 | WX_DECLARE_OBJARRAY(wxHtmlHistoryItem, wxHtmlHistoryArray); | |
63 | WX_DEFINE_OBJARRAY(wxHtmlHistoryArray); | |
64 | ||
65 | WX_DECLARE_LIST(wxHtmlProcessor, wxHtmlProcessorList); | |
66 | WX_DEFINE_LIST(wxHtmlProcessorList); | |
67 | ||
68 | //----------------------------------------------------------------------------- | |
69 | // wxHtmlWindow | |
70 | //----------------------------------------------------------------------------- | |
71 | ||
72 | ||
73 | wxHtmlWindow::wxHtmlWindow(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, | |
74 | long style, const wxString& name) : wxScrolledWindow(parent, id, pos, size, style | wxVSCROLL | wxHSCROLL, name) | |
75 | { | |
76 | m_tmpMouseMoved = FALSE; | |
77 | m_tmpLastLink = NULL; | |
78 | m_tmpCanDrawLocks = 0; | |
79 | m_FS = new wxFileSystem(); | |
80 | m_RelatedStatusBar = -1; | |
81 | m_RelatedFrame = NULL; | |
82 | m_TitleFormat = wxT("%s"); | |
83 | m_OpenedPage = m_OpenedAnchor = m_OpenedPageTitle = wxEmptyString; | |
84 | m_Cell = NULL; | |
85 | m_Parser = new wxHtmlWinParser(this); | |
86 | m_Parser->SetFS(m_FS); | |
87 | SetBorders(10); | |
88 | m_HistoryPos = -1; | |
89 | m_HistoryOn = TRUE; | |
90 | m_History = new wxHtmlHistoryArray; | |
91 | m_Processors = NULL; | |
92 | m_Style = style; | |
93 | SetPage(wxT("<html><body></body></html>")); | |
94 | } | |
95 | ||
96 | ||
97 | ||
98 | wxHtmlWindow::~wxHtmlWindow() | |
99 | { | |
100 | HistoryClear(); | |
101 | ||
102 | if (m_Cell) delete m_Cell; | |
103 | ||
104 | delete m_Parser; | |
105 | delete m_FS; | |
106 | delete m_History; | |
107 | delete m_Processors; | |
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 | } | |
124 | ||
125 | ||
126 | ||
127 | void wxHtmlWindow::SetFonts(wxString normal_face, wxString fixed_face, const int *sizes) | |
128 | { | |
129 | wxString op = m_OpenedPage; | |
130 | ||
131 | m_Parser->SetFonts(normal_face, fixed_face, sizes); | |
132 | // fonts changed => contents invalid, so reload the page: | |
133 | SetPage(wxT("<html><body></body></html>")); | |
134 | if (!op.IsEmpty()) LoadPage(op); | |
135 | } | |
136 | ||
137 | ||
138 | ||
139 | bool wxHtmlWindow::SetPage(const wxString& source) | |
140 | { | |
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 | } | |
168 | ||
169 | // ...and run the parser on it: | |
170 | wxClientDC *dc = new wxClientDC(this); | |
171 | dc->SetMapMode(wxMM_TEXT); | |
172 | SetBackgroundColour(wxColour(0xFF, 0xFF, 0xFF)); | |
173 | m_OpenedPage = m_OpenedAnchor = m_OpenedPageTitle = wxEmptyString; | |
174 | m_Parser->SetDC(dc); | |
175 | if (m_Cell) | |
176 | { | |
177 | delete m_Cell; | |
178 | m_Cell = NULL; | |
179 | } | |
180 | m_Cell = (wxHtmlContainerCell*) m_Parser->Parse(newsrc); | |
181 | delete dc; | |
182 | m_Cell->SetIndent(m_Borders, wxHTML_INDENT_ALL, wxHTML_UNITS_PIXELS); | |
183 | m_Cell->SetAlignHor(wxHTML_ALIGN_CENTER); | |
184 | CreateLayout(); | |
185 | if (m_tmpCanDrawLocks == 0) | |
186 | Refresh(); | |
187 | return TRUE; | |
188 | } | |
189 | ||
190 | ||
191 | bool wxHtmlWindow::LoadPage(const wxString& location) | |
192 | { | |
193 | wxFSFile *f; | |
194 | bool rt_val; | |
195 | bool needs_refresh = FALSE; | |
196 | ||
197 | SetCursor(*wxHOURGLASS_CURSOR); | |
198 | wxYield(); Refresh(FALSE); | |
199 | ||
200 | m_tmpCanDrawLocks++; | |
201 | if (m_HistoryOn && (m_HistoryPos != -1)) // store scroll position into history item | |
202 | { | |
203 | int x, y; | |
204 | ViewStart(&x, &y); | |
205 | (*m_History)[m_HistoryPos].SetPos(y); | |
206 | } | |
207 | ||
208 | if (location[0] == wxT('#')) // local anchor | |
209 | { | |
210 | wxString anch = location.Mid(1) /*1 to end*/; | |
211 | m_tmpCanDrawLocks--; | |
212 | rt_val = ScrollToAnchor(anch); | |
213 | m_tmpCanDrawLocks++; | |
214 | } | |
215 | else if (location.Find(wxT('#')) != wxNOT_FOUND && location.BeforeFirst(wxT('#')) == m_OpenedPage) | |
216 | { | |
217 | wxString anch = location.AfterFirst(wxT('#')); | |
218 | m_tmpCanDrawLocks--; | |
219 | rt_val = ScrollToAnchor(anch); | |
220 | m_tmpCanDrawLocks++; | |
221 | } | |
222 | else if (location.Find(wxT('#')) != wxNOT_FOUND && | |
223 | (m_FS->GetPath() + location.BeforeFirst(wxT('#'))) == m_OpenedPage) | |
224 | { | |
225 | wxString anch = location.AfterFirst(wxT('#')); | |
226 | m_tmpCanDrawLocks--; | |
227 | rt_val = ScrollToAnchor(anch); | |
228 | m_tmpCanDrawLocks++; | |
229 | } | |
230 | ||
231 | else | |
232 | { | |
233 | needs_refresh = TRUE; | |
234 | // load&display it: | |
235 | if (m_RelatedStatusBar != -1) | |
236 | { | |
237 | m_RelatedFrame->SetStatusText(_("Connecting..."), m_RelatedStatusBar); | |
238 | Refresh(FALSE); | |
239 | } | |
240 | ||
241 | f = m_FS->OpenFile(location); | |
242 | ||
243 | if (f == NULL) | |
244 | { | |
245 | wxString err; | |
246 | ||
247 | wxLogError(_("Unable to open requested HTML document: %s"), location.c_str()); | |
248 | m_tmpCanDrawLocks--; | |
249 | ||
250 | SetCursor(*wxSTANDARD_CURSOR); | |
251 | return FALSE; | |
252 | } | |
253 | ||
254 | else | |
255 | { | |
256 | wxNode *node; | |
257 | wxString src = wxEmptyString; | |
258 | ||
259 | if (m_RelatedStatusBar != -1) | |
260 | { | |
261 | wxString msg = _("Loading : ") + location; | |
262 | m_RelatedFrame->SetStatusText(msg, m_RelatedStatusBar); | |
263 | Refresh(FALSE); | |
264 | } | |
265 | ||
266 | node = m_Filters.GetFirst(); | |
267 | while (node) | |
268 | { | |
269 | wxHtmlFilter *h = (wxHtmlFilter*) node->GetData(); | |
270 | if (h->CanRead(*f)) | |
271 | { | |
272 | src = h->ReadFile(*f); | |
273 | break; | |
274 | } | |
275 | node = node->GetNext(); | |
276 | } | |
277 | if (src == wxEmptyString) | |
278 | { | |
279 | if (m_DefaultFilter == NULL) m_DefaultFilter = GetDefaultFilter(); | |
280 | src = m_DefaultFilter->ReadFile(*f); | |
281 | } | |
282 | ||
283 | m_FS->ChangePathTo(f->GetLocation()); | |
284 | rt_val = SetPage(src); | |
285 | m_OpenedPage = f->GetLocation(); | |
286 | if (f->GetAnchor() != wxEmptyString) | |
287 | { | |
288 | wxYield(); | |
289 | ScrollToAnchor(f->GetAnchor()); | |
290 | } | |
291 | ||
292 | delete f; | |
293 | ||
294 | if (m_RelatedStatusBar != -1) m_RelatedFrame->SetStatusText(_("Done"), m_RelatedStatusBar); | |
295 | } | |
296 | } | |
297 | ||
298 | if (m_HistoryOn) // add this page to history there: | |
299 | { | |
300 | int c = m_History->GetCount() - (m_HistoryPos + 1); | |
301 | ||
302 | m_HistoryPos++; | |
303 | for (int i = 0; i < c; i++) | |
304 | m_History->Remove(m_HistoryPos); | |
305 | m_History->Add(new wxHtmlHistoryItem(m_OpenedPage, m_OpenedAnchor)); | |
306 | } | |
307 | ||
308 | if (m_OpenedPageTitle == wxEmptyString) | |
309 | OnSetTitle(wxFileNameFromPath(m_OpenedPage)); | |
310 | SetCursor(*wxSTANDARD_CURSOR); | |
311 | ||
312 | if (needs_refresh) | |
313 | { | |
314 | wxYield(); | |
315 | m_tmpCanDrawLocks--; | |
316 | Refresh(); | |
317 | } | |
318 | else | |
319 | m_tmpCanDrawLocks--; | |
320 | ||
321 | return rt_val; | |
322 | } | |
323 | ||
324 | ||
325 | ||
326 | bool wxHtmlWindow::ScrollToAnchor(const wxString& anchor) | |
327 | { | |
328 | const wxHtmlCell *c = m_Cell->Find(wxHTML_COND_ISANCHOR, &anchor); | |
329 | if (!c) | |
330 | { | |
331 | wxLogWarning(_("HTML anchor %s does not exist."), anchor.c_str()); | |
332 | return FALSE; | |
333 | } | |
334 | else | |
335 | { | |
336 | int y; | |
337 | ||
338 | for (y = 0; c != NULL; c = c->GetParent()) y += c->GetPosY(); | |
339 | Scroll(-1, y / wxHTML_SCROLL_STEP); | |
340 | m_OpenedAnchor = anchor; | |
341 | return TRUE; | |
342 | } | |
343 | } | |
344 | ||
345 | ||
346 | void wxHtmlWindow::OnSetTitle(const wxString& title) | |
347 | { | |
348 | if (m_RelatedFrame) | |
349 | { | |
350 | wxString tit; | |
351 | tit.Printf(m_TitleFormat, title.c_str()); | |
352 | m_RelatedFrame->SetTitle(tit); | |
353 | } | |
354 | m_OpenedPageTitle = title; | |
355 | } | |
356 | ||
357 | ||
358 | ||
359 | ||
360 | ||
361 | void wxHtmlWindow::CreateLayout() | |
362 | { | |
363 | int ClientWidth, ClientHeight; | |
364 | ||
365 | if (!m_Cell) return; | |
366 | ||
367 | if (m_Style & wxHW_SCROLLBAR_NEVER) | |
368 | { | |
369 | SetScrollbars(wxHTML_SCROLL_STEP, 1, m_Cell->GetWidth() / wxHTML_SCROLL_STEP, 0); // always off | |
370 | GetClientSize(&ClientWidth, &ClientHeight); | |
371 | m_Cell->Layout(ClientWidth); | |
372 | } | |
373 | ||
374 | else { | |
375 | GetClientSize(&ClientWidth, &ClientHeight); | |
376 | m_Cell->Layout(ClientWidth); | |
377 | if (ClientHeight < m_Cell->GetHeight() + GetCharHeight()) | |
378 | { | |
379 | SetScrollbars( | |
380 | wxHTML_SCROLL_STEP, wxHTML_SCROLL_STEP, | |
381 | m_Cell->GetWidth() / wxHTML_SCROLL_STEP, | |
382 | (m_Cell->GetHeight() + GetCharHeight()) / wxHTML_SCROLL_STEP | |
383 | /*cheat: top-level frag is always container*/); | |
384 | } | |
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... | |
388 | GetClientSize(&ClientWidth, &ClientHeight); | |
389 | m_Cell->Layout(ClientWidth); // ...and relayout | |
390 | } | |
391 | } | |
392 | } | |
393 | ||
394 | ||
395 | ||
396 | void wxHtmlWindow::ReadCustomization(wxConfigBase *cfg, wxString path) | |
397 | { | |
398 | wxString oldpath; | |
399 | wxString tmp; | |
400 | int p_fontsizes[7]; | |
401 | wxString p_fff, p_ffn; | |
402 | ||
403 | if (path != wxEmptyString) | |
404 | { | |
405 | oldpath = cfg->GetPath(); | |
406 | cfg->SetPath(path); | |
407 | } | |
408 | ||
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); | |
412 | for (int i = 0; i < 7; i++) | |
413 | { | |
414 | tmp.Printf(wxT("wxHtmlWindow/FontsSize%i"), i); | |
415 | p_fontsizes[i] = cfg->Read(tmp, m_Parser->m_FontsSizes[i]); | |
416 | } | |
417 | SetFonts(p_ffn, p_fff, p_fontsizes); | |
418 | ||
419 | if (path != wxEmptyString) | |
420 | cfg->SetPath(oldpath); | |
421 | } | |
422 | ||
423 | ||
424 | ||
425 | void wxHtmlWindow::WriteCustomization(wxConfigBase *cfg, wxString path) | |
426 | { | |
427 | wxString oldpath; | |
428 | wxString tmp; | |
429 | ||
430 | if (path != wxEmptyString) | |
431 | { | |
432 | oldpath = cfg->GetPath(); | |
433 | cfg->SetPath(path); | |
434 | } | |
435 | ||
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); | |
439 | for (int i = 0; i < 7; i++) | |
440 | { | |
441 | tmp.Printf(wxT("wxHtmlWindow/FontsSize%i"), i); | |
442 | cfg->Write(tmp, (long) m_Parser->m_FontsSizes[i]); | |
443 | } | |
444 | ||
445 | if (path != wxEmptyString) | |
446 | cfg->SetPath(oldpath); | |
447 | } | |
448 | ||
449 | ||
450 | ||
451 | bool wxHtmlWindow::HistoryBack() | |
452 | { | |
453 | wxString a, l; | |
454 | ||
455 | if (m_HistoryPos < 1) return FALSE; | |
456 | ||
457 | // store scroll position into history item: | |
458 | int x, y; | |
459 | ViewStart(&x, &y); | |
460 | (*m_History)[m_HistoryPos].SetPos(y); | |
461 | ||
462 | // go to previous position: | |
463 | m_HistoryPos--; | |
464 | ||
465 | l = (*m_History)[m_HistoryPos].GetPage(); | |
466 | a = (*m_History)[m_HistoryPos].GetAnchor(); | |
467 | m_HistoryOn = FALSE; | |
468 | m_tmpCanDrawLocks++; | |
469 | if (a == wxEmptyString) LoadPage(l); | |
470 | else LoadPage(l + wxT("#") + a); | |
471 | m_HistoryOn = TRUE; | |
472 | wxYield(); | |
473 | m_tmpCanDrawLocks--; | |
474 | Scroll(0, (*m_History)[m_HistoryPos].GetPos()); | |
475 | Refresh(); | |
476 | return TRUE; | |
477 | } | |
478 | ||
479 | bool wxHtmlWindow::HistoryCanBack() | |
480 | { | |
481 | if (m_HistoryPos < 1) return FALSE; | |
482 | return TRUE ; | |
483 | } | |
484 | ||
485 | ||
486 | bool wxHtmlWindow::HistoryForward() | |
487 | { | |
488 | wxString a, l; | |
489 | ||
490 | if (m_HistoryPos == -1) return FALSE; | |
491 | if (m_HistoryPos >= (int)m_History->GetCount() - 1)return FALSE; | |
492 | ||
493 | m_OpenedPage = wxEmptyString; // this will disable adding new entry into history in LoadPage() | |
494 | ||
495 | m_HistoryPos++; | |
496 | l = (*m_History)[m_HistoryPos].GetPage(); | |
497 | a = (*m_History)[m_HistoryPos].GetAnchor(); | |
498 | m_HistoryOn = FALSE; | |
499 | m_tmpCanDrawLocks++; | |
500 | if (a == wxEmptyString) LoadPage(l); | |
501 | else LoadPage(l + wxT("#") + a); | |
502 | m_HistoryOn = TRUE; | |
503 | wxYield(); | |
504 | m_tmpCanDrawLocks--; | |
505 | Scroll(0, (*m_History)[m_HistoryPos].GetPos()); | |
506 | Refresh(); | |
507 | return TRUE; | |
508 | } | |
509 | ||
510 | bool wxHtmlWindow::HistoryCanForward() | |
511 | { | |
512 | if (m_HistoryPos == -1) return FALSE; | |
513 | if (m_HistoryPos >= (int)m_History->GetCount() - 1)return FALSE; | |
514 | return TRUE ; | |
515 | } | |
516 | ||
517 | ||
518 | void wxHtmlWindow::HistoryClear() | |
519 | { | |
520 | m_History->Empty(); | |
521 | m_HistoryPos = -1; | |
522 | } | |
523 | ||
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; | |
532 | ||
533 | for (node = m_Processors->GetFirst(); node; node = node->GetNext()) | |
534 | { | |
535 | if (processor->GetPriority() > node->GetData()->GetPriority()) | |
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; | |
551 | ||
552 | for (node = m_SharedProcessors->GetFirst(); node; node = node->GetNext()) | |
553 | { | |
554 | if (processor->GetPriority() > node->GetData()->GetPriority()) | |
555 | { | |
556 | m_SharedProcessors->Insert(node, processor); | |
557 | break; | |
558 | } | |
559 | } | |
560 | } | |
561 | ||
562 | ||
563 | ||
564 | wxList wxHtmlWindow::m_Filters; | |
565 | wxHtmlFilter *wxHtmlWindow::m_DefaultFilter = NULL; | |
566 | wxCursor *wxHtmlWindow::s_cur_hand = NULL; | |
567 | wxCursor *wxHtmlWindow::s_cur_arrow = NULL; | |
568 | wxHtmlProcessorList *wxHtmlWindow::m_SharedProcessors = NULL; | |
569 | ||
570 | void wxHtmlWindow::CleanUpStatics() | |
571 | { | |
572 | delete m_DefaultFilter; | |
573 | m_DefaultFilter = NULL; | |
574 | m_Filters.DeleteContents(TRUE); | |
575 | m_Filters.Clear(); | |
576 | ||
577 | delete m_SharedProcessors; | |
578 | m_SharedProcessors = NULL; | |
579 | ||
580 | delete s_cur_hand; | |
581 | delete s_cur_arrow; | |
582 | } | |
583 | ||
584 | ||
585 | ||
586 | void wxHtmlWindow::AddFilter(wxHtmlFilter *filter) | |
587 | { | |
588 | m_Filters.Append(filter); | |
589 | } | |
590 | ||
591 | ||
592 | ||
593 | ||
594 | void wxHtmlWindow::OnLinkClicked(const wxHtmlLinkInfo& link) | |
595 | { | |
596 | LoadPage(link.GetHref()); | |
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 | ||
607 | if (m_tmpCanDrawLocks > 0) return; | |
608 | ||
609 | dc.SetMapMode(wxMM_TEXT); | |
610 | #if 0 | |
611 | /* VS - I don't think this is neccessary any longer | |
612 | MSC_VER 1200 means MSVC 6.0 and it works fine */ | |
613 | #if defined(_MSC_VER) && (_MSC_VER == 1200) | |
614 | ::SetMapMode((HDC)dc.GetHDC(), MM_TEXT); | |
615 | #endif | |
616 | #endif | |
617 | dc.SetBackgroundMode(wxTRANSPARENT); | |
618 | ViewStart(&x, &y); | |
619 | ||
620 | while (upd) | |
621 | { | |
622 | v_y = upd.GetY(); | |
623 | v_h = upd.GetH(); | |
624 | if (m_Cell) m_Cell->Draw(dc, 0, 0, y * wxHTML_SCROLL_STEP + v_y, y * wxHTML_SCROLL_STEP + v_h + v_y); | |
625 | upd++; | |
626 | } | |
627 | } | |
628 | ||
629 | ||
630 | ||
631 | ||
632 | void wxHtmlWindow::OnSize(wxSizeEvent& event) | |
633 | { | |
634 | wxScrolledWindow::OnSize(event); | |
635 | CreateLayout(); | |
636 | Refresh(); | |
637 | } | |
638 | ||
639 | ||
640 | void wxHtmlWindow::OnMouseEvent(wxMouseEvent& event) | |
641 | { | |
642 | m_tmpMouseMoved = TRUE; | |
643 | ||
644 | if (event.ButtonDown()) | |
645 | { | |
646 | int sx, sy; | |
647 | wxPoint pos; | |
648 | wxString lnk; | |
649 | ||
650 | ViewStart(&sx, &sy); sx *= wxHTML_SCROLL_STEP; sy *= wxHTML_SCROLL_STEP; | |
651 | pos = event.GetPosition(); | |
652 | ||
653 | if (m_Cell) | |
654 | m_Cell->OnMouseClick(this, sx + pos.x, sy + pos.y, event); | |
655 | } | |
656 | } | |
657 | ||
658 | ||
659 | ||
660 | void wxHtmlWindow::OnIdle(wxIdleEvent& WXUNUSED(event)) | |
661 | { | |
662 | if (s_cur_hand == NULL) | |
663 | { | |
664 | s_cur_hand = new wxCursor(wxCURSOR_HAND); | |
665 | s_cur_arrow = new wxCursor(wxCURSOR_ARROW); | |
666 | } | |
667 | ||
668 | if (m_tmpMouseMoved && (m_Cell != NULL)) | |
669 | { | |
670 | int sx, sy; | |
671 | int x, y; | |
672 | wxHtmlLinkInfo *lnk; | |
673 | ||
674 | ViewStart(&sx, &sy); sx *= wxHTML_SCROLL_STEP; sy *= wxHTML_SCROLL_STEP; | |
675 | wxGetMousePosition(&x, &y); | |
676 | ScreenToClient(&x, &y); | |
677 | lnk = m_Cell->GetLink(sx + x, sy + y); | |
678 | ||
679 | if (lnk != m_tmpLastLink) | |
680 | { | |
681 | if (lnk == NULL) | |
682 | { | |
683 | SetCursor(*s_cur_arrow); | |
684 | if (m_RelatedStatusBar != -1) m_RelatedFrame->SetStatusText(wxEmptyString, m_RelatedStatusBar); | |
685 | } | |
686 | else | |
687 | { | |
688 | SetCursor(*s_cur_hand); | |
689 | if (m_RelatedStatusBar != -1) | |
690 | m_RelatedFrame->SetStatusText(lnk->GetHref(), m_RelatedStatusBar); | |
691 | } | |
692 | m_tmpLastLink = lnk; | |
693 | } | |
694 | m_tmpMouseMoved = FALSE; | |
695 | } | |
696 | } | |
697 | ||
698 | ||
699 | ||
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) | |
708 | END_EVENT_TABLE() | |
709 | ||
710 | ||
711 | ||
712 | ||
713 | ||
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 | ||
729 | ||
730 | ||
731 | ||
732 | ///// default mod handlers are forced there: | |
733 | ||
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) | |
743 | FORCE_LINK(m_meta) | |
744 | ||
745 | ||
746 | #endif |