#include "wx/wxprec.h"
#ifndef WX_PRECOMP
-#include "wx/nonownedwnd.h"
+ #include "wx/nonownedwnd.h"
+ #include "wx/log.h"
#endif
#ifdef __WXMAC__
#include "wx/osx/private.h"
#endif
+#if wxUSE_CARET
+ #include "wx/caret.h"
+#endif
+
NSRect wxOSXGetFrameForControl( wxWindowMac* window , const wxPoint& pos , const wxSize &size , bool adjustForOrigin )
{
int x, y, w, h ;
@interface wxNSView : NSView
{
- wxWidgetImpl* impl;
+ WXCOCOAIMPL_COMMON_MEMBERS
}
- (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)keyDown:(NSEvent *)event;
-- (void)keyUp:(NSEvent *)event;
-- (void)flagsChanged:(NSEvent *)event;
-- (void)handleKeyEvent:(NSEvent *)event;
-
-- (void)setImplementation: (wxWidgetImpl *) theImplementation;
-- (wxWidgetImpl*) implementation;
-- (BOOL) isFlipped;
-- (BOOL) becomeFirstResponder;
-- (BOOL) resignFirstResponder;
+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;
+- (void)setFloatValue:(float)aFloat;
+- (void)setDoubleValue:(double)aDouble;
+
+- (void)setMinValue:(double)aDouble;
+- (void)setMaxValue:(double)aDouble;
+
+- (void)sizeToFit;
+
+- (BOOL)isEnabled;
+- (void)setEnabled:(BOOL)flag;
+
+- (void)setImage:(NSImage *)image;
+- (void)setControlSize:(NSControlSize)size;
+
+- (id)contentView;
+@end
+
long wxOSXTranslateCocoaKey(unsigned short code, int unichar )
{
long retval = code;
// 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_clickCount = clickCount;
wxevent.SetTimestamp( [nsEvent timestamp] * 1000.0 ) ;
/*
+ UInt32 mouseChord = 0; // TODO does this exist for cocoa
// a control click is interpreted as a right click
bool thisButtonIsFakeRight = false ;
if ( button == kEventMouseButtonPrimary && (modifiers & controlKey) )
}
}
--(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);
-}
-
-- (void)keyDown:(NSEvent *)event
-{
- [self handleKeyEvent:event];
-}
-
-- (void)keyUp:(NSEvent *)event
-{
- [self handleKeyEvent:event];
-}
-
-- (void)flagsChanged:(NSEvent *)event
-{
- [self handleKeyEvent:event];
-}
-
-- (void)handleKeyEvent:(NSEvent *)event
-{
- wxKeyEvent wxevent(wxEVT_KEY_DOWN);
- SetupKeyEvent( wxevent, event );
- impl->GetWXPeer()->HandleWindowEvent(wxevent);
-}
-
-
-- (void)setImplementation: (wxWidgetImpl *) theImplementation
-{
- impl = theImplementation;
-}
-
-- (wxWidgetImpl*) implementation
-{
- return 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;
-}
+WXCOCOAIMPL_COMMON_IMPLEMENTATION
- (BOOL) canBecomeKeyView
{
void wxWidgetCocoaImpl::Move(int x, int y, int width, int height)
{
+ wxWindowMac* parent = GetWXPeer()->GetParent();
+ // under Cocoa we might have a contentView in the wxParent to which we have to
+ // adjust the coordinates
+ if (parent)
+ {
+ wxPoint pt(parent->GetClientAreaOrigin());
+ x -= pt.x;
+ y -= pt.y;
+ }
NSRect r = wxToNSRect( [m_osxView superview], wxRect(x,y,width, height) );
[m_osxView setFrame:r];
}
void wxWidgetCocoaImpl::GetContentArea( int&left, int &top, int &width, int &height ) const
{
- left = top = 0;
- GetSize( width, height );
+ if ( [m_osxView respondsToSelector:@selector(contentView) ] )
+ {
+ NSView* cv = [m_osxView contentView];
+
+ NSRect bounds = [m_osxView bounds];
+ NSRect rect = [cv frame];
+
+ int y = rect.origin.y;
+ int x = rect.origin.x;
+ if ( ![ m_osxView isFlipped ] )
+ y = bounds.size.height - (rect.origin.y + rect.size.height);
+ left = x;
+ top = y;
+ width = rect.size.width;
+ height = rect.size.height;
+ }
+ else
+ {
+ left = top = 0;
+ GetSize( width, height );
+ }
}
void wxWidgetCocoaImpl::SetNeedsDisplay( const wxRect* where )
{
}
+bool wxWidgetCocoaImpl::DoHandleKeyEvent(NSEvent *event)
+{
+ wxKeyEvent wxevent(wxEVT_KEY_DOWN);
+ SetupKeyEvent( wxevent, event );
+ return GetWXPeer()->HandleWindowEvent(wxevent);
+}
+
+bool 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;
+
+ return GetWXPeer()->HandleWindowEvent(wxevent);
+}
+
+void wxWidgetCocoaImpl::DoNotifyFocusEvent(bool receivedFocus)
+{
+ wxWindow* thisWindow = GetWXPeer();
+ if ( thisWindow->MacGetTopLevelWindow() && NeedsFocusRect() )
+ {
+ thisWindow->MacInvalidateBorders();
+ }
+
+ if ( receivedFocus )
+ {
+ wxLogTrace(_T("Focus"), _T("focus set(%p)"), static_cast<void*>(thisWindow));
+ wxChildFocusEvent eventFocus((wxWindow*)thisWindow);
+ thisWindow->HandleWindowEvent(eventFocus);
+
+#if wxUSE_CARET
+ if ( thisWindow->GetCaret() )
+ thisWindow->GetCaret()->OnSetFocus();
+#endif
+
+ wxFocusEvent event(wxEVT_SET_FOCUS, thisWindow->GetId());
+ event.SetEventObject(thisWindow);
+ // TODO how to find out the targetFocusWindow ?
+ // event.SetWindow(targetFocusWindow);
+ thisWindow->HandleWindowEvent(event) ;
+ }
+ else // !receivedFocuss
+ {
+#if wxUSE_CARET
+ if ( thisWindow->GetCaret() )
+ thisWindow->GetCaret()->OnKillFocus();
+#endif
+
+ wxLogTrace(_T("Focus"), _T("focus lost(%p)"), static_cast<void*>(thisWindow));
+
+ wxFocusEvent event( wxEVT_KILL_FOCUS, thisWindow->GetId());
+ event.SetEventObject(thisWindow);
+ // TODO how to find out the targetFocusWindow ?
+ // event.SetWindow(targetFocusWindow);
+ thisWindow->HandleWindowEvent(event) ;
+ }
+}
+
+
//
// Factory methods
//