+#import <AppKit/NSScrollView.h>
+#import <AppKit/NSColor.h>
+#import <AppKit/NSClipView.h>
+#import <Foundation/NSException.h>
+#import <AppKit/NSApplication.h>
+#import <AppKit/NSWindow.h>
+
+// Turn this on to paint green over the dummy views for debugging
+#undef WXCOCOA_FILL_DUMMY_VIEW
+
+#ifdef WXCOCOA_FILL_DUMMY_VIEW
+#import <AppKit/NSBezierPath.h>
+#endif //def WXCOCOA_FILL_DUMMY_VIEW
+
+/* NSComparisonResult is typedef'd as an enum pre-Leopard but typedef'd as
+ * NSInteger post-Leopard. Pre-Leopard the Cocoa toolkit expects a function
+ * returning int and not NSComparisonResult. Post-Leopard the Cocoa toolkit
+ * expects a function returning the new non-enum NSComparsionResult.
+ * Hence we create a typedef named CocoaWindowCompareFunctionResult.
+ */
+#if defined(NSINTEGER_DEFINED)
+typedef NSComparisonResult CocoaWindowCompareFunctionResult;
+#else
+typedef int CocoaWindowCompareFunctionResult;
+#endif
+
+// A category for methods that are only present in Panther's SDK
+@interface NSView(wxNSViewPrePantherCompatibility)
+- (void)getRectsBeingDrawn:(const NSRect **)rects count:(int *)count;
+@end
+
+NSPoint CocoaTransformNSViewBoundsToWx(NSView *nsview, NSPoint pointBounds)
+{
+ wxCHECK_MSG(nsview, pointBounds, wxT("Need to have a Cocoa view to do translation"));
+ if([nsview isFlipped])
+ return pointBounds;
+ NSRect ourBounds = [nsview bounds];
+ return NSMakePoint
+ ( pointBounds.x
+ , ourBounds.size.height - pointBounds.y
+ );
+}
+
+NSRect CocoaTransformNSViewBoundsToWx(NSView *nsview, NSRect rectBounds)
+{
+ wxCHECK_MSG(nsview, rectBounds, wxT("Need to have a Cocoa view to do translation"));
+ if([nsview isFlipped])
+ return rectBounds;
+ NSRect ourBounds = [nsview bounds];
+ return NSMakeRect
+ ( rectBounds.origin.x
+ , ourBounds.size.height - (rectBounds.origin.y + rectBounds.size.height)
+ , rectBounds.size.width
+ , rectBounds.size.height
+ );
+}
+
+NSPoint CocoaTransformNSViewWxToBounds(NSView *nsview, NSPoint pointWx)
+{
+ wxCHECK_MSG(nsview, pointWx, wxT("Need to have a Cocoa view to do translation"));
+ if([nsview isFlipped])
+ return pointWx;
+ NSRect ourBounds = [nsview bounds];
+ return NSMakePoint
+ ( pointWx.x
+ , ourBounds.size.height - pointWx.y
+ );
+}
+
+NSRect CocoaTransformNSViewWxToBounds(NSView *nsview, NSRect rectWx)
+{
+ wxCHECK_MSG(nsview, rectWx, wxT("Need to have a Cocoa view to do translation"));
+ if([nsview isFlipped])
+ return rectWx;
+ NSRect ourBounds = [nsview bounds];
+ return NSMakeRect
+ ( rectWx.origin.x
+ , ourBounds.size.height - (rectWx.origin.y + rectWx.size.height)
+ , rectWx.size.width
+ , rectWx.size.height
+ );
+}
+
+// ========================================================================
+// wxWindowCocoaHider
+// ========================================================================
+class wxWindowCocoaHider: protected wxCocoaNSView
+{
+ DECLARE_NO_COPY_CLASS(wxWindowCocoaHider)
+public:
+ wxWindowCocoaHider(wxWindow *owner);
+ virtual ~wxWindowCocoaHider();
+ inline WX_NSView GetNSView() { return m_dummyNSView; }
+protected:
+ wxWindowCocoa *m_owner;
+ WX_NSView m_dummyNSView;
+ virtual void Cocoa_FrameChanged(void);
+ virtual void Cocoa_synthesizeMouseMoved(void) {}
+#ifdef WXCOCOA_FILL_DUMMY_VIEW
+ virtual bool Cocoa_drawRect(const NSRect& rect);
+#endif //def WXCOCOA_FILL_DUMMY_VIEW
+private:
+ wxWindowCocoaHider();
+};
+
+// ========================================================================
+// wxWindowCocoaScrollView
+// ========================================================================
+class wxWindowCocoaScrollView: protected wxCocoaNSView
+{
+ DECLARE_NO_COPY_CLASS(wxWindowCocoaScrollView)
+public:
+ wxWindowCocoaScrollView(wxWindow *owner);
+ virtual ~wxWindowCocoaScrollView();
+ inline WX_NSScrollView GetNSScrollView() { return m_cocoaNSScrollView; }
+ void ClientSizeToSize(int &width, int &height);
+ void DoGetClientSize(int *x, int *y) const;
+ void Encapsulate();
+ void Unencapsulate();
+protected:
+ wxWindowCocoa *m_owner;
+ WX_NSScrollView m_cocoaNSScrollView;
+ virtual void Cocoa_FrameChanged(void);
+ virtual void Cocoa_synthesizeMouseMoved(void) {}
+private:
+ wxWindowCocoaScrollView();
+};
+
+// ========================================================================
+// wxDummyNSView
+// ========================================================================
+@interface wxDummyNSView : NSView
+- (NSView *)hitTest:(NSPoint)aPoint;
+@end
+WX_DECLARE_GET_OBJC_CLASS(wxDummyNSView,NSView)
+
+@implementation wxDummyNSView : NSView
+- (NSView *)hitTest:(NSPoint)aPoint
+{
+ return nil;
+}
+
+@end
+WX_IMPLEMENT_GET_OBJC_CLASS(wxDummyNSView,NSView)
+
+// ========================================================================
+// wxWindowCocoaHider
+// ========================================================================
+wxWindowCocoaHider::wxWindowCocoaHider(wxWindow *owner)
+: m_owner(owner)
+{
+ wxASSERT(owner);
+ wxASSERT(owner->GetNSViewForHiding());
+ m_dummyNSView = [[WX_GET_OBJC_CLASS(wxDummyNSView) alloc]
+ initWithFrame:[owner->GetNSViewForHiding() frame]];
+ [m_dummyNSView setAutoresizingMask: [owner->GetNSViewForHiding() autoresizingMask]];
+ AssociateNSView(m_dummyNSView);
+}
+
+wxWindowCocoaHider::~wxWindowCocoaHider()
+{
+ DisassociateNSView(m_dummyNSView);
+ [m_dummyNSView release];
+}
+
+void wxWindowCocoaHider::Cocoa_FrameChanged(void)
+{
+ // Keep the real window in synch with the dummy
+ wxASSERT(m_dummyNSView);
+ [m_owner->GetNSViewForHiding() setFrame:[m_dummyNSView frame]];
+}