Fix for wxTextCtrl::GetSelection for singel line controls in GTK2 mode
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@22692 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -515,7 +515,7 @@ wxString wxTextCtrl::GetValue() const
|
|||||||
GtkTextIter end;
|
GtkTextIter end;
|
||||||
gtk_text_buffer_get_end_iter( text_buffer, &end );
|
gtk_text_buffer_get_end_iter( text_buffer, &end );
|
||||||
gchar *text = gtk_text_buffer_get_text( text_buffer, &start, &end, TRUE );
|
gchar *text = gtk_text_buffer_get_text( text_buffer, &start, &end, TRUE );
|
||||||
|
|
||||||
#if wxUSE_UNICODE
|
#if wxUSE_UNICODE
|
||||||
wxWCharBuffer buffer( wxConvUTF8.cMB2WX( text ) );
|
wxWCharBuffer buffer( wxConvUTF8.cMB2WX( text ) );
|
||||||
#else
|
#else
|
||||||
@@ -592,7 +592,7 @@ void wxTextCtrl::WriteText( const wxString &text )
|
|||||||
wxCharBuffer buffer( wxConvUTF8.cWC2MB( wxConvLocal.cWX2WC( text ) ) );
|
wxCharBuffer buffer( wxConvUTF8.cWC2MB( wxConvLocal.cWX2WC( text ) ) );
|
||||||
#endif
|
#endif
|
||||||
GtkTextBuffer *text_buffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW(m_text) );
|
GtkTextBuffer *text_buffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW(m_text) );
|
||||||
|
|
||||||
// TODO: Call whatever is needed to delete the selection.
|
// TODO: Call whatever is needed to delete the selection.
|
||||||
wxGtkTextInsert( m_text, text_buffer, m_defaultStyle, buffer );
|
wxGtkTextInsert( m_text, text_buffer, m_defaultStyle, buffer );
|
||||||
|
|
||||||
@@ -1185,36 +1185,49 @@ void wxTextCtrl::GetSelection(long* fromOut, long* toOut) const
|
|||||||
{
|
{
|
||||||
wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );
|
wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );
|
||||||
|
|
||||||
gint from, to;
|
gint from = -1;
|
||||||
|
gint to = -1;
|
||||||
|
bool haveSelection = FALSE;
|
||||||
|
|
||||||
#ifdef __WXGTK20__
|
#ifdef __WXGTK20__
|
||||||
GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (m_text));
|
if (m_windowStyle & wxTE_MULTILINE)
|
||||||
GtkTextIter ifrom, ito;
|
{
|
||||||
if (!gtk_text_buffer_get_selection_bounds(buffer, &ifrom, &ito))
|
GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (m_text));
|
||||||
#else
|
GtkTextIter ifrom, ito;
|
||||||
if ( !(GTK_EDITABLE(m_text)->has_selection) )
|
if ( gtk_text_buffer_get_selection_bounds(buffer, &ifrom, &ito) )
|
||||||
#endif
|
{
|
||||||
{
|
haveSelection = TRUE;
|
||||||
from =
|
from = gtk_text_iter_get_offset(&ifrom);
|
||||||
to = GetInsertionPoint();
|
to = gtk_text_iter_get_offset(&ito);
|
||||||
}
|
}
|
||||||
else // got selection
|
}
|
||||||
{
|
else // not multi-line
|
||||||
#ifdef __WXGTK20__
|
{
|
||||||
from = gtk_text_iter_get_offset(&ifrom);
|
if ( gtk_editable_get_selection_bounds( GTK_EDITABLE(m_text),
|
||||||
to = gtk_text_iter_get_offset(&ito);
|
&from, &to) )
|
||||||
#else
|
{
|
||||||
from = (long) GTK_EDITABLE(m_text)->selection_start_pos;
|
haveSelection = TRUE;
|
||||||
to = (long) GTK_EDITABLE(m_text)->selection_end_pos;
|
}
|
||||||
|
}
|
||||||
|
#else // not GTK2
|
||||||
|
if ( (GTK_EDITABLE(m_text)->has_selection) )
|
||||||
|
{
|
||||||
|
haveSelection = TRUE;
|
||||||
|
from = (long) GTK_EDITABLE(m_text)->selection_start_pos;
|
||||||
|
to = (long) GTK_EDITABLE(m_text)->selection_end_pos;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ( from > to )
|
if (! haveSelection )
|
||||||
{
|
from = to = GetInsertionPoint();
|
||||||
// exchange them to be compatible with wxMSW
|
|
||||||
gint tmp = from;
|
if ( from > to )
|
||||||
from = to;
|
{
|
||||||
to = tmp;
|
// exchange them to be compatible with wxMSW
|
||||||
}
|
gint tmp = from;
|
||||||
}
|
from = to;
|
||||||
|
to = tmp;
|
||||||
|
}
|
||||||
|
|
||||||
if ( fromOut )
|
if ( fromOut )
|
||||||
*fromOut = from;
|
*fromOut = from;
|
||||||
@@ -1222,6 +1235,7 @@ void wxTextCtrl::GetSelection(long* fromOut, long* toOut) const
|
|||||||
*toOut = to;
|
*toOut = to;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool wxTextCtrl::IsEditable() const
|
bool wxTextCtrl::IsEditable() const
|
||||||
{
|
{
|
||||||
wxCHECK_MSG( m_text != NULL, FALSE, wxT("invalid text ctrl") );
|
wxCHECK_MSG( m_text != NULL, FALSE, wxT("invalid text ctrl") );
|
||||||
@@ -1449,7 +1463,7 @@ bool wxTextCtrl::SetStyle( long start, long end, const wxTextAttr& style )
|
|||||||
#else
|
#else
|
||||||
// VERY dirty way to do that - removes the required text and re-adds it
|
// VERY dirty way to do that - removes the required text and re-adds it
|
||||||
// with styling (FIXME)
|
// with styling (FIXME)
|
||||||
|
|
||||||
gint l = gtk_text_get_length( GTK_TEXT(m_text) );
|
gint l = gtk_text_get_length( GTK_TEXT(m_text) );
|
||||||
|
|
||||||
wxCHECK_MSG( start >= 0 && end <= l, FALSE,
|
wxCHECK_MSG( start >= 0 && end <= l, FALSE,
|
||||||
|
|||||||
@@ -515,7 +515,7 @@ wxString wxTextCtrl::GetValue() const
|
|||||||
GtkTextIter end;
|
GtkTextIter end;
|
||||||
gtk_text_buffer_get_end_iter( text_buffer, &end );
|
gtk_text_buffer_get_end_iter( text_buffer, &end );
|
||||||
gchar *text = gtk_text_buffer_get_text( text_buffer, &start, &end, TRUE );
|
gchar *text = gtk_text_buffer_get_text( text_buffer, &start, &end, TRUE );
|
||||||
|
|
||||||
#if wxUSE_UNICODE
|
#if wxUSE_UNICODE
|
||||||
wxWCharBuffer buffer( wxConvUTF8.cMB2WX( text ) );
|
wxWCharBuffer buffer( wxConvUTF8.cMB2WX( text ) );
|
||||||
#else
|
#else
|
||||||
@@ -592,7 +592,7 @@ void wxTextCtrl::WriteText( const wxString &text )
|
|||||||
wxCharBuffer buffer( wxConvUTF8.cWC2MB( wxConvLocal.cWX2WC( text ) ) );
|
wxCharBuffer buffer( wxConvUTF8.cWC2MB( wxConvLocal.cWX2WC( text ) ) );
|
||||||
#endif
|
#endif
|
||||||
GtkTextBuffer *text_buffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW(m_text) );
|
GtkTextBuffer *text_buffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW(m_text) );
|
||||||
|
|
||||||
// TODO: Call whatever is needed to delete the selection.
|
// TODO: Call whatever is needed to delete the selection.
|
||||||
wxGtkTextInsert( m_text, text_buffer, m_defaultStyle, buffer );
|
wxGtkTextInsert( m_text, text_buffer, m_defaultStyle, buffer );
|
||||||
|
|
||||||
@@ -1185,36 +1185,49 @@ void wxTextCtrl::GetSelection(long* fromOut, long* toOut) const
|
|||||||
{
|
{
|
||||||
wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );
|
wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );
|
||||||
|
|
||||||
gint from, to;
|
gint from = -1;
|
||||||
|
gint to = -1;
|
||||||
|
bool haveSelection = FALSE;
|
||||||
|
|
||||||
#ifdef __WXGTK20__
|
#ifdef __WXGTK20__
|
||||||
GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (m_text));
|
if (m_windowStyle & wxTE_MULTILINE)
|
||||||
GtkTextIter ifrom, ito;
|
{
|
||||||
if (!gtk_text_buffer_get_selection_bounds(buffer, &ifrom, &ito))
|
GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (m_text));
|
||||||
#else
|
GtkTextIter ifrom, ito;
|
||||||
if ( !(GTK_EDITABLE(m_text)->has_selection) )
|
if ( gtk_text_buffer_get_selection_bounds(buffer, &ifrom, &ito) )
|
||||||
#endif
|
{
|
||||||
{
|
haveSelection = TRUE;
|
||||||
from =
|
from = gtk_text_iter_get_offset(&ifrom);
|
||||||
to = GetInsertionPoint();
|
to = gtk_text_iter_get_offset(&ito);
|
||||||
}
|
}
|
||||||
else // got selection
|
}
|
||||||
{
|
else // not multi-line
|
||||||
#ifdef __WXGTK20__
|
{
|
||||||
from = gtk_text_iter_get_offset(&ifrom);
|
if ( gtk_editable_get_selection_bounds( GTK_EDITABLE(m_text),
|
||||||
to = gtk_text_iter_get_offset(&ito);
|
&from, &to) )
|
||||||
#else
|
{
|
||||||
from = (long) GTK_EDITABLE(m_text)->selection_start_pos;
|
haveSelection = TRUE;
|
||||||
to = (long) GTK_EDITABLE(m_text)->selection_end_pos;
|
}
|
||||||
|
}
|
||||||
|
#else // not GTK2
|
||||||
|
if ( (GTK_EDITABLE(m_text)->has_selection) )
|
||||||
|
{
|
||||||
|
haveSelection = TRUE;
|
||||||
|
from = (long) GTK_EDITABLE(m_text)->selection_start_pos;
|
||||||
|
to = (long) GTK_EDITABLE(m_text)->selection_end_pos;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ( from > to )
|
if (! haveSelection )
|
||||||
{
|
from = to = GetInsertionPoint();
|
||||||
// exchange them to be compatible with wxMSW
|
|
||||||
gint tmp = from;
|
if ( from > to )
|
||||||
from = to;
|
{
|
||||||
to = tmp;
|
// exchange them to be compatible with wxMSW
|
||||||
}
|
gint tmp = from;
|
||||||
}
|
from = to;
|
||||||
|
to = tmp;
|
||||||
|
}
|
||||||
|
|
||||||
if ( fromOut )
|
if ( fromOut )
|
||||||
*fromOut = from;
|
*fromOut = from;
|
||||||
@@ -1222,6 +1235,7 @@ void wxTextCtrl::GetSelection(long* fromOut, long* toOut) const
|
|||||||
*toOut = to;
|
*toOut = to;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool wxTextCtrl::IsEditable() const
|
bool wxTextCtrl::IsEditable() const
|
||||||
{
|
{
|
||||||
wxCHECK_MSG( m_text != NULL, FALSE, wxT("invalid text ctrl") );
|
wxCHECK_MSG( m_text != NULL, FALSE, wxT("invalid text ctrl") );
|
||||||
@@ -1449,7 +1463,7 @@ bool wxTextCtrl::SetStyle( long start, long end, const wxTextAttr& style )
|
|||||||
#else
|
#else
|
||||||
// VERY dirty way to do that - removes the required text and re-adds it
|
// VERY dirty way to do that - removes the required text and re-adds it
|
||||||
// with styling (FIXME)
|
// with styling (FIXME)
|
||||||
|
|
||||||
gint l = gtk_text_get_length( GTK_TEXT(m_text) );
|
gint l = gtk_text_get_length( GTK_TEXT(m_text) );
|
||||||
|
|
||||||
wxCHECK_MSG( start >= 0 && end <= l, FALSE,
|
wxCHECK_MSG( start >= 0 && end <= l, FALSE,
|
||||||
|
|||||||
Reference in New Issue
Block a user