1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/html/htmlcell.cpp
3 // Purpose: wxHtmlCell - basic element of HTML output
4 // Author: Vaclav Slavik
6 // Copyright: (c) 1999 Vaclav Slavik
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 #include "wx/wxprec.h"
16 #if wxUSE_HTML && wxUSE_STREAMS
19 #include "wx/dynarray.h"
21 #include "wx/colour.h"
23 #include "wx/settings.h"
24 #include "wx/module.h"
25 #include "wx/wxcrtvararg.h"
28 #include "wx/html/htmlcell.h"
29 #include "wx/html/htmlwin.h"
33 //-----------------------------------------------------------------------------
35 //-----------------------------------------------------------------------------
37 void wxHtmlSelection::Set(const wxPoint
& fromPos
, const wxHtmlCell
*fromCell
,
38 const wxPoint
& toPos
, const wxHtmlCell
*toCell
)
40 m_fromCell
= fromCell
;
46 void wxHtmlSelection::Set(const wxHtmlCell
*fromCell
, const wxHtmlCell
*toCell
)
48 wxPoint p1
= fromCell
? fromCell
->GetAbsPos() : wxDefaultPosition
;
49 wxPoint p2
= toCell
? toCell
->GetAbsPos() : wxDefaultPosition
;
52 p2
.x
+= toCell
->GetWidth();
53 p2
.y
+= toCell
->GetHeight();
55 Set(p1
, fromCell
, p2
, toCell
);
59 wxDefaultHtmlRenderingStyle::
60 GetSelectedTextColour(const wxColour
& WXUNUSED(clr
))
62 return wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
66 wxDefaultHtmlRenderingStyle::
67 GetSelectedTextBgColour(const wxColour
& WXUNUSED(clr
))
69 return wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
);
73 //-----------------------------------------------------------------------------
75 //-----------------------------------------------------------------------------
77 IMPLEMENT_ABSTRACT_CLASS(wxHtmlCell
, wxObject
)
79 wxHtmlCell::wxHtmlCell() : wxObject()
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;
90 wxHtmlCell::~wxHtmlCell()
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
)
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;
106 m_ScriptBaseline
= 0;
108 m_Descent
+= m_ScriptBaseline
;
111 #if WXWIN_COMPATIBILITY_2_6
113 struct wxHtmlCellOnMouseClickCompatHelper
;
115 static wxHtmlCellOnMouseClickCompatHelper
*gs_helperOnMouseClick
= NULL
;
117 // helper for routing calls to new ProcessMouseClick() method to deprecated
118 // OnMouseClick() method
119 struct wxHtmlCellOnMouseClickCompatHelper
121 wxHtmlCellOnMouseClickCompatHelper(wxHtmlWindowInterface
*window_
,
123 const wxMouseEvent
& event_
)
124 : window(window_
), pos(pos_
), event(event_
), retval(false)
128 bool CallOnMouseClick(wxHtmlCell
*cell
)
130 wxHtmlCellOnMouseClickCompatHelper
*oldHelper
= gs_helperOnMouseClick
;
131 gs_helperOnMouseClick
= this;
134 window
? window
->GetHTMLWindow() : NULL
,
138 gs_helperOnMouseClick
= oldHelper
;
142 wxHtmlWindowInterface
*window
;
144 const wxMouseEvent
& event
;
147 #endif // WXWIN_COMPATIBILITY_2_6
149 bool wxHtmlCell::ProcessMouseClick(wxHtmlWindowInterface
*window
,
151 const wxMouseEvent
& event
)
153 wxCHECK_MSG( window
, false, wxT("window interface must be provided") );
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
161 wxHtmlCellOnMouseClickCompatHelper
compat(window
, pos
, event
);
162 return compat
.CallOnMouseClick(this);
165 void wxHtmlCell::OnMouseClick(wxWindow
*, int, int, const wxMouseEvent
& event
)
167 wxCHECK_RET( gs_helperOnMouseClick
, wxT("unexpected call to OnMouseClick") );
168 wxHtmlWindowInterface
*window
= gs_helperOnMouseClick
->window
;
169 const wxPoint
& pos
= gs_helperOnMouseClick
->pos
;
170 #endif // WXWIN_COMPATIBILITY_2_6
172 wxHtmlLinkInfo
*lnk
= GetLink(pos
.x
, pos
.y
);
177 wxHtmlLinkInfo
lnk2(*lnk
);
178 lnk2
.SetEvent(&event
);
179 lnk2
.SetHtmlCell(this);
181 window
->OnHTMLLinkClicked(lnk2
);
185 #if WXWIN_COMPATIBILITY_2_6
186 gs_helperOnMouseClick
->retval
= retval
;
189 #endif // WXWIN_COMPATIBILITY_2_6
192 #if WXWIN_COMPATIBILITY_2_6
193 wxCursor
wxHtmlCell::GetCursor() const
197 #endif // WXWIN_COMPATIBILITY_2_6
200 wxHtmlCell::GetMouseCursor(wxHtmlWindowInterface
* WXUNUSED(window
)) const
202 // This is never called directly, only from GetMouseCursorAt() and we
203 // return an invalid cursor by default to let it delegate to the window.
208 wxHtmlCell::GetMouseCursorAt(wxHtmlWindowInterface
*window
,
209 const wxPoint
& relPos
) const
211 #if WXWIN_COMPATIBILITY_2_6
212 // NB: Older versions of wx used GetCursor() virtual method in place of
213 // GetMouseCursor(interface). This code ensures that user code that
214 // overridden GetCursor() continues to work. The trick is that the base
215 // wxHtmlCell::GetCursor() method simply returns wxNullCursor, so we
216 // know that GetCursor() was overridden iff it returns valid cursor.
217 wxCursor cur
= GetCursor();
220 #endif // WXWIN_COMPATIBILITY_2_6
222 const wxCursor curCell
= GetMouseCursor(window
);
223 if ( curCell
.IsOk() )
226 if ( GetLink(relPos
.x
, relPos
.y
) )
228 return window
->GetHTMLCursor(wxHtmlWindowInterface::HTMLCursor_Link
);
232 return window
->GetHTMLCursor(wxHtmlWindowInterface::HTMLCursor_Default
);
238 wxHtmlCell::AdjustPagebreak(int *pagebreak
,
239 const wxArrayInt
& WXUNUSED(known_pagebreaks
),
240 int pageHeight
) const
242 // Notice that we always break the cells bigger than the page height here
243 // as otherwise we wouldn't be able to break them at all.
244 if ( m_Height
<= pageHeight
&&
245 (!m_CanLiveOnPagebreak
&&
246 m_PosY
< *pagebreak
&& m_PosY
+ m_Height
> *pagebreak
) )
257 void wxHtmlCell::SetLink(const wxHtmlLinkInfo
& link
)
260 if (link
.GetHref() != wxEmptyString
)
261 m_Link
= new wxHtmlLinkInfo(link
);
265 void wxHtmlCell::Layout(int WXUNUSED(w
))
272 const wxHtmlCell
* wxHtmlCell::Find(int WXUNUSED(condition
), const void* WXUNUSED(param
)) const
278 wxHtmlCell
*wxHtmlCell::FindCellByPos(wxCoord x
, wxCoord y
,
279 unsigned flags
) const
281 if ( x
>= 0 && x
< m_Width
&& y
>= 0 && y
< m_Height
)
283 return wxConstCast(this, wxHtmlCell
);
287 if ((flags
& wxHTML_FIND_NEAREST_AFTER
) &&
288 (y
< 0 || (y
< 0+m_Height
&& x
< 0+m_Width
)))
289 return wxConstCast(this, wxHtmlCell
);
290 else if ((flags
& wxHTML_FIND_NEAREST_BEFORE
) &&
291 (y
>= 0+m_Height
|| (y
>= 0 && x
>= 0)))
292 return wxConstCast(this, wxHtmlCell
);
299 wxPoint
wxHtmlCell::GetAbsPos(wxHtmlCell
*rootCell
) const
301 wxPoint
p(m_PosX
, m_PosY
);
302 for (wxHtmlCell
*parent
= m_Parent
; parent
&& parent
!= rootCell
;
303 parent
= parent
->m_Parent
)
305 p
.x
+= parent
->m_PosX
;
306 p
.y
+= parent
->m_PosY
;
311 wxHtmlCell
*wxHtmlCell::GetRootCell() const
313 wxHtmlCell
*c
= wxConstCast(this, wxHtmlCell
);
314 while ( c
->m_Parent
)
319 unsigned wxHtmlCell::GetDepth() const
322 for (wxHtmlCell
*p
= m_Parent
; p
; p
= p
->m_Parent
)
327 bool wxHtmlCell::IsBefore(wxHtmlCell
*cell
) const
329 const wxHtmlCell
*c1
= this;
330 const wxHtmlCell
*c2
= cell
;
331 unsigned d1
= GetDepth();
332 unsigned d2
= cell
->GetDepth();
335 for (; d1
!= d2
; d1
-- )
338 for (; d1
!= d2
; d2
-- )
346 if ( c1
->m_Parent
== c2
->m_Parent
)
363 wxFAIL_MSG(wxT("Cells are in different trees"));
368 //-----------------------------------------------------------------------------
370 //-----------------------------------------------------------------------------
372 IMPLEMENT_ABSTRACT_CLASS(wxHtmlWordCell
, wxHtmlCell
)
374 wxHtmlWordCell::wxHtmlWordCell(const wxString
& word
, const wxDC
& dc
) : wxHtmlCell()
378 dc
.GetTextExtent(m_Word
, &w
, &h
, &d
);
382 SetCanLiveOnPagebreak(false);
383 m_allowLinebreak
= true;
386 void wxHtmlWordCell::SetPreviousWord(wxHtmlWordCell
*cell
)
388 if ( cell
&& m_Parent
== cell
->m_Parent
&&
389 !wxIsspace(cell
->m_Word
.Last()) && !wxIsspace(m_Word
[0u]) )
391 m_allowLinebreak
= false;
395 // Splits m_Word into up to three parts according to selection, returns
396 // substring before, in and after selection and the points (in relative coords)
397 // where s2 and s3 start:
398 void wxHtmlWordCell::Split(const wxDC
& dc
,
399 const wxPoint
& selFrom
, const wxPoint
& selTo
,
400 unsigned& pos1
, unsigned& pos2
) const
402 wxPoint pt1
= (selFrom
== wxDefaultPosition
) ?
403 wxDefaultPosition
: selFrom
- GetAbsPos();
404 wxPoint pt2
= (selTo
== wxDefaultPosition
) ?
405 wxPoint(m_Width
, wxDefaultCoord
) : selTo
- GetAbsPos();
407 // if the selection is entirely within this cell, make sure pt1 < pt2 in
408 // order to make the rest of this function simpler:
409 if ( selFrom
!= wxDefaultPosition
&& selTo
!= wxDefaultPosition
&&
410 selFrom
.x
> selTo
.x
)
417 unsigned len
= m_Word
.length();
421 // adjust for cases when the start/end position is completely
425 if ( pt2
.y
>= m_Height
)
429 // (include character under caret only if in first half of width)
431 // implementation using PartialExtents to support fractional widths
433 dc
.GetPartialTextExtents(m_Word
,widths
) ;
434 while( i
< len
&& pt1
.x
>= widths
[i
] )
438 int charW
= (i
> 0) ? widths
[i
] - widths
[i
-1] : widths
[i
];
439 if ( widths
[i
] - pt1
.x
< charW
/2 )
443 wxCoord charW
, charH
;
444 while ( pt1
.x
> 0 && i
< len
)
446 dc
.GetTextExtent(m_Word
[i
], &charW
, &charH
);
448 if ( pt1
.x
>= -charW
/2 )
454 #endif // __WXMAC__/!__WXMAC__
457 // (include character under caret only if in first half of width)
460 while( j
< len
&& pt2
.x
>= widths
[j
] )
464 int charW
= (j
> 0) ? widths
[j
] - widths
[j
-1] : widths
[j
];
465 if ( widths
[j
] - pt2
.x
< charW
/2 )
471 while ( pt2
.x
> 0 && j
< len
)
473 dc
.GetTextExtent(m_Word
[j
], &charW
, &charH
);
475 if ( pt2
.x
>= -charW
/2 )
481 #endif // __WXMAC__/!__WXMAC__
486 wxASSERT( pos2
>= pos1
);
489 void wxHtmlWordCell::SetSelectionPrivPos(const wxDC
& dc
, wxHtmlSelection
*s
) const
494 this == s
->GetFromCell() ? s
->GetFromPos() : wxDefaultPosition
,
495 this == s
->GetToCell() ? s
->GetToPos() : wxDefaultPosition
,
498 if ( this == s
->GetFromCell() )
499 s
->SetFromCharacterPos (p1
); // selection starts here
500 if ( this == s
->GetToCell() )
501 s
->SetToCharacterPos (p2
); // selection ends here
505 static void SwitchSelState(wxDC
& dc
, wxHtmlRenderingInfo
& info
,
508 wxColour fg
= info
.GetState().GetFgColour();
509 wxColour bg
= info
.GetState().GetBgColour();
513 dc
.SetBackgroundMode(wxSOLID
);
514 dc
.SetTextForeground(info
.GetStyle().GetSelectedTextColour(fg
));
515 dc
.SetTextBackground(info
.GetStyle().GetSelectedTextBgColour(bg
));
516 dc
.SetBackground(wxBrush(info
.GetStyle().GetSelectedTextBgColour(bg
),
517 wxBRUSHSTYLE_SOLID
));
521 const int mode
= info
.GetState().GetBgMode();
522 dc
.SetBackgroundMode(mode
);
523 dc
.SetTextForeground(fg
);
524 dc
.SetTextBackground(bg
);
525 if ( mode
!= wxTRANSPARENT
)
526 dc
.SetBackground(wxBrush(bg
, mode
));
531 void wxHtmlWordCell::Draw(wxDC
& dc
, int x
, int y
,
532 int WXUNUSED(view_y1
), int WXUNUSED(view_y2
),
533 wxHtmlRenderingInfo
& info
)
535 #if 0 // useful for debugging
536 dc
.SetPen(*wxBLACK_PEN
);
537 dc
.DrawRectangle(x
+m_PosX
,y
+m_PosY
,m_Width
/* VZ: +1? */ ,m_Height
);
540 bool drawSelectionAfterCell
= false;
542 if ( info
.GetState().GetSelectionState() == wxHTML_SEL_CHANGING
)
544 // Selection changing, we must draw the word piecewise:
545 wxHtmlSelection
*s
= info
.GetSelection();
550 // NB: this is quite a hack: in order to compute selection boundaries
551 // (in word's characters) we must know current font, which is only
552 // possible inside rendering code. Therefore we update the
553 // information here and store it in wxHtmlSelection so that
554 // ConvertToText can use it later:
555 if ( !s
->AreFromToCharacterPosSet () )
557 SetSelectionPrivPos(dc
, s
);
560 int part1
= s
->GetFromCell()==this ? s
->GetFromCharacterPos() : 0;
561 int part2
= s
->GetToCell()==this ? s
->GetToCharacterPos() : m_Word
.Length();
565 txt
= m_Word
.Mid(0, part1
);
566 dc
.DrawText(txt
, x
+ m_PosX
, y
+ m_PosY
);
567 dc
.GetTextExtent(txt
, &w
, &h
);
571 SwitchSelState(dc
, info
, true);
573 txt
= m_Word
.Mid(part1
, part2
-part1
);
574 dc
.DrawText(txt
, ofs
+ x
+ m_PosX
, y
+ m_PosY
);
576 if ( (size_t)part2
< m_Word
.length() )
578 dc
.GetTextExtent(txt
, &w
, &h
);
580 SwitchSelState(dc
, info
, false);
581 txt
= m_Word
.Mid(part2
);
582 dc
.DrawText(txt
, ofs
+ x
+ m_PosX
, y
+ m_PosY
);
585 drawSelectionAfterCell
= true;
589 wxHtmlSelectionState selstate
= info
.GetState().GetSelectionState();
590 // Not changing selection state, draw the word in single mode:
591 SwitchSelState(dc
, info
, selstate
!= wxHTML_SEL_OUT
);
592 dc
.DrawText(m_Word
, x
+ m_PosX
, y
+ m_PosY
);
593 drawSelectionAfterCell
= (selstate
!= wxHTML_SEL_OUT
);
596 // NB: If the text is justified then there is usually some free space
597 // between adjacent cells and drawing the selection only onto cells
598 // would result in ugly unselected spaces. The code below detects
599 // this special case and renders the selection *outside* the sell,
601 if ( m_Parent
->GetAlignHor() == wxHTML_ALIGN_JUSTIFY
&&
602 drawSelectionAfterCell
)
604 wxHtmlCell
*nextCell
= m_Next
;
605 while ( nextCell
&& nextCell
->IsFormattingCell() )
606 nextCell
= nextCell
->GetNext();
609 int nextX
= nextCell
->GetPosX();
610 if ( m_PosX
+ m_Width
< nextX
)
612 dc
.SetBrush(dc
.GetBackground());
613 dc
.SetPen(*wxTRANSPARENT_PEN
);
614 dc
.DrawRectangle(x
+ m_PosX
+ m_Width
, y
+ m_PosY
,
615 nextX
- m_PosX
- m_Width
, m_Height
);
621 wxCursor
wxHtmlWordCell::GetMouseCursor(wxHtmlWindowInterface
*window
) const
625 return window
->GetHTMLCursor(wxHtmlWindowInterface::HTMLCursor_Text
);
629 return wxHtmlCell::GetMouseCursor(window
);
633 wxString
wxHtmlWordCell::ConvertToText(wxHtmlSelection
*s
) const
635 if ( s
&& (this == s
->GetFromCell() || this == s
->GetToCell()) )
637 // VZ: we may be called before we had a chance to re-render ourselves
638 // and in this case GetFrom/ToPrivPos() is not set yet -- assume
639 // that this only happens in case of a double/triple click (which
640 // seems to be the case now) and so it makes sense to select the
641 // entire contents of the cell in this case
643 // TODO: but this really needs to be fixed in some better way later...
644 if ( s
->AreFromToCharacterPosSet() )
646 const int part1
= s
->GetFromCell()==this ? s
->GetFromCharacterPos() : 0;
647 const int part2
= s
->GetToCell()==this ? s
->GetToCharacterPos() : m_Word
.Length();
648 if ( part1
== part2
)
649 return wxEmptyString
;
650 return GetPartAsText(part1
, part2
);
652 //else: return the whole word below
655 return GetAllAsText();
658 wxString
wxHtmlWordWithTabsCell::GetAllAsText() const
663 wxString
wxHtmlWordWithTabsCell::GetPartAsText(int begin
, int end
) const
665 // NB: The 'begin' and 'end' positions are in the _displayed_ text
666 // (stored in m_Word) and not in the text with tabs that should
667 // be copied to clipboard (m_wordOrig).
669 // NB: Because selection is performed on displayed text, it's possible
670 // to select e.g. "half of TAB character" -- IOW, 'begin' and 'end'
671 // may be in the middle of TAB character expansion into ' 's. In this
672 // case, we copy the TAB character to clipboard once.
674 wxASSERT( begin
< end
);
676 const unsigned SPACES_PER_TAB
= 8;
681 wxString::const_iterator i
= m_wordOrig
.begin();
683 // find the beginning of text to copy:
684 for ( ; pos
< begin
; ++i
)
688 pos
+= 8 - (m_linepos
+ pos
) % SPACES_PER_TAB
;
700 // copy the content until we reach 'end':
701 for ( ; pos
< end
; ++i
)
707 pos
+= 8 - (m_linepos
+ pos
) % SPACES_PER_TAB
;
717 //-----------------------------------------------------------------------------
718 // wxHtmlContainerCell
719 //-----------------------------------------------------------------------------
721 IMPLEMENT_ABSTRACT_CLASS(wxHtmlContainerCell
, wxHtmlCell
)
723 wxHtmlContainerCell::wxHtmlContainerCell(wxHtmlContainerCell
*parent
) : wxHtmlCell()
725 m_Cells
= m_LastCell
= NULL
;
728 if (m_Parent
) m_Parent
->InsertCell(this);
729 m_AlignHor
= wxHTML_ALIGN_LEFT
;
730 m_AlignVer
= wxHTML_ALIGN_BOTTOM
;
731 m_IndentLeft
= m_IndentRight
= m_IndentTop
= m_IndentBottom
= 0;
732 m_WidthFloat
= 100; m_WidthFloatUnits
= wxHTML_UNITS_PERCENT
;
733 m_BkColour
= wxNullColour
;
736 m_MinHeightAlign
= wxHTML_ALIGN_TOP
;
740 wxHtmlContainerCell::~wxHtmlContainerCell()
742 wxHtmlCell
*cell
= m_Cells
;
745 wxHtmlCell
*cellNext
= cell
->GetNext();
753 void wxHtmlContainerCell::SetIndent(int i
, int what
, int units
)
755 int val
= (units
== wxHTML_UNITS_PIXELS
) ? i
: -i
;
756 if (what
& wxHTML_INDENT_LEFT
) m_IndentLeft
= val
;
757 if (what
& wxHTML_INDENT_RIGHT
) m_IndentRight
= val
;
758 if (what
& wxHTML_INDENT_TOP
) m_IndentTop
= val
;
759 if (what
& wxHTML_INDENT_BOTTOM
) m_IndentBottom
= val
;
765 int wxHtmlContainerCell::GetIndent(int ind
) const
767 if (ind
& wxHTML_INDENT_LEFT
) return m_IndentLeft
;
768 else if (ind
& wxHTML_INDENT_RIGHT
) return m_IndentRight
;
769 else if (ind
& wxHTML_INDENT_TOP
) return m_IndentTop
;
770 else if (ind
& wxHTML_INDENT_BOTTOM
) return m_IndentBottom
;
771 else return -1; /* BUG! Should not be called... */
777 int wxHtmlContainerCell::GetIndentUnits(int ind
) const
780 if (ind
& wxHTML_INDENT_LEFT
) p
= m_IndentLeft
< 0;
781 else if (ind
& wxHTML_INDENT_RIGHT
) p
= m_IndentRight
< 0;
782 else if (ind
& wxHTML_INDENT_TOP
) p
= m_IndentTop
< 0;
783 else if (ind
& wxHTML_INDENT_BOTTOM
) p
= m_IndentBottom
< 0;
784 if (p
) return wxHTML_UNITS_PERCENT
;
785 else return wxHTML_UNITS_PIXELS
;
790 wxHtmlContainerCell::AdjustPagebreak(int *pagebreak
,
791 const wxArrayInt
& known_pagebreaks
,
792 int pageHeight
) const
794 if (!m_CanLiveOnPagebreak
)
795 return wxHtmlCell::AdjustPagebreak(pagebreak
, known_pagebreaks
, pageHeight
);
797 wxHtmlCell
*c
= GetFirstChild();
799 int pbrk
= *pagebreak
- m_PosY
;
803 if (c
->AdjustPagebreak(&pbrk
, known_pagebreaks
, pageHeight
))
808 *pagebreak
= pbrk
+ m_PosY
;
813 void wxHtmlContainerCell::Layout(int w
)
815 wxHtmlCell::Layout(w
);
817 if (m_LastLayout
== w
)
821 // VS: Any attempt to layout with negative or zero width leads to hell,
822 // but we can't ignore such attempts completely, since it sometimes
823 // happen (e.g. when trying how small a table can be). The best thing we
824 // can do is to set the width of child cells to zero
828 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
830 // this does two things: it recursively calls this code on all
831 // child contrainers and resets children's position to (0,0)
835 wxHtmlCell
*nextCell
;
836 long xpos
= 0, ypos
= m_IndentTop
;
837 int xdelta
= 0, ybasicpos
= 0, ydiff
;
838 int s_width
, nextWordWidth
, s_indent
;
839 int ysizeup
= 0, ysizedown
= 0;
840 int MaxLineWidth
= 0;
841 int curLineWidth
= 0;
851 if (m_WidthFloatUnits
== wxHTML_UNITS_PERCENT
)
853 if (m_WidthFloat
< 0) m_Width
= (100 + m_WidthFloat
) * w
/ 100;
854 else m_Width
= m_WidthFloat
* w
/ 100;
858 if (m_WidthFloat
< 0) m_Width
= w
+ m_WidthFloat
;
859 else m_Width
= m_WidthFloat
;
864 int l
= (m_IndentLeft
< 0) ? (-m_IndentLeft
* m_Width
/ 100) : m_IndentLeft
;
865 int r
= (m_IndentRight
< 0) ? (-m_IndentRight
* m_Width
/ 100) : m_IndentRight
;
866 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
867 cell
->Layout(m_Width
- (l
+ r
));
876 // adjust indentation:
877 s_indent
= (m_IndentLeft
< 0) ? (-m_IndentLeft
* m_Width
/ 100) : m_IndentLeft
;
878 s_width
= m_Width
- s_indent
- ((m_IndentRight
< 0) ? (-m_IndentRight
* m_Width
/ 100) : m_IndentRight
);
881 wxHtmlCell
*cell
= m_Cells
,
887 case wxHTML_ALIGN_TOP
: ybasicpos
= 0; break;
888 case wxHTML_ALIGN_BOTTOM
: ybasicpos
= - cell
->GetHeight(); break;
889 case wxHTML_ALIGN_CENTER
: ybasicpos
= - cell
->GetHeight() / 2; break;
891 ydiff
= cell
->GetHeight() + ybasicpos
;
893 if (cell
->GetDescent() + ydiff
> ysizedown
) ysizedown
= cell
->GetDescent() + ydiff
;
894 if (ybasicpos
+ cell
->GetDescent() < -ysizeup
) ysizeup
= - (ybasicpos
+ cell
->GetDescent());
896 // layout nonbreakable run of cells:
897 cell
->SetPos(xpos
, ybasicpos
+ cell
->GetDescent());
898 xpos
+= cell
->GetWidth();
899 if (!cell
->IsTerminalCell())
901 // Container cell indicates new line
902 if (curLineWidth
> m_MaxTotalWidth
)
903 m_MaxTotalWidth
= curLineWidth
;
905 if (wxMax(cell
->GetWidth(), cell
->GetMaxTotalWidth()) > m_MaxTotalWidth
)
906 m_MaxTotalWidth
= cell
->GetMaxTotalWidth();
910 // Normal cell, add maximum cell width to line width
911 curLineWidth
+= cell
->GetMaxTotalWidth();
913 cell
= cell
->GetNext();
915 // compute length of the next word that would be added:
922 nextWordWidth
+= nextCell
->GetWidth();
923 nextCell
= nextCell
->GetNext();
924 } while (nextCell
&& !nextCell
->IsLinebreakAllowed());
927 // force new line if occurred:
928 if ((cell
== NULL
) ||
929 (xpos
+ nextWordWidth
> s_width
&& cell
->IsLinebreakAllowed()))
931 if (xpos
> MaxLineWidth
) MaxLineWidth
= xpos
;
932 if (ysizeup
< 0) ysizeup
= 0;
933 if (ysizedown
< 0) ysizedown
= 0;
934 switch (m_AlignHor
) {
935 case wxHTML_ALIGN_LEFT
:
936 case wxHTML_ALIGN_JUSTIFY
:
939 case wxHTML_ALIGN_RIGHT
:
940 xdelta
= 0 + (s_width
- xpos
);
942 case wxHTML_ALIGN_CENTER
:
943 xdelta
= 0 + (s_width
- xpos
) / 2;
946 if (xdelta
< 0) xdelta
= 0;
951 if (m_AlignHor
!= wxHTML_ALIGN_JUSTIFY
|| cell
== NULL
)
955 line
->SetPos(line
->GetPosX() + xdelta
,
956 ypos
+ line
->GetPosY());
957 line
= line
->GetNext();
960 else // align == justify
962 // we have to distribute the extra horz space between the cells
965 // an added complication is that some cells have fixed size and
966 // shouldn't get any increment (it so happens that these cells
967 // also don't allow line break on them which provides with an
968 // easy way to test for this) -- and neither should the cells
969 // adjacent to them as this could result in a visible space
970 // between two cells separated by, e.g. font change, cell which
973 int step
= s_width
- xpos
;
976 // first count the cells which will get extra space
982 for ( c
= line
; c
!= cell
; c
= c
->GetNext() )
984 if ( c
->IsLinebreakAllowed() )
991 // and now extra space to those cells which merit it
994 // first visible cell on line is not moved:
995 while (line
!=cell
&& !line
->IsLinebreakAllowed())
997 line
->SetPos(line
->GetPosX() + s_indent
,
998 line
->GetPosY() + ypos
);
999 line
= line
->GetNext();
1004 line
->SetPos(line
->GetPosX() + s_indent
,
1005 line
->GetPosY() + ypos
);
1007 line
= line
->GetNext();
1010 for ( int n
= 0; line
!= cell
; line
= line
->GetNext() )
1012 if ( line
->IsLinebreakAllowed() )
1014 // offset the next cell relative to this one
1015 // thus increasing our size
1019 line
->SetPos(line
->GetPosX() + s_indent
+
1020 ((n
* step
) / total
),
1021 line
->GetPosY() + ypos
);
1026 // this will cause the code to enter "else branch" below:
1031 if ( step
<= 0 ) // no extra space to distribute
1033 // just set the indent properly
1034 while (line
!= cell
)
1036 line
->SetPos(line
->GetPosX() + s_indent
,
1037 line
->GetPosY() + ypos
);
1038 line
= line
->GetNext();
1045 ysizeup
= ysizedown
= 0;
1050 // setup height & width, depending on container layout:
1051 m_Height
= ypos
+ (ysizedown
+ ysizeup
) + m_IndentBottom
;
1053 if (m_Height
< m_MinHeight
)
1055 if (m_MinHeightAlign
!= wxHTML_ALIGN_TOP
)
1057 int diff
= m_MinHeight
- m_Height
;
1058 if (m_MinHeightAlign
== wxHTML_ALIGN_CENTER
) diff
/= 2;
1062 cell
->SetPos(cell
->GetPosX(), cell
->GetPosY() + diff
);
1063 cell
= cell
->GetNext();
1066 m_Height
= m_MinHeight
;
1069 if (curLineWidth
> m_MaxTotalWidth
)
1070 m_MaxTotalWidth
= curLineWidth
;
1072 m_MaxTotalWidth
+= s_indent
+ ((m_IndentRight
< 0) ? (-m_IndentRight
* m_Width
/ 100) : m_IndentRight
);
1073 MaxLineWidth
+= s_indent
+ ((m_IndentRight
< 0) ? (-m_IndentRight
* m_Width
/ 100) : m_IndentRight
);
1074 if (m_Width
< MaxLineWidth
) m_Width
= MaxLineWidth
;
1077 void wxHtmlContainerCell::UpdateRenderingStatePre(wxHtmlRenderingInfo
& info
,
1078 wxHtmlCell
*cell
) const
1080 wxHtmlSelection
*s
= info
.GetSelection();
1082 if (s
->GetFromCell() == cell
|| s
->GetToCell() == cell
)
1084 info
.GetState().SetSelectionState(wxHTML_SEL_CHANGING
);
1088 void wxHtmlContainerCell::UpdateRenderingStatePost(wxHtmlRenderingInfo
& info
,
1089 wxHtmlCell
*cell
) const
1091 wxHtmlSelection
*s
= info
.GetSelection();
1093 if (s
->GetToCell() == cell
)
1094 info
.GetState().SetSelectionState(wxHTML_SEL_OUT
);
1095 else if (s
->GetFromCell() == cell
)
1096 info
.GetState().SetSelectionState(wxHTML_SEL_IN
);
1099 #define mMin(a, b) (((a) < (b)) ? (a) : (b))
1100 #define mMax(a, b) (((a) < (b)) ? (b) : (a))
1102 void wxHtmlContainerCell::Draw(wxDC
& dc
, int x
, int y
, int view_y1
, int view_y2
,
1103 wxHtmlRenderingInfo
& info
)
1105 #if 0 // useful for debugging
1106 dc
.SetPen(*wxRED_PEN
);
1107 dc
.DrawRectangle(x
+m_PosX
,y
+m_PosY
,m_Width
,m_Height
);
1110 int xlocal
= x
+ m_PosX
;
1111 int ylocal
= y
+ m_PosY
;
1113 if (m_BkColour
.IsOk())
1115 wxBrush myb
= wxBrush(m_BkColour
, wxBRUSHSTYLE_SOLID
);
1117 int real_y1
= mMax(ylocal
, view_y1
);
1118 int real_y2
= mMin(ylocal
+ m_Height
- 1, view_y2
);
1121 dc
.SetPen(*wxTRANSPARENT_PEN
);
1122 dc
.DrawRectangle(xlocal
, real_y1
, m_Width
, real_y2
- real_y1
+ 1);
1127 // draw thin border using lines
1128 wxPen
mypen1(m_BorderColour1
, 1, wxPENSTYLE_SOLID
);
1129 wxPen
mypen2(m_BorderColour2
, 1, wxPENSTYLE_SOLID
);
1132 dc
.DrawLine(xlocal
, ylocal
, xlocal
, ylocal
+ m_Height
- 1);
1133 dc
.DrawLine(xlocal
, ylocal
, xlocal
+ m_Width
, ylocal
);
1135 dc
.DrawLine(xlocal
+ m_Width
- 1, ylocal
, xlocal
+ m_Width
- 1, ylocal
+ m_Height
- 1);
1136 dc
.DrawLine(xlocal
, ylocal
+ m_Height
- 1, xlocal
+ m_Width
, ylocal
+ m_Height
- 1);
1138 else if (m_Border
> 0)
1140 wxBrush
mybrush1(m_BorderColour1
, wxBRUSHSTYLE_SOLID
);
1141 wxBrush
mybrush2(m_BorderColour2
, wxBRUSHSTYLE_SOLID
);
1143 // draw upper left corner
1144 // 0---------------5
1153 poly
[0].x
=m_PosX
; poly
[0].y
= m_PosY
;
1154 poly
[1].x
=m_PosX
; poly
[1].y
= m_PosY
+ m_Height
;
1155 poly
[2].x
=m_PosX
+ m_Border
; poly
[2].y
= poly
[1].y
- m_Border
;
1156 poly
[3].x
=poly
[2].x
; poly
[3].y
= m_PosY
+ m_Border
;
1157 poly
[4].x
=m_PosX
+ m_Width
- m_Border
; poly
[4].y
= poly
[3].y
;
1158 poly
[5].x
=m_PosX
+ m_Width
; poly
[5].y
= m_PosY
;
1160 dc
.SetBrush(mybrush1
);
1161 dc
.SetPen(*wxTRANSPARENT_PEN
);
1162 dc
.DrawPolygon(6, poly
, x
, y
);
1164 // draw lower right corner reusing point 1,2,4 and 5
1171 // 1---------------0
1172 dc
.SetBrush(mybrush2
);
1173 poly
[0].x
= poly
[5].x
; poly
[0].y
= poly
[1].y
;
1174 poly
[3].x
= poly
[4].x
; poly
[3].y
= poly
[2].y
;
1175 dc
.DrawPolygon(6, poly
, x
, y
);
1177 // smooth color transition like firefox
1178 wxColour
borderMediumColour(
1179 (m_BorderColour1
.Red() + m_BorderColour2
.Red()) /2 ,
1180 (m_BorderColour1
.Green() + m_BorderColour2
.Green()) /2 ,
1181 (m_BorderColour1
.Blue() + m_BorderColour2
.Blue()) /2
1183 wxPen
mypen3(borderMediumColour
, 1, wxPENSTYLE_SOLID
);
1185 dc
.DrawLines(2, &poly
[1], x
, y
- 1); // between 1 and 2
1186 dc
.DrawLines(2, &poly
[4], x
, y
- 1); // between 4 and 5
1190 // draw container's contents:
1191 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
1194 // optimize drawing: don't render off-screen content:
1195 if ((ylocal
+ cell
->GetPosY() <= view_y2
) &&
1196 (ylocal
+ cell
->GetPosY() + cell
->GetHeight() > view_y1
))
1198 // the cell is visible, draw it:
1199 UpdateRenderingStatePre(info
, cell
);
1201 xlocal
, ylocal
, view_y1
, view_y2
,
1203 UpdateRenderingStatePost(info
, cell
);
1207 // the cell is off-screen, proceed with font+color+etc.
1209 cell
->DrawInvisible(dc
, xlocal
, ylocal
, info
);
1217 void wxHtmlContainerCell::DrawInvisible(wxDC
& dc
, int x
, int y
,
1218 wxHtmlRenderingInfo
& info
)
1222 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
1224 UpdateRenderingStatePre(info
, cell
);
1225 cell
->DrawInvisible(dc
, x
+ m_PosX
, y
+ m_PosY
, info
);
1226 UpdateRenderingStatePost(info
, cell
);
1232 wxColour
wxHtmlContainerCell::GetBackgroundColour()
1239 wxHtmlLinkInfo
*wxHtmlContainerCell::GetLink(int x
, int y
) const
1241 wxHtmlCell
*cell
= FindCellByPos(x
, y
);
1243 // VZ: I don't know if we should pass absolute or relative coords to
1244 // wxHtmlCell::GetLink()? As the base class version just ignores them
1245 // anyhow, it hardly matters right now but should still be clarified
1246 return cell
? cell
->GetLink(x
, y
) : NULL
;
1251 void wxHtmlContainerCell::InsertCell(wxHtmlCell
*f
)
1253 if (!m_Cells
) m_Cells
= m_LastCell
= f
;
1256 m_LastCell
->SetNext(f
);
1258 if (m_LastCell
) while (m_LastCell
->GetNext()) m_LastCell
= m_LastCell
->GetNext();
1266 void wxHtmlContainerCell::SetAlign(const wxHtmlTag
& tag
)
1268 if (tag
.HasParam(wxT("ALIGN")))
1270 wxString alg
= tag
.GetParam(wxT("ALIGN"));
1272 if (alg
== wxT("CENTER"))
1273 SetAlignHor(wxHTML_ALIGN_CENTER
);
1274 else if (alg
== wxT("LEFT"))
1275 SetAlignHor(wxHTML_ALIGN_LEFT
);
1276 else if (alg
== wxT("JUSTIFY"))
1277 SetAlignHor(wxHTML_ALIGN_JUSTIFY
);
1278 else if (alg
== wxT("RIGHT"))
1279 SetAlignHor(wxHTML_ALIGN_RIGHT
);
1286 void wxHtmlContainerCell::SetWidthFloat(const wxHtmlTag
& tag
, double pixel_scale
)
1288 if (tag
.HasParam(wxT("WIDTH")))
1291 wxString wd
= tag
.GetParam(wxT("WIDTH"));
1293 if (wd
[wd
.length()-1] == wxT('%'))
1295 wxSscanf(wd
.c_str(), wxT("%i%%"), &wdi
);
1296 SetWidthFloat(wdi
, wxHTML_UNITS_PERCENT
);
1300 wxSscanf(wd
.c_str(), wxT("%i"), &wdi
);
1301 SetWidthFloat((int)(pixel_scale
* (double)wdi
), wxHTML_UNITS_PIXELS
);
1309 const wxHtmlCell
* wxHtmlContainerCell::Find(int condition
, const void* param
) const
1313 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
1315 const wxHtmlCell
*r
= cell
->Find(condition
, param
);
1323 wxHtmlCell
*wxHtmlContainerCell::FindCellByPos(wxCoord x
, wxCoord y
,
1324 unsigned flags
) const
1326 if ( flags
& wxHTML_FIND_EXACT
)
1328 for ( const wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext() )
1330 int cx
= cell
->GetPosX(),
1331 cy
= cell
->GetPosY();
1333 if ( (cx
<= x
) && (cx
+ cell
->GetWidth() > x
) &&
1334 (cy
<= y
) && (cy
+ cell
->GetHeight() > y
) )
1336 return cell
->FindCellByPos(x
- cx
, y
- cy
, flags
);
1340 else if ( flags
& wxHTML_FIND_NEAREST_AFTER
)
1343 for ( const wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext() )
1345 if ( cell
->IsFormattingCell() )
1347 int cellY
= cell
->GetPosY();
1348 if (!( y
< cellY
|| (y
< cellY
+ cell
->GetHeight() &&
1349 x
< cell
->GetPosX() + cell
->GetWidth()) ))
1352 c
= cell
->FindCellByPos(x
- cell
->GetPosX(), y
- cellY
, flags
);
1356 else if ( flags
& wxHTML_FIND_NEAREST_BEFORE
)
1358 wxHtmlCell
*c2
, *c
= NULL
;
1359 for ( const wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext() )
1361 if ( cell
->IsFormattingCell() )
1363 int cellY
= cell
->GetPosY();
1364 if (!( cellY
+ cell
->GetHeight() <= y
||
1365 (y
>= cellY
&& x
>= cell
->GetPosX()) ))
1367 c2
= cell
->FindCellByPos(x
- cell
->GetPosX(), y
- cellY
, flags
);
1378 bool wxHtmlContainerCell::ProcessMouseClick(wxHtmlWindowInterface
*window
,
1380 const wxMouseEvent
& event
)
1382 #if WXWIN_COMPATIBILITY_2_6
1383 wxHtmlCellOnMouseClickCompatHelper
compat(window
, pos
, event
);
1384 return compat
.CallOnMouseClick(this);
1387 void wxHtmlContainerCell::OnMouseClick(wxWindow
*,
1388 int, int, const wxMouseEvent
& event
)
1390 wxCHECK_RET( gs_helperOnMouseClick
, wxT("unexpected call to OnMouseClick") );
1391 wxHtmlWindowInterface
*window
= gs_helperOnMouseClick
->window
;
1392 const wxPoint
& pos
= gs_helperOnMouseClick
->pos
;
1393 #endif // WXWIN_COMPATIBILITY_2_6
1395 bool retval
= false;
1396 wxHtmlCell
*cell
= FindCellByPos(pos
.x
, pos
.y
);
1398 retval
= cell
->ProcessMouseClick(window
, pos
, event
);
1400 #if WXWIN_COMPATIBILITY_2_6
1401 gs_helperOnMouseClick
->retval
= retval
;
1404 #endif // WXWIN_COMPATIBILITY_2_6
1408 wxHtmlCell
*wxHtmlContainerCell::GetFirstTerminal() const
1413 for (wxHtmlCell
*c
= m_Cells
; c
; c
= c
->GetNext())
1415 c2
= c
->GetFirstTerminal();
1423 wxHtmlCell
*wxHtmlContainerCell::GetLastTerminal() const
1427 // most common case first:
1428 wxHtmlCell
*c
= m_LastCell
->GetLastTerminal();
1433 wxHtmlCell
*c2
= NULL
;
1434 for (c
= m_Cells
; c
; c
= c
->GetNext())
1436 ctmp
= c
->GetLastTerminal();
1447 static bool IsEmptyContainer(wxHtmlContainerCell
*cell
)
1449 for ( wxHtmlCell
*c
= cell
->GetFirstChild(); c
; c
= c
->GetNext() )
1451 if ( !c
->IsTerminalCell() || !c
->IsFormattingCell() )
1457 void wxHtmlContainerCell::RemoveExtraSpacing(bool top
, bool bottom
)
1460 SetIndent(0, wxHTML_INDENT_TOP
);
1462 SetIndent(0, wxHTML_INDENT_BOTTOM
);
1467 wxHtmlContainerCell
*cont
;
1470 for ( c
= m_Cells
; c
; c
= c
->GetNext() )
1472 if ( c
->IsTerminalCell() )
1474 if ( !c
->IsFormattingCell() )
1479 cont
= (wxHtmlContainerCell
*)c
;
1480 if ( IsEmptyContainer(cont
) )
1482 cont
->SetIndent(0, wxHTML_INDENT_VERTICAL
);
1486 cont
->RemoveExtraSpacing(true, false);
1496 for ( c
= m_Cells
; c
; c
= c
->GetNext() )
1499 for ( int i
= arr
.GetCount() - 1; i
>= 0; i
--)
1501 c
= (wxHtmlCell
*)arr
[i
];
1502 if ( c
->IsTerminalCell() )
1504 if ( !c
->IsFormattingCell() )
1509 cont
= (wxHtmlContainerCell
*)c
;
1510 if ( IsEmptyContainer(cont
) )
1512 cont
->SetIndent(0, wxHTML_INDENT_VERTICAL
);
1516 cont
->RemoveExtraSpacing(false, true);
1528 // --------------------------------------------------------------------------
1530 // --------------------------------------------------------------------------
1532 IMPLEMENT_ABSTRACT_CLASS(wxHtmlColourCell
, wxHtmlCell
)
1534 void wxHtmlColourCell::Draw(wxDC
& dc
,
1536 int WXUNUSED(view_y1
), int WXUNUSED(view_y2
),
1537 wxHtmlRenderingInfo
& info
)
1539 DrawInvisible(dc
, x
, y
, info
);
1542 void wxHtmlColourCell::DrawInvisible(wxDC
& dc
,
1543 int WXUNUSED(x
), int WXUNUSED(y
),
1544 wxHtmlRenderingInfo
& info
)
1546 wxHtmlRenderingState
& state
= info
.GetState();
1547 if (m_Flags
& wxHTML_CLR_FOREGROUND
)
1549 state
.SetFgColour(m_Colour
);
1550 if (state
.GetSelectionState() != wxHTML_SEL_IN
)
1551 dc
.SetTextForeground(m_Colour
);
1553 dc
.SetTextForeground(
1554 info
.GetStyle().GetSelectedTextColour(m_Colour
));
1556 if (m_Flags
& wxHTML_CLR_BACKGROUND
)
1558 state
.SetBgColour(m_Colour
);
1559 state
.SetBgMode(wxSOLID
);
1560 const wxColour c
= state
.GetSelectionState() == wxHTML_SEL_IN
1561 ? info
.GetStyle().GetSelectedTextBgColour(m_Colour
)
1563 dc
.SetTextBackground(c
);
1564 dc
.SetBackground(c
);
1565 dc
.SetBackgroundMode(wxSOLID
);
1567 if (m_Flags
& wxHTML_CLR_TRANSPARENT_BACKGROUND
)
1569 state
.SetBgColour(m_Colour
);
1570 state
.SetBgMode(wxTRANSPARENT
);
1571 const wxColour c
= state
.GetSelectionState() == wxHTML_SEL_IN
1572 ? info
.GetStyle().GetSelectedTextBgColour(m_Colour
)
1574 dc
.SetTextBackground(c
);
1575 dc
.SetBackgroundMode(wxTRANSPARENT
);
1582 // ---------------------------------------------------------------------------
1584 // ---------------------------------------------------------------------------
1586 IMPLEMENT_ABSTRACT_CLASS(wxHtmlFontCell
, wxHtmlCell
)
1588 void wxHtmlFontCell::Draw(wxDC
& dc
,
1589 int WXUNUSED(x
), int WXUNUSED(y
),
1590 int WXUNUSED(view_y1
), int WXUNUSED(view_y2
),
1591 wxHtmlRenderingInfo
& WXUNUSED(info
))
1596 void wxHtmlFontCell::DrawInvisible(wxDC
& dc
, int WXUNUSED(x
), int WXUNUSED(y
),
1597 wxHtmlRenderingInfo
& WXUNUSED(info
))
1609 // ---------------------------------------------------------------------------
1611 // ---------------------------------------------------------------------------
1613 IMPLEMENT_ABSTRACT_CLASS(wxHtmlWidgetCell
, wxHtmlCell
)
1615 wxHtmlWidgetCell::wxHtmlWidgetCell(wxWindow
*wnd
, int w
)
1619 m_Wnd
->GetSize(&sx
, &sy
);
1620 m_Width
= sx
, m_Height
= sy
;
1625 void wxHtmlWidgetCell::Draw(wxDC
& WXUNUSED(dc
),
1626 int WXUNUSED(x
), int WXUNUSED(y
),
1627 int WXUNUSED(view_y1
), int WXUNUSED(view_y2
),
1628 wxHtmlRenderingInfo
& WXUNUSED(info
))
1630 int absx
= 0, absy
= 0, stx
, sty
;
1631 wxHtmlCell
*c
= this;
1635 absx
+= c
->GetPosX();
1636 absy
+= c
->GetPosY();
1640 wxScrolledWindow
*scrolwin
=
1641 wxDynamicCast(m_Wnd
->GetParent(), wxScrolledWindow
);
1642 wxCHECK_RET( scrolwin
,
1643 wxT("widget cells can only be placed in wxHtmlWindow") );
1645 scrolwin
->GetViewStart(&stx
, &sty
);
1646 m_Wnd
->SetSize(absx
- wxHTML_SCROLL_STEP
* stx
,
1647 absy
- wxHTML_SCROLL_STEP
* sty
,
1653 void wxHtmlWidgetCell::DrawInvisible(wxDC
& WXUNUSED(dc
),
1654 int WXUNUSED(x
), int WXUNUSED(y
),
1655 wxHtmlRenderingInfo
& WXUNUSED(info
))
1657 int absx
= 0, absy
= 0, stx
, sty
;
1658 wxHtmlCell
*c
= this;
1662 absx
+= c
->GetPosX();
1663 absy
+= c
->GetPosY();
1667 ((wxScrolledWindow
*)(m_Wnd
->GetParent()))->GetViewStart(&stx
, &sty
);
1668 m_Wnd
->SetSize(absx
- wxHTML_SCROLL_STEP
* stx
, absy
- wxHTML_SCROLL_STEP
* sty
, m_Width
, m_Height
);
1673 void wxHtmlWidgetCell::Layout(int w
)
1675 if (m_WidthFloat
!= 0)
1677 m_Width
= (w
* m_WidthFloat
) / 100;
1678 m_Wnd
->SetSize(m_Width
, m_Height
);
1681 wxHtmlCell::Layout(w
);
1686 // ----------------------------------------------------------------------------
1687 // wxHtmlTerminalCellsInterator
1688 // ----------------------------------------------------------------------------
1690 const wxHtmlCell
* wxHtmlTerminalCellsInterator::operator++()
1697 if ( m_pos
== m_to
)
1703 if ( m_pos
->GetNext() )
1704 m_pos
= m_pos
->GetNext();
1707 // we must go up the hierarchy until we reach container where this
1708 // is not the last child, and then go down to first terminal cell:
1709 while ( m_pos
->GetNext() == NULL
)
1711 m_pos
= m_pos
->GetParent();
1715 m_pos
= m_pos
->GetNext();
1717 while ( m_pos
->GetFirstChild() != NULL
)
1718 m_pos
= m_pos
->GetFirstChild();
1719 } while ( !m_pos
->IsTerminalCell() );