X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0f9b48d1e1535f8b92a73031be8cceff39123d27..bb69632a56a827bed4cfae842bfffa88259ac1aa:/src/osx/cocoa/window.mm diff --git a/src/osx/cocoa/window.mm b/src/osx/cocoa/window.mm index f2f51d18d9..4594a4931d 100644 --- a/src/osx/cocoa/window.mm +++ b/src/osx/cocoa/window.mm @@ -11,7 +11,9 @@ #include "wx/wxprec.h" -#include +#ifndef WX_PRECOMP +#include "wx/nonownedwnd.h" +#endif #ifdef __WXMAC__ #include "wx/osx/private.h" @@ -43,14 +45,117 @@ NSRect wxOSXGetFrameForControl( wxWindowMac* window , const wxPoint& pos , const -(void)otherMouseUp:(NSEvent *)event ; -(void)handleMouseEvent:(NSEvent *)event; +- (void)keyDown:(NSEvent *)event; +- (void)keyUp:(NSEvent *)event; +- (void)flagsChanged:(NSEvent *)event; +- (void)handleKeyEvent:(NSEvent *)event; + - (void)setImplementation: (wxWidgetImpl *) theImplementation; - (wxWidgetImpl*) implementation; - (BOOL) isFlipped; - (BOOL) becomeFirstResponder; - (BOOL) resignFirstResponder; +- (BOOL) canBecomeKeyView; @end // wxNSView +long wxOSXTranslateCocoaKey(unsigned short code, int unichar ) +{ + long retval = code; + switch( unichar ) + { + case NSUpArrowFunctionKey : + retval = WXK_UP; + break; + case NSDownArrowFunctionKey : + retval = WXK_DOWN; + break; + case NSLeftArrowFunctionKey : + retval = WXK_LEFT; + break; + case NSRightArrowFunctionKey : + retval = WXK_RIGHT; + break; + case NSInsertFunctionKey : + retval = WXK_INSERT; + break; + case NSDeleteFunctionKey : + retval = WXK_DELETE; + break; + case NSHomeFunctionKey : + retval = WXK_HOME; + break; +// case NSBeginFunctionKey : +// retval = WXK_BEGIN; +// break; + case NSEndFunctionKey : + retval = WXK_END; + break; + case NSPageUpFunctionKey : + retval = WXK_PAGEUP; + break; + case NSPageDownFunctionKey : + retval = WXK_PAGEDOWN; + break; + case NSHelpFunctionKey : + retval = WXK_HELP; + break; + + default : + if ( unichar >= NSF1FunctionKey && unichar >= NSF24FunctionKey ) + retval = WXK_F1 + (unichar - NSF1FunctionKey ); + break; + } + return retval; +} + +void SetupKeyEvent( wxKeyEvent &wxevent , NSEvent * nsEvent ) +{ + UInt32 modifiers = [nsEvent modifierFlags] ; + int eventType = [nsEvent type]; + + wxevent.m_shiftDown = modifiers & NSShiftKeyMask; + wxevent.m_controlDown = modifiers & NSControlKeyMask; + wxevent.m_altDown = modifiers & NSAlternateKeyMask; + wxevent.m_metaDown = modifiers & NSCommandKeyMask; + + wxString chars; + if ( eventType != NSFlagsChanged ) + { + NSString* nschars = [nsEvent characters]; + if ( nschars ) + { + wxCFStringRef cfchars((CFStringRef)[nschars retain]); + chars = cfchars.AsString(); + } + } + + int unichar = chars.Length() > 0 ? chars[0] : 0; + +#if wxUSE_UNICODE + wxevent.m_uniChar = unichar; +#endif + wxevent.m_keyCode = wxOSXTranslateCocoaKey( [nsEvent keyCode], unichar ) ; +// wxevent.m_rawCode = keymessage; + wxevent.m_rawFlags = modifiers; + + wxevent.SetTimestamp( [nsEvent timestamp] * 1000.0 ) ; + switch (eventType) + { + case NSKeyDown : + wxevent.SetEventType( wxEVT_KEY_DOWN ) ; + break; + case NSKeyUp : + wxevent.SetEventType( wxEVT_KEY_UP ) ; + break; + case NSFlagsChanged : + // setup common code here + break; + default : + break ; + } +} + void SetupMouseEvent( wxMouseEvent &wxevent , NSEvent * nsEvent ) { UInt32 modifiers = [nsEvent modifierFlags] ; @@ -222,7 +327,7 @@ void SetupMouseEvent( wxMouseEvent &wxevent , NSEvent * nsEvent ) wxRegion updateRgn; const NSRect *rects; - int count ; + NSInteger count; [self getRectsBeingDrawn:&rects count:&count]; for ( int i = 0 ; i < count ; ++i ) @@ -285,6 +390,29 @@ void SetupMouseEvent( wxMouseEvent &wxevent , NSEvent * nsEvent ) impl->GetWXPeer()->HandleWindowEvent(wxevent); } +- (void)keyDown:(NSEvent *)event +{ + [self handleKeyEvent:event]; +} + +- (void)keyUp:(NSEvent *)event +{ + [self handleKeyEvent:event]; +} + +- (void)flagsChanged:(NSEvent *)event +{ + [self handleKeyEvent:event]; +} + +- (void)handleKeyEvent:(NSEvent *)event +{ + wxKeyEvent wxevent(wxEVT_KEY_DOWN); + SetupKeyEvent( wxevent, event ); + impl->GetWXPeer()->HandleWindowEvent(wxevent); +} + + - (void)setImplementation: (wxWidgetImpl *) theImplementation { impl = theImplementation; @@ -318,6 +446,10 @@ void SetupMouseEvent( wxMouseEvent &wxevent , NSEvent * nsEvent ) return r; } +- (BOOL) canBecomeKeyView +{ + return YES; +} @end // wxNSView @@ -581,6 +713,15 @@ void wxWidgetCocoaImpl::SetControlSize( wxWindowVariant variant ) [m_osxView setControlSize:size]; } +void wxWidgetCocoaImpl::SetFont(wxFont const&, wxColour const&, long, bool) +{ + // TODO +} + +void wxWidgetCocoaImpl::InstallEventHandler( WXWidget control ) +{ +} + // // Factory methods //