public:
wxHtmlSelection()
: m_fromPos(wxDefaultPosition), m_toPos(wxDefaultPosition),
- m_fromPrivPos(wxDefaultPosition), m_toPrivPos(wxDefaultPosition),
+ m_fromCharacterPos(-1), m_toCharacterPos(-1),
m_fromCell(NULL), m_toCell(NULL) {}
+ // this version is used for the user selection defined with the mouse
void Set(const wxPoint& fromPos, const wxHtmlCell *fromCell,
const wxPoint& toPos, const wxHtmlCell *toCell);
void Set(const wxHtmlCell *fromCell, const wxHtmlCell *toCell);
const wxPoint& GetToPos() const { return m_toPos; }
// these are From/ToCell's private data
- const wxPoint& GetFromPrivPos() const { return m_fromPrivPos; }
- const wxPoint& GetToPrivPos() const { return m_toPrivPos; }
- void SetFromPrivPos(const wxPoint& pos) { m_fromPrivPos = pos; }
- void SetToPrivPos(const wxPoint& pos) { m_toPrivPos = pos; }
- void ClearPrivPos() { m_toPrivPos = m_fromPrivPos = wxDefaultPosition; }
+ void ClearFromToCharacterPos() { m_toCharacterPos = m_fromCharacterPos = -1; }
+ bool AreFromToCharacterPosSet() const { return m_toCharacterPos != -1 && m_fromCharacterPos != -1; }
+
+ void SetFromCharacterPos (wxCoord pos) { m_fromCharacterPos = pos; }
+ void SetToCharacterPos (wxCoord pos) { m_toCharacterPos = pos; }
+ wxCoord GetFromCharacterPos () const { return m_fromCharacterPos; }
+ wxCoord GetToCharacterPos () const { return m_toCharacterPos; }
bool IsEmpty() const
{ return m_fromPos == wxDefaultPosition &&
private:
wxPoint m_fromPos, m_toPos;
- wxPoint m_fromPrivPos, m_toPrivPos;
+ wxCoord m_fromCharacterPos, m_toCharacterPos;
const wxHtmlCell *m_fromCell, *m_toCell;
};
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);
+ s->SetFromCharacterPos (p1); // selection starts here
if ( this == s->GetToCell() )
- s->SetToPrivPos(p);
+ s->SetToCharacterPos (p2); // selection ends here
}
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 )
+ if ( !s->AreFromToCharacterPosSet () )
{
SetSelectionPrivPos(dc, s);
- priv = (this == s->GetFromCell()) ?
- s->GetFromPrivPos() : s->GetToPrivPos();
}
- int part1 = priv.x;
- int part2 = priv.y;
+ int part1 = s->GetFromCell()==this ? s->GetFromCharacterPos() : 0;
+ int part2 = s->GetToCell()==this ? s->GetToCharacterPos() : m_Word.Length();
if ( part1 > 0 )
{
{
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
// entire contents of the cell in this case
//
// TODO: but this really needs to be fixed in some better way later...
- if ( priv != wxDefaultPosition )
+ if ( s->AreFromToCharacterPosSet() )
{
- const int part1 = priv.x;
- const int part2 = priv.y;
+ const int part1 = s->GetFromCell()==this ? s->GetFromCharacterPos() : 0;
+ const int part2 = s->GetToCell()==this ? s->GetToCharacterPos() : m_Word.Length();
if ( part1 == part2 )
return wxEmptyString;
return GetPartAsText(part1, part2);
{
m_selection->Set(m_selection->GetFromCell(),
m_selection->GetToCell());
- m_selection->ClearPrivPos();
+ m_selection->ClearFromToCharacterPos();
}
Refresh();
m_selection->Set(wxPoint(x,y), selcell,
m_tmpSelFromPos, m_tmpSelFromCell);
}
- m_selection->ClearPrivPos();
+ m_selection->ClearFromToCharacterPos();
Refresh();
}
}