// $Revision: 1.2 $ // Feedbacker.C // Copyright (C) 1994, 1995 Taligent, Inc. All rights reserved. #ifndef TaligentSamples_FEEDBACKER #include "Feedbacker.h" #endif #ifndef Taligent_GRAPHICS #include #endif #ifndef Taligent_ASSERTIONS #include #endif #ifndef Taligent_AREAGEOMETRY #include #endif #ifndef Taligent_VIEW #include #endif //................................................................................ MFeedbacker::MFeedbacker(const TViewHandle& view) : fFeedback(NIL, NIL), fFeedbackLock(), fView(view) { } MFeedbacker::~MFeedbacker() { Assertion(fFeedback.Count() == 0, "MFeedbacker::~MFeedbacker"); } void MFeedbacker::AdoptFeedback(MGraphic* graphic) { TMonitorEntry entry(&fFeedbackLock); Assertion(graphic != NIL, "MFeedbacker::AdoptFeedback"); Assertion(!fFeedback.Member(*graphic), "MFeedbacker::AdoptFeedback"); if (fFeedback.Count() == 0) { HandleHideCurrentSelectionFeedback(); } fFeedback.Add(graphic); HandleFeedbackChanged(graphic->GetLooseFitBounds(GetFeedbackView().GetView()->GetGrafPort())); } MGraphic* MFeedbacker::OrphanFeedback(const MGraphic& graphic) { TMonitorEntry entry(&fFeedbackLock); Assertion(fFeedback.Member(graphic), "MFeedbacker::OrphanFeedback"); MGraphic* result = fFeedback.Remove(graphic); HandleFeedbackChanged(result->GetLooseFitBounds(GetFeedbackView().GetView()->GetGrafPort())); if (fFeedback.Count() == 0) { HandleShowCurrentSelectionFeedback(); } return result; } MGraphic* MFeedbacker::ReplaceFeedback(const MGraphic& oldFeedback, MGraphic* newFeedback) { TMonitorEntry entry(&fFeedbackLock); Assertion(newFeedback != NIL, "MFeedbacker::ReplaceFeedback"); Assertion(fFeedback.Member(oldFeedback), "MFeedbacker::ReplaceFeedback"); MGraphic* result = fFeedback.Remove(oldFeedback); TGArea invalidArea(result->GetLooseFitBounds(GetFeedbackView().GetView()->GetGrafPort())); invalidArea += newFeedback->GetLooseFitBounds(GetFeedbackView().GetView()->GetGrafPort()); fFeedback.Add(newFeedback); HandleFeedbackChanged(invalidArea); return result; } bool MFeedbacker::DrawFeedback(TGrafPort& port) const { TMonitorEntry entry((TMonitorLock*)&fFeedbackLock); //cast away const TDequeOfIterator iter(&fFeedback); for (MGraphic* item = iter.First(); item != NIL; item = iter.Next()) { item->Draw(port); } return fFeedback.Count() > 0; } TViewHandle MFeedbacker::GetFeedbackView() const { Assertion(fView.GetView() != NIL, "MFeedbacker::GetFeedbackView"); return fView; } void MFeedbacker::HandleHideCurrentSelectionFeedback() { GetFeedbackView().GetView()->Invalidate(); } void MFeedbacker::HandleShowCurrentSelectionFeedback() { GetFeedbackView().GetView()->Invalidate(); } void MFeedbacker::HandleFeedbackChanged(const TGArea& area) { GetFeedbackView().GetView()->Invalidate(area); }