]> git.saurik.com Git - wxWidgets.git/commitdiff
GetSelection() always returns from <= to as wxMSW does
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 7 May 2001 15:08:38 +0000 (15:08 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 7 May 2001 15:08:38 +0000 (15:08 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@10033 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/gtk/textctrl.cpp
src/gtk1/textctrl.cpp

index c525be6c9c14d736179c88565927e77ede32238e..841605437b58d24d1ae87b7bb8ae2a111c46e3c1 100644 (file)
@@ -916,20 +916,34 @@ bool wxTextCtrl::CanRedo() const
 
 // If the return values from and to are the same, there is no
 // selection.
-void wxTextCtrl::GetSelection(long* from, long* to) const
+void wxTextCtrl::GetSelection(long* fromOut, long* toOut) const
 {
     wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );
 
-    if (!(GTK_EDITABLE(m_text)->has_selection))
+    long from, to;
+    if ( !(GTK_EDITABLE(m_text)->has_selection) )
     {
-        long i = GetInsertionPoint();
-        if (from) *from = i;
-        if (to)   *to = i;
-        return;
+        from =
+        to = GetInsertionPoint();
+    }
+    else // got selection
+    {
+        from = (long) GTK_EDITABLE(m_text)->selection_start_pos;
+        to = (long) GTK_EDITABLE(m_text)->selection_end_pos;
+
+        if ( from > to )
+        {
+            // exchange them to be compatible with wxMSW
+            long tmp = from;
+            from = to;
+            to = tmp;
+        }
     }
 
-    if (from) *from = (long) GTK_EDITABLE(m_text)->selection_start_pos;
-    if (to)   *to = (long) GTK_EDITABLE(m_text)->selection_end_pos;
+    if ( fromOut )
+        *fromOut = from;
+    if ( toOut )
+        *toOut = to;
 }
 
 bool wxTextCtrl::IsEditable() const
index c525be6c9c14d736179c88565927e77ede32238e..841605437b58d24d1ae87b7bb8ae2a111c46e3c1 100644 (file)
@@ -916,20 +916,34 @@ bool wxTextCtrl::CanRedo() const
 
 // If the return values from and to are the same, there is no
 // selection.
-void wxTextCtrl::GetSelection(long* from, long* to) const
+void wxTextCtrl::GetSelection(long* fromOut, long* toOut) const
 {
     wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );
 
-    if (!(GTK_EDITABLE(m_text)->has_selection))
+    long from, to;
+    if ( !(GTK_EDITABLE(m_text)->has_selection) )
     {
-        long i = GetInsertionPoint();
-        if (from) *from = i;
-        if (to)   *to = i;
-        return;
+        from =
+        to = GetInsertionPoint();
+    }
+    else // got selection
+    {
+        from = (long) GTK_EDITABLE(m_text)->selection_start_pos;
+        to = (long) GTK_EDITABLE(m_text)->selection_end_pos;
+
+        if ( from > to )
+        {
+            // exchange them to be compatible with wxMSW
+            long tmp = from;
+            from = to;
+            to = tmp;
+        }
     }
 
-    if (from) *from = (long) GTK_EDITABLE(m_text)->selection_start_pos;
-    if (to)   *to = (long) GTK_EDITABLE(m_text)->selection_end_pos;
+    if ( fromOut )
+        *fromOut = from;
+    if ( toOut )
+        *toOut = to;
 }
 
 bool wxTextCtrl::IsEditable() const