Skip to main content
Inspiring
February 6, 2009
Question

CS3: Detection selection change of page items

  • February 6, 2009
  • 2 replies
  • 1171 views
Hi<br /><br />I like to detect the selection change of page items (text or graphic frames). I implemented a doc change observer, but this doesn't work. The update method is called if I create a new page item for example. This means that the observer works, but not for the selection change. Maybe I have forgotten the right attachment.<br /><br />How can I detect the selection changes of page items?<br /><br />Here is my code where I attach my doc change observer.<br /><br />-------------------------------------------------------------------------<br /><br />void CTabFlowDocChangesObserver::AttachDocument(IDocument* ipDocument)<br />{<br /> do {<br /> InterfacePtr<ISubject> ipDocSubject(ipDocument, UseDefaultIID());<br /> if (ipDocSubject == nil) break;<br /> if (!ipDocSubject->IsAttached(ISubject::kRegularAttachment, this, IID_IHIERARCHY_DOCUMENT, IID_ITABFLOWDOCCHANGESOBSERVER)) {<br /> ipDocSubject->AttachObserver(ISubject::kRegularAttachment, this, IID_IHIERARCHY_DOCUMENT, IID_ITABFLOWDOCCHANGESOBSERVER);<br /> }<br /> if (!ipDocSubject->IsAttached(this, IID_IPATHSELECTIONDATA, IID_ITABFLOWDOCCHANGESOBSERVER)) {<br /> ipDocSubject->AttachObserver(this, IID_IPATHSELECTIONDATA, IID_ITABFLOWDOCCHANGESOBSERVER);<br /> }<br /> if (!ipDocSubject->IsAttached(this, IID_IPATHSELECTION, IID_ITABFLOWDOCCHANGESOBSERVER)) {<br /> ipDocSubject->AttachObserver(this, IID_IPATHSELECTION, IID_ITABFLOWDOCCHANGESOBSERVER);<br /> }<br /> if (!ipDocSubject->IsAttached(this, IID_IHIERARCHY, IID_ITABFLOWDOCCHANGESOBSERVER)) {<br /> ipDocSubject->AttachObserver(this, IID_IHIERARCHY, IID_ITABFLOWDOCCHANGESOBSERVER);<br /> }<br /> if (!ipDocSubject->IsAttached(this, IID_IPATHSELECTIONCHANGE, IID_ITABFLOWDOCCHANGESOBSERVER)) {<br /> ipDocSubject->AttachObserver(this, IID_IPATHSELECTIONCHANGE, IID_ITABFLOWDOCCHANGESOBSERVER);<br /> }<br /> if (!ipDocSubject->IsAttached(this, IID_IPATHSELECTIONDOCOBSERVER, IID_ITABFLOWDOCCHANGESOBSERVER)) {<br /> ipDocSubject->AttachObserver(this, IID_IPATHSELECTIONDOCOBSERVER, IID_ITABFLOWDOCCHANGESOBSERVER);<br /> }<br /> if (!ipDocSubject->IsAttached(this, IID_ISELECTIONFILTER, IID_ITABFLOWDOCCHANGESOBSERVER)) {<br /> ipDocSubject->AttachObserver(this, IID_ISELECTIONFILTER, IID_ITABFLOWDOCCHANGESOBSERVER);<br /> }<br /> if (!ipDocSubject->IsAttached(this, IID_IGEOMETRY_DOCUMENT, IID_ITABFLOWDOCCHANGESOBSERVER)) {<br /> ipDocSubject->AttachObserver(this, IID_IGEOMETRY_DOCUMENT, IID_ITABFLOWDOCCHANGESOBSERVER);<br /> }<br /><br /> if (!ipDocSubject->IsAttached(this, IID_ITRANSFORM_DOCUMENT, IID_ITABFLOWDOCCHANGESOBSERVER)) {<br /> ipDocSubject->AttachObserver(this, IID_ITRANSFORM_DOCUMENT, IID_ITABFLOWDOCCHANGESOBSERVER);<br /> }<br /><br /> if (!ipDocSubject->IsAttached(this, IID_IMOVEREFERENCEPOINTCMDDATA , IID_ITABFLOWDOCCHANGESOBSERVER)) {<br /> ipDocSubject->AttachObserver(this, IID_IMOVEREFERENCEPOINTCMDDATA , IID_ITABFLOWDOCCHANGESOBSERVER);<br /> }<br /> } while (kFalse);<br />}<br /><br />-------------------------------------------------------------------------<br /><br />Is it correct to use a doc chnage observer?<br /><br />Have I to use a selection filter? How can I implement it if yes?<br /><br />Thanks for the support<br />Hans
This topic has been closed for replies.

2 replies

hstoesselAuthor
Inspiring
February 9, 2009
Hi

Thanks for the help. It works now.

Hans
October 22, 2013

Hi Hans,

I have a requirement to trigger the event whenever user select the text frame . As you worked on it. Could you send me the code for .fr and observer class.

Participating Frequently
February 6, 2009
The selection filter was mentioned for a very specific use case - Jelle had to notify an external application. For details see that other thread, but for you that approach is probably wrong anyway.

Typically you follow the selection in order to update a widget - if not, please explain.
For that case you would aggregate a selection observer (e.g. derived from ActiveSelectionObserver* ) on your widget or its parent panel. In the observer, you would _not_ override Update(), instead use the various Handle() methods.

That notification should be sufficient for simple selection changes on page items, the selection should not need to follow multiple protocols. If there is a deeper sense behind your quoted enormous collection of protocols, then you might need a Suite with SelectionExt* which would preprocess all those notifications and reduce them to a single custom protocol. You'll probably need a Suite anyway unless you can reuse an existing one, to obtain a value for your widget.

In other words, all the _DOCUMENT are not related to the selection, they are just side effects. IID_ISELECTIONFILTER makes no sense. All those PATHSELECTION are only relevant if you want to watch every change to shapes. The reference point again is a sideeffect - I think of scrolling / active spread, it is very unlikely that you really need that notification.

Btw, do not check for IsAttached() during AutoAttach. It just suppresses an ASSERT, better fix the reason (unbalanced Attach / Detach).

* = search the SDK.

Dirk