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.

74 lines
2.5KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. You may use this code under the terms of the GPL v3
  6. (see www.gnu.org/licenses).
  7. For this technical preview, this file is not subject to commercial licensing.
  8. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  9. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  10. DISCLAIMED.
  11. ==============================================================================
  12. */
  13. namespace juce
  14. {
  15. //==============================================================================
  16. #if JUCE_SUPPORT_CARBON && JUCE_MAC_WINDOW_VISIBITY_BODGE
  17. /* When you wrap a WindowRef as an NSWindow, it seems to bugger up the HideWindow
  18. function, so when the host tries (and fails) to hide the window, this stuff catches
  19. the event and forces it to update.
  20. */
  21. static pascal OSStatus windowVisibilityBodge (EventHandlerCallRef, EventRef e, void* user)
  22. {
  23. NSWindow* hostWindow = (NSWindow*) user;
  24. switch (GetEventKind (e))
  25. {
  26. case kEventWindowInit: [hostWindow display]; break;
  27. case kEventWindowShown: [hostWindow orderFront: nil]; break;
  28. case kEventWindowHidden: [hostWindow orderOut: nil]; break;
  29. }
  30. return eventNotHandledErr;
  31. }
  32. inline void attachWindowHidingHooks (Component* comp, void* hostWindowRef, NSWindow* nsWindow)
  33. {
  34. const EventTypeSpec eventsToCatch[] =
  35. {
  36. { kEventClassWindow, kEventWindowInit },
  37. { kEventClassWindow, kEventWindowShown },
  38. { kEventClassWindow, kEventWindowHidden }
  39. };
  40. EventHandlerRef ref;
  41. InstallWindowEventHandler ((WindowRef) hostWindowRef,
  42. NewEventHandlerUPP (windowVisibilityBodge),
  43. GetEventTypeCount (eventsToCatch), eventsToCatch,
  44. (void*) nsWindow, &ref);
  45. comp->getProperties().set ("carbonEventRef", String::toHexString ((pointer_sized_int) (void*) ref));
  46. }
  47. inline void removeWindowHidingHooks (Component* comp)
  48. {
  49. if (comp != nullptr)
  50. RemoveEventHandler ((EventHandlerRef) (void*) (pointer_sized_int)
  51. comp->getProperties() ["carbonEventRef"].toString().getHexValue64());
  52. }
  53. #elif JUCE_MAC
  54. inline void attachWindowHidingHooks (void*, void*, void*) {}
  55. inline void removeWindowHidingHooks (void*) {}
  56. #endif
  57. } // namespace juce