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