The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
3.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #if JUCE_WINDOWS
  18. namespace
  19. {
  20. static HHOOK mouseWheelHook = 0;
  21. static int numHookUsers = 0;
  22. struct WindowsHooks
  23. {
  24. WindowsHooks()
  25. {
  26. if (numHookUsers++ == 0)
  27. {
  28. mouseWheelHook = SetWindowsHookEx (WH_MOUSE, mouseWheelHookCallback,
  29. (HINSTANCE) Process::getCurrentModuleInstanceHandle(),
  30. GetCurrentThreadId());
  31. #if 0 // XXX temporary for testing
  32. keyboardHook = SetWindowsHookEx (WH_KEYBOARD, keyboardHookCallback,
  33. (HINSTANCE) Process::getCurrentModuleInstanceHandle(),
  34. GetCurrentThreadId());
  35. #endif
  36. }
  37. }
  38. ~WindowsHooks()
  39. {
  40. if (--numHookUsers == 0)
  41. {
  42. if (mouseWheelHook != 0)
  43. {
  44. UnhookWindowsHookEx (mouseWheelHook);
  45. mouseWheelHook = 0;
  46. }
  47. #if 0 // XXX temporary for testing
  48. if (keyboardHook != 0)
  49. {
  50. UnhookWindowsHookEx (keyboardHook);
  51. keyboardHook = 0;
  52. }
  53. #endif
  54. }
  55. }
  56. static LRESULT CALLBACK mouseWheelHookCallback (int nCode, WPARAM wParam, LPARAM lParam)
  57. {
  58. if (nCode >= 0 && wParam == WM_MOUSEWHEEL)
  59. {
  60. // using a local copy of this struct to support old mingw libraries
  61. struct MOUSEHOOKSTRUCTEX_ : public MOUSEHOOKSTRUCT { DWORD mouseData; };
  62. const MOUSEHOOKSTRUCTEX_& hs = *(MOUSEHOOKSTRUCTEX_*) lParam;
  63. if (Component* const comp = Desktop::getInstance().findComponentAt (Point<int> (hs.pt.x, hs.pt.y)))
  64. if (comp->getWindowHandle() != 0)
  65. return PostMessage ((HWND) comp->getWindowHandle(), WM_MOUSEWHEEL,
  66. hs.mouseData & 0xffff0000, (hs.pt.x & 0xffff) | (hs.pt.y << 16));
  67. }
  68. return CallNextHookEx (mouseWheelHook, nCode, wParam, lParam);
  69. }
  70. #if 0 // XXX temporary for testing
  71. static LRESULT CALLBACK keyboardHookCallback (int nCode, WPARAM wParam, LPARAM lParam)
  72. {
  73. if (nCode >= 0 && nCode == HC_ACTION)
  74. if (passKeyUpDownToPeer (GetFocus(), wParam, (lParam & (1 << 31)) == 0))
  75. return 1;
  76. return CallNextHookEx (keyboardHook, nCode, wParam, lParam);
  77. }
  78. #endif
  79. };
  80. }
  81. #endif