InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
CSubject Class Reference

#include <CSubject.h>

Inheritance diagram for CSubject:
ISubjectIPMUnknown

Public Member Functions

 CSubject (IPMUnknown *boss)
 
virtual IChangeManagerGetChangeManager () const
 
virtual bool16 IsAttached (IObserver *observer, const PMIID &interestedIn, const PMIID &asObserver=IID_IOBSERVER)
 
virtual void AttachObserver (IObserver *observer, const PMIID &interestedIn, const PMIID &asObserver=IID_IOBSERVER)
 
virtual void DetachObserver (IObserver *observer, const PMIID &interestedIn, const PMIID &asObserver=IID_IOBSERVER)
 
virtual void Change (ClassID theChange, const PMIID &interestedIn=IID_IUNKNOWN, void *changedBy=nil)
 
virtual void Change (ISubject *originalSubject, ClassID theChange, const PMIID &interestedIn=IID_IUNKNOWN, void *changedBy=nil)
 
virtual void Mute (bool16 muteOn)
 
virtual bool16 IsMuted () const
 
virtual void AttachObserver (AttachmentType attachType, IObserver *observer, const PMIID &interestedIn, const PMIID &asObserver)
 
virtual void DetachObserver (AttachmentType attachType, IObserver *observer, const PMIID &interestedIn, const PMIID &asObserver)
 
virtual bool16 IsAttached (AttachmentType attachType, IObserver *observer, const PMIID &interestedIn, const PMIID &asObserver)
 
virtual void ModelChange (ClassID theChange, const PMIID &interestedIn, void *changedBy, LazyNotificationData *data)
 
virtual void ModelChange (ISubject *originalSubject, ClassID theChange, const PMIID &interestedIn, void *changedBy, LazyNotificationData *data)
 
virtual void ModelChange (IDataBase *model, ClassID theChange, const PMIID &interestedIn, void *changedBy, LazyNotificationData *data)
 

Protected Attributes

bool16 fDetachObserversOnDelete
 
bool16 fMuted
 
const UIDRef fThisRef
 

Additional Inherited Members

- Public Types inherited from ISubject
enum  { kDefaultIID = IID_ISUBJECT }
 
enum  AttachmentType { kRegularAttachment = 0, kLazyAttachment, kBothAttachments }
 

Detailed Description

Base class for implementing ISubject. Usually you can reuse existing implementations of ISubject; either

See Also
kCSubjectImpl or
kCPersistSubjectImpl. If for some reason this doesn't work, you should inherit from CSubject instead of directly from ISubject so you get default class behaviors. See ISubject for information about what the methods do.
ISubject
IObserver

Member Function Documentation

virtual void CSubject::AttachObserver (IObserverobserver,
const PMIIDinterestedIn,
const PMIIDasObserver = IID_IOBSERVER 
)
virtual

Attach an observer that uses regular attachment to this subject.

Note: this method is equivalent to calling ISubject::AttachObserver(AttachmentType, IObserver*, const PMIID& interestedIn, const PMIID& asObserver) specifying an attachment type of kRegularAttachment.

Parameters
observerthe observer to be attached
interestedInmay be used to narrow the scope of interested changes
asObservermust be used if the observer has an interface id that is different than IID_IOBSERVER

Implements ISubject.

virtual void CSubject::AttachObserver (AttachmentType attachType,
IObserverobserver,
const PMIIDinterestedIn,
const PMIIDasObserver 
)
virtual

Attach the observer using the given attachment type (regular, lazy or both) to this subject.

Parameters
attachTypespecifies the type of attachment the observer uses and controls the type of notification it receives, for example regular notification or lazy notification.
observeris the observer to be attached
interestedInspecifies the scope of interested changes; for example if you are interested in a specific interface on this subject pass the interface id here.
asObserverthe interface id of the observer

Implements ISubject.

virtual void CSubject::Change (ClassID theChange,
const PMIIDinterestedIn = IID_IUNKNOWN,
void * changedBy = nil 
)
virtual

Notify observers that are attached to this subject via regular attachment that the object this subject is part of has been changed.

This method iterates over the observers that are attached to this subject using regular attachment and calls their IObserver::Update method (regular notification).

Parameters
theChangeis the actual change, often the ClassID of a command
interestedInspecifies the interface of the object that was modified
changedByis generic pointer to the object that caused the change, usually a pointer to a command object
See Also
IObserver::Update

Implements ISubject.

virtual void CSubject::Change (ISubjectoriginalSubject,
ClassID theChange,
const PMIIDinterestedIn = IID_IUNKNOWN,
void * changedBy = nil 
)
virtual

Notify observers that are attached to this subject via regular attachment that the object this subject is part of has been changed.

This method iterates over the observers that are attached to this subject using regular attachment and calls their IObserver::Update method (regular notification).

The difference between this method and the other Change method is that the object given by the originalSubject parameter is passed into IObserver::Update as the subject that was changed, rather than this subject.

Parameters
originalSubjectis the original subject of the object that was changed
theChangeis the actual change, often the ClassID of a command
interestedInidentifies the interface of the object that was modified
changedByis generic pointer to the object that caused the change, usually a pointer to a command object
See Also
IObserver::Update

Implements ISubject.

virtual void CSubject::DetachObserver (IObserverobserver,
const PMIIDinterestedIn,
const PMIIDasObserver = IID_IOBSERVER 
)
virtual

Detach an observer that uses regular attachment from this subject.

Note: this method is equivalent to calling ISubject::DetachObserver(AttachmentType, IObserver*, const PMIID& interestedIn, const PMIID& asObserver) specifying an attachment type of kRegularAttachment.

Parameters
observerthe observer to be detached
interestedInidentifies the interface in this subject that the observer is attached to
asObserveris the interface id of the observer

Implements ISubject.

virtual void CSubject::DetachObserver (AttachmentType attachType,
IObserverobserver,
const PMIIDinterestedIn,
const PMIIDasObserver 
)
virtual

Detach the observer using the given attachment type (regular, lazy or both) from this subject.

Parameters
attachTypespecifies the type of attachment
observeris the observer to be detached
interestedInidentifies the interface in this subject that the observer is attached to
asObserverthe interface id of the observer

Implements ISubject.

virtual IChangeManager* CSubject::GetChangeManager () const
virtual

Access the internal implementation of the notification mechanism.

Returns
the change manager interface pointer

Implements ISubject.

virtual bool16 CSubject::IsAttached (IObserverobserver,
const PMIIDinterestedIn,
const PMIIDasObserver = IID_IOBSERVER 
)
virtual

Check whether an observer that uses regular attachment is attached to this subject.

Note: this method is equivalent to calling ISubject::IsAttached(AttachmentType, IObserver*, const PMIID& interestedIn, const PMIID& asObserver) specifying and attachment type of kRegularAttachment.

Parameters
observerthe observer to be checked
interestedInidentifies the interface in this subject that the observer is attached to
asObserverthe interface id of the observer
Returns
kTrue if the specified observer has been attached

Implements ISubject.

virtual bool16 CSubject::IsAttached (AttachmentType attachType,
IObserverobserver,
const PMIIDinterestedIn,
const PMIIDasObserver 
)
virtual

Check whether the observer is attached to this subject.

Parameters
attachTypespecifies the type of attachment
observeris the observer to be checked
interestedInidentifies the interface in this subject that the observer is attached to
asObserverthe interface id of the observer
Returns
kTrue if the specified observer is attached, kFalse otherwise

Implements ISubject.

virtual bool16 CSubject::IsMuted () const
virtual

Returns kTrue if this subject is muted.

Implements ISubject.

virtual void CSubject::ModelChange (ClassID theChange,
const PMIIDinterestedIn,
void * changedBy,
LazyNotificationDatadata 
)
virtual

Notify observers that are attached to this subject via regular or lazy attachment that the object this subject is part of has been changed; this is the ModelChange method you probably want to call.

This method iterates over the observers that are attached to this subject using regular attachment and calls their IObserver::Update method (regular notification). Additionally, this method queues a message so that observers that are attached to the subject using lazy attachment get called later on when the application is idle via their IObserver::LazyUpdate method (lazy notification).

Precondition
this subject must be part of an InDesign database that supports undo
Parameters
theChangeis the actual change, often the ClassID of a command
interestedInidentifies the interface of the object that was modified
changedBypointer to the object that caused the change, usually a pointer to a command object
datacontains additional information about the change, nil otherwise; see LazyNotificationData for documentation.
See Also
IObserver::Update
IObserver::LazyUpdate

Implements ISubject.

virtual void CSubject::ModelChange (ISubjectoriginalSubject,
ClassID theChange,
const PMIIDinterestedIn,
void * changedBy,
LazyNotificationDatadata 
)
virtual

Notify observers that are attached to this subject via regular or lazy attachment that the object this subject is part of has been changed. Only use this method if you are sure you cannot use ISubject::ModelChange(ClassID, const PMIID&, void*, LazyNotificationData*).

This method passes the object given by the originalSubject parameter to IObserver::Update as the subject that was changed, rather than this subject. However, the originalSubject is not available when IObserver::LazyUpdate is called. When the lazy notification occurs, this subject is passed to IObserver::LazyUpdate. If you need access to originalSubject, do so in the IObserver::Update method.

Precondition
this subject must be part of an InDesign database that supports undo
Parameters
originalSubjectis the original subject of the object that was changed
theChangeis the actual change, often the ClassID of a command
interestedInidentifies the interface of the object that was modified
changedByis generic pointer to the object that caused the change, usually a pointer to a command object
datacontains additional information about the change, nil otherwise; see LazyNotificationData for documentation.
See Also
IObserver::Update
IObserver::LazyUpdate

Implements ISubject.

virtual void CSubject::ModelChange (IDataBasemodel,
ClassID theChange,
const PMIIDinterestedIn,
void * changedBy,
LazyNotificationDatadata 
)
virtual

Use of this method is very rare. Call one of the other ModelChange methods unless you are sure this one is the right one for your use case. It is used to notify that a "snapshot view interface" has changed. For example, the layout widget uses this method to notify that ILayoutControlData has changed. ILayoutControlData is implemented as a "snapshot view interface" and change to this interface must get undone and redone as changes to the document being viewed get undone and redone.

Parameters
modelpointer to an InDesign database that supports undo
theChangeis the actual change, often the ClassID of a command
interestedInidentifies the interface of the object that was modified
changedByis generic pointer to the object that caused the change, usually a pointer to a command object
datacontains additional information about the change, nil otherwise; see LazyNotificationData for documentation.
See Also
CREATE_VIEW_PMINTERFACE in "InterfaceFactory.h".
"Snapshot view interface" extension pattern documentation in the Programming Guide

Implements ISubject.

virtual void CSubject::Mute (bool16 muteOn)
virtual

Mutes all messages from this object. Muting a subject allows you to make changes to the object without notifying its observers.

Parameters
muteOnif kTrue, turns mute on; if kFalse, turns mute off

Implements ISubject.