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