1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxHtmlCell - basic element of HTML output
4 // Author: Vaclav Slavik
6 // Copyright: (c) 1999 Vaclav Slavik
7 // Licence: wxWindows Licence
8 /////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "htmlcell.h"
14 #include "wx/wxprec.h"
18 #if wxUSE_HTML && wxUSE_STREAMS
26 #include "wx/colour.h"
30 #include "wx/html/htmlcell.h"
31 #include "wx/html/htmlwin.h"
32 #include "wx/settings.h"
33 #include "wx/module.h"
37 //-----------------------------------------------------------------------------
39 //-----------------------------------------------------------------------------
41 static wxCursor
*gs_cursorLink
= NULL
;
42 static wxCursor
*gs_cursorText
= NULL
;
45 //-----------------------------------------------------------------------------
47 //-----------------------------------------------------------------------------
49 void wxHtmlSelection::Set(const wxPoint
& fromPos
, const wxHtmlCell
*fromCell
,
50 const wxPoint
& toPos
, const wxHtmlCell
*toCell
)
52 m_fromCell
= fromCell
;
58 void wxHtmlSelection::Set(const wxHtmlCell
*fromCell
, const wxHtmlCell
*toCell
)
60 wxPoint p1
= fromCell
? fromCell
->GetAbsPos() : wxDefaultPosition
;
61 wxPoint p2
= toCell
? toCell
->GetAbsPos() : wxDefaultPosition
;
64 p2
.x
+= toCell
->GetWidth()-1;
65 p2
.y
+= toCell
->GetHeight()-1;
67 Set(p1
, fromCell
, p2
, toCell
);
70 wxColour
wxDefaultHtmlRenderingStyle::GetSelectedTextColour(
73 return wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
76 wxColour
wxDefaultHtmlRenderingStyle::GetSelectedTextBgColour(
77 const wxColour
& WXUNUSED(clr
))
79 return wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
);
83 //-----------------------------------------------------------------------------
85 //-----------------------------------------------------------------------------
87 wxHtmlCell::wxHtmlCell() : wxObject()
91 m_Width
= m_Height
= m_Descent
= 0;
92 m_CanLiveOnPagebreak
= TRUE
;
96 wxHtmlCell::~wxHtmlCell()
102 void wxHtmlCell::OnMouseClick(wxWindow
*parent
, int x
, int y
,
103 const wxMouseEvent
& event
)
105 wxHtmlLinkInfo
*lnk
= GetLink(x
, y
);
108 wxHtmlLinkInfo
lnk2(*lnk
);
109 lnk2
.SetEvent(&event
);
110 lnk2
.SetHtmlCell(this);
112 // note : this cast is legal because parent is *always* wxHtmlWindow
113 wxStaticCast(parent
, wxHtmlWindow
)->OnLinkClicked(lnk2
);
118 wxCursor
wxHtmlCell::GetCursor() const
122 if ( !gs_cursorLink
)
123 gs_cursorLink
= new wxCursor(wxCURSOR_HAND
);
124 return *gs_cursorLink
;
127 return *wxSTANDARD_CURSOR
;
131 bool wxHtmlCell::AdjustPagebreak(int *pagebreak
, int* WXUNUSED(known_pagebreaks
), int WXUNUSED(number_of_pages
)) const
133 if ((!m_CanLiveOnPagebreak
) &&
134 m_PosY
< *pagebreak
&& m_PosY
+ m_Height
> *pagebreak
)
145 void wxHtmlCell::SetLink(const wxHtmlLinkInfo
& link
)
147 if (m_Link
) delete m_Link
;
149 if (link
.GetHref() != wxEmptyString
)
150 m_Link
= new wxHtmlLinkInfo(link
);
154 void wxHtmlCell::Layout(int WXUNUSED(w
))
161 void wxHtmlCell::GetHorizontalConstraints(int *left
, int *right
) const
166 *right
= m_PosX
+ m_Width
;
171 const wxHtmlCell
* wxHtmlCell::Find(int WXUNUSED(condition
), const void* WXUNUSED(param
)) const
177 wxHtmlCell
*wxHtmlCell::FindCellByPos(wxCoord x
, wxCoord y
,
178 unsigned flags
) const
180 if ( x
>= 0 && x
< m_Width
&& y
>= 0 && y
< m_Height
)
182 return wxConstCast(this, wxHtmlCell
);
186 if ((flags
& wxHTML_FIND_NEAREST_AFTER
) &&
187 (y
< 0 || (y
< 0+m_Height
&& x
< 0+m_Width
)))
188 return wxConstCast(this, wxHtmlCell
);
189 else if ((flags
& wxHTML_FIND_NEAREST_BEFORE
) &&
190 (y
>= 0+m_Height
|| (y
>= 0 && x
>= 0)))
191 return wxConstCast(this, wxHtmlCell
);
198 wxPoint
wxHtmlCell::GetAbsPos() const
200 wxPoint
p(m_PosX
, m_PosY
);
201 for (wxHtmlCell
*parent
= m_Parent
; parent
; parent
= parent
->m_Parent
)
203 p
.x
+= parent
->m_PosX
;
204 p
.y
+= parent
->m_PosY
;
209 unsigned wxHtmlCell::GetDepth() const
212 for (wxHtmlCell
*p
= m_Parent
; p
; p
= p
->m_Parent
)
217 bool wxHtmlCell::IsBefore(wxHtmlCell
*cell
) const
219 const wxHtmlCell
*c1
= this;
220 const wxHtmlCell
*c2
= cell
;
221 unsigned d1
= GetDepth();
222 unsigned d2
= cell
->GetDepth();
225 for (; d1
!= d2
; d1
-- )
228 for (; d1
!= d2
; d2
-- )
236 if ( c1
->m_Parent
== c2
->m_Parent
)
253 wxFAIL_MSG(_T("Cells are in different trees"));
258 //-----------------------------------------------------------------------------
260 //-----------------------------------------------------------------------------
262 wxHtmlWordCell::wxHtmlWordCell(const wxString
& word
, wxDC
& dc
) : wxHtmlCell()
265 dc
.GetTextExtent(m_Word
, &m_Width
, &m_Height
, &m_Descent
);
266 SetCanLiveOnPagebreak(FALSE
);
270 // Splits m_Word into up to three parts according to selection, returns
271 // substring before, in and after selection and the points (in relative coords)
272 // where s2 and s3 start:
273 void wxHtmlWordCell::Split(wxDC
& dc
,
274 const wxPoint
& selFrom
, const wxPoint
& selTo
,
275 unsigned& pos1
, unsigned& pos2
) const
277 wxPoint pt1
= (selFrom
== wxDefaultPosition
) ?
278 wxDefaultPosition
: selFrom
- GetAbsPos();
279 wxPoint pt2
= (selTo
== wxDefaultPosition
) ?
280 wxPoint(m_Width
, -1) : selTo
- GetAbsPos();
282 wxCoord charW
, charH
;
283 unsigned len
= m_Word
.length();
287 // adjust for cases when the start/end position is completely
291 if ( pt2
.y
>= m_Height
)
295 while ( pt1
.x
> 0 && i
< len
)
297 dc
.GetTextExtent(m_Word
[i
], &charW
, &charH
);
310 while ( pt2
.x
> 0 && j
< len
)
312 dc
.GetTextExtent(m_Word
[j
], &charW
, &charH
);
325 void wxHtmlWordCell::SetSelectionPrivPos(wxDC
& dc
, wxHtmlSelection
*s
) const
330 this == s
->GetFromCell() ? s
->GetFromPos() : wxDefaultPosition
,
331 this == s
->GetToCell() ? s
->GetToPos() : wxDefaultPosition
,
334 wxPoint
p(0, m_Word
.length());
336 if ( this == s
->GetFromCell() )
337 p
.x
= p1
; // selection starts here
338 if ( this == s
->GetToCell() )
339 p
.y
= p2
; // selection ends here
341 if ( this == s
->GetFromCell() )
342 s
->SetFromPrivPos(p
);
343 if ( this == s
->GetToCell() )
348 static void SwitchSelState(wxDC
& dc
, wxHtmlRenderingInfo
& info
,
351 wxColour fg
= info
.GetState().GetFgColour();
352 wxColour bg
= info
.GetState().GetBgColour();
356 dc
.SetBackgroundMode(wxSOLID
);
357 dc
.SetTextForeground(info
.GetStyle().GetSelectedTextColour(fg
));
358 dc
.SetTextBackground(info
.GetStyle().GetSelectedTextBgColour(bg
));
359 dc
.SetBackground(wxBrush(info
.GetStyle().GetSelectedTextBgColour(bg
),
364 dc
.SetBackgroundMode(wxTRANSPARENT
);
365 dc
.SetTextForeground(fg
);
366 dc
.SetTextBackground(bg
);
367 dc
.SetBackground(wxBrush(bg
, wxSOLID
));
372 void wxHtmlWordCell::Draw(wxDC
& dc
, int x
, int y
,
373 int WXUNUSED(view_y1
), int WXUNUSED(view_y2
),
374 wxHtmlRenderingInfo
& info
)
376 #if 0 // useful for debugging
377 dc
.DrawRectangle(x
+m_PosX
,y
+m_PosY
,m_Width
,m_Height
);
380 bool drawSelectionAfterCell
= false;
382 if ( info
.GetState().GetSelectionState() == wxHTML_SEL_CHANGING
)
384 // Selection changing, we must draw the word piecewise:
385 wxHtmlSelection
*s
= info
.GetSelection();
390 wxPoint priv
= (this == s
->GetFromCell()) ?
391 s
->GetFromPrivPos() : s
->GetToPrivPos();
393 // NB: this is quite a hack: in order to compute selection boundaries
394 // (in word's characters) we must know current font, which is only
395 // possible inside rendering code. Therefore we update the
396 // information here and store it in wxHtmlSelection so that
397 // ConvertToText can use it later:
398 if ( priv
== wxDefaultPosition
)
400 SetSelectionPrivPos(dc
, s
);
401 priv
= (this == s
->GetFromCell()) ?
402 s
->GetFromPrivPos() : s
->GetToPrivPos();
410 txt
= m_Word
.Mid(0, part1
);
411 dc
.DrawText(txt
, x
+ m_PosX
, y
+ m_PosY
);
412 dc
.GetTextExtent(txt
, &w
, &h
);
416 SwitchSelState(dc
, info
, true);
418 txt
= m_Word
.Mid(part1
, part2
-part1
);
419 dc
.DrawText(txt
, ofs
+ x
+ m_PosX
, y
+ m_PosY
);
421 if ( (size_t)part2
< m_Word
.length() )
423 dc
.GetTextExtent(txt
, &w
, &h
);
425 SwitchSelState(dc
, info
, false);
426 txt
= m_Word
.Mid(part2
);
427 dc
.DrawText(txt
, ofs
+ x
+ m_PosX
, y
+ m_PosY
);
430 drawSelectionAfterCell
= true;
434 wxHtmlSelectionState selstate
= info
.GetState().GetSelectionState();
435 // Not changing selection state, draw the word in single mode:
436 if ( selstate
!= wxHTML_SEL_OUT
&&
437 dc
.GetBackgroundMode() != wxSOLID
)
439 SwitchSelState(dc
, info
, true);
441 else if ( selstate
== wxHTML_SEL_OUT
&&
442 dc
.GetBackgroundMode() == wxSOLID
)
444 SwitchSelState(dc
, info
, false);
446 dc
.DrawText(m_Word
, x
+ m_PosX
, y
+ m_PosY
);
447 drawSelectionAfterCell
= (selstate
!= wxHTML_SEL_OUT
);
450 // NB: If the text is justified then there is usually some free space
451 // between adjacent cells and drawing the selection only onto cells
452 // would result in ugly unselected spaces. The code below detects
453 // this special case and renders the selection *outside* the sell,
455 if ( m_Parent
->GetAlignHor() == wxHTML_ALIGN_JUSTIFY
&&
456 drawSelectionAfterCell
)
458 wxHtmlCell
*nextCell
= m_Next
;
459 while ( nextCell
&& nextCell
->IsFormattingCell() )
460 nextCell
= nextCell
->GetNext();
463 int nextX
= nextCell
->GetPosX();
464 if ( m_PosX
+ m_Width
< nextX
)
466 dc
.SetBrush(dc
.GetBackground());
467 dc
.SetPen(*wxTRANSPARENT_PEN
);
468 dc
.DrawRectangle(x
+ m_PosX
+ m_Width
, y
+ m_PosY
,
469 nextX
- m_PosX
- m_Width
, m_Height
);
476 wxString
wxHtmlWordCell::ConvertToText(wxHtmlSelection
*s
) const
478 if ( s
&& (this == s
->GetFromCell() || this == s
->GetToCell()) )
480 wxPoint priv
= this == s
->GetFromCell() ? s
->GetFromPrivPos()
483 // VZ: we may be called before we had a chance to re-render ourselves
484 // and in this case GetFrom/ToPrivPos() is not set yet -- assume
485 // that this only happens in case of a double/triple click (which
486 // seems to be the case now) and so it makes sense to select the
487 // entire contents of the cell in this case
489 // TODO: but this really needs to be fixed in some better way later...
490 if ( priv
!= wxDefaultPosition
)
494 return m_Word
.Mid(part1
, part2
-part1
);
496 //else: return the whole word below
502 wxCursor
wxHtmlWordCell::GetCursor() const
506 if ( !gs_cursorText
)
507 gs_cursorText
= new wxCursor(wxCURSOR_IBEAM
);
508 return *gs_cursorText
;
511 return wxHtmlCell::GetCursor();
515 //-----------------------------------------------------------------------------
516 // wxHtmlContainerCell
517 //-----------------------------------------------------------------------------
520 wxHtmlContainerCell::wxHtmlContainerCell(wxHtmlContainerCell
*parent
) : wxHtmlCell()
522 m_Cells
= m_LastCell
= NULL
;
524 if (m_Parent
) m_Parent
->InsertCell(this);
525 m_AlignHor
= wxHTML_ALIGN_LEFT
;
526 m_AlignVer
= wxHTML_ALIGN_BOTTOM
;
527 m_IndentLeft
= m_IndentRight
= m_IndentTop
= m_IndentBottom
= 0;
528 m_WidthFloat
= 100; m_WidthFloatUnits
= wxHTML_UNITS_PERCENT
;
529 m_UseBkColour
= FALSE
;
532 m_MinHeightAlign
= wxHTML_ALIGN_TOP
;
536 wxHtmlContainerCell::~wxHtmlContainerCell()
538 wxHtmlCell
*cell
= m_Cells
;
541 wxHtmlCell
*cellNext
= cell
->GetNext();
549 void wxHtmlContainerCell::SetIndent(int i
, int what
, int units
)
551 int val
= (units
== wxHTML_UNITS_PIXELS
) ? i
: -i
;
552 if (what
& wxHTML_INDENT_LEFT
) m_IndentLeft
= val
;
553 if (what
& wxHTML_INDENT_RIGHT
) m_IndentRight
= val
;
554 if (what
& wxHTML_INDENT_TOP
) m_IndentTop
= val
;
555 if (what
& wxHTML_INDENT_BOTTOM
) m_IndentBottom
= val
;
561 int wxHtmlContainerCell::GetIndent(int ind
) const
563 if (ind
& wxHTML_INDENT_LEFT
) return m_IndentLeft
;
564 else if (ind
& wxHTML_INDENT_RIGHT
) return m_IndentRight
;
565 else if (ind
& wxHTML_INDENT_TOP
) return m_IndentTop
;
566 else if (ind
& wxHTML_INDENT_BOTTOM
) return m_IndentBottom
;
567 else return -1; /* BUG! Should not be called... */
573 int wxHtmlContainerCell::GetIndentUnits(int ind
) const
576 if (ind
& wxHTML_INDENT_LEFT
) p
= m_IndentLeft
< 0;
577 else if (ind
& wxHTML_INDENT_RIGHT
) p
= m_IndentRight
< 0;
578 else if (ind
& wxHTML_INDENT_TOP
) p
= m_IndentTop
< 0;
579 else if (ind
& wxHTML_INDENT_BOTTOM
) p
= m_IndentBottom
< 0;
580 if (p
) return wxHTML_UNITS_PERCENT
;
581 else return wxHTML_UNITS_PIXELS
;
586 bool wxHtmlContainerCell::AdjustPagebreak(int *pagebreak
, int* known_pagebreaks
, int number_of_pages
) const
588 if (!m_CanLiveOnPagebreak
)
589 return wxHtmlCell::AdjustPagebreak(pagebreak
, known_pagebreaks
, number_of_pages
);
593 wxHtmlCell
*c
= GetFirstChild();
595 int pbrk
= *pagebreak
- m_PosY
;
599 if (c
->AdjustPagebreak(&pbrk
, known_pagebreaks
, number_of_pages
))
604 *pagebreak
= pbrk
+ m_PosY
;
611 void wxHtmlContainerCell::Layout(int w
)
613 wxHtmlCell::Layout(w
);
615 if (m_LastLayout
== w
) return;
617 // VS: Any attempt to layout with negative or zero width leads to hell,
618 // but we can't ignore such attempts completely, since it sometimes
619 // happen (e.g. when trying how small a table can be). The best thing we
620 // can do is to set the width of child cells to zero
624 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
626 // this does two things: it recursively calls this code on all
627 // child contrainers and resets children's position to (0,0)
631 wxHtmlCell
*cell
= m_Cells
, *line
= m_Cells
;
632 long xpos
= 0, ypos
= m_IndentTop
;
633 int xdelta
= 0, ybasicpos
= 0, ydiff
;
634 int s_width
, s_indent
;
635 int ysizeup
= 0, ysizedown
= 0;
636 int MaxLineWidth
= 0;
646 if (m_WidthFloatUnits
== wxHTML_UNITS_PERCENT
)
648 if (m_WidthFloat
< 0) m_Width
= (100 + m_WidthFloat
) * w
/ 100;
649 else m_Width
= m_WidthFloat
* w
/ 100;
653 if (m_WidthFloat
< 0) m_Width
= w
+ m_WidthFloat
;
654 else m_Width
= m_WidthFloat
;
659 int l
= (m_IndentLeft
< 0) ? (-m_IndentLeft
* m_Width
/ 100) : m_IndentLeft
;
660 int r
= (m_IndentRight
< 0) ? (-m_IndentRight
* m_Width
/ 100) : m_IndentRight
;
661 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
662 cell
->Layout(m_Width
- (l
+ r
));
671 // adjust indentation:
672 s_indent
= (m_IndentLeft
< 0) ? (-m_IndentLeft
* m_Width
/ 100) : m_IndentLeft
;
673 s_width
= m_Width
- s_indent
- ((m_IndentRight
< 0) ? (-m_IndentRight
* m_Width
/ 100) : m_IndentRight
);
680 case wxHTML_ALIGN_TOP
: ybasicpos
= 0; break;
681 case wxHTML_ALIGN_BOTTOM
: ybasicpos
= - cell
->GetHeight(); break;
682 case wxHTML_ALIGN_CENTER
: ybasicpos
= - cell
->GetHeight() / 2; break;
684 ydiff
= cell
->GetHeight() + ybasicpos
;
686 if (cell
->GetDescent() + ydiff
> ysizedown
) ysizedown
= cell
->GetDescent() + ydiff
;
687 if (ybasicpos
+ cell
->GetDescent() < -ysizeup
) ysizeup
= - (ybasicpos
+ cell
->GetDescent());
689 cell
->SetPos(xpos
, ybasicpos
+ cell
->GetDescent());
690 xpos
+= cell
->GetWidth();
691 cell
= cell
->GetNext();
694 // force new line if occured:
695 if ((cell
== NULL
) || (xpos
+ cell
->GetWidth() > s_width
))
697 if (xpos
> MaxLineWidth
) MaxLineWidth
= xpos
;
698 if (ysizeup
< 0) ysizeup
= 0;
699 if (ysizedown
< 0) ysizedown
= 0;
700 switch (m_AlignHor
) {
701 case wxHTML_ALIGN_LEFT
:
702 case wxHTML_ALIGN_JUSTIFY
:
705 case wxHTML_ALIGN_RIGHT
:
706 xdelta
= 0 + (s_width
- xpos
);
708 case wxHTML_ALIGN_CENTER
:
709 xdelta
= 0 + (s_width
- xpos
) / 2;
712 if (xdelta
< 0) xdelta
= 0;
717 if (m_AlignHor
!= wxHTML_ALIGN_JUSTIFY
|| cell
== NULL
)
720 line
->SetPos(line
->GetPosX() + xdelta
,
721 ypos
+ line
->GetPosY());
722 line
= line
->GetNext();
727 int step
= (s_width
- xpos
);
728 if (step
< 0) step
= 0;
730 if (xcnt
> 0) while (line
!= cell
)
732 line
->SetPos(line
->GetPosX() + s_indent
+
733 (counter
++ * step
/ xcnt
),
734 ypos
+ line
->GetPosY());
735 line
= line
->GetNext();
742 ysizeup
= ysizedown
= 0;
747 // setup height & width, depending on container layout:
748 m_Height
= ypos
+ (ysizedown
+ ysizeup
) + m_IndentBottom
;
750 if (m_Height
< m_MinHeight
)
752 if (m_MinHeightAlign
!= wxHTML_ALIGN_TOP
)
754 int diff
= m_MinHeight
- m_Height
;
755 if (m_MinHeightAlign
== wxHTML_ALIGN_CENTER
) diff
/= 2;
759 cell
->SetPos(cell
->GetPosX(), cell
->GetPosY() + diff
);
760 cell
= cell
->GetNext();
763 m_Height
= m_MinHeight
;
766 MaxLineWidth
+= s_indent
+ ((m_IndentRight
< 0) ? (-m_IndentRight
* m_Width
/ 100) : m_IndentRight
);
767 if (m_Width
< MaxLineWidth
) m_Width
= MaxLineWidth
;
772 void wxHtmlContainerCell::UpdateRenderingStatePre(wxHtmlRenderingInfo
& info
,
773 wxHtmlCell
*cell
) const
775 wxHtmlSelection
*s
= info
.GetSelection();
777 if (s
->GetFromCell() == cell
|| s
->GetToCell() == cell
)
779 info
.GetState().SetSelectionState(wxHTML_SEL_CHANGING
);
783 void wxHtmlContainerCell::UpdateRenderingStatePost(wxHtmlRenderingInfo
& info
,
784 wxHtmlCell
*cell
) const
786 wxHtmlSelection
*s
= info
.GetSelection();
788 if (s
->GetToCell() == cell
)
789 info
.GetState().SetSelectionState(wxHTML_SEL_OUT
);
790 else if (s
->GetFromCell() == cell
)
791 info
.GetState().SetSelectionState(wxHTML_SEL_IN
);
794 #define mMin(a, b) (((a) < (b)) ? (a) : (b))
795 #define mMax(a, b) (((a) < (b)) ? (b) : (a))
797 void wxHtmlContainerCell::Draw(wxDC
& dc
, int x
, int y
, int view_y1
, int view_y2
,
798 wxHtmlRenderingInfo
& info
)
800 // container visible, draw it:
801 if ((y
+ m_PosY
<= view_y2
) && (y
+ m_PosY
+ m_Height
> view_y1
))
805 wxBrush myb
= wxBrush(m_BkColour
, wxSOLID
);
807 int real_y1
= mMax(y
+ m_PosY
, view_y1
);
808 int real_y2
= mMin(y
+ m_PosY
+ m_Height
- 1, view_y2
);
811 dc
.SetPen(*wxTRANSPARENT_PEN
);
812 dc
.DrawRectangle(x
+ m_PosX
, real_y1
, m_Width
, real_y2
- real_y1
+ 1);
817 wxPen
mypen1(m_BorderColour1
, 1, wxSOLID
);
818 wxPen
mypen2(m_BorderColour2
, 1, wxSOLID
);
821 dc
.DrawLine(x
+ m_PosX
, y
+ m_PosY
, x
+ m_PosX
, y
+ m_PosY
+ m_Height
- 1);
822 dc
.DrawLine(x
+ m_PosX
, y
+ m_PosY
, x
+ m_PosX
+ m_Width
, y
+ m_PosY
);
824 dc
.DrawLine(x
+ m_PosX
+ m_Width
- 1, y
+ m_PosY
, x
+ m_PosX
+ m_Width
- 1, y
+ m_PosY
+ m_Height
- 1);
825 dc
.DrawLine(x
+ m_PosX
, y
+ m_PosY
+ m_Height
- 1, x
+ m_PosX
+ m_Width
, y
+ m_PosY
+ m_Height
- 1);
830 // draw container's contents:
831 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
833 UpdateRenderingStatePre(info
, cell
);
835 x
+ m_PosX
, y
+ m_PosY
, view_y1
, view_y2
,
837 UpdateRenderingStatePost(info
, cell
);
841 // container invisible, just proceed font+color changing:
844 DrawInvisible(dc
, x
, y
, info
);
850 void wxHtmlContainerCell::DrawInvisible(wxDC
& dc
, int x
, int y
,
851 wxHtmlRenderingInfo
& info
)
855 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
857 UpdateRenderingStatePre(info
, cell
);
858 cell
->DrawInvisible(dc
, x
+ m_PosX
, y
+ m_PosY
, info
);
859 UpdateRenderingStatePost(info
, cell
);
865 wxColour
wxHtmlContainerCell::GetBackgroundColour()
875 wxHtmlLinkInfo
*wxHtmlContainerCell::GetLink(int x
, int y
) const
877 wxHtmlCell
*cell
= FindCellByPos(x
, y
);
879 // VZ: I don't know if we should pass absolute or relative coords to
880 // wxHtmlCell::GetLink()? As the base class version just ignores them
881 // anyhow, it hardly matters right now but should still be clarified
882 return cell
? cell
->GetLink(x
, y
) : NULL
;
887 void wxHtmlContainerCell::InsertCell(wxHtmlCell
*f
)
889 if (!m_Cells
) m_Cells
= m_LastCell
= f
;
892 m_LastCell
->SetNext(f
);
894 if (m_LastCell
) while (m_LastCell
->GetNext()) m_LastCell
= m_LastCell
->GetNext();
902 void wxHtmlContainerCell::SetAlign(const wxHtmlTag
& tag
)
904 if (tag
.HasParam(wxT("ALIGN")))
906 wxString alg
= tag
.GetParam(wxT("ALIGN"));
908 if (alg
== wxT("CENTER"))
909 SetAlignHor(wxHTML_ALIGN_CENTER
);
910 else if (alg
== wxT("LEFT"))
911 SetAlignHor(wxHTML_ALIGN_LEFT
);
912 else if (alg
== wxT("JUSTIFY"))
913 SetAlignHor(wxHTML_ALIGN_JUSTIFY
);
914 else if (alg
== wxT("RIGHT"))
915 SetAlignHor(wxHTML_ALIGN_RIGHT
);
922 void wxHtmlContainerCell::SetWidthFloat(const wxHtmlTag
& tag
, double pixel_scale
)
924 if (tag
.HasParam(wxT("WIDTH")))
927 wxString wd
= tag
.GetParam(wxT("WIDTH"));
929 if (wd
[wd
.Length()-1] == wxT('%'))
931 wxSscanf(wd
.c_str(), wxT("%i%%"), &wdi
);
932 SetWidthFloat(wdi
, wxHTML_UNITS_PERCENT
);
936 wxSscanf(wd
.c_str(), wxT("%i"), &wdi
);
937 SetWidthFloat((int)(pixel_scale
* (double)wdi
), wxHTML_UNITS_PIXELS
);
945 const wxHtmlCell
* wxHtmlContainerCell::Find(int condition
, const void* param
) const
949 const wxHtmlCell
*r
= NULL
;
951 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
953 r
= cell
->Find(condition
, param
);
961 wxHtmlCell
*wxHtmlContainerCell::FindCellByPos(wxCoord x
, wxCoord y
,
962 unsigned flags
) const
964 if ( flags
& wxHTML_FIND_EXACT
)
966 for ( const wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext() )
968 int cx
= cell
->GetPosX(),
969 cy
= cell
->GetPosY();
971 if ( (cx
<= x
) && (cx
+ cell
->GetWidth() > x
) &&
972 (cy
<= y
) && (cy
+ cell
->GetHeight() > y
) )
974 return cell
->FindCellByPos(x
- cx
, y
- cy
, flags
);
978 else if ( flags
& wxHTML_FIND_NEAREST_AFTER
)
981 for ( const wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext() )
983 if ( cell
->IsFormattingCell() )
985 int cellY
= cell
->GetPosY();
986 if (!( y
< cellY
|| (y
< cellY
+ cell
->GetHeight() &&
987 x
< cell
->GetPosX() + cell
->GetWidth()) ))
990 c
= cell
->FindCellByPos(x
- cell
->GetPosX(), y
- cellY
, flags
);
994 else if ( flags
& wxHTML_FIND_NEAREST_BEFORE
)
996 wxHtmlCell
*c2
, *c
= NULL
;
997 for ( const wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext() )
999 if ( cell
->IsFormattingCell() )
1001 int cellY
= cell
->GetPosY();
1002 if (!( cellY
+ cell
->GetHeight() <= y
||
1003 (y
>= cellY
&& x
>= cell
->GetPosX()) ))
1005 c2
= cell
->FindCellByPos(x
- cell
->GetPosX(), y
- cellY
, flags
);
1016 void wxHtmlContainerCell::OnMouseClick(wxWindow
*parent
, int x
, int y
, const wxMouseEvent
& event
)
1018 wxHtmlCell
*cell
= FindCellByPos(x
, y
);
1020 cell
->OnMouseClick(parent
, x
, y
, event
);
1025 void wxHtmlContainerCell::GetHorizontalConstraints(int *left
, int *right
) const
1027 int cleft
= m_PosX
+ m_Width
, cright
= m_PosX
; // worst case
1030 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
1032 cell
->GetHorizontalConstraints(&l
, &r
);
1039 cleft
-= (m_IndentLeft
< 0) ? (-m_IndentLeft
* m_Width
/ 100) : m_IndentLeft
;
1040 cright
+= (m_IndentRight
< 0) ? (-m_IndentRight
* m_Width
/ 100) : m_IndentRight
;
1049 wxHtmlCell
*wxHtmlContainerCell::GetFirstTerminal() const
1054 for (wxHtmlCell
*c
= m_Cells
; c
; c
= c
->GetNext())
1056 c2
= c
->GetFirstTerminal();
1064 wxHtmlCell
*wxHtmlContainerCell::GetLastTerminal() const
1068 // most common case first:
1069 wxHtmlCell
*c
= m_LastCell
->GetLastTerminal();
1073 wxHtmlCell
*c2
= NULL
;
1074 for (c
= m_Cells
; c
; c
= c
->GetNext())
1075 c2
= c
->GetLastTerminal();
1085 // --------------------------------------------------------------------------
1087 // --------------------------------------------------------------------------
1089 void wxHtmlColourCell::Draw(wxDC
& dc
,
1091 int WXUNUSED(view_y1
), int WXUNUSED(view_y2
),
1092 wxHtmlRenderingInfo
& info
)
1094 DrawInvisible(dc
, x
, y
, info
);
1097 void wxHtmlColourCell::DrawInvisible(wxDC
& dc
,
1098 int WXUNUSED(x
), int WXUNUSED(y
),
1099 wxHtmlRenderingInfo
& info
)
1101 wxHtmlRenderingState
& state
= info
.GetState();
1102 if (m_Flags
& wxHTML_CLR_FOREGROUND
)
1104 state
.SetFgColour(m_Colour
);
1105 if (state
.GetSelectionState() != wxHTML_SEL_IN
)
1106 dc
.SetTextForeground(m_Colour
);
1108 dc
.SetTextForeground(
1109 info
.GetStyle().GetSelectedTextColour(m_Colour
));
1111 if (m_Flags
& wxHTML_CLR_BACKGROUND
)
1113 state
.SetBgColour(m_Colour
);
1114 if (state
.GetSelectionState() != wxHTML_SEL_IN
)
1116 dc
.SetTextBackground(m_Colour
);
1117 dc
.SetBackground(wxBrush(m_Colour
, wxSOLID
));
1121 wxColour c
= info
.GetStyle().GetSelectedTextBgColour(m_Colour
);
1122 dc
.SetTextBackground(c
);
1123 dc
.SetBackground(wxBrush(c
, wxSOLID
));
1131 // ---------------------------------------------------------------------------
1133 // ---------------------------------------------------------------------------
1135 void wxHtmlFontCell::Draw(wxDC
& dc
,
1136 int WXUNUSED(x
), int WXUNUSED(y
),
1137 int WXUNUSED(view_y1
), int WXUNUSED(view_y2
),
1138 wxHtmlRenderingInfo
& WXUNUSED(info
))
1143 void wxHtmlFontCell::DrawInvisible(wxDC
& dc
, int WXUNUSED(x
), int WXUNUSED(y
),
1144 wxHtmlRenderingInfo
& WXUNUSED(info
))
1156 // ---------------------------------------------------------------------------
1158 // ---------------------------------------------------------------------------
1160 wxHtmlWidgetCell::wxHtmlWidgetCell(wxWindow
*wnd
, int w
)
1164 m_Wnd
->GetSize(&sx
, &sy
);
1165 m_Width
= sx
, m_Height
= sy
;
1170 void wxHtmlWidgetCell::Draw(wxDC
& WXUNUSED(dc
),
1171 int WXUNUSED(x
), int WXUNUSED(y
),
1172 int WXUNUSED(view_y1
), int WXUNUSED(view_y2
),
1173 wxHtmlRenderingInfo
& WXUNUSED(info
))
1175 int absx
= 0, absy
= 0, stx
, sty
;
1176 wxHtmlCell
*c
= this;
1180 absx
+= c
->GetPosX();
1181 absy
+= c
->GetPosY();
1185 ((wxScrolledWindow
*)(m_Wnd
->GetParent()))->GetViewStart(&stx
, &sty
);
1186 m_Wnd
->SetSize(absx
- wxHTML_SCROLL_STEP
* stx
, absy
- wxHTML_SCROLL_STEP
* sty
, m_Width
, m_Height
);
1191 void wxHtmlWidgetCell::DrawInvisible(wxDC
& WXUNUSED(dc
),
1192 int WXUNUSED(x
), int WXUNUSED(y
),
1193 wxHtmlRenderingInfo
& WXUNUSED(info
))
1195 int absx
= 0, absy
= 0, stx
, sty
;
1196 wxHtmlCell
*c
= this;
1200 absx
+= c
->GetPosX();
1201 absy
+= c
->GetPosY();
1205 ((wxScrolledWindow
*)(m_Wnd
->GetParent()))->GetViewStart(&stx
, &sty
);
1206 m_Wnd
->SetSize(absx
- wxHTML_SCROLL_STEP
* stx
, absy
- wxHTML_SCROLL_STEP
* sty
, m_Width
, m_Height
);
1211 void wxHtmlWidgetCell::Layout(int w
)
1213 if (m_WidthFloat
!= 0)
1215 m_Width
= (w
* m_WidthFloat
) / 100;
1216 m_Wnd
->SetSize(m_Width
, m_Height
);
1219 wxHtmlCell::Layout(w
);
1224 // ----------------------------------------------------------------------------
1225 // wxHtmlTerminalCellsInterator
1226 // ----------------------------------------------------------------------------
1228 const wxHtmlCell
* wxHtmlTerminalCellsInterator::operator++()
1235 if ( m_pos
== m_to
)
1241 if ( m_pos
->GetNext() )
1242 m_pos
= m_pos
->GetNext();
1245 // we must go up the hierarchy until we reach container where this
1246 // is not the last child, and then go down to first terminal cell:
1247 while ( m_pos
->GetNext() == NULL
)
1249 m_pos
= m_pos
->GetParent();
1253 m_pos
= m_pos
->GetNext();
1255 while ( m_pos
->GetFirstChild() != NULL
)
1256 m_pos
= m_pos
->GetFirstChild();
1257 } while ( !m_pos
->IsTerminalCell() );
1268 //-----------------------------------------------------------------------------
1270 //-----------------------------------------------------------------------------
1272 class wxHtmlCellModule
: public wxModule
1274 DECLARE_DYNAMIC_CLASS(wxHtmlCellModule
)
1276 wxHtmlCellModule() : wxModule() {}
1277 bool OnInit() { return true; }
1280 wxDELETE(gs_cursorLink
);
1281 wxDELETE(gs_cursorText
);
1285 IMPLEMENT_DYNAMIC_CLASS(wxHtmlCellModule
, wxModule
)