Paolo Mantovani wrote On 05/14/06 23:54,:
Just a small addition:
Of course, holding a reference of the listener into a global variable is a
good thing, (especially when you need to de-register it at latter time),
anyway, the listener survives even if you don't store it in a global var:
AFAIK a registered listener is not disposed by the Basic engine while the
broadcaster still holds a reference to it:
f.e. with the following code you will be bothered by the msgbox whenever you
change selection, and to kill the listener you must close the document:
------------------
Sub testListener()
oListener = createUnoListener("Doc_", _
"com.sun.star.view.XSelectionChangeListener")
ThisComponent.CurrentController.addSelectionChangeListener(oListener)
End Sub
Sub Doc_selectionChanged(oEvent)
msgbox "ciao"
End Sub
Sub Document_disposing(oEvent)
'nothing to do
End Sub
Hi Paolo,
In your example I cannot see how you want to store data context
dependent. The macros are static and can be called from several user
interface element instances! There are information which are
view-dependent (like cursor position) or model-dependent (like modified
state) and there are situations where a macro wants to store the data
for later use. Macros can retrieve the context information from the
oEvent object, but how should a macro store this data dependent on the
event source?
From my point of view the only way one could write macros would be to
not store any data, but make it dependent on listeners.
A developer wants to display the cursor position in a toolbar edit field
with an add-on. The Basic script has to be listener for "OnViewCreated".
Whenever the listener is called it has to add a second listener for the
cursor travel. When the cursor travel listener is called the correct
dispatch object must be retrieved from a global instance (may be
something like a DispatchObjectManager for macros) and the information
must be provided via statusChanged. Macros are therefore triggered by
the listener mechanism, which overcomes the static nature of macros.
Regards,
Carsten
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]