// Internal Helper function for computing row or column from some
 // (unscrolled) coordinate value, using either
-// m_defaultRowHeight/m_defaultColWidth or binary search on array 
+// m_defaultRowHeight/m_defaultColWidth or binary search on array
 // of m_rowBottoms/m_ColRights to speed up the search!
 
 // Internal helper macros for simpler use of that function
 
     if (m_isDragging)
     {
-        m_rowLabelWin->ReleaseMouse();
+        if (m_rowLabelWin->HasCapture()) m_rowLabelWin->ReleaseMouse();
         m_isDragging = FALSE;
     }
 
 
     if (m_isDragging)
     {
-        m_colLabelWin->ReleaseMouse();
+        if (m_colLabelWin->HasCapture()) m_colLabelWin->ReleaseMouse();
         m_isDragging = FALSE;
     }
 
 
     if ( m_winCapture )
     {
-        m_winCapture->ReleaseMouse();
+        if (m_winCapture->HasCapture()) m_winCapture->ReleaseMouse();
         m_winCapture = (wxWindow *)NULL;
     }
 
             {
                 if (m_winCapture)
                 {
-                    m_winCapture->ReleaseMouse();
+                    if (m_winCapture->HasCapture()) m_winCapture->ReleaseMouse();
                     m_winCapture = NULL;
                 }
 
 
             // cell is shifted by one pixel
             // However, don't allow x or y to become negative
-            // since the SetSize() method interprets that as 
+            // since the SetSize() method interprets that as
             // "don't change."
             if (rect.x > 0)
                 rect.x--;
 
 // Internal Helper function for computing row or column from some
 // (unscrolled) coordinate value, using either
-// m_defaultRowHeight/m_defaultColWidth or binary search on array 
+// m_defaultRowHeight/m_defaultColWidth or binary search on array
 // of m_rowBottoms/m_ColRights to speed up the search!
 
 static int CoordToRowOrCol(int coord, int defaultDist, int minDist,
 
     if ( i_max >= BorderArray.GetCount())
         i_max = BorderArray.GetCount() - 1;
-    else 
+    else
     {
         if ( coord >= BorderArray[i_max])
         {