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"
35 //-----------------------------------------------------------------------------
37 //-----------------------------------------------------------------------------
39 void wxHtmlSelection::Set(const wxPoint
& fromPos
, wxHtmlCell
*fromCell
,
40 const wxPoint
& toPos
, wxHtmlCell
*toCell
)
42 m_fromCell
= fromCell
;
48 void wxHtmlSelection::Set(wxHtmlCell
*fromCell
, wxHtmlCell
*toCell
)
50 wxPoint p1
= fromCell
? fromCell
->GetAbsPos() : wxDefaultPosition
;
51 wxPoint p2
= toCell
? toCell
->GetAbsPos() : wxDefaultPosition
;
54 p2
.x
+= toCell
->GetWidth()-1;
55 p2
.y
+= toCell
->GetHeight()-1;
57 Set(p1
, fromCell
, p2
, toCell
);
60 wxColour
wxDefaultHtmlRenderingStyle::GetSelectedTextColour(
63 return wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
66 wxColour
wxDefaultHtmlRenderingStyle::GetSelectedTextBgColour(
67 const wxColour
& WXUNUSED(clr
))
69 return wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
);
73 //-----------------------------------------------------------------------------
75 //-----------------------------------------------------------------------------
77 wxHtmlCell::wxHtmlCell() : wxObject()
81 m_Width
= m_Height
= m_Descent
= 0;
82 m_CanLiveOnPagebreak
= TRUE
;
86 wxHtmlCell::~wxHtmlCell()
92 void wxHtmlCell::OnMouseClick(wxWindow
*parent
, int x
, int y
,
93 const wxMouseEvent
& event
)
95 wxHtmlLinkInfo
*lnk
= GetLink(x
, y
);
98 wxHtmlLinkInfo
lnk2(*lnk
);
99 lnk2
.SetEvent(&event
);
100 lnk2
.SetHtmlCell(this);
102 // note : this cast is legal because parent is *always* wxHtmlWindow
103 wxStaticCast(parent
, wxHtmlWindow
)->OnLinkClicked(lnk2
);
109 bool wxHtmlCell::AdjustPagebreak(int *pagebreak
, int* WXUNUSED(known_pagebreaks
), int WXUNUSED(number_of_pages
)) const
111 if ((!m_CanLiveOnPagebreak
) &&
112 m_PosY
< *pagebreak
&& m_PosY
+ m_Height
> *pagebreak
)
123 void wxHtmlCell::SetLink(const wxHtmlLinkInfo
& link
)
125 if (m_Link
) delete m_Link
;
127 if (link
.GetHref() != wxEmptyString
)
128 m_Link
= new wxHtmlLinkInfo(link
);
133 void wxHtmlCell::Layout(int WXUNUSED(w
))
140 void wxHtmlCell::GetHorizontalConstraints(int *left
, int *right
) const
145 *right
= m_PosX
+ m_Width
;
150 const wxHtmlCell
* wxHtmlCell::Find(int WXUNUSED(condition
), const void* WXUNUSED(param
)) const
156 wxHtmlCell
*wxHtmlCell::FindCellByPos(wxCoord x
, wxCoord y
,
157 unsigned flags
) const
159 if ( x
>= 0 && x
< m_Width
&& y
>= 0 && y
< m_Height
)
161 return wxConstCast(this, wxHtmlCell
);
165 if ((flags
& wxHTML_FIND_NEAREST_AFTER
) &&
166 (y
< 0 || (y
== 0 && x
<= 0)))
167 return wxConstCast(this, wxHtmlCell
);
168 else if ((flags
& wxHTML_FIND_NEAREST_BEFORE
) &&
169 (y
> m_Height
-1 || (y
== m_Height
-1 && x
>= m_Width
)))
170 return wxConstCast(this, wxHtmlCell
);
177 wxPoint
wxHtmlCell::GetAbsPos() const
179 wxPoint
p(m_PosX
, m_PosY
);
180 for (wxHtmlCell
*parent
= m_Parent
; parent
; parent
= parent
->m_Parent
)
182 p
.x
+= parent
->m_PosX
;
183 p
.y
+= parent
->m_PosY
;
188 unsigned wxHtmlCell::GetDepth() const
191 for (wxHtmlCell
*p
= m_Parent
; p
; p
= p
->m_Parent
)
196 bool wxHtmlCell::IsBefore(wxHtmlCell
*cell
) const
198 const wxHtmlCell
*c1
= this;
199 const wxHtmlCell
*c2
= cell
;
200 unsigned d1
= GetDepth();
201 unsigned d2
= cell
->GetDepth();
204 for (; d1
!= d2
; d1
-- )
207 for (; d1
!= d2
; d2
-- )
215 if ( c1
->m_Parent
== c2
->m_Parent
)
232 wxFAIL_MSG(_T("Cells are in different trees"));
237 //-----------------------------------------------------------------------------
239 //-----------------------------------------------------------------------------
241 wxHtmlWordCell::wxHtmlWordCell(const wxString
& word
, wxDC
& dc
) : wxHtmlCell()
244 dc
.GetTextExtent(m_Word
, &m_Width
, &m_Height
, &m_Descent
);
245 SetCanLiveOnPagebreak(FALSE
);
249 // Splits m_Word into up to three parts according to selection, returns
250 // substring before, in and after selection and the points (in relative coords)
251 // where s2 and s3 start:
252 void wxHtmlWordCell::Split(wxDC
& dc
,
253 const wxPoint
& selFrom
, const wxPoint
& selTo
,
254 unsigned& pos1
, unsigned& pos2
) const
256 wxPoint pt1
= (selFrom
== wxDefaultPosition
) ?
257 wxDefaultPosition
: selFrom
- GetAbsPos();
258 wxPoint pt2
= (selTo
== wxDefaultPosition
) ?
259 wxPoint(m_Width
, -1) : selTo
- GetAbsPos();
261 wxCoord charW
, charH
;
262 unsigned len
= m_Word
.length();
267 while ( pt1
.x
> 0 && i
< len
)
269 dc
.GetTextExtent(m_Word
[i
], &charW
, &charH
);
282 while ( pt2
.x
> 0 && j
< len
)
284 dc
.GetTextExtent(m_Word
[j
], &charW
, &charH
);
297 void wxHtmlWordCell::SetSelectionPrivPos(wxDC
& dc
, wxHtmlSelection
*s
) const
302 this == s
->GetFromCell() ? s
->GetFromPos() : wxDefaultPosition
,
303 this == s
->GetToCell() ? s
->GetToPos() : wxDefaultPosition
,
306 wxPoint
p(0, m_Word
.length());
308 if ( this == s
->GetFromCell() )
309 p
.x
= p1
; // selection starts here
310 if ( this == s
->GetToCell() )
311 p
.y
= p2
; // selection ends here
313 if ( this == s
->GetFromCell() )
314 s
->SetFromPrivPos(p
);
315 if ( this == s
->GetToCell() )
320 static void SwitchSelState(wxDC
& dc
, wxHtmlRenderingInfo
& info
,
323 wxColour fg
= info
.GetState().GetFgColour();
324 wxColour bg
= info
.GetState().GetBgColour();
328 dc
.SetBackgroundMode(wxSOLID
);
329 dc
.SetTextForeground(info
.GetStyle().GetSelectedTextColour(fg
));
330 dc
.SetTextBackground(info
.GetStyle().GetSelectedTextBgColour(bg
));
334 dc
.SetBackgroundMode(wxTRANSPARENT
);
335 dc
.SetTextForeground(fg
);
336 dc
.SetTextBackground(bg
);
341 void wxHtmlWordCell::Draw(wxDC
& dc
, int x
, int y
,
342 int WXUNUSED(view_y1
), int WXUNUSED(view_y2
),
343 wxHtmlRenderingInfo
& info
)
345 #if 0 // useful for debugging
346 dc
.DrawRectangle(x
+m_PosX
,y
+m_PosY
,m_Width
,m_Height
);
349 if ( info
.GetState().GetSelectionState() == wxHTML_SEL_CHANGING
)
351 // Selection changing, we must draw the word piecewise:
352 wxHtmlSelection
*s
= info
.GetSelection();
357 wxPoint priv
= (this == s
->GetFromCell()) ?
358 s
->GetFromPrivPos() : s
->GetToPrivPos();
364 txt
= m_Word
.Mid(0, part1
);
365 dc
.DrawText(txt
, x
+ m_PosX
, y
+ m_PosY
);
366 dc
.GetTextExtent(txt
, &w
, &h
);
370 SwitchSelState(dc
, info
, true);
372 txt
= m_Word
.Mid(part1
, part2
-part1
);
373 dc
.DrawText(txt
, ofs
+ x
+ m_PosX
, y
+ m_PosY
);
375 if ( (size_t)part2
< m_Word
.length() )
377 dc
.GetTextExtent(txt
, &w
, &h
);
379 SwitchSelState(dc
, info
, false);
380 txt
= m_Word
.Mid(part2
);
381 dc
.DrawText(txt
, ofs
+ x
+ m_PosX
, y
+ m_PosY
);
386 // Not changing selection state, draw the word in single mode:
388 if ( info
.GetState().GetSelectionState() != wxHTML_SEL_OUT
&&
389 dc
.GetBackgroundMode() != wxSOLID
)
391 SwitchSelState(dc
, info
, true);
393 else if ( info
.GetState().GetSelectionState() == wxHTML_SEL_OUT
&&
394 dc
.GetBackgroundMode() == wxSOLID
)
396 SwitchSelState(dc
, info
, false);
398 dc
.DrawText(m_Word
, x
+ m_PosX
, y
+ m_PosY
);
403 wxString
wxHtmlWordCell::ConvertToText(wxHtmlSelection
*s
) const
405 if ( s
&& (this == s
->GetFromCell() || this == s
->GetToCell()) )
407 wxPoint priv
= (this == s
->GetFromCell()) ?
408 s
->GetFromPrivPos() : s
->GetToPrivPos();
411 return m_Word
.Mid(part1
, part2
-part1
);
419 //-----------------------------------------------------------------------------
420 // wxHtmlContainerCell
421 //-----------------------------------------------------------------------------
424 wxHtmlContainerCell::wxHtmlContainerCell(wxHtmlContainerCell
*parent
) : wxHtmlCell()
426 m_Cells
= m_LastCell
= NULL
;
428 if (m_Parent
) m_Parent
->InsertCell(this);
429 m_AlignHor
= wxHTML_ALIGN_LEFT
;
430 m_AlignVer
= wxHTML_ALIGN_BOTTOM
;
431 m_IndentLeft
= m_IndentRight
= m_IndentTop
= m_IndentBottom
= 0;
432 m_WidthFloat
= 100; m_WidthFloatUnits
= wxHTML_UNITS_PERCENT
;
433 m_UseBkColour
= FALSE
;
436 m_MinHeightAlign
= wxHTML_ALIGN_TOP
;
440 wxHtmlContainerCell::~wxHtmlContainerCell()
442 wxHtmlCell
*cell
= m_Cells
;
445 wxHtmlCell
*cellNext
= cell
->GetNext();
453 void wxHtmlContainerCell::SetIndent(int i
, int what
, int units
)
455 int val
= (units
== wxHTML_UNITS_PIXELS
) ? i
: -i
;
456 if (what
& wxHTML_INDENT_LEFT
) m_IndentLeft
= val
;
457 if (what
& wxHTML_INDENT_RIGHT
) m_IndentRight
= val
;
458 if (what
& wxHTML_INDENT_TOP
) m_IndentTop
= val
;
459 if (what
& wxHTML_INDENT_BOTTOM
) m_IndentBottom
= val
;
465 int wxHtmlContainerCell::GetIndent(int ind
) const
467 if (ind
& wxHTML_INDENT_LEFT
) return m_IndentLeft
;
468 else if (ind
& wxHTML_INDENT_RIGHT
) return m_IndentRight
;
469 else if (ind
& wxHTML_INDENT_TOP
) return m_IndentTop
;
470 else if (ind
& wxHTML_INDENT_BOTTOM
) return m_IndentBottom
;
471 else return -1; /* BUG! Should not be called... */
477 int wxHtmlContainerCell::GetIndentUnits(int ind
) const
480 if (ind
& wxHTML_INDENT_LEFT
) p
= m_IndentLeft
< 0;
481 else if (ind
& wxHTML_INDENT_RIGHT
) p
= m_IndentRight
< 0;
482 else if (ind
& wxHTML_INDENT_TOP
) p
= m_IndentTop
< 0;
483 else if (ind
& wxHTML_INDENT_BOTTOM
) p
= m_IndentBottom
< 0;
484 if (p
) return wxHTML_UNITS_PERCENT
;
485 else return wxHTML_UNITS_PIXELS
;
490 bool wxHtmlContainerCell::AdjustPagebreak(int *pagebreak
, int* known_pagebreaks
, int number_of_pages
) const
492 if (!m_CanLiveOnPagebreak
)
493 return wxHtmlCell::AdjustPagebreak(pagebreak
, known_pagebreaks
, number_of_pages
);
497 wxHtmlCell
*c
= GetFirstChild();
499 int pbrk
= *pagebreak
- m_PosY
;
503 if (c
->AdjustPagebreak(&pbrk
, known_pagebreaks
, number_of_pages
))
508 *pagebreak
= pbrk
+ m_PosY
;
515 void wxHtmlContainerCell::Layout(int w
)
517 wxHtmlCell::Layout(w
);
519 if (m_LastLayout
== w
) return;
521 // VS: Any attempt to layout with negative or zero width leads to hell,
522 // but we can't ignore such attempts completely, since it sometimes
523 // happen (e.g. when trying how small a table can be). The best thing we
524 // can do is to set the width of child cells to zero
528 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
530 // this does two things: it recursively calls this code on all
531 // child contrainers and resets children's position to (0,0)
535 wxHtmlCell
*cell
= m_Cells
, *line
= m_Cells
;
536 long xpos
= 0, ypos
= m_IndentTop
;
537 int xdelta
= 0, ybasicpos
= 0, ydiff
;
538 int s_width
, s_indent
;
539 int ysizeup
= 0, ysizedown
= 0;
540 int MaxLineWidth
= 0;
550 if (m_WidthFloatUnits
== wxHTML_UNITS_PERCENT
)
552 if (m_WidthFloat
< 0) m_Width
= (100 + m_WidthFloat
) * w
/ 100;
553 else m_Width
= m_WidthFloat
* w
/ 100;
557 if (m_WidthFloat
< 0) m_Width
= w
+ m_WidthFloat
;
558 else m_Width
= m_WidthFloat
;
563 int l
= (m_IndentLeft
< 0) ? (-m_IndentLeft
* m_Width
/ 100) : m_IndentLeft
;
564 int r
= (m_IndentRight
< 0) ? (-m_IndentRight
* m_Width
/ 100) : m_IndentRight
;
565 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
566 cell
->Layout(m_Width
- (l
+ r
));
575 // adjust indentation:
576 s_indent
= (m_IndentLeft
< 0) ? (-m_IndentLeft
* m_Width
/ 100) : m_IndentLeft
;
577 s_width
= m_Width
- s_indent
- ((m_IndentRight
< 0) ? (-m_IndentRight
* m_Width
/ 100) : m_IndentRight
);
584 case wxHTML_ALIGN_TOP
: ybasicpos
= 0; break;
585 case wxHTML_ALIGN_BOTTOM
: ybasicpos
= - cell
->GetHeight(); break;
586 case wxHTML_ALIGN_CENTER
: ybasicpos
= - cell
->GetHeight() / 2; break;
588 ydiff
= cell
->GetHeight() + ybasicpos
;
590 if (cell
->GetDescent() + ydiff
> ysizedown
) ysizedown
= cell
->GetDescent() + ydiff
;
591 if (ybasicpos
+ cell
->GetDescent() < -ysizeup
) ysizeup
= - (ybasicpos
+ cell
->GetDescent());
593 cell
->SetPos(xpos
, ybasicpos
+ cell
->GetDescent());
594 xpos
+= cell
->GetWidth();
595 cell
= cell
->GetNext();
598 // force new line if occured:
599 if ((cell
== NULL
) || (xpos
+ cell
->GetWidth() > s_width
))
601 if (xpos
> MaxLineWidth
) MaxLineWidth
= xpos
;
602 if (ysizeup
< 0) ysizeup
= 0;
603 if (ysizedown
< 0) ysizedown
= 0;
604 switch (m_AlignHor
) {
605 case wxHTML_ALIGN_LEFT
:
606 case wxHTML_ALIGN_JUSTIFY
:
609 case wxHTML_ALIGN_RIGHT
:
610 xdelta
= 0 + (s_width
- xpos
);
612 case wxHTML_ALIGN_CENTER
:
613 xdelta
= 0 + (s_width
- xpos
) / 2;
616 if (xdelta
< 0) xdelta
= 0;
621 if (m_AlignHor
!= wxHTML_ALIGN_JUSTIFY
|| cell
== NULL
)
624 line
->SetPos(line
->GetPosX() + xdelta
,
625 ypos
+ line
->GetPosY());
626 line
= line
->GetNext();
631 int step
= (s_width
- xpos
);
632 if (step
< 0) step
= 0;
634 if (xcnt
> 0) while (line
!= cell
)
636 line
->SetPos(line
->GetPosX() + s_indent
+
637 (counter
++ * step
/ xcnt
),
638 ypos
+ line
->GetPosY());
639 line
= line
->GetNext();
646 ysizeup
= ysizedown
= 0;
651 // setup height & width, depending on container layout:
652 m_Height
= ypos
+ (ysizedown
+ ysizeup
) + m_IndentBottom
;
654 if (m_Height
< m_MinHeight
)
656 if (m_MinHeightAlign
!= wxHTML_ALIGN_TOP
)
658 int diff
= m_MinHeight
- m_Height
;
659 if (m_MinHeightAlign
== wxHTML_ALIGN_CENTER
) diff
/= 2;
663 cell
->SetPos(cell
->GetPosX(), cell
->GetPosY() + diff
);
664 cell
= cell
->GetNext();
667 m_Height
= m_MinHeight
;
670 MaxLineWidth
+= s_indent
+ ((m_IndentRight
< 0) ? (-m_IndentRight
* m_Width
/ 100) : m_IndentRight
);
671 if (m_Width
< MaxLineWidth
) m_Width
= MaxLineWidth
;
676 void wxHtmlContainerCell::UpdateRenderingStatePre(wxHtmlRenderingInfo
& info
,
677 wxHtmlCell
*cell
) const
679 wxHtmlSelection
*s
= info
.GetSelection();
681 if (s
->GetFromCell() == cell
|| s
->GetToCell() == cell
)
683 info
.GetState().SetSelectionState(wxHTML_SEL_CHANGING
);
687 void wxHtmlContainerCell::UpdateRenderingStatePost(wxHtmlRenderingInfo
& info
,
688 wxHtmlCell
*cell
) const
690 wxHtmlSelection
*s
= info
.GetSelection();
692 if (s
->GetToCell() == cell
)
693 info
.GetState().SetSelectionState(wxHTML_SEL_OUT
);
694 else if (s
->GetFromCell() == cell
)
695 info
.GetState().SetSelectionState(wxHTML_SEL_IN
);
698 #define mMin(a, b) (((a) < (b)) ? (a) : (b))
699 #define mMax(a, b) (((a) < (b)) ? (b) : (a))
701 void wxHtmlContainerCell::Draw(wxDC
& dc
, int x
, int y
, int view_y1
, int view_y2
,
702 wxHtmlRenderingInfo
& info
)
704 // container visible, draw it:
705 if ((y
+ m_PosY
<= view_y2
) && (y
+ m_PosY
+ m_Height
> view_y1
))
709 wxBrush myb
= wxBrush(m_BkColour
, wxSOLID
);
711 int real_y1
= mMax(y
+ m_PosY
, view_y1
);
712 int real_y2
= mMin(y
+ m_PosY
+ m_Height
- 1, view_y2
);
715 dc
.SetPen(*wxTRANSPARENT_PEN
);
716 dc
.DrawRectangle(x
+ m_PosX
, real_y1
, m_Width
, real_y2
- real_y1
+ 1);
721 wxPen
mypen1(m_BorderColour1
, 1, wxSOLID
);
722 wxPen
mypen2(m_BorderColour2
, 1, wxSOLID
);
725 dc
.DrawLine(x
+ m_PosX
, y
+ m_PosY
, x
+ m_PosX
, y
+ m_PosY
+ m_Height
- 1);
726 dc
.DrawLine(x
+ m_PosX
, y
+ m_PosY
, x
+ m_PosX
+ m_Width
, y
+ m_PosY
);
728 dc
.DrawLine(x
+ m_PosX
+ m_Width
- 1, y
+ m_PosY
, x
+ m_PosX
+ m_Width
- 1, y
+ m_PosY
+ m_Height
- 1);
729 dc
.DrawLine(x
+ m_PosX
, y
+ m_PosY
+ m_Height
- 1, x
+ m_PosX
+ m_Width
, y
+ m_PosY
+ m_Height
- 1);
734 // draw container's contents:
735 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
737 UpdateRenderingStatePre(info
, cell
);
739 x
+ m_PosX
, y
+ m_PosY
, view_y1
, view_y2
,
741 UpdateRenderingStatePost(info
, cell
);
745 // container invisible, just proceed font+color changing:
748 DrawInvisible(dc
, x
, y
, info
);
754 void wxHtmlContainerCell::DrawInvisible(wxDC
& dc
, int x
, int y
,
755 wxHtmlRenderingInfo
& info
)
759 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
761 UpdateRenderingStatePre(info
, cell
);
762 cell
->DrawInvisible(dc
, x
+ m_PosX
, y
+ m_PosY
, info
);
763 UpdateRenderingStatePost(info
, cell
);
769 wxColour
wxHtmlContainerCell::GetBackgroundColour()
779 wxHtmlLinkInfo
*wxHtmlContainerCell::GetLink(int x
, int y
) const
781 wxHtmlCell
*cell
= FindCellByPos(x
, y
);
783 // VZ: I don't know if we should pass absolute or relative coords to
784 // wxHtmlCell::GetLink()? As the base class version just ignores them
785 // anyhow, it hardly matters right now but should still be clarified
786 return cell
? cell
->GetLink(x
, y
) : NULL
;
791 void wxHtmlContainerCell::InsertCell(wxHtmlCell
*f
)
793 if (!m_Cells
) m_Cells
= m_LastCell
= f
;
796 m_LastCell
->SetNext(f
);
798 if (m_LastCell
) while (m_LastCell
->GetNext()) m_LastCell
= m_LastCell
->GetNext();
806 void wxHtmlContainerCell::SetAlign(const wxHtmlTag
& tag
)
808 if (tag
.HasParam(wxT("ALIGN")))
810 wxString alg
= tag
.GetParam(wxT("ALIGN"));
812 if (alg
== wxT("CENTER"))
813 SetAlignHor(wxHTML_ALIGN_CENTER
);
814 else if (alg
== wxT("LEFT"))
815 SetAlignHor(wxHTML_ALIGN_LEFT
);
816 else if (alg
== wxT("JUSTIFY"))
817 SetAlignHor(wxHTML_ALIGN_JUSTIFY
);
818 else if (alg
== wxT("RIGHT"))
819 SetAlignHor(wxHTML_ALIGN_RIGHT
);
826 void wxHtmlContainerCell::SetWidthFloat(const wxHtmlTag
& tag
, double pixel_scale
)
828 if (tag
.HasParam(wxT("WIDTH")))
831 wxString wd
= tag
.GetParam(wxT("WIDTH"));
833 if (wd
[wd
.Length()-1] == wxT('%'))
835 wxSscanf(wd
.c_str(), wxT("%i%%"), &wdi
);
836 SetWidthFloat(wdi
, wxHTML_UNITS_PERCENT
);
840 wxSscanf(wd
.c_str(), wxT("%i"), &wdi
);
841 SetWidthFloat((int)(pixel_scale
* (double)wdi
), wxHTML_UNITS_PIXELS
);
849 const wxHtmlCell
* wxHtmlContainerCell::Find(int condition
, const void* param
) const
853 const wxHtmlCell
*r
= NULL
;
855 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
857 r
= cell
->Find(condition
, param
);
865 wxHtmlCell
*wxHtmlContainerCell::FindCellByPos(wxCoord x
, wxCoord y
,
866 unsigned flags
) const
868 if ( flags
& wxHTML_FIND_EXACT
)
870 for ( const wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext() )
872 int cx
= cell
->GetPosX(),
873 cy
= cell
->GetPosY();
875 if ( (cx
<= x
) && (cx
+ cell
->GetWidth() > x
) &&
876 (cy
<= y
) && (cy
+ cell
->GetHeight() > y
) )
878 return cell
->FindCellByPos(x
- cx
, y
- cy
, flags
);
882 else if ( flags
& wxHTML_FIND_NEAREST_AFTER
)
886 for ( const wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext() )
888 y2
= cell
->GetPosY() + cell
->GetHeight() - 1;
889 if (y2
< y
|| (y2
== y
&& cell
->GetPosX()+cell
->GetWidth()-1 < x
))
891 c
= cell
->FindCellByPos(x
- cell
->GetPosX(), y
- cell
->GetPosY(),
896 else if ( flags
& wxHTML_FIND_NEAREST_BEFORE
)
898 wxHtmlCell
*c2
, *c
= NULL
;
899 for ( const wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext() )
901 if (cell
->GetPosY() > y
||
902 (cell
->GetPosY() == y
&& cell
->GetPosX() > x
))
904 c2
= cell
->FindCellByPos(x
- cell
->GetPosX(), y
- cell
->GetPosY(),
916 void wxHtmlContainerCell::OnMouseClick(wxWindow
*parent
, int x
, int y
, const wxMouseEvent
& event
)
918 wxHtmlCell
*cell
= FindCellByPos(x
, y
);
920 cell
->OnMouseClick(parent
, x
, y
, event
);
925 void wxHtmlContainerCell::GetHorizontalConstraints(int *left
, int *right
) const
927 int cleft
= m_PosX
+ m_Width
, cright
= m_PosX
; // worst case
930 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
932 cell
->GetHorizontalConstraints(&l
, &r
);
939 cleft
-= (m_IndentLeft
< 0) ? (-m_IndentLeft
* m_Width
/ 100) : m_IndentLeft
;
940 cright
+= (m_IndentRight
< 0) ? (-m_IndentRight
* m_Width
/ 100) : m_IndentRight
;
949 wxHtmlCell
*wxHtmlContainerCell::GetFirstTerminal() const
954 for (wxHtmlCell
*c
= m_Cells
; c
; c
= c
->GetNext())
956 c2
= c
->GetFirstTerminal();
964 wxHtmlCell
*wxHtmlContainerCell::GetLastTerminal() const
968 // most common case first:
969 wxHtmlCell
*c
= m_LastCell
->GetLastTerminal();
973 wxHtmlCell
*c2
= NULL
;
974 for (c
= m_Cells
; c
; c
= c
->GetNext())
975 c2
= c
->GetLastTerminal();
985 // --------------------------------------------------------------------------
987 // --------------------------------------------------------------------------
989 void wxHtmlColourCell::Draw(wxDC
& dc
,
991 int WXUNUSED(view_y1
), int WXUNUSED(view_y2
),
992 wxHtmlRenderingInfo
& info
)
994 DrawInvisible(dc
, x
, y
, info
);
997 void wxHtmlColourCell::DrawInvisible(wxDC
& dc
,
998 int WXUNUSED(x
), int WXUNUSED(y
),
999 wxHtmlRenderingInfo
& info
)
1001 wxHtmlRenderingState
& state
= info
.GetState();
1002 if (m_Flags
& wxHTML_CLR_FOREGROUND
)
1004 state
.SetFgColour(m_Colour
);
1005 if (state
.GetSelectionState() != wxHTML_SEL_IN
)
1006 dc
.SetTextForeground(m_Colour
);
1008 dc
.SetTextForeground(
1009 info
.GetStyle().GetSelectedTextColour(m_Colour
));
1011 if (m_Flags
& wxHTML_CLR_BACKGROUND
)
1013 state
.SetBgColour(m_Colour
);
1014 if (state
.GetSelectionState() != wxHTML_SEL_IN
)
1015 dc
.SetTextBackground(m_Colour
);
1017 dc
.SetTextBackground(
1018 info
.GetStyle().GetSelectedTextBgColour(m_Colour
));
1019 dc
.SetBackground(wxBrush(m_Colour
, wxSOLID
));
1026 // ---------------------------------------------------------------------------
1028 // ---------------------------------------------------------------------------
1030 void wxHtmlFontCell::Draw(wxDC
& dc
,
1031 int WXUNUSED(x
), int WXUNUSED(y
),
1032 int WXUNUSED(view_y1
), int WXUNUSED(view_y2
),
1033 wxHtmlRenderingInfo
& WXUNUSED(info
))
1038 void wxHtmlFontCell::DrawInvisible(wxDC
& dc
, int WXUNUSED(x
), int WXUNUSED(y
),
1039 wxHtmlRenderingInfo
& WXUNUSED(info
))
1051 // ---------------------------------------------------------------------------
1053 // ---------------------------------------------------------------------------
1055 wxHtmlWidgetCell::wxHtmlWidgetCell(wxWindow
*wnd
, int w
)
1059 m_Wnd
->GetSize(&sx
, &sy
);
1060 m_Width
= sx
, m_Height
= sy
;
1065 void wxHtmlWidgetCell::Draw(wxDC
& WXUNUSED(dc
),
1066 int WXUNUSED(x
), int WXUNUSED(y
),
1067 int WXUNUSED(view_y1
), int WXUNUSED(view_y2
),
1068 wxHtmlRenderingInfo
& WXUNUSED(info
))
1070 int absx
= 0, absy
= 0, stx
, sty
;
1071 wxHtmlCell
*c
= this;
1075 absx
+= c
->GetPosX();
1076 absy
+= c
->GetPosY();
1080 ((wxScrolledWindow
*)(m_Wnd
->GetParent()))->GetViewStart(&stx
, &sty
);
1081 m_Wnd
->SetSize(absx
- wxHTML_SCROLL_STEP
* stx
, absy
- wxHTML_SCROLL_STEP
* sty
, m_Width
, m_Height
);
1086 void wxHtmlWidgetCell::DrawInvisible(wxDC
& WXUNUSED(dc
),
1087 int WXUNUSED(x
), int WXUNUSED(y
),
1088 wxHtmlRenderingInfo
& WXUNUSED(info
))
1090 int absx
= 0, absy
= 0, stx
, sty
;
1091 wxHtmlCell
*c
= this;
1095 absx
+= c
->GetPosX();
1096 absy
+= c
->GetPosY();
1100 ((wxScrolledWindow
*)(m_Wnd
->GetParent()))->GetViewStart(&stx
, &sty
);
1101 m_Wnd
->SetSize(absx
- wxHTML_SCROLL_STEP
* stx
, absy
- wxHTML_SCROLL_STEP
* sty
, m_Width
, m_Height
);
1106 void wxHtmlWidgetCell::Layout(int w
)
1108 if (m_WidthFloat
!= 0)
1110 m_Width
= (w
* m_WidthFloat
) / 100;
1111 m_Wnd
->SetSize(m_Width
, m_Height
);
1114 wxHtmlCell::Layout(w
);
1119 // ----------------------------------------------------------------------------
1120 // wxHtmlTerminalCellsInterator
1121 // ----------------------------------------------------------------------------
1123 const wxHtmlCell
* wxHtmlTerminalCellsInterator::operator++()
1130 if ( m_pos
== m_to
)
1136 if ( m_pos
->GetNext() )
1137 m_pos
= m_pos
->GetNext();
1140 // we must go up the hierarchy until we reach container where this
1141 // is not the last child, and then go down to first terminal cell:
1142 while ( m_pos
->GetNext() == NULL
)
1144 m_pos
= m_pos
->GetParent();
1148 m_pos
= m_pos
->GetNext();
1150 while ( m_pos
->GetFirstChild() != NULL
)
1151 m_pos
= m_pos
->GetFirstChild();
1152 } while ( !m_pos
->IsTerminalCell() );