[Solved] Register MouseEvents from Desktop Container

Java, C++, C#, Delphi... - Using the UNO bridges
Post Reply
jelias
Posts: 6
Joined: Fri Dec 25, 2015 9:32 am

[Solved] Register MouseEvents from Desktop Container

Post by jelias »

Hello guys.

I'm trying to develop a external Java application that interacts with OpenOffice. Basically I want to show the main toolbar buttons (new, save, ...) hints (when mouseover) in a other way, externally. I've been reading, trying and learning a lot OO SDK and UNO API last couple of days, developing a app that intercepts which button from toolbar would you moving the mouse, but until now I couldn't get this up.

Main code until now:

Code: Select all

XComponentContext xContext =  com.sun.star.comp.helper.Bootstrap.bootstrap();
XMultiComponentFactory xServiceManager = xContext.getServiceManager();
Object desktop = xServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", xContext );
XDesktop xDesktop = UnoRuntime.queryInterface(XDesktop.class, desktop);
XComponentLoader xComponentLoader =  (XComponentLoader)UnoRuntime.queryInterface(XComponentLoader.class, desktop );

// load a spreadsheet document
String loadURL = "private:factory/scalc"; PropertyValue[] loadProps = new PropertyValue[0];
XComponent document = xComponentLoader.loadComponentFromURL(loadURL, "_blank", 0, loadProps);

xFAL xFAL0 = new xFAL();

XDocumentEventBroadcaster xDEB =  (XDocumentEventBroadcaster)UnoRuntime.queryInterface(XDocumentEventBroadcaster.class, document );
xDEL xDEL0 = new xDEL();
xDEB.addDocumentEventListener(xDEL0);

xEL xEL0 = new xEL(); xEL xEL1 = new xEL();
xML xML0  = new xML(); xML xML1 = new xML();
xMM xMM0  = new xMM(); xMM xMM1 = new xMM();
xKL xKL0  = new xKL(); xKL xKL1 = new xKL();

XFrame frame = xDesktop.getCurrentFrame();

frame.getCreator().getActiveFrame().getContainerWindow().addMouseListener(xML0);
frame.getCreator().getActiveFrame().getContainerWindow().addMouseMotionListener(xMM0);
frame.getCreator().getActiveFrame().getContainerWindow().addKeyListener(xKL0);
frame.getCreator().getActiveFrame().getComponentWindow().addMouseListener(xML1);
frame.getCreator().getActiveFrame().getComponentWindow().addMouseMotionListener(xMM1);
frame.getCreator().getActiveFrame().getComponentWindow().addKeyListener(xKL1);

frame.getCreator().getActiveFrame().addFrameActionListener(xFAL0);

xWL xWL0 = new xWL();
frame.getCreator().getActiveFrame().getContainerWindow().addWindowListener(xWL0);
From all the component/container listeners above, just the WindowListener is registering the events. All mouse/key listeners are backing to me with nothing.

Can anyone help me with that code? Or suggest me a other way to go?
I'll appreciate any help.
Last edited by jelias on Sun Dec 27, 2015 6:41 am, edited 1 time in total.
OpenOffice 4.1.2 on LinuxMint 17.1 (x64)
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Register MouseEvents from Desktop Container

Post by Villeroy »

Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
jelias
Posts: 6
Joined: Fri Dec 25, 2015 9:32 am

Re: Register MouseEvents from Desktop Container

Post by jelias »

Thanks for the quick answer. The ODFToolkit is very interesting, but I will keep trying to register the OO main GUI events. May be JAVA AWT can't do that (register mouse/key events) because the GUI is being rendered in GTK?
OpenOffice 4.1.2 on LinuxMint 17.1 (x64)
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Register MouseEvents from Desktop Container

Post by Villeroy »

Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
jelias
Posts: 6
Joined: Fri Dec 25, 2015 9:32 am

Re: Register MouseEvents from Desktop Container

Post by jelias »

Thanks again Villeroy. I was trying to work with MRI since yesterday. With your link I could learn how to show up the generated MRI Java code and compare it with my. The only difference that I could notice is that it uses XWindow2 interface when I get the Container Window. I was following the SDK: https://wiki.openoffice.org/wiki/Docume ... Interfaces .
But the result was the same, no reponse from the listeners attached to Conatiner/Component Windows (either XWindow or XWindow2).
OpenOffice 4.1.2 on LinuxMint 17.1 (x64)
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Register MouseEvents from Desktop Container

Post by Villeroy »

Topic Header wrote:Register MouseEvents from Desktop Container
The desktop is an abstract container of frames without windows nor controllers. The contained frames may have windows (container window and component window). Windows can have mouse listeners.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
jelias
Posts: 6
Joined: Fri Dec 25, 2015 9:32 am

Re: Register MouseEvents from Desktop Container

Post by jelias »

Right! So, I tried

Code: Select all

xDesktop.getCurrentFrame().getContainerWindow().addMouseListener(xML0);
xDesktop.getCurrentFrame().getComponentWindow().addMouseListener(xML1);
But, until now, they didn't register any event.
Many thanks for your quick help.
OpenOffice 4.1.2 on LinuxMint 17.1 (x64)
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Register MouseEvents from Desktop Container

Post by Villeroy »

Could be a bug or not. I would not change the GUI programmatically. If I would change anthing at all, I would always configure a different GUI for a particular document template. Open/LibreOffice is much more about templates, styles and XML configuration rather than programming.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
jelias
Posts: 6
Joined: Fri Dec 25, 2015 9:32 am

Re: Register MouseEvents from Desktop Container

Post by jelias »

OK, let me try a new approach. From an external app I can simulate a click on any of the main toolbar buttons, trough the OO SDK?
OpenOffice 4.1.2 on LinuxMint 17.1 (x64)
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Register MouseEvents from Desktop Container

Post by Villeroy »

Use the dispatch framework as the macro recorder does. viewtopic.php?f=45&t=79540&p=365636#p365636
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
jelias
Posts: 6
Joined: Fri Dec 25, 2015 9:32 am

Re: Register MouseEvents from Desktop Container

Post by jelias »

Villeroy, many thanks for your tips. They guided me to a little sucess, 'cause now I have external control over the OO main UI.
Here the main piece of code. Hopefully it will help someone:

Code: Select all

XComponentContext xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
XMultiComponentFactory xServiceManager = xContext.getServiceManager();
Object desktop = xServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", xContext );
XDesktop xDesktop = UnoRuntime.queryInterface(XDesktop.class, desktop);
XComponentLoader xComponentLoader =  (XComponentLoader)UnoRuntime.queryInterface(XComponentLoader.class, desktop );

XComponent document = xComponentLoader.loadComponentFromURL("private:factory/scalc", "_blank", 0, loadProps);

XFrame dFrame = xDesktop.getCurrentFrame();
while (dFrame == null) dFrame = xDesktop.getCurrentFrame();

Object dispatcher = xServiceManager.createInstanceWithContext("com.sun.star.frame.DispatchHelper", xContext );
XDispatchHelper dispatch = UnoRuntime.queryInterface(XDispatchHelper.class, dispatcher);
XDispatchProvider provider = UnoRuntime.queryInterface(XDispatchProvider.class, dFrame);

dispatch.executeDispatch(provider, ".uno:SaveAs", "", 0, null);

xTL xTL0 = new xTL(); xDesktop.addTerminateListener(xTL0);
synchronized(xTL0){ xTL0.wait(); }
OpenOffice 4.1.2 on LinuxMint 17.1 (x64)
Post Reply