]>
Commit | Line | Data |
---|---|---|
5526e819 VS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: htmlcell.cpp | |
3 | // Purpose: wxHtmlCell - basic element of HTML output | |
4 | // Author: Vaclav Slavik | |
69941f05 | 5 | // RCS-ID: $Id$ |
5526e819 VS |
6 | // Copyright: (c) 1999 Vaclav Slavik |
7 | // Licence: wxWindows Licence | |
8 | ///////////////////////////////////////////////////////////////////////////// | |
9 | ||
5526e819 | 10 | #ifdef __GNUG__ |
69941f05 | 11 | #pragma implementation |
5526e819 VS |
12 | #endif |
13 | ||
4dcaf11a | 14 | #include "wx/wxprec.h" |
5526e819 | 15 | |
314260fb | 16 | #include "wx/defs.h" |
f6bcfd97 BP |
17 | |
18 | #if wxUSE_HTML && wxUSE_STREAMS | |
5526e819 VS |
19 | |
20 | #ifdef __BORDLANDC__ | |
21 | #pragma hdrstop | |
22 | #endif | |
23 | ||
24 | #ifndef WXPRECOMP | |
04dbb646 VZ |
25 | #include "wx/brush.h" |
26 | #include "wx/colour.h" | |
27 | #include "wx/dc.h" | |
5526e819 VS |
28 | #endif |
29 | ||
4dcaf11a RR |
30 | #include "wx/html/htmlcell.h" |
31 | #include "wx/html/htmlwin.h" | |
5526e819 VS |
32 | #include <stdlib.h> |
33 | ||
34 | ||
5526e819 VS |
35 | //----------------------------------------------------------------------------- |
36 | // wxHtmlCell | |
37 | //----------------------------------------------------------------------------- | |
38 | ||
04dbb646 | 39 | wxHtmlCell::wxHtmlCell() : wxObject() |
846914d1 | 40 | { |
04dbb646 VZ |
41 | m_Next = NULL; |
42 | m_Parent = NULL; | |
43 | m_Width = m_Height = m_Descent = 0; | |
846914d1 VS |
44 | m_CanLiveOnPagebreak = TRUE; |
45 | m_Link = NULL; | |
46 | } | |
47 | ||
04dbb646 | 48 | wxHtmlCell::~wxHtmlCell() |
846914d1 | 49 | { |
0cb9cfb2 | 50 | delete m_Link; |
846914d1 VS |
51 | } |
52 | ||
5526e819 | 53 | |
04dbb646 | 54 | void wxHtmlCell::OnMouseClick(wxWindow *parent, int x, int y, |
0b2dadd3 | 55 | const wxMouseEvent& event) |
5526e819 | 56 | { |
846914d1 VS |
57 | wxHtmlLinkInfo *lnk = GetLink(x, y); |
58 | if (lnk != NULL) | |
0b2dadd3 VS |
59 | { |
60 | wxHtmlLinkInfo lnk2(*lnk); | |
61 | lnk2.SetEvent(&event); | |
9bc8fded | 62 | lnk2.SetHtmlCell(this); |
0cb9cfb2 VZ |
63 | |
64 | // note : this cast is legal because parent is *always* wxHtmlWindow | |
65 | wxStaticCast(parent, wxHtmlWindow)->OnLinkClicked(lnk2); | |
0b2dadd3 | 66 | } |
5526e819 VS |
67 | } |
68 | ||
69 | ||
70 | ||
5660c520 | 71 | bool wxHtmlCell::AdjustPagebreak(int *pagebreak) const |
db98870d | 72 | { |
04dbb646 VZ |
73 | if ((!m_CanLiveOnPagebreak) && |
74 | m_PosY < *pagebreak && m_PosY + m_Height > *pagebreak) | |
0cb9cfb2 | 75 | { |
db98870d | 76 | *pagebreak = m_PosY; |
db98870d VS |
77 | return TRUE; |
78 | } | |
0cb9cfb2 VZ |
79 | |
80 | return FALSE; | |
db98870d VS |
81 | } |
82 | ||
83 | ||
84 | ||
04dbb646 | 85 | void wxHtmlCell::SetLink(const wxHtmlLinkInfo& link) |
846914d1 VS |
86 | { |
87 | if (m_Link) delete m_Link; | |
af1ed0c1 VS |
88 | m_Link = NULL; |
89 | if (link.GetHref() != wxEmptyString) | |
90 | m_Link = new wxHtmlLinkInfo(link); | |
846914d1 VS |
91 | } |
92 | ||
93 | ||
db98870d | 94 | |
d699f48b | 95 | void wxHtmlCell::Layout(int WXUNUSED(w)) |
721ab905 | 96 | { |
04dbb646 | 97 | SetPos(0, 0); |
721ab905 VS |
98 | } |
99 | ||
100 | ||
79d6c018 VS |
101 | |
102 | void wxHtmlCell::GetHorizontalConstraints(int *left, int *right) const | |
103 | { | |
104 | if (left) | |
105 | *left = m_PosX; | |
106 | if (right) | |
026d1fac | 107 | *right = m_PosX + m_Width; |
79d6c018 VS |
108 | } |
109 | ||
110 | ||
111 | ||
d699f48b | 112 | const wxHtmlCell* wxHtmlCell::Find(int WXUNUSED(condition), const void* WXUNUSED(param)) const |
721ab905 | 113 | { |
bf7d7ee7 | 114 | return NULL; |
721ab905 VS |
115 | } |
116 | ||
117 | ||
118 | ||
5526e819 VS |
119 | //----------------------------------------------------------------------------- |
120 | // wxHtmlWordCell | |
121 | //----------------------------------------------------------------------------- | |
122 | ||
123 | wxHtmlWordCell::wxHtmlWordCell(const wxString& word, wxDC& dc) : wxHtmlCell() | |
124 | { | |
125 | m_Word = word; | |
5526e819 | 126 | dc.GetTextExtent(m_Word, &m_Width, &m_Height, &m_Descent); |
db98870d | 127 | SetCanLiveOnPagebreak(FALSE); |
5526e819 VS |
128 | } |
129 | ||
130 | ||
131 | ||
d699f48b | 132 | void wxHtmlWordCell::Draw(wxDC& dc, int x, int y, int WXUNUSED(view_y1), int WXUNUSED(view_y2)) |
5526e819 VS |
133 | { |
134 | dc.DrawText(m_Word, x + m_PosX, y + m_PosY); | |
5526e819 VS |
135 | } |
136 | ||
137 | ||
138 | ||
5526e819 VS |
139 | //----------------------------------------------------------------------------- |
140 | // wxHtmlContainerCell | |
141 | //----------------------------------------------------------------------------- | |
142 | ||
143 | ||
144 | wxHtmlContainerCell::wxHtmlContainerCell(wxHtmlContainerCell *parent) : wxHtmlCell() | |
145 | { | |
146 | m_Cells = m_LastCell = NULL; | |
147 | m_Parent = parent; | |
4f9297b0 | 148 | if (m_Parent) m_Parent->InsertCell(this); |
efba2b89 VS |
149 | m_AlignHor = wxHTML_ALIGN_LEFT; |
150 | m_AlignVer = wxHTML_ALIGN_BOTTOM; | |
5526e819 | 151 | m_IndentLeft = m_IndentRight = m_IndentTop = m_IndentBottom = 0; |
efba2b89 | 152 | m_WidthFloat = 100; m_WidthFloatUnits = wxHTML_UNITS_PERCENT; |
5526e819 VS |
153 | m_UseBkColour = FALSE; |
154 | m_UseBorder = FALSE; | |
5c1bfc5d | 155 | m_MinHeight = 0; |
efba2b89 | 156 | m_MinHeightAlign = wxHTML_ALIGN_TOP; |
5660c520 | 157 | m_LastLayout = -1; |
5526e819 VS |
158 | } |
159 | ||
04dbb646 | 160 | wxHtmlContainerCell::~wxHtmlContainerCell() |
721ab905 | 161 | { |
491c9920 VZ |
162 | wxHtmlCell *cell = m_Cells; |
163 | while ( cell ) | |
bf7d7ee7 | 164 | { |
491c9920 VZ |
165 | wxHtmlCell *cellNext = cell->GetNext(); |
166 | delete cell; | |
167 | cell = cellNext; | |
bf7d7ee7 | 168 | } |
721ab905 VS |
169 | } |
170 | ||
5526e819 VS |
171 | |
172 | ||
173 | void wxHtmlContainerCell::SetIndent(int i, int what, int units) | |
174 | { | |
efba2b89 VS |
175 | int val = (units == wxHTML_UNITS_PIXELS) ? i : -i; |
176 | if (what & wxHTML_INDENT_LEFT) m_IndentLeft = val; | |
177 | if (what & wxHTML_INDENT_RIGHT) m_IndentRight = val; | |
178 | if (what & wxHTML_INDENT_TOP) m_IndentTop = val; | |
179 | if (what & wxHTML_INDENT_BOTTOM) m_IndentBottom = val; | |
5660c520 | 180 | m_LastLayout = -1; |
5526e819 VS |
181 | } |
182 | ||
183 | ||
184 | ||
185 | int wxHtmlContainerCell::GetIndent(int ind) const | |
186 | { | |
efba2b89 VS |
187 | if (ind & wxHTML_INDENT_LEFT) return m_IndentLeft; |
188 | else if (ind & wxHTML_INDENT_RIGHT) return m_IndentRight; | |
189 | else if (ind & wxHTML_INDENT_TOP) return m_IndentTop; | |
190 | else if (ind & wxHTML_INDENT_BOTTOM) return m_IndentBottom; | |
5526e819 VS |
191 | else return -1; /* BUG! Should not be called... */ |
192 | } | |
193 | ||
194 | ||
195 | ||
196 | ||
197 | int wxHtmlContainerCell::GetIndentUnits(int ind) const | |
198 | { | |
199 | bool p = FALSE; | |
efba2b89 VS |
200 | if (ind & wxHTML_INDENT_LEFT) p = m_IndentLeft < 0; |
201 | else if (ind & wxHTML_INDENT_RIGHT) p = m_IndentRight < 0; | |
202 | else if (ind & wxHTML_INDENT_TOP) p = m_IndentTop < 0; | |
203 | else if (ind & wxHTML_INDENT_BOTTOM) p = m_IndentBottom < 0; | |
204 | if (p) return wxHTML_UNITS_PERCENT; | |
205 | else return wxHTML_UNITS_PIXELS; | |
5526e819 VS |
206 | } |
207 | ||
208 | ||
209 | ||
5660c520 | 210 | bool wxHtmlContainerCell::AdjustPagebreak(int *pagebreak) const |
db98870d | 211 | { |
04dbb646 | 212 | if (!m_CanLiveOnPagebreak) |
db98870d | 213 | return wxHtmlCell::AdjustPagebreak(pagebreak); |
e52d6dbc | 214 | |
04dbb646 | 215 | else |
4f9297b0 | 216 | { |
db98870d VS |
217 | wxHtmlCell *c = GetFirstCell(); |
218 | bool rt = FALSE; | |
e52d6dbc | 219 | int pbrk = *pagebreak - m_PosY; |
db98870d | 220 | |
04dbb646 | 221 | while (c) |
0cb9cfb2 | 222 | { |
d699f48b | 223 | if (c->AdjustPagebreak(&pbrk)) |
bf7d7ee7 | 224 | rt = TRUE; |
4f9297b0 | 225 | c = c->GetNext(); |
db98870d | 226 | } |
d699f48b | 227 | if (rt) |
bf7d7ee7 | 228 | *pagebreak = pbrk + m_PosY; |
db98870d VS |
229 | return rt; |
230 | } | |
231 | } | |
232 | ||
233 | ||
234 | ||
5526e819 VS |
235 | void wxHtmlContainerCell::Layout(int w) |
236 | { | |
026d1fac VS |
237 | wxHtmlCell::Layout(w); |
238 | ||
239 | if (m_LastLayout == w) return; | |
0cb9cfb2 | 240 | |
026d1fac VS |
241 | // VS: Any attempt to layout with negative or zero width leads to hell, |
242 | // but we can't ignore such attempts completely, since it sometimes | |
243 | // happen (e.g. when trying how small a table can be). The best thing we | |
244 | // can do is to set the width of child cells to zero | |
0cb9cfb2 | 245 | if (w < 1) |
4f9297b0 | 246 | { |
026d1fac VS |
247 | m_Width = 0; |
248 | for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) | |
249 | cell->Layout(0); | |
0cb9cfb2 | 250 | // this does two things: it recursively calls this code on all child |
026d1fac VS |
251 | // contrainers and resets children's position to (0,0) |
252 | return; | |
04dbb646 | 253 | } |
5660c520 | 254 | |
5526e819 VS |
255 | wxHtmlCell *cell = m_Cells, *line = m_Cells; |
256 | long xpos = 0, ypos = m_IndentTop; | |
257 | int xdelta = 0, ybasicpos = 0, ydiff; | |
258 | int s_width, s_indent; | |
259 | int ysizeup = 0, ysizedown = 0; | |
5c1bfc5d VS |
260 | int MaxLineWidth = 0; |
261 | int xcnt = 0; | |
262 | ||
5526e819 VS |
263 | |
264 | /* | |
7e941458 | 265 | |
5526e819 | 266 | WIDTH ADJUSTING : |
7e941458 | 267 | |
5526e819 VS |
268 | */ |
269 | ||
04dbb646 | 270 | if (m_WidthFloatUnits == wxHTML_UNITS_PERCENT) |
4f9297b0 | 271 | { |
5526e819 VS |
272 | if (m_WidthFloat < 0) m_Width = (100 + m_WidthFloat) * w / 100; |
273 | else m_Width = m_WidthFloat * w / 100; | |
274 | } | |
04dbb646 | 275 | else |
4f9297b0 | 276 | { |
5526e819 VS |
277 | if (m_WidthFloat < 0) m_Width = w + m_WidthFloat; |
278 | else m_Width = m_WidthFloat; | |
279 | } | |
280 | ||
04dbb646 | 281 | if (m_Cells) |
4f9297b0 | 282 | { |
5526e819 VS |
283 | int l = (m_IndentLeft < 0) ? (-m_IndentLeft * m_Width / 100) : m_IndentLeft; |
284 | int r = (m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight; | |
bf7d7ee7 VS |
285 | for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) |
286 | cell->Layout(m_Width - (l + r)); | |
5526e819 VS |
287 | } |
288 | ||
289 | /* | |
290 | ||
291 | LAYOUTING : | |
7e941458 | 292 | |
5526e819 VS |
293 | */ |
294 | ||
295 | // adjust indentation: | |
296 | s_indent = (m_IndentLeft < 0) ? (-m_IndentLeft * m_Width / 100) : m_IndentLeft; | |
297 | s_width = m_Width - s_indent - ((m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight); | |
298 | ||
5526e819 | 299 | // my own layouting: |
04dbb646 | 300 | while (cell != NULL) |
4f9297b0 | 301 | { |
04dbb646 | 302 | switch (m_AlignVer) |
0cb9cfb2 | 303 | { |
efba2b89 | 304 | case wxHTML_ALIGN_TOP : ybasicpos = 0; break; |
4f9297b0 VS |
305 | case wxHTML_ALIGN_BOTTOM : ybasicpos = - cell->GetHeight(); break; |
306 | case wxHTML_ALIGN_CENTER : ybasicpos = - cell->GetHeight() / 2; break; | |
5526e819 | 307 | } |
4f9297b0 | 308 | ydiff = cell->GetHeight() + ybasicpos; |
5526e819 | 309 | |
4f9297b0 VS |
310 | if (cell->GetDescent() + ydiff > ysizedown) ysizedown = cell->GetDescent() + ydiff; |
311 | if (ybasicpos + cell->GetDescent() < -ysizeup) ysizeup = - (ybasicpos + cell->GetDescent()); | |
5526e819 | 312 | |
4f9297b0 VS |
313 | cell->SetPos(xpos, ybasicpos + cell->GetDescent()); |
314 | xpos += cell->GetWidth(); | |
315 | cell = cell->GetNext(); | |
5c1bfc5d | 316 | xcnt++; |
5526e819 VS |
317 | |
318 | // force new line if occured: | |
04dbb646 | 319 | if ((cell == NULL) || (xpos + cell->GetWidth() > s_width)) |
0cb9cfb2 | 320 | { |
5c1bfc5d | 321 | if (xpos > MaxLineWidth) MaxLineWidth = xpos; |
5526e819 VS |
322 | if (ysizeup < 0) ysizeup = 0; |
323 | if (ysizedown < 0) ysizedown = 0; | |
324 | switch (m_AlignHor) { | |
04dbb646 VZ |
325 | case wxHTML_ALIGN_LEFT : |
326 | case wxHTML_ALIGN_JUSTIFY : | |
327 | xdelta = 0; | |
5c1bfc5d | 328 | break; |
04dbb646 VZ |
329 | case wxHTML_ALIGN_RIGHT : |
330 | xdelta = 0 + (s_width - xpos); | |
5c1bfc5d | 331 | break; |
04dbb646 VZ |
332 | case wxHTML_ALIGN_CENTER : |
333 | xdelta = 0 + (s_width - xpos) / 2; | |
5c1bfc5d | 334 | break; |
5526e819 VS |
335 | } |
336 | if (xdelta < 0) xdelta = 0; | |
337 | xdelta += s_indent; | |
338 | ||
339 | ypos += ysizeup; | |
04dbb646 | 340 | |
5c1bfc5d | 341 | if (m_AlignHor != wxHTML_ALIGN_JUSTIFY || cell == NULL) |
04dbb646 | 342 | while (line != cell) |
0cb9cfb2 | 343 | { |
04dbb646 | 344 | line->SetPos(line->GetPosX() + xdelta, |
4f9297b0 VS |
345 | ypos + line->GetPosY()); |
346 | line = line->GetNext(); | |
5c1bfc5d VS |
347 | } |
348 | else | |
04dbb646 | 349 | { |
5c1bfc5d VS |
350 | int counter = 0; |
351 | int step = (s_width - xpos); | |
352 | if (step < 0) step = 0; | |
c1e5e881 | 353 | xcnt--; |
04dbb646 | 354 | if (xcnt > 0) while (line != cell) |
0cb9cfb2 | 355 | { |
4f9297b0 | 356 | line->SetPos(line->GetPosX() + s_indent + |
5c1bfc5d | 357 | (counter++ * step / xcnt), |
4f9297b0 VS |
358 | ypos + line->GetPosY()); |
359 | line = line->GetNext(); | |
5c1bfc5d | 360 | } |
c1e5e881 | 361 | xcnt++; |
5526e819 VS |
362 | } |
363 | ||
364 | ypos += ysizedown; | |
5c1bfc5d | 365 | xpos = xcnt = 0; |
5526e819 VS |
366 | ysizeup = ysizedown = 0; |
367 | line = cell; | |
368 | } | |
369 | } | |
370 | ||
371 | // setup height & width, depending on container layout: | |
372 | m_Height = ypos + (ysizedown + ysizeup) + m_IndentBottom; | |
373 | ||
04dbb646 | 374 | if (m_Height < m_MinHeight) |
4f9297b0 | 375 | { |
04dbb646 | 376 | if (m_MinHeightAlign != wxHTML_ALIGN_TOP) |
0cb9cfb2 | 377 | { |
5526e819 | 378 | int diff = m_MinHeight - m_Height; |
efba2b89 | 379 | if (m_MinHeightAlign == wxHTML_ALIGN_CENTER) diff /= 2; |
5526e819 | 380 | cell = m_Cells; |
04dbb646 | 381 | while (cell) |
0cb9cfb2 | 382 | { |
4f9297b0 VS |
383 | cell->SetPos(cell->GetPosX(), cell->GetPosY() + diff); |
384 | cell = cell->GetNext(); | |
5526e819 VS |
385 | } |
386 | } | |
387 | m_Height = m_MinHeight; | |
388 | } | |
389 | ||
5c1bfc5d VS |
390 | MaxLineWidth += s_indent + ((m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight); |
391 | if (m_Width < MaxLineWidth) m_Width = MaxLineWidth; | |
5526e819 | 392 | |
5660c520 | 393 | m_LastLayout = w; |
5526e819 VS |
394 | } |
395 | ||
396 | ||
397 | #define mMin(a, b) (((a) < (b)) ? (a) : (b)) | |
398 | #define mMax(a, b) (((a) < (b)) ? (b) : (a)) | |
399 | ||
400 | void wxHtmlContainerCell::Draw(wxDC& dc, int x, int y, int view_y1, int view_y2) | |
401 | { | |
402 | // container visible, draw it: | |
04dbb646 | 403 | if ((y + m_PosY < view_y2) && (y + m_PosY + m_Height > view_y1)) |
4f9297b0 | 404 | { |
5526e819 | 405 | |
04dbb646 | 406 | if (m_UseBkColour) |
0cb9cfb2 | 407 | { |
5526e819 VS |
408 | wxBrush myb = wxBrush(m_BkColour, wxSOLID); |
409 | ||
410 | int real_y1 = mMax(y + m_PosY, view_y1); | |
411 | int real_y2 = mMin(y + m_PosY + m_Height - 1, view_y2); | |
412 | ||
413 | dc.SetBrush(myb); | |
414 | dc.SetPen(*wxTRANSPARENT_PEN); | |
415 | dc.DrawRectangle(x + m_PosX, real_y1, m_Width, real_y2 - real_y1 + 1); | |
416 | } | |
417 | ||
04dbb646 | 418 | if (m_UseBorder) |
0cb9cfb2 | 419 | { |
5526e819 VS |
420 | wxPen mypen1(m_BorderColour1, 1, wxSOLID); |
421 | wxPen mypen2(m_BorderColour2, 1, wxSOLID); | |
422 | ||
423 | dc.SetPen(mypen1); | |
424 | dc.DrawLine(x + m_PosX, y + m_PosY, x + m_PosX, y + m_PosY + m_Height - 1); | |
425 | dc.DrawLine(x + m_PosX, y + m_PosY, x + m_PosX + m_Width - 1, y + m_PosY); | |
426 | dc.SetPen(mypen2); | |
427 | dc.DrawLine(x + m_PosX + m_Width - 1, y + m_PosY, x + m_PosX + m_Width - 1, y + m_PosY + m_Height - 1); | |
428 | dc.DrawLine(x + m_PosX, y + m_PosY + m_Height - 1, x + m_PosX + m_Width - 1, y + m_PosY + m_Height - 1); | |
429 | } | |
430 | ||
d699f48b | 431 | if (m_Cells) |
bf7d7ee7 VS |
432 | { |
433 | for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) | |
434 | cell->Draw(dc, x + m_PosX, y + m_PosY, view_y1, view_y2); | |
435 | } | |
5526e819 VS |
436 | } |
437 | // container invisible, just proceed font+color changing: | |
04dbb646 | 438 | else |
4f9297b0 | 439 | { |
d699f48b | 440 | if (m_Cells) |
bf7d7ee7 VS |
441 | { |
442 | for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) | |
443 | cell->DrawInvisible(dc, x + m_PosX, y + m_PosY); | |
444 | } | |
5526e819 | 445 | } |
5526e819 VS |
446 | } |
447 | ||
448 | ||
449 | ||
450 | void wxHtmlContainerCell::DrawInvisible(wxDC& dc, int x, int y) | |
451 | { | |
d699f48b | 452 | if (m_Cells) |
bf7d7ee7 VS |
453 | { |
454 | for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) | |
455 | cell->DrawInvisible(dc, x + m_PosX, y + m_PosY); | |
456 | } | |
5526e819 VS |
457 | } |
458 | ||
459 | ||
460 | ||
846914d1 | 461 | wxHtmlLinkInfo *wxHtmlContainerCell::GetLink(int x, int y) const |
5526e819 VS |
462 | { |
463 | wxHtmlCell *c = m_Cells; | |
464 | int cx, cy, cw, ch; | |
465 | ||
04dbb646 | 466 | while (c) |
4f9297b0 VS |
467 | { |
468 | cx = c->GetPosX(), cy = c->GetPosY(); | |
469 | cw = c->GetWidth(), ch = c->GetHeight(); | |
5526e819 | 470 | if ((x >= cx) && (x < cx + cw) && (y >= cy) && (y < cy + ch)) |
4f9297b0 VS |
471 | return c->GetLink(x - cx, y - cy); |
472 | c = c->GetNext(); | |
5526e819 | 473 | } |
846914d1 | 474 | return NULL; |
5526e819 VS |
475 | } |
476 | ||
477 | ||
478 | ||
479 | void wxHtmlContainerCell::InsertCell(wxHtmlCell *f) | |
480 | { | |
481 | if (!m_Cells) m_Cells = m_LastCell = f; | |
04dbb646 | 482 | else |
4f9297b0 VS |
483 | { |
484 | m_LastCell->SetNext(f); | |
5526e819 | 485 | m_LastCell = f; |
4f9297b0 | 486 | if (m_LastCell) while (m_LastCell->GetNext()) m_LastCell = m_LastCell->GetNext(); |
5526e819 | 487 | } |
4f9297b0 | 488 | f->SetParent(this); |
5660c520 | 489 | m_LastLayout = -1; |
5526e819 VS |
490 | } |
491 | ||
492 | ||
493 | ||
494 | void wxHtmlContainerCell::SetAlign(const wxHtmlTag& tag) | |
495 | { | |
04dbb646 | 496 | if (tag.HasParam(wxT("ALIGN"))) |
4f9297b0 | 497 | { |
0413cec5 | 498 | wxString alg = tag.GetParam(wxT("ALIGN")); |
5526e819 | 499 | alg.MakeUpper(); |
0413cec5 | 500 | if (alg == wxT("CENTER")) |
efba2b89 | 501 | SetAlignHor(wxHTML_ALIGN_CENTER); |
0413cec5 | 502 | else if (alg == wxT("LEFT")) |
efba2b89 | 503 | SetAlignHor(wxHTML_ALIGN_LEFT); |
5c1bfc5d VS |
504 | else if (alg == wxT("JUSTIFY")) |
505 | SetAlignHor(wxHTML_ALIGN_JUSTIFY); | |
0413cec5 | 506 | else if (alg == wxT("RIGHT")) |
efba2b89 | 507 | SetAlignHor(wxHTML_ALIGN_RIGHT); |
5660c520 | 508 | m_LastLayout = -1; |
5526e819 VS |
509 | } |
510 | } | |
511 | ||
512 | ||
513 | ||
edbd0635 | 514 | void wxHtmlContainerCell::SetWidthFloat(const wxHtmlTag& tag, double pixel_scale) |
5526e819 | 515 | { |
04dbb646 | 516 | if (tag.HasParam(wxT("WIDTH"))) |
4f9297b0 | 517 | { |
5526e819 | 518 | int wdi; |
0413cec5 | 519 | wxString wd = tag.GetParam(wxT("WIDTH")); |
5526e819 | 520 | |
04dbb646 | 521 | if (wd[wd.Length()-1] == wxT('%')) |
0cb9cfb2 | 522 | { |
66a77a74 | 523 | wxSscanf(wd.c_str(), wxT("%i%%"), &wdi); |
efba2b89 | 524 | SetWidthFloat(wdi, wxHTML_UNITS_PERCENT); |
5526e819 | 525 | } |
04dbb646 | 526 | else |
0cb9cfb2 | 527 | { |
66a77a74 | 528 | wxSscanf(wd.c_str(), wxT("%i"), &wdi); |
edbd0635 | 529 | SetWidthFloat((int)(pixel_scale * (double)wdi), wxHTML_UNITS_PIXELS); |
5526e819 | 530 | } |
5660c520 | 531 | m_LastLayout = -1; |
5526e819 VS |
532 | } |
533 | } | |
534 | ||
535 | ||
536 | ||
537 | const wxHtmlCell* wxHtmlContainerCell::Find(int condition, const void* param) const | |
538 | { | |
04dbb646 | 539 | if (m_Cells) |
d699f48b | 540 | { |
bf7d7ee7 | 541 | const wxHtmlCell *r = NULL; |
5526e819 | 542 | |
bf7d7ee7 VS |
543 | for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) |
544 | { | |
545 | r = cell->Find(condition, param); | |
546 | if (r) return r; | |
547 | } | |
548 | } | |
549 | return NULL; | |
5526e819 VS |
550 | } |
551 | ||
552 | ||
553 | ||
0b2dadd3 | 554 | void wxHtmlContainerCell::OnMouseClick(wxWindow *parent, int x, int y, const wxMouseEvent& event) |
5526e819 | 555 | { |
04dbb646 | 556 | if (m_Cells) |
4f9297b0 | 557 | { |
5526e819 | 558 | wxHtmlCell *c = m_Cells; |
04dbb646 | 559 | while (c) |
0cb9cfb2 | 560 | { |
4f9297b0 VS |
561 | if ( (c->GetPosX() <= x) && |
562 | (c->GetPosY() <= y) && | |
563 | (c->GetPosX() + c->GetWidth() > x) && | |
04dbb646 | 564 | (c->GetPosY() + c->GetHeight() > y)) |
0cb9cfb2 | 565 | { |
4f9297b0 | 566 | c->OnMouseClick(parent, x - c->GetPosX(), y - c->GetPosY(), event); |
5526e819 VS |
567 | break; |
568 | } | |
4f9297b0 | 569 | c = c->GetNext(); |
5526e819 VS |
570 | } |
571 | } | |
572 | } | |
573 | ||
574 | ||
575 | ||
79d6c018 VS |
576 | void wxHtmlContainerCell::GetHorizontalConstraints(int *left, int *right) const |
577 | { | |
578 | int cleft = m_PosX + m_Width, cright = m_PosX; // worst case | |
579 | int l, r; | |
0cb9cfb2 | 580 | |
79d6c018 VS |
581 | for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) |
582 | { | |
583 | cell->GetHorizontalConstraints(&l, &r); | |
584 | if (l < cleft) | |
585 | cleft = l; | |
586 | if (r > cright) | |
587 | cright = r; | |
0cb9cfb2 | 588 | } |
79d6c018 | 589 | |
026d1fac VS |
590 | cleft -= (m_IndentLeft < 0) ? (-m_IndentLeft * m_Width / 100) : m_IndentLeft; |
591 | cright += (m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight; | |
592 | ||
79d6c018 VS |
593 | if (left) |
594 | *left = cleft; | |
595 | if (right) | |
596 | *right = cright; | |
597 | } | |
598 | ||
599 | ||
600 | ||
5526e819 VS |
601 | |
602 | ||
603 | //-------------------------------------------------------------------------------- | |
604 | // wxHtmlColourCell | |
605 | //-------------------------------------------------------------------------------- | |
606 | ||
d699f48b | 607 | void wxHtmlColourCell::Draw(wxDC& dc, int WXUNUSED(x), int WXUNUSED(y), int WXUNUSED(view_y1), int WXUNUSED(view_y2)) |
5526e819 | 608 | { |
efba2b89 | 609 | if (m_Flags & wxHTML_CLR_FOREGROUND) |
5526e819 | 610 | dc.SetTextForeground(m_Colour); |
04dbb646 | 611 | if (m_Flags & wxHTML_CLR_BACKGROUND) |
4f9297b0 | 612 | { |
5526e819 VS |
613 | dc.SetBackground(wxBrush(m_Colour, wxSOLID)); |
614 | dc.SetTextBackground(m_Colour); | |
615 | } | |
5526e819 VS |
616 | } |
617 | ||
d699f48b | 618 | void wxHtmlColourCell::DrawInvisible(wxDC& dc, int WXUNUSED(x), int WXUNUSED(y)) |
5526e819 | 619 | { |
efba2b89 | 620 | if (m_Flags & wxHTML_CLR_FOREGROUND) |
5526e819 | 621 | dc.SetTextForeground(m_Colour); |
04dbb646 | 622 | if (m_Flags & wxHTML_CLR_BACKGROUND) |
4f9297b0 | 623 | { |
5526e819 VS |
624 | dc.SetBackground(wxBrush(m_Colour, wxSOLID)); |
625 | dc.SetTextBackground(m_Colour); | |
626 | } | |
5526e819 VS |
627 | } |
628 | ||
629 | ||
630 | ||
631 | ||
632 | //-------------------------------------------------------------------------------- | |
633 | // wxHtmlFontCell | |
634 | //-------------------------------------------------------------------------------- | |
635 | ||
d699f48b | 636 | void wxHtmlFontCell::Draw(wxDC& dc, int WXUNUSED(x), int WXUNUSED(y), int WXUNUSED(view_y1), int WXUNUSED(view_y2)) |
5526e819 | 637 | { |
921d0fb1 | 638 | dc.SetFont(m_Font); |
5526e819 VS |
639 | } |
640 | ||
d699f48b | 641 | void wxHtmlFontCell::DrawInvisible(wxDC& dc, int WXUNUSED(x), int WXUNUSED(y)) |
5526e819 | 642 | { |
921d0fb1 | 643 | dc.SetFont(m_Font); |
5526e819 VS |
644 | } |
645 | ||
646 | ||
647 | ||
648 | ||
649 | ||
650 | ||
651 | ||
652 | ||
653 | //-------------------------------------------------------------------------------- | |
654 | // wxHtmlWidgetCell | |
655 | //-------------------------------------------------------------------------------- | |
656 | ||
657 | wxHtmlWidgetCell::wxHtmlWidgetCell(wxWindow *wnd, int w) | |
658 | { | |
659 | int sx, sy; | |
660 | m_Wnd = wnd; | |
4f9297b0 | 661 | m_Wnd->GetSize(&sx, &sy); |
5526e819 VS |
662 | m_Width = sx, m_Height = sy; |
663 | m_WidthFloat = w; | |
664 | } | |
665 | ||
666 | ||
d699f48b | 667 | void wxHtmlWidgetCell::Draw(wxDC& WXUNUSED(dc), int WXUNUSED(x), int WXUNUSED(y), int WXUNUSED(view_y1), int WXUNUSED(view_y2)) |
5526e819 VS |
668 | { |
669 | int absx = 0, absy = 0, stx, sty; | |
670 | wxHtmlCell *c = this; | |
671 | ||
04dbb646 | 672 | while (c) |
4f9297b0 VS |
673 | { |
674 | absx += c->GetPosX(); | |
675 | absy += c->GetPosY(); | |
676 | c = c->GetParent(); | |
5526e819 VS |
677 | } |
678 | ||
e421922f | 679 | ((wxScrolledWindow*)(m_Wnd->GetParent()))->GetViewStart(&stx, &sty); |
4f9297b0 | 680 | m_Wnd->SetSize(absx - wxHTML_SCROLL_STEP * stx, absy - wxHTML_SCROLL_STEP * sty, m_Width, m_Height); |
5526e819 VS |
681 | } |
682 | ||
683 | ||
684 | ||
d699f48b | 685 | void wxHtmlWidgetCell::DrawInvisible(wxDC& WXUNUSED(dc), int WXUNUSED(x), int WXUNUSED(y)) |
5526e819 VS |
686 | { |
687 | int absx = 0, absy = 0, stx, sty; | |
688 | wxHtmlCell *c = this; | |
689 | ||
04dbb646 | 690 | while (c) |
4f9297b0 VS |
691 | { |
692 | absx += c->GetPosX(); | |
693 | absy += c->GetPosY(); | |
694 | c = c->GetParent(); | |
5526e819 | 695 | } |
7e941458 | 696 | |
e421922f | 697 | ((wxScrolledWindow*)(m_Wnd->GetParent()))->GetViewStart(&stx, &sty); |
4f9297b0 | 698 | m_Wnd->SetSize(absx - wxHTML_SCROLL_STEP * stx, absy - wxHTML_SCROLL_STEP * sty, m_Width, m_Height); |
5526e819 VS |
699 | } |
700 | ||
701 | ||
702 | ||
703 | void wxHtmlWidgetCell::Layout(int w) | |
704 | { | |
04dbb646 | 705 | if (m_WidthFloat != 0) |
4f9297b0 | 706 | { |
5526e819 | 707 | m_Width = (w * m_WidthFloat) / 100; |
4f9297b0 | 708 | m_Wnd->SetSize(m_Width, m_Height); |
5526e819 VS |
709 | } |
710 | ||
711 | wxHtmlCell::Layout(w); | |
712 | } | |
713 | ||
714 | #endif |