'****************************************************************************
'* Copyright (C) 2004 Peter Mortensen and Matthias Mann *
'* This file is part of MSQuant. *
'* *
'* MSQuant is distributed under the terms of *
'* the GNU General Public License. See src/COPYING.TXT or *
'* <http://www.gnu.org/licenses/gpl.txt> for details. *
'* *
'* MSQuant is free software; you can redistribute it *
'* and/or modify it under the terms of the GNU *
'* General Public License as published by the Free *
'* Software Foundation; either version 2 of the *
'* License, or (at your option) any later version. *
'* *
'* MSQuant is distributed in the hope that it will be *
'* useful, but WITHOUT ANY WARRANTY; without even the *
'* implied warranty of MERCHANTABILITY or FITNESS FOR *
'* A PARTICULAR PURPOSE. See the GNU General Public *
'* License for more details. *
'* *
'* You should have received a copy of the GNU General *
'* Public License along with MSQuant; if not, write to *
'* the Free Software Foundation, Inc., 59 Temple *
'* Place, Suite 330, Boston, MA 02111-1307 USA *
'* *
'* Purpose: XYZ. *
'* Holds Class ListViewCEBIExtended4, see below for *
'* documentation. *
'* *
'****************************************************************************
'****************************************************************************
'* CEBI *
'* Software Development Group *
'* Peter Mortensen *
'* E-mail: NUKESPAMMERSdrmortensen@get2netZZZZZZ.dk *
'* WWW: http://www.cebi.sdu.dk/ *
'* *
'* Program for post-processing of result from search in mass *
'* spectrometric data. *
'* *
'* FILENAME: ListViewCEBIExtended4.vb *
'* TYPE: VISUAL_BASIC *
'* *
'* CREATED: PM 2004-07-01 Vrs 1.0. Estimated date... *
'* UPDATED: PM 2007-xx-xx *
'* *
'****************************************************************************
'Changed PM_WORK_ON_SELECTION 2004-07-06. All of this file...
Option Strict On
Option Explicit On
'Purpose: subclasses the .NET ListView control to overcome some bugs in it.
' Our purpose is to let the user select a range, possibly discontinous,
' of rows without any change of the Checked status.
' Based on <http://www.gotdotnet.com/community/messageboard/Thread.aspx?id=236954>.
'
Public Class ListViewCEBIExtended4
Inherits System.Windows.Forms.ListView
Private mLeftMouseDown As Boolean = False
Private mLeftMouseDownPosition As Point
'****************************************************************************
'* <placeholder for header> *
'****************************************************************************
Protected Function IsControlDown() As Boolean
'Should we not use bitwise AND???????????
'C#: return (Control.ModifierKeys & Keys.Control) == Keys.Control;
Return Control.ModifierKeys = Keys.Control
End Function 'IsControlDown
'****************************************************************************
'* <placeholder for header> *
'****************************************************************************
Protected Function IsShiftDown() As Boolean
'Should we not use bitwise AND???????????
'C#: return (Control.ModifierKeys & Keys.Shift) == Keys.Shift;
Return Control.ModifierKeys = Keys.Shift
End Function 'IsShiftDown
'****************************************************************************
'* <placeholder for header> *
'* *
'* OnMouseDown and OnMouseUp: resolve the issues of items being randomly *
'* selected while using the mouse select or control and shift keys to *
'* select items. Add this code to the MouseDown and MouseUp events so *
'* that we know if the left mouse is down. *
'****************************************************************************
Protected Overrides Sub OnMouseDown( _
ByVal anEvent As System.Windows.Forms.MouseEventArgs)
MyBase.OnMouseDown(anEvent)
'Changed PM_VS2005 2006-06-14
'If anEvent.Button = Windows.Forms.MouseButtons.Left Then
If anEvent.Button = Windows.Forms.MouseButtons.Left Then
mLeftMouseDown = True
mLeftMouseDownPosition = New Point(anEvent.X, anEvent.Y)
End If
End Sub 'OnMouseDown
'****************************************************************************
'* <placeholder for header> *
'* *
'* OnMouseDown and OnMouseUp: resolve the issues of items being randomly *
'* selected while using the mouse select or control and shift keys to *
'* select items. Add this code to the MouseDown and MouseUp events so *
'* that we know if the left mouse is down. *
'****************************************************************************
Protected Overrides Sub OnMouseUp( _
ByVal anEvent As System.Windows.Forms.MouseEventArgs)
MyBase.OnMouseUp(anEvent)
'Changed PM_VS2005 2006-06-14
'If anEvent.Button = Windows.Forms.MouseButtons.Left Then
If anEvent.Button = Windows.Forms.MouseButtons.Left Then
mLeftMouseDown = False
End If
End Sub 'OnMouseDown
'****************************************************************************
'* <placeholder for header> *
'* In the item check, filter out the checking of items if the left *
'* mouse is down and has moved, or tthe left mouse is down and *
'* the control or shift key is pressed. *
'****************************************************************************
Protected Overrides Sub OnItemCheck( _
ByVal anEvent As System.Windows.Forms.ItemCheckEventArgs)
'Changed PM_MULTSELECT_PROTEINCHECKED_CLEAR_BUG 2005-03-15
'Moved down as we need to signal to handler whether it is a selection
' or a change in the check status.
'MyBase.OnItemCheck(anEvent)
Dim mousePosition As Point = Me.PointToClient(Control.MousePosition)
Dim mouseHasMoved As Boolean = _
(mousePosition.X <> mLeftMouseDownPosition.X) Or _
(mousePosition.Y <> mLeftMouseDownPosition.Y)
'Holding the mouse key down and moving the cursor to
'select items in the list to select items results in the
'list check items at random. Also, holding down control or
'shift and clicking to select items causes the same issue.
'This is a Microsoft bug.
'
'This bug is only present when FullRowSelect = true,
'MultiSelect = true and CheckBoxes = true.
'
'In order to fix this bug, we cancel the checks when the
'mouse is down and has moved, the shift key is down, or
'the control key is down. The reason we check to see if
'the mouse has moved is to allow clicks of a checkbox in
'the list to be handled without cancelling.
Dim notChecked As Boolean = _
(mLeftMouseDown AndAlso _
(Me.IsShiftDown() Or IsControlDown() Or mouseHasMoved))
If notChecked Then
'Adjust the new checked status as it is not really
'changing, only the selection was set (for several items).
anEvent.NewValue = anEvent.CurrentValue
Else
'Checked status was really changed
MyBase.OnItemCheck(anEvent) 'Should this be unconditional at the
' end of this function??
End If
End Sub 'OnItemCheck
End Class 'ListViewCEBIExtended4
Generated by script codePublish.pl at 2009-01-05T15:20:59.