Many hidden treasures are slumbering beyond the menus of OOo. If you only scan the menu bar for those features you're searching for, you'll find at most 10% of them.

Well, you can argue the exact percentage, but I'm quite sure that you will miss a lot if you never explore beyond the obvious menu commands.

  • Some dialogs and wizards will only show up on some actions, as with drag-and-drop from Calc to Base.

  • Some cool features are only part of context menus, like the Arrange, Align, Flip, and Convert commands in Impress.

  • And some useful things can be inserted into your documents, but they never show up as commands in the Insert menu. Such are the Push Buttons and other Form Controls.

Let's take an intuitive beginner's approach to explore the power of Form Controls. Or to scratch the surface of Push Buttons.

To insert an action button to open another document

You want to add a new button to your document. When you click that button, OOo will start some action, for example, open a certain document in addition to the current document. I chose this example because this is a built-in action, so it's an easy first start.

  1. Open a new Writer text document. Optionally type some text.

  2. Choose View - Toolbars - Form Controls.

    You see the Form Controls toolbar. As with most other toolbars, you can drag the toolbar to other places, dock and undock it to the document borders, and reshape it to show more rows or more columns of icons. And you can click the down arrow in the title bar to open a menu. The Visible Buttons command shows a nice overview of the available icons with their names.


  3. On the Form Controls toolbar, click the Push Button icon. (Do not click the Push Button command in the Visible Buttons menu: this would hide the icon from the toolbar!)

  4. Drag a rectangle of the position and size of the push button, then release the mouse button.

  5. Right-click the new push button and choose Control from the context menu. This opens one of the two main properties windows.


  6. Click the Action list button and select "Open document/web page" from the list.

  7. The URL text field is now enabled. Click the … button next to the URL text field to select the document that should be opened when a user clicks the button.


That's it. You have created your first action push button. However, we are not finished yet.

  • Currently the button is labeled "Button". Select the text in the Label text field and enter a more descriptive text, like "Open Memo Doc".

Currently the document is set to design mode. When you click the button, it gets eight handles to resize the button, and you can change the button's properties. In order to use the push button, you must leave the design mode. There are two ways to leave the design mode:

  • Click the Design Mode On/Off icon on the Form Controls toolbar. You can immediately test the actions of your form controls. Don't forget to save your document before you test the actions. May be the action is defined to quit the current document.

  • Save the document and open it again. By default a document with form controls is opened in "action mode", not in design mode. You can change this, of course.

To create an action button to close the current document

Now you know how to create a working push button. However, not all actions are listed in the Actions list box. If you want to define the action to close the current document, you would need a macro that does just that. Then you assign that macro to the push button.

Intuitively, you might want to use the built-in macro recorder of OpenOffice.org. But that is not a good idea when you try to record the "Close this document" action, because that also closes the macro recorder.

So the next choice is to search the web for "OpenOffice.org macro to close the current document". Some minutes later, you find this command:

StarDesktop.CurrentComponent.CurrentController.Frame.close( true )

  1. In your web browser or wherever you found the macro, select the macro and copy it to the clipboard.

  2. Open the Writer document where you want to create a Close push button.

  3. Choose Tools - Macros - Organize Macros - OpenOffice.org Basic.

    This opens the Macros dialog.

  4. Click Edit.

    This opens the Basic IDE (Integrated Development Environment).

  5. Paste the macro command between the Sub and End Sub statements as follows. Rename the Sub Main to another meaningful name like Sub close_current:


  6. Close the Basic IDE. OOo saves your macro automatically.

Next, you create a push button as outlined above in steps 1 to 5.

  1. Right-click the button and choose Control to open the Properties window.

  2. Click the Events tab on top of the Properties window.

    You see the Events tab page, where you can assign macros to all possible button events.


  3. Normally, a button responds to a mouse click when you release the mouse button. So you assign the close_current macro to that event. Click the … icon next to "Mouse button released".

  4. You see the Assign Action dialog. Click the Macro button on top right.

  5. You see the Macro Selector dialog. Click to open the path "My Macros - Standard - Module1". Now you can select the close_current macro and click OK.

Almost finished. You have written the close_current macro in the Basic IDE, then you have assigned the macro to the "release mouse button" event of your own push button. Not bad for a beginner!

Again, you may want to change the Label of the button to some meaningful text like "Close this doc".

And do not forget to save the document before you try out the Close button in action mode.


Comments:

How to create a button which would from one database entry form open another form in application modal mode, so that that subform must be closed before further data inputting may occur in the main form? Maybe a suggestion for another article on this site ...

Posted by Tomas Valusek on August 08, 2008 at 01:36 PM CEST #

@ Tomas: We're not there yet. We just introduced the existance of Form Controls. Next step would be to link those controls to a database for a user defined UI for managing data records. Then we can introduce subforms. And only then we will face what you mention in your comment.
Why not create a Wiki page with your findings at http://wiki.services.openoffice.org/wiki/Documentation or http://wiki.services.openoffice.org/wiki/Documentation/How_Tos

Posted by ufi on August 08, 2008 at 02:48 PM CEST #

My first comment was a desperate attempt to find answer to my current problem ...

Posted by Tomas Valusek on August 08, 2008 at 02:51 PM CEST #

For solving problems, pls subscribe to the users list of the database project: http://dba.openoffice.org/servlets/ProjectMailingListList
and/or read the list archive.

Posted by ufi on August 08, 2008 at 03:08 PM CEST #

Post a Comment:
  • HTML Syntax: NOT allowed

This blog copyright 2009 by fpe