]> git.saurik.com Git - wxWidgets.git/blob - src/html/mod_layout.cpp
fixed (didn't work at all)
[wxWidgets.git] / src / html / mod_layout.cpp
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 if (tag.ScanParam("TEXT", "#%lX", &tmp) == 1) {
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
175 if (tag.HasParam("LINK")) {
176 if (tag.ScanParam("LINK", "#%lX", &tmp) == 1) {
177 clr = wxColour((tmp & 0xFF0000) >> 16 , (tmp & 0x00FF00) >> 8, (tmp & 0x0000FF));
178 m_WParser -> SetLinkColor(clr);
179 }
180 }
181
182 if (tag.HasParam("BGCOLOR")) {
183 if (tag.ScanParam("BGCOLOR", "#%lX", &tmp) == 1) {
184 clr = wxColour((tmp & 0xFF0000) >> 16 , (tmp & 0x00FF00) >> 8, (tmp & 0x0000FF));
185 m_WParser -> GetContainer() -> InsertCell(new wxHtmlColourCell(clr, HTML_CLR_BACKGROUND));
186 if (m_WParser -> GetWindow() != NULL)
187 m_WParser -> GetWindow() -> SetBackgroundColour(clr);
188 }
189 }
190 return FALSE;
191 }
192
193 TAG_HANDLER_END(BODY)
194
195
196
197 TAG_HANDLER_BEGIN(BLOCKQUOTE, "BLOCKQUOTE")
198
199 TAG_HANDLER_PROC(tag)
200 {
201 wxHtmlContainerCell *c;
202
203 m_WParser -> CloseContainer();
204 c = m_WParser -> OpenContainer();
205 if (c -> GetAlignHor() == HTML_ALIGN_RIGHT)
206 c -> SetIndent(5 * m_WParser -> GetCharWidth(), HTML_INDENT_RIGHT);
207 else
208 c -> SetIndent(5 * m_WParser -> GetCharWidth(), HTML_INDENT_LEFT);
209 c -> SetIndent(m_WParser -> GetCharHeight(), HTML_INDENT_TOP);
210 m_WParser -> OpenContainer();
211 ParseInner(tag);
212 c = m_WParser -> CloseContainer();
213 c -> SetIndent(m_WParser -> GetCharHeight(), HTML_INDENT_BOTTOM);
214 m_WParser -> CloseContainer();
215 m_WParser -> OpenContainer();
216 return TRUE;
217 }
218
219 TAG_HANDLER_END(BLOCKQUOTE)
220
221
222
223
224
225
226 TAGS_MODULE_BEGIN(Layout)
227
228 TAGS_MODULE_ADD(P)
229 TAGS_MODULE_ADD(BR)
230 TAGS_MODULE_ADD(CENTER)
231 TAGS_MODULE_ADD(DIV)
232 TAGS_MODULE_ADD(TITLE)
233 TAGS_MODULE_ADD(BODY)
234 TAGS_MODULE_ADD(BLOCKQUOTE)
235
236 TAGS_MODULE_END(Layout)
237
238 #endif