]> git.saurik.com Git - wxWidgets.git/commitdiff
reworking event handling to redirect to c++ virtual functions
authorStefan Csomor <csomor@advancedconcepts.ch>
Sat, 7 Feb 2009 13:25:58 +0000 (13:25 +0000)
committerStefan Csomor <csomor@advancedconcepts.ch>
Sat, 7 Feb 2009 13:25:58 +0000 (13:25 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58704 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

29 files changed:
include/wx/osx/carbon/private.h
include/wx/osx/cocoa/private.h
include/wx/osx/cursor.h
include/wx/osx/dnd.h
include/wx/osx/window.h
src/osx/carbon/dnd.cpp
src/osx/carbon/font.cpp
src/osx/carbon/window.cpp
src/osx/cocoa/bmpbuttn.mm
src/osx/cocoa/button.mm
src/osx/cocoa/checkbox.mm
src/osx/cocoa/choice.mm
src/osx/cocoa/filedlg.mm
src/osx/cocoa/gauge.mm
src/osx/cocoa/glcanvas.mm
src/osx/cocoa/listbox.mm
src/osx/cocoa/notebook.mm
src/osx/cocoa/radiobut.mm
src/osx/cocoa/scrolbar.mm
src/osx/cocoa/slider.mm
src/osx/cocoa/spinbutt.mm
src/osx/cocoa/srchctrl.mm
src/osx/cocoa/statbox.mm
src/osx/cocoa/statline.mm
src/osx/cocoa/stattext.mm
src/osx/cocoa/textctrl.mm
src/osx/cocoa/tglbtn.mm
src/osx/cocoa/window.mm
src/osx/window_osx.cpp

index 5b36ffe55aa207d7a2ea6ce9cf2bdce68ce28692..088fe282f3fa825e4a6037a0bd31c13ab8a6c5b1 100644 (file)
@@ -455,7 +455,7 @@ public :
 
     virtual OSStatus SetTabEnabled( SInt16 tabNo , bool enable );
 
-    void InstallEventHandler( WXWidget control = NULL );
+    virtual void InstallEventHandler( WXWidget control = NULL );
 protected :
     WXEVENTHANDLERREF    m_macControlEventHandler ;
     ControlRef  m_controlRef;
index d1c7059d7e9a1e57f4becbc4fc1a8d4bec5361e7..507816b18217b0b1c723116bba4591fcff5d44ce 100644 (file)
@@ -127,8 +127,28 @@ public :
     virtual bool        DoHandleKeyEvent(NSEvent *event); 
     virtual void        DoNotifyFocusEvent(bool receivedFocus); 
 
+    void                SetFlipped(bool flipped);
+
+    virtual unsigned int        draggingEntered(void* sender, WXWidget slf, void* _cmd);
+    virtual void                draggingExited(void* sender, WXWidget slf, void* _cmd);
+    virtual unsigned int        draggingUpdated(void* sender, WXWidget slf, void* _cmd);
+    virtual bool                performDragOperation(void* sender, WXWidget slf, void* _cmd);
+    virtual void                mouseEvent(WX_NSEvent event, WXWidget slf, void* _cmd);
+    virtual void                keyEvent(WX_NSEvent event, WXWidget slf, void* _cmd);
+    virtual bool                performKeyEquivalent(WX_NSEvent event, WXWidget slf, void* _cmd);
+    virtual bool                becomeFirstResponder(WXWidget slf, void* _cmd);
+    virtual bool                resignFirstResponder(WXWidget slf, void* _cmd);
+    virtual void                resetCursorRects(WXWidget slf, void* _cmd);
+    virtual bool                isFlipped(WXWidget slf, void* _cmd);
+    virtual void                drawRect(void* rect, WXWidget slf, void* _cmd);
+    
+    virtual void                clickedAction(WXWidget slf, void* _cmd, void* sender);
+    virtual void                doubleClickedAction(WXWidget slf, void* _cmd, void *sender);
+
 protected:
     WXWidget m_osxView;
+    bool m_isFlipped;
+    
     DECLARE_DYNAMIC_CLASS_NO_COPY(wxWidgetCocoaImpl)
 };
 
@@ -203,217 +223,24 @@ protected :
     NSRect WXDLLIMPEXP_CORE wxOSXGetFrameForControl( wxWindowMac* window , const wxPoint& pos , const wxSize &size , 
         bool adjustForOrigin = true );
         
-    // common code snippets for cocoa implementations
-    // later to be done using injection in method table
-        
-    #define WXCOCOAIMPL_COMMON_EVENTS_INTERFACE -(void)mouseDown:(NSEvent *)event ;\
-        - (void)rightMouseDown:(NSEvent *)event ;\
-        - (void)otherMouseDown:(NSEvent *)event ;\
-        - (void)mouseUp:(NSEvent *)event ;\
-        - (void)rightMouseUp:(NSEvent *)event ;\
-        - (void)otherMouseUp:(NSEvent *)event ;\
-        - (void)mouseMoved:(NSEvent *)event;\
-        - (void)mouseDragged:(NSEvent *)event;\
-        - (void)rightMouseDragged:(NSEvent *)event;\
-        - (void)otherMouseDragged:(NSEvent *)event;\
-        - (void)scrollWheel:(NSEvent *)theEvent;\
-        - (void)mouseEntered:(NSEvent *)event;\
-        - (void)mouseExited:(NSEvent *)event;\
-        - (void)keyDown:(NSEvent *)event;\
-        - (void)keyUp:(NSEvent *)event;\
-        - (BOOL)performKeyEquivalent:(NSEvent *)event;\
-        - (void)flagsChanged:(NSEvent *)event;\
-        - (BOOL)becomeFirstResponder;\
-        - (BOOL)resignFirstResponder;\
-        - (void)resetCursorRects;
-
-
-    #define WXCOCOAIMPL_COMMON_EVENTS_IMPLEMENTATION_NO_MOUSEDOWN        -(void)rightMouseDown:(NSEvent *)event\
-        {\
-            if ( !impl->DoHandleMouseEvent(event) )\
-                [super rightMouseDown:event];\
-        }\
-        -(void)otherMouseDown:(NSEvent *)event\
-        {\
-            if ( !impl->DoHandleMouseEvent(event) )\
-                [super otherMouseDown:event];\
-        }\
-        -(void)mouseUp:(NSEvent *)event\
-        {\
-            if ( !impl->DoHandleMouseEvent(event) )\
-                [super mouseUp:event];\
-        }\
-        -(void)rightMouseUp:(NSEvent *)event\
-        {\
-            if ( !impl->DoHandleMouseEvent(event) )\
-                [super rightMouseUp:event];\
-        }\
-        -(void)otherMouseUp:(NSEvent *)event\
-        {\
-            if ( !impl->DoHandleMouseEvent(event) )\
-                [super otherMouseUp:event];\
-        }\
-        -(void)mouseMoved:(NSEvent *)event\
-        {\
-            if ( !impl->DoHandleMouseEvent(event) )\
-                [super mouseMoved:event];\
-        }\
-        -(void)mouseDragged:(NSEvent *)event\
-        {\
-            if ( !impl->DoHandleMouseEvent(event) )\
-                [super mouseDragged:event];\
-        }\
-        -(void)rightMouseDragged:(NSEvent *)event\
-        {\
-            if ( !impl->DoHandleMouseEvent(event) )\
-                [super rightMouseDragged:event];\
-        }\
-        -(void)otherMouseDragged:(NSEvent *)event\
-        {\
-            if ( !impl->DoHandleMouseEvent(event) )\
-                [super otherMouseDragged:event];\
-        }\
-        -(void)scrollWheel:(NSEvent *)event\
-        {\
-            if ( !impl->DoHandleMouseEvent(event) )\
-                [super scrollWheel:event];\
-        }\
-        -(void)mouseEntered:(NSEvent *)event\
-        {\
-            if ( !impl->DoHandleMouseEvent(event) )\
-                [super mouseEntered:event];\
-        }\
-        -(void)mouseExited:(NSEvent *)event\
-        {\
-            if ( !impl->DoHandleMouseEvent(event) )\
-                [super mouseExited:event];\
-        }\
-        -(BOOL)performKeyEquivalent:(NSEvent *)event\
-        {\
-            if ( !impl->DoHandleKeyEvent(event) )\
-                return [super performKeyEquivalent:event];\
-            return YES;\
-        }\
-        -(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];\
-        }\
-        - (BOOL) becomeFirstResponder\
-        {\
-            BOOL r = [super becomeFirstResponder];\
-            if ( r )\
-                impl->DoNotifyFocusEvent( true );\
-            return r;\
-        }\
-        - (BOOL) resignFirstResponder\
-        {\
-            BOOL r = [super resignFirstResponder];\
-            if ( r )\
-                impl->DoNotifyFocusEvent( false );\
-            return r;\
-        }\
-        - (void) resetCursorRects\
-        {\
-            if ( impl )\
-            {\
-                wxWindow* wxpeer = impl->GetWXPeer();\
-                if ( wxpeer )\
-                {\
-                    NSCursor *cursor = (NSCursor*)wxpeer->GetCursor().GetHCURSOR();\
-                    if (cursor == NULL)\
-                        [super resetCursorRects];\
-                    else\
-                        [self addCursorRect: [self bounds]\
-                            cursor: cursor];\
-                }\
-            }\
-        }
-
-    #define WXCOCOAIMPL_COMMON_EVENTS_IMPLEMENTATION -(void)mouseDown:(NSEvent *)event \
-        {\
-            if ( !impl->DoHandleMouseEvent(event) )\
-                [super mouseDown:event];\
-        }\
-        WXCOCOAIMPL_COMMON_EVENTS_IMPLEMENTATION_NO_MOUSEDOWN
-
-    #define WXCOCOAIMPL_COMMON_MEMBERS wxWidgetCocoaImpl* impl;
-    
-    #define WXCOCOAIMPL_COMMON_INTERFACE \
-        - (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation;\
-        - (wxWidgetCocoaImpl*) implementation;\
-        - (BOOL) isFlipped;\
-        WXCOCOAIMPL_COMMON_EVENTS_INTERFACE
-
-    #define WXCOCOAIMPL_COMMON_IMPLEMENTATION_BASE - (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation\
-        {\
-            impl = theImplementation;\
-        }\
-        - (wxWidgetCocoaImpl*) implementation\
-        {\
-            return impl;\
-        }\
-
-    #define WXCOCOAIMPL_COMMON_IMPLEMENTATION WXCOCOAIMPL_COMMON_EVENTS_IMPLEMENTATION \
-        WXCOCOAIMPL_COMMON_IMPLEMENTATION_BASE \
-        - (BOOL) isFlipped\
-        {\
-            return YES;\
-        }
-
-    #define WXCOCOAIMPL_COMMON_IMPLEMENTATION_NO_MOUSEDOWN WXCOCOAIMPL_COMMON_EVENTS_IMPLEMENTATION_NO_MOUSEDOWN \
-        WXCOCOAIMPL_COMMON_IMPLEMENTATION_BASE \
-        - (BOOL) isFlipped\
-        {\
-            return YES;\
-        }
-
-
-     #define WXCOCOAIMPL_COMMON_IMPLEMENTATION_NOT_FLIPPED WXCOCOAIMPL_COMMON_EVENTS_IMPLEMENTATION \
-        WXCOCOAIMPL_COMMON_IMPLEMENTATION_BASE \
-        - (BOOL) isFlipped\
-        {\
-            return NO;\
-        }
-
     // 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
 
     @interface wxNSMenu : NSMenu
@@ -438,6 +265,8 @@ protected :
     - (BOOL)validateMenuItem:(NSMenuItem *)menuItem;
 
     @end 
+    
+    void wxOSXCocoaClassAddWXMethods(Class c);
 
 #endif // __OBJC__
 
index fe0c01391c16d89ad548e27895a6a9c768b9fb45..cf00e0c8e477f86521b671782dd20072479a3390 100644 (file)
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        wx/mac/carbon/cursor.h
+// Name:        wx/osx/cursor.h
 // Purpose:     wxCursor class
 // Author:      Stefan Csomor
 // Modified by:
index dea6815a45f01cebbc4888547bc556f05f5b8f6b..dd91f63789af72ea37177f20783c7421fc34b433 100644 (file)
@@ -57,10 +57,9 @@ class WXDLLIMPEXP_CORE wxDropTarget: public wxDropTargetBase
     virtual bool GetData();
 
     bool CurrentDragHasSupportedFormat() ;
-    void SetCurrentDrag( void* drag ) { m_currentDrag = drag ; }
-    void* GetCurrentDrag() { return m_currentDrag ; }
+    void SetCurrentDragPasteboard( void* dragpasteboard ) { m_currentDragPasteboard = dragpasteboard ; }
   protected :
-    void* m_currentDrag ;
+    void* m_currentDragPasteboard ;
 };
 
 //-------------------------------------------------------------------------
@@ -93,13 +92,12 @@ public:
     virtual wxDragResult DoDragDrop(int flags = wxDrag_CopyOnly);
 
     wxWindow*     GetWindow() { return m_window ; }
-    void SetCurrentDrag( void* drag ) { m_currentDrag = drag ; }
-    void* GetCurrentDrag() { return m_currentDrag ; }
+    void SetCurrentDragPasteboard( void* dragpasteboard ) { m_currentDragPasteboard = dragpasteboard ; }
     bool MacInstallDefaultCursor(wxDragResult effect) ;
   protected :
 
     wxWindow        *m_window;
-    void* m_currentDrag ;
+    void* m_currentDragPasteboard ;
 };
 
 #endif // wxUSE_DRAG_AND_DROP
index 1137022d2163b2d409e3c9aa1619e5560c23c989..999f126e8aa6d316dfbaa3a8ba59fb53c2bae8c9 100644 (file)
@@ -138,7 +138,7 @@ public:
 
     // event handlers
     // --------------
-    void OnPaint( wxPaintEvent& event );
+
     void OnNcPaint( wxNcPaintEvent& event );
     void OnEraseBackground(wxEraseEvent& event );
     void OnMouseEvent( wxMouseEvent &event );
index 172b99a437fdab905440699a868a5d02db4a7cd5..0d195b15024cde87c8fad246b7f13d5a5d8664e5 100644 (file)
@@ -107,17 +107,10 @@ bool wxDropTarget::CurrentDragHasSupportedFormat()
         }
     }
 
-#if wxOSX_USE_CARBON
     if ( !supported )
     {
-        PasteboardRef   pasteboard;
-
-        if ( GetDragPasteboard( (DragReference)m_currentDrag, &pasteboard ) == noErr )
-        {
-            supported = m_dataObject->HasDataInPasteboard( pasteboard );
-        }
+        supported = m_dataObject->HasDataInPasteboard( m_currentDragPasteboard );
     }
-#endif
 
     return supported;
 }
@@ -166,17 +159,10 @@ bool wxDropTarget::GetData()
         }
     }
 
-#if wxOSX_USE_CARBON
     if ( !transferred )
     {
-        PasteboardRef   pasteboard;
-
-        if ( GetDragPasteboard(  (DragReference)m_currentDrag, &pasteboard ) == noErr )
-        {
-            transferred = m_dataObject->GetFromPasteboard( pasteboard );
-        }
+        transferred = m_dataObject->GetFromPasteboard( m_currentDragPasteboard );
     }
-#endif
 
     return transferred;
 }
@@ -369,7 +355,8 @@ pascal OSErr wxMacWindowDragTrackingHandler(
     DragAttributes attributes;
 
     GetDragAttributes( theDrag, &attributes );
-
+    PasteboardRef   pasteboard = 0;
+    GetDragPasteboard( theDrag, &pasteboard );
     wxNonOwnedWindow* toplevel = wxNonOwnedWindow::GetFromWXWindow( (WXWindow) theWindow );
 
     bool optionDown = GetCurrentKeyModifiers() & optionKey;
@@ -427,7 +414,7 @@ pascal OSErr wxMacWindowDragTrackingHandler(
 #ifndef __LP64__
                             HideDragHilite( theDrag );
 #endif
-                            trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag );
+                            trackingGlobals->m_currentTarget->SetCurrentDragPasteboard( pasteboard );
                             trackingGlobals->m_currentTarget->OnLeave();
                             trackingGlobals->m_currentTarget = NULL;
                             trackingGlobals->m_currentTargetWindow = NULL;
@@ -442,7 +429,7 @@ pascal OSErr wxMacWindowDragTrackingHandler(
                         {
                             if ( trackingGlobals->m_currentTarget )
                             {
-                                trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag );
+                                trackingGlobals->m_currentTarget->SetCurrentDragPasteboard( pasteboard );
                                 result = trackingGlobals->m_currentTarget->OnEnter( localx, localy, result );
                             }
 
@@ -467,7 +454,7 @@ pascal OSErr wxMacWindowDragTrackingHandler(
                 {
                     if ( trackingGlobals->m_currentTarget )
                     {
-                        trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag );
+                        trackingGlobals->m_currentTarget->SetCurrentDragPasteboard( pasteboard );
                         result = trackingGlobals->m_currentTarget->OnDragOver( localx, localy, result );
                     }
                 }
@@ -517,7 +504,7 @@ pascal OSErr wxMacWindowDragTrackingHandler(
 
             if (trackingGlobals->m_currentTarget)
             {
-                trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag );
+                trackingGlobals->m_currentTarget->SetCurrentDragPasteboard( pasteboard );
                 trackingGlobals->m_currentTarget->OnLeave();
 #ifndef __LP64__
                 HideDragHilite( theDrag );
@@ -545,7 +532,9 @@ pascal OSErr wxMacWindowDragReceiveHandler(
         Point mouse, localMouse;
         int localx, localy;
 
-        trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag );
+        PasteboardRef   pasteboard = 0;
+        GetDragPasteboard( theDrag, &pasteboard );
+        trackingGlobals->m_currentTarget->SetCurrentDragPasteboard( pasteboard );
         GetDragMouse( theDrag, &mouse, 0L );
         localMouse = mouse;
         localx = localMouse.h;
index d1c72dac0714815c868eacbfb2e42536a5f12378..3d295d4bb901df0cd264ce2f6c82d0d22ec2f416 100644 (file)
@@ -424,7 +424,7 @@ void wxFontRefData::MacFindFont()
                 // QD selection algorithm is the fastest by orders of magnitude on 10.5
                 if ( m_faceName.IsAscii() )
                 {
-                    uint8 qdstyle = 0;
+                    uint8_t qdstyle = 0;
                     if (m_weight == wxFONTWEIGHT_BOLD)
                         qdstyle |= bold;
                     if (m_style == wxFONTSTYLE_ITALIC || m_style == wxFONTSTYLE_SLANT)
index 67227916f37906da08d1935047680c8d2afcaeba..f56dde4393a6fe15c7e59d41301fe75866d980c8 100644 (file)
@@ -210,8 +210,6 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl
                             CGContextClearRect( cgContext, bounds );
                         }
 
-
-
                         if ( thisWindow->MacDoRedraw( updateRgn , cEvent.GetTicks() ) )
                             result = noErr ;
 
index ab3433bd7fb7134dc7edcc86e088aa5b89cba3ae..fd5f716ff8a2361dc59e78e44512b9109cf3e625 100644 (file)
@@ -50,7 +50,6 @@ wxWidgetImplType* wxWidgetImpl::CreateBitmapButton( wxWindowMac* wxpeer,
     [v setImage:bitmap.GetNSImage() ];
     [v setButtonType:NSMomentaryPushInButton];
     wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
-    [v setImplementation:c];
     return c;
 }
 
index ee7070142cc58d4c41ed3dcdb3d30513d7e2c719..7df36925de73d3967c6b5c0dcddeac82068391ac 100644 (file)
@@ -123,24 +123,13 @@ wxSize wxButton::GetDefaultSize()
 
 @implementation wxNSButton
 
-- (id)initWithFrame:(NSRect)frame
++ (void)initialize
 {
-    [super initWithFrame:frame];
-    impl = NULL;
-    [self setTarget: self];
-    [self setAction: @selector(clickedAction:)];
-    return self;
-}
-
-WXCOCOAIMPL_COMMON_IMPLEMENTATION
-
-- (void) clickedAction: (id) sender
-{
-    if ( impl )
+    static BOOL initialized = NO;
+    if (!initialized) 
     {
-        wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
-        if ( wxpeer )
-            wxpeer->OSXHandleClicked(0);
+        initialized = YES;
+        wxOSXCocoaClassAddWXMethods( self );
     }
 }
 
@@ -199,7 +188,6 @@ wxWidgetImplType* wxWidgetImpl::CreateButton( wxWindowMac* wxpeer,
     
     [v setButtonType:NSMomentaryPushInButton];
     wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
-    [v setImplementation:c];
     return c;
 /*
     OSStatus err;
@@ -278,6 +266,5 @@ wxWidgetImplType* wxWidgetImpl::CreateDisclosureTriangle( wxWindowMac* wxpeer,
     [v setTitle:wxCFStringRef( label).AsNSString()];
     [v setImagePosition:NSImageRight];
     wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
-    [v setImplementation:c];
     return c;
 }
index 8e79189ed1eef16421a4a733b0553bfad09dbe80..b100875515f3c29d18bf8a73d177244b4823559a 100644 (file)
@@ -33,7 +33,6 @@ wxWidgetImplType* wxWidgetImpl::CreateCheckBox( wxWindowMac* wxpeer,
         [v setAllowsMixedState:YES];
         
     wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
-    [v setImplementation:c];
     return c;
 }
 
index 5ebf6a244537ed94f484afa0b27a78158cb54ec2..197e4d758f7d7fdefb8429ddbd679e8d9b6467d8 100644 (file)
 
 @interface wxNSPopUpButton : NSPopUpButton
 {
-    WXCOCOAIMPL_COMMON_MEMBERS
 }
 
-WXCOCOAIMPL_COMMON_INTERFACE
-
-- (void) clickedAction: (id) sender;
-
 @end
 
 @implementation wxNSPopUpButton
 
-- (id)initWithFrame:(NSRect)frame pullsDown:(BOOL) pd
-{
-    [super initWithFrame:frame pullsDown:pd];
-    impl = NULL;
-    [self setTarget: self];
-    [self setAction: @selector(clickedAction:)];
-    return self;
-}
-
-- (void) clickedAction: (id) sender
++ (void)initialize
 {
-    if ( impl )
+    static BOOL initialized = NO;
+    if (!initialized) 
     {
-        wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
-        if ( wxpeer )
-            wxpeer->OSXHandleClicked(0);
+        initialized = YES;
+        wxOSXCocoaClassAddWXMethods( self );
     }
 }
 
-WXCOCOAIMPL_COMMON_IMPLEMENTATION
-
 - (int) intValue
 {
    return [self indexOfSelectedItem];
@@ -81,7 +65,6 @@ wxWidgetImplType* wxWidgetImpl::CreateChoice( wxWindowMac* wxpeer,
     wxNSPopUpButton* v = [[wxNSPopUpButton alloc] initWithFrame:r pullsDown:NO];
     [v setMenu: menu->GetHMenu()];
     wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
-    [v setImplementation:c];
     return c;
 }
 
index c212ecea36b3046b63079136db86e3f146aabd78..462ee154e477e7d604f7fcb7e385642a0cf11f63 100644 (file)
 // implementation
 // ============================================================================
 
+// Open Items:
+// - support for old style MacOS creator / type combos
+// - parameter support for descending into packages as directories (setTreatsFilePackagesAsDirectories)
+
 IMPLEMENT_CLASS(wxFileDialog, wxFileDialogBase)
 
 wxFileDialog::wxFileDialog(
@@ -123,8 +127,8 @@ NSArray* GetTypesFromFilter( const wxString filter )
             wxCFStringRef cfext(extension);
             [types addObject: (NSString*)cfext.AsNSString()  ];
 #if 0
+            // add support for classic fileType / creator here
             wxUint32 fileType, creator;
-
             // extension -> mactypes
 #endif
         }
@@ -152,7 +156,10 @@ int wxFileDialog::ShowModal()
         // makes things more convenient:
         [sPanel setCanCreateDirectories:YES];
         [sPanel setMessage:cf.AsNSString()];
+        // if we should be able to descend into pacakges we must somehow
+        // be able to pass this in
         [sPanel setTreatsFilePackagesAsDirectories:NO];
+        [sPanel setCanSelectHiddenExtension:YES];
 
         if ( HasFlag(wxFD_OVERWRITE_PROMPT) )
         {
@@ -206,181 +213,4 @@ int wxFileDialog::ShowModal()
     return result;
 }
 
-#if 0
-
-    wxASSERT(CreateBase(parent,wxID_ANY,pos,wxDefaultSize,style,wxDefaultValidator,wxDialogNameStr));
-
-    if ( parent )
-        parent->AddChild(this);
-
-    m_cocoaNSWindow = nil;
-    m_cocoaNSView = nil;
-
-    //Init the wildcard array
-    m_wildcards = [[NSMutableArray alloc] initWithCapacity:0];
-
-    //If the user requests to save - use a NSSavePanel
-    //else use a NSOpenPanel
-    if (HasFlag(wxFD_SAVE))
-    {
-        SetNSPanel([NSSavePanel savePanel]);
-
-        [GetNSSavePanel() setTitle:wxNSStringWithWxString(message)];
-
-        [GetNSSavePanel() setPrompt:@"Save"];
-        [GetNSSavePanel() setTreatsFilePackagesAsDirectories:YES];
-        [GetNSSavePanel() setCanSelectHiddenExtension:YES];
-
-//        Cached as per-app in obj-c
-//        [GetNSSavePanel() setExtensionHidden:YES];
-
-        //
-        // NB:  Note that only Panther supports wildcards
-        // with save dialogs - not that wildcards in save
-        // dialogs are all that useful, anyway :)
-        //
-    }
-    else //m_dialogStyle & wxFD_OPEN
-    {
-        SetNSPanel([NSOpenPanel openPanel]);
-        [m_cocoaNSWindow setTitle:wxNSStringWithWxString(message)];
-
-        [(NSOpenPanel*)m_cocoaNSWindow setAllowsMultipleSelection:(HasFlag(wxFD_MULTIPLE))];
-        [(NSOpenPanel*)m_cocoaNSWindow setResolvesAliases:YES];
-        [(NSOpenPanel*)m_cocoaNSWindow setCanChooseFiles:YES];
-        [(NSOpenPanel*)m_cocoaNSWindow setCanChooseDirectories:NO];
-        [GetNSSavePanel() setPrompt:@"Open"];
-
-        //convert wildcards - open panel only takes file extensions -
-        //no actual wildcards here :)
-        size_t lastwcpos = 0;
-        bool bDescription = true;
-        size_t i;
-        for(i = wildCard.find('|');
-                i != wxString::npos;
-                i = wildCard.find('|', lastwcpos+1))
-        {
-            size_t oldi = i;
-
-            if(!bDescription)
-            {
-                bDescription = !bDescription;
-
-                //work backwards looking for a period
-                while(i != lastwcpos && wildCard[--i] != '.') {}
-
-                if(i == lastwcpos)
-                {
-                    //no extension - can't use this wildcard
-                    lastwcpos = oldi;
-                    continue;
-                }
-
-                [m_wildcards addObject:wxNSStringWithWxString(wildCard.substr(i+1, oldi-i-1))];
-            }
-            else
-                bDescription = !bDescription;
-            lastwcpos = oldi;
-        }
-
-        if (!bDescription)
-        {
-            //get last wildcard
-            size_t oldi = wildCard.length();
-            i = oldi;
-
-            //work backwards looking for a period
-            while(i != lastwcpos && wildCard[--i] != '.') {}
-
-            if(i != lastwcpos)
-                [m_wildcards addObject:wxNSStringWithWxString(wildCard.substr(i+1, oldi-i-1))];
-        }
-
-        if ([m_wildcards count] == 0)
-        {
-            [m_wildcards release];
-            m_wildcards = nil;
-        }
-    }
-}
-
-wxFileDialog::~wxFileDialog()
-{
-    [m_wildcards release];
-}
-
-void wxFileDialog::GetPaths(wxArrayString& paths) const
-{
-    paths.Empty();
-
-    wxString dir(m_dir);
-    if ( m_dir.Last() != _T('\\') )
-        dir += _T('\\');
-
-    size_t count = m_fileNames.GetCount();
-    for ( size_t n = 0; n < count; n++ )
-    {
-        if (wxFileName(m_fileNames[n]).IsAbsolute())
-            paths.Add(m_fileNames[n]);
-        else
-            paths.Add(dir + m_fileNames[n]);
-    }
-}
-
-void wxFileDialog::GetFilenames(wxArrayString& files) const
-{
-    files = m_fileNames;
-}
-
-void wxFileDialog::SetPath(const wxString& path)
-{
-    wxString ext;
-    wxFileName::SplitPath(path, &m_dir, &m_fileName, &ext);
-    if ( !ext.empty() )
-        m_fileName << _T('.') << ext;
-}
-
-int wxFileDialog::ShowModal()
-{
-    wxAutoNSAutoreleasePool thePool;
-
-    m_fileNames.Empty();
-
-    int nResult;
-
-    if (HasFlag(wxFD_SAVE))
-    {
-        nResult = [GetNSSavePanel()
-                    runModalForDirectory:wxNSStringWithWxString(m_dir)
-                    file:wxNSStringWithWxString(m_fileName)];
-
-        if (nResult == NSOKButton)
-        {
-            m_fileNames.Add(wxStringWithNSString([GetNSSavePanel() filename]));
-            m_path = m_fileNames[0];
-        }
-    }
-    else //m_dialogStyle & wxFD_OPEN
-    {
-        nResult = [(NSOpenPanel*)m_cocoaNSWindow
-                    runModalForDirectory:wxNSStringWithWxString(m_dir)
-                    file:wxNSStringWithWxString(m_fileName)
-                    types:m_wildcards];
-
-        if (nResult == NSOKButton)
-        {
-            for(unsigned i = 0; i < [[(NSOpenPanel*)m_cocoaNSWindow filenames] count]; ++i)
-            {
-                m_fileNames.Add(wxStringWithNSString([[(NSOpenPanel*)m_cocoaNSWindow filenames] objectAtIndex:(i)]));
-            }
-
-            m_path = m_fileNames[0];
-        }
-    }
-
-    return nResult == NSOKButton ? wxID_OK : wxID_CANCEL;
-}
-
-#endif
-
 #endif // wxUSE_FILEDLG
index 2620e530357f786a36836b41e82364687c11860a..895a70cae809a09f7ff0741cb27fbc1c2a81e368 100644 (file)
 
 @interface wxNSProgressIndicator : NSProgressIndicator
 {
-    WXCOCOAIMPL_COMMON_MEMBERS
 }
 
-WXCOCOAIMPL_COMMON_INTERFACE
-
 @end
 
 @implementation wxNSProgressIndicator
 
-- (id)initWithFrame:(NSRect)frame
++ (void)initialize
 {
-    [super initWithFrame:frame];
-    impl = NULL;
-    return self;
+    static BOOL initialized = NO;
+    if (!initialized) 
+    {
+        initialized = YES;
+        wxOSXCocoaClassAddWXMethods( self );
+    }
 }
 
-WXCOCOAIMPL_COMMON_IMPLEMENTATION
-
 @end
 
 class wxOSXGaugeCocoaImpl : public wxWidgetCocoaImpl
@@ -98,7 +96,6 @@ wxWidgetImplType* wxWidgetImpl::CreateGauge( wxWindowMac* wxpeer,
     [v setIndeterminate:FALSE];
     [v setDoubleValue: (double) value];
     wxWidgetCocoaImpl* c = new wxOSXGaugeCocoaImpl( wxpeer, v );
-    [v setImplementation:c];
     return c;
 }
 
index e088ede061fa7e95f27632a927dfcf52364b93d6..83c99ce833f7778d1ac7b66bd9fbf8287ce8c455 100644 (file)
@@ -229,27 +229,23 @@ bool wxGLContext::SetCurrent(const wxGLCanvas& win) const
 
 @interface wxNSCustomOpenGLView : NSView
 {
-    WXCOCOAIMPL_COMMON_MEMBERS
     NSOpenGLContext* context;
 }
 
-- (id)initWithFrame:(NSRect)frame;
-
-WXCOCOAIMPL_COMMON_INTERFACE
-
 @end
 
 @implementation wxNSCustomOpenGLView
 
-- (id)initWithFrame:(NSRect)frame
++ (void)initialize
 {
-    [super initWithFrame:frame];
-    impl = NULL;
-    return self;
+    static BOOL initialized = NO;
+    if (!initialized) 
+    {
+        initialized = YES;
+        wxOSXCocoaClassAddWXMethods( self );
+    }
 }
 
-WXCOCOAIMPL_COMMON_IMPLEMENTATION
-
 - (BOOL)isOpaque
 {
     return YES;
@@ -279,7 +275,6 @@ bool wxGLCanvas::Create(wxWindow *parent,
     NSRect r = wxOSXGetFrameForControl( this, pos , size ) ;
     wxNSCustomOpenGLView* v = [[wxNSCustomOpenGLView alloc] initWithFrame:r];
     m_peer = new wxWidgetCocoaImpl( this, v );
-    [v setImplementation:m_peer];
 
     MacPostControlCreate(pos, size) ;
 */
index 270d3ba4df2532ac0e9aa4365fb4762ec66e4c4b..01bb7fc73f6d99164c4f06728b1955b03e974282 100644 (file)
@@ -14,6 +14,7 @@
 #if wxUSE_LISTBOX
 
 #include "wx/listbox.h"
+#include "wx/dnd.h"
 
 #ifndef WX_PRECOMP
     #include "wx/log.h"
@@ -54,14 +55,8 @@ class wxListWidgetCocoaImpl;
 
 @interface wxNSTableView : NSTableView
 {
-    wxListWidgetCocoaImpl* impl;
 }
 
-- (void)setImplementation: (wxListWidgetCocoaImpl *) theImplementation;
-- (wxListWidgetCocoaImpl*) implementation;
-- (void)clickedAction: (id) sender;
-- (void)doubleClickedAction: (id) sender;
-
 @end
 
 //
@@ -147,6 +142,9 @@ public :
     }
     virtual void            UpdateLine( unsigned int n, wxListWidgetColumn* col = NULL ) ;
     virtual void            UpdateLineToEnd( unsigned int n);
+
+    virtual void            clickedAction(WXWidget slf, void* _cmd, void *sender);
+    virtual void            doubleClickedAction(void* _cmd);
 protected :
     wxNSTableView*          m_tableView ;
     
@@ -274,55 +272,13 @@ protected:
 
 @implementation wxNSTableView
 
-- (void)setImplementation: (wxListWidgetCocoaImpl *) theImplementation
-{
-    impl = theImplementation;
-}
-
-- (wxListWidgetCocoaImpl*) implementation
-{
-    return impl;
-}
-
-- (id) init
++ (void)initialize
 {
-    [super init];
-    impl = NULL;
-    [self setTarget: self];
-    [self setAction: @selector(clickedAction:)];
-    [self setDoubleAction: @selector(doubleClickedAction:)];
-    return self;
-}
-
-- (void) clickedAction: (id) sender
-{
-    if ( impl )
+    static BOOL initialized = NO;
+    if (!initialized) 
     {
-        wxListBox *list = static_cast<wxListBox*> ( impl->GetWXPeer());
-        wxCHECK_RET( list != NULL , wxT("Listbox expected"));
-
-        wxCommandEvent event( wxEVT_COMMAND_LISTBOX_SELECTED, list->GetId() );
-
-        int sel = [self clickedRow];
-        if ((sel < 0) || (sel > (int) list->GetCount()))  // OS X can select an item below the last item (why?)
-           return;
-           
-        list->HandleLineEvent( sel, false );
-    }
-}
-
-- (void) doubleClickedAction: (id) sender
-{
-    if ( impl )
-    {
-        wxListBox *list = static_cast<wxListBox*> ( impl->GetWXPeer());
-        wxCHECK_RET( list != NULL , wxT("Listbox expected"));
-
-        int sel = [self clickedRow];
-        if ((sel < 0) || (sel > (int) list->GetCount()))  // OS X can select an item below the last item (why?)
-           return;
-
-        list->HandleLineEvent( sel, true );
+        initialized = YES;
+        wxOSXCocoaClassAddWXMethods( self );
     }
 }
 
@@ -335,6 +291,7 @@ protected:
 wxListWidgetCocoaImpl::wxListWidgetCocoaImpl( wxWindowMac* peer, NSScrollView* view, wxNSTableView* tableview, wxNSTableDataSource* data ) :
     wxWidgetCocoaImpl( peer, view ), m_tableView(tableview), m_dataSource(data)
 {
+    InstallEventHandler( tableview );
 }
 
 wxListWidgetCocoaImpl::~wxListWidgetCocoaImpl()
@@ -514,6 +471,31 @@ void wxListWidgetCocoaImpl::UpdateLineToEnd( unsigned int n)
     [m_tableView reloadData];
 }
 
+void wxListWidgetCocoaImpl::clickedAction(WXWidget slf,void* _cmd, void *sender)
+{
+    wxListBox *list = static_cast<wxListBox*> ( GetWXPeer());
+    wxCHECK_RET( list != NULL , wxT("Listbox expected"));
+
+    wxCommandEvent event( wxEVT_COMMAND_LISTBOX_SELECTED, list->GetId() );
+
+    int sel = [m_tableView clickedRow];
+    if ((sel < 0) || (sel > (int) list->GetCount()))  // OS X can select an item below the last item (why?)
+       return;
+       
+    list->HandleLineEvent( sel, false );
+}
+
+void wxListWidgetCocoaImpl::doubleClickedAction(void* _cmd)
+{
+    wxListBox *list = static_cast<wxListBox*> ( GetWXPeer());
+    wxCHECK_RET( list != NULL , wxT("Listbox expected"));
+
+    int sel = [m_tableView clickedRow];
+    if ((sel < 0) || (sel > (int) list->GetCount()))  // OS X can select an item below the last item (why?)
+       return;
+
+    list->HandleLineEvent( sel, true );
+}
 
 // accessing content
 
@@ -555,7 +537,11 @@ wxWidgetImplType* wxWidgetImpl::CreateListBox( wxWindowMac* wxpeer,
     wxNSTableDataSource* ds = [[ wxNSTableDataSource alloc] init];
     [tableview setDataSource:ds];
     wxListWidgetCocoaImpl* c = new wxListWidgetCocoaImpl( wxpeer, scrollview, tableview, ds );
-    [tableview setImplementation:c];
+
+    // temporary hook for dnd
+    [tableview registerForDraggedTypes:[NSArray arrayWithObjects:
+        NSStringPboardType, NSFilenamesPboardType, NSTIFFPboardType, NSPICTPboardType, NSPDFPboardType, nil]];
+
     [ds setImplementation:c];
     return c;
 }
index 2c47ce8133fa7ccc49808e642bd54df75673a49c..36abc047db64ffafc2c02cd4a22c3c116668597d 100644 (file)
 
 @interface wxNSTabView : NSTabView
 {
-    WXCOCOAIMPL_COMMON_MEMBERS
 }
 
-WXCOCOAIMPL_COMMON_INTERFACE
-
 @end
 
 @implementation wxTabViewController
@@ -59,7 +56,8 @@ WXCOCOAIMPL_COMMON_INTERFACE
 - (BOOL)tabView:(NSTabView *)tabView shouldSelectTabViewItem:(NSTabViewItem *)tabViewItem
 {
     wxNSTabView* view = (wxNSTabView*) tabView;
-    wxWidgetCocoaImpl* viewimpl = [view implementation];
+    wxWidgetCocoaImpl* viewimpl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( view );
+
     if ( viewimpl )
     {
         // wxNotebook* wxpeer = (wxNotebook*) viewimpl->GetWXPeer();
@@ -71,7 +69,7 @@ WXCOCOAIMPL_COMMON_INTERFACE
 
 {
     wxNSTabView* view = (wxNSTabView*) tabView;
-    wxWidgetCocoaImpl* viewimpl = [view implementation];
+    wxWidgetCocoaImpl* viewimpl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( view );
     if ( viewimpl )
     {
         wxNotebook* wxpeer = (wxNotebook*) viewimpl->GetWXPeer();
@@ -83,7 +81,15 @@ WXCOCOAIMPL_COMMON_INTERFACE
 
 @implementation wxNSTabView
 
-WXCOCOAIMPL_COMMON_IMPLEMENTATION
++ (void)initialize
+{
+    static BOOL initialized = NO;
+    if (!initialized) 
+    {
+        initialized = YES;
+        wxOSXCocoaClassAddWXMethods( self );
+    }
+}
 
 @end
 
@@ -244,7 +250,6 @@ wxWidgetImplType* wxWidgetImpl::CreateTabView( wxWindowMac* wxpeer,
     wxNSTabView* v = [[wxNSTabView alloc] initWithFrame:r];
     [v setTabViewType:tabstyle];
     wxWidgetCocoaImpl* c = new wxCocoaTabView( wxpeer, v );
-    [v setImplementation:c];
     [v setDelegate: controller];
     return c;
 }
index 681f6cf9c9f9faa4fb3a8cd6e55b1df4ac7e28d7..1ca43e661525133ddf7ae6476c8c5ca891872873 100644 (file)
@@ -31,7 +31,6 @@ wxWidgetImplType* wxWidgetImpl::CreateRadioButton( wxWindowMac* wxpeer,
     [v setButtonType:NSRadioButton];    
         
     wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
-    [v setImplementation:c];
     return c;
 }
 
index 74168cf6e00b4cd8269728a52f0a9dcb3c69e144..533f5e92dc493e8a95cbae3b4c61b42d00f9e948 100644 (file)
 
 @interface wxNSScroller : NSScroller
 {
-    WXCOCOAIMPL_COMMON_MEMBERS
 }
-
-WXCOCOAIMPL_COMMON_INTERFACE
-
- - (void) clickedAction: (id) sender;
-
 @end
 
 @implementation wxNSScroller
 
-- (id)initWithFrame:(NSRect)frame
++ (void)initialize
 {
-    [super initWithFrame:frame];
-    impl = NULL;
-    [self setTarget: self];
-    [self setAction: @selector(clickedAction:)];
-    return self;
-}
-
-WXCOCOAIMPL_COMMON_IMPLEMENTATION_NO_MOUSEDOWN
-
-// we will have a mouseDown, then in the native 
-// implementation of mouseDown the tracking code
-// is calling clickedAction, therefore we wire this
-// to thumbtrack and only after super mouseDown 
-// returns we will call the thumbrelease
-
-- (void) clickedAction: (id) sender
-{
-    if ( impl )
-    {
-        wxEventType scrollEvent = wxEVT_NULL;
-        switch ([self hitPart]) 
-        {
-        case NSScrollerIncrementLine:
-            scrollEvent = wxEVT_SCROLL_LINEDOWN;
-            break;
-        case NSScrollerIncrementPage:
-            scrollEvent = wxEVT_SCROLL_PAGEDOWN;
-            break;
-        case NSScrollerDecrementLine:
-            scrollEvent = wxEVT_SCROLL_LINEUP;
-            break;
-        case NSScrollerDecrementPage:
-            scrollEvent = wxEVT_SCROLL_PAGEUP;
-            break;
-        case NSScrollerKnob:
-        case NSScrollerKnobSlot:
-            scrollEvent = wxEVT_SCROLL_THUMBTRACK;
-            break;
-        case NSScrollerNoPart:
-        default:
-            return;
-        }
-
-        wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
-        if ( wxpeer )
-            wxpeer->TriggerScrollEvent(scrollEvent);
-    }
-}
-
--(void)mouseDown:(NSEvent *)event 
-{
-    if ( !impl->DoHandleMouseEvent(event) )
-        [super mouseDown:event];
-
-    // send a release event in case we've been tracking the thumb
-    NSScrollerPart hit = [self hitPart];
-    if ( impl && (hit == NSScrollerKnob || hit == NSScrollerKnobSlot) )
+    static BOOL initialized = NO;
+    if (!initialized) 
     {
-        wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
-        if ( wxpeer )
-            wxpeer->TriggerScrollEvent(wxEVT_SCROLL_THUMBRELEASE);
+        initialized = YES;
+        wxOSXCocoaClassAddWXMethods(self);
     }
 }
 
@@ -118,7 +56,7 @@ public :
     void    SetScrollThumb( wxInt32 value, wxInt32 thumbSize ) 
     {
         double v = ((double) value)/m_maximum;
-        double t = ((double) thumbSize)/m_maximum;
+        double t = ((double) thumbSize)/(m_maximum+thumbSize);
 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
         [(wxNSScroller*) m_osxView setFloatValue:v knobProportion:t];
 #else
@@ -127,19 +65,76 @@ public :
 #endif
     }
     
-    wxInt32 GetValue() const
+    virtual wxInt32 GetValue() const
     {
         return [(wxNSScroller*) m_osxView floatValue] * m_maximum;
     }
     
-    wxInt32 GetMaximum() const
+    virtual wxInt32 GetMaximum() const
     {
         return m_maximum;
     }
+
+    virtual void clickedAction(WXWidget slf, void* _cmd, void *sender);
+    virtual void mouseEvent(WX_NSEvent event, WXWidget slf, void* _cmd);
 protected:
     wxInt32 m_maximum;
 };
 
+// we will have a mouseDown, then in the native 
+// implementation of mouseDown the tracking code
+// is calling clickedAction, therefore we wire this
+// to thumbtrack and only after super mouseDown 
+// returns we will call the thumbrelease
+
+void wxOSXScrollBarCocoaImpl::clickedAction( WXWidget slf, void *_cmd, void *sender)
+{
+    wxEventType scrollEvent = wxEVT_NULL;
+    switch ([(NSScroller*)m_osxView hitPart]) 
+    {
+    case NSScrollerIncrementLine:
+        scrollEvent = wxEVT_SCROLL_LINEDOWN;
+        break;
+    case NSScrollerIncrementPage:
+        scrollEvent = wxEVT_SCROLL_PAGEDOWN;
+        break;
+    case NSScrollerDecrementLine:
+        scrollEvent = wxEVT_SCROLL_LINEUP;
+        break;
+    case NSScrollerDecrementPage:
+        scrollEvent = wxEVT_SCROLL_PAGEUP;
+        break;
+    case NSScrollerKnob:
+    case NSScrollerKnobSlot:
+        scrollEvent = wxEVT_SCROLL_THUMBTRACK;
+        break;
+    case NSScrollerNoPart:
+    default:
+        return;
+    }
+
+    wxWindow* wxpeer = (wxWindow*) GetWXPeer();
+    if ( wxpeer )
+        wxpeer->TriggerScrollEvent(scrollEvent);
+}
+
+void wxOSXScrollBarCocoaImpl::mouseEvent(WX_NSEvent event, WXWidget slf, void *_cmd)
+{
+    wxWidgetCocoaImpl::mouseEvent(event, slf, _cmd);
+    
+    // send a release event in case we've been tracking the thumb
+    if ( strcmp( sel_getName((SEL) _cmd) , "mouseDown:") == 0 )
+    {
+        NSScrollerPart hit = [(NSScroller*)m_osxView hitPart];
+        if ( (hit == NSScrollerKnob || hit == NSScrollerKnobSlot) )
+        {
+            wxWindow* wxpeer = (wxWindow*) GetWXPeer();
+            if ( wxpeer )
+                wxpeer->OSXHandleClicked(0);
+        }
+    }
+}
+
 wxWidgetImplType* wxWidgetImpl::CreateScrollBar( wxWindowMac* wxpeer, 
                                     wxWindowMac* parent, 
                                     wxWindowID id, 
@@ -152,7 +147,6 @@ wxWidgetImplType* wxWidgetImpl::CreateScrollBar( wxWindowMac* wxpeer,
     wxNSScroller* v = [[wxNSScroller alloc] initWithFrame:r];
 
     wxWidgetCocoaImpl* c = new wxOSXScrollBarCocoaImpl( wxpeer, v );
-    [v setImplementation:c];
     [v setEnabled:YES];
     return c;
 }
index cb94d5cf52485e06fbcc9d93729ee8c23bff992c..a627ce9febdf0bacb698fe3fe17d113a1497a275 100644 (file)
 
 @interface wxNSSlider : NSSlider
 {
-    WXCOCOAIMPL_COMMON_MEMBERS
 }
-
-WXCOCOAIMPL_COMMON_INTERFACE
-
- - (void) clickedAction: (id) sender;
-
 @end
 
 @implementation wxNSSlider
 
-- (id)initWithFrame:(NSRect)frame
++ (void)initialize
 {
-    [super initWithFrame:frame];
-    impl = NULL;
-    [self setTarget: self];
-    [self setAction: @selector(clickedAction:)];
-    return self;
+    static BOOL initialized = NO;
+    if (!initialized) 
+    {
+        initialized = YES;
+        wxOSXCocoaClassAddWXMethods(self);
+    }
 }
 
-WXCOCOAIMPL_COMMON_IMPLEMENTATION_NO_MOUSEDOWN
+@end
+
+class wxSliderCocoaImpl : public wxWidgetCocoaImpl
+{
+public :
+    wxSliderCocoaImpl(wxWindowMac* peer , WXWidget w) :
+        wxWidgetCocoaImpl(peer, w)
+    {
+    }
+    
+    ~wxSliderCocoaImpl()
+    {
+    }
+
+    virtual void clickedAction(WXWidget slf, void* _cmd, void *sender);
+    virtual void mouseEvent(WX_NSEvent event, WXWidget slf, void* _cmd);
+};
 
 // we will have a mouseDown, then in the native 
 // implementation of mouseDown the tracking code
@@ -46,30 +57,26 @@ WXCOCOAIMPL_COMMON_IMPLEMENTATION_NO_MOUSEDOWN
 // to thumbtrack and only after super mouseDown 
 // returns we will call the thumbrelease
 
-- (void) clickedAction: (id) sender
+void wxSliderCocoaImpl::clickedAction( WXWidget slf, void *_cmd, void *sender)
 {
-    if ( impl )
-    {
-        wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
-        if ( wxpeer )
-            wxpeer->TriggerScrollEvent(wxEVT_SCROLL_THUMBTRACK);
-    }
+    wxWindow* wxpeer = (wxWindow*) GetWXPeer();
+    if ( wxpeer )
+        wxpeer->TriggerScrollEvent(wxEVT_SCROLL_THUMBTRACK);
 }
 
--(void)mouseDown:(NSEvent *)event 
+void wxSliderCocoaImpl::mouseEvent(WX_NSEvent event, WXWidget slf, void *_cmd)
 {
-    if ( !impl->DoHandleMouseEvent(event) )
-        [super mouseDown:event];
-
-    if ( impl )
+    wxWidgetCocoaImpl::mouseEvent(event, slf, _cmd);
+    
+    if ( strcmp( sel_getName((SEL) _cmd) , "mouseDown:") == 0 )
     {
-        wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
+        wxWindow* wxpeer = (wxWindow*) GetWXPeer();
         if ( wxpeer )
             wxpeer->OSXHandleClicked(0);
     }
 }
 
-@end
+
 
 wxWidgetImplType* wxWidgetImpl::CreateSlider( wxWindowMac* wxpeer, 
                                     wxWindowMac* parent, 
@@ -102,8 +109,7 @@ wxWidgetImplType* wxWidgetImpl::CreateSlider( wxWindowMac* wxpeer,
     [v setMinValue: minimum];
     [v setMaxValue: maximum];
     [v setFloatValue: (double) value];
-    wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
-    [v setImplementation:c];
+    wxWidgetCocoaImpl* c = new wxSliderCocoaImpl( wxpeer, v );
     return c;
 }
 
index da57bbea789765a65db782a19cf1d07585621a23..2104c0e7c2e20d3670c5d47d2ad7f19f71881cc4 100644 (file)
 
 @interface wxNSStepper : NSStepper
 {
-    WXCOCOAIMPL_COMMON_MEMBERS
-    int formerValue;
 }
-
-WXCOCOAIMPL_COMMON_INTERFACE
-
- - (void) clickedAction: (id) sender;
-
 @end
 
 @implementation wxNSStepper
 
-- (id)initWithFrame:(NSRect)frame
++ (void)initialize
 {
-    [super initWithFrame:frame];
-    impl = NULL;
-    formerValue = 0;
-    [self setTarget: self];
-    [self setAction: @selector(clickedAction:)];
-    return self;
+    static BOOL initialized = NO;
+    if (!initialized) 
+    {
+        initialized = YES;
+        wxOSXCocoaClassAddWXMethods(self);
+    }
 }
 
-- (void) clickedAction: (id) sender
+@end
+
+class wxSpinButtonCocoaImpl : public wxWidgetCocoaImpl
 {
-    if ( impl )
+public :
+    wxSpinButtonCocoaImpl(wxWindowMac* peer , WXWidget w) :
+        wxWidgetCocoaImpl(peer, w)
+    {
+        m_formerValue = 0;
+    }
+    
+    ~wxSpinButtonCocoaImpl()
     {
-        wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
-        if ( wxpeer )
-        {
-            // because wx expects to be able to veto 
-            // a change we must revert the value change
-            // and expose it
-            int currentValue = [self intValue];
-            [self setIntValue:formerValue];
-            int inc = currentValue-formerValue;
-            
-            // adjust for wrap arounds
-            if ( inc > 1 )
-                inc = -1;
-            else if (inc < -1 )
-                inc = 1;
-                
-            if ( inc == 1 )
-                wxpeer->TriggerScrollEvent(wxEVT_SCROLL_LINEUP);
-            else if ( inc == -1 )
-                wxpeer->TriggerScrollEvent(wxEVT_SCROLL_LINEDOWN);
-
-            formerValue = [self intValue];
-        }
     }
-}
 
--(void)mouseDown:(NSEvent *)event 
+    virtual void clickedAction(WXWidget slf, void* _cmd, void *sender);
+    virtual void mouseEvent(WX_NSEvent event, WXWidget slf, void* _cmd);
+private:
+    int m_formerValue;
+};
+
+void wxSpinButtonCocoaImpl::mouseEvent(WX_NSEvent event, WXWidget slf, void *_cmd)
 {
-    formerValue = [self intValue];
-    if ( !impl->DoHandleMouseEvent(event) )
-        [super mouseDown:event];
+    
+    // send a release event in case we've been tracking the thumb
+    if ( strcmp( sel_getName((SEL) _cmd) , "mouseDown:") == 0 )
+    {
+        m_formerValue = [(NSStepper*)m_osxView intValue];
+    }
+
+    wxWidgetCocoaImpl::mouseEvent(event, slf, _cmd);
 }
 
-WXCOCOAIMPL_COMMON_IMPLEMENTATION_NO_MOUSEDOWN
+void wxSpinButtonCocoaImpl::clickedAction( WXWidget slf, void *_cmd, void *sender)
+{
+    wxWindow* wxpeer = (wxWindow*) GetWXPeer();
+    if ( wxpeer )
+    {
+        // because wx expects to be able to veto 
+        // a change we must revert the value change
+        // and expose it
+        int currentValue = [(NSStepper*)m_osxView intValue];
+        [(NSStepper*)m_osxView setIntValue:m_formerValue];
+        int inc = currentValue-m_formerValue;
+        
+        // adjust for wrap arounds
+        if ( inc > 1 )
+            inc = -1;
+        else if (inc < -1 )
+            inc = 1;
+            
+        if ( inc == 1 )
+            wxpeer->TriggerScrollEvent(wxEVT_SCROLL_LINEUP);
+        else if ( inc == -1 )
+            wxpeer->TriggerScrollEvent(wxEVT_SCROLL_LINEDOWN);
 
-@end
+        m_formerValue = [(NSStepper*)m_osxView intValue];
+    }
+}
 
 wxWidgetImplType* wxWidgetImpl::CreateSpinButton( wxWindowMac* wxpeer, 
                                     wxWindowMac* parent, 
@@ -102,8 +114,7 @@ wxWidgetImplType* wxWidgetImpl::CreateSpinButton( wxWindowMac* wxpeer,
     if ( style & wxSP_WRAP )
         [v setValueWraps:YES];
     
-    wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
-    [v setImplementation:c];
+    wxWidgetCocoaImpl* c = new wxSpinButtonCocoaImpl( wxpeer, v );
     return c;
 }
 
index c1abb250ffce51000f9272e86c4295ba9c9dc435..861605298e3a0f5228f6b47052e6ec68b0d2bd18 100644 (file)
 
 @interface wxNSSearchField : NSSearchField
 {
-    WXCOCOAIMPL_COMMON_MEMBERS
 }
 
-WXCOCOAIMPL_COMMON_INTERFACE
-
 @end
 
 @implementation wxNSSearchField
 
++ (void)initialize
+{
+    static BOOL initialized = NO;
+    if (!initialized) 
+    {
+        initialized = YES;
+        wxOSXCocoaClassAddWXMethods( self );
+    }
+}
+
 - (id)initWithFrame:(NSRect)frame
 {
     [super initWithFrame:frame];
-    impl = NULL;
     [self setTarget: self];
     [self setAction: @selector(searchAction:)];
     return self;
 }
 
-WXCOCOAIMPL_COMMON_IMPLEMENTATION
-
 // use our common calls
 - (void) setTitle:(NSString *) title
 {
@@ -59,6 +63,7 @@ WXCOCOAIMPL_COMMON_IMPLEMENTATION
 
 - (void) searchAction: (id) sender
 {
+    wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
     if ( impl )
     {
         wxSearchCtrl* wxpeer = dynamic_cast<wxSearchCtrl*>( impl->GetWXPeer() );
@@ -168,7 +173,6 @@ wxWidgetImplType* wxWidgetImpl::CreateSearchControl( wxTextCtrl* wxpeer,
 
     wxNSSearchFieldControl* c = new wxNSSearchFieldControl( wxpeer, v );
     c->SetStringValue( str );
-    [v setImplementation:c];
     return c;
 }
 
index 34c2f272466ee5251ffee427774b37ba0c969f2f..6c5bff4a67d7c01434a4accc8ad0fac41157f236 100644 (file)
 
 @implementation wxNSBox
 
-WXCOCOAIMPL_COMMON_IMPLEMENTATION_NOT_FLIPPED
++ (void)initialize
+{
+    static BOOL initialized = NO;
+    if (!initialized) 
+    {
+        initialized = YES;
+        wxOSXCocoaClassAddWXMethods( self );
+    }
+}
 
 @end
 
@@ -34,7 +42,7 @@ wxWidgetImplType* wxWidgetImpl::CreateGroupBox( wxWindowMac* wxpeer,
     NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
     wxNSBox* v = [[wxNSBox alloc] initWithFrame:r];
     wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
-    [v setImplementation:c];
+    c->SetFlipped(false);
     return c;
 }
 
index f57c1bb28fb0f13ae55e563937c6a5b9b0c11d82..fdff4b0c274baa7369e55309ffe83832f2363a80 100644 (file)
@@ -44,7 +44,6 @@ wxWidgetImplType* wxWidgetImpl::CreateStaticLine( wxWindowMac* wxpeer,
     NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
     wxNSBox* v = [[wxNSBox alloc] initWithFrame:r];
     wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
-    [v setImplementation:c];
     return c;
 }
 
index b3d5f89ebc39ffeddaec6915b4814e1c8b04690f..efb6e563439674fca253c04d628565590cc64e8e 100644 (file)
@@ -88,7 +88,6 @@ wxWidgetImplType* wxWidgetImpl::CreateStaticText( wxWindowMac* wxpeer,
     [v setDrawsBackground:NO];
 
     wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
-    [v setImplementation:c];
     return c;
 /*
     Rect bounds = wxMacGetBoundsForControl( wxpeer, pos, size );
index 3e5b8d87e79d5b7fd771bde8bfee1d3e2fc88d82..a9898bf349644d93fa78c0873b17fdd2607d49fd 100644 (file)
 
 @implementation wxNSTextField
 
-WXCOCOAIMPL_COMMON_IMPLEMENTATION
++ (void)initialize
+{
+    static BOOL initialized = NO;
+    if (!initialized) 
+    {
+        initialized = YES;
+        wxOSXCocoaClassAddWXMethods( self );
+    }
+}
 
 - (id)initWithFrame:(NSRect)frame
 {
     [super initWithFrame:frame];
-    impl = NULL;
     [self setDelegate: self];
     [self setTarget: self];
 //    [self setAction: @selector(enterAction:)];
@@ -190,7 +197,6 @@ wxWidgetImplType* wxWidgetImpl::CreateTextControl( wxTextCtrl* wxpeer,
     //[v setDrawsBackground:NO];
     
     wxWidgetCocoaImpl* c = new wxNSTextFieldControl( wxpeer, v );
-    [v setImplementation:c];
     return c;
 }
 
index 5db9b8e456099aa374f9bcb4f6feef201d23d13f..f5d052809e09c2d0f3b216620be1c65fa8174abb 100644 (file)
@@ -40,7 +40,6 @@ wxWidgetImplType* wxWidgetImpl::CreateToggleButton( wxWindowMac* wxpeer,
     [v setBezelStyle:NSRoundedBezelStyle];    
     [v setButtonType:NSOnOffButton];
     wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
-    [v setImplementation:c];
     return c;
 }
 
@@ -59,7 +58,6 @@ wxWidgetImplType* wxWidgetImpl::CreateBitmapToggleButton( wxWindowMac* wxpeer,
     [v setBezelStyle:NSRegularSquareBezelStyle];
     [v setButtonType:NSOnOffButton];
     wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
-    [v setImplementation:c];
     return c;
 }
 
index 44b70b7f01168a5e827a2aa31888294f70ca5701..fafa57b77ea5657242162e541b7c4d7a378364fe 100644 (file)
 #endif
 
 #ifdef __WXMAC__
-#include "wx/osx/private.h"
+    #include "wx/osx/private.h"
 #endif
 
 #if wxUSE_CARET
     #include "wx/caret.h"
 #endif
 
+#if wxUSE_DRAG_AND_DROP
+    #include "wx/dnd.h"
+#endif
+
+#include <objc/objc-runtime.h>
+
 NSRect wxOSXGetFrameForControl( wxWindowMac* window , const wxPoint& pos , const wxSize &size , bool adjustForOrigin )
 {
     int x, y, w, h ;
@@ -37,19 +43,13 @@ NSRect wxOSXGetFrameForControl( wxWindowMac* window , const wxPoint& pos , const
 
 @interface wxNSView : NSView
 {
-    WXCOCOAIMPL_COMMON_MEMBERS
 }
 
-- (void)drawRect: (NSRect) rect;
-
-WXCOCOAIMPL_COMMON_INTERFACE
-
 - (BOOL) canBecomeKeyView;
 
 @end // wxNSView
 
 @interface NSView(PossibleMethods) 
-- (void)setImplementation:(wxWidgetCocoaImpl *)theImplementation;
 - (void)setTitle:(NSString *)aString;
 - (void)setStringValue:(NSString *)aString;
 - (void)setIntValue:(int)anInt;
@@ -70,6 +70,10 @@ WXCOCOAIMPL_COMMON_INTERFACE
 - (void)setControlSize:(NSControlSize)size;
 
 - (id)contentView;
+
+- (void)setTarget:(id)anObject;
+- (void)setAction:(SEL)aSelector;
+- (void)setDoubleAction:(SEL)aSelector;
 @end 
 
 long wxOSXTranslateCocoaKey( int unichar )
@@ -336,87 +340,550 @@ void SetupMouseEvent( wxMouseEvent &wxevent , NSEvent * nsEvent )
 
 @implementation wxNSView
 
-#define OSX_DEBUG_DRAWING 0
++ (void)initialize
+{
+    static BOOL initialized = NO;
+    if (!initialized) 
+    {
+        initialized = YES;
+        wxOSXCocoaClassAddWXMethods( self );
+    }
+}
+
+- (BOOL) canBecomeKeyView
+{
+    return YES;
+}
+
+@end // wxNSView
+
+//
+// event handlers
+//
+
+#if wxUSE_DRAG_AND_DROP
+
+// see http://lists.apple.com/archives/Cocoa-dev/2005/Jul/msg01244.html
+// for details on the NSPasteboard -> PasteboardRef conversion
+
+NSDragOperation wxOSX_draggingEntered( id self, SEL _cmd, id <NSDraggingInfo>sender )
+{
+    wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
+    if (impl == NULL)
+        return NSDragOperationNone;
+        
+    return impl->draggingEntered(sender, self, _cmd);
+}
+
+void wxOSX_draggingExited( id self, SEL _cmd, id <NSDraggingInfo> sender )
+{
+    wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
+    if (impl == NULL)
+        return ;
+        
+    return impl->draggingExited(sender, self, _cmd);
+}
+
+NSDragOperation wxOSX_draggingUpdated( id self, SEL _cmd, id <NSDraggingInfo>sender )
+{
+    wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
+    if (impl == NULL)
+        return NSDragOperationNone;
+        
+    return impl->draggingUpdated(sender, self, _cmd);
+}
+
+BOOL wxOSX_performDragOperation( id self, SEL _cmd, id <NSDraggingInfo> sender )
+{
+    wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
+    if (impl == NULL)
+        return NSDragOperationNone;
+        
+    return impl->performDragOperation(sender, self, _cmd) ? YES:NO ;
+}
+
+void wxOSX_mouseEvent(NSView* self, SEL _cmd, NSEvent *event) 
+{
+    wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
+    if (impl == NULL)
+        return;
+        
+    impl->mouseEvent(event, self, _cmd);
+}
+
+void wxOSX_keyEvent(NSView* self, SEL _cmd, NSEvent *event) 
+{
+    wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
+    if (impl == NULL)
+        return;
+        
+    impl->keyEvent(event, self, _cmd);
+}
+
+BOOL wxOSX_performKeyEquivalent(NSView* self, SEL _cmd, NSEvent *event) 
+{
+    wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
+    if (impl == NULL)
+        return NO;
+        
+    return impl->performKeyEquivalent(event, self, _cmd);
+}
+
+BOOL wxOSX_becomeFirstResponder(NSView* self, SEL _cmd)
+{
+    wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
+    if (impl == NULL)
+        return NO;
+        
+    return impl->becomeFirstResponder(self, _cmd);
+}
+
+BOOL wxOSX_resignFirstResponder(NSView* self, SEL _cmd)
+{
+    wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
+    if (impl == NULL)
+        return NO;
+        
+    return impl->resignFirstResponder(self, _cmd);
+}
+
+void wxOSX_resetCursorRects(NSView* self, SEL _cmd)
+{
+    wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
+    if (impl == NULL)
+        return;
+        
+    impl->resetCursorRects(self, _cmd);
+}
+
+BOOL wxOSX_isFlipped(NSView* self, SEL _cmd)
+{
+    wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
+    if (impl == NULL)
+        return NO;
+        
+    return impl->isFlipped(self, _cmd) ? YES:NO;
+}
+
+void wxOSX_drawRect(NSView* self, SEL _cmd, NSRect rect)
+{
+    wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
+    if (impl == NULL)
+        return;
+        
+    return impl->drawRect(&rect, self, _cmd);
+}
+
+void wxOSX_clickedAction(NSView* self, SEL _cmd, id sender)
+{
+    wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
+    if (impl == NULL)
+        return;
+        
+    impl->clickedAction(self, _cmd, sender);
+}
+
+void wxOSX_doubleClickedAction(NSView* self, SEL _cmd, id sender)
+{
+    wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
+    if (impl == NULL)
+        return;
+        
+    impl->doubleClickedAction(self, _cmd, sender);
+}
 
-- (void)drawRect: (NSRect) rect
+unsigned int wxWidgetCocoaImpl::draggingEntered(void* s, WXWidget slf, void *_cmd)
 {
-    if ( impl )
+    id <NSDraggingInfo>sender = (id <NSDraggingInfo>) s;
+    NSPasteboard *pboard = [sender draggingPasteboard];
+    NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
+    
+    wxWindow* wxpeer = GetWXPeer();
+    if ( wxpeer == NULL )
+        return NSDragOperationNone;
+        
+    wxDropTarget* target = wxpeer->GetDropTarget();
+    if ( target == NULL )
+        return NSDragOperationNone;
+
+    wxDragResult result = wxDragNone;
+    wxPoint pt = wxFromNSPoint( m_osxView, [sender draggingLocation] );
+
+    if ( sourceDragMask & NSDragOperationLink )
+        result = wxDragLink;
+    else if ( sourceDragMask & NSDragOperationCopy )
+        result = wxDragCopy;
+    else if ( sourceDragMask & NSDragOperationMove )
+        result = wxDragMove;
+
+    PasteboardRef pboardRef;    
+    PasteboardCreate((CFStringRef)[pboard name], &pboardRef);
+    target->SetCurrentDragPasteboard(pboardRef);
+    result = target->OnEnter(pt.x, pt.y, result);
+    CFRelease(pboardRef);
+     
+    NSDragOperation nsresult = NSDragOperationNone;
+    switch (result )
     {
-        CGContextRef context = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
-        CGContextSaveGState( context );
-#if OSX_DEBUG_DRAWING
-        CGContextBeginPath( context );
-        CGContextMoveToPoint(context, 0, 0);
-        NSRect bounds = [self bounds];
-        CGContextAddLineToPoint(context, 10, 0);
-        CGContextMoveToPoint(context, 0, 0);
-        CGContextAddLineToPoint(context, 0, 10);
-        CGContextMoveToPoint(context, bounds.size.width, bounds.size.height);
-        CGContextAddLineToPoint(context, bounds.size.width, bounds.size.height-10);
-        CGContextMoveToPoint(context, bounds.size.width, bounds.size.height);
-        CGContextAddLineToPoint(context, bounds.size.width-10, bounds.size.height);
-        CGContextClosePath( context );
-        CGContextStrokePath(context);
-#endif
+        case wxDragLink:
+            nsresult = NSDragOperationLink;
+        case wxDragMove:
+            nsresult = NSDragOperationMove;
+        case wxDragCopy:
+            nsresult = NSDragOperationCopy;
+        default :
+            break;
+    }
+    return nsresult;
+}
 
-        if ( [ self isFlipped ] == NO )
-        {
-            CGContextTranslateCTM( context, 0,  [self bounds].size.height );
-            CGContextScaleCTM( context, 1, -1 );
-        }
+void wxWidgetCocoaImpl::draggingExited(void* s, WXWidget slf, void *_cmd)
+{
+    id <NSDraggingInfo>sender = (id <NSDraggingInfo>) s;
+    NSPasteboard *pboard = [sender draggingPasteboard];
+    
+    wxWindow* wxpeer = GetWXPeer();
+    if ( wxpeer == NULL )
+        return;
+        
+    wxDropTarget* target = wxpeer->GetDropTarget();
+    if ( target == NULL )
+        return;
+        
+    PasteboardRef pboardRef;    
+    PasteboardCreate((CFStringRef)[pboard name], &pboardRef);
+    target->SetCurrentDragPasteboard(pboardRef);
+    target->OnLeave();
+    CFRelease(pboardRef);
+ }
+
+unsigned int wxWidgetCocoaImpl::draggingUpdated(void* s, WXWidget slf, void *_cmd)
+{
+    id <NSDraggingInfo>sender = (id <NSDraggingInfo>) s;
+    NSPasteboard *pboard = [sender draggingPasteboard];
+    NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
         
-        wxRegion updateRgn;
-        const NSRect *rects;
-        NSInteger count;
+    wxWindow* wxpeer = GetWXPeer();
+    if ( wxpeer == NULL )
+        return NSDragOperationNone;
+        
+    wxDropTarget* target = wxpeer->GetDropTarget();
+    if ( target == NULL )
+        return NSDragOperationNone;
+
+    wxDragResult result = wxDragNone;
+    wxPoint pt = wxFromNSPoint( m_osxView, [sender draggingLocation] );
+
+    if ( sourceDragMask & NSDragOperationLink )
+        result = wxDragLink;
+    else if ( sourceDragMask & NSDragOperationCopy )
+        result = wxDragCopy;
+    else if ( sourceDragMask & NSDragOperationMove )
+        result = wxDragMove;
+
+    PasteboardRef pboardRef;    
+    PasteboardCreate((CFStringRef)[pboard name], &pboardRef);
+    target->SetCurrentDragPasteboard(pboardRef);
+    result = target->OnDragOver(pt.x, pt.y, result);
+    CFRelease(pboardRef);
+     
+    NSDragOperation nsresult = NSDragOperationNone;
+    switch (result )
+    {
+        case wxDragLink:
+            nsresult = NSDragOperationLink;
+        case wxDragMove:
+            nsresult = NSDragOperationMove;
+        case wxDragCopy:
+            nsresult = NSDragOperationCopy;
+        default :
+            break;
+    }
+    return nsresult;
+}
+
+bool wxWidgetCocoaImpl::performDragOperation(void* s, WXWidget slf, void *_cmd)
+{
+    id <NSDraggingInfo>sender = (id <NSDraggingInfo>) s;
 
-        [self getRectsBeingDrawn:&rects count:&count];
-        for ( int i = 0 ; i < count ; ++i )
+    NSPasteboard *pboard = [sender draggingPasteboard];
+    NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
+    
+    wxWindow* wxpeer = GetWXPeer();
+    wxDropTarget* target = wxpeer->GetDropTarget();
+    wxDragResult result = wxDragNone;
+    wxPoint pt = wxFromNSPoint( m_osxView, [sender draggingLocation] );
+
+    if ( sourceDragMask & NSDragOperationLink )
+        result = wxDragLink;
+    else if ( sourceDragMask & NSDragOperationCopy )
+        result = wxDragCopy;
+    else if ( sourceDragMask & NSDragOperationMove )
+        result = wxDragMove;
+
+    PasteboardRef pboardRef;    
+    PasteboardCreate((CFStringRef)[pboard name], &pboardRef);
+    target->SetCurrentDragPasteboard(pboardRef);
+    result = target->OnData(pt.x, pt.y, result);
+    CFRelease(pboardRef);
+     
+    return result != wxDragNone;
+}
+
+#endif
+
+typedef void (*wxOSX_EventHandlerPtr)(NSView* self, SEL _cmd, NSEvent *event);
+typedef BOOL (*wxOSX_PerformKeyEventHandlerPtr)(NSView* self, SEL _cmd, NSEvent *event);
+typedef BOOL (*wxOSX_FocusHandlerPtr)(NSView* self, SEL _cmd);
+typedef BOOL (*wxOSX_ResetCursorRectsHandlerPtr)(NSView* self, SEL _cmd);
+typedef BOOL (*wxOSX_DrawRectHandlerPtr)(NSView* self, SEL _cmd, NSRect rect);
+
+void wxWidgetCocoaImpl::mouseEvent(WX_NSEvent event, WXWidget slf, void *_cmd)
+{
+    if ( !DoHandleMouseEvent(event) )
+    {
+        wxOSX_EventHandlerPtr superimpl = (wxOSX_EventHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
+        superimpl(slf, (SEL)_cmd, event);
+    }
+}
+
+void wxWidgetCocoaImpl::keyEvent(WX_NSEvent event, WXWidget slf, void *_cmd)
+{
+    if ( !DoHandleKeyEvent(event) )
+    {
+        wxOSX_EventHandlerPtr superimpl = (wxOSX_EventHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
+        superimpl(slf, (SEL)_cmd, event);
+    }
+}
+
+bool wxWidgetCocoaImpl::performKeyEquivalent(WX_NSEvent event, WXWidget slf, void *_cmd)
+{
+    if ( !DoHandleKeyEvent(event) )
+    {
+        wxOSX_PerformKeyEventHandlerPtr superimpl = (wxOSX_PerformKeyEventHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
+        return superimpl(slf, (SEL)_cmd, event);
+    }
+
+    return YES;
+}
+
+bool wxWidgetCocoaImpl::becomeFirstResponder(WXWidget slf, void *_cmd)
+{
+    wxOSX_FocusHandlerPtr superimpl = (wxOSX_FocusHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
+    BOOL r = superimpl(slf, (SEL)_cmd);
+    if ( r )
+        DoNotifyFocusEvent( true );
+    return r;
+}
+
+bool wxWidgetCocoaImpl::resignFirstResponder(WXWidget slf, void *_cmd)
+{
+    wxOSX_FocusHandlerPtr superimpl = (wxOSX_FocusHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
+    BOOL r = superimpl(slf, (SEL)_cmd);
+    if ( r )
+        DoNotifyFocusEvent( false );
+    return r;
+}
+
+void wxWidgetCocoaImpl::resetCursorRects(WXWidget slf, void *_cmd)
+{
+    wxWindow* wxpeer = GetWXPeer();
+    if ( wxpeer )
+    {
+        NSCursor *cursor = (NSCursor*)wxpeer->GetCursor().GetHCURSOR();
+        if (cursor == NULL)
         {
-            updateRgn.Union(wxFromNSRect(self, rects[i]) );
+            wxOSX_ResetCursorRectsHandlerPtr superimpl = (wxOSX_ResetCursorRectsHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
+            superimpl(slf, (SEL)_cmd);
         }
+        else
+            [slf addCursorRect: [slf bounds]
+                cursor: cursor];
+    }
+}
+  
+bool wxWidgetCocoaImpl::isFlipped(WXWidget slf, void *_cmd)
+{
+    return m_isFlipped;
+}
 
-        wxWindow* wxpeer = impl->GetWXPeer();
-        wxpeer->GetUpdateRegion() = updateRgn;
-        wxpeer->MacSetCGContextRef( context );
-        
-        wxPaintEvent event;
-        event.SetTimestamp(0); //  todo
-        event.SetEventObject(wxpeer);
-        wxpeer->HandleWindowEvent(event);
-                
-        CGContextRestoreGState( context );
+
+#define OSX_DEBUG_DRAWING 0
+
+void wxWidgetCocoaImpl::drawRect(void* rect, WXWidget slf, void *_cmd)
+{
+    CGContextRef context = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
+    CGContextSaveGState( context );
+    
+#if OSX_DEBUG_DRAWING
+    CGContextBeginPath( context );
+    CGContextMoveToPoint(context, 0, 0);
+    NSRect bounds = [self bounds];
+    CGContextAddLineToPoint(context, 10, 0);
+    CGContextMoveToPoint(context, 0, 0);
+    CGContextAddLineToPoint(context, 0, 10);
+    CGContextMoveToPoint(context, bounds.size.width, bounds.size.height);
+    CGContextAddLineToPoint(context, bounds.size.width, bounds.size.height-10);
+    CGContextMoveToPoint(context, bounds.size.width, bounds.size.height);
+    CGContextAddLineToPoint(context, bounds.size.width-10, bounds.size.height);
+    CGContextClosePath( context );
+    CGContextStrokePath(context);
+#endif
+
+    if ( !m_isFlipped )
+    {
+        CGContextTranslateCTM( context, 0,  [m_osxView bounds].size.height );
+        CGContextScaleCTM( context, 1, -1 );
+    }
+    
+    wxRegion updateRgn;
+    const NSRect *rects;
+    NSInteger count;
+
+    [slf getRectsBeingDrawn:&rects count:&count];
+    for ( int i = 0 ; i < count ; ++i )
+    {
+        updateRgn.Union(wxFromNSRect(slf, rects[i]) );
+    }
+
+    wxWindow* wxpeer = GetWXPeer();
+    wxpeer->GetUpdateRegion() = updateRgn;
+    wxpeer->MacSetCGContextRef( context );
+    
+    wxPaintEvent event;
+    event.SetTimestamp(0); //  todo
+    event.SetEventObject(wxpeer);
+    bool handled = wxpeer->HandleWindowEvent(event);
+            
+    CGContextRestoreGState( context );
+    
+    if ( !handled )
+    {
+        // call super
+        SEL _cmd = @selector(drawRect:);
+        wxOSX_DrawRectHandlerPtr superimpl = (wxOSX_DrawRectHandlerPtr) [[slf superclass] instanceMethodForSelector:_cmd];
+        superimpl(slf, _cmd, *(NSRect*)rect);
     }
 }
 
-WXCOCOAIMPL_COMMON_IMPLEMENTATION
+void wxWidgetCocoaImpl::clickedAction( WXWidget slf, void *_cmd, void *sender)
+{
+    wxWindow* wxpeer = (wxWindow*) GetWXPeer();
+    if ( wxpeer )
+        wxpeer->OSXHandleClicked(0);
+}
 
-- (BOOL) canBecomeKeyView
+void wxWidgetCocoaImpl::doubleClickedAction( WXWidget slf, void *_cmd, void *sender)
 {
-    return YES;
 }
 
-@end // wxNSView
+// 
+
+#if OBJC_API_VERSION >= 2
+
+#define wxOSX_CLASS_ADD_METHOD( c, s, i, t ) \
+    class_addMethod(c, s, i, t );
+
+#else
+
+#define wxOSX_CLASS_ADD_METHOD( c, s, i, t ) \
+    { s, t, i },
+
+#endif
+
+void wxOSXCocoaClassAddWXMethods(Class c)
+{
+
+#if OBJC_API_VERSION < 2
+    static objc_method wxmethods[] =
+    {
+#endif
+
+    wxOSX_CLASS_ADD_METHOD(c, @selector(mouseDown:), (IMP) wxOSX_mouseEvent, "v@:@" )
+    wxOSX_CLASS_ADD_METHOD(c, @selector(rightMouseDown:), (IMP) wxOSX_mouseEvent, "v@:@" )
+    wxOSX_CLASS_ADD_METHOD(c, @selector(otherMouseDown:), (IMP) wxOSX_mouseEvent, "v@:@" )
+
+    wxOSX_CLASS_ADD_METHOD(c, @selector(mouseUp:), (IMP) wxOSX_mouseEvent, "v@:@" )
+    wxOSX_CLASS_ADD_METHOD(c, @selector(rightMouseUp:), (IMP) wxOSX_mouseEvent, "v@:@" )
+    wxOSX_CLASS_ADD_METHOD(c, @selector(otherMouseUp:), (IMP) wxOSX_mouseEvent, "v@:@" )
+
+    wxOSX_CLASS_ADD_METHOD(c, @selector(mouseMoved:), (IMP) wxOSX_mouseEvent, "v@:@" )
+
+    wxOSX_CLASS_ADD_METHOD(c, @selector(mouseDragged:), (IMP) wxOSX_mouseEvent, "v@:@" )
+    wxOSX_CLASS_ADD_METHOD(c, @selector(rightMouseDragged:), (IMP) wxOSX_mouseEvent, "v@:@" )
+    wxOSX_CLASS_ADD_METHOD(c, @selector(otherMouseDragged:), (IMP) wxOSX_mouseEvent, "v@:@" )
+
+    wxOSX_CLASS_ADD_METHOD(c, @selector(scrollWheel:), (IMP) wxOSX_mouseEvent, "v@:@" )
+    wxOSX_CLASS_ADD_METHOD(c, @selector(mouseEntered:), (IMP) wxOSX_mouseEvent, "v@:@" )
+    wxOSX_CLASS_ADD_METHOD(c, @selector(mouseExited:), (IMP) wxOSX_mouseEvent, "v@:@" )
+    
+    wxOSX_CLASS_ADD_METHOD(c, @selector(keyDown:), (IMP) wxOSX_keyEvent, "v@:@" )
+    wxOSX_CLASS_ADD_METHOD(c, @selector(keyUp:), (IMP) wxOSX_keyEvent, "v@:@" )
+    wxOSX_CLASS_ADD_METHOD(c, @selector(flagsChanged:), (IMP) wxOSX_keyEvent, "v@:@" )
+
+    wxOSX_CLASS_ADD_METHOD(c, @selector(performKeyEquivalent:), (IMP) wxOSX_performKeyEquivalent, "v@:@" )
+
+
+    wxOSX_CLASS_ADD_METHOD(c, @selector(becomeFirstResponder), (IMP) wxOSX_becomeFirstResponder, "c@:" )
+    wxOSX_CLASS_ADD_METHOD(c, @selector(resignFirstResponder), (IMP) wxOSX_resignFirstResponder, "c@:" )
+    wxOSX_CLASS_ADD_METHOD(c, @selector(resetCursorRects), (IMP) wxOSX_resetCursorRects, "v@:" )
+
+    wxOSX_CLASS_ADD_METHOD(c, @selector(isFlipped), (IMP) wxOSX_isFlipped, "c@:" )
+    wxOSX_CLASS_ADD_METHOD(c, @selector(drawRect:), (IMP) wxOSX_drawRect, "v@:{_NSRect={_NSPoint=ff}{_NSSize=ff}}" )
+
+    wxOSX_CLASS_ADD_METHOD(c, @selector(clickedAction:), (IMP) wxOSX_clickedAction, "v@:@" )
+    wxOSX_CLASS_ADD_METHOD(c, @selector(doubleClickedAction:), (IMP) wxOSX_doubleClickedAction, "v@:@" )
+
+#if wxUSE_DRAG_AND_DROP
+    wxOSX_CLASS_ADD_METHOD(c, @selector(draggingEntered:), (IMP) wxOSX_draggingEntered, "I@:@" )
+    wxOSX_CLASS_ADD_METHOD(c, @selector(draggingUpdated:), (IMP) wxOSX_draggingUpdated, "I@:@" )
+    wxOSX_CLASS_ADD_METHOD(c, @selector(draggingExited:), (IMP) wxOSX_draggingExited, "v@:@" )
+    wxOSX_CLASS_ADD_METHOD(c, @selector(performDragOperation:), (IMP) wxOSX_performDragOperation, "c@:@" )
+#endif     
+        
+#if OBJC_API_VERSION < 2
+    } ;
+    static int method_count = WXSIZEOF( wxmethods );
+    static objc_method_list *wxmethodlist = NULL;
+    if ( wxmethodlist == NULL )
+    {
+        wxmethodlist = (objc_method_list*) malloc(sizeof(objc_method_list) + sizeof(wxmethods) );
+        memcpy( &wxmethodlist->method_list[0], &wxmethods[0], sizeof(wxmethods) );
+        wxmethodlist->method_count = method_count;
+        wxmethodlist->obsolete = 0;
+    }
+    class_addMethods( c, wxmethodlist );
+#endif
+}
+
+//
+// C++ implementation class
+//
 
 IMPLEMENT_DYNAMIC_CLASS( wxWidgetCocoaImpl , wxWidgetImpl )
 
 wxWidgetCocoaImpl::wxWidgetCocoaImpl( wxWindowMac* peer , WXWidget w, bool isRootControl ) :
-    wxWidgetImpl( peer, isRootControl ), m_osxView(w)
+    wxWidgetImpl( peer, isRootControl )
 {
+    Init();
+    m_osxView = w;
 }
 
 wxWidgetCocoaImpl::wxWidgetCocoaImpl() 
 {
+    Init();
 }
 
 void wxWidgetCocoaImpl::Init()
 {
     m_osxView = NULL;
+    m_isFlipped = true;
 }
 
 wxWidgetCocoaImpl::~wxWidgetCocoaImpl()
 {
-    if ( [m_osxView respondsToSelector:@selector(setImplementation:) ] )
-        [m_osxView setImplementation:NULL];
+    RemoveAssociations( this );
+
     if ( !IsRootControl() )
     {
         NSView *sv = [m_osxView superview];
@@ -722,6 +1189,18 @@ void wxWidgetCocoaImpl::SetFont(wxFont const&, wxColour const&, long, bool)
 
 void wxWidgetCocoaImpl::InstallEventHandler( WXWidget control )
 {
+    WXWidget c =  control ? control : (WXWidget) m_osxView;
+    wxWidgetImpl::Associate( c, this ) ;
+    if ([c respondsToSelector:@selector(setAction:)])
+    {
+        [c setTarget: c];
+        [c setAction: @selector(clickedAction:)];
+        if ([c respondsToSelector:@selector(setDoubleAction:)])
+        {
+            [c setDoubleAction: @selector(doubleClickedAction:)];
+        }
+        
+    }
 }
 
 bool wxWidgetCocoaImpl::DoHandleKeyEvent(NSEvent *event)
@@ -810,6 +1289,11 @@ void wxWidgetCocoaImpl::ReleaseMouse()
     [[m_osxView window] enableCursorRects];
 }
 
+void wxWidgetCocoaImpl::SetFlipped(bool flipped)
+{
+    m_isFlipped = flipped;
+}
+
 //
 // Factory methods
 //
@@ -817,13 +1301,14 @@ void wxWidgetCocoaImpl::ReleaseMouse()
 wxWidgetImpl* wxWidgetImpl::CreateUserPane( wxWindowMac* wxpeer, wxWindowMac* parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
                             long style, long extraStyle)
 {
-    NSView* sv = (wxpeer->GetParent()->GetHandle() );
-    
     NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
     wxNSView* v = [[wxNSView alloc] initWithFrame:r];
-    [sv addSubview:v];
+
+    // temporary hook for dnd
+    [v registerForDraggedTypes:[NSArray arrayWithObjects:
+        NSStringPboardType, NSFilenamesPboardType, NSTIFFPboardType, NSPICTPboardType, NSPDFPboardType, nil]];
+        
     wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
-    [v setImplementation:c];
     return c;
 }
 
@@ -832,7 +1317,6 @@ wxWidgetImpl* wxWidgetImpl::CreateContentView( wxNonOwnedWindow* now )
     NSWindow* tlw = now->GetWXWindow();
     wxNSView* v = [[wxNSView alloc] initWithFrame:[[tlw contentView] frame]];
     wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( now, v, true );
-    [v setImplementation:c];
     [tlw setContentView:v];
     return c;
 }
index b9817fbfc108ed1af488756b191a5dcdbbfe0a20..5e8a0b9f46981c4a78d03029294d22b4f27d8584 100644 (file)
@@ -85,7 +85,6 @@
 BEGIN_EVENT_TABLE(wxWindowMac, wxWindowBase)
     EVT_NC_PAINT(wxWindowMac::OnNcPaint)
     EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground)
-    EVT_PAINT(wxWindowMac::OnPaint)
     EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent)
 END_EVENT_TABLE()
 
@@ -1869,7 +1868,19 @@ bool wxWindowMac::MacDoRedraw( void* updatergnr , long time )
             wxPaintEvent event;
             event.SetTimestamp(time);
             event.SetEventObject(this);
-            HandleWindowEvent(event);
+            if ( !HandleWindowEvent(event) )
+            {
+                // for native controls: call their native paint method
+                if ( !MacIsUserPane() || ( IsTopLevel() && GetBackgroundStyle() == wxBG_STYLE_SYSTEM ) )
+                {
+                    if ( wxTheApp->MacGetCurrentEvent() != NULL && wxTheApp->MacGetCurrentEventHandlerCallRef() != NULL
+                        && GetBackgroundStyle() != wxBG_STYLE_TRANSPARENT )
+                        CallNextEventHandler(
+                            (EventHandlerCallRef)wxTheApp->MacGetCurrentEventHandlerCallRef() ,
+                            (EventRef) wxTheApp->MacGetCurrentEvent() ) ;
+                }
+            }
+            
             handled = true ;
         }
 
@@ -2200,21 +2211,6 @@ void wxWindowMac::OnMouseEvent( wxMouseEvent &event )
     }
 }
 
-void wxWindowMac::OnPaint( wxPaintEvent & WXUNUSED(event) )
-{
-#if wxOSX_USE_COCOA_OR_CARBON
-    // for native controls: call their native paint method
-    if ( !MacIsUserPane() || ( IsTopLevel() && GetBackgroundStyle() == wxBG_STYLE_SYSTEM ) )
-    {
-        if ( wxTheApp->MacGetCurrentEvent() != NULL && wxTheApp->MacGetCurrentEventHandlerCallRef() != NULL
-             && GetBackgroundStyle() != wxBG_STYLE_TRANSPARENT )
-            CallNextEventHandler(
-                (EventHandlerCallRef)wxTheApp->MacGetCurrentEventHandlerCallRef() ,
-                (EventRef) wxTheApp->MacGetCurrentEvent() ) ;
-    }
-#endif
-}
-
 void wxWindowMac::TriggerScrollEvent( wxEventType WXUNUSED(scrollEvent) )
 {
 }