// $Revision: 1.1 $ // AutoDropAcceptor.C // Copyright (C) 1994, 1995 Taligent, Inc. All rights reserved. #include "AutoDropAcceptor.h" #ifndef Taligent_MODELSCRAPITEM #include #endif #ifndef TaligentSamples_SIMPLEDRAGANDDROPITEM #include "SimpleDragAndDropItem.h" #endif #ifndef TaligentSamples_INSERTIONTARGET #include "InsertionTarget.h" #endif #ifndef TaligentSamples_HIGHLIGHTFEEDBACKSTYLE #include "HighlightFeedbackStyle.h" #endif #ifndef Taligent_MOUSEDRAGANDDROP #include #endif #ifndef Taligent_SCRAPITEM #include #endif #ifndef Taligent_COMPOUNDDOCUMENTCOMMAND #include #endif //-------------------------- Class MAutoDropAcceptor ------------------- MAutoDropAcceptor::MAutoDropAcceptor() : fTarget(NIL) { } MAutoDropAcceptor::MAutoDropAcceptor(TInsertionTarget* target) : fTarget(target) { } MAutoDropAcceptor::~MAutoDropAcceptor() { } void MAutoDropAcceptor::AdoptTarget(TInsertionTarget* target) { fTarget = target; } void MAutoDropAcceptor::DragItemEntered(const TGPoint& where, const TSequenceOf& availableTypes) { if (fTarget) { fTarget->SetInsertionLocation(where); AdjustFeedbackGraphic(availableTypes); } } void MAutoDropAcceptor::DragItemMoved(const TGPoint& where, const TSequenceOf& availableTypes) { if (fTarget) { fTarget->SetInsertionLocation(where); AdjustFeedbackGraphic(availableTypes); } } void MAutoDropAcceptor::DragItemExited(const TGPoint& where) { if (fTarget) { fTarget->SetInsertionLocation(where); delete fTarget->OrphanFeedback(); } } bool MAutoDropAcceptor::ChoosePreferredType(const TGPoint& whereDropped, const TSequenceOf& availableTypes, TTypeDescription& chosenType) const { bool result = false; if (fTarget) { fTarget->SetInsertionLocation(whereDropped); MDataExchanger* exchanger; DynamicCastTo(exchanger, fTarget->GetSelection()); TTypeDescription* type = NIL; if (exchanger) { type = NegotiateType(exchanger, availableTypes); if(type) { chosenType = *type; } } result = type != NIL; } return result; } bool MAutoDropAcceptor::AcceptDrop(const TGPoint& whereDropped, const TTypeDescription& type, const TScrapItem& item) { bool result = false; if (fTarget) { const TModelScrapItem* scrap = NIL; DynamicCastTo(scrap, &item); fTarget->SetInsertionLocation(whereDropped); MDataExchanger* exchanger; DynamicCastTo(exchanger, fTarget->GetSelection()); if (exchanger) { TModel* data = scrap->CopyModel(type); Assertion(data, "MAutoDropAcceptor::AcceptDrop"); TDocumentComponentWriteEntry entry(fTarget->GetSelection()->GetModelReference()); delete exchanger->ReplaceData(data); result = true; } } return result; } void MAutoDropAcceptor::AdjustFeedbackGraphic(const TSequenceOf& availableTypes) { MDataExchanger* exchanger; DynamicCastTo(exchanger, fTarget->GetSelection()); if (exchanger && NegotiateType(exchanger, availableTypes)) { fTarget->AdoptFeedback( THighlightFeedbackStyle(TRGBColor(1, .2, .2), 0.5).CreateFeedback(*fTarget)); } } TTypeDescription* MAutoDropAcceptor::NegotiateType(MDataExchanger* exchanger, const TSequenceOf& available) const { TDequeOf chosen(new TOperatorComparator(), new TPolymorphicStreamer()); { TDocumentComponentReadEntry entry(fTarget->GetSelection()->GetModelReference()); exchanger->ChooseTypes(available, chosen); } TTypeDescription* result = chosen.First(); chosen.RemoveAll(); return result; }