Implement wxTextCtrl::HitTest() function under wxQt
This commit is contained in:
parent
6d7f9342be
commit
9b2e4ff2e5
2 changed files with 59 additions and 0 deletions
|
|
@ -52,6 +52,14 @@ public:
|
|||
|
||||
virtual void ShowPosition(long pos) override;
|
||||
|
||||
virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, long *pos) const override;
|
||||
virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt,
|
||||
wxTextCoord *col,
|
||||
wxTextCoord *row) const override
|
||||
{
|
||||
return wxTextCtrlBase::HitTest(pt, col, row);
|
||||
}
|
||||
|
||||
virtual void SetInsertionPoint(long pos) override;
|
||||
virtual long GetInsertionPoint() const override;
|
||||
virtual void SetSelection( long from, long to ) override;
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ public:
|
|||
virtual bool GetSelection(long *from, long *to) const = 0;
|
||||
virtual long XYToPosition(long x, long y) const = 0;
|
||||
virtual bool PositionToXY(long pos, long *x, long *y) const = 0;
|
||||
virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, long *pos) const = 0;
|
||||
virtual QScrollArea *ScrollBarsContainer() const = 0;
|
||||
virtual void WriteText( const wxString &text ) = 0;
|
||||
virtual void MarkDirty() = 0;
|
||||
|
|
@ -96,6 +97,10 @@ public:
|
|||
return GetHandler()->GetValue();
|
||||
}
|
||||
|
||||
// cursorRect() is protected in base class. Make it public
|
||||
// so it can be accessed by wxQtSingleLineEdit::HitTest()
|
||||
using QLineEdit::cursorRect;
|
||||
|
||||
private:
|
||||
void textChanged();
|
||||
};
|
||||
|
|
@ -241,6 +246,27 @@ public:
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual wxTextCtrlHitTestResult
|
||||
HitTest(const wxPoint& pt, long* pos) const override
|
||||
{
|
||||
auto qtEdit = static_cast<wxQtTextEdit* const>(m_edit);
|
||||
|
||||
auto cursor = qtEdit->cursorForPosition( wxQtConvertPoint(pt) );
|
||||
auto curRect = qtEdit->cursorRect(cursor);
|
||||
|
||||
if ( pos )
|
||||
*pos = cursor.position();
|
||||
|
||||
if ( pt.y > curRect.y() + qtEdit->fontMetrics().height() )
|
||||
return wxTE_HT_BELOW;
|
||||
|
||||
if ( pt.x > curRect.x() + qtEdit->fontMetrics().averageCharWidth() )
|
||||
return wxTE_HT_BEYOND;
|
||||
|
||||
return wxTE_HT_ON_TEXT;
|
||||
}
|
||||
|
||||
virtual void WriteText( const wxString &text ) override
|
||||
{
|
||||
m_edit->insertPlainText(wxQtConvertString( text ));
|
||||
|
|
@ -489,6 +515,25 @@ public:
|
|||
return true;
|
||||
}
|
||||
|
||||
virtual wxTextCtrlHitTestResult
|
||||
HitTest(const wxPoint& pt, long *pos) const override
|
||||
{
|
||||
auto qtEdit = static_cast<wxQtLineEdit* const>(m_edit);
|
||||
auto curPos = qtEdit->cursorPositionAt( wxQtConvertPoint(pt) );
|
||||
auto curRect = qtEdit->cursorRect();
|
||||
|
||||
if ( pos )
|
||||
*pos = curPos;
|
||||
|
||||
if ( pt.y > curRect.y() + qtEdit->fontMetrics().height() )
|
||||
return wxTE_HT_BELOW;
|
||||
|
||||
if ( pt.x > curRect.x() + qtEdit->fontMetrics().averageCharWidth() )
|
||||
return wxTE_HT_BEYOND;
|
||||
|
||||
return wxTE_HT_ON_TEXT;
|
||||
}
|
||||
|
||||
virtual QScrollArea *ScrollBarsContainer() const override
|
||||
{
|
||||
return nullptr;
|
||||
|
|
@ -676,6 +721,12 @@ void wxTextCtrl::ShowPosition(long WXUNUSED(pos))
|
|||
{
|
||||
}
|
||||
|
||||
wxTextCtrlHitTestResult
|
||||
wxTextCtrl::HitTest(const wxPoint& pt, long *pos) const
|
||||
{
|
||||
return m_qtEdit->HitTest(pt, pos);
|
||||
}
|
||||
|
||||
bool wxTextCtrl::DoLoadFile(const wxString& WXUNUSED(file), int WXUNUSED(fileType))
|
||||
{
|
||||
return false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue