// $Revision: 1.3 $ // RangeSelector.C // Copyright (C) 1994, 1995 Taligent, Inc. All rights reserved. #ifndef TaligentSamples_RANGESELECTOR #include "RangeSelector.h" #endif #ifndef TaligentSamples_SELECTIONTARGET #include "SelectionTarget.h" #endif #ifndef TaligentSamples_CURRENTSELECTIONTARGET #include "CurrentSelectionTarget.h" #endif #ifndef Taligent_VIEW #include #endif #ifndef Taligent_COMPOUNDDOCUMENT #include #endif #ifndef Taligent_KEYBOARDINPUT #include #endif #ifndef TaligentSamples_HIGHLIGHTFEEDBACKSTYLE #include "HighlightFeedbackStyle.h" #endif #ifndef TaligentSamples_BOUNDSFEEDBACKSTYLE #include "BoundsFeedbackStyle.h" #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(TRangeSelector) TRangeSelector::TRangeSelector(MToolHandler* handler) : TInteractor(), MMouseEventHandler(), fHandler(handler), fAnchorPoint(), fInitialSelection(), fBandSelection(NIL), fNewSelection(NIL) { } TRangeSelector::~TRangeSelector() { } bool TRangeSelector::MouseDown(TMouseDownEvent& mouseDown) { static const TTypeDescription kSelectionTargetType(StaticTypeInfo(TSelectionTarget)); static const TTypeDescription kCurrentSelectionTargetType(StaticTypeInfo(TCurrentSelectionTarget)); fAnchorPoint = mouseDown.GetGlobalEventPosition(); DynamicCreationCastTo(fNewSelection, fHandler->CreateToolTarget(kSelectionTargetType, fAnchorPoint)); DynamicCreationCastTo(fBandSelection, fHandler->CreateToolTarget(kSelectionTargetType, fAnchorPoint)); if (fBandSelection != NIL && fNewSelection != NIL) { Assertion(fNewSelection->GetCoordinateView() == fBandSelection->GetCoordinateView()); SetCoordinateView(fNewSelection->GetCoordinateView()); fNewSelection->GetCoordinateView().GetView()->GlobalToLocal(fAnchorPoint); bool extendSelection = TKeyboardInputDevice::GetDefaultKeyboardInputDevice(mouseDown)->GetModifierKeys().IsPowerKeyDown(); if (extendSelection) { TDeleterFor currentSelection; DynamicCreationCastTo(currentSelection, fHandler->CreateToolTarget(kCurrentSelectionTargetType, fAnchorPoint)); if (currentSelection != NIL) { fInitialSelection = currentSelection->GetSelectionDisplayArea(); } else { fNewSelection = NIL; fBandSelection = NIL; } } else { fInitialSelection.SetToEmpty(); } SyncSelections(fAnchorPoint); SyncFeedback(fAnchorPoint); StartMouseMovedEvents(*(TMouseInputDevice*)mouseDown.GetInputDevice()); } else { SetDone(true); } return fNewSelection != NIL && fBandSelection != NIL; } bool TRangeSelector::MouseMoved(TMouseMovedEvent& mouseMoved) { SyncSelections(mouseMoved.GetEventPosition()); SyncFeedback(mouseMoved.GetEventPosition()); return true; } bool TRangeSelector::MouseUp(TMouseUpEvent& mouseUp) { static const TTypeDescription kCurrentSelectionTargetType(StaticTypeInfo(TCurrentSelectionTarget)); StopMouseMovedEvents(); SetDone(true); SyncSelections(mouseUp.GetEventPosition()); TDeleterFor currentSelection; DynamicCreationCastTo(currentSelection, fHandler->CreateToolTarget(kCurrentSelectionTargetType, fAnchorPoint)); currentSelection->AdoptSelection(::Copy(*fNewSelection->GetSelection())); return true; } void TRangeSelector::SyncSelections(const TGPoint& where) { TGPoint endPoint(where); TGPoint startPoint(fAnchorPoint); TGRect bounds(fBandSelection->GetCoordinateView().GetView()->GetAllocatedArea()); bounds.Pin(startPoint); bounds.Pin(endPoint); TGRect bandBox(startPoint, endPoint); bandBox.OrderPoints(); if (bandBox.IsEmpty()) { fBandSelection->SetSelectedArea(where); } else { fBandSelection->SetSelectedArea(bandBox); } fNewSelection->SetSelectedArea( fInitialSelection ^ fBandSelection->GetSelectionDisplayArea()); } void TRangeSelector::SyncFeedback(const TGPoint& where) { fNewSelection->AdoptFeedback(THighlightFeedbackStyle().CreateFeedback(*fNewSelection)); TGPoint endPoint(where); TGPoint startPoint(fAnchorPoint); TGRect bounds(fBandSelection->GetCoordinateView().GetView()->GetAllocatedArea()); bounds.Pin(endPoint); bounds.Pin(startPoint); TGRect bandBox(startPoint, endPoint); bandBox.OrderPoints(); fBandSelection->AdoptFeedback( TBoundsFeedbackStyle().DoCreateFeedback(TGArea(bandBox))); }