+void wxHtmlWordCell::SetPreviousWord(wxHtmlWordCell *cell)
+{
+ if ( cell && m_Parent == cell->m_Parent &&
+ !wxIsspace(cell->m_Word.Last()) && !wxIsspace(m_Word[0u]) )
+ {
+ m_allowLinebreak = false;
+ }
+}
+
+// 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(const wxDC& dc,
+ const wxPoint& selFrom, const wxPoint& selTo,
+ unsigned& pos1, unsigned& pos2) const
+{
+ wxPoint pt1 = (selFrom == wxDefaultPosition) ?
+ wxDefaultPosition : selFrom - GetAbsPos();
+ wxPoint pt2 = (selTo == wxDefaultPosition) ?
+ wxPoint(m_Width, wxDefaultCoord) : selTo - GetAbsPos();
+
+ // if the selection is entirely within this cell, make sure pt1 < pt2 in
+ // order to make the rest of this function simpler:
+ if ( selFrom != wxDefaultPosition && selTo != wxDefaultPosition &&
+ selFrom.x > selTo.x )
+ {
+ wxPoint tmp = pt1;
+ pt1 = pt2;
+ pt2 = tmp;
+ }
+
+ unsigned len = m_Word.length();
+ unsigned i = 0;
+ pos1 = 0;
+
+ // adjust for cases when the start/end position is completely
+ // outside the cell:
+ if ( pt1.y < 0 )
+ pt1.x = 0;
+ if ( pt2.y >= m_Height )
+ pt2.x = m_Width;
+
+ // before selection:
+ // (include character under caret only if in first half of width)
+#ifdef __WXMAC__
+ // implementation using PartialExtents to support fractional widths
+ wxArrayInt widths ;
+ dc.GetPartialTextExtents(m_Word,widths) ;
+ while( i < len && pt1.x >= widths[i] )
+ i++ ;
+ if ( i < len )
+ {
+ int charW = (i > 0) ? widths[i] - widths[i-1] : widths[i];
+ if ( widths[i] - pt1.x < charW/2 )
+ i++;
+ }
+#else // !__WXMAC__
+ wxCoord charW, charH;
+ while ( pt1.x > 0 && i < len )
+ {
+ dc.GetTextExtent(m_Word[i], &charW, &charH);
+ pt1.x -= charW;
+ if ( pt1.x >= -charW/2 )
+ {
+ pos1 += charW;
+ i++;
+ }
+ }
+#endif // __WXMAC__/!__WXMAC__
+
+ // in selection:
+ // (include character under caret only if in first half of width)
+ unsigned j = i;
+#ifdef __WXMAC__
+ while( j < len && pt2.x >= widths[j] )
+ j++ ;
+ if ( j < len )
+ {
+ int charW = (j > 0) ? widths[j] - widths[j-1] : widths[j];
+ if ( widths[j] - pt2.x < charW/2 )
+ j++;
+ }
+#else // !__WXMAC__
+ pos2 = pos1;
+ pt2.x -= pos2;
+ while ( pt2.x > 0 && j < len )
+ {
+ dc.GetTextExtent(m_Word[j], &charW, &charH);
+ pt2.x -= charW;
+ if ( pt2.x >= -charW/2 )
+ {
+ pos2 += charW;
+ j++;
+ }
+ }
+#endif // __WXMAC__/!__WXMAC__
+
+ pos1 = i;
+ pos2 = j;
+}
+
+void wxHtmlWordCell::SetSelectionPrivPos(const wxDC& dc, wxHtmlSelection *s) const
+{
+ unsigned p1, p2;
+
+ Split(dc,
+ this == s->GetFromCell() ? s->GetFromPos() : wxDefaultPosition,
+ this == s->GetToCell() ? s->GetToPos() : wxDefaultPosition,
+ p1, p2);
+
+ wxPoint p(0, m_Word.length());
+
+ if ( this == s->GetFromCell() )
+ p.x = p1; // selection starts here
+ if ( this == s->GetToCell() )
+ p.y = p2; // selection ends here
+
+ if ( this == s->GetFromCell() )
+ s->SetFromPrivPos(p);
+ if ( this == s->GetToCell() )
+ s->SetToPrivPos(p);
+}
+
+
+static void SwitchSelState(wxDC& dc, wxHtmlRenderingInfo& info,
+ bool toSelection)
+{
+ wxColour fg = info.GetState().GetFgColour();
+ wxColour bg = info.GetState().GetBgColour();
+
+ if ( toSelection )
+ {
+ dc.SetBackgroundMode(wxBRUSHSTYLE_SOLID);
+ dc.SetTextForeground(info.GetStyle().GetSelectedTextColour(fg));
+ dc.SetTextBackground(info.GetStyle().GetSelectedTextBgColour(bg));
+ dc.SetBackground(wxBrush(info.GetStyle().GetSelectedTextBgColour(bg),
+ wxBRUSHSTYLE_SOLID));
+ }
+ else
+ {
+ dc.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT);
+ dc.SetTextForeground(fg);
+ dc.SetTextBackground(bg);
+ dc.SetBackground(wxBrush(bg, wxBRUSHSTYLE_SOLID));
+ }
+}