21.08.2013 Views

OpenOffice.org BASIC Guide - OpenOffice.org wiki

OpenOffice.org BASIC Guide - OpenOffice.org wiki

OpenOffice.org BASIC Guide - OpenOffice.org wiki

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Control element-specific events: Events that only occur in relation to certain control elements.<br />

When you work with events, make sure that you create the associated dialog in the <strong>OpenOffice</strong>.<strong>org</strong> development<br />

environment and that it contains the required control elements or documents (if you apply the events to a form).<br />

The <strong>OpenOffice</strong>.<strong>org</strong> Basic development environment<br />

The figure above shows the <strong>OpenOffice</strong>.<strong>org</strong> Basic development environment with a dialog window that contains<br />

two list boxes. You can move the data from one list to the other using the buttons between the two list boxes.<br />

Events<br />

If you want to display the layout on screen, then you should create the associated <strong>OpenOffice</strong>.<strong>org</strong> Basic<br />

procedures so that they can be called up by the event handlers. Even though you can use these procedures in any<br />

module, it is best to limit their use to two modules. To make your code easier to read, you should assign<br />

meaningful names to these procedures. Jumping directly to a general program procedure from a macro can result<br />

in unclear code. Instead, to simplify code maintenance and troubleshooting, you should create another procedure<br />

to serve as an entry point for event handling - even if it only executes a single call to the target procedure.<br />

The code in the following example moves an entry from the left to the right list box of a dialog.<br />

Sub cmdSelect_Initiated<br />

Dim lstEntries As Object<br />

Dim lstSelection As Object<br />

lstEntries = Dlg.getControl("lstEntries")<br />

lstSelection = Dlg.getControl("lstSelection")<br />

If lstEntries.SelectedItem > 0 Then<br />

lstSelection.AddItem(lstEntries.SelectedItem, 0)<br />

lstEntries.removeItems(lstEntries.SelectItemPos, 1)<br />

Else<br />

Beep<br />

End If<br />

End Sub<br />

If this procedure was created in <strong>OpenOffice</strong>.<strong>org</strong> Basic, you can assign it to an event required using the property<br />

window of the dialog editor.<br />

The Assign Action dialog<br />

Chapter 11 · Dialogs 157

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!