1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxHtmlCell - basic element of HTML output
4 // Author: Vaclav Slavik
6 // Copyright: (c) 1999 Vaclav Slavik
7 // Licence: wxWindows Licence
8 /////////////////////////////////////////////////////////////////////////////
10 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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
);
72 wxDefaultHtmlRenderingStyle::
73 GetSelectedTextColour(const wxColour
& WXUNUSED(clr
))
75 return wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
79 wxDefaultHtmlRenderingStyle::
80 GetSelectedTextBgColour(const wxColour
& WXUNUSED(clr
))
82 return wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
);
86 //-----------------------------------------------------------------------------
88 //-----------------------------------------------------------------------------
90 wxHtmlCell::wxHtmlCell() : wxObject()
94 m_Width
= m_Height
= m_Descent
= 0;
95 m_CanLiveOnPagebreak
= TRUE
;
99 wxHtmlCell::~wxHtmlCell()
105 void wxHtmlCell::OnMouseClick(wxWindow
*parent
, int x
, int y
,
106 const wxMouseEvent
& event
)
108 wxHtmlLinkInfo
*lnk
= GetLink(x
, y
);
111 wxHtmlLinkInfo
lnk2(*lnk
);
112 lnk2
.SetEvent(&event
);
113 lnk2
.SetHtmlCell(this);
115 // note : this cast is legal because parent is *always* wxHtmlWindow
116 wxStaticCast(parent
, wxHtmlWindow
)->OnLinkClicked(lnk2
);
121 wxCursor
wxHtmlCell::GetCursor() const
125 if ( !gs_cursorLink
)
126 gs_cursorLink
= new wxCursor(wxCURSOR_HAND
);
127 return *gs_cursorLink
;
130 return *wxSTANDARD_CURSOR
;
134 bool wxHtmlCell::AdjustPagebreak(int *pagebreak
, int* WXUNUSED(known_pagebreaks
), int WXUNUSED(number_of_pages
)) const
136 if ((!m_CanLiveOnPagebreak
) &&
137 m_PosY
< *pagebreak
&& m_PosY
+ m_Height
> *pagebreak
)
148 void wxHtmlCell::SetLink(const wxHtmlLinkInfo
& link
)
150 if (m_Link
) delete m_Link
;
152 if (link
.GetHref() != wxEmptyString
)
153 m_Link
= new wxHtmlLinkInfo(link
);
157 void wxHtmlCell::Layout(int WXUNUSED(w
))
164 const wxHtmlCell
* wxHtmlCell::Find(int WXUNUSED(condition
), const void* WXUNUSED(param
)) const
170 wxHtmlCell
*wxHtmlCell::FindCellByPos(wxCoord x
, wxCoord y
,
171 unsigned flags
) const
173 if ( x
>= 0 && x
< m_Width
&& y
>= 0 && y
< m_Height
)
175 return wxConstCast(this, wxHtmlCell
);
179 if ((flags
& wxHTML_FIND_NEAREST_AFTER
) &&
180 (y
< 0 || (y
< 0+m_Height
&& x
< 0+m_Width
)))
181 return wxConstCast(this, wxHtmlCell
);
182 else if ((flags
& wxHTML_FIND_NEAREST_BEFORE
) &&
183 (y
>= 0+m_Height
|| (y
>= 0 && x
>= 0)))
184 return wxConstCast(this, wxHtmlCell
);
191 wxPoint
wxHtmlCell::GetAbsPos() const
193 wxPoint
p(m_PosX
, m_PosY
);
194 for (wxHtmlCell
*parent
= m_Parent
; parent
; parent
= parent
->m_Parent
)
196 p
.x
+= parent
->m_PosX
;
197 p
.y
+= parent
->m_PosY
;
202 unsigned wxHtmlCell::GetDepth() const
205 for (wxHtmlCell
*p
= m_Parent
; p
; p
= p
->m_Parent
)
210 bool wxHtmlCell::IsBefore(wxHtmlCell
*cell
) const
212 const wxHtmlCell
*c1
= this;
213 const wxHtmlCell
*c2
= cell
;
214 unsigned d1
= GetDepth();
215 unsigned d2
= cell
->GetDepth();
218 for (; d1
!= d2
; d1
-- )
221 for (; d1
!= d2
; d2
-- )
229 if ( c1
->m_Parent
== c2
->m_Parent
)
246 wxFAIL_MSG(_T("Cells are in different trees"));
251 //-----------------------------------------------------------------------------
253 //-----------------------------------------------------------------------------
255 wxHtmlWordCell::wxHtmlWordCell(const wxString
& word
, wxDC
& dc
) : wxHtmlCell()
258 dc
.GetTextExtent(m_Word
, &m_Width
, &m_Height
, &m_Descent
);
259 SetCanLiveOnPagebreak(FALSE
);
260 m_allowLinebreak
= true;
263 void wxHtmlWordCell::SetPreviousWord(wxHtmlWordCell
*cell
)
265 if ( cell
&& m_Parent
== cell
->m_Parent
&&
266 !wxIsspace(cell
->m_Word
.Last()) && !wxIsspace(m_Word
[0u]) )
268 m_allowLinebreak
= false;
272 // Splits m_Word into up to three parts according to selection, returns
273 // substring before, in and after selection and the points (in relative coords)
274 // where s2 and s3 start:
275 void wxHtmlWordCell::Split(wxDC
& dc
,
276 const wxPoint
& selFrom
, const wxPoint
& selTo
,
277 unsigned& pos1
, unsigned& pos2
) const
279 wxPoint pt1
= (selFrom
== wxDefaultPosition
) ?
280 wxDefaultPosition
: selFrom
- GetAbsPos();
281 wxPoint pt2
= (selTo
== wxDefaultPosition
) ?
282 wxPoint(m_Width
, -1) : selTo
- GetAbsPos();
284 wxCoord charW
, charH
;
285 unsigned len
= m_Word
.length();
289 // adjust for cases when the start/end position is completely
293 if ( pt2
.y
>= m_Height
)
297 while ( pt1
.x
> 0 && i
< len
)
299 dc
.GetTextExtent(m_Word
[i
], &charW
, &charH
);
312 while ( pt2
.x
> 0 && j
< len
)
314 dc
.GetTextExtent(m_Word
[j
], &charW
, &charH
);
327 void wxHtmlWordCell::SetSelectionPrivPos(wxDC
& dc
, wxHtmlSelection
*s
) const
332 this == s
->GetFromCell() ? s
->GetFromPos() : wxDefaultPosition
,
333 this == s
->GetToCell() ? s
->GetToPos() : wxDefaultPosition
,
336 wxPoint
p(0, m_Word
.length());
338 if ( this == s
->GetFromCell() )
339 p
.x
= p1
; // selection starts here
340 if ( this == s
->GetToCell() )
341 p
.y
= p2
; // selection ends here
343 if ( this == s
->GetFromCell() )
344 s
->SetFromPrivPos(p
);
345 if ( this == s
->GetToCell() )
350 static void SwitchSelState(wxDC
& dc
, wxHtmlRenderingInfo
& info
,
353 wxColour fg
= info
.GetState().GetFgColour();
354 wxColour bg
= info
.GetState().GetBgColour();
358 dc
.SetBackgroundMode(wxSOLID
);
359 dc
.SetTextForeground(info
.GetStyle().GetSelectedTextColour(fg
));
360 dc
.SetTextBackground(info
.GetStyle().GetSelectedTextBgColour(bg
));
361 dc
.SetBackground(wxBrush(info
.GetStyle().GetSelectedTextBgColour(bg
),
366 dc
.SetBackgroundMode(wxTRANSPARENT
);
367 dc
.SetTextForeground(fg
);
368 dc
.SetTextBackground(bg
);
369 dc
.SetBackground(wxBrush(bg
, wxSOLID
));
374 void wxHtmlWordCell::Draw(wxDC
& dc
, int x
, int y
,
375 int WXUNUSED(view_y1
), int WXUNUSED(view_y2
),
376 wxHtmlRenderingInfo
& info
)
378 #if 0 // useful for debugging
379 dc
.SetPen(*wxBLACK_PEN
);
380 dc
.DrawRectangle(x
+m_PosX
,y
+m_PosY
,m_Width
,m_Height
);
383 bool drawSelectionAfterCell
= false;
385 if ( info
.GetState().GetSelectionState() == wxHTML_SEL_CHANGING
)
387 // Selection changing, we must draw the word piecewise:
388 wxHtmlSelection
*s
= info
.GetSelection();
393 wxPoint priv
= (this == s
->GetFromCell()) ?
394 s
->GetFromPrivPos() : s
->GetToPrivPos();
396 // NB: this is quite a hack: in order to compute selection boundaries
397 // (in word's characters) we must know current font, which is only
398 // possible inside rendering code. Therefore we update the
399 // information here and store it in wxHtmlSelection so that
400 // ConvertToText can use it later:
401 if ( priv
== wxDefaultPosition
)
403 SetSelectionPrivPos(dc
, s
);
404 priv
= (this == s
->GetFromCell()) ?
405 s
->GetFromPrivPos() : s
->GetToPrivPos();
413 txt
= m_Word
.Mid(0, part1
);
414 dc
.DrawText(txt
, x
+ m_PosX
, y
+ m_PosY
);
415 dc
.GetTextExtent(txt
, &w
, &h
);
419 SwitchSelState(dc
, info
, true);
421 txt
= m_Word
.Mid(part1
, part2
-part1
);
422 dc
.DrawText(txt
, ofs
+ x
+ m_PosX
, y
+ m_PosY
);
424 if ( (size_t)part2
< m_Word
.length() )
426 dc
.GetTextExtent(txt
, &w
, &h
);
428 SwitchSelState(dc
, info
, false);
429 txt
= m_Word
.Mid(part2
);
430 dc
.DrawText(txt
, ofs
+ x
+ m_PosX
, y
+ m_PosY
);
433 drawSelectionAfterCell
= true;
437 wxHtmlSelectionState selstate
= info
.GetState().GetSelectionState();
438 // Not changing selection state, draw the word in single mode:
439 if ( selstate
!= wxHTML_SEL_OUT
&&
440 dc
.GetBackgroundMode() != wxSOLID
)
442 SwitchSelState(dc
, info
, true);
444 else if ( selstate
== wxHTML_SEL_OUT
&&
445 dc
.GetBackgroundMode() == wxSOLID
)
447 SwitchSelState(dc
, info
, false);
449 dc
.DrawText(m_Word
, x
+ m_PosX
, y
+ m_PosY
);
450 drawSelectionAfterCell
= (selstate
!= wxHTML_SEL_OUT
);
453 // NB: If the text is justified then there is usually some free space
454 // between adjacent cells and drawing the selection only onto cells
455 // would result in ugly unselected spaces. The code below detects
456 // this special case and renders the selection *outside* the sell,
458 if ( m_Parent
->GetAlignHor() == wxHTML_ALIGN_JUSTIFY
&&
459 drawSelectionAfterCell
)
461 wxHtmlCell
*nextCell
= m_Next
;
462 while ( nextCell
&& nextCell
->IsFormattingCell() )
463 nextCell
= nextCell
->GetNext();
466 int nextX
= nextCell
->GetPosX();
467 if ( m_PosX
+ m_Width
< nextX
)
469 dc
.SetBrush(dc
.GetBackground());
470 dc
.SetPen(*wxTRANSPARENT_PEN
);
471 dc
.DrawRectangle(x
+ m_PosX
+ m_Width
, y
+ m_PosY
,
472 nextX
- m_PosX
- m_Width
, m_Height
);
479 wxString
wxHtmlWordCell::ConvertToText(wxHtmlSelection
*s
) const
481 if ( s
&& (this == s
->GetFromCell() || this == s
->GetToCell()) )
483 wxPoint priv
= this == s
->GetFromCell() ? s
->GetFromPrivPos()
486 // VZ: we may be called before we had a chance to re-render ourselves
487 // and in this case GetFrom/ToPrivPos() is not set yet -- assume
488 // that this only happens in case of a double/triple click (which
489 // seems to be the case now) and so it makes sense to select the
490 // entire contents of the cell in this case
492 // TODO: but this really needs to be fixed in some better way later...
493 if ( priv
!= wxDefaultPosition
)
497 return m_Word
.Mid(part1
, part2
-part1
);
499 //else: return the whole word below
505 wxCursor
wxHtmlWordCell::GetCursor() const
509 if ( !gs_cursorText
)
510 gs_cursorText
= new wxCursor(wxCURSOR_IBEAM
);
511 return *gs_cursorText
;
514 return wxHtmlCell::GetCursor();
518 //-----------------------------------------------------------------------------
519 // wxHtmlContainerCell
520 //-----------------------------------------------------------------------------
523 wxHtmlContainerCell::wxHtmlContainerCell(wxHtmlContainerCell
*parent
) : wxHtmlCell()
525 m_Cells
= m_LastCell
= NULL
;
527 if (m_Parent
) m_Parent
->InsertCell(this);
528 m_AlignHor
= wxHTML_ALIGN_LEFT
;
529 m_AlignVer
= wxHTML_ALIGN_BOTTOM
;
530 m_IndentLeft
= m_IndentRight
= m_IndentTop
= m_IndentBottom
= 0;
531 m_WidthFloat
= 100; m_WidthFloatUnits
= wxHTML_UNITS_PERCENT
;
532 m_UseBkColour
= FALSE
;
535 m_MinHeightAlign
= wxHTML_ALIGN_TOP
;
539 wxHtmlContainerCell::~wxHtmlContainerCell()
541 wxHtmlCell
*cell
= m_Cells
;
544 wxHtmlCell
*cellNext
= cell
->GetNext();
552 void wxHtmlContainerCell::SetIndent(int i
, int what
, int units
)
554 int val
= (units
== wxHTML_UNITS_PIXELS
) ? i
: -i
;
555 if (what
& wxHTML_INDENT_LEFT
) m_IndentLeft
= val
;
556 if (what
& wxHTML_INDENT_RIGHT
) m_IndentRight
= val
;
557 if (what
& wxHTML_INDENT_TOP
) m_IndentTop
= val
;
558 if (what
& wxHTML_INDENT_BOTTOM
) m_IndentBottom
= val
;
564 int wxHtmlContainerCell::GetIndent(int ind
) const
566 if (ind
& wxHTML_INDENT_LEFT
) return m_IndentLeft
;
567 else if (ind
& wxHTML_INDENT_RIGHT
) return m_IndentRight
;
568 else if (ind
& wxHTML_INDENT_TOP
) return m_IndentTop
;
569 else if (ind
& wxHTML_INDENT_BOTTOM
) return m_IndentBottom
;
570 else return -1; /* BUG! Should not be called... */
576 int wxHtmlContainerCell::GetIndentUnits(int ind
) const
579 if (ind
& wxHTML_INDENT_LEFT
) p
= m_IndentLeft
< 0;
580 else if (ind
& wxHTML_INDENT_RIGHT
) p
= m_IndentRight
< 0;
581 else if (ind
& wxHTML_INDENT_TOP
) p
= m_IndentTop
< 0;
582 else if (ind
& wxHTML_INDENT_BOTTOM
) p
= m_IndentBottom
< 0;
583 if (p
) return wxHTML_UNITS_PERCENT
;
584 else return wxHTML_UNITS_PIXELS
;
589 bool wxHtmlContainerCell::AdjustPagebreak(int *pagebreak
, int* known_pagebreaks
, int number_of_pages
) const
591 if (!m_CanLiveOnPagebreak
)
592 return wxHtmlCell::AdjustPagebreak(pagebreak
, known_pagebreaks
, number_of_pages
);
596 wxHtmlCell
*c
= GetFirstChild();
598 int pbrk
= *pagebreak
- m_PosY
;
602 if (c
->AdjustPagebreak(&pbrk
, known_pagebreaks
, number_of_pages
))
607 *pagebreak
= pbrk
+ m_PosY
;
614 void wxHtmlContainerCell::Layout(int w
)
616 wxHtmlCell::Layout(w
);
618 if (m_LastLayout
== w
) return;
620 // VS: Any attempt to layout with negative or zero width leads to hell,
621 // but we can't ignore such attempts completely, since it sometimes
622 // happen (e.g. when trying how small a table can be). The best thing we
623 // can do is to set the width of child cells to zero
627 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
629 // this does two things: it recursively calls this code on all
630 // child contrainers and resets children's position to (0,0)
634 wxHtmlCell
*cell
= m_Cells
, *line
= m_Cells
;
635 wxHtmlCell
*nextCell
;
636 long xpos
= 0, ypos
= m_IndentTop
;
637 int xdelta
= 0, ybasicpos
= 0, ydiff
;
638 int s_width
, nextWordWidth
, s_indent
;
639 int ysizeup
= 0, ysizedown
= 0;
640 int MaxLineWidth
= 0;
650 if (m_WidthFloatUnits
== wxHTML_UNITS_PERCENT
)
652 if (m_WidthFloat
< 0) m_Width
= (100 + m_WidthFloat
) * w
/ 100;
653 else m_Width
= m_WidthFloat
* w
/ 100;
657 if (m_WidthFloat
< 0) m_Width
= w
+ m_WidthFloat
;
658 else m_Width
= m_WidthFloat
;
663 int l
= (m_IndentLeft
< 0) ? (-m_IndentLeft
* m_Width
/ 100) : m_IndentLeft
;
664 int r
= (m_IndentRight
< 0) ? (-m_IndentRight
* m_Width
/ 100) : m_IndentRight
;
665 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
666 cell
->Layout(m_Width
- (l
+ r
));
675 // adjust indentation:
676 s_indent
= (m_IndentLeft
< 0) ? (-m_IndentLeft
* m_Width
/ 100) : m_IndentLeft
;
677 s_width
= m_Width
- s_indent
- ((m_IndentRight
< 0) ? (-m_IndentRight
* m_Width
/ 100) : m_IndentRight
);
684 case wxHTML_ALIGN_TOP
: ybasicpos
= 0; break;
685 case wxHTML_ALIGN_BOTTOM
: ybasicpos
= - cell
->GetHeight(); break;
686 case wxHTML_ALIGN_CENTER
: ybasicpos
= - cell
->GetHeight() / 2; break;
688 ydiff
= cell
->GetHeight() + ybasicpos
;
690 if (cell
->GetDescent() + ydiff
> ysizedown
) ysizedown
= cell
->GetDescent() + ydiff
;
691 if (ybasicpos
+ cell
->GetDescent() < -ysizeup
) ysizeup
= - (ybasicpos
+ cell
->GetDescent());
693 // layout nonbreakable run of cells:
694 cell
->SetPos(xpos
, ybasicpos
+ cell
->GetDescent());
695 xpos
+= cell
->GetWidth();
696 cell
= cell
->GetNext();
699 // compute length of the next word that would be added:
706 nextWordWidth
+= nextCell
->GetWidth();
707 nextCell
= nextCell
->GetNext();
708 } while (nextCell
&& !nextCell
->IsLinebreakAllowed());
711 // force new line if occured:
712 if ((cell
== NULL
) ||
713 (xpos
+ nextWordWidth
> s_width
&& cell
->IsLinebreakAllowed()))
715 if (xpos
> MaxLineWidth
) MaxLineWidth
= xpos
;
716 if (ysizeup
< 0) ysizeup
= 0;
717 if (ysizedown
< 0) ysizedown
= 0;
718 switch (m_AlignHor
) {
719 case wxHTML_ALIGN_LEFT
:
720 case wxHTML_ALIGN_JUSTIFY
:
723 case wxHTML_ALIGN_RIGHT
:
724 xdelta
= 0 + (s_width
- xpos
);
726 case wxHTML_ALIGN_CENTER
:
727 xdelta
= 0 + (s_width
- xpos
) / 2;
730 if (xdelta
< 0) xdelta
= 0;
735 if (m_AlignHor
!= wxHTML_ALIGN_JUSTIFY
|| cell
== NULL
)
738 line
->SetPos(line
->GetPosX() + xdelta
,
739 ypos
+ line
->GetPosY());
740 line
= line
->GetNext();
745 int step
= (s_width
- xpos
);
746 if (step
< 0) step
= 0;
748 if (xcnt
> 0) while (line
!= cell
)
750 line
->SetPos(line
->GetPosX() + s_indent
+
751 (counter
++ * step
/ xcnt
),
752 ypos
+ line
->GetPosY());
753 line
= line
->GetNext();
760 ysizeup
= ysizedown
= 0;
765 // setup height & width, depending on container layout:
766 m_Height
= ypos
+ (ysizedown
+ ysizeup
) + m_IndentBottom
;
768 if (m_Height
< m_MinHeight
)
770 if (m_MinHeightAlign
!= wxHTML_ALIGN_TOP
)
772 int diff
= m_MinHeight
- m_Height
;
773 if (m_MinHeightAlign
== wxHTML_ALIGN_CENTER
) diff
/= 2;
777 cell
->SetPos(cell
->GetPosX(), cell
->GetPosY() + diff
);
778 cell
= cell
->GetNext();
781 m_Height
= m_MinHeight
;
784 MaxLineWidth
+= s_indent
+ ((m_IndentRight
< 0) ? (-m_IndentRight
* m_Width
/ 100) : m_IndentRight
);
785 if (m_Width
< MaxLineWidth
) m_Width
= MaxLineWidth
;
790 void wxHtmlContainerCell::UpdateRenderingStatePre(wxHtmlRenderingInfo
& info
,
791 wxHtmlCell
*cell
) const
793 wxHtmlSelection
*s
= info
.GetSelection();
795 if (s
->GetFromCell() == cell
|| s
->GetToCell() == cell
)
797 info
.GetState().SetSelectionState(wxHTML_SEL_CHANGING
);
801 void wxHtmlContainerCell::UpdateRenderingStatePost(wxHtmlRenderingInfo
& info
,
802 wxHtmlCell
*cell
) const
804 wxHtmlSelection
*s
= info
.GetSelection();
806 if (s
->GetToCell() == cell
)
807 info
.GetState().SetSelectionState(wxHTML_SEL_OUT
);
808 else if (s
->GetFromCell() == cell
)
809 info
.GetState().SetSelectionState(wxHTML_SEL_IN
);
812 #define mMin(a, b) (((a) < (b)) ? (a) : (b))
813 #define mMax(a, b) (((a) < (b)) ? (b) : (a))
815 void wxHtmlContainerCell::Draw(wxDC
& dc
, int x
, int y
, int view_y1
, int view_y2
,
816 wxHtmlRenderingInfo
& info
)
818 #if 0 // useful for debugging
819 dc
.SetPen(*wxRED_PEN
);
820 dc
.DrawRectangle(x
+m_PosX
,y
+m_PosY
,m_Width
,m_Height
);
822 // container visible, draw it:
823 if ((y
+ m_PosY
<= view_y2
) && (y
+ m_PosY
+ m_Height
> view_y1
))
827 wxBrush myb
= wxBrush(m_BkColour
, wxSOLID
);
829 int real_y1
= mMax(y
+ m_PosY
, view_y1
);
830 int real_y2
= mMin(y
+ m_PosY
+ m_Height
- 1, view_y2
);
833 dc
.SetPen(*wxTRANSPARENT_PEN
);
834 dc
.DrawRectangle(x
+ m_PosX
, real_y1
, m_Width
, real_y2
- real_y1
+ 1);
839 wxPen
mypen1(m_BorderColour1
, 1, wxSOLID
);
840 wxPen
mypen2(m_BorderColour2
, 1, wxSOLID
);
843 dc
.DrawLine(x
+ m_PosX
, y
+ m_PosY
, x
+ m_PosX
, y
+ m_PosY
+ m_Height
- 1);
844 dc
.DrawLine(x
+ m_PosX
, y
+ m_PosY
, x
+ m_PosX
+ m_Width
, y
+ m_PosY
);
846 dc
.DrawLine(x
+ m_PosX
+ m_Width
- 1, y
+ m_PosY
, x
+ m_PosX
+ m_Width
- 1, y
+ m_PosY
+ m_Height
- 1);
847 dc
.DrawLine(x
+ m_PosX
, y
+ m_PosY
+ m_Height
- 1, x
+ m_PosX
+ m_Width
, y
+ m_PosY
+ m_Height
- 1);
852 // draw container's contents:
853 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
855 UpdateRenderingStatePre(info
, cell
);
857 x
+ m_PosX
, y
+ m_PosY
, view_y1
, view_y2
,
859 UpdateRenderingStatePost(info
, cell
);
863 // container invisible, just proceed font+color changing:
866 DrawInvisible(dc
, x
, y
, info
);
872 void wxHtmlContainerCell::DrawInvisible(wxDC
& dc
, int x
, int y
,
873 wxHtmlRenderingInfo
& info
)
877 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
879 UpdateRenderingStatePre(info
, cell
);
880 cell
->DrawInvisible(dc
, x
+ m_PosX
, y
+ m_PosY
, info
);
881 UpdateRenderingStatePost(info
, cell
);
887 wxColour
wxHtmlContainerCell::GetBackgroundColour()
897 wxHtmlLinkInfo
*wxHtmlContainerCell::GetLink(int x
, int y
) const
899 wxHtmlCell
*cell
= FindCellByPos(x
, y
);
901 // VZ: I don't know if we should pass absolute or relative coords to
902 // wxHtmlCell::GetLink()? As the base class version just ignores them
903 // anyhow, it hardly matters right now but should still be clarified
904 return cell
? cell
->GetLink(x
, y
) : NULL
;
909 void wxHtmlContainerCell::InsertCell(wxHtmlCell
*f
)
911 if (!m_Cells
) m_Cells
= m_LastCell
= f
;
914 m_LastCell
->SetNext(f
);
916 if (m_LastCell
) while (m_LastCell
->GetNext()) m_LastCell
= m_LastCell
->GetNext();
924 void wxHtmlContainerCell::SetAlign(const wxHtmlTag
& tag
)
926 if (tag
.HasParam(wxT("ALIGN")))
928 wxString alg
= tag
.GetParam(wxT("ALIGN"));
930 if (alg
== wxT("CENTER"))
931 SetAlignHor(wxHTML_ALIGN_CENTER
);
932 else if (alg
== wxT("LEFT"))
933 SetAlignHor(wxHTML_ALIGN_LEFT
);
934 else if (alg
== wxT("JUSTIFY"))
935 SetAlignHor(wxHTML_ALIGN_JUSTIFY
);
936 else if (alg
== wxT("RIGHT"))
937 SetAlignHor(wxHTML_ALIGN_RIGHT
);
944 void wxHtmlContainerCell::SetWidthFloat(const wxHtmlTag
& tag
, double pixel_scale
)
946 if (tag
.HasParam(wxT("WIDTH")))
949 wxString wd
= tag
.GetParam(wxT("WIDTH"));
951 if (wd
[wd
.Length()-1] == wxT('%'))
953 wxSscanf(wd
.c_str(), wxT("%i%%"), &wdi
);
954 SetWidthFloat(wdi
, wxHTML_UNITS_PERCENT
);
958 wxSscanf(wd
.c_str(), wxT("%i"), &wdi
);
959 SetWidthFloat((int)(pixel_scale
* (double)wdi
), wxHTML_UNITS_PIXELS
);
967 const wxHtmlCell
* wxHtmlContainerCell::Find(int condition
, const void* param
) const
971 const wxHtmlCell
*r
= NULL
;
973 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
975 r
= cell
->Find(condition
, param
);
983 wxHtmlCell
*wxHtmlContainerCell::FindCellByPos(wxCoord x
, wxCoord y
,
984 unsigned flags
) const
986 if ( flags
& wxHTML_FIND_EXACT
)
988 for ( const wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext() )
990 int cx
= cell
->GetPosX(),
991 cy
= cell
->GetPosY();
993 if ( (cx
<= x
) && (cx
+ cell
->GetWidth() > x
) &&
994 (cy
<= y
) && (cy
+ cell
->GetHeight() > y
) )
996 return cell
->FindCellByPos(x
- cx
, y
- cy
, flags
);
1000 else if ( flags
& wxHTML_FIND_NEAREST_AFTER
)
1003 for ( const wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext() )
1005 if ( cell
->IsFormattingCell() )
1007 int cellY
= cell
->GetPosY();
1008 if (!( y
< cellY
|| (y
< cellY
+ cell
->GetHeight() &&
1009 x
< cell
->GetPosX() + cell
->GetWidth()) ))
1012 c
= cell
->FindCellByPos(x
- cell
->GetPosX(), y
- cellY
, flags
);
1016 else if ( flags
& wxHTML_FIND_NEAREST_BEFORE
)
1018 wxHtmlCell
*c2
, *c
= NULL
;
1019 for ( const wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext() )
1021 if ( cell
->IsFormattingCell() )
1023 int cellY
= cell
->GetPosY();
1024 if (!( cellY
+ cell
->GetHeight() <= y
||
1025 (y
>= cellY
&& x
>= cell
->GetPosX()) ))
1027 c2
= cell
->FindCellByPos(x
- cell
->GetPosX(), y
- cellY
, flags
);
1038 void wxHtmlContainerCell::OnMouseClick(wxWindow
*parent
, int x
, int y
, const wxMouseEvent
& event
)
1040 wxHtmlCell
*cell
= FindCellByPos(x
, y
);
1042 cell
->OnMouseClick(parent
, x
, y
, event
);
1047 wxHtmlCell
*wxHtmlContainerCell::GetFirstTerminal() const
1052 for (wxHtmlCell
*c
= m_Cells
; c
; c
= c
->GetNext())
1054 c2
= c
->GetFirstTerminal();
1062 wxHtmlCell
*wxHtmlContainerCell::GetLastTerminal() const
1066 // most common case first:
1067 wxHtmlCell
*c
= m_LastCell
->GetLastTerminal();
1072 wxHtmlCell
*c2
= NULL
;
1073 for (c
= m_Cells
; c
; c
= c
->GetNext())
1075 ctmp
= c
->GetLastTerminal();
1086 static bool IsEmptyContainer(wxHtmlContainerCell
*cell
)
1088 for ( wxHtmlCell
*c
= cell
->GetFirstChild(); c
; c
= c
->GetNext() )
1090 if ( !c
->IsTerminalCell() || !c
->IsFormattingCell() )
1096 void wxHtmlContainerCell::RemoveExtraSpacing(bool top
, bool bottom
)
1099 SetIndent(0, wxHTML_INDENT_TOP
);
1101 SetIndent(0, wxHTML_INDENT_BOTTOM
);
1106 wxHtmlContainerCell
*cont
;
1109 for ( c
= m_Cells
; c
; c
= c
->GetNext() )
1111 if ( c
->IsTerminalCell() )
1113 if ( !c
->IsFormattingCell() )
1118 cont
= (wxHtmlContainerCell
*)c
;
1119 if ( IsEmptyContainer(cont
) )
1121 cont
->SetIndent(0, wxHTML_INDENT_VERTICAL
);
1125 cont
->RemoveExtraSpacing(true, false);
1135 for ( c
= m_Cells
; c
; c
= c
->GetNext() )
1138 for ( int i
= arr
.GetCount() - 1; i
>= 0; i
--)
1140 c
= (wxHtmlCell
*)arr
[i
];
1141 if ( c
->IsTerminalCell() )
1143 if ( !c
->IsFormattingCell() )
1148 cont
= (wxHtmlContainerCell
*)c
;
1149 if ( IsEmptyContainer(cont
) )
1151 cont
->SetIndent(0, wxHTML_INDENT_VERTICAL
); }
1154 cont
->RemoveExtraSpacing(false, true);
1166 // --------------------------------------------------------------------------
1168 // --------------------------------------------------------------------------
1170 void wxHtmlColourCell::Draw(wxDC
& dc
,
1172 int WXUNUSED(view_y1
), int WXUNUSED(view_y2
),
1173 wxHtmlRenderingInfo
& info
)
1175 DrawInvisible(dc
, x
, y
, info
);
1178 void wxHtmlColourCell::DrawInvisible(wxDC
& dc
,
1179 int WXUNUSED(x
), int WXUNUSED(y
),
1180 wxHtmlRenderingInfo
& info
)
1182 wxHtmlRenderingState
& state
= info
.GetState();
1183 if (m_Flags
& wxHTML_CLR_FOREGROUND
)
1185 state
.SetFgColour(m_Colour
);
1186 if (state
.GetSelectionState() != wxHTML_SEL_IN
)
1187 dc
.SetTextForeground(m_Colour
);
1189 dc
.SetTextForeground(
1190 info
.GetStyle().GetSelectedTextColour(m_Colour
));
1192 if (m_Flags
& wxHTML_CLR_BACKGROUND
)
1194 state
.SetBgColour(m_Colour
);
1195 if (state
.GetSelectionState() != wxHTML_SEL_IN
)
1197 dc
.SetTextBackground(m_Colour
);
1198 dc
.SetBackground(wxBrush(m_Colour
, wxSOLID
));
1202 wxColour c
= info
.GetStyle().GetSelectedTextBgColour(m_Colour
);
1203 dc
.SetTextBackground(c
);
1204 dc
.SetBackground(wxBrush(c
, wxSOLID
));
1212 // ---------------------------------------------------------------------------
1214 // ---------------------------------------------------------------------------
1216 void wxHtmlFontCell::Draw(wxDC
& dc
,
1217 int WXUNUSED(x
), int WXUNUSED(y
),
1218 int WXUNUSED(view_y1
), int WXUNUSED(view_y2
),
1219 wxHtmlRenderingInfo
& WXUNUSED(info
))
1224 void wxHtmlFontCell::DrawInvisible(wxDC
& dc
, int WXUNUSED(x
), int WXUNUSED(y
),
1225 wxHtmlRenderingInfo
& WXUNUSED(info
))
1237 // ---------------------------------------------------------------------------
1239 // ---------------------------------------------------------------------------
1241 wxHtmlWidgetCell::wxHtmlWidgetCell(wxWindow
*wnd
, int w
)
1245 m_Wnd
->GetSize(&sx
, &sy
);
1246 m_Width
= sx
, m_Height
= sy
;
1251 void wxHtmlWidgetCell::Draw(wxDC
& WXUNUSED(dc
),
1252 int WXUNUSED(x
), int WXUNUSED(y
),
1253 int WXUNUSED(view_y1
), int WXUNUSED(view_y2
),
1254 wxHtmlRenderingInfo
& WXUNUSED(info
))
1256 int absx
= 0, absy
= 0, stx
, sty
;
1257 wxHtmlCell
*c
= this;
1261 absx
+= c
->GetPosX();
1262 absy
+= c
->GetPosY();
1266 ((wxScrolledWindow
*)(m_Wnd
->GetParent()))->GetViewStart(&stx
, &sty
);
1267 m_Wnd
->SetSize(absx
- wxHTML_SCROLL_STEP
* stx
, absy
- wxHTML_SCROLL_STEP
* sty
, m_Width
, m_Height
);
1272 void wxHtmlWidgetCell::DrawInvisible(wxDC
& WXUNUSED(dc
),
1273 int WXUNUSED(x
), int WXUNUSED(y
),
1274 wxHtmlRenderingInfo
& WXUNUSED(info
))
1276 int absx
= 0, absy
= 0, stx
, sty
;
1277 wxHtmlCell
*c
= this;
1281 absx
+= c
->GetPosX();
1282 absy
+= c
->GetPosY();
1286 ((wxScrolledWindow
*)(m_Wnd
->GetParent()))->GetViewStart(&stx
, &sty
);
1287 m_Wnd
->SetSize(absx
- wxHTML_SCROLL_STEP
* stx
, absy
- wxHTML_SCROLL_STEP
* sty
, m_Width
, m_Height
);
1292 void wxHtmlWidgetCell::Layout(int w
)
1294 if (m_WidthFloat
!= 0)
1296 m_Width
= (w
* m_WidthFloat
) / 100;
1297 m_Wnd
->SetSize(m_Width
, m_Height
);
1300 wxHtmlCell::Layout(w
);
1305 // ----------------------------------------------------------------------------
1306 // wxHtmlTerminalCellsInterator
1307 // ----------------------------------------------------------------------------
1309 const wxHtmlCell
* wxHtmlTerminalCellsInterator::operator++()
1316 if ( m_pos
== m_to
)
1322 if ( m_pos
->GetNext() )
1323 m_pos
= m_pos
->GetNext();
1326 // we must go up the hierarchy until we reach container where this
1327 // is not the last child, and then go down to first terminal cell:
1328 while ( m_pos
->GetNext() == NULL
)
1330 m_pos
= m_pos
->GetParent();
1334 m_pos
= m_pos
->GetNext();
1336 while ( m_pos
->GetFirstChild() != NULL
)
1337 m_pos
= m_pos
->GetFirstChild();
1338 } while ( !m_pos
->IsTerminalCell() );
1349 //-----------------------------------------------------------------------------
1351 //-----------------------------------------------------------------------------
1353 class wxHtmlCellModule
: public wxModule
1355 DECLARE_DYNAMIC_CLASS(wxHtmlCellModule
)
1357 wxHtmlCellModule() : wxModule() {}
1358 bool OnInit() { return true; }
1361 wxDELETE(gs_cursorLink
);
1362 wxDELETE(gs_cursorText
);
1366 IMPLEMENT_DYNAMIC_CLASS(wxHtmlCellModule
, wxModule
)