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