+#include "wx/wxprec.h"
+#ifndef WX_PRECOMP
+ #include "wx/log.h"
+ #include "wx/tooltip.h"
+ #include "wx/window.h"
+#endif //WX_PRECOMP
+
+#include "wx/cocoa/autorelease.h"
+#include "wx/cocoa/string.h"
+
+#import <AppKit/NSView.h>
+#import <AppKit/NSEvent.h>
+#import <AppKit/NSScrollView.h>
+#import <AppKit/NSColor.h>
+#import <AppKit/NSClipView.h>
+#import <Foundation/NSException.h>
+
+#include <objc/objc-runtime.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
+
+// A category for methods that are only present in Panther's SDK
+@interface NSView(wxNSViewPrePantherCompatibility)
+- (void)getRectsBeingDrawn:(const NSRect **)rects count:(int *)count;
+@end
+
+// ========================================================================
+// 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);
+#ifdef WXCOCOA_FILL_DUMMY_VIEW
+ virtual bool Cocoa_drawRect(const NSRect& rect);
+#endif //def WXCOCOA_FILL_DUMMY_VIEW
+private:
+ wxWindowCocoaHider();
+};
+
+// ========================================================================
+// wxWindowCocoaScroller
+// ========================================================================
+class wxWindowCocoaScroller: protected wxCocoaNSView
+{
+ DECLARE_NO_COPY_CLASS(wxWindowCocoaScroller)
+public:
+ wxWindowCocoaScroller(wxWindow *owner);
+ virtual ~wxWindowCocoaScroller();
+ 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);
+private:
+ wxWindowCocoaScroller();
+};
+
+// ========================================================================
+// wxDummyNSView
+// ========================================================================
+@interface wxDummyNSView : NSView
+- (NSView *)hitTest:(NSPoint)aPoint;
+@end
+
+@implementation wxDummyNSView : NSView
+- (NSView *)hitTest:(NSPoint)aPoint
+{
+ return nil;
+}
+
+@end
+
+// ========================================================================
+// wxWindowCocoaHider
+// ========================================================================
+wxWindowCocoaHider::wxWindowCocoaHider(wxWindow *owner)
+: m_owner(owner)
+{
+ wxASSERT(owner);
+ wxASSERT(owner->GetNSViewForHiding());
+ m_dummyNSView = [[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]];
+}
+
+
+#ifdef WXCOCOA_FILL_DUMMY_VIEW
+bool wxWindowCocoaHider::Cocoa_drawRect(const NSRect& rect)
+{
+ NSBezierPath *bezpath = [NSBezierPath bezierPathWithRect:rect];
+ [[NSColor greenColor] set];
+ [bezpath stroke];
+ [bezpath fill];
+ return true;
+}
+#endif //def WXCOCOA_FILL_DUMMY_VIEW
+
+// ========================================================================
+// wxFlippedNSClipView
+// ========================================================================
+@interface wxFlippedNSClipView : NSClipView
+- (BOOL)isFlipped;
+@end
+
+@implementation wxFlippedNSClipView : NSClipView
+- (BOOL)isFlipped
+{
+ return YES;
+}
+
+@end
+
+// ========================================================================
+// wxWindowCocoaScroller
+// ========================================================================
+wxWindowCocoaScroller::wxWindowCocoaScroller(wxWindow *owner)
+: m_owner(owner)
+{
+ wxAutoNSAutoreleasePool pool;
+ wxASSERT(owner);
+ wxASSERT(owner->GetNSView());
+ m_cocoaNSScrollView = [[NSScrollView alloc]
+ initWithFrame:[owner->GetNSView() frame]];
+ AssociateNSView(m_cocoaNSScrollView);
+
+ /* Replace the default NSClipView with a flipped one. This ensures
+ scrolling is "pinned" to the top-left instead of bottom-right. */
+ NSClipView *flippedClip = [[wxFlippedNSClipView alloc]
+ initWithFrame: [[m_cocoaNSScrollView contentView] frame]];
+ [m_cocoaNSScrollView setContentView:flippedClip];
+ [flippedClip release];
+
+ [m_cocoaNSScrollView setBackgroundColor: [NSColor windowBackgroundColor]];
+ [m_cocoaNSScrollView setHasHorizontalScroller: YES];
+ [m_cocoaNSScrollView setHasVerticalScroller: YES];
+ Encapsulate();
+}