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