// $Revision: 1.8 $ // Copyright (c) 1995 Taligent, Inc. All rights reserved. #ifndef TaligentSamples_COLORSOURCEVIEW #include "ColorSourceView.h" #endif #ifndef Taligent_ASSERTIONS #include #endif #ifndef Taligent_MOUSEDRAGANDDROP #include #endif #ifndef Taligent_GRAFPORT #include #endif #ifndef TaligentSamples_COLORSCRAPITEM #include "ColorScrapItem.h" #endif #ifndef TaligentSamples_SINGLEDRAGANDDROPITEM #include "SingleDragAndDropItem.h" #endif MCollectibleDefinitionsMacro(TColorSourceView, 0); TColorSourceView::TColorSourceView(const TGPoint& extent, const TGPoint& location, const TColor& color) : TContentView(extent, location), MMouseEventHandler(), fColor(color) { } TColorSourceView::~TColorSourceView() { } void TColorSourceView::HandleAfterConnectionToViewRoot() { RegisterSimpleTarget(*InternalGetEventReceiver()); SetCoordinateView(TViewHandle(*this)); } void TColorSourceView::HandleBeforeDisconnectionFromViewRoot() { DeregisterSimpleTarget(*InternalGetEventReceiver()); } void TColorSourceView::DrawContents(TGrafPort& port) const { TGArea area; GetAllocatedArea(area); port.Draw(area, TFillAndFrameBundle(fColor, TRGBColor(0,0,0), 1.0, TPen::kInsetFrame)); } bool TColorSourceView::MouseButtonDown(TMouseDownEvent& event, short) { TDeleterFor graphic = new TEllipse(TGEllipse(TGRect(-10, -10, 10, 10)), new TGrafBundle(fColor, TRGBColor(0,0,0))); TDeleterFor scrap = new TColorScrapItem(fColor); TDeleterFor dragItem = new TSingleDragAndDropItem(TViewHandle(*this), scrap.OrphanObject()); TInteractor* interactor = new TMouseDragAndDropInteractor( dragItem.OrphanObject(), graphic.OrphanObject(), TViewHandle(*this)); event.StartInteractor(interactor); return true; } void TColorSourceView::HandleAllocatedAreaChanged(const TGArea&) { InvalidateAll(); } TColorSourceView::TColorSourceView() : TContentView(), MMouseEventHandler(), fColor(1, 1, 1) { } TColorSourceView::TColorSourceView(const TColorSourceView& source) { Assertion(false, "cannot copy TColorSourceView"); }