/src/ois/src/mac/MacInputManager.cpp

https://bitbucket.org/cabalistic/ogredeps/ · C++ · 210 lines · 138 code · 30 blank · 42 comment · 31 complexity · 5d0e40c98a8d1c1d3d66e6c3758e17b0 MD5 · raw file

  1. /*
  2. The zlib/libpng License
  3. Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
  4. This software is provided 'as-is', without any express or implied warranty. In no event will
  5. the authors be held liable for any damages arising from the use of this software.
  6. Permission is granted to anyone to use this software for any purpose, including commercial
  7. applications, and to alter it and redistribute it freely, subject to the following
  8. restrictions:
  9. 1. The origin of this software must not be misrepresented; you must not claim that
  10. you wrote the original software. If you use this software in a product,
  11. an acknowledgment in the product documentation would be appreciated but is
  12. not required.
  13. 2. Altered source versions must be plainly marked as such, and must not be
  14. misrepresented as being the original software.
  15. 3. This notice may not be removed or altered from any source distribution.
  16. */
  17. #ifndef __LP64__
  18. #include "mac/MacInputManager.h"
  19. #include "mac/MacKeyboard.h"
  20. #include "mac/MacMouse.h"
  21. #include "mac/MacHIDManager.h"
  22. #include "OISException.h"
  23. #include <Carbon/Carbon.h>
  24. #include <iostream>
  25. using namespace std;
  26. using namespace OIS;
  27. //--------------------------------------------------------------------------------//
  28. MacInputManager::MacInputManager() : InputManager("Mac OS X Input Manager")
  29. {
  30. mHideMouse = true;
  31. mUseRepeat = false;
  32. mEventTargetRef = NULL;
  33. mWindow = NULL;
  34. keyboardUsed = mouseUsed = false;
  35. //Setup our internal factories
  36. mFactories.push_back(this);
  37. mHIDManager = new MacHIDManager();
  38. mFactories.push_back(mHIDManager);
  39. }
  40. //--------------------------------------------------------------------------------//
  41. MacInputManager::~MacInputManager()
  42. {
  43. delete mHIDManager;
  44. }
  45. //--------------------------------------------------------------------------------//
  46. void MacInputManager::_initialize( ParamList &paramList )
  47. {
  48. _parseConfigSettings( paramList );
  49. //Enumerate all devices attached
  50. _enumerateDevices();
  51. mHIDManager->initialize();
  52. }
  53. //--------------------------------------------------------------------------------//
  54. void MacInputManager::_parseConfigSettings( ParamList &paramList )
  55. {
  56. // Some carbon apps are running in a window, however full screen apps
  57. // do not have a window, so we need to account for that too.
  58. ParamList::iterator i = paramList.find("WINDOW");
  59. if(i != paramList.end())
  60. {
  61. mWindow = (WindowRef)strtoul(i->second.c_str(), 0, 10);
  62. if(mWindow == 0)
  63. {
  64. mWindow = NULL;
  65. mEventTargetRef = GetApplicationEventTarget();
  66. }
  67. else
  68. {
  69. //mEventTargetRef = GetWindowEventTarget(mWindow);
  70. mEventTargetRef = GetApplicationEventTarget();
  71. }
  72. }
  73. else
  74. {
  75. // else get the main active window.. user might not have access to it through some
  76. // graphics libraries, if that fails then try at the application level.
  77. mWindow = ActiveNonFloatingWindow();
  78. if(mWindow == NULL)
  79. {
  80. mEventTargetRef = GetApplicationEventTarget();
  81. }
  82. else
  83. {
  84. //mEventTargetRef = GetWindowEventTarget(mWindow);
  85. mEventTargetRef = GetApplicationEventTarget();
  86. }
  87. }
  88. if(mEventTargetRef == NULL)
  89. OIS_EXCEPT( E_General, "MacInputManager::_parseConfigSettings >> Unable to find a window or event target" );
  90. // Keyboard
  91. if(paramList.find("MacAutoRepeatOn") != paramList.end())
  92. {
  93. if(paramList.find("MacAutoRepeatOn")->second == "true")
  94. {
  95. mUseRepeat = true;
  96. }
  97. }
  98. }
  99. //--------------------------------------------------------------------------------//
  100. void MacInputManager::_enumerateDevices()
  101. {
  102. }
  103. //--------------------------------------------------------------------------------//
  104. DeviceList MacInputManager::freeDeviceList()
  105. {
  106. DeviceList ret;
  107. if( keyboardUsed == false )
  108. ret.insert(std::make_pair(OISKeyboard, mInputSystemName));
  109. if( mouseUsed == false )
  110. ret.insert(std::make_pair(OISMouse, mInputSystemName));
  111. return ret;
  112. }
  113. //--------------------------------------------------------------------------------//
  114. int MacInputManager::totalDevices(Type iType)
  115. {
  116. switch(iType)
  117. {
  118. case OISKeyboard: return 1;
  119. case OISMouse: return 1;
  120. default: return 0;
  121. }
  122. }
  123. //--------------------------------------------------------------------------------//
  124. int MacInputManager::freeDevices(Type iType)
  125. {
  126. switch(iType)
  127. {
  128. case OISKeyboard: return keyboardUsed ? 0 : 1;
  129. case OISMouse: return mouseUsed ? 0 : 1;
  130. default: return 0;
  131. }
  132. }
  133. //--------------------------------------------------------------------------------//
  134. bool MacInputManager::vendorExist(Type iType, const std::string & vendor)
  135. {
  136. if( (iType == OISKeyboard || iType == OISMouse) && vendor == mInputSystemName )
  137. return true;
  138. return false;
  139. }
  140. //--------------------------------------------------------------------------------//
  141. Object* MacInputManager::createObject(InputManager* creator, Type iType, bool bufferMode,
  142. const std::string & vendor)
  143. {
  144. Object *obj = 0;
  145. switch(iType)
  146. {
  147. case OISKeyboard:
  148. {
  149. if( keyboardUsed == false )
  150. obj = new MacKeyboard(this, bufferMode, mUseRepeat);
  151. break;
  152. }
  153. case OISMouse:
  154. {
  155. if( mouseUsed == false )
  156. obj = new MacMouse(this, bufferMode);
  157. break;
  158. }
  159. default:
  160. {
  161. obj = mHIDManager->createObject(creator, iType, bufferMode, vendor);
  162. break;
  163. }
  164. }
  165. if( obj == 0 )
  166. OIS_EXCEPT(E_InputDeviceNonExistant, "No devices match requested type.");
  167. return obj;
  168. }
  169. //--------------------------------------------------------------------------------//
  170. void MacInputManager::destroyObject(Object* obj)
  171. {
  172. delete obj;
  173. }
  174. #endif