Use more clear names for variables in wxHtmlSelection code.

Call the variables and related methods "character position" instead of
"private position" which wasn't very clear.

Closes #13307.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@69870 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2011-11-30 09:21:33 +00:00
parent 35ce2b44b5
commit 2f0bebe646
3 changed files with 20 additions and 32 deletions

View File

@ -34,9 +34,10 @@ class WXDLLIMPEXP_HTML wxHtmlSelection
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);
@ -49,11 +50,13 @@ public:
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 &&
@ -61,7 +64,7 @@ public:
private:
wxPoint m_fromPos, m_toPos;
wxPoint m_fromPrivPos, m_toPrivPos;
wxCoord m_fromCharacterPos, m_toCharacterPos;
const wxHtmlCell *m_fromCell, *m_toCell;
};

View File

@ -476,17 +476,10 @@ void wxHtmlWordCell::SetSelectionPrivPos(const wxDC& dc, wxHtmlSelection *s) con
this == s->GetToCell() ? s->GetToPos() : wxDefaultPosition,
p1, p2);
wxPoint p(0, m_Word.length());
if ( this == s->GetFromCell() )
p.x = p1; // selection starts here
s->SetFromCharacterPos (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);
s->SetToCharacterPos (p2); // selection ends here
}
@ -533,23 +526,18 @@ void wxHtmlWordCell::Draw(wxDC& dc, int x, int y,
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 )
{
@ -634,9 +622,6 @@ 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
@ -644,10 +629,10 @@ wxString wxHtmlWordCell::ConvertToText(wxHtmlSelection *s) const
// 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);

View File

@ -1214,7 +1214,7 @@ void wxHtmlWindow::OnSize(wxSizeEvent& event)
{
m_selection->Set(m_selection->GetFromCell(),
m_selection->GetToCell());
m_selection->ClearPrivPos();
m_selection->ClearFromToCharacterPos();
}
Refresh();
@ -1415,7 +1415,7 @@ void wxHtmlWindow::OnInternalIdle()
m_selection->Set(wxPoint(x,y), selcell,
m_tmpSelFromPos, m_tmpSelFromCell);
}
m_selection->ClearPrivPos();
m_selection->ClearFromToCharacterPos();
Refresh();
}
}