class TShapeView : public TSimpleView, public virtual VViewInitialize { public: MCollectibleDeclarationsMacro(TShapeView); TShapeView(TShapeList* shapeList, const TGPoint& size, const TGPoint& locationInParent = TGPoint::kOrigin); TShapeView(const TShapeView&); virtual ~TShapeView(); protected: virtual void DrawContents(TGrafPort&) const; virtual void HandleAddedShape(const TNotification&); virtual void HandleRemovedShape(const TNotification&); private: TShapeList* fShapeList; TMemberFunctionConnectionTo<TShapeView> fConnection; enum { kOriginalVersion }; };
The protocol for creating interests in an instance of TShapeList is to call the appropriate member functions of that instance. The receiver creates the interests and adds them to the connection, associating a member function with each interest. The connection automatically dispatches notifications to the appropriate handler.
When the receiver is ready to handle notifications, it calls Connect on its connection.
TShapeView::TShapeView(TShapeList* shapeList, const TGPoint& size, const TGPoint& locationInParent) : TSimpleView (size, locationInParent), fConnection(this), VViewInitialize(&gMetaInfo) { fShapeList = shapeList; CheckForInitialize(&gMetaInfo); fConnection.AddInterest(fShapeList->GetAddedShapeInterest(), &TShapeView::HandleAddedShape); fConnection.AddInterest(fShapeList->GetRemovedShapeInterest(), &TShapeView::HandleRemovedShape); fConnection.Connect(); }
void TShapeView::HandleAddedShape(const TNotification& notification) { InvalidateAll(); }