]> git.saurik.com Git - wxWidgets.git/commitdiff
using subclass as impl ptr, common code in macro because mix-in are not possible...
authorStefan Csomor <csomor@advancedconcepts.ch>
Tue, 13 Jan 2009 18:35:23 +0000 (18:35 +0000)
committerStefan Csomor <csomor@advancedconcepts.ch>
Tue, 13 Jan 2009 18:35:23 +0000 (18:35 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58078 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

14 files changed:
include/wx/osx/cocoa/private.h
src/osx/cocoa/bmpbuttn.mm
src/osx/cocoa/button.mm
src/osx/cocoa/choice.mm
src/osx/cocoa/gauge.mm
src/osx/cocoa/glcanvas.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/stattext.mm
src/osx/cocoa/textctrl.mm
src/osx/cocoa/window.mm

index d56945236f75c3f925845380017482dacc1f4702..d9ccabc652e8baae90a5d4e1c1fb50a154911466 100644 (file)
 #endif
 
 #ifdef __OBJC__
-
     #import <Cocoa/Cocoa.h>
-
-    #if wxUSE_GUI
-
-    extern NSRect wxToNSRect( NSView* parent, const wxRect& r );
-    extern wxRect wxFromNSRect( NSView* parent, const NSRect& rect );
-    extern NSPoint wxToNSPoint( NSView* parent, const wxPoint& p );
-    extern wxPoint wxFromNSPoint( NSView* parent, const NSPoint& p );
-    
-    // used for many wxControls
-    
-    @interface wxNSButton : NSButton
-    {
-        wxWidgetImpl* impl;
-    }
-
-    - (void)setImplementation: (wxWidgetImpl *) theImplementation;
-    - (wxWidgetImpl*) implementation;
-    - (BOOL) isFlipped;
-    - (void) clickedAction: (id) sender;
-
-    @end
-
-    @interface wxNSBox : NSBox
-    {
-        wxWidgetImpl* impl;
-    }
-
-    - (void)setImplementation: (wxWidgetImpl *) theImplementation;
-    - (wxWidgetImpl*) implementation;
-    - (BOOL) isFlipped;
-
-    @end
-
-    @interface wxNSTextField : NSTextField
-    {
-        wxWidgetImpl* impl;
-    }
-
-    - (void)setImplementation: (wxWidgetImpl *) theImplementation;
-    - (wxWidgetImpl*) implementation;
-    - (BOOL) isFlipped;
-
-    @end
-
-    NSRect WXDLLIMPEXP_CORE wxOSXGetFrameForControl( wxWindowMac* window , const wxPoint& pos , const wxSize &size , 
-        bool adjustForOrigin = true );
-        
-    #endif // wxUSE_GUI
-
-#endif // __OBJC__
+#endif
 
 //
 // shared between Cocoa and Carbon
@@ -166,6 +116,9 @@ public :
     void                SetFont( const wxFont & font , const wxColour& foreground , long windowStyle, bool ignoreBlack = true );
 
     void                InstallEventHandler( WXWidget control = NULL );
+    
+    virtual void        DoHandleMouseEvent(NSEvent *event); 
+
 protected:
     WXWidget m_osxView;
     DECLARE_DYNAMIC_CLASS_NO_COPY(wxWidgetCocoaImpl)
@@ -230,6 +183,94 @@ protected :
     DECLARE_DYNAMIC_CLASS_NO_COPY(wxNonOwnedWindowCocoaImpl)
 };    
 
+#ifdef __OBJC__
+
+    extern NSRect wxToNSRect( NSView* parent, const wxRect& r );
+    extern wxRect wxFromNSRect( NSView* parent, const NSRect& rect );
+    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 );
+        
+    // common code snippets for cocoa implementations
+    // later to be done using injection in method table
+        
+    #define WXCOCOAIMPL_COMMON_MOUSE_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)handleMouseEvent:(NSEvent *)event;
+
+    #define WXCOCOAIMPL_COMMON_MOUSE_IMPLEMENTATION -(void)mouseDown:(NSEvent *)event \
+        {\
+            [self handleMouseEvent:event];\
+        }\
+        -(void)rightMouseDown:(NSEvent *)event\
+        {\
+            [self handleMouseEvent:event];\
+        }\
+        -(void)otherMouseDown:(NSEvent *)event\
+        {\
+            [self handleMouseEvent:event];\
+        }\
+        -(void)mouseUp:(NSEvent *)event\
+        {\
+            [self handleMouseEvent:event];\
+        }\
+        -(void)rightMouseUp:(NSEvent *)event\
+        {\
+            [self handleMouseEvent:event];\
+        }\
+        -(void)otherMouseUp:(NSEvent *)event\
+        {\
+            [self handleMouseEvent:event];\
+        }\
+        -(void)handleMouseEvent:(NSEvent *)event\
+        {\
+            impl->DoHandleMouseEvent(event);\
+        }
+        
+#endif // __OBJC__
+
 // NSCursor
 
 WX_NSCursor wxMacCocoaCreateStockCursor( int cursor_type );
index 0c1f471a3ea87a7d70b14c7dfef0354c9e8c96b9..ab3433bd7fb7134dc7edcc86e088aa5b89cba3ae 100644 (file)
@@ -33,8 +33,20 @@ wxWidgetImplType* wxWidgetImpl::CreateBitmapButton( wxWindowMac* wxpeer,
 {
     NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
     wxNSButton* v = [[wxNSButton alloc] initWithFrame:r];
+
+    // trying to get as close as possible to flags
+    if ( style & wxBORDER_NONE )
+    {
+        [v setBezelStyle:NSShadowlessSquareBezelStyle];
+    }
+    else
+    {
+        if ( style & wxBU_AUTODRAW )
+            [v setBezelStyle:NSShadowlessSquareBezelStyle];
+        else
+            [v setBezelStyle:NSRegularSquareBezelStyle];
+    }
     
-    [v setBezelStyle:NSRegularSquareBezelStyle];
     [v setImage:bitmap.GetNSImage() ];
     [v setButtonType:NSMomentaryPushInButton];
     wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
index bbf249361fd37c04b6e01e050378f3cd05ef3511..60c1c45bf468822315a6d34166b11bf76d59d282 100644 (file)
@@ -142,12 +142,12 @@ wxSize wxButton::GetDefaultSize()
     }
 }
 
-- (void)setImplementation: (wxWidgetImpl *) theImplementation
+- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation
 {
     impl = theImplementation;
 }
 
-- (wxWidgetImpl*) implementation
+- (wxWidgetCocoaImpl*) implementation
 {
     return impl;
 }
index cf583d5fee7bc6e8efd68f70e26bd7e267d12624..931a7308d47971556767049b4e7d512df2e7f868 100644 (file)
 
 @interface wxNSPopUpButton : NSPopUpButton
 {
-    wxWidgetImpl* impl;
+    wxWidgetCocoaImpl* impl;
 }
 
-- (void)setImplementation: (wxWidgetImpl *) theImplementation;
-- (wxWidgetImpl*) implementation;
+- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation;
+- (wxWidgetCocoaImpl*) implementation;
 - (BOOL) isFlipped;
 - (void) clickedAction: (id) sender;
 
     }
 }
 
-- (void)setImplementation: (wxWidgetImpl *) theImplementation
+- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation
 {
     impl = theImplementation;
 }
 
-- (wxWidgetImpl*) implementation
+- (wxWidgetCocoaImpl*) implementation
 {
     return impl;
 }
index 71b9043b0a4055e0e0f77b16dc3feefb6de70e87..77189ce3d5fdb37096f8727c7b824be9ad1bd8e6 100644 (file)
 
 @interface wxNSProgressIndicator : NSProgressIndicator
 {
-    wxWidgetImpl* impl;
+    wxWidgetCocoaImpl* impl;
 }
 
-- (void)setImplementation: (wxWidgetImpl *) theImplementation;
+- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation;
 - (wxWidgetImpl*) implementation;
 - (BOOL) isFlipped;
 
     return self;
 }
 
-- (void)setImplementation: (wxWidgetImpl *) theImplementation
+- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation
 {
     impl = theImplementation;
 }
 
-- (wxWidgetImpl*) implementation
+- (wxWidgetCocoaImpl*) implementation
 {
     return impl;
 }
index ee5d515c4ec65adcd2a9a9702f2cfa20688e2f69..4e6654452c4669c851b067225bdf33a0173d0ee0 100644 (file)
@@ -229,13 +229,13 @@ bool wxGLContext::SetCurrent(const wxGLCanvas& win) const
 
 @interface wxNSCustomOpenGLView : NSView
 {
-    wxWidgetImpl* impl;
+    wxWidgetCocoaImpl* impl;
     NSOpenGLContext* context;
 }
 
 - (id)initWithFrame:(NSRect)frame;
-- (void)setImplementation: (wxWidgetImpl *) theImplementation;
-- (wxWidgetImpl*) implementation;
+- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation;
+- (wxWidgetCocoaImpl*) implementation;
 - (BOOL) isFlipped;
 
 @end
@@ -249,12 +249,12 @@ bool wxGLContext::SetCurrent(const wxGLCanvas& win) const
     return self;
 }
 
-- (void)setImplementation: (wxWidgetImpl *) theImplementation
+- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation
 {
     impl = theImplementation;
 }
 
-- (wxWidgetImpl*) implementation
+- (wxWidgetCocoaImpl*) implementation
 {
     return impl;
 }
index c3e7b73b6d418598f530edee675e7f114d163abc..e2a7b01f98ce40dcaf7bd36d85c18cc5948b7a69 100644 (file)
 
 @interface wxNSScroller : NSScroller
 {
-    wxWidgetImpl* impl;
+    wxWidgetCocoaImpl* impl;
 }
 
-- (void)setImplementation: (wxWidgetImpl *) theImplementation;
-- (wxWidgetImpl*) implementation;
+- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation;
+- (wxWidgetCocoaImpl*) implementation;
 - (BOOL) isFlipped;
  - (void) clickedAction: (id) sender;
 
     }
 }
 
-- (void)setImplementation: (wxWidgetImpl *) theImplementation
+- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation
 {
     impl = theImplementation;
 }
 
-- (wxWidgetImpl*) implementation
+- (wxWidgetCocoaImpl*) implementation
 {
     return impl ;
 }
index 8fc664c26c5798226e57245d02b37c0994fd4318..227435b77d413dac1cbcfdba82a4722bb42e1754 100644 (file)
 
 @interface wxNSSlider : NSSlider
 {
-    wxWidgetImpl* impl;
+    wxWidgetCocoaImpl* impl;
 }
 
-- (void)setImplementation: (wxWidgetImpl *) theImplementation;
-- (wxWidgetImpl*) implementation;
+- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation;
+- (wxWidgetCocoaImpl*) implementation;
 - (BOOL) isFlipped;
  - (void) clickedAction: (id) sender;
 
     }
 }
 
-- (void)setImplementation: (wxWidgetImpl *) theImplementation
+- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation
 {
     impl = theImplementation;
 }
 
-- (wxWidgetImpl*) implementation
+- (wxWidgetCocoaImpl*) implementation
 {
     return impl;
 }
index 436576b8b37416c3d2be3925ae6e093b07c81a69..980fc81ddaf448e1ff1583635a68eda66a41db61 100644 (file)
 
 @interface wxNSStepper : NSStepper
 {
-    wxWidgetImpl* impl;
+    wxWidgetCocoaImpl* impl;
 }
 
-- (void)setImplementation: (wxWidgetImpl *) theImplementation;
-- (wxWidgetImpl*) implementation;
+- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation;
+- (wxWidgetCocoaImpl*) implementation;
 - (BOOL) isFlipped;
  - (void) clickedAction: (id) sender;
 
     }
 }
 
-- (void)setImplementation: (wxWidgetImpl *) theImplementation
+- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation
 {
     impl = theImplementation;
 }
 
-- (wxWidgetImpl*) implementation
+- (wxWidgetCocoaImpl*) implementation
 {
     return impl;
 }
index 6cda0bfab594529a29d2b9d24d9c5abbdb1bc505..34758780b96fb23579d429deaced3a551492006d 100644 (file)
@@ -31,7 +31,7 @@
 
 @interface wxNSSearchField : NSSearchField
 {
-    wxWidgetImpl* impl;
+    wxWidgetCocoaImpl* impl;
 }
 
 @end
     return self;
 }
 
-- (void)setImplementation: (wxWidgetImpl *) theImplementation
+- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation
 {
     impl = theImplementation;
 }
 
-- (wxWidgetImpl*) implementation
+- (wxWidgetCocoaImpl*) implementation
 {
     return impl;
 }
index 3eca187518acd3745df68faac2750ff6fc2d155c..6f7fecfc38fa6644f3157266bff06a8c906ed98b 100644 (file)
 
 @implementation wxNSBox
 
-- (void)setImplementation: (wxWidgetImpl *) theImplementation
+- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation
 {
     impl = theImplementation;
 }
 
-- (wxWidgetImpl*) implementation
+- (wxWidgetCocoaImpl*) implementation
 {
     return impl;
 }
index c1ed173666796aeb08f9e6fbca90a63a283c343b..b3d5f89ebc39ffeddaec6915b4814e1c8b04690f 100644 (file)
 
 wxSize wxStaticText::DoGetBestSize() const
 {
-    Point bounds;
-#if wxOSX_USE_CARBON
-    Rect bestsize = { 0 , 0 , 0 , 0 } ;
-
-    // try the built-in best size if available
-    Boolean former = m_peer->GetData<Boolean>( kControlStaticTextIsMultilineTag);
-    m_peer->SetData( kControlStaticTextIsMultilineTag, (Boolean)0 );
-    m_peer->GetBestRect( &bestsize ) ;
-    m_peer->SetData( kControlStaticTextIsMultilineTag, former );
-    if ( !EmptyRect( &bestsize ) )
+Point bounds;
+
+#if wxOSX_USE_ATSU_TEXT
+    OSStatus err = noErr;
+    wxCFStringRef str( m_label,  GetFont().GetEncoding() );
+
+    SInt16 baseline;
+    if ( m_font.MacGetThemeFontID() != kThemeCurrentPortFont )
     {
-        bounds.h = bestsize.right - bestsize.left ;
-        bounds.v = bestsize.bottom - bestsize.top ;
+        err = GetThemeTextDimensions(
+            (!m_label.empty() ? (CFStringRef)str : CFSTR(" ")),
+            m_font.MacGetThemeFontID(), kThemeStateActive, false, &bounds, &baseline );
+        verify_noerr( err );
     }
     else
 #endif
     {
-#if wxOSX_USE_CARBON
-        ControlFontStyleRec controlFont;
-        OSStatus err = m_peer->GetData<ControlFontStyleRec>( kControlEntireControl, kControlFontStyleTag, &controlFont );
-        verify_noerr( err );
+        wxClientDC dc(const_cast<wxStaticText*>(this));
+        wxCoord width, height ;
+        dc.GetTextExtent( m_label , &width, &height);
+        // Some labels seem to have their last characters
+        // stripped out.  Adding 4 pixels seems to be enough to fix this.
+        bounds.h = width+4;
+        bounds.v = height;
+    }
 
-        wxCFStringRef str( m_label,  GetFont().GetEncoding() );
+    if ( m_label.empty() )
+        bounds.h = 0;
 
-#if wxOSX_USE_ATSU_TEXT
-        SInt16 baseline;
-        if ( m_font.MacGetThemeFontID() != kThemeCurrentPortFont )
-        {
-            err = GetThemeTextDimensions(
-                (!m_label.empty() ? (CFStringRef)str : CFSTR(" ")),
-                m_font.MacGetThemeFontID(), kThemeStateActive, false, &bounds, &baseline );
-            verify_noerr( err );
-        }
-        else
-#endif
-#endif
-        {
-            wxClientDC dc(const_cast<wxStaticText*>(this));
-            wxCoord width, height ;
-            dc.GetTextExtent( m_label , &width, &height);
-            bounds.h = width;
-            bounds.v = height;
-        }
-
-        if ( m_label.empty() )
-            bounds.h = 0;
-    }
     bounds.h += MacGetLeftBorderSize() + MacGetRightBorderSize();
     bounds.v += MacGetTopBorderSize() + MacGetBottomBorderSize();
 
index 6a2b2946dea08400885860c223a79fd543f84a0c..199f6de54368df617c7616e4f408d76e19db0c88 100644 (file)
 
 @implementation wxNSTextField
 
-- (void)setImplementation: (wxWidgetImpl *) theImplementation
+- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation
 {
     impl = theImplementation;
 }
 
-- (wxWidgetImpl*) implementation
+- (wxWidgetCocoaImpl*) implementation
 {
     return impl;
 }
index 4594a4931da1e3aea95e38e5319baa305a1c93fb..ce2fa679f822a14aa42934a4704986fd83f10c52 100644 (file)
@@ -32,26 +32,20 @@ NSRect wxOSXGetFrameForControl( wxWindowMac* window , const wxPoint& pos , const
 
 @interface wxNSView : NSView
 {
-    wxWidgetImpl* impl;
+    wxWidgetCocoaImpl* impl;
 }
 
 - (void)drawRect: (NSRect) rect;
 
--(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)handleMouseEvent:(NSEvent *)event;
+WXCOCOAIMPL_COMMON_MOUSE_INTERFACE
 
 - (void)keyDown:(NSEvent *)event;
 - (void)keyUp:(NSEvent *)event;
 - (void)flagsChanged:(NSEvent *)event;
 - (void)handleKeyEvent:(NSEvent *)event;
 
-- (void)setImplementation: (wxWidgetImpl *) theImplementation;
-- (wxWidgetImpl*) implementation;
+- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation;
+- (wxWidgetCocoaImpl*) implementation;
 - (BOOL) isFlipped;
 - (BOOL) becomeFirstResponder;
 - (BOOL) resignFirstResponder;
@@ -348,47 +342,7 @@ void SetupMouseEvent( wxMouseEvent &wxevent , NSEvent * nsEvent )
     }
 }
 
--(void)mouseDown:(NSEvent *)event 
-{
-    [self handleMouseEvent:event];
-}
-
--(void)rightMouseDown:(NSEvent *)event 
-{
-    [self handleMouseEvent:event];
-}
-
--(void)otherMouseDown:(NSEvent *)event 
-{
-    [self handleMouseEvent:event];
-}
-
--(void)mouseUp:(NSEvent *)event 
-{
-    [self handleMouseEvent:event];
-}
-
--(void)rightMouseUp:(NSEvent *)event 
-{
-    [self handleMouseEvent:event];
-}
-
--(void)otherMouseUp:(NSEvent *)event 
-{
-    [self handleMouseEvent:event];
-}
-
--(void)handleMouseEvent:(NSEvent *)event 
-{ 
-    NSPoint clickLocation; 
-    clickLocation = [self convertPoint:[event locationInWindow] fromView:nil]; 
-    wxPoint pt = wxFromNSPoint( self, clickLocation );
-    wxMouseEvent wxevent(wxEVT_LEFT_DOWN);
-    SetupMouseEvent( wxevent , event ) ;
-    wxevent.m_x = pt.x;
-    wxevent.m_y = pt.y;
-    impl->GetWXPeer()->HandleWindowEvent(wxevent);
-}
+WXCOCOAIMPL_COMMON_MOUSE_IMPLEMENTATION
 
 - (void)keyDown:(NSEvent *)event
 {
@@ -413,12 +367,12 @@ void SetupMouseEvent( wxMouseEvent &wxevent , NSEvent * nsEvent )
 }
 
 
-- (void)setImplementation: (wxWidgetImpl *) theImplementation
+- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation
 {
     impl = theImplementation;
 }
 
-- (wxWidgetImpl*) implementation
+- (wxWidgetCocoaImpl*) implementation
 {
     return impl;
 }
@@ -722,6 +676,19 @@ void wxWidgetCocoaImpl::InstallEventHandler( WXWidget control )
 {
 }
 
+void wxWidgetCocoaImpl::DoHandleMouseEvent(NSEvent *event)
+{
+    NSPoint clickLocation; 
+    clickLocation = [m_osxView convertPoint:[event locationInWindow] fromView:nil]; 
+    wxPoint pt = wxFromNSPoint( m_osxView, clickLocation );
+    wxMouseEvent wxevent(wxEVT_LEFT_DOWN);
+    SetupMouseEvent( wxevent , event ) ;
+    wxevent.m_x = pt.x;
+    wxevent.m_y = pt.y;
+    GetWXPeer()->HandleWindowEvent(wxevent);
+}
+
+
 //
 // Factory methods
 //