]> git.saurik.com Git - wxWidgets.git/blob - src/html/m_layout.cpp
probably forgot to commit mimetype split to this file?
[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
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 m_WParser -> CloseContainer();
41 m_WParser -> OpenContainer();
42 }
43 m_WParser -> GetContainer() -> SetIndent(m_WParser -> GetCharHeight(), wxHTML_INDENT_TOP);
44 m_WParser -> GetContainer() -> SetAlign(tag);
45 return FALSE;
46 }
47
48 TAG_HANDLER_END(P)
49
50
51
52 TAG_HANDLER_BEGIN(BR, "BR")
53
54 TAG_HANDLER_PROC(tag)
55 {
56 int al = m_WParser -> GetContainer() -> GetAlignHor();
57 wxHtmlContainerCell *c;
58
59 m_WParser -> CloseContainer();
60 c = m_WParser -> OpenContainer();
61 c -> SetAlignHor(al);
62 c -> SetAlign(tag);
63 c -> SetMinHeight(m_WParser -> GetCharHeight());
64 return FALSE;
65 }
66
67 TAG_HANDLER_END(BR)
68
69
70
71 TAG_HANDLER_BEGIN(CENTER, "CENTER")
72
73 TAG_HANDLER_PROC(tag)
74 {
75 int old = m_WParser -> GetAlign();
76 wxHtmlContainerCell *c = m_WParser -> GetContainer();
77
78 m_WParser -> SetAlign(wxHTML_ALIGN_CENTER);
79 if (c -> GetFirstCell() != NULL) {
80 m_WParser -> CloseContainer();
81 m_WParser -> OpenContainer();
82 }
83 else
84 c -> SetAlignHor(wxHTML_ALIGN_CENTER);
85
86 if (tag.HasEnding()) {
87 ParseInner(tag);
88
89 m_WParser -> SetAlign(old);
90 if (c -> GetFirstCell() != NULL) {
91 m_WParser -> CloseContainer();
92 m_WParser -> OpenContainer();
93 }
94 else
95 c -> SetAlignHor(old);
96
97 return TRUE;
98 }
99 else return FALSE;
100 }
101
102 TAG_HANDLER_END(CENTER)
103
104
105
106 TAG_HANDLER_BEGIN(DIV, "DIV")
107
108 TAG_HANDLER_PROC(tag)
109 {
110 int old = m_WParser -> GetAlign();
111 wxHtmlContainerCell *c = m_WParser -> GetContainer();
112 if (c -> GetFirstCell() != NULL) {
113 m_WParser -> CloseContainer();
114 m_WParser -> OpenContainer();
115 c = m_WParser -> GetContainer();
116 c -> SetAlign(tag);
117 m_WParser -> SetAlign(c -> GetAlignHor());
118 }
119 else {
120 c -> SetAlign(tag);
121 m_WParser -> SetAlign(c -> GetAlignHor());
122 }
123
124 ParseInner(tag);
125
126 m_WParser -> SetAlign(old);
127 if (c -> GetFirstCell() != NULL) {
128 m_WParser -> CloseContainer();
129 m_WParser -> OpenContainer();
130 }
131 else
132 c -> SetAlignHor(old);
133
134 return TRUE;
135 }
136
137 TAG_HANDLER_END(DIV)
138
139
140
141
142 TAG_HANDLER_BEGIN(TITLE, "TITLE")
143
144 TAG_HANDLER_PROC(tag)
145 {
146 if (m_WParser -> GetWindow()) {
147 wxHtmlWindow *wfr = (wxHtmlWindow*)(m_WParser -> GetWindow());
148 if (wfr) {
149 wxString title = "";
150 wxString *src = m_WParser -> GetSource();
151
152 for (int i = tag.GetBeginPos(); i < tag.GetEndPos1(); i++) title += (*src)[(unsigned int) i];
153 wfr -> OnSetTitle(title);
154 }
155 }
156 return TRUE;
157 }
158
159 TAG_HANDLER_END(TITLE)
160
161
162
163
164 TAG_HANDLER_BEGIN(BODY, "BODY")
165
166 TAG_HANDLER_PROC(tag)
167 {
168 unsigned long tmp;
169 wxColour clr;
170
171 if (tag.HasParam(wxT("TEXT"))) {
172 if (tag.ScanParam(wxT("TEXT"), wxT("#%lX"), &tmp) == 1) {
173 clr = wxColour((tmp & 0xFF0000) >> 16 , (tmp & 0x00FF00) >> 8, (tmp & 0x0000FF));
174 m_WParser -> SetActualColor(clr);
175 m_WParser -> GetContainer() -> InsertCell(new wxHtmlColourCell(clr));
176 }
177 }
178
179 if (tag.HasParam(wxT("LINK"))) {
180 if (tag.ScanParam(wxT("LINK"), wxT("#%lX"), &tmp) == 1) {
181 clr = wxColour((tmp & 0xFF0000) >> 16 , (tmp & 0x00FF00) >> 8, (tmp & 0x0000FF));
182 m_WParser -> SetLinkColor(clr);
183 }
184 }
185
186 if (tag.HasParam(wxT("BGCOLOR"))) {
187 if (tag.ScanParam(wxT("BGCOLOR"), wxT("#%lX"), &tmp) == 1) {
188 clr = wxColour((tmp & 0xFF0000) >> 16 , (tmp & 0x00FF00) >> 8, (tmp & 0x0000FF));
189 m_WParser -> GetContainer() -> InsertCell(new wxHtmlColourCell(clr, wxHTML_CLR_BACKGROUND));
190 if (m_WParser -> GetWindow() != NULL)
191 m_WParser -> GetWindow() -> SetBackgroundColour(clr);
192 }
193 }
194 return FALSE;
195 }
196
197 TAG_HANDLER_END(BODY)
198
199
200
201 TAG_HANDLER_BEGIN(BLOCKQUOTE, "BLOCKQUOTE")
202
203 TAG_HANDLER_PROC(tag)
204 {
205 wxHtmlContainerCell *c;
206
207 m_WParser -> CloseContainer();
208 c = m_WParser -> OpenContainer();
209 if (c -> GetAlignHor() == wxHTML_ALIGN_RIGHT)
210 c -> SetIndent(5 * m_WParser -> GetCharWidth(), wxHTML_INDENT_RIGHT);
211 else
212 c -> SetIndent(5 * m_WParser -> GetCharWidth(), wxHTML_INDENT_LEFT);
213 c -> SetIndent(m_WParser -> GetCharHeight(), wxHTML_INDENT_TOP);
214 m_WParser -> OpenContainer();
215 ParseInner(tag);
216 c = m_WParser -> CloseContainer();
217 c -> SetIndent(m_WParser -> GetCharHeight(), wxHTML_INDENT_BOTTOM);
218 m_WParser -> CloseContainer();
219 m_WParser -> OpenContainer();
220 return TRUE;
221 }
222
223 TAG_HANDLER_END(BLOCKQUOTE)
224
225
226
227
228
229
230 TAGS_MODULE_BEGIN(Layout)
231
232 TAGS_MODULE_ADD(P)
233 TAGS_MODULE_ADD(BR)
234 TAGS_MODULE_ADD(CENTER)
235 TAGS_MODULE_ADD(DIV)
236 TAGS_MODULE_ADD(TITLE)
237 TAGS_MODULE_ADD(BODY)
238 TAGS_MODULE_ADD(BLOCKQUOTE)
239
240 TAGS_MODULE_END(Layout)
241
242 #endif