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