SOme drag and drop controls questions

TeeTree VCL for Borland Delphi and C++ Builder.
Post Reply
Mortong
Newbie
Newbie
Posts: 15
Joined: Mon Mar 29, 2004 5:00 am
Location: london

SOme drag and drop controls questions

Post by Mortong » Thu May 06, 2004 5:09 pm

Hi there - D7, Teechart 2

4 interlinked questions please:

A root is called Europe
A Child is is called LEngland
A Child is is called LGermany
A Child is is called France
A root is called Asia
A Child is is called India
A Child is is called China
A Child is is called Japan

Question 1. I want to drag Japan ONLY under Europe or another root but NOT not under any of the children - ie keep it with 2 columns

A seperate LINKED TeeTree exists
It has loads of roots - called big, small, medium....

Question 2. I want to drag say big to India or another Child in the first TeeTree BUT NOT to the roots - ie leaves me with a thrid column

Question 3. The target child in Q2 (say London) can only have ONE child added - another item dragged from the second teetree simply replaces the first - ie London-Big becomes London-Small NOT London - Big, small.

Question 4. I would like to see "London-Big" appear next to each other - NOT beneath each other.

Many thanks for your help


Morton

tom
Advanced
Posts: 211
Joined: Mon Dec 01, 2003 5:00 am
Contact:

Post by tom » Thu May 06, 2004 6:42 pm

Please, send me a part of your source code, so I can look at it and give examples on how you can solve things

Regards,
Tom.

Mortong
Newbie
Newbie
Posts: 15
Joined: Mon Mar 29, 2004 5:00 am
Location: london

Post by Mortong » Fri May 07, 2004 11:52 am

I have no source code as I could see no way of checking out levels. All the accepts and allows seemed to do nothing....

Basically I want to be able to check the level of where I am about to drop somehting - If it is at the wrong level then prevent that drop


Hence the questions...

Morton

Mortong
Newbie
Newbie
Posts: 15
Joined: Mon Mar 29, 2004 5:00 am
Location: london

Post by Mortong » Tue May 11, 2004 6:28 pm

Anyone there????

tom
Advanced
Posts: 211
Joined: Mon Dec 01, 2003 5:00 am
Contact:

Post by tom » Tue May 11, 2004 9:27 pm

Ah, sorry, I thought you were facing problems with your code, that's why I asked for your source-code.

Okay.

1. Do you already have the big demo application of teeTree? If not, I'll send it to you

2. To find the level of a node, you can use the level function of TTreeNodeShape:

function Level: Integer;

The Level property returns the number of "generations" (parent of parent...).

Nodes without parent ( roots ) have a Level equal to zero ( 0 ).

3. To find out which node is on an X,Y position, you can use the ClickedShape method of TCustomTree:

function ClickedShape(X, Y: Integer): TTreeNodeShape;

The ClickedShape method returns the shape that contains the mouse XY position.

4. You can also use the OnDragDropShape event.

Regards,
Tom

tom
Advanced
Posts: 211
Joined: Mon Dec 01, 2003 5:00 am
Contact:

Post by tom » Tue May 11, 2004 10:53 pm

Also have a look at the tree DragAndDrop class which allows some settings to ease some TTree drag & drop configurations:

Set Automatic to True to enable Automatic dragging and dropping of nodes within a single tree or between different teeTrees.

Set DragRoots to allow the dragging of roots.

Set DragToRoot if you want to allow non-root nodes which are dragged to another tree to be converted into root nodes.

Set FromOtherTree property to True to allow nodes from other teetree's to be dragged and dropped on tree.

Set RemoveNodes to False if you want to prevent the removal of the dragged node at the source tree. If so a clone of the dragged node is created at the destination tree. RemoveNodes set to True is the default behavior and the dragged node will be removed from the source tree when dropped on the destination tree.

Set TotherTree property to True to allow nodes from tree to be dragged and dropped on other teetree components.

Mortong
Newbie
Newbie
Posts: 15
Joined: Mon Mar 29, 2004 5:00 am
Location: london

Post by Mortong » Wed May 12, 2004 4:54 pm

The drag and stuff demo stuff is sound enough... Thats what I used originally but the levels stuff and the allow does not make sense....

The issue is stopping a drop:

All I want is the equivalent of say:
Continent - Country - Currency where currency is in table 2.

1. Tree level 2 item can only be dropped under a lvel 1 and no where else...
Say UK can now become part of Asia or Africa....
If I drop UK under France it stops... If I drop it under pounds it stops...

2. Level 2 item can only be dropped under another level 1 (root) NOT 2 to be come a 3 or a 3 to become a 4.
I see UK has pounds so I drag pounds over to it.
If select pounds I can only drag it uunder a country...

tom
Advanced
Posts: 211
Joined: Mon Dec 01, 2003 5:00 am
Contact:

Post by tom » Wed May 12, 2004 8:13 pm

Then you've to implement your own rules, eg with the use of the level function (as commented on Tue May 11, 2004 9:27 pm)

Below you've a example how you can handle your own drag & drop:

>>> Set DragAndDrop.Automatic to False <<<

procedure TDragDropPreventForm.Tree1DragOver(Sender, Source: TObject; X,
Y: Integer; State: TDragState; var Accept: Boolean);
var tmpNode: TTreeNodeShape;
begin
inherited;
Accept := False;
tmpNode := Tree1.ClickedShape(X,Y);
// eg only allow to drop if node is a root (level = 0)
// a child just below the root has level = 1 etc

if Assigned(tmpNode) then
begin
if tmpNode.Level = 0 then Accept := True;
end;
end;

procedure TDragDropPreventForm.Tree1ClickShape(Sender: TTreeNodeShape;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
inherited;
if (Button = mbLeft) and (not (ssDouble in Shift)) then
begin
tmpDraggedNode := Sender;
Tree1.BeginDrag(False, -1);
end;
end;

procedure TDragDropPreventForm.Tree1EndDrag(Sender, Target: TObject; X,
Y: Integer);
var tmpTarget: TTreeNodeShape;
tmpC : TTreeConnection;
begin
inherited;

tmpTarget:=Tree1.ClickedShape(x,y);
if not Assigned(tmpDraggedNode) or not Assigned(tmpTarget) then exit;

if Assigned(tmpDraggedNode.Parent) then
begin
{ if a connection exists, switch it to the new node }
if Assigned(tmpDraggedNode.Parent.Connections) then
begin
tmpC:=tmpDraggedNode.Parent.Connections.ToShape(tmpDraggedNode);
if Assigned(tmpC) then
begin
tmpC.FromShape:=tmpTarget;
end;
end;
end
else tmpTarget.AddConnection(tmpDraggedNode);

tmpDraggedNode.Parent:=tmpTarget;
tmpDraggedNode.Visible:=tmpTarget.Visible;
if tmpTarget.Visible then tmpTarget.Expanded:=True;

end;

Regards,
Tom.

Post Reply