// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
-#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
-#pragma implementation "htmlcell.h"
-#endif
-
#include "wx/wxprec.h"
#include "wx/defs.h"
m_Next = NULL;
m_Parent = NULL;
m_Width = m_Height = m_Descent = 0;
+ m_ScriptMode = wxHTML_SCRIPT_NORMAL; // <sub> or <sup> mode
+ m_ScriptBaseline = 0; // <sub> or <sup> baseline
m_CanLiveOnPagebreak = true;
m_Link = NULL;
}
delete m_Link;
}
+// Update the descent value when whe are in a <sub> or <sup>.
+// 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)
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);
// 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
{
wxPoint pt2 = (selTo == wxDefaultPosition) ?
wxPoint(m_Width, wxDefaultCoord) : selTo - GetAbsPos();
- wxCoord charW, charH;
unsigned len = m_Word.length();
unsigned i = 0;
pos1 = 0;
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);
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 )
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;
#endif
bool drawSelectionAfterCell = false;
-
+
if ( info.GetState().GetSelectionState() == wxHTML_SEL_CHANGING )
{
// Selection changing, we must draw the word piecewise:
return;
}
- wxHtmlCell *cell = m_Cells,
- *line = m_Cells;
wxHtmlCell *nextCell;
long xpos = 0, ypos = m_IndentTop;
int xdelta = 0, ybasicpos = 0, ydiff;
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)
curLineWidth += cell->GetMaxTotalWidth();
cell = cell->GetNext();
-
+
// compute length of the next word that would be added:
nextWordWidth = 0;
if (cell)
nextCell = nextCell->GetNext();
} while (nextCell && !nextCell->IsLinebreakAllowed());
}
-
- // force new line if occured:
- if ((cell == NULL) ||
+
+ // force new line if occurred:
+ if ((cell == NULL) ||
(xpos + nextWordWidth > s_width && cell->IsLinebreakAllowed()))
{
if (xpos > MaxLineWidth) MaxLineWidth = xpos;
// first cell on line is not moved:
line->SetPos(line->GetPosX() + s_indent,
line->GetPosY() + ypos);
-
+
line = line->GetNext();
for ( int n = 0; line != cell; line = line->GetNext() )
{
// thus increasing our size
n++;
}
-
+
line->SetPos(line->GetPosX() + s_indent +
((n * step) / total),
line->GetPosY() + ypos);
if (curLineWidth > m_MaxTotalWidth)
m_MaxTotalWidth = curLineWidth;
-
+
m_MaxTotalWidth += s_indent + ((m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight);
MaxLineWidth += s_indent + ((m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight);
if (m_Width < MaxLineWidth) m_Width = MaxLineWidth;
dc.SetPen(*wxRED_PEN);
dc.DrawRectangle(x+m_PosX,y+m_PosY,m_Width,m_Height);
#endif
- // container visible, draw it:
- if ((y + m_PosY <= view_y2) && (y + m_PosY + m_Height > view_y1))
+
+ int xlocal = x + m_PosX;
+ int ylocal = y + m_PosY;
+
+ if (m_UseBkColour)
{
- if (m_UseBkColour)
- {
- wxBrush myb = wxBrush(m_BkColour, wxSOLID);
+ wxBrush myb = wxBrush(m_BkColour, wxSOLID);
- int real_y1 = mMax(y + m_PosY, view_y1);
- int real_y2 = mMin(y + m_PosY + m_Height - 1, view_y2);
+ int real_y1 = mMax(ylocal, view_y1);
+ int real_y2 = mMin(ylocal + m_Height - 1, view_y2);
- dc.SetBrush(myb);
- dc.SetPen(*wxTRANSPARENT_PEN);
- dc.DrawRectangle(x + m_PosX, real_y1, m_Width, real_y2 - real_y1 + 1);
- }
+ dc.SetBrush(myb);
+ dc.SetPen(*wxTRANSPARENT_PEN);
+ dc.DrawRectangle(xlocal, real_y1, m_Width, real_y2 - real_y1 + 1);
+ }
- if (m_UseBorder)
- {
- wxPen mypen1(m_BorderColour1, 1, wxSOLID);
- wxPen mypen2(m_BorderColour2, 1, wxSOLID);
-
- dc.SetPen(mypen1);
- dc.DrawLine(x + m_PosX, y + m_PosY, x + m_PosX, y + m_PosY + m_Height - 1);
- dc.DrawLine(x + m_PosX, y + m_PosY, x + m_PosX + m_Width, y + m_PosY);
- dc.SetPen(mypen2);
- dc.DrawLine(x + m_PosX + m_Width - 1, y + m_PosY, x + m_PosX + m_Width - 1, y + m_PosY + m_Height - 1);
- dc.DrawLine(x + m_PosX, y + m_PosY + m_Height - 1, x + m_PosX + m_Width, y + m_PosY + m_Height - 1);
- }
+ if (m_UseBorder)
+ {
+ wxPen mypen1(m_BorderColour1, 1, wxSOLID);
+ wxPen mypen2(m_BorderColour2, 1, wxSOLID);
+
+ dc.SetPen(mypen1);
+ dc.DrawLine(xlocal, ylocal, xlocal, ylocal + m_Height - 1);
+ dc.DrawLine(xlocal, ylocal, xlocal + m_Width, ylocal);
+ dc.SetPen(mypen2);
+ dc.DrawLine(xlocal + m_Width - 1, ylocal, xlocal + m_Width - 1, ylocal + m_Height - 1);
+ dc.DrawLine(xlocal, ylocal + m_Height - 1, xlocal + m_Width, ylocal + m_Height - 1);
+ }
- if (m_Cells)
+ if (m_Cells)
+ {
+ // draw container's contents:
+ for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext())
{
- // 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))
{
+ // the cell is visible, draw it:
UpdateRenderingStatePre(info, cell);
cell->Draw(dc,
- x + m_PosX, y + m_PosY, view_y1, view_y2,
+ xlocal, ylocal, view_y1, view_y2,
info);
UpdateRenderingStatePost(info, cell);
}
+ else
+ {
+ // the cell is off-screen, proceed with font+color+etc.
+ // changes only:
+ cell->DrawInvisible(dc, xlocal, ylocal, info);
+ }
}
}
- // container invisible, just proceed font+color changing:
- else
- {
- DrawInvisible(dc, x, y, info);
- }
}
if ( cell->IsFormattingCell() )
continue;
int cellY = cell->GetPosY();
- if (!( y < cellY || (y < cellY + cell->GetHeight() &&
+ if (!( y < cellY || (y < cellY + cell->GetHeight() &&
x < cell->GetPosX() + cell->GetWidth()) ))
continue;
-
+
c = cell->FindCellByPos(x - cell->GetPosX(), y - cellY, flags);
if (c) return c;
}
}
void wxHtmlContainerCell::RemoveExtraSpacing(bool top, bool bottom)
-{
+{
if ( top )
SetIndent(0, wxHTML_INDENT_TOP);
if ( bottom )
}
}
}
-
+
if ( bottom )
{
wxArrayPtrVoid arr;
for ( c = m_Cells; c; c = c->GetNext() )
arr.Add((void*)c);
-
+
for ( int i = arr.GetCount() - 1; i >= 0; i--)
{
c = (wxHtmlCell*)arr[i];
cont = (wxHtmlContainerCell*)c;
if ( IsEmptyContainer(cont) )
{
- cont->SetIndent(0, wxHTML_INDENT_VERTICAL); }
+ cont->SetIndent(0, wxHTML_INDENT_VERTICAL);
+ }
else
{
cont->RemoveExtraSpacing(false, true);