using subclass as impl ptr, common code in macro because mix-in are not possible in obj-c

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58078 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor
2009-01-13 18:35:23 +00:00
parent 2126732187
commit 4850cc8b2e
14 changed files with 185 additions and 183 deletions

View File

@@ -26,58 +26,8 @@
#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 );

View File

@@ -34,7 +34,19 @@ 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 setImage:bitmap.GetNSImage() ];
[v setButtonType:NSMomentaryPushInButton];
wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );

View File

@@ -142,12 +142,12 @@ wxSize wxButton::GetDefaultSize()
}
}
- (void)setImplementation: (wxWidgetImpl *) theImplementation
- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation
{
impl = theImplementation;
}
- (wxWidgetImpl*) implementation
- (wxWidgetCocoaImpl*) implementation
{
return impl;
}

View File

@@ -24,11 +24,11 @@
@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;
@@ -55,12 +55,12 @@
}
}
- (void)setImplementation: (wxWidgetImpl *) theImplementation
- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation
{
impl = theImplementation;
}
- (wxWidgetImpl*) implementation
- (wxWidgetCocoaImpl*) implementation
{
return impl;
}

View File

@@ -19,10 +19,10 @@
@interface wxNSProgressIndicator : NSProgressIndicator
{
wxWidgetImpl* impl;
wxWidgetCocoaImpl* impl;
}
- (void)setImplementation: (wxWidgetImpl *) theImplementation;
- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation;
- (wxWidgetImpl*) implementation;
- (BOOL) isFlipped;
@@ -37,12 +37,12 @@
return self;
}
- (void)setImplementation: (wxWidgetImpl *) theImplementation
- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation
{
impl = theImplementation;
}
- (wxWidgetImpl*) implementation
- (wxWidgetCocoaImpl*) implementation
{
return impl;
}

View 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;
}

View File

@@ -23,11 +23,11 @@
@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;
@@ -54,12 +54,12 @@
}
}
- (void)setImplementation: (wxWidgetImpl *) theImplementation
- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation
{
impl = theImplementation;
}
- (wxWidgetImpl*) implementation
- (wxWidgetCocoaImpl*) implementation
{
return impl ;
}

View File

@@ -18,11 +18,11 @@
@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;
@@ -49,12 +49,12 @@
}
}
- (void)setImplementation: (wxWidgetImpl *) theImplementation
- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation
{
impl = theImplementation;
}
- (wxWidgetImpl*) implementation
- (wxWidgetCocoaImpl*) implementation
{
return impl;
}

View File

@@ -18,11 +18,11 @@
@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;
@@ -49,12 +49,12 @@
}
}
- (void)setImplementation: (wxWidgetImpl *) theImplementation
- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation
{
impl = theImplementation;
}
- (wxWidgetImpl*) implementation
- (wxWidgetCocoaImpl*) implementation
{
return impl;
}

View File

@@ -31,7 +31,7 @@
@interface wxNSSearchField : NSSearchField
{
wxWidgetImpl* impl;
wxWidgetCocoaImpl* impl;
}
@end
@@ -47,12 +47,12 @@
return self;
}
- (void)setImplementation: (wxWidgetImpl *) theImplementation
- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation
{
impl = theImplementation;
}
- (wxWidgetImpl*) implementation
- (wxWidgetCocoaImpl*) implementation
{
return impl;
}

View File

@@ -18,12 +18,12 @@
@implementation wxNSBox
- (void)setImplementation: (wxWidgetImpl *) theImplementation
- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation
{
impl = theImplementation;
}
- (wxWidgetImpl*) implementation
- (wxWidgetCocoaImpl*) implementation
{
return impl;
}

View File

@@ -29,31 +29,12 @@
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 ) )
{
bounds.h = bestsize.right - bestsize.left ;
bounds.v = bestsize.bottom - bestsize.top ;
}
else
#endif
{
#if wxOSX_USE_CARBON
ControlFontStyleRec controlFont;
OSStatus err = m_peer->GetData<ControlFontStyleRec>( kControlEntireControl, kControlFontStyleTag, &controlFont );
verify_noerr( err );
wxCFStringRef str( m_label, GetFont().GetEncoding() );
Point bounds;
#if wxOSX_USE_ATSU_TEXT
OSStatus err = noErr;
wxCFStringRef str( m_label, GetFont().GetEncoding() );
SInt16 baseline;
if ( m_font.MacGetThemeFontID() != kThemeCurrentPortFont )
{
@@ -63,19 +44,20 @@ wxSize wxStaticText::DoGetBestSize() const
verify_noerr( err );
}
else
#endif
#endif
{
wxClientDC dc(const_cast<wxStaticText*>(this));
wxCoord width, height ;
dc.GetTextExtent( m_label , &width, &height);
bounds.h = width;
// 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;
}
if ( m_label.empty() )
bounds.h = 0;
}
bounds.h += MacGetLeftBorderSize() + MacGetRightBorderSize();
bounds.v += MacGetTopBorderSize() + MacGetBottomBorderSize();

View File

@@ -51,12 +51,12 @@
@implementation wxNSTextField
- (void)setImplementation: (wxWidgetImpl *) theImplementation
- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation
{
impl = theImplementation;
}
- (wxWidgetImpl*) implementation
- (wxWidgetCocoaImpl*) implementation
{
return impl;
}

View 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
//