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