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:
Robin Dunn
2003-08-08 03:57:35 +00:00
parent 68a2e005a5
commit 5b87f8bf2e
2 changed files with 88 additions and 60 deletions

View File

@@ -1185,28 +1185,42 @@ 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__
if (m_windowStyle & wxTE_MULTILINE)
{
GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (m_text)); GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (m_text));
GtkTextIter ifrom, ito; GtkTextIter ifrom, ito;
if (!gtk_text_buffer_get_selection_bounds(buffer, &ifrom, &ito)) if ( gtk_text_buffer_get_selection_bounds(buffer, &ifrom, &ito) )
#else
if ( !(GTK_EDITABLE(m_text)->has_selection) )
#endif
{ {
from = haveSelection = TRUE;
to = GetInsertionPoint();
}
else // got selection
{
#ifdef __WXGTK20__
from = gtk_text_iter_get_offset(&ifrom); from = gtk_text_iter_get_offset(&ifrom);
to = gtk_text_iter_get_offset(&ito); to = gtk_text_iter_get_offset(&ito);
#else }
}
else // not multi-line
{
if ( gtk_editable_get_selection_bounds( GTK_EDITABLE(m_text),
&from, &to) )
{
haveSelection = TRUE;
}
}
#else // not GTK2
if ( (GTK_EDITABLE(m_text)->has_selection) )
{
haveSelection = TRUE;
from = (long) GTK_EDITABLE(m_text)->selection_start_pos; from = (long) GTK_EDITABLE(m_text)->selection_start_pos;
to = (long) GTK_EDITABLE(m_text)->selection_end_pos; to = (long) GTK_EDITABLE(m_text)->selection_end_pos;
}
#endif #endif
if (! haveSelection )
from = to = GetInsertionPoint();
if ( from > to ) if ( from > to )
{ {
// exchange them to be compatible with wxMSW // exchange them to be compatible with wxMSW
@@ -1214,7 +1228,6 @@ void wxTextCtrl::GetSelection(long* fromOut, long* toOut) const
from = to; from = to;
to = tmp; 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") );

View File

@@ -1185,28 +1185,42 @@ 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__
if (m_windowStyle & wxTE_MULTILINE)
{
GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (m_text)); GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (m_text));
GtkTextIter ifrom, ito; GtkTextIter ifrom, ito;
if (!gtk_text_buffer_get_selection_bounds(buffer, &ifrom, &ito)) if ( gtk_text_buffer_get_selection_bounds(buffer, &ifrom, &ito) )
#else
if ( !(GTK_EDITABLE(m_text)->has_selection) )
#endif
{ {
from = haveSelection = TRUE;
to = GetInsertionPoint();
}
else // got selection
{
#ifdef __WXGTK20__
from = gtk_text_iter_get_offset(&ifrom); from = gtk_text_iter_get_offset(&ifrom);
to = gtk_text_iter_get_offset(&ito); to = gtk_text_iter_get_offset(&ito);
#else }
}
else // not multi-line
{
if ( gtk_editable_get_selection_bounds( GTK_EDITABLE(m_text),
&from, &to) )
{
haveSelection = TRUE;
}
}
#else // not GTK2
if ( (GTK_EDITABLE(m_text)->has_selection) )
{
haveSelection = TRUE;
from = (long) GTK_EDITABLE(m_text)->selection_start_pos; from = (long) GTK_EDITABLE(m_text)->selection_start_pos;
to = (long) GTK_EDITABLE(m_text)->selection_end_pos; to = (long) GTK_EDITABLE(m_text)->selection_end_pos;
}
#endif #endif
if (! haveSelection )
from = to = GetInsertionPoint();
if ( from > to ) if ( from > to )
{ {
// exchange them to be compatible with wxMSW // exchange them to be compatible with wxMSW
@@ -1214,7 +1228,6 @@ void wxTextCtrl::GetSelection(long* fromOut, long* toOut) const
from = to; from = to;
to = tmp; 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") );