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