Macros in Database Documents

From Apache OpenOffice Wiki
Revision as of 03:18, 29 November 2007 by Pmsyyz (Talk | contribs)

Jump to: navigation, search
Specification Status
Author Frank Schönheit
Last Change 2007-11-28
Status (Help) Preliminary

Abstract Base, unlike the other applications, is currently not able to embed macros and scripts into its documents. We will empower Base users to use macros and scripts (StarBasic, JavaScript, BeanShell, Python) in their database documents the very same way they can use them in all other application's documents.

Detailed Specification

Accessing Macros and Scripts

  • Macro and Script Organizers (Template:Menuitem) will show opened database documents, and allow editing/creating macros/scripts therein.
  • The Basic IDE will treat macros in database documents the very same way as macros in other application's documents.
  • The Macro Selector (Template:Menuitem) will show opened database documents, and allow to run them.
  • The UI customization dialog (Template:Menuitem) will allow access to the current database document's macros and scripts, when invoked for this document.

Basic Macros

  • In a running Basic macro embedded in a database document, the globally available context variable ThisComponent will contain the database document.

Database Document Macros vs. Macros in Sub Documents

Up to now, macros can be embedded into sub documents of a database document, that is, into forms and reports (which technically are Text documents).

We will not allow this in the future anymore. The reason is that it is hard to find a consistent concept (in particular: create a consistent user experience) which allows both, macros in the embedding database document and macros in the embedded form/report document.

As a consequence, in any place where you can currently access macros in forms (which we'll use as placeholder for forms and reports from now on), you won't be able to do so anymore. Instead, you can access the database documents's macros.

This means:

  • Currently, when you have a form, and open the customization dialog, it will give you access to macros embedded in this form. In the future, you will have access to the database document's macros only.
  • Currently, you see all open form documents in the macro organizer and the macro selector. In the future, you will see open database documents only (and all other application's documents, of course).
  • Assigning macros to elements in a form document (in particular: to events of form controls, from the "Events" tab page of the property browser) will be possible with macros from the database document only, not with macros from the form document.


Database documents created with version prior to 3.0 might contain forms or reports with embedded macros or scripts. Since this constellation is prohibited as soon as macros in database documents are implemented, a migration path is necessary.

The goal is to transform documents so that all the macros and scripts are in the database document, not in its sub documents anymore. Unfortunately, this cannot be done automatically.

For once, it is difficult to (in a generic way) merge all macros from embedded documents into the database document. For instance, if two forms both contain a Basic library named "Standard", with a module named "Module1", with a function named "Foo", then moving both libraries/modules into the database document's Basic libraries will lead to name clashes. Solving those in an automated way is possible, but references to those macros will almost certainly be broken then.

Second, a complete automatic migration requires a syntactical analysis of the macro/script code. For instance, imagine a Basic macro which does a LoadLibrary call with the name of a Basic library in the form document. If this library has been moved to the database document, and perhaps been renamed in this course, the LoadLibrary call would need to be adjusted to refer to the new name. This is effectively impossible without analyzing the Basic code, effectively compiling it. Similar arguments hold for other script types.

As a consequence, we won't migrate macros and scripts in sub documents automatically.

Compatibility Warning

Instead, we will show the following message box when the user opens a database document which contains a form or report with embedded scripts or macros:

Macros in Database Documents: Compatibility warning

Template:SpecUIElement/LabelHeading |- | style="vertical-align:top; background-color:#eeeeee;" | Label | style="vertical-align:top; background-color:#F8F8F8;" | Text | The document contains forms and/or reports with macros and/or scripts embedded. | |- | style="vertical-align:top; background-color:#eeeeee;" | Label | style="vertical-align:top; background-color:#F8F8F8;" | Text | Scripts and macros should nowadays be embedded into the database document itself.

You can continue to use your document as before, however, you are encouraged to migrate your scripts and macros. The menu item "Tools / Migrate Scripts and Macros ..." will assist you with this.

Note that you won't be able to embed macros or scripts into the database document until this migration is done. | |}

So, when the user simply opens an "old" document containing macros and/or scripts in the sub documents, nothing except the above warning will happen in the first instance. Until the user migrated the macros, the database document, and all sub documents, will behave as if the feature which this spec is about were never implemented. In particular, the user is free to create additional or modify existing macros in her forms and reports, to customize macros from sub documents into her toolbar/menu, to bind those macros to events in the sub documents, and so on.

Semi-automatic Migration

We will introduce a new menu item, called "Migrate Scripts and Macros ...", located in the top-level menu "Tools", immediately below the existing "SQL ..." item.

Menu Item(s)

Item Sub Item Sub Item KBD Shortcut Icon Comment
Migrate Scripts and Macros ...

TODO: specify the behavior in detail

Assigning Macros to Events

TODO: specify the Tools/Customize/Events appearance/behavior for database documents. We want, for instance, be able to assign a macro, embedded in the database document, to the document's OnLoad event.

Database Specific Events

TODO: specify events which are specific to database documents, and available in the Tools/Custormize/Events tab page. Not yet sure whether we need this.

Implementation Milestones

Timeline and Tasks

The development of this feature will produce the following milestones:

Milestone Due
  • embedding/organizing/running macros/scripts works
2nd January 2008
  • sub documents cannot contain macros/scripts anymore
  • old documents offer the migration menu entry, but still work as before until migration is done
  • semi-automatic migration works as described in the specification
31st January 2008
  • Assigning macros to database document events (Template:Menuitem) works. For instance, it is possible to assign a macro to the OnLoad event of an DB document itself.
20th February 2008

TODO: There's more to come here ...


TODO: There's more to come here ...



Task Status M
<lengthy task description> planned M1
<lengthy task description> planned M1
<lengthy task description> planned M1
<lengthy task description> planned M2

Open Issues

  • When assigning a macro, located in the database document, to, say, the "When initiated" event of a button in an embedded form document: should the called Basic code have some easy access to the form which the button lives in? It might become necessary to refer to this form document, similar to how ThisComponent will refer to the database document as a whole. On the other hand, the macros get an css.lang.EventObject, which in all cases is sufficient to obtain the form document (which is an ancestor in the parent-child-hierarchy of the control model).

Future Tasks

  • For the moment, it will not be possible to sign macros embedded in database documents. This is up to a later step.
  • Macro recording will still not be possible in database documents. This is a separate topic, which requires implementations in a completely different area.


Acronyms and Abbreviations

Acronym / Abbreviation Definition
Customization dialog is the dialog which allows to customize menus, toolbars, keyboard and event bindings. Reached via Template:Menuitem in all applications. For all aforementioned UI types, it allows to add macros or scripts, for instance, you can customize your toolbar or menu to include a reference certain Basic function. This holds for office-wide macros as well as document-local macros, in which case you usually store the customization in the document only, and not application-wide.
Macro Organizer is the dialog which you open via Template:Menuitem in all applications.
Macro Selector is the dialog which allows you to select a single macro. It is invoked whenever the user needs to specify a macro or script function or method, for instance when you choose the "Macro" button on the "Events" tab page of the organizer dialog. Note that there are cases where the macro selector allows to select macros or scripts from all currently-open documents (for instance when invoked via Template:Menuitem), and cases where it contains only macros/scripts from the active document (e.g. when invoked from the customization dialog of an active document).


Reference Document Check Location (URL)
Specification Process Entry Check [passed/failed] n/a
Product Requirement, RFE, Issue ID available

Possibility to put macros in *.odb files
Impossible to bind a macro to an Base document
RFE: add database specific event for macros to the database

Test case specification not available


Role Name
Developer Frank Schönheit
Quality Assurance Marc Neumann
Documentation Uwe Fischer
User Experience Bettina Haberer
Personal tools