From: Stefan Csomor Date: Wed, 14 Jan 2009 13:56:05 +0000 (+0000) Subject: cleaning up warnings, more common event code X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/ffad7b0dd2907634d93daacfb54d503c6f7a4ad4 cleaning up warnings, more common event code git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58092 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/osx/cocoa/private.h b/include/wx/osx/cocoa/private.h index 26f1a90a50..de4b72ae46 100644 --- a/include/wx/osx/cocoa/private.h +++ b/include/wx/osx/cocoa/private.h @@ -118,12 +118,15 @@ public : void InstallEventHandler( WXWidget control = NULL ); virtual bool DoHandleMouseEvent(NSEvent *event); + virtual bool DoHandleKeyEvent(NSEvent *event); protected: WXWidget m_osxView; DECLARE_DYNAMIC_CLASS_NO_COPY(wxWidgetCocoaImpl) }; +DECLARE_WXCOCOA_OBJC_CLASS( wxNSWindow ); + class wxNonOwnedWindowCocoaImpl : public wxNonOwnedWindowImpl { public : @@ -178,7 +181,7 @@ public : wxNonOwnedWindow* GetWXPeer() { return m_wxPeer; } protected : - WX_NSWindow m_macWindow; + WX_wxNSWindow m_macWindow; void * m_macFullScreenData ; DECLARE_DYNAMIC_CLASS_NO_COPY(wxNonOwnedWindowCocoaImpl) }; @@ -202,6 +205,9 @@ protected : -(void)mouseUp:(NSEvent *)event ;\ -(void)rightMouseUp:(NSEvent *)event ;\ -(void)otherMouseUp:(NSEvent *)event ;\ + - (void)keyDown:(NSEvent *)event;\ + - (void)keyUp:(NSEvent *)event;\ + - (void)flagsChanged:(NSEvent *)event;\ #define WXCOCOAIMPL_COMMON_MOUSE_IMPLEMENTATION -(void)mouseDown:(NSEvent *)event \ {\ @@ -232,6 +238,21 @@ protected : {\ if ( !impl->DoHandleMouseEvent(event) )\ [super otherMouseUp:event];\ + }\ + -(void)keyDown:(NSEvent *)event\ + {\ + if ( !impl->DoHandleKeyEvent(event) )\ + [super keyDown:event];\ + }\ + -(void)keyUp:(NSEvent *)event\ + {\ + if ( !impl->DoHandleKeyEvent(event) )\ + [super keyUp:event];\ + }\ + -(void)flagsChanged:(NSEvent *)event\ + {\ + if ( !impl->DoHandleKeyEvent(event) )\ + [super flagsChanged:event];\ } #define WXCOCOAIMPL_COMMON_MEMBERS wxWidgetCocoaImpl* impl; @@ -286,6 +307,28 @@ protected : @end + @interface wxNSMenu : NSMenu + { + wxMenuImpl* impl; + } + + - (void) setImplementation:(wxMenuImpl*) item; + - (wxMenuImpl*) implementation; + + @end + + @interface wxNSMenuItem : NSMenuItem + { + wxMenuItemImpl* impl; + } + + - (void) setImplementation:(wxMenuItemImpl*) item; + - (wxMenuItemImpl*) implementation; + + - (void)clickedAction:(id)sender; + - (BOOL)validateMenuItem:(NSMenuItem *)menuItem; + + @end #endif // __OBJC__ diff --git a/src/osx/cocoa/listbox.mm b/src/osx/cocoa/listbox.mm index 94d57afad6..270d3ba4df 100644 --- a/src/osx/cocoa/listbox.mm +++ b/src/osx/cocoa/listbox.mm @@ -41,8 +41,8 @@ class wxListWidgetCocoaImpl; objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex; -- (id)tableView:(NSTableView *)aTableView - setObjectValue:(NSTableColumn *)aTableColumn +- (void)tableView:(NSTableView *)aTableView + setObjectValue:(id)value forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex; - (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView; diff --git a/src/osx/cocoa/menu.mm b/src/osx/cocoa/menu.mm index 09a753f6b5..3127597356 100644 --- a/src/osx/cocoa/menu.mm +++ b/src/osx/cocoa/menu.mm @@ -34,18 +34,6 @@ // ---------------------- #include -@class wxNSMenuItem; - -@interface wxNSMenu : NSMenu -{ - wxMenuImpl* impl; -} - -- (void) setImplementation:(wxMenuImpl*) item; -- (wxMenuImpl*) implementation; - -@end - @implementation wxNSMenu - (id) init @@ -128,6 +116,10 @@ @end +@interface NSApplication(MissingAppleMenuCall) +- (void)setAppleMenu:(NSMenu *)menu; +@end + class wxMenuCocoaImpl : public wxMenuImpl { public : diff --git a/src/osx/cocoa/menuitem.mm b/src/osx/cocoa/menuitem.mm index 87132b4600..6b05d359fb 100644 --- a/src/osx/cocoa/menuitem.mm +++ b/src/osx/cocoa/menuitem.mm @@ -21,19 +21,6 @@ #include "wx/osx/private.h" -@interface wxNSMenuItem : NSMenuItem -{ - wxMenuItemImpl* impl; -} - -- (void) setImplementation:(wxMenuItemImpl*) item; -- (wxMenuItemImpl*) implementation; - -- (void) clickedAction: (id) sender; -- (BOOL)validateMenuItem:(NSMenuItem *) menuItem; - -@end - @implementation wxNSMenuItem - (id) init diff --git a/src/osx/cocoa/notebook.mm b/src/osx/cocoa/notebook.mm index bf86c4fbdf..a0c65acb66 100644 --- a/src/osx/cocoa/notebook.mm +++ b/src/osx/cocoa/notebook.mm @@ -62,7 +62,7 @@ WXCOCOAIMPL_COMMON_INTERFACE wxWidgetCocoaImpl* viewimpl = [view implementation]; if ( viewimpl ) { - wxNotebook* wxpeer = (wxNotebook*) viewimpl->GetWXPeer(); + // wxNotebook* wxpeer = (wxNotebook*) viewimpl->GetWXPeer(); } return YES; } diff --git a/src/osx/cocoa/statbox.mm b/src/osx/cocoa/statbox.mm index 6f7fecfc38..c05dc97365 100644 --- a/src/osx/cocoa/statbox.mm +++ b/src/osx/cocoa/statbox.mm @@ -18,20 +18,7 @@ @implementation wxNSBox -- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation -{ - impl = theImplementation; -} - -- (wxWidgetCocoaImpl*) implementation -{ - return impl; -} - -- (BOOL) isFlipped -{ - return NO; -} +WXCOCOAIMPL_COMMON_IMPLEMENTATION @end diff --git a/src/osx/cocoa/textctrl.mm b/src/osx/cocoa/textctrl.mm index 16881be7c7..61b8506db8 100644 --- a/src/osx/cocoa/textctrl.mm +++ b/src/osx/cocoa/textctrl.mm @@ -53,12 +53,64 @@ WXCOCOAIMPL_COMMON_IMPLEMENTATION +- (id)initWithFrame:(NSRect)frame +{ + [super initWithFrame:frame]; + impl = NULL; + [self setDelegate: self]; + [self setTarget: self]; +// [self setAction: @selector(enterAction:)]; + return self; +} + // use our common calls - (void) setTitle:(NSString *) title { [self setStringValue: title]; } +/* +- (void)controlTextDidChange:(NSNotification *)aNotification +{ + if ( impl ) + { + wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer(); + if ( wxpeer ) { + wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, wxpeer->GetId()); + event.SetEventObject( wxpeer ); + event.SetString( static_cast(wxpeer)->GetValue() ); + wxpeer->HandleWindowEvent( event ); + } + } +} + +- (void)controlTextDidEndEditing:(NSNotification *)aNotification +{ + if ( impl ) + { + wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer(); + if ( wxpeer ) { + wxFocusEvent event(wxEVT_KILL_FOCUS, wxpeer->GetId()); + event.SetEventObject( wxpeer ); + event.SetWindow( wxpeer ); + wxpeer->HandleWindowEvent( event ); + } + } +} +- (void) enterAction: (id) sender +{ + if ( impl ) + { + wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer(); + if ( wxpeer && (wxpeer->GetWindowStyle() & wxTE_PROCESS_ENTER) ) { + wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, wxpeer->GetId()); + event.SetEventObject( wxpeer ); + event.SetString( static_cast(wxpeer)->GetValue() ); + wxpeer->HandleWindowEvent( event ); + } + } +} +*/ @end wxNSTextFieldControl::wxNSTextFieldControl( wxTextCtrl *wxPeer, WXWidget w ) : wxWidgetCocoaImpl(wxPeer, w) diff --git a/src/osx/cocoa/window.mm b/src/osx/cocoa/window.mm index 524a5b2645..c50baa63a0 100644 --- a/src/osx/cocoa/window.mm +++ b/src/osx/cocoa/window.mm @@ -37,11 +37,6 @@ NSRect wxOSXGetFrameForControl( wxWindowMac* window , const wxPoint& pos , const - (void)drawRect: (NSRect) rect; -- (void)keyDown:(NSEvent *)event; -- (void)keyUp:(NSEvent *)event; -- (void)flagsChanged:(NSEvent *)event; -- (void)handleKeyEvent:(NSEvent *)event; - WXCOCOAIMPL_COMMON_INTERFACE - (BOOL) becomeFirstResponder; @@ -50,6 +45,26 @@ WXCOCOAIMPL_COMMON_INTERFACE @end // wxNSView +@interface NSView(PossibleMethods) +- (void)setImplementation:(wxWidgetCocoaImpl *)theImplementation; +- (void)setTitle:(NSString *)aString; +- (void)setStringValue:(NSString *)aString; +- (void)setIntValue:(int)anInt; +- (void)setFloatValue:(float)aFloat; +- (void)setDoubleValue:(double)aDouble; + +- (void)setMinValue:(double)aDouble; +- (void)setMaxValue:(double)aDouble; + +- (void)sizeToFit; + +- (BOOL)isEnabled; +- (void)setEnabled:(BOOL)flag; + +- (void)setImage:(NSImage *)image; +- (void)setControlSize:(NSControlSize)size; +@end + long wxOSXTranslateCocoaKey(unsigned short code, int unichar ) { long retval = code; @@ -155,7 +170,6 @@ void SetupMouseEvent( wxMouseEvent &wxevent , NSEvent * nsEvent ) // these parameters are not given for all events UInt32 button = [nsEvent buttonNumber]; UInt32 clickCount = [nsEvent clickCount]; - UInt32 mouseChord = 0; // TODO does this exist for cocoa wxevent.m_x = screenMouseLocation.x; wxevent.m_y = screenMouseLocation.y; @@ -166,6 +180,7 @@ void SetupMouseEvent( wxMouseEvent &wxevent , NSEvent * nsEvent ) wxevent.m_clickCount = clickCount; wxevent.SetTimestamp( [nsEvent timestamp] * 1000.0 ) ; /* + UInt32 mouseChord = 0; // TODO does this exist for cocoa // a control click is interpreted as a right click bool thisButtonIsFakeRight = false ; if ( button == kEventMouseButtonPrimary && (modifiers & controlKey) ) @@ -341,28 +356,6 @@ void SetupMouseEvent( wxMouseEvent &wxevent , NSEvent * nsEvent ) WXCOCOAIMPL_COMMON_IMPLEMENTATION -- (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); -} - - (BOOL) becomeFirstResponder { BOOL r = [super becomeFirstResponder]; @@ -657,6 +650,13 @@ void wxWidgetCocoaImpl::InstallEventHandler( WXWidget control ) { } +bool wxWidgetCocoaImpl::DoHandleKeyEvent(NSEvent *event) +{ + wxKeyEvent wxevent(wxEVT_KEY_DOWN); + SetupKeyEvent( wxevent, event ); + return GetWXPeer()->HandleWindowEvent(wxevent); +} + bool wxWidgetCocoaImpl::DoHandleMouseEvent(NSEvent *event) { NSPoint clickLocation;