Visio Event Sinking

J

Jonathan Spane

Hello all,

I am trying to use the visio event system to listen for formula changes on a
per cell basis in the Custom Properties section of a shape. I cannot seem to
get a callback to work. I can get a callback to work at the shape level for
a cell being changed. The following is the code I am using to register a
callback with a shape which works and the code to register a callback for a
cell which doesn't seem to work. I have checked for a valid event so
AddAdvise is successful. Any ideas what I am doing wrong. I can clearly see
the event of formula changed in the generic Event Listener.

///=============================================================================
///
/// FUNCTION: RegisterCallbackForShape
///
/// This assigns the callback to listen for the cell changed
event
/// for the shape that is passed in.
///
///=============================================================================
bool
VisioEventManager::RegisterCallbackForShape(CVisioShape &visioShape,
LPVISEVENTPROC pCallback)
{
if(!visioShape.IsSet()) return false;

if(pCallback == NULL) return false;

//Ths sink object that gets created by Visio
IUnknown FAR *pSink = NULL;
//The list events from the shape that will be added to
CVisioEventList eList;
//Event that will be created.
CVisioEvent visioEvent;

if(SUCCEEDED(visioShape.EventList(eList)))
{
if(SUCCEEDED(CoCreateAddonSink(pCallback, &pSink)))
{
VBstr vbBlankStr(_T(""));
if(SUCCEEDED(eList.AddAdvise((short)(visEvtCell|visEvtMod),
VVariant(pSink),
vbBlankStr,
vbBlankStr,
visioEvent)))
{
}
//If AddAdvise succeeded, Visio now holds a reference to the
sink
//object via the event object, and pSink can be released.
pSink->Release();
pSink = NULL;

return true;
}
}

return false;
}

///=============================================================================
///
/// FUNCTION: RegisterCallbackForCell
///
/// This assigns the callback to listen for the cell changed
event
/// for the cell that is passed in.
///
///=============================================================================
bool
VisioEventManager::RegisterCallbackForCell(CVisioCell &visioCell,
LPVISEVENTPROC pCallback)
{
if(!visioCell.IsSet()) return false;

if(pCallback == NULL) return false;

//Ths sink object that gets created by Visio
IUnknown FAR *pSink = NULL;
//The list events from the shape that will be added to
CVisioEventList eList;
//Event that will be created.
CVisioEvent visioEvent;

if(SUCCEEDED(visioCell.EventList(eList)))
{
if(SUCCEEDED(CoCreateAddonSink(pCallback, &pSink)))
{
VBstr vbBlankStr(_T(""));

if(SUCCEEDED(eList.AddAdvise((short)(visEvtFormula|visEvtMod),
VVariant(pSink),
vbBlankStr,
vbBlankStr,
visioEvent)))
{
}
//If AddAdvise succeeded, Visio now holds a reference to the
sink
//object via the event object, and pSink can be released.
pSink->Release();
pSink = NULL;

return true;
}
}

return false;
}

Thanks for any help.

JP

P.S. I have substitude the or symbol | with a + sign... no help.
 
J

Jonathan Spane

Here is a follow up question. Why can nonpersitant events not persist
between the master shape and its instances? I am trying to add an event to
the shape in a master that resides in a stencil. This events only seems to
exist for the scope that I am applying settings to the shape. Even though
the other settings applied to the shape are passed down to instances my
event disappears on me at some point completey. I have tried increse an
extra reference to the shape's event so it can't disappear but it doesn't
seem to matter. I can have however now add events to instanced shapes and
they will stay around. Is there some undocumented rules for events of shapes
in the master?

I was editing the master's copy and that was causing the event to be killed
as soon as I closed the copy. What is the deal?

Thanks for any help
JP
 
J

Jonathan Spane

I still have some weirdness with Visio Events. When a shape is dropped, I
listen for that event. At that point I find the shape that was just dropped
and add some custom cell changed events. The weird thing is that cell event
disappears as soon as my shape object in code looses scope. If apply the
event some point later by just walking on the shapes in page the cell event
holds. Very weird. Anyone know the proper way to add non-persistent events
to a dropped shape?

Thanks
 

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