Displaying Dialogs

From Apache OpenOffice Wiki
< Documentation‎ | DevGuide
Revision as of 18:43, 21 December 2020 by DiGro (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

After you have inserted the controls, you can create a WindowPeer, a low level object that makes sure the window is displayed correctly, and the dialog can be executed. A dialog implements com.sun.star.awt.XWindow. To access the window toolkit implementation, a com.sun.star.awt.XWindowPeer must be created. The dialog control is shown by calling the execute() method of the com.sun.star.awt.XDialog interface. It can be closed by calling endExecute(), or by offering a Cancel or OK Button on the dialog Command Button. Dialogs such as this one are described as modal because they do not permit any other program action until they are closed. While the dialog is open, the program remains in the execute() call. The dispose() method at the end of the code frees the resources used by the dialog. It is important to note that dispose() - the method to free the memory - must be positioned directly after the execute() call and not behind endExecute();

  public short executeDialog() throws com.sun.star.script.BasicErrorException{
      XWindow xWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class, m_xDlgContainer);
      // set the dialog invisible until it is executed
      Object oToolkit = m_xMCF.createInstanceWithContext("com.sun.star.awt.Toolkit", m_xContext);
      XToolkit xToolkit = (XToolkit) UnoRuntime.queryInterface(XToolkit.class, oToolkit);
      XWindowPeer xWindowParentPeer = xToolkit.getDesktopWindow();
      m_xDialogControl.createPeer(xToolkit, xWindowParentPeer);
      m_xWindowPeer = m_xDialogControl.getPeer();
      XDialog xDialog = (XDialog) UnoRuntime.queryInterface(XDialog.class, m_xDialogControl);
      XComponent xDialogComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, m_xDialogControl);
      // the return value contains information about how the dialog has been closed...
      short nReturnValue = xDialog.execute();
      // free the resources...
      return nReturnValue;

The method createPeer() creates an internal or low level peer-object, that makes sure that the window is displayed correctly.

Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages