Difference between revisions of "Documentation/DevGuide/GUI/Displaying Dialogs"

From Apache OpenOffice Wiki
Jump to: navigation, search
 
Line 8: Line 8:
 
  {{DISPLAYTITLE:Displaying Dialogs}}
 
  {{DISPLAYTITLE:Displaying Dialogs}}
 
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 <idl>com.sun.star.awt.XWindow</idl>. To access the window toolkit implementation, a <idl>com.sun.star.awt.XWindowPeer</idl> must be created. The dialog control is shown by calling the <code>execute()</code> method of the <idl>com.sun.star.awt.XDialog</idl> interface. It can be closed by calling <code>endExecute()</code>, or by offering a '''Cancel''' or '''OK''' Button on the dialog [[Documentation/DevGuide/Basic/Command Button|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 <code>execute()</code> call. The <code>dispose()</code> method at the end of the code frees the resources used by the dialog. It is important to note that <code>dispose()</code> - the method to free the memory - must be positioned directly after the execute() call and not behind <code>endExecute();</code>
 
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 <idl>com.sun.star.awt.XWindow</idl>. To access the window toolkit implementation, a <idl>com.sun.star.awt.XWindowPeer</idl> must be created. The dialog control is shown by calling the <code>execute()</code> method of the <idl>com.sun.star.awt.XDialog</idl> interface. It can be closed by calling <code>endExecute()</code>, or by offering a '''Cancel''' or '''OK''' Button on the dialog [[Documentation/DevGuide/Basic/Command Button|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 <code>execute()</code> call. The <code>dispose()</code> method at the end of the code frees the resources used by the dialog. It is important to note that <code>dispose()</code> - the method to free the memory - must be positioned directly after the execute() call and not behind <code>endExecute();</code>
<source lang="java">
+
<syntaxhighlight lang="java">
 
   public short executeDialog() throws com.sun.star.script.BasicErrorException{
 
   public short executeDialog() throws com.sun.star.script.BasicErrorException{
 
       XWindow xWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class, m_xDlgContainer);
 
       XWindow xWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class, m_xDlgContainer);
Line 27: Line 27:
 
       return nReturnValue;
 
       return nReturnValue;
 
   }
 
   }
</source>
+
</syntaxhighlight>
 
The method <code>createPeer()</code> creates an internal or low level peer-object, that makes sure that the window is displayed correctly.
 
The method <code>createPeer()</code> creates an internal or low level peer-object, that makes sure that the window is displayed correctly.
  

Latest revision as of 18:43, 21 December 2020



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
      xWindow.setVisible(false);
      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...
      xDialogComponent.dispose();
      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