WX_PRECOMP, not WXPRECOMP
[wxWidgets.git] / src / html / htmlcell.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/html/htmlcell.cpp
3 // Purpose: wxHtmlCell - basic element of HTML output
4 // Author: Vaclav Slavik
5 // RCS-ID: $Id$
6 // Copyright: (c) 1999 Vaclav Slavik
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #include "wx/wxprec.h"
11
12 #ifdef __BORLANDC__
13 #pragma hdrstop
14 #endif
15
16 #if wxUSE_HTML && wxUSE_STREAMS
17
18 #ifndef WX_PRECOMP
19 #include "wx/dynarray.h"
20 #include "wx/brush.h"
21 #include "wx/colour.h"
22 #include "wx/dc.h"
23 #include "wx/settings.h"
24 #include "wx/module.h"
25 #include "wx/wxcrtvararg.h"
26 #endif
27
28 #include "wx/html/htmlcell.h"
29 #include "wx/html/htmlwin.h"
30
31 #include <stdlib.h>
32
33 //-----------------------------------------------------------------------------
34 // Helper classes
35 //-----------------------------------------------------------------------------
36
37 void wxHtmlSelection::Set(const wxPoint& fromPos, const wxHtmlCell *fromCell,
38 const wxPoint& toPos, const wxHtmlCell *toCell)
39 {
40 m_fromCell = fromCell;
41 m_toCell = toCell;
42 m_fromPos = fromPos;
43 m_toPos = toPos;
44 }
45
46 void wxHtmlSelection::Set(const wxHtmlCell *fromCell, const wxHtmlCell *toCell)
47 {
48 wxPoint p1 = fromCell ? fromCell->GetAbsPos() : wxDefaultPosition;
49 wxPoint p2 = toCell ? toCell->GetAbsPos() : wxDefaultPosition;
50 if ( toCell )
51 {
52 p2.x += toCell->GetWidth();
53 p2.y += toCell->GetHeight();
54 }
55 Set(p1, fromCell, p2, toCell);
56 }
57
58 wxColour
59 wxDefaultHtmlRenderingStyle::
60 GetSelectedTextColour(const wxColour& WXUNUSED(clr))
61 {
62 return wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT);
63 }
64
65 wxColour
66 wxDefaultHtmlRenderingStyle::
67 GetSelectedTextBgColour(const wxColour& WXUNUSED(clr))
68 {
69 return wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT);
70 }
71
72
73 //-----------------------------------------------------------------------------
74 // wxHtmlCell
75 //-----------------------------------------------------------------------------
76
77 IMPLEMENT_ABSTRACT_CLASS(wxHtmlCell, wxObject)
78
79 wxHtmlCell::wxHtmlCell() : wxObject()
80 {
81 m_Next = NULL;
82 m_Parent = NULL;
83 m_Width = m_Height = m_Descent = 0;
84 m_ScriptMode = wxHTML_SCRIPT_NORMAL; // <sub> or <sup> mode
85 m_ScriptBaseline = 0; // <sub> or <sup> baseline
86 m_CanLiveOnPagebreak = true;
87 m_Link = NULL;
88 }
89
90 wxHtmlCell::~wxHtmlCell()
91 {
92 delete m_Link;
93 }
94
95 // Update the descent value when whe are in a <sub> or <sup>.
96 // prevbase is the parent base
97 void wxHtmlCell::SetScriptMode(wxHtmlScriptMode mode, long previousBase)
98 {
99 m_ScriptMode = mode;
100
101 if (mode == wxHTML_SCRIPT_SUP)
102 m_ScriptBaseline = previousBase - (m_Height + 1) / 2;
103 else if (mode == wxHTML_SCRIPT_SUB)
104 m_ScriptBaseline = previousBase + (m_Height + 1) / 6;
105 else
106 m_ScriptBaseline = 0;
107
108 m_Descent += m_ScriptBaseline;
109 }
110
111 #if WXWIN_COMPATIBILITY_2_6
112
113 struct wxHtmlCellOnMouseClickCompatHelper;
114
115 static wxHtmlCellOnMouseClickCompatHelper *gs_helperOnMouseClick = NULL;
116
117 // helper for routing calls to new ProcessMouseClick() method to deprecated
118 // OnMouseClick() method
119 struct wxHtmlCellOnMouseClickCompatHelper
120 {
121 wxHtmlCellOnMouseClickCompatHelper(wxHtmlWindowInterface *window_,
122 const wxPoint& pos_,
123 const wxMouseEvent& event_)
124 : window(window_), pos(pos_), event(event_), retval(false)
125 {
126 }
127
128 bool CallOnMouseClick(wxHtmlCell *cell)
129 {
130 wxHtmlCellOnMouseClickCompatHelper *oldHelper = gs_helperOnMouseClick;
131 gs_helperOnMouseClick = this;
132 cell->OnMouseClick
133 (
134 window ? window->GetHTMLWindow() : NULL,
135 pos.x, pos.y,
136 event
137 );
138 gs_helperOnMouseClick = oldHelper;
139 return retval;
140 }
141
142 wxHtmlWindowInterface *window;
143 const wxPoint& pos;
144 const wxMouseEvent& event;
145 bool retval;
146 };
147 #endif // WXWIN_COMPATIBILITY_2_6
148
149 bool wxHtmlCell::ProcessMouseClick(wxHtmlWindowInterface *window,
150 const wxPoint& pos,
151 const wxMouseEvent& event)
152 {
153 wxCHECK_MSG( window, false, _T("window interface must be provided") );
154
155 #if WXWIN_COMPATIBILITY_2_6
156 // NB: this hack puts the body of ProcessMouseClick() into OnMouseClick()
157 // (for which it has to pass the arguments and return value via a
158 // helper variable because these two methods have different
159 // signatures), so that old code overriding OnMouseClick will continue
160 // to work
161 wxHtmlCellOnMouseClickCompatHelper compat(window, pos, event);
162 return compat.CallOnMouseClick(this);
163 }
164
165 void wxHtmlCell::OnMouseClick(wxWindow *, int, int, const wxMouseEvent& event)
166 {
167 wxCHECK_RET( gs_helperOnMouseClick, _T("unexpected call to OnMouseClick") );
168 wxHtmlWindowInterface *window = gs_helperOnMouseClick->window;
169 const wxPoint& pos = gs_helperOnMouseClick->pos;
170 #endif // WXWIN_COMPATIBILITY_2_6
171
172 wxHtmlLinkInfo *lnk = GetLink(pos.x, pos.y);
173 bool retval = false;
174
175 if (lnk)
176 {
177 wxHtmlLinkInfo lnk2(*lnk);
178 lnk2.SetEvent(&event);
179 lnk2.SetHtmlCell(this);
180
181 window->OnHTMLLinkClicked(lnk2);
182 retval = true;
183 }
184
185 #if WXWIN_COMPATIBILITY_2_6
186 gs_helperOnMouseClick->retval = retval;
187 #else
188 return retval;
189 #endif // WXWIN_COMPATIBILITY_2_6
190 }
191
192 #if WXWIN_COMPATIBILITY_2_6
193 wxCursor wxHtmlCell::GetCursor() const
194 {
195 return wxNullCursor;
196 }
197 #endif // WXWIN_COMPATIBILITY_2_6
198
199 wxCursor wxHtmlCell::GetMouseCursor(wxHtmlWindowInterface *window) const
200 {
201 #if WXWIN_COMPATIBILITY_2_6
202 // NB: Older versions of wx used GetCursor() virtual method in place of
203 // GetMouseCursor(interface). This code ensures that user code that
204 // overriden GetCursor() continues to work. The trick is that the base
205 // wxHtmlCell::GetCursor() method simply returns wxNullCursor, so we
206 // know that GetCursor() was overriden iff it returns valid cursor.
207 wxCursor cur = GetCursor();
208 if (cur.Ok())
209 return cur;
210 #endif // WXWIN_COMPATIBILITY_2_6
211
212 if ( GetLink() )
213 {
214 return window->GetHTMLCursor(wxHtmlWindowInterface::HTMLCursor_Link);
215 }
216 else
217 {
218 return window->GetHTMLCursor(wxHtmlWindowInterface::HTMLCursor_Default);
219 }
220 }
221
222
223 bool wxHtmlCell::AdjustPagebreak(int *pagebreak,
224 wxArrayInt& WXUNUSED(known_pagebreaks)) const
225 {
226 if ((!m_CanLiveOnPagebreak) &&
227 m_PosY < *pagebreak && m_PosY + m_Height > *pagebreak)
228 {
229 *pagebreak = m_PosY;
230 return true;
231 }
232
233 return false;
234 }
235
236
237
238 void wxHtmlCell::SetLink(const wxHtmlLinkInfo& link)
239 {
240 if (m_Link) delete m_Link;
241 m_Link = NULL;
242 if (link.GetHref() != wxEmptyString)
243 m_Link = new wxHtmlLinkInfo(link);
244 }
245
246
247 void wxHtmlCell::Layout(int WXUNUSED(w))
248 {
249 SetPos(0, 0);
250 }
251
252
253
254 const wxHtmlCell* wxHtmlCell::Find(int WXUNUSED(condition), const void* WXUNUSED(param)) const
255 {
256 return NULL;
257 }
258
259
260 wxHtmlCell *wxHtmlCell::FindCellByPos(wxCoord x, wxCoord y,
261 unsigned flags) const
262 {
263 if ( x >= 0 && x < m_Width && y >= 0 && y < m_Height )
264 {
265 return wxConstCast(this, wxHtmlCell);
266 }
267 else
268 {
269 if ((flags & wxHTML_FIND_NEAREST_AFTER) &&
270 (y < 0 || (y < 0+m_Height && x < 0+m_Width)))
271 return wxConstCast(this, wxHtmlCell);
272 else if ((flags & wxHTML_FIND_NEAREST_BEFORE) &&
273 (y >= 0+m_Height || (y >= 0 && x >= 0)))
274 return wxConstCast(this, wxHtmlCell);
275 else
276 return NULL;
277 }
278 }
279
280
281 wxPoint wxHtmlCell::GetAbsPos(wxHtmlCell *rootCell) const
282 {
283 wxPoint p(m_PosX, m_PosY);
284 for (wxHtmlCell *parent = m_Parent; parent && parent != rootCell;
285 parent = parent->m_Parent)
286 {
287 p.x += parent->m_PosX;
288 p.y += parent->m_PosY;
289 }
290 return p;
291 }
292
293 wxHtmlCell *wxHtmlCell::GetRootCell() const
294 {
295 wxHtmlCell *c = wxConstCast(this, wxHtmlCell);
296 while ( c->m_Parent )
297 c = c->m_Parent;
298 return c;
299 }
300
301 unsigned wxHtmlCell::GetDepth() const
302 {
303 unsigned d = 0;
304 for (wxHtmlCell *p = m_Parent; p; p = p->m_Parent)
305 d++;
306 return d;
307 }
308
309 bool wxHtmlCell::IsBefore(wxHtmlCell *cell) const
310 {
311 const wxHtmlCell *c1 = this;
312 const wxHtmlCell *c2 = cell;
313 unsigned d1 = GetDepth();
314 unsigned d2 = cell->GetDepth();
315
316 if ( d1 > d2 )
317 for (; d1 != d2; d1-- )
318 c1 = c1->m_Parent;
319 else if ( d1 < d2 )
320 for (; d1 != d2; d2-- )
321 c2 = c2->m_Parent;
322
323 if ( cell == this )
324 return true;
325
326 while ( c1 && c2 )
327 {
328 if ( c1->m_Parent == c2->m_Parent )
329 {
330 while ( c1 )
331 {
332 if ( c1 == c2 )
333 return true;
334 c1 = c1->GetNext();
335 }
336 return false;
337 }
338 else
339 {
340 c1 = c1->m_Parent;
341 c2 = c2->m_Parent;
342 }
343 }
344
345 wxFAIL_MSG(_T("Cells are in different trees"));
346 return false;
347 }
348
349
350 //-----------------------------------------------------------------------------
351 // wxHtmlWordCell
352 //-----------------------------------------------------------------------------
353
354 IMPLEMENT_ABSTRACT_CLASS(wxHtmlWordCell, wxHtmlCell)
355
356 wxHtmlWordCell::wxHtmlWordCell(const wxString& word, const wxDC& dc) : wxHtmlCell()
357 {
358 m_Word = word;
359 dc.GetTextExtent(m_Word, &m_Width, &m_Height, &m_Descent);
360 SetCanLiveOnPagebreak(false);
361 m_allowLinebreak = true;
362 }
363
364 void wxHtmlWordCell::SetPreviousWord(wxHtmlWordCell *cell)
365 {
366 if ( cell && m_Parent == cell->m_Parent &&
367 !wxIsspace(cell->m_Word.Last()) && !wxIsspace(m_Word[0u]) )
368 {
369 m_allowLinebreak = false;
370 }
371 }
372
373 // Splits m_Word into up to three parts according to selection, returns
374 // substring before, in and after selection and the points (in relative coords)
375 // where s2 and s3 start:
376 void wxHtmlWordCell::Split(const wxDC& dc,
377 const wxPoint& selFrom, const wxPoint& selTo,
378 unsigned& pos1, unsigned& pos2) const
379 {
380 wxPoint pt1 = (selFrom == wxDefaultPosition) ?
381 wxDefaultPosition : selFrom - GetAbsPos();
382 wxPoint pt2 = (selTo == wxDefaultPosition) ?
383 wxPoint(m_Width, wxDefaultCoord) : selTo - GetAbsPos();
384
385 unsigned len = m_Word.length();
386 unsigned i = 0;
387 pos1 = 0;
388
389 // adjust for cases when the start/end position is completely
390 // outside the cell:
391 if ( pt1.y < 0 )
392 pt1.x = 0;
393 if ( pt2.y >= m_Height )
394 pt2.x = m_Width;
395
396 // before selection:
397 #ifdef __WXMAC__
398 // implementation using PartialExtents to support fractional widths
399 wxArrayInt widths ;
400 dc.GetPartialTextExtents(m_Word,widths) ;
401 while( i < len && pt1.x >= widths[i] )
402 i++ ;
403 #else // __WXMAC__
404 wxCoord charW, charH;
405 while ( pt1.x > 0 && i < len )
406 {
407 dc.GetTextExtent(m_Word[i], &charW, &charH);
408 pt1.x -= charW;
409 if ( pt1.x >= 0 )
410 {
411 pos1 += charW;
412 i++;
413 }
414 }
415 #endif // __WXMAC__/!__WXMAC__
416
417 // in selection:
418 unsigned j = i;
419 #ifdef __WXMAC__
420 while( j < len && pt2.x >= widths[j] )
421 j++ ;
422 #else // __WXMAC__
423 pos2 = pos1;
424 pt2.x -= pos2;
425 while ( pt2.x > 0 && j < len )
426 {
427 dc.GetTextExtent(m_Word[j], &charW, &charH);
428 pt2.x -= charW;
429 if ( pt2.x >= 0 )
430 {
431 pos2 += charW;
432 j++;
433 }
434 }
435 #endif // __WXMAC__/!__WXMAC__
436
437 pos1 = i;
438 pos2 = j;
439 }
440
441 void wxHtmlWordCell::SetSelectionPrivPos(const wxDC& dc, wxHtmlSelection *s) const
442 {
443 unsigned p1, p2;
444
445 Split(dc,
446 this == s->GetFromCell() ? s->GetFromPos() : wxDefaultPosition,
447 this == s->GetToCell() ? s->GetToPos() : wxDefaultPosition,
448 p1, p2);
449
450 wxPoint p(0, m_Word.length());
451
452 if ( this == s->GetFromCell() )
453 p.x = p1; // selection starts here
454 if ( this == s->GetToCell() )
455 p.y = p2; // selection ends here
456
457 if ( this == s->GetFromCell() )
458 s->SetFromPrivPos(p);
459 if ( this == s->GetToCell() )
460 s->SetToPrivPos(p);
461 }
462
463
464 static void SwitchSelState(wxDC& dc, wxHtmlRenderingInfo& info,
465 bool toSelection)
466 {
467 wxColour fg = info.GetState().GetFgColour();
468 wxColour bg = info.GetState().GetBgColour();
469
470 if ( toSelection )
471 {
472 dc.SetBackgroundMode(wxSOLID);
473 dc.SetTextForeground(info.GetStyle().GetSelectedTextColour(fg));
474 dc.SetTextBackground(info.GetStyle().GetSelectedTextBgColour(bg));
475 dc.SetBackground(wxBrush(info.GetStyle().GetSelectedTextBgColour(bg),
476 wxSOLID));
477 }
478 else
479 {
480 dc.SetBackgroundMode(wxTRANSPARENT);
481 dc.SetTextForeground(fg);
482 dc.SetTextBackground(bg);
483 dc.SetBackground(wxBrush(bg, wxSOLID));
484 }
485 }
486
487
488 void wxHtmlWordCell::Draw(wxDC& dc, int x, int y,
489 int WXUNUSED(view_y1), int WXUNUSED(view_y2),
490 wxHtmlRenderingInfo& info)
491 {
492 #if 0 // useful for debugging
493 dc.SetPen(*wxBLACK_PEN);
494 dc.DrawRectangle(x+m_PosX,y+m_PosY,m_Width /* VZ: +1? */ ,m_Height);
495 #endif
496
497 bool drawSelectionAfterCell = false;
498
499 if ( info.GetState().GetSelectionState() == wxHTML_SEL_CHANGING )
500 {
501 // Selection changing, we must draw the word piecewise:
502 wxHtmlSelection *s = info.GetSelection();
503 wxString txt;
504 int w, h;
505 int ofs = 0;
506
507 wxPoint priv = (this == s->GetFromCell()) ?
508 s->GetFromPrivPos() : s->GetToPrivPos();
509
510 // NB: this is quite a hack: in order to compute selection boundaries
511 // (in word's characters) we must know current font, which is only
512 // possible inside rendering code. Therefore we update the
513 // information here and store it in wxHtmlSelection so that
514 // ConvertToText can use it later:
515 if ( priv == wxDefaultPosition )
516 {
517 SetSelectionPrivPos(dc, s);
518 priv = (this == s->GetFromCell()) ?
519 s->GetFromPrivPos() : s->GetToPrivPos();
520 }
521
522 int part1 = priv.x;
523 int part2 = priv.y;
524
525 if ( part1 > 0 )
526 {
527 txt = m_Word.Mid(0, part1);
528 dc.DrawText(txt, x + m_PosX, y + m_PosY);
529 dc.GetTextExtent(txt, &w, &h);
530 ofs += w;
531 }
532
533 SwitchSelState(dc, info, true);
534
535 txt = m_Word.Mid(part1, part2-part1);
536 dc.DrawText(txt, ofs + x + m_PosX, y + m_PosY);
537
538 if ( (size_t)part2 < m_Word.length() )
539 {
540 dc.GetTextExtent(txt, &w, &h);
541 ofs += w;
542 SwitchSelState(dc, info, false);
543 txt = m_Word.Mid(part2);
544 dc.DrawText(txt, ofs + x + m_PosX, y + m_PosY);
545 }
546 else
547 drawSelectionAfterCell = true;
548 }
549 else
550 {
551 wxHtmlSelectionState selstate = info.GetState().GetSelectionState();
552 // Not changing selection state, draw the word in single mode:
553 if ( selstate != wxHTML_SEL_OUT &&
554 dc.GetBackgroundMode() != wxSOLID )
555 {
556 SwitchSelState(dc, info, true);
557 }
558 else if ( selstate == wxHTML_SEL_OUT &&
559 dc.GetBackgroundMode() == wxSOLID )
560 {
561 SwitchSelState(dc, info, false);
562 }
563 dc.DrawText(m_Word, x + m_PosX, y + m_PosY);
564 drawSelectionAfterCell = (selstate != wxHTML_SEL_OUT);
565 }
566
567 // NB: If the text is justified then there is usually some free space
568 // between adjacent cells and drawing the selection only onto cells
569 // would result in ugly unselected spaces. The code below detects
570 // this special case and renders the selection *outside* the sell,
571 // too.
572 if ( m_Parent->GetAlignHor() == wxHTML_ALIGN_JUSTIFY &&
573 drawSelectionAfterCell )
574 {
575 wxHtmlCell *nextCell = m_Next;
576 while ( nextCell && nextCell->IsFormattingCell() )
577 nextCell = nextCell->GetNext();
578 if ( nextCell )
579 {
580 int nextX = nextCell->GetPosX();
581 if ( m_PosX + m_Width < nextX )
582 {
583 dc.SetBrush(dc.GetBackground());
584 dc.SetPen(*wxTRANSPARENT_PEN);
585 dc.DrawRectangle(x + m_PosX + m_Width, y + m_PosY,
586 nextX - m_PosX - m_Width, m_Height);
587 }
588 }
589 }
590 }
591
592
593 wxString wxHtmlWordCell::ConvertToText(wxHtmlSelection *s) const
594 {
595 if ( s && (this == s->GetFromCell() || this == s->GetToCell()) )
596 {
597 wxPoint priv = this == s->GetFromCell() ? s->GetFromPrivPos()
598 : s->GetToPrivPos();
599
600 // VZ: we may be called before we had a chance to re-render ourselves
601 // and in this case GetFrom/ToPrivPos() is not set yet -- assume
602 // that this only happens in case of a double/triple click (which
603 // seems to be the case now) and so it makes sense to select the
604 // entire contents of the cell in this case
605 //
606 // TODO: but this really needs to be fixed in some better way later...
607 if ( priv != wxDefaultPosition )
608 {
609 int part1 = priv.x;
610 int part2 = priv.y;
611 return m_Word.Mid(part1, part2-part1);
612 }
613 //else: return the whole word below
614 }
615
616 return m_Word;
617 }
618
619 wxCursor wxHtmlWordCell::GetMouseCursor(wxHtmlWindowInterface *window) const
620 {
621 if ( !GetLink() )
622 {
623 return window->GetHTMLCursor(wxHtmlWindowInterface::HTMLCursor_Text);
624 }
625 else
626 {
627 return wxHtmlCell::GetMouseCursor(window);
628 }
629 }
630
631
632 //-----------------------------------------------------------------------------
633 // wxHtmlContainerCell
634 //-----------------------------------------------------------------------------
635
636 IMPLEMENT_ABSTRACT_CLASS(wxHtmlContainerCell, wxHtmlCell)
637
638 wxHtmlContainerCell::wxHtmlContainerCell(wxHtmlContainerCell *parent) : wxHtmlCell()
639 {
640 m_Cells = m_LastCell = NULL;
641 m_Parent = parent;
642 m_MaxTotalWidth = 0;
643 if (m_Parent) m_Parent->InsertCell(this);
644 m_AlignHor = wxHTML_ALIGN_LEFT;
645 m_AlignVer = wxHTML_ALIGN_BOTTOM;
646 m_IndentLeft = m_IndentRight = m_IndentTop = m_IndentBottom = 0;
647 m_WidthFloat = 100; m_WidthFloatUnits = wxHTML_UNITS_PERCENT;
648 m_UseBkColour = false;
649 m_UseBorder = false;
650 m_MinHeight = 0;
651 m_MinHeightAlign = wxHTML_ALIGN_TOP;
652 m_LastLayout = -1;
653 }
654
655 wxHtmlContainerCell::~wxHtmlContainerCell()
656 {
657 wxHtmlCell *cell = m_Cells;
658 while ( cell )
659 {
660 wxHtmlCell *cellNext = cell->GetNext();
661 delete cell;
662 cell = cellNext;
663 }
664 }
665
666
667
668 void wxHtmlContainerCell::SetIndent(int i, int what, int units)
669 {
670 int val = (units == wxHTML_UNITS_PIXELS) ? i : -i;
671 if (what & wxHTML_INDENT_LEFT) m_IndentLeft = val;
672 if (what & wxHTML_INDENT_RIGHT) m_IndentRight = val;
673 if (what & wxHTML_INDENT_TOP) m_IndentTop = val;
674 if (what & wxHTML_INDENT_BOTTOM) m_IndentBottom = val;
675 m_LastLayout = -1;
676 }
677
678
679
680 int wxHtmlContainerCell::GetIndent(int ind) const
681 {
682 if (ind & wxHTML_INDENT_LEFT) return m_IndentLeft;
683 else if (ind & wxHTML_INDENT_RIGHT) return m_IndentRight;
684 else if (ind & wxHTML_INDENT_TOP) return m_IndentTop;
685 else if (ind & wxHTML_INDENT_BOTTOM) return m_IndentBottom;
686 else return -1; /* BUG! Should not be called... */
687 }
688
689
690
691
692 int wxHtmlContainerCell::GetIndentUnits(int ind) const
693 {
694 bool p = false;
695 if (ind & wxHTML_INDENT_LEFT) p = m_IndentLeft < 0;
696 else if (ind & wxHTML_INDENT_RIGHT) p = m_IndentRight < 0;
697 else if (ind & wxHTML_INDENT_TOP) p = m_IndentTop < 0;
698 else if (ind & wxHTML_INDENT_BOTTOM) p = m_IndentBottom < 0;
699 if (p) return wxHTML_UNITS_PERCENT;
700 else return wxHTML_UNITS_PIXELS;
701 }
702
703
704 bool wxHtmlContainerCell::AdjustPagebreak(int *pagebreak,
705 wxArrayInt& known_pagebreaks) const
706 {
707 if (!m_CanLiveOnPagebreak)
708 return wxHtmlCell::AdjustPagebreak(pagebreak, known_pagebreaks);
709
710 wxHtmlCell *c = GetFirstChild();
711 bool rt = false;
712 int pbrk = *pagebreak - m_PosY;
713
714 while (c)
715 {
716 if (c->AdjustPagebreak(&pbrk, known_pagebreaks))
717 rt = true;
718 c = c->GetNext();
719 }
720 if (rt)
721 *pagebreak = pbrk + m_PosY;
722 return rt;
723 }
724
725
726 void wxHtmlContainerCell::Layout(int w)
727 {
728 wxHtmlCell::Layout(w);
729
730 if (m_LastLayout == w) return;
731
732 // VS: Any attempt to layout with negative or zero width leads to hell,
733 // but we can't ignore such attempts completely, since it sometimes
734 // happen (e.g. when trying how small a table can be). The best thing we
735 // can do is to set the width of child cells to zero
736 if (w < 1)
737 {
738 m_Width = 0;
739 for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext())
740 cell->Layout(0);
741 // this does two things: it recursively calls this code on all
742 // child contrainers and resets children's position to (0,0)
743 return;
744 }
745
746 wxHtmlCell *nextCell;
747 long xpos = 0, ypos = m_IndentTop;
748 int xdelta = 0, ybasicpos = 0, ydiff;
749 int s_width, nextWordWidth, s_indent;
750 int ysizeup = 0, ysizedown = 0;
751 int MaxLineWidth = 0;
752 int curLineWidth = 0;
753 m_MaxTotalWidth = 0;
754
755
756 /*
757
758 WIDTH ADJUSTING :
759
760 */
761
762 if (m_WidthFloatUnits == wxHTML_UNITS_PERCENT)
763 {
764 if (m_WidthFloat < 0) m_Width = (100 + m_WidthFloat) * w / 100;
765 else m_Width = m_WidthFloat * w / 100;
766 }
767 else
768 {
769 if (m_WidthFloat < 0) m_Width = w + m_WidthFloat;
770 else m_Width = m_WidthFloat;
771 }
772
773 if (m_Cells)
774 {
775 int l = (m_IndentLeft < 0) ? (-m_IndentLeft * m_Width / 100) : m_IndentLeft;
776 int r = (m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight;
777 for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext())
778 cell->Layout(m_Width - (l + r));
779 }
780
781 /*
782
783 LAYOUTING :
784
785 */
786
787 // adjust indentation:
788 s_indent = (m_IndentLeft < 0) ? (-m_IndentLeft * m_Width / 100) : m_IndentLeft;
789 s_width = m_Width - s_indent - ((m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight);
790
791 // my own layouting:
792 wxHtmlCell *cell = m_Cells,
793 *line = m_Cells;
794 while (cell != NULL)
795 {
796 switch (m_AlignVer)
797 {
798 case wxHTML_ALIGN_TOP : ybasicpos = 0; break;
799 case wxHTML_ALIGN_BOTTOM : ybasicpos = - cell->GetHeight(); break;
800 case wxHTML_ALIGN_CENTER : ybasicpos = - cell->GetHeight() / 2; break;
801 }
802 ydiff = cell->GetHeight() + ybasicpos;
803
804 if (cell->GetDescent() + ydiff > ysizedown) ysizedown = cell->GetDescent() + ydiff;
805 if (ybasicpos + cell->GetDescent() < -ysizeup) ysizeup = - (ybasicpos + cell->GetDescent());
806
807 // layout nonbreakable run of cells:
808 cell->SetPos(xpos, ybasicpos + cell->GetDescent());
809 xpos += cell->GetWidth();
810 if (!cell->IsTerminalCell())
811 {
812 // Container cell indicates new line
813 if (curLineWidth > m_MaxTotalWidth)
814 m_MaxTotalWidth = curLineWidth;
815
816 if (wxMax(cell->GetWidth(), cell->GetMaxTotalWidth()) > m_MaxTotalWidth)
817 m_MaxTotalWidth = cell->GetMaxTotalWidth();
818 curLineWidth = 0;
819 }
820 else
821 // Normal cell, add maximum cell width to line width
822 curLineWidth += cell->GetMaxTotalWidth();
823
824 cell = cell->GetNext();
825
826 // compute length of the next word that would be added:
827 nextWordWidth = 0;
828 if (cell)
829 {
830 nextCell = cell;
831 do
832 {
833 nextWordWidth += nextCell->GetWidth();
834 nextCell = nextCell->GetNext();
835 } while (nextCell && !nextCell->IsLinebreakAllowed());
836 }
837
838 // force new line if occurred:
839 if ((cell == NULL) ||
840 (xpos + nextWordWidth > s_width && cell->IsLinebreakAllowed()))
841 {
842 if (xpos > MaxLineWidth) MaxLineWidth = xpos;
843 if (ysizeup < 0) ysizeup = 0;
844 if (ysizedown < 0) ysizedown = 0;
845 switch (m_AlignHor) {
846 case wxHTML_ALIGN_LEFT :
847 case wxHTML_ALIGN_JUSTIFY :
848 xdelta = 0;
849 break;
850 case wxHTML_ALIGN_RIGHT :
851 xdelta = 0 + (s_width - xpos);
852 break;
853 case wxHTML_ALIGN_CENTER :
854 xdelta = 0 + (s_width - xpos) / 2;
855 break;
856 }
857 if (xdelta < 0) xdelta = 0;
858 xdelta += s_indent;
859
860 ypos += ysizeup;
861
862 if (m_AlignHor != wxHTML_ALIGN_JUSTIFY || cell == NULL)
863 {
864 while (line != cell)
865 {
866 line->SetPos(line->GetPosX() + xdelta,
867 ypos + line->GetPosY());
868 line = line->GetNext();
869 }
870 }
871 else // align == justify
872 {
873 // we have to distribute the extra horz space between the cells
874 // on this line
875
876 // an added complication is that some cells have fixed size and
877 // shouldn't get any increment (it so happens that these cells
878 // also don't allow line break on them which provides with an
879 // easy way to test for this) -- and neither should the cells
880 // adjacent to them as this could result in a visible space
881 // between two cells separated by, e.g. font change, cell which
882 // is wrong
883
884 int step = s_width - xpos;
885 if ( step > 0 )
886 {
887 // first count the cells which will get extra space
888 int total = -1;
889
890 const wxHtmlCell *c;
891 if ( line != cell )
892 {
893 for ( c = line; c != cell; c = c->GetNext() )
894 {
895 if ( c->IsLinebreakAllowed() )
896 {
897 total++;
898 }
899 }
900 }
901
902 // and now extra space to those cells which merit it
903 if ( total )
904 {
905 // first visible cell on line is not moved:
906 while (line !=cell && !line->IsLinebreakAllowed())
907 {
908 line->SetPos(line->GetPosX() + s_indent,
909 line->GetPosY() + ypos);
910 line = line->GetNext();
911 }
912
913 if (line != cell)
914 {
915 line->SetPos(line->GetPosX() + s_indent,
916 line->GetPosY() + ypos);
917
918 line = line->GetNext();
919 }
920
921 for ( int n = 0; line != cell; line = line->GetNext() )
922 {
923 if ( line->IsLinebreakAllowed() )
924 {
925 // offset the next cell relative to this one
926 // thus increasing our size
927 n++;
928 }
929
930 line->SetPos(line->GetPosX() + s_indent +
931 ((n * step) / total),
932 line->GetPosY() + ypos);
933 }
934 }
935 else
936 {
937 // this will cause the code to enter "else branch" below:
938 step = 0;
939 }
940 }
941 // else branch:
942 if ( step <= 0 ) // no extra space to distribute
943 {
944 // just set the indent properly
945 while (line != cell)
946 {
947 line->SetPos(line->GetPosX() + s_indent,
948 line->GetPosY() + ypos);
949 line = line->GetNext();
950 }
951 }
952 }
953
954 ypos += ysizedown;
955 xpos = 0;
956 ysizeup = ysizedown = 0;
957 line = cell;
958 }
959 }
960
961 // setup height & width, depending on container layout:
962 m_Height = ypos + (ysizedown + ysizeup) + m_IndentBottom;
963
964 if (m_Height < m_MinHeight)
965 {
966 if (m_MinHeightAlign != wxHTML_ALIGN_TOP)
967 {
968 int diff = m_MinHeight - m_Height;
969 if (m_MinHeightAlign == wxHTML_ALIGN_CENTER) diff /= 2;
970 cell = m_Cells;
971 while (cell)
972 {
973 cell->SetPos(cell->GetPosX(), cell->GetPosY() + diff);
974 cell = cell->GetNext();
975 }
976 }
977 m_Height = m_MinHeight;
978 }
979
980 if (curLineWidth > m_MaxTotalWidth)
981 m_MaxTotalWidth = curLineWidth;
982
983 m_MaxTotalWidth += s_indent + ((m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight);
984 MaxLineWidth += s_indent + ((m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight);
985 if (m_Width < MaxLineWidth) m_Width = MaxLineWidth;
986
987 m_LastLayout = w;
988 }
989
990 void wxHtmlContainerCell::UpdateRenderingStatePre(wxHtmlRenderingInfo& info,
991 wxHtmlCell *cell) const
992 {
993 wxHtmlSelection *s = info.GetSelection();
994 if (!s) return;
995 if (s->GetFromCell() == cell || s->GetToCell() == cell)
996 {
997 info.GetState().SetSelectionState(wxHTML_SEL_CHANGING);
998 }
999 }
1000
1001 void wxHtmlContainerCell::UpdateRenderingStatePost(wxHtmlRenderingInfo& info,
1002 wxHtmlCell *cell) const
1003 {
1004 wxHtmlSelection *s = info.GetSelection();
1005 if (!s) return;
1006 if (s->GetToCell() == cell)
1007 info.GetState().SetSelectionState(wxHTML_SEL_OUT);
1008 else if (s->GetFromCell() == cell)
1009 info.GetState().SetSelectionState(wxHTML_SEL_IN);
1010 }
1011
1012 #define mMin(a, b) (((a) < (b)) ? (a) : (b))
1013 #define mMax(a, b) (((a) < (b)) ? (b) : (a))
1014
1015 void wxHtmlContainerCell::Draw(wxDC& dc, int x, int y, int view_y1, int view_y2,
1016 wxHtmlRenderingInfo& info)
1017 {
1018 #if 0 // useful for debugging
1019 dc.SetPen(*wxRED_PEN);
1020 dc.DrawRectangle(x+m_PosX,y+m_PosY,m_Width,m_Height);
1021 #endif
1022
1023 int xlocal = x + m_PosX;
1024 int ylocal = y + m_PosY;
1025
1026 if (m_UseBkColour)
1027 {
1028 wxBrush myb = wxBrush(m_BkColour, wxSOLID);
1029
1030 int real_y1 = mMax(ylocal, view_y1);
1031 int real_y2 = mMin(ylocal + m_Height - 1, view_y2);
1032
1033 dc.SetBrush(myb);
1034 dc.SetPen(*wxTRANSPARENT_PEN);
1035 dc.DrawRectangle(xlocal, real_y1, m_Width, real_y2 - real_y1 + 1);
1036 }
1037
1038 if (m_UseBorder)
1039 {
1040 wxPen mypen1(m_BorderColour1, 1, wxSOLID);
1041 wxPen mypen2(m_BorderColour2, 1, wxSOLID);
1042
1043 dc.SetPen(mypen1);
1044 dc.DrawLine(xlocal, ylocal, xlocal, ylocal + m_Height - 1);
1045 dc.DrawLine(xlocal, ylocal, xlocal + m_Width, ylocal);
1046 dc.SetPen(mypen2);
1047 dc.DrawLine(xlocal + m_Width - 1, ylocal, xlocal + m_Width - 1, ylocal + m_Height - 1);
1048 dc.DrawLine(xlocal, ylocal + m_Height - 1, xlocal + m_Width, ylocal + m_Height - 1);
1049 }
1050
1051 if (m_Cells)
1052 {
1053 // draw container's contents:
1054 for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext())
1055 {
1056
1057 // optimize drawing: don't render off-screen content:
1058 if ((ylocal + cell->GetPosY() <= view_y2) &&
1059 (ylocal + cell->GetPosY() + cell->GetHeight() > view_y1))
1060 {
1061 // the cell is visible, draw it:
1062 UpdateRenderingStatePre(info, cell);
1063 cell->Draw(dc,
1064 xlocal, ylocal, view_y1, view_y2,
1065 info);
1066 UpdateRenderingStatePost(info, cell);
1067 }
1068 else
1069 {
1070 // the cell is off-screen, proceed with font+color+etc.
1071 // changes only:
1072 cell->DrawInvisible(dc, xlocal, ylocal, info);
1073 }
1074 }
1075 }
1076 }
1077
1078
1079
1080 void wxHtmlContainerCell::DrawInvisible(wxDC& dc, int x, int y,
1081 wxHtmlRenderingInfo& info)
1082 {
1083 if (m_Cells)
1084 {
1085 for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext())
1086 {
1087 UpdateRenderingStatePre(info, cell);
1088 cell->DrawInvisible(dc, x + m_PosX, y + m_PosY, info);
1089 UpdateRenderingStatePost(info, cell);
1090 }
1091 }
1092 }
1093
1094
1095 wxColour wxHtmlContainerCell::GetBackgroundColour()
1096 {
1097 if (m_UseBkColour)
1098 return m_BkColour;
1099 else
1100 return wxNullColour;
1101 }
1102
1103
1104
1105 wxHtmlLinkInfo *wxHtmlContainerCell::GetLink(int x, int y) const
1106 {
1107 wxHtmlCell *cell = FindCellByPos(x, y);
1108
1109 // VZ: I don't know if we should pass absolute or relative coords to
1110 // wxHtmlCell::GetLink()? As the base class version just ignores them
1111 // anyhow, it hardly matters right now but should still be clarified
1112 return cell ? cell->GetLink(x, y) : NULL;
1113 }
1114
1115
1116
1117 void wxHtmlContainerCell::InsertCell(wxHtmlCell *f)
1118 {
1119 if (!m_Cells) m_Cells = m_LastCell = f;
1120 else
1121 {
1122 m_LastCell->SetNext(f);
1123 m_LastCell = f;
1124 if (m_LastCell) while (m_LastCell->GetNext()) m_LastCell = m_LastCell->GetNext();
1125 }
1126 f->SetParent(this);
1127 m_LastLayout = -1;
1128 }
1129
1130
1131
1132 void wxHtmlContainerCell::SetAlign(const wxHtmlTag& tag)
1133 {
1134 if (tag.HasParam(wxT("ALIGN")))
1135 {
1136 wxString alg = tag.GetParam(wxT("ALIGN"));
1137 alg.MakeUpper();
1138 if (alg == wxT("CENTER"))
1139 SetAlignHor(wxHTML_ALIGN_CENTER);
1140 else if (alg == wxT("LEFT"))
1141 SetAlignHor(wxHTML_ALIGN_LEFT);
1142 else if (alg == wxT("JUSTIFY"))
1143 SetAlignHor(wxHTML_ALIGN_JUSTIFY);
1144 else if (alg == wxT("RIGHT"))
1145 SetAlignHor(wxHTML_ALIGN_RIGHT);
1146 m_LastLayout = -1;
1147 }
1148 }
1149
1150
1151
1152 void wxHtmlContainerCell::SetWidthFloat(const wxHtmlTag& tag, double pixel_scale)
1153 {
1154 if (tag.HasParam(wxT("WIDTH")))
1155 {
1156 int wdi;
1157 wxString wd = tag.GetParam(wxT("WIDTH"));
1158
1159 if (wd[wd.length()-1] == wxT('%'))
1160 {
1161 wxSscanf(wd.c_str(), wxT("%i%%"), &wdi);
1162 SetWidthFloat(wdi, wxHTML_UNITS_PERCENT);
1163 }
1164 else
1165 {
1166 wxSscanf(wd.c_str(), wxT("%i"), &wdi);
1167 SetWidthFloat((int)(pixel_scale * (double)wdi), wxHTML_UNITS_PIXELS);
1168 }
1169 m_LastLayout = -1;
1170 }
1171 }
1172
1173
1174
1175 const wxHtmlCell* wxHtmlContainerCell::Find(int condition, const void* param) const
1176 {
1177 if (m_Cells)
1178 {
1179 for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext())
1180 {
1181 const wxHtmlCell *r = cell->Find(condition, param);
1182 if (r) return r;
1183 }
1184 }
1185 return NULL;
1186 }
1187
1188
1189 wxHtmlCell *wxHtmlContainerCell::FindCellByPos(wxCoord x, wxCoord y,
1190 unsigned flags) const
1191 {
1192 if ( flags & wxHTML_FIND_EXACT )
1193 {
1194 for ( const wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext() )
1195 {
1196 int cx = cell->GetPosX(),
1197 cy = cell->GetPosY();
1198
1199 if ( (cx <= x) && (cx + cell->GetWidth() > x) &&
1200 (cy <= y) && (cy + cell->GetHeight() > y) )
1201 {
1202 return cell->FindCellByPos(x - cx, y - cy, flags);
1203 }
1204 }
1205 }
1206 else if ( flags & wxHTML_FIND_NEAREST_AFTER )
1207 {
1208 wxHtmlCell *c;
1209 for ( const wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext() )
1210 {
1211 if ( cell->IsFormattingCell() )
1212 continue;
1213 int cellY = cell->GetPosY();
1214 if (!( y < cellY || (y < cellY + cell->GetHeight() &&
1215 x < cell->GetPosX() + cell->GetWidth()) ))
1216 continue;
1217
1218 c = cell->FindCellByPos(x - cell->GetPosX(), y - cellY, flags);
1219 if (c) return c;
1220 }
1221 }
1222 else if ( flags & wxHTML_FIND_NEAREST_BEFORE )
1223 {
1224 wxHtmlCell *c2, *c = NULL;
1225 for ( const wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext() )
1226 {
1227 if ( cell->IsFormattingCell() )
1228 continue;
1229 int cellY = cell->GetPosY();
1230 if (!( cellY + cell->GetHeight() <= y ||
1231 (y >= cellY && x >= cell->GetPosX()) ))
1232 break;
1233 c2 = cell->FindCellByPos(x - cell->GetPosX(), y - cellY, flags);
1234 if (c2)
1235 c = c2;
1236 }
1237 if (c) return c;
1238 }
1239
1240 return NULL;
1241 }
1242
1243
1244 bool wxHtmlContainerCell::ProcessMouseClick(wxHtmlWindowInterface *window,
1245 const wxPoint& pos,
1246 const wxMouseEvent& event)
1247 {
1248 #if WXWIN_COMPATIBILITY_2_6
1249 wxHtmlCellOnMouseClickCompatHelper compat(window, pos, event);
1250 return compat.CallOnMouseClick(this);
1251 }
1252
1253 void wxHtmlContainerCell::OnMouseClick(wxWindow*,
1254 int, int, const wxMouseEvent& event)
1255 {
1256 wxCHECK_RET( gs_helperOnMouseClick, _T("unexpected call to OnMouseClick") );
1257 wxHtmlWindowInterface *window = gs_helperOnMouseClick->window;
1258 const wxPoint& pos = gs_helperOnMouseClick->pos;
1259 #endif // WXWIN_COMPATIBILITY_2_6
1260
1261 bool retval = false;
1262 wxHtmlCell *cell = FindCellByPos(pos.x, pos.y);
1263 if ( cell )
1264 retval = cell->ProcessMouseClick(window, pos, event);
1265
1266 #if WXWIN_COMPATIBILITY_2_6
1267 gs_helperOnMouseClick->retval = retval;
1268 #else
1269 return retval;
1270 #endif // WXWIN_COMPATIBILITY_2_6
1271 }
1272
1273
1274 wxHtmlCell *wxHtmlContainerCell::GetFirstTerminal() const
1275 {
1276 if ( m_Cells )
1277 {
1278 wxHtmlCell *c2;
1279 for (wxHtmlCell *c = m_Cells; c; c = c->GetNext())
1280 {
1281 c2 = c->GetFirstTerminal();
1282 if ( c2 )
1283 return c2;
1284 }
1285 }
1286 return NULL;
1287 }
1288
1289 wxHtmlCell *wxHtmlContainerCell::GetLastTerminal() const
1290 {
1291 if ( m_Cells )
1292 {
1293 // most common case first:
1294 wxHtmlCell *c = m_LastCell->GetLastTerminal();
1295 if ( c )
1296 return c;
1297
1298 wxHtmlCell *ctmp;
1299 wxHtmlCell *c2 = NULL;
1300 for (c = m_Cells; c; c = c->GetNext())
1301 {
1302 ctmp = c->GetLastTerminal();
1303 if ( ctmp )
1304 c2 = ctmp;
1305 }
1306 return c2;
1307 }
1308 else
1309 return NULL;
1310 }
1311
1312
1313 static bool IsEmptyContainer(wxHtmlContainerCell *cell)
1314 {
1315 for ( wxHtmlCell *c = cell->GetFirstChild(); c; c = c->GetNext() )
1316 {
1317 if ( !c->IsTerminalCell() || !c->IsFormattingCell() )
1318 return false;
1319 }
1320 return true;
1321 }
1322
1323 void wxHtmlContainerCell::RemoveExtraSpacing(bool top, bool bottom)
1324 {
1325 if ( top )
1326 SetIndent(0, wxHTML_INDENT_TOP);
1327 if ( bottom )
1328 SetIndent(0, wxHTML_INDENT_BOTTOM);
1329
1330 if ( m_Cells )
1331 {
1332 wxHtmlCell *c;
1333 wxHtmlContainerCell *cont;
1334 if ( top )
1335 {
1336 for ( c = m_Cells; c; c = c->GetNext() )
1337 {
1338 if ( c->IsTerminalCell() )
1339 {
1340 if ( !c->IsFormattingCell() )
1341 break;
1342 }
1343 else
1344 {
1345 cont = (wxHtmlContainerCell*)c;
1346 if ( IsEmptyContainer(cont) )
1347 {
1348 cont->SetIndent(0, wxHTML_INDENT_VERTICAL);
1349 }
1350 else
1351 {
1352 cont->RemoveExtraSpacing(true, false);
1353 break;
1354 }
1355 }
1356 }
1357 }
1358
1359 if ( bottom )
1360 {
1361 wxArrayPtrVoid arr;
1362 for ( c = m_Cells; c; c = c->GetNext() )
1363 arr.Add((void*)c);
1364
1365 for ( int i = arr.GetCount() - 1; i >= 0; i--)
1366 {
1367 c = (wxHtmlCell*)arr[i];
1368 if ( c->IsTerminalCell() )
1369 {
1370 if ( !c->IsFormattingCell() )
1371 break;
1372 }
1373 else
1374 {
1375 cont = (wxHtmlContainerCell*)c;
1376 if ( IsEmptyContainer(cont) )
1377 {
1378 cont->SetIndent(0, wxHTML_INDENT_VERTICAL);
1379 }
1380 else
1381 {
1382 cont->RemoveExtraSpacing(false, true);
1383 break;
1384 }
1385 }
1386 }
1387 }
1388 }
1389 }
1390
1391
1392
1393
1394 // --------------------------------------------------------------------------
1395 // wxHtmlColourCell
1396 // --------------------------------------------------------------------------
1397
1398 IMPLEMENT_ABSTRACT_CLASS(wxHtmlColourCell, wxHtmlCell)
1399
1400 void wxHtmlColourCell::Draw(wxDC& dc,
1401 int x, int y,
1402 int WXUNUSED(view_y1), int WXUNUSED(view_y2),
1403 wxHtmlRenderingInfo& info)
1404 {
1405 DrawInvisible(dc, x, y, info);
1406 }
1407
1408 void wxHtmlColourCell::DrawInvisible(wxDC& dc,
1409 int WXUNUSED(x), int WXUNUSED(y),
1410 wxHtmlRenderingInfo& info)
1411 {
1412 wxHtmlRenderingState& state = info.GetState();
1413 if (m_Flags & wxHTML_CLR_FOREGROUND)
1414 {
1415 state.SetFgColour(m_Colour);
1416 if (state.GetSelectionState() != wxHTML_SEL_IN)
1417 dc.SetTextForeground(m_Colour);
1418 else
1419 dc.SetTextForeground(
1420 info.GetStyle().GetSelectedTextColour(m_Colour));
1421 }
1422 if (m_Flags & wxHTML_CLR_BACKGROUND)
1423 {
1424 state.SetBgColour(m_Colour);
1425 if (state.GetSelectionState() != wxHTML_SEL_IN)
1426 {
1427 dc.SetTextBackground(m_Colour);
1428 dc.SetBackground(wxBrush(m_Colour, wxSOLID));
1429 }
1430 else
1431 {
1432 wxColour c = info.GetStyle().GetSelectedTextBgColour(m_Colour);
1433 dc.SetTextBackground(c);
1434 dc.SetBackground(wxBrush(c, wxSOLID));
1435 }
1436 }
1437 }
1438
1439
1440
1441
1442 // ---------------------------------------------------------------------------
1443 // wxHtmlFontCell
1444 // ---------------------------------------------------------------------------
1445
1446 IMPLEMENT_ABSTRACT_CLASS(wxHtmlFontCell, wxHtmlCell)
1447
1448 void wxHtmlFontCell::Draw(wxDC& dc,
1449 int WXUNUSED(x), int WXUNUSED(y),
1450 int WXUNUSED(view_y1), int WXUNUSED(view_y2),
1451 wxHtmlRenderingInfo& WXUNUSED(info))
1452 {
1453 dc.SetFont(m_Font);
1454 }
1455
1456 void wxHtmlFontCell::DrawInvisible(wxDC& dc, int WXUNUSED(x), int WXUNUSED(y),
1457 wxHtmlRenderingInfo& WXUNUSED(info))
1458 {
1459 dc.SetFont(m_Font);
1460 }
1461
1462
1463
1464
1465
1466
1467
1468
1469 // ---------------------------------------------------------------------------
1470 // wxHtmlWidgetCell
1471 // ---------------------------------------------------------------------------
1472
1473 IMPLEMENT_ABSTRACT_CLASS(wxHtmlWidgetCell, wxHtmlCell)
1474
1475 wxHtmlWidgetCell::wxHtmlWidgetCell(wxWindow *wnd, int w)
1476 {
1477 int sx, sy;
1478 m_Wnd = wnd;
1479 m_Wnd->GetSize(&sx, &sy);
1480 m_Width = sx, m_Height = sy;
1481 m_WidthFloat = w;
1482 }
1483
1484
1485 void wxHtmlWidgetCell::Draw(wxDC& WXUNUSED(dc),
1486 int WXUNUSED(x), int WXUNUSED(y),
1487 int WXUNUSED(view_y1), int WXUNUSED(view_y2),
1488 wxHtmlRenderingInfo& WXUNUSED(info))
1489 {
1490 int absx = 0, absy = 0, stx, sty;
1491 wxHtmlCell *c = this;
1492
1493 while (c)
1494 {
1495 absx += c->GetPosX();
1496 absy += c->GetPosY();
1497 c = c->GetParent();
1498 }
1499
1500 ((wxScrolledWindow*)(m_Wnd->GetParent()))->GetViewStart(&stx, &sty);
1501 m_Wnd->SetSize(absx - wxHTML_SCROLL_STEP * stx, absy - wxHTML_SCROLL_STEP * sty, m_Width, m_Height);
1502 }
1503
1504
1505
1506 void wxHtmlWidgetCell::DrawInvisible(wxDC& WXUNUSED(dc),
1507 int WXUNUSED(x), int WXUNUSED(y),
1508 wxHtmlRenderingInfo& WXUNUSED(info))
1509 {
1510 int absx = 0, absy = 0, stx, sty;
1511 wxHtmlCell *c = this;
1512
1513 while (c)
1514 {
1515 absx += c->GetPosX();
1516 absy += c->GetPosY();
1517 c = c->GetParent();
1518 }
1519
1520 ((wxScrolledWindow*)(m_Wnd->GetParent()))->GetViewStart(&stx, &sty);
1521 m_Wnd->SetSize(absx - wxHTML_SCROLL_STEP * stx, absy - wxHTML_SCROLL_STEP * sty, m_Width, m_Height);
1522 }
1523
1524
1525
1526 void wxHtmlWidgetCell::Layout(int w)
1527 {
1528 if (m_WidthFloat != 0)
1529 {
1530 m_Width = (w * m_WidthFloat) / 100;
1531 m_Wnd->SetSize(m_Width, m_Height);
1532 }
1533
1534 wxHtmlCell::Layout(w);
1535 }
1536
1537
1538
1539 // ----------------------------------------------------------------------------
1540 // wxHtmlTerminalCellsInterator
1541 // ----------------------------------------------------------------------------
1542
1543 const wxHtmlCell* wxHtmlTerminalCellsInterator::operator++()
1544 {
1545 if ( !m_pos )
1546 return NULL;
1547
1548 do
1549 {
1550 if ( m_pos == m_to )
1551 {
1552 m_pos = NULL;
1553 return NULL;
1554 }
1555
1556 if ( m_pos->GetNext() )
1557 m_pos = m_pos->GetNext();
1558 else
1559 {
1560 // we must go up the hierarchy until we reach container where this
1561 // is not the last child, and then go down to first terminal cell:
1562 while ( m_pos->GetNext() == NULL )
1563 {
1564 m_pos = m_pos->GetParent();
1565 if ( !m_pos )
1566 return NULL;
1567 }
1568 m_pos = m_pos->GetNext();
1569 }
1570 while ( m_pos->GetFirstChild() != NULL )
1571 m_pos = m_pos->GetFirstChild();
1572 } while ( !m_pos->IsTerminalCell() );
1573
1574 return m_pos;
1575 }
1576
1577 #endif