// $Revision: 1.4 $ // SelectionToolInteractor.C // Copyright (C) 1994, 1995 Taligent, Inc. All rights reserved. #ifndef TaligentSamples_SELECTIONTOOLINTERACTOR #include "SelectionToolInteractor.h" #endif #ifndef TaligentSamples_CURRENTSELECTIONTARGET #include "CurrentSelectionTarget.h" #endif #ifndef TaligentSamples_SELECTIONTARGET #include "SelectionTarget.h" #endif #ifndef TaligentSamples_RANGESELECTOR #include "RangeSelector.h" #endif #ifndef TaligentSamples_DRAGSELECTOR #include "DragSelector.h" #endif #ifndef TaligentSamples_OUTLINEFEEDBACKSTYLE #include "OutlineFeedbackStyle.h" #endif #ifndef Taligent_VIEW #include #endif #ifndef Taligent_KEYBOARDINPUT #include #endif #ifndef Taligent_MODELSCRAPITEM #include #endif #ifndef TaligentSamples_SIMPLEDRAGANDDROPITEM #include "SimpleDragAndDropItem.h" #endif #ifndef Taligent_MOUSEDRAGANDDROP #include #endif //................................................................................ #ifndef TaligentSamples_DYNAMICCREATIONCASTTO #define TaligentSamples_DYNAMICCREATIONCASTTO template bool DynamicCreationCastTo(TDeleterFor& dest, TSOURCE* sourceToAdopt) { TDEST* result; DynamicCastTo(result, sourceToAdopt); if (result == NIL) { delete sourceToAdopt; } else { dest = result; } return result != NIL; } #endif //................................................................................ TaligentTypeExtensionMacro_Abstract(TSelectionToolInteractor) TSelectionToolInteractor::TSelectionToolInteractor(MToolHandler* handler) : TToolInteractor(handler), MMouseEventHandler(), fSubInteractor(NIL) { } TSelectionToolInteractor::~TSelectionToolInteractor() { } bool TSelectionToolInteractor::MouseDown(TMouseDownEvent& mouseDown) { fSubInteractor = NIL; static const TTypeDescription kCurrentSelectionTargetType(StaticTypeInfo(TCurrentSelectionTarget)); static const TTypeDescription kSelectionTargetType(StaticTypeInfo(TSelectionTarget)); TGPoint global(mouseDown.GetGlobalEventPosition()); TGPoint local(mouseDown.GetGlobalEventPosition()); TDeleterFor clickSelection; DynamicCreationCastTo(clickSelection, GetToolHandler()->CreateToolTarget(kSelectionTargetType, global)); if (clickSelection != NIL) { clickSelection->GetCoordinateView().GetView()->GlobalToLocal(local); clickSelection->SetSelectedArea(local); if (!clickSelection->GetSelection()->IsDefined() || clickSelection->GetSelection()->IsEmpty()) { fSubInteractor = new TRangeSelector(GetToolHandler()); fSubInteractor->Activate(); } else { TDeleterFor currentSelection; DynamicCreationCastTo(currentSelection, GetToolHandler()->CreateToolTarget(kCurrentSelectionTargetType, global)); if (currentSelection != NIL) { if (TKeyboardInputDevice::GetDefaultKeyboardInputDevice(mouseDown)->GetModifierKeys().IsPowerKeyDown()) { clickSelection->SetSelectedArea(clickSelection->GetSelectionDisplayArea() ^ currentSelection->GetSelectionDisplayArea()); currentSelection->AdoptSelection(::Copy(*clickSelection->GetSelection())); } else if (TKeyboardInputDevice::GetDefaultKeyboardInputDevice(mouseDown)->GetModifierKeys().IsShiftKeyDown()) { TGRect bounds(currentSelection->GetSelectionDisplayArea().GetBounds()); bounds.ExtendTo(local); clickSelection->SetSelectedArea(bounds); currentSelection->AdoptSelection(::Copy(*clickSelection->GetSelection())); } else if (!currentSelection->GetSelectionDisplayArea().Contains(local)) { currentSelection->AdoptSelection(::Copy(*clickSelection->GetSelection())); } clickSelection = NIL; if (currentSelection->GetSelectionDisplayArea().Contains(local)) { SetCoordinateView(currentSelection->GetCoordinateView()); StartMouseMovedEvents(*(TMouseInputDevice*)mouseDown.GetInputDevice()); } } } } return (fSubInteractor != NIL) ? DispatchEvent(mouseDown) : true; } bool TSelectionToolInteractor::MouseMoved(TMouseMovedEvent& mouseDown) { static const TTypeDescription kCurrentSelectionTargetType(StaticTypeInfo(TCurrentSelectionTarget)); StopMouseMovedEvents(); TGPoint global(mouseDown.GetGlobalEventPosition()); TGPoint local(mouseDown.GetGlobalEventPosition()); TDeleterFor currentSelection; DynamicCreationCastTo(currentSelection, GetToolHandler()->CreateToolTarget(kCurrentSelectionTargetType, global)); if (currentSelection != NIL) { currentSelection->GetCoordinateView().GetView()->GlobalToLocal(local); TDeleterFor graphic = TOutlineFeedbackStyle().CreateFeedback(*currentSelection); graphic->TransformBy(TGrafMatrix(TGPoint::kOrigin - local)); TDeleterFor scrap = new TModelScrapItem(*currentSelection->GetSelection()); TDeleterFor dragItem = new TSimpleDragAndDropItem(currentSelection->GetCoordinateView()); dragItem->AdoptScrapItem(scrap.OrphanObject()); fSubInteractor = new TDragSelector( dragItem.OrphanObject(), graphic.OrphanObject(), TViewHandle(currentSelection->GetCoordinateView()), mouseDown); fSubInteractor->Activate(); } else { SetDone(true); } return (fSubInteractor != NIL) ? DispatchEvent(mouseDown) : false; } bool TSelectionToolInteractor::MouseUp(TMouseUpEvent& mouseUp) { Assertion(!fSubInteractor, "TSelectionToolInteractor::MouseUp"); StopMouseMovedEvents(); SetDone(true); return true; } bool TSelectionToolInteractor::DispatchEvent(TEvent& event) { Assertion(IsActive() && !IsDone(), "TSelectionToolInteractor::DispatchEvent"); bool handled = false; if (fSubInteractor) { handled = fSubInteractor->DispatchEvent(event); if (fSubInteractor->IsDone()) { fSubInteractor = NIL; SetDone(true); } } else { handled = TToolInteractor::DispatchEvent(event); } return handled; }