From 55b51f1788e49766c1d23bf7a2f69db1d1b9de13 Mon Sep 17 00:00:00 2001 From: juha Date: Sat, 18 Feb 2017 11:26:43 +0000 Subject: [PATCH] LCL: Implement TTreeView.MultiSelectStyle. Issue #18043, patch from AlexeyT. git-svn-id: trunk@54187 - --- lcl/comctrls.pp | 2 ++ lcl/include/treeview.inc | 36 +++++++++++++++++++++++------------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/lcl/comctrls.pp b/lcl/comctrls.pp index 7696787ba9..f1b45f8d22 100644 --- a/lcl/comctrls.pp +++ b/lcl/comctrls.pp @@ -3383,6 +3383,8 @@ type procedure UpdateScrollbars; procedure UpdateTooltip(X, Y: integer); procedure InternalSelectionChanged; + function AllowMultiSelectWithCtrl(AState: TShiftState): Boolean; + function AllowMultiSelectWithShift(AState: TShiftState): Boolean; protected FChangeTimer: TTimer; FEditor: TEdit; diff --git a/lcl/include/treeview.inc b/lcl/include/treeview.inc index e6450a822a..cbe3b83645 100644 --- a/lcl/include/treeview.inc +++ b/lcl/include/treeview.inc @@ -4041,37 +4041,37 @@ begin VK_DOWN: begin - MoveToNextNode(ssShift in Shift); + MoveToNextNode(AllowMultiSelectWithShift(Shift)); Key:=VK_UNKNOWN; end; VK_UP: begin - MoveToPrevNode(ssShift in Shift); + MoveToPrevNode(AllowMultiSelectWithShift(Shift)); Key:=VK_UNKNOWN; end; VK_HOME: begin - MoveHome(ssShift in Shift); + MoveHome(AllowMultiSelectWithShift(Shift)); Key:=VK_UNKNOWN; end; VK_END: begin - MoveEnd(ssShift in Shift); + MoveEnd(AllowMultiSelectWithShift(Shift)); Key:=VK_UNKNOWN; end; VK_PRIOR: // Page Up begin - MovePageUp(ssShift in Shift); + MovePageUp(AllowMultiSelectWithShift(Shift)); Key:=VK_UNKNOWN; end; VK_NEXT: // Page Down begin - MovePageDown(ssShift in Shift); + MovePageDown(AllowMultiSelectWithShift(Shift)); Key:=VK_UNKNOWN; end; @@ -4079,7 +4079,7 @@ begin if not (Key in [VK_LEFT,VK_RIGHT,VK_ADD,VK_SUBTRACT]) then Exit; - if (tvoAllowMultiSelect in FOptions) and (ssShift in Shift) then + if (tvoAllowMultiSelect in FOptions) and AllowMultiSelectWithShift(Shift) then lNode := FTreeNodes.FLastMultiSelected else lNode := Selected; @@ -4121,7 +4121,7 @@ begin end; if lNode <> nil then - MoveSelection(lNode, ([ssShift] * Shift) <> []); + MoveSelection(lNode, AllowMultiSelectWithShift(Shift)); end; end; @@ -5361,7 +5361,7 @@ begin //change selection on right click if (Button = mbRight) and RightClickSelect and//right click (([ssDouble, ssTriple, ssQuad] * Shift) = []) and//single or first of a multi click - not(ssCtrl in Shift) and//only when CTRL is not pressed + not AllowMultiSelectWithCtrl(Shift) and//only when CTRL is not pressed (CursorNode <> nil) and (LogicalX >= CursorNode.DisplayStateIconLeft)//only after expand sign then @@ -5409,17 +5409,17 @@ begin Selected := CursorNode else begin - if (ssShift in Shift) then + if AllowMultiSelectWithShift(Shift) then begin Exclude(FStates,tvsEditOnMouseUp); LockSelectionChangeEvent; try - Items.MultiSelect(CursorNode, not(ssCtrl in Shift)); + Items.MultiSelect(CursorNode, not AllowMultiSelectWithCtrl(Shift)); finally UnlockSelectionChangeEvent; end; end - else if (ssCtrl in Shift) then + else if AllowMultiSelectWithCtrl(Shift) then begin Exclude(FStates,tvsEditOnMouseUp); CursorNode.MultiSelected:=not CursorNode.MultiSelected; @@ -5820,6 +5820,16 @@ begin end; end; +function TCustomTreeView.AllowMultiSelectWithCtrl(AState: TShiftState): Boolean; +begin + Result := (ssCtrl in AState) and (msControlSelect in FMultiSelectStyle); +end; + +function TCustomTreeView.AllowMultiSelectWithShift(AState: TShiftState): Boolean; +begin + Result := (ssShift in AState) and (msShiftSelect in FMultiSelectStyle); +end; + class procedure TCustomTreeView.WSRegisterClass; begin inherited WSRegisterClass; @@ -6022,7 +6032,7 @@ end; procedure TCustomTreeView.Select(Node: TTreeNode; ShiftState: TShiftState = []); begin - if (tvoAllowMultiSelect in FOptions) and (ssCtrl in ShiftState) then + if (tvoAllowMultiSelect in FOptions) and AllowMultiSelectWithCtrl(ShiftState) then Node.Selected := True else begin ClearSelection;