PageRenderTime 28ms CodeModel.GetById 16ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 1ms

/src/ois/src/mac/MacHelpers.cpp

https://bitbucket.org/cabalistic/ogredeps/
C++ | 162 lines | 57 code | 17 blank | 88 comment | 11 complexity | 1d08ae8880c10e47016eda700415144c MD5 | raw file
  1/*
  2 The zlib/libpng License
  3 
  4 Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
  5 
  6 This software is provided 'as-is', without any express or implied warranty. In no event will
  7 the authors be held liable for any damages arising from the use of this software.
  8 
  9 Permission is granted to anyone to use this software for any purpose, including commercial
 10 applications, and to alter it and redistribute it freely, subject to the following
 11 restrictions:
 12 
 13 1. The origin of this software must not be misrepresented; you must not claim that
 14 you wrote the original software. If you use this software in a product,
 15 an acknowledgment in the product documentation would be appreciated but is
 16 not required.
 17 
 18 2. Altered source versions must be plainly marked as such, and must not be
 19 misrepresented as being the original software.
 20 
 21 3. This notice may not be removed or altered from any source distribution.
 22 */
 23
 24#ifndef __LP64__
 25
 26#include "mac/MacHelpers.h"
 27#include "mac/MacKeyboard.h"
 28#include "mac/MacMouse.h"
 29#include "OISException.h"
 30
 31#include <Carbon/Carbon.h>
 32
 33using namespace OIS;
 34    
 35//-------------------------------------------------------------------//
 36OSStatus KeyDownWrapper( EventHandlerCallRef nextHandler,
 37                        EventRef               theEvent,
 38                        void*                  callClass )
 39{
 40    // TODO find a better way. This cast isn't very safe
 41    if (callClass != NULL) {
 42        ((MacKeyboard*)callClass)->_keyDownCallback( theEvent );
 43        
 44        // propagate the event down the chain
 45        return CallNextEventHandler( nextHandler, theEvent );
 46    }
 47    else {
 48        OIS_EXCEPT(E_General, "KeyDownWrapper >> Being called by something other than our event handler!");
 49        return noErr;
 50    }
 51}
 52
 53
 54//-------------------------------------------------------------------//
 55OSStatus KeyUpWrapper( EventHandlerCallRef nextHandler,
 56                       EventRef               theEvent,
 57                       void*                  callClass )
 58{
 59    if (callClass != NULL) {
 60        ((MacKeyboard*)callClass)->_keyUpCallback( theEvent );
 61        
 62        // propagate the event down the chain
 63        return CallNextEventHandler( nextHandler, theEvent );
 64    }
 65    else {
 66        OIS_EXCEPT(E_General, "KeyUpWrapper >> Being called by something other than our event handler!");
 67        return noErr;
 68    }
 69}
 70
 71
 72//-------------------------------------------------------------------//
 73OSStatus KeyModWrapper( EventHandlerCallRef nextHandler,
 74                        EventRef               theEvent,
 75                        void*                  callClass )
 76{
 77    if (callClass != NULL) {
 78        ((MacKeyboard*)callClass)->_modChangeCallback( theEvent );
 79        
 80        // propagate the event down the chain
 81        return CallNextEventHandler( nextHandler, theEvent );
 82        
 83    }
 84    else {
 85        OIS_EXCEPT(E_General, "KeyModWrapper >> Being called by something other than our event handler!");
 86        return noErr;
 87    }
 88}
 89
 90/*
 91//-------------------------------------------------------------------//
 92OSStatus MouseMoveWrapper( EventHandlerCallRef nextHandler,
 93                           EventRef            theEvent,
 94                           void*               callClass )
 95{
 96    if (callClass != NULL) {
 97        ((MacMouse*)callClass)->_mouseMoveCallback( theEvent );
 98        
 99        // propagate the event down the chain
100        return CallNextEventHandler( nextHandler, theEvent );
101        
102    }
103    else {
104        OIS_EXCEPT(E_General, "MouseMoveWrapper >> Being called by something other than our event handler!");
105        return noErr;
106    }
107}
108
109
110//-------------------------------------------------------------------//
111OSStatus MouseScrollWrapper( EventHandlerCallRef nextHandler,
112                             EventRef            theEvent,
113                             void*               callClass )
114{
115    if (callClass != NULL) {
116        ((MacMouse*)callClass)->_mouseScrollCallback( theEvent );
117        
118        // propagate the event down the chain
119        return CallNextEventHandler( nextHandler, theEvent );
120        
121    }
122    else {
123        OIS_EXCEPT(E_General, "MouseScrollWrapper >> Being called by something other than our event handler!");
124        return noErr;
125    }
126}
127
128
129//-------------------------------------------------------------------//
130OSStatus MouseButtonWrapper( EventHandlerCallRef nextHandler,
131                             EventRef            theEvent,
132                             void*               callClass )
133{
134    if (callClass != NULL) {
135        ((MacMouse*)callClass)->_mouseButtonCallback( theEvent );
136        
137        // propagate the event down the chain
138        return CallNextEventHandler( nextHandler, theEvent );
139        
140    }
141    else {
142        OIS_EXCEPT(E_General, "MouseButtonWrapper >> Being called by something other than our event handler!");
143        return noErr;
144    }
145}
146*/
147
148//-------------------------------------------------------------------//
149OSStatus MouseWrapper( EventHandlerCallRef nextHandler, EventRef theEvent, void* callClass )
150{
151    if (callClass != NULL)
152	{
153        ((MacMouse*)callClass)->_mouseCallback( theEvent );
154
155        // propagate the event down the chain
156        return CallNextEventHandler( nextHandler, theEvent );        
157    }
158    else
159        OIS_EXCEPT(E_General, "MouseWrapper >> Being called by something other than our event handler!");
160}
161
162#endif