From b466e85a7e81db84545bc44c83cbe4ccacd4fe8e Mon Sep 17 00:00:00 2001
From: Stefan Csomor <csomor@advancedconcepts.ch>
Date: Wed, 14 Jan 2009 08:58:59 +0000
Subject: [PATCH] routing native events first to the wx class and only if
 skipped call native handler

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58090 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---
 include/wx/osx/cocoa/private.h | 114 +++++++++++++++++++--------------
 src/osx/cocoa/button.mm        |  17 +----
 src/osx/cocoa/choice.mm        |  22 ++-----
 src/osx/cocoa/gauge.mm         |  21 +-----
 src/osx/cocoa/glcanvas.mm      |  22 ++-----
 src/osx/cocoa/notebook.mm      |  21 +-----
 src/osx/cocoa/scrolbar.mm      |  22 ++-----
 src/osx/cocoa/slider.mm        |  22 ++-----
 src/osx/cocoa/spinbutt.mm      |  22 ++-----
 src/osx/cocoa/srchctrl.mm      |  19 ++----
 src/osx/cocoa/textctrl.mm      |  15 +----
 src/osx/cocoa/window.mm        |  32 ++-------
 12 files changed, 106 insertions(+), 243 deletions(-)

diff --git a/include/wx/osx/cocoa/private.h b/include/wx/osx/cocoa/private.h
index d9ccabc652..26f1a90a50 100644
--- a/include/wx/osx/cocoa/private.h
+++ b/include/wx/osx/cocoa/private.h
@@ -117,7 +117,7 @@ public :
 
     void                InstallEventHandler( WXWidget control = NULL );
     
-    virtual void        DoHandleMouseEvent(NSEvent *event); 
+    virtual bool        DoHandleMouseEvent(NSEvent *event); 
 
 protected:
     WXWidget m_osxView;
@@ -190,42 +190,6 @@ protected :
     extern NSPoint wxToNSPoint( NSView* parent, const wxPoint& p );
     extern wxPoint wxFromNSPoint( NSView* parent, const NSPoint& p );
     
-    // used for many wxControls
-    
-    @interface wxNSButton : NSButton
-    {
-        wxWidgetCocoaImpl* impl;
-    }
-
-    - (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation;
-    - (wxWidgetCocoaImpl*) implementation;
-    - (BOOL) isFlipped;
-    - (void) clickedAction: (id) sender;
-
-    @end
-
-    @interface wxNSBox : NSBox
-    {
-        wxWidgetCocoaImpl* impl;
-    }
-
-    - (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation;
-    - (wxWidgetCocoaImpl*) implementation;
-    - (BOOL) isFlipped;
-
-    @end
-
-    @interface wxNSTextField : NSTextField
-    {
-        wxWidgetCocoaImpl* impl;
-    }
-
-    - (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation;
-    - (wxWidgetCocoaImpl*) implementation;
-    - (BOOL) isFlipped;
-
-    @end
-
     NSRect WXDLLIMPEXP_CORE wxOSXGetFrameForControl( wxWindowMac* window , const wxPoint& pos , const wxSize &size , 
         bool adjustForOrigin = true );
         
@@ -238,37 +202,91 @@ protected :
         -(void)mouseUp:(NSEvent *)event ;\
         -(void)rightMouseUp:(NSEvent *)event ;\
         -(void)otherMouseUp:(NSEvent *)event ;\
-        -(void)handleMouseEvent:(NSEvent *)event;
 
     #define WXCOCOAIMPL_COMMON_MOUSE_IMPLEMENTATION -(void)mouseDown:(NSEvent *)event \
         {\
-            [self handleMouseEvent:event];\
+            if ( !impl->DoHandleMouseEvent(event) )\
+                [super mouseDown:event];\
         }\
         -(void)rightMouseDown:(NSEvent *)event\
         {\
-            [self handleMouseEvent:event];\
+            if ( !impl->DoHandleMouseEvent(event) )\
+                [super rightMouseDown:event];\
         }\
         -(void)otherMouseDown:(NSEvent *)event\
         {\
-            [self handleMouseEvent:event];\
+            if ( !impl->DoHandleMouseEvent(event) )\
+                [super otherMouseDown:event];\
         }\
         -(void)mouseUp:(NSEvent *)event\
         {\
-            [self handleMouseEvent:event];\
+            if ( !impl->DoHandleMouseEvent(event) )\
+                [super mouseUp:event];\
         }\
         -(void)rightMouseUp:(NSEvent *)event\
         {\
-            [self handleMouseEvent:event];\
+            if ( !impl->DoHandleMouseEvent(event) )\
+                [super rightMouseUp:event];\
         }\
         -(void)otherMouseUp:(NSEvent *)event\
         {\
-            [self handleMouseEvent:event];\
-        }\
-        -(void)handleMouseEvent:(NSEvent *)event\
-        {\
-            impl->DoHandleMouseEvent(event);\
+            if ( !impl->DoHandleMouseEvent(event) )\
+                [super otherMouseUp:event];\
         }
         
+    #define WXCOCOAIMPL_COMMON_MEMBERS wxWidgetCocoaImpl* impl;
+    
+    #define WXCOCOAIMPL_COMMON_INTERFACE \
+        - (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation;\
+        - (wxWidgetCocoaImpl*) implementation;\
+        - (BOOL) isFlipped;\
+        WXCOCOAIMPL_COMMON_MOUSE_INTERFACE
+
+    #define WXCOCOAIMPL_COMMON_IMPLEMENTATION WXCOCOAIMPL_COMMON_MOUSE_IMPLEMENTATION \
+        - (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation\
+        {\
+            impl = theImplementation;\
+        }\
+        - (wxWidgetCocoaImpl*) implementation\
+        {\
+            return impl;\
+        }\
+        - (BOOL) isFlipped\
+        {\
+            return YES;\
+        }\
+
+    // used for many wxControls
+    
+    @interface wxNSButton : NSButton
+    {
+        WXCOCOAIMPL_COMMON_MEMBERS
+    }
+
+    WXCOCOAIMPL_COMMON_INTERFACE
+    - (void) clickedAction: (id) sender;
+
+    @end
+
+    @interface wxNSBox : NSBox
+    {
+        WXCOCOAIMPL_COMMON_MEMBERS
+    }
+
+    WXCOCOAIMPL_COMMON_INTERFACE
+
+    @end
+
+    @interface wxNSTextField : NSTextField
+    {
+       WXCOCOAIMPL_COMMON_MEMBERS
+    }
+
+    WXCOCOAIMPL_COMMON_INTERFACE
+    
+    @end
+
+
 #endif // __OBJC__
 
 // NSCursor
diff --git a/src/osx/cocoa/button.mm b/src/osx/cocoa/button.mm
index 60c1c45bf4..ffe3c6e397 100644
--- a/src/osx/cocoa/button.mm
+++ b/src/osx/cocoa/button.mm
@@ -132,6 +132,8 @@ wxSize wxButton::GetDefaultSize()
     return self;
 }
 
+WXCOCOAIMPL_COMMON_IMPLEMENTATION
+
 - (void) clickedAction: (id) sender
 {
     if ( impl )
@@ -142,21 +144,6 @@ wxSize wxButton::GetDefaultSize()
     }
 }
 
-- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation
-{
-    impl = theImplementation;
-}
-
-- (wxWidgetCocoaImpl*) implementation
-{
-    return impl;
-}
-
-- (BOOL) isFlipped
-{
-    return YES;
-}
-
 - (int) intValue
 {
     switch ( [self state] )
diff --git a/src/osx/cocoa/choice.mm b/src/osx/cocoa/choice.mm
index 931a7308d4..01ba759f82 100644
--- a/src/osx/cocoa/choice.mm
+++ b/src/osx/cocoa/choice.mm
@@ -24,12 +24,11 @@
 
 @interface wxNSPopUpButton : NSPopUpButton
 {
-    wxWidgetCocoaImpl* impl;
+    WXCOCOAIMPL_COMMON_MEMBERS
 }
 
-- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation;
-- (wxWidgetCocoaImpl*) implementation;
-- (BOOL) isFlipped;
+WXCOCOAIMPL_COMMON_INTERFACE
+
 - (void) clickedAction: (id) sender;
 
 @end
@@ -55,20 +54,7 @@
     }
 }
 
-- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation
-{
-    impl = theImplementation;
-}
-
-- (wxWidgetCocoaImpl*) implementation
-{
-    return impl;
-}
-
-- (BOOL) isFlipped
-{
-    return YES;
-}
+WXCOCOAIMPL_COMMON_IMPLEMENTATION
 
 - (int) intValue
 {
diff --git a/src/osx/cocoa/gauge.mm b/src/osx/cocoa/gauge.mm
index 77189ce3d5..2620e53035 100644
--- a/src/osx/cocoa/gauge.mm
+++ b/src/osx/cocoa/gauge.mm
@@ -19,12 +19,10 @@
 
 @interface wxNSProgressIndicator : NSProgressIndicator
 {
-    wxWidgetCocoaImpl* impl;
+    WXCOCOAIMPL_COMMON_MEMBERS
 }
 
-- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation;
-- (wxWidgetImpl*) implementation;
-- (BOOL) isFlipped;
+WXCOCOAIMPL_COMMON_INTERFACE
 
 @end
 
@@ -37,20 +35,7 @@
     return self;
 }
 
-- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation
-{
-    impl = theImplementation;
-}
-
-- (wxWidgetCocoaImpl*) implementation
-{
-    return impl;
-}
-
-- (BOOL) isFlipped
-{
-    return YES;
-}
+WXCOCOAIMPL_COMMON_IMPLEMENTATION
 
 @end
 
diff --git a/src/osx/cocoa/glcanvas.mm b/src/osx/cocoa/glcanvas.mm
index 4e6654452c..e088ede061 100644
--- a/src/osx/cocoa/glcanvas.mm
+++ b/src/osx/cocoa/glcanvas.mm
@@ -229,14 +229,13 @@ bool wxGLContext::SetCurrent(const wxGLCanvas& win) const
 
 @interface wxNSCustomOpenGLView : NSView
 {
-    wxWidgetCocoaImpl* impl;
+    WXCOCOAIMPL_COMMON_MEMBERS
     NSOpenGLContext* context;
 }
 
 - (id)initWithFrame:(NSRect)frame;
-- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation;
-- (wxWidgetCocoaImpl*) implementation;
-- (BOOL) isFlipped;
+
+WXCOCOAIMPL_COMMON_INTERFACE
 
 @end
 
@@ -249,20 +248,7 @@ bool wxGLContext::SetCurrent(const wxGLCanvas& win) const
     return self;
 }
 
-- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation
-{
-    impl = theImplementation;
-}
-
-- (wxWidgetCocoaImpl*) implementation
-{
-    return impl;
-}
-
-- (BOOL) isFlipped
-{
-    return YES;
-}
+WXCOCOAIMPL_COMMON_IMPLEMENTATION
 
 - (BOOL)isOpaque
 {
diff --git a/src/osx/cocoa/notebook.mm b/src/osx/cocoa/notebook.mm
index d4acf6b320..bf86c4fbdf 100644
--- a/src/osx/cocoa/notebook.mm
+++ b/src/osx/cocoa/notebook.mm
@@ -41,12 +41,10 @@
 
 @interface wxNSTabView : NSTabView
 {
-    wxWidgetCocoaImpl* impl;
+    WXCOCOAIMPL_COMMON_MEMBERS
 }
 
-- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation;
-- (wxWidgetCocoaImpl*) implementation;
-- (BOOL) isFlipped;
+WXCOCOAIMPL_COMMON_INTERFACE
 
 @end
 
@@ -85,20 +83,7 @@
 
 @implementation wxNSTabView
 
-- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation
-{
-    impl = theImplementation;
-}
-
-- (wxWidgetCocoaImpl*) implementation
-{
-    return impl;
-}
-
-- (BOOL) isFlipped
-{
-    return YES;
-}
+WXCOCOAIMPL_COMMON_IMPLEMENTATION
 
 @end
 
diff --git a/src/osx/cocoa/scrolbar.mm b/src/osx/cocoa/scrolbar.mm
index e2a7b01f98..ba5a6f1a57 100644
--- a/src/osx/cocoa/scrolbar.mm
+++ b/src/osx/cocoa/scrolbar.mm
@@ -23,12 +23,11 @@
 
 @interface wxNSScroller : NSScroller
 {
-    wxWidgetCocoaImpl* impl;
+    WXCOCOAIMPL_COMMON_MEMBERS
 }
 
-- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation;
-- (wxWidgetCocoaImpl*) implementation;
-- (BOOL) isFlipped;
+WXCOCOAIMPL_COMMON_INTERFACE
+
  - (void) clickedAction: (id) sender;
 
 @end
@@ -54,20 +53,7 @@
     }
 }
 
-- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation
-{
-    impl = theImplementation;
-}
-
-- (wxWidgetCocoaImpl*) implementation
-{
-    return impl ;
-}
-
-- (BOOL) isFlipped
-{
-    return YES;
-}
+WXCOCOAIMPL_COMMON_IMPLEMENTATION
 
 @end
 
diff --git a/src/osx/cocoa/slider.mm b/src/osx/cocoa/slider.mm
index 227435b77d..a56acbeadd 100644
--- a/src/osx/cocoa/slider.mm
+++ b/src/osx/cocoa/slider.mm
@@ -18,12 +18,11 @@
 
 @interface wxNSSlider : NSSlider
 {
-    wxWidgetCocoaImpl* impl;
+    WXCOCOAIMPL_COMMON_MEMBERS
 }
 
-- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation;
-- (wxWidgetCocoaImpl*) implementation;
-- (BOOL) isFlipped;
+WXCOCOAIMPL_COMMON_INTERFACE
+
  - (void) clickedAction: (id) sender;
 
 @end
@@ -49,20 +48,7 @@
     }
 }
 
-- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation
-{
-    impl = theImplementation;
-}
-
-- (wxWidgetCocoaImpl*) implementation
-{
-    return impl;
-}
-
-- (BOOL) isFlipped
-{
-    return YES;
-}
+WXCOCOAIMPL_COMMON_IMPLEMENTATION
 
 @end
 
diff --git a/src/osx/cocoa/spinbutt.mm b/src/osx/cocoa/spinbutt.mm
index 980fc81dda..872bef97a8 100644
--- a/src/osx/cocoa/spinbutt.mm
+++ b/src/osx/cocoa/spinbutt.mm
@@ -18,12 +18,11 @@
 
 @interface wxNSStepper : NSStepper
 {
-    wxWidgetCocoaImpl* impl;
+    WXCOCOAIMPL_COMMON_MEMBERS
 }
 
-- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation;
-- (wxWidgetCocoaImpl*) implementation;
-- (BOOL) isFlipped;
+WXCOCOAIMPL_COMMON_INTERFACE
+
  - (void) clickedAction: (id) sender;
 
 @end
@@ -49,20 +48,7 @@
     }
 }
 
-- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation
-{
-    impl = theImplementation;
-}
-
-- (wxWidgetCocoaImpl*) implementation
-{
-    return impl;
-}
-
-- (BOOL) isFlipped
-{
-    return YES;
-}
+WXCOCOAIMPL_COMMON_IMPLEMENTATION
 
 @end
 
diff --git a/src/osx/cocoa/srchctrl.mm b/src/osx/cocoa/srchctrl.mm
index 34758780b9..c1abb250ff 100644
--- a/src/osx/cocoa/srchctrl.mm
+++ b/src/osx/cocoa/srchctrl.mm
@@ -31,9 +31,11 @@
 
 @interface wxNSSearchField : NSSearchField
 {
-    wxWidgetCocoaImpl* impl;
+    WXCOCOAIMPL_COMMON_MEMBERS
 }
 
+WXCOCOAIMPL_COMMON_INTERFACE
+
 @end
 
 @implementation wxNSSearchField
@@ -47,20 +49,7 @@
     return self;
 }
 
-- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation
-{
-    impl = theImplementation;
-}
-
-- (wxWidgetCocoaImpl*) implementation
-{
-    return impl;
-}
-
-- (BOOL) isFlipped
-{
-    return YES;
-}
+WXCOCOAIMPL_COMMON_IMPLEMENTATION
 
 // use our common calls
 - (void) setTitle:(NSString *) title
diff --git a/src/osx/cocoa/textctrl.mm b/src/osx/cocoa/textctrl.mm
index 199f6de543..16881be7c7 100644
--- a/src/osx/cocoa/textctrl.mm
+++ b/src/osx/cocoa/textctrl.mm
@@ -51,20 +51,7 @@
 
 @implementation wxNSTextField
 
-- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation
-{
-    impl = theImplementation;
-}
-
-- (wxWidgetCocoaImpl*) implementation
-{
-    return impl;
-}
-
-- (BOOL) isFlipped
-{
-    return YES;
-}
+WXCOCOAIMPL_COMMON_IMPLEMENTATION
 
 // use our common calls
 - (void) setTitle:(NSString *) title
diff --git a/src/osx/cocoa/window.mm b/src/osx/cocoa/window.mm
index ce2fa679f8..524a5b2645 100644
--- a/src/osx/cocoa/window.mm
+++ b/src/osx/cocoa/window.mm
@@ -32,21 +32,18 @@ NSRect wxOSXGetFrameForControl( wxWindowMac* window , const wxPoint& pos , const
 
 @interface wxNSView : NSView
 {
-    wxWidgetCocoaImpl* impl;
+    WXCOCOAIMPL_COMMON_MEMBERS
 }
 
 - (void)drawRect: (NSRect) rect;
 
-WXCOCOAIMPL_COMMON_MOUSE_INTERFACE
-
 - (void)keyDown:(NSEvent *)event;
 - (void)keyUp:(NSEvent *)event;
 - (void)flagsChanged:(NSEvent *)event;
 - (void)handleKeyEvent:(NSEvent *)event;
 
-- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation;
-- (wxWidgetCocoaImpl*) implementation;
-- (BOOL) isFlipped;
+WXCOCOAIMPL_COMMON_INTERFACE
+
 - (BOOL) becomeFirstResponder;
 - (BOOL) resignFirstResponder;
 - (BOOL) canBecomeKeyView;
@@ -342,7 +339,7 @@ void SetupMouseEvent( wxMouseEvent &wxevent , NSEvent * nsEvent )
     }
 }
 
-WXCOCOAIMPL_COMMON_MOUSE_IMPLEMENTATION
+WXCOCOAIMPL_COMMON_IMPLEMENTATION
 
 - (void)keyDown:(NSEvent *)event
 {
@@ -366,22 +363,6 @@ WXCOCOAIMPL_COMMON_MOUSE_IMPLEMENTATION
     impl->GetWXPeer()->HandleWindowEvent(wxevent);
 }
 
-
-- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation
-{
-    impl = theImplementation;
-}
-
-- (wxWidgetCocoaImpl*) implementation
-{
-    return impl;
-}
-
-- (BOOL) isFlipped
-{
-    return YES;
-}
-
 - (BOOL) becomeFirstResponder
 {
     BOOL r = [super becomeFirstResponder];
@@ -676,7 +657,7 @@ void wxWidgetCocoaImpl::InstallEventHandler( WXWidget control )
 {
 }
 
-void wxWidgetCocoaImpl::DoHandleMouseEvent(NSEvent *event)
+bool wxWidgetCocoaImpl::DoHandleMouseEvent(NSEvent *event)
 {
     NSPoint clickLocation; 
     clickLocation = [m_osxView convertPoint:[event locationInWindow] fromView:nil]; 
@@ -685,7 +666,8 @@ void wxWidgetCocoaImpl::DoHandleMouseEvent(NSEvent *event)
     SetupMouseEvent( wxevent , event ) ;
     wxevent.m_x = pt.x;
     wxevent.m_y = pt.y;
-    GetWXPeer()->HandleWindowEvent(wxevent);
+
+    return GetWXPeer()->HandleWindowEvent(wxevent);
 }
 
 
-- 
2.47.2