wheelsdong wrote:
Hi,
I am trying to create a simple OO Add-On supporting context menu, mouse
click and menu command.
I created an simple OpenOffice.org Add-on using the OpenOffice plugin for
NetBeans.
And I implemented two interfaces: com.sun.star.ui.XContextMenuInterceptor
and com.sun.star.awt.XMouseClickHandler.
The ContextMenuInterceptor and MouseClickHandler are registered in
initialize() function.
However, The problem is:
1, When I clicked the right mouse button, initialize() will be called, so
ContextMenuInterceptor and MouseClickHandler are registered more than one
time.
So If a left mouse button is pressed and released, the mouseReleased
function will be called many times.
2, The first time I click the newly added menu title, initialize() will also
be called.
My question is:
Since initialize() may be called many times. Where should I register
ContextMenuInterceptor and MouseClickHandler so that they are called only
once?
Thank you very much for your help.
Below are some code for your reference:
public void initialize(Object[] object)
throws com.sun.star.uno.Exception {
if (object.length > 0) {
m_xFrame = (com.sun.star.frame.XFrame) UnoRuntime.queryInterface(
com.sun.star.frame.XFrame.class, object[0]);
System.out.println("initialize is called. ");
XController xController = m_xFrame.getController();
// register context menu
// problem: how to add context menu immediately when the program is loaded?
if (xController != null) {
com.sun.star.ui.XContextMenuInterception xContextMenuInterception =
(com.sun.star.ui.XContextMenuInterception) UnoRuntime.queryInterface(
com.sun.star.ui.XContextMenuInterception.class, xController);
if (xContextMenuInterception != null) {
com.sun.star.ui.XContextMenuInterceptor xContextMenuInterceptor =
(com.sun.star.ui.XContextMenuInterceptor) UnoRuntime.queryInterface(
com.sun.star.ui.XContextMenuInterceptor.class, this);
xContextMenuInterception.registerContextMenuInterceptor(xContextMenuInterceptor);
}
// register mouse handler
com.sun.star.awt.XUserInputInterception xUserInputInterception =
(com.sun.star.awt.XUserInputInterception) UnoRuntime.queryInterface(
com.sun.star.awt.XUserInputInterception.class, xController);
if (xUserInputInterception != null) {
xUserInputInterception.addMouseClickHandler(this);
}
}
}
}wheelsdong
Hi wheelsdong,
You should use a job and register for "OnViewCreated" events which call
your code once for every new frame. You can find more information about
Jobs in the online wiki:
http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/WritingUNO/Jobs/Jobs
Regards,
Carsten
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]