Follow these steps to process batched notification:
class TShapeView : public TSimpleView, public virtual VViewInitialize { protected: virtual void HandleBatchNotification(const TNotification&); // ... private: TGArea fAreaToInvalidate; // ... };
TShapeView::TShapeView(TShapeList* shapeList, const TGPoint& size, const TGPoint& locationInParent) : TSimpleView (size, locationInParent), fConnection(this, &TShapeView::HandleBatchNotification), fAreaToInvalidate(), VViewInitialize(&gMetaInfo) { fShapeList = shapeList; CheckForInitialize(&gMetaInfo); fConnection.AddInterest(fShapeList->GetAddedShapeInterest(), &TShapeView::HandleAddedShape); fConnection.AddInterest(fShapeList->GetRemovedShapeInterest(), &TShapeView::HandleRemovedShape); fConnection.SetBatchNotify(); fConnection.Connect(); }
HandleBatchNotification coerces the notification into a TBatchNotification and calls DispatchNotifications. The call to DispatchNotifications sends the notifications contained in the batch notification to the other appropriate handlers. These handlers modify the area to invalidate.
Finally, HandleBatchNotification invalidates the area and restores it for the next time it is called.
void TShapeView::HandleBatchNotification(const TNotification& notification) { TBatchedNotification* batch = (const TBatchNotification*)¬ification; batch->DispatchNotifications(); Invalidate(fAreaToInvalidate); fAreaToInvalidate.SetToEmpty(); }
void TShapeView::HandleAddedShape(const TNotification& notification) { const TShapeNotification* shapeNotification = (const TShapeNotification*)¬ification; fAreaToInvalidate += areaNotification->GetShape()->GetLooseFitBounds(); }