universal implementation for osx cocoa

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@54819 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor
2008-07-29 19:58:39 +00:00
parent c16b215350
commit 33e902756f
3 changed files with 948 additions and 0 deletions

View File

@@ -0,0 +1,376 @@
/////////////////////////////////////////////////////////////////////////////
// Name: src/mac/cocoa/nonownedwnd.mm
// Purpose: non owned window for cocoa
// Author: DavidStefan Csomor
// Modified by:
// Created: 2008-06-20
// RCS-ID: $Id: nonownedwnd.mm 48805 2007-09-19 14:52:25Z SC $
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#include "wx/wxprec.h"
#if wxOSX_USE_COCOA
#include <Cocoa/Cocoa.h>
#else
#include <UIKit/UIKit.h>
#endif
#ifdef __WXMAC__
#include "wx/osx/private.h"
#endif
#if wxOSX_USE_COCOA
NSRect wxToNSRect( NSView* parent, const wxRect& r )
{
NSRect frame = parent ? [parent bounds] : [[NSScreen mainScreen] frame];
int y = r.y;
int x = r.x ;
if ( parent != NULL && ![ parent isFlipped ] )
y = frame.size.height - ( r.y + r.height );
return NSMakeRect(x, y, r.width , r.height);
}
wxRect wxFromNSRect( NSView* parent, const NSRect& rect )
{
NSRect frame = parent ? [parent bounds] : [[NSScreen mainScreen] frame];
int y = rect.origin.y;
int x = rect.origin.x;
if ( parent != NULL && ![ parent isFlipped ] )
y = frame.size.height - (rect.origin.y + rect.size.height);
return wxRect( x, y, rect.size.width, rect.size.height );
}
NSPoint wxToNSPoint( NSView* parent, const wxPoint& p )
{
NSRect frame = parent ? [parent bounds] : [[NSScreen mainScreen] frame];
int x = p.x ;
int y = p.y;
if ( parent != NULL && ![ parent isFlipped ] )
y = frame.size.height - ( p.y );
return NSMakePoint(x, y);
}
wxPoint wxFromNSPoint( NSView* parent, const NSPoint& p )
{
NSRect frame = parent ? [parent bounds] : [[NSScreen mainScreen] frame];
int x = p.x;
int y = p.y;
if ( parent != NULL && ![ parent isFlipped ] )
y = frame.size.height - ( p.y );
return wxPoint( x, y);
}
IMPLEMENT_DYNAMIC_CLASS( wxNonOwnedWindowCocoaImpl , wxNonOwnedWindowImpl )
wxNonOwnedWindowCocoaImpl::wxNonOwnedWindowCocoaImpl( wxNonOwnedWindow* nonownedwnd) :
wxNonOwnedWindowImpl(nonownedwnd)
{
m_macWindow = NULL;
m_macFullScreenData = NULL;
}
wxNonOwnedWindowCocoaImpl::wxNonOwnedWindowCocoaImpl()
{
m_macWindow = NULL;
m_macFullScreenData = NULL;
}
wxNonOwnedWindowCocoaImpl::~wxNonOwnedWindowCocoaImpl()
{
[m_macWindow release];
}
void wxNonOwnedWindowCocoaImpl::Destroy()
{
wxPendingDelete.Append( new wxDeferredObjectDeleter( this ) );
}
void wxNonOwnedWindowCocoaImpl::Create( wxWindow* parent, const wxPoint& pos, const wxSize& size,
long style, long extraStyle, const wxString& name )
{
int windowstyle = NSBorderlessWindowMask;
if ( style & wxFRAME_TOOL_WINDOW )
m_macWindow = [NSPanel alloc];
else
m_macWindow = [NSWindow alloc];
CGWindowLevel level = kCGNormalWindowLevelKey;
if ( style & wxFRAME_TOOL_WINDOW )
{
if ( ( style & wxSTAY_ON_TOP ) )
level = kCGUtilityWindowLevel;
else
level = kCGFloatingWindowLevel ;
}
else if ( ( style & wxPOPUP_WINDOW ) )
{
level = kCGPopUpMenuWindowLevel;
/*
if ( ( style & wxBORDER_NONE ) )
{
wclass = kHelpWindowClass ; // has no border
attr |= kWindowNoShadowAttribute;
}
else
{
wclass = kPlainWindowClass ; // has a single line border, it will have to do for now
}
*/
}
else if ( ( style & wxCAPTION ) )
{
windowstyle |= NSTitledWindowMask ;
}
else if ( ( style & wxFRAME_DRAWER ) )
{
/*
wclass = kDrawerWindowClass;
*/
}
else
{
// set these even if we have no title, otherwise the controls won't be visible
if ( ( style & wxMINIMIZE_BOX ) || ( style & wxMAXIMIZE_BOX ) ||
( style & wxCLOSE_BOX ) || ( style & wxSYSTEM_MENU ) )
{
windowstyle |= NSTitledWindowMask ;
}
/*
else if ( ( style & wxNO_BORDER ) )
{
wclass = kSimpleWindowClass ;
}
else
{
wclass = kPlainWindowClass ;
}
*/
}
if ( windowstyle & NSTitledWindowMask )
{
if ( ( style & wxMINIMIZE_BOX ) )
windowstyle |= NSMiniaturizableWindowMask ;
if ( ( style & wxMAXIMIZE_BOX ) )
windowstyle |= NSResizableWindowMask ; // TODO showing ZOOM ?
if ( ( style & wxRESIZE_BORDER ) )
windowstyle |= NSResizableWindowMask ;
if ( ( style & wxCLOSE_BOX) )
windowstyle |= NSClosableWindowMask ;
}
if ( extraStyle & wxFRAME_EX_METAL)
windowstyle |= NSTexturedBackgroundWindowMask;
if ( ( style & wxSTAY_ON_TOP ) )
level = kCGUtilityWindowLevel;
/*
if ( ( style & wxFRAME_FLOAT_ON_PARENT ) )
group = GetWindowGroupOfClass(kFloatingWindowClass);
*/
NSRect r = wxToNSRect( NULL, wxRect( pos, size) );
[m_macWindow initWithContentRect:r
styleMask:windowstyle
backing:NSBackingStoreBuffered
defer:NO
];
[m_macWindow setLevel:level];
// [m_macWindow makeKeyAndOrderFront:nil];
}
WXWindow wxNonOwnedWindowCocoaImpl::GetWXWindow() const
{
return m_macWindow;
}
void wxNonOwnedWindowCocoaImpl::Raise()
{
[m_macWindow orderWindow:NSWindowAbove relativeTo:0];
}
void wxNonOwnedWindowCocoaImpl::Lower()
{
[m_macWindow orderWindow:NSWindowBelow relativeTo:0];
}
bool wxNonOwnedWindowCocoaImpl::Show(bool show)
{
if ( show )
{
[m_macWindow orderFront:nil];
[[m_macWindow contentView] setNeedsDisplay:YES];
}
else
[m_macWindow orderOut:nil];
return true;
}
bool wxNonOwnedWindowCocoaImpl::ShowWithEffect(bool show, wxShowEffect effect, unsigned timeout)
{
return Show(show);
}
void wxNonOwnedWindowCocoaImpl::Update()
{
[m_macWindow displayIfNeeded];
}
bool wxNonOwnedWindowCocoaImpl::SetTransparent(wxByte alpha)
{
[m_macWindow setAlphaValue:(CGFloat) alpha/255.0];
return true;
}
bool wxNonOwnedWindowCocoaImpl::SetBackgroundColour(const wxColour& col )
{
return true;
}
void wxNonOwnedWindowCocoaImpl::SetExtraStyle( long exStyle )
{
if ( m_macWindow )
{
bool metal = exStyle & wxFRAME_EX_METAL ;
int windowStyle = [ m_macWindow styleMask];
if ( metal && !(windowStyle & NSTexturedBackgroundWindowMask) )
{
wxFAIL_MSG( _T("Metal Style cannot be changed after creation") );
}
else if ( !metal && (windowStyle & NSTexturedBackgroundWindowMask ) )
{
wxFAIL_MSG( _T("Metal Style cannot be changed after creation") );
}
}
}
bool wxNonOwnedWindowCocoaImpl::SetBackgroundStyle(wxBackgroundStyle style)
{
return true;
}
bool wxNonOwnedWindowCocoaImpl::CanSetTransparent()
{
return true;
}
void wxNonOwnedWindowCocoaImpl::MoveWindow(int x, int y, int width, int height)
{
NSRect r = wxToNSRect( NULL, wxRect(x,y,width, height) );
[m_macWindow setFrame:r display:YES];
}
void wxNonOwnedWindowCocoaImpl::GetPosition( int &x, int &y ) const
{
wxRect r = wxFromNSRect( NULL, [m_macWindow frame] );
x = r.GetLeft();
y = r.GetTop();
}
void wxNonOwnedWindowCocoaImpl::GetSize( int &width, int &height ) const
{
NSRect rect = [m_macWindow frame];
width = rect.size.width;
height = rect.size.height;
}
void wxNonOwnedWindowCocoaImpl::GetContentArea( int& left, int &right, int &width, int &height ) const
{
NSRect outer = NSMakeRect(100,100,100,100);
NSRect content = [NSWindow contentRectForFrameRect:outer styleMask:[m_macWindow styleMask] ];
NSRect rect = [[m_macWindow contentView] frame];
width = rect.size.width;
height = rect.size.height;
}
bool wxNonOwnedWindowCocoaImpl::SetShape(const wxRegion& region)
{
return false;
}
void wxNonOwnedWindowCocoaImpl::SetTitle( const wxString& title, wxFontEncoding encoding )
{
[m_macWindow setTitle:wxCFStringRef( title , encoding ).AsNSString()];
}
bool wxNonOwnedWindowCocoaImpl::IsMaximized() const
{
return [m_macWindow isZoomed];
}
bool wxNonOwnedWindowCocoaImpl::IsIconized() const
{
return [m_macWindow isMiniaturized];
}
void wxNonOwnedWindowCocoaImpl::Iconize( bool iconize )
{
if ( iconize )
[m_macWindow miniaturize:nil];
else
[m_macWindow deminiaturize:nil];
}
void wxNonOwnedWindowCocoaImpl::Maximize(bool maximize)
{
[m_macWindow zoom:nil];
}
// http://cocoadevcentral.com/articles/000028.php
typedef struct
{
int m_formerLevel;
NSRect m_formerFrame;
} FullScreenData ;
bool wxNonOwnedWindowCocoaImpl::IsFullScreen() const
{
return m_macFullScreenData != NULL ;
}
bool wxNonOwnedWindowCocoaImpl::ShowFullScreen(bool show, long style)
{
if ( show )
{
FullScreenData *data = (FullScreenData *)m_macFullScreenData ;
delete data ;
data = new FullScreenData();
m_macFullScreenData = data ;
data->m_formerLevel = [m_macWindow level];
data->m_formerFrame = [m_macWindow frame];
CGDisplayCapture( kCGDirectMainDisplay );
[m_macWindow setLevel:CGShieldingWindowLevel()];
[m_macWindow setFrame:[[NSScreen mainScreen] frame] display:YES];
}
else if ( m_macFullScreenData != NULL )
{
FullScreenData *data = (FullScreenData *) m_macFullScreenData ;
CGDisplayRelease( kCGDirectMainDisplay );
[m_macWindow setLevel:data->m_formerLevel];
[m_macWindow setFrame:data->m_formerFrame display:YES];
delete data ;
m_macFullScreenData = NULL ;
}
return true;
}
void wxNonOwnedWindowCocoaImpl::RequestUserAttention(int WXUNUSED(flags))
{
}
#endif

138
src/osx/cocoa/utils.mm Normal file
View File

@@ -0,0 +1,138 @@
/////////////////////////////////////////////////////////////////////////////
// Name: src/mac/cocoa/utils.mm
// Purpose: various cocoa utility functions
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id: utils.mm 48805 2007-09-19 14:52:25Z SC $
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#include "wx/wxprec.h"
#include "wx/wxprec.h"
#include "wx/utils.h"
#ifndef WX_PRECOMP
#include "wx/intl.h"
#include "wx/app.h"
#if wxUSE_GUI
#include "wx/toplevel.h"
#include "wx/font.h"
#endif
#endif
#include "wx/apptrait.h"
#include "wx/osx/private.h"
#if wxUSE_GUI
#if wxOSX_USE_COCOA_OR_CARBON
#include "wx/osx/uma.h"
#include <CoreServices/CoreServices.h>
#include <Carbon/Carbon.h>
#include "wx/osx/private/timer.h"
#endif
#endif // wxUSE_GUI
#if wxOSX_USE_COCOA
#if wxUSE_BASE
// Emit a beeeeeep
void wxBell()
{
NSBeep();
}
// ----------------------------------------------------------------------------
// Common Event Support
// ----------------------------------------------------------------------------
void wxMacWakeUp()
{
// TODO
}
#endif // wxUSE_BASE
#if wxUSE_GUI
void wxClientDisplayRect(int *x, int *y, int *width, int *height)
{
NSRect displayRect = [[NSScreen mainScreen] visibleFrame];
wxRect r = wxFromNSRect( NULL, displayRect );
if ( x )
*x = r.x;
if ( y )
*y = r.y;
if ( width )
*width = r.GetWidth();
if ( height )
*height = r.GetHeight();
}
void wxGetMousePosition( int* x, int* y )
{
wxPoint pt = wxFromNSPoint(NULL, [NSEvent mouseLocation]);
};
wxTimerImpl* wxGUIAppTraits::CreateTimerImpl(wxTimer *timer)
{
return new wxCarbonTimerImpl(timer);
}
int gs_wxBusyCursorCount = 0;
extern wxCursor gMacCurrentCursor;
wxCursor gMacStoredActiveCursor;
// Set the cursor to the busy cursor for all windows
void wxBeginBusyCursor(const wxCursor *cursor)
{
if (gs_wxBusyCursorCount++ == 0)
{
gMacStoredActiveCursor = gMacCurrentCursor;
cursor->MacInstall();
wxSetCursor(*cursor);
}
//else: nothing to do, already set
}
// Restore cursor to normal
void wxEndBusyCursor()
{
wxCHECK_RET( gs_wxBusyCursorCount > 0,
wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
if (--gs_wxBusyCursorCount == 0)
{
gMacStoredActiveCursor.MacInstall();
gMacStoredActiveCursor = wxNullCursor;
wxSetCursor(wxNullCursor);
}
}
// true if we're between the above two calls
bool wxIsBusy()
{
return (gs_wxBusyCursorCount > 0);
}
void wxMacGlobalToLocal( WindowRef window , Point*pt )
{
}
void wxMacLocalToGlobal( WindowRef window , Point*pt )
{
}
#endif // wxUSE_GUI
#endif // wxOSX_USE_COCOA

434
src/osx/cocoa/window.mm Normal file
View File

@@ -0,0 +1,434 @@
/////////////////////////////////////////////////////////////////////////////
// Name: src/osx/cocoa/window.mm
// Purpose: widgets (non tlw) for cocoa
// Author: Stefan Csomor
// Modified by:
// Created: 2008-06-20
// RCS-ID: $Id: window.mm 48805 2007-09-19 14:52:25Z SC $
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#include "wx/wxprec.h"
#include <Cocoa/Cocoa.h>
#ifdef __WXMAC__
#include "wx/osx/private.h"
#endif
#if wxOSX_USE_COCOA
@interface wxNSView : NSView
{
wxWidgetImpl* m_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;
- (void)setImplementation: (wxWidgetImpl *) theImplementation;
- (wxWidgetImpl*) implementation;
- (BOOL) isFlipped;
- (BOOL) becomeFirstResponder;
- (BOOL) resignFirstResponder;
@end // wxNSView
void SetupMouseEvent( wxMouseEvent &wxevent , NSEvent * nsEvent )
{
UInt32 modifiers = [nsEvent modifierFlags] ;
wxPoint screenMouseLocation = wxFromNSPoint( NULL, [nsEvent locationInWindow]);
// these parameters are not given for all events
UInt32 button = [nsEvent buttonNumber];
UInt32 clickCount = [nsEvent clickCount];
UInt32 mouseChord = 0; // TODO does this exist for cocoa
wxevent.m_x = screenMouseLocation.x;
wxevent.m_y = screenMouseLocation.y;
wxevent.m_shiftDown = modifiers & NSShiftKeyMask;
wxevent.m_controlDown = modifiers & NSControlKeyMask;
wxevent.m_altDown = modifiers & NSAlternateKeyMask;
wxevent.m_metaDown = modifiers & NSCommandKeyMask;
wxevent.m_clickCount = clickCount;
wxevent.SetTimestamp( [nsEvent timestamp] ) ;
/*
// a control click is interpreted as a right click
bool thisButtonIsFakeRight = false ;
if ( button == kEventMouseButtonPrimary && (modifiers & controlKey) )
{
button = kEventMouseButtonSecondary ;
thisButtonIsFakeRight = true ;
}
// otherwise we report double clicks by connecting a left click with a ctrl-left click
if ( clickCount > 1 && button != g_lastButton )
clickCount = 1 ;
// we must make sure that our synthetic 'right' button corresponds in
// mouse down, moved and mouse up, and does not deliver a right down and left up
if ( cEvent.GetKind() == kEventMouseDown )
{
g_lastButton = button ;
g_lastButtonWasFakeRight = thisButtonIsFakeRight ;
}
if ( button == 0 )
{
g_lastButton = 0 ;
g_lastButtonWasFakeRight = false ;
}
else if ( g_lastButton == kEventMouseButtonSecondary && g_lastButtonWasFakeRight )
button = g_lastButton ;
// Adjust the chord mask to remove the primary button and add the
// secondary button. It is possible that the secondary button is
// already pressed, e.g. on a mouse connected to a laptop, but this
// possibility is ignored here:
if( thisButtonIsFakeRight && ( mouseChord & 1U ) )
mouseChord = ((mouseChord & ~1U) | 2U);
if(mouseChord & 1U)
wxevent.m_leftDown = true ;
if(mouseChord & 2U)
wxevent.m_rightDown = true ;
if(mouseChord & 4U)
wxevent.m_middleDown = true ;
*/
// translate into wx types
int eventType = [nsEvent type];
switch (eventType)
{
case NSLeftMouseDown :
case NSRightMouseDown :
case NSOtherMouseDown :
switch ( button )
{
case 0 :
wxevent.SetEventType( clickCount > 1 ? wxEVT_LEFT_DCLICK : wxEVT_LEFT_DOWN ) ;
break ;
case 1 :
wxevent.SetEventType( clickCount > 1 ? wxEVT_RIGHT_DCLICK : wxEVT_RIGHT_DOWN ) ;
break ;
case 2 :
wxevent.SetEventType( clickCount > 1 ? wxEVT_MIDDLE_DCLICK : wxEVT_MIDDLE_DOWN ) ;
break ;
default:
break ;
}
break ;
case NSLeftMouseUp :
case NSRightMouseUp :
case NSOtherMouseUp :
switch ( button )
{
case 0 :
wxevent.SetEventType( wxEVT_LEFT_UP ) ;
break ;
case 1 :
wxevent.SetEventType( wxEVT_RIGHT_UP ) ;
break ;
case 2 :
wxevent.SetEventType( wxEVT_MIDDLE_UP ) ;
break ;
default:
break ;
}
break ;
case NSScrollWheel :
{
wxevent.SetEventType( wxEVT_MOUSEWHEEL ) ;
/*
EventMouseWheelAxis axis = cEvent.GetParameter<EventMouseWheelAxis>(kEventParamMouseWheelAxis, typeMouseWheelAxis) ;
SInt32 delta = cEvent.GetParameter<SInt32>(kEventParamMouseWheelDelta, typeSInt32) ;
*/
wxevent.m_wheelRotation = 10; // delta;
wxevent.m_wheelDelta = 1;
wxevent.m_linesPerAction = 1;
if ( 0 /* axis == kEventMouseWheelAxisX*/ )
wxevent.m_wheelAxis = 1;
}
break ;
case NSMouseEntered :
case NSMouseExited :
case NSLeftMouseDragged :
case NSRightMouseDragged :
case NSOtherMouseDragged :
case NSMouseMoved :
wxevent.SetEventType( wxEVT_MOTION ) ;
break;
default :
break ;
}
}
@implementation wxNSView
- (void)drawRect: (NSRect) rect
{
if ( m_impl )
{
CGContextRef context = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
CGContextSaveGState( context );
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);
if ( [ self isFlipped ] == NO )
{
CGContextTranslateCTM( context, 0, [self bounds].size.height );
CGContextScaleCTM( context, 1, -1 );
}
m_impl->GetWXPeer()->MacSetCGContextRef( context );
wxPaintEvent event;
event.SetTimestamp(0); // todo
event.SetEventObject(m_impl->GetWXPeer());
m_impl->GetWXPeer()->HandleWindowEvent(event);
CGContextRestoreGState( context );
}
}
-(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;
m_impl->GetWXPeer()->HandleWindowEvent(wxevent);
}
- (void)setImplementation: (wxWidgetImpl *) theImplementation
{
m_impl = theImplementation;
}
- (wxWidgetImpl*) implementation
{
return m_impl;
}
- (BOOL) isFlipped
{
return YES;
}
- (BOOL) becomeFirstResponder
{
BOOL r = [super becomeFirstResponder];
if ( r )
{
}
return r;
}
- (BOOL) resignFirstResponder
{
BOOL r = [super resignFirstResponder];
if ( r )
{
}
return r;
}
@end // wxNSView
IMPLEMENT_DYNAMIC_CLASS( wxWidgetCocoaImpl , wxWidgetImpl )
wxWidgetCocoaImpl::wxWidgetCocoaImpl( wxWindowMac* peer , WXWidget w, bool isRootControl ) :
wxWidgetImpl( peer, isRootControl ), m_osxView(w)
{
}
wxWidgetCocoaImpl::wxWidgetCocoaImpl()
{
}
void wxWidgetCocoaImpl::Init()
{
m_osxView = NULL;
}
wxWidgetCocoaImpl::~wxWidgetCocoaImpl()
{
[m_osxView setImplementation:NULL];
[m_osxView release];
}
bool wxWidgetCocoaImpl::IsVisible() const
{
return [m_osxView isHiddenOrHasHiddenAncestor] == NO;
}
void wxWidgetCocoaImpl::Raise()
{
}
void wxWidgetCocoaImpl::Lower()
{
}
void wxWidgetCocoaImpl::ScrollRect( const wxRect *rect, int dx, int dy )
{
}
void wxWidgetCocoaImpl::Move(int x, int y, int width, int height)
{
NSRect r = wxToNSRect( [m_osxView superview], wxRect(x,y,width, height) );
[m_osxView setFrame:r];
}
void wxWidgetCocoaImpl::GetPosition( int &x, int &y ) const
{
wxRect r = wxFromNSRect( [m_osxView superview], [m_osxView frame] );
x = r.GetLeft();
y = r.GetTop();
}
void wxWidgetCocoaImpl::GetSize( int &width, int &height ) const
{
NSRect rect = [m_osxView frame];
width = rect.size.width;
height = rect.size.height;
}
void wxWidgetCocoaImpl::GetContentArea( int&left, int &top, int &width, int &height )
{
left = top = 0;
GetSize( width, height );
}
void wxWidgetCocoaImpl::SetNeedsDisplay( const wxRect* where )
{
if ( where )
[m_osxView setNeedsDisplayInRect:wxToNSRect(m_osxView, *where )];
else
[m_osxView setNeedsDisplay:YES];
}
bool wxWidgetCocoaImpl::GetNeedsDisplay() const
{
return [m_osxView needsDisplay];
}
void wxWidgetCocoaImpl::CanFocus() const
{
return [m_osxView acceptsFirstResponder] == YES;
}
bool wxWidgetCocoaImpl::HasFocus() const
{
return [m_osxView isFirstResponder] == YES;
}
bool wxWidgetCocoaImpl::SetFocus()
{
[m_osxView makeKeyWindow] ;
}
void wxWidgetCocoaImpl::RemoveFromParent()
{
[m_osxView removeFromSuperview];
}
void wxWidgetCocoaImpl::Embed( wxWidgetImpl *parent )
{
NSView* container = parent->GetWXWidget() ;
wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ;
[container addSubview:m_osxView];
}
//
// Factory methods
//
wxWidgetImpl* wxWidgetImpl::CreateUserPane( wxWindowMac* wxpeer, const wxPoint& pos, const wxSize& size,
long style, long extraStyle, const wxString& name)
{
NSView* sv = (wxpeer->GetParent()->GetHandle() );
NSRect r = wxToNSRect( sv, wxRect( pos, size) );
// Rect bounds = wxMacGetBoundsForControl( wxpeer, pos , size ) ;
wxNSView* v = [[wxNSView alloc] initWithFrame:r];
[sv addSubview:v];
wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
[v setImplementation:c];
return c;
}
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;
}
#endif