Adding a dialog: Part II

Friday, September 9th, 2005

In the first part of this series of articles, we developed some macros for basic string manipulation on a selected range of cells. We also created a new menu item for easy invocation of these macros.

In the second part, we developed a dialog to allow the user to select from a list of functions.

We will now integrate the enhanced menu, the new dialog and our new functions.

Each radio button in our dialog was given a name. They wereUpperCButton, LowerCButton and ProperCButton.
Another key property associated with radio buttons is the Stateproperty which has a value of 1 if the button is checked, 0 otherwise. The default state value is 0. In our dialog, we would like to have theProperC button selected on startup - so we set the state value as shown below..

There are no Events associated with the radio buttons. The other components/controls of the dialog will be able to query the state of each button as we shall see in the code. The subroutines listed below - RunTextUtilsDlg and ExitTextUtilsDlg will be associated with theRun and Exit command buttons. We link the macros and command buttons via the events dialog of each component as shown below. Be careful to choose the correct event type when doing the mapping.

In the dialog editor, select the button to which we wish to assign a macro. Select the Events tab. For a button control, we want to map the macro to the Mouse button pressed event. Invoke the Assign Macro dialog as shown below.

Making sure the corrct event is selected, invoke the Macro Selector as shown below.

With the macro selected,click OK to complete the macro assignment/mapping.

Here is the additonal macro code required to complete the integration. Note the mechanism by which we query the state of each radio button.

Dim oTextUtilsDlg

Sub RunTextUtilsDlg
Dim oLib
Dim oLibDlg

DialogLibraries.loadLibrary(”Standard”)

oLib = DialogLibraries.getByName(”Standard”)

oLibDlg = oLib.getByName(”TextUtils”)

oTextUtilsDlg = CreateUnoDialog(oLibDlg)

oTextUtilsDlg.execute

End Sub

Sub ExitTextUtilsDlg
oTextUtilsDlg.endExecute()
End Sub

Sub TextUtils
‘Print oTextUtilsDlg.getModel().getByName(”UpperCButton”).State
If oTextUtilsDlg.getModel().getByName(”UpperCButton”).State = 1 Then
Call UpperC
ElseIf oTextUtilsDlg.getModel().getByName(”LowerCButton”).State = 1 Then
Call LowerC
ElseIf oTextUtilsDlg.getModel().getByName(”ProperCButton”).State = 1 Then
Call ProperC
End If
End Sub

Asa final step, we customize our menu to provide a single point of entry to the TextUtils dialog via the RunTextUtilsDlg macro.

Please note that this is just one possible way of implementing the new Calc functionality we have introduced in this series of tips.

Here is the example we have just worked through for you to
download.

Posted in OpenOffice Basic | No Comments »