#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
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)
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 );
{
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 );
}
}
-- (void)setImplementation: (wxWidgetImpl *) theImplementation
+- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation
{
impl = theImplementation;
}
-- (wxWidgetImpl*) implementation
+- (wxWidgetCocoaImpl*) implementation
{
return impl;
}
@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;
}
@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;
}
@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
return self;
}
-- (void)setImplementation: (wxWidgetImpl *) theImplementation
+- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation
{
impl = theImplementation;
}
-- (wxWidgetImpl*) implementation
+- (wxWidgetCocoaImpl*) implementation
{
return impl;
}
@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 ;
}
@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;
}
@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;
}
@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;
}
@implementation wxNSBox
-- (void)setImplementation: (wxWidgetImpl *) theImplementation
+- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation
{
impl = theImplementation;
}
-- (wxWidgetImpl*) implementation
+- (wxWidgetCocoaImpl*) implementation
{
return impl;
}
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();
@implementation wxNSTextField
-- (void)setImplementation: (wxWidgetImpl *) theImplementation
+- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation
{
impl = theImplementation;
}
-- (wxWidgetImpl*) implementation
+- (wxWidgetCocoaImpl*) implementation
{
return impl;
}
@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;
}
}
--(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
{
}
-- (void)setImplementation: (wxWidgetImpl *) theImplementation
+- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation
{
impl = theImplementation;
}
-- (wxWidgetImpl*) implementation
+- (wxWidgetCocoaImpl*) implementation
{
return impl;
}
{
}
+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
//