// $Revision: 1.3 $ // DragOMatic.C // Copyright (C) 1994, 1995 Taligent, Inc. All rights reserved. #ifndef TaligentSamples_DRAGOMATIC #include "DragOMatic.h" #endif #ifndef TaligentSamples_INSERTIONTARGET #include "InsertionTarget.h" #endif #ifndef TaligentSamples_HIGHLIGHTFEEDBACKSTYLE #include "HighlightFeedbackStyle.h" #endif #ifndef Taligent_KEYBOARDINPUT #include #endif TaligentTypeExtensionMacro(TDOMDocumentComponentView) TDOMDocumentComponentView::TDOMDocumentComponentView() : TDocumentComponentView(), MDropAcceptor(TViewHandle(*this)), MSelectionMapping(TViewHandle(*this)), fFeedbacker(TViewHandle(*this)), fSelectionToolHandler(&fFeedbacker, this, this), fNegotiator(NIL), fDropAcceptor() { } TDOMDocumentComponentView::TDOMDocumentComponentView(TGUIBundle* guiBundleToAlias) : TDocumentComponentView(guiBundleToAlias), MDropAcceptor(TViewHandle(*this)), MSelectionMapping(TViewHandle(*this)), fFeedbacker(TViewHandle(*this)), fSelectionToolHandler(&fFeedbacker, this, this), fNegotiator(NIL), fDropAcceptor() { } TDOMDocumentComponentView::~TDOMDocumentComponentView() { } TStream& TDOMDocumentComponentView::operator>>=(TStream& s) const { ::WriteVersion(s, kOriginalVersion); TDocumentComponentView::operator>>=(s); return s; } TStream& TDOMDocumentComponentView::operator<<=(TStream& s) { ::ReadVersion(s, kOriginalVersion, kOriginalVersion); TDocumentComponentView::operator<<=(s); return s; } bool TDOMDocumentComponentView::DispatchEvent(TEvent& event) { bool handled = FALSE; if (fNegotiator) { handled = fNegotiator->DispatchEvent(event); } if (!handled) { handled = TDocumentComponentView::DispatchEvent(event); } return handled; } void TDOMDocumentComponentView::DragItemEntered(const TGPoint& where, const TSequenceOf& availableTypes) { static const TTypeDescription kInsertionTargetType(StaticTypeInfo(TInsertionTarget)); TGPoint globalWhere(where); LocalToGlobal(globalWhere); TDeleterFor temp = fSelectionToolHandler.CreateToolTarget(kInsertionTargetType, globalWhere); TInsertionTarget* target; DynamicCastTo(target, temp.GetObject()); if (target != NIL) { temp.OrphanObject(); fDropAcceptor.AdoptTarget(target); } fDropAcceptor.DragItemEntered(where, availableTypes); } void TDOMDocumentComponentView::DragItemMoved(const TGPoint& where, const TSequenceOf& availableTypes) { fDropAcceptor.DragItemMoved(where, availableTypes); } void TDOMDocumentComponentView::DragItemExited(const TGPoint& where) { fDropAcceptor.DragItemExited(where); } bool TDOMDocumentComponentView::ChoosePreferredType(const TGPoint& whereDropped, const TSequenceOf& availableTypes, TTypeDescription& chosenType) const { return fDropAcceptor.ChoosePreferredType(whereDropped, availableTypes, chosenType); } bool TDOMDocumentComponentView::AcceptDrop(const TGPoint& whereDropped, const TTypeDescription& type, const TScrapItem& item) { return fDropAcceptor.AcceptDrop(whereDropped, type, item); } void TDOMDocumentComponentView::DrawContents(TGrafPort& port) const { if (!fFeedbacker.DrawFeedback(port)) { // Draw the selected area if (GetCurrentModelSelection() != NIL) { TDeleterFor selection(::CopyPointer(GetCurrentModelSelection())); TGArea selectedArea(GetSelectionDisplayArea(*selection.GetObject())); TDeleterFor highlight = THighlightFeedbackStyle().DoCreateFeedback(selectedArea); highlight->Draw(port); } } } void TDOMDocumentComponentView::HandleAfterConnectionToViewRoot() { TDocumentComponentView::HandleAfterConnectionToViewRoot(); fNegotiator = new TToolNegotiator(&fSelectionToolHandler, TViewHandle(*this)); } void TDOMDocumentComponentView::HandleBeforeDisconnectionFromViewRoot() { delete fNegotiator; fNegotiator = NIL; TDocumentComponentView::HandleBeforeDisconnectionFromViewRoot(); } TGArea TDOMDocumentComponentView::GetSelectionDisplayArea(const TModelSelection& area) const { TGArea result; GetAllocatedArea(result); return result; } TModelSelection* TDOMDocumentComponentView::CreateInsertionPoint(const TGPoint& where) const { const TModelPointerTo model(GetModelReference()); TModelSelection* selection = model->CreateSelection(); TGArea viewArea; GetAllocatedArea(viewArea); if (viewArea.Contains(where)) { selection->DeselectAll(); } else { selection->SetUndefined(); } return selection; } TModelSelection* TDOMDocumentComponentView::CreateSelectionFromPoint(const TGPoint& where) const { const TModelPointerTo model(GetModelReference()); TModelSelection* selection = model->CreateSelection(); TGArea viewArea; GetAllocatedArea(viewArea); if (viewArea.Contains(where)) { selection->SelectWholeModel(); } else { selection->SetUndefined(); } return selection; } TModelSelection* TDOMDocumentComponentView::CreateSelectionFromArea(const TGArea& where) const { const TModelPointerTo model(GetModelReference()); TModelSelection* selection = model->CreateSelection(); TGArea viewArea; GetAllocatedArea(viewArea); if (!(viewArea * where).IsEmpty()) { selection->SelectWholeModel(); } else { selection->SetUndefined(); } return selection; } TDOMDocumentComponentView::TDOMDocumentComponentView(const TDOMDocumentComponentView& source) : TDocumentComponentView(), MDropAcceptor(TViewHandle(*this)), MSelectionMapping(TViewHandle(*this)), fFeedbacker(TViewHandle(*this)), fSelectionToolHandler(&fFeedbacker, this, this), fNegotiator(NIL), fDropAcceptor() { Assertion(false, "TDOMDocumentComponentView can't be copied"); }