]>
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__ |
1aedb1dd | 11 | #pragma implementation "htmlcell.h" |
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 | 19 | |
2b5f62a0 | 20 | #ifdef __BORLANDC__ |
5526e819 VS |
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" | |
36c4ff4d | 32 | #include "wx/settings.h" |
5526e819 VS |
33 | #include <stdlib.h> |
34 | ||
e3774124 VS |
35 | //----------------------------------------------------------------------------- |
36 | // Helper classes | |
37 | //----------------------------------------------------------------------------- | |
38 | ||
1338c59a VS |
39 | void wxHtmlSelection::Set(const wxPoint& fromPos, const wxHtmlCell *fromCell, |
40 | const wxPoint& toPos, const wxHtmlCell *toCell) | |
e3774124 VS |
41 | { |
42 | m_fromCell = fromCell; | |
43 | m_toCell = toCell; | |
44 | m_fromPos = fromPos; | |
45 | m_toPos = toPos; | |
46 | } | |
47 | ||
1338c59a | 48 | void wxHtmlSelection::Set(const wxHtmlCell *fromCell, const wxHtmlCell *toCell) |
e3774124 VS |
49 | { |
50 | wxPoint p1 = fromCell ? fromCell->GetAbsPos() : wxDefaultPosition; | |
51 | wxPoint p2 = toCell ? toCell->GetAbsPos() : wxDefaultPosition; | |
52 | if ( toCell ) | |
53 | { | |
54 | p2.x += toCell->GetWidth()-1; | |
55 | p2.y += toCell->GetHeight()-1; | |
56 | } | |
57 | Set(p1, fromCell, p2, toCell); | |
58 | } | |
5526e819 | 59 | |
f30e67db | 60 | wxColour wxDefaultHtmlRenderingStyle::GetSelectedTextColour( |
bfc248a3 | 61 | const wxColour& clr) |
f30e67db VS |
62 | { |
63 | return wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT); | |
64 | } | |
65 | ||
66 | wxColour wxDefaultHtmlRenderingStyle::GetSelectedTextBgColour( | |
67 | const wxColour& WXUNUSED(clr)) | |
68 | { | |
69 | return wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT); | |
70 | } | |
71 | ||
72 | ||
5526e819 VS |
73 | //----------------------------------------------------------------------------- |
74 | // wxHtmlCell | |
75 | //----------------------------------------------------------------------------- | |
76 | ||
04dbb646 | 77 | wxHtmlCell::wxHtmlCell() : wxObject() |
846914d1 | 78 | { |
04dbb646 VZ |
79 | m_Next = NULL; |
80 | m_Parent = NULL; | |
81 | m_Width = m_Height = m_Descent = 0; | |
846914d1 VS |
82 | m_CanLiveOnPagebreak = TRUE; |
83 | m_Link = NULL; | |
84 | } | |
85 | ||
04dbb646 | 86 | wxHtmlCell::~wxHtmlCell() |
846914d1 | 87 | { |
0cb9cfb2 | 88 | delete m_Link; |
846914d1 VS |
89 | } |
90 | ||
5526e819 | 91 | |
04dbb646 | 92 | void wxHtmlCell::OnMouseClick(wxWindow *parent, int x, int y, |
0b2dadd3 | 93 | const wxMouseEvent& event) |
5526e819 | 94 | { |
846914d1 VS |
95 | wxHtmlLinkInfo *lnk = GetLink(x, y); |
96 | if (lnk != NULL) | |
0b2dadd3 VS |
97 | { |
98 | wxHtmlLinkInfo lnk2(*lnk); | |
99 | lnk2.SetEvent(&event); | |
9bc8fded | 100 | lnk2.SetHtmlCell(this); |
0cb9cfb2 VZ |
101 | |
102 | // note : this cast is legal because parent is *always* wxHtmlWindow | |
103 | wxStaticCast(parent, wxHtmlWindow)->OnLinkClicked(lnk2); | |
0b2dadd3 | 104 | } |
5526e819 VS |
105 | } |
106 | ||
107 | ||
108 | ||
f2034f1b | 109 | bool wxHtmlCell::AdjustPagebreak(int *pagebreak, int* WXUNUSED(known_pagebreaks), int WXUNUSED(number_of_pages)) const |
db98870d | 110 | { |
04dbb646 VZ |
111 | if ((!m_CanLiveOnPagebreak) && |
112 | m_PosY < *pagebreak && m_PosY + m_Height > *pagebreak) | |
0cb9cfb2 | 113 | { |
db98870d | 114 | *pagebreak = m_PosY; |
db98870d VS |
115 | return TRUE; |
116 | } | |
0cb9cfb2 VZ |
117 | |
118 | return FALSE; | |
db98870d VS |
119 | } |
120 | ||
121 | ||
122 | ||
04dbb646 | 123 | void wxHtmlCell::SetLink(const wxHtmlLinkInfo& link) |
846914d1 VS |
124 | { |
125 | if (m_Link) delete m_Link; | |
af1ed0c1 VS |
126 | m_Link = NULL; |
127 | if (link.GetHref() != wxEmptyString) | |
128 | m_Link = new wxHtmlLinkInfo(link); | |
846914d1 VS |
129 | } |
130 | ||
131 | ||
db98870d | 132 | |
d699f48b | 133 | void wxHtmlCell::Layout(int WXUNUSED(w)) |
721ab905 | 134 | { |
04dbb646 | 135 | SetPos(0, 0); |
721ab905 VS |
136 | } |
137 | ||
138 | ||
79d6c018 VS |
139 | |
140 | void wxHtmlCell::GetHorizontalConstraints(int *left, int *right) const | |
141 | { | |
142 | if (left) | |
143 | *left = m_PosX; | |
144 | if (right) | |
026d1fac | 145 | *right = m_PosX + m_Width; |
79d6c018 VS |
146 | } |
147 | ||
148 | ||
149 | ||
d699f48b | 150 | const wxHtmlCell* wxHtmlCell::Find(int WXUNUSED(condition), const void* WXUNUSED(param)) const |
721ab905 | 151 | { |
bf7d7ee7 | 152 | return NULL; |
721ab905 VS |
153 | } |
154 | ||
155 | ||
36c4ff4d VS |
156 | wxHtmlCell *wxHtmlCell::FindCellByPos(wxCoord x, wxCoord y, |
157 | unsigned flags) const | |
f6010d8f | 158 | { |
adf2eb2d | 159 | if ( x >= 0 && x < m_Width && y >= 0 && y < m_Height ) |
36c4ff4d | 160 | { |
f6010d8f | 161 | return wxConstCast(this, wxHtmlCell); |
36c4ff4d | 162 | } |
adf2eb2d VS |
163 | else |
164 | { | |
165 | if ((flags & wxHTML_FIND_NEAREST_AFTER) && | |
166 | (y < 0 || (y == 0 && x <= 0))) | |
167 | return wxConstCast(this, wxHtmlCell); | |
168 | else if ((flags & wxHTML_FIND_NEAREST_BEFORE) && | |
169 | (y > m_Height-1 || (y == m_Height-1 && x >= m_Width))) | |
170 | return wxConstCast(this, wxHtmlCell); | |
171 | else | |
172 | return NULL; | |
173 | } | |
174 | } | |
175 | ||
176 | ||
177 | wxPoint wxHtmlCell::GetAbsPos() const | |
178 | { | |
179 | wxPoint p(m_PosX, m_PosY); | |
180 | for (wxHtmlCell *parent = m_Parent; parent; parent = parent->m_Parent) | |
181 | { | |
182 | p.x += parent->m_PosX; | |
183 | p.y += parent->m_PosY; | |
184 | } | |
185 | return p; | |
f6010d8f | 186 | } |
e3774124 VS |
187 | |
188 | unsigned wxHtmlCell::GetDepth() const | |
189 | { | |
190 | unsigned d = 0; | |
191 | for (wxHtmlCell *p = m_Parent; p; p = p->m_Parent) | |
192 | d++; | |
193 | return d; | |
194 | } | |
195 | ||
196 | bool wxHtmlCell::IsBefore(wxHtmlCell *cell) const | |
197 | { | |
198 | const wxHtmlCell *c1 = this; | |
199 | const wxHtmlCell *c2 = cell; | |
200 | unsigned d1 = GetDepth(); | |
201 | unsigned d2 = cell->GetDepth(); | |
202 | ||
203 | if ( d1 > d2 ) | |
204 | for (; d1 != d2; d1-- ) | |
205 | c1 = c1->m_Parent; | |
206 | else if ( d1 < d2 ) | |
207 | for (; d1 != d2; d2-- ) | |
208 | c2 = c2->m_Parent; | |
209 | ||
210 | if ( cell == this ) | |
211 | return true; | |
212 | ||
213 | while ( c1 && c2 ) | |
214 | { | |
215 | if ( c1->m_Parent == c2->m_Parent ) | |
216 | { | |
217 | while ( c1 ) | |
218 | { | |
219 | if ( c1 == c2 ) | |
220 | return true; | |
221 | c1 = c1->GetNext(); | |
222 | } | |
223 | return false; | |
224 | } | |
225 | else | |
226 | { | |
227 | c1 = c1->m_Parent; | |
228 | c2 = c2->m_Parent; | |
229 | } | |
230 | } | |
231 | ||
232 | wxFAIL_MSG(_T("Cells are in different trees")); | |
233 | return false; | |
234 | } | |
f6010d8f | 235 | |
721ab905 | 236 | |
5526e819 VS |
237 | //----------------------------------------------------------------------------- |
238 | // wxHtmlWordCell | |
239 | //----------------------------------------------------------------------------- | |
240 | ||
241 | wxHtmlWordCell::wxHtmlWordCell(const wxString& word, wxDC& dc) : wxHtmlCell() | |
242 | { | |
243 | m_Word = word; | |
5526e819 | 244 | dc.GetTextExtent(m_Word, &m_Width, &m_Height, &m_Descent); |
db98870d | 245 | SetCanLiveOnPagebreak(FALSE); |
5526e819 VS |
246 | } |
247 | ||
248 | ||
5a1597e9 VS |
249 | // Splits m_Word into up to three parts according to selection, returns |
250 | // substring before, in and after selection and the points (in relative coords) | |
251 | // where s2 and s3 start: | |
1338c59a | 252 | void wxHtmlWordCell::Split(wxDC& dc, |
5a1597e9 | 253 | const wxPoint& selFrom, const wxPoint& selTo, |
f30e67db | 254 | unsigned& pos1, unsigned& pos2) const |
5a1597e9 VS |
255 | { |
256 | wxPoint pt1 = (selFrom == wxDefaultPosition) ? | |
257 | wxDefaultPosition : selFrom - GetAbsPos(); | |
258 | wxPoint pt2 = (selTo == wxDefaultPosition) ? | |
259 | wxPoint(m_Width, -1) : selTo - GetAbsPos(); | |
260 | ||
261 | wxCoord charW, charH; | |
262 | unsigned len = m_Word.length(); | |
263 | unsigned i = 0; | |
264 | pos1 = 0; | |
5a1597e9 VS |
265 | |
266 | // before selection: | |
267 | while ( pt1.x > 0 && i < len ) | |
268 | { | |
269 | dc.GetTextExtent(m_Word[i], &charW, &charH); | |
270 | pt1.x -= charW; | |
271 | if ( pt1.x >= 0 ) | |
272 | { | |
273 | pos1 += charW; | |
274 | i++; | |
275 | } | |
276 | } | |
5526e819 | 277 | |
5a1597e9 VS |
278 | // in selection: |
279 | unsigned j = i; | |
280 | pos2 = pos1; | |
f30e67db | 281 | pt2.x -= pos2; |
5a1597e9 VS |
282 | while ( pt2.x > 0 && j < len ) |
283 | { | |
284 | dc.GetTextExtent(m_Word[j], &charW, &charH); | |
285 | pt2.x -= charW; | |
286 | if ( pt2.x >= 0 ) | |
287 | { | |
288 | pos2 += charW; | |
289 | j++; | |
290 | } | |
291 | } | |
f30e67db VS |
292 | |
293 | pos1 = i; | |
294 | pos2 = j; | |
295 | } | |
296 | ||
297 | void wxHtmlWordCell::SetSelectionPrivPos(wxDC& dc, wxHtmlSelection *s) const | |
298 | { | |
299 | unsigned p1, p2; | |
300 | ||
301 | Split(dc, | |
302 | this == s->GetFromCell() ? s->GetFromPos() : wxDefaultPosition, | |
303 | this == s->GetToCell() ? s->GetToPos() : wxDefaultPosition, | |
304 | p1, p2); | |
305 | ||
306 | wxPoint p(0, m_Word.length()); | |
5a1597e9 | 307 | |
f30e67db VS |
308 | if ( this == s->GetFromCell() ) |
309 | p.x = p1; // selection starts here | |
310 | if ( this == s->GetToCell() ) | |
311 | p.y = p2; // selection ends here | |
312 | ||
313 | if ( this == s->GetFromCell() ) | |
314 | s->SetFromPrivPos(p); | |
315 | if ( this == s->GetToCell() ) | |
316 | s->SetToPrivPos(p); | |
5a1597e9 VS |
317 | } |
318 | ||
319 | ||
f30e67db | 320 | static void SwitchSelState(wxDC& dc, wxHtmlRenderingInfo& info, |
5a1597e9 | 321 | bool toSelection) |
5526e819 | 322 | { |
f30e67db VS |
323 | wxColour fg = info.GetState().GetFgColour(); |
324 | wxColour bg = info.GetState().GetBgColour(); | |
325 | ||
5a1597e9 | 326 | if ( toSelection ) |
36c4ff4d VS |
327 | { |
328 | dc.SetBackgroundMode(wxSOLID); | |
f30e67db VS |
329 | dc.SetTextForeground(info.GetStyle().GetSelectedTextColour(fg)); |
330 | dc.SetTextBackground(info.GetStyle().GetSelectedTextBgColour(bg)); | |
36c4ff4d | 331 | } |
5a1597e9 | 332 | else |
36c4ff4d VS |
333 | { |
334 | dc.SetBackgroundMode(wxTRANSPARENT); | |
f30e67db VS |
335 | dc.SetTextForeground(fg); |
336 | dc.SetTextBackground(bg); | |
36c4ff4d | 337 | } |
5a1597e9 | 338 | } |
36c4ff4d | 339 | |
5a1597e9 VS |
340 | |
341 | void wxHtmlWordCell::Draw(wxDC& dc, int x, int y, | |
342 | int WXUNUSED(view_y1), int WXUNUSED(view_y2), | |
f30e67db | 343 | wxHtmlRenderingInfo& info) |
5a1597e9 VS |
344 | { |
345 | #if 0 // useful for debugging | |
346 | dc.DrawRectangle(x+m_PosX,y+m_PosY,m_Width,m_Height); | |
347 | #endif | |
348 | ||
f30e67db | 349 | if ( info.GetState().GetSelectionState() == wxHTML_SEL_CHANGING ) |
5a1597e9 VS |
350 | { |
351 | // Selection changing, we must draw the word piecewise: | |
f30e67db VS |
352 | wxHtmlSelection *s = info.GetSelection(); |
353 | wxString txt; | |
354 | int w, h; | |
355 | int ofs = 0; | |
bfc248a3 | 356 | |
f30e67db VS |
357 | wxPoint priv = (this == s->GetFromCell()) ? |
358 | s->GetFromPrivPos() : s->GetToPrivPos(); | |
1338c59a VS |
359 | |
360 | // NB: this is quite a hack: in order to compute selection boundaries | |
361 | // (in word's characters) we must know current font, which is only | |
362 | // possible inside rendering code. Therefore we update the | |
363 | // information here and store it in wxHtmlSelection so that | |
364 | // ConvertToText can use it later: | |
365 | if ( priv == wxDefaultPosition ) | |
366 | { | |
367 | SetSelectionPrivPos(dc, s); | |
368 | priv = (this == s->GetFromCell()) ? | |
369 | s->GetFromPrivPos() : s->GetToPrivPos(); | |
370 | } | |
371 | ||
f30e67db VS |
372 | int part1 = priv.x; |
373 | int part2 = priv.y; | |
374 | ||
375 | if ( part1 > 0 ) | |
5a1597e9 | 376 | { |
f30e67db VS |
377 | txt = m_Word.Mid(0, part1); |
378 | dc.DrawText(txt, x + m_PosX, y + m_PosY); | |
379 | dc.GetTextExtent(txt, &w, &h); | |
380 | ofs += w; | |
5a1597e9 | 381 | } |
f30e67db VS |
382 | |
383 | SwitchSelState(dc, info, true); | |
384 | ||
385 | txt = m_Word.Mid(part1, part2-part1); | |
386 | dc.DrawText(txt, ofs + x + m_PosX, y + m_PosY); | |
387 | ||
70bae016 | 388 | if ( (size_t)part2 < m_Word.length() ) |
5a1597e9 | 389 | { |
f30e67db VS |
390 | dc.GetTextExtent(txt, &w, &h); |
391 | ofs += w; | |
392 | SwitchSelState(dc, info, false); | |
393 | txt = m_Word.Mid(part2); | |
394 | dc.DrawText(txt, ofs + x + m_PosX, y + m_PosY); | |
5a1597e9 VS |
395 | } |
396 | } | |
397 | else | |
398 | { | |
399 | // Not changing selection state, draw the word in single mode: | |
400 | ||
f30e67db | 401 | if ( info.GetState().GetSelectionState() != wxHTML_SEL_OUT && |
5a1597e9 VS |
402 | dc.GetBackgroundMode() != wxSOLID ) |
403 | { | |
f30e67db | 404 | SwitchSelState(dc, info, true); |
5a1597e9 | 405 | } |
f30e67db | 406 | else if ( info.GetState().GetSelectionState() == wxHTML_SEL_OUT && |
5a1597e9 VS |
407 | dc.GetBackgroundMode() == wxSOLID ) |
408 | { | |
f30e67db | 409 | SwitchSelState(dc, info, false); |
5a1597e9 VS |
410 | } |
411 | dc.DrawText(m_Word, x + m_PosX, y + m_PosY); | |
412 | } | |
5526e819 | 413 | } |
e3774124 VS |
414 | |
415 | ||
f30e67db | 416 | wxString wxHtmlWordCell::ConvertToText(wxHtmlSelection *s) const |
e3774124 | 417 | { |
f30e67db VS |
418 | if ( s && (this == s->GetFromCell() || this == s->GetToCell()) ) |
419 | { | |
420 | wxPoint priv = (this == s->GetFromCell()) ? | |
421 | s->GetFromPrivPos() : s->GetToPrivPos(); | |
422 | int part1 = priv.x; | |
423 | int part2 = priv.y; | |
424 | return m_Word.Mid(part1, part2-part1); | |
425 | } | |
426 | else | |
427 | return m_Word; | |
e3774124 | 428 | } |
5526e819 VS |
429 | |
430 | ||
431 | ||
5526e819 VS |
432 | //----------------------------------------------------------------------------- |
433 | // wxHtmlContainerCell | |
434 | //----------------------------------------------------------------------------- | |
435 | ||
436 | ||
437 | wxHtmlContainerCell::wxHtmlContainerCell(wxHtmlContainerCell *parent) : wxHtmlCell() | |
438 | { | |
439 | m_Cells = m_LastCell = NULL; | |
440 | m_Parent = parent; | |
4f9297b0 | 441 | if (m_Parent) m_Parent->InsertCell(this); |
efba2b89 VS |
442 | m_AlignHor = wxHTML_ALIGN_LEFT; |
443 | m_AlignVer = wxHTML_ALIGN_BOTTOM; | |
5526e819 | 444 | m_IndentLeft = m_IndentRight = m_IndentTop = m_IndentBottom = 0; |
efba2b89 | 445 | m_WidthFloat = 100; m_WidthFloatUnits = wxHTML_UNITS_PERCENT; |
5526e819 VS |
446 | m_UseBkColour = FALSE; |
447 | m_UseBorder = FALSE; | |
5c1bfc5d | 448 | m_MinHeight = 0; |
efba2b89 | 449 | m_MinHeightAlign = wxHTML_ALIGN_TOP; |
5660c520 | 450 | m_LastLayout = -1; |
5526e819 VS |
451 | } |
452 | ||
04dbb646 | 453 | wxHtmlContainerCell::~wxHtmlContainerCell() |
721ab905 | 454 | { |
491c9920 VZ |
455 | wxHtmlCell *cell = m_Cells; |
456 | while ( cell ) | |
bf7d7ee7 | 457 | { |
491c9920 VZ |
458 | wxHtmlCell *cellNext = cell->GetNext(); |
459 | delete cell; | |
460 | cell = cellNext; | |
bf7d7ee7 | 461 | } |
721ab905 VS |
462 | } |
463 | ||
5526e819 VS |
464 | |
465 | ||
466 | void wxHtmlContainerCell::SetIndent(int i, int what, int units) | |
467 | { | |
efba2b89 VS |
468 | int val = (units == wxHTML_UNITS_PIXELS) ? i : -i; |
469 | if (what & wxHTML_INDENT_LEFT) m_IndentLeft = val; | |
470 | if (what & wxHTML_INDENT_RIGHT) m_IndentRight = val; | |
471 | if (what & wxHTML_INDENT_TOP) m_IndentTop = val; | |
472 | if (what & wxHTML_INDENT_BOTTOM) m_IndentBottom = val; | |
5660c520 | 473 | m_LastLayout = -1; |
5526e819 VS |
474 | } |
475 | ||
476 | ||
477 | ||
478 | int wxHtmlContainerCell::GetIndent(int ind) const | |
479 | { | |
efba2b89 VS |
480 | if (ind & wxHTML_INDENT_LEFT) return m_IndentLeft; |
481 | else if (ind & wxHTML_INDENT_RIGHT) return m_IndentRight; | |
482 | else if (ind & wxHTML_INDENT_TOP) return m_IndentTop; | |
483 | else if (ind & wxHTML_INDENT_BOTTOM) return m_IndentBottom; | |
5526e819 VS |
484 | else return -1; /* BUG! Should not be called... */ |
485 | } | |
486 | ||
487 | ||
488 | ||
489 | ||
490 | int wxHtmlContainerCell::GetIndentUnits(int ind) const | |
491 | { | |
492 | bool p = FALSE; | |
efba2b89 VS |
493 | if (ind & wxHTML_INDENT_LEFT) p = m_IndentLeft < 0; |
494 | else if (ind & wxHTML_INDENT_RIGHT) p = m_IndentRight < 0; | |
495 | else if (ind & wxHTML_INDENT_TOP) p = m_IndentTop < 0; | |
496 | else if (ind & wxHTML_INDENT_BOTTOM) p = m_IndentBottom < 0; | |
497 | if (p) return wxHTML_UNITS_PERCENT; | |
498 | else return wxHTML_UNITS_PIXELS; | |
5526e819 VS |
499 | } |
500 | ||
501 | ||
502 | ||
f2034f1b | 503 | bool wxHtmlContainerCell::AdjustPagebreak(int *pagebreak, int* known_pagebreaks, int number_of_pages) const |
db98870d | 504 | { |
04dbb646 | 505 | if (!m_CanLiveOnPagebreak) |
f2034f1b | 506 | return wxHtmlCell::AdjustPagebreak(pagebreak, known_pagebreaks, number_of_pages); |
e52d6dbc | 507 | |
04dbb646 | 508 | else |
4f9297b0 | 509 | { |
e3774124 | 510 | wxHtmlCell *c = GetFirstChild(); |
db98870d | 511 | bool rt = FALSE; |
e52d6dbc | 512 | int pbrk = *pagebreak - m_PosY; |
db98870d | 513 | |
04dbb646 | 514 | while (c) |
0cb9cfb2 | 515 | { |
f2034f1b | 516 | if (c->AdjustPagebreak(&pbrk, known_pagebreaks, number_of_pages)) |
bf7d7ee7 | 517 | rt = TRUE; |
4f9297b0 | 518 | c = c->GetNext(); |
db98870d | 519 | } |
d699f48b | 520 | if (rt) |
bf7d7ee7 | 521 | *pagebreak = pbrk + m_PosY; |
db98870d VS |
522 | return rt; |
523 | } | |
524 | } | |
525 | ||
526 | ||
527 | ||
5526e819 VS |
528 | void wxHtmlContainerCell::Layout(int w) |
529 | { | |
026d1fac VS |
530 | wxHtmlCell::Layout(w); |
531 | ||
532 | if (m_LastLayout == w) return; | |
0cb9cfb2 | 533 | |
026d1fac VS |
534 | // VS: Any attempt to layout with negative or zero width leads to hell, |
535 | // but we can't ignore such attempts completely, since it sometimes | |
536 | // happen (e.g. when trying how small a table can be). The best thing we | |
537 | // can do is to set the width of child cells to zero | |
0cb9cfb2 | 538 | if (w < 1) |
4f9297b0 | 539 | { |
026d1fac VS |
540 | m_Width = 0; |
541 | for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) | |
542 | cell->Layout(0); | |
2b5f62a0 VZ |
543 | // this does two things: it recursively calls this code on all |
544 | // child contrainers and resets children's position to (0,0) | |
026d1fac | 545 | return; |
04dbb646 | 546 | } |
5660c520 | 547 | |
5526e819 VS |
548 | wxHtmlCell *cell = m_Cells, *line = m_Cells; |
549 | long xpos = 0, ypos = m_IndentTop; | |
550 | int xdelta = 0, ybasicpos = 0, ydiff; | |
551 | int s_width, s_indent; | |
552 | int ysizeup = 0, ysizedown = 0; | |
5c1bfc5d VS |
553 | int MaxLineWidth = 0; |
554 | int xcnt = 0; | |
555 | ||
5526e819 VS |
556 | |
557 | /* | |
7e941458 | 558 | |
5526e819 | 559 | WIDTH ADJUSTING : |
7e941458 | 560 | |
5526e819 VS |
561 | */ |
562 | ||
04dbb646 | 563 | if (m_WidthFloatUnits == wxHTML_UNITS_PERCENT) |
4f9297b0 | 564 | { |
5526e819 VS |
565 | if (m_WidthFloat < 0) m_Width = (100 + m_WidthFloat) * w / 100; |
566 | else m_Width = m_WidthFloat * w / 100; | |
567 | } | |
04dbb646 | 568 | else |
4f9297b0 | 569 | { |
5526e819 VS |
570 | if (m_WidthFloat < 0) m_Width = w + m_WidthFloat; |
571 | else m_Width = m_WidthFloat; | |
572 | } | |
573 | ||
04dbb646 | 574 | if (m_Cells) |
4f9297b0 | 575 | { |
5526e819 VS |
576 | int l = (m_IndentLeft < 0) ? (-m_IndentLeft * m_Width / 100) : m_IndentLeft; |
577 | int r = (m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight; | |
bf7d7ee7 VS |
578 | for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) |
579 | cell->Layout(m_Width - (l + r)); | |
5526e819 VS |
580 | } |
581 | ||
582 | /* | |
583 | ||
584 | LAYOUTING : | |
7e941458 | 585 | |
5526e819 VS |
586 | */ |
587 | ||
588 | // adjust indentation: | |
589 | s_indent = (m_IndentLeft < 0) ? (-m_IndentLeft * m_Width / 100) : m_IndentLeft; | |
590 | s_width = m_Width - s_indent - ((m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight); | |
591 | ||
5526e819 | 592 | // my own layouting: |
04dbb646 | 593 | while (cell != NULL) |
4f9297b0 | 594 | { |
04dbb646 | 595 | switch (m_AlignVer) |
0cb9cfb2 | 596 | { |
efba2b89 | 597 | case wxHTML_ALIGN_TOP : ybasicpos = 0; break; |
4f9297b0 VS |
598 | case wxHTML_ALIGN_BOTTOM : ybasicpos = - cell->GetHeight(); break; |
599 | case wxHTML_ALIGN_CENTER : ybasicpos = - cell->GetHeight() / 2; break; | |
5526e819 | 600 | } |
4f9297b0 | 601 | ydiff = cell->GetHeight() + ybasicpos; |
5526e819 | 602 | |
4f9297b0 VS |
603 | if (cell->GetDescent() + ydiff > ysizedown) ysizedown = cell->GetDescent() + ydiff; |
604 | if (ybasicpos + cell->GetDescent() < -ysizeup) ysizeup = - (ybasicpos + cell->GetDescent()); | |
5526e819 | 605 | |
4f9297b0 VS |
606 | cell->SetPos(xpos, ybasicpos + cell->GetDescent()); |
607 | xpos += cell->GetWidth(); | |
608 | cell = cell->GetNext(); | |
5c1bfc5d | 609 | xcnt++; |
5526e819 VS |
610 | |
611 | // force new line if occured: | |
04dbb646 | 612 | if ((cell == NULL) || (xpos + cell->GetWidth() > s_width)) |
0cb9cfb2 | 613 | { |
5c1bfc5d | 614 | if (xpos > MaxLineWidth) MaxLineWidth = xpos; |
5526e819 VS |
615 | if (ysizeup < 0) ysizeup = 0; |
616 | if (ysizedown < 0) ysizedown = 0; | |
617 | switch (m_AlignHor) { | |
04dbb646 VZ |
618 | case wxHTML_ALIGN_LEFT : |
619 | case wxHTML_ALIGN_JUSTIFY : | |
620 | xdelta = 0; | |
5c1bfc5d | 621 | break; |
04dbb646 VZ |
622 | case wxHTML_ALIGN_RIGHT : |
623 | xdelta = 0 + (s_width - xpos); | |
5c1bfc5d | 624 | break; |
04dbb646 VZ |
625 | case wxHTML_ALIGN_CENTER : |
626 | xdelta = 0 + (s_width - xpos) / 2; | |
5c1bfc5d | 627 | break; |
5526e819 VS |
628 | } |
629 | if (xdelta < 0) xdelta = 0; | |
630 | xdelta += s_indent; | |
631 | ||
632 | ypos += ysizeup; | |
04dbb646 | 633 | |
5c1bfc5d | 634 | if (m_AlignHor != wxHTML_ALIGN_JUSTIFY || cell == NULL) |
04dbb646 | 635 | while (line != cell) |
0cb9cfb2 | 636 | { |
04dbb646 | 637 | line->SetPos(line->GetPosX() + xdelta, |
4f9297b0 VS |
638 | ypos + line->GetPosY()); |
639 | line = line->GetNext(); | |
5c1bfc5d VS |
640 | } |
641 | else | |
04dbb646 | 642 | { |
5c1bfc5d VS |
643 | int counter = 0; |
644 | int step = (s_width - xpos); | |
645 | if (step < 0) step = 0; | |
c1e5e881 | 646 | xcnt--; |
04dbb646 | 647 | if (xcnt > 0) while (line != cell) |
0cb9cfb2 | 648 | { |
4f9297b0 | 649 | line->SetPos(line->GetPosX() + s_indent + |
5c1bfc5d | 650 | (counter++ * step / xcnt), |
4f9297b0 VS |
651 | ypos + line->GetPosY()); |
652 | line = line->GetNext(); | |
5c1bfc5d | 653 | } |
c1e5e881 | 654 | xcnt++; |
5526e819 VS |
655 | } |
656 | ||
657 | ypos += ysizedown; | |
5c1bfc5d | 658 | xpos = xcnt = 0; |
5526e819 VS |
659 | ysizeup = ysizedown = 0; |
660 | line = cell; | |
661 | } | |
662 | } | |
663 | ||
664 | // setup height & width, depending on container layout: | |
665 | m_Height = ypos + (ysizedown + ysizeup) + m_IndentBottom; | |
666 | ||
04dbb646 | 667 | if (m_Height < m_MinHeight) |
4f9297b0 | 668 | { |
04dbb646 | 669 | if (m_MinHeightAlign != wxHTML_ALIGN_TOP) |
0cb9cfb2 | 670 | { |
5526e819 | 671 | int diff = m_MinHeight - m_Height; |
efba2b89 | 672 | if (m_MinHeightAlign == wxHTML_ALIGN_CENTER) diff /= 2; |
5526e819 | 673 | cell = m_Cells; |
04dbb646 | 674 | while (cell) |
0cb9cfb2 | 675 | { |
4f9297b0 VS |
676 | cell->SetPos(cell->GetPosX(), cell->GetPosY() + diff); |
677 | cell = cell->GetNext(); | |
5526e819 VS |
678 | } |
679 | } | |
680 | m_Height = m_MinHeight; | |
681 | } | |
682 | ||
5c1bfc5d VS |
683 | MaxLineWidth += s_indent + ((m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight); |
684 | if (m_Width < MaxLineWidth) m_Width = MaxLineWidth; | |
5526e819 | 685 | |
5660c520 | 686 | m_LastLayout = w; |
5526e819 VS |
687 | } |
688 | ||
f30e67db | 689 | void wxHtmlContainerCell::UpdateRenderingStatePre(wxHtmlRenderingInfo& info, |
36c4ff4d VS |
690 | wxHtmlCell *cell) const |
691 | { | |
f30e67db | 692 | wxHtmlSelection *s = info.GetSelection(); |
36c4ff4d | 693 | if (!s) return; |
cd275246 | 694 | if (s->GetFromCell() == cell || s->GetToCell() == cell) |
36c4ff4d | 695 | { |
f30e67db | 696 | info.GetState().SetSelectionState(wxHTML_SEL_CHANGING); |
36c4ff4d VS |
697 | } |
698 | } | |
699 | ||
f30e67db | 700 | void wxHtmlContainerCell::UpdateRenderingStatePost(wxHtmlRenderingInfo& info, |
36c4ff4d VS |
701 | wxHtmlCell *cell) const |
702 | { | |
f30e67db | 703 | wxHtmlSelection *s = info.GetSelection(); |
36c4ff4d | 704 | if (!s) return; |
adf2eb2d | 705 | if (s->GetToCell() == cell) |
f30e67db | 706 | info.GetState().SetSelectionState(wxHTML_SEL_OUT); |
adf2eb2d | 707 | else if (s->GetFromCell() == cell) |
f30e67db | 708 | info.GetState().SetSelectionState(wxHTML_SEL_IN); |
36c4ff4d | 709 | } |
5526e819 VS |
710 | |
711 | #define mMin(a, b) (((a) < (b)) ? (a) : (b)) | |
712 | #define mMax(a, b) (((a) < (b)) ? (b) : (a)) | |
713 | ||
36c4ff4d | 714 | void wxHtmlContainerCell::Draw(wxDC& dc, int x, int y, int view_y1, int view_y2, |
f30e67db | 715 | wxHtmlRenderingInfo& info) |
5526e819 | 716 | { |
94bc8b14 VS |
717 | // container visible, draw it: |
718 | if ((y + m_PosY <= view_y2) && (y + m_PosY + m_Height > view_y1)) | |
4f9297b0 | 719 | { |
04dbb646 | 720 | if (m_UseBkColour) |
0cb9cfb2 | 721 | { |
5526e819 VS |
722 | wxBrush myb = wxBrush(m_BkColour, wxSOLID); |
723 | ||
724 | int real_y1 = mMax(y + m_PosY, view_y1); | |
725 | int real_y2 = mMin(y + m_PosY + m_Height - 1, view_y2); | |
726 | ||
727 | dc.SetBrush(myb); | |
728 | dc.SetPen(*wxTRANSPARENT_PEN); | |
729 | dc.DrawRectangle(x + m_PosX, real_y1, m_Width, real_y2 - real_y1 + 1); | |
730 | } | |
731 | ||
04dbb646 | 732 | if (m_UseBorder) |
0cb9cfb2 | 733 | { |
5526e819 VS |
734 | wxPen mypen1(m_BorderColour1, 1, wxSOLID); |
735 | wxPen mypen2(m_BorderColour2, 1, wxSOLID); | |
736 | ||
737 | dc.SetPen(mypen1); | |
738 | dc.DrawLine(x + m_PosX, y + m_PosY, x + m_PosX, y + m_PosY + m_Height - 1); | |
5f265f87 | 739 | dc.DrawLine(x + m_PosX, y + m_PosY, x + m_PosX + m_Width, y + m_PosY); |
5526e819 VS |
740 | dc.SetPen(mypen2); |
741 | dc.DrawLine(x + m_PosX + m_Width - 1, y + m_PosY, x + m_PosX + m_Width - 1, y + m_PosY + m_Height - 1); | |
5f265f87 | 742 | dc.DrawLine(x + m_PosX, y + m_PosY + m_Height - 1, x + m_PosX + m_Width, y + m_PosY + m_Height - 1); |
5526e819 VS |
743 | } |
744 | ||
d699f48b | 745 | if (m_Cells) |
bf7d7ee7 | 746 | { |
36c4ff4d | 747 | // draw container's contents: |
bf7d7ee7 | 748 | for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) |
36c4ff4d | 749 | { |
f30e67db | 750 | UpdateRenderingStatePre(info, cell); |
36c4ff4d VS |
751 | cell->Draw(dc, |
752 | x + m_PosX, y + m_PosY, view_y1, view_y2, | |
f30e67db VS |
753 | info); |
754 | UpdateRenderingStatePost(info, cell); | |
36c4ff4d | 755 | } |
bf7d7ee7 | 756 | } |
5526e819 VS |
757 | } |
758 | // container invisible, just proceed font+color changing: | |
04dbb646 | 759 | else |
4f9297b0 | 760 | { |
f30e67db | 761 | DrawInvisible(dc, x, y, info); |
5526e819 | 762 | } |
5526e819 VS |
763 | } |
764 | ||
765 | ||
766 | ||
36c4ff4d | 767 | void wxHtmlContainerCell::DrawInvisible(wxDC& dc, int x, int y, |
f30e67db | 768 | wxHtmlRenderingInfo& info) |
5526e819 | 769 | { |
d699f48b | 770 | if (m_Cells) |
bf7d7ee7 VS |
771 | { |
772 | for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) | |
36c4ff4d | 773 | { |
f30e67db VS |
774 | UpdateRenderingStatePre(info, cell); |
775 | cell->DrawInvisible(dc, x + m_PosX, y + m_PosY, info); | |
776 | UpdateRenderingStatePost(info, cell); | |
36c4ff4d | 777 | } |
bf7d7ee7 | 778 | } |
5526e819 VS |
779 | } |
780 | ||
781 | ||
2b5f62a0 VZ |
782 | wxColour wxHtmlContainerCell::GetBackgroundColour() |
783 | { | |
784 | if (m_UseBkColour) | |
785 | return m_BkColour; | |
786 | else | |
787 | return wxNullColour; | |
788 | } | |
789 | ||
790 | ||
5526e819 | 791 | |
846914d1 | 792 | wxHtmlLinkInfo *wxHtmlContainerCell::GetLink(int x, int y) const |
5526e819 | 793 | { |
f6010d8f | 794 | wxHtmlCell *cell = FindCellByPos(x, y); |
5526e819 | 795 | |
f6010d8f VZ |
796 | // VZ: I don't know if we should pass absolute or relative coords to |
797 | // wxHtmlCell::GetLink()? As the base class version just ignores them | |
798 | // anyhow, it hardly matters right now but should still be clarified | |
799 | return cell ? cell->GetLink(x, y) : NULL; | |
5526e819 VS |
800 | } |
801 | ||
802 | ||
803 | ||
804 | void wxHtmlContainerCell::InsertCell(wxHtmlCell *f) | |
805 | { | |
806 | if (!m_Cells) m_Cells = m_LastCell = f; | |
04dbb646 | 807 | else |
4f9297b0 VS |
808 | { |
809 | m_LastCell->SetNext(f); | |
5526e819 | 810 | m_LastCell = f; |
4f9297b0 | 811 | if (m_LastCell) while (m_LastCell->GetNext()) m_LastCell = m_LastCell->GetNext(); |
5526e819 | 812 | } |
4f9297b0 | 813 | f->SetParent(this); |
5660c520 | 814 | m_LastLayout = -1; |
5526e819 VS |
815 | } |
816 | ||
817 | ||
818 | ||
819 | void wxHtmlContainerCell::SetAlign(const wxHtmlTag& tag) | |
820 | { | |
04dbb646 | 821 | if (tag.HasParam(wxT("ALIGN"))) |
4f9297b0 | 822 | { |
0413cec5 | 823 | wxString alg = tag.GetParam(wxT("ALIGN")); |
5526e819 | 824 | alg.MakeUpper(); |
0413cec5 | 825 | if (alg == wxT("CENTER")) |
efba2b89 | 826 | SetAlignHor(wxHTML_ALIGN_CENTER); |
0413cec5 | 827 | else if (alg == wxT("LEFT")) |
efba2b89 | 828 | SetAlignHor(wxHTML_ALIGN_LEFT); |
5c1bfc5d VS |
829 | else if (alg == wxT("JUSTIFY")) |
830 | SetAlignHor(wxHTML_ALIGN_JUSTIFY); | |
0413cec5 | 831 | else if (alg == wxT("RIGHT")) |
efba2b89 | 832 | SetAlignHor(wxHTML_ALIGN_RIGHT); |
5660c520 | 833 | m_LastLayout = -1; |
5526e819 VS |
834 | } |
835 | } | |
836 | ||
837 | ||
838 | ||
edbd0635 | 839 | void wxHtmlContainerCell::SetWidthFloat(const wxHtmlTag& tag, double pixel_scale) |
5526e819 | 840 | { |
04dbb646 | 841 | if (tag.HasParam(wxT("WIDTH"))) |
4f9297b0 | 842 | { |
5526e819 | 843 | int wdi; |
0413cec5 | 844 | wxString wd = tag.GetParam(wxT("WIDTH")); |
5526e819 | 845 | |
04dbb646 | 846 | if (wd[wd.Length()-1] == wxT('%')) |
0cb9cfb2 | 847 | { |
66a77a74 | 848 | wxSscanf(wd.c_str(), wxT("%i%%"), &wdi); |
efba2b89 | 849 | SetWidthFloat(wdi, wxHTML_UNITS_PERCENT); |
5526e819 | 850 | } |
04dbb646 | 851 | else |
0cb9cfb2 | 852 | { |
66a77a74 | 853 | wxSscanf(wd.c_str(), wxT("%i"), &wdi); |
edbd0635 | 854 | SetWidthFloat((int)(pixel_scale * (double)wdi), wxHTML_UNITS_PIXELS); |
5526e819 | 855 | } |
5660c520 | 856 | m_LastLayout = -1; |
5526e819 VS |
857 | } |
858 | } | |
859 | ||
860 | ||
861 | ||
862 | const wxHtmlCell* wxHtmlContainerCell::Find(int condition, const void* param) const | |
863 | { | |
04dbb646 | 864 | if (m_Cells) |
d699f48b | 865 | { |
bf7d7ee7 | 866 | const wxHtmlCell *r = NULL; |
5526e819 | 867 | |
bf7d7ee7 VS |
868 | for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) |
869 | { | |
870 | r = cell->Find(condition, param); | |
871 | if (r) return r; | |
872 | } | |
873 | } | |
874 | return NULL; | |
5526e819 VS |
875 | } |
876 | ||
877 | ||
36c4ff4d VS |
878 | wxHtmlCell *wxHtmlContainerCell::FindCellByPos(wxCoord x, wxCoord y, |
879 | unsigned flags) const | |
5526e819 | 880 | { |
6d41981d | 881 | if ( flags & wxHTML_FIND_EXACT ) |
4f9297b0 | 882 | { |
adf2eb2d VS |
883 | for ( const wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext() ) |
884 | { | |
885 | int cx = cell->GetPosX(), | |
886 | cy = cell->GetPosY(); | |
887 | ||
888 | if ( (cx <= x) && (cx + cell->GetWidth() > x) && | |
889 | (cy <= y) && (cy + cell->GetHeight() > y) ) | |
890 | { | |
891 | return cell->FindCellByPos(x - cx, y - cy, flags); | |
892 | } | |
893 | } | |
adf2eb2d | 894 | } |
6d41981d | 895 | else if ( flags & wxHTML_FIND_NEAREST_AFTER ) |
adf2eb2d VS |
896 | { |
897 | wxHtmlCell *c; | |
898 | int y2; | |
899 | for ( const wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext() ) | |
0cb9cfb2 | 900 | { |
adf2eb2d VS |
901 | y2 = cell->GetPosY() + cell->GetHeight() - 1; |
902 | if (y2 < y || (y2 == y && cell->GetPosX()+cell->GetWidth()-1 < x)) | |
903 | continue; | |
904 | c = cell->FindCellByPos(x - cell->GetPosX(), y - cell->GetPosY(), | |
905 | flags); | |
906 | if (c) return c; | |
5526e819 VS |
907 | } |
908 | } | |
6d41981d | 909 | else if ( flags & wxHTML_FIND_NEAREST_BEFORE ) |
adf2eb2d | 910 | { |
e24529d7 | 911 | wxHtmlCell *c2, *c = NULL; |
adf2eb2d VS |
912 | for ( const wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext() ) |
913 | { | |
914 | if (cell->GetPosY() > y || | |
915 | (cell->GetPosY() == y && cell->GetPosX() > x)) | |
916 | break; | |
e24529d7 VS |
917 | c2 = cell->FindCellByPos(x - cell->GetPosX(), y - cell->GetPosY(), |
918 | flags); | |
919 | if (c2) | |
920 | c = c2; | |
adf2eb2d | 921 | } |
e24529d7 | 922 | if (c) return c; |
adf2eb2d | 923 | } |
6d41981d VZ |
924 | |
925 | return NULL; | |
f6010d8f VZ |
926 | } |
927 | ||
928 | ||
929 | void wxHtmlContainerCell::OnMouseClick(wxWindow *parent, int x, int y, const wxMouseEvent& event) | |
930 | { | |
931 | wxHtmlCell *cell = FindCellByPos(x, y); | |
932 | if ( cell ) | |
933 | cell->OnMouseClick(parent, x, y, event); | |
5526e819 VS |
934 | } |
935 | ||
936 | ||
937 | ||
79d6c018 VS |
938 | void wxHtmlContainerCell::GetHorizontalConstraints(int *left, int *right) const |
939 | { | |
940 | int cleft = m_PosX + m_Width, cright = m_PosX; // worst case | |
941 | int l, r; | |
0cb9cfb2 | 942 | |
79d6c018 VS |
943 | for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) |
944 | { | |
945 | cell->GetHorizontalConstraints(&l, &r); | |
946 | if (l < cleft) | |
947 | cleft = l; | |
948 | if (r > cright) | |
949 | cright = r; | |
0cb9cfb2 | 950 | } |
79d6c018 | 951 | |
026d1fac VS |
952 | cleft -= (m_IndentLeft < 0) ? (-m_IndentLeft * m_Width / 100) : m_IndentLeft; |
953 | cright += (m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight; | |
954 | ||
79d6c018 VS |
955 | if (left) |
956 | *left = cleft; | |
957 | if (right) | |
958 | *right = cright; | |
959 | } | |
960 | ||
adf2eb2d VS |
961 | |
962 | wxHtmlCell *wxHtmlContainerCell::GetFirstTerminal() const | |
963 | { | |
e3774124 VS |
964 | if ( m_Cells ) |
965 | { | |
966 | wxHtmlCell *c2; | |
967 | for (wxHtmlCell *c = m_Cells; c; c = c->GetNext()) | |
968 | { | |
969 | c2 = c->GetFirstTerminal(); | |
970 | if ( c2 ) | |
971 | return c2; | |
972 | } | |
973 | } | |
974 | return NULL; | |
adf2eb2d VS |
975 | } |
976 | ||
977 | wxHtmlCell *wxHtmlContainerCell::GetLastTerminal() const | |
978 | { | |
e3774124 | 979 | if ( m_Cells ) |
adf2eb2d | 980 | { |
e3774124 | 981 | // most common case first: |
4ce19ed7 | 982 | wxHtmlCell *c = m_LastCell->GetLastTerminal(); |
e3774124 VS |
983 | if ( c ) |
984 | return c; | |
4ce19ed7 VZ |
985 | |
986 | wxHtmlCell *c2 = NULL; | |
987 | for (c = m_Cells; c; c = c->GetNext()) | |
e3774124 VS |
988 | c2 = c->GetLastTerminal(); |
989 | return c2; | |
adf2eb2d VS |
990 | } |
991 | else | |
992 | return NULL; | |
993 | } | |
79d6c018 VS |
994 | |
995 | ||
5526e819 VS |
996 | |
997 | ||
36c4ff4d | 998 | // -------------------------------------------------------------------------- |
5526e819 | 999 | // wxHtmlColourCell |
36c4ff4d | 1000 | // -------------------------------------------------------------------------- |
5526e819 | 1001 | |
36c4ff4d VS |
1002 | void wxHtmlColourCell::Draw(wxDC& dc, |
1003 | int x, int y, | |
1004 | int WXUNUSED(view_y1), int WXUNUSED(view_y2), | |
f30e67db | 1005 | wxHtmlRenderingInfo& info) |
5526e819 | 1006 | { |
f30e67db | 1007 | DrawInvisible(dc, x, y, info); |
5526e819 VS |
1008 | } |
1009 | ||
36c4ff4d VS |
1010 | void wxHtmlColourCell::DrawInvisible(wxDC& dc, |
1011 | int WXUNUSED(x), int WXUNUSED(y), | |
f30e67db | 1012 | wxHtmlRenderingInfo& info) |
5526e819 | 1013 | { |
f30e67db | 1014 | wxHtmlRenderingState& state = info.GetState(); |
efba2b89 | 1015 | if (m_Flags & wxHTML_CLR_FOREGROUND) |
36c4ff4d VS |
1016 | { |
1017 | state.SetFgColour(m_Colour); | |
1018 | if (state.GetSelectionState() != wxHTML_SEL_IN) | |
bfc248a3 VS |
1019 | dc.SetTextForeground(m_Colour); |
1020 | else | |
1021 | dc.SetTextForeground( | |
1022 | info.GetStyle().GetSelectedTextColour(m_Colour)); | |
36c4ff4d | 1023 | } |
04dbb646 | 1024 | if (m_Flags & wxHTML_CLR_BACKGROUND) |
4f9297b0 | 1025 | { |
36c4ff4d VS |
1026 | state.SetBgColour(m_Colour); |
1027 | if (state.GetSelectionState() != wxHTML_SEL_IN) | |
1028 | dc.SetTextBackground(m_Colour); | |
bfc248a3 VS |
1029 | else |
1030 | dc.SetTextBackground( | |
1031 | info.GetStyle().GetSelectedTextBgColour(m_Colour)); | |
5526e819 | 1032 | dc.SetBackground(wxBrush(m_Colour, wxSOLID)); |
5526e819 | 1033 | } |
5526e819 VS |
1034 | } |
1035 | ||
1036 | ||
1037 | ||
1038 | ||
36c4ff4d | 1039 | // --------------------------------------------------------------------------- |
5526e819 | 1040 | // wxHtmlFontCell |
36c4ff4d | 1041 | // --------------------------------------------------------------------------- |
5526e819 | 1042 | |
36c4ff4d VS |
1043 | void wxHtmlFontCell::Draw(wxDC& dc, |
1044 | int WXUNUSED(x), int WXUNUSED(y), | |
1045 | int WXUNUSED(view_y1), int WXUNUSED(view_y2), | |
f30e67db | 1046 | wxHtmlRenderingInfo& WXUNUSED(info)) |
5526e819 | 1047 | { |
921d0fb1 | 1048 | dc.SetFont(m_Font); |
5526e819 VS |
1049 | } |
1050 | ||
36c4ff4d | 1051 | void wxHtmlFontCell::DrawInvisible(wxDC& dc, int WXUNUSED(x), int WXUNUSED(y), |
f30e67db | 1052 | wxHtmlRenderingInfo& WXUNUSED(info)) |
5526e819 | 1053 | { |
921d0fb1 | 1054 | dc.SetFont(m_Font); |
5526e819 VS |
1055 | } |
1056 | ||
1057 | ||
1058 | ||
1059 | ||
1060 | ||
1061 | ||
1062 | ||
1063 | ||
36c4ff4d | 1064 | // --------------------------------------------------------------------------- |
5526e819 | 1065 | // wxHtmlWidgetCell |
36c4ff4d | 1066 | // --------------------------------------------------------------------------- |
5526e819 VS |
1067 | |
1068 | wxHtmlWidgetCell::wxHtmlWidgetCell(wxWindow *wnd, int w) | |
1069 | { | |
1070 | int sx, sy; | |
1071 | m_Wnd = wnd; | |
4f9297b0 | 1072 | m_Wnd->GetSize(&sx, &sy); |
5526e819 VS |
1073 | m_Width = sx, m_Height = sy; |
1074 | m_WidthFloat = w; | |
1075 | } | |
1076 | ||
1077 | ||
36c4ff4d VS |
1078 | void wxHtmlWidgetCell::Draw(wxDC& WXUNUSED(dc), |
1079 | int WXUNUSED(x), int WXUNUSED(y), | |
1080 | int WXUNUSED(view_y1), int WXUNUSED(view_y2), | |
f30e67db | 1081 | wxHtmlRenderingInfo& WXUNUSED(info)) |
5526e819 VS |
1082 | { |
1083 | int absx = 0, absy = 0, stx, sty; | |
1084 | wxHtmlCell *c = this; | |
1085 | ||
04dbb646 | 1086 | while (c) |
4f9297b0 VS |
1087 | { |
1088 | absx += c->GetPosX(); | |
1089 | absy += c->GetPosY(); | |
1090 | c = c->GetParent(); | |
5526e819 VS |
1091 | } |
1092 | ||
e421922f | 1093 | ((wxScrolledWindow*)(m_Wnd->GetParent()))->GetViewStart(&stx, &sty); |
4f9297b0 | 1094 | m_Wnd->SetSize(absx - wxHTML_SCROLL_STEP * stx, absy - wxHTML_SCROLL_STEP * sty, m_Width, m_Height); |
5526e819 VS |
1095 | } |
1096 | ||
1097 | ||
1098 | ||
36c4ff4d VS |
1099 | void wxHtmlWidgetCell::DrawInvisible(wxDC& WXUNUSED(dc), |
1100 | int WXUNUSED(x), int WXUNUSED(y), | |
f30e67db | 1101 | wxHtmlRenderingInfo& WXUNUSED(info)) |
5526e819 VS |
1102 | { |
1103 | int absx = 0, absy = 0, stx, sty; | |
1104 | wxHtmlCell *c = this; | |
1105 | ||
04dbb646 | 1106 | while (c) |
4f9297b0 VS |
1107 | { |
1108 | absx += c->GetPosX(); | |
1109 | absy += c->GetPosY(); | |
1110 | c = c->GetParent(); | |
5526e819 | 1111 | } |
7e941458 | 1112 | |
e421922f | 1113 | ((wxScrolledWindow*)(m_Wnd->GetParent()))->GetViewStart(&stx, &sty); |
4f9297b0 | 1114 | m_Wnd->SetSize(absx - wxHTML_SCROLL_STEP * stx, absy - wxHTML_SCROLL_STEP * sty, m_Width, m_Height); |
5526e819 VS |
1115 | } |
1116 | ||
1117 | ||
1118 | ||
1119 | void wxHtmlWidgetCell::Layout(int w) | |
1120 | { | |
04dbb646 | 1121 | if (m_WidthFloat != 0) |
4f9297b0 | 1122 | { |
5526e819 | 1123 | m_Width = (w * m_WidthFloat) / 100; |
4f9297b0 | 1124 | m_Wnd->SetSize(m_Width, m_Height); |
5526e819 VS |
1125 | } |
1126 | ||
1127 | wxHtmlCell::Layout(w); | |
1128 | } | |
1129 | ||
e3774124 VS |
1130 | |
1131 | ||
1132 | // ---------------------------------------------------------------------------- | |
1133 | // wxHtmlTerminalCellsInterator | |
1134 | // ---------------------------------------------------------------------------- | |
1135 | ||
1136 | const wxHtmlCell* wxHtmlTerminalCellsInterator::operator++() | |
1137 | { | |
1138 | if ( !m_pos ) | |
1139 | return NULL; | |
1140 | ||
1141 | do | |
1142 | { | |
1143 | if ( m_pos == m_to ) | |
1144 | { | |
1145 | m_pos = NULL; | |
1146 | return NULL; | |
1147 | } | |
1148 | ||
1149 | if ( m_pos->GetNext() ) | |
1150 | m_pos = m_pos->GetNext(); | |
1151 | else | |
1152 | { | |
1153 | // we must go up the hierarchy until we reach container where this | |
1154 | // is not the last child, and then go down to first terminal cell: | |
1155 | while ( m_pos->GetNext() == NULL ) | |
1156 | { | |
1157 | m_pos = m_pos->GetParent(); | |
1158 | if ( !m_pos ) | |
1159 | return NULL; | |
1160 | } | |
1161 | m_pos = m_pos->GetNext(); | |
1162 | } | |
1163 | while ( m_pos->GetFirstChild() != NULL ) | |
1164 | m_pos = m_pos->GetFirstChild(); | |
1165 | } while ( !m_pos->IsTerminalCell() ); | |
1166 | ||
1167 | return m_pos; | |
1168 | } | |
1169 | ||
5526e819 | 1170 | #endif |