]>
Commit | Line | Data |
---|---|---|
5526e819 | 1 | ///////////////////////////////////////////////////////////////////////////// |
93763ad5 | 2 | // Name: src/html/htmlwin.cpp |
5526e819 VS |
3 | // Purpose: wxHtmlWindow class for parsing & displaying HTML (implementation) |
4 | // Author: Vaclav Slavik | |
69941f05 | 5 | // RCS-ID: $Id$ |
5526e819 | 6 | // Copyright: (c) 1999 Vaclav Slavik |
65571936 | 7 | // Licence: wxWindows licence |
5526e819 VS |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
3096bd2f | 10 | #include "wx/wxprec.h" |
5526e819 | 11 | |
2b5f62a0 | 12 | #ifdef __BORLANDC__ |
93763ad5 | 13 | #pragma hdrstop |
5526e819 VS |
14 | #endif |
15 | ||
93763ad5 WS |
16 | #if wxUSE_HTML && wxUSE_STREAMS |
17 | ||
5526e819 | 18 | #ifndef WXPRECOMP |
8ecff181 | 19 | #include "wx/list.h" |
04dbb646 VZ |
20 | #include "wx/log.h" |
21 | #include "wx/intl.h" | |
22 | #include "wx/dcclient.h" | |
23 | #include "wx/frame.h" | |
f38924e8 | 24 | #include "wx/dcmemory.h" |
5526e819 VS |
25 | #endif |
26 | ||
69941f05 | 27 | #include "wx/html/htmlwin.h" |
892aeafc | 28 | #include "wx/html/htmlproc.h" |
e3774124 | 29 | #include "wx/clipbrd.h" |
2b2309a4 | 30 | #include "wx/dataobj.h" |
1338c59a | 31 | #include "wx/timer.h" |
7acd3625 | 32 | #include "wx/settings.h" |
04dbb646 VZ |
33 | |
34 | #include "wx/arrimpl.cpp" | |
892aeafc VS |
35 | #include "wx/listimpl.cpp" |
36 | ||
1338c59a | 37 | |
1338c59a VS |
38 | #if wxUSE_CLIPBOARD |
39 | // ---------------------------------------------------------------------------- | |
40 | // wxHtmlWinAutoScrollTimer: the timer used to generate a stream of scroll | |
41 | // events when a captured mouse is held outside the window | |
42 | // ---------------------------------------------------------------------------- | |
43 | ||
44 | class wxHtmlWinAutoScrollTimer : public wxTimer | |
45 | { | |
46 | public: | |
47 | wxHtmlWinAutoScrollTimer(wxScrolledWindow *win, | |
48 | wxEventType eventTypeToSend, | |
49 | int pos, int orient) | |
50 | { | |
51 | m_win = win; | |
52 | m_eventType = eventTypeToSend; | |
53 | m_pos = pos; | |
54 | m_orient = orient; | |
55 | } | |
56 | ||
57 | virtual void Notify(); | |
58 | ||
59 | private: | |
60 | wxScrolledWindow *m_win; | |
61 | wxEventType m_eventType; | |
62 | int m_pos, | |
63 | m_orient; | |
64 | ||
65 | DECLARE_NO_COPY_CLASS(wxHtmlWinAutoScrollTimer) | |
66 | }; | |
67 | ||
68 | void wxHtmlWinAutoScrollTimer::Notify() | |
69 | { | |
70 | // only do all this as long as the window is capturing the mouse | |
71 | if ( wxWindow::GetCapture() != m_win ) | |
72 | { | |
73 | Stop(); | |
74 | } | |
75 | else // we still capture the mouse, continue generating events | |
76 | { | |
77 | // first scroll the window if we are allowed to do it | |
78 | wxScrollWinEvent event1(m_eventType, m_pos, m_orient); | |
79 | event1.SetEventObject(m_win); | |
80 | if ( m_win->GetEventHandler()->ProcessEvent(event1) ) | |
81 | { | |
82 | // and then send a pseudo mouse-move event to refresh the selection | |
83 | wxMouseEvent event2(wxEVT_MOTION); | |
84 | wxGetMousePosition(&event2.m_x, &event2.m_y); | |
85 | ||
86 | // the mouse event coordinates should be client, not screen as | |
87 | // returned by wxGetMousePosition | |
88 | wxWindow *parentTop = m_win; | |
89 | while ( parentTop->GetParent() ) | |
90 | parentTop = parentTop->GetParent(); | |
91 | wxPoint ptOrig = parentTop->GetPosition(); | |
92 | event2.m_x -= ptOrig.x; | |
93 | event2.m_y -= ptOrig.y; | |
94 | ||
95 | event2.SetEventObject(m_win); | |
96 | ||
97 | // FIXME: we don't fill in the other members - ok? | |
98 | m_win->GetEventHandler()->ProcessEvent(event2); | |
99 | } | |
100 | else // can't scroll further, stop | |
101 | { | |
102 | Stop(); | |
103 | } | |
104 | } | |
105 | } | |
d659d703 VZ |
106 | |
107 | #endif // wxUSE_CLIPBOARD | |
1338c59a VS |
108 | |
109 | ||
110 | ||
892aeafc VS |
111 | //----------------------------------------------------------------------------- |
112 | // wxHtmlHistoryItem | |
113 | //----------------------------------------------------------------------------- | |
114 | ||
115 | // item of history list | |
4460b6c4 | 116 | class WXDLLIMPEXP_HTML wxHtmlHistoryItem |
892aeafc VS |
117 | { |
118 | public: | |
119 | wxHtmlHistoryItem(const wxString& p, const wxString& a) {m_Page = p, m_Anchor = a, m_Pos = 0;} | |
120 | int GetPos() const {return m_Pos;} | |
121 | void SetPos(int p) {m_Pos = p;} | |
122 | const wxString& GetPage() const {return m_Page;} | |
123 | const wxString& GetAnchor() const {return m_Anchor;} | |
124 | ||
125 | private: | |
126 | wxString m_Page; | |
127 | wxString m_Anchor; | |
128 | int m_Pos; | |
129 | }; | |
5526e819 | 130 | |
5526e819 VS |
131 | |
132 | //----------------------------------------------------------------------------- | |
892aeafc | 133 | // our private arrays: |
5526e819 VS |
134 | //----------------------------------------------------------------------------- |
135 | ||
892aeafc | 136 | WX_DECLARE_OBJARRAY(wxHtmlHistoryItem, wxHtmlHistoryArray); |
17a1ebd1 | 137 | WX_DEFINE_OBJARRAY(wxHtmlHistoryArray) |
5526e819 | 138 | |
892aeafc | 139 | WX_DECLARE_LIST(wxHtmlProcessor, wxHtmlProcessorList); |
17a1ebd1 | 140 | WX_DEFINE_LIST(wxHtmlProcessorList) |
5526e819 | 141 | |
bc55e31b VS |
142 | //----------------------------------------------------------------------------- |
143 | // wxHtmlWindowMouseHelper | |
144 | //----------------------------------------------------------------------------- | |
145 | ||
146 | wxHtmlWindowMouseHelper::wxHtmlWindowMouseHelper(wxHtmlWindowInterface *iface) | |
147 | : m_tmpMouseMoved(false), | |
148 | m_tmpLastLink(NULL), | |
149 | m_tmpLastCell(NULL), | |
150 | m_interface(iface) | |
151 | { | |
152 | } | |
153 | ||
154 | void wxHtmlWindowMouseHelper::HandleMouseMoved() | |
155 | { | |
156 | m_tmpMouseMoved = true; | |
157 | } | |
158 | ||
159 | bool wxHtmlWindowMouseHelper::HandleMouseClick(wxHtmlCell *rootCell, | |
160 | const wxPoint& pos, | |
161 | const wxMouseEvent& event) | |
162 | { | |
163 | if (!rootCell) | |
164 | return false; | |
165 | ||
166 | wxHtmlCell *cell = rootCell->FindCellByPos(pos.x, pos.y); | |
167 | // this check is needed because FindCellByPos returns terminal cell and | |
168 | // containers may have empty borders -- in this case NULL will be | |
169 | // returned | |
170 | if (!cell) | |
171 | return false; | |
172 | ||
173 | // adjust the coordinates to be relative to this cell: | |
174 | wxPoint relpos = pos - cell->GetAbsPos(rootCell); | |
175 | ||
176 | return OnCellClicked(cell, relpos.x, relpos.y, event); | |
177 | } | |
178 | ||
179 | void wxHtmlWindowMouseHelper::HandleIdle(wxHtmlCell *rootCell, | |
180 | const wxPoint& pos) | |
181 | { | |
182 | wxHtmlCell *cell = rootCell ? rootCell->FindCellByPos(pos.x, pos.y) : NULL; | |
183 | ||
184 | if (cell != m_tmpLastCell) | |
185 | { | |
186 | wxHtmlLinkInfo *lnk = NULL; | |
187 | if (cell) | |
188 | { | |
189 | // adjust the coordinates to be relative to this cell: | |
190 | wxPoint relpos = pos - cell->GetAbsPos(rootCell); | |
191 | lnk = cell->GetLink(relpos.x, relpos.y); | |
192 | } | |
193 | ||
194 | wxCursor cur; | |
195 | if (cell) | |
88a1b648 | 196 | cur = cell->GetMouseCursor(m_interface); |
bc55e31b | 197 | else |
88a1b648 VS |
198 | cur = m_interface->GetHTMLCursor( |
199 | wxHtmlWindowInterface::HTMLCursor_Default); | |
200 | ||
bc55e31b VS |
201 | m_interface->GetHTMLWindow()->SetCursor(cur); |
202 | ||
203 | if (lnk != m_tmpLastLink) | |
204 | { | |
205 | if (lnk) | |
206 | m_interface->SetHTMLStatusText(lnk->GetHref()); | |
207 | else | |
208 | m_interface->SetHTMLStatusText(wxEmptyString); | |
209 | ||
210 | m_tmpLastLink = lnk; | |
211 | } | |
212 | ||
213 | m_tmpLastCell = cell; | |
214 | } | |
215 | else // mouse moved but stayed in the same cell | |
216 | { | |
217 | if ( cell ) | |
218 | { | |
219 | OnCellMouseHover(cell, pos.x, pos.y); | |
220 | } | |
221 | } | |
222 | ||
223 | m_tmpMouseMoved = false; | |
224 | } | |
225 | ||
226 | bool wxHtmlWindowMouseHelper::OnCellClicked(wxHtmlCell *cell, | |
227 | wxCoord x, wxCoord y, | |
228 | const wxMouseEvent& event) | |
229 | { | |
230 | wxCHECK_MSG( cell, false, _T("can't be called with NULL cell") ); | |
231 | ||
232 | return cell->ProcessMouseClick(m_interface, wxPoint(x, y), event); | |
233 | } | |
234 | ||
235 | void wxHtmlWindowMouseHelper::OnCellMouseHover(wxHtmlCell * WXUNUSED(cell), | |
236 | wxCoord WXUNUSED(x), | |
237 | wxCoord WXUNUSED(y)) | |
238 | { | |
239 | // do nothing here | |
240 | } | |
241 | ||
892aeafc VS |
242 | //----------------------------------------------------------------------------- |
243 | // wxHtmlWindow | |
244 | //----------------------------------------------------------------------------- | |
5526e819 | 245 | |
88a1b648 VS |
246 | wxList wxHtmlWindow::m_Filters; |
247 | wxHtmlFilter *wxHtmlWindow::m_DefaultFilter = NULL; | |
248 | wxHtmlProcessorList *wxHtmlWindow::m_GlobalProcessors = NULL; | |
249 | wxCursor *wxHtmlWindow::ms_cursorLink = NULL; | |
250 | wxCursor *wxHtmlWindow::ms_cursorText = NULL; | |
251 | ||
252 | void wxHtmlWindow::CleanUpStatics() | |
253 | { | |
254 | wxDELETE(m_DefaultFilter); | |
255 | WX_CLEAR_LIST(wxList, m_Filters); | |
256 | if (m_GlobalProcessors) | |
257 | WX_CLEAR_LIST(wxHtmlProcessorList, *m_GlobalProcessors); | |
258 | wxDELETE(m_GlobalProcessors); | |
259 | wxDELETE(ms_cursorLink); | |
260 | wxDELETE(ms_cursorText); | |
261 | } | |
5526e819 | 262 | |
4f417130 | 263 | void wxHtmlWindow::Init() |
5526e819 | 264 | { |
89de9af3 | 265 | m_tmpCanDrawLocks = 0; |
5526e819 | 266 | m_FS = new wxFileSystem(); |
67a99992 | 267 | #if wxUSE_STATUSBAR |
5526e819 | 268 | m_RelatedStatusBar = -1; |
67a99992 | 269 | #endif // wxUSE_STATUSBAR |
5526e819 | 270 | m_RelatedFrame = NULL; |
892aeafc | 271 | m_TitleFormat = wxT("%s"); |
d5db80c2 | 272 | m_OpenedPage = m_OpenedAnchor = m_OpenedPageTitle = wxEmptyString; |
5526e819 VS |
273 | m_Cell = NULL; |
274 | m_Parser = new wxHtmlWinParser(this); | |
4f9297b0 | 275 | m_Parser->SetFS(m_FS); |
5526e819 | 276 | m_HistoryPos = -1; |
d1da8872 | 277 | m_HistoryOn = true; |
892aeafc VS |
278 | m_History = new wxHtmlHistoryArray; |
279 | m_Processors = NULL; | |
4f417130 VS |
280 | m_Style = 0; |
281 | SetBorders(10); | |
adf2eb2d VS |
282 | m_selection = NULL; |
283 | m_makingSelection = false; | |
1338c59a VS |
284 | #if wxUSE_CLIPBOARD |
285 | m_timerAutoScroll = NULL; | |
6ce51985 | 286 | m_lastDoubleClick = 0; |
d659d703 | 287 | #endif // wxUSE_CLIPBOARD |
1338c59a | 288 | m_backBuffer = NULL; |
518ba663 | 289 | m_eraseBgInOnPaint = false; |
b3c03420 | 290 | m_tmpSelFromCell = NULL; |
4f417130 VS |
291 | } |
292 | ||
790dbce3 | 293 | bool wxHtmlWindow::Create(wxWindow *parent, wxWindowID id, |
4f417130 | 294 | const wxPoint& pos, const wxSize& size, |
790dbce3 | 295 | long style, const wxString& name) |
4f417130 | 296 | { |
790dbce3 | 297 | if (!wxScrolledWindow::Create(parent, id, pos, size, |
2a536376 VS |
298 | style | wxVSCROLL | wxHSCROLL, |
299 | name)) | |
d1da8872 | 300 | return false; |
4f417130 | 301 | |
a547ebff | 302 | m_Style = style; |
4f9297b0 | 303 | SetPage(wxT("<html><body></body></html>")); |
d1da8872 | 304 | return true; |
5526e819 VS |
305 | } |
306 | ||
307 | ||
5526e819 VS |
308 | wxHtmlWindow::~wxHtmlWindow() |
309 | { | |
1338c59a VS |
310 | #if wxUSE_CLIPBOARD |
311 | StopAutoScrolling(); | |
d659d703 | 312 | #endif // wxUSE_CLIPBOARD |
5526e819 VS |
313 | HistoryClear(); |
314 | ||
689c4829 VZ |
315 | delete m_selection; |
316 | ||
317 | delete m_Cell; | |
5526e819 | 318 | |
d80096a2 VZ |
319 | if ( m_Processors ) |
320 | { | |
321 | WX_CLEAR_LIST(wxHtmlProcessorList, *m_Processors); | |
322 | } | |
222ed1d6 | 323 | |
5526e819 VS |
324 | delete m_Parser; |
325 | delete m_FS; | |
892aeafc VS |
326 | delete m_History; |
327 | delete m_Processors; | |
1338c59a | 328 | delete m_backBuffer; |
5526e819 VS |
329 | } |
330 | ||
331 | ||
332 | ||
333 | void wxHtmlWindow::SetRelatedFrame(wxFrame* frame, const wxString& format) | |
334 | { | |
335 | m_RelatedFrame = frame; | |
336 | m_TitleFormat = format; | |
337 | } | |
338 | ||
339 | ||
340 | ||
67a99992 | 341 | #if wxUSE_STATUSBAR |
5526e819 VS |
342 | void wxHtmlWindow::SetRelatedStatusBar(int bar) |
343 | { | |
344 | m_RelatedStatusBar = bar; | |
345 | } | |
67a99992 | 346 | #endif // wxUSE_STATUSBAR |
269e8200 RD |
347 | |
348 | ||
349 | ||
fbfb8bcc | 350 | void wxHtmlWindow::SetFonts(const wxString& normal_face, const wxString& fixed_face, const int *sizes) |
5526e819 | 351 | { |
4f9297b0 | 352 | m_Parser->SetFonts(normal_face, fixed_face, sizes); |
73de5077 VS |
353 | |
354 | // re-layout the page after changing fonts: | |
355 | DoSetPage(*(m_Parser->GetSource())); | |
5526e819 VS |
356 | } |
357 | ||
10e5c7ea VS |
358 | void wxHtmlWindow::SetStandardFonts(int size, |
359 | const wxString& normal_face, | |
360 | const wxString& fixed_face) | |
7acd3625 | 361 | { |
10e5c7ea | 362 | m_Parser->SetStandardFonts(size, normal_face, fixed_face); |
5526e819 | 363 | |
73de5077 VS |
364 | // re-layout the page after changing fonts: |
365 | DoSetPage(*(m_Parser->GetSource())); | |
366 | } | |
5526e819 VS |
367 | |
368 | bool wxHtmlWindow::SetPage(const wxString& source) | |
73de5077 VS |
369 | { |
370 | m_OpenedPage = m_OpenedAnchor = m_OpenedPageTitle = wxEmptyString; | |
371 | return DoSetPage(source); | |
372 | } | |
373 | ||
374 | bool wxHtmlWindow::DoSetPage(const wxString& source) | |
5526e819 | 375 | { |
892aeafc VS |
376 | wxString newsrc(source); |
377 | ||
adf2eb2d VS |
378 | wxDELETE(m_selection); |
379 | ||
b3c03420 VS |
380 | // we will soon delete all the cells, so clear pointers to them: |
381 | m_tmpSelFromCell = NULL; | |
382 | ||
892aeafc | 383 | // pass HTML through registered processors: |
960ba969 | 384 | if (m_Processors || m_GlobalProcessors) |
892aeafc | 385 | { |
222ed1d6 | 386 | wxHtmlProcessorList::compatibility_iterator nodeL, nodeG; |
960ba969 | 387 | int prL, prG; |
892aeafc | 388 | |
0cc70962 VZ |
389 | if ( m_Processors ) |
390 | nodeL = m_Processors->GetFirst(); | |
391 | if ( m_GlobalProcessors ) | |
392 | nodeG = m_GlobalProcessors->GetFirst(); | |
960ba969 VS |
393 | |
394 | // VS: there are two lists, global and local, both of them sorted by | |
e421922f | 395 | // priority. Since we have to go through _both_ lists with |
960ba969 VS |
396 | // decreasing priority, we "merge-sort" the lists on-line by |
397 | // processing that one of the two heads that has higher priority | |
398 | // in every iteration | |
399 | while (nodeL || nodeG) | |
892aeafc VS |
400 | { |
401 | prL = (nodeL) ? nodeL->GetData()->GetPriority() : -1; | |
960ba969 VS |
402 | prG = (nodeG) ? nodeG->GetData()->GetPriority() : -1; |
403 | if (prL > prG) | |
892aeafc | 404 | { |
73348d09 VS |
405 | if (nodeL->GetData()->IsEnabled()) |
406 | newsrc = nodeL->GetData()->Process(newsrc); | |
892aeafc VS |
407 | nodeL = nodeL->GetNext(); |
408 | } | |
960ba969 | 409 | else // prL <= prG |
892aeafc | 410 | { |
73348d09 VS |
411 | if (nodeG->GetData()->IsEnabled()) |
412 | newsrc = nodeG->GetData()->Process(newsrc); | |
960ba969 | 413 | nodeG = nodeG->GetNext(); |
892aeafc VS |
414 | } |
415 | } | |
416 | } | |
5526e819 | 417 | |
892aeafc VS |
418 | // ...and run the parser on it: |
419 | wxClientDC *dc = new wxClientDC(this); | |
4f9297b0 | 420 | dc->SetMapMode(wxMM_TEXT); |
5526e819 | 421 | SetBackgroundColour(wxColour(0xFF, 0xFF, 0xFF)); |
97e490f8 | 422 | SetBackgroundImage(wxNullBitmap); |
73de5077 | 423 | |
4f9297b0 | 424 | m_Parser->SetDC(dc); |
33ac7e6f | 425 | if (m_Cell) |
4f9297b0 | 426 | { |
89de9af3 VS |
427 | delete m_Cell; |
428 | m_Cell = NULL; | |
f61815af | 429 | } |
892aeafc | 430 | m_Cell = (wxHtmlContainerCell*) m_Parser->Parse(newsrc); |
5526e819 | 431 | delete dc; |
4f9297b0 VS |
432 | m_Cell->SetIndent(m_Borders, wxHTML_INDENT_ALL, wxHTML_UNITS_PIXELS); |
433 | m_Cell->SetAlignHor(wxHTML_ALIGN_CENTER); | |
5526e819 | 434 | CreateLayout(); |
bfb9ee96 | 435 | if (m_tmpCanDrawLocks == 0) |
892aeafc | 436 | Refresh(); |
d1da8872 | 437 | return true; |
5526e819 VS |
438 | } |
439 | ||
39029898 VS |
440 | bool wxHtmlWindow::AppendToPage(const wxString& source) |
441 | { | |
73de5077 | 442 | return DoSetPage(*(GetParser()->GetSource()) + source); |
39029898 | 443 | } |
5526e819 VS |
444 | |
445 | bool wxHtmlWindow::LoadPage(const wxString& location) | |
446 | { | |
1ccabb81 | 447 | wxBusyCursor busyCursor; |
790dbce3 | 448 | |
5526e819 VS |
449 | wxFSFile *f; |
450 | bool rt_val; | |
d1da8872 | 451 | bool needs_refresh = false; |
33ac7e6f | 452 | |
89de9af3 | 453 | m_tmpCanDrawLocks++; |
e421922f | 454 | if (m_HistoryOn && (m_HistoryPos != -1)) |
4f9297b0 | 455 | { |
960ba969 | 456 | // store scroll position into history item: |
5526e819 | 457 | int x, y; |
e421922f | 458 | GetViewStart(&x, &y); |
892aeafc | 459 | (*m_History)[m_HistoryPos].SetPos(y); |
5526e819 VS |
460 | } |
461 | ||
e421922f | 462 | if (location[0] == wxT('#')) |
4f9297b0 | 463 | { |
960ba969 | 464 | // local anchor: |
5526e819 | 465 | wxString anch = location.Mid(1) /*1 to end*/; |
89de9af3 | 466 | m_tmpCanDrawLocks--; |
5526e819 | 467 | rt_val = ScrollToAnchor(anch); |
fc7dfaf8 VS |
468 | m_tmpCanDrawLocks++; |
469 | } | |
33ac7e6f | 470 | else if (location.Find(wxT('#')) != wxNOT_FOUND && location.BeforeFirst(wxT('#')) == m_OpenedPage) |
4f9297b0 | 471 | { |
fc7dfaf8 VS |
472 | wxString anch = location.AfterFirst(wxT('#')); |
473 | m_tmpCanDrawLocks--; | |
474 | rt_val = ScrollToAnchor(anch); | |
475 | m_tmpCanDrawLocks++; | |
476 | } | |
33ac7e6f KB |
477 | else if (location.Find(wxT('#')) != wxNOT_FOUND && |
478 | (m_FS->GetPath() + location.BeforeFirst(wxT('#'))) == m_OpenedPage) | |
e421922f | 479 | { |
fc7dfaf8 VS |
480 | wxString anch = location.AfterFirst(wxT('#')); |
481 | m_tmpCanDrawLocks--; | |
482 | rt_val = ScrollToAnchor(anch); | |
483 | m_tmpCanDrawLocks++; | |
5526e819 VS |
484 | } |
485 | ||
33ac7e6f | 486 | else |
4f9297b0 | 487 | { |
67a99992 WS |
488 | needs_refresh = true; |
489 | #if wxUSE_STATUSBAR | |
5526e819 | 490 | // load&display it: |
33ac7e6f | 491 | if (m_RelatedStatusBar != -1) |
e421922f | 492 | { |
4f9297b0 | 493 | m_RelatedFrame->SetStatusText(_("Connecting..."), m_RelatedStatusBar); |
67a99992 | 494 | Refresh(false); |
5526e819 | 495 | } |
67a99992 | 496 | #endif // wxUSE_STATUSBAR |
790dbce3 | 497 | |
6cc4e6b8 | 498 | f = m_Parser->OpenURL(wxHTML_URL_PAGE, location); |
33ac7e6f | 499 | |
7cb9cf89 VS |
500 | // try to interpret 'location' as filename instead of URL: |
501 | if (f == NULL) | |
502 | { | |
503 | wxFileName fn(location); | |
504 | wxString location2 = wxFileSystem::FileNameToURL(fn); | |
505 | f = m_Parser->OpenURL(wxHTML_URL_PAGE, location2); | |
506 | } | |
507 | ||
33ac7e6f | 508 | if (f == NULL) |
e421922f | 509 | { |
f6bcfd97 | 510 | wxLogError(_("Unable to open requested HTML document: %s"), location.c_str()); |
89de9af3 | 511 | m_tmpCanDrawLocks--; |
67a99992 | 512 | return false; |
5526e819 VS |
513 | } |
514 | ||
33ac7e6f | 515 | else |
e421922f | 516 | { |
222ed1d6 | 517 | wxList::compatibility_iterator node; |
5526e819 VS |
518 | wxString src = wxEmptyString; |
519 | ||
67a99992 | 520 | #if wxUSE_STATUSBAR |
33ac7e6f | 521 | if (m_RelatedStatusBar != -1) |
e421922f | 522 | { |
5526e819 | 523 | wxString msg = _("Loading : ") + location; |
4f9297b0 | 524 | m_RelatedFrame->SetStatusText(msg, m_RelatedStatusBar); |
67a99992 | 525 | Refresh(false); |
5526e819 | 526 | } |
67a99992 | 527 | #endif // wxUSE_STATUSBAR |
5526e819 VS |
528 | |
529 | node = m_Filters.GetFirst(); | |
4f9297b0 | 530 | while (node) |
e421922f | 531 | { |
4f9297b0 VS |
532 | wxHtmlFilter *h = (wxHtmlFilter*) node->GetData(); |
533 | if (h->CanRead(*f)) | |
e421922f | 534 | { |
4f9297b0 | 535 | src = h->ReadFile(*f); |
5526e819 VS |
536 | break; |
537 | } | |
4f9297b0 | 538 | node = node->GetNext(); |
5526e819 | 539 | } |
33ac7e6f | 540 | if (src == wxEmptyString) |
e421922f | 541 | { |
89de9af3 | 542 | if (m_DefaultFilter == NULL) m_DefaultFilter = GetDefaultFilter(); |
4f9297b0 | 543 | src = m_DefaultFilter->ReadFile(*f); |
89de9af3 | 544 | } |
5526e819 | 545 | |
4f9297b0 | 546 | m_FS->ChangePathTo(f->GetLocation()); |
5526e819 | 547 | rt_val = SetPage(src); |
4f9297b0 | 548 | m_OpenedPage = f->GetLocation(); |
33ac7e6f | 549 | if (f->GetAnchor() != wxEmptyString) |
e421922f | 550 | { |
4f9297b0 | 551 | ScrollToAnchor(f->GetAnchor()); |
5526e819 VS |
552 | } |
553 | ||
554 | delete f; | |
555 | ||
67a99992 | 556 | #if wxUSE_STATUSBAR |
d1da8872 | 557 | if (m_RelatedStatusBar != -1) |
67a99992 WS |
558 | m_RelatedFrame->SetStatusText(_("Done"), m_RelatedStatusBar); |
559 | #endif // wxUSE_STATUSBAR | |
5526e819 VS |
560 | } |
561 | } | |
562 | ||
4f9297b0 VS |
563 | if (m_HistoryOn) // add this page to history there: |
564 | { | |
892aeafc | 565 | int c = m_History->GetCount() - (m_HistoryPos + 1); |
5526e819 | 566 | |
0cb9cfb2 | 567 | if (m_HistoryPos < 0 || |
ee19c324 VS |
568 | (*m_History)[m_HistoryPos].GetPage() != m_OpenedPage || |
569 | (*m_History)[m_HistoryPos].GetAnchor() != m_OpenedAnchor) | |
570 | { | |
571 | m_HistoryPos++; | |
572 | for (int i = 0; i < c; i++) | |
b54e41c5 | 573 | m_History->RemoveAt(m_HistoryPos); |
ee19c324 VS |
574 | m_History->Add(new wxHtmlHistoryItem(m_OpenedPage, m_OpenedAnchor)); |
575 | } | |
5526e819 VS |
576 | } |
577 | ||
096824d7 VS |
578 | if (m_OpenedPageTitle == wxEmptyString) |
579 | OnSetTitle(wxFileNameFromPath(m_OpenedPage)); | |
fc7dfaf8 | 580 | |
33ac7e6f | 581 | if (needs_refresh) |
4f9297b0 | 582 | { |
fc7dfaf8 VS |
583 | m_tmpCanDrawLocks--; |
584 | Refresh(); | |
585 | } | |
586 | else | |
587 | m_tmpCanDrawLocks--; | |
588 | ||
5526e819 VS |
589 | return rt_val; |
590 | } | |
591 | ||
592 | ||
7cb9cf89 VS |
593 | bool wxHtmlWindow::LoadFile(const wxFileName& filename) |
594 | { | |
595 | wxString url = wxFileSystem::FileNameToURL(filename); | |
596 | return LoadPage(url); | |
597 | } | |
598 | ||
5526e819 VS |
599 | |
600 | bool wxHtmlWindow::ScrollToAnchor(const wxString& anchor) | |
601 | { | |
4f9297b0 | 602 | const wxHtmlCell *c = m_Cell->Find(wxHTML_COND_ISANCHOR, &anchor); |
f3c82859 VS |
603 | if (!c) |
604 | { | |
f6bcfd97 | 605 | wxLogWarning(_("HTML anchor %s does not exist."), anchor.c_str()); |
d1da8872 | 606 | return false; |
f3c82859 | 607 | } |
33ac7e6f | 608 | else |
4f9297b0 | 609 | { |
5526e819 | 610 | int y; |
269e8200 | 611 | |
4f9297b0 | 612 | for (y = 0; c != NULL; c = c->GetParent()) y += c->GetPosY(); |
efba2b89 | 613 | Scroll(-1, y / wxHTML_SCROLL_STEP); |
5526e819 | 614 | m_OpenedAnchor = anchor; |
d1da8872 | 615 | return true; |
5526e819 VS |
616 | } |
617 | } | |
618 | ||
619 | ||
d5db80c2 | 620 | void wxHtmlWindow::OnSetTitle(const wxString& title) |
5526e819 | 621 | { |
33ac7e6f | 622 | if (m_RelatedFrame) |
4f9297b0 | 623 | { |
5526e819 VS |
624 | wxString tit; |
625 | tit.Printf(m_TitleFormat, title.c_str()); | |
4f9297b0 | 626 | m_RelatedFrame->SetTitle(tit); |
5526e819 | 627 | } |
d5db80c2 | 628 | m_OpenedPageTitle = title; |
5526e819 VS |
629 | } |
630 | ||
631 | ||
632 | ||
633 | ||
634 | ||
635 | void wxHtmlWindow::CreateLayout() | |
636 | { | |
637 | int ClientWidth, ClientHeight; | |
638 | ||
639 | if (!m_Cell) return; | |
a547ebff | 640 | |
33ac7e6f | 641 | if (m_Style & wxHW_SCROLLBAR_NEVER) |
4f9297b0 VS |
642 | { |
643 | SetScrollbars(wxHTML_SCROLL_STEP, 1, m_Cell->GetWidth() / wxHTML_SCROLL_STEP, 0); // always off | |
a547ebff | 644 | GetClientSize(&ClientWidth, &ClientHeight); |
4f9297b0 | 645 | m_Cell->Layout(ClientWidth); |
a547ebff VS |
646 | } |
647 | ||
648 | else { | |
649 | GetClientSize(&ClientWidth, &ClientHeight); | |
4f9297b0 | 650 | m_Cell->Layout(ClientWidth); |
33ac7e6f | 651 | if (ClientHeight < m_Cell->GetHeight() + GetCharHeight()) |
e421922f | 652 | { |
f3bcfd9b VS |
653 | SetScrollbars( |
654 | wxHTML_SCROLL_STEP, wxHTML_SCROLL_STEP, | |
4f9297b0 VS |
655 | m_Cell->GetWidth() / wxHTML_SCROLL_STEP, |
656 | (m_Cell->GetHeight() + GetCharHeight()) / wxHTML_SCROLL_STEP | |
f3bcfd9b | 657 | /*cheat: top-level frag is always container*/); |
a547ebff | 658 | } |
4f9297b0 | 659 | else /* we fit into window, no need for scrollbars */ |
e421922f | 660 | { |
4f9297b0 | 661 | SetScrollbars(wxHTML_SCROLL_STEP, 1, m_Cell->GetWidth() / wxHTML_SCROLL_STEP, 0); // disable... |
89de9af3 | 662 | GetClientSize(&ClientWidth, &ClientHeight); |
4f9297b0 | 663 | m_Cell->Layout(ClientWidth); // ...and relayout |
89de9af3 | 664 | } |
a547ebff | 665 | } |
5526e819 VS |
666 | } |
667 | ||
269e8200 | 668 | |
5526e819 VS |
669 | |
670 | void wxHtmlWindow::ReadCustomization(wxConfigBase *cfg, wxString path) | |
671 | { | |
672 | wxString oldpath; | |
673 | wxString tmp; | |
d5db80c2 VS |
674 | int p_fontsizes[7]; |
675 | wxString p_fff, p_ffn; | |
5526e819 | 676 | |
33ac7e6f | 677 | if (path != wxEmptyString) |
4f9297b0 VS |
678 | { |
679 | oldpath = cfg->GetPath(); | |
680 | cfg->SetPath(path); | |
5526e819 VS |
681 | } |
682 | ||
892aeafc VS |
683 | m_Borders = cfg->Read(wxT("wxHtmlWindow/Borders"), m_Borders); |
684 | p_fff = cfg->Read(wxT("wxHtmlWindow/FontFaceFixed"), m_Parser->m_FontFaceFixed); | |
685 | p_ffn = cfg->Read(wxT("wxHtmlWindow/FontFaceNormal"), m_Parser->m_FontFaceNormal); | |
bfb9ee96 | 686 | for (int i = 0; i < 7; i++) |
4f9297b0 | 687 | { |
66a77a74 | 688 | tmp.Printf(wxT("wxHtmlWindow/FontsSize%i"), i); |
4f9297b0 | 689 | p_fontsizes[i] = cfg->Read(tmp, m_Parser->m_FontsSizes[i]); |
5526e819 | 690 | } |
8eb2940f | 691 | SetFonts(p_ffn, p_fff, p_fontsizes); |
5526e819 VS |
692 | |
693 | if (path != wxEmptyString) | |
4f9297b0 | 694 | cfg->SetPath(oldpath); |
5526e819 VS |
695 | } |
696 | ||
697 | ||
698 | ||
699 | void wxHtmlWindow::WriteCustomization(wxConfigBase *cfg, wxString path) | |
700 | { | |
701 | wxString oldpath; | |
702 | wxString tmp; | |
703 | ||
33ac7e6f | 704 | if (path != wxEmptyString) |
4f9297b0 VS |
705 | { |
706 | oldpath = cfg->GetPath(); | |
707 | cfg->SetPath(path); | |
5526e819 VS |
708 | } |
709 | ||
892aeafc VS |
710 | cfg->Write(wxT("wxHtmlWindow/Borders"), (long) m_Borders); |
711 | cfg->Write(wxT("wxHtmlWindow/FontFaceFixed"), m_Parser->m_FontFaceFixed); | |
712 | cfg->Write(wxT("wxHtmlWindow/FontFaceNormal"), m_Parser->m_FontFaceNormal); | |
bfb9ee96 | 713 | for (int i = 0; i < 7; i++) |
4f9297b0 | 714 | { |
66a77a74 | 715 | tmp.Printf(wxT("wxHtmlWindow/FontsSize%i"), i); |
4f9297b0 | 716 | cfg->Write(tmp, (long) m_Parser->m_FontsSizes[i]); |
5526e819 VS |
717 | } |
718 | ||
719 | if (path != wxEmptyString) | |
4f9297b0 | 720 | cfg->SetPath(oldpath); |
5526e819 VS |
721 | } |
722 | ||
723 | ||
724 | ||
725 | bool wxHtmlWindow::HistoryBack() | |
726 | { | |
727 | wxString a, l; | |
728 | ||
d1da8872 | 729 | if (m_HistoryPos < 1) return false; |
5526e819 | 730 | |
bbda1088 VS |
731 | // store scroll position into history item: |
732 | int x, y; | |
e421922f | 733 | GetViewStart(&x, &y); |
892aeafc | 734 | (*m_History)[m_HistoryPos].SetPos(y); |
bbda1088 VS |
735 | |
736 | // go to previous position: | |
5526e819 VS |
737 | m_HistoryPos--; |
738 | ||
892aeafc VS |
739 | l = (*m_History)[m_HistoryPos].GetPage(); |
740 | a = (*m_History)[m_HistoryPos].GetAnchor(); | |
d1da8872 | 741 | m_HistoryOn = false; |
89de9af3 | 742 | m_tmpCanDrawLocks++; |
5526e819 | 743 | if (a == wxEmptyString) LoadPage(l); |
fc7dfaf8 | 744 | else LoadPage(l + wxT("#") + a); |
d1da8872 | 745 | m_HistoryOn = true; |
89de9af3 | 746 | m_tmpCanDrawLocks--; |
892aeafc | 747 | Scroll(0, (*m_History)[m_HistoryPos].GetPos()); |
5526e819 | 748 | Refresh(); |
d1da8872 | 749 | return true; |
5526e819 VS |
750 | } |
751 | ||
1b113a81 VS |
752 | bool wxHtmlWindow::HistoryCanBack() |
753 | { | |
d1da8872 WS |
754 | if (m_HistoryPos < 1) return false; |
755 | return true ; | |
1b113a81 | 756 | } |
5526e819 VS |
757 | |
758 | ||
759 | bool wxHtmlWindow::HistoryForward() | |
760 | { | |
761 | wxString a, l; | |
762 | ||
d1da8872 WS |
763 | if (m_HistoryPos == -1) return false; |
764 | if (m_HistoryPos >= (int)m_History->GetCount() - 1)return false; | |
5526e819 VS |
765 | |
766 | m_OpenedPage = wxEmptyString; // this will disable adding new entry into history in LoadPage() | |
767 | ||
768 | m_HistoryPos++; | |
892aeafc VS |
769 | l = (*m_History)[m_HistoryPos].GetPage(); |
770 | a = (*m_History)[m_HistoryPos].GetAnchor(); | |
d1da8872 | 771 | m_HistoryOn = false; |
89de9af3 | 772 | m_tmpCanDrawLocks++; |
5526e819 | 773 | if (a == wxEmptyString) LoadPage(l); |
fc7dfaf8 | 774 | else LoadPage(l + wxT("#") + a); |
d1da8872 | 775 | m_HistoryOn = true; |
89de9af3 | 776 | m_tmpCanDrawLocks--; |
892aeafc | 777 | Scroll(0, (*m_History)[m_HistoryPos].GetPos()); |
5526e819 | 778 | Refresh(); |
d1da8872 | 779 | return true; |
5526e819 VS |
780 | } |
781 | ||
1b113a81 VS |
782 | bool wxHtmlWindow::HistoryCanForward() |
783 | { | |
d1da8872 WS |
784 | if (m_HistoryPos == -1) return false; |
785 | if (m_HistoryPos >= (int)m_History->GetCount() - 1)return false; | |
786 | return true ; | |
1b113a81 | 787 | } |
5526e819 VS |
788 | |
789 | ||
790 | void wxHtmlWindow::HistoryClear() | |
791 | { | |
892aeafc | 792 | m_History->Empty(); |
5526e819 VS |
793 | m_HistoryPos = -1; |
794 | } | |
795 | ||
892aeafc VS |
796 | void wxHtmlWindow::AddProcessor(wxHtmlProcessor *processor) |
797 | { | |
798 | if (!m_Processors) | |
799 | { | |
800 | m_Processors = new wxHtmlProcessorList; | |
892aeafc | 801 | } |
222ed1d6 | 802 | wxHtmlProcessorList::compatibility_iterator node; |
bfb9ee96 | 803 | |
892aeafc VS |
804 | for (node = m_Processors->GetFirst(); node; node = node->GetNext()) |
805 | { | |
bfb9ee96 | 806 | if (processor->GetPriority() > node->GetData()->GetPriority()) |
892aeafc VS |
807 | { |
808 | m_Processors->Insert(node, processor); | |
960ba969 | 809 | return; |
892aeafc VS |
810 | } |
811 | } | |
960ba969 | 812 | m_Processors->Append(processor); |
892aeafc VS |
813 | } |
814 | ||
960ba969 | 815 | /*static */ void wxHtmlWindow::AddGlobalProcessor(wxHtmlProcessor *processor) |
892aeafc | 816 | { |
960ba969 | 817 | if (!m_GlobalProcessors) |
892aeafc | 818 | { |
960ba969 | 819 | m_GlobalProcessors = new wxHtmlProcessorList; |
892aeafc | 820 | } |
222ed1d6 | 821 | wxHtmlProcessorList::compatibility_iterator node; |
e421922f | 822 | |
960ba969 | 823 | for (node = m_GlobalProcessors->GetFirst(); node; node = node->GetNext()) |
892aeafc | 824 | { |
bfb9ee96 | 825 | if (processor->GetPriority() > node->GetData()->GetPriority()) |
892aeafc | 826 | { |
960ba969 VS |
827 | m_GlobalProcessors->Insert(node, processor); |
828 | return; | |
892aeafc VS |
829 | } |
830 | } | |
960ba969 | 831 | m_GlobalProcessors->Append(processor); |
892aeafc VS |
832 | } |
833 | ||
5526e819 VS |
834 | |
835 | ||
5526e819 VS |
836 | void wxHtmlWindow::AddFilter(wxHtmlFilter *filter) |
837 | { | |
5526e819 VS |
838 | m_Filters.Append(filter); |
839 | } | |
840 | ||
841 | ||
36c4ff4d VS |
842 | bool wxHtmlWindow::IsSelectionEnabled() const |
843 | { | |
844 | #if wxUSE_CLIPBOARD | |
845 | return !(m_Style & wxHW_NO_SELECTION); | |
846 | #else | |
847 | return false; | |
848 | #endif | |
849 | } | |
d659d703 | 850 | |
e3774124 | 851 | |
1338c59a | 852 | #if wxUSE_CLIPBOARD |
977b867e | 853 | wxString wxHtmlWindow::DoSelectionToText(wxHtmlSelection *sel) |
e3774124 | 854 | { |
977b867e | 855 | if ( !sel ) |
e3774124 VS |
856 | return wxEmptyString; |
857 | ||
f30e67db VS |
858 | wxClientDC dc(this); |
859 | ||
977b867e | 860 | const wxHtmlCell *end = sel->GetToCell(); |
e3774124 | 861 | wxString text; |
977b867e | 862 | wxHtmlTerminalCellsInterator i(sel->GetFromCell(), end); |
e3774124 VS |
863 | if ( i ) |
864 | { | |
977b867e | 865 | text << i->ConvertToText(sel); |
e3774124 VS |
866 | ++i; |
867 | } | |
868 | const wxHtmlCell *prev = *i; | |
869 | while ( i ) | |
870 | { | |
871 | if ( prev->GetParent() != i->GetParent() ) | |
872 | text << _T('\n'); | |
977b867e | 873 | text << i->ConvertToText(*i == end ? sel : NULL); |
e3774124 VS |
874 | prev = *i; |
875 | ++i; | |
876 | } | |
877 | return text; | |
878 | } | |
879 | ||
977b867e VS |
880 | wxString wxHtmlWindow::ToText() |
881 | { | |
882 | if (m_Cell) | |
883 | { | |
884 | wxHtmlSelection sel; | |
885 | sel.Set(m_Cell->GetFirstTerminal(), m_Cell->GetLastTerminal()); | |
886 | return DoSelectionToText(&sel); | |
887 | } | |
888 | else | |
889 | return wxEmptyString; | |
890 | } | |
891 | ||
d659d703 VZ |
892 | #endif // wxUSE_CLIPBOARD |
893 | ||
8feaa81f | 894 | bool wxHtmlWindow::CopySelection(ClipboardType t) |
e3774124 | 895 | { |
d659d703 | 896 | #if wxUSE_CLIPBOARD |
e3774124 VS |
897 | if ( m_selection ) |
898 | { | |
28b2ac5b | 899 | #if defined(__UNIX__) && !defined(__WXMAC__) |
e3774124 | 900 | wxTheClipboard->UsePrimarySelection(t == Primary); |
d659d703 VZ |
901 | #else // !__UNIX__ |
902 | // Primary selection exists only under X11, so don't do anything under | |
903 | // the other platforms when we try to access it | |
904 | // | |
905 | // TODO: this should be abstracted at wxClipboard level! | |
906 | if ( t == Primary ) | |
8feaa81f | 907 | return false; |
d659d703 VZ |
908 | #endif // __UNIX__/!__UNIX__ |
909 | ||
e3774124 VS |
910 | if ( wxTheClipboard->Open() ) |
911 | { | |
d659d703 | 912 | const wxString txt(SelectionToText()); |
e3774124 VS |
913 | wxTheClipboard->SetData(new wxTextDataObject(txt)); |
914 | wxTheClipboard->Close(); | |
915 | wxLogTrace(_T("wxhtmlselection"), | |
916 | _("Copied to clipboard:\"%s\""), txt.c_str()); | |
8feaa81f VZ |
917 | |
918 | return true; | |
e3774124 VS |
919 | } |
920 | } | |
caf448e3 WS |
921 | #else |
922 | wxUnusedVar(t); | |
d659d703 | 923 | #endif // wxUSE_CLIPBOARD |
8feaa81f VZ |
924 | |
925 | return false; | |
e3774124 | 926 | } |
5526e819 VS |
927 | |
928 | ||
0b2dadd3 | 929 | void wxHtmlWindow::OnLinkClicked(const wxHtmlLinkInfo& link) |
5526e819 | 930 | { |
31d8b4ad VS |
931 | const wxMouseEvent *e = link.GetEvent(); |
932 | if (e == NULL || e->LeftUp()) | |
933 | LoadPage(link.GetHref()); | |
5526e819 VS |
934 | } |
935 | ||
12148be2 | 936 | void wxHtmlWindow::OnEraseBackground(wxEraseEvent& event) |
1338c59a | 937 | { |
97e490f8 VZ |
938 | if ( !m_bmpBg.Ok() ) |
939 | { | |
518ba663 VZ |
940 | // don't even skip the event, if we don't have a bg bitmap we're going |
941 | // to overwrite background in OnPaint() below anyhow, so letting the | |
942 | // default handling take place would only result in flicker, just set a | |
943 | // flag to erase the background below | |
944 | m_eraseBgInOnPaint = true; | |
97e490f8 VZ |
945 | return; |
946 | } | |
947 | ||
948 | wxDC& dc = *event.GetDC(); | |
949 | ||
950 | // if the image is not fully opaque, we have to erase the background before | |
951 | // drawing it, however avoid doing it for opaque images as this would just | |
952 | // result in extra flicker without any other effect as background is | |
953 | // completely covered anyhow | |
954 | if ( m_bmpBg.GetMask() ) | |
955 | { | |
956 | dc.SetBackground(wxBrush(GetBackgroundColour(), wxSOLID)); | |
957 | dc.Clear(); | |
958 | } | |
959 | ||
960 | const wxSize sizeWin(GetClientSize()); | |
961 | const wxSize sizeBmp(m_bmpBg.GetWidth(), m_bmpBg.GetHeight()); | |
962 | for ( wxCoord x = 0; x < sizeWin.x; x += sizeBmp.x ) | |
963 | { | |
964 | for ( wxCoord y = 0; y < sizeWin.y; y += sizeBmp.y ) | |
965 | { | |
966 | dc.DrawBitmap(m_bmpBg, x, y, true /* use mask */); | |
967 | } | |
968 | } | |
1338c59a VS |
969 | } |
970 | ||
971 | void wxHtmlWindow::OnPaint(wxPaintEvent& WXUNUSED(event)) | |
5526e819 | 972 | { |
1338c59a VS |
973 | wxPaintDC dc(this); |
974 | ||
518ba663 VZ |
975 | if (m_tmpCanDrawLocks > 0 || m_Cell == NULL) |
976 | return; | |
5526e819 | 977 | |
b835e9bf | 978 | int x, y; |
e421922f | 979 | GetViewStart(&x, &y); |
1338c59a VS |
980 | wxRect rect = GetUpdateRegion().GetBox(); |
981 | wxSize sz = GetSize(); | |
982 | ||
983 | wxMemoryDC dcm; | |
984 | if ( !m_backBuffer ) | |
985 | m_backBuffer = new wxBitmap(sz.x, sz.y); | |
d659d703 | 986 | dcm.SelectObject(*m_backBuffer); |
a03ae172 | 987 | |
518ba663 VZ |
988 | if ( m_eraseBgInOnPaint ) |
989 | { | |
990 | dcm.SetBackground(wxBrush(GetBackgroundColour(), wxSOLID)); | |
991 | dcm.Clear(); | |
992 | ||
993 | m_eraseBgInOnPaint = false; | |
994 | } | |
995 | else // someone has already erased the background, keep it | |
996 | { | |
997 | // preserve the existing background, otherwise we'd erase anything the | |
998 | // user code had drawn in its EVT_ERASE_BACKGROUND handler when we do | |
999 | // the Blit back below | |
1000 | dcm.Blit(0, rect.GetTop(), | |
1001 | sz.x, rect.GetBottom() - rect.GetTop() + 1, | |
1002 | &dc, | |
1003 | 0, rect.GetTop()); | |
1004 | } | |
a03ae172 | 1005 | |
7f461f8a | 1006 | PrepareDC(dcm); |
1338c59a VS |
1007 | dcm.SetMapMode(wxMM_TEXT); |
1008 | dcm.SetBackgroundMode(wxTRANSPARENT); | |
d659d703 | 1009 | |
f30e67db VS |
1010 | wxHtmlRenderingInfo rinfo; |
1011 | wxDefaultHtmlRenderingStyle rstyle; | |
1012 | rinfo.SetSelection(m_selection); | |
1013 | rinfo.SetStyle(&rstyle); | |
1338c59a | 1014 | m_Cell->Draw(dcm, 0, 0, |
790dbce3 | 1015 | y * wxHTML_SCROLL_STEP + rect.GetTop(), |
36c4ff4d | 1016 | y * wxHTML_SCROLL_STEP + rect.GetBottom(), |
f30e67db | 1017 | rinfo); |
d1da8872 WS |
1018 | |
1019 | //#define DEBUG_HTML_SELECTION | |
03693319 VS |
1020 | #ifdef DEBUG_HTML_SELECTION |
1021 | { | |
1022 | int xc, yc, x, y; | |
1023 | wxGetMousePosition(&xc, &yc); | |
1024 | ScreenToClient(&xc, &yc); | |
1025 | CalcUnscrolledPosition(xc, yc, &x, &y); | |
1026 | wxHtmlCell *at = m_Cell->FindCellByPos(x, y); | |
d1da8872 | 1027 | wxHtmlCell *before = |
03693319 | 1028 | m_Cell->FindCellByPos(x, y, wxHTML_FIND_NEAREST_BEFORE); |
d1da8872 | 1029 | wxHtmlCell *after = |
03693319 | 1030 | m_Cell->FindCellByPos(x, y, wxHTML_FIND_NEAREST_AFTER); |
d1da8872 | 1031 | |
03693319 VS |
1032 | dcm.SetBrush(*wxTRANSPARENT_BRUSH); |
1033 | dcm.SetPen(*wxBLACK_PEN); | |
1034 | if (at) | |
1035 | dcm.DrawRectangle(at->GetAbsPos(), | |
1036 | wxSize(at->GetWidth(),at->GetHeight())); | |
1037 | dcm.SetPen(*wxGREEN_PEN); | |
1038 | if (before) | |
1039 | dcm.DrawRectangle(before->GetAbsPos().x+1, before->GetAbsPos().y+1, | |
1040 | before->GetWidth()-2,before->GetHeight()-2); | |
1041 | dcm.SetPen(*wxRED_PEN); | |
1042 | if (after) | |
1043 | dcm.DrawRectangle(after->GetAbsPos().x+2, after->GetAbsPos().y+2, | |
1044 | after->GetWidth()-4,after->GetHeight()-4); | |
1045 | } | |
1046 | #endif | |
d1da8872 | 1047 | |
1338c59a VS |
1048 | dcm.SetDeviceOrigin(0,0); |
1049 | dc.Blit(0, rect.GetTop(), | |
1050 | sz.x, rect.GetBottom() - rect.GetTop() + 1, | |
1051 | &dcm, | |
1052 | 0, rect.GetTop()); | |
5526e819 VS |
1053 | } |
1054 | ||
1055 | ||
1056 | ||
1057 | ||
1058 | void wxHtmlWindow::OnSize(wxSizeEvent& event) | |
1059 | { | |
1338c59a VS |
1060 | wxDELETE(m_backBuffer); |
1061 | ||
5526e819 VS |
1062 | wxScrolledWindow::OnSize(event); |
1063 | CreateLayout(); | |
1338c59a VS |
1064 | |
1065 | // Recompute selection if necessary: | |
1066 | if ( m_selection ) | |
1067 | { | |
1068 | m_selection->Set(m_selection->GetFromCell(), | |
1069 | m_selection->GetToCell()); | |
1070 | m_selection->ClearPrivPos(); | |
1071 | } | |
d659d703 | 1072 | |
f6bcfd97 | 1073 | Refresh(); |
5526e819 VS |
1074 | } |
1075 | ||
1076 | ||
fc7a2a60 | 1077 | void wxHtmlWindow::OnMouseMove(wxMouseEvent& WXUNUSED(event)) |
5526e819 | 1078 | { |
bc55e31b | 1079 | wxHtmlWindowMouseHelper::HandleMouseMoved(); |
31d8b4ad | 1080 | } |
5526e819 | 1081 | |
adf2eb2d | 1082 | void wxHtmlWindow::OnMouseDown(wxMouseEvent& event) |
31d8b4ad | 1083 | { |
0994d968 | 1084 | #if wxUSE_CLIPBOARD |
adf2eb2d | 1085 | if ( event.LeftDown() && IsSelectionEnabled() ) |
4f9297b0 | 1086 | { |
0994d968 VS |
1087 | const long TRIPLECLICK_LEN = 200; // 0.2 sec after doubleclick |
1088 | if ( wxGetLocalTimeMillis() - m_lastDoubleClick <= TRIPLECLICK_LEN ) | |
adf2eb2d | 1089 | { |
0994d968 | 1090 | SelectLine(CalcUnscrolledPosition(event.GetPosition())); |
d659d703 | 1091 | |
5de65c69 | 1092 | (void) CopySelection(); |
adf2eb2d | 1093 | } |
0994d968 | 1094 | else |
d659d703 | 1095 | { |
0994d968 | 1096 | m_makingSelection = true; |
d659d703 | 1097 | |
0994d968 VS |
1098 | if ( m_selection ) |
1099 | { | |
1100 | wxDELETE(m_selection); | |
1101 | Refresh(); | |
1102 | } | |
1103 | m_tmpSelFromPos = CalcUnscrolledPosition(event.GetPosition()); | |
1104 | m_tmpSelFromCell = NULL; | |
5526e819 | 1105 | |
0994d968 VS |
1106 | CaptureMouse(); |
1107 | } | |
adf2eb2d | 1108 | } |
caf448e3 WS |
1109 | #else |
1110 | wxUnusedVar(event); | |
d659d703 | 1111 | #endif // wxUSE_CLIPBOARD |
adf2eb2d | 1112 | } |
5526e819 | 1113 | |
adf2eb2d VS |
1114 | void wxHtmlWindow::OnMouseUp(wxMouseEvent& event) |
1115 | { | |
1338c59a | 1116 | #if wxUSE_CLIPBOARD |
adf2eb2d VS |
1117 | if ( m_makingSelection ) |
1118 | { | |
1119 | ReleaseMouse(); | |
1120 | m_makingSelection = false; | |
1121 | ||
1122 | // did the user move the mouse far enough from starting point? | |
8feaa81f | 1123 | if ( CopySelection(Primary) ) |
adf2eb2d VS |
1124 | { |
1125 | // we don't want mouse up event that ended selecting to be | |
1126 | // handled as mouse click and e.g. follow hyperlink: | |
1127 | return; | |
1128 | } | |
1129 | } | |
d659d703 VZ |
1130 | #endif // wxUSE_CLIPBOARD |
1131 | ||
adf2eb2d | 1132 | SetFocus(); |
f6010d8f | 1133 | |
bc55e31b VS |
1134 | wxPoint pos = CalcUnscrolledPosition(event.GetPosition()); |
1135 | wxHtmlWindowMouseHelper::HandleMouseClick(m_Cell, pos, event); | |
5526e819 VS |
1136 | } |
1137 | ||
1138 | ||
1139 | ||
5180055b JS |
1140 | void wxHtmlWindow::OnInternalIdle() |
1141 | { | |
1142 | wxWindow::OnInternalIdle(); | |
d1da8872 | 1143 | |
bc55e31b | 1144 | if (m_Cell != NULL && DidMouseMove()) |
4f9297b0 | 1145 | { |
03693319 VS |
1146 | #ifdef DEBUG_HTML_SELECTION |
1147 | Refresh(); | |
1148 | #endif | |
adf2eb2d VS |
1149 | int xc, yc, x, y; |
1150 | wxGetMousePosition(&xc, &yc); | |
1151 | ScreenToClient(&xc, &yc); | |
1152 | CalcUnscrolledPosition(xc, yc, &x, &y); | |
0cb9cfb2 | 1153 | |
f6010d8f | 1154 | wxHtmlCell *cell = m_Cell->FindCellByPos(x, y); |
adf2eb2d VS |
1155 | |
1156 | // handle selection update: | |
1157 | if ( m_makingSelection ) | |
1158 | { | |
adf2eb2d | 1159 | if ( !m_tmpSelFromCell ) |
748418c0 VS |
1160 | m_tmpSelFromCell = m_Cell->FindCellByPos( |
1161 | m_tmpSelFromPos.x,m_tmpSelFromPos.y); | |
d1da8872 | 1162 | |
03693319 VS |
1163 | // NB: a trick - we adjust selFromPos to be upper left or bottom |
1164 | // right corner of the first cell of the selection depending | |
1165 | // on whether the mouse is moving to the right or to the left. | |
1166 | // This gives us more "natural" behaviour when selecting | |
1167 | // a line (specifically, first cell of the next line is not | |
1168 | // included if you drag selection from left to right over | |
1169 | // entire line): | |
1170 | wxPoint dirFromPos; | |
1171 | if ( !m_tmpSelFromCell ) | |
1172 | { | |
1173 | dirFromPos = m_tmpSelFromPos; | |
1174 | } | |
1175 | else | |
1176 | { | |
1177 | dirFromPos = m_tmpSelFromCell->GetAbsPos(); | |
1178 | if ( x < m_tmpSelFromPos.x ) | |
1179 | { | |
1180 | dirFromPos.x += m_tmpSelFromCell->GetWidth(); | |
1181 | dirFromPos.y += m_tmpSelFromCell->GetHeight(); | |
1182 | } | |
1183 | } | |
d1da8872 | 1184 | bool goingDown = dirFromPos.y < y || |
03693319 VS |
1185 | (dirFromPos.y == y && dirFromPos.x < x); |
1186 | ||
1187 | // determine selection span: | |
748418c0 | 1188 | if ( /*still*/ !m_tmpSelFromCell ) |
adf2eb2d VS |
1189 | { |
1190 | if (goingDown) | |
1191 | { | |
5a1597e9 VS |
1192 | m_tmpSelFromCell = m_Cell->FindCellByPos( |
1193 | m_tmpSelFromPos.x,m_tmpSelFromPos.y, | |
1194 | wxHTML_FIND_NEAREST_AFTER); | |
adf2eb2d VS |
1195 | if (!m_tmpSelFromCell) |
1196 | m_tmpSelFromCell = m_Cell->GetFirstTerminal(); | |
1197 | } | |
1198 | else | |
1199 | { | |
5a1597e9 VS |
1200 | m_tmpSelFromCell = m_Cell->FindCellByPos( |
1201 | m_tmpSelFromPos.x,m_tmpSelFromPos.y, | |
1202 | wxHTML_FIND_NEAREST_BEFORE); | |
adf2eb2d VS |
1203 | if (!m_tmpSelFromCell) |
1204 | m_tmpSelFromCell = m_Cell->GetLastTerminal(); | |
1205 | } | |
1206 | } | |
1207 | ||
1208 | wxHtmlCell *selcell = cell; | |
1209 | if (!selcell) | |
1210 | { | |
1211 | if (goingDown) | |
1212 | { | |
1213 | selcell = m_Cell->FindCellByPos(x, y, | |
03693319 | 1214 | wxHTML_FIND_NEAREST_BEFORE); |
adf2eb2d VS |
1215 | if (!selcell) |
1216 | selcell = m_Cell->GetLastTerminal(); | |
1217 | } | |
1218 | else | |
1219 | { | |
1220 | selcell = m_Cell->FindCellByPos(x, y, | |
03693319 | 1221 | wxHTML_FIND_NEAREST_AFTER); |
adf2eb2d VS |
1222 | if (!selcell) |
1223 | selcell = m_Cell->GetFirstTerminal(); | |
1224 | } | |
1225 | } | |
1226 | ||
1227 | // NB: it may *rarely* happen that the code above didn't find one | |
1228 | // of the cells, e.g. if wxHtmlWindow doesn't contain any | |
d659d703 | 1229 | // visible cells. |
adf2eb2d | 1230 | if ( selcell && m_tmpSelFromCell ) |
d659d703 | 1231 | { |
adf2eb2d VS |
1232 | if ( !m_selection ) |
1233 | { | |
1234 | // start selecting only if mouse movement was big enough | |
1235 | // (otherwise it was meant as mouse click, not selection): | |
1236 | const int PRECISION = 2; | |
1237 | wxPoint diff = m_tmpSelFromPos - wxPoint(x,y); | |
1238 | if (abs(diff.x) > PRECISION || abs(diff.y) > PRECISION) | |
1239 | { | |
1240 | m_selection = new wxHtmlSelection(); | |
1241 | } | |
1242 | } | |
1243 | if ( m_selection ) | |
1244 | { | |
e3774124 | 1245 | if ( m_tmpSelFromCell->IsBefore(selcell) ) |
adf2eb2d VS |
1246 | { |
1247 | m_selection->Set(m_tmpSelFromPos, m_tmpSelFromCell, | |
f30e67db | 1248 | wxPoint(x,y), selcell); } |
adf2eb2d VS |
1249 | else |
1250 | { | |
1251 | m_selection->Set(wxPoint(x,y), selcell, | |
1252 | m_tmpSelFromPos, m_tmpSelFromCell); | |
1253 | } | |
1338c59a VS |
1254 | m_selection->ClearPrivPos(); |
1255 | Refresh(); | |
adf2eb2d VS |
1256 | } |
1257 | } | |
1258 | } | |
d659d703 | 1259 | |
adf2eb2d | 1260 | // handle cursor and status bar text changes: |
f6010d8f | 1261 | |
bc55e31b VS |
1262 | // NB: because we're passing in 'cell' and not 'm_Cell' (so that the |
1263 | // leaf cell lookup isn't done twice), we need to adjust the | |
1264 | // position for the new root: | |
1265 | wxPoint posInCell(x, y); | |
1266 | if (cell) | |
1267 | posInCell -= cell->GetAbsPos(); | |
1268 | wxHtmlWindowMouseHelper::HandleIdle(cell, posInCell); | |
5526e819 VS |
1269 | } |
1270 | } | |
1271 | ||
e3774124 | 1272 | #if wxUSE_CLIPBOARD |
1338c59a VS |
1273 | void wxHtmlWindow::StopAutoScrolling() |
1274 | { | |
1275 | if ( m_timerAutoScroll ) | |
1276 | { | |
1277 | wxDELETE(m_timerAutoScroll); | |
1278 | } | |
1279 | } | |
1280 | ||
1281 | void wxHtmlWindow::OnMouseEnter(wxMouseEvent& event) | |
1282 | { | |
1283 | StopAutoScrolling(); | |
1284 | event.Skip(); | |
1285 | } | |
1286 | ||
1287 | void wxHtmlWindow::OnMouseLeave(wxMouseEvent& event) | |
1288 | { | |
1289 | // don't prevent the usual processing of the event from taking place | |
1290 | event.Skip(); | |
1291 | ||
1292 | // when a captured mouse leave a scrolled window we start generate | |
1293 | // scrolling events to allow, for example, extending selection beyond the | |
1294 | // visible area in some controls | |
1295 | if ( wxWindow::GetCapture() == this ) | |
1296 | { | |
1297 | // where is the mouse leaving? | |
1298 | int pos, orient; | |
1299 | wxPoint pt = event.GetPosition(); | |
1300 | if ( pt.x < 0 ) | |
1301 | { | |
1302 | orient = wxHORIZONTAL; | |
1303 | pos = 0; | |
1304 | } | |
1305 | else if ( pt.y < 0 ) | |
1306 | { | |
1307 | orient = wxVERTICAL; | |
1308 | pos = 0; | |
1309 | } | |
1310 | else // we're lower or to the right of the window | |
1311 | { | |
1312 | wxSize size = GetClientSize(); | |
1313 | if ( pt.x > size.x ) | |
1314 | { | |
1315 | orient = wxHORIZONTAL; | |
1316 | pos = GetVirtualSize().x / wxHTML_SCROLL_STEP; | |
1317 | } | |
1318 | else if ( pt.y > size.y ) | |
1319 | { | |
1320 | orient = wxVERTICAL; | |
1321 | pos = GetVirtualSize().y / wxHTML_SCROLL_STEP; | |
1322 | } | |
1323 | else // this should be impossible | |
1324 | { | |
1325 | // but seems to happen sometimes under wxMSW - maybe it's a bug | |
1326 | // there but for now just ignore it | |
1327 | ||
1328 | //wxFAIL_MSG( _T("can't understand where has mouse gone") ); | |
1329 | ||
1330 | return; | |
1331 | } | |
1332 | } | |
1333 | ||
1334 | // only start the auto scroll timer if the window can be scrolled in | |
1335 | // this direction | |
1336 | if ( !HasScrollbar(orient) ) | |
1337 | return; | |
1338 | ||
1339 | delete m_timerAutoScroll; | |
1340 | m_timerAutoScroll = new wxHtmlWinAutoScrollTimer | |
1341 | ( | |
1342 | this, | |
1343 | pos == 0 ? wxEVT_SCROLLWIN_LINEUP | |
1344 | : wxEVT_SCROLLWIN_LINEDOWN, | |
1345 | pos, | |
1346 | orient | |
1347 | ); | |
1348 | m_timerAutoScroll->Start(50); // FIXME: make configurable | |
1349 | } | |
1350 | } | |
1351 | ||
e3774124 VS |
1352 | void wxHtmlWindow::OnKeyUp(wxKeyEvent& event) |
1353 | { | |
abe64011 | 1354 | if ( IsSelectionEnabled() && event.GetKeyCode() == 'C' && event.CmdDown() ) |
e3774124 | 1355 | { |
5de65c69 | 1356 | (void) CopySelection(); |
e3774124 | 1357 | } |
e3774124 VS |
1358 | } |
1359 | ||
fc7a2a60 | 1360 | void wxHtmlWindow::OnCopy(wxCommandEvent& WXUNUSED(event)) |
e3774124 | 1361 | { |
5de65c69 | 1362 | (void) CopySelection(); |
e3774124 | 1363 | } |
d659d703 | 1364 | |
31eefb99 VS |
1365 | void wxHtmlWindow::OnDoubleClick(wxMouseEvent& event) |
1366 | { | |
1367 | // select word under cursor: | |
1368 | if ( IsSelectionEnabled() ) | |
1369 | { | |
0994d968 | 1370 | SelectWord(CalcUnscrolledPosition(event.GetPosition())); |
d659d703 | 1371 | |
5de65c69 | 1372 | (void) CopySelection(Primary); |
d659d703 | 1373 | |
0994d968 | 1374 | m_lastDoubleClick = wxGetLocalTimeMillis(); |
31eefb99 VS |
1375 | } |
1376 | else | |
1377 | event.Skip(); | |
1378 | } | |
0994d968 VS |
1379 | |
1380 | void wxHtmlWindow::SelectWord(const wxPoint& pos) | |
1381 | { | |
2a536376 | 1382 | if ( m_Cell ) |
0994d968 | 1383 | { |
2a536376 VS |
1384 | wxHtmlCell *cell = m_Cell->FindCellByPos(pos.x, pos.y); |
1385 | if ( cell ) | |
1386 | { | |
1387 | delete m_selection; | |
1388 | m_selection = new wxHtmlSelection(); | |
1389 | m_selection->Set(cell, cell); | |
1390 | RefreshRect(wxRect(CalcScrolledPosition(cell->GetAbsPos()), | |
1391 | wxSize(cell->GetWidth(), cell->GetHeight()))); | |
1392 | } | |
0994d968 VS |
1393 | } |
1394 | } | |
1395 | ||
1396 | void wxHtmlWindow::SelectLine(const wxPoint& pos) | |
1397 | { | |
2a536376 | 1398 | if ( m_Cell ) |
0994d968 | 1399 | { |
2a536376 VS |
1400 | wxHtmlCell *cell = m_Cell->FindCellByPos(pos.x, pos.y); |
1401 | if ( cell ) | |
0994d968 | 1402 | { |
2a536376 VS |
1403 | // We use following heuristic to find a "line": let the line be all |
1404 | // cells in same container as the cell under mouse cursor that are | |
1405 | // neither completely above nor completely bellow the clicked cell | |
1406 | // (i.e. are likely to be words positioned on same line of text). | |
1407 | ||
1408 | int y1 = cell->GetAbsPos().y; | |
1409 | int y2 = y1 + cell->GetHeight(); | |
1410 | int y; | |
1411 | const wxHtmlCell *c; | |
1412 | const wxHtmlCell *before = NULL; | |
1413 | const wxHtmlCell *after = NULL; | |
1414 | ||
1415 | // find last cell of line: | |
1416 | for ( c = cell->GetNext(); c; c = c->GetNext()) | |
1417 | { | |
1418 | y = c->GetAbsPos().y; | |
1419 | if ( y + c->GetHeight() > y1 && y < y2 ) | |
1420 | after = c; | |
1421 | else | |
1422 | break; | |
1423 | } | |
1424 | if ( !after ) | |
1425 | after = cell; | |
0994d968 | 1426 | |
2a536376 VS |
1427 | // find first cell of line: |
1428 | for ( c = cell->GetParent()->GetFirstChild(); | |
1429 | c && c != cell; c = c->GetNext()) | |
0994d968 | 1430 | { |
2a536376 VS |
1431 | y = c->GetAbsPos().y; |
1432 | if ( y + c->GetHeight() > y1 && y < y2 ) | |
1433 | { | |
1434 | if ( ! before ) | |
1435 | before = c; | |
1436 | } | |
1437 | else | |
1438 | before = NULL; | |
0994d968 | 1439 | } |
2a536376 VS |
1440 | if ( !before ) |
1441 | before = cell; | |
1442 | ||
1443 | delete m_selection; | |
1444 | m_selection = new wxHtmlSelection(); | |
1445 | m_selection->Set(before, after); | |
1446 | ||
1447 | Refresh(); | |
0994d968 | 1448 | } |
2a536376 VS |
1449 | } |
1450 | } | |
d659d703 | 1451 | |
2a536376 VS |
1452 | void wxHtmlWindow::SelectAll() |
1453 | { | |
1454 | if ( m_Cell ) | |
1455 | { | |
0994d968 VS |
1456 | delete m_selection; |
1457 | m_selection = new wxHtmlSelection(); | |
2a536376 | 1458 | m_selection->Set(m_Cell->GetFirstTerminal(), m_Cell->GetLastTerminal()); |
0994d968 VS |
1459 | Refresh(); |
1460 | } | |
1461 | } | |
2a536376 | 1462 | |
d659d703 | 1463 | #endif // wxUSE_CLIPBOARD |
e3774124 VS |
1464 | |
1465 | ||
5526e819 | 1466 | |
bfb9ee96 | 1467 | IMPLEMENT_ABSTRACT_CLASS(wxHtmlProcessor,wxObject) |
5526e819 | 1468 | |
786a2425 SC |
1469 | #if wxUSE_EXTENDED_RTTI |
1470 | IMPLEMENT_DYNAMIC_CLASS_XTI(wxHtmlWindow, wxScrolledWindow,"wx/html/htmlwin.h") | |
1471 | ||
459f2add | 1472 | wxBEGIN_PROPERTIES_TABLE(wxHtmlWindow) |
786a2425 | 1473 | /* |
d1da8872 WS |
1474 | TODO PROPERTIES |
1475 | style , wxHW_SCROLLBAR_AUTO | |
1476 | borders , (dimension) | |
1477 | url , string | |
1478 | htmlcode , string | |
786a2425 | 1479 | */ |
459f2add | 1480 | wxEND_PROPERTIES_TABLE() |
786a2425 | 1481 | |
459f2add SC |
1482 | wxBEGIN_HANDLERS_TABLE(wxHtmlWindow) |
1483 | wxEND_HANDLERS_TABLE() | |
786a2425 | 1484 | |
d1da8872 | 1485 | wxCONSTRUCTOR_5( wxHtmlWindow , wxWindow* , Parent , wxWindowID , Id , wxPoint , Position , wxSize , Size , long , WindowStyle ) |
786a2425 | 1486 | #else |
5526e819 | 1487 | IMPLEMENT_DYNAMIC_CLASS(wxHtmlWindow,wxScrolledWindow) |
786a2425 | 1488 | #endif |
5526e819 VS |
1489 | |
1490 | BEGIN_EVENT_TABLE(wxHtmlWindow, wxScrolledWindow) | |
1491 | EVT_SIZE(wxHtmlWindow::OnSize) | |
adf2eb2d VS |
1492 | EVT_LEFT_DOWN(wxHtmlWindow::OnMouseDown) |
1493 | EVT_LEFT_UP(wxHtmlWindow::OnMouseUp) | |
1494 | EVT_RIGHT_UP(wxHtmlWindow::OnMouseUp) | |
31d8b4ad | 1495 | EVT_MOTION(wxHtmlWindow::OnMouseMove) |
1338c59a VS |
1496 | EVT_ERASE_BACKGROUND(wxHtmlWindow::OnEraseBackground) |
1497 | EVT_PAINT(wxHtmlWindow::OnPaint) | |
e3774124 | 1498 | #if wxUSE_CLIPBOARD |
31eefb99 | 1499 | EVT_LEFT_DCLICK(wxHtmlWindow::OnDoubleClick) |
1338c59a VS |
1500 | EVT_ENTER_WINDOW(wxHtmlWindow::OnMouseEnter) |
1501 | EVT_LEAVE_WINDOW(wxHtmlWindow::OnMouseLeave) | |
e3774124 VS |
1502 | EVT_KEY_UP(wxHtmlWindow::OnKeyUp) |
1503 | EVT_MENU(wxID_COPY, wxHtmlWindow::OnCopy) | |
d659d703 | 1504 | #endif // wxUSE_CLIPBOARD |
5526e819 VS |
1505 | END_EVENT_TABLE() |
1506 | ||
bc55e31b VS |
1507 | //----------------------------------------------------------------------------- |
1508 | // wxHtmlWindowInterface implementation in wxHtmlWindow | |
1509 | //----------------------------------------------------------------------------- | |
1510 | ||
1511 | void wxHtmlWindow::SetHTMLWindowTitle(const wxString& title) | |
1512 | { | |
1513 | OnSetTitle(title); | |
1514 | } | |
1515 | ||
1516 | void wxHtmlWindow::OnHTMLLinkClicked(const wxHtmlLinkInfo& link) | |
1517 | { | |
1518 | OnLinkClicked(link); | |
1519 | } | |
1520 | ||
1521 | wxHtmlOpeningStatus wxHtmlWindow::OnHTMLOpeningURL(wxHtmlURLType type, | |
1522 | const wxString& url, | |
1523 | wxString *redirect) const | |
1524 | { | |
1525 | return OnOpeningURL(type, url, redirect); | |
1526 | } | |
1527 | ||
1528 | wxPoint wxHtmlWindow::HTMLCoordsToWindow(wxHtmlCell *WXUNUSED(cell), | |
1529 | const wxPoint& pos) const | |
1530 | { | |
1531 | return CalcScrolledPosition(pos); | |
1532 | } | |
1533 | ||
1534 | wxWindow* wxHtmlWindow::GetHTMLWindow() | |
1535 | { | |
1536 | return this; | |
1537 | } | |
1538 | ||
1539 | wxColour wxHtmlWindow::GetHTMLBackgroundColour() const | |
1540 | { | |
1541 | return GetBackgroundColour(); | |
1542 | } | |
1543 | ||
1544 | void wxHtmlWindow::SetHTMLBackgroundColour(const wxColour& clr) | |
1545 | { | |
1546 | SetBackgroundColour(clr); | |
1547 | } | |
1548 | ||
1549 | void wxHtmlWindow::SetHTMLBackgroundImage(const wxBitmap& bmpBg) | |
1550 | { | |
1551 | SetBackgroundImage(bmpBg); | |
1552 | } | |
5526e819 | 1553 | |
bc55e31b VS |
1554 | void wxHtmlWindow::SetHTMLStatusText(const wxString& text) |
1555 | { | |
1556 | #if wxUSE_STATUSBAR | |
1557 | if (m_RelatedStatusBar != -1) | |
1558 | m_RelatedFrame->SetStatusText(text, m_RelatedStatusBar); | |
1559 | #endif // wxUSE_STATUSBAR | |
1560 | } | |
5526e819 | 1561 | |
88a1b648 VS |
1562 | /*static*/ |
1563 | wxCursor wxHtmlWindow::GetDefaultHTMLCursor(HTMLCursor type) | |
1564 | { | |
1565 | switch (type) | |
1566 | { | |
1567 | case HTMLCursor_Link: | |
1568 | if ( !ms_cursorLink ) | |
1569 | ms_cursorLink = new wxCursor(wxCURSOR_HAND); | |
1570 | return *ms_cursorLink; | |
1571 | ||
1572 | case HTMLCursor_Text: | |
1573 | if ( !ms_cursorText ) | |
1574 | ms_cursorText = new wxCursor(wxCURSOR_IBEAM); | |
1575 | return *ms_cursorText; | |
1576 | ||
1577 | case HTMLCursor_Default: | |
1578 | default: | |
1579 | return *wxSTANDARD_CURSOR; | |
1580 | } | |
1581 | } | |
1582 | ||
1583 | wxCursor wxHtmlWindow::GetHTMLCursor(HTMLCursor type) const | |
1584 | { | |
1585 | return GetDefaultHTMLCursor(type); | |
1586 | } | |
1587 | ||
5526e819 | 1588 | |
bc55e31b VS |
1589 | //----------------------------------------------------------------------------- |
1590 | // wxHtmlWinModule | |
1591 | //----------------------------------------------------------------------------- | |
5526e819 | 1592 | |
a76015e6 VS |
1593 | // A module to allow initialization/cleanup |
1594 | // without calling these functions from app.cpp or from | |
1595 | // the user's application. | |
1596 | ||
1597 | class wxHtmlWinModule: public wxModule | |
1598 | { | |
1599 | DECLARE_DYNAMIC_CLASS(wxHtmlWinModule) | |
1600 | public: | |
1601 | wxHtmlWinModule() : wxModule() {} | |
d1da8872 | 1602 | bool OnInit() { return true; } |
a76015e6 VS |
1603 | void OnExit() { wxHtmlWindow::CleanUpStatics(); } |
1604 | }; | |
1605 | ||
1606 | IMPLEMENT_DYNAMIC_CLASS(wxHtmlWinModule, wxModule) | |
1607 | ||
5526e819 | 1608 | |
0cecad31 VS |
1609 | // This hack forces the linker to always link in m_* files |
1610 | // (wxHTML doesn't work without handlers from these files) | |
1611 | #include "wx/html/forcelnk.h" | |
1612 | FORCE_WXHTML_MODULES() | |
5526e819 | 1613 | |
d659d703 | 1614 | #endif // wxUSE_HTML |