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