implemented HitTest() for GTK2; test it in the sample

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@28430 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2004-07-23 18:07:40 +00:00
parent e38c6b5fc7
commit 692c9b8696
9 changed files with 109 additions and 9 deletions

View File

@@ -226,16 +226,17 @@ Unix:
wxGTK:
- wxGTK uses GTK+ 2.x by default now, you have to pass --disable-gtk2 to
configure if you want to use GTK+ 1.2
- fixed many rendering artifacts and wrong colours with lots of GTK+ themes
- implemented wxColourDialog as native dialog
- implemented wxTextCtrl::HitTest() (GTK+ >= 2)
- wxTreeCtrl::GetCount() counts root as well now (compatible with MSW)
- added support for wxCHK_3STATE style (GTK2 only)
- implemented text underlining under GTK2
- implemented wxFRAME_NO_TASKBAR style (GTK >= 2.2)
- implemented support for wxSYS_DCLICK_?, wxSYS_DRAG_? and wxSYS_CURSOR_?
in wxSystemSettings::GetMetric (Mart Raudsepp)
- wxGTK uses GTK+ 2.x by default now, you have to pass --disable-gtk2 to
configure if you want to use GTK+ 1.2
- implemented wxTopLevel::IsMaximized() for GTK+2 and WMs that implement
freedesktop.org's wm-spec (Mart Raudsepp)

View File

@@ -825,8 +825,8 @@ pixels. If the return code is not \texttt{wxTE\_HT\_UNKNOWN} the row and column
of the character closest to this position are returned in the \arg{col} and
\arg{row} parameters (unless the pointers are {\tt NULL} which is allowed).
Please note that this function is currently only implemented in wxUniv and
wxMSW ports.
Please note that this function is currently only implemented in wxUniv,
wxMSW and wxGTK2 ports.
\wxheading{See also}

View File

@@ -330,6 +330,7 @@ public:
//
// NB: pt is in device coords (not adjusted for the client area origin nor
// scrolling)
virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, long *pos) const;
virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt,
wxTextCoord *col,
wxTextCoord *row) const;

View File

@@ -191,6 +191,7 @@ public:
void RemoveSelection();
wxString GetSelectionText() const;
virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, long *pos) const;
virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt,
wxTextCoord *col,
wxTextCoord *row) const;

View File

@@ -662,15 +662,24 @@ void MyTextCtrl::OnMouseEvent(wxMouseEvent& ev)
msg = GetMouseEventDesc(ev);
}
msg << _T(" at (") << ev.GetX() << _T(", ") << ev.GetY() << _T(") ")
<< _T("Flags: ")
msg << _T(" at (") << ev.GetX() << _T(", ") << ev.GetY() << _T(") ");
long pos;
wxTextCtrlHitTestResult rc = HitTest(ev.GetPosition(), &pos);
if ( rc != wxTE_HT_UNKNOWN )
{
msg << _T("at position ") << pos;
}
msg << _T("[Flags: ")
<< GetChar( ev.LeftIsDown(), _T('1') )
<< GetChar( ev.MiddleIsDown(), _T('2') )
<< GetChar( ev.RightIsDown(), _T('3') )
<< GetChar( ev.ControlDown(), _T('C') )
<< GetChar( ev.AltDown(), _T('A') )
<< GetChar( ev.ShiftDown(), _T('S') )
<< GetChar( ev.MetaDown(), _T('M') );
<< GetChar( ev.MetaDown(), _T('M') )
<< _T(']');
wxLogMessage(msg);
}

View File

@@ -495,10 +495,26 @@ void wxTextCtrlBase::DoUpdateWindowUI(wxUpdateUIEvent& event)
// hit testing
// ----------------------------------------------------------------------------
wxTextCtrlHitTestResult
wxTextCtrlBase::HitTest(const wxPoint& pt, wxTextCoord *x, wxTextCoord *y) const
{
// implement in terms of the other overload as the native ports typically
// can get the position and not (x, y) pair directly (although wxUniv
// directly gets x and y -- and so overrides this method as well)
long pos;
wxTextCtrlHitTestResult rc = HitTest(pt, &pos);
if ( rc != wxTE_HT_UNKNOWN )
{
PositionToXY(pos, x, y);
}
return rc;
}
wxTextCtrlHitTestResult
wxTextCtrlBase::HitTest(const wxPoint& WXUNUSED(pt),
wxTextCoord * WXUNUSED(col),
wxTextCoord * WXUNUSED(row)) const
long * WXUNUSED(pos)) const
{
// not implemented
return wxTE_HT_UNKNOWN;

View File

@@ -1057,6 +1057,36 @@ void wxTextCtrl::ShowPosition( long pos )
}
}
#ifdef __WXGTK20__
wxTextCtrlHitTestResult
wxTextCtrl::HitTest(const wxPoint& pt, long *pos) const
{
if ( !IsMultiLine() )
{
// not supported
return wxTE_HT_UNKNOWN;
}
int x, y;
gtk_text_view_window_to_buffer_coords
(
GTK_TEXT_VIEW(m_text),
GTK_TEXT_WINDOW_TEXT,
pt.x, pt.y,
&x, &y
);
GtkTextIter iter;
gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(m_text), &iter, x, y);
if ( pos )
*pos = gtk_text_iter_get_offset(&iter);
return wxTE_HT_ON_TEXT;
}
#endif // __WXGTK20__
long wxTextCtrl::GetInsertionPoint() const
{
wxCHECK_MSG( m_text != NULL, 0, wxT("invalid text ctrl") );

View File

@@ -1057,6 +1057,36 @@ void wxTextCtrl::ShowPosition( long pos )
}
}
#ifdef __WXGTK20__
wxTextCtrlHitTestResult
wxTextCtrl::HitTest(const wxPoint& pt, long *pos) const
{
if ( !IsMultiLine() )
{
// not supported
return wxTE_HT_UNKNOWN;
}
int x, y;
gtk_text_view_window_to_buffer_coords
(
GTK_TEXT_VIEW(m_text),
GTK_TEXT_WINDOW_TEXT,
pt.x, pt.y,
&x, &y
);
GtkTextIter iter;
gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(m_text), &iter, x, y);
if ( pos )
*pos = gtk_text_iter_get_offset(&iter);
return wxTE_HT_ON_TEXT;
}
#endif // __WXGTK20__
long wxTextCtrl::GetInsertionPoint() const
{
wxCHECK_MSG( m_text != NULL, 0, wxT("invalid text ctrl") );

View File

@@ -2952,6 +2952,18 @@ wxTextCtrlHitTestResult wxTextCtrl::HitTestLine(const wxString& line,
return res;
}
wxTextCtrlHitTestResult wxTextCtrl::HitTest(const wxPoint& pt, long *pos) const
{
wxTextCoord x, y;
wxTextCtrlHitTestResult rc = HitTest(pt, &x, &y);
if ( rc != wxTE_HT_UNKNOWN && pos )
{
*pos = XYToPosition(x, y);
}
return rc;
}
wxTextCtrlHitTestResult wxTextCtrl::HitTest(const wxPoint& pos,
wxTextCoord *colOut,
wxTextCoord *rowOut) const