X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2e5f9929e68e3878728c6a915268f4e8ed09383a..ddd7e4307b4a58a21e8a5eb04afe06e1fe65f7d8:/src/osx/cocoa/evtloop.mm diff --git a/src/osx/cocoa/evtloop.mm b/src/osx/cocoa/evtloop.mm index 89957cd2bd..91df515ef9 100644 --- a/src/osx/cocoa/evtloop.mm +++ b/src/osx/cocoa/evtloop.mm @@ -4,7 +4,7 @@ // Author: Vadim Zeitlin, Stefan Csomor // Modified by: // Created: 2006-01-12 -// RCS-ID: $Id: evtloop.cpp 54845 2008-07-30 14:52:41Z SC $ +// RCS-ID: $Id$ // Copyright: (c) 2006 Vadim Zeitlin // Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// @@ -39,45 +39,80 @@ // wxEventLoop implementation // ============================================================================ -/* -static int CalculateNSEventMaskFromEventCategory(wxEventCategory cat) -{ - NSLeftMouseDownMask | - NSLeftMouseUpMask | - NSRightMouseDownMask | - NSRightMouseUpMask = 1 << NSRightMouseUp, - NSMouseMovedMask = 1 << NSMouseMoved, - NSLeftMouseDraggedMask = 1 << NSLeftMouseDragged, - NSRightMouseDraggedMask = 1 << NSRightMouseDragged, - NSMouseEnteredMask = 1 << NSMouseEntered, - NSMouseExitedMask = 1 << NSMouseExited, - NSScrollWheelMask = 1 << NSScrollWheel, -#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 - NSTabletPointMask = 1 << NSTabletPoint, - NSTabletProximityMask = 1 << NSTabletProximity, -#endif - NSOtherMouseDownMask = 1 << NSOtherMouseDown, - NSOtherMouseUpMask = 1 << NSOtherMouseUp, - NSOtherMouseDraggedMask = 1 << NSOtherMouseDragged, +#if 0 +// in case we want to integrate this +static NSUInteger CalculateNSEventMaskFromEventCategory(wxEventCategory cat) +{ + // the masking system doesn't really help, as only the lowlevel UI events + // are split in a useful way, all others are way to broad + + if ( (cat | wxEVT_CATEGORY_USER_INPUT) && (cat | (~wxEVT_CATEGORY_USER_INPUT) ) ) + return NSAnyEventMask; + + NSUInteger mask = 0; - NSKeyDownMask = 1 << NSKeyDown, - NSKeyUpMask = 1 << NSKeyUp, - NSFlagsChangedMask = 1 << NSFlagsChanged, + if ( cat | wxEVT_CATEGORY_USER_INPUT ) + { + mask |= + NSLeftMouseDownMask | + NSLeftMouseUpMask | + NSRightMouseDownMask | + NSRightMouseUpMask | + NSMouseMovedMask | + NSLeftMouseDraggedMask | + NSRightMouseDraggedMask | + NSMouseEnteredMask | + NSMouseExitedMask | + NSScrollWheelMask | +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 + NSTabletPointMask | + NSTabletProximityMask | +#endif + NSOtherMouseDownMask | + NSOtherMouseUpMask | + NSOtherMouseDraggedMask | + + NSKeyDownMask | + NSKeyUpMask | + NSFlagsChangedMask | +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 + NSEventMaskGesture | + NSEventMaskMagnify | + NSEventMaskSwipe | + NSEventMaskRotate | + NSEventMaskBeginGesture | + NSEventMaskEndGesture | +#endif + 0; + } + + if ( cat | (~wxEVT_CATEGORY_USER_INPUT) ) + { + mask |= + NSAppKitDefinedMask | + NSSystemDefinedMask | + NSApplicationDefinedMask | + NSPeriodicMask | + NSCursorUpdateMask; + } + + return mask; +} - NSAppKitDefinedMask = 1 << NSAppKitDefined, - NSSystemDefinedMask = 1 << NSSystemDefined, - NSApplicationDefinedMask = 1 << NSApplicationDefined, - NSPeriodicMask = 1 << NSPeriodic, - NSCursorUpdateMask = 1 << NSCursorUpdate, +#endif - NSAnyEventMask = 0xffffffffU +wxGUIEventLoop::wxGUIEventLoop() +{ + m_modalSession = nil; + m_dummyWindow = nil; } -*/ -wxGUIEventLoop::wxGUIEventLoop() +wxGUIEventLoop::~wxGUIEventLoop() { + wxASSERT( m_modalSession == nil ); + wxASSERT( m_dummyWindow == nil ); } //----------------------------------------------------------------------------- @@ -156,18 +191,48 @@ int wxGUIEventLoop::DoDispatchTimeout(unsigned long timeout) { wxMacAutoreleasePool autoreleasepool; - NSEvent *event = [NSApp - nextEventMatchingMask:NSAnyEventMask - untilDate:[NSDate dateWithTimeIntervalSinceNow: timeout/1000] - inMode:NSDefaultRunLoopMode - dequeue: YES]; - - if ( event == nil ) + if ( m_modalSession ) + { + NSInteger response = [NSApp runModalSession:(NSModalSession)m_modalSession]; + + switch (response) + { + case NSRunContinuesResponse: + { + if ( [[NSApplication sharedApplication] + nextEventMatchingMask: NSAnyEventMask + untilDate: nil + inMode: NSDefaultRunLoopMode + dequeue: NO] != nil ) + return 1; + + return -1; + } + + case NSRunStoppedResponse: + case NSRunAbortedResponse: + return -1; + default: + wxFAIL_MSG("unknown response code"); + break; + } return -1; + } + else + { + NSEvent *event = [NSApp + nextEventMatchingMask:NSAnyEventMask + untilDate:[NSDate dateWithTimeIntervalSinceNow: timeout/1000] + inMode:NSDefaultRunLoopMode + dequeue: YES]; + + if ( event == nil ) + return -1; - [NSApp sendEvent: event]; + [NSApp sendEvent: event]; - return 1; + return 1; + } } void wxGUIEventLoop::DoRun() @@ -240,3 +305,117 @@ void wxModalEventLoop::DoStop() [NSApp stopModal]; } +void wxGUIEventLoop::BeginModalSession( wxWindow* modalWindow ) +{ + WXWindow nsnow = nil; + + if ( modalWindow ) + { + // we must show now, otherwise beginModalSessionForWindow does it but it + // also would do a centering of the window before overriding all our position + if ( !modalWindow->IsShownOnScreen() ) + modalWindow->Show(); + + wxNonOwnedWindow* now = dynamic_cast (modalWindow); + wxASSERT_MSG( now != NULL, "must pass in a toplevel window for modal event loop" ); + nsnow = now ? now->GetWXWindow() : nil; + } + else + { + NSRect r = NSMakeRect(10, 10, 0, 0); + nsnow = [NSPanel alloc]; + [nsnow initWithContentRect:r + styleMask:NSBorderlessWindowMask + backing:NSBackingStoreBuffered + defer:YES + ]; + [nsnow orderOut:nil]; + m_dummyWindow = nsnow; + } + m_modalSession = [NSApp beginModalSessionForWindow:nsnow]; +} + +void wxGUIEventLoop::EndModalSession() +{ + wxASSERT_MSG(m_modalSession != NULL, "no modal session active"); + [NSApp endModalSession:(NSModalSession)m_modalSession]; + m_modalSession = nil; + if ( m_dummyWindow ) + { + [m_dummyWindow release]; + m_dummyWindow = nil; + } +} + +// +// +// + +wxWindowDisabler::wxWindowDisabler(bool disable) +{ + m_modalEventLoop = NULL; + m_disabled = disable; + if ( disable ) + DoDisable(); +} + +wxWindowDisabler::wxWindowDisabler(wxWindow *winToSkip) +{ + m_disabled = true; + DoDisable(winToSkip); +} + +void wxWindowDisabler::DoDisable(wxWindow *winToSkip) +{ + // remember the top level windows which were already disabled, so that we + // don't reenable them later + m_winDisabled = NULL; + + wxWindowList::compatibility_iterator node; + for ( node = wxTopLevelWindows.GetFirst(); node; node = node->GetNext() ) + { + wxWindow *winTop = node->GetData(); + if ( winTop == winToSkip ) + continue; + + // we don't need to disable the hidden or already disabled windows + if ( winTop->IsEnabled() && winTop->IsShown() ) + { + winTop->Disable(); + } + else + { + if ( !m_winDisabled ) + { + m_winDisabled = new wxWindowList; + } + + m_winDisabled->Append(winTop); + } + } + + m_modalEventLoop = (wxEventLoop*)wxEventLoopBase::GetActive(); + m_modalEventLoop->BeginModalSession(winToSkip); +} + +wxWindowDisabler::~wxWindowDisabler() +{ + if ( !m_disabled ) + return; + + m_modalEventLoop->EndModalSession(); + + wxWindowList::compatibility_iterator node; + for ( node = wxTopLevelWindows.GetFirst(); node; node = node->GetNext() ) + { + wxWindow *winTop = node->GetData(); + if ( !m_winDisabled || !m_winDisabled->Find(winTop) ) + { + winTop->Enable(); + } + //else: had been already disabled, don't reenable + } + + delete m_winDisabled; +} +