// $Revision: 1.4 $ // Copyright (c) 1994-1995 Taligent, Inc. All rights reserved. #ifndef TaligentSamples_KEYINPUTVIEW #include "KeyInputView.h" #endif #ifndef Taligent_GRAFPORT #include #endif #ifndef Taligent_NUMBERFORMAT #include #endif #ifndef Taligent_RGBCOLOR #include #endif #ifndef Taligent_TEXTDISPLAY #include #endif #ifndef Taligent_TYPINGCONFIGURATION #include #endif MCollectibleDefinitionsMacro(TKeyInputView, kOriginalVersion); TKeyInputView::TKeyInputView() : TContentView(TGPoint(200, 50)), MKeyEventHandler(), fLastKey(TVirtualKeyCode::kUndefinedVirtualKey), fLastModifiers() { } TKeyInputView::TKeyInputView(const TGPoint& size, const TGPoint& location) : TContentView(size, location), MKeyEventHandler(), fLastKey(TVirtualKeyCode::kUndefinedVirtualKey), fLastModifiers() { } TKeyInputView::~TKeyInputView() { } void TKeyInputView::HandleAfterConnectionToViewRoot() { RegisterSimpleTarget(*InternalGetEventReceiver()); } void TKeyInputView::HandleBeforeDisconnectionFromViewRoot() { DeregisterSimpleTarget(*InternalGetEventReceiver()); } void TKeyInputView::DrawContents(TGrafPort& port) const { static const TFillAndFrameBundle bundle(TRGBColor(1.0, 0.7, 0.7), TRGBColor(0,0,0), 2.0, TPen::kInsetFrame); TGArea area; GetBounds(area); port.Draw(area, bundle); static TTypingConfigurationHandle typingConfiguration; TStandardText text; typingConfiguration.MapKeyToText(fLastKey, fLastModifiers, text); TTextDisplay display(text); TGRect textBounds = area.GetBounds(); textBounds.Inset(TGPoint(5, 5)); display.SetBoundaryRectangle(textBounds); display.SetPointSize(TFontPointSizeStyle(18)); display.Draw(port); } bool TKeyInputView::KeyDown(TKeyDownEvent& keyDownEvent) { fLastKey = keyDownEvent.GetVirtualKey(); fLastModifiers = keyDownEvent.GetModifierKeys(); Invalidate(); return true; } void TKeyInputView::HandleAllocatedAreaChanged(const TGArea&) { InvalidateAll(); }