|
- /*
- ==============================================================================
-
- This file is part of the JUCE 6 technical preview.
- Copyright (c) 2020 - Raw Material Software Limited
-
- You may use this code under the terms of the GPL v3
- (see www.gnu.org/licenses).
-
- For this technical preview, this file is not subject to commercial licensing.
-
- JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
- EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
- DISCLAIMED.
-
- ==============================================================================
- */
-
- namespace juce
- {
-
- //==============================================================================
- #if JUCE_SUPPORT_CARBON && JUCE_MAC_WINDOW_VISIBITY_BODGE
-
- /* When you wrap a WindowRef as an NSWindow, it seems to bugger up the HideWindow
- function, so when the host tries (and fails) to hide the window, this stuff catches
- the event and forces it to update.
- */
- static pascal OSStatus windowVisibilityBodge (EventHandlerCallRef, EventRef e, void* user)
- {
- NSWindow* hostWindow = (NSWindow*) user;
-
- switch (GetEventKind (e))
- {
- case kEventWindowInit: [hostWindow display]; break;
- case kEventWindowShown: [hostWindow orderFront: nil]; break;
- case kEventWindowHidden: [hostWindow orderOut: nil]; break;
- }
-
- return eventNotHandledErr;
- }
-
- inline void attachWindowHidingHooks (Component* comp, void* hostWindowRef, NSWindow* nsWindow)
- {
- const EventTypeSpec eventsToCatch[] =
- {
- { kEventClassWindow, kEventWindowInit },
- { kEventClassWindow, kEventWindowShown },
- { kEventClassWindow, kEventWindowHidden }
- };
-
- EventHandlerRef ref;
- InstallWindowEventHandler ((WindowRef) hostWindowRef,
- NewEventHandlerUPP (windowVisibilityBodge),
- GetEventTypeCount (eventsToCatch), eventsToCatch,
- (void*) nsWindow, &ref);
-
- comp->getProperties().set ("carbonEventRef", String::toHexString ((pointer_sized_int) (void*) ref));
- }
-
- inline void removeWindowHidingHooks (Component* comp)
- {
- if (comp != nullptr)
- RemoveEventHandler ((EventHandlerRef) (void*) (pointer_sized_int)
- comp->getProperties() ["carbonEventRef"].toString().getHexValue64());
- }
-
- #elif JUCE_MAC
- inline void attachWindowHidingHooks (void*, void*, void*) {}
- inline void removeWindowHidingHooks (void*) {}
- #endif
-
- } // namespace juce
|