]> git.saurik.com Git - wxWidgets.git/commitdiff
check for error in GetSelection(long *, long *); clean up SetSelect(long, long)
authorVadim Zeitlin <vadim@wxwidgets.org>
Fri, 21 Jan 2005 15:02:58 +0000 (15:02 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Fri, 21 Jan 2005 15:02:58 +0000 (15:02 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@31542 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/msw/combobox.cpp

index 4bb8998363281544bb3aa2ba7e7c956bfa762fe3..642e48329ae4dfacf27b63af69ab8f3b14be2660 100644 (file)
@@ -650,12 +650,11 @@ void wxComboBox::SetInsertionPointEnd()
 
 long wxComboBox::GetInsertionPoint() const
 {
-#ifdef __WIN32__
-    DWORD Pos=(DWORD)SendMessage(GetHwnd(), CB_GETEDITSEL, 0, 0L);
-    return Pos&0xFFFF;
-#else
-    return 0;
-#endif
+    // CB_GETEDITSEL returns the index of the last character after selection in
+    // its high-order word
+    DWORD pos= (DWORD)::SendMessage(GetHwnd(), CB_GETEDITSEL, 0, 0L);
+
+    return HIWORD(pos);
 }
 
 wxTextPos wxComboBox::GetLastPosition() const
@@ -691,19 +690,15 @@ void wxComboBox::Remove(long from, long to)
 
 void wxComboBox::SetSelection(long from, long to)
 {
-    HWND hWnd = GetHwnd();
-    long fromChar = from;
-    long toChar = to;
-    // if from and to are both -1, it means
-    // (in wxWidgets) that all text should be selected.
-    // This translates into Windows convention
-    if ((from == -1) && (to == -1))
+    // if from and to are both -1, it means (in wxWidgets) that all text should
+    // be selected, translate this into Windows convention
+    if ( (from == -1) && (to == -1) )
     {
-      fromChar = 0;
-      toChar = -1;
+        from = 0;
     }
 
-    if ( SendMessage(hWnd, CB_SETEDITSEL, (WPARAM)0, (LPARAM)MAKELONG(fromChar, toChar)) == CB_ERR )
+    if ( SendMessage(GetHwnd(), CB_SETEDITSEL,
+                     0, (LPARAM)MAKELONG(from, to)) == CB_ERR )
     {
         wxLogDebug(_T("CB_SETEDITSEL failed"));
     }
@@ -712,10 +707,17 @@ void wxComboBox::SetSelection(long from, long to)
 void wxComboBox::GetSelection(long* from, long* to) const
 {
     DWORD dwStart, dwEnd;
-    ::SendMessage(GetHwnd(), CB_GETEDITSEL, (WPARAM)&dwStart, (LPARAM)&dwEnd);
-
-    *from = dwStart;
-    *to = dwEnd;
+    if ( ::SendMessage(GetHwnd(), CB_GETEDITSEL,
+                       (WPARAM)&dwStart, (LPARAM)&dwEnd) == CB_ERR )
+    {
+        *from =
+        *to = 0;
+    }
+    else
+    {
+        *from = dwStart;
+        *to = dwEnd;
+    }
 }
 
 int wxComboBox::GetSelection() const