]>
Commit | Line | Data |
---|---|---|
5526e819 | 1 | ///////////////////////////////////////////////////////////////////////////// |
93763ad5 | 2 | // Name: src/html/m_links.cpp |
5526e819 VS |
3 | // Purpose: wxHtml module for links & anchors |
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 | ||
314260fb | 10 | #include "wx/wxprec.h" |
3364ab79 | 11 | |
2b5f62a0 | 12 | #ifdef __BORLANDC__ |
93763ad5 | 13 | #pragma hdrstop |
3364ab79 RS |
14 | #endif |
15 | ||
93763ad5 WS |
16 | #if wxUSE_HTML && wxUSE_STREAMS |
17 | ||
b4f4d3dd | 18 | #ifndef WX_PRECOMP |
3364ab79 RS |
19 | #endif |
20 | ||
69941f05 VS |
21 | #include "wx/html/forcelnk.h" |
22 | #include "wx/html/m_templ.h" | |
0d7acfb9 | 23 | #include "wx/html/styleparams.h" |
f42b1601 | 24 | |
5526e819 | 25 | |
c88293a4 | 26 | FORCE_LINK_ME(m_links) |
5526e819 VS |
27 | |
28 | ||
29 | class wxHtmlAnchorCell : public wxHtmlCell | |
30 | { | |
36c4ff4d VS |
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), | |
e3ac6ee1 | 40 | wxHtmlRenderingInfo& WXUNUSED(info)) {} |
36c4ff4d VS |
41 | |
42 | virtual const wxHtmlCell* Find(int condition, const void* param) const | |
43 | { | |
d1da8872 | 44 | if ((condition == wxHTML_COND_ISANCHOR) && |
36c4ff4d VS |
45 | (m_AnchorName == (*((const wxString*)param)))) |
46 | { | |
47 | return this; | |
48 | } | |
49 | else | |
5526e819 | 50 | { |
36c4ff4d | 51 | return wxHtmlCell::Find(condition, param); |
f42b1601 | 52 | } |
36c4ff4d | 53 | } |
fc7a2a60 | 54 | |
c0c133e1 | 55 | wxDECLARE_NO_COPY_CLASS(wxHtmlAnchorCell); |
5526e819 VS |
56 | }; |
57 | ||
58 | ||
59 | ||
60 | TAG_HANDLER_BEGIN(A, "A") | |
fc7a2a60 | 61 | TAG_HANDLER_CONSTR(A) { } |
5526e819 VS |
62 | |
63 | TAG_HANDLER_PROC(tag) | |
64 | { | |
2b5f62a0 | 65 | if (tag.HasParam( wxT("NAME") )) |
04dbb646 | 66 | { |
2b5f62a0 | 67 | m_WParser->GetContainer()->InsertCell(new wxHtmlAnchorCell(tag.GetParam( wxT("NAME") ))); |
5526e819 | 68 | } |
f42b1601 | 69 | |
2b5f62a0 | 70 | if (tag.HasParam( wxT("HREF") )) |
04dbb646 | 71 | { |
4f9297b0 VS |
72 | wxHtmlLinkInfo oldlnk = m_WParser->GetLink(); |
73 | wxColour oldclr = m_WParser->GetActualColor(); | |
0d7acfb9 VZ |
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(); | |
4f9297b0 | 79 | int oldund = m_WParser->GetFontUnderlined(); |
0d7acfb9 | 80 | wxString oldfontface = m_WParser->GetFontFace(); |
2b5f62a0 | 81 | wxString name(tag.GetParam( wxT("HREF") )), target; |
5526e819 | 82 | |
2b5f62a0 | 83 | if (tag.HasParam( wxT("TARGET") )) target = tag.GetParam( wxT("TARGET") ); |
0d7acfb9 VZ |
84 | |
85 | // set default styles, might get overridden by ApplyStyle | |
4f9297b0 VS |
86 | m_WParser->SetActualColor(m_WParser->GetLinkColor()); |
87 | m_WParser->GetContainer()->InsertCell(new wxHtmlColourCell(m_WParser->GetLinkColor())); | |
d1da8872 | 88 | m_WParser->SetFontUnderlined(true); |
4f9297b0 VS |
89 | m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont())); |
90 | m_WParser->SetLink(wxHtmlLinkInfo(name, target)); | |
5526e819 | 91 | |
0d7acfb9 VZ |
92 | // Load any style parameters |
93 | wxHtmlStyleParams styleParams(tag); | |
94 | ApplyStyle(styleParams); | |
95 | ||
5526e819 VS |
96 | ParseInner(tag); |
97 | ||
4f9297b0 | 98 | m_WParser->SetLink(oldlnk); |
0d7acfb9 VZ |
99 | m_WParser->SetFontSize(oldsize); |
100 | m_WParser->SetFontBold(oldbold); | |
101 | m_WParser->SetFontFace(oldfontface); | |
102 | m_WParser->SetFontItalic(olditalic); | |
4f9297b0 VS |
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)); | |
5526e819 | 107 | |
0d7acfb9 VZ |
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 | ||
d1da8872 | 117 | return true; |
5526e819 | 118 | } |
d1da8872 | 119 | else return false; |
5526e819 VS |
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 |