[api-dev] Changing menus of a document in background

2006-11-06 Thread Tobias Krais
Hi together again,

I have one more question. I would like to change the menus in a document
in the background. Up to now I can change menus for loaded documents in
the foreground. Here is the code:
-%-
XPropertySet xps = (XPropertySet)
UnoRuntime.queryInterface(XPropertySet.class,
xDesktop.getCurrentFrame());

XLayoutManager xLayoutManager = (XLayoutManager)
UnoRuntime.queryInterface(XLayoutManager.class,
xps.getPropertyValue(LayoutManager));
-%-

With this code (getCurrentFrame) I can only get the XLayoutManager of
the foreground Window.

Background info: I wrote a java application that opens a document.
Shortly after loading the document I start changing the menus. It can
happen that meanwhile an other OO Document comes in foreground and I
change the menus of this foreground window.

How can I get the XLayoutManager of the XComponent I am working on with
my application?

Greetings, Tobias

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



Re: [api-dev] Changing menus of a document in background

2006-11-06 Thread Stephan Wunderlich

Hi Tobias,
I have one more question. I would like to change the menus in a  
document
in the background. Up to now I can change menus for loaded  
documents in

the foreground. Here is the code:
-%-
XPropertySet xps = (XPropertySet)
UnoRuntime.queryInterface(XPropertySet.class,
xDesktop.getCurrentFrame());

XLayoutManager xLayoutManager = (XLayoutManager)
UnoRuntime.queryInterface(XLayoutManager.class,
xps.getPropertyValue(LayoutManager));
-%-

With this code (getCurrentFrame) I can only get the XLayoutManager of
the foreground Window.

Background info: I wrote a java application that opens a document.
Shortly after loading the document I start changing the menus. It can
happen that meanwhile an other OO Document comes in foreground and I
change the menus of this foreground window.

How can I get the XLayoutManager of the XComponent I am working on  
with

my application?


You could query the Interface com.sun.star.frame.XModel from you  
document.
This has a method getCurrentController() which returns a  
com.sun.star.frame.XController.
Now you could use the method getFrame() of this interface and so  
get the XFrame your document resides in.


Hope that helps

Regards

Stephan

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



Re: [api-dev] Changing menus of a document in background

2006-11-06 Thread Mathias Bauer
Tobias Krais wrote:

 Hi together again,
 
 I have one more question. I would like to change the menus in a document
 in the background. Up to now I can change menus for loaded documents in
 the foreground. Here is the code:
 -%-
 XPropertySet xps = (XPropertySet)
   UnoRuntime.queryInterface(XPropertySet.class,
 xDesktop.getCurrentFrame());
 
 XLayoutManager xLayoutManager = (XLayoutManager)
 UnoRuntime.queryInterface(XLayoutManager.class,
 xps.getPropertyValue(LayoutManager));
 -%-
 
 With this code (getCurrentFrame) I can only get the XLayoutManager of
 the foreground Window.
 
 Background info: I wrote a java application that opens a document.
 Shortly after loading the document I start changing the menus. It can
 happen that meanwhile an other OO Document comes in foreground and I
 change the menus of this foreground window.
 
 How can I get the XLayoutManager of the XComponent I am working on with
 my application?

Stefan gave the right answer.

I just wanted to add that relying on which window is in the foreground
is a bad idea in general. It's platform dependent (on Linux it even
depends on the particular window manager installed) and doesn't make
your application reliable. Stefan's suggestion will work always.

To express it in short terms: use currentFrame only if you are fine
with getting which frame whatsoever or even no frame at all when OOo is
still subject to focus changes caused by the WM.

Ciao,
Mathias
-- 
Mathias Bauer - OpenOffice.org Application Framework Project Lead
Please reply to the list only, [EMAIL PROTECTED] is a spam sink.

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