+void wxDC::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())
+ {
+ wxDC *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 wxDC::CocoaUnwindStackAndTakeFocus()
+{
+ wxCocoaDCStack::compatibility_iterator node=sm_cocoaDCStack.GetFirst();
+ for(;node;node = sm_cocoaDCStack.GetFirst())
+ {
+ wxDC *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();
+}
+