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