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
));
355 dc
.SetBackgroundMode(wxTRANSPARENT
);
356 dc
.SetTextForeground(fg
);
357 dc
.SetTextBackground(bg
);
362 void wxHtmlWordCell::Draw(wxDC
& dc
, int x
, int y
,
363 int WXUNUSED(view_y1
), int WXUNUSED(view_y2
),
364 wxHtmlRenderingInfo
& info
)
366 #if 0 // useful for debugging
367 dc
.DrawRectangle(x
+m_PosX
,y
+m_PosY
,m_Width
,m_Height
);
370 if ( info
.GetState().GetSelectionState() == wxHTML_SEL_CHANGING
)
372 // Selection changing, we must draw the word piecewise:
373 wxHtmlSelection
*s
= info
.GetSelection();
378 wxPoint priv
= (this == s
->GetFromCell()) ?
379 s
->GetFromPrivPos() : s
->GetToPrivPos();
381 // NB: this is quite a hack: in order to compute selection boundaries
382 // (in word's characters) we must know current font, which is only
383 // possible inside rendering code. Therefore we update the
384 // information here and store it in wxHtmlSelection so that
385 // ConvertToText can use it later:
386 if ( priv
== wxDefaultPosition
)
388 SetSelectionPrivPos(dc
, s
);
389 priv
= (this == s
->GetFromCell()) ?
390 s
->GetFromPrivPos() : s
->GetToPrivPos();
398 txt
= m_Word
.Mid(0, part1
);
399 dc
.DrawText(txt
, x
+ m_PosX
, y
+ m_PosY
);
400 dc
.GetTextExtent(txt
, &w
, &h
);
404 SwitchSelState(dc
, info
, true);
406 txt
= m_Word
.Mid(part1
, part2
-part1
);
407 dc
.DrawText(txt
, ofs
+ x
+ m_PosX
, y
+ m_PosY
);
409 if ( (size_t)part2
< m_Word
.length() )
411 dc
.GetTextExtent(txt
, &w
, &h
);
413 SwitchSelState(dc
, info
, false);
414 txt
= m_Word
.Mid(part2
);
415 dc
.DrawText(txt
, ofs
+ x
+ m_PosX
, y
+ m_PosY
);
420 // Not changing selection state, draw the word in single mode:
422 if ( info
.GetState().GetSelectionState() != wxHTML_SEL_OUT
&&
423 dc
.GetBackgroundMode() != wxSOLID
)
425 SwitchSelState(dc
, info
, true);
427 else if ( info
.GetState().GetSelectionState() == wxHTML_SEL_OUT
&&
428 dc
.GetBackgroundMode() == wxSOLID
)
430 SwitchSelState(dc
, info
, false);
432 dc
.DrawText(m_Word
, x
+ m_PosX
, y
+ m_PosY
);
437 wxString
wxHtmlWordCell::ConvertToText(wxHtmlSelection
*s
) const
439 if ( s
&& (this == s
->GetFromCell() || this == s
->GetToCell()) )
441 wxPoint priv
= this == s
->GetFromCell() ? s
->GetFromPrivPos()
444 // VZ: we may be called before we had a chance to re-render ourselves
445 // and in this case GetFrom/ToPrivPos() is not set yet -- assume
446 // that this only happens in case of a double/triple click (which
447 // seems to be the case now) and so it makes sense to select the
448 // entire contents of the cell in this case
450 // TODO: but this really needs to be fixed in some better way later...
451 if ( priv
!= wxDefaultPosition
)
455 return m_Word
.Mid(part1
, part2
-part1
);
457 //else: return the whole word below
463 wxCursor
wxHtmlWordCell::GetCursor() const
467 if ( !gs_cursorText
)
468 gs_cursorText
= new wxCursor(wxCURSOR_IBEAM
);
469 return *gs_cursorText
;
472 return wxHtmlCell::GetCursor();
476 //-----------------------------------------------------------------------------
477 // wxHtmlContainerCell
478 //-----------------------------------------------------------------------------
481 wxHtmlContainerCell::wxHtmlContainerCell(wxHtmlContainerCell
*parent
) : wxHtmlCell()
483 m_Cells
= m_LastCell
= NULL
;
485 if (m_Parent
) m_Parent
->InsertCell(this);
486 m_AlignHor
= wxHTML_ALIGN_LEFT
;
487 m_AlignVer
= wxHTML_ALIGN_BOTTOM
;
488 m_IndentLeft
= m_IndentRight
= m_IndentTop
= m_IndentBottom
= 0;
489 m_WidthFloat
= 100; m_WidthFloatUnits
= wxHTML_UNITS_PERCENT
;
490 m_UseBkColour
= FALSE
;
493 m_MinHeightAlign
= wxHTML_ALIGN_TOP
;
497 wxHtmlContainerCell::~wxHtmlContainerCell()
499 wxHtmlCell
*cell
= m_Cells
;
502 wxHtmlCell
*cellNext
= cell
->GetNext();
510 void wxHtmlContainerCell::SetIndent(int i
, int what
, int units
)
512 int val
= (units
== wxHTML_UNITS_PIXELS
) ? i
: -i
;
513 if (what
& wxHTML_INDENT_LEFT
) m_IndentLeft
= val
;
514 if (what
& wxHTML_INDENT_RIGHT
) m_IndentRight
= val
;
515 if (what
& wxHTML_INDENT_TOP
) m_IndentTop
= val
;
516 if (what
& wxHTML_INDENT_BOTTOM
) m_IndentBottom
= val
;
522 int wxHtmlContainerCell::GetIndent(int ind
) const
524 if (ind
& wxHTML_INDENT_LEFT
) return m_IndentLeft
;
525 else if (ind
& wxHTML_INDENT_RIGHT
) return m_IndentRight
;
526 else if (ind
& wxHTML_INDENT_TOP
) return m_IndentTop
;
527 else if (ind
& wxHTML_INDENT_BOTTOM
) return m_IndentBottom
;
528 else return -1; /* BUG! Should not be called... */
534 int wxHtmlContainerCell::GetIndentUnits(int ind
) const
537 if (ind
& wxHTML_INDENT_LEFT
) p
= m_IndentLeft
< 0;
538 else if (ind
& wxHTML_INDENT_RIGHT
) p
= m_IndentRight
< 0;
539 else if (ind
& wxHTML_INDENT_TOP
) p
= m_IndentTop
< 0;
540 else if (ind
& wxHTML_INDENT_BOTTOM
) p
= m_IndentBottom
< 0;
541 if (p
) return wxHTML_UNITS_PERCENT
;
542 else return wxHTML_UNITS_PIXELS
;
547 bool wxHtmlContainerCell::AdjustPagebreak(int *pagebreak
, int* known_pagebreaks
, int number_of_pages
) const
549 if (!m_CanLiveOnPagebreak
)
550 return wxHtmlCell::AdjustPagebreak(pagebreak
, known_pagebreaks
, number_of_pages
);
554 wxHtmlCell
*c
= GetFirstChild();
556 int pbrk
= *pagebreak
- m_PosY
;
560 if (c
->AdjustPagebreak(&pbrk
, known_pagebreaks
, number_of_pages
))
565 *pagebreak
= pbrk
+ m_PosY
;
572 void wxHtmlContainerCell::Layout(int w
)
574 wxHtmlCell::Layout(w
);
576 if (m_LastLayout
== w
) return;
578 // VS: Any attempt to layout with negative or zero width leads to hell,
579 // but we can't ignore such attempts completely, since it sometimes
580 // happen (e.g. when trying how small a table can be). The best thing we
581 // can do is to set the width of child cells to zero
585 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
587 // this does two things: it recursively calls this code on all
588 // child contrainers and resets children's position to (0,0)
592 wxHtmlCell
*cell
= m_Cells
, *line
= m_Cells
;
593 long xpos
= 0, ypos
= m_IndentTop
;
594 int xdelta
= 0, ybasicpos
= 0, ydiff
;
595 int s_width
, s_indent
;
596 int ysizeup
= 0, ysizedown
= 0;
597 int MaxLineWidth
= 0;
607 if (m_WidthFloatUnits
== wxHTML_UNITS_PERCENT
)
609 if (m_WidthFloat
< 0) m_Width
= (100 + m_WidthFloat
) * w
/ 100;
610 else m_Width
= m_WidthFloat
* w
/ 100;
614 if (m_WidthFloat
< 0) m_Width
= w
+ m_WidthFloat
;
615 else m_Width
= m_WidthFloat
;
620 int l
= (m_IndentLeft
< 0) ? (-m_IndentLeft
* m_Width
/ 100) : m_IndentLeft
;
621 int r
= (m_IndentRight
< 0) ? (-m_IndentRight
* m_Width
/ 100) : m_IndentRight
;
622 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
623 cell
->Layout(m_Width
- (l
+ r
));
632 // adjust indentation:
633 s_indent
= (m_IndentLeft
< 0) ? (-m_IndentLeft
* m_Width
/ 100) : m_IndentLeft
;
634 s_width
= m_Width
- s_indent
- ((m_IndentRight
< 0) ? (-m_IndentRight
* m_Width
/ 100) : m_IndentRight
);
641 case wxHTML_ALIGN_TOP
: ybasicpos
= 0; break;
642 case wxHTML_ALIGN_BOTTOM
: ybasicpos
= - cell
->GetHeight(); break;
643 case wxHTML_ALIGN_CENTER
: ybasicpos
= - cell
->GetHeight() / 2; break;
645 ydiff
= cell
->GetHeight() + ybasicpos
;
647 if (cell
->GetDescent() + ydiff
> ysizedown
) ysizedown
= cell
->GetDescent() + ydiff
;
648 if (ybasicpos
+ cell
->GetDescent() < -ysizeup
) ysizeup
= - (ybasicpos
+ cell
->GetDescent());
650 cell
->SetPos(xpos
, ybasicpos
+ cell
->GetDescent());
651 xpos
+= cell
->GetWidth();
652 cell
= cell
->GetNext();
655 // force new line if occured:
656 if ((cell
== NULL
) || (xpos
+ cell
->GetWidth() > s_width
))
658 if (xpos
> MaxLineWidth
) MaxLineWidth
= xpos
;
659 if (ysizeup
< 0) ysizeup
= 0;
660 if (ysizedown
< 0) ysizedown
= 0;
661 switch (m_AlignHor
) {
662 case wxHTML_ALIGN_LEFT
:
663 case wxHTML_ALIGN_JUSTIFY
:
666 case wxHTML_ALIGN_RIGHT
:
667 xdelta
= 0 + (s_width
- xpos
);
669 case wxHTML_ALIGN_CENTER
:
670 xdelta
= 0 + (s_width
- xpos
) / 2;
673 if (xdelta
< 0) xdelta
= 0;
678 if (m_AlignHor
!= wxHTML_ALIGN_JUSTIFY
|| cell
== NULL
)
681 line
->SetPos(line
->GetPosX() + xdelta
,
682 ypos
+ line
->GetPosY());
683 line
= line
->GetNext();
688 int step
= (s_width
- xpos
);
689 if (step
< 0) step
= 0;
691 if (xcnt
> 0) while (line
!= cell
)
693 line
->SetPos(line
->GetPosX() + s_indent
+
694 (counter
++ * step
/ xcnt
),
695 ypos
+ line
->GetPosY());
696 line
= line
->GetNext();
703 ysizeup
= ysizedown
= 0;
708 // setup height & width, depending on container layout:
709 m_Height
= ypos
+ (ysizedown
+ ysizeup
) + m_IndentBottom
;
711 if (m_Height
< m_MinHeight
)
713 if (m_MinHeightAlign
!= wxHTML_ALIGN_TOP
)
715 int diff
= m_MinHeight
- m_Height
;
716 if (m_MinHeightAlign
== wxHTML_ALIGN_CENTER
) diff
/= 2;
720 cell
->SetPos(cell
->GetPosX(), cell
->GetPosY() + diff
);
721 cell
= cell
->GetNext();
724 m_Height
= m_MinHeight
;
727 MaxLineWidth
+= s_indent
+ ((m_IndentRight
< 0) ? (-m_IndentRight
* m_Width
/ 100) : m_IndentRight
);
728 if (m_Width
< MaxLineWidth
) m_Width
= MaxLineWidth
;
733 void wxHtmlContainerCell::UpdateRenderingStatePre(wxHtmlRenderingInfo
& info
,
734 wxHtmlCell
*cell
) const
736 wxHtmlSelection
*s
= info
.GetSelection();
738 if (s
->GetFromCell() == cell
|| s
->GetToCell() == cell
)
740 info
.GetState().SetSelectionState(wxHTML_SEL_CHANGING
);
744 void wxHtmlContainerCell::UpdateRenderingStatePost(wxHtmlRenderingInfo
& info
,
745 wxHtmlCell
*cell
) const
747 wxHtmlSelection
*s
= info
.GetSelection();
749 if (s
->GetToCell() == cell
)
750 info
.GetState().SetSelectionState(wxHTML_SEL_OUT
);
751 else if (s
->GetFromCell() == cell
)
752 info
.GetState().SetSelectionState(wxHTML_SEL_IN
);
755 #define mMin(a, b) (((a) < (b)) ? (a) : (b))
756 #define mMax(a, b) (((a) < (b)) ? (b) : (a))
758 void wxHtmlContainerCell::Draw(wxDC
& dc
, int x
, int y
, int view_y1
, int view_y2
,
759 wxHtmlRenderingInfo
& info
)
761 // container visible, draw it:
762 if ((y
+ m_PosY
<= view_y2
) && (y
+ m_PosY
+ m_Height
> view_y1
))
766 wxBrush myb
= wxBrush(m_BkColour
, wxSOLID
);
768 int real_y1
= mMax(y
+ m_PosY
, view_y1
);
769 int real_y2
= mMin(y
+ m_PosY
+ m_Height
- 1, view_y2
);
772 dc
.SetPen(*wxTRANSPARENT_PEN
);
773 dc
.DrawRectangle(x
+ m_PosX
, real_y1
, m_Width
, real_y2
- real_y1
+ 1);
778 wxPen
mypen1(m_BorderColour1
, 1, wxSOLID
);
779 wxPen
mypen2(m_BorderColour2
, 1, wxSOLID
);
782 dc
.DrawLine(x
+ m_PosX
, y
+ m_PosY
, x
+ m_PosX
, y
+ m_PosY
+ m_Height
- 1);
783 dc
.DrawLine(x
+ m_PosX
, y
+ m_PosY
, x
+ m_PosX
+ m_Width
, y
+ m_PosY
);
785 dc
.DrawLine(x
+ m_PosX
+ m_Width
- 1, y
+ m_PosY
, x
+ m_PosX
+ m_Width
- 1, y
+ m_PosY
+ m_Height
- 1);
786 dc
.DrawLine(x
+ m_PosX
, y
+ m_PosY
+ m_Height
- 1, x
+ m_PosX
+ m_Width
, y
+ m_PosY
+ m_Height
- 1);
791 // draw container's contents:
792 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
794 UpdateRenderingStatePre(info
, cell
);
796 x
+ m_PosX
, y
+ m_PosY
, view_y1
, view_y2
,
798 UpdateRenderingStatePost(info
, cell
);
802 // container invisible, just proceed font+color changing:
805 DrawInvisible(dc
, x
, y
, info
);
811 void wxHtmlContainerCell::DrawInvisible(wxDC
& dc
, int x
, int y
,
812 wxHtmlRenderingInfo
& info
)
816 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
818 UpdateRenderingStatePre(info
, cell
);
819 cell
->DrawInvisible(dc
, x
+ m_PosX
, y
+ m_PosY
, info
);
820 UpdateRenderingStatePost(info
, cell
);
826 wxColour
wxHtmlContainerCell::GetBackgroundColour()
836 wxHtmlLinkInfo
*wxHtmlContainerCell::GetLink(int x
, int y
) const
838 wxHtmlCell
*cell
= FindCellByPos(x
, y
);
840 // VZ: I don't know if we should pass absolute or relative coords to
841 // wxHtmlCell::GetLink()? As the base class version just ignores them
842 // anyhow, it hardly matters right now but should still be clarified
843 return cell
? cell
->GetLink(x
, y
) : NULL
;
848 void wxHtmlContainerCell::InsertCell(wxHtmlCell
*f
)
850 if (!m_Cells
) m_Cells
= m_LastCell
= f
;
853 m_LastCell
->SetNext(f
);
855 if (m_LastCell
) while (m_LastCell
->GetNext()) m_LastCell
= m_LastCell
->GetNext();
863 void wxHtmlContainerCell::SetAlign(const wxHtmlTag
& tag
)
865 if (tag
.HasParam(wxT("ALIGN")))
867 wxString alg
= tag
.GetParam(wxT("ALIGN"));
869 if (alg
== wxT("CENTER"))
870 SetAlignHor(wxHTML_ALIGN_CENTER
);
871 else if (alg
== wxT("LEFT"))
872 SetAlignHor(wxHTML_ALIGN_LEFT
);
873 else if (alg
== wxT("JUSTIFY"))
874 SetAlignHor(wxHTML_ALIGN_JUSTIFY
);
875 else if (alg
== wxT("RIGHT"))
876 SetAlignHor(wxHTML_ALIGN_RIGHT
);
883 void wxHtmlContainerCell::SetWidthFloat(const wxHtmlTag
& tag
, double pixel_scale
)
885 if (tag
.HasParam(wxT("WIDTH")))
888 wxString wd
= tag
.GetParam(wxT("WIDTH"));
890 if (wd
[wd
.Length()-1] == wxT('%'))
892 wxSscanf(wd
.c_str(), wxT("%i%%"), &wdi
);
893 SetWidthFloat(wdi
, wxHTML_UNITS_PERCENT
);
897 wxSscanf(wd
.c_str(), wxT("%i"), &wdi
);
898 SetWidthFloat((int)(pixel_scale
* (double)wdi
), wxHTML_UNITS_PIXELS
);
906 const wxHtmlCell
* wxHtmlContainerCell::Find(int condition
, const void* param
) const
910 const wxHtmlCell
*r
= NULL
;
912 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
914 r
= cell
->Find(condition
, param
);
922 wxHtmlCell
*wxHtmlContainerCell::FindCellByPos(wxCoord x
, wxCoord y
,
923 unsigned flags
) const
925 if ( flags
& wxHTML_FIND_EXACT
)
927 for ( const wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext() )
929 int cx
= cell
->GetPosX(),
930 cy
= cell
->GetPosY();
932 if ( (cx
<= x
) && (cx
+ cell
->GetWidth() > x
) &&
933 (cy
<= y
) && (cy
+ cell
->GetHeight() > y
) )
935 return cell
->FindCellByPos(x
- cx
, y
- cy
, flags
);
939 else if ( flags
& wxHTML_FIND_NEAREST_AFTER
)
943 for ( const wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext() )
945 y2
= cell
->GetPosY() + cell
->GetHeight() - 1;
946 if (y2
< y
|| (y2
== y
&& cell
->GetPosX()+cell
->GetWidth()-1 < x
))
948 c
= cell
->FindCellByPos(x
- cell
->GetPosX(), y
- cell
->GetPosY(),
953 else if ( flags
& wxHTML_FIND_NEAREST_BEFORE
)
955 wxHtmlCell
*c2
, *c
= NULL
;
956 for ( const wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext() )
958 if (cell
->GetPosY() > y
||
959 (cell
->GetPosY() == y
&& cell
->GetPosX() > x
))
961 c2
= cell
->FindCellByPos(x
- cell
->GetPosX(), y
- cell
->GetPosY(),
973 void wxHtmlContainerCell::OnMouseClick(wxWindow
*parent
, int x
, int y
, const wxMouseEvent
& event
)
975 wxHtmlCell
*cell
= FindCellByPos(x
, y
);
977 cell
->OnMouseClick(parent
, x
, y
, event
);
982 void wxHtmlContainerCell::GetHorizontalConstraints(int *left
, int *right
) const
984 int cleft
= m_PosX
+ m_Width
, cright
= m_PosX
; // worst case
987 for (wxHtmlCell
*cell
= m_Cells
; cell
; cell
= cell
->GetNext())
989 cell
->GetHorizontalConstraints(&l
, &r
);
996 cleft
-= (m_IndentLeft
< 0) ? (-m_IndentLeft
* m_Width
/ 100) : m_IndentLeft
;
997 cright
+= (m_IndentRight
< 0) ? (-m_IndentRight
* m_Width
/ 100) : m_IndentRight
;
1006 wxHtmlCell
*wxHtmlContainerCell::GetFirstTerminal() const
1011 for (wxHtmlCell
*c
= m_Cells
; c
; c
= c
->GetNext())
1013 c2
= c
->GetFirstTerminal();
1021 wxHtmlCell
*wxHtmlContainerCell::GetLastTerminal() const
1025 // most common case first:
1026 wxHtmlCell
*c
= m_LastCell
->GetLastTerminal();
1030 wxHtmlCell
*c2
= NULL
;
1031 for (c
= m_Cells
; c
; c
= c
->GetNext())
1032 c2
= c
->GetLastTerminal();
1042 // --------------------------------------------------------------------------
1044 // --------------------------------------------------------------------------
1046 void wxHtmlColourCell::Draw(wxDC
& dc
,
1048 int WXUNUSED(view_y1
), int WXUNUSED(view_y2
),
1049 wxHtmlRenderingInfo
& info
)
1051 DrawInvisible(dc
, x
, y
, info
);
1054 void wxHtmlColourCell::DrawInvisible(wxDC
& dc
,
1055 int WXUNUSED(x
), int WXUNUSED(y
),
1056 wxHtmlRenderingInfo
& info
)
1058 wxHtmlRenderingState
& state
= info
.GetState();
1059 if (m_Flags
& wxHTML_CLR_FOREGROUND
)
1061 state
.SetFgColour(m_Colour
);
1062 if (state
.GetSelectionState() != wxHTML_SEL_IN
)
1063 dc
.SetTextForeground(m_Colour
);
1065 dc
.SetTextForeground(
1066 info
.GetStyle().GetSelectedTextColour(m_Colour
));
1068 if (m_Flags
& wxHTML_CLR_BACKGROUND
)
1070 state
.SetBgColour(m_Colour
);
1071 if (state
.GetSelectionState() != wxHTML_SEL_IN
)
1072 dc
.SetTextBackground(m_Colour
);
1074 dc
.SetTextBackground(
1075 info
.GetStyle().GetSelectedTextBgColour(m_Colour
));
1076 dc
.SetBackground(wxBrush(m_Colour
, wxSOLID
));
1083 // ---------------------------------------------------------------------------
1085 // ---------------------------------------------------------------------------
1087 void wxHtmlFontCell::Draw(wxDC
& dc
,
1088 int WXUNUSED(x
), int WXUNUSED(y
),
1089 int WXUNUSED(view_y1
), int WXUNUSED(view_y2
),
1090 wxHtmlRenderingInfo
& WXUNUSED(info
))
1095 void wxHtmlFontCell::DrawInvisible(wxDC
& dc
, int WXUNUSED(x
), int WXUNUSED(y
),
1096 wxHtmlRenderingInfo
& WXUNUSED(info
))
1108 // ---------------------------------------------------------------------------
1110 // ---------------------------------------------------------------------------
1112 wxHtmlWidgetCell::wxHtmlWidgetCell(wxWindow
*wnd
, int w
)
1116 m_Wnd
->GetSize(&sx
, &sy
);
1117 m_Width
= sx
, m_Height
= sy
;
1122 void wxHtmlWidgetCell::Draw(wxDC
& WXUNUSED(dc
),
1123 int WXUNUSED(x
), int WXUNUSED(y
),
1124 int WXUNUSED(view_y1
), int WXUNUSED(view_y2
),
1125 wxHtmlRenderingInfo
& WXUNUSED(info
))
1127 int absx
= 0, absy
= 0, stx
, sty
;
1128 wxHtmlCell
*c
= this;
1132 absx
+= c
->GetPosX();
1133 absy
+= c
->GetPosY();
1137 ((wxScrolledWindow
*)(m_Wnd
->GetParent()))->GetViewStart(&stx
, &sty
);
1138 m_Wnd
->SetSize(absx
- wxHTML_SCROLL_STEP
* stx
, absy
- wxHTML_SCROLL_STEP
* sty
, m_Width
, m_Height
);
1143 void wxHtmlWidgetCell::DrawInvisible(wxDC
& WXUNUSED(dc
),
1144 int WXUNUSED(x
), int WXUNUSED(y
),
1145 wxHtmlRenderingInfo
& WXUNUSED(info
))
1147 int absx
= 0, absy
= 0, stx
, sty
;
1148 wxHtmlCell
*c
= this;
1152 absx
+= c
->GetPosX();
1153 absy
+= c
->GetPosY();
1157 ((wxScrolledWindow
*)(m_Wnd
->GetParent()))->GetViewStart(&stx
, &sty
);
1158 m_Wnd
->SetSize(absx
- wxHTML_SCROLL_STEP
* stx
, absy
- wxHTML_SCROLL_STEP
* sty
, m_Width
, m_Height
);
1163 void wxHtmlWidgetCell::Layout(int w
)
1165 if (m_WidthFloat
!= 0)
1167 m_Width
= (w
* m_WidthFloat
) / 100;
1168 m_Wnd
->SetSize(m_Width
, m_Height
);
1171 wxHtmlCell::Layout(w
);
1176 // ----------------------------------------------------------------------------
1177 // wxHtmlTerminalCellsInterator
1178 // ----------------------------------------------------------------------------
1180 const wxHtmlCell
* wxHtmlTerminalCellsInterator::operator++()
1187 if ( m_pos
== m_to
)
1193 if ( m_pos
->GetNext() )
1194 m_pos
= m_pos
->GetNext();
1197 // we must go up the hierarchy until we reach container where this
1198 // is not the last child, and then go down to first terminal cell:
1199 while ( m_pos
->GetNext() == NULL
)
1201 m_pos
= m_pos
->GetParent();
1205 m_pos
= m_pos
->GetNext();
1207 while ( m_pos
->GetFirstChild() != NULL
)
1208 m_pos
= m_pos
->GetFirstChild();
1209 } while ( !m_pos
->IsTerminalCell() );
1220 //-----------------------------------------------------------------------------
1222 //-----------------------------------------------------------------------------
1224 class wxHtmlCellModule
: public wxModule
1226 DECLARE_DYNAMIC_CLASS(wxHtmlCellModule
)
1228 wxHtmlCellModule() : wxModule() {}
1229 bool OnInit() { return true; }
1232 wxDELETE(gs_cursorLink
);
1233 wxDELETE(gs_cursorText
);
1237 IMPLEMENT_DYNAMIC_CLASS(wxHtmlCellModule
, wxModule
)