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