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
, const wxHtmlCell
*fromCell
,
40 const wxPoint
& toPos
, const wxHtmlCell
*toCell
)
42 m_fromCell
= fromCell
;
48 void wxHtmlSelection::Set(const wxHtmlCell
*fromCell
, const 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();
360 // NB: this is quite a hack: in order to compute selection boundaries
361 // (in word's characters) we must know current font, which is only
362 // possible inside rendering code. Therefore we update the
363 // information here and store it in wxHtmlSelection so that
364 // ConvertToText can use it later:
365 if ( priv
== wxDefaultPosition
)
367 SetSelectionPrivPos(dc
, s
);
368 priv
= (this == s
->GetFromCell()) ?
369 s
->GetFromPrivPos() : s
->GetToPrivPos();
377 txt
= m_Word
.Mid(0, part1
);
378 dc
.DrawText(txt
, x
+ m_PosX
, y
+ m_PosY
);
379 dc
.GetTextExtent(txt
, &w
, &h
);
383 SwitchSelState(dc
, info
, true);
385 txt
= m_Word
.Mid(part1
, part2
-part1
);
386 dc
.DrawText(txt
, ofs
+ x
+ m_PosX
, y
+ m_PosY
);
388 if ( (size_t)part2
< m_Word
.length() )
390 dc
.GetTextExtent(txt
, &w
, &h
);
392 SwitchSelState(dc
, info
, false);
393 txt
= m_Word
.Mid(part2
);
394 dc
.DrawText(txt
, ofs
+ x
+ m_PosX
, y
+ m_PosY
);
399 // Not changing selection state, draw the word in single mode:
401 if ( info
.GetState().GetSelectionState() != wxHTML_SEL_OUT
&&
402 dc
.GetBackgroundMode() != wxSOLID
)
404 SwitchSelState(dc
, info
, true);
406 else if ( info
.GetState().GetSelectionState() == wxHTML_SEL_OUT
&&
407 dc
.GetBackgroundMode() == wxSOLID
)
409 SwitchSelState(dc
, info
, false);
411 dc
.DrawText(m_Word
, x
+ m_PosX
, y
+ m_PosY
);
416 wxString
wxHtmlWordCell::ConvertToText(wxHtmlSelection
*s
) const
418 if ( s
&& (this == s
->GetFromCell() || this == s
->GetToCell()) )
420 wxPoint priv
= (this == s
->GetFromCell()) ?
421 s
->GetFromPrivPos() : s
->GetToPrivPos();
424 return m_Word
.Mid(part1
, part2
-part1
);
432 //-----------------------------------------------------------------------------
433 // wxHtmlContainerCell
434 //-----------------------------------------------------------------------------
437 wxHtmlContainerCell::wxHtmlContainerCell(wxHtmlContainerCell
*parent
) : wxHtmlCell()
439 m_Cells
= m_LastCell
= NULL
;
441 if (m_Parent
) m_Parent
->InsertCell(this);
442 m_AlignHor
= wxHTML_ALIGN_LEFT
;
443 m_AlignVer
= wxHTML_ALIGN_BOTTOM
;
444 m_IndentLeft
= m_IndentRight
= m_IndentTop
= m_IndentBottom
= 0;
445 m_WidthFloat
= 100; m_WidthFloatUnits
= wxHTML_UNITS_PERCENT
;
446 m_UseBkColour
= FALSE
;
449 m_MinHeightAlign
= wxHTML_ALIGN_TOP
;
453 wxHtmlContainerCell::~wxHtmlContainerCell()
455 wxHtmlCell
*cell
= m_Cells
;
458 wxHtmlCell
*cellNext
= cell
->GetNext();
466 void wxHtmlContainerCell::SetIndent(int i
, int what
, int units
)
468 int val
= (units
== wxHTML_UNITS_PIXELS
) ? i
: -i
;
469 if (what
& wxHTML_INDENT_LEFT
) m_IndentLeft
= val
;
470 if (what
& wxHTML_INDENT_RIGHT
) m_IndentRight
= val
;
471 if (what
& wxHTML_INDENT_TOP
) m_IndentTop
= val
;
472 if (what
& wxHTML_INDENT_BOTTOM
) m_IndentBottom
= val
;
478 int wxHtmlContainerCell::GetIndent(int ind
) const
480 if (ind
& wxHTML_INDENT_LEFT
) return m_IndentLeft
;
481 else if (ind
& wxHTML_INDENT_RIGHT
) return m_IndentRight
;
482 else if (ind
& wxHTML_INDENT_TOP
) return m_IndentTop
;
483 else if (ind
& wxHTML_INDENT_BOTTOM
) return m_IndentBottom
;
484 else return -1; /* BUG! Should not be called... */
490 int wxHtmlContainerCell::GetIndentUnits(int ind
) const
493 if (ind
& wxHTML_INDENT_LEFT
) p
= m_IndentLeft
< 0;
494 else if (ind
& wxHTML_INDENT_RIGHT
) p
= m_IndentRight
< 0;
495 else if (ind
& wxHTML_INDENT_TOP
) p
= m_IndentTop
< 0;
496 else if (ind
& wxHTML_INDENT_BOTTOM
) p
= m_IndentBottom
< 0;
497 if (p
) return wxHTML_UNITS_PERCENT
;
498 else return wxHTML_UNITS_PIXELS
;
503 bool wxHtmlContainerCell::AdjustPagebreak(int *pagebreak
, int* known_pagebreaks
, int number_of_pages
) const
505 if (!m_CanLiveOnPagebreak
)
506 return wxHtmlCell::AdjustPagebreak(pagebreak
, known_pagebreaks
, number_of_pages
);
510 wxHtmlCell
*c
= GetFirstChild();
512 int pbrk
= *pagebreak
- m_PosY
;
516 if (c
->AdjustPagebreak(&pbrk
, known_pagebreaks
, number_of_pages
))
521 *pagebreak
= pbrk
+ m_PosY
;
528 void wxHtmlContainerCell::Layout(int w
)
530 wxHtmlCell::Layout(w
);
532 if (m_LastLayout
== w
) return;
534 // VS: Any attempt to layout with negative or zero width leads to hell,
535 // but we can't ignore such attempts completely, since it sometimes
536 // happen (e.g. when trying how small a table can be). The best thing we
537 // can do is to set the width of child cells to zero
541 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
543 // this does two things: it recursively calls this code on all
544 // child contrainers and resets children's position to (0,0)
548 wxHtmlCell
*cell
= m_Cells
, *line
= m_Cells
;
549 long xpos
= 0, ypos
= m_IndentTop
;
550 int xdelta
= 0, ybasicpos
= 0, ydiff
;
551 int s_width
, s_indent
;
552 int ysizeup
= 0, ysizedown
= 0;
553 int MaxLineWidth
= 0;
563 if (m_WidthFloatUnits
== wxHTML_UNITS_PERCENT
)
565 if (m_WidthFloat
< 0) m_Width
= (100 + m_WidthFloat
) * w
/ 100;
566 else m_Width
= m_WidthFloat
* w
/ 100;
570 if (m_WidthFloat
< 0) m_Width
= w
+ m_WidthFloat
;
571 else m_Width
= m_WidthFloat
;
576 int l
= (m_IndentLeft
< 0) ? (-m_IndentLeft
* m_Width
/ 100) : m_IndentLeft
;
577 int r
= (m_IndentRight
< 0) ? (-m_IndentRight
* m_Width
/ 100) : m_IndentRight
;
578 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
579 cell
->Layout(m_Width
- (l
+ r
));
588 // adjust indentation:
589 s_indent
= (m_IndentLeft
< 0) ? (-m_IndentLeft
* m_Width
/ 100) : m_IndentLeft
;
590 s_width
= m_Width
- s_indent
- ((m_IndentRight
< 0) ? (-m_IndentRight
* m_Width
/ 100) : m_IndentRight
);
597 case wxHTML_ALIGN_TOP
: ybasicpos
= 0; break;
598 case wxHTML_ALIGN_BOTTOM
: ybasicpos
= - cell
->GetHeight(); break;
599 case wxHTML_ALIGN_CENTER
: ybasicpos
= - cell
->GetHeight() / 2; break;
601 ydiff
= cell
->GetHeight() + ybasicpos
;
603 if (cell
->GetDescent() + ydiff
> ysizedown
) ysizedown
= cell
->GetDescent() + ydiff
;
604 if (ybasicpos
+ cell
->GetDescent() < -ysizeup
) ysizeup
= - (ybasicpos
+ cell
->GetDescent());
606 cell
->SetPos(xpos
, ybasicpos
+ cell
->GetDescent());
607 xpos
+= cell
->GetWidth();
608 cell
= cell
->GetNext();
611 // force new line if occured:
612 if ((cell
== NULL
) || (xpos
+ cell
->GetWidth() > s_width
))
614 if (xpos
> MaxLineWidth
) MaxLineWidth
= xpos
;
615 if (ysizeup
< 0) ysizeup
= 0;
616 if (ysizedown
< 0) ysizedown
= 0;
617 switch (m_AlignHor
) {
618 case wxHTML_ALIGN_LEFT
:
619 case wxHTML_ALIGN_JUSTIFY
:
622 case wxHTML_ALIGN_RIGHT
:
623 xdelta
= 0 + (s_width
- xpos
);
625 case wxHTML_ALIGN_CENTER
:
626 xdelta
= 0 + (s_width
- xpos
) / 2;
629 if (xdelta
< 0) xdelta
= 0;
634 if (m_AlignHor
!= wxHTML_ALIGN_JUSTIFY
|| cell
== NULL
)
637 line
->SetPos(line
->GetPosX() + xdelta
,
638 ypos
+ line
->GetPosY());
639 line
= line
->GetNext();
644 int step
= (s_width
- xpos
);
645 if (step
< 0) step
= 0;
647 if (xcnt
> 0) while (line
!= cell
)
649 line
->SetPos(line
->GetPosX() + s_indent
+
650 (counter
++ * step
/ xcnt
),
651 ypos
+ line
->GetPosY());
652 line
= line
->GetNext();
659 ysizeup
= ysizedown
= 0;
664 // setup height & width, depending on container layout:
665 m_Height
= ypos
+ (ysizedown
+ ysizeup
) + m_IndentBottom
;
667 if (m_Height
< m_MinHeight
)
669 if (m_MinHeightAlign
!= wxHTML_ALIGN_TOP
)
671 int diff
= m_MinHeight
- m_Height
;
672 if (m_MinHeightAlign
== wxHTML_ALIGN_CENTER
) diff
/= 2;
676 cell
->SetPos(cell
->GetPosX(), cell
->GetPosY() + diff
);
677 cell
= cell
->GetNext();
680 m_Height
= m_MinHeight
;
683 MaxLineWidth
+= s_indent
+ ((m_IndentRight
< 0) ? (-m_IndentRight
* m_Width
/ 100) : m_IndentRight
);
684 if (m_Width
< MaxLineWidth
) m_Width
= MaxLineWidth
;
689 void wxHtmlContainerCell::UpdateRenderingStatePre(wxHtmlRenderingInfo
& info
,
690 wxHtmlCell
*cell
) const
692 wxHtmlSelection
*s
= info
.GetSelection();
694 if (s
->GetFromCell() == cell
|| s
->GetToCell() == cell
)
696 info
.GetState().SetSelectionState(wxHTML_SEL_CHANGING
);
700 void wxHtmlContainerCell::UpdateRenderingStatePost(wxHtmlRenderingInfo
& info
,
701 wxHtmlCell
*cell
) const
703 wxHtmlSelection
*s
= info
.GetSelection();
705 if (s
->GetToCell() == cell
)
706 info
.GetState().SetSelectionState(wxHTML_SEL_OUT
);
707 else if (s
->GetFromCell() == cell
)
708 info
.GetState().SetSelectionState(wxHTML_SEL_IN
);
711 #define mMin(a, b) (((a) < (b)) ? (a) : (b))
712 #define mMax(a, b) (((a) < (b)) ? (b) : (a))
714 void wxHtmlContainerCell::Draw(wxDC
& dc
, int x
, int y
, int view_y1
, int view_y2
,
715 wxHtmlRenderingInfo
& info
)
717 // container visible, draw it:
718 if ((y
+ m_PosY
<= view_y2
) && (y
+ m_PosY
+ m_Height
> view_y1
))
722 wxBrush myb
= wxBrush(m_BkColour
, wxSOLID
);
724 int real_y1
= mMax(y
+ m_PosY
, view_y1
);
725 int real_y2
= mMin(y
+ m_PosY
+ m_Height
- 1, view_y2
);
728 dc
.SetPen(*wxTRANSPARENT_PEN
);
729 dc
.DrawRectangle(x
+ m_PosX
, real_y1
, m_Width
, real_y2
- real_y1
+ 1);
734 wxPen
mypen1(m_BorderColour1
, 1, wxSOLID
);
735 wxPen
mypen2(m_BorderColour2
, 1, wxSOLID
);
738 dc
.DrawLine(x
+ m_PosX
, y
+ m_PosY
, x
+ m_PosX
, y
+ m_PosY
+ m_Height
- 1);
739 dc
.DrawLine(x
+ m_PosX
, y
+ m_PosY
, x
+ m_PosX
+ m_Width
, y
+ m_PosY
);
741 dc
.DrawLine(x
+ m_PosX
+ m_Width
- 1, y
+ m_PosY
, x
+ m_PosX
+ m_Width
- 1, y
+ m_PosY
+ m_Height
- 1);
742 dc
.DrawLine(x
+ m_PosX
, y
+ m_PosY
+ m_Height
- 1, x
+ m_PosX
+ m_Width
, y
+ m_PosY
+ m_Height
- 1);
747 // draw container's contents:
748 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
750 UpdateRenderingStatePre(info
, cell
);
752 x
+ m_PosX
, y
+ m_PosY
, view_y1
, view_y2
,
754 UpdateRenderingStatePost(info
, cell
);
758 // container invisible, just proceed font+color changing:
761 DrawInvisible(dc
, x
, y
, info
);
767 void wxHtmlContainerCell::DrawInvisible(wxDC
& dc
, int x
, int y
,
768 wxHtmlRenderingInfo
& info
)
772 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
774 UpdateRenderingStatePre(info
, cell
);
775 cell
->DrawInvisible(dc
, x
+ m_PosX
, y
+ m_PosY
, info
);
776 UpdateRenderingStatePost(info
, cell
);
782 wxColour
wxHtmlContainerCell::GetBackgroundColour()
792 wxHtmlLinkInfo
*wxHtmlContainerCell::GetLink(int x
, int y
) const
794 wxHtmlCell
*cell
= FindCellByPos(x
, y
);
796 // VZ: I don't know if we should pass absolute or relative coords to
797 // wxHtmlCell::GetLink()? As the base class version just ignores them
798 // anyhow, it hardly matters right now but should still be clarified
799 return cell
? cell
->GetLink(x
, y
) : NULL
;
804 void wxHtmlContainerCell::InsertCell(wxHtmlCell
*f
)
806 if (!m_Cells
) m_Cells
= m_LastCell
= f
;
809 m_LastCell
->SetNext(f
);
811 if (m_LastCell
) while (m_LastCell
->GetNext()) m_LastCell
= m_LastCell
->GetNext();
819 void wxHtmlContainerCell::SetAlign(const wxHtmlTag
& tag
)
821 if (tag
.HasParam(wxT("ALIGN")))
823 wxString alg
= tag
.GetParam(wxT("ALIGN"));
825 if (alg
== wxT("CENTER"))
826 SetAlignHor(wxHTML_ALIGN_CENTER
);
827 else if (alg
== wxT("LEFT"))
828 SetAlignHor(wxHTML_ALIGN_LEFT
);
829 else if (alg
== wxT("JUSTIFY"))
830 SetAlignHor(wxHTML_ALIGN_JUSTIFY
);
831 else if (alg
== wxT("RIGHT"))
832 SetAlignHor(wxHTML_ALIGN_RIGHT
);
839 void wxHtmlContainerCell::SetWidthFloat(const wxHtmlTag
& tag
, double pixel_scale
)
841 if (tag
.HasParam(wxT("WIDTH")))
844 wxString wd
= tag
.GetParam(wxT("WIDTH"));
846 if (wd
[wd
.Length()-1] == wxT('%'))
848 wxSscanf(wd
.c_str(), wxT("%i%%"), &wdi
);
849 SetWidthFloat(wdi
, wxHTML_UNITS_PERCENT
);
853 wxSscanf(wd
.c_str(), wxT("%i"), &wdi
);
854 SetWidthFloat((int)(pixel_scale
* (double)wdi
), wxHTML_UNITS_PIXELS
);
862 const wxHtmlCell
* wxHtmlContainerCell::Find(int condition
, const void* param
) const
866 const wxHtmlCell
*r
= NULL
;
868 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
870 r
= cell
->Find(condition
, param
);
878 wxHtmlCell
*wxHtmlContainerCell::FindCellByPos(wxCoord x
, wxCoord y
,
879 unsigned flags
) const
881 if ( flags
& wxHTML_FIND_EXACT
)
883 for ( const wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext() )
885 int cx
= cell
->GetPosX(),
886 cy
= cell
->GetPosY();
888 if ( (cx
<= x
) && (cx
+ cell
->GetWidth() > x
) &&
889 (cy
<= y
) && (cy
+ cell
->GetHeight() > y
) )
891 return cell
->FindCellByPos(x
- cx
, y
- cy
, flags
);
895 else if ( flags
& wxHTML_FIND_NEAREST_AFTER
)
899 for ( const wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext() )
901 y2
= cell
->GetPosY() + cell
->GetHeight() - 1;
902 if (y2
< y
|| (y2
== y
&& cell
->GetPosX()+cell
->GetWidth()-1 < x
))
904 c
= cell
->FindCellByPos(x
- cell
->GetPosX(), y
- cell
->GetPosY(),
909 else if ( flags
& wxHTML_FIND_NEAREST_BEFORE
)
911 wxHtmlCell
*c2
, *c
= NULL
;
912 for ( const wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext() )
914 if (cell
->GetPosY() > y
||
915 (cell
->GetPosY() == y
&& cell
->GetPosX() > x
))
917 c2
= cell
->FindCellByPos(x
- cell
->GetPosX(), y
- cell
->GetPosY(),
929 void wxHtmlContainerCell::OnMouseClick(wxWindow
*parent
, int x
, int y
, const wxMouseEvent
& event
)
931 wxHtmlCell
*cell
= FindCellByPos(x
, y
);
933 cell
->OnMouseClick(parent
, x
, y
, event
);
938 void wxHtmlContainerCell::GetHorizontalConstraints(int *left
, int *right
) const
940 int cleft
= m_PosX
+ m_Width
, cright
= m_PosX
; // worst case
943 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
945 cell
->GetHorizontalConstraints(&l
, &r
);
952 cleft
-= (m_IndentLeft
< 0) ? (-m_IndentLeft
* m_Width
/ 100) : m_IndentLeft
;
953 cright
+= (m_IndentRight
< 0) ? (-m_IndentRight
* m_Width
/ 100) : m_IndentRight
;
962 wxHtmlCell
*wxHtmlContainerCell::GetFirstTerminal() const
967 for (wxHtmlCell
*c
= m_Cells
; c
; c
= c
->GetNext())
969 c2
= c
->GetFirstTerminal();
977 wxHtmlCell
*wxHtmlContainerCell::GetLastTerminal() const
981 // most common case first:
982 wxHtmlCell
*c
= m_LastCell
->GetLastTerminal();
986 wxHtmlCell
*c2
= NULL
;
987 for (c
= m_Cells
; c
; c
= c
->GetNext())
988 c2
= c
->GetLastTerminal();
998 // --------------------------------------------------------------------------
1000 // --------------------------------------------------------------------------
1002 void wxHtmlColourCell::Draw(wxDC
& dc
,
1004 int WXUNUSED(view_y1
), int WXUNUSED(view_y2
),
1005 wxHtmlRenderingInfo
& info
)
1007 DrawInvisible(dc
, x
, y
, info
);
1010 void wxHtmlColourCell::DrawInvisible(wxDC
& dc
,
1011 int WXUNUSED(x
), int WXUNUSED(y
),
1012 wxHtmlRenderingInfo
& info
)
1014 wxHtmlRenderingState
& state
= info
.GetState();
1015 if (m_Flags
& wxHTML_CLR_FOREGROUND
)
1017 state
.SetFgColour(m_Colour
);
1018 if (state
.GetSelectionState() != wxHTML_SEL_IN
)
1019 dc
.SetTextForeground(m_Colour
);
1021 dc
.SetTextForeground(
1022 info
.GetStyle().GetSelectedTextColour(m_Colour
));
1024 if (m_Flags
& wxHTML_CLR_BACKGROUND
)
1026 state
.SetBgColour(m_Colour
);
1027 if (state
.GetSelectionState() != wxHTML_SEL_IN
)
1028 dc
.SetTextBackground(m_Colour
);
1030 dc
.SetTextBackground(
1031 info
.GetStyle().GetSelectedTextBgColour(m_Colour
));
1032 dc
.SetBackground(wxBrush(m_Colour
, wxSOLID
));
1039 // ---------------------------------------------------------------------------
1041 // ---------------------------------------------------------------------------
1043 void wxHtmlFontCell::Draw(wxDC
& dc
,
1044 int WXUNUSED(x
), int WXUNUSED(y
),
1045 int WXUNUSED(view_y1
), int WXUNUSED(view_y2
),
1046 wxHtmlRenderingInfo
& WXUNUSED(info
))
1051 void wxHtmlFontCell::DrawInvisible(wxDC
& dc
, int WXUNUSED(x
), int WXUNUSED(y
),
1052 wxHtmlRenderingInfo
& WXUNUSED(info
))
1064 // ---------------------------------------------------------------------------
1066 // ---------------------------------------------------------------------------
1068 wxHtmlWidgetCell::wxHtmlWidgetCell(wxWindow
*wnd
, int w
)
1072 m_Wnd
->GetSize(&sx
, &sy
);
1073 m_Width
= sx
, m_Height
= sy
;
1078 void wxHtmlWidgetCell::Draw(wxDC
& WXUNUSED(dc
),
1079 int WXUNUSED(x
), int WXUNUSED(y
),
1080 int WXUNUSED(view_y1
), int WXUNUSED(view_y2
),
1081 wxHtmlRenderingInfo
& WXUNUSED(info
))
1083 int absx
= 0, absy
= 0, stx
, sty
;
1084 wxHtmlCell
*c
= this;
1088 absx
+= c
->GetPosX();
1089 absy
+= c
->GetPosY();
1093 ((wxScrolledWindow
*)(m_Wnd
->GetParent()))->GetViewStart(&stx
, &sty
);
1094 m_Wnd
->SetSize(absx
- wxHTML_SCROLL_STEP
* stx
, absy
- wxHTML_SCROLL_STEP
* sty
, m_Width
, m_Height
);
1099 void wxHtmlWidgetCell::DrawInvisible(wxDC
& WXUNUSED(dc
),
1100 int WXUNUSED(x
), int WXUNUSED(y
),
1101 wxHtmlRenderingInfo
& WXUNUSED(info
))
1103 int absx
= 0, absy
= 0, stx
, sty
;
1104 wxHtmlCell
*c
= this;
1108 absx
+= c
->GetPosX();
1109 absy
+= c
->GetPosY();
1113 ((wxScrolledWindow
*)(m_Wnd
->GetParent()))->GetViewStart(&stx
, &sty
);
1114 m_Wnd
->SetSize(absx
- wxHTML_SCROLL_STEP
* stx
, absy
- wxHTML_SCROLL_STEP
* sty
, m_Width
, m_Height
);
1119 void wxHtmlWidgetCell::Layout(int w
)
1121 if (m_WidthFloat
!= 0)
1123 m_Width
= (w
* m_WidthFloat
) / 100;
1124 m_Wnd
->SetSize(m_Width
, m_Height
);
1127 wxHtmlCell::Layout(w
);
1132 // ----------------------------------------------------------------------------
1133 // wxHtmlTerminalCellsInterator
1134 // ----------------------------------------------------------------------------
1136 const wxHtmlCell
* wxHtmlTerminalCellsInterator::operator++()
1143 if ( m_pos
== m_to
)
1149 if ( m_pos
->GetNext() )
1150 m_pos
= m_pos
->GetNext();
1153 // we must go up the hierarchy until we reach container where this
1154 // is not the last child, and then go down to first terminal cell:
1155 while ( m_pos
->GetNext() == NULL
)
1157 m_pos
= m_pos
->GetParent();
1161 m_pos
= m_pos
->GetNext();
1163 while ( m_pos
->GetFirstChild() != NULL
)
1164 m_pos
= m_pos
->GetFirstChild();
1165 } while ( !m_pos
->IsTerminalCell() );