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 void wxHtmlCell::GetHorizontalConstraints(int *left
, int *right
) const
166 *right
= m_PosX
+ m_Width
;
171 const wxHtmlCell
* wxHtmlCell::Find(int WXUNUSED(condition
), const void* WXUNUSED(param
)) const
177 wxHtmlCell
*wxHtmlCell::FindCellByPos(wxCoord x
, wxCoord y
,
178 unsigned flags
) const
180 if ( x
>= 0 && x
< m_Width
&& y
>= 0 && y
< m_Height
)
182 return wxConstCast(this, wxHtmlCell
);
186 if ((flags
& wxHTML_FIND_NEAREST_AFTER
) &&
187 (y
< 0 || (y
== 0 && x
<= 0)))
188 return wxConstCast(this, wxHtmlCell
);
189 else if ((flags
& wxHTML_FIND_NEAREST_BEFORE
) &&
190 (y
> m_Height
-1 || (y
== m_Height
-1 && x
>= m_Width
)))
191 return wxConstCast(this, wxHtmlCell
);
198 wxPoint
wxHtmlCell::GetAbsPos() const
200 wxPoint
p(m_PosX
, m_PosY
);
201 for (wxHtmlCell
*parent
= m_Parent
; parent
; parent
= parent
->m_Parent
)
203 p
.x
+= parent
->m_PosX
;
204 p
.y
+= parent
->m_PosY
;
209 unsigned wxHtmlCell::GetDepth() const
212 for (wxHtmlCell
*p
= m_Parent
; p
; p
= p
->m_Parent
)
217 bool wxHtmlCell::IsBefore(wxHtmlCell
*cell
) const
219 const wxHtmlCell
*c1
= this;
220 const wxHtmlCell
*c2
= cell
;
221 unsigned d1
= GetDepth();
222 unsigned d2
= cell
->GetDepth();
225 for (; d1
!= d2
; d1
-- )
228 for (; d1
!= d2
; d2
-- )
236 if ( c1
->m_Parent
== c2
->m_Parent
)
253 wxFAIL_MSG(_T("Cells are in different trees"));
258 //-----------------------------------------------------------------------------
260 //-----------------------------------------------------------------------------
262 wxHtmlWordCell::wxHtmlWordCell(const wxString
& word
, wxDC
& dc
) : wxHtmlCell()
265 dc
.GetTextExtent(m_Word
, &m_Width
, &m_Height
, &m_Descent
);
266 SetCanLiveOnPagebreak(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();
288 while ( pt1
.x
> 0 && i
< len
)
290 dc
.GetTextExtent(m_Word
[i
], &charW
, &charH
);
303 while ( pt2
.x
> 0 && j
< len
)
305 dc
.GetTextExtent(m_Word
[j
], &charW
, &charH
);
318 void wxHtmlWordCell::SetSelectionPrivPos(wxDC
& dc
, wxHtmlSelection
*s
) const
323 this == s
->GetFromCell() ? s
->GetFromPos() : wxDefaultPosition
,
324 this == s
->GetToCell() ? s
->GetToPos() : wxDefaultPosition
,
327 wxPoint
p(0, m_Word
.length());
329 if ( this == s
->GetFromCell() )
330 p
.x
= p1
; // selection starts here
331 if ( this == s
->GetToCell() )
332 p
.y
= p2
; // selection ends here
334 if ( this == s
->GetFromCell() )
335 s
->SetFromPrivPos(p
);
336 if ( this == s
->GetToCell() )
341 static void SwitchSelState(wxDC
& dc
, wxHtmlRenderingInfo
& info
,
344 wxColour fg
= info
.GetState().GetFgColour();
345 wxColour bg
= info
.GetState().GetBgColour();
349 dc
.SetBackgroundMode(wxSOLID
);
350 dc
.SetTextForeground(info
.GetStyle().GetSelectedTextColour(fg
));
351 dc
.SetTextBackground(info
.GetStyle().GetSelectedTextBgColour(bg
));
352 dc
.SetBackground(wxBrush(info
.GetStyle().GetSelectedTextBgColour(bg
),
357 dc
.SetBackgroundMode(wxTRANSPARENT
);
358 dc
.SetTextForeground(fg
);
359 dc
.SetTextBackground(bg
);
360 dc
.SetBackground(wxBrush(bg
, wxSOLID
));
365 void wxHtmlWordCell::Draw(wxDC
& dc
, int x
, int y
,
366 int WXUNUSED(view_y1
), int WXUNUSED(view_y2
),
367 wxHtmlRenderingInfo
& info
)
369 #if 0 // useful for debugging
370 dc
.DrawRectangle(x
+m_PosX
,y
+m_PosY
,m_Width
,m_Height
);
373 bool drawSelectionAfterCell
= false;
375 if ( info
.GetState().GetSelectionState() == wxHTML_SEL_CHANGING
)
377 // Selection changing, we must draw the word piecewise:
378 wxHtmlSelection
*s
= info
.GetSelection();
383 wxPoint priv
= (this == s
->GetFromCell()) ?
384 s
->GetFromPrivPos() : s
->GetToPrivPos();
386 // NB: this is quite a hack: in order to compute selection boundaries
387 // (in word's characters) we must know current font, which is only
388 // possible inside rendering code. Therefore we update the
389 // information here and store it in wxHtmlSelection so that
390 // ConvertToText can use it later:
391 if ( priv
== wxDefaultPosition
)
393 SetSelectionPrivPos(dc
, s
);
394 priv
= (this == s
->GetFromCell()) ?
395 s
->GetFromPrivPos() : s
->GetToPrivPos();
403 txt
= m_Word
.Mid(0, part1
);
404 dc
.DrawText(txt
, x
+ m_PosX
, y
+ m_PosY
);
405 dc
.GetTextExtent(txt
, &w
, &h
);
409 SwitchSelState(dc
, info
, true);
411 txt
= m_Word
.Mid(part1
, part2
-part1
);
412 dc
.DrawText(txt
, ofs
+ x
+ m_PosX
, y
+ m_PosY
);
414 if ( (size_t)part2
< m_Word
.length() )
416 dc
.GetTextExtent(txt
, &w
, &h
);
418 SwitchSelState(dc
, info
, false);
419 txt
= m_Word
.Mid(part2
);
420 dc
.DrawText(txt
, ofs
+ x
+ m_PosX
, y
+ m_PosY
);
423 drawSelectionAfterCell
= true;
427 wxHtmlSelectionState selstate
= info
.GetState().GetSelectionState();
428 // Not changing selection state, draw the word in single mode:
429 if ( selstate
!= wxHTML_SEL_OUT
&&
430 dc
.GetBackgroundMode() != wxSOLID
)
432 SwitchSelState(dc
, info
, true);
434 else if ( selstate
== wxHTML_SEL_OUT
&&
435 dc
.GetBackgroundMode() == wxSOLID
)
437 SwitchSelState(dc
, info
, false);
439 dc
.DrawText(m_Word
, x
+ m_PosX
, y
+ m_PosY
);
440 drawSelectionAfterCell
= (selstate
!= wxHTML_SEL_OUT
);
443 // NB: If the text is justified then there is usually some free space
444 // between adjacent cells and drawing the selection only onto cells
445 // would result in ugly unselected spaces. The code below detects
446 // this special case and renders the selection *outside* the sell,
448 if ( m_Parent
->GetAlignHor() == wxHTML_ALIGN_JUSTIFY
&&
449 drawSelectionAfterCell
)
451 wxHtmlCell
*nextCell
= m_Next
;
452 while ( nextCell
&& nextCell
->IsFormattingCell() )
453 nextCell
= nextCell
->GetNext();
456 int nextX
= nextCell
->GetPosX();
457 if ( m_PosX
+ m_Width
< nextX
)
459 dc
.SetBrush(dc
.GetBackground());
460 dc
.SetPen(*wxTRANSPARENT_PEN
);
461 dc
.DrawRectangle(x
+ m_PosX
+ m_Width
, y
+ m_PosY
,
462 nextX
- m_PosX
- m_Width
, m_Height
);
469 wxString
wxHtmlWordCell::ConvertToText(wxHtmlSelection
*s
) const
471 if ( s
&& (this == s
->GetFromCell() || this == s
->GetToCell()) )
473 wxPoint priv
= this == s
->GetFromCell() ? s
->GetFromPrivPos()
476 // VZ: we may be called before we had a chance to re-render ourselves
477 // and in this case GetFrom/ToPrivPos() is not set yet -- assume
478 // that this only happens in case of a double/triple click (which
479 // seems to be the case now) and so it makes sense to select the
480 // entire contents of the cell in this case
482 // TODO: but this really needs to be fixed in some better way later...
483 if ( priv
!= wxDefaultPosition
)
487 return m_Word
.Mid(part1
, part2
-part1
);
489 //else: return the whole word below
495 wxCursor
wxHtmlWordCell::GetCursor() const
499 if ( !gs_cursorText
)
500 gs_cursorText
= new wxCursor(wxCURSOR_IBEAM
);
501 return *gs_cursorText
;
504 return wxHtmlCell::GetCursor();
508 //-----------------------------------------------------------------------------
509 // wxHtmlContainerCell
510 //-----------------------------------------------------------------------------
513 wxHtmlContainerCell::wxHtmlContainerCell(wxHtmlContainerCell
*parent
) : wxHtmlCell()
515 m_Cells
= m_LastCell
= NULL
;
517 if (m_Parent
) m_Parent
->InsertCell(this);
518 m_AlignHor
= wxHTML_ALIGN_LEFT
;
519 m_AlignVer
= wxHTML_ALIGN_BOTTOM
;
520 m_IndentLeft
= m_IndentRight
= m_IndentTop
= m_IndentBottom
= 0;
521 m_WidthFloat
= 100; m_WidthFloatUnits
= wxHTML_UNITS_PERCENT
;
522 m_UseBkColour
= FALSE
;
525 m_MinHeightAlign
= wxHTML_ALIGN_TOP
;
529 wxHtmlContainerCell::~wxHtmlContainerCell()
531 wxHtmlCell
*cell
= m_Cells
;
534 wxHtmlCell
*cellNext
= cell
->GetNext();
542 void wxHtmlContainerCell::SetIndent(int i
, int what
, int units
)
544 int val
= (units
== wxHTML_UNITS_PIXELS
) ? i
: -i
;
545 if (what
& wxHTML_INDENT_LEFT
) m_IndentLeft
= val
;
546 if (what
& wxHTML_INDENT_RIGHT
) m_IndentRight
= val
;
547 if (what
& wxHTML_INDENT_TOP
) m_IndentTop
= val
;
548 if (what
& wxHTML_INDENT_BOTTOM
) m_IndentBottom
= val
;
554 int wxHtmlContainerCell::GetIndent(int ind
) const
556 if (ind
& wxHTML_INDENT_LEFT
) return m_IndentLeft
;
557 else if (ind
& wxHTML_INDENT_RIGHT
) return m_IndentRight
;
558 else if (ind
& wxHTML_INDENT_TOP
) return m_IndentTop
;
559 else if (ind
& wxHTML_INDENT_BOTTOM
) return m_IndentBottom
;
560 else return -1; /* BUG! Should not be called... */
566 int wxHtmlContainerCell::GetIndentUnits(int ind
) const
569 if (ind
& wxHTML_INDENT_LEFT
) p
= m_IndentLeft
< 0;
570 else if (ind
& wxHTML_INDENT_RIGHT
) p
= m_IndentRight
< 0;
571 else if (ind
& wxHTML_INDENT_TOP
) p
= m_IndentTop
< 0;
572 else if (ind
& wxHTML_INDENT_BOTTOM
) p
= m_IndentBottom
< 0;
573 if (p
) return wxHTML_UNITS_PERCENT
;
574 else return wxHTML_UNITS_PIXELS
;
579 bool wxHtmlContainerCell::AdjustPagebreak(int *pagebreak
, int* known_pagebreaks
, int number_of_pages
) const
581 if (!m_CanLiveOnPagebreak
)
582 return wxHtmlCell::AdjustPagebreak(pagebreak
, known_pagebreaks
, number_of_pages
);
586 wxHtmlCell
*c
= GetFirstChild();
588 int pbrk
= *pagebreak
- m_PosY
;
592 if (c
->AdjustPagebreak(&pbrk
, known_pagebreaks
, number_of_pages
))
597 *pagebreak
= pbrk
+ m_PosY
;
604 void wxHtmlContainerCell::Layout(int w
)
606 wxHtmlCell::Layout(w
);
608 if (m_LastLayout
== w
) return;
610 // VS: Any attempt to layout with negative or zero width leads to hell,
611 // but we can't ignore such attempts completely, since it sometimes
612 // happen (e.g. when trying how small a table can be). The best thing we
613 // can do is to set the width of child cells to zero
617 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
619 // this does two things: it recursively calls this code on all
620 // child contrainers and resets children's position to (0,0)
624 wxHtmlCell
*cell
= m_Cells
, *line
= m_Cells
;
625 long xpos
= 0, ypos
= m_IndentTop
;
626 int xdelta
= 0, ybasicpos
= 0, ydiff
;
627 int s_width
, s_indent
;
628 int ysizeup
= 0, ysizedown
= 0;
629 int MaxLineWidth
= 0;
639 if (m_WidthFloatUnits
== wxHTML_UNITS_PERCENT
)
641 if (m_WidthFloat
< 0) m_Width
= (100 + m_WidthFloat
) * w
/ 100;
642 else m_Width
= m_WidthFloat
* w
/ 100;
646 if (m_WidthFloat
< 0) m_Width
= w
+ m_WidthFloat
;
647 else m_Width
= m_WidthFloat
;
652 int l
= (m_IndentLeft
< 0) ? (-m_IndentLeft
* m_Width
/ 100) : m_IndentLeft
;
653 int r
= (m_IndentRight
< 0) ? (-m_IndentRight
* m_Width
/ 100) : m_IndentRight
;
654 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
655 cell
->Layout(m_Width
- (l
+ r
));
664 // adjust indentation:
665 s_indent
= (m_IndentLeft
< 0) ? (-m_IndentLeft
* m_Width
/ 100) : m_IndentLeft
;
666 s_width
= m_Width
- s_indent
- ((m_IndentRight
< 0) ? (-m_IndentRight
* m_Width
/ 100) : m_IndentRight
);
673 case wxHTML_ALIGN_TOP
: ybasicpos
= 0; break;
674 case wxHTML_ALIGN_BOTTOM
: ybasicpos
= - cell
->GetHeight(); break;
675 case wxHTML_ALIGN_CENTER
: ybasicpos
= - cell
->GetHeight() / 2; break;
677 ydiff
= cell
->GetHeight() + ybasicpos
;
679 if (cell
->GetDescent() + ydiff
> ysizedown
) ysizedown
= cell
->GetDescent() + ydiff
;
680 if (ybasicpos
+ cell
->GetDescent() < -ysizeup
) ysizeup
= - (ybasicpos
+ cell
->GetDescent());
682 cell
->SetPos(xpos
, ybasicpos
+ cell
->GetDescent());
683 xpos
+= cell
->GetWidth();
684 cell
= cell
->GetNext();
687 // force new line if occured:
688 if ((cell
== NULL
) || (xpos
+ cell
->GetWidth() > s_width
))
690 if (xpos
> MaxLineWidth
) MaxLineWidth
= xpos
;
691 if (ysizeup
< 0) ysizeup
= 0;
692 if (ysizedown
< 0) ysizedown
= 0;
693 switch (m_AlignHor
) {
694 case wxHTML_ALIGN_LEFT
:
695 case wxHTML_ALIGN_JUSTIFY
:
698 case wxHTML_ALIGN_RIGHT
:
699 xdelta
= 0 + (s_width
- xpos
);
701 case wxHTML_ALIGN_CENTER
:
702 xdelta
= 0 + (s_width
- xpos
) / 2;
705 if (xdelta
< 0) xdelta
= 0;
710 if (m_AlignHor
!= wxHTML_ALIGN_JUSTIFY
|| cell
== NULL
)
713 line
->SetPos(line
->GetPosX() + xdelta
,
714 ypos
+ line
->GetPosY());
715 line
= line
->GetNext();
720 int step
= (s_width
- xpos
);
721 if (step
< 0) step
= 0;
723 if (xcnt
> 0) while (line
!= cell
)
725 line
->SetPos(line
->GetPosX() + s_indent
+
726 (counter
++ * step
/ xcnt
),
727 ypos
+ line
->GetPosY());
728 line
= line
->GetNext();
735 ysizeup
= ysizedown
= 0;
740 // setup height & width, depending on container layout:
741 m_Height
= ypos
+ (ysizedown
+ ysizeup
) + m_IndentBottom
;
743 if (m_Height
< m_MinHeight
)
745 if (m_MinHeightAlign
!= wxHTML_ALIGN_TOP
)
747 int diff
= m_MinHeight
- m_Height
;
748 if (m_MinHeightAlign
== wxHTML_ALIGN_CENTER
) diff
/= 2;
752 cell
->SetPos(cell
->GetPosX(), cell
->GetPosY() + diff
);
753 cell
= cell
->GetNext();
756 m_Height
= m_MinHeight
;
759 MaxLineWidth
+= s_indent
+ ((m_IndentRight
< 0) ? (-m_IndentRight
* m_Width
/ 100) : m_IndentRight
);
760 if (m_Width
< MaxLineWidth
) m_Width
= MaxLineWidth
;
765 void wxHtmlContainerCell::UpdateRenderingStatePre(wxHtmlRenderingInfo
& info
,
766 wxHtmlCell
*cell
) const
768 wxHtmlSelection
*s
= info
.GetSelection();
770 if (s
->GetFromCell() == cell
|| s
->GetToCell() == cell
)
772 info
.GetState().SetSelectionState(wxHTML_SEL_CHANGING
);
776 void wxHtmlContainerCell::UpdateRenderingStatePost(wxHtmlRenderingInfo
& info
,
777 wxHtmlCell
*cell
) const
779 wxHtmlSelection
*s
= info
.GetSelection();
781 if (s
->GetToCell() == cell
)
782 info
.GetState().SetSelectionState(wxHTML_SEL_OUT
);
783 else if (s
->GetFromCell() == cell
)
784 info
.GetState().SetSelectionState(wxHTML_SEL_IN
);
787 #define mMin(a, b) (((a) < (b)) ? (a) : (b))
788 #define mMax(a, b) (((a) < (b)) ? (b) : (a))
790 void wxHtmlContainerCell::Draw(wxDC
& dc
, int x
, int y
, int view_y1
, int view_y2
,
791 wxHtmlRenderingInfo
& info
)
793 // container visible, draw it:
794 if ((y
+ m_PosY
<= view_y2
) && (y
+ m_PosY
+ m_Height
> view_y1
))
798 wxBrush myb
= wxBrush(m_BkColour
, wxSOLID
);
800 int real_y1
= mMax(y
+ m_PosY
, view_y1
);
801 int real_y2
= mMin(y
+ m_PosY
+ m_Height
- 1, view_y2
);
804 dc
.SetPen(*wxTRANSPARENT_PEN
);
805 dc
.DrawRectangle(x
+ m_PosX
, real_y1
, m_Width
, real_y2
- real_y1
+ 1);
810 wxPen
mypen1(m_BorderColour1
, 1, wxSOLID
);
811 wxPen
mypen2(m_BorderColour2
, 1, wxSOLID
);
814 dc
.DrawLine(x
+ m_PosX
, y
+ m_PosY
, x
+ m_PosX
, y
+ m_PosY
+ m_Height
- 1);
815 dc
.DrawLine(x
+ m_PosX
, y
+ m_PosY
, x
+ m_PosX
+ m_Width
, y
+ m_PosY
);
817 dc
.DrawLine(x
+ m_PosX
+ m_Width
- 1, y
+ m_PosY
, x
+ m_PosX
+ m_Width
- 1, y
+ m_PosY
+ m_Height
- 1);
818 dc
.DrawLine(x
+ m_PosX
, y
+ m_PosY
+ m_Height
- 1, x
+ m_PosX
+ m_Width
, y
+ m_PosY
+ m_Height
- 1);
823 // draw container's contents:
824 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
826 UpdateRenderingStatePre(info
, cell
);
828 x
+ m_PosX
, y
+ m_PosY
, view_y1
, view_y2
,
830 UpdateRenderingStatePost(info
, cell
);
834 // container invisible, just proceed font+color changing:
837 DrawInvisible(dc
, x
, y
, info
);
843 void wxHtmlContainerCell::DrawInvisible(wxDC
& dc
, int x
, int y
,
844 wxHtmlRenderingInfo
& info
)
848 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
850 UpdateRenderingStatePre(info
, cell
);
851 cell
->DrawInvisible(dc
, x
+ m_PosX
, y
+ m_PosY
, info
);
852 UpdateRenderingStatePost(info
, cell
);
858 wxColour
wxHtmlContainerCell::GetBackgroundColour()
868 wxHtmlLinkInfo
*wxHtmlContainerCell::GetLink(int x
, int y
) const
870 wxHtmlCell
*cell
= FindCellByPos(x
, y
);
872 // VZ: I don't know if we should pass absolute or relative coords to
873 // wxHtmlCell::GetLink()? As the base class version just ignores them
874 // anyhow, it hardly matters right now but should still be clarified
875 return cell
? cell
->GetLink(x
, y
) : NULL
;
880 void wxHtmlContainerCell::InsertCell(wxHtmlCell
*f
)
882 if (!m_Cells
) m_Cells
= m_LastCell
= f
;
885 m_LastCell
->SetNext(f
);
887 if (m_LastCell
) while (m_LastCell
->GetNext()) m_LastCell
= m_LastCell
->GetNext();
895 void wxHtmlContainerCell::SetAlign(const wxHtmlTag
& tag
)
897 if (tag
.HasParam(wxT("ALIGN")))
899 wxString alg
= tag
.GetParam(wxT("ALIGN"));
901 if (alg
== wxT("CENTER"))
902 SetAlignHor(wxHTML_ALIGN_CENTER
);
903 else if (alg
== wxT("LEFT"))
904 SetAlignHor(wxHTML_ALIGN_LEFT
);
905 else if (alg
== wxT("JUSTIFY"))
906 SetAlignHor(wxHTML_ALIGN_JUSTIFY
);
907 else if (alg
== wxT("RIGHT"))
908 SetAlignHor(wxHTML_ALIGN_RIGHT
);
915 void wxHtmlContainerCell::SetWidthFloat(const wxHtmlTag
& tag
, double pixel_scale
)
917 if (tag
.HasParam(wxT("WIDTH")))
920 wxString wd
= tag
.GetParam(wxT("WIDTH"));
922 if (wd
[wd
.Length()-1] == wxT('%'))
924 wxSscanf(wd
.c_str(), wxT("%i%%"), &wdi
);
925 SetWidthFloat(wdi
, wxHTML_UNITS_PERCENT
);
929 wxSscanf(wd
.c_str(), wxT("%i"), &wdi
);
930 SetWidthFloat((int)(pixel_scale
* (double)wdi
), wxHTML_UNITS_PIXELS
);
938 const wxHtmlCell
* wxHtmlContainerCell::Find(int condition
, const void* param
) const
942 const wxHtmlCell
*r
= NULL
;
944 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
946 r
= cell
->Find(condition
, param
);
954 wxHtmlCell
*wxHtmlContainerCell::FindCellByPos(wxCoord x
, wxCoord y
,
955 unsigned flags
) const
957 if ( flags
& wxHTML_FIND_EXACT
)
959 for ( const wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext() )
961 int cx
= cell
->GetPosX(),
962 cy
= cell
->GetPosY();
964 if ( (cx
<= x
) && (cx
+ cell
->GetWidth() > x
) &&
965 (cy
<= y
) && (cy
+ cell
->GetHeight() > y
) )
967 return cell
->FindCellByPos(x
- cx
, y
- cy
, flags
);
971 else if ( flags
& wxHTML_FIND_NEAREST_AFTER
)
975 for ( const wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext() )
977 y2
= cell
->GetPosY() + cell
->GetHeight() - 1;
978 if (y2
< y
|| (y2
== y
&& cell
->GetPosX()+cell
->GetWidth()-1 < x
))
980 c
= cell
->FindCellByPos(x
- cell
->GetPosX(), y
- cell
->GetPosY(),
985 else if ( flags
& wxHTML_FIND_NEAREST_BEFORE
)
987 wxHtmlCell
*c2
, *c
= NULL
;
988 for ( const wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext() )
990 if (cell
->GetPosY() > y
||
991 (cell
->GetPosY() == y
&& cell
->GetPosX() > x
))
993 c2
= cell
->FindCellByPos(x
- cell
->GetPosX(), y
- cell
->GetPosY(),
1005 void wxHtmlContainerCell::OnMouseClick(wxWindow
*parent
, int x
, int y
, const wxMouseEvent
& event
)
1007 wxHtmlCell
*cell
= FindCellByPos(x
, y
);
1009 cell
->OnMouseClick(parent
, x
, y
, event
);
1014 void wxHtmlContainerCell::GetHorizontalConstraints(int *left
, int *right
) const
1016 int cleft
= m_PosX
+ m_Width
, cright
= m_PosX
; // worst case
1019 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
1021 cell
->GetHorizontalConstraints(&l
, &r
);
1028 cleft
-= (m_IndentLeft
< 0) ? (-m_IndentLeft
* m_Width
/ 100) : m_IndentLeft
;
1029 cright
+= (m_IndentRight
< 0) ? (-m_IndentRight
* m_Width
/ 100) : m_IndentRight
;
1038 wxHtmlCell
*wxHtmlContainerCell::GetFirstTerminal() const
1043 for (wxHtmlCell
*c
= m_Cells
; c
; c
= c
->GetNext())
1045 c2
= c
->GetFirstTerminal();
1053 wxHtmlCell
*wxHtmlContainerCell::GetLastTerminal() const
1057 // most common case first:
1058 wxHtmlCell
*c
= m_LastCell
->GetLastTerminal();
1062 wxHtmlCell
*c2
= NULL
;
1063 for (c
= m_Cells
; c
; c
= c
->GetNext())
1064 c2
= c
->GetLastTerminal();
1074 // --------------------------------------------------------------------------
1076 // --------------------------------------------------------------------------
1078 void wxHtmlColourCell::Draw(wxDC
& dc
,
1080 int WXUNUSED(view_y1
), int WXUNUSED(view_y2
),
1081 wxHtmlRenderingInfo
& info
)
1083 DrawInvisible(dc
, x
, y
, info
);
1086 void wxHtmlColourCell::DrawInvisible(wxDC
& dc
,
1087 int WXUNUSED(x
), int WXUNUSED(y
),
1088 wxHtmlRenderingInfo
& info
)
1090 wxHtmlRenderingState
& state
= info
.GetState();
1091 if (m_Flags
& wxHTML_CLR_FOREGROUND
)
1093 state
.SetFgColour(m_Colour
);
1094 if (state
.GetSelectionState() != wxHTML_SEL_IN
)
1095 dc
.SetTextForeground(m_Colour
);
1097 dc
.SetTextForeground(
1098 info
.GetStyle().GetSelectedTextColour(m_Colour
));
1100 if (m_Flags
& wxHTML_CLR_BACKGROUND
)
1102 state
.SetBgColour(m_Colour
);
1103 if (state
.GetSelectionState() != wxHTML_SEL_IN
)
1105 dc
.SetTextBackground(m_Colour
);
1106 dc
.SetBackground(wxBrush(m_Colour
, wxSOLID
));
1110 wxColour c
= info
.GetStyle().GetSelectedTextBgColour(m_Colour
);
1111 dc
.SetTextBackground(c
);
1112 dc
.SetBackground(wxBrush(c
, wxSOLID
));
1120 // ---------------------------------------------------------------------------
1122 // ---------------------------------------------------------------------------
1124 void wxHtmlFontCell::Draw(wxDC
& dc
,
1125 int WXUNUSED(x
), int WXUNUSED(y
),
1126 int WXUNUSED(view_y1
), int WXUNUSED(view_y2
),
1127 wxHtmlRenderingInfo
& WXUNUSED(info
))
1132 void wxHtmlFontCell::DrawInvisible(wxDC
& dc
, int WXUNUSED(x
), int WXUNUSED(y
),
1133 wxHtmlRenderingInfo
& WXUNUSED(info
))
1145 // ---------------------------------------------------------------------------
1147 // ---------------------------------------------------------------------------
1149 wxHtmlWidgetCell::wxHtmlWidgetCell(wxWindow
*wnd
, int w
)
1153 m_Wnd
->GetSize(&sx
, &sy
);
1154 m_Width
= sx
, m_Height
= sy
;
1159 void wxHtmlWidgetCell::Draw(wxDC
& WXUNUSED(dc
),
1160 int WXUNUSED(x
), int WXUNUSED(y
),
1161 int WXUNUSED(view_y1
), int WXUNUSED(view_y2
),
1162 wxHtmlRenderingInfo
& WXUNUSED(info
))
1164 int absx
= 0, absy
= 0, stx
, sty
;
1165 wxHtmlCell
*c
= this;
1169 absx
+= c
->GetPosX();
1170 absy
+= c
->GetPosY();
1174 ((wxScrolledWindow
*)(m_Wnd
->GetParent()))->GetViewStart(&stx
, &sty
);
1175 m_Wnd
->SetSize(absx
- wxHTML_SCROLL_STEP
* stx
, absy
- wxHTML_SCROLL_STEP
* sty
, m_Width
, m_Height
);
1180 void wxHtmlWidgetCell::DrawInvisible(wxDC
& WXUNUSED(dc
),
1181 int WXUNUSED(x
), int WXUNUSED(y
),
1182 wxHtmlRenderingInfo
& WXUNUSED(info
))
1184 int absx
= 0, absy
= 0, stx
, sty
;
1185 wxHtmlCell
*c
= this;
1189 absx
+= c
->GetPosX();
1190 absy
+= c
->GetPosY();
1194 ((wxScrolledWindow
*)(m_Wnd
->GetParent()))->GetViewStart(&stx
, &sty
);
1195 m_Wnd
->SetSize(absx
- wxHTML_SCROLL_STEP
* stx
, absy
- wxHTML_SCROLL_STEP
* sty
, m_Width
, m_Height
);
1200 void wxHtmlWidgetCell::Layout(int w
)
1202 if (m_WidthFloat
!= 0)
1204 m_Width
= (w
* m_WidthFloat
) / 100;
1205 m_Wnd
->SetSize(m_Width
, m_Height
);
1208 wxHtmlCell::Layout(w
);
1213 // ----------------------------------------------------------------------------
1214 // wxHtmlTerminalCellsInterator
1215 // ----------------------------------------------------------------------------
1217 const wxHtmlCell
* wxHtmlTerminalCellsInterator::operator++()
1224 if ( m_pos
== m_to
)
1230 if ( m_pos
->GetNext() )
1231 m_pos
= m_pos
->GetNext();
1234 // we must go up the hierarchy until we reach container where this
1235 // is not the last child, and then go down to first terminal cell:
1236 while ( m_pos
->GetNext() == NULL
)
1238 m_pos
= m_pos
->GetParent();
1242 m_pos
= m_pos
->GetNext();
1244 while ( m_pos
->GetFirstChild() != NULL
)
1245 m_pos
= m_pos
->GetFirstChild();
1246 } while ( !m_pos
->IsTerminalCell() );
1257 //-----------------------------------------------------------------------------
1259 //-----------------------------------------------------------------------------
1261 class wxHtmlCellModule
: public wxModule
1263 DECLARE_DYNAMIC_CLASS(wxHtmlCellModule
)
1265 wxHtmlCellModule() : wxModule() {}
1266 bool OnInit() { return true; }
1269 wxDELETE(gs_cursorLink
);
1270 wxDELETE(gs_cursorText
);
1274 IMPLEMENT_DYNAMIC_CLASS(wxHtmlCellModule
, wxModule
)