Creating custom shapes using Drag&Drop

N

Niklas Deutschmann

Hi,

I have a tree view with my model elements as an anchor window. When a model
element from this tree view is dragged on the page, a new shape should be
created that has some model-specific information attached (e.g. the ID of the
model element).

The code on the drag source side is like this:

private void modelStructureTree_ItemDrag(object sender, ItemDragEventArgs
e){
TreeNode draggedNode = e.Item as TreeNode;
object modelObject = draggedNode.Tag;
Master master = getMasterForObjectType(modelObject.GetType());
Shape shape = master.Shapes[1];
DoDragDrop(shape, DragDropEffects.Move);
}

I cannot attach the model element ID to "shape" because "shape" is the
master shape, and not a shape that has been created from the master (this
happens when the shape is dropped, I guess).

So, I
1.) Either need to instantiate a shape on the drag source side. Can I create
a shape "in memory", without dropping it on a page, and pass it to
DoDragDrop()?

2.) Or access the dropped object on the drop target side (in the event
handler for visEvtCodeMouseMove). But I don't see any property for the
Drag&Drop data transfer object in Visio's MouseEvent object. Moreover, when I
pass a custom object (and not a shape) to DoDragDrop() on the drag source
side, dropping the object will be refused by Visio and no visEvtCodeMouseMove
event that represents a drop will be generated at all.

So, how can I create shapes which reference their model elements by
drag&drop from an anchor window?

Regards,
Niklas
 
D

David Parker

I would go for option 2 (or rather I have done several times)
You can set an ItemForDrag (or similar) when the drag is commenced from the
treeview, then when the new shape is created (using the ShapeAdded event),
set the new shape properties from this ItemForDrag object.


Niklas Deutschmann said:
Hi,

I have a tree view with my model elements as an anchor window. When a
model
element from this tree view is dragged on the page, a new shape should be
created that has some model-specific information attached (e.g. the ID of
the
model element).

The code on the drag source side is like this:

private void modelStructureTree_ItemDrag(object sender, ItemDragEventArgs
e){
TreeNode draggedNode = e.Item as TreeNode;
object modelObject = draggedNode.Tag;
Master master = getMasterForObjectType(modelObject.GetType());
Shape shape = master.Shapes[1];
DoDragDrop(shape, DragDropEffects.Move);
}

I cannot attach the model element ID to "shape" because "shape" is the
master shape, and not a shape that has been created from the master (this
happens when the shape is dropped, I guess).

So, I
1.) Either need to instantiate a shape on the drag source side. Can I
create
a shape "in memory", without dropping it on a page, and pass it to
DoDragDrop()?

2.) Or access the dropped object on the drop target side (in the event
handler for visEvtCodeMouseMove). But I don't see any property for the
Drag&Drop data transfer object in Visio's MouseEvent object. Moreover,
when I
pass a custom object (and not a shape) to DoDragDrop() on the drag source
side, dropping the object will be refused by Visio and no
visEvtCodeMouseMove
event that represents a drop will be generated at all.

So, how can I create shapes which reference their model elements by
drag&drop from an anchor window?

Regards,
Niklas
 
N

Niklas Deutschmann

Hi David,
I would go for option 2 (or rather I have done several times)
You can set an ItemForDrag (or similar) when the drag is commenced from the
treeview, then when the new shape is created (using the ShapeAdded event),
set the new shape properties from this ItemForDrag object.

Could you maybe go into some more detail? I can't find this property or any
similarly named property or object in the documentation, and I would really
like to know how to access the drag&drop data exchange object when handling a
drop event.

Regards,
Niklas
 
N

Nikolay Belyh

Hi David,


Could you maybe go into some more detail? I can't find this property or any
similarly named property or object in the documentation, and I would really
like to know how to access the drag&drop data exchange object when handling a
drop event.

Regards,
Niklas

I think what is actually meant, that before calling DoDragDrop,
you can set some "global" variable that will "hold" the node you are
dragging.
Also, you could create an event handler for Visio's "shape added"
event (visEvtShape+visEvtAdd).
And in that "shape added" event handler, you could just use that
variable to initialize the (new) shape
(the shape being dropped is passed in as an argument to that event
handler).
And, IMHO there is no point in using that "mouse move" event you
mentioned.

Kind regards, Nikolay.
 
D

David Parker

I agree, and I should also add that I got my original code from Graham
Wideman's book, http://diagramantics.com/ or
http://www.amazon.com/Visio-2003-Developers/dp/1412011124/ref=sr_11_1?ie=UTF8


Hi David,


Could you maybe go into some more detail? I can't find this property or
any
similarly named property or object in the documentation, and I would
really
like to know how to access the drag&drop data exchange object when
handling a
drop event.

Regards,
Niklas

I think what is actually meant, that before calling DoDragDrop,
you can set some "global" variable that will "hold" the node you are
dragging.
Also, you could create an event handler for Visio's "shape added"
event (visEvtShape+visEvtAdd).
And in that "shape added" event handler, you could just use that
variable to initialize the (new) shape
(the shape being dropped is passed in as an argument to that event
handler).
And, IMHO there is no point in using that "mouse move" event you
mentioned.

Kind regards, Nikolay.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top