Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Page.Drop vs User dropping shape

45 views
Skip to first unread message

James Frost

unread,
Mar 10, 2004, 6:13:29 AM3/10/04
to
Hi,

We're developing a visio solution that needs to differentiate between
a user dragging a shape onto a page and the solution code dropping a
shape onto a page. We need to know the difference when the
ShapeDropped event gets fired.

We've looked at the following options (for the "solution" drop):

1) Drop the shape onto the page then setting a custom property on it.
This works sometimes but often the shape dropped gets called before we
get a chance to set the property

2) Edit the local document master adding the custom property before
dropping the shape and then reset it back again afterwards. Not got
this to work yet!

3) Have two copies of all our shapes in the stencil, one with the
"solution" custom property set and one without, and have the
"solution" masters hidden. This is ugly and wasteful but seems the
most robust way of doing it thus far.

Any other suggestions? Anyone had an experience of 2) that might help
us out?

Regards,

James Frost

Chris Roth

unread,
Mar 10, 2004, 6:38:41 AM3/10/04
to
James Frost,

The solution code responds to events (ie: ShapeDropped), but the solution
code also does the dropping.

Therefore before your code does any dropping, it could set some sort of
flag, say bMyCodeIsDoingThis = True. Then, in the ShapeDropped event, you
can look to see if this flag is set. If so, then it should respond
differently. When your code is done, it should set bMyCodeIsDoingThis back
to False.

This should work as long as you don't have infinitely fast users, or your
modification code isn't really really slow.

You can try this VBA code to get a sense.

1. Make a new drawing
2. Show the document stencil
3. Create a simple rectangle and move it to the stencil.
4. Name the new master "Bob"

- If you drop Bob on the page, he will turn red.
- If you run DoDrop, the shapes will not turn red.

Dim bBusy As Boolean

Sub DoDrop()
bBusy = True
Dim dx As Double
Dim dy As Double
dx = Rnd() * 7.5 + 0.5
dy = Rnd() * 10 + 0.5
ActivePage.Drop ThisDocument.Masters("Bob"), dx, dy
bBusy = False
End Sub

Private Sub Document_ShapeAdded(ByVal Shape As IVShape)
If bBusy Then Exit Sub
Shape.Cells("FillForegnd").Formula = "2"
End Sub

--

Hope this helps,

Chris Roth
Visio MVP


"James Frost" <goo...@vaultzero.com> wrote in message
news:713c23a6.04031...@posting.google.com...

Markus Breugst

unread,
Mar 10, 2004, 6:44:48 AM3/10/04
to
Hello James,

we do this in the following way:

Before our application drops a shape, the application increments an internal
counter in order to indicate that the next ShapeAdded event belongs to a
shape that has been added via automation. Inside the event handling
function, the counter is decremented again.
So, if the counter value is 0, the application knows that the shape has been
dropped by the user, otherwise it has been added via automation.

We are using a counter instead of a simple boolean flag in order to consider
the asynchonous arrival of Visio events in the case that our application
adds multiple shapes.

This mechanism works for several months now, and it has prooved to be
reliable. (Incrementing and decrementing of course have to be thread save.
In C#, we are using Interlocked.Increment and Interlocked.Decrement.)

Best regards,
Markus


"James Frost" <goo...@vaultzero.com> schrieb im Newsbeitrag
news:713c23a6.04031...@posting.google.com...

"dani<->moser_a_t_hot<->mail.com" <"dani<->moser_a_t_hot

unread,
Mar 10, 2004, 6:47:21 AM3/10/04
to
Hi James

in your solution, disable events before dropping the shape, and after
the shape is dropped, enable them again with the EventsEnabled-property
of the ApplicationObject.

If you want, you still can call a method to initialise the shape dropped
by your solution.

I also use this for deciding if a shape gets deleted by the user or
through my solution.

Hope this helped

Daniel

Heidi Munson [MSFT]

unread,
Mar 10, 2004, 1:55:02 PM3/10/04
to
General technique: Mark the beginning and end of the actions that your
solution performs and that you want to ignore (exclude) in your event
handling code with marker events. There should be one marker event before
the actions (Drop shape in your case) and one after. Your solution then
needs to keep track of whether or the events you receive are between the
marker events, if they are ignore the events and if they are not process
them.

There are several ways to implement this, two of them appear in the Visio
2003 SDK.
1) Put strings in your marker events that identify the your solution and the
purpose of the marker events. There should be one string to indicate that
you want to begin excluding events and an other string to indicate that your
done excluding events. Keep an internal flag that indicates if you are in
an exclude range. Flip the flag on after receiving the begin marker event
and flip the flag off after receiving the end marker event. Before
processing an event check the flag and don't process events when the flag
has been set to True. The treeview sample Visio 2003 SDK shows how to use
this approach. Tree view sample is written in VB.net. This mechanism works
well your solution parse marker events strings anyway.
2) If you are using Visio Event Object and AddAdvise to do your event
handling, make use of the event sequence numbers. One of the parameters
pass to the VisEventProc method is the event sequence number. In this case
when you queue a marker event you do not need to give it a context string.
Instead keep track of the sequence numbers for your begin events and end
events. In a complex solution you would need to be able to store multiple
pairs of begin and end sequences. In your event handling code
(VisEventProc), check to see if its event sequence number is between any of
the begin/end pairs. Also remove the begin/end pairs from your list of
begin/end ranges when your event handling code receives marker event whose
sequence number corresponds to the an the end sequence for a pair. There
is a simple example of this in the C++ Flowchart Add-on in the Visio 2003
SDK. This approach has better performance (no need to parse a string) but
is more complicated that the first one. Most internal Microsoft Visio
solutions use this technique.

You can download the Visio 2003 SDK here,
http://www.microsoft.com/downloads/details.aspx?familyid=557120bd-b0bb-46e7-936a-b8539898d44d&displaylang=en

-Heidi
Microsoft Corp

This posting is provided "AS IS" with no warranties, and confers no rights

"James Frost" <goo...@vaultzero.com> wrote in message
news:713c23a6.04031...@posting.google.com...

Michael

unread,
May 3, 2004, 4:18:35 PM5/3/04
to
just stumled onto this post, but better late then never?
I had the same problem, i.e. how to tell whether the user dropped something
using
drag and drop or did my code do it or something else do it?

In my case a stunning but simple solution worked...
when the user drops something, the active page selection count = 1 ...
if less or higher something else is going on...

Hope this is still of help.

Michael

"Heidi Munson [MSFT]" <hei...@online.microsoft.com> wrote in message
news:%23bjI3Et...@TK2MSFTNGP11.phx.gbl...

Heidi Munson [MSFT]

unread,
May 5, 2004, 4:10:45 PM5/5/04
to
Not always. Is possible to get a shape added event in a drop scope and
have a the selection count be greater than 1.

Try the following. To see the events that fire use Visio Event monitor
available in both Visio 2002 and Visio 2003 SDK.
1) Open a document, make sure there is more than one shape on the active
page.
2) Right click on the page tab to insert a new page
3) In the new page dialog check the "open page in new window check box"
4) Depending on your widow setting (for example, if the current drawing
window is maximized in Visio) then you may need to go to windows > tile.
This should give you at least two drawing windows.
5) Go back to the window that display the drawing page from step 1.
6) Select all the shapes
7) Make sure the pointer tool is active then drag all the shapes from this
window to the drawing window created in step 3.

-Heidi
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights


"Michael" <Micha...@no-Spam.planet.nl> wrote in message
news:OgOf8uUM...@tk2msftngp13.phx.gbl...

0 new messages