]>
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" |
c0badb70 | 25 | #include "wx/timer.h" |
9eddec69 | 26 | #include "wx/settings.h" |
28f92d74 | 27 | #include "wx/dataobj.h" |
5526e819 VS |
28 | #endif |
29 | ||
69941f05 | 30 | #include "wx/html/htmlwin.h" |
892aeafc | 31 | #include "wx/html/htmlproc.h" |
e3774124 | 32 | #include "wx/clipbrd.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 | 642 | { |
689f42f4 | 643 | SetScrollbars(1, 1, 0, 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 | ||
63e819f2 VS |
1138 | #if wxUSE_CLIPBOARD |
1139 | void wxHtmlWindow::OnMouseCaptureLost(wxMouseCaptureLostEvent& WXUNUSED(event)) | |
1140 | { | |
1141 | if ( !m_makingSelection ) | |
1142 | return; | |
1143 | ||
1144 | // discard the selecting operation | |
1145 | m_makingSelection = false; | |
1146 | wxDELETE(m_selection); | |
1147 | m_tmpSelFromCell = NULL; | |
1148 | Refresh(); | |
1149 | } | |
1150 | #endif // wxUSE_CLIPBOARD | |
5526e819 VS |
1151 | |
1152 | ||
5180055b JS |
1153 | void wxHtmlWindow::OnInternalIdle() |
1154 | { | |
1155 | wxWindow::OnInternalIdle(); | |
d1da8872 | 1156 | |
bc55e31b | 1157 | if (m_Cell != NULL && DidMouseMove()) |
4f9297b0 | 1158 | { |
03693319 VS |
1159 | #ifdef DEBUG_HTML_SELECTION |
1160 | Refresh(); | |
1161 | #endif | |
adf2eb2d VS |
1162 | int xc, yc, x, y; |
1163 | wxGetMousePosition(&xc, &yc); | |
1164 | ScreenToClient(&xc, &yc); | |
1165 | CalcUnscrolledPosition(xc, yc, &x, &y); | |
0cb9cfb2 | 1166 | |
f6010d8f | 1167 | wxHtmlCell *cell = m_Cell->FindCellByPos(x, y); |
adf2eb2d VS |
1168 | |
1169 | // handle selection update: | |
1170 | if ( m_makingSelection ) | |
1171 | { | |
adf2eb2d | 1172 | if ( !m_tmpSelFromCell ) |
748418c0 VS |
1173 | m_tmpSelFromCell = m_Cell->FindCellByPos( |
1174 | m_tmpSelFromPos.x,m_tmpSelFromPos.y); | |
d1da8872 | 1175 | |
03693319 VS |
1176 | // NB: a trick - we adjust selFromPos to be upper left or bottom |
1177 | // right corner of the first cell of the selection depending | |
1178 | // on whether the mouse is moving to the right or to the left. | |
1179 | // This gives us more "natural" behaviour when selecting | |
1180 | // a line (specifically, first cell of the next line is not | |
1181 | // included if you drag selection from left to right over | |
1182 | // entire line): | |
1183 | wxPoint dirFromPos; | |
1184 | if ( !m_tmpSelFromCell ) | |
1185 | { | |
1186 | dirFromPos = m_tmpSelFromPos; | |
1187 | } | |
1188 | else | |
1189 | { | |
1190 | dirFromPos = m_tmpSelFromCell->GetAbsPos(); | |
1191 | if ( x < m_tmpSelFromPos.x ) | |
1192 | { | |
1193 | dirFromPos.x += m_tmpSelFromCell->GetWidth(); | |
1194 | dirFromPos.y += m_tmpSelFromCell->GetHeight(); | |
1195 | } | |
1196 | } | |
d1da8872 | 1197 | bool goingDown = dirFromPos.y < y || |
03693319 VS |
1198 | (dirFromPos.y == y && dirFromPos.x < x); |
1199 | ||
1200 | // determine selection span: | |
748418c0 | 1201 | if ( /*still*/ !m_tmpSelFromCell ) |
adf2eb2d VS |
1202 | { |
1203 | if (goingDown) | |
1204 | { | |
5a1597e9 VS |
1205 | m_tmpSelFromCell = m_Cell->FindCellByPos( |
1206 | m_tmpSelFromPos.x,m_tmpSelFromPos.y, | |
1207 | wxHTML_FIND_NEAREST_AFTER); | |
adf2eb2d VS |
1208 | if (!m_tmpSelFromCell) |
1209 | m_tmpSelFromCell = m_Cell->GetFirstTerminal(); | |
1210 | } | |
1211 | else | |
1212 | { | |
5a1597e9 VS |
1213 | m_tmpSelFromCell = m_Cell->FindCellByPos( |
1214 | m_tmpSelFromPos.x,m_tmpSelFromPos.y, | |
1215 | wxHTML_FIND_NEAREST_BEFORE); | |
adf2eb2d VS |
1216 | if (!m_tmpSelFromCell) |
1217 | m_tmpSelFromCell = m_Cell->GetLastTerminal(); | |
1218 | } | |
1219 | } | |
1220 | ||
1221 | wxHtmlCell *selcell = cell; | |
1222 | if (!selcell) | |
1223 | { | |
1224 | if (goingDown) | |
1225 | { | |
1226 | selcell = m_Cell->FindCellByPos(x, y, | |
03693319 | 1227 | wxHTML_FIND_NEAREST_BEFORE); |
adf2eb2d VS |
1228 | if (!selcell) |
1229 | selcell = m_Cell->GetLastTerminal(); | |
1230 | } | |
1231 | else | |
1232 | { | |
1233 | selcell = m_Cell->FindCellByPos(x, y, | |
03693319 | 1234 | wxHTML_FIND_NEAREST_AFTER); |
adf2eb2d VS |
1235 | if (!selcell) |
1236 | selcell = m_Cell->GetFirstTerminal(); | |
1237 | } | |
1238 | } | |
1239 | ||
1240 | // NB: it may *rarely* happen that the code above didn't find one | |
1241 | // of the cells, e.g. if wxHtmlWindow doesn't contain any | |
d659d703 | 1242 | // visible cells. |
adf2eb2d | 1243 | if ( selcell && m_tmpSelFromCell ) |
d659d703 | 1244 | { |
adf2eb2d VS |
1245 | if ( !m_selection ) |
1246 | { | |
1247 | // start selecting only if mouse movement was big enough | |
1248 | // (otherwise it was meant as mouse click, not selection): | |
1249 | const int PRECISION = 2; | |
1250 | wxPoint diff = m_tmpSelFromPos - wxPoint(x,y); | |
1251 | if (abs(diff.x) > PRECISION || abs(diff.y) > PRECISION) | |
1252 | { | |
1253 | m_selection = new wxHtmlSelection(); | |
1254 | } | |
1255 | } | |
1256 | if ( m_selection ) | |
1257 | { | |
e3774124 | 1258 | if ( m_tmpSelFromCell->IsBefore(selcell) ) |
adf2eb2d VS |
1259 | { |
1260 | m_selection->Set(m_tmpSelFromPos, m_tmpSelFromCell, | |
f30e67db | 1261 | wxPoint(x,y), selcell); } |
adf2eb2d VS |
1262 | else |
1263 | { | |
1264 | m_selection->Set(wxPoint(x,y), selcell, | |
1265 | m_tmpSelFromPos, m_tmpSelFromCell); | |
1266 | } | |
1338c59a VS |
1267 | m_selection->ClearPrivPos(); |
1268 | Refresh(); | |
adf2eb2d VS |
1269 | } |
1270 | } | |
1271 | } | |
d659d703 | 1272 | |
adf2eb2d | 1273 | // handle cursor and status bar text changes: |
f6010d8f | 1274 | |
bc55e31b VS |
1275 | // NB: because we're passing in 'cell' and not 'm_Cell' (so that the |
1276 | // leaf cell lookup isn't done twice), we need to adjust the | |
1277 | // position for the new root: | |
1278 | wxPoint posInCell(x, y); | |
1279 | if (cell) | |
1280 | posInCell -= cell->GetAbsPos(); | |
1281 | wxHtmlWindowMouseHelper::HandleIdle(cell, posInCell); | |
5526e819 VS |
1282 | } |
1283 | } | |
1284 | ||
e3774124 | 1285 | #if wxUSE_CLIPBOARD |
1338c59a VS |
1286 | void wxHtmlWindow::StopAutoScrolling() |
1287 | { | |
1288 | if ( m_timerAutoScroll ) | |
1289 | { | |
1290 | wxDELETE(m_timerAutoScroll); | |
1291 | } | |
1292 | } | |
1293 | ||
1294 | void wxHtmlWindow::OnMouseEnter(wxMouseEvent& event) | |
1295 | { | |
1296 | StopAutoScrolling(); | |
1297 | event.Skip(); | |
1298 | } | |
1299 | ||
1300 | void wxHtmlWindow::OnMouseLeave(wxMouseEvent& event) | |
1301 | { | |
1302 | // don't prevent the usual processing of the event from taking place | |
1303 | event.Skip(); | |
1304 | ||
1305 | // when a captured mouse leave a scrolled window we start generate | |
1306 | // scrolling events to allow, for example, extending selection beyond the | |
1307 | // visible area in some controls | |
1308 | if ( wxWindow::GetCapture() == this ) | |
1309 | { | |
1310 | // where is the mouse leaving? | |
1311 | int pos, orient; | |
1312 | wxPoint pt = event.GetPosition(); | |
1313 | if ( pt.x < 0 ) | |
1314 | { | |
1315 | orient = wxHORIZONTAL; | |
1316 | pos = 0; | |
1317 | } | |
1318 | else if ( pt.y < 0 ) | |
1319 | { | |
1320 | orient = wxVERTICAL; | |
1321 | pos = 0; | |
1322 | } | |
1323 | else // we're lower or to the right of the window | |
1324 | { | |
1325 | wxSize size = GetClientSize(); | |
1326 | if ( pt.x > size.x ) | |
1327 | { | |
1328 | orient = wxHORIZONTAL; | |
1329 | pos = GetVirtualSize().x / wxHTML_SCROLL_STEP; | |
1330 | } | |
1331 | else if ( pt.y > size.y ) | |
1332 | { | |
1333 | orient = wxVERTICAL; | |
1334 | pos = GetVirtualSize().y / wxHTML_SCROLL_STEP; | |
1335 | } | |
1336 | else // this should be impossible | |
1337 | { | |
1338 | // but seems to happen sometimes under wxMSW - maybe it's a bug | |
1339 | // there but for now just ignore it | |
1340 | ||
1341 | //wxFAIL_MSG( _T("can't understand where has mouse gone") ); | |
1342 | ||
1343 | return; | |
1344 | } | |
1345 | } | |
1346 | ||
1347 | // only start the auto scroll timer if the window can be scrolled in | |
1348 | // this direction | |
1349 | if ( !HasScrollbar(orient) ) | |
1350 | return; | |
1351 | ||
1352 | delete m_timerAutoScroll; | |
1353 | m_timerAutoScroll = new wxHtmlWinAutoScrollTimer | |
1354 | ( | |
1355 | this, | |
1356 | pos == 0 ? wxEVT_SCROLLWIN_LINEUP | |
1357 | : wxEVT_SCROLLWIN_LINEDOWN, | |
1358 | pos, | |
1359 | orient | |
1360 | ); | |
1361 | m_timerAutoScroll->Start(50); // FIXME: make configurable | |
1362 | } | |
1363 | } | |
1364 | ||
e3774124 VS |
1365 | void wxHtmlWindow::OnKeyUp(wxKeyEvent& event) |
1366 | { | |
abe64011 | 1367 | if ( IsSelectionEnabled() && event.GetKeyCode() == 'C' && event.CmdDown() ) |
e3774124 | 1368 | { |
5de65c69 | 1369 | (void) CopySelection(); |
e3774124 | 1370 | } |
e3774124 VS |
1371 | } |
1372 | ||
fc7a2a60 | 1373 | void wxHtmlWindow::OnCopy(wxCommandEvent& WXUNUSED(event)) |
e3774124 | 1374 | { |
5de65c69 | 1375 | (void) CopySelection(); |
e3774124 | 1376 | } |
d659d703 | 1377 | |
31eefb99 VS |
1378 | void wxHtmlWindow::OnDoubleClick(wxMouseEvent& event) |
1379 | { | |
1380 | // select word under cursor: | |
1381 | if ( IsSelectionEnabled() ) | |
1382 | { | |
0994d968 | 1383 | SelectWord(CalcUnscrolledPosition(event.GetPosition())); |
d659d703 | 1384 | |
5de65c69 | 1385 | (void) CopySelection(Primary); |
d659d703 | 1386 | |
0994d968 | 1387 | m_lastDoubleClick = wxGetLocalTimeMillis(); |
31eefb99 VS |
1388 | } |
1389 | else | |
1390 | event.Skip(); | |
1391 | } | |
0994d968 VS |
1392 | |
1393 | void wxHtmlWindow::SelectWord(const wxPoint& pos) | |
1394 | { | |
2a536376 | 1395 | if ( m_Cell ) |
0994d968 | 1396 | { |
2a536376 VS |
1397 | wxHtmlCell *cell = m_Cell->FindCellByPos(pos.x, pos.y); |
1398 | if ( cell ) | |
1399 | { | |
1400 | delete m_selection; | |
1401 | m_selection = new wxHtmlSelection(); | |
1402 | m_selection->Set(cell, cell); | |
1403 | RefreshRect(wxRect(CalcScrolledPosition(cell->GetAbsPos()), | |
1404 | wxSize(cell->GetWidth(), cell->GetHeight()))); | |
1405 | } | |
0994d968 VS |
1406 | } |
1407 | } | |
1408 | ||
1409 | void wxHtmlWindow::SelectLine(const wxPoint& pos) | |
1410 | { | |
2a536376 | 1411 | if ( m_Cell ) |
0994d968 | 1412 | { |
2a536376 VS |
1413 | wxHtmlCell *cell = m_Cell->FindCellByPos(pos.x, pos.y); |
1414 | if ( cell ) | |
0994d968 | 1415 | { |
2a536376 VS |
1416 | // We use following heuristic to find a "line": let the line be all |
1417 | // cells in same container as the cell under mouse cursor that are | |
1418 | // neither completely above nor completely bellow the clicked cell | |
1419 | // (i.e. are likely to be words positioned on same line of text). | |
1420 | ||
1421 | int y1 = cell->GetAbsPos().y; | |
1422 | int y2 = y1 + cell->GetHeight(); | |
1423 | int y; | |
1424 | const wxHtmlCell *c; | |
1425 | const wxHtmlCell *before = NULL; | |
1426 | const wxHtmlCell *after = NULL; | |
1427 | ||
1428 | // find last cell of line: | |
1429 | for ( c = cell->GetNext(); c; c = c->GetNext()) | |
1430 | { | |
1431 | y = c->GetAbsPos().y; | |
1432 | if ( y + c->GetHeight() > y1 && y < y2 ) | |
1433 | after = c; | |
1434 | else | |
1435 | break; | |
1436 | } | |
1437 | if ( !after ) | |
1438 | after = cell; | |
0994d968 | 1439 | |
2a536376 VS |
1440 | // find first cell of line: |
1441 | for ( c = cell->GetParent()->GetFirstChild(); | |
1442 | c && c != cell; c = c->GetNext()) | |
0994d968 | 1443 | { |
2a536376 VS |
1444 | y = c->GetAbsPos().y; |
1445 | if ( y + c->GetHeight() > y1 && y < y2 ) | |
1446 | { | |
1447 | if ( ! before ) | |
1448 | before = c; | |
1449 | } | |
1450 | else | |
1451 | before = NULL; | |
0994d968 | 1452 | } |
2a536376 VS |
1453 | if ( !before ) |
1454 | before = cell; | |
1455 | ||
1456 | delete m_selection; | |
1457 | m_selection = new wxHtmlSelection(); | |
1458 | m_selection->Set(before, after); | |
1459 | ||
1460 | Refresh(); | |
0994d968 | 1461 | } |
2a536376 VS |
1462 | } |
1463 | } | |
d659d703 | 1464 | |
2a536376 VS |
1465 | void wxHtmlWindow::SelectAll() |
1466 | { | |
1467 | if ( m_Cell ) | |
1468 | { | |
0994d968 VS |
1469 | delete m_selection; |
1470 | m_selection = new wxHtmlSelection(); | |
2a536376 | 1471 | m_selection->Set(m_Cell->GetFirstTerminal(), m_Cell->GetLastTerminal()); |
0994d968 VS |
1472 | Refresh(); |
1473 | } | |
1474 | } | |
2a536376 | 1475 | |
d659d703 | 1476 | #endif // wxUSE_CLIPBOARD |
e3774124 VS |
1477 | |
1478 | ||
5526e819 | 1479 | |
bfb9ee96 | 1480 | IMPLEMENT_ABSTRACT_CLASS(wxHtmlProcessor,wxObject) |
5526e819 | 1481 | |
786a2425 SC |
1482 | #if wxUSE_EXTENDED_RTTI |
1483 | IMPLEMENT_DYNAMIC_CLASS_XTI(wxHtmlWindow, wxScrolledWindow,"wx/html/htmlwin.h") | |
1484 | ||
459f2add | 1485 | wxBEGIN_PROPERTIES_TABLE(wxHtmlWindow) |
786a2425 | 1486 | /* |
d1da8872 WS |
1487 | TODO PROPERTIES |
1488 | style , wxHW_SCROLLBAR_AUTO | |
1489 | borders , (dimension) | |
1490 | url , string | |
1491 | htmlcode , string | |
786a2425 | 1492 | */ |
459f2add | 1493 | wxEND_PROPERTIES_TABLE() |
786a2425 | 1494 | |
459f2add SC |
1495 | wxBEGIN_HANDLERS_TABLE(wxHtmlWindow) |
1496 | wxEND_HANDLERS_TABLE() | |
786a2425 | 1497 | |
d1da8872 | 1498 | wxCONSTRUCTOR_5( wxHtmlWindow , wxWindow* , Parent , wxWindowID , Id , wxPoint , Position , wxSize , Size , long , WindowStyle ) |
786a2425 | 1499 | #else |
5526e819 | 1500 | IMPLEMENT_DYNAMIC_CLASS(wxHtmlWindow,wxScrolledWindow) |
786a2425 | 1501 | #endif |
5526e819 VS |
1502 | |
1503 | BEGIN_EVENT_TABLE(wxHtmlWindow, wxScrolledWindow) | |
1504 | EVT_SIZE(wxHtmlWindow::OnSize) | |
adf2eb2d VS |
1505 | EVT_LEFT_DOWN(wxHtmlWindow::OnMouseDown) |
1506 | EVT_LEFT_UP(wxHtmlWindow::OnMouseUp) | |
1507 | EVT_RIGHT_UP(wxHtmlWindow::OnMouseUp) | |
31d8b4ad | 1508 | EVT_MOTION(wxHtmlWindow::OnMouseMove) |
1338c59a VS |
1509 | EVT_ERASE_BACKGROUND(wxHtmlWindow::OnEraseBackground) |
1510 | EVT_PAINT(wxHtmlWindow::OnPaint) | |
e3774124 | 1511 | #if wxUSE_CLIPBOARD |
31eefb99 | 1512 | EVT_LEFT_DCLICK(wxHtmlWindow::OnDoubleClick) |
1338c59a VS |
1513 | EVT_ENTER_WINDOW(wxHtmlWindow::OnMouseEnter) |
1514 | EVT_LEAVE_WINDOW(wxHtmlWindow::OnMouseLeave) | |
63e819f2 | 1515 | EVT_MOUSE_CAPTURE_LOST(wxHtmlWindow::OnMouseCaptureLost) |
e3774124 VS |
1516 | EVT_KEY_UP(wxHtmlWindow::OnKeyUp) |
1517 | EVT_MENU(wxID_COPY, wxHtmlWindow::OnCopy) | |
d659d703 | 1518 | #endif // wxUSE_CLIPBOARD |
5526e819 VS |
1519 | END_EVENT_TABLE() |
1520 | ||
bc55e31b VS |
1521 | //----------------------------------------------------------------------------- |
1522 | // wxHtmlWindowInterface implementation in wxHtmlWindow | |
1523 | //----------------------------------------------------------------------------- | |
1524 | ||
1525 | void wxHtmlWindow::SetHTMLWindowTitle(const wxString& title) | |
1526 | { | |
1527 | OnSetTitle(title); | |
1528 | } | |
1529 | ||
1530 | void wxHtmlWindow::OnHTMLLinkClicked(const wxHtmlLinkInfo& link) | |
1531 | { | |
1532 | OnLinkClicked(link); | |
1533 | } | |
1534 | ||
1535 | wxHtmlOpeningStatus wxHtmlWindow::OnHTMLOpeningURL(wxHtmlURLType type, | |
1536 | const wxString& url, | |
1537 | wxString *redirect) const | |
1538 | { | |
1539 | return OnOpeningURL(type, url, redirect); | |
1540 | } | |
1541 | ||
1542 | wxPoint wxHtmlWindow::HTMLCoordsToWindow(wxHtmlCell *WXUNUSED(cell), | |
1543 | const wxPoint& pos) const | |
1544 | { | |
1545 | return CalcScrolledPosition(pos); | |
1546 | } | |
1547 | ||
1548 | wxWindow* wxHtmlWindow::GetHTMLWindow() | |
1549 | { | |
1550 | return this; | |
1551 | } | |
1552 | ||
1553 | wxColour wxHtmlWindow::GetHTMLBackgroundColour() const | |
1554 | { | |
1555 | return GetBackgroundColour(); | |
1556 | } | |
1557 | ||
1558 | void wxHtmlWindow::SetHTMLBackgroundColour(const wxColour& clr) | |
1559 | { | |
1560 | SetBackgroundColour(clr); | |
1561 | } | |
1562 | ||
1563 | void wxHtmlWindow::SetHTMLBackgroundImage(const wxBitmap& bmpBg) | |
1564 | { | |
1565 | SetBackgroundImage(bmpBg); | |
1566 | } | |
5526e819 | 1567 | |
bc55e31b VS |
1568 | void wxHtmlWindow::SetHTMLStatusText(const wxString& text) |
1569 | { | |
1570 | #if wxUSE_STATUSBAR | |
1571 | if (m_RelatedStatusBar != -1) | |
1572 | m_RelatedFrame->SetStatusText(text, m_RelatedStatusBar); | |
80d99525 WS |
1573 | #else |
1574 | wxUnusedVar(text); | |
bc55e31b VS |
1575 | #endif // wxUSE_STATUSBAR |
1576 | } | |
5526e819 | 1577 | |
88a1b648 VS |
1578 | /*static*/ |
1579 | wxCursor wxHtmlWindow::GetDefaultHTMLCursor(HTMLCursor type) | |
1580 | { | |
1581 | switch (type) | |
1582 | { | |
1583 | case HTMLCursor_Link: | |
1584 | if ( !ms_cursorLink ) | |
1585 | ms_cursorLink = new wxCursor(wxCURSOR_HAND); | |
1586 | return *ms_cursorLink; | |
1587 | ||
1588 | case HTMLCursor_Text: | |
1589 | if ( !ms_cursorText ) | |
1590 | ms_cursorText = new wxCursor(wxCURSOR_IBEAM); | |
1591 | return *ms_cursorText; | |
1592 | ||
1593 | case HTMLCursor_Default: | |
1594 | default: | |
1595 | return *wxSTANDARD_CURSOR; | |
1596 | } | |
1597 | } | |
1598 | ||
1599 | wxCursor wxHtmlWindow::GetHTMLCursor(HTMLCursor type) const | |
1600 | { | |
1601 | return GetDefaultHTMLCursor(type); | |
1602 | } | |
1603 | ||
5526e819 | 1604 | |
bc55e31b VS |
1605 | //----------------------------------------------------------------------------- |
1606 | // wxHtmlWinModule | |
1607 | //----------------------------------------------------------------------------- | |
5526e819 | 1608 | |
a76015e6 VS |
1609 | // A module to allow initialization/cleanup |
1610 | // without calling these functions from app.cpp or from | |
1611 | // the user's application. | |
1612 | ||
1613 | class wxHtmlWinModule: public wxModule | |
1614 | { | |
1615 | DECLARE_DYNAMIC_CLASS(wxHtmlWinModule) | |
1616 | public: | |
1617 | wxHtmlWinModule() : wxModule() {} | |
d1da8872 | 1618 | bool OnInit() { return true; } |
a76015e6 VS |
1619 | void OnExit() { wxHtmlWindow::CleanUpStatics(); } |
1620 | }; | |
1621 | ||
1622 | IMPLEMENT_DYNAMIC_CLASS(wxHtmlWinModule, wxModule) | |
1623 | ||
5526e819 | 1624 | |
0cecad31 VS |
1625 | // This hack forces the linker to always link in m_* files |
1626 | // (wxHTML doesn't work without handlers from these files) | |
1627 | #include "wx/html/forcelnk.h" | |
1628 | FORCE_WXHTML_MODULES() | |
5526e819 | 1629 | |
d659d703 | 1630 | #endif // wxUSE_HTML |