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