// @(#)root/graf2d:$Id$ // Author: Timur Pocheptsov 16/02/2012 /************************************************************************* * Copyright (C) 1995-2012, Rene Brun and Fons Rademakers. * * All rights reserved. * * * * For the licensing terms see $ROOTSYS/LICENSE. * * For the list of contributors see $ROOTSYS/README/CREDITS. * *************************************************************************/ #ifndef ROOT_X11Events #define ROOT_X11Events #include #ifndef ROOT_GuiTypes #include "GuiTypes.h" #endif ////////////////////////////////////////////////////////////////////////// // // // EventTranslator class translates Cocoa events to 'ROOT's X11' events.// // In 90% cases there is no direct mapping from Cocoa event to // // X11 event: Cocoa events are more simple (from programmer's POV). // // EventTranslator tries to emulate X11 behavior. // // // ////////////////////////////////////////////////////////////////////////// class TGCocoa; @protocol X11Window; @class QuartzWindow; @class NSEvent; @class NSView; namespace ROOT { namespace MacOSX { namespace X11 {//X11 emulation for Cocoa. enum PointerGrab { kPGNoGrab, kPGImplicitGrab, kPGActiveGrab, kPGPassiveGrab }; typedef std::deque EventQueue_t; class EventTranslator { friend class ::TGCocoa; public: EventTranslator(); void GenerateConfigureNotifyEvent(NSView *view, const NSRect &newFrame); void GenerateDestroyNotify(unsigned winID); void GenerateExposeEvent(NSView *view, const NSRect &exposedRect); void GenerateCrossingEvent(NSEvent *theEvent); void GeneratePointerMotionEvent(NSEvent *theEvent); //TODO: instead of passing EMouseButton, use info from NSEvent??? void GenerateButtonPressEvent(NSView *eventView, NSEvent *theEvent, EMouseButton btn); void GenerateButtonReleaseEvent(NSView *eventView, NSEvent *theEvent, EMouseButton btn); void GenerateKeyPressEvent(NSView *eventView, NSEvent *theEvent); void GenerateKeyReleaseEvent(NSView *eventView, NSEvent *theEvent); void GenerateFocusChangeEvent(NSView *eventView); void SetPointerGrab(NSView *grabView, unsigned eventMask, bool ownerEvents); void CancelPointerGrab(); void SetInputFocus(NSView *focusView); unsigned GetInputFocus()const; //Window winID was either deleted or unmapped. //If it's a grab view or a parent of a grab view - cancel grab. //If it's a "view under pointer" - reset view under pointer. //If it's a focus view, cancel focus. void CheckUnmappedView(Window_t winID); bool HasPointerGrab()const; private: //Used both by grab and non-grab case. void GenerateCrossingEventNoGrab(NSEvent *theEvent); void GenerateCrossingEventActiveGrab(NSEvent *theEvent); void GeneratePointerMotionEventNoGrab(NSEvent *theEvent); void GeneratePointerMotionEventActiveGrab(NSEvent *theEvent); void GenerateButtonPressEventNoGrab(NSView *view, NSEvent *theEvent, EMouseButton btn); void GenerateButtonPressEventActiveGrab(NSView *view, NSEvent *theEvent, EMouseButton btn); void GenerateButtonReleaseEventNoGrab(NSView *eventView, NSEvent *theEvent, EMouseButton btn); void GenerateButtonReleaseEventActiveGrab(NSView *eventView, NSEvent *theEvent, EMouseButton btn); void GenerateKeyPressEventNoGrab(NSEvent *theEvent); void GenerateKeyReleaseEventNoGrab(NSEvent *theEvent); void GenerateKeyEventActiveGrab(NSEvent *theEvent);//Both press/release events. void GenerateKeyEventForView(NSView *view, NSEvent *theEvent);//Both press/release events. void FindButtonGrab(NSView *fromView, NSEvent *theEvent, EMouseButton btn); void FindKeyGrabView(NSView *fromView, NSEvent *theEvent); NSView *fViewUnderPointer; PointerGrab fPointerGrabType; unsigned fGrabEventMask; bool fOwnerEvents; NSView *fButtonGrabView; NSView *fKeyGrabView; NSView *fFocusView; EMouseButton fImplicitGrabButton; EventQueue_t fEventQueue; }; void MapUnicharToKeySym(unichar key, char *buf, Int_t len, UInt_t &rootKeySym); Int_t MapKeySymToKeyCode(Int_t keySym); NSUInteger GetCocoaKeyModifiersFromROOTKeyModifiers(UInt_t rootKeyModifiers); UInt_t GetModifiers();//Mouse buttons + keyboard modifiers. }//X11 }//MacOSX }//ROOT #endif