+bool wxWindowDC::CocoaLockFocusOnNSView(WX_NSView nsview)
+{
+ if([nsview lockFocusIfCanDraw])
+ {
+ sm_cocoaDCStack.Insert(this);
+ m_cocoaFlipped = [nsview isFlipped];
+ m_cocoaHeight = [nsview bounds].size.height;
+ CocoaApplyTransformations();
+ m_lockedNSView = nsview;
+ return true;
+ }
+ wxLogDebug(wxT("focus lock failed!"));
+ return false;
+}
+
+bool wxWindowDC::CocoaUnlockFocusOnNSView()
+{
+ [[m_lockedNSView window] flushWindow];
+ [m_lockedNSView unlockFocus];
+ m_lockedNSView = NULL;
+ return true;
+}
+
+bool wxWindowDC::CocoaLockFocus()
+{
+ wxLogTrace(wxTRACE_COCOA,wxT("Locking focus on wxWindowDC=%p, NSView=%p"),this, m_window->GetNonClientNSView());
+ return CocoaLockFocusOnNSView(m_window->GetNonClientNSView());
+}
+
+bool wxWindowDC::CocoaUnlockFocus()
+{
+ wxLogTrace(wxTRACE_COCOA,wxT("Unlocking focus on wxWindowDC=%p, NSView=%p"),this, m_window->GetNonClientNSView());
+ return CocoaUnlockFocusOnNSView();
+}
+
+void wxWindowDC::Clear()
+{
+ if(!CocoaTakeFocus()) return;
+
+ NSGraphicsContext *context = [NSGraphicsContext currentContext];
+ [context saveGraphicsState];
+
+ [m_backgroundBrush.GetNSColor() set];
+ [NSBezierPath fillRect:[m_lockedNSView bounds]];
+
+ [context restoreGraphicsState];
+}
+