AutoPilot Dialogs

From Apache OpenOffice Wiki
Jump to: navigation, search

The final step is to create a small AutoPilot with two pages. The Dialogs have a simple concept for AutoPilot pages. Each dialog and each control in a dialog has a property Page (Step) to control the pages of a dialog. Normally, dialogs are on page 0, but they can be set to a different page, for example, to page 1. All controls having 1 in their Page property are visible as long as the dialog is on page 1. All controls having 2 in their page property are only displayed on page 2 and so forth. If the dialog is on Page 0, all controls are visible at once. If a control has its Page property set to 0, it is visible on all dialog pages.

This feature is used to create a second page in our dialog. Hold down the Control key, and click the label and file control in the dialog to select them. In the Properties Dialog, fill in 1 for the Page property and press Enter to apply the change. Next, select the dialog by clicking the outer rim of the dialog in the dialog editor, enter 2 for the Page property and press the Enter key. The label and file control disappear, because we are on page 2 now. Only the buttons are visible since they are on page 0.

On page 2, add a label "Anchor" and two option buttons "at Paragraph" and "as Character". Name the option buttons AtParagraph and AsCharacter, and toggle the State property of the AtParagraph button, so that it is selected by default. The new controls automatically receive 2 in their Page property. When page 2 is finished, set the dialog to page 1 again, because we want it to be on page 1 on startup.

The Insert Graphics Wizard

The Subs below handle the << Back and Next >> buttons, and the Sub FinishGraphicsDialog has been extended to anchor the new graphics selected by the user. Note that the property that is called Page (Step) in the GUI, is called Step in the API.

  Sub BackGraphicsDialog
      oDialog.Model.Step = 1
      oDialog.Model.Back.Enabled = false
      oDialog.Model.Next.Enabled = true
  End Sub
  Sub NextGraphicsDialog
      oDialog.Model.Step = 2
      oDialog.Model.Back.Enabled = true
      oDialog.Model.Next.Enabled = false
  End Sub
  Sub FinishGraphicsDialog
      Dim sGraphicURL as String, iAnchor as Long
      sFile = oDialog.Model.FileControl1.Text
      ' State = Selected corresponds to 1 in the API
      if oDialog.Model.AsCharacter.State = 1 then
          iAnchor =
      elseif oDialog.Model.AtParagraph.State = 1 then
          iAnchor =
      ' the File Selection control returns a system path, we have to transform it to a File URL
      ' We use the built-in Basic runtime function ConvertToURL for this purpose
      sGraphicURL = ConvertToURL(sFile)
      ' access the document model
      oDoc = ThisComponent
      ' get the Text service of the document
      oText = oDoc.getText()
      ' create an instance of a graphic object using the document service factory
      oGraphicObject = oDoc.createInstance("")
      ' set the URL of the graphic
      oGraphicObject.GraphicURL = sGraphicURL
      oGraphicObject.AnchorType = iAnchor
      ' get the current cursor position in the GUI and create a text cursor from it
      oViewCursor = oDoc.getCurrentController().getViewCursor()
      oCursor = oText.createTextCursorByRange(oViewCursor.getStart())
      ' insert the graphical object at the beginning of the text
      oText.insertTextContent(oCursor.getStart(), oGraphicObject, false)
  End Sub
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages