Using Macros, Scripts, and Events

Learning More Before You Begin

Ensure you've set the right setup option in Specifying StarBasic Macro Options on page 151.

This section covers basics of how to link to or insert scripts, macros, and events, just in the context of having them in your HTML page. These are advanced topics; to learn more about macros, see Macro Basics on page 961. To learn more about events, see Chapter 36, Creating and Using Forms, Controls, and Events , on page 921.

What You Can Do in This Section

This section covers how to add scripts to any document, whether by inserting them in a document so that they're run when the document is loaded, or associating them with a graphic or text link.

You can also link macros and JavaScript to text or button hyperlink events.

Finally, you can create controls, like a push button, and attach them to macros or events. Events are actions like moving the mouse over the hyperlink, clicking the mouse on the hyperlink, and moving the mouse away from the hyperlink.

Inserting Scripts in Documents

You can insert JavaScript in documents. The inserted script is indicated by a small green square.

To attach JavaScript to a control, such as a button; see Macro and Events Basics on page 947; to attach it to a hyperlink, see Using Macros, Scripts, and Events on page 487.

Showing and Hiding Script Indicators

To show or hide note indicators, choose Tools > Options > HTML Document > Contents and select or deselect the Notes option. This applies to the indicator for notes, as well.

Inserting a Script
  1. Choose Insert > Script.

  2. The Insert Script window will appear (Figure 16-17). Enter the plugin information and click OK.

    Figure 16-17. Inserting a script

    graphics/16fig17.jpg

Editing Scripts
  1. Double-click the green script indicator.

  2. The Edit Script window is like the Insert Script window, except that you can browse from script to script using the arrows.

    graphics/16inf04.jpg

Printing Scripts

The Print Options window lets you choose whether to print document scripts and notes, and where. See page 493 for more information.

Just Typing Macros in the HTML Source

OpenOffice.org macros have to be in the header of the HTML document. After you add the macro to the document, it will appear in the source text of the HTML document (in the header) with the following syntax (a "Hello World" example macro is used):

 <HEAD> (any additional content) <SCRIPT LANGUAGE="STARBASIC"> <!-- ' $LIBRARY: library_name ' $MODULE: module_name Sub test msgbox "Hello World" End Sub // --> </SCRIPT> </HEAD> 

Inserting Hyperlinks to Macros and Scripts

You've already learned how to make text and graphics hyperlinks that will take you to a file or Web page. You can also make them run scripts, using the procedures in this section.

Linking Macros and Scripts to Text or a Button
  1. Open any document.

  2. Position the cursor in the document where you want the link to appear.

  3. Choose Insert > Hyperlink or click the Hyperlink Dialog icon.

    graphics/hyperlinkdialog.jpg

  4. On the left side of the Hyperlink window, select any of the options: Internet, New Document, etc.

  5. Set up the link for the appropriate type of link (see page 471 through page 476).

  6. Click the Events icon.

    graphics/events.jpg

  7. In the Assign Macro window (Figure 16-18), select one of the events.

    Figure 16-18. Linking a button or text to a macro using the Assign Macro window

    graphics/16fig18.jpg

    Note

    If you add an existing macro, be sure the macro's library (the category it's listed within) is activated. Choose Tools > Macros, click the Organizer button, then click the Libraries tab and be sure the checkbox next to the library is checked.

    Enter the appropriate information, then click OK.

Linking Macros to Graphics

If you've added a graphic to a document, you can use the Graphics window to make it trigger an action.

  1. Right-click the graphic and choose Graphics.

  2. In the Graphics window, click the Macro tab (Figure 16-19).

    Figure 16-19. Linking a graphic to a macro using the Graphics window

    graphics/16fig19.jpg

  3. Select an event that will trigger the macro.

    Enter the appropriate information, then click OK.

Note

Most of the macro-insertion features in the program let you insert a macro from the Standard and other libraries, and from the document you're currently in, but not any other documents you've created. If you're having trouble finding the macro you want, it's probably in a separate document. You'll need to cut and paste it into a module in the Standard library, a new library, or create a module for it in your current document.




OpenOffice. org 1.0 Resource Kit
OpenOffice.Org 1.0 Resource Kit
ISBN: 0131407457
EAN: 2147483647
Year: 2005
Pages: 407

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net