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