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 //-----------------------------------------------------------------------------
62 //-----------------------------------------------------------------------------
64 wxHtmlCell::wxHtmlCell() : wxObject()
68 m_Width
= m_Height
= m_Descent
= 0;
69 m_CanLiveOnPagebreak
= TRUE
;
73 wxHtmlCell::~wxHtmlCell()
79 void wxHtmlCell::OnMouseClick(wxWindow
*parent
, int x
, int y
,
80 const wxMouseEvent
& event
)
82 wxHtmlLinkInfo
*lnk
= GetLink(x
, y
);
85 wxHtmlLinkInfo
lnk2(*lnk
);
86 lnk2
.SetEvent(&event
);
87 lnk2
.SetHtmlCell(this);
89 // note : this cast is legal because parent is *always* wxHtmlWindow
90 wxStaticCast(parent
, wxHtmlWindow
)->OnLinkClicked(lnk2
);
96 bool wxHtmlCell::AdjustPagebreak(int *pagebreak
, int* WXUNUSED(known_pagebreaks
), int WXUNUSED(number_of_pages
)) const
98 if ((!m_CanLiveOnPagebreak
) &&
99 m_PosY
< *pagebreak
&& m_PosY
+ m_Height
> *pagebreak
)
110 void wxHtmlCell::SetLink(const wxHtmlLinkInfo
& link
)
112 if (m_Link
) delete m_Link
;
114 if (link
.GetHref() != wxEmptyString
)
115 m_Link
= new wxHtmlLinkInfo(link
);
120 void wxHtmlCell::Layout(int WXUNUSED(w
))
127 void wxHtmlCell::GetHorizontalConstraints(int *left
, int *right
) const
132 *right
= m_PosX
+ m_Width
;
137 const wxHtmlCell
* wxHtmlCell::Find(int WXUNUSED(condition
), const void* WXUNUSED(param
)) const
143 wxHtmlCell
*wxHtmlCell::FindCellByPos(wxCoord x
, wxCoord y
,
144 unsigned flags
) const
146 if ( x
>= 0 && x
< m_Width
&& y
>= 0 && y
< m_Height
)
148 return wxConstCast(this, wxHtmlCell
);
152 if ((flags
& wxHTML_FIND_NEAREST_AFTER
) &&
153 (y
< 0 || (y
== 0 && x
<= 0)))
154 return wxConstCast(this, wxHtmlCell
);
155 else if ((flags
& wxHTML_FIND_NEAREST_BEFORE
) &&
156 (y
> m_Height
-1 || (y
== m_Height
-1 && x
>= m_Width
)))
157 return wxConstCast(this, wxHtmlCell
);
164 wxPoint
wxHtmlCell::GetAbsPos() const
166 wxPoint
p(m_PosX
, m_PosY
);
167 for (wxHtmlCell
*parent
= m_Parent
; parent
; parent
= parent
->m_Parent
)
169 p
.x
+= parent
->m_PosX
;
170 p
.y
+= parent
->m_PosY
;
175 unsigned wxHtmlCell::GetDepth() const
178 for (wxHtmlCell
*p
= m_Parent
; p
; p
= p
->m_Parent
)
183 bool wxHtmlCell::IsBefore(wxHtmlCell
*cell
) const
185 const wxHtmlCell
*c1
= this;
186 const wxHtmlCell
*c2
= cell
;
187 unsigned d1
= GetDepth();
188 unsigned d2
= cell
->GetDepth();
191 for (; d1
!= d2
; d1
-- )
194 for (; d1
!= d2
; d2
-- )
202 if ( c1
->m_Parent
== c2
->m_Parent
)
219 wxFAIL_MSG(_T("Cells are in different trees"));
224 //-----------------------------------------------------------------------------
226 //-----------------------------------------------------------------------------
228 wxHtmlWordCell::wxHtmlWordCell(const wxString
& word
, wxDC
& dc
) : wxHtmlCell()
231 dc
.GetTextExtent(m_Word
, &m_Width
, &m_Height
, &m_Descent
);
232 SetCanLiveOnPagebreak(FALSE
);
236 // Splits m_Word into up to three parts according to selection, returns
237 // substring before, in and after selection and the points (in relative coords)
238 // where s2 and s3 start:
239 void wxHtmlWordCell::Split(wxDC
& dc
,
240 const wxPoint
& selFrom
, const wxPoint
& selTo
,
241 wxString
& s1
, wxString
& s2
, wxString
& s3
,
242 unsigned& pos1
, unsigned& pos2
)
244 wxPoint pt1
= (selFrom
== wxDefaultPosition
) ?
245 wxDefaultPosition
: selFrom
- GetAbsPos();
246 wxPoint pt2
= (selTo
== wxDefaultPosition
) ?
247 wxPoint(m_Width
, -1) : selTo
- GetAbsPos();
249 wxCoord charW
, charH
;
250 unsigned len
= m_Word
.length();
253 s1
= s2
= s3
= wxEmptyString
;
256 while ( pt1
.x
> 0 && i
< len
)
258 dc
.GetTextExtent(m_Word
[i
], &charW
, &charH
);
271 while ( pt2
.x
> 0 && j
< len
)
273 dc
.GetTextExtent(m_Word
[j
], &charW
, &charH
);
282 s1
= m_Word
.Mid(0, i
);
283 s2
= m_Word
.Mid(i
, j
-i
);
286 printf(" '%s' %i '%s' %i '%s'\n", s1
.mb_str(), pos1
,
287 s2
.mb_str(), pos2
,s3
.mb_str());
292 static void SwitchSelState(wxDC
& dc
, wxHtmlRenderingState
& state
,
297 dc
.SetBackgroundMode(wxSOLID
);
298 dc
.SetTextBackground(
299 wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
));
300 dc
.SetTextForeground(
301 wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
));
305 dc
.SetBackgroundMode(wxTRANSPARENT
);
306 dc
.SetTextForeground(state
.GetFgColour());
307 dc
.SetTextBackground(state
.GetBgColour());
312 void wxHtmlWordCell::Draw(wxDC
& dc
, int x
, int y
,
313 int WXUNUSED(view_y1
), int WXUNUSED(view_y2
),
314 wxHtmlRenderingState
& state
)
316 #if 0 // useful for debugging
317 dc
.DrawRectangle(x
+m_PosX
,y
+m_PosY
,m_Width
,m_Height
);
320 if ( state
.GetSelectionState() == wxHTML_SEL_CHANGING
)
322 // Selection changing, we must draw the word piecewise:
325 wxString textBefore
, textInside
, textAfter
;
326 wxHtmlSelection
*s
= state
.GetSelection();
329 this == s
->GetFromCell() ? s
->GetFromPos() : wxDefaultPosition
,
330 this == s
->GetToCell() ? s
->GetToPos() : wxDefaultPosition
,
331 textBefore
, textInside
, textAfter
, ofs1
, ofs2
);
332 dc
.DrawText(textBefore
, x
+ m_PosX
, y
+ m_PosY
);
334 dc
.GetTextExtent(textBefore
, &w1
,&h123
);
335 dc
.GetTextExtent(textInside
, &w2
,&h123
);
336 dc
.GetTextExtent(textAfter
, &w3
,&h123
);
337 if ( !textInside
.empty() )
339 SwitchSelState(dc
, state
, true);
340 dc
.DrawText(textInside
, x
+ m_PosX
+ ofs1
, y
+ m_PosY
);
342 if ( !textAfter
.empty() )
344 SwitchSelState(dc
, state
, false);
345 dc
.DrawText(textAfter
, x
+ m_PosX
+ ofs2
, y
+ m_PosY
);
350 // Not changing selection state, draw the word in single mode:
352 if ( state
.GetSelectionState() != wxHTML_SEL_OUT
&&
353 dc
.GetBackgroundMode() != wxSOLID
)
355 SwitchSelState(dc
, state
, true);
357 else if ( state
.GetSelectionState() == wxHTML_SEL_OUT
&&
358 dc
.GetBackgroundMode() == wxSOLID
)
360 SwitchSelState(dc
, state
, false);
362 dc
.DrawText(m_Word
, x
+ m_PosX
, y
+ m_PosY
);
367 wxString
wxHtmlWordCell::ConvertToText(wxHtmlSelection
*sel
) const
369 // FIXME - use selection
375 //-----------------------------------------------------------------------------
376 // wxHtmlContainerCell
377 //-----------------------------------------------------------------------------
380 wxHtmlContainerCell::wxHtmlContainerCell(wxHtmlContainerCell
*parent
) : wxHtmlCell()
382 m_Cells
= m_LastCell
= NULL
;
384 if (m_Parent
) m_Parent
->InsertCell(this);
385 m_AlignHor
= wxHTML_ALIGN_LEFT
;
386 m_AlignVer
= wxHTML_ALIGN_BOTTOM
;
387 m_IndentLeft
= m_IndentRight
= m_IndentTop
= m_IndentBottom
= 0;
388 m_WidthFloat
= 100; m_WidthFloatUnits
= wxHTML_UNITS_PERCENT
;
389 m_UseBkColour
= FALSE
;
392 m_MinHeightAlign
= wxHTML_ALIGN_TOP
;
396 wxHtmlContainerCell::~wxHtmlContainerCell()
398 wxHtmlCell
*cell
= m_Cells
;
401 wxHtmlCell
*cellNext
= cell
->GetNext();
409 void wxHtmlContainerCell::SetIndent(int i
, int what
, int units
)
411 int val
= (units
== wxHTML_UNITS_PIXELS
) ? i
: -i
;
412 if (what
& wxHTML_INDENT_LEFT
) m_IndentLeft
= val
;
413 if (what
& wxHTML_INDENT_RIGHT
) m_IndentRight
= val
;
414 if (what
& wxHTML_INDENT_TOP
) m_IndentTop
= val
;
415 if (what
& wxHTML_INDENT_BOTTOM
) m_IndentBottom
= val
;
421 int wxHtmlContainerCell::GetIndent(int ind
) const
423 if (ind
& wxHTML_INDENT_LEFT
) return m_IndentLeft
;
424 else if (ind
& wxHTML_INDENT_RIGHT
) return m_IndentRight
;
425 else if (ind
& wxHTML_INDENT_TOP
) return m_IndentTop
;
426 else if (ind
& wxHTML_INDENT_BOTTOM
) return m_IndentBottom
;
427 else return -1; /* BUG! Should not be called... */
433 int wxHtmlContainerCell::GetIndentUnits(int ind
) const
436 if (ind
& wxHTML_INDENT_LEFT
) p
= m_IndentLeft
< 0;
437 else if (ind
& wxHTML_INDENT_RIGHT
) p
= m_IndentRight
< 0;
438 else if (ind
& wxHTML_INDENT_TOP
) p
= m_IndentTop
< 0;
439 else if (ind
& wxHTML_INDENT_BOTTOM
) p
= m_IndentBottom
< 0;
440 if (p
) return wxHTML_UNITS_PERCENT
;
441 else return wxHTML_UNITS_PIXELS
;
446 bool wxHtmlContainerCell::AdjustPagebreak(int *pagebreak
, int* known_pagebreaks
, int number_of_pages
) const
448 if (!m_CanLiveOnPagebreak
)
449 return wxHtmlCell::AdjustPagebreak(pagebreak
, known_pagebreaks
, number_of_pages
);
453 wxHtmlCell
*c
= GetFirstChild();
455 int pbrk
= *pagebreak
- m_PosY
;
459 if (c
->AdjustPagebreak(&pbrk
, known_pagebreaks
, number_of_pages
))
464 *pagebreak
= pbrk
+ m_PosY
;
471 void wxHtmlContainerCell::Layout(int w
)
473 wxHtmlCell::Layout(w
);
475 if (m_LastLayout
== w
) return;
477 // VS: Any attempt to layout with negative or zero width leads to hell,
478 // but we can't ignore such attempts completely, since it sometimes
479 // happen (e.g. when trying how small a table can be). The best thing we
480 // can do is to set the width of child cells to zero
484 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
486 // this does two things: it recursively calls this code on all
487 // child contrainers and resets children's position to (0,0)
491 wxHtmlCell
*cell
= m_Cells
, *line
= m_Cells
;
492 long xpos
= 0, ypos
= m_IndentTop
;
493 int xdelta
= 0, ybasicpos
= 0, ydiff
;
494 int s_width
, s_indent
;
495 int ysizeup
= 0, ysizedown
= 0;
496 int MaxLineWidth
= 0;
506 if (m_WidthFloatUnits
== wxHTML_UNITS_PERCENT
)
508 if (m_WidthFloat
< 0) m_Width
= (100 + m_WidthFloat
) * w
/ 100;
509 else m_Width
= m_WidthFloat
* w
/ 100;
513 if (m_WidthFloat
< 0) m_Width
= w
+ m_WidthFloat
;
514 else m_Width
= m_WidthFloat
;
519 int l
= (m_IndentLeft
< 0) ? (-m_IndentLeft
* m_Width
/ 100) : m_IndentLeft
;
520 int r
= (m_IndentRight
< 0) ? (-m_IndentRight
* m_Width
/ 100) : m_IndentRight
;
521 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
522 cell
->Layout(m_Width
- (l
+ r
));
531 // adjust indentation:
532 s_indent
= (m_IndentLeft
< 0) ? (-m_IndentLeft
* m_Width
/ 100) : m_IndentLeft
;
533 s_width
= m_Width
- s_indent
- ((m_IndentRight
< 0) ? (-m_IndentRight
* m_Width
/ 100) : m_IndentRight
);
540 case wxHTML_ALIGN_TOP
: ybasicpos
= 0; break;
541 case wxHTML_ALIGN_BOTTOM
: ybasicpos
= - cell
->GetHeight(); break;
542 case wxHTML_ALIGN_CENTER
: ybasicpos
= - cell
->GetHeight() / 2; break;
544 ydiff
= cell
->GetHeight() + ybasicpos
;
546 if (cell
->GetDescent() + ydiff
> ysizedown
) ysizedown
= cell
->GetDescent() + ydiff
;
547 if (ybasicpos
+ cell
->GetDescent() < -ysizeup
) ysizeup
= - (ybasicpos
+ cell
->GetDescent());
549 cell
->SetPos(xpos
, ybasicpos
+ cell
->GetDescent());
550 xpos
+= cell
->GetWidth();
551 cell
= cell
->GetNext();
554 // force new line if occured:
555 if ((cell
== NULL
) || (xpos
+ cell
->GetWidth() > s_width
))
557 if (xpos
> MaxLineWidth
) MaxLineWidth
= xpos
;
558 if (ysizeup
< 0) ysizeup
= 0;
559 if (ysizedown
< 0) ysizedown
= 0;
560 switch (m_AlignHor
) {
561 case wxHTML_ALIGN_LEFT
:
562 case wxHTML_ALIGN_JUSTIFY
:
565 case wxHTML_ALIGN_RIGHT
:
566 xdelta
= 0 + (s_width
- xpos
);
568 case wxHTML_ALIGN_CENTER
:
569 xdelta
= 0 + (s_width
- xpos
) / 2;
572 if (xdelta
< 0) xdelta
= 0;
577 if (m_AlignHor
!= wxHTML_ALIGN_JUSTIFY
|| cell
== NULL
)
580 line
->SetPos(line
->GetPosX() + xdelta
,
581 ypos
+ line
->GetPosY());
582 line
= line
->GetNext();
587 int step
= (s_width
- xpos
);
588 if (step
< 0) step
= 0;
590 if (xcnt
> 0) while (line
!= cell
)
592 line
->SetPos(line
->GetPosX() + s_indent
+
593 (counter
++ * step
/ xcnt
),
594 ypos
+ line
->GetPosY());
595 line
= line
->GetNext();
602 ysizeup
= ysizedown
= 0;
607 // setup height & width, depending on container layout:
608 m_Height
= ypos
+ (ysizedown
+ ysizeup
) + m_IndentBottom
;
610 if (m_Height
< m_MinHeight
)
612 if (m_MinHeightAlign
!= wxHTML_ALIGN_TOP
)
614 int diff
= m_MinHeight
- m_Height
;
615 if (m_MinHeightAlign
== wxHTML_ALIGN_CENTER
) diff
/= 2;
619 cell
->SetPos(cell
->GetPosX(), cell
->GetPosY() + diff
);
620 cell
= cell
->GetNext();
623 m_Height
= m_MinHeight
;
626 MaxLineWidth
+= s_indent
+ ((m_IndentRight
< 0) ? (-m_IndentRight
* m_Width
/ 100) : m_IndentRight
);
627 if (m_Width
< MaxLineWidth
) m_Width
= MaxLineWidth
;
632 void wxHtmlContainerCell::UpdateRenderingStatePre(wxHtmlRenderingState
& state
,
633 wxHtmlCell
*cell
) const
635 wxHtmlSelection
*s
= state
.GetSelection();
637 if (s
->GetFromCell() == cell
|| s
->GetToCell() == cell
)
639 state
.SetSelectionState(wxHTML_SEL_CHANGING
);
643 void wxHtmlContainerCell::UpdateRenderingStatePost(wxHtmlRenderingState
& state
,
644 wxHtmlCell
*cell
) const
646 wxHtmlSelection
*s
= state
.GetSelection();
648 if (s
->GetToCell() == cell
)
649 state
.SetSelectionState(wxHTML_SEL_OUT
);
650 else if (s
->GetFromCell() == cell
)
651 state
.SetSelectionState(wxHTML_SEL_IN
);
654 #define mMin(a, b) (((a) < (b)) ? (a) : (b))
655 #define mMax(a, b) (((a) < (b)) ? (b) : (a))
657 void wxHtmlContainerCell::Draw(wxDC
& dc
, int x
, int y
, int view_y1
, int view_y2
,
658 wxHtmlRenderingState
& state
)
660 // container visible, draw it:
661 if ((y
+ m_PosY
<= view_y2
) && (y
+ m_PosY
+ m_Height
> view_y1
))
665 wxBrush myb
= wxBrush(m_BkColour
, wxSOLID
);
667 int real_y1
= mMax(y
+ m_PosY
, view_y1
);
668 int real_y2
= mMin(y
+ m_PosY
+ m_Height
- 1, view_y2
);
671 dc
.SetPen(*wxTRANSPARENT_PEN
);
672 dc
.DrawRectangle(x
+ m_PosX
, real_y1
, m_Width
, real_y2
- real_y1
+ 1);
677 wxPen
mypen1(m_BorderColour1
, 1, wxSOLID
);
678 wxPen
mypen2(m_BorderColour2
, 1, wxSOLID
);
681 dc
.DrawLine(x
+ m_PosX
, y
+ m_PosY
, x
+ m_PosX
, y
+ m_PosY
+ m_Height
- 1);
682 dc
.DrawLine(x
+ m_PosX
, y
+ m_PosY
, x
+ m_PosX
+ m_Width
, y
+ m_PosY
);
684 dc
.DrawLine(x
+ m_PosX
+ m_Width
- 1, y
+ m_PosY
, x
+ m_PosX
+ m_Width
- 1, y
+ m_PosY
+ m_Height
- 1);
685 dc
.DrawLine(x
+ m_PosX
, y
+ m_PosY
+ m_Height
- 1, x
+ m_PosX
+ m_Width
, y
+ m_PosY
+ m_Height
- 1);
690 // draw container's contents:
691 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
693 UpdateRenderingStatePre(state
, cell
);
695 x
+ m_PosX
, y
+ m_PosY
, view_y1
, view_y2
,
697 UpdateRenderingStatePost(state
, cell
);
701 // container invisible, just proceed font+color changing:
704 DrawInvisible(dc
, x
, y
, state
);
710 void wxHtmlContainerCell::DrawInvisible(wxDC
& dc
, int x
, int y
,
711 wxHtmlRenderingState
& state
)
715 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
717 UpdateRenderingStatePre(state
, cell
);
718 cell
->DrawInvisible(dc
, x
+ m_PosX
, y
+ m_PosY
, state
);
719 UpdateRenderingStatePost(state
, cell
);
725 wxColour
wxHtmlContainerCell::GetBackgroundColour()
735 wxHtmlLinkInfo
*wxHtmlContainerCell::GetLink(int x
, int y
) const
737 wxHtmlCell
*cell
= FindCellByPos(x
, y
);
739 // VZ: I don't know if we should pass absolute or relative coords to
740 // wxHtmlCell::GetLink()? As the base class version just ignores them
741 // anyhow, it hardly matters right now but should still be clarified
742 return cell
? cell
->GetLink(x
, y
) : NULL
;
747 void wxHtmlContainerCell::InsertCell(wxHtmlCell
*f
)
749 if (!m_Cells
) m_Cells
= m_LastCell
= f
;
752 m_LastCell
->SetNext(f
);
754 if (m_LastCell
) while (m_LastCell
->GetNext()) m_LastCell
= m_LastCell
->GetNext();
762 void wxHtmlContainerCell::SetAlign(const wxHtmlTag
& tag
)
764 if (tag
.HasParam(wxT("ALIGN")))
766 wxString alg
= tag
.GetParam(wxT("ALIGN"));
768 if (alg
== wxT("CENTER"))
769 SetAlignHor(wxHTML_ALIGN_CENTER
);
770 else if (alg
== wxT("LEFT"))
771 SetAlignHor(wxHTML_ALIGN_LEFT
);
772 else if (alg
== wxT("JUSTIFY"))
773 SetAlignHor(wxHTML_ALIGN_JUSTIFY
);
774 else if (alg
== wxT("RIGHT"))
775 SetAlignHor(wxHTML_ALIGN_RIGHT
);
782 void wxHtmlContainerCell::SetWidthFloat(const wxHtmlTag
& tag
, double pixel_scale
)
784 if (tag
.HasParam(wxT("WIDTH")))
787 wxString wd
= tag
.GetParam(wxT("WIDTH"));
789 if (wd
[wd
.Length()-1] == wxT('%'))
791 wxSscanf(wd
.c_str(), wxT("%i%%"), &wdi
);
792 SetWidthFloat(wdi
, wxHTML_UNITS_PERCENT
);
796 wxSscanf(wd
.c_str(), wxT("%i"), &wdi
);
797 SetWidthFloat((int)(pixel_scale
* (double)wdi
), wxHTML_UNITS_PIXELS
);
805 const wxHtmlCell
* wxHtmlContainerCell::Find(int condition
, const void* param
) const
809 const wxHtmlCell
*r
= NULL
;
811 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
813 r
= cell
->Find(condition
, param
);
821 wxHtmlCell
*wxHtmlContainerCell::FindCellByPos(wxCoord x
, wxCoord y
,
822 unsigned flags
) const
824 if ( flags
& wxHTML_FIND_EXACT
)
826 for ( const wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext() )
828 int cx
= cell
->GetPosX(),
829 cy
= cell
->GetPosY();
831 if ( (cx
<= x
) && (cx
+ cell
->GetWidth() > x
) &&
832 (cy
<= y
) && (cy
+ cell
->GetHeight() > y
) )
834 return cell
->FindCellByPos(x
- cx
, y
- cy
, flags
);
838 else if ( flags
& wxHTML_FIND_NEAREST_AFTER
)
842 for ( const wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext() )
844 y2
= cell
->GetPosY() + cell
->GetHeight() - 1;
845 if (y2
< y
|| (y2
== y
&& cell
->GetPosX()+cell
->GetWidth()-1 < x
))
847 c
= cell
->FindCellByPos(x
- cell
->GetPosX(), y
- cell
->GetPosY(),
852 else if ( flags
& wxHTML_FIND_NEAREST_BEFORE
)
854 wxHtmlCell
*c2
, *c
= NULL
;
855 for ( const wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext() )
857 if (cell
->GetPosY() > y
||
858 (cell
->GetPosY() == y
&& cell
->GetPosX() > x
))
860 c2
= cell
->FindCellByPos(x
- cell
->GetPosX(), y
- cell
->GetPosY(),
872 void wxHtmlContainerCell::OnMouseClick(wxWindow
*parent
, int x
, int y
, const wxMouseEvent
& event
)
874 wxHtmlCell
*cell
= FindCellByPos(x
, y
);
876 cell
->OnMouseClick(parent
, x
, y
, event
);
881 void wxHtmlContainerCell::GetHorizontalConstraints(int *left
, int *right
) const
883 int cleft
= m_PosX
+ m_Width
, cright
= m_PosX
; // worst case
886 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
888 cell
->GetHorizontalConstraints(&l
, &r
);
895 cleft
-= (m_IndentLeft
< 0) ? (-m_IndentLeft
* m_Width
/ 100) : m_IndentLeft
;
896 cright
+= (m_IndentRight
< 0) ? (-m_IndentRight
* m_Width
/ 100) : m_IndentRight
;
905 wxHtmlCell
*wxHtmlContainerCell::GetFirstTerminal() const
910 for (wxHtmlCell
*c
= m_Cells
; c
; c
= c
->GetNext())
912 c2
= c
->GetFirstTerminal();
920 wxHtmlCell
*wxHtmlContainerCell::GetLastTerminal() const
924 // most common case first:
925 wxHtmlCell
*c
= m_LastCell
->GetLastTerminal();
929 wxHtmlCell
*c2
= NULL
;
930 for (c
= m_Cells
; c
; c
= c
->GetNext())
931 c2
= c
->GetLastTerminal();
941 // --------------------------------------------------------------------------
943 // --------------------------------------------------------------------------
945 void wxHtmlColourCell::Draw(wxDC
& dc
,
947 int WXUNUSED(view_y1
), int WXUNUSED(view_y2
),
948 wxHtmlRenderingState
& state
)
950 DrawInvisible(dc
, x
, y
, state
);
953 void wxHtmlColourCell::DrawInvisible(wxDC
& dc
,
954 int WXUNUSED(x
), int WXUNUSED(y
),
955 wxHtmlRenderingState
& state
)
957 if (m_Flags
& wxHTML_CLR_FOREGROUND
)
959 state
.SetFgColour(m_Colour
);
960 if (state
.GetSelectionState() != wxHTML_SEL_IN
)
961 dc
.SetTextForeground(m_Colour
);
963 if (m_Flags
& wxHTML_CLR_BACKGROUND
)
965 state
.SetBgColour(m_Colour
);
966 if (state
.GetSelectionState() != wxHTML_SEL_IN
)
967 dc
.SetTextBackground(m_Colour
);
968 dc
.SetBackground(wxBrush(m_Colour
, wxSOLID
));
975 // ---------------------------------------------------------------------------
977 // ---------------------------------------------------------------------------
979 void wxHtmlFontCell::Draw(wxDC
& dc
,
980 int WXUNUSED(x
), int WXUNUSED(y
),
981 int WXUNUSED(view_y1
), int WXUNUSED(view_y2
),
982 wxHtmlRenderingState
& WXUNUSED(state
))
987 void wxHtmlFontCell::DrawInvisible(wxDC
& dc
, int WXUNUSED(x
), int WXUNUSED(y
),
988 wxHtmlRenderingState
& WXUNUSED(state
))
1000 // ---------------------------------------------------------------------------
1002 // ---------------------------------------------------------------------------
1004 wxHtmlWidgetCell::wxHtmlWidgetCell(wxWindow
*wnd
, int w
)
1008 m_Wnd
->GetSize(&sx
, &sy
);
1009 m_Width
= sx
, m_Height
= sy
;
1014 void wxHtmlWidgetCell::Draw(wxDC
& WXUNUSED(dc
),
1015 int WXUNUSED(x
), int WXUNUSED(y
),
1016 int WXUNUSED(view_y1
), int WXUNUSED(view_y2
),
1017 wxHtmlRenderingState
& WXUNUSED(state
))
1019 int absx
= 0, absy
= 0, stx
, sty
;
1020 wxHtmlCell
*c
= this;
1024 absx
+= c
->GetPosX();
1025 absy
+= c
->GetPosY();
1029 ((wxScrolledWindow
*)(m_Wnd
->GetParent()))->GetViewStart(&stx
, &sty
);
1030 m_Wnd
->SetSize(absx
- wxHTML_SCROLL_STEP
* stx
, absy
- wxHTML_SCROLL_STEP
* sty
, m_Width
, m_Height
);
1035 void wxHtmlWidgetCell::DrawInvisible(wxDC
& WXUNUSED(dc
),
1036 int WXUNUSED(x
), int WXUNUSED(y
),
1037 wxHtmlRenderingState
& WXUNUSED(state
))
1039 int absx
= 0, absy
= 0, stx
, sty
;
1040 wxHtmlCell
*c
= this;
1044 absx
+= c
->GetPosX();
1045 absy
+= c
->GetPosY();
1049 ((wxScrolledWindow
*)(m_Wnd
->GetParent()))->GetViewStart(&stx
, &sty
);
1050 m_Wnd
->SetSize(absx
- wxHTML_SCROLL_STEP
* stx
, absy
- wxHTML_SCROLL_STEP
* sty
, m_Width
, m_Height
);
1055 void wxHtmlWidgetCell::Layout(int w
)
1057 if (m_WidthFloat
!= 0)
1059 m_Width
= (w
* m_WidthFloat
) / 100;
1060 m_Wnd
->SetSize(m_Width
, m_Height
);
1063 wxHtmlCell::Layout(w
);
1068 // ----------------------------------------------------------------------------
1069 // wxHtmlTerminalCellsInterator
1070 // ----------------------------------------------------------------------------
1072 const wxHtmlCell
* wxHtmlTerminalCellsInterator::operator++()
1079 if ( m_pos
== m_to
)
1085 if ( m_pos
->GetNext() )
1086 m_pos
= m_pos
->GetNext();
1089 // we must go up the hierarchy until we reach container where this
1090 // is not the last child, and then go down to first terminal cell:
1091 while ( m_pos
->GetNext() == NULL
)
1093 m_pos
= m_pos
->GetParent();
1097 m_pos
= m_pos
->GetNext();
1099 while ( m_pos
->GetFirstChild() != NULL
)
1100 m_pos
= m_pos
->GetFirstChild();
1101 } while ( !m_pos
->IsTerminalCell() );