// $Revision: 1.7 $ // Copyright (c) 1995 Taligent, Inc. All rights reserved. #ifndef TaligentSamples_COLORACCEPTORVIEW #include "ColorAcceptorView.h" #endif #ifndef Taligent_GRAFPORT #include #endif #ifndef Taligent_ASSERTIONS #include #endif #ifndef TaligentSamples_COLORSCRAPITEM #include "ColorScrapItem.h" #endif MCollectibleDefinitionsMacro(TColorAcceptorView, 0); TColorAcceptorView::TColorAcceptorView() : TSimpleView(), MDropAcceptor(TViewHandle(*this)), fColor(1, 1, 1) { } TColorAcceptorView::TColorAcceptorView(const TGPoint& extent, const TColor& color) : TSimpleView(extent), MDropAcceptor(TViewHandle(*this)), fColor(color) { } TColorAcceptorView::~TColorAcceptorView() { } TColorAcceptorView::TColorAcceptorView(const TColorAcceptorView& source) : TSimpleView(), MDropAcceptor(TViewHandle(*this)), fColor(1, 1, 1) { // We need this or else the compiler complains that in MCollectibleDefinitionsMacro // it can't construct an object of type "TColorAcceptorView" from a "const TColorAcceptorView" expression. Assertion(false, "cannot copy TColorAcceptorView."); } void TColorAcceptorView::DrawContents(TGrafPort& port) const { TGArea area; GetAllocatedArea(area); port.Draw(area.GetBounds(), TFillAndFrameBundle(fColor, TRGBColor(0,0,0), 1.0, TPen::kInsetFrame)); } bool TColorAcceptorView::ChoosePreferredType( const TGPoint& location, const TSequenceOf& availableTypes, TTypeDescription& chosenType) const { bool result = false; TIteratorOver* iter = availableTypes.CreateIterator(); for (const TTypeDescription* td = iter->First(); td; td = iter->Next()) { if (*td == TColorScrapItem::kScrapItemType) { chosenType = *td; result = true; break; } } delete iter; return result; } bool TColorAcceptorView::AcceptDrop( const TGPoint& location, const TTypeDescription& typeDescription, const TScrapItem& scrapItem) { bool result = false; if (typeDescription == TColorScrapItem::kScrapItemType) { fColor = ((TColorScrapItem&)scrapItem).GetColor(); Invalidate(); result = true; } return result; } void TColorAcceptorView::HandleAllocatedAreaChanged(const TGArea&) { InvalidateAll(); }