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
Posts: 3
Joined: Sun Oct 19, 2008 9:12 am
Primary OS: Ms Windows XP
OOo version: 2.4.X
Secondary OS(s): Mac OS
Private messageE-mail
--
View this message in context:
http://www.nabble.com/Where-to-register-MouseClickHandler-in-an-Add-On--tp20221786p20221786.html
Sent from the openoffice - api dev mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]