Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Examples  

gadget::EventWindowOSX Class Reference

OSX event window class. More...

#include <EventWindowOSX.h>

Inheritance diagram for gadget::EventWindowOSX:

Inheritance graph
[legend]
Collaboration diagram for gadget::EventWindowOSX:

Collaboration graph
[legend]
List of all members.

Public Types

enum  lockState { Unlocked, Lock_LockKey, Lock_KeyDown }
 Enum to keep track of current lock state for state machine. More...


Public Methods

 EventWindowOSX ()
virtual ~EventWindowOSX ()
virtual bool config (jccl::ConfigElementPtr e)
 Constructor. More...

bool sample ()
 Do nothing the events are handled by call backs from the Carbon event manager. More...

void updateData ()
 Update the data. More...

int isKeyPressed (int Key)
 Returns the number of times the key was pressed during the last frame, so you can put this in an if to check if was pressed at all, or if you are doing processing based on this catch the actual number.. More...

pascal OSStatus gotKeyEvent (EventHandlerCallRef nextHandler, EventRef theEvent, void *userData)
 Called by callback function. More...

void operator delete (void *p)
 Invokes the global scope delete operator. More...

Pure virtuals required by gadget::Input.
bool startSampling ()
 Start a device sampling. More...

bool stopSampling ()
 StopSampling. More...


Static Public Methods

std::string getElementType ()
 Returns the string rep of the element type used to config this device. More...


Protected Methods

void destroy ()
 Deletes this object. More...

int attachEvents (WindowRef aWindow)

Protected Attributes

bool mShared
 True if the window is shared between multiple processes. More...

int m_screen
int m_x
int m_y
 screen id, x_origin, y_origin. More...

unsigned int m_width
unsigned int m_height
float m_mouse_sensitivity
bool mAmSampling
WindowRef mWindow
 The carbon window. More...

Event window state holders
int m_keys [gadget::LAST_KEY]
 (0,*): The num key presses during an UpdateData (ie. More...

int m_realkeys [gadget::LAST_KEY]
 (0,1): The real keyboard state, all events processed (ie. More...

vpr::Mutex mKeysLock
 Must hold this lock when accessing m_keys OR mHandleEventsHasBeenCalled. More...

bool mHandleEventsHasBeenCalled
 This flag keeps track of wether or not HandleEvents has been called since the last updateData. More...

lockState mLockState
 The current state of locking. More...

int mLockStoredKey
 The key that was pressed down. More...

int mLockToggleKey
 The key that toggles the locking. More...


Detailed Description

OSX event window class.

This device is a source of keyboard events. The device should not be used directly, it should be referenced through proxies.

Change to reflect the removal of the mouse lock on every button press.

Mouse Locking:
This device receives input from the carbon event loop. As such, the window must have focus to generate events. In order to help users keep the window in focus, there are two cases where the driver will "lock" the mouse to the window, thus preventing loss of focus.
CASE 1: The user holds down any key. (ie. a,b, ctrl, shift, etc)
CASE 2: The user can toggle locking using a special "locking" key defined in the configuration element.

See also:
EventWindow, EventWindowProxy

Definition at line 68 of file EventWindowOSX.h.


Member Enumeration Documentation

enum gadget::EventWindowOSX::lockState
 

Enum to keep track of current lock state for state machine.

Enumeration values:
Unlocked  The mouse is free.
Lock_LockKey  The mouse is locked due to lock toggle key press.
Lock_KeyDown  The mouse is locked due to a key being held down.

Definition at line 72 of file EventWindowOSX.h.

00073    {
00074       Unlocked,     
00075       Lock_LockKey, 
00076       Lock_KeyDown  
00077    };


Constructor & Destructor Documentation

gadget::EventWindowOSX::EventWindowOSX  
 

Definition at line 56 of file EventWindowOSX.cpp.

00057    : InputMixer<Input, EventWindow>()
00058    , mHandleEventsHasBeenCalled(false) // Initialize to not being called yet
00059    , mLockState(Unlocked)     // Initialize to unlocked.
00060    , mAmSampling(false)       // Sampling has not been called yet
00061 {
00062    //mExitFlag = false;
00063    //mWeOwnTheWindow = true;
00064    //mShared = false;                         // False by default
00065 }

virtual gadget::EventWindowOSX::~EventWindowOSX   [inline, virtual]
 

Definition at line 81 of file EventWindowOSX.h.

References stopSampling.

00082    {
00083       stopSampling();
00084    }


Member Function Documentation

bool gadget::EventWindowOSX::config jccl::ConfigElementPtr    e [virtual]
 

Constructor.

Reimplemented from gadget::EventWindow.

Definition at line 73 of file EventWindowOSX.cpp.

References gadgetDBG_INPUT_MGR, Lock_LockKey, m_height, m_keys, m_mouse_sensitivity, m_realkeys, m_width, m_x, m_y, gadget::EventWindow::mCurKeys, mLockState, and mLockToggleKey.

00074 {
00075    if ( ! (Input::config(e) && EventWindow::config(e)) )
00076    {
00077       return false;
00078    }
00079 
00080    for ( int i = 0; i < gadget::LAST_KEY; ++i )
00081    {
00082       m_realkeys[i] = m_keys[i] = mCurKeys[i];
00083    }
00084 
00085    // Get size and position
00086    m_width = e->getProperty<int>("width");
00087    m_height = e->getProperty<int>("height");
00088 
00089    if ( m_width == 0 )
00090    {
00091       m_width = 400;
00092    }
00093 
00094    if ( m_height == 0 )
00095    {
00096       m_height = 400;
00097    }
00098 
00099    m_x = e->getProperty<int>("origin", 0);
00100    m_y = e->getProperty<int>("origin", 1);
00101 
00102    // Get the lock information
00103    mLockToggleKey = e->getProperty<int>("lock_key");
00104    bool start_locked = e->getProperty<bool>("start_locked");
00105    if ( start_locked )
00106    {
00107       mLockState = Lock_LockKey;      // Initialize to the locked state
00108    }
00109 
00110    m_mouse_sensitivity = e->getProperty<float>("mouse_sensitivity");
00111    if ( 0.0f == m_mouse_sensitivity )
00112    {
00113       m_mouse_sensitivity = 0.5;
00114    }
00115 
00116    vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_STATE_LVL)
00117       << "Mouse Sensititivty: " << m_mouse_sensitivity << std::endl
00118       << vprDEBUG_FLUSH;
00119 
00120    return true;
00121 }

bool gadget::EventWindowOSX::startSampling   [virtual]
 

Start a device sampling.

Start the device sampling, normally this will spawn a thread which will just repeatedly call Sample(). This function should return true when it sucessfully starts, false otherwise.

Implements gadget::Input.

Definition at line 123 of file EventWindowOSX.cpp.

References gadgetDBG_INPUT_MGR, and mAmSampling.

00124 {
00125    if ( mAmSampling == true )
00126    {
00127       vprDEBUG(vprDBG_ERROR,vprDBG_CRITICAL_LVL)
00128          << clrOutNORM(clrRED,"ERROR:")
00129          << "gadget::EventWindowOSX: startSampling called, when already sampling.\n"
00130          << vprDEBUG_FLUSH;
00131       vprASSERT(false);
00132    }
00133 
00134    vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
00135       << "Start sampling in gadget::EventWindowOSX\n" << vprDEBUG_FLUSH;
00136    openTheWindow();
00137    mAmSampling = true;
00138 
00139    return 1;
00140 }

bool gadget::EventWindowOSX::stopSampling   [virtual]
 

StopSampling.

Reverse the effects of StartSampling().

Implements gadget::Input.

Definition at line 206 of file EventWindowOSX.cpp.

Referenced by ~EventWindowOSX.

00207 {
00208    // Add code to remove window
00209    // Deleate the UPP handle
00210    //mExitFlag = true;
00211    return 1;
00212 }

bool gadget::EventWindowOSX::sample   [inline, virtual]
 

Do nothing the events are handled by call backs from the Carbon event manager.

Implements gadget::Input.

Definition at line 98 of file EventWindowOSX.h.

00099    {
00100       return 1;
00101    }

void gadget::EventWindowOSX::updateData   [virtual]
 

Update the data.

After this function is called subsequent calls to GetData(d) will return the most recent data at the time of THIS function call. Data is guaranteed to be valid and static until the next call to UpdateData.

Implements gadget::Input.

Definition at line 160 of file EventWindowOSX.cpp.

References m_keys, m_mouse_sensitivity, m_realkeys, gadget::EventWindow::mCurKeys, mHandleEventsHasBeenCalled, mKeysLock, and gadget::EventWindow::updateEventQueue.

00161 {
00162    vpr::Guard<vpr::Mutex> guard(mKeysLock);      // Lock access to the m_keys array
00163    //if ( mHandleEventsHasBeenCalled )            // If we haven't updated anything, then don't swap stuff
00164    {
00165       mHandleEventsHasBeenCalled = false;
00166 
00167       // Scale mouse values based on sensitivity
00168       m_keys[gadget::MOUSE_POSX] = int(float(m_keys[gadget::MOUSE_POSX]) * m_mouse_sensitivity);
00169       m_keys[gadget::MOUSE_NEGX] = int(float(m_keys[gadget::MOUSE_NEGX]) * m_mouse_sensitivity);
00170       m_keys[gadget::MOUSE_POSY] = int(float(m_keys[gadget::MOUSE_POSY]) * m_mouse_sensitivity);
00171       m_keys[gadget::MOUSE_NEGY] = int(float(m_keys[gadget::MOUSE_NEGY]) * m_mouse_sensitivity);
00172 
00173       /*
00174       vprDEBUG(vprDBG_ALL, vprDBG_CRITICAL_LVL)
00175          << "gadget::EventWindowOSX::updateData:" << mInstName << " -- "
00176          << "mouse_keys: px:" << m_keys[gadget::MOUSE_POSX]
00177          << " nx:" << m_keys[gadget::MOUSE_NEGX]
00178          << " py:" << m_keys[gadget::MOUSE_POSY]
00179          << " ny:" << m_keys[gadget::MOUSE_NEGY]
00180          << std::endl << vprDEBUG_FLUSH;
00181       */
00182 
00183       // Copy over values
00184       for ( unsigned int i = 0; i < gadget::LAST_KEY; ++i )
00185       {
00186          mCurKeys[i] = m_keys[i];
00187       }
00188 
00189       // Re-initialize the m_keys based on current key state in realKeys
00190       // Set the initial state of the m_key key counts based on the current state of the system
00191       for ( unsigned int j = 0; j < gadget::LAST_KEY; ++j )
00192       {
00193          m_keys[j] = m_realkeys[j];
00194       }
00195 
00196       //clear the mouse movement
00197       m_keys[gadget::MOUSE_POSX] = 0;
00198       m_keys[gadget::MOUSE_NEGX] = 0;
00199       m_keys[gadget::MOUSE_POSY] = 0;
00200       m_keys[gadget::MOUSE_NEGY] = 0;
00201    }
00202 
00203    updateEventQueue();
00204 }

std::string gadget::EventWindowOSX::getElementType   [static]
 

Returns the string rep of the element type used to config this device.

This string is used by the device factory to look up device drivers based up the type of element it is trying to load.

Reimplemented from gadget::Input.

Definition at line 67 of file EventWindowOSX.cpp.

00068 {
00069    return "event_window";
00070 }

int gadget::EventWindowOSX::isKeyPressed int    Key [inline]
 

Returns the number of times the key was pressed during the last frame, so you can put this in an if to check if was pressed at all, or if you are doing processing based on this catch the actual number..

Definition at line 112 of file EventWindowOSX.h.

References gadget::EventWindow::mCurKeys.

00113    {
00114       return mCurKeys[Key];
00115    }

pascal OSStatus gadget::EventWindowOSX::gotKeyEvent EventHandlerCallRef    nextHandler,
EventRef    theEvent,
void *    userData
 

Called by callback function.

Processes the event.

Definition at line 528 of file EventWindowOSX.cpp.

References gadgetDBG_INPUT_MGR, Lock_KeyDown, Lock_LockKey, m_keys, m_realkeys, mHandleEventsHasBeenCalled, mKeysLock, mLockState, mLockStoredKey, mLockToggleKey, and Unlocked.

00530 {
00531    boost::ignore_unused_variable_warning(userData);
00532 
00533    //The type of event
00534    UInt32 event_class, event_kind;
00535    gadget::Keys vj_key; // The key in vj space
00536 
00537    //The modifier keys
00538    UInt32 modKeys;
00539 
00540    //The mouse button
00541    UInt16 myButton;
00542 
00543    //Status from system calls
00544    OSStatus result;
00545    //Status from core graphics calls
00546    //CGEventErr err;
00547 
00548    Point mouse_pos;
00549 
00550    vpr::Guard<vpr::Mutex> guard(mKeysLock);
00551    // Lock access to the m_keys array for the duration of this function
00552 
00553    mHandleEventsHasBeenCalled = true;
00554 
00555    event_class = GetEventClass(theEvent);
00556    event_kind  = GetEventKind(theEvent);
00557 
00558    if ( ( event_class == kEventClassKeyboard && event_kind == kEventRawKeyDown) ||
00559         ( event_class == kEventClassKeyboard && event_kind == kEventRawKeyRepeat) )
00560    {
00561       UInt32 keyInt;
00562       GetEventParameter(theEvent, kEventParamKeyCode, typeUInt32, NULL,
00563                         sizeof(typeUInt32), NULL, &keyInt);
00564 
00565       vj_key = osxKeyToKey(keyInt);
00566       m_realkeys[vj_key] = 1;
00567       m_keys[vj_key] += 1;
00568 
00569       vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_HVERB_LVL)
00570          << "vj_key press value: " << (unsigned int) vj_key
00571          << std::endl << vprDEBUG_FLUSH;
00572       addKeyEvent(vj_key, gadget::KeyPressEvent, theEvent);
00573 
00574       // -- Update lock state -- //
00575       // Any[key == ESC]/unlock(ifneeded) -> Unlocked
00576       // Unlocked[key!=lockKey]/lockMouse -> lock_keydown
00577       // Unlocked[key==lockKey]/lockMouse -> lock_keylock
00578       // lock_keydown[key==lockKey] -> lock_keylock
00579       // lock_keylock[key==lockKey] -> Unlocked
00580       if ( vj_key == gadget::KEY_ESC )       // Check for Escape from bad state
00581       {
00582          vprDEBUG(gadgetDBG_INPUT_MGR,vprDBG_STATE_LVL)
00583             << "gadget::EventWindowOSX: Trying to ESCAPE from current state.\n"
00584             << vprDEBUG_FLUSH;
00585 
00586          if ( mLockState != Unlocked )
00587          {
00588             vprDEBUG_NEXT(gadgetDBG_INPUT_MGR,vprDBG_STATE_LVL)
00589                << "gadget::EventWindowOSX: STATE switch: <ESCAPE> --> Unlocked\n"
00590                << vprDEBUG_FLUSH;
00591             mLockState = Unlocked;
00592             unlockMouse();
00593          }
00594          else
00595          {
00596             vprDEBUG_NEXT(gadgetDBG_INPUT_MGR,vprDBG_STATE_LVL)
00597             << "gadget::EventWindowOSX: Already unlocked.  Cannot ESCAPE."
00598                << vprDEBUG_FLUSH;
00599          }
00600       }
00601       else if ( mLockState == Unlocked )
00602       {
00603          if ( vj_key != mLockToggleKey )
00604          {
00605             mLockState = Lock_KeyDown;       // Switch state
00606             mLockStoredKey = vj_key;         // Store the VJ key that is down
00607             vprDEBUG(gadgetDBG_INPUT_MGR,vprDBG_STATE_LVL)
00608                << "gadget::EventWindowOSX: STATE switch: Unlocked --> Lock_KeyDown\n"
00609                << vprDEBUG_FLUSH;
00610             lockMouse();
00611          }
00612          else if ( vj_key == mLockToggleKey )
00613          {
00614             mLockState = Lock_LockKey;
00615             vprDEBUG(gadgetDBG_INPUT_MGR,vprDBG_STATE_LVL)
00616                << "gadget::EventWindowOSX: STATE switch: Unlocked --> Lock_LockKey\n"
00617                << vprDEBUG_FLUSH;
00618             lockMouse();
00619          }
00620       }
00621       else if ( (mLockState == Lock_KeyDown) && (vj_key == mLockToggleKey) )
00622       // Just switch the current locking state
00623       {
00624          mLockState = Lock_LockKey;
00625          vprDEBUG(gadgetDBG_INPUT_MGR,vprDBG_STATE_LVL)
00626             << "gadget::EventWindowOSX: STATE switch: Lock_KeyDown --> Lock_LockKey\n"
00627             << vprDEBUG_FLUSH;
00628       }
00629       else if ( (mLockState == Lock_LockKey) && (vj_key == mLockToggleKey) )
00630       {
00631          mLockState = Unlocked;
00632          vprDEBUG(gadgetDBG_INPUT_MGR,vprDBG_STATE_LVL)
00633             << "gadget::EventWindowOSX: STATE switch: Lock_LockKey --> Unlocked\n"
00634             << vprDEBUG_FLUSH;
00635          unlockMouse();
00636       }
00637       /*
00638       vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_HVERB_LVL)
00639           << "KeyPress:  " << std::hex << key
00640           << " state:" << ((XKeyEvent*)&event)->state
00641           << " ==> " << xKeyToKey(key) << std::endl << vprDEBUG_FLUSH;
00642       break;
00643       */
00644    }
00645 
00646    if ( event_class == kEventClassKeyboard && event_kind == kEventRawKeyUp )
00647    {
00648       UInt32 keyInt;
00649       GetEventParameter(theEvent, kEventParamKeyCode, typeUInt32, NULL,
00650                         sizeof(typeUInt32), NULL, &keyInt);
00651 
00652       vj_key = osxKeyToKey(keyInt);
00653       m_realkeys[vj_key] = 0;
00654       addKeyEvent(vj_key, gadget::KeyReleaseEvent, theEvent);
00655 
00656       //std::cout << "Got Up: " << vj_key << std::endl;
00657 
00658       // -- Update lock state -- //
00659       // lock_keyDown[key==storedKey]/unlockMouse -> unlocked
00660       if ( (mLockState == Lock_KeyDown) && (vj_key == mLockStoredKey) )
00661       {
00662          mLockState = Unlocked;
00663          vprDEBUG(gadgetDBG_INPUT_MGR,vprDBG_STATE_LVL)
00664             << "gadget::EventWindowOSX: STATE switch: Lock_KeyDown --> Unlocked\n"
00665             << vprDEBUG_FLUSH;
00666          unlockMouse();
00667       }
00668 
00669       //What does this do?
00670       /*
00671       vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_HVERB_LVL)
00672           << "KeyRelease:" << std::hex << key
00673           << " state:" << ((XKeyEvent*)&event)->state
00674           << " ==> " << xKeyToKey(key) << std::endl << vprDEBUG_FLUSH;
00675       */
00676 
00677    }
00678 
00679    // XXX: This does not currently add an event to the queue.  My
00680    // assumption is that the key press/release event handling above
00681    // will deal with that since modifiers are just keys.
00682    if ( event_class == kEventClassKeyboard && event_kind == kEventRawKeyModifiersChanged )
00683    {
00684       GetEventParameter(theEvent, kEventParamKeyModifiers, typeUInt32, NULL,
00685                         sizeof(typeUInt32), NULL, &modKeys);
00686 
00687       /* Juggler does not care about caps and command
00688       if (modKeys & alphaLock)
00689       {
00690           cout << "Caps ";
00691       }
00692       if (modKeys & cmdKey)
00693       {
00694           cout << "CMD ";
00695       }
00696       */
00697       if ( modKeys & shiftKey )
00698       {
00699          m_realkeys[gadget::KEY_SHIFT] = 1;
00700          m_keys[gadget::KEY_SHIFT] += 1;
00701          // The m_key value will not reflect the number of times the mod key
00702          // was pressed but rather how many times it was pressed when
00703          // any mod key changes state
00704       }
00705       else
00706       {
00707          m_realkeys[gadget::KEY_SHIFT] = 0;
00708       }
00709 
00710       if ( modKeys & optionKey )
00711       {
00712          m_realkeys[gadget::KEY_ALT] = 1;
00713          m_keys[gadget::KEY_ALT] += 1;
00714       }
00715       else
00716       {
00717          m_realkeys[gadget::KEY_ALT] = 0;
00718       }
00719 
00720       if ( modKeys & controlKey )
00721       {
00722 
00723          m_realkeys[gadget::KEY_CTRL] = 1;
00724          m_keys[gadget::KEY_CTRL] += 1;
00725       }
00726       else
00727       {
00728          m_realkeys[gadget::KEY_CTRL] = 0;
00729       }
00730 
00731       // If any mod keys are pressed lock the mouse
00732       if ( (modKeys & shiftKey) || (modKeys & controlKey) ||
00733            (modKeys & optionKey) || (modKeys & shiftKey) )
00734       {
00735          if ( mLockState == Unlocked )
00736          {
00737             mLockState = Lock_KeyDown;       // Switch state
00738             vprDEBUG(gadgetDBG_INPUT_MGR,vprDBG_STATE_LVL)
00739                << "gadget::EventWindowOSX: STATE switch: Unlocked --> Lock_KeyDown\n"
00740                << vprDEBUG_FLUSH;
00741             lockMouse();
00742          }
00743       }
00744       //Unlock mouse if lock key is not down
00745       else
00746       {
00747          if ( mLockState != Lock_LockKey )
00748          {
00749             mLockState = Unlocked;
00750             vprDEBUG(gadgetDBG_INPUT_MGR,vprDBG_STATE_LVL)
00751                << "gadget::EventWindowOSX: STATE switch: Lock_KeyDown --> Unlocked\n"
00752                << vprDEBUG_FLUSH;
00753             unlockMouse();
00754          }
00755       }
00756    }
00757 
00758    if ( event_class == kEventClassMouse && event_kind == kEventMouseDown )
00759    {
00760       //Allow the base handler to take care of most mouse events
00761       result = CallNextEventHandler(nextHandler, theEvent);
00762 
00763       GetEventParameter(theEvent, kEventParamMouseButton, typeMouseButton,
00764                         NULL, sizeof(typeMouseButton), NULL, &myButton);
00765 
00766       // Note that the button ordering in Carbon is:
00767       // left (Primary), right (Secondary), and middle (Tertiary)
00768       switch ( myButton )
00769       {
00770          case kEventMouseButtonPrimary :
00771             m_realkeys[gadget::MBUTTON1] = m_keys[gadget::MBUTTON1] = 1;
00772             addMouseButtonEvent(gadget::MBUTTON1, theEvent,
00773                                 gadget::MouseButtonPressEvent);
00774             break;
00775          case kEventMouseButtonSecondary:
00776             m_realkeys[gadget::MBUTTON2] = m_keys[gadget::MBUTTON2] = 1;
00777             addMouseButtonEvent(gadget::MBUTTON3, theEvent,
00778                                 gadget::MouseButtonPressEvent);
00779             break;
00780          case kEventMouseButtonTertiary:
00781             m_realkeys[gadget::MBUTTON3] = m_keys[gadget::MBUTTON3] = 1;
00782             addMouseButtonEvent(gadget::MBUTTON2, theEvent,
00783                                 gadget::MouseButtonPressEvent);
00784             break;
00785       }
00786       //std::cout << "mouse down" << std::endl;
00787    }
00788 
00789    if ( event_class == kEventClassMouse && event_kind == kEventMouseUp )
00790    {
00791       //std::cout << "mouse up" << std::endl;
00792       result = CallNextEventHandler(nextHandler, theEvent);
00793 
00794       GetEventParameter(theEvent, kEventParamMouseButton, typeMouseButton,
00795                         NULL, sizeof(typeMouseButton), NULL, &myButton);
00796 
00797       switch ( myButton )
00798       {
00799          case kEventMouseButtonPrimary :
00800             m_realkeys[gadget::MBUTTON1] = m_keys[gadget::MBUTTON1] = 0;
00801             addMouseButtonEvent(gadget::MBUTTON1, theEvent,
00802                                 gadget::MouseButtonReleaseEvent);
00803             break;
00804          case kEventMouseButtonSecondary:
00805             m_realkeys[gadget::MBUTTON2] = m_keys[gadget::MBUTTON2] = 0;
00806             addMouseButtonEvent(gadget::MBUTTON2, theEvent,
00807                                 gadget::MouseButtonReleaseEvent);
00808             break;
00809          case kEventMouseButtonTertiary:
00810             m_realkeys[gadget::MBUTTON3] = m_keys[gadget::MBUTTON3] = 0;
00811             addMouseButtonEvent(gadget::MBUTTON3, theEvent,
00812                                 gadget::MouseButtonReleaseEvent);
00813             break;
00814       }
00815    }
00816 
00817    if ( event_class == kEventClassMouse &&
00818         (event_kind == kEventMouseMoved || event_kind == kEventMouseDragged) )
00819    {
00820 
00821       result = CallNextEventHandler(nextHandler, theEvent);
00822 
00823       //std::cout << "mouse moved" << std::endl;
00824 
00825       // Note even though 'kEventParamMouseDelta' is a carbon call
00826       // it does not work on OS 9
00827       GetEventParameter(theEvent, kEventParamMouseDelta, typeQDPoint,
00828                         NULL, sizeof(typeQDPoint), NULL, &mouse_pos);
00829 
00830       // Update m_keys based on key pressed and store in the key array
00831       if ( mouse_pos.h > 0 )
00832       {
00833          m_keys[gadget::MOUSE_POSX] = m_keys[gadget::MOUSE_POSX] + mouse_pos.h;
00834          // Positive movement in the x direction.
00835       }
00836       else
00837       {
00838          m_keys[gadget::MOUSE_NEGX] = m_keys[gadget::MOUSE_NEGX] - mouse_pos.h;
00839          // Negative movement in the x direction.
00840       }
00841 
00842       if ( mouse_pos.v > 0 )
00843       {
00844          m_keys[gadget::MOUSE_POSY] = m_keys[gadget::MOUSE_POSY] + mouse_pos.v;
00845          // Positive movement in the y direction.
00846       }
00847       else
00848       {
00849          m_keys[gadget::MOUSE_NEGY] = m_keys[gadget::MOUSE_NEGY] - mouse_pos.v;
00850          // Negative movement in the y direction.
00851       }
00852    }
00853 
00854    return noErr;                                // Report success
00855 }

void gadget::EventWindowOSX::operator delete void *    p [inline]
 

Invokes the global scope delete operator.

This is required for proper releasing of memory in DLLs on Win32.

Definition at line 128 of file EventWindowOSX.h.

00129    {
00130       ::operator delete(p);
00131    }

void gadget::EventWindowOSX::destroy   [inline, protected, virtual]
 

Deletes this object.

This is an implementation of the pure virtual gadget::Input::destroy() method.

Implements gadget::Input.

Definition at line 138 of file EventWindowOSX.h.

00139    {
00140       delete this;
00141    }

int gadget::EventWindowOSX::attachEvents WindowRef    aWindow [protected]
 

Definition at line 420 of file EventWindowOSX.cpp.

References gadget::keyboardHandlerOSX.

00421 {
00422    EventTypeSpec   event_types[8];  //Remember to pass the size when registering ther handler
00423    EventHandlerUPP handler_upp;
00424 
00425    // Set up the events to listen for
00426    event_types[0].eventClass = kEventClassKeyboard;
00427    event_types[0].eventKind  = kEventRawKeyDown;
00428 
00429    event_types[1].eventClass = kEventClassKeyboard;
00430    event_types[1].eventKind  = kEventRawKeyRepeat;
00431 
00432    event_types[2].eventClass = kEventClassKeyboard;
00433    event_types[2].eventKind  = kEventRawKeyUp;
00434 
00435    event_types[3].eventClass = kEventClassKeyboard;
00436    event_types[3].eventKind  = kEventRawKeyModifiersChanged;
00437 
00438    event_types[4].eventClass = kEventClassMouse;
00439    event_types[4].eventKind  = kEventMouseDown;
00440 
00441    event_types[5].eventClass = kEventClassMouse;
00442    event_types[5].eventKind  = kEventMouseUp;
00443 
00444    event_types[6].eventClass = kEventClassMouse;
00445    event_types[6].eventKind  = kEventMouseMoved;
00446 
00447    event_types[7].eventClass = kEventClassMouse;
00448    event_types[7].eventKind  = kEventMouseDragged;
00449 
00450    handler_upp = NewEventHandlerUPP(keyboardHandlerOSX);
00451 
00452    InstallWindowEventHandler(aWindow, handler_upp,  // Install handler
00453                              8, event_types, this, NULL);
00454 
00455    return 1;
00456 }


Member Data Documentation

bool gadget::EventWindowOSX::mShared [protected]
 

True if the window is shared between multiple processes.

Definition at line 222 of file EventWindowOSX.h.

int gadget::EventWindowOSX::m_screen [protected]
 

Definition at line 229 of file EventWindowOSX.h.

int gadget::EventWindowOSX::m_x [protected]
 

Definition at line 229 of file EventWindowOSX.h.

Referenced by config.

int gadget::EventWindowOSX::m_y [protected]
 

screen id, x_origin, y_origin.

Definition at line 229 of file EventWindowOSX.h.

Referenced by config.

unsigned int gadget::EventWindowOSX::m_width [protected]
 

Definition at line 230 of file EventWindowOSX.h.

Referenced by config.

unsigned int gadget::EventWindowOSX::m_height [protected]
 

Definition at line 230 of file EventWindowOSX.h.

Referenced by config.

int gadget::EventWindowOSX::m_keys[gadget::LAST_KEY] [protected]
 

(0,*): The num key presses during an UpdateData (ie.

How many keypress events).

Definition at line 236 of file EventWindowOSX.h.

Referenced by config, gotKeyEvent, and updateData.

int gadget::EventWindowOSX::m_realkeys[gadget::LAST_KEY] [protected]
 

(0,1): The real keyboard state, all events processed (ie.

what is the key now).

Definition at line 237 of file EventWindowOSX.h.

Referenced by config, gotKeyEvent, and updateData.

vpr::Mutex gadget::EventWindowOSX::mKeysLock [protected]
 

Must hold this lock when accessing m_keys OR mHandleEventsHasBeenCalled.

Definition at line 238 of file EventWindowOSX.h.

Referenced by gotKeyEvent, and updateData.

bool gadget::EventWindowOSX::mHandleEventsHasBeenCalled [protected]
 

This flag keeps track of wether or not HandleEvents has been called since the last updateData.

It is used by updateData to make sure we don't get a "blank" update where no keys are pressed.

Definition at line 239 of file EventWindowOSX.h.

Referenced by gotKeyEvent, and updateData.

lockState gadget::EventWindowOSX::mLockState [protected]
 

The current state of locking.

Definition at line 243 of file EventWindowOSX.h.

Referenced by config, and gotKeyEvent.

int gadget::EventWindowOSX::mLockStoredKey [protected]
 

The key that was pressed down.

Definition at line 244 of file EventWindowOSX.h.

Referenced by gotKeyEvent.

int gadget::EventWindowOSX::mLockToggleKey [protected]
 

The key that toggles the locking.

Definition at line 245 of file EventWindowOSX.h.

Referenced by config, and gotKeyEvent.

float gadget::EventWindowOSX::m_mouse_sensitivity [protected]
 

Definition at line 250 of file EventWindowOSX.h.

Referenced by config, and updateData.

bool gadget::EventWindowOSX::mAmSampling [protected]
 

Definition at line 253 of file EventWindowOSX.h.

Referenced by startSampling.

WindowRef gadget::EventWindowOSX::mWindow [protected]
 

The carbon window.

Definition at line 254 of file EventWindowOSX.h.


The documentation for this class was generated from the following files:
Generated on Sun May 2 14:26:47 2004 for Gadgeteer by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002