]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: mod_layout.cpp | |
3 | // Purpose: wxHtml module for basic paragraphs/layout handling | |
4 | // Author: Vaclav Slavik | |
5 | // Copyright: (c) 1999 Vaclav Slavik | |
6 | // Licence: wxWindows Licence | |
7 | ///////////////////////////////////////////////////////////////////////////// | |
8 | #ifdef __GNUG__ | |
9 | #pragma implementation | |
10 | #endif | |
11 | ||
12 | #include <wx/wxprec.h> | |
13 | ||
14 | #if wxUSE_HTML | |
15 | #ifdef __BORDLANDC__ | |
16 | #pragma hdrstop | |
17 | #endif | |
18 | ||
19 | #ifndef WXPRECOMP | |
20 | #include <wx/wx.h> | |
21 | #endif | |
22 | ||
23 | ||
24 | #include <wx/html/forcelink.h> | |
25 | #include <wx/html/mod_templ.h> | |
26 | ||
27 | #include <wx/html/htmlwin.h> | |
28 | ||
29 | FORCE_LINK_ME(mod_layout) | |
30 | ||
31 | ||
32 | TAG_HANDLER_BEGIN(P, "P") | |
33 | ||
34 | TAG_HANDLER_PROC(tag) | |
35 | { | |
36 | if (m_WParser -> GetContainer() -> GetFirstCell() != NULL) { | |
37 | m_WParser -> CloseContainer(); | |
38 | m_WParser -> OpenContainer(); | |
39 | } | |
40 | m_WParser -> GetContainer() -> SetIndent(m_WParser -> GetCharHeight(), HTML_INDENT_TOP); | |
41 | m_WParser -> GetContainer() -> SetAlign(tag); | |
42 | return FALSE; | |
43 | } | |
44 | ||
45 | TAG_HANDLER_END(P) | |
46 | ||
47 | ||
48 | ||
49 | TAG_HANDLER_BEGIN(BR, "BR") | |
50 | ||
51 | TAG_HANDLER_PROC(tag) | |
52 | { | |
53 | int al = m_WParser -> GetContainer() -> GetAlignHor(); | |
54 | wxHtmlContainerCell *c; | |
55 | ||
56 | m_WParser -> CloseContainer(); | |
57 | c = m_WParser -> OpenContainer(); | |
58 | c -> SetAlignHor(al); | |
59 | c -> SetAlign(tag); | |
60 | return FALSE; | |
61 | } | |
62 | ||
63 | TAG_HANDLER_END(BR) | |
64 | ||
65 | ||
66 | ||
67 | TAG_HANDLER_BEGIN(CENTER, "CENTER") | |
68 | ||
69 | TAG_HANDLER_PROC(tag) | |
70 | { | |
71 | int old = m_WParser -> GetAlign(); | |
72 | wxHtmlContainerCell *c = m_WParser -> GetContainer(); | |
73 | ||
74 | m_WParser -> SetAlign(HTML_ALIGN_CENTER); | |
75 | if (c -> GetFirstCell() != NULL) { | |
76 | m_WParser -> CloseContainer(); | |
77 | m_WParser -> OpenContainer(); | |
78 | } | |
79 | else | |
80 | c -> SetAlignHor(HTML_ALIGN_CENTER); | |
81 | ||
82 | if (tag.HasEnding()) { | |
83 | ParseInner(tag); | |
84 | ||
85 | m_WParser -> SetAlign(old); | |
86 | if (c -> GetFirstCell() != NULL) { | |
87 | m_WParser -> CloseContainer(); | |
88 | m_WParser -> OpenContainer(); | |
89 | } | |
90 | else | |
91 | c -> SetAlignHor(old); | |
92 | ||
93 | return TRUE; | |
94 | } | |
95 | else return FALSE; | |
96 | } | |
97 | ||
98 | TAG_HANDLER_END(CENTER) | |
99 | ||
100 | ||
101 | ||
102 | TAG_HANDLER_BEGIN(DIV, "DIV") | |
103 | ||
104 | TAG_HANDLER_PROC(tag) | |
105 | { | |
106 | int old = m_WParser -> GetAlign(); | |
107 | wxHtmlContainerCell *c = m_WParser -> GetContainer(); | |
108 | if (c -> GetFirstCell() != NULL) { | |
109 | m_WParser -> CloseContainer(); | |
110 | m_WParser -> OpenContainer(); | |
111 | c = m_WParser -> GetContainer(); | |
112 | c -> SetAlign(tag); | |
113 | m_WParser -> SetAlign(c -> GetAlignHor()); | |
114 | } | |
115 | else { | |
116 | c -> SetAlign(tag); | |
117 | m_WParser -> SetAlign(c -> GetAlignHor()); | |
118 | } | |
119 | ||
120 | ParseInner(tag); | |
121 | ||
122 | m_WParser -> SetAlign(old); | |
123 | if (c -> GetFirstCell() != NULL) { | |
124 | m_WParser -> CloseContainer(); | |
125 | m_WParser -> OpenContainer(); | |
126 | } | |
127 | else | |
128 | c -> SetAlignHor(old); | |
129 | ||
130 | return TRUE; | |
131 | } | |
132 | ||
133 | TAG_HANDLER_END(DIV) | |
134 | ||
135 | ||
136 | ||
137 | ||
138 | TAG_HANDLER_BEGIN(TITLE, "TITLE") | |
139 | ||
140 | TAG_HANDLER_PROC(tag) | |
141 | { | |
142 | if (m_WParser -> GetWindow()) { | |
143 | wxHtmlWindow *wfr = (wxHtmlWindow*)(m_WParser -> GetWindow()); | |
144 | if (wfr) { | |
145 | wxString title = ""; | |
146 | wxString *src = m_WParser -> GetSource(); | |
147 | ||
148 | for (int i = tag.GetBeginPos(); i < tag.GetEndPos1(); i++) title += (*src)[i]; | |
149 | wfr -> SetTitle(title); | |
150 | } | |
151 | } | |
152 | return TRUE; | |
153 | } | |
154 | ||
155 | TAG_HANDLER_END(TITLE) | |
156 | ||
157 | ||
158 | ||
159 | ||
160 | TAG_HANDLER_BEGIN(BODY, "BODY") | |
161 | ||
162 | TAG_HANDLER_PROC(tag) | |
163 | { | |
164 | unsigned long tmp; | |
165 | wxColour clr; | |
166 | ||
167 | if (tag.HasParam("TEXT")) { | |
168 | tag.ScanParam("TEXT", "#%lX", &tmp); | |
169 | clr = wxColour((tmp & 0xFF0000) >> 16 , (tmp & 0x00FF00) >> 8, (tmp & 0x0000FF)); | |
170 | m_WParser -> SetActualColor(clr); | |
171 | m_WParser -> GetContainer() -> InsertCell(new wxHtmlColourCell(clr)); | |
172 | } | |
173 | ||
174 | if (tag.HasParam("LINK")) { | |
175 | tag.ScanParam("LINK", "#%lX", &tmp); | |
176 | clr = wxColour((tmp & 0xFF0000) >> 16 , (tmp & 0x00FF00) >> 8, (tmp & 0x0000FF)); | |
177 | m_WParser -> SetLinkColor(clr); | |
178 | } | |
179 | ||
180 | if (tag.HasParam("BGCOLOR")) { | |
181 | tag.ScanParam("BGCOLOR", "#%lX", &tmp); | |
182 | clr = wxColour((tmp & 0xFF0000) >> 16 , (tmp & 0x00FF00) >> 8, (tmp & 0x0000FF)); | |
183 | m_WParser -> GetContainer() -> InsertCell(new wxHtmlColourCell(clr, HTML_CLR_BACKGROUND)); | |
184 | if (m_WParser -> GetWindow() != NULL) | |
185 | m_WParser -> GetWindow() -> SetBackgroundColour(clr); | |
186 | } | |
187 | return FALSE; | |
188 | } | |
189 | ||
190 | TAG_HANDLER_END(BODY) | |
191 | ||
192 | ||
193 | ||
194 | TAG_HANDLER_BEGIN(BLOCKQUOTE, "BLOCKQUOTE") | |
195 | ||
196 | TAG_HANDLER_PROC(tag) | |
197 | { | |
198 | wxHtmlContainerCell *c; | |
199 | ||
200 | m_WParser -> CloseContainer(); | |
201 | c = m_WParser -> OpenContainer(); | |
202 | if (c -> GetAlignHor() == HTML_ALIGN_RIGHT) | |
203 | c -> SetIndent(5 * m_WParser -> GetCharWidth(), HTML_INDENT_RIGHT); | |
204 | else | |
205 | c -> SetIndent(5 * m_WParser -> GetCharWidth(), HTML_INDENT_LEFT); | |
206 | c -> SetIndent(m_WParser -> GetCharHeight(), HTML_INDENT_TOP); | |
207 | m_WParser -> OpenContainer(); | |
208 | ParseInner(tag); | |
209 | c = m_WParser -> CloseContainer(); | |
210 | c -> SetIndent(m_WParser -> GetCharHeight(), HTML_INDENT_BOTTOM); | |
211 | m_WParser -> CloseContainer(); | |
212 | m_WParser -> OpenContainer(); | |
213 | return TRUE; | |
214 | } | |
215 | ||
216 | TAG_HANDLER_END(BLOCKQUOTE) | |
217 | ||
218 | ||
219 | ||
220 | ||
221 | ||
222 | ||
223 | TAGS_MODULE_BEGIN(Layout) | |
224 | ||
225 | TAGS_MODULE_ADD(P) | |
226 | TAGS_MODULE_ADD(BR) | |
227 | TAGS_MODULE_ADD(CENTER) | |
228 | TAGS_MODULE_ADD(DIV) | |
229 | TAGS_MODULE_ADD(TITLE) | |
230 | TAGS_MODULE_ADD(BODY) | |
231 | TAGS_MODULE_ADD(BLOCKQUOTE) | |
232 | ||
233 | TAGS_MODULE_END(Layout) | |
234 | ||
235 | #endif |