+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,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);
+
+ txt = m_Word.Mid(part1, part2-part1);
+ dc.DrawText(txt, ofs + x + m_PosX, y + m_PosY);
+
+ if ( (size_t)part2 < m_Word.length() )
+ {
+ dc.GetTextExtent(txt, &w, &h);
+ ofs += w;
+ SwitchSelState(dc, info, false);
+ txt = m_Word.Mid(part2);
+ dc.DrawText(txt, ofs + x + m_PosX, y + m_PosY);
+ }
+ else
+ drawSelectionAfterCell = true;
+ }
+ else
+ {
+ wxHtmlSelectionState selstate = info.GetState().GetSelectionState();
+ // Not changing selection state, draw the word in single mode:
+ if ( selstate != wxHTML_SEL_OUT &&
+ dc.GetBackgroundMode() != wxSOLID )
+ {
+ SwitchSelState(dc, info, true);
+ }
+ else if ( selstate == wxHTML_SEL_OUT &&
+ dc.GetBackgroundMode() == wxSOLID )
+ {
+ SwitchSelState(dc, info, false);
+ }
+ dc.DrawText(m_Word, x + m_PosX, y + m_PosY);
+ drawSelectionAfterCell = (selstate != wxHTML_SEL_OUT);
+ }
+
+ // NB: If the text is justified then there is usually some free space
+ // between adjacent cells and drawing the selection only onto cells
+ // would result in ugly unselected spaces. The code below detects
+ // this special case and renders the selection *outside* the sell,
+ // too.
+ if ( m_Parent->GetAlignHor() == wxHTML_ALIGN_JUSTIFY &&
+ drawSelectionAfterCell )
+ {
+ wxHtmlCell *nextCell = m_Next;
+ while ( nextCell && nextCell->IsFormattingCell() )
+ nextCell = nextCell->GetNext();
+ if ( nextCell )
+ {
+ int nextX = nextCell->GetPosX();
+ if ( m_PosX + m_Width < nextX )
+ {
+ dc.SetBrush(dc.GetBackground());
+ dc.SetPen(*wxTRANSPARENT_PEN);
+ dc.DrawRectangle(x + m_PosX + m_Width, y + m_PosY,
+ nextX - m_PosX - m_Width, m_Height);
+ }
+ }
+ }
+}
+
+
+wxString wxHtmlWordCell::ConvertToText(wxHtmlSelection *s) const
+{
+ if ( s && (this == s->GetFromCell() || this == s->GetToCell()) )
+ {
+ wxPoint priv = this == s->GetFromCell() ? s->GetFromPrivPos()
+ : s->GetToPrivPos();
+
+ // VZ: we may be called before we had a chance to re-render ourselves
+ // and in this case GetFrom/ToPrivPos() is not set yet -- assume
+ // that this only happens in case of a double/triple click (which
+ // seems to be the case now) and so it makes sense to select the
+ // entire contents of the cell in this case
+ //
+ // TODO: but this really needs to be fixed in some better way later...
+ if ( priv != wxDefaultPosition )
+ {
+ int part1 = priv.x;
+ int part2 = priv.y;
+ return m_Word.Mid(part1, part2-part1);
+ }
+ //else: return the whole word below
+ }
+
+ return m_Word;
+}
+
+wxCursor wxHtmlWordCell::GetCursor() const
+{
+ if ( !GetLink() )
+ {
+ if ( !gs_cursorText )
+ gs_cursorText = new wxCursor(wxCURSOR_IBEAM);
+ return *gs_cursorText;
+ }
+ else
+ return wxHtmlCell::GetCursor();
+}
+