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