J
Josef Meile
Hi
I added the following events to my event sink class using the
AddAdvise method:
Shape added: visEvtShape + visEvtAdd
Query Selection delete: visEvtCodeQueryCancelSelDel
Connection added: visEvtConnect + visEvtAdd
Connection deleted: visEvtConnect + visEvtDel
The problem I'm having is that during connecting or disconnecting shapes
sometimes I need to paste or delete some shapes, so, the shape added
event or query selection delete event will be triggered as well. I would
like to disable the shape added and query selection delete events while
handling the connection events. I have tried several things, but I haven't
had any success:
Alternative 1:
1) Save the event codes and its corresponding events ids of the events added
to my event sink. ie:
to add an event I did the following inside a method from my sink class:
//Shape added event
short eventCode = (short)Visio.VisEventCodes.visEvtShape +
(short)Visio.VisEventCodes.visEvtMod;
Visio.Event addedEvent = eventList.AddAdvise(eventCode,this, "", "");
DocumentEvents[eventCode] = addedEvent.ID;
//Same for the query selection deleted
eventCode = (short)Visio.VisEventCodes.visEvtCodeQueryCancelSelDel;
addedEvent = eventList.AddAdvise(eventCode,this, "", "");
DocumentEvents[eventCode] = addedEvent.ID;
2) Whenever I handle a connection added or deleted event, disable the
shape added and query selection delete events, process the event, and
enable the events again:
//Shape added event
short eventCode = (short)Visio.VisEventCodes.visEvtShape +
(short)Visio.VisEventCodes.visEvtMod;
int eventId = (int) DocumentEvents[eventCode];
Visio.EventList eventList = vsoDocument.EventList;
Visio.Event shapeAddedEv = eventList.get_ItemFromID(eventId);
shapeAddedEv.Enabled = 0;
//Same for the query selection deleted comes here
eventCode =
selDeleteEv = ....
//Proccess event here
//At the end, enable events again
shapeAddedEv.Enabled = 1;
selDeleteEv.Enabled = 1;
3) After having handled the connection events I set the Enable property to
1. At this point, the program exists from the VisEventProc method, then
later it fires either the shape added or the query selection deleted event.
So, it means that somehow the event was deffered instead of being disabled.
Alternative 2:
1) Add the events to the sink class and to the DocumentEvents as done in
the first step of Alternative 1.
2) When handling the connection events, delete the event from the EventList
Collection, process the event and add the events again (ugly):
//Shape added event
eventCode = (short)Visio.VisEventCodes.visEvtShape +
(short)Visio.VisEventCodes.visEvtMod;
eventId = (int) DocumentEvents[eventCode];
Visio.EventList eventList = vsoDocument.EventList;
Visio.Event shapeAddedEv = eventList.get_ItemFromID(eventId);
//physically delete the shape added event
shapeAddedEv.Delete();
//Same for the query selection deleted comes here
selDeleteEv = ....
//Proccess event here
//At the end, add the events again
short eventCode = (short)Visio.VisEventCodes.visEvtShape +
(short)Visio.VisEventCodes.visEvtMod;
Visio.Event addedEvent = eventList.AddAdvise(eventCode,this, "", "");
DocumentEvents[eventCode] = addedEvent.ID;
//Same for the query selection deleted
eventCode = (short)Visio.VisEventCodes.visEvtCodeQueryCancelSelDel;
addedEvent = eventList.AddAdvise(eventCode,this, "", "");
DocumentEvents[eventCode] = addedEvent.ID;
This method worked similar to the alternative 1. Either the shape added or
query selection delete events were fired after returning from the VisEventProc
method. I have to admit that I really don't like this approach.
Alternative 3: Use several combination of the OnComponentEnterState method of
the application object:
1) This behaved the same as alternatives 1 and 2:
visioApp.OnComponentEnterState(
Visio.VisOnComponentEnterCodes.visComponentStateModal |
Visio.VisOnComponentEnterCodes.visModalDisableVisiosFrame |
Visio.VisOnComponentEnterCodes.visModalDontBlockMessages, true);
//Handle event here
visioApp.OnComponentEnterState(
Visio.VisOnComponentEnterCodes.visComponentStateModal |
Visio.VisOnComponentEnterCodes.visModalDisableVisiosFrame |
Visio.VisOnComponentEnterCodes.visModalDontBlockMessages, false);
I also tried without the visModalDisableVisiosFrame, but the effect was
the same.
Alternative 4 (in progress): whenever an event is caught, instead of handling
it, put the event type and the data it modifies into a queue (ArrayList
maybe),
then in the handler of the NoEventsPending event, process that queue and each
time that a connection event is going to be handled, set a flag, which will
avoid
adding other events to enter to the queue.
I think I will give a try to Alternative 4, which was suggested by Mark
Nelson in
a post from Jan 29 2004:
* preventing events to be fired
group: microsoft.public.visio.developer
http://tinyurl.com/cq54g
But the question is: when I disconnect a shape and connect it to another one
without releasing the mouse button, is there any chance that first the
connection
delete event occurs, then the NoEventsPending event and finally the connection
added event? If so, then I will have problems again because I need always to
handle both events.
Finally, if somebody else has another suggestion, you are welcome to post it.
Regards
Josef
I added the following events to my event sink class using the
AddAdvise method:
Shape added: visEvtShape + visEvtAdd
Query Selection delete: visEvtCodeQueryCancelSelDel
Connection added: visEvtConnect + visEvtAdd
Connection deleted: visEvtConnect + visEvtDel
The problem I'm having is that during connecting or disconnecting shapes
sometimes I need to paste or delete some shapes, so, the shape added
event or query selection delete event will be triggered as well. I would
like to disable the shape added and query selection delete events while
handling the connection events. I have tried several things, but I haven't
had any success:
Alternative 1:
1) Save the event codes and its corresponding events ids of the events added
to my event sink. ie:
to add an event I did the following inside a method from my sink class:
//Shape added event
short eventCode = (short)Visio.VisEventCodes.visEvtShape +
(short)Visio.VisEventCodes.visEvtMod;
Visio.Event addedEvent = eventList.AddAdvise(eventCode,this, "", "");
DocumentEvents[eventCode] = addedEvent.ID;
//Same for the query selection deleted
eventCode = (short)Visio.VisEventCodes.visEvtCodeQueryCancelSelDel;
addedEvent = eventList.AddAdvise(eventCode,this, "", "");
DocumentEvents[eventCode] = addedEvent.ID;
2) Whenever I handle a connection added or deleted event, disable the
shape added and query selection delete events, process the event, and
enable the events again:
//Shape added event
short eventCode = (short)Visio.VisEventCodes.visEvtShape +
(short)Visio.VisEventCodes.visEvtMod;
int eventId = (int) DocumentEvents[eventCode];
Visio.EventList eventList = vsoDocument.EventList;
Visio.Event shapeAddedEv = eventList.get_ItemFromID(eventId);
shapeAddedEv.Enabled = 0;
//Same for the query selection deleted comes here
eventCode =
selDeleteEv = ....
//Proccess event here
//At the end, enable events again
shapeAddedEv.Enabled = 1;
selDeleteEv.Enabled = 1;
3) After having handled the connection events I set the Enable property to
1. At this point, the program exists from the VisEventProc method, then
later it fires either the shape added or the query selection deleted event.
So, it means that somehow the event was deffered instead of being disabled.
Alternative 2:
1) Add the events to the sink class and to the DocumentEvents as done in
the first step of Alternative 1.
2) When handling the connection events, delete the event from the EventList
Collection, process the event and add the events again (ugly):
//Shape added event
eventCode = (short)Visio.VisEventCodes.visEvtShape +
(short)Visio.VisEventCodes.visEvtMod;
eventId = (int) DocumentEvents[eventCode];
Visio.EventList eventList = vsoDocument.EventList;
Visio.Event shapeAddedEv = eventList.get_ItemFromID(eventId);
//physically delete the shape added event
shapeAddedEv.Delete();
//Same for the query selection deleted comes here
selDeleteEv = ....
//Proccess event here
//At the end, add the events again
short eventCode = (short)Visio.VisEventCodes.visEvtShape +
(short)Visio.VisEventCodes.visEvtMod;
Visio.Event addedEvent = eventList.AddAdvise(eventCode,this, "", "");
DocumentEvents[eventCode] = addedEvent.ID;
//Same for the query selection deleted
eventCode = (short)Visio.VisEventCodes.visEvtCodeQueryCancelSelDel;
addedEvent = eventList.AddAdvise(eventCode,this, "", "");
DocumentEvents[eventCode] = addedEvent.ID;
This method worked similar to the alternative 1. Either the shape added or
query selection delete events were fired after returning from the VisEventProc
method. I have to admit that I really don't like this approach.
Alternative 3: Use several combination of the OnComponentEnterState method of
the application object:
1) This behaved the same as alternatives 1 and 2:
visioApp.OnComponentEnterState(
Visio.VisOnComponentEnterCodes.visComponentStateModal |
Visio.VisOnComponentEnterCodes.visModalDisableVisiosFrame |
Visio.VisOnComponentEnterCodes.visModalDontBlockMessages, true);
//Handle event here
visioApp.OnComponentEnterState(
Visio.VisOnComponentEnterCodes.visComponentStateModal |
Visio.VisOnComponentEnterCodes.visModalDisableVisiosFrame |
Visio.VisOnComponentEnterCodes.visModalDontBlockMessages, false);
I also tried without the visModalDisableVisiosFrame, but the effect was
the same.
Alternative 4 (in progress): whenever an event is caught, instead of handling
it, put the event type and the data it modifies into a queue (ArrayList
maybe),
then in the handler of the NoEventsPending event, process that queue and each
time that a connection event is going to be handled, set a flag, which will
avoid
adding other events to enter to the queue.
I think I will give a try to Alternative 4, which was suggested by Mark
Nelson in
a post from Jan 29 2004:
* preventing events to be fired
group: microsoft.public.visio.developer
http://tinyurl.com/cq54g
But the question is: when I disconnect a shape and connect it to another one
without releasing the mouse button, is there any chance that first the
connection
delete event occurs, then the NoEventsPending event and finally the connection
added event? If so, then I will have problems again because I need always to
handle both events.
Finally, if somebody else has another suggestion, you are welcome to post it.
Regards
Josef