]> git.saurik.com Git - wxWidgets.git/blob - src/html/m_links.cpp
Add handling of http errors to wxWebViewIE. Tidy up existing large case statement.
[wxWidgets.git] / src / html / m_links.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/html/m_links.cpp
3 // Purpose: wxHtml module for links & anchors
4 // Author: Vaclav Slavik
5 // RCS-ID: $Id$
6 // Copyright: (c) 1999 Vaclav Slavik
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #include "wx/wxprec.h"
11
12 #ifdef __BORLANDC__
13 #pragma hdrstop
14 #endif
15
16 #if wxUSE_HTML && wxUSE_STREAMS
17
18 #ifndef WX_PRECOMP
19 #endif
20
21 #include "wx/html/forcelnk.h"
22 #include "wx/html/m_templ.h"
23 #include "wx/html/styleparams.h"
24
25
26 FORCE_LINK_ME(m_links)
27
28
29 class wxHtmlAnchorCell : public wxHtmlCell
30 {
31 private:
32 wxString m_AnchorName;
33
34 public:
35 wxHtmlAnchorCell(const wxString& name) : wxHtmlCell()
36 { m_AnchorName = name; }
37 void Draw(wxDC& WXUNUSED(dc),
38 int WXUNUSED(x), int WXUNUSED(y),
39 int WXUNUSED(view_y1), int WXUNUSED(view_y2),
40 wxHtmlRenderingInfo& WXUNUSED(info)) {}
41
42 virtual const wxHtmlCell* Find(int condition, const void* param) const
43 {
44 if ((condition == wxHTML_COND_ISANCHOR) &&
45 (m_AnchorName == (*((const wxString*)param))))
46 {
47 return this;
48 }
49 else
50 {
51 return wxHtmlCell::Find(condition, param);
52 }
53 }
54
55 wxDECLARE_NO_COPY_CLASS(wxHtmlAnchorCell);
56 };
57
58
59
60 TAG_HANDLER_BEGIN(A, "A")
61 TAG_HANDLER_CONSTR(A) { }
62
63 TAG_HANDLER_PROC(tag)
64 {
65 if (tag.HasParam( wxT("NAME") ))
66 {
67 m_WParser->GetContainer()->InsertCell(new wxHtmlAnchorCell(tag.GetParam( wxT("NAME") )));
68 }
69
70 if (tag.HasParam( wxT("HREF") ))
71 {
72 wxHtmlLinkInfo oldlnk = m_WParser->GetLink();
73 wxColour oldclr = m_WParser->GetActualColor();
74 wxColour oldbackclr = m_WParser->GetActualBackgroundColor();
75 int oldbackmode = m_WParser->GetActualBackgroundMode();
76 int oldsize = m_WParser->GetFontSize();
77 int oldbold = m_WParser->GetFontBold();
78 int olditalic = m_WParser->GetFontItalic();
79 int oldund = m_WParser->GetFontUnderlined();
80 wxString oldfontface = m_WParser->GetFontFace();
81 wxString name(tag.GetParam( wxT("HREF") )), target;
82
83 if (tag.HasParam( wxT("TARGET") )) target = tag.GetParam( wxT("TARGET") );
84
85 // set default styles, might get overridden by ApplyStyle
86 m_WParser->SetActualColor(m_WParser->GetLinkColor());
87 m_WParser->GetContainer()->InsertCell(new wxHtmlColourCell(m_WParser->GetLinkColor()));
88 m_WParser->SetFontUnderlined(true);
89 m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
90 m_WParser->SetLink(wxHtmlLinkInfo(name, target));
91
92 // Load any style parameters
93 wxHtmlStyleParams styleParams(tag);
94 ApplyStyle(styleParams);
95
96 ParseInner(tag);
97
98 m_WParser->SetLink(oldlnk);
99 m_WParser->SetFontSize(oldsize);
100 m_WParser->SetFontBold(oldbold);
101 m_WParser->SetFontFace(oldfontface);
102 m_WParser->SetFontItalic(olditalic);
103 m_WParser->SetFontUnderlined(oldund);
104 m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
105 m_WParser->SetActualColor(oldclr);
106 m_WParser->GetContainer()->InsertCell(new wxHtmlColourCell(oldclr));
107
108 if (oldbackmode != m_WParser->GetActualBackgroundMode() ||
109 oldbackclr != m_WParser->GetActualBackgroundColor())
110 {
111 m_WParser->SetActualBackgroundMode(oldbackmode);
112 m_WParser->SetActualBackgroundColor(oldbackclr);
113 m_WParser->GetContainer()->InsertCell(
114 new wxHtmlColourCell(oldbackclr, oldbackmode == wxTRANSPARENT ? wxHTML_CLR_TRANSPARENT_BACKGROUND : wxHTML_CLR_BACKGROUND));
115 }
116
117 return true;
118 }
119 else return false;
120 }
121
122 TAG_HANDLER_END(A)
123
124
125
126 TAGS_MODULE_BEGIN(Links)
127
128 TAGS_MODULE_ADD(A)
129
130 TAGS_MODULE_END(Links)
131
132
133 #endif