Form Layer Views

From Apache OpenOffice Wiki
Jump to: navigation, search

View Modes

An important aspect to know when dealing with forms is that the view for a form layer is in different modes. More precise, there is a design mode available, opposite to a live mode. In design mode, you design your form interactively with by inserting new controls, resizing them, and modifying their properties, together with control models and shapes, although hides this. In live mode, the controls interact with the user for data input.

The live mode is the natural mode for form views, because usually a form is designed once and used again.

The following example switches a given document view between the two modes:

  /** toggles the design mode of the form layer of active view of our sample document
  protected void toggleFormDesignMode() throws java.lang.Exception {
      // get a dispatcher for the toggle URL
      URL[] aToggleURL = new URL[] {new URL()};
      aToggleURL[0].Complete = new String(".uno:SwitchControlDesignMode");
      XDispatch xDispatcher = getDispatcher(aToggleURL);
      // dispatch the URL - this will result in toggling the mode
      PropertyValue[] aDummyArgs = new PropertyValue[] {};
      xDispatcher.dispatch(aToggleURL[0], aDummyArgs);

The basic idea is to dispatch the URL ".uno:SwitchControlDesignMode" into the current view. This triggers the same functionality as if the button Design Mode On/Off was pressed in In fact, SwitchControlDesignMode is the UNO name for the slot triggered by this button.

Locating Controls

A common task when working with form documents using the API is to obtain controls. Given that there is a control model, and a view to the document it belongs to, you may want to know the control that is used to represent the model in that view. This is what the interface at the controller of a document view is made for.

  /** retrieves a control within the current view of a document
      @param xModel
          specifies the control model which's control should be located
          the control tied to the model
  public XControl getControl(XControlModel xModel) throws {
      XControlAccess xCtrlAcc = (XControlAccess)UnoRuntime.queryInterface(
          XControlAccess.class , m_xController);
      // delegate the task of looking for the control
      return xCtrlAcc.getControl(xModel);

Focusing Controls

To focus a specific control in your document, or more precisely, in one of the views of your document:

  /** sets the focus to a specific control
      @param xModel
          a control model. The focus is set to that control which is part of our view
          and associated with the given model.
  public void grabControlFocus(Object xModel) throws {
      // look for the control from the current view which belongs to the model
      XControl xControl = getControl(xModel);
      // the focus can be set to an XWindow only
      XWindow xControlWindow = (XWindow)UnoRuntime.queryInterface(Xwindow.class, xControl);
      // grab the focus

As you can see, focusing controls is reduced to locating controls. Once you have located the control, the interface provides everything needed for focusing.

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