]>
Commit | Line | Data |
---|---|---|
5526e819 VS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: htmlcell.cpp | |
3 | // Purpose: wxHtmlCell - basic element of HTML output | |
4 | // Author: Vaclav Slavik | |
69941f05 | 5 | // RCS-ID: $Id$ |
5526e819 VS |
6 | // Copyright: (c) 1999 Vaclav Slavik |
7 | // Licence: wxWindows Licence | |
8 | ///////////////////////////////////////////////////////////////////////////// | |
9 | ||
5526e819 | 10 | #ifdef __GNUG__ |
69941f05 | 11 | #pragma implementation |
5526e819 VS |
12 | #endif |
13 | ||
4dcaf11a | 14 | #include "wx/wxprec.h" |
5526e819 | 15 | |
314260fb | 16 | #include "wx/defs.h" |
f6bcfd97 BP |
17 | |
18 | #if wxUSE_HTML && wxUSE_STREAMS | |
5526e819 VS |
19 | |
20 | #ifdef __BORDLANDC__ | |
21 | #pragma hdrstop | |
22 | #endif | |
23 | ||
24 | #ifndef WXPRECOMP | |
4dcaf11a | 25 | #include "wx/wx.h" |
5526e819 VS |
26 | #endif |
27 | ||
4dcaf11a RR |
28 | #include "wx/html/htmlcell.h" |
29 | #include "wx/html/htmlwin.h" | |
5526e819 VS |
30 | #include <stdlib.h> |
31 | ||
32 | ||
5526e819 VS |
33 | //----------------------------------------------------------------------------- |
34 | // wxHtmlCell | |
35 | //----------------------------------------------------------------------------- | |
36 | ||
846914d1 VS |
37 | wxHtmlCell::wxHtmlCell() : wxObject() |
38 | { | |
39 | m_Next = NULL; | |
40 | m_Parent = NULL; | |
41 | m_Width = m_Height = m_Descent = 0; | |
42 | m_CanLiveOnPagebreak = TRUE; | |
43 | m_Link = NULL; | |
44 | } | |
45 | ||
46 | wxHtmlCell::~wxHtmlCell() | |
47 | { | |
48 | if (m_Link) delete m_Link; | |
49 | if (m_Next) delete m_Next; | |
50 | } | |
51 | ||
5526e819 | 52 | |
0b2dadd3 VS |
53 | void wxHtmlCell::OnMouseClick(wxWindow *parent, int x, int y, |
54 | const wxMouseEvent& event) | |
5526e819 | 55 | { |
846914d1 VS |
56 | wxHtmlLinkInfo *lnk = GetLink(x, y); |
57 | if (lnk != NULL) | |
0b2dadd3 VS |
58 | { |
59 | wxHtmlLinkInfo lnk2(*lnk); | |
60 | lnk2.SetEvent(&event); | |
9bc8fded | 61 | lnk2.SetHtmlCell(this); |
4f9297b0 | 62 | ((wxHtmlWindow*)parent)->OnLinkClicked(lnk2); |
5526e819 | 63 | // note : this overcasting is legal because parent is *always* wxHtmlWindow |
0b2dadd3 | 64 | } |
5526e819 VS |
65 | } |
66 | ||
67 | ||
68 | ||
5660c520 | 69 | bool wxHtmlCell::AdjustPagebreak(int *pagebreak) const |
db98870d | 70 | { |
db98870d | 71 | if ((!m_CanLiveOnPagebreak) && |
4f9297b0 VS |
72 | m_PosY < *pagebreak && m_PosY + m_Height > *pagebreak) |
73 | { | |
db98870d | 74 | *pagebreak = m_PosY; |
4f9297b0 | 75 | if (m_Next != NULL) m_Next->AdjustPagebreak(pagebreak); |
db98870d VS |
76 | return TRUE; |
77 | } | |
78 | ||
4f9297b0 VS |
79 | else |
80 | { | |
81 | if (m_Next != NULL) return m_Next->AdjustPagebreak(pagebreak); | |
db98870d VS |
82 | else return FALSE; |
83 | } | |
84 | } | |
85 | ||
86 | ||
87 | ||
846914d1 VS |
88 | void wxHtmlCell::SetLink(const wxHtmlLinkInfo& link) |
89 | { | |
90 | if (m_Link) delete m_Link; | |
af1ed0c1 VS |
91 | m_Link = NULL; |
92 | if (link.GetHref() != wxEmptyString) | |
93 | m_Link = new wxHtmlLinkInfo(link); | |
846914d1 VS |
94 | } |
95 | ||
96 | ||
db98870d | 97 | |
721ab905 VS |
98 | void wxHtmlCell::Layout(int w) |
99 | { | |
100 | SetPos(0, 0); | |
4f9297b0 | 101 | if (m_Next) m_Next->Layout(w); |
721ab905 VS |
102 | } |
103 | ||
104 | ||
105 | void wxHtmlCell::Draw(wxDC& dc, int x, int y, int view_y1, int view_y2) | |
106 | { | |
4f9297b0 | 107 | if (m_Next) m_Next->Draw(dc, x, y, view_y1, view_y2); |
721ab905 VS |
108 | } |
109 | ||
110 | ||
111 | ||
112 | void wxHtmlCell::DrawInvisible(wxDC& dc, int x, int y) | |
113 | { | |
4f9297b0 | 114 | if (m_Next) m_Next->DrawInvisible(dc, x, y); |
721ab905 VS |
115 | } |
116 | ||
117 | ||
118 | ||
119 | const wxHtmlCell* wxHtmlCell::Find(int condition, const void* param) const | |
120 | { | |
4f9297b0 | 121 | if (m_Next) return m_Next->Find(condition, param); |
721ab905 VS |
122 | else return NULL; |
123 | } | |
124 | ||
125 | ||
126 | ||
5526e819 VS |
127 | //----------------------------------------------------------------------------- |
128 | // wxHtmlWordCell | |
129 | //----------------------------------------------------------------------------- | |
130 | ||
131 | wxHtmlWordCell::wxHtmlWordCell(const wxString& word, wxDC& dc) : wxHtmlCell() | |
132 | { | |
133 | m_Word = word; | |
c181287c VS |
134 | |
135 | if (m_Word.Find(wxT('&')) != -1) | |
136 | { | |
5660c520 | 137 | #define ESCSEQ(escape, subst) \ |
0bbfe845 JS |
138 | { _T("&") _T(escape) _T(";"), _T("&") _T(escape) _T(" "), _T("&") _T(escape), _T(subst) } |
139 | static wxChar* substitutions[][4] = | |
c181287c | 140 | { |
5660c520 | 141 | ESCSEQ("quot", "\""), |
0bbfe845 | 142 | ESCSEQ("#34", "\""), |
5660c520 | 143 | ESCSEQ("lt", "<"), |
0bbfe845 | 144 | ESCSEQ("#60", "<"), |
5660c520 | 145 | ESCSEQ("gt", ">"), |
0bbfe845 JS |
146 | ESCSEQ("#62", ">"), |
147 | ||
148 | ESCSEQ("#94", "^"), /* ^ */ | |
5660c520 VS |
149 | |
150 | ESCSEQ("nbsp", " "), | |
0bbfe845 | 151 | ESCSEQ("#32", " "), |
5660c520 | 152 | ESCSEQ("iexcl", "!"), |
0bbfe845 JS |
153 | ESCSEQ("#33", "!"), |
154 |