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:
@@ -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() )
|
||||
|
Reference in New Issue
Block a user