From b385b12038cce0d14c28a4a606d1f5bf978dbfa2 Mon Sep 17 00:00:00 2001 From: lazarus Date: Mon, 9 Sep 2002 19:04:01 +0000 Subject: [PATCH] MG: started TTreeView dragging git-svn-id: trunk@3308 - --- lcl/comctrls.pp | 30 +++++----- lcl/include/treeview.inc | 118 +++++++++++++++++++-------------------- 2 files changed, 75 insertions(+), 73 deletions(-) diff --git a/lcl/comctrls.pp b/lcl/comctrls.pp index 66a9f1adbf..25f9561eb1 100644 --- a/lcl/comctrls.pp +++ b/lcl/comctrls.pp @@ -932,7 +932,7 @@ type function GetHasChildren: Boolean; function GetCount: Integer; function GetCut: boolean; - //function GetDropTarget: Boolean; + function GetDropTarget: Boolean; function GetExpanded: Boolean; function GetFocused: Boolean; function GetHeight: integer; @@ -953,7 +953,7 @@ type procedure ReadDelphiData(Stream: TStream; Info: PDelphiNodeInfo); procedure SetCut(AValue: Boolean); procedure SetData(AValue: Pointer); - //procedure SetDropTarget(Value: Boolean); + procedure SetDropTarget(AValue: Boolean); procedure SetExpanded(AValue: Boolean); procedure SetFocused(AValue: Boolean); procedure SetHasChildren(AValue: Boolean); @@ -1023,7 +1023,7 @@ type property Data: Pointer read FData write SetData; property Deleting: Boolean read FDeleting; property Focused: Boolean read GetFocused write SetFocused; - //property DropTarget: Boolean read GetDropTarget write SetDropTarget; + property DropTarget: Boolean read GetDropTarget write SetDropTarget; property Expanded: Boolean read GetExpanded write SetExpanded; property Handle: THandle read GetHandle; property HasChildren: Boolean read GetHasChildren write SetHasChildren; @@ -1174,8 +1174,7 @@ type tvoRowSelect, tvoKeepCollapsedNodes, tvoShowSeparators, - tvoAllowMultiselect, - tvoAutoItemHeight + tvoAllowMultiselect ); TTreeViewOptions = set of TTreeViewOption; @@ -1245,14 +1244,14 @@ type //procedure CMColorChanged(var Message: TMessage); message CM_COLORCHANGED; //procedure CMCtl3DChanged(var Message: TMessage); message CM_CTL3DCHANGED; //procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED; - //procedure CMDrag(var Message: TCMDrag); message CM_DRAG; + procedure CMDrag(var AMessage: TCMDrag); message CM_DRAG; //procedure CNNotify(var Message: TWMNotify); message CN_NOTIFY; procedure EditWndProc(var Message: TLMessage); - //procedure DoDragOver(Source: TDragObject; X, Y: Integer; CanDrop: Boolean); + procedure DoDragOver(Source: TDragObject; X, Y: Integer; CanDrop: Boolean); function GetAutoExpand: boolean; function GetBottomItem: TTreeNode; function GetChangeDelay: Integer; - //function GetDropTarget: TTreeNode; + function GetDropTarget: TTreeNode; function GetHideSelection: boolean; function GetHotTrack: boolean; function GetKeepCollapsedNodes: boolean; @@ -1276,7 +1275,7 @@ type procedure SetChangeDelay(Value: Integer); procedure SetDefaultItemHeight(Value: integer); procedure SetExpandSignType(Value: TTreeViewExpandSignType); - //procedure SetDropTarget(Value: TTreeNode); + procedure SetDropTarget(Value: TTreeNode); procedure SetHideSelection(Value: Boolean); procedure SetHotTrack(Value: Boolean); //procedure SetImageList(Value: HImageList; Flags: Integer); @@ -1310,8 +1309,8 @@ type procedure UpdateScrollbars; procedure WMHScroll(var Msg: TLMScroll); message LM_HSCROLL; procedure WMVScroll(var Msg: TLMScroll); message LM_VSCROLL; - procedure WMLButtonDown(var Message: TLMLButtonDown); message LM_LBUTTONDOWN; - procedure WMNotify(var Message: TLMNotify); message LM_NOTIFY; + procedure WMLButtonDown(var AMessage: TLMLButtonDown); message LM_LBUTTONDOWN; + procedure WMNotify(var AMessage: TLMNotify); message LM_NOTIFY; procedure WMSize(var Msg: TLMSize); message LM_SIZE; //procedure WMContextMenu(var Message: TLMContextMenu); message LM_CONTEXTMENU; //procedure CMSysColorChange(var Message: TMessage); message CM_SYSCOLORCHANGE; @@ -1340,7 +1339,7 @@ type procedure EndEditing; procedure EnsureNodeIsVisible(ANode: TTreeNode); procedure Expand(Node: TTreeNode); dynamic; - //function GetDragImages: TDragImageList; override; + function GetDragImages: TDragImageList; //override; procedure GetImageIndex(Node: TTreeNode); virtual; function GetMaxLvl: integer; function GetMaxScrollLeft: integer; @@ -1433,7 +1432,7 @@ type property BorderWidth; property BottomItem: TTreeNode read GetBottomItem write SetBottomItem; property Canvas: TCanvas read FCanvas; - //property DropTarget: TTreeNode read GetDropTarget write SetDropTarget; + property DropTarget: TTreeNode read GetDropTarget write SetDropTarget; property DefaultItemHeight: integer read FDefItemHeight write SetDefaultItemHeight; property ExpandSignType: TTreeViewExpandSignType @@ -1462,7 +1461,7 @@ type property ChangeDelay; property Color; property Ctl3D; - //property Constraints; + property Constraints; property DefaultItemHeight; property DragKind; property DragCursor; @@ -1656,6 +1655,9 @@ end. { ============================================================================= $Log$ + Revision 1.41 2002/09/09 19:04:01 lazarus + MG: started TTreeView dragging + Revision 1.40 2002/09/09 17:41:18 lazarus MG: added multiselection to TTreeView diff --git a/lcl/include/treeview.inc b/lcl/include/treeview.inc index 4cbcf8f550..8a5c688ea7 100644 --- a/lcl/include/treeview.inc +++ b/lcl/include/treeview.inc @@ -510,16 +510,26 @@ begin TreeView_SetItem(Handle, Item);} end; -{function TTreeNode.GetDropTarget: Boolean; +function TTreeNode.GetDropTarget: Boolean; begin Result := GetState(nsDropHilited); -end;} +end; -{procedure TTreeNode.SetDropTarget(Value: Boolean); +procedure TTreeNode.SetDropTarget(AValue: Boolean); begin - if Value then TreeView_SelectDropTarget(Handle, ItemId) - else if DropTarget then TreeView_SelectDropTarget(Handle, nil); -end;} + if AValue=GetDropTarget then exit; + if AValue then begin + Include(FStates,nsDropHilited); + if TreeView<>nil then + TreeView.FLastDropTarget:=Self; + end else begin + Exclude(FStates,nsDropHilited); + if TreeView<>nil then + TreeView.FLastDropTarget:=nil; + end; + {if Value then TreeView_SelectDropTarget(Handle, ItemId) + else if DropTarget then TreeView_SelectDropTarget(Handle, nil);} +end; function TTreeNode.GetHasChildren: Boolean; begin @@ -869,6 +879,8 @@ begin if Owner.Owner<>nil then begin Owner.Owner.FStates:=Owner.Owner.FStates+[tvsMaxRightNeedsUpdate, tvsTopsNeedsUpdate,tvsTopItemNeedsUpdate,tvsBottomItemNeedsUpdate]; + if Owner.Owner.FLastDropTarget=Self then + Owner.Owner.FLastDropTarget:=nil; end; end; UnbindFromMultiSelected; @@ -3374,15 +3386,17 @@ begin Result := FChangeTimer.Interval; end; -{function TCustomTreeView.GetDropTarget: TTreeNode; +function TCustomTreeView.GetDropTarget: TTreeNode; begin if HandleAllocated then begin - Result := Items.GetNode(TreeView_GetDropHilite(Handle)); - if Result = nil then Result := FLastDropTarget; + //Result := Items.GetNode(TreeView_GetDropHilite(Handle)); + //if Result = nil then Result := FLastDropTarget; + Result := FLastDropTarget; end - else Result := nil; -end;} + else + Result := nil; +end; function TCustomTreeView.GetHideSelection: boolean; begin @@ -3414,12 +3428,14 @@ begin Result:=(tvoRowSelect in FOptions); end; -{procedure TCustomTreeView.SetDropTarget(Value: TTreeNode); +procedure TCustomTreeView.SetDropTarget(Value: TTreeNode); begin if HandleAllocated then - if Value <> nil then Value.DropTarget := True - else TreeView_SelectDropTarget(Handle, nil); -end;} + if Value <> nil then + Value.DropTarget := True; + {else + TreeView_SelectDropTarget(Handle, nil);} +end; {function TCustomTreeView.GetNodeFromItem(const Item: TTVItem): TTreeNode; begin @@ -3672,14 +3688,14 @@ begin end; end;} -{function TCustomTreeView.GetDragImages: TDragImageList; +function TCustomTreeView.GetDragImages: TDragImageList; begin if FDragImage.Count > 0 then Result := FDragImage else Result := nil; end; -} + procedure TCustomTreeView.WndProc(var Message: TLMessage); begin if not (csDesigning in ComponentState) @@ -3732,14 +3748,15 @@ begin FLastDropTarget := nil; end; -{procedure TCustomTreeView.CMDrag(var Message: TCMDrag); +procedure TCustomTreeView.CMDrag(var AMessage: TCMDrag); begin - inherited; - with Message, DragRec^ do + inherited CMDrag(AMessage); +writeln('TCustomTreeView.CMDrag ',ord(AMessage.DragMessage)); + with AMessage, DragRec^ do case DragMessage of dmDragMove: with ScreenToClient(Pos) do - DoDragOver(Source, X, Y, Message.Result <> 0); + DoDragOver(Source, X, Y, AMessage.Result <> 0); dmDragLeave: begin TDragObject(Source).HideDragImage; @@ -3749,23 +3766,24 @@ begin end; dmDragDrop: FLastDropTarget := nil; end; -end;} +end; -{procedure TCustomTreeView.DoDragOver(Source: TDragObject; X, Y: Integer; +procedure TCustomTreeView.DoDragOver(Source: TDragObject; X, Y: Integer; CanDrop: Boolean); var Node: TTreeNode; begin Node := GetNodeAt(X, Y); - if (Node <> nil) and - ((Node <> DropTarget) or (Node = FLastDropTarget)) then +writeln('TCustomTreeView.DoDragOver ',Node<>nil,' ',Node <> DropTarget,' ',Node = FLastDropTarget); + if (Node <> nil) + and ((Node <> DropTarget) or (Node = FLastDropTarget)) then begin FLastDropTarget := nil; TDragObject(Source).HideDragImage; Node.DropTarget := True; TDragObject(Source).ShowDragImage; end; -end;} +end; procedure TCustomTreeView.DoPaint; var @@ -4181,22 +4199,16 @@ begin end else begin Items.ClearMultiSelection; CursorNode.MultiSelected:=true; - writeln('AAA1 ',CursorNode.MultiSelected); end; end; bStartDrag := true; end; end; - if (Button = mbLeft) and bStartDrag then - Include(fStates, tvsWaitForDragging) - else begin - if ([tvsDblClicked,tvsTripleClicked,tvsQuadClicked]*fStates)<>[] then - begin - if Button=mbMiddle then begin - // insert primary selection text + if (bStartDrag) then + Include(fStates, tvsWaitForDragging); + if Button=mbMiddle then begin + // insert primary selection text - end; - end; end; end; //LCLLinux.SetFocus(Handle); @@ -4205,20 +4217,13 @@ end; procedure TCustomTreeView.MouseMove(Shift: TShiftState; X, Y: Integer); begin inherited MouseMove(Shift, x, y); - if (X>=ClientWidth-ScrollBarWidth) or (Y>=(ClientHeight-ScrollBarWidth)) then - begin - // workaround vs scrollbar clientrect bug in lcl - exit; - end; - if MouseCapture and (tvsWaitForDragging in fStates) then begin + if {MouseCapture and} (tvsWaitForDragging in fStates) then begin if (Abs(fMouseDownX - X) >= GetSystemMetrics(SM_CXDRAG)) - or (Abs(fMouseDownY - Y) >= GetSystemMetrics(SM_CYDRAG)) + or (Abs(fMouseDownY - Y) >= GetSystemMetrics(SM_CYDRAG)) then begin Exclude(fStates, tvsWaitForDragging); - //BeginDrag(false); + BeginDrag(false); end; - end else if (ssLeft in Shift) and MouseCapture then begin - end; end; @@ -4226,22 +4231,17 @@ procedure TCustomTreeView.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin inherited MouseUp(Button, Shift, X, Y); - if (X>=ClientWidth-ScrollBarWidth) or (Y>=(ClientHeight-ScrollBarWidth)) then - begin - exit; - end; if (Button = mbRight) and (Shift = [ssRight]) and Assigned(PopupMenu) then exit; MouseCapture := False; - if fStates * [tvsDblClicked, tvsWaitForDragging] = [tvsWaitForDragging] then - begin - Exclude(fStates, tvsWaitForDragging); - end; + Exclude(fStates, tvsWaitForDragging); if (Button=mbLeft) - and (fStates * [tvsDblClicked, tvsWaitForDragging] = []) then begin + and (fStates * [tvsDblClicked, tvsTripleClicked, tvsQuadClicked, + tvsWaitForDragging] = []) + then begin //AquirePrimarySelection; end; - Exclude(fStates, tvsDblClicked); + fStates:=fStates-[tvsDblClicked,tvsTripleClicked,tvsQuadClicked]; end; procedure TCustomTreeView.Notification(AComponent: TComponent; @@ -4383,7 +4383,7 @@ begin end; end; -procedure TCustomTreeView.WMLButtonDown(var Message: TLMLButtonDown); +procedure TCustomTreeView.WMLButtonDown(var AMessage: TLMLButtonDown); var Node: TTreeNode; MousePos: TPoint; @@ -4401,7 +4401,7 @@ begin Perform(LM_LBUTTONUP, 0, MakeLong(X, Y)); end else begin - Node := GetNodeAt(Message.XPos, Message.YPos); + Node := GetNodeAt(AMessage.XPos, AMessage.YPos); if Node <> nil then begin Node.Focused := True; @@ -4415,7 +4415,7 @@ begin end; end; -procedure TCustomTreeView.WMNotify(var Message: TLMNotify); +procedure TCustomTreeView.WMNotify(var AMessage: TLMNotify); {var Node: TTreeNode; MaxTextLen: Integer;