Add wxTextCtrl::PositionToCoords() functions for wxMSW and wxGTK.

The new method allows to find the coordinates in pixels of the given character
in a text control.

Closes #13221.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@68450 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2011-07-29 15:11:54 +00:00
parent d298f18ffb
commit 6ce832135e
10 changed files with 304 additions and 0 deletions

View File

@@ -1218,6 +1218,37 @@ int wxTextCtrl::GetLineLength(long lineNo) const
}
}
wxPoint wxTextCtrl::DoPositionToCoords(long pos) const
{
if ( !IsMultiLine() )
{
// Single line text entry (GtkTextEntry) doesn't have support for
// getting the coordinates for the given offset. Perhaps we could
// find them ourselves by using GetTextExtent() but for now just leave
// it unimplemented, this function is more useful for multiline
// controls anyhow.
return wxDefaultPosition;
}
// Window coordinates for the given position is calculated by getting
// the buffer coordinates and converting them to window coordinates.
GtkTextView *textview = GTK_TEXT_VIEW(m_text);
GtkTextIter iter;
gtk_text_buffer_get_iter_at_offset(m_buffer, &iter, pos);
GdkRectangle bufferCoords;
gtk_text_view_get_iter_location(textview, &iter, &bufferCoords);
gint winCoordX = 0,
winCoordY = 0;
gtk_text_view_buffer_to_window_coords(textview, GTK_TEXT_WINDOW_WIDGET,
bufferCoords.x, bufferCoords.y,
&winCoordX, &winCoordY);
return wxPoint(winCoordX, winCoordY);
}
int wxTextCtrl::GetNumberOfLines() const
{
if ( IsMultiLine() )