00001 #include "mac/MacMouse.h"
00002 #include "mac/MacInputManager.h"
00003 #include "mac/MacHelpers.h"
00004 #include "OISException.h"
00005 #include "OISEvents.h"
00006
00007 #include <Carbon/Carbon.h>
00008
00009 #include <list>
00010 #include <string>
00011
00012 using namespace OIS;
00013
00014
00015 MacMouse::MacMouse( InputManager* creator, bool buffered ) : mRegainFocus( false )
00016 {
00017 mCreator = creator;
00018 mouseButtonEventRef = NULL;
00019 mouseMoveEventRef = NULL;
00020 mouseScrollEventRef = NULL;
00021
00022 mBuffered = buffered;
00023 mType = OISMouse;
00024 listener = 0;
00025
00026 mouseButtonUPP = NewEventHandlerUPP( MouseButtonWrapper );
00027 mouseMoveUPP = NewEventHandlerUPP( MouseMoveWrapper );
00028 mouseScrollUPP = NewEventHandlerUPP( MouseScrollWrapper );
00029 }
00030
00031 MacMouse::~MacMouse()
00032 {
00033 if( mouseButtonEventRef != NULL ) RemoveEventHandler( mouseButtonEventRef );
00034 if( mouseMoveEventRef != NULL ) RemoveEventHandler( mouseMoveEventRef );
00035 if( mouseScrollEventRef != NULL ) RemoveEventHandler( mouseScrollEventRef );
00036
00037 DisposeEventHandlerUPP( mouseButtonUPP );
00038 DisposeEventHandlerUPP( mouseMoveUPP );
00039 DisposeEventHandlerUPP( mouseScrollUPP );
00040 }
00041
00042 void MacMouse::_initialize()
00043 {
00044 mState.clear();
00045 mRegainFocus = false;
00046
00047 OSStatus status;
00048 WindowRef window = (( MacInputManager* )mCreator)->_getWindow();
00049
00050 if( mouseButtonEventRef != NULL ) RemoveEventHandler( mouseButtonEventRef );
00051 if( mouseMoveEventRef != NULL ) RemoveEventHandler( mouseMoveEventRef );
00052 if( mouseScrollEventRef != NULL ) RemoveEventHandler( mouseScrollEventRef );
00053
00054 mouseButtonEventRef = NULL;
00055 mouseMoveEventRef = NULL;
00056 mouseScrollEventRef = NULL;
00057
00058 const EventTypeSpec mouseButtonEvents[] =
00059 {
00060 { kEventClassMouse, kEventMouseDown },
00061 { kEventClassMouse, kEventMouseUp }
00062 };
00063
00064 const EventTypeSpec mouseMoveEvents[] =
00065 {
00066 { kEventClassMouse, kEventMouseMoved }
00067 };
00068
00069 const EventTypeSpec mouseScrollEvents[] =
00070 {
00071 { kEventClassMouse, kEventMouseWheelMoved }
00072 };
00073
00074 status = InstallWindowEventHandler( window, mouseButtonUPP, GetEventTypeCount( mouseButtonEvents ), mouseButtonEvents, this, &mouseButtonEventRef );
00075 if( status != noErr )
00076 {
00077 OIS_EXCEPT( E_General, "MacMouse::_initialize >> Error loading MouseButton event handler" );
00078 }
00079
00080 status = InstallWindowEventHandler( window, mouseMoveUPP, GetEventTypeCount( mouseMoveEvents ), mouseMoveEvents, this, &mouseMoveEventRef );
00081 if( status != noErr )
00082 {
00083 OIS_EXCEPT( E_General, "MacMouse::_initialize >> Error loading MouseMove event handler" );
00084 }
00085
00086 status = InstallWindowEventHandler( window, mouseScrollUPP, GetEventTypeCount( mouseScrollEvents ), mouseScrollEvents, this, &mouseScrollEventRef );
00087 if( status != noErr )
00088 {
00089 OIS_EXCEPT( E_General, "MacMouse::_initialize >> Error loading MouseScroll event handler" );
00090 }
00091 }
00092
00093 void MacMouse::setBuffered( bool buffered )
00094 {
00095 mBuffered = buffered;
00096 }
00097
00098 void MacMouse::capture()
00099 {
00100 if( !mBuffered )
00101 return;
00102
00103
00104 }
00105
00106 void MacMouse::_mouseButtonCallback( EventRef theEvent )
00107 {
00108
00109 }
00110
00111 void MacMouse::_mouseMoveCallback( EventRef theEvent )
00112 {
00113
00114 }
00115
00116 void MacMouse::_mouseScrollCallback( EventRef theEvent )
00117 {
00118
00119 }