Can you tell me why this code doesn't work then:

public void someMethod() {
unoidl.com.sun.star.uno.XComponentContext localContext = uno.util.Bootstrap.bootstrap(); unoidl.com.sun.star.lang.XMultiServiceFactory multiServiceFactory = (unoidl.com.sun.star.lang.XMultiServiceFactory) localContext.getServiceManager();

XComponentLoader componentLoader =

               (XComponentLoader)multiServiceFactory.createInstance(

                                     "com.sun.star.frame.Desktop");

//Create a new blank writer document using our component //enable macros
           PropertyValue[] args = new PropertyValue[1];
           args[0] = new PropertyValue();
           args[0].Name = "MacroExecutionMode";
           args[0].Value = new Any(MacroExecMode.ALWAYS_EXECUTE_NO_WARN);
XComponent xComponent = componentLoader.loadComponentFromURL( "private:factory/swriter", "_blank", 0, args
               );

//get the document frame XFrame frame = ((unoidl.com.sun.star.text.XTextDocument)xComponent).getCurrentController().getFrame(); //If i add the listener to the frame here, the outer most frame is prevented from closing, but the user can still click the internal document window's close button and the document will close which is not the behavior I want
/*           XCloseBroadcaster xcb = (XCloseBroadcaster)frame;
           xcb.addCloseListener(new CloseListener());*/

//If i add the listener to the xcomponent, the queryClosing method is fired when either the internal document's close button or the frame's close button is clicked, but the document is not prevented from closing XCloseBroadcaster xc = (XCloseBroadcaster)xComponent; xc.addCloseListener(new CloseListener());

}

   public class CloseListener : XCloseListener {

public void notifyClosing(unoidl.com.sun.star.lang.EventObject Source) { }

public void queryClosing(unoidl.com.sun.star.lang.EventObject Source, bool GetsOwnership) {
               throw new CloseVetoException();
           }



public void disposing(unoidl.com.sun.star.lang.EventObject Source) { }

}

Mathias Bauer wrote:
Adam Patacchiola wrote:

Hi,

How can I prevent a document from closing? I've figured out how to do it
for the frame by adding a CloseListener and throwing a
CloseVetoException in queryClosing, but this does not seem to work for
the internal document.

It works the same way. The document will not be closed (=destroyed)
then. I assume that you also want to prevent the document windows from
being closed. This is only possible by registering your listener at the
corresponding frames.

Best regards,
Mathias


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

Reply via email to