TShapeList exports the protocol and notifies appropriately

TShapeList adds two new member functions that create TShapeInterests in changes to particular shapes.

When a shape is added, TShapeList creates a TShapeNotification with a TShapeInterest for that shape and calls Notify twice--once to send the notification to receivers that registered interest in the addition of that particular shape and once to send it to receivers that registered interest in the addition of any shape. Removal of a shape works similarly.

Here is the change to the interface of TShapeList:

      class TShapeList : public TNotifier {
      public:
          TShapeInterest  GetAddedThisShapeInterest(const TShape&); // TShapeNotification
          TShapeInterest  GetRemovedThisShapeInterest(const TShape&); // TShapeNotification
          // ...
      }
The implementation of GetAddedThisShapeInterest is as expected; GetRemovedThisShapeInterest is similar. The token that names the GetAddedThisShapeInterest need not match that for GetAddedShapeInterest.

      TShapeInterest TShapeList::GetAddedThisShapeInterest(const TShape& shape)
      {
          const TToken kAddedThisShape("kAddedThisShape");
          return TShapeInterest(this, kAddedThisShape, shape);
      }
The implementation of AdoptShape notifies twice, using different interests each time.

The TShapeNotification contains an instance of TShapeInterest, in case receivers want to look at it.

      void TShapeList::AdoptShape(MGraphic* shape)
      {
          fShapes.Add(shape);
      
          TShapeNotification notification(GetAddedThisShapeInterest(shape), *shape);
      
          Notify(notification);   // sent using the shape interest
          Notify(notification, GetAddedShapeInterest());  // sent using different interest
      }

[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker