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.

80 lines
2.9KB

  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. #ifndef JUCE_CARBONVISIBILITY_H_INCLUDED
  18. #define JUCE_CARBONVISIBILITY_H_INCLUDED
  19. //==============================================================================
  20. #if JUCE_SUPPORT_CARBON && JUCE_MAC_WINDOW_VISIBITY_BODGE
  21. /* When you wrap a WindowRef as an NSWindow, it seems to bugger up the HideWindow
  22. function, so when the host tries (and fails) to hide the window, this stuff catches
  23. the event and forces it to update.
  24. */
  25. static pascal OSStatus windowVisibilityBodge (EventHandlerCallRef, EventRef e, void* user)
  26. {
  27. NSWindow* hostWindow = (NSWindow*) user;
  28. switch (GetEventKind (e))
  29. {
  30. case kEventWindowInit: [hostWindow display]; break;
  31. case kEventWindowShown: [hostWindow orderFront: nil]; break;
  32. case kEventWindowHidden: [hostWindow orderOut: nil]; break;
  33. }
  34. return eventNotHandledErr;
  35. }
  36. inline void attachWindowHidingHooks (Component* comp, void* hostWindowRef, NSWindow* nsWindow)
  37. {
  38. const EventTypeSpec eventsToCatch[] =
  39. {
  40. { kEventClassWindow, kEventWindowInit },
  41. { kEventClassWindow, kEventWindowShown },
  42. { kEventClassWindow, kEventWindowHidden }
  43. };
  44. EventHandlerRef ref;
  45. InstallWindowEventHandler ((WindowRef) hostWindowRef,
  46. NewEventHandlerUPP (windowVisibilityBodge),
  47. GetEventTypeCount (eventsToCatch), eventsToCatch,
  48. (void*) nsWindow, &ref);
  49. comp->getProperties().set ("carbonEventRef", String::toHexString ((pointer_sized_int) (void*) ref));
  50. }
  51. inline void removeWindowHidingHooks (Component* comp)
  52. {
  53. if (comp != nullptr)
  54. RemoveEventHandler ((EventHandlerRef) (void*) (pointer_sized_int)
  55. comp->getProperties() ["carbonEventRef"].toString().getHexValue64());
  56. }
  57. #elif JUCE_MAC
  58. inline void attachWindowHidingHooks (void*, void*, void*) {}
  59. inline void removeWindowHidingHooks (void*) {}
  60. #endif
  61. #endif // JUCE_CARBONVISIBILITY_H_INCLUDED