/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. 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/MacHelpers.h"
  19. #include "mac/MacKeyboard.h"
  20. #include "mac/MacMouse.h"
  21. #include "OISException.h"
  22. #include <Carbon/Carbon.h>
  23. using namespace OIS;
  24. //-------------------------------------------------------------------//
  25. OSStatus KeyDownWrapper( EventHandlerCallRef nextHandler,
  26. EventRef theEvent,
  27. void* callClass )
  28. {
  29. // TODO find a better way. This cast isn't very safe
  30. if (callClass != NULL) {
  31. ((MacKeyboard*)callClass)->_keyDownCallback( theEvent );
  32. // propagate the event down the chain
  33. return CallNextEventHandler( nextHandler, theEvent );
  34. }
  35. else {
  36. OIS_EXCEPT(E_General, "KeyDownWrapper >> Being called by something other than our event handler!");
  37. return noErr;
  38. }
  39. }
  40. //-------------------------------------------------------------------//
  41. OSStatus KeyUpWrapper( EventHandlerCallRef nextHandler,
  42. EventRef theEvent,
  43. void* callClass )
  44. {
  45. if (callClass != NULL) {
  46. ((MacKeyboard*)callClass)->_keyUpCallback( theEvent );
  47. // propagate the event down the chain
  48. return CallNextEventHandler( nextHandler, theEvent );
  49. }
  50. else {
  51. OIS_EXCEPT(E_General, "KeyUpWrapper >> Being called by something other than our event handler!");
  52. return noErr;
  53. }
  54. }
  55. //-------------------------------------------------------------------//
  56. OSStatus KeyModWrapper( EventHandlerCallRef nextHandler,
  57. EventRef theEvent,
  58. void* callClass )
  59. {
  60. if (callClass != NULL) {
  61. ((MacKeyboard*)callClass)->_modChangeCallback( theEvent );
  62. // propagate the event down the chain
  63. return CallNextEventHandler( nextHandler, theEvent );
  64. }
  65. else {
  66. OIS_EXCEPT(E_General, "KeyModWrapper >> Being called by something other than our event handler!");
  67. return noErr;
  68. }
  69. }
  70. /*
  71. //-------------------------------------------------------------------//
  72. OSStatus MouseMoveWrapper( EventHandlerCallRef nextHandler,
  73. EventRef theEvent,
  74. void* callClass )
  75. {
  76. if (callClass != NULL) {
  77. ((MacMouse*)callClass)->_mouseMoveCallback( theEvent );
  78. // propagate the event down the chain
  79. return CallNextEventHandler( nextHandler, theEvent );
  80. }
  81. else {
  82. OIS_EXCEPT(E_General, "MouseMoveWrapper >> Being called by something other than our event handler!");
  83. return noErr;
  84. }
  85. }
  86. //-------------------------------------------------------------------//
  87. OSStatus MouseScrollWrapper( EventHandlerCallRef nextHandler,
  88. EventRef theEvent,
  89. void* callClass )
  90. {
  91. if (callClass != NULL) {
  92. ((MacMouse*)callClass)->_mouseScrollCallback( theEvent );
  93. // propagate the event down the chain
  94. return CallNextEventHandler( nextHandler, theEvent );
  95. }
  96. else {
  97. OIS_EXCEPT(E_General, "MouseScrollWrapper >> Being called by something other than our event handler!");
  98. return noErr;
  99. }
  100. }
  101. //-------------------------------------------------------------------//
  102. OSStatus MouseButtonWrapper( EventHandlerCallRef nextHandler,
  103. EventRef theEvent,
  104. void* callClass )
  105. {
  106. if (callClass != NULL) {
  107. ((MacMouse*)callClass)->_mouseButtonCallback( theEvent );
  108. // propagate the event down the chain
  109. return CallNextEventHandler( nextHandler, theEvent );
  110. }
  111. else {
  112. OIS_EXCEPT(E_General, "MouseButtonWrapper >> Being called by something other than our event handler!");
  113. return noErr;
  114. }
  115. }
  116. */
  117. //-------------------------------------------------------------------//
  118. OSStatus MouseWrapper( EventHandlerCallRef nextHandler, EventRef theEvent, void* callClass )
  119. {
  120. if (callClass != NULL)
  121. {
  122. ((MacMouse*)callClass)->_mouseCallback( theEvent );
  123. // propagate the event down the chain
  124. return CallNextEventHandler( nextHandler, theEvent );
  125. }
  126. else
  127. OIS_EXCEPT(E_General, "MouseWrapper >> Being called by something other than our event handler!");
  128. }
  129. #endif