@interface NSEvent (DeviceDelta)
- (CGFloat)deviceDeltaX;
- (CGFloat)deviceDeltaY;
+
+// 10.7+
+- (BOOL)hasPreciseScrollingDeltas;
+- (CGFloat)scrollingDeltaX;
+- (CGFloat)scrollingDeltaY;
@end
void wxWidgetCocoaImpl::SetupMouseEvent( wxMouseEvent &wxevent , NSEvent * nsEvent )
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;
return true;
}
+void wxWidgetCocoaImpl::SetDropTarget(wxDropTarget* target)
+{
+ [m_osxView unregisterDraggedTypes];
+
+ if ( target == NULL )
+ return;
+
+ wxDataObject* dobj = target->GetDataObject();
+
+ if( dobj )
+ {
+ CFMutableArrayRef typesarray = CFArrayCreateMutable(kCFAllocatorDefault,0,&kCFTypeArrayCallBacks);
+ dobj->AddSupportedTypes(typesarray);
+ NSView* targetView = m_osxView;
+ if ( [m_osxView isKindOfClass:[NSScrollView class] ] )
+ targetView = [(NSScrollView*) m_osxView documentView];
+
+ [targetView registerForDraggedTypes:(NSArray*)typesarray];
+ CFRelease(typesarray);
+ }
+}
void wxWidgetCocoaImpl::RemoveFromParent()
{
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)]];
if ( !result )
{
- if ( IsUserPane() && [event type] == NSKeyDown)
+ if ( [event type] == NSKeyDown)
{
long keycode = wxOSXTranslateCocoaKey( event, wxEVT_CHAR );
// eventually we could setup a doCommandBySelector catcher and retransform this into the wx key chars
wxKeyEvent wxevent2(wxevent) ;
wxevent2.SetEventType(wxEVT_CHAR);
+ SetupKeyEvent( wxevent2, event );
wxevent2.m_keyCode = keycode;
result = GetWXPeer()->OSXHandleKeyEvent(wxevent2);
}
+ else if (wxevent.CmdDown())
+ {
+ wxKeyEvent wxevent2(wxevent) ;
+ wxevent2.SetEventType(wxEVT_CHAR);
+ SetupKeyEvent( wxevent2, event );
+ result = GetWXPeer()->OSXHandleKeyEvent(wxevent2);
+ }
else
{
- if ( !wxevent.CmdDown() )
+ if ( IsUserPane() && !wxevent.CmdDown() )
{
if ( [m_osxView isKindOfClass:[NSScrollView class] ] )
[[(NSScrollView*)m_osxView documentView] interpretKeyEvents:[NSArray arrayWithObject:event]];
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)
NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
wxNSView* v = [[wxNSView alloc] initWithFrame:r];
- // temporary hook for dnd
- [v registerForDraggedTypes:[NSArray arrayWithObjects:
- NSStringPboardType, NSFilenamesPboardType, NSTIFFPboardType, NSPICTPboardType, NSPDFPboardType, nil]];
-
wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v, false, true );
return c;
}