Hi Cor,

Cor Nouws escribió:
Hi Ariel,

Solved, but one question left:
b. First I tried com.sun.star.awt.XKeyListener, but addKeyListener seems not to be a method of oView, and I can't see any info why.
[...]
For adding a key handler, you must use the method addKeyHandler() from the interface XUserInputInterception. This interface is implemented by the controller css.frame.Controller (of all office documents except OOo Base). [...] For adding a key listener, you must use the method addKeyListener() from the interface css.awt.XWindow. In Basic

ThisComponent.getCurrentController().getFrame().getContainerWindow().addKeyListener()


How could I have found the different components that are needed by those two listeners?

Oh what a question! not very simple to answer! So I tell just how *I*
started (may be someone else has a better story/method).

First, it's quite impossible to start in OOo Basic/OOo API without
Bernard's Xray (we should build him a monument!), the variables Watcher
in the IDE is fine, but Xray is more powerful.

Then let's assume you have found somehow that there is an interface
com.sun.star.awt.XKeyListener that has methods you want to use.

The key to use the API documentation is going to the page where the
interface is documented, for example

http://api.openoffice.org/docs/common/ref/com/sun/star/awt/XKeyListener.html

then click on the top "Use", that shows you how this interface is used

http://api.openoffice.org/docs/common/ref/com/sun/star/awt/XKeyListener-xref.html
this "uses of interface XKeyListener" page is quite useful (if available
includes references to the Dev's Guide)

There you see

Uses as Parameter
XWindow::addKeyListener()
XWindow::removeKeyListener()

this means that if you want to listen to keyboard events, you must add a key listener using the XWindow 's method addKeyListener(myListener)

The next step is answering to yourself "so, where do I get an XWindow?"
Here start clicking on the XWindow link, that will take you to
http://api.openoffice.org/docs/common/ref/com/sun/star/awt/XWindow.html
There you have the Dev's Guide links, and also the "Use" link.

In "Use" look at "Services which Support this Interface"
There you can learn that the UnoControlDialog supports XWindow, so if
you want to add a key listener to a dialog you just do in OOo Basic

oDlg = createUnoDialog(MyLibrary.MyModule.MyDlg)
...
oDlg.addKeyListener()

and as every dialog control is a[n abstract] window, you can also add a listener to a control:

oCtrl = oDlg.getControl("MyControl")
...
oCtrl.addKeyListener()

For knowing where to get an XWindow from an OOo document, you will have
to go to the Dev's Guide. In
http://api.openoffice.org/docs/common/ref/com/sun/star/awt/XWindow.html
they send you to the right places in the Office Development chapter. You
puzzle is solved in
http://doc.services.openoffice.org/wiki/Documentation/DevGuide/OfficeDev/Component/Getting_Frames%2C_Controllers_and_Models_from_Each_Other

The graphic
http://doc.services.openoffice.org/wiki/Image:FCMNavigation.png is quite
explicit: "The following illustration shows the methods that get the
controller and frame for a document model and conversely. From the frame
, obtain the corresponding component and container window."
Just notice that you can get the XModel in OOo simply using ThisComponent

If you do not want to read all this chapter, that for an OOo Basic user
may be quite abstract/high-level, you can just Xray ThisComponent, but
* tell it to show you the "Details": in this way it tells you that
ContainerWindow is a com.sun.star.awt.XWindow, not only an object
* you will have to inspect until discovering that the way to the
ContainerWindow is ThisComponent - CurrentController - Frame -
ContainerWindow.


I only get used to all this when I started with Java and then C++: the
simplicity of OOo Basic hides the knowledge of what interfaces an object
implements, what methods an interfaces offers, etc. because the dot "."
as operator just keeps things simple (and well hidden). so that at some
point you may not know if something is a method of an interface
implemented by the object, or a property of the service the object is
instantiated from, etc

Notice that I get used, but I don't have all the clues: I'm now wondering how do I get in OOo Basic a css::rendering::XCanvas from a css::awt::XWindow (ironically I know how to get it from a vcl Window, as it has two methods: Window::GetCanvas() and Window::GetFullScreenCanvas() [vcl/inc/vcl/window.hxx, 1071ss // vcl/source/window/window.cxx, 9719ss])
But this is another topic, and I will ask it here in turn.


Regards
Ariel.




--
Ariel Constenla-Haile
La Plata, Argentina

[EMAIL PROTECTED]
[EMAIL PROTECTED]

http://www.ArielConstenlaHaile.com.ar/ooo/



"Aus der Kriegsschule des Lebens
                - Was mich nicht umbringt,
        macht mich härter."
                Nietzsche Götzendämmerung, Sprüche und Pfeile, 8.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to