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"
34 #include "wx/dynarray.h"
38 //-----------------------------------------------------------------------------
40 //-----------------------------------------------------------------------------
42 static wxCursor
*gs_cursorLink
= NULL
;
43 static wxCursor
*gs_cursorText
= NULL
;
46 //-----------------------------------------------------------------------------
48 //-----------------------------------------------------------------------------
50 void wxHtmlSelection::Set(const wxPoint
& fromPos
, const wxHtmlCell
*fromCell
,
51 const wxPoint
& toPos
, const wxHtmlCell
*toCell
)
53 m_fromCell
= fromCell
;
59 void wxHtmlSelection::Set(const wxHtmlCell
*fromCell
, const wxHtmlCell
*toCell
)
61 wxPoint p1
= fromCell
? fromCell
->GetAbsPos() : wxDefaultPosition
;
62 wxPoint p2
= toCell
? toCell
->GetAbsPos() : wxDefaultPosition
;
65 p2
.x
+= toCell
->GetWidth()-1;
66 p2
.y
+= toCell
->GetHeight()-1;
68 Set(p1
, fromCell
, p2
, toCell
);
71 wxColour
wxDefaultHtmlRenderingStyle::GetSelectedTextColour(
74 return wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
77 wxColour
wxDefaultHtmlRenderingStyle::GetSelectedTextBgColour(
78 const wxColour
& WXUNUSED(clr
))
80 return wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
);
84 //-----------------------------------------------------------------------------
86 //-----------------------------------------------------------------------------
88 wxHtmlCell::wxHtmlCell() : wxObject()
92 m_Width
= m_Height
= m_Descent
= 0;
93 m_CanLiveOnPagebreak
= TRUE
;
97 wxHtmlCell::~wxHtmlCell()
103 void wxHtmlCell::OnMouseClick(wxWindow
*parent
, int x
, int y
,
104 const wxMouseEvent
& event
)
106 wxHtmlLinkInfo
*lnk
= GetLink(x
, y
);
109 wxHtmlLinkInfo
lnk2(*lnk
);
110 lnk2
.SetEvent(&event
);
111 lnk2
.SetHtmlCell(this);
113 // note : this cast is legal because parent is *always* wxHtmlWindow
114 wxStaticCast(parent
, wxHtmlWindow
)->OnLinkClicked(lnk2
);
119 wxCursor
wxHtmlCell::GetCursor() const
123 if ( !gs_cursorLink
)
124 gs_cursorLink
= new wxCursor(wxCURSOR_HAND
);
125 return *gs_cursorLink
;
128 return *wxSTANDARD_CURSOR
;
132 bool wxHtmlCell::AdjustPagebreak(int *pagebreak
, int* WXUNUSED(known_pagebreaks
), int WXUNUSED(number_of_pages
)) const
134 if ((!m_CanLiveOnPagebreak
) &&
135 m_PosY
< *pagebreak
&& m_PosY
+ m_Height
> *pagebreak
)
146 void wxHtmlCell::SetLink(const wxHtmlLinkInfo
& link
)
148 if (m_Link
) delete m_Link
;
150 if (link
.GetHref() != wxEmptyString
)
151 m_Link
= new wxHtmlLinkInfo(link
);
155 void wxHtmlCell::Layout(int WXUNUSED(w
))
162 const wxHtmlCell
* wxHtmlCell::Find(int WXUNUSED(condition
), const void* WXUNUSED(param
)) const
168 wxHtmlCell
*wxHtmlCell::FindCellByPos(wxCoord x
, wxCoord y
,
169 unsigned flags
) const
171 if ( x
>= 0 && x
< m_Width
&& y
>= 0 && y
< m_Height
)
173 return wxConstCast(this, wxHtmlCell
);
177 if ((flags
& wxHTML_FIND_NEAREST_AFTER
) &&
178 (y
< 0 || (y
< 0+m_Height
&& x
< 0+m_Width
)))
179 return wxConstCast(this, wxHtmlCell
);
180 else if ((flags
& wxHTML_FIND_NEAREST_BEFORE
) &&
181 (y
>= 0+m_Height
|| (y
>= 0 && x
>= 0)))
182 return wxConstCast(this, wxHtmlCell
);
189 wxPoint
wxHtmlCell::GetAbsPos() const
191 wxPoint
p(m_PosX
, m_PosY
);
192 for (wxHtmlCell
*parent
= m_Parent
; parent
; parent
= parent
->m_Parent
)
194 p
.x
+= parent
->m_PosX
;
195 p
.y
+= parent
->m_PosY
;
200 unsigned wxHtmlCell::GetDepth() const
203 for (wxHtmlCell
*p
= m_Parent
; p
; p
= p
->m_Parent
)
208 bool wxHtmlCell::IsBefore(wxHtmlCell
*cell
) const
210 const wxHtmlCell
*c1
= this;
211 const wxHtmlCell
*c2
= cell
;
212 unsigned d1
= GetDepth();
213 unsigned d2
= cell
->GetDepth();
216 for (; d1
!= d2
; d1
-- )
219 for (; d1
!= d2
; d2
-- )
227 if ( c1
->m_Parent
== c2
->m_Parent
)
244 wxFAIL_MSG(_T("Cells are in different trees"));
249 //-----------------------------------------------------------------------------
251 //-----------------------------------------------------------------------------
253 wxHtmlWordCell::wxHtmlWordCell(const wxString
& word
, wxDC
& dc
) : wxHtmlCell()
256 dc
.GetTextExtent(m_Word
, &m_Width
, &m_Height
, &m_Descent
);
257 SetCanLiveOnPagebreak(FALSE
);
258 m_allowLinebreak
= true;
261 void wxHtmlWordCell::SetPreviousWord(wxHtmlWordCell
*cell
)
263 if ( cell
&& m_Parent
== cell
->m_Parent
&&
264 !wxIsspace(cell
->m_Word
.Last()) && !wxIsspace(m_Word
[0u]) )
266 m_allowLinebreak
= 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
.SetPen(*wxBLACK_PEN
);
378 dc
.DrawRectangle(x
+m_PosX
,y
+m_PosY
,m_Width
,m_Height
);
381 bool drawSelectionAfterCell
= false;
383 if ( info
.GetState().GetSelectionState() == wxHTML_SEL_CHANGING
)
385 // Selection changing, we must draw the word piecewise:
386 wxHtmlSelection
*s
= info
.GetSelection();
391 wxPoint priv
= (this == s
->GetFromCell()) ?
392 s
->GetFromPrivPos() : s
->GetToPrivPos();
394 // NB: this is quite a hack: in order to compute selection boundaries
395 // (in word's characters) we must know current font, which is only
396 // possible inside rendering code. Therefore we update the
397 // information here and store it in wxHtmlSelection so that
398 // ConvertToText can use it later:
399 if ( priv
== wxDefaultPosition
)
401 SetSelectionPrivPos(dc
, s
);
402 priv
= (this == s
->GetFromCell()) ?
403 s
->GetFromPrivPos() : s
->GetToPrivPos();
411 txt
= m_Word
.Mid(0, part1
);
412 dc
.DrawText(txt
, x
+ m_PosX
, y
+ m_PosY
);
413 dc
.GetTextExtent(txt
, &w
, &h
);
417 SwitchSelState(dc
, info
, true);
419 txt
= m_Word
.Mid(part1
, part2
-part1
);
420 dc
.DrawText(txt
, ofs
+ x
+ m_PosX
, y
+ m_PosY
);
422 if ( (size_t)part2
< m_Word
.length() )
424 dc
.GetTextExtent(txt
, &w
, &h
);
426 SwitchSelState(dc
, info
, false);
427 txt
= m_Word
.Mid(part2
);
428 dc
.DrawText(txt
, ofs
+ x
+ m_PosX
, y
+ m_PosY
);
431 drawSelectionAfterCell
= true;
435 wxHtmlSelectionState selstate
= info
.GetState().GetSelectionState();
436 // Not changing selection state, draw the word in single mode:
437 if ( selstate
!= wxHTML_SEL_OUT
&&
438 dc
.GetBackgroundMode() != wxSOLID
)
440 SwitchSelState(dc
, info
, true);
442 else if ( selstate
== wxHTML_SEL_OUT
&&
443 dc
.GetBackgroundMode() == wxSOLID
)
445 SwitchSelState(dc
, info
, false);
447 dc
.DrawText(m_Word
, x
+ m_PosX
, y
+ m_PosY
);
448 drawSelectionAfterCell
= (selstate
!= wxHTML_SEL_OUT
);
451 // NB: If the text is justified then there is usually some free space
452 // between adjacent cells and drawing the selection only onto cells
453 // would result in ugly unselected spaces. The code below detects
454 // this special case and renders the selection *outside* the sell,
456 if ( m_Parent
->GetAlignHor() == wxHTML_ALIGN_JUSTIFY
&&
457 drawSelectionAfterCell
)
459 wxHtmlCell
*nextCell
= m_Next
;
460 while ( nextCell
&& nextCell
->IsFormattingCell() )
461 nextCell
= nextCell
->GetNext();
464 int nextX
= nextCell
->GetPosX();
465 if ( m_PosX
+ m_Width
< nextX
)
467 dc
.SetBrush(dc
.GetBackground());
468 dc
.SetPen(*wxTRANSPARENT_PEN
);
469 dc
.DrawRectangle(x
+ m_PosX
+ m_Width
, y
+ m_PosY
,
470 nextX
- m_PosX
- m_Width
, m_Height
);
477 wxString
wxHtmlWordCell::ConvertToText(wxHtmlSelection
*s
) const
479 if ( s
&& (this == s
->GetFromCell() || this == s
->GetToCell()) )
481 wxPoint priv
= this == s
->GetFromCell() ? s
->GetFromPrivPos()
484 // VZ: we may be called before we had a chance to re-render ourselves
485 // and in this case GetFrom/ToPrivPos() is not set yet -- assume
486 // that this only happens in case of a double/triple click (which
487 // seems to be the case now) and so it makes sense to select the
488 // entire contents of the cell in this case
490 // TODO: but this really needs to be fixed in some better way later...
491 if ( priv
!= wxDefaultPosition
)
495 return m_Word
.Mid(part1
, part2
-part1
);
497 //else: return the whole word below
503 wxCursor
wxHtmlWordCell::GetCursor() const
507 if ( !gs_cursorText
)
508 gs_cursorText
= new wxCursor(wxCURSOR_IBEAM
);
509 return *gs_cursorText
;
512 return wxHtmlCell::GetCursor();
516 //-----------------------------------------------------------------------------
517 // wxHtmlContainerCell
518 //-----------------------------------------------------------------------------
521 wxHtmlContainerCell::wxHtmlContainerCell(wxHtmlContainerCell
*parent
) : wxHtmlCell()
523 m_Cells
= m_LastCell
= NULL
;
525 if (m_Parent
) m_Parent
->InsertCell(this);
526 m_AlignHor
= wxHTML_ALIGN_LEFT
;
527 m_AlignVer
= wxHTML_ALIGN_BOTTOM
;
528 m_IndentLeft
= m_IndentRight
= m_IndentTop
= m_IndentBottom
= 0;
529 m_WidthFloat
= 100; m_WidthFloatUnits
= wxHTML_UNITS_PERCENT
;
530 m_UseBkColour
= FALSE
;
533 m_MinHeightAlign
= wxHTML_ALIGN_TOP
;
537 wxHtmlContainerCell::~wxHtmlContainerCell()
539 wxHtmlCell
*cell
= m_Cells
;
542 wxHtmlCell
*cellNext
= cell
->GetNext();
550 void wxHtmlContainerCell::SetIndent(int i
, int what
, int units
)
552 int val
= (units
== wxHTML_UNITS_PIXELS
) ? i
: -i
;
553 if (what
& wxHTML_INDENT_LEFT
) m_IndentLeft
= val
;
554 if (what
& wxHTML_INDENT_RIGHT
) m_IndentRight
= val
;
555 if (what
& wxHTML_INDENT_TOP
) m_IndentTop
= val
;
556 if (what
& wxHTML_INDENT_BOTTOM
) m_IndentBottom
= val
;
562 int wxHtmlContainerCell::GetIndent(int ind
) const
564 if (ind
& wxHTML_INDENT_LEFT
) return m_IndentLeft
;
565 else if (ind
& wxHTML_INDENT_RIGHT
) return m_IndentRight
;
566 else if (ind
& wxHTML_INDENT_TOP
) return m_IndentTop
;
567 else if (ind
& wxHTML_INDENT_BOTTOM
) return m_IndentBottom
;
568 else return -1; /* BUG! Should not be called... */
574 int wxHtmlContainerCell::GetIndentUnits(int ind
) const
577 if (ind
& wxHTML_INDENT_LEFT
) p
= m_IndentLeft
< 0;
578 else if (ind
& wxHTML_INDENT_RIGHT
) p
= m_IndentRight
< 0;
579 else if (ind
& wxHTML_INDENT_TOP
) p
= m_IndentTop
< 0;
580 else if (ind
& wxHTML_INDENT_BOTTOM
) p
= m_IndentBottom
< 0;
581 if (p
) return wxHTML_UNITS_PERCENT
;
582 else return wxHTML_UNITS_PIXELS
;
587 bool wxHtmlContainerCell::AdjustPagebreak(int *pagebreak
, int* known_pagebreaks
, int number_of_pages
) const
589 if (!m_CanLiveOnPagebreak
)
590 return wxHtmlCell::AdjustPagebreak(pagebreak
, known_pagebreaks
, number_of_pages
);
594 wxHtmlCell
*c
= GetFirstChild();
596 int pbrk
= *pagebreak
- m_PosY
;
600 if (c
->AdjustPagebreak(&pbrk
, known_pagebreaks
, number_of_pages
))
605 *pagebreak
= pbrk
+ m_PosY
;
612 void wxHtmlContainerCell::Layout(int w
)
614 wxHtmlCell::Layout(w
);
616 if (m_LastLayout
== w
) return;
618 // VS: Any attempt to layout with negative or zero width leads to hell,
619 // but we can't ignore such attempts completely, since it sometimes
620 // happen (e.g. when trying how small a table can be). The best thing we
621 // can do is to set the width of child cells to zero
625 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
627 // this does two things: it recursively calls this code on all
628 // child contrainers and resets children's position to (0,0)
632 wxHtmlCell
*cell
= m_Cells
, *line
= m_Cells
;
633 wxHtmlCell
*nextCell
;
634 long xpos
= 0, ypos
= m_IndentTop
;
635 int xdelta
= 0, ybasicpos
= 0, ydiff
;
636 int s_width
, nextWordWidth
, s_indent
;
637 int ysizeup
= 0, ysizedown
= 0;
638 int MaxLineWidth
= 0;
648 if (m_WidthFloatUnits
== wxHTML_UNITS_PERCENT
)
650 if (m_WidthFloat
< 0) m_Width
= (100 + m_WidthFloat
) * w
/ 100;
651 else m_Width
= m_WidthFloat
* w
/ 100;
655 if (m_WidthFloat
< 0) m_Width
= w
+ m_WidthFloat
;
656 else m_Width
= m_WidthFloat
;
661 int l
= (m_IndentLeft
< 0) ? (-m_IndentLeft
* m_Width
/ 100) : m_IndentLeft
;
662 int r
= (m_IndentRight
< 0) ? (-m_IndentRight
* m_Width
/ 100) : m_IndentRight
;
663 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
664 cell
->Layout(m_Width
- (l
+ r
));
673 // adjust indentation:
674 s_indent
= (m_IndentLeft
< 0) ? (-m_IndentLeft
* m_Width
/ 100) : m_IndentLeft
;
675 s_width
= m_Width
- s_indent
- ((m_IndentRight
< 0) ? (-m_IndentRight
* m_Width
/ 100) : m_IndentRight
);
682 case wxHTML_ALIGN_TOP
: ybasicpos
= 0; break;
683 case wxHTML_ALIGN_BOTTOM
: ybasicpos
= - cell
->GetHeight(); break;
684 case wxHTML_ALIGN_CENTER
: ybasicpos
= - cell
->GetHeight() / 2; break;
686 ydiff
= cell
->GetHeight() + ybasicpos
;
688 if (cell
->GetDescent() + ydiff
> ysizedown
) ysizedown
= cell
->GetDescent() + ydiff
;
689 if (ybasicpos
+ cell
->GetDescent() < -ysizeup
) ysizeup
= - (ybasicpos
+ cell
->GetDescent());
691 // layout nonbreakable run of cells:
692 cell
->SetPos(xpos
, ybasicpos
+ cell
->GetDescent());
693 xpos
+= cell
->GetWidth();
694 cell
= cell
->GetNext();
697 // compute length of the next word that would be added:
704 nextWordWidth
+= nextCell
->GetWidth();
705 nextCell
= nextCell
->GetNext();
706 } while (nextCell
&& !nextCell
->IsLinebreakAllowed());
709 // force new line if occured:
710 if ((cell
== NULL
) ||
711 (xpos
+ nextWordWidth
> s_width
&& cell
->IsLinebreakAllowed()))
713 if (xpos
> MaxLineWidth
) MaxLineWidth
= xpos
;
714 if (ysizeup
< 0) ysizeup
= 0;
715 if (ysizedown
< 0) ysizedown
= 0;
716 switch (m_AlignHor
) {
717 case wxHTML_ALIGN_LEFT
:
718 case wxHTML_ALIGN_JUSTIFY
:
721 case wxHTML_ALIGN_RIGHT
:
722 xdelta
= 0 + (s_width
- xpos
);
724 case wxHTML_ALIGN_CENTER
:
725 xdelta
= 0 + (s_width
- xpos
) / 2;
728 if (xdelta
< 0) xdelta
= 0;
733 if (m_AlignHor
!= wxHTML_ALIGN_JUSTIFY
|| cell
== NULL
)
736 line
->SetPos(line
->GetPosX() + xdelta
,
737 ypos
+ line
->GetPosY());
738 line
= line
->GetNext();
743 int step
= (s_width
- xpos
);
744 if (step
< 0) step
= 0;
746 if (xcnt
> 0) while (line
!= cell
)
748 line
->SetPos(line
->GetPosX() + s_indent
+
749 (counter
++ * step
/ xcnt
),
750 ypos
+ line
->GetPosY());
751 line
= line
->GetNext();
758 ysizeup
= ysizedown
= 0;
763 // setup height & width, depending on container layout:
764 m_Height
= ypos
+ (ysizedown
+ ysizeup
) + m_IndentBottom
;
766 if (m_Height
< m_MinHeight
)
768 if (m_MinHeightAlign
!= wxHTML_ALIGN_TOP
)
770 int diff
= m_MinHeight
- m_Height
;
771 if (m_MinHeightAlign
== wxHTML_ALIGN_CENTER
) diff
/= 2;
775 cell
->SetPos(cell
->GetPosX(), cell
->GetPosY() + diff
);
776 cell
= cell
->GetNext();
779 m_Height
= m_MinHeight
;
782 MaxLineWidth
+= s_indent
+ ((m_IndentRight
< 0) ? (-m_IndentRight
* m_Width
/ 100) : m_IndentRight
);
783 if (m_Width
< MaxLineWidth
) m_Width
= MaxLineWidth
;
788 void wxHtmlContainerCell::UpdateRenderingStatePre(wxHtmlRenderingInfo
& info
,
789 wxHtmlCell
*cell
) const
791 wxHtmlSelection
*s
= info
.GetSelection();
793 if (s
->GetFromCell() == cell
|| s
->GetToCell() == cell
)
795 info
.GetState().SetSelectionState(wxHTML_SEL_CHANGING
);
799 void wxHtmlContainerCell::UpdateRenderingStatePost(wxHtmlRenderingInfo
& info
,
800 wxHtmlCell
*cell
) const
802 wxHtmlSelection
*s
= info
.GetSelection();
804 if (s
->GetToCell() == cell
)
805 info
.GetState().SetSelectionState(wxHTML_SEL_OUT
);
806 else if (s
->GetFromCell() == cell
)
807 info
.GetState().SetSelectionState(wxHTML_SEL_IN
);
810 #define mMin(a, b) (((a) < (b)) ? (a) : (b))
811 #define mMax(a, b) (((a) < (b)) ? (b) : (a))
813 void wxHtmlContainerCell::Draw(wxDC
& dc
, int x
, int y
, int view_y1
, int view_y2
,
814 wxHtmlRenderingInfo
& info
)
816 #if 0 // useful for debugging
817 dc
.SetPen(*wxRED_PEN
);
818 dc
.DrawRectangle(x
+m_PosX
,y
+m_PosY
,m_Width
,m_Height
);
820 // container visible, draw it:
821 if ((y
+ m_PosY
<= view_y2
) && (y
+ m_PosY
+ m_Height
> view_y1
))
825 wxBrush myb
= wxBrush(m_BkColour
, wxSOLID
);
827 int real_y1
= mMax(y
+ m_PosY
, view_y1
);
828 int real_y2
= mMin(y
+ m_PosY
+ m_Height
- 1, view_y2
);
831 dc
.SetPen(*wxTRANSPARENT_PEN
);
832 dc
.DrawRectangle(x
+ m_PosX
, real_y1
, m_Width
, real_y2
- real_y1
+ 1);
837 wxPen
mypen1(m_BorderColour1
, 1, wxSOLID
);
838 wxPen
mypen2(m_BorderColour2
, 1, wxSOLID
);
841 dc
.DrawLine(x
+ m_PosX
, y
+ m_PosY
, x
+ m_PosX
, y
+ m_PosY
+ m_Height
- 1);
842 dc
.DrawLine(x
+ m_PosX
, y
+ m_PosY
, x
+ m_PosX
+ m_Width
, y
+ m_PosY
);
844 dc
.DrawLine(x
+ m_PosX
+ m_Width
- 1, y
+ m_PosY
, x
+ m_PosX
+ m_Width
- 1, y
+ m_PosY
+ m_Height
- 1);
845 dc
.DrawLine(x
+ m_PosX
, y
+ m_PosY
+ m_Height
- 1, x
+ m_PosX
+ m_Width
, y
+ m_PosY
+ m_Height
- 1);
850 // draw container's contents:
851 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
853 UpdateRenderingStatePre(info
, cell
);
855 x
+ m_PosX
, y
+ m_PosY
, view_y1
, view_y2
,
857 UpdateRenderingStatePost(info
, cell
);
861 // container invisible, just proceed font+color changing:
864 DrawInvisible(dc
, x
, y
, info
);
870 void wxHtmlContainerCell::DrawInvisible(wxDC
& dc
, int x
, int y
,
871 wxHtmlRenderingInfo
& info
)
875 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
877 UpdateRenderingStatePre(info
, cell
);
878 cell
->DrawInvisible(dc
, x
+ m_PosX
, y
+ m_PosY
, info
);
879 UpdateRenderingStatePost(info
, cell
);
885 wxColour
wxHtmlContainerCell::GetBackgroundColour()
895 wxHtmlLinkInfo
*wxHtmlContainerCell::GetLink(int x
, int y
) const
897 wxHtmlCell
*cell
= FindCellByPos(x
, y
);
899 // VZ: I don't know if we should pass absolute or relative coords to
900 // wxHtmlCell::GetLink()? As the base class version just ignores them
901 // anyhow, it hardly matters right now but should still be clarified
902 return cell
? cell
->GetLink(x
, y
) : NULL
;
907 void wxHtmlContainerCell::InsertCell(wxHtmlCell
*f
)
909 if (!m_Cells
) m_Cells
= m_LastCell
= f
;
912 m_LastCell
->SetNext(f
);
914 if (m_LastCell
) while (m_LastCell
->GetNext()) m_LastCell
= m_LastCell
->GetNext();
922 void wxHtmlContainerCell::SetAlign(const wxHtmlTag
& tag
)
924 if (tag
.HasParam(wxT("ALIGN")))
926 wxString alg
= tag
.GetParam(wxT("ALIGN"));
928 if (alg
== wxT("CENTER"))
929 SetAlignHor(wxHTML_ALIGN_CENTER
);
930 else if (alg
== wxT("LEFT"))
931 SetAlignHor(wxHTML_ALIGN_LEFT
);
932 else if (alg
== wxT("JUSTIFY"))
933 SetAlignHor(wxHTML_ALIGN_JUSTIFY
);
934 else if (alg
== wxT("RIGHT"))
935 SetAlignHor(wxHTML_ALIGN_RIGHT
);
942 void wxHtmlContainerCell::SetWidthFloat(const wxHtmlTag
& tag
, double pixel_scale
)
944 if (tag
.HasParam(wxT("WIDTH")))
947 wxString wd
= tag
.GetParam(wxT("WIDTH"));
949 if (wd
[wd
.Length()-1] == wxT('%'))
951 wxSscanf(wd
.c_str(), wxT("%i%%"), &wdi
);
952 SetWidthFloat(wdi
, wxHTML_UNITS_PERCENT
);
956 wxSscanf(wd
.c_str(), wxT("%i"), &wdi
);
957 SetWidthFloat((int)(pixel_scale
* (double)wdi
), wxHTML_UNITS_PIXELS
);
965 const wxHtmlCell
* wxHtmlContainerCell::Find(int condition
, const void* param
) const
969 const wxHtmlCell
*r
= NULL
;
971 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
973 r
= cell
->Find(condition
, param
);
981 wxHtmlCell
*wxHtmlContainerCell::FindCellByPos(wxCoord x
, wxCoord y
,
982 unsigned flags
) const
984 if ( flags
& wxHTML_FIND_EXACT
)
986 for ( const wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext() )
988 int cx
= cell
->GetPosX(),
989 cy
= cell
->GetPosY();
991 if ( (cx
<= x
) && (cx
+ cell
->GetWidth() > x
) &&
992 (cy
<= y
) && (cy
+ cell
->GetHeight() > y
) )
994 return cell
->FindCellByPos(x
- cx
, y
- cy
, flags
);
998 else if ( flags
& wxHTML_FIND_NEAREST_AFTER
)
1001 for ( const wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext() )
1003 if ( cell
->IsFormattingCell() )
1005 int cellY
= cell
->GetPosY();
1006 if (!( y
< cellY
|| (y
< cellY
+ cell
->GetHeight() &&
1007 x
< cell
->GetPosX() + cell
->GetWidth()) ))
1010 c
= cell
->FindCellByPos(x
- cell
->GetPosX(), y
- cellY
, flags
);
1014 else if ( flags
& wxHTML_FIND_NEAREST_BEFORE
)
1016 wxHtmlCell
*c2
, *c
= NULL
;
1017 for ( const wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext() )
1019 if ( cell
->IsFormattingCell() )
1021 int cellY
= cell
->GetPosY();
1022 if (!( cellY
+ cell
->GetHeight() <= y
||
1023 (y
>= cellY
&& x
>= cell
->GetPosX()) ))
1025 c2
= cell
->FindCellByPos(x
- cell
->GetPosX(), y
- cellY
, flags
);
1036 void wxHtmlContainerCell::OnMouseClick(wxWindow
*parent
, int x
, int y
, const wxMouseEvent
& event
)
1038 wxHtmlCell
*cell
= FindCellByPos(x
, y
);
1040 cell
->OnMouseClick(parent
, x
, y
, event
);
1045 wxHtmlCell
*wxHtmlContainerCell::GetFirstTerminal() const
1050 for (wxHtmlCell
*c
= m_Cells
; c
; c
= c
->GetNext())
1052 c2
= c
->GetFirstTerminal();
1060 wxHtmlCell
*wxHtmlContainerCell::GetLastTerminal() const
1064 // most common case first:
1065 wxHtmlCell
*c
= m_LastCell
->GetLastTerminal();
1070 wxHtmlCell
*c2
= NULL
;
1071 for (c
= m_Cells
; c
; c
= c
->GetNext())
1073 ctmp
= c
->GetLastTerminal();
1084 static bool IsEmptyContainer(wxHtmlContainerCell
*cell
)
1086 for ( wxHtmlCell
*c
= cell
->GetFirstChild(); c
; c
= c
->GetNext() )
1088 if ( !c
->IsTerminalCell() || !c
->IsFormattingCell() )
1094 void wxHtmlContainerCell::RemoveExtraSpacing(bool top
, bool bottom
)
1097 SetIndent(0, wxHTML_INDENT_TOP
);
1099 SetIndent(0, wxHTML_INDENT_BOTTOM
);
1104 wxHtmlContainerCell
*cont
;
1107 for ( c
= m_Cells
; c
; c
= c
->GetNext() )
1109 if ( c
->IsTerminalCell() )
1111 if ( !c
->IsFormattingCell() )
1116 cont
= (wxHtmlContainerCell
*)c
;
1117 if ( IsEmptyContainer(cont
) )
1119 cont
->SetIndent(0, wxHTML_INDENT_VERTICAL
);
1123 cont
->RemoveExtraSpacing(true, false);
1133 for ( c
= m_Cells
; c
; c
= c
->GetNext() )
1136 for ( int i
= arr
.GetCount() - 1; i
>= 0; i
--)
1138 c
= (wxHtmlCell
*)arr
[i
];
1139 if ( c
->IsTerminalCell() )
1141 if ( !c
->IsFormattingCell() )
1146 cont
= (wxHtmlContainerCell
*)c
;
1147 if ( IsEmptyContainer(cont
) )
1149 cont
->SetIndent(0, wxHTML_INDENT_VERTICAL
); }
1152 cont
->RemoveExtraSpacing(false, true);
1164 // --------------------------------------------------------------------------
1166 // --------------------------------------------------------------------------
1168 void wxHtmlColourCell::Draw(wxDC
& dc
,
1170 int WXUNUSED(view_y1
), int WXUNUSED(view_y2
),
1171 wxHtmlRenderingInfo
& info
)
1173 DrawInvisible(dc
, x
, y
, info
);
1176 void wxHtmlColourCell::DrawInvisible(wxDC
& dc
,
1177 int WXUNUSED(x
), int WXUNUSED(y
),
1178 wxHtmlRenderingInfo
& info
)
1180 wxHtmlRenderingState
& state
= info
.GetState();
1181 if (m_Flags
& wxHTML_CLR_FOREGROUND
)
1183 state
.SetFgColour(m_Colour
);
1184 if (state
.GetSelectionState() != wxHTML_SEL_IN
)
1185 dc
.SetTextForeground(m_Colour
);
1187 dc
.SetTextForeground(
1188 info
.GetStyle().GetSelectedTextColour(m_Colour
));
1190 if (m_Flags
& wxHTML_CLR_BACKGROUND
)
1192 state
.SetBgColour(m_Colour
);
1193 if (state
.GetSelectionState() != wxHTML_SEL_IN
)
1195 dc
.SetTextBackground(m_Colour
);
1196 dc
.SetBackground(wxBrush(m_Colour
, wxSOLID
));
1200 wxColour c
= info
.GetStyle().GetSelectedTextBgColour(m_Colour
);
1201 dc
.SetTextBackground(c
);
1202 dc
.SetBackground(wxBrush(c
, wxSOLID
));
1210 // ---------------------------------------------------------------------------
1212 // ---------------------------------------------------------------------------
1214 void wxHtmlFontCell::Draw(wxDC
& dc
,
1215 int WXUNUSED(x
), int WXUNUSED(y
),
1216 int WXUNUSED(view_y1
), int WXUNUSED(view_y2
),
1217 wxHtmlRenderingInfo
& WXUNUSED(info
))
1222 void wxHtmlFontCell::DrawInvisible(wxDC
& dc
, int WXUNUSED(x
), int WXUNUSED(y
),
1223 wxHtmlRenderingInfo
& WXUNUSED(info
))
1235 // ---------------------------------------------------------------------------
1237 // ---------------------------------------------------------------------------
1239 wxHtmlWidgetCell::wxHtmlWidgetCell(wxWindow
*wnd
, int w
)
1243 m_Wnd
->GetSize(&sx
, &sy
);
1244 m_Width
= sx
, m_Height
= sy
;
1249 void wxHtmlWidgetCell::Draw(wxDC
& WXUNUSED(dc
),
1250 int WXUNUSED(x
), int WXUNUSED(y
),
1251 int WXUNUSED(view_y1
), int WXUNUSED(view_y2
),
1252 wxHtmlRenderingInfo
& WXUNUSED(info
))
1254 int absx
= 0, absy
= 0, stx
, sty
;
1255 wxHtmlCell
*c
= this;
1259 absx
+= c
->GetPosX();
1260 absy
+= c
->GetPosY();
1264 ((wxScrolledWindow
*)(m_Wnd
->GetParent()))->GetViewStart(&stx
, &sty
);
1265 m_Wnd
->SetSize(absx
- wxHTML_SCROLL_STEP
* stx
, absy
- wxHTML_SCROLL_STEP
* sty
, m_Width
, m_Height
);
1270 void wxHtmlWidgetCell::DrawInvisible(wxDC
& WXUNUSED(dc
),
1271 int WXUNUSED(x
), int WXUNUSED(y
),
1272 wxHtmlRenderingInfo
& WXUNUSED(info
))
1274 int absx
= 0, absy
= 0, stx
, sty
;
1275 wxHtmlCell
*c
= this;
1279 absx
+= c
->GetPosX();
1280 absy
+= c
->GetPosY();
1284 ((wxScrolledWindow
*)(m_Wnd
->GetParent()))->GetViewStart(&stx
, &sty
);
1285 m_Wnd
->SetSize(absx
- wxHTML_SCROLL_STEP
* stx
, absy
- wxHTML_SCROLL_STEP
* sty
, m_Width
, m_Height
);
1290 void wxHtmlWidgetCell::Layout(int w
)
1292 if (m_WidthFloat
!= 0)
1294 m_Width
= (w
* m_WidthFloat
) / 100;
1295 m_Wnd
->SetSize(m_Width
, m_Height
);
1298 wxHtmlCell::Layout(w
);
1303 // ----------------------------------------------------------------------------
1304 // wxHtmlTerminalCellsInterator
1305 // ----------------------------------------------------------------------------
1307 const wxHtmlCell
* wxHtmlTerminalCellsInterator::operator++()
1314 if ( m_pos
== m_to
)
1320 if ( m_pos
->GetNext() )
1321 m_pos
= m_pos
->GetNext();
1324 // we must go up the hierarchy until we reach container where this
1325 // is not the last child, and then go down to first terminal cell:
1326 while ( m_pos
->GetNext() == NULL
)
1328 m_pos
= m_pos
->GetParent();
1332 m_pos
= m_pos
->GetNext();
1334 while ( m_pos
->GetFirstChild() != NULL
)
1335 m_pos
= m_pos
->GetFirstChild();
1336 } while ( !m_pos
->IsTerminalCell() );
1347 //-----------------------------------------------------------------------------
1349 //-----------------------------------------------------------------------------
1351 class wxHtmlCellModule
: public wxModule
1353 DECLARE_DYNAMIC_CLASS(wxHtmlCellModule
)
1355 wxHtmlCellModule() : wxModule() {}
1356 bool OnInit() { return true; }
1359 wxDELETE(gs_cursorLink
);
1360 wxDELETE(gs_cursorText
);
1364 IMPLEMENT_DYNAMIC_CLASS(wxHtmlCellModule
, wxModule
)