+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(wxSOLID);
+ dc.SetTextForeground(info.GetStyle().GetSelectedTextColour(fg));
+ dc.SetTextBackground(info.GetStyle().GetSelectedTextBgColour(bg));
+ dc.SetBackground(wxBrush(info.GetStyle().GetSelectedTextBgColour(bg),
+ wxSOLID));
+ }
+ else
+ {
+ dc.SetBackgroundMode(wxTRANSPARENT);
+ dc.SetTextForeground(fg);
+ dc.SetTextBackground(bg);
+ dc.SetBackground(wxBrush(bg, wxSOLID));
+ }
+}
+
+
+void wxHtmlWordCell::Draw(wxDC& dc, int x, int y,
+ int WXUNUSED(view_y1), int WXUNUSED(view_y2),
+ wxHtmlRenderingInfo& info)
+{
+#if 0 // useful for debugging
+ dc.SetPen(*wxBLACK_PEN);
+ dc.DrawRectangle(x+m_PosX,y+m_PosY,m_Width /* VZ: +1? */ ,m_Height);
+#endif
+
+ bool drawSelectionAfterCell = false;
+
+ if ( info.GetState().GetSelectionState() == wxHTML_SEL_CHANGING )
+ {
+ // Selection changing, we must draw the word piecewise:
+ wxHtmlSelection *s = info.GetSelection();
+ wxString txt;
+ int w, h;
+ int ofs = 0;
+
+ wxPoint priv = (this == s->GetFromCell()) ?
+ s->GetFromPrivPos() : s->GetToPrivPos();
+
+ // NB: this is quite a hack: in order to compute selection boundaries
+ // (in word's characters) we must know current font, which is only
+ // possible inside rendering code. Therefore we update the
+ // information here and store it in wxHtmlSelection so that
+ // ConvertToText can use it later:
+ if ( priv == wxDefaultPosition )
+ {
+ SetSelectionPrivPos(dc, s);
+ priv = (this == s->GetFromCell()) ?
+ s->GetFromPrivPos() : s->GetToPrivPos();
+ }
+
+ int part1 = priv.x;
+ int part2 = priv.y;
+
+ if ( part1 > 0 )
+ {
+ txt = m_Word.Mid(0, part1);
+ dc.DrawText(txt, x + m_PosX, y + m_PosY);
+ dc.GetTextExtent(txt, &w, &h);
+ ofs += w;
+ }
+
+ SwitchSelState(dc, info, true);