+WX_DECLARE_HASH_MAP(WXWidget, wxWidgetImpl*, wxPointerHash, wxPointerEqual, MacControlMap);
+
+static MacControlMap wxWinMacControlList;
+
+wxWindowMac *wxFindWindowFromWXWidget(WXWidget inControl )
+{
+ wxWidgetImpl* impl = wxWidgetImpl::FindFromWXWidget( inControl );
+ if ( impl )
+ return impl->GetWXPeer();
+
+ return NULL;
+}
+
+wxWidgetImpl *wxWidgetImpl::FindFromWXWidget(WXWidget inControl )
+{
+ MacControlMap::iterator node = wxWinMacControlList.find(inControl);
+
+ return (node == wxWinMacControlList.end()) ? NULL : node->second;
+}
+
+void wxWidgetImpl::Associate(WXWidget inControl, wxWidgetImpl *impl)
+{
+ // adding NULL ControlRef is (first) surely a result of an error and
+ // (secondly) breaks native event processing
+ wxCHECK_RET( inControl != (WXWidget) NULL, wxT("attempt to add a NULL WXWidget to control map") );
+
+ wxWinMacControlList[inControl] = impl;
+}
+
+void wxWidgetImpl::RemoveAssociations(wxWidgetImpl* impl)
+{
+ // iterate over all the elements in the class
+ // is the iterator stable ? as we might have two associations pointing to the same wxWindow
+ // we should go on...
+
+ bool found = true ;
+ while ( found )
+ {
+ found = false ;
+ MacControlMap::iterator it;
+ for ( it = wxWinMacControlList.begin(); it != wxWinMacControlList.end(); ++it )
+ {
+ if ( it->second == impl )
+ {
+ wxWinMacControlList.erase(it);
+ found = true ;
+ break;
+ }
+ }
+ }
+}
+