]> git.saurik.com Git - wxWidgets.git/blob - src/html/htmlcell.cpp
(blind) compilation fix for wxCocoa
[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 = 0;
888
889 const wxHtmlCell *c;
890 if ( line != cell )
891 {
892 for ( c = line->GetNext(); 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 cell on line is not moved:
905 line->SetPos(line->GetPosX() + s_indent,
906 line->GetPosY() + ypos);
907
908 line = line->GetNext();
909 for ( int n = 0; line != cell; line = line->GetNext() )
910 {
911 if ( line->IsLinebreakAllowed() )
912 {
913 // offset the next cell relative to this one
914 // thus increasing our size
915 n++;
916 }
917
918 line->SetPos(line->GetPosX() + s_indent +
919 ((n * step) / total),
920 line->GetPosY() + ypos);
921 }
922 }
923 else
924 {
925 // this will cause the code to enter "else branch" below:
926 step = 0;
927 }
928 }
929 // else branch:
930 if ( step <= 0 ) // no extra space to distribute
931 {
932 // just set the indent properly
933 while (line != cell)
934 {
935 line->SetPos(line->GetPosX() + s_indent,
936 line->GetPosY() + ypos);
937 line = line->GetNext();
938 }
939 }
940 }
941
942 ypos += ysizedown;
943 xpos = 0;
944 ysizeup = ysizedown = 0;
945 line = cell;
946 }
947 }
948
949 // setup height & width, depending on container layout:
950 m_Height = ypos + (ysizedown + ysizeup) + m_IndentBottom;
951
952 if (m_Height < m_MinHeight)
953 {
954 if (m_MinHeightAlign != wxHTML_ALIGN_TOP)
955 {
956 int diff = m_MinHeight - m_Height;
957 if (m_MinHeightAlign == wxHTML_ALIGN_CENTER) diff /= 2;
958 cell = m_Cells;
959 while (cell)
960 {
961 cell->SetPos(cell->GetPosX(), cell->GetPosY() + diff);
962 cell = cell->GetNext();
963 }
964 }
965 m_Height = m_MinHeight;
966 }
967
968 if (curLineWidth > m_MaxTotalWidth)
969 m_MaxTotalWidth = curLineWidth;
970
971 m_MaxTotalWidth += s_indent + ((m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight);
972 MaxLineWidth += s_indent + ((m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight);
973 if (m_Width < MaxLineWidth) m_Width = MaxLineWidth;
974
975 m_LastLayout = w;
976 }
977
978 void wxHtmlContainerCell::UpdateRenderingStatePre(wxHtmlRenderingInfo& info,
979 wxHtmlCell *cell) const
980 {
981 wxHtmlSelection *s = info.GetSelection();
982 if (!s) return;
983 if (s->GetFromCell() == cell || s->GetToCell() == cell)
984 {
985 info.GetState().SetSelectionState(wxHTML_SEL_CHANGING);
986 }
987 }
988
989 void wxHtmlContainerCell::UpdateRenderingStatePost(wxHtmlRenderingInfo& info,
990 wxHtmlCell *cell) const
991 {
992 wxHtmlSelection *s = info.GetSelection();
993 if (!s) return;
994 if (s->GetToCell() == cell)
995 info.GetState().SetSelectionState(wxHTML_SEL_OUT);
996 else if (s->GetFromCell() == cell)
997 info.GetState().SetSelectionState(wxHTML_SEL_IN);
998 }
999
1000 #define mMin(a, b) (((a) < (b)) ? (a) : (b))
1001 #define mMax(a, b) (((a) < (b)) ? (b) : (a))
1002
1003 void wxHtmlContainerCell::Draw(wxDC& dc, int x, int y, int view_y1, int view_y2,
1004 wxHtmlRenderingInfo& info)
1005 {
1006 #if 0 // useful for debugging
1007 dc.SetPen(*wxRED_PEN);
1008 dc.DrawRectangle(x+m_PosX,y+m_PosY,m_Width,m_Height);
1009 #endif
1010
1011 int xlocal = x + m_PosX;
1012 int ylocal = y + m_PosY;
1013
1014 if (m_UseBkColour)
1015 {
1016 wxBrush myb = wxBrush(m_BkColour, wxSOLID);
1017
1018 int real_y1 = mMax(ylocal, view_y1);
1019 int real_y2 = mMin(ylocal + m_Height - 1, view_y2);
1020
1021 dc.SetBrush(myb);
1022 dc.SetPen(*wxTRANSPARENT_PEN);
1023 dc.DrawRectangle(xlocal, real_y1, m_Width, real_y2 - real_y1 + 1);
1024 }
1025
1026 if (m_UseBorder)
1027 {
1028 wxPen mypen1(m_BorderColour1, 1, wxSOLID);
1029 wxPen mypen2(m_BorderColour2, 1, wxSOLID);
1030
1031 dc.SetPen(mypen1);
1032 dc.DrawLine(xlocal, ylocal, xlocal, ylocal + m_Height - 1);
1033 dc.DrawLine(xlocal, ylocal, xlocal + m_Width, ylocal);
1034 dc.SetPen(mypen2);
1035 dc.DrawLine(xlocal + m_Width - 1, ylocal, xlocal + m_Width - 1, ylocal + m_Height - 1);
1036 dc.DrawLine(xlocal, ylocal + m_Height - 1, xlocal + m_Width, ylocal + m_Height - 1);
1037 }
1038
1039 if (m_Cells)
1040 {
1041 // draw container's contents:
1042 for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext())
1043 {
1044
1045 // optimize drawing: don't render off-screen content:
1046 if ((ylocal + cell->GetPosY() <= view_y2) &&
1047 (ylocal + cell->GetPosY() + cell->GetHeight() > view_y1))
1048 {
1049 // the cell is visible, draw it:
1050 UpdateRenderingStatePre(info, cell);
1051 cell->Draw(dc,
1052 xlocal, ylocal, view_y1, view_y2,
1053 info);
1054 UpdateRenderingStatePost(info, cell);
1055 }
1056 else
1057 {
1058 // the cell is off-screen, proceed with font+color+etc.
1059 // changes only:
1060 cell->DrawInvisible(dc, xlocal, ylocal, info);
1061 }
1062 }
1063 }
1064 }
1065
1066
1067
1068 void wxHtmlContainerCell::DrawInvisible(wxDC& dc, int x, int y,
1069 wxHtmlRenderingInfo& info)
1070 {
1071 if (m_Cells)
1072 {
1073 for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext())
1074 {
1075 UpdateRenderingStatePre(info, cell);
1076 cell->DrawInvisible(dc, x + m_PosX, y + m_PosY, info);
1077 UpdateRenderingStatePost(info, cell);
1078 }
1079 }
1080 }
1081
1082
1083 wxColour wxHtmlContainerCell::GetBackgroundColour()
1084 {
1085 if (m_UseBkColour)
1086 return m_BkColour;
1087 else
1088 return wxNullColour;
1089 }
1090
1091
1092
1093 wxHtmlLinkInfo *wxHtmlContainerCell::GetLink(int x, int y) const
1094 {
1095 wxHtmlCell *cell = FindCellByPos(x, y);
1096
1097 // VZ: I don't know if we should pass absolute or relative coords to
1098 // wxHtmlCell::GetLink()? As the base class version just ignores them
1099 // anyhow, it hardly matters right now but should still be clarified
1100 return cell ? cell->GetLink(x, y) : NULL;
1101 }
1102
1103
1104
1105 void wxHtmlContainerCell::InsertCell(wxHtmlCell *f)
1106 {
1107 if (!m_Cells) m_Cells = m_LastCell = f;
1108 else
1109 {
1110 m_LastCell->SetNext(f);
1111 m_LastCell = f;
1112 if (m_LastCell) while (m_LastCell->GetNext()) m_LastCell = m_LastCell->GetNext();
1113 }
1114 f->SetParent(this);
1115 m_LastLayout = -1;
1116 }
1117
1118
1119
1120 void wxHtmlContainerCell::SetAlign(const wxHtmlTag& tag)
1121 {
1122 if (tag.HasParam(wxT("ALIGN")))
1123 {
1124 wxString alg = tag.GetParam(wxT("ALIGN"));
1125 alg.MakeUpper();
1126 if (alg == wxT("CENTER"))
1127 SetAlignHor(wxHTML_ALIGN_CENTER);
1128 else if (alg == wxT("LEFT"))
1129 SetAlignHor(wxHTML_ALIGN_LEFT);
1130 else if (alg == wxT("JUSTIFY"))
1131 SetAlignHor(wxHTML_ALIGN_JUSTIFY);
1132 else if (alg == wxT("RIGHT"))
1133 SetAlignHor(wxHTML_ALIGN_RIGHT);
1134 m_LastLayout = -1;
1135 }
1136 }
1137
1138
1139
1140 void wxHtmlContainerCell::SetWidthFloat(const wxHtmlTag& tag, double pixel_scale)
1141 {
1142 if (tag.HasParam(wxT("WIDTH")))
1143 {
1144 int wdi;
1145 wxString wd = tag.GetParam(wxT("WIDTH"));
1146
1147 if (wd[wd.length()-1] == wxT('%'))
1148 {
1149 wxSscanf(wd.c_str(), wxT("%i%%"), &wdi);
1150 SetWidthFloat(wdi, wxHTML_UNITS_PERCENT);
1151 }
1152 else
1153 {
1154 wxSscanf(wd.c_str(), wxT("%i"), &wdi);
1155 SetWidthFloat((int)(pixel_scale * (double)wdi), wxHTML_UNITS_PIXELS);
1156 }
1157 m_LastLayout = -1;
1158 }
1159 }
1160
1161
1162
1163 const wxHtmlCell* wxHtmlContainerCell::Find(int condition, const void* param) const
1164 {
1165 if (m_Cells)
1166 {
1167 for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext())
1168 {
1169 const wxHtmlCell *r = cell->Find(condition, param);
1170 if (r) return r;
1171 }
1172 }
1173 return NULL;
1174 }
1175
1176
1177 wxHtmlCell *wxHtmlContainerCell::FindCellByPos(wxCoord x, wxCoord y,
1178 unsigned flags) const
1179 {
1180 if ( flags & wxHTML_FIND_EXACT )
1181 {
1182 for ( const wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext() )
1183 {
1184 int cx = cell->GetPosX(),
1185 cy = cell->GetPosY();
1186
1187 if ( (cx <= x) && (cx + cell->GetWidth() > x) &&
1188 (cy <= y) && (cy + cell->GetHeight() > y) )
1189 {
1190 return cell->FindCellByPos(x - cx, y - cy, flags);
1191 }
1192 }
1193 }
1194 else if ( flags & wxHTML_FIND_NEAREST_AFTER )
1195 {
1196 wxHtmlCell *c;
1197 for ( const wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext() )
1198 {
1199 if ( cell->IsFormattingCell() )
1200 continue;
1201 int cellY = cell->GetPosY();
1202 if (!( y < cellY || (y < cellY + cell->GetHeight() &&
1203 x < cell->GetPosX() + cell->GetWidth()) ))
1204 continue;
1205
1206 c = cell->FindCellByPos(x - cell->GetPosX(), y - cellY, flags);
1207 if (c) return c;
1208 }
1209 }
1210 else if ( flags & wxHTML_FIND_NEAREST_BEFORE )
1211 {
1212 wxHtmlCell *c2, *c = NULL;
1213 for ( const wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext() )
1214 {
1215 if ( cell->IsFormattingCell() )
1216 continue;
1217 int cellY = cell->GetPosY();
1218 if (!( cellY + cell->GetHeight() <= y ||
1219 (y >= cellY && x >= cell->GetPosX()) ))
1220 break;
1221 c2 = cell->FindCellByPos(x - cell->GetPosX(), y - cellY, flags);
1222 if (c2)
1223 c = c2;
1224 }
1225 if (c) return c;
1226 }
1227
1228 return NULL;
1229 }
1230
1231
1232 bool wxHtmlContainerCell::ProcessMouseClick(wxHtmlWindowInterface *window,
1233 const wxPoint& pos,
1234 const wxMouseEvent& event)
1235 {
1236 #if WXWIN_COMPATIBILITY_2_6
1237 wxHtmlCellOnMouseClickCompatHelper compat(window, pos, event);
1238 return compat.CallOnMouseClick(this);
1239 }
1240
1241 void wxHtmlContainerCell::OnMouseClick(wxWindow*,
1242 int, int, const wxMouseEvent& event)
1243 {
1244 wxCHECK_RET( gs_helperOnMouseClick, _T("unexpected call to OnMouseClick") );
1245 wxHtmlWindowInterface *window = gs_helperOnMouseClick->window;
1246 const wxPoint& pos = gs_helperOnMouseClick->pos;
1247 #endif // WXWIN_COMPATIBILITY_2_6
1248
1249 bool retval = false;
1250 wxHtmlCell *cell = FindCellByPos(pos.x, pos.y);
1251 if ( cell )
1252 retval = cell->ProcessMouseClick(window, pos, event);
1253
1254 #if WXWIN_COMPATIBILITY_2_6
1255 gs_helperOnMouseClick->retval = retval;
1256 #else
1257 return retval;
1258 #endif // WXWIN_COMPATIBILITY_2_6
1259 }
1260
1261
1262 wxHtmlCell *wxHtmlContainerCell::GetFirstTerminal() const
1263 {
1264 if ( m_Cells )
1265 {
1266 wxHtmlCell *c2;
1267 for (wxHtmlCell *c = m_Cells; c; c = c->GetNext())
1268 {
1269 c2 = c->GetFirstTerminal();
1270 if ( c2 )
1271 return c2;
1272 }
1273 }
1274 return NULL;
1275 }
1276
1277 wxHtmlCell *wxHtmlContainerCell::GetLastTerminal() const
1278 {
1279 if ( m_Cells )
1280 {
1281 // most common case first:
1282 wxHtmlCell *c = m_LastCell->GetLastTerminal();
1283 if ( c )
1284 return c;
1285
1286 wxHtmlCell *ctmp;
1287 wxHtmlCell *c2 = NULL;
1288 for (c = m_Cells; c; c = c->GetNext())
1289 {
1290 ctmp = c->GetLastTerminal();
1291 if ( ctmp )
1292 c2 = ctmp;
1293 }
1294 return c2;
1295 }
1296 else
1297 return NULL;
1298 }
1299
1300
1301 static bool IsEmptyContainer(wxHtmlContainerCell *cell)
1302 {
1303 for ( wxHtmlCell *c = cell->GetFirstChild(); c; c = c->GetNext() )
1304 {
1305 if ( !c->IsTerminalCell() || !c->IsFormattingCell() )
1306 return false;
1307 }
1308 return true;
1309 }
1310
1311 void wxHtmlContainerCell::RemoveExtraSpacing(bool top, bool bottom)
1312 {
1313 if ( top )
1314 SetIndent(0, wxHTML_INDENT_TOP);
1315 if ( bottom )
1316 SetIndent(0, wxHTML_INDENT_BOTTOM);
1317
1318 if ( m_Cells )
1319 {
1320 wxHtmlCell *c;
1321 wxHtmlContainerCell *cont;
1322 if ( top )
1323 {
1324 for ( c = m_Cells; c; c = c->GetNext() )
1325 {
1326 if ( c->IsTerminalCell() )
1327 {
1328 if ( !c->IsFormattingCell() )
1329 break;
1330 }
1331 else
1332 {
1333 cont = (wxHtmlContainerCell*)c;
1334 if ( IsEmptyContainer(cont) )
1335 {
1336 cont->SetIndent(0, wxHTML_INDENT_VERTICAL);
1337 }
1338 else
1339 {
1340 cont->RemoveExtraSpacing(true, false);
1341 break;
1342 }
1343 }
1344 }
1345 }
1346
1347 if ( bottom )
1348 {
1349 wxArrayPtrVoid arr;
1350 for ( c = m_Cells; c; c = c->GetNext() )
1351 arr.Add((void*)c);
1352
1353 for ( int i = arr.GetCount() - 1; i >= 0; i--)
1354 {
1355 c = (wxHtmlCell*)arr[i];
1356 if ( c->IsTerminalCell() )
1357 {
1358 if ( !c->IsFormattingCell() )
1359 break;
1360 }
1361 else
1362 {
1363 cont = (wxHtmlContainerCell*)c;
1364 if ( IsEmptyContainer(cont) )
1365 {
1366 cont->SetIndent(0, wxHTML_INDENT_VERTICAL);
1367 }
1368 else
1369 {
1370 cont->RemoveExtraSpacing(false, true);
1371 break;
1372 }
1373 }
1374 }
1375 }
1376 }
1377 }
1378
1379
1380
1381
1382 // --------------------------------------------------------------------------
1383 // wxHtmlColourCell
1384 // --------------------------------------------------------------------------
1385
1386 IMPLEMENT_ABSTRACT_CLASS(wxHtmlColourCell, wxHtmlCell)
1387
1388 void wxHtmlColourCell::Draw(wxDC& dc,
1389 int x, int y,
1390 int WXUNUSED(view_y1), int WXUNUSED(view_y2),
1391 wxHtmlRenderingInfo& info)
1392 {
1393 DrawInvisible(dc, x, y, info);
1394 }
1395
1396 void wxHtmlColourCell::DrawInvisible(wxDC& dc,
1397 int WXUNUSED(x), int WXUNUSED(y),
1398 wxHtmlRenderingInfo& info)
1399 {
1400 wxHtmlRenderingState& state = info.GetState();
1401 if (m_Flags & wxHTML_CLR_FOREGROUND)
1402 {
1403 state.SetFgColour(m_Colour);
1404 if (state.GetSelectionState() != wxHTML_SEL_IN)
1405 dc.SetTextForeground(m_Colour);
1406 else
1407 dc.SetTextForeground(
1408 info.GetStyle().GetSelectedTextColour(m_Colour));
1409 }
1410 if (m_Flags & wxHTML_CLR_BACKGROUND)
1411 {
1412 state.SetBgColour(m_Colour);
1413 if (state.GetSelectionState() != wxHTML_SEL_IN)
1414 {
1415 dc.SetTextBackground(m_Colour);
1416 dc.SetBackground(wxBrush(m_Colour, wxSOLID));
1417 }
1418 else
1419 {
1420 wxColour c = info.GetStyle().GetSelectedTextBgColour(m_Colour);
1421 dc.SetTextBackground(c);
1422 dc.SetBackground(wxBrush(c, wxSOLID));
1423 }
1424 }
1425 }
1426
1427
1428
1429
1430 // ---------------------------------------------------------------------------
1431 // wxHtmlFontCell
1432 // ---------------------------------------------------------------------------
1433
1434 IMPLEMENT_ABSTRACT_CLASS(wxHtmlFontCell, wxHtmlCell)
1435
1436 void wxHtmlFontCell::Draw(wxDC& dc,
1437 int WXUNUSED(x), int WXUNUSED(y),
1438 int WXUNUSED(view_y1), int WXUNUSED(view_y2),
1439 wxHtmlRenderingInfo& WXUNUSED(info))
1440 {
1441 dc.SetFont(m_Font);
1442 }
1443
1444 void wxHtmlFontCell::DrawInvisible(wxDC& dc, int WXUNUSED(x), int WXUNUSED(y),
1445 wxHtmlRenderingInfo& WXUNUSED(info))
1446 {
1447 dc.SetFont(m_Font);
1448 }
1449
1450
1451
1452
1453
1454
1455
1456
1457 // ---------------------------------------------------------------------------
1458 // wxHtmlWidgetCell
1459 // ---------------------------------------------------------------------------
1460
1461 IMPLEMENT_ABSTRACT_CLASS(wxHtmlWidgetCell, wxHtmlCell)
1462
1463 wxHtmlWidgetCell::wxHtmlWidgetCell(wxWindow *wnd, int w)
1464 {
1465 int sx, sy;
1466 m_Wnd = wnd;
1467 m_Wnd->GetSize(&sx, &sy);
1468 m_Width = sx, m_Height = sy;
1469 m_WidthFloat = w;
1470 }
1471
1472
1473 void wxHtmlWidgetCell::Draw(wxDC& WXUNUSED(dc),
1474 int WXUNUSED(x), int WXUNUSED(y),
1475 int WXUNUSED(view_y1), int WXUNUSED(view_y2),
1476 wxHtmlRenderingInfo& WXUNUSED(info))
1477 {
1478 int absx = 0, absy = 0, stx, sty;
1479 wxHtmlCell *c = this;
1480
1481 while (c)
1482 {
1483 absx += c->GetPosX();
1484 absy += c->GetPosY();
1485 c = c->GetParent();
1486 }
1487
1488 ((wxScrolledWindow*)(m_Wnd->GetParent()))->GetViewStart(&stx, &sty);
1489 m_Wnd->SetSize(absx - wxHTML_SCROLL_STEP * stx, absy - wxHTML_SCROLL_STEP * sty, m_Width, m_Height);
1490 }
1491
1492
1493
1494 void wxHtmlWidgetCell::DrawInvisible(wxDC& WXUNUSED(dc),
1495 int WXUNUSED(x), int WXUNUSED(y),
1496 wxHtmlRenderingInfo& WXUNUSED(info))
1497 {
1498 int absx = 0, absy = 0, stx, sty;
1499 wxHtmlCell *c = this;
1500
1501 while (c)
1502 {
1503 absx += c->GetPosX();
1504 absy += c->GetPosY();
1505 c = c->GetParent();
1506 }
1507
1508 ((wxScrolledWindow*)(m_Wnd->GetParent()))->GetViewStart(&stx, &sty);
1509 m_Wnd->SetSize(absx - wxHTML_SCROLL_STEP * stx, absy - wxHTML_SCROLL_STEP * sty, m_Width, m_Height);
1510 }
1511
1512
1513
1514 void wxHtmlWidgetCell::Layout(int w)
1515 {
1516 if (m_WidthFloat != 0)
1517 {
1518 m_Width = (w * m_WidthFloat) / 100;
1519 m_Wnd->SetSize(m_Width, m_Height);
1520 }
1521
1522 wxHtmlCell::Layout(w);
1523 }
1524
1525
1526
1527 // ----------------------------------------------------------------------------
1528 // wxHtmlTerminalCellsInterator
1529 // ----------------------------------------------------------------------------
1530
1531 const wxHtmlCell* wxHtmlTerminalCellsInterator::operator++()
1532 {
1533 if ( !m_pos )
1534 return NULL;
1535
1536 do
1537 {
1538 if ( m_pos == m_to )
1539 {
1540 m_pos = NULL;
1541 return NULL;
1542 }
1543
1544 if ( m_pos->GetNext() )
1545 m_pos = m_pos->GetNext();
1546 else
1547 {
1548 // we must go up the hierarchy until we reach container where this
1549 // is not the last child, and then go down to first terminal cell:
1550 while ( m_pos->GetNext() == NULL )
1551 {
1552 m_pos = m_pos->GetParent();
1553 if ( !m_pos )
1554 return NULL;
1555 }
1556 m_pos = m_pos->GetNext();
1557 }
1558 while ( m_pos->GetFirstChild() != NULL )
1559 m_pos = m_pos->GetFirstChild();
1560 } while ( !m_pos->IsTerminalCell() );
1561
1562 return m_pos;
1563 }
1564
1565 #endif