+void wxCocoaDCImpl::CocoaUnwindStackAndLoseFocus()
+{
+ wxCocoaDCStack::compatibility_iterator ourNode=sm_cocoaDCStack.Find(this);
+ if(ourNode)
+ {
+ wxCocoaDCStack::compatibility_iterator node=sm_cocoaDCStack.GetFirst();
+ for(;node!=ourNode; node=sm_cocoaDCStack.GetFirst())
+ {
+ wxCocoaDCImpl *dc = node->GetData();
+ wxASSERT(dc);
+ wxASSERT(dc!=this);
+ if(!dc->CocoaUnlockFocus())
+ {
+ wxFAIL_MSG(wxT("Unable to unlock focus on higher-level DC!"));
+ }
+ sm_cocoaDCStack.Erase(node);
+ }
+ wxASSERT(node==ourNode);
+ wxASSERT(ourNode->GetData() == this);
+ ourNode->GetData()->CocoaUnlockFocus();
+ sm_cocoaDCStack.Erase(ourNode);
+ }
+}
+
+bool wxCocoaDCImpl::CocoaUnwindStackAndTakeFocus()
+{
+ wxCocoaDCStack::compatibility_iterator node=sm_cocoaDCStack.GetFirst();
+ for(;node;node = sm_cocoaDCStack.GetFirst())
+ {
+ wxCocoaDCImpl *dc = node->GetData();
+ wxASSERT(dc);
+ // If we're on the stack, then it's unwound enough and we have focus
+ if(dc==this)
+ return true;
+ // If unable to unlockFocus (e.g. wxPaintDC) stop here
+ if(!dc->CocoaUnlockFocus())
+ break;
+ sm_cocoaDCStack.Erase(node);
+ }
+ return CocoaLockFocus();
+}
+
+wxCocoaDCImpl::wxCocoaDCImpl(wxDC *owner)
+: wxDCImpl(owner)
+{
+ m_cocoaWxToBoundsTransform = nil;
+ m_pen = *wxBLACK_PEN;
+}
+
+wxCocoaDCImpl::~wxDC(void)
+{
+ [m_cocoaWxToBoundsTransform release];
+}
+
+bool wxCocoaDCImpl::CocoaLockFocus()
+{
+ return false;
+}
+
+bool wxCocoaDCImpl::CocoaUnlockFocus()
+{
+ return false;
+}
+
+/*static*/ WX_NSAffineTransform wxCocoaDCImpl::CocoaGetWxToBoundsTransform(bool isFlipped, float height)
+{
+ NSAffineTransform *transform = nil;
+ // This transform flips the graphics since wxDC uses top-left origin
+ if(!isFlipped)
+ {
+ // The transform is auto released
+ transform = [NSAffineTransform transform];
+ /* x' = 1x + 0y + 0
+ y' = 0x + -1y + window's height
+ */
+ NSAffineTransformStruct matrix = {
+ 1, 0
+ , 0, -1
+ , 0, height
+ };
+ [transform setTransformStruct: matrix];
+ }
+ return transform;
+}
+
+void wxCocoaDCImpl::CocoaApplyTransformations()