X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d757ef939eda7da3c6fa66552ecc3df1f0db3c52..ab67e8874db324fab5223cc8d5dff8a8de3e2b77:/src/osx/cocoa/window.mm diff --git a/src/osx/cocoa/window.mm b/src/osx/cocoa/window.mm index 92c2406644..5e2a80e53f 100644 --- a/src/osx/cocoa/window.mm +++ b/src/osx/cocoa/window.mm @@ -455,6 +455,11 @@ bool g_lastButtonWasFakeRight = false ; @interface NSEvent (DeviceDelta) - (CGFloat)deviceDeltaX; - (CGFloat)deviceDeltaY; + +// 10.7+ +- (BOOL)hasPreciseScrollingDeltas; +- (CGFloat)scrollingDeltaX; +- (CGFloat)scrollingDeltaY; @end void wxWidgetCocoaImpl::SetupMouseEvent( wxMouseEvent &wxevent , NSEvent * nsEvent ) @@ -609,23 +614,39 @@ void wxWidgetCocoaImpl::SetupMouseEvent( wxMouseEvent &wxevent , NSEvent * nsEve wxevent.SetEventType( wxEVT_MOUSEWHEEL ) ; - // see http://developer.apple.com/qa/qa2005/qa1453.html - // for more details on why we have to look for the exact type - - const EventRef cEvent = (EventRef) [nsEvent eventRef]; - bool isMouseScrollEvent = false; - if ( cEvent ) - isMouseScrollEvent = ::GetEventKind(cEvent) == kEventMouseScroll; - - if ( isMouseScrollEvent ) + if ( UMAGetSystemVersion() >= 0x1070 ) { - deltaX = [nsEvent deviceDeltaX]; - deltaY = [nsEvent deviceDeltaY]; + if ( [nsEvent hasPreciseScrollingDeltas] ) + { + deltaX = [nsEvent scrollingDeltaX]; + deltaY = [nsEvent scrollingDeltaY]; + } + else + { + deltaX = [nsEvent scrollingDeltaX] * 10; + deltaY = [nsEvent scrollingDeltaY] * 10; + } } else { - deltaX = ([nsEvent deltaX] * 10); - deltaY = ([nsEvent deltaY] * 10); + const EventRef cEvent = (EventRef) [nsEvent eventRef]; + // see http://developer.apple.com/qa/qa2005/qa1453.html + // for more details on why we have to look for the exact type + + bool isMouseScrollEvent = false; + if ( cEvent ) + isMouseScrollEvent = ::GetEventKind(cEvent) == kEventMouseScroll; + + if ( isMouseScrollEvent ) + { + deltaX = [nsEvent deviceDeltaX]; + deltaY = [nsEvent deviceDeltaY]; + } + else + { + deltaX = ([nsEvent deltaX] * 10); + deltaY = ([nsEvent deltaY] * 10); + } } wxevent.m_wheelDelta = 10; @@ -1128,8 +1149,8 @@ void wxWidgetCocoaImpl::mouseEvent(WX_NSEvent event, WXWidget slf, void *_cmd) superimpl(slf, (SEL)_cmd, event); // super of built-ins keeps the mouse up, as wx expects this event, we have to synthesize it - - if ( [ event type] == NSLeftMouseDown ) + // only trigger if at this moment the mouse is already up + if ( [ event type] == NSLeftMouseDown && !wxGetMouseState().LeftIsDown() ) { wxMouseEvent wxevent(wxEVT_LEFT_DOWN); SetupMouseEvent(wxevent , event) ; @@ -1417,7 +1438,10 @@ void wxWidgetCocoaImpl::controlAction( WXWidget WXUNUSED(slf), void *WXUNUSED(_c { wxWindow* wxpeer = (wxWindow*) GetWXPeer(); if ( wxpeer ) + { + wxpeer->OSXSimulateFocusEvents(); wxpeer->OSXHandleClicked(0); + } } void wxWidgetCocoaImpl::controlDoubleAction( WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd), void *WXUNUSED(sender)) @@ -2104,6 +2128,9 @@ void wxWidgetCocoaImpl::Embed( wxWidgetImpl *parent ) NSView* container = parent->GetWXWidget() ; wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ; [container addSubview:m_osxView]; + + if( m_wxPeer->IsFrozen() ) + [[m_osxView window] disableFlushWindow]; } void wxWidgetCocoaImpl::SetBackgroundColour( const wxColour &col ) @@ -2351,14 +2378,33 @@ void wxWidgetCocoaImpl::SetControlSize( wxWindowVariant variant ) if ([cell respondsToSelector:@selector(setControlSize:)]) [cell setControlSize:size]; } + + // we need to propagate this to inner views as well + if ( [m_osxView isKindOfClass:[NSScrollView class] ] ) + { + NSView* targetView = [(NSScrollView*) m_osxView documentView]; + + if ( [targetView respondsToSelector:@selector(setControlSize:)] ) + [targetView setControlSize:size]; + else if ([targetView respondsToSelector:@selector(cell)]) + { + id cell = [(id)targetView cell]; + if ([cell respondsToSelector:@selector(setControlSize:)]) + [cell setControlSize:size]; + } + } } void wxWidgetCocoaImpl::SetFont(wxFont const& font, wxColour const&col, long, bool) { - if ([m_osxView respondsToSelector:@selector(setFont:)]) - [m_osxView setFont: font.OSXGetNSFont()]; - if ([m_osxView respondsToSelector:@selector(setTextColor:)]) - [m_osxView setTextColor:[NSColor colorWithCalibratedRed:(CGFloat) (col.Red() / 255.0) + NSView* targetView = m_osxView; + if ( [m_osxView isKindOfClass:[NSScrollView class] ] ) + targetView = [(NSScrollView*) m_osxView documentView]; + + if ([targetView respondsToSelector:@selector(setFont:)]) + [targetView setFont: font.OSXGetNSFont()]; + if ([targetView respondsToSelector:@selector(setTextColor:)]) + [targetView setTextColor:[NSColor colorWithCalibratedRed:(CGFloat) (col.Red() / 255.0) green:(CGFloat) (col.Green() / 255.0) blue:(CGFloat) (col.Blue() / 255.0) alpha:(CGFloat) (col.Alpha() / 255.0)]]; @@ -2497,7 +2543,7 @@ void wxWidgetCocoaImpl::DoNotifyFocusEvent(bool receivedFocus, wxWidgetImpl* oth event.SetWindow(otherWindow->GetWXPeer()); thisWindow->HandleWindowEvent(event) ; } - else // !receivedFocuss + else // !receivedFocus { #if wxUSE_CARET if ( thisWindow->GetCaret() ) @@ -2531,12 +2577,14 @@ void wxWidgetCocoaImpl::SetCursor(const wxCursor& cursor) void wxWidgetCocoaImpl::CaptureMouse() { - [[m_osxView window] disableCursorRects]; + // TODO remove if we don't get into problems with cursor settings + // [[m_osxView window] disableCursorRects]; } void wxWidgetCocoaImpl::ReleaseMouse() { - [[m_osxView window] enableCursorRects]; + // TODO remove if we don't get into problems with cursor settings + // [[m_osxView window] enableCursorRects]; } void wxWidgetCocoaImpl::SetFlipped(bool flipped) @@ -2544,6 +2592,18 @@ void wxWidgetCocoaImpl::SetFlipped(bool flipped) m_isFlipped = flipped; } +void wxWidgetCocoaImpl::SetDrawingEnabled(bool enabled) +{ + if ( enabled ) + { + [[m_osxView window] enableFlushWindow]; + [m_osxView setNeedsDisplay:YES]; + } + else + { + [[m_osxView window] disableFlushWindow]; + } +} // // Factory methods //