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