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"
37 //-----------------------------------------------------------------------------
39 //-----------------------------------------------------------------------------
41 static wxCursor
*gs_cursorLink
= NULL
;
42 static wxCursor
*gs_cursorText
= NULL
;
45 //-----------------------------------------------------------------------------
47 //-----------------------------------------------------------------------------
49 void wxHtmlSelection::Set(const wxPoint
& fromPos
, const wxHtmlCell
*fromCell
,
50 const wxPoint
& toPos
, const wxHtmlCell
*toCell
)
52 m_fromCell
= fromCell
;
58 void wxHtmlSelection::Set(const wxHtmlCell
*fromCell
, const wxHtmlCell
*toCell
)
60 wxPoint p1
= fromCell
? fromCell
->GetAbsPos() : wxDefaultPosition
;
61 wxPoint p2
= toCell
? toCell
->GetAbsPos() : wxDefaultPosition
;
64 p2
.x
+= toCell
->GetWidth()-1;
65 p2
.y
+= toCell
->GetHeight()-1;
67 Set(p1
, fromCell
, p2
, toCell
);
70 wxColour
wxDefaultHtmlRenderingStyle::GetSelectedTextColour(
73 return wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
76 wxColour
wxDefaultHtmlRenderingStyle::GetSelectedTextBgColour(
77 const wxColour
& WXUNUSED(clr
))
79 return wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
);
83 //-----------------------------------------------------------------------------
85 //-----------------------------------------------------------------------------
87 wxHtmlCell::wxHtmlCell() : wxObject()
91 m_Width
= m_Height
= m_Descent
= 0;
92 m_CanLiveOnPagebreak
= TRUE
;
96 wxHtmlCell::~wxHtmlCell()
102 void wxHtmlCell::OnMouseClick(wxWindow
*parent
, int x
, int y
,
103 const wxMouseEvent
& event
)
105 wxHtmlLinkInfo
*lnk
= GetLink(x
, y
);
108 wxHtmlLinkInfo
lnk2(*lnk
);
109 lnk2
.SetEvent(&event
);
110 lnk2
.SetHtmlCell(this);
112 // note : this cast is legal because parent is *always* wxHtmlWindow
113 wxStaticCast(parent
, wxHtmlWindow
)->OnLinkClicked(lnk2
);
118 wxCursor
wxHtmlCell::GetCursor() const
122 if ( !gs_cursorLink
)
123 gs_cursorLink
= new wxCursor(wxCURSOR_HAND
);
124 return *gs_cursorLink
;
127 return *wxSTANDARD_CURSOR
;
131 bool wxHtmlCell::AdjustPagebreak(int *pagebreak
, int* WXUNUSED(known_pagebreaks
), int WXUNUSED(number_of_pages
)) const
133 if ((!m_CanLiveOnPagebreak
) &&
134 m_PosY
< *pagebreak
&& m_PosY
+ m_Height
> *pagebreak
)
145 void wxHtmlCell::SetLink(const wxHtmlLinkInfo
& link
)
147 if (m_Link
) delete m_Link
;
149 if (link
.GetHref() != wxEmptyString
)
150 m_Link
= new wxHtmlLinkInfo(link
);
154 void wxHtmlCell::Layout(int WXUNUSED(w
))
161 const wxHtmlCell
* wxHtmlCell::Find(int WXUNUSED(condition
), const void* WXUNUSED(param
)) const
167 wxHtmlCell
*wxHtmlCell::FindCellByPos(wxCoord x
, wxCoord y
,
168 unsigned flags
) const
170 if ( x
>= 0 && x
< m_Width
&& y
>= 0 && y
< m_Height
)
172 return wxConstCast(this, wxHtmlCell
);
176 if ((flags
& wxHTML_FIND_NEAREST_AFTER
) &&
177 (y
< 0 || (y
< 0+m_Height
&& x
< 0+m_Width
)))
178 return wxConstCast(this, wxHtmlCell
);
179 else if ((flags
& wxHTML_FIND_NEAREST_BEFORE
) &&
180 (y
>= 0+m_Height
|| (y
>= 0 && x
>= 0)))
181 return wxConstCast(this, wxHtmlCell
);
188 wxPoint
wxHtmlCell::GetAbsPos() const
190 wxPoint
p(m_PosX
, m_PosY
);
191 for (wxHtmlCell
*parent
= m_Parent
; parent
; parent
= parent
->m_Parent
)
193 p
.x
+= parent
->m_PosX
;
194 p
.y
+= parent
->m_PosY
;
199 unsigned wxHtmlCell::GetDepth() const
202 for (wxHtmlCell
*p
= m_Parent
; p
; p
= p
->m_Parent
)
207 bool wxHtmlCell::IsBefore(wxHtmlCell
*cell
) const
209 const wxHtmlCell
*c1
= this;
210 const wxHtmlCell
*c2
= cell
;
211 unsigned d1
= GetDepth();
212 unsigned d2
= cell
->GetDepth();
215 for (; d1
!= d2
; d1
-- )
218 for (; d1
!= d2
; d2
-- )
226 if ( c1
->m_Parent
== c2
->m_Parent
)
243 wxFAIL_MSG(_T("Cells are in different trees"));
248 //-----------------------------------------------------------------------------
250 //-----------------------------------------------------------------------------
252 wxHtmlWordCell::wxHtmlWordCell(const wxString
& word
, wxDC
& dc
) : wxHtmlCell()
255 dc
.GetTextExtent(m_Word
, &m_Width
, &m_Height
, &m_Descent
);
256 SetCanLiveOnPagebreak(FALSE
);
257 m_allowLinebreak
= true;
260 void wxHtmlWordCell::SetPreviousWord(wxHtmlWordCell
*cell
)
262 if ( cell
&& m_Parent
== cell
->m_Parent
&&
263 !wxIsspace(cell
->m_Word
.Last()) && !wxIsspace(m_Word
[0u]) )
265 m_allowLinebreak
= false;
269 // Splits m_Word into up to three parts according to selection, returns
270 // substring before, in and after selection and the points (in relative coords)
271 // where s2 and s3 start:
272 void wxHtmlWordCell::Split(wxDC
& dc
,
273 const wxPoint
& selFrom
, const wxPoint
& selTo
,
274 unsigned& pos1
, unsigned& pos2
) const
276 wxPoint pt1
= (selFrom
== wxDefaultPosition
) ?
277 wxDefaultPosition
: selFrom
- GetAbsPos();
278 wxPoint pt2
= (selTo
== wxDefaultPosition
) ?
279 wxPoint(m_Width
, -1) : selTo
- GetAbsPos();
281 wxCoord charW
, charH
;
282 unsigned len
= m_Word
.length();
286 // adjust for cases when the start/end position is completely
290 if ( pt2
.y
>= m_Height
)
294 while ( pt1
.x
> 0 && i
< len
)
296 dc
.GetTextExtent(m_Word
[i
], &charW
, &charH
);
309 while ( pt2
.x
> 0 && j
< len
)
311 dc
.GetTextExtent(m_Word
[j
], &charW
, &charH
);
324 void wxHtmlWordCell::SetSelectionPrivPos(wxDC
& dc
, wxHtmlSelection
*s
) const
329 this == s
->GetFromCell() ? s
->GetFromPos() : wxDefaultPosition
,
330 this == s
->GetToCell() ? s
->GetToPos() : wxDefaultPosition
,
333 wxPoint
p(0, m_Word
.length());
335 if ( this == s
->GetFromCell() )
336 p
.x
= p1
; // selection starts here
337 if ( this == s
->GetToCell() )
338 p
.y
= p2
; // selection ends here
340 if ( this == s
->GetFromCell() )
341 s
->SetFromPrivPos(p
);
342 if ( this == s
->GetToCell() )
347 static void SwitchSelState(wxDC
& dc
, wxHtmlRenderingInfo
& info
,
350 wxColour fg
= info
.GetState().GetFgColour();
351 wxColour bg
= info
.GetState().GetBgColour();
355 dc
.SetBackgroundMode(wxSOLID
);
356 dc
.SetTextForeground(info
.GetStyle().GetSelectedTextColour(fg
));
357 dc
.SetTextBackground(info
.GetStyle().GetSelectedTextBgColour(bg
));
358 dc
.SetBackground(wxBrush(info
.GetStyle().GetSelectedTextBgColour(bg
),
363 dc
.SetBackgroundMode(wxTRANSPARENT
);
364 dc
.SetTextForeground(fg
);
365 dc
.SetTextBackground(bg
);
366 dc
.SetBackground(wxBrush(bg
, wxSOLID
));
371 void wxHtmlWordCell::Draw(wxDC
& dc
, int x
, int y
,
372 int WXUNUSED(view_y1
), int WXUNUSED(view_y2
),
373 wxHtmlRenderingInfo
& info
)
375 #if 0 // useful for debugging
376 dc
.DrawRectangle(x
+m_PosX
,y
+m_PosY
,m_Width
,m_Height
);
379 bool drawSelectionAfterCell
= false;
381 if ( info
.GetState().GetSelectionState() == wxHTML_SEL_CHANGING
)
383 // Selection changing, we must draw the word piecewise:
384 wxHtmlSelection
*s
= info
.GetSelection();
389 wxPoint priv
= (this == s
->GetFromCell()) ?
390 s
->GetFromPrivPos() : s
->GetToPrivPos();
392 // NB: this is quite a hack: in order to compute selection boundaries
393 // (in word's characters) we must know current font, which is only
394 // possible inside rendering code. Therefore we update the
395 // information here and store it in wxHtmlSelection so that
396 // ConvertToText can use it later:
397 if ( priv
== wxDefaultPosition
)
399 SetSelectionPrivPos(dc
, s
);
400 priv
= (this == s
->GetFromCell()) ?
401 s
->GetFromPrivPos() : s
->GetToPrivPos();
409 txt
= m_Word
.Mid(0, part1
);
410 dc
.DrawText(txt
, x
+ m_PosX
, y
+ m_PosY
);
411 dc
.GetTextExtent(txt
, &w
, &h
);
415 SwitchSelState(dc
, info
, true);
417 txt
= m_Word
.Mid(part1
, part2
-part1
);
418 dc
.DrawText(txt
, ofs
+ x
+ m_PosX
, y
+ m_PosY
);
420 if ( (size_t)part2
< m_Word
.length() )
422 dc
.GetTextExtent(txt
, &w
, &h
);
424 SwitchSelState(dc
, info
, false);
425 txt
= m_Word
.Mid(part2
);
426 dc
.DrawText(txt
, ofs
+ x
+ m_PosX
, y
+ m_PosY
);
429 drawSelectionAfterCell
= true;
433 wxHtmlSelectionState selstate
= info
.GetState().GetSelectionState();
434 // Not changing selection state, draw the word in single mode:
435 if ( selstate
!= wxHTML_SEL_OUT
&&
436 dc
.GetBackgroundMode() != wxSOLID
)
438 SwitchSelState(dc
, info
, true);
440 else if ( selstate
== wxHTML_SEL_OUT
&&
441 dc
.GetBackgroundMode() == wxSOLID
)
443 SwitchSelState(dc
, info
, false);
445 dc
.DrawText(m_Word
, x
+ m_PosX
, y
+ m_PosY
);
446 drawSelectionAfterCell
= (selstate
!= wxHTML_SEL_OUT
);
449 // NB: If the text is justified then there is usually some free space
450 // between adjacent cells and drawing the selection only onto cells
451 // would result in ugly unselected spaces. The code below detects
452 // this special case and renders the selection *outside* the sell,
454 if ( m_Parent
->GetAlignHor() == wxHTML_ALIGN_JUSTIFY
&&
455 drawSelectionAfterCell
)
457 wxHtmlCell
*nextCell
= m_Next
;
458 while ( nextCell
&& nextCell
->IsFormattingCell() )
459 nextCell
= nextCell
->GetNext();
462 int nextX
= nextCell
->GetPosX();
463 if ( m_PosX
+ m_Width
< nextX
)
465 dc
.SetBrush(dc
.GetBackground());
466 dc
.SetPen(*wxTRANSPARENT_PEN
);
467 dc
.DrawRectangle(x
+ m_PosX
+ m_Width
, y
+ m_PosY
,
468 nextX
- m_PosX
- m_Width
, m_Height
);
475 wxString
wxHtmlWordCell::ConvertToText(wxHtmlSelection
*s
) const
477 if ( s
&& (this == s
->GetFromCell() || this == s
->GetToCell()) )
479 wxPoint priv
= this == s
->GetFromCell() ? s
->GetFromPrivPos()
482 // VZ: we may be called before we had a chance to re-render ourselves
483 // and in this case GetFrom/ToPrivPos() is not set yet -- assume
484 // that this only happens in case of a double/triple click (which
485 // seems to be the case now) and so it makes sense to select the
486 // entire contents of the cell in this case
488 // TODO: but this really needs to be fixed in some better way later...
489 if ( priv
!= wxDefaultPosition
)
493 return m_Word
.Mid(part1
, part2
-part1
);
495 //else: return the whole word below
501 wxCursor
wxHtmlWordCell::GetCursor() const
505 if ( !gs_cursorText
)
506 gs_cursorText
= new wxCursor(wxCURSOR_IBEAM
);
507 return *gs_cursorText
;
510 return wxHtmlCell::GetCursor();
514 //-----------------------------------------------------------------------------
515 // wxHtmlContainerCell
516 //-----------------------------------------------------------------------------
519 wxHtmlContainerCell::wxHtmlContainerCell(wxHtmlContainerCell
*parent
) : wxHtmlCell()
521 m_Cells
= m_LastCell
= NULL
;
523 if (m_Parent
) m_Parent
->InsertCell(this);
524 m_AlignHor
= wxHTML_ALIGN_LEFT
;
525 m_AlignVer
= wxHTML_ALIGN_BOTTOM
;
526 m_IndentLeft
= m_IndentRight
= m_IndentTop
= m_IndentBottom
= 0;
527 m_WidthFloat
= 100; m_WidthFloatUnits
= wxHTML_UNITS_PERCENT
;
528 m_UseBkColour
= FALSE
;
531 m_MinHeightAlign
= wxHTML_ALIGN_TOP
;
535 wxHtmlContainerCell::~wxHtmlContainerCell()
537 wxHtmlCell
*cell
= m_Cells
;
540 wxHtmlCell
*cellNext
= cell
->GetNext();
548 void wxHtmlContainerCell::SetIndent(int i
, int what
, int units
)
550 int val
= (units
== wxHTML_UNITS_PIXELS
) ? i
: -i
;
551 if (what
& wxHTML_INDENT_LEFT
) m_IndentLeft
= val
;
552 if (what
& wxHTML_INDENT_RIGHT
) m_IndentRight
= val
;
553 if (what
& wxHTML_INDENT_TOP
) m_IndentTop
= val
;
554 if (what
& wxHTML_INDENT_BOTTOM
) m_IndentBottom
= val
;
560 int wxHtmlContainerCell::GetIndent(int ind
) const
562 if (ind
& wxHTML_INDENT_LEFT
) return m_IndentLeft
;
563 else if (ind
& wxHTML_INDENT_RIGHT
) return m_IndentRight
;
564 else if (ind
& wxHTML_INDENT_TOP
) return m_IndentTop
;
565 else if (ind
& wxHTML_INDENT_BOTTOM
) return m_IndentBottom
;
566 else return -1; /* BUG! Should not be called... */
572 int wxHtmlContainerCell::GetIndentUnits(int ind
) const
575 if (ind
& wxHTML_INDENT_LEFT
) p
= m_IndentLeft
< 0;
576 else if (ind
& wxHTML_INDENT_RIGHT
) p
= m_IndentRight
< 0;
577 else if (ind
& wxHTML_INDENT_TOP
) p
= m_IndentTop
< 0;
578 else if (ind
& wxHTML_INDENT_BOTTOM
) p
= m_IndentBottom
< 0;
579 if (p
) return wxHTML_UNITS_PERCENT
;
580 else return wxHTML_UNITS_PIXELS
;
585 bool wxHtmlContainerCell::AdjustPagebreak(int *pagebreak
, int* known_pagebreaks
, int number_of_pages
) const
587 if (!m_CanLiveOnPagebreak
)
588 return wxHtmlCell::AdjustPagebreak(pagebreak
, known_pagebreaks
, number_of_pages
);
592 wxHtmlCell
*c
= GetFirstChild();
594 int pbrk
= *pagebreak
- m_PosY
;
598 if (c
->AdjustPagebreak(&pbrk
, known_pagebreaks
, number_of_pages
))
603 *pagebreak
= pbrk
+ m_PosY
;
610 void wxHtmlContainerCell::Layout(int w
)
612 wxHtmlCell::Layout(w
);
614 if (m_LastLayout
== w
) return;
616 // VS: Any attempt to layout with negative or zero width leads to hell,
617 // but we can't ignore such attempts completely, since it sometimes
618 // happen (e.g. when trying how small a table can be). The best thing we
619 // can do is to set the width of child cells to zero
623 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
625 // this does two things: it recursively calls this code on all
626 // child contrainers and resets children's position to (0,0)
630 wxHtmlCell
*cell
= m_Cells
, *line
= m_Cells
;
631 wxHtmlCell
*nextCell
;
632 long xpos
= 0, ypos
= m_IndentTop
;
633 int xdelta
= 0, ybasicpos
= 0, ydiff
;
634 int s_width
, nextWordWidth
, s_indent
;
635 int ysizeup
= 0, ysizedown
= 0;
636 int MaxLineWidth
= 0;
646 if (m_WidthFloatUnits
== wxHTML_UNITS_PERCENT
)
648 if (m_WidthFloat
< 0) m_Width
= (100 + m_WidthFloat
) * w
/ 100;
649 else m_Width
= m_WidthFloat
* w
/ 100;
653 if (m_WidthFloat
< 0) m_Width
= w
+ m_WidthFloat
;
654 else m_Width
= m_WidthFloat
;
659 int l
= (m_IndentLeft
< 0) ? (-m_IndentLeft
* m_Width
/ 100) : m_IndentLeft
;
660 int r
= (m_IndentRight
< 0) ? (-m_IndentRight
* m_Width
/ 100) : m_IndentRight
;
661 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
662 cell
->Layout(m_Width
- (l
+ r
));
671 // adjust indentation:
672 s_indent
= (m_IndentLeft
< 0) ? (-m_IndentLeft
* m_Width
/ 100) : m_IndentLeft
;
673 s_width
= m_Width
- s_indent
- ((m_IndentRight
< 0) ? (-m_IndentRight
* m_Width
/ 100) : m_IndentRight
);
680 case wxHTML_ALIGN_TOP
: ybasicpos
= 0; break;
681 case wxHTML_ALIGN_BOTTOM
: ybasicpos
= - cell
->GetHeight(); break;
682 case wxHTML_ALIGN_CENTER
: ybasicpos
= - cell
->GetHeight() / 2; break;
684 ydiff
= cell
->GetHeight() + ybasicpos
;
686 if (cell
->GetDescent() + ydiff
> ysizedown
) ysizedown
= cell
->GetDescent() + ydiff
;
687 if (ybasicpos
+ cell
->GetDescent() < -ysizeup
) ysizeup
= - (ybasicpos
+ cell
->GetDescent());
689 // layout nonbreakable run of cells:
690 cell
->SetPos(xpos
, ybasicpos
+ cell
->GetDescent());
691 xpos
+= cell
->GetWidth();
692 cell
= cell
->GetNext();
695 // compute length of the next word that would be added:
702 nextWordWidth
+= nextCell
->GetWidth();
703 nextCell
= nextCell
->GetNext();
704 } while (nextCell
&& !nextCell
->IsLinebreakAllowed());
707 // force new line if occured:
708 if ((cell
== NULL
) ||
709 (xpos
+ nextWordWidth
> s_width
&& cell
->IsLinebreakAllowed()))
711 if (xpos
> MaxLineWidth
) MaxLineWidth
= xpos
;
712 if (ysizeup
< 0) ysizeup
= 0;
713 if (ysizedown
< 0) ysizedown
= 0;
714 switch (m_AlignHor
) {
715 case wxHTML_ALIGN_LEFT
:
716 case wxHTML_ALIGN_JUSTIFY
:
719 case wxHTML_ALIGN_RIGHT
:
720 xdelta
= 0 + (s_width
- xpos
);
722 case wxHTML_ALIGN_CENTER
:
723 xdelta
= 0 + (s_width
- xpos
) / 2;
726 if (xdelta
< 0) xdelta
= 0;
731 if (m_AlignHor
!= wxHTML_ALIGN_JUSTIFY
|| cell
== NULL
)
734 line
->SetPos(line
->GetPosX() + xdelta
,
735 ypos
+ line
->GetPosY());
736 line
= line
->GetNext();
741 int step
= (s_width
- xpos
);
742 if (step
< 0) step
= 0;
744 if (xcnt
> 0) while (line
!= cell
)
746 line
->SetPos(line
->GetPosX() + s_indent
+
747 (counter
++ * step
/ xcnt
),
748 ypos
+ line
->GetPosY());
749 line
= line
->GetNext();
756 ysizeup
= ysizedown
= 0;
761 // setup height & width, depending on container layout:
762 m_Height
= ypos
+ (ysizedown
+ ysizeup
) + m_IndentBottom
;
764 if (m_Height
< m_MinHeight
)
766 if (m_MinHeightAlign
!= wxHTML_ALIGN_TOP
)
768 int diff
= m_MinHeight
- m_Height
;
769 if (m_MinHeightAlign
== wxHTML_ALIGN_CENTER
) diff
/= 2;
773 cell
->SetPos(cell
->GetPosX(), cell
->GetPosY() + diff
);
774 cell
= cell
->GetNext();
777 m_Height
= m_MinHeight
;
780 MaxLineWidth
+= s_indent
+ ((m_IndentRight
< 0) ? (-m_IndentRight
* m_Width
/ 100) : m_IndentRight
);
781 if (m_Width
< MaxLineWidth
) m_Width
= MaxLineWidth
;
786 void wxHtmlContainerCell::UpdateRenderingStatePre(wxHtmlRenderingInfo
& info
,
787 wxHtmlCell
*cell
) const
789 wxHtmlSelection
*s
= info
.GetSelection();
791 if (s
->GetFromCell() == cell
|| s
->GetToCell() == cell
)
793 info
.GetState().SetSelectionState(wxHTML_SEL_CHANGING
);
797 void wxHtmlContainerCell::UpdateRenderingStatePost(wxHtmlRenderingInfo
& info
,
798 wxHtmlCell
*cell
) const
800 wxHtmlSelection
*s
= info
.GetSelection();
802 if (s
->GetToCell() == cell
)
803 info
.GetState().SetSelectionState(wxHTML_SEL_OUT
);
804 else if (s
->GetFromCell() == cell
)
805 info
.GetState().SetSelectionState(wxHTML_SEL_IN
);
808 #define mMin(a, b) (((a) < (b)) ? (a) : (b))
809 #define mMax(a, b) (((a) < (b)) ? (b) : (a))
811 void wxHtmlContainerCell::Draw(wxDC
& dc
, int x
, int y
, int view_y1
, int view_y2
,
812 wxHtmlRenderingInfo
& info
)
814 // container visible, draw it:
815 if ((y
+ m_PosY
<= view_y2
) && (y
+ m_PosY
+ m_Height
> view_y1
))
819 wxBrush myb
= wxBrush(m_BkColour
, wxSOLID
);
821 int real_y1
= mMax(y
+ m_PosY
, view_y1
);
822 int real_y2
= mMin(y
+ m_PosY
+ m_Height
- 1, view_y2
);
825 dc
.SetPen(*wxTRANSPARENT_PEN
);
826 dc
.DrawRectangle(x
+ m_PosX
, real_y1
, m_Width
, real_y2
- real_y1
+ 1);
831 wxPen
mypen1(m_BorderColour1
, 1, wxSOLID
);
832 wxPen
mypen2(m_BorderColour2
, 1, wxSOLID
);
835 dc
.DrawLine(x
+ m_PosX
, y
+ m_PosY
, x
+ m_PosX
, y
+ m_PosY
+ m_Height
- 1);
836 dc
.DrawLine(x
+ m_PosX
, y
+ m_PosY
, x
+ m_PosX
+ m_Width
, y
+ m_PosY
);
838 dc
.DrawLine(x
+ m_PosX
+ m_Width
- 1, y
+ m_PosY
, x
+ m_PosX
+ m_Width
- 1, y
+ m_PosY
+ m_Height
- 1);
839 dc
.DrawLine(x
+ m_PosX
, y
+ m_PosY
+ m_Height
- 1, x
+ m_PosX
+ m_Width
, y
+ m_PosY
+ m_Height
- 1);
844 // draw container's contents:
845 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
847 UpdateRenderingStatePre(info
, cell
);
849 x
+ m_PosX
, y
+ m_PosY
, view_y1
, view_y2
,
851 UpdateRenderingStatePost(info
, cell
);
855 // container invisible, just proceed font+color changing:
858 DrawInvisible(dc
, x
, y
, info
);
864 void wxHtmlContainerCell::DrawInvisible(wxDC
& dc
, int x
, int y
,
865 wxHtmlRenderingInfo
& info
)
869 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
871 UpdateRenderingStatePre(info
, cell
);
872 cell
->DrawInvisible(dc
, x
+ m_PosX
, y
+ m_PosY
, info
);
873 UpdateRenderingStatePost(info
, cell
);
879 wxColour
wxHtmlContainerCell::GetBackgroundColour()
889 wxHtmlLinkInfo
*wxHtmlContainerCell::GetLink(int x
, int y
) const
891 wxHtmlCell
*cell
= FindCellByPos(x
, y
);
893 // VZ: I don't know if we should pass absolute or relative coords to
894 // wxHtmlCell::GetLink()? As the base class version just ignores them
895 // anyhow, it hardly matters right now but should still be clarified
896 return cell
? cell
->GetLink(x
, y
) : NULL
;
901 void wxHtmlContainerCell::InsertCell(wxHtmlCell
*f
)
903 if (!m_Cells
) m_Cells
= m_LastCell
= f
;
906 m_LastCell
->SetNext(f
);
908 if (m_LastCell
) while (m_LastCell
->GetNext()) m_LastCell
= m_LastCell
->GetNext();
916 void wxHtmlContainerCell::SetAlign(const wxHtmlTag
& tag
)
918 if (tag
.HasParam(wxT("ALIGN")))
920 wxString alg
= tag
.GetParam(wxT("ALIGN"));
922 if (alg
== wxT("CENTER"))
923 SetAlignHor(wxHTML_ALIGN_CENTER
);
924 else if (alg
== wxT("LEFT"))
925 SetAlignHor(wxHTML_ALIGN_LEFT
);
926 else if (alg
== wxT("JUSTIFY"))
927 SetAlignHor(wxHTML_ALIGN_JUSTIFY
);
928 else if (alg
== wxT("RIGHT"))
929 SetAlignHor(wxHTML_ALIGN_RIGHT
);
936 void wxHtmlContainerCell::SetWidthFloat(const wxHtmlTag
& tag
, double pixel_scale
)
938 if (tag
.HasParam(wxT("WIDTH")))
941 wxString wd
= tag
.GetParam(wxT("WIDTH"));
943 if (wd
[wd
.Length()-1] == wxT('%'))
945 wxSscanf(wd
.c_str(), wxT("%i%%"), &wdi
);
946 SetWidthFloat(wdi
, wxHTML_UNITS_PERCENT
);
950 wxSscanf(wd
.c_str(), wxT("%i"), &wdi
);
951 SetWidthFloat((int)(pixel_scale
* (double)wdi
), wxHTML_UNITS_PIXELS
);
959 const wxHtmlCell
* wxHtmlContainerCell::Find(int condition
, const void* param
) const
963 const wxHtmlCell
*r
= NULL
;
965 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
967 r
= cell
->Find(condition
, param
);
975 wxHtmlCell
*wxHtmlContainerCell::FindCellByPos(wxCoord x
, wxCoord y
,
976 unsigned flags
) const
978 if ( flags
& wxHTML_FIND_EXACT
)
980 for ( const wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext() )
982 int cx
= cell
->GetPosX(),
983 cy
= cell
->GetPosY();
985 if ( (cx
<= x
) && (cx
+ cell
->GetWidth() > x
) &&
986 (cy
<= y
) && (cy
+ cell
->GetHeight() > y
) )
988 return cell
->FindCellByPos(x
- cx
, y
- cy
, flags
);
992 else if ( flags
& wxHTML_FIND_NEAREST_AFTER
)
995 for ( const wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext() )
997 if ( cell
->IsFormattingCell() )
999 int cellY
= cell
->GetPosY();
1000 if (!( y
< cellY
|| (y
< cellY
+ cell
->GetHeight() &&
1001 x
< cell
->GetPosX() + cell
->GetWidth()) ))
1004 c
= cell
->FindCellByPos(x
- cell
->GetPosX(), y
- cellY
, flags
);
1008 else if ( flags
& wxHTML_FIND_NEAREST_BEFORE
)
1010 wxHtmlCell
*c2
, *c
= NULL
;
1011 for ( const wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext() )
1013 if ( cell
->IsFormattingCell() )
1015 int cellY
= cell
->GetPosY();
1016 if (!( cellY
+ cell
->GetHeight() <= y
||
1017 (y
>= cellY
&& x
>= cell
->GetPosX()) ))
1019 c2
= cell
->FindCellByPos(x
- cell
->GetPosX(), y
- cellY
, flags
);
1030 void wxHtmlContainerCell::OnMouseClick(wxWindow
*parent
, int x
, int y
, const wxMouseEvent
& event
)
1032 wxHtmlCell
*cell
= FindCellByPos(x
, y
);
1034 cell
->OnMouseClick(parent
, x
, y
, event
);
1039 wxHtmlCell
*wxHtmlContainerCell::GetFirstTerminal() const
1044 for (wxHtmlCell
*c
= m_Cells
; c
; c
= c
->GetNext())
1046 c2
= c
->GetFirstTerminal();
1054 wxHtmlCell
*wxHtmlContainerCell::GetLastTerminal() const
1058 // most common case first:
1059 wxHtmlCell
*c
= m_LastCell
->GetLastTerminal();
1063 wxHtmlCell
*c2
= NULL
;
1064 for (c
= m_Cells
; c
; c
= c
->GetNext())
1065 c2
= c
->GetLastTerminal();
1075 // --------------------------------------------------------------------------
1077 // --------------------------------------------------------------------------
1079 void wxHtmlColourCell::Draw(wxDC
& dc
,
1081 int WXUNUSED(view_y1
), int WXUNUSED(view_y2
),
1082 wxHtmlRenderingInfo
& info
)
1084 DrawInvisible(dc
, x
, y
, info
);
1087 void wxHtmlColourCell::DrawInvisible(wxDC
& dc
,
1088 int WXUNUSED(x
), int WXUNUSED(y
),
1089 wxHtmlRenderingInfo
& info
)
1091 wxHtmlRenderingState
& state
= info
.GetState();
1092 if (m_Flags
& wxHTML_CLR_FOREGROUND
)
1094 state
.SetFgColour(m_Colour
);
1095 if (state
.GetSelectionState() != wxHTML_SEL_IN
)
1096 dc
.SetTextForeground(m_Colour
);
1098 dc
.SetTextForeground(
1099 info
.GetStyle().GetSelectedTextColour(m_Colour
));
1101 if (m_Flags
& wxHTML_CLR_BACKGROUND
)
1103 state
.SetBgColour(m_Colour
);
1104 if (state
.GetSelectionState() != wxHTML_SEL_IN
)
1106 dc
.SetTextBackground(m_Colour
);
1107 dc
.SetBackground(wxBrush(m_Colour
, wxSOLID
));
1111 wxColour c
= info
.GetStyle().GetSelectedTextBgColour(m_Colour
);
1112 dc
.SetTextBackground(c
);
1113 dc
.SetBackground(wxBrush(c
, wxSOLID
));
1121 // ---------------------------------------------------------------------------
1123 // ---------------------------------------------------------------------------
1125 void wxHtmlFontCell::Draw(wxDC
& dc
,
1126 int WXUNUSED(x
), int WXUNUSED(y
),
1127 int WXUNUSED(view_y1
), int WXUNUSED(view_y2
),
1128 wxHtmlRenderingInfo
& WXUNUSED(info
))
1133 void wxHtmlFontCell::DrawInvisible(wxDC
& dc
, int WXUNUSED(x
), int WXUNUSED(y
),
1134 wxHtmlRenderingInfo
& WXUNUSED(info
))
1146 // ---------------------------------------------------------------------------
1148 // ---------------------------------------------------------------------------
1150 wxHtmlWidgetCell::wxHtmlWidgetCell(wxWindow
*wnd
, int w
)
1154 m_Wnd
->GetSize(&sx
, &sy
);
1155 m_Width
= sx
, m_Height
= sy
;
1160 void wxHtmlWidgetCell::Draw(wxDC
& WXUNUSED(dc
),
1161 int WXUNUSED(x
), int WXUNUSED(y
),
1162 int WXUNUSED(view_y1
), int WXUNUSED(view_y2
),
1163 wxHtmlRenderingInfo
& WXUNUSED(info
))
1165 int absx
= 0, absy
= 0, stx
, sty
;
1166 wxHtmlCell
*c
= this;
1170 absx
+= c
->GetPosX();
1171 absy
+= c
->GetPosY();
1175 ((wxScrolledWindow
*)(m_Wnd
->GetParent()))->GetViewStart(&stx
, &sty
);
1176 m_Wnd
->SetSize(absx
- wxHTML_SCROLL_STEP
* stx
, absy
- wxHTML_SCROLL_STEP
* sty
, m_Width
, m_Height
);
1181 void wxHtmlWidgetCell::DrawInvisible(wxDC
& WXUNUSED(dc
),
1182 int WXUNUSED(x
), int WXUNUSED(y
),
1183 wxHtmlRenderingInfo
& WXUNUSED(info
))
1185 int absx
= 0, absy
= 0, stx
, sty
;
1186 wxHtmlCell
*c
= this;
1190 absx
+= c
->GetPosX();
1191 absy
+= c
->GetPosY();
1195 ((wxScrolledWindow
*)(m_Wnd
->GetParent()))->GetViewStart(&stx
, &sty
);
1196 m_Wnd
->SetSize(absx
- wxHTML_SCROLL_STEP
* stx
, absy
- wxHTML_SCROLL_STEP
* sty
, m_Width
, m_Height
);
1201 void wxHtmlWidgetCell::Layout(int w
)
1203 if (m_WidthFloat
!= 0)
1205 m_Width
= (w
* m_WidthFloat
) / 100;
1206 m_Wnd
->SetSize(m_Width
, m_Height
);
1209 wxHtmlCell::Layout(w
);
1214 // ----------------------------------------------------------------------------
1215 // wxHtmlTerminalCellsInterator
1216 // ----------------------------------------------------------------------------
1218 const wxHtmlCell
* wxHtmlTerminalCellsInterator::operator++()
1225 if ( m_pos
== m_to
)
1231 if ( m_pos
->GetNext() )
1232 m_pos
= m_pos
->GetNext();
1235 // we must go up the hierarchy until we reach container where this
1236 // is not the last child, and then go down to first terminal cell:
1237 while ( m_pos
->GetNext() == NULL
)
1239 m_pos
= m_pos
->GetParent();
1243 m_pos
= m_pos
->GetNext();
1245 while ( m_pos
->GetFirstChild() != NULL
)
1246 m_pos
= m_pos
->GetFirstChild();
1247 } while ( !m_pos
->IsTerminalCell() );
1258 //-----------------------------------------------------------------------------
1260 //-----------------------------------------------------------------------------
1262 class wxHtmlCellModule
: public wxModule
1264 DECLARE_DYNAMIC_CLASS(wxHtmlCellModule
)
1266 wxHtmlCellModule() : wxModule() {}
1267 bool OnInit() { return true; }
1270 wxDELETE(gs_cursorLink
);
1271 wxDELETE(gs_cursorText
);
1275 IMPLEMENT_DYNAMIC_CLASS(wxHtmlCellModule
, wxModule
)