TreeView: Fix selection and scrolling behaviour when ShowCheck property is set.

[GB.GUI.BASE]
* BUG: TreeView: Fix selection and scrolling behaviour when ShowCheck property is set.
This commit is contained in:
gambas 2020-05-20 11:40:27 +02:00
parent 6a8055ccc4
commit ff5ec08817
5 changed files with 69 additions and 49 deletions

View file

@ -7,7 +7,7 @@ Component=gb.image
Component=gb.gui
Arguments=[["-style=oxygen"],["-style=qtcurve"]]
CurrentArgument=0
Environment="GB_JIT_DEBUG=1\nGB_GUI=gb.gtk3\nLIBOVERLAY_SCROLLBAR=0"
Environment="GB_JIT_DEBUG=1\nGB_GUI=gb.qt5\nLIBOVERLAY_SCROLLBAR=0"
TabSize=2
Language=fr
Type=Component

View file

@ -62,6 +62,7 @@ Event Draw(X As Integer, Y As Integer, Width As Integer, Height As Integer, Row
Public _DoNotDrawSelection As Boolean
Public _NoMouse As Boolean
Public _ToggleSelection As Boolean
Private $hView As ScrollArea
Private $bGrid As Boolean = True
@ -956,6 +957,19 @@ Private Sub InRowHeader(X As Integer) As Boolean
End
Private Sub StartScrollTimer()
Dim F As Integer = _GetFrameWidth()
$SX = Mouse.X - F
$SY = Mouse.Y - F
If $hTimerScroll Then Return
$hTimerScroll = New Timer(50) As "TimerScroll"
End
Public Sub ScrollArea_MouseMove()
@ -972,11 +986,7 @@ Public Sub ScrollArea_MouseMove()
If $hRows.Count = 0 And If $hColumns.Count = 0 Then Return
If $bInCell And If Mouse.Left And If Not $hTimerScroll Then
$hTimerScroll = New Timer As "TimerScroll"
$hTimerScroll.Delay = 50
$hTimerScroll.Start
Endif
If $bInCell And If Mouse.Left Then StartScrollTimer
MX = Mouse.X - F
MY = Mouse.Y - F
@ -1092,8 +1102,6 @@ Public Sub ScrollArea_MouseMove()
X = MX
Y = MY
$SX = X
$SY = Y
If Not System.RightToLeft Then X -= $hRows.W
@ -1171,7 +1179,6 @@ Public Sub _EnsureVisibleScroll(X As Integer, Y As Integer)
End
Public Sub ScrollArea_MouseDrag()
If Me.Design Then Return
@ -1179,16 +1186,12 @@ Public Sub ScrollArea_MouseDrag()
If _NoMouse Then Return
$bIgnoreMove = False
If $bResize Or If $bMoveSelect Then
If $bResize Or If $bMoveSelect Or If $bMoveUnselect Then
Stop Event
Return
Endif
If Not $hTimerScroll Then
$hTimerScroll = New Timer As "TimerScroll"
$hTimerScroll.Delay = 50
$hTimerScroll.Start
Endif
StartScrollTimer
End
@ -1243,12 +1246,17 @@ Public Sub ScrollArea_MouseDown()
Dec $iRow
MoveTo($iRow + 1, -1)
Else If Not _IsRowSelected($iRow) Then
$hRows._GetSel().UnSelectAll
If Not _ToggleSelection Then $hRows._GetSel().UnSelectAll
$hRows.Select($iRow, 1)
$iMoveSelectRow = $iRow
$hMoveOldSelection = $hRows._SaveSelection()
$bMoveSelect = True
Else
If _ToggleSelection Then
$hRows.UnSelect($iRow, 1)
$hMoveOldSelection = $hRows._SaveSelection()
$bMoveUnSelect = True
Endif
$iMoveSelectRow = $iRow
Endif
Endif
@ -1297,6 +1305,12 @@ End
Private Sub AfterMouseUp()
If Me.Design Then Return
If $hTimerScroll Then
$hTimerScroll.Stop
$hTimerScroll = Null
Endif
If _NoMouse Then Return
$bResize = False
@ -1306,11 +1320,6 @@ Private Sub AfterMouseUp()
$iMoveSelectRow = -1
$bIgnoreMove = False
If $hTimerScroll Then
$hTimerScroll.Stop
$hTimerScroll = Null
Endif
End
@ -1444,7 +1453,7 @@ Public Sub MoveTo(Row As Integer, Column As Integer)
Raise Change
If $iMode = Select.Single Then
Raise Select
Else If $bMoveSelect Or $bMoveUnSelect Then
Else If $bMoveSelect Or If $bMoveUnSelect Then
If $hMoveOldSelection Then
$hRows._RestoreSelection($hMoveOldSelection)
S = Min($iRow, $iMoveSelectRow)

View file

@ -86,6 +86,7 @@ End
Public Sub tvwTest_MouseDrag()
Debug "START"
Drag.Icon = Picture["icon:/small/text"]
Drag(tvwTest, "toto", "text/plain")
Debug "END"

View file

@ -57,12 +57,14 @@
MoveScaled(13,22,42,26)
Drop = True
Expand = True
Mode = Select.Multiple
Sorted = True
Editable = True
Header = False
Resizable = True
Border = False
ShowLines = True
ShowCheck = True
}
{ GridView1 GridView
MoveScaled(20,51,37,27)

View file

@ -751,8 +751,6 @@ Public Sub GridView_MouseDown()
Dim iRow As Integer = $hView.RowAt(Mouse.Y)
Dim hItem As _TreeView_Item = RowToItem(iRow)
Dim X As Integer
Dim iFrom As Integer
Dim bSelect As Boolean
If Not hItem Then Return
If Mouse.Click > 1 Then Return
@ -782,30 +780,39 @@ Public Sub GridView_MouseDown()
Endif
If $bShowCheck Then
If System.RightToLeft Then
X -= $iDepthW
Else
X += $iDepthW
Endif
If Mouse.X >= X + $iDepthW \ 8 Then 'And If Mouse.X < X + $iDepthW - $iDepthW \ 8 Then
iFrom = $hView.Row
If Mouse.Shift And If iFrom >= 0 Then
bSelect = RowToItem(iFrom).Selected
While iFrom <> iRow
iFrom += Sgn(iRow - iFrom)
RowToItem(iFrom).Selected = bSelect
Wend
Else
hItem.Selected = Not hItem.Selected
Endif
Endif
$hView.Row = iRow
Endif
' If False Then
'
' If System.RightToLeft Then
' X -= $iDepthW
' Else
' X += $iDepthW
' Endif
'
' If Mouse.X >= X + $iDepthW \ 8 Then 'And If Mouse.X < X + $iDepthW - $iDepthW \ 8 Then
'
' iFrom = $hView.Row
' If Mouse.Shift And If iFrom >= 0 Then
' $bSelectItem = RowToItem(iFrom).Selected
' While iFrom <> iRow
' iFrom += Sgn(iRow - iFrom)
' RowToItem(iFrom).Selected = $bSelectItem
' Wend
' $hView.Row = iRow
' Else
' $hView.Row = iRow
' hItem.Selected = Not hItem.Selected
' $bSelectItem = hItem.Selected
' Endif
'
' Stop Event
'
' Else
'
' $hView.Row = iRow
'
' Endif
'
' Endif
End
@ -1799,7 +1806,8 @@ Private Sub ShowCheck_Write(Value As Boolean)
If $bShowCheck = Value Then Return
$bShowCheck = Value
$hView._DoNotDrawSelection = Value
$hView._NoMouse = Value
$hView._ToggleSelection = Value
'$hView._NoMouse = Value
$hView.Refresh
End