Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) How to prohibit moving table ouside of container? (Read 5118 times)
MUDO
Junior Member
**
Offline



Posts: 90
Joined: Nov 29th, 2008
How to prohibit moving table ouside of container?
Jun 15th, 2009 at 10:44am
Print Post  
Hi.

I want to prohibit moving table from container. So I used GetNodeAt. But it returns Table which Im dragging. So I need to get node directly under that table! How is filling DiagramNodeCollection after I call GetNodesAt? How can I get next node in Zorder under that moving table without iterating collection?


Another solution...How I know which container will be parent for node? If Im dragging node over container, container is drawn with another color. Can I handle this event? Or how I can recognize the node was moved from one container to another???

Thx.

...MUDO...
« Last Edit: Jun 15th, 2009 at 12:47pm by MUDO »  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to prohibit moving table ouside of contain
Reply #1 - Jun 15th, 2009 at 1:30pm
Print Post  
Hi,

Set table.Constraints.KeepInsideParent = true.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
MUDO
Junior Member
**
Offline



Posts: 90
Joined: Nov 29th, 2008
Re: How to prohibit moving table ouside of contain
Reply #2 - Jun 15th, 2009 at 1:33pm
Print Post  
Hi!

Ou, sry, my mistake...I want to prohibit moving table from container to free area of diagramview but its possible to move table to another container.

So whats the most simple way how to do that?

Thx.

...MUDO...
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to prohibit moving table ouside of contain
Reply #3 - Jun 15th, 2009 at 1:58pm
Print Post  
Hi,

One of the GetNodeAt overloads has a skipSelected argument you could use to get the node under the table being dragged. Call it form NodeModifying and set e.Cancel = true if the method returns null or a node that's not a container.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
MUDO
Junior Member
**
Offline



Posts: 90
Joined: Nov 29th, 2008
Re: How to prohibit moving table ouside of contain
Reply #4 - Jun 15th, 2009 at 3:35pm
Print Post  
Hi Stoyo!

Thx for suggestion.

My part of code of NodeModifying method and AllowDropNodeOutsideOfContainer function:

Code
Select All
.
.
.
Dim LoPointF As PointF = fcDiagramView.ClientToDoc(fcDiagramView.PointToClient(Control.MousePosition))
Dim LoContainerForTable As ClsMMContainerNode = AllowDropNodeOutsideOfContainer(LoPointF)

     If LoContainerForTable Is Nothing Then
          e.Cancel = True
          Debug.Print("setting TRUE")
     Else
          e.Cancel = False
          Debug.Print("setting FALSE")
          Me.fcDiagramView.CurrentCursor = Cursors.SizeAll
     End If
.
.
.



'examine possibility to drop node outside of container
Private Function AllowDropNodeOutsideOfContainer(ByVal LoCoordinate As PointF) As ClsMMContainerNode
Dim LoNodeUnderCursor As DiagramNode = Me.fcDiagram.GetNodeAt(LoCoordinate, True, True)

     If LoNodeUnderCursor IsNot Nothing AndAlso LoNodeUnderCursor.GetType.Name = "ClsMMContainerNode" Then
          Return LoNodeUnderCursor
     Else
          Return Nothing
     End If

End Function
 





Cursor is not set correctly (it is stagnant after first time is "No" cursor). I need to set it manually. Any suggestions why?
Btw. I have derived BehaviorBase (SetMouseCursor and StartDraw methods) but I think its not problem.

And what about my question about coloring of container when node is dragged over it. Is there any event for that? Simply, how can I recognize the node was moved from one container to another?

Thx.

...MUDO...
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to prohibit moving table ouside of contain
Reply #5 - Jun 16th, 2009 at 12:48pm
Print Post  
Hi Mudo,

Is your problem that the cursor does not return to the default until you release the mouse button?

The events raised when you move a child node from one container to another are ContainerChildRemoved and ContainerChildAdded. There is no event raised when a container is colored to show that it would accept the child. This container is the one that returned true from DragOverNode, and since you mentioned you are using a custom container class, you could override the method and raise some event from there.

Stoyan
  
Back to top
 
IP Logged
 
MUDO
Junior Member
**
Offline



Posts: 90
Joined: Nov 29th, 2008
Re: How to prohibit moving table ouside of contain
Reply #6 - Jun 17th, 2009 at 7:48am
Print Post  
Hi Stoyo!

Yes, thats the problem:

1. I start dragging
2. Im dragging over acceptable area --> cursor is "SizeAll" type
3. Im dragging over nonacceptable area --> cursor is "No" tpye
4. Im dragging over acceptable area again --> cursor is still "No" type
.
.
.
...cursor is still "No" type

Thats why Im calling
Code
Select All
Me.fcDiagramView.CurrentCursor = Cursors.SizeAll
 


when Im dragging over nonacceptable area.


Ok, I know where to place event (before "Return MyBase.OnDropOver(item)")

Code
Select All
'overrided sub - when a diagram item is dropped over this node
    Public Overrides Function OnDropOver(ByVal item As MindFusion.Diagramming.DiagramItem) As Boolean
        'only table is accepted for adding to container
        If AllowAddNodeToContainer(item) Then
            RaiseEvent a()
            Return MyBase.OnDropOver(item)
        Else
            Return False
        End If
    End Function
 



But how to handle this event? Where?

Thx.

...MUDO...
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to prohibit moving table ouside of contain
Reply #7 - Jun 17th, 2009 at 9:34am
Print Post  
Hi,

Could you copy the whole NodeModifying handler here? I've tried this simple test and it worked as expected:

Code
Select All
private void diagram_NodeModifying(object sender, NodeValidationEventArgs e)
{
	diagramView.CurrentCursor = e.MousePosition.X < 200 ?
		Cursors.IBeam : Cursors.HSplit;
}
 



My guess is that your handler doesn't set view.Cursor in all code paths.

Stoyan
  
Back to top
 
IP Logged
 
MUDO
Junior Member
**
Offline



Posts: 90
Joined: Nov 29th, 2008
Re: How to prohibit moving table ouside of contain
Reply #8 - Jun 17th, 2009 at 4:46pm
Print Post  
Hi Stoyo!

Heres my NodeModifying function. But I dont set cursor with CurrentCursor but I let e.Cancel do that thing.

Code
Select All
'perform fitting of size of table for any types of modification
    Private Sub fcDiagram_NodeModifying(ByVal sender As Object, ByVal e As MindFusion.Diagramming.NodeValidationEventArgs) Handles fcDiagram.NodeModifying
        MoAmodFile.FileWasModified = True

        Select Case e.AdjustmentHandle
            Case AdjustmentHandles.ResizeBottomCenter, AdjustmentHandles.ResizeBottomLeft, _
                 AdjustmentHandles.ResizeBottomRight, AdjustmentHandles.ResizeMiddleLeft, AdjustmentHandles.ResizeMiddleRight, _
                 AdjustmentHandles.ResizeTopCenter, AdjustmentHandles.ResizeTopLeft, AdjustmentHandles.ResizeTopRight
                Select Case e.Node.GetType.Name
                    Case "ClsMMTableNode"
                        CType(e.Node, ClsMMTableNode).MMResizeAllToFitTable(False)
                    Case "ClsMMContainerNode"
                        CType(e.Node, ClsMMContainerNode).MMResizeHeightOfCaption()
                End Select
            Case AdjustmentHandles.Move
                Select Case e.Node.GetType.Name
                    Case "ClsMMTableNode"
                        Dim LoPointF As PointF = fcDiagramView.ClientToDoc(fcDiagramView.PointToClient(Control.MousePosition))
                        Dim LoContainerForTable As ClsMMContainerNode = AllowDropNodeOutsideOfContainer(LoPointF)

                        If LoContainerForTable Is Nothing Then
                            e.Cancel = True
                            Debug.Print("nastavujem TRUE")
                        Else
                            e.Cancel = False
                            Debug.Print("nastavujem FALSE")
                            Me.fcDiagramView.CurrentCursor = Cursors.SizeAll
                        End If

                        Debug.Print(e.Cancel)
                End Select
        End Select
    End Sub
 



Yes, and could you help me with that event from my own ContainerNode class?

Thx.

...MUDO...
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to prohibit moving table ouside of contain
Reply #9 - Jun 18th, 2009 at 5:36am
Print Post  
Hi Mudo,

Well, once you set CurrentCursor, the default cursor won't show until the mouse button is released. So you will have to set it in the e.Cancel = True case too. Otherwise you might try setting view.Cursor instead of view.CurrentCursor.

Note that the control calls an OnDragOut method when a dragged item leaves the container's boundaries. You could override it together with OnDragOver and update a static/shared boolean member of your custom container class that tracks whether the mouse is inside any container. Then you could check the value of that member from any mouse-related event.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
MUDO
Junior Member
**
Offline



Posts: 90
Joined: Nov 29th, 2008
Re: How to prohibit moving table ouside of contain
Reply #10 - Jun 19th, 2009 at 9:23am
Print Post  
Hi Stoyo!

Any misunderstanding is here...

Now with this NodeModifying is everything ok! Cursor is changing good. But if the line "Me.fcDiagramView.CurrentCursor = Cursors.SizeAll" is omitted behavior of cursor is like I describe in my first post from Jun 17th. Originally I wanted to set it with "e.Cancel = True" and "e.Cancel = False" as you wrote. But it didnt work! Thats why I added "Me.fcDiagramView.CurrentCursor = Cursors.SizeAll".
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint