Re: AXObserverRemoveNotification & destroyed elements.
Re: AXObserverRemoveNotification & destroyed elements.
- Subject: Re: AXObserverRemoveNotification & destroyed elements.
- From: Bill Cheeseman <email@hidden>
- Date: Fri, 02 Jun 2006 04:59:43 -0400
- Thread-topic: AXObserverRemoveNotification & destroyed elements.
on 2006-06-01 6:45 PM, Tom Bunch at email@hidden wrote:
> Are our observers automatically unregistered for notifications
> regarding destroyed AXUIElements? If I call
> AXObserverRemoveNotification with a destroyed element I get
> kAXErrorInvalidUIElement.
>
> I would like to be able to pass NULL for the element and/or the
> notification argument to AXObserverRemoveNotification to remove my
> observer from all elements and/or notifications.
This is a potentially complex subject.
I decided a long time ago that I must unregister notifications before
CFReleasing the destroyed element reference.
In my Cocoa framework covering the accessibility API, I take pains to remove
all registrations for a UI element before I finally release and dealloc it.
My Cocoa framework uses Cocoa UI element and observer objects, which contain
AXUIElementRef and AXObserverRef objects, among other things. These Cocoa
objects handle a lot of other issues, and I need to unwind a lot of stuff.
When calling AXObserverRemoveNotification, I simply ignore any
kAXErrorInvalidUIElement error. My Cocoa observer object has methods to
-unregisterForNotification:fromElement:,
-unregisterForAllNotificationsFromElement: and
-unregisterForAllNotifications. The latter two call the first in a loop.
I also use Ken Case's "weak retain" mechanism to make all this work without
circular retains, because I register all of my Cocoa UI element objects to
monitor kAXUIElementDestroyedNotification so I can deal with the destruction
of the element. See www.cocoadev.com/index.pl?WeakReferences. This is how
PreFab UI Browser is able to turn all destroyed elements orange in its
interface as soon as you close a window, for example.
You also have to watch out for a bug that has been in the accessibility API
since the beginning. The application activated/deactivated and hidden/shown
notifications are issued twice by Cocoa applications (once by Carbon and
once by Cocoa). In my Cocoa framework, I work around this, but to do so I
have to force registration and unregistration of both notifications in these
two pairs simultaneously.
--
Bill Cheeseman - email@hidden
Quechee Software, Quechee, Vermont, USA
http://www.quecheesoftware.com
PreFab Software - http://www.prefab.com/scripting.html
The AppleScript Sourcebook - http://www.AppleScriptSourcebook.com
Vermont Recipes - http://www.stepwise.com/Articles/VermontRecipes
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Accessibility-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden