Creating and Customizing OpenOffice.org Dialogs

How to Create a Dialog with the OpenOffice.org Basic IDE

© Mark Alexander Bain

Jun 20, 2009
Creating and Customizing OpenOffice.org Dialogs, Mark Alexander Bain
Application dialogs tend very simple and uninspiring. However, that's not true of OpenOffice.org. An OpenOffice.org dialog is fully customizable and very flexible.

An underrated and underused area of OpenOffice.org is the dialog.

Most visual programming languages (such as Visual Basic and VBScript) have some means of simple user interaction (for example MsgBox and InputBox), however the OpenOffice.org IDE (Integrated Design Environment) provides the means of creating a fully customizable dialog box which, in may ways, is better than OpenOffice.org Base's forms (as can been seen in figure 1 at the bottom of this article).

In just a short time the programmer can create a very professional looking user interface.

Creating a Blank OpenOffice.org Dialog

A custom dialog can be created very easily. It is just a matter of opening one of the OpenOffice.org applications (Writer, Calc or Base) and then clicking on:

  • Tools
  • Macros
  • Organize Dialogs

The OpenOffice.org Basic Macro Organizer will now be displayed (as shown in figure 2). The programmer then needs to:

  • Select the “Dialogs” tab (if it is not already selected)
  • Select the document (for example a database .odb file) that the dialog will be saved in
  • Click on “New”
  • Choose a suitable name for the new dialog

The application designer will now be able to see the blank dialog by clicking on the “Edit” button. If they do this then the IDE will display the blank dialog (as shown in figure 3).

Adding Components to the OpenOffice.org Dialog

Components can be added to the dialog from the IDE toolbox so that the programmer can add elements such as:

  • Labels
  • Text boxes
  • Combo-boxes
  • Date, time and numeric fields

Once a component has been added then its properties can be accessed (by right mouse clicking on the object). The programmer can modify the properties to:

  • change the look and feel of the components (for example, to add text to a label)
  • add functionality to the component's events (for example, to run a macro when a button is clicked)

After a little dragging and dropping the developer will have produced a dialog that will improve the user interaction with their application.

Loading and Running the Dialog

Some programming is required in order for the new dialog to be made visible to the user (and so anyone unsure of how to create an OpenOffice.org macro should read How to Create OpenOffice.org Database Macros). The macro itself requires a global object that will represent the dialog:

Dim oLogon As Object

There are then two steps to displaying the dialog:

  • load the dialog into memory
  • execute the dialog

It's worth encapsulating the first step into a function (so that it can be reused for any dialog):

Function loadDialog (dialog as String, Optional library as String)
Dim oLib as Object
Dim oDialog as Object
If isMissing(library) Then
library = "Standard" 'the default library for any document
End If
DialogLibraries.LoadLibrary(library)
oLib = DialogLibraries.GetByName(library)
oDialog = oLib.GetByName(dialog)
loadDialog = CreateUnoDialog(oDialog)
End Function

This function loads all of the correct libraries as well as the dialog itself. This next macro makes use of the function and executes the dialog:

Sub Main
oLogon = LoadDialog ("logon")
oLogon.Execute
End Sub

If this macro is run then the custom dialog will be displayed. It will not have any functionality at the the moment and so the programmer will have to:

  • Write a macro
  • Assign the macro to events in the dialog

And at the end of the process the developer's application will contain a completely customized dialog – one that adds useful content for the application users.


The copyright of the article Creating and Customizing OpenOffice.org Dialogs in Computer Programming is owned by Mark Alexander Bain. Permission to republish Creating and Customizing OpenOffice.org Dialogs in print or online must be granted by the author in writing.


Creating and Customizing OpenOffice.org Dialogs, Mark Alexander Bain
Figure 1: A Customized OpenOffice, Mark Alexander Bain
Figure 2: Creating a Blank Dialog, Mark Alexander Bain
Figure 3: A Blank Dialog, Mark Alexander Bain
 


Post this Article to facebook Add this Article to del.icio.us! Digg this Article furl this Article Add this Article to Reddit Add this Article to Technorati Add this Article to Newsvine Add this Article to Windows Live Add this Article to Yahoo Add this Article to StumbleUpon Add this Article to BlinkLists Add this Article to Spurl Add this Article to Google Add this Article to Ask Add this Article to Squidoo