Instantiation of a Dialog

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

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

The first step to create a dialog is to instantiate the dialog and its corresponding model . As can be seen in the following code example, the dialog as well as its model are created by the global MultiComponentFactory. The model is assigned to the dialog using setModel(). The dialog model is a that keeps all control models and accesses them by their name. Similarly the dialog implements the interface that accesses the controls via the method getControl(). In a later step, each control model must be added to the Name-Container of the dialog model, which is why these object variables are defined with a public scope in the code example. Alternatively you can also retrieve the dialog model using the method getModel() at the dialog interface

  public XNameContainer m_xDlgModelNameContainer = null;
  public XControlContainer m_xDlgContainer = null;
  private void createDialog(XMultiComponentFactory _xMCF) {
  try {
      Object oDialogModel = _xMCF.createInstanceWithContext("", m_xContext);
      // The XMultiServiceFactory of the dialogmodel is needed to instantiate the controls...
      m_xMSFDialogModel = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, oDialogModel);
      // The named container is used to insert the created controls into...
      m_xDlgModelNameContainer = (XNameContainer) UnoRuntime.queryInterface(XNameContainer.class, oDialogModel);
      // create the dialog...
      Object oUnoDialog = _xMCF.createInstanceWithContext("", m_xContext);
      m_xDialogControl = (XControl) UnoRuntime.queryInterface(XControl.class, oUnoDialog);
      // The scope of the control container is public...
      m_xDlgContainer = (XControlContainer) UnoRuntime.queryInterface(XControlContainer.class, oUnoDialog);
      m_xTopWindow = (XTopWindow) UnoRuntime.queryInterface(XTopWindow.class, m_xDlgContainer); 
      // link the dialog and its model...
      XControlModel xControlModel = (XControlModel) UnoRuntime.queryInterface(XControlModel.class, oDialogModel);
  } catch ( exception) {
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages