]>
Commit | Line | Data |
---|---|---|
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 VS |
6 | // Copyright: (c) 1999 Vaclav Slavik |
7 | // Licence: wxWindows Licence | |
8 | ///////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | ||
11 | #ifdef __GNUG__ | |
12 | #pragma implementation | |
13 | #endif | |
14 | ||
3096bd2f | 15 | #include "wx/wxprec.h" |
5526e819 VS |
16 | |
17 | #include "wx/defs.h" | |
f6bcfd97 | 18 | #if wxUSE_HTML && wxUSE_STREAMS |
5526e819 VS |
19 | |
20 | #ifdef __BORDLANDC__ | |
21 | #pragma hdrstop | |
22 | #endif | |
23 | ||
24 | #ifndef WXPRECOMP | |
3096bd2f | 25 | #include "wx/wx.h" |
5526e819 VS |
26 | #endif |
27 | ||
69941f05 | 28 | #include "wx/html/htmlwin.h" |
69941f05 | 29 | #include "wx/html/forcelnk.h" |
f3c82859 | 30 | #include "wx/log.h" |
5526e819 | 31 | |
5526e819 VS |
32 | |
33 | //----------------------------------------------------------------------------- | |
34 | // wxHtmlWindow | |
35 | //----------------------------------------------------------------------------- | |
36 | ||
37 | ||
38 | ||
3096bd2f | 39 | #include "wx/arrimpl.cpp" |
5526e819 VS |
40 | WX_DEFINE_OBJARRAY(HtmlHistoryArray) |
41 | ||
42 | ||
269e8200 | 43 | wxHtmlWindow::wxHtmlWindow(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, |
f6bcfd97 | 44 | long style, const wxString& name) : wxScrolledWindow(parent, id, pos, size, style | wxVSCROLL | wxHSCROLL, name) |
5526e819 VS |
45 | { |
46 | m_tmpMouseMoved = FALSE; | |
846914d1 | 47 | m_tmpLastLink = NULL; |
89de9af3 | 48 | m_tmpCanDrawLocks = 0; |
5526e819 VS |
49 | m_FS = new wxFileSystem(); |
50 | m_RelatedStatusBar = -1; | |
51 | m_RelatedFrame = NULL; | |
52 | m_TitleFormat = "%s"; | |
d5db80c2 | 53 | m_OpenedPage = m_OpenedAnchor = m_OpenedPageTitle = wxEmptyString; |
5526e819 VS |
54 | m_Cell = NULL; |
55 | m_Parser = new wxHtmlWinParser(this); | |
4f9297b0 | 56 | m_Parser->SetFS(m_FS); |
5526e819 VS |
57 | SetBorders(10); |
58 | m_HistoryPos = -1; | |
59 | m_HistoryOn = TRUE; | |
a547ebff | 60 | m_Style = style; |
4f9297b0 | 61 | SetPage(wxT("<html><body></body></html>")); |
5526e819 VS |
62 | } |
63 | ||
64 | ||
65 | ||
66 | wxHtmlWindow::~wxHtmlWindow() | |
67 | { | |
68 | HistoryClear(); | |
69 | ||
70 | if (m_Cell) delete m_Cell; | |
71 | ||
5526e819 VS |
72 | delete m_Parser; |
73 | delete m_FS; | |
74 | } | |
75 | ||
76 | ||
77 | ||
78 | void wxHtmlWindow::SetRelatedFrame(wxFrame* frame, const wxString& format) | |
79 | { | |
80 | m_RelatedFrame = frame; | |
81 | m_TitleFormat = format; | |
82 | } | |
83 | ||
84 | ||
85 | ||
86 | void wxHtmlWindow::SetRelatedStatusBar(int bar) | |
87 | { | |
88 | m_RelatedStatusBar = bar; | |
89 | } | |
269e8200 RD |
90 | |
91 | ||
92 | ||
8eb2940f | 93 | void wxHtmlWindow::SetFonts(wxString normal_face, wxString fixed_face, const int *sizes) |
5526e819 | 94 | { |
d5db80c2 VS |
95 | wxString op = m_OpenedPage; |
96 | ||
4f9297b0 | 97 | m_Parser->SetFonts(normal_face, fixed_face, sizes); |
fb5700fe | 98 | SetPage(wxT("<html><body></body></html>")); // fonts changed => contents invalid |
d5db80c2 | 99 | if (!op.IsEmpty()) LoadPage(op); |
5526e819 VS |
100 | } |
101 | ||
102 | ||
103 | ||
104 | bool wxHtmlWindow::SetPage(const wxString& source) | |
105 | { | |
106 | wxClientDC *dc = new wxClientDC(this); | |
107 | ||
4f9297b0 | 108 | dc->SetMapMode(wxMM_TEXT); |
5526e819 | 109 | SetBackgroundColour(wxColour(0xFF, 0xFF, 0xFF)); |
d5db80c2 | 110 | m_OpenedPage = m_OpenedAnchor = m_OpenedPageTitle = wxEmptyString; |
4f9297b0 VS |
111 | m_Parser->SetDC(dc); |
112 | if (m_Cell) | |
113 | { | |
89de9af3 VS |
114 | delete m_Cell; |
115 | m_Cell = NULL; | |
f61815af | 116 | } |
4f9297b0 | 117 | m_Cell = (wxHtmlContainerCell*) m_Parser->Parse(source); |
5526e819 | 118 | delete dc; |
4f9297b0 VS |
119 | m_Cell->SetIndent(m_Borders, wxHTML_INDENT_ALL, wxHTML_UNITS_PIXELS); |
120 | m_Cell->SetAlignHor(wxHTML_ALIGN_CENTER); | |
5526e819 | 121 | CreateLayout(); |
89de9af3 | 122 | if (m_tmpCanDrawLocks == 0) Refresh(); |
5526e819 VS |
123 | return TRUE; |
124 | } | |
125 | ||
126 | ||
127 | bool wxHtmlWindow::LoadPage(const wxString& location) | |
128 | { | |
129 | wxFSFile *f; | |
130 | bool rt_val; | |
fc7dfaf8 VS |
131 | bool needs_refresh = FALSE; |
132 | ||
169ee06c | 133 | SetCursor(*wxHOURGLASS_CURSOR); |
fc7dfaf8 | 134 | wxYield(); Refresh(FALSE); |
5526e819 | 135 | |
89de9af3 | 136 | m_tmpCanDrawLocks++; |
4f9297b0 VS |
137 | if (m_HistoryOn && (m_HistoryPos != -1)) // store scroll position into history item |
138 | { | |
5526e819 VS |
139 | int x, y; |
140 | ViewStart(&x, &y); | |
141 | m_History[m_HistoryPos].SetPos(y); | |
142 | } | |
143 | ||
4f9297b0 VS |
144 | if (location[0] == wxT('#')) // local anchor |
145 | { | |
5526e819 | 146 | wxString anch = location.Mid(1) /*1 to end*/; |
89de9af3 | 147 | m_tmpCanDrawLocks--; |
5526e819 | 148 | rt_val = ScrollToAnchor(anch); |
fc7dfaf8 VS |
149 | m_tmpCanDrawLocks++; |
150 | } | |
4f9297b0 VS |
151 | else if (location.Find(wxT('#')) != wxNOT_FOUND && location.BeforeFirst(wxT('#')) == m_OpenedPage) |
152 | { | |
fc7dfaf8 VS |
153 | wxString anch = location.AfterFirst(wxT('#')); |
154 | m_tmpCanDrawLocks--; | |
155 | rt_val = ScrollToAnchor(anch); | |
156 | m_tmpCanDrawLocks++; | |
157 | } | |
158 | else if (location.Find(wxT('#')) != wxNOT_FOUND && | |
4f9297b0 VS |
159 | (m_FS->GetPath() + location.BeforeFirst(wxT('#'))) == m_OpenedPage) |
160 | { | |
fc7dfaf8 VS |
161 | wxString anch = location.AfterFirst(wxT('#')); |
162 | m_tmpCanDrawLocks--; | |
163 | rt_val = ScrollToAnchor(anch); | |
164 | m_tmpCanDrawLocks++; | |
5526e819 VS |
165 | } |
166 | ||
4f9297b0 VS |
167 | else |
168 | { | |
fc7dfaf8 | 169 | needs_refresh = TRUE; |
5526e819 | 170 | // load&display it: |
4f9297b0 VS |
171 | if (m_RelatedStatusBar != -1) |
172 | { | |
173 | m_RelatedFrame->SetStatusText(_("Connecting..."), m_RelatedStatusBar); | |
fc7dfaf8 | 174 | Refresh(FALSE); |
5526e819 VS |
175 | } |
176 | ||
4f9297b0 | 177 | f = m_FS->OpenFile(location); |
fc7dfaf8 | 178 | |
4f9297b0 VS |
179 | if (f == NULL) |
180 | { | |
5526e819 VS |
181 | wxString err; |
182 | ||
f6bcfd97 | 183 | wxLogError(_("Unable to open requested HTML document: %s"), location.c_str()); |
89de9af3 | 184 | m_tmpCanDrawLocks--; |
169ee06c VS |
185 | |
186 | SetCursor(*wxSTANDARD_CURSOR); | |
5526e819 VS |
187 | return FALSE; |
188 | } | |
189 | ||
4f9297b0 VS |
190 | else |
191 | { | |
5526e819 VS |
192 | wxNode *node; |
193 | wxString src = wxEmptyString; | |
194 | ||
4f9297b0 VS |
195 | if (m_RelatedStatusBar != -1) |
196 | { | |
5526e819 | 197 | wxString msg = _("Loading : ") + location; |
4f9297b0 | 198 | m_RelatedFrame->SetStatusText(msg, m_RelatedStatusBar); |
fc7dfaf8 | 199 | Refresh(FALSE); |
5526e819 VS |
200 | } |
201 | ||
202 | node = m_Filters.GetFirst(); | |
4f9297b0 VS |
203 | while (node) |
204 | { | |
205 | wxHtmlFilter *h = (wxHtmlFilter*) node->GetData(); | |
206 | if (h->CanRead(*f)) | |
207 | { | |
208 | src = h->ReadFile(*f); | |
5526e819 VS |
209 | break; |
210 | } | |
4f9297b0 | 211 | node = node->GetNext(); |
5526e819 | 212 | } |
4f9297b0 VS |
213 | if (src == wxEmptyString) |
214 | { | |
89de9af3 | 215 | if (m_DefaultFilter == NULL) m_DefaultFilter = GetDefaultFilter(); |
4f9297b0 | 216 | src = m_DefaultFilter->ReadFile(*f); |
89de9af3 | 217 | } |
5526e819 | 218 | |
4f9297b0 | 219 | m_FS->ChangePathTo(f->GetLocation()); |
5526e819 | 220 | rt_val = SetPage(src); |
4f9297b0 VS |
221 | m_OpenedPage = f->GetLocation(); |
222 | if (f->GetAnchor() != wxEmptyString) | |
223 | { | |
fc7dfaf8 | 224 | wxYield(); |
4f9297b0 | 225 | ScrollToAnchor(f->GetAnchor()); |
5526e819 VS |
226 | } |
227 | ||
228 | delete f; | |
229 | ||
4f9297b0 | 230 | if (m_RelatedStatusBar != -1) m_RelatedFrame->SetStatusText(_("Done"), m_RelatedStatusBar); |
5526e819 VS |
231 | } |
232 | } | |
233 | ||
4f9297b0 VS |
234 | if (m_HistoryOn) // add this page to history there: |
235 | { | |
5526e819 VS |
236 | int c = m_History.GetCount() - (m_HistoryPos + 1); |
237 | ||
238 | m_HistoryPos++; | |
239 | for (int i = 0; i < c; i++) | |
240 | m_History.Remove(m_HistoryPos); | |
241 | m_History.Add(new HtmlHistoryItem(m_OpenedPage, m_OpenedAnchor)); | |
242 | } | |
243 | ||
096824d7 VS |
244 | if (m_OpenedPageTitle == wxEmptyString) |
245 | OnSetTitle(wxFileNameFromPath(m_OpenedPage)); | |
169ee06c | 246 | SetCursor(*wxSTANDARD_CURSOR); |
fc7dfaf8 | 247 | |
4f9297b0 VS |
248 | if (needs_refresh) |
249 | { | |
fc7dfaf8 VS |
250 | wxYield(); |
251 | m_tmpCanDrawLocks--; | |
252 | Refresh(); | |
253 | } | |
254 | else | |
255 | m_tmpCanDrawLocks--; | |
256 | ||
5526e819 VS |
257 | return rt_val; |
258 | } | |
259 | ||
260 | ||
261 | ||
262 | bool wxHtmlWindow::ScrollToAnchor(const wxString& anchor) | |
263 | { | |
4f9297b0 | 264 | const wxHtmlCell *c = m_Cell->Find(wxHTML_COND_ISANCHOR, &anchor); |
f3c82859 VS |
265 | if (!c) |
266 | { | |
f6bcfd97 | 267 | wxLogWarning(_("HTML anchor %s does not exist."), anchor.c_str()); |
f3c82859 VS |
268 | return FALSE; |
269 | } | |
4f9297b0 VS |
270 | else |
271 | { | |
5526e819 | 272 | int y; |
269e8200 | 273 | |
4f9297b0 | 274 | for (y = 0; c != NULL; c = c->GetParent()) y += c->GetPosY(); |
efba2b89 | 275 | Scroll(-1, y / wxHTML_SCROLL_STEP); |
5526e819 VS |
276 | m_OpenedAnchor = anchor; |
277 | return TRUE; | |
278 | } | |
279 | } | |
280 | ||
281 | ||
d5db80c2 | 282 | void wxHtmlWindow::OnSetTitle(const wxString& title) |
5526e819 | 283 | { |
4f9297b0 VS |
284 | if (m_RelatedFrame) |
285 | { | |
5526e819 VS |
286 | wxString tit; |
287 | tit.Printf(m_TitleFormat, title.c_str()); | |
4f9297b0 | 288 | m_RelatedFrame->SetTitle(tit); |
5526e819 | 289 | } |
d5db80c2 | 290 | m_OpenedPageTitle = title; |
5526e819 VS |
291 | } |
292 | ||
293 | ||
294 | ||
295 | ||
296 | ||
297 | void wxHtmlWindow::CreateLayout() | |
298 | { | |
299 | int ClientWidth, ClientHeight; | |
300 | ||
301 | if (!m_Cell) return; | |
a547ebff | 302 | |
4f9297b0 VS |
303 | if (m_Style & wxHW_SCROLLBAR_NEVER) |
304 | { | |
305 | SetScrollbars(wxHTML_SCROLL_STEP, 1, m_Cell->GetWidth() / wxHTML_SCROLL_STEP, 0); // always off | |
a547ebff | 306 | GetClientSize(&ClientWidth, &ClientHeight); |
4f9297b0 | 307 | m_Cell->Layout(ClientWidth); |
a547ebff VS |
308 | } |
309 | ||
310 | else { | |
311 | GetClientSize(&ClientWidth, &ClientHeight); | |
4f9297b0 VS |
312 | m_Cell->Layout(ClientWidth); |
313 | if (ClientHeight < m_Cell->GetHeight() + GetCharHeight()) | |
314 | { | |
f3bcfd9b VS |
315 | SetScrollbars( |
316 | wxHTML_SCROLL_STEP, wxHTML_SCROLL_STEP, | |
4f9297b0 VS |
317 | m_Cell->GetWidth() / wxHTML_SCROLL_STEP, |
318 | (m_Cell->GetHeight() + GetCharHeight()) / wxHTML_SCROLL_STEP | |
f3bcfd9b | 319 | /*cheat: top-level frag is always container*/); |
a547ebff | 320 | } |
4f9297b0 VS |
321 | else /* we fit into window, no need for scrollbars */ |
322 | { | |
323 | SetScrollbars(wxHTML_SCROLL_STEP, 1, m_Cell->GetWidth() / wxHTML_SCROLL_STEP, 0); // disable... | |
89de9af3 | 324 | GetClientSize(&ClientWidth, &ClientHeight); |
4f9297b0 | 325 | m_Cell->Layout(ClientWidth); // ...and relayout |
89de9af3 | 326 | } |
a547ebff | 327 | } |
5526e819 VS |
328 | } |
329 | ||
269e8200 | 330 | |
5526e819 VS |
331 | |
332 | void wxHtmlWindow::ReadCustomization(wxConfigBase *cfg, wxString path) | |
333 | { | |
334 | wxString oldpath; | |
335 | wxString tmp; | |
d5db80c2 VS |
336 | int p_fontsizes[7]; |
337 | wxString p_fff, p_ffn; | |
5526e819 | 338 | |
4f9297b0 VS |
339 | if (path != wxEmptyString) |
340 | { | |
341 | oldpath = cfg->GetPath(); | |
342 | cfg->SetPath(path); | |
5526e819 VS |
343 | } |
344 | ||
4f9297b0 VS |
345 | m_Borders = cfg->Read("wxHtmlWindow/Borders", m_Borders); |
346 | p_fff = cfg->Read("wxHtmlWindow/FontFaceFixed", m_Parser->m_FontFaceFixed); | |
347 | p_ffn = cfg->Read("wxHtmlWindow/FontFaceNormal", m_Parser->m_FontFaceNormal); | |
348 | for (int i = 0; i < 7; i++) | |
349 | { | |
66a77a74 | 350 | tmp.Printf(wxT("wxHtmlWindow/FontsSize%i"), i); |
4f9297b0 | 351 | p_fontsizes[i] = cfg->Read(tmp, m_Parser->m_FontsSizes[i]); |
5526e819 | 352 | } |
8eb2940f | 353 | SetFonts(p_ffn, p_fff, p_fontsizes); |
5526e819 VS |
354 | |
355 | if (path != wxEmptyString) | |
4f9297b0 | 356 | cfg->SetPath(oldpath); |
5526e819 VS |
357 | } |
358 | ||
359 | ||
360 | ||
361 | void wxHtmlWindow::WriteCustomization(wxConfigBase *cfg, wxString path) | |
362 | { | |
363 | wxString oldpath; | |
364 | wxString tmp; | |
365 | ||
4f9297b0 VS |
366 | if (path != wxEmptyString) |
367 | { | |
368 | oldpath = cfg->GetPath(); | |
369 | cfg->SetPath(path); | |
5526e819 VS |
370 | } |
371 | ||
4f9297b0 VS |
372 | cfg->Write("wxHtmlWindow/Borders", (long) m_Borders); |
373 | cfg->Write("wxHtmlWindow/FontFaceFixed", m_Parser->m_FontFaceFixed); | |
374 | cfg->Write("wxHtmlWindow/FontFaceNormal", m_Parser->m_FontFaceNormal); | |
375 | for (int i = 0; i < 7; i++) | |
376 | { | |
66a77a74 | 377 | tmp.Printf(wxT("wxHtmlWindow/FontsSize%i"), i); |
4f9297b0 | 378 | cfg->Write(tmp, (long) m_Parser->m_FontsSizes[i]); |
5526e819 VS |
379 | } |
380 | ||
381 | if (path != wxEmptyString) | |
4f9297b0 | 382 | cfg->SetPath(oldpath); |
5526e819 VS |
383 | } |
384 | ||
385 | ||
386 | ||
387 | bool wxHtmlWindow::HistoryBack() | |
388 | { | |
389 | wxString a, l; | |
390 | ||
391 | if (m_HistoryPos < 1) return FALSE; | |
392 | ||
bbda1088 VS |
393 | // store scroll position into history item: |
394 | int x, y; | |
395 | ViewStart(&x, &y); | |
396 | m_History[m_HistoryPos].SetPos(y); | |
397 | ||
398 | // go to previous position: | |
5526e819 VS |
399 | m_HistoryPos--; |
400 | ||
401 | l = m_History[m_HistoryPos].GetPage(); | |
402 | a = m_History[m_HistoryPos].GetAnchor(); | |
403 | m_HistoryOn = FALSE; | |
89de9af3 | 404 | m_tmpCanDrawLocks++; |
5526e819 | 405 | if (a == wxEmptyString) LoadPage(l); |
fc7dfaf8 | 406 | else LoadPage(l + wxT("#") + a); |
5526e819 | 407 | m_HistoryOn = TRUE; |
c88293a4 | 408 | wxYield(); |
89de9af3 | 409 | m_tmpCanDrawLocks--; |
c88293a4 | 410 | Scroll(0, m_History[m_HistoryPos].GetPos()); |
5526e819 VS |
411 | Refresh(); |
412 | return TRUE; | |
413 | } | |
414 | ||
1b113a81 VS |
415 | bool wxHtmlWindow::HistoryCanBack() |
416 | { | |
417 | if (m_HistoryPos < 1) return FALSE; | |
418 | return TRUE ; | |
419 | } | |
5526e819 VS |
420 | |
421 | ||
422 | bool wxHtmlWindow::HistoryForward() | |
423 | { | |
424 | wxString a, l; | |
425 | ||
426 | if (m_HistoryPos == -1) return FALSE; | |
427 | if (m_HistoryPos >= (int)m_History.GetCount() - 1)return FALSE; | |
428 | ||
429 | m_OpenedPage = wxEmptyString; // this will disable adding new entry into history in LoadPage() | |
430 | ||
431 | m_HistoryPos++; | |
432 | l = m_History[m_HistoryPos].GetPage(); | |
433 | a = m_History[m_HistoryPos].GetAnchor(); | |
434 | m_HistoryOn = FALSE; | |
89de9af3 | 435 | m_tmpCanDrawLocks++; |
5526e819 | 436 | if (a == wxEmptyString) LoadPage(l); |
fc7dfaf8 | 437 | else LoadPage(l + wxT("#") + a); |
5526e819 | 438 | m_HistoryOn = TRUE; |
c88293a4 | 439 | wxYield(); |
89de9af3 | 440 | m_tmpCanDrawLocks--; |
c88293a4 | 441 | Scroll(0, m_History[m_HistoryPos].GetPos()); |
5526e819 VS |
442 | Refresh(); |
443 | return TRUE; | |
444 | } | |
445 | ||
1b113a81 VS |
446 | bool wxHtmlWindow::HistoryCanForward() |
447 | { | |
448 | if (m_HistoryPos == -1) return FALSE; | |
449 | if (m_HistoryPos >= (int)m_History.GetCount() - 1)return FALSE; | |
450 | return TRUE ; | |
451 | } | |
5526e819 VS |
452 | |
453 | ||
454 | void wxHtmlWindow::HistoryClear() | |
455 | { | |
456 | m_History.Empty(); | |
457 | m_HistoryPos = -1; | |
458 | } | |
459 | ||
460 | ||
461 | ||
462 | wxList wxHtmlWindow::m_Filters; | |
a76015e6 | 463 | wxHtmlFilter *wxHtmlWindow::m_DefaultFilter = NULL; |
66806a0b VS |
464 | wxCursor *wxHtmlWindow::s_cur_hand = NULL; |
465 | wxCursor *wxHtmlWindow::s_cur_arrow = NULL; | |
a76015e6 VS |
466 | |
467 | void wxHtmlWindow::CleanUpStatics() | |
468 | { | |
469 | if (m_DefaultFilter) delete m_DefaultFilter; | |
470 | m_DefaultFilter = NULL; | |
269e8200 RD |
471 | m_Filters.DeleteContents(TRUE); |
472 | m_Filters.Clear(); | |
66806a0b VS |
473 | if (s_cur_hand) delete s_cur_hand; |
474 | if (s_cur_arrow) delete s_cur_arrow; | |
a76015e6 VS |
475 | } |
476 | ||
477 | ||
5526e819 VS |
478 | |
479 | void wxHtmlWindow::AddFilter(wxHtmlFilter *filter) | |
480 | { | |
5526e819 VS |
481 | m_Filters.Append(filter); |
482 | } | |
483 | ||
484 | ||
485 | ||
486 | ||
0b2dadd3 | 487 | void wxHtmlWindow::OnLinkClicked(const wxHtmlLinkInfo& link) |
5526e819 | 488 | { |
0b2dadd3 | 489 | LoadPage(link.GetHref()); |
5526e819 VS |
490 | } |
491 | ||
492 | ||
493 | ||
494 | void wxHtmlWindow::OnDraw(wxDC& dc) | |
495 | { | |
496 | int x, y; | |
497 | wxRegionIterator upd(GetUpdateRegion()); // get the update rect list | |
498 | int v_y, v_h; | |
499 | ||
89de9af3 | 500 | if (m_tmpCanDrawLocks > 0) return; |
fc7dfaf8 | 501 | |
5526e819 | 502 | dc.SetMapMode(wxMM_TEXT); |
2faa3a6b VS |
503 | #if 0 |
504 | /* VS - I don't think this is neccessary any longer | |
505 | MSC_VER 1200 means MSVC 6.0 and it works fine */ | |
5526e819 VS |
506 | #if defined(_MSC_VER) && (_MSC_VER == 1200) |
507 | ::SetMapMode((HDC)dc.GetHDC(), MM_TEXT); | |
2faa3a6b | 508 | #endif |
5526e819 VS |
509 | #endif |
510 | dc.SetBackgroundMode(wxTRANSPARENT); | |
511 | ViewStart(&x, &y); | |
512 | ||
4f9297b0 VS |
513 | while (upd) |
514 | { | |
5526e819 VS |
515 | v_y = upd.GetY(); |
516 | v_h = upd.GetH(); | |
4f9297b0 | 517 | if (m_Cell) m_Cell->Draw(dc, 0, 0, y * wxHTML_SCROLL_STEP + v_y, y * wxHTML_SCROLL_STEP + v_h + v_y); |
5526e819 VS |
518 | upd++; |
519 | } | |
520 | } | |
521 | ||
522 | ||
523 | ||
524 | ||
525 | void wxHtmlWindow::OnSize(wxSizeEvent& event) | |
526 | { | |
527 | wxScrolledWindow::OnSize(event); | |
528 | CreateLayout(); | |
f6bcfd97 | 529 | Refresh(); |
5526e819 VS |
530 | } |
531 | ||
532 | ||
5526e819 VS |
533 | void wxHtmlWindow::OnMouseEvent(wxMouseEvent& event) |
534 | { | |
535 | m_tmpMouseMoved = TRUE; | |
536 | ||
4f9297b0 VS |
537 | if (event.ButtonDown()) |
538 | { | |
5526e819 VS |
539 | int sx, sy; |
540 | wxPoint pos; | |
541 | wxString lnk; | |
542 | ||
efba2b89 | 543 | ViewStart(&sx, &sy); sx *= wxHTML_SCROLL_STEP; sy *= wxHTML_SCROLL_STEP; |
5526e819 VS |
544 | pos = event.GetPosition(); |
545 | ||
546 | if (m_Cell) | |
4f9297b0 | 547 | m_Cell->OnMouseClick(this, sx + pos.x, sy + pos.y, event); |
5526e819 VS |
548 | } |
549 | } | |
550 | ||
551 | ||
552 | ||
553 | void wxHtmlWindow::OnIdle(wxIdleEvent& event) | |
554 | { | |
66806a0b VS |
555 | if (s_cur_hand == NULL) |
556 | { | |
557 | s_cur_hand = new wxCursor(wxCURSOR_HAND); | |
558 | s_cur_arrow = new wxCursor(wxCURSOR_ARROW); | |
559 | } | |
5526e819 | 560 | |
4f9297b0 VS |
561 | if (m_tmpMouseMoved && (m_Cell != NULL)) |
562 | { | |
5526e819 VS |
563 | int sx, sy; |
564 | int x, y; | |
846914d1 | 565 | wxHtmlLinkInfo *lnk; |
5526e819 | 566 | |
efba2b89 | 567 | ViewStart(&sx, &sy); sx *= wxHTML_SCROLL_STEP; sy *= wxHTML_SCROLL_STEP; |
5526e819 VS |
568 | wxGetMousePosition(&x, &y); |
569 | ScreenToClient(&x, &y); | |
4f9297b0 | 570 | lnk = m_Cell->GetLink(sx + x, sy + y); |
5526e819 | 571 | |
4f9297b0 VS |
572 | if (lnk != m_tmpLastLink) |
573 | { | |
574 | if (lnk == NULL) | |
575 | { | |
66806a0b | 576 | SetCursor(*s_cur_arrow); |
4f9297b0 | 577 | if (m_RelatedStatusBar != -1) m_RelatedFrame->SetStatusText(wxEmptyString, m_RelatedStatusBar); |
622ea783 | 578 | } |
4f9297b0 VS |
579 | else |
580 | { | |
66806a0b | 581 | SetCursor(*s_cur_hand); |
846914d1 | 582 | if (m_RelatedStatusBar != -1) |
4f9297b0 | 583 | m_RelatedFrame->SetStatusText(lnk->GetHref(), m_RelatedStatusBar); |
622ea783 VS |
584 | } |
585 | m_tmpLastLink = lnk; | |
5526e819 VS |
586 | } |
587 | m_tmpMouseMoved = FALSE; | |
588 | } | |
589 | } | |
590 | ||
591 | ||
592 | ||
593 | ||
594 | IMPLEMENT_DYNAMIC_CLASS(wxHtmlWindow,wxScrolledWindow) | |
595 | ||
596 | BEGIN_EVENT_TABLE(wxHtmlWindow, wxScrolledWindow) | |
597 | EVT_SIZE(wxHtmlWindow::OnSize) | |
598 | EVT_LEFT_DOWN(wxHtmlWindow::OnMouseEvent) | |
599 | EVT_MOTION(wxHtmlWindow::OnMouseEvent) | |
600 | EVT_IDLE(wxHtmlWindow::OnIdle) | |
5526e819 VS |
601 | END_EVENT_TABLE() |
602 | ||
603 | ||
604 | ||
605 | ||
606 | ||
a76015e6 VS |
607 | // A module to allow initialization/cleanup |
608 | // without calling these functions from app.cpp or from | |
609 | // the user's application. | |
610 | ||
611 | class wxHtmlWinModule: public wxModule | |
612 | { | |
613 | DECLARE_DYNAMIC_CLASS(wxHtmlWinModule) | |
614 | public: | |
615 | wxHtmlWinModule() : wxModule() {} | |
616 | bool OnInit() { return TRUE; } | |
617 | void OnExit() { wxHtmlWindow::CleanUpStatics(); } | |
618 | }; | |
619 | ||
620 | IMPLEMENT_DYNAMIC_CLASS(wxHtmlWinModule, wxModule) | |
621 | ||
5526e819 VS |
622 | |
623 | ||
624 | ||
625 | ///// default mod handlers are forced there: | |
626 | ||
c88293a4 VS |
627 | FORCE_LINK(m_layout) |
628 | FORCE_LINK(m_fonts) | |
629 | FORCE_LINK(m_image) | |
630 | FORCE_LINK(m_list) | |
631 | FORCE_LINK(m_dflist) | |
632 | FORCE_LINK(m_pre) | |
633 | FORCE_LINK(m_hline) | |
634 | FORCE_LINK(m_links) | |
635 | FORCE_LINK(m_tables) | |
fa146dd7 | 636 | FORCE_LINK(m_meta) |
5526e819 VS |
637 | |
638 | ||
483ff5a5 | 639 | #endif |