X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3103e8a97e834e9793f0eb149aa82a99fd64ef9a..7ea1c917764fb2588fe1aadc75c49ba300f8cb2f:/src/html/htmlcell.cpp diff --git a/src/html/htmlcell.cpp b/src/html/htmlcell.cpp index 9a8a34aeb3..114097e2fa 100644 --- a/src/html/htmlcell.cpp +++ b/src/html/htmlcell.cpp @@ -7,10 +7,6 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) -#pragma implementation "htmlcell.h" -#endif - #include "wx/wxprec.h" #include "wx/defs.h" @@ -94,6 +90,8 @@ wxHtmlCell::wxHtmlCell() : wxObject() m_Next = NULL; m_Parent = NULL; m_Width = m_Height = m_Descent = 0; + m_ScriptMode = wxHTML_SCRIPT_NORMAL; // or mode + m_ScriptBaseline = 0; // or baseline m_CanLiveOnPagebreak = true; m_Link = NULL; } @@ -103,6 +101,21 @@ wxHtmlCell::~wxHtmlCell() delete m_Link; } +// Update the descent value when whe are in a or . +// prevbase is the parent base +void wxHtmlCell::SetScriptMode(wxHtmlScriptMode mode, long previousBase) +{ + m_ScriptMode = mode; + + if (mode == wxHTML_SCRIPT_SUP) + m_ScriptBaseline = previousBase - (m_Height + 1) / 2; + else if (mode == wxHTML_SCRIPT_SUB) + m_ScriptBaseline = previousBase + (m_Height + 1) / 6; + else + m_ScriptBaseline = 0; + + m_Descent += m_ScriptBaseline; +} void wxHtmlCell::OnMouseClick(wxWindow *parent, int x, int y, const wxMouseEvent& event) @@ -256,7 +269,7 @@ bool wxHtmlCell::IsBefore(wxHtmlCell *cell) const IMPLEMENT_ABSTRACT_CLASS(wxHtmlWordCell, wxHtmlCell) -wxHtmlWordCell::wxHtmlWordCell(const wxString& word, wxDC& dc) : wxHtmlCell() +wxHtmlWordCell::wxHtmlWordCell(const wxString& word, const wxDC& dc) : wxHtmlCell() { m_Word = word; dc.GetTextExtent(m_Word, &m_Width, &m_Height, &m_Descent); @@ -276,7 +289,7 @@ void wxHtmlWordCell::SetPreviousWord(wxHtmlWordCell *cell) // Splits m_Word into up to three parts according to selection, returns // substring before, in and after selection and the points (in relative coords) // where s2 and s3 start: -void wxHtmlWordCell::Split(wxDC& dc, +void wxHtmlWordCell::Split(const wxDC& dc, const wxPoint& selFrom, const wxPoint& selTo, unsigned& pos1, unsigned& pos2) const { @@ -285,7 +298,6 @@ void wxHtmlWordCell::Split(wxDC& dc, wxPoint pt2 = (selTo == wxDefaultPosition) ? wxPoint(m_Width, wxDefaultCoord) : selTo - GetAbsPos(); - wxCoord charW, charH; unsigned len = m_Word.length(); unsigned i = 0; pos1 = 0; @@ -298,6 +310,14 @@ void wxHtmlWordCell::Split(wxDC& dc, pt2.x = m_Width; // before selection: +#ifdef __WXMAC__ + // implementation using PartialExtents to support fractional widths + wxArrayInt widths ; + dc.GetPartialTextExtents(m_Word,widths) ; + while( i < len && pt1.x >= widths[i] ) + i++ ; +#else // __WXMAC__ + wxCoord charW, charH; while ( pt1.x > 0 && i < len ) { dc.GetTextExtent(m_Word[i], &charW, &charH); @@ -308,9 +328,14 @@ void wxHtmlWordCell::Split(wxDC& dc, i++; } } +#endif // __WXMAC__/!__WXMAC__ // in selection: unsigned j = i; +#ifdef __WXMAC__ + while( j < len && pt2.x >= widths[j] ) + j++ ; +#else // __WXMAC__ pos2 = pos1; pt2.x -= pos2; while ( pt2.x > 0 && j < len ) @@ -323,12 +348,13 @@ void wxHtmlWordCell::Split(wxDC& dc, j++; } } +#endif // __WXMAC__/!__WXMAC__ pos1 = i; pos2 = j; } -void wxHtmlWordCell::SetSelectionPrivPos(wxDC& dc, wxHtmlSelection *s) const +void wxHtmlWordCell::SetSelectionPrivPos(const wxDC& dc, wxHtmlSelection *s) const { unsigned p1, p2; @@ -637,8 +663,6 @@ void wxHtmlContainerCell::Layout(int w) return; } - wxHtmlCell *cell = m_Cells, - *line = m_Cells; wxHtmlCell *nextCell; long xpos = 0, ypos = m_IndentTop; int xdelta = 0, ybasicpos = 0, ydiff; @@ -685,6 +709,8 @@ void wxHtmlContainerCell::Layout(int w) s_width = m_Width - s_indent - ((m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight); // my own layouting: + wxHtmlCell *cell = m_Cells, + *line = m_Cells; while (cell != NULL) { switch (m_AlignVer) @@ -902,7 +928,7 @@ void wxHtmlContainerCell::Draw(wxDC& dc, int x, int y, int view_y1, int view_y2, dc.SetPen(*wxRED_PEN); dc.DrawRectangle(x+m_PosX,y+m_PosY,m_Width,m_Height); #endif - + int xlocal = x + m_PosX; int ylocal = y + m_PosY; @@ -936,7 +962,7 @@ void wxHtmlContainerCell::Draw(wxDC& dc, int x, int y, int view_y1, int view_y2, // draw container's contents: for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) { - + // optimize drawing: don't render off-screen content: if ((ylocal + cell->GetPosY() <= view_y2) && (ylocal + cell->GetPosY() + cell->GetHeight() > view_y1))