// $Revision: 1.4 $ // Copyright (c) 1994-1995 Taligent, Inc. All rights reserved. #ifndef TaligentSamples_MOUSEINPUTVIEW #include "MouseInputView.h" #endif #ifndef Taligent_GRAFPORT #include #endif #ifndef Taligent_NUMBERFORMAT #include #endif #ifndef Taligent_RGBCOLOR #include #endif #ifndef Taligent_TEXTDISPLAY #include #endif MCollectibleDefinitionsMacro(TMouseInputView, kOriginalVersion); TMouseInputView::TMouseInputView() : TContentView(TGPoint(300, 50)), MMouseEventHandler(), fLastButtonChanged(0), fLastButtonChangeWasDown(false), fLastButtonChangeGlobalCoordinates(TGPoint::kOrigin) { } TMouseInputView::TMouseInputView(const TGPoint& size, const TGPoint& location) : TContentView(size, location), MMouseEventHandler(), fLastButtonChanged(0), fLastButtonChangeWasDown(false), fLastButtonChangeGlobalCoordinates(TGPoint::kOrigin) { } TMouseInputView::~TMouseInputView() { } // We don't know the event receiver until we're connected, and it should forget // about us before we're disconnected. void TMouseInputView::HandleAfterConnectionToViewRoot() { RegisterSimpleTarget(*InternalGetEventReceiver()); } void TMouseInputView::HandleBeforeDisconnectionFromViewRoot() { DeregisterSimpleTarget(*InternalGetEventReceiver()); } // Draw the information about the last mouse event that we received. void TMouseInputView::DrawContents(TGrafPort& port) const { static const TFillAndFrameBundle bundle(TRGBColor(1,1,1), TRGBColor(0,0,0), 2.0, TPen::kInsetFrame); TGArea area; GetBounds(area); port.Draw(area, bundle); TStandardText text; if (fLastButtonChanged == 0) { text = TStandardText("No mouse changes received yet."); } else { static TUniversalNumberFormatter formatter; TStandardText buttonNumber; formatter.Format(TFormattableNumber(fLastButtonChanged), buttonNumber); TStandardText change = TStandardText(fLastButtonChangeWasDown ? " Down" : " Up"); TStandardText xLoc; formatter.Format(TFormattableNumber(fLastButtonChangeGlobalCoordinates.fX), xLoc); TStandardText yLoc; formatter.Format(TFormattableNumber(fLastButtonChangeGlobalCoordinates.fY), yLoc); text = TStandardText("Button ") + buttonNumber + change + TStandardText (" at ") + xLoc + TStandardText("@") + yLoc; } TTextDisplay display(text); TGRect textBounds = area.GetBounds(); textBounds.Inset(TGPoint(5, 5)); display.SetBoundaryRectangle(textBounds); display.SetPointSize(TFontPointSizeStyle(18)); display.Draw(port); } // Remember the information, and invalidate so the new info is displayed. bool TMouseInputView::MouseButtonDown(TMouseDownEvent& mouseDownEvent, short) { fLastButtonChanged = mouseDownEvent.GetButtonNumber(); fLastButtonChangeWasDown = true; fLastButtonChangeGlobalCoordinates = mouseDownEvent.GetEventPosition(); Invalidate(); return true; } bool TMouseInputView::MouseButtonUp(TMouseUpEvent& mouseUpEvent, short) { fLastButtonChanged = mouseUpEvent.GetButtonNumber(); fLastButtonChangeWasDown = false; fLastButtonChangeGlobalCoordinates = mouseUpEvent.GetEventPosition(); Invalidate(); return true; } void TMouseInputView::HandleAllocatedAreaChanged(const TGArea&) { InvalidateAll(); }