| View previous topic :: View next topic |
| Author |
Message |
mallorn Newbie

Joined: 08 Oct 2003 Posts: 4
|
Posted: Wed Oct 08, 2003 2:29 am Post subject: new CheckBox |
|
|
I'm looking for information how to add a new CheckBox into a Dialog box by the program code - without declaring it in a Dialog form
I need to insert from 5 to 50 CheckBoxes, now I do it by inserting 50 blank CheckBoxes on a form and I'm hidding not needed CheckBoxes by "(...).Visible = false" attribute
Is there any better option?  _________________ maLLorn |
|
| Back to top |
|
 |
SergeM Super User

Joined: 09 Sep 2003 Posts: 3208 Location: Troyes France
|
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 4021 Location: Lawrence, Kansas, USA
|
Posted: Wed Oct 08, 2003 10:09 am Post subject: |
|
|
SergeM is correct. Depending on your version of the Developer's Guide, p.771 may or may not get you what you want. You should look in chapter 11, at 11.6 Creating Dialogs at Runtime...
http://api.openoffice.org/docs/DevelopersGuide/BasicAndDialogs/BasicAndDialogs.htm#1+6+Creating+Dialogs+at+Runtime
and at 11.5 Programming Dialogs and Dialog Controls...
http://api.openoffice.org/docs/DevelopersGuide/BasicAndDialogs/BasicAndDialogs.htm#1+5+Programming+Dialogs+and+Dialog+Controls
I am planning to look into this further, do some experimenting, and then reply again.
I do know from personal experience that I can create a completely new dialog from Python. Without designing it in the dialog box designer. Just using Python text code, I am able to create a dialog box. Put a text label onto it. Put a button onto it. Assign an event listener to the button. Display (execute) the dialog. My python program is notified when the button is clicked.
In fact, based upon this technique, I want to create in Python (or maybe Java) a "toolkit" to make it easy to create and lay-out dialog boxes. That way a Java or Python component installed into OOo to extend OOo can display "native" dialog boxes that look like they are properly part of OOo and have whatever look & feel that OOo has on the platform on which it is running. Yes, I know that a Java component could theoretically display a Swing or AWT dialog, but this looks out of place in an OOo component.
As soon as I get a chance I'll attempt to create a working example in Basic that creates a dialog box from scratch, with some checkboxes and displays it. This will be my first adventure with Event Listeners in Basic -- which is a topic I've been meaning to cover anyway. _________________ Want to make OOo Drawings like the colored flower design to the left? |
|
| Back to top |
|
 |
mallorn Newbie

Joined: 08 Oct 2003 Posts: 4
|
Posted: Wed Oct 08, 2003 11:58 am Post subject: |
|
|
| DannyB wrote: | SergeM is correct. [...]
I am planning to look into this further, do some experimenting, [...]
As soon as I get a chance I'll attempt to create a working example in Basic that creates a dialog box from scratch, with some checkboxes and displays it. This will be my first adventure with Event Listeners in Basic -- which is a topic I've been meaning to cover anyway. |
I'll try it too
I think that is IT, thanks !! _________________ maLLorn |
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 4021 Location: Lawrence, Kansas, USA
|
Posted: Thu Oct 09, 2003 1:41 pm Post subject: |
|
|
I mentioned building a tool to make it easy to create dialog boxes out of thin air. Well, here is the progress so far.
This should be enough for you to figure out how to have several checkboxes share an action listener.
Here is an example of a Basic program that creates a simple dialog box.
| Code: | Private nNumDoggies As Long
Private nNumKitties As Long
Private nNumMonkeys As Long
Private bOkay As Boolean
Sub Main
nNumDoggies = 0
nNumKitties = 0
nNumMonkeys = 0
bOkay = False
' Begin creating a new dialog box.
DlgTool_CreateNewDialog( 60, 50, 200, 90, "Doggie/Kitty/Monkey Dialog" )
' Add an OK and a Cancel button.
' Both buttons share an action listener named "btnOKorCancel".
DlgTool_Button( -10, -10, 50, 14, "btnOK", "OK", "btnOKorCancel" )
DlgTool_Button( -70, -10, 50, 14, "btnCancel", "Cancel", "btnOKorCancel" )
' Add three buttons. Since no action listener name is given,
' as was done for OK and Cancel,
' these buttons must have action listener subroutines named
' after the name of the button control.
DlgTool_Button( 5, 10, 50, 14, "btnDoggie", "Add Doggie" )
DlgTool_Button( 5, 30, 50, 14, "btnKitty", "Add Kitty" )
DlgTool_Button( 5, 50, 50, 14, "btnMonkey", "Add Monkey" )
' Put a label on the dialog.
DlgTool_Label( 60, 10, 100, 14, "lbl1", "Add some doggies, kitties, and monkeys." )
' Now add a checkbox.
DlgTool_Checkbox( 60, 30, 50, 14, "chkTails", "With tails", True )
' Display the modal dialog.
DlgTool_Execute()
' Now show the results...
Print "Doggies: ", nNumDoggies, "Kitties: ", nNumKitties, "Monkeys: ", nNumMonkeys
If bOkay Then
Print "You clicked OK"
Else
Print "You clicked Cancel"
EndIf
End Sub
' Each of the Doggie, Kitty or Money buttons are assigned
' to a corresponding action listener below.
Sub btnDoggie_actionPerformed( oEvent )
nNumDoggies = nNumDoggies + 1
End Sub
Sub btnKitty_actionPerformed( oEvent )
nNumKitties = nNumKitties + 1
End Sub
Sub btnMonkey_actionPerformed( oEvent )
nNumMonkeys = nNumMonkeys + 1
End Sub
' The OK and Cancel buttons share this action listener,
' whose name was given for both buttons.
Sub btnOKorCancel_actionPerformed( oEvent )
If oEvent.Source.getModel().Name = "btnOK" Then
bOkay = True
EndIf
' If this action listener fires, it means that either
' OK or Cancel was clicked.
' Dismiss the dialog box.
DlgTool_EndExecute()
End Sub
Sub chkTails_actionPerformed( oEvent )
End Sub
|
Now hopefully, this simple program is very easy to understand. It creates a dialog box out of thin air! You don't design a dialog box in the dialog designer. The statements in the above create a new dialog box directly from the program text.
First we set up three counters for the number of doggies, kitties and monkeys.
Then we create a dialog box.
Then we create an OK and a Cancel button. The negative X and Y coordinates are to place the button from the bottom right edge of the dialog box. Notice that an action listener named "btnOKorCancel" is assigned to both buttons. This means that a subroutine MUST be defined named btnOKorCancel_actionPerformed. You can see that subroutine in the above code. Whenever EITHER button (OK or Cancel) is clicked, this action listener is called. The action listener dismisses the dialog box. But first, it checks to see whether it was the OK button that had been clicked.
Next, three more buttons are added to the dialog box. Each button is assigned it's own action listener (because no action listener name is passed, as in the OK and Cancel buttons). Each action listener increments the appropriate counter.
Then a label is added. Then a checkbox.
Finally, the dialog is executed.
Then the results are printed.
In order to make this work, you need the following additional code, which is the actual dialog toolkit. Having the following routines makes creating new dialog boxes as easy as the above code illustrates.
Sorry, no checkboxes yet, which is what you wanted. This is just a preview.
| Code: | Private oDialogModel As New com.sun.star.awt.UnoControlDialogModel
Private oDialogControl As New com.sun.star.awt.UnoControlDialog
Private oControls
Private nNumControls As Long
' Columns in the oControls array
Const CTRL_NAME = 0
Const CTRL_MODEL = 1
Const CTRL_CONTROL = 2
Const CTRL_NUM_COLUMNS = 3
Sub Main
End Sub
'----------
' Call this to begin creating a new dialog box.
'
Sub DlgTool_CreateNewDialog( x As Long, y As Long, width As Long, height As Long, cTitle As String )
oDialogModel = createUnoService( "com.sun.star.awt.UnoControlDialogModel" )
' Initialize the dialog model's properties.
oDialogModel.PositionX = x
oDialogModel.PositionY = y
oDialogModel.Width = width
oDialogModel.Height = height
oDialogModel.Title = cTitle
oDialogControl = createUnoService( "com.sun.star.awt.UnoControlDialog" )
oDialogControl.setModel( oDialogModel )
nNumControls = 0
ReDim oControls( nNumControls, CTRL_NUM_COLUMNS-1 )
End Sub
'------------------------------------------------------------
' Every Button must have an action listener subroutine
' of the following form.
'
' Sub btnName_actionPerformed( oEvent As com.sun.star.awt.ActionEvent )
' or
' Sub btnName_actionPerformed( oEvent )
'
' Where btnName is the name of the button, or is the cEventListenerName parameter.
'
' When the action listener is called, it is passed a parameter
' which is a struct com.sun.star.awt.ActionEvent
' which contains the following members:
' ActionCommand As String
' Source As com.sun.star.uno.XInterface
' so you can refer to the properties...
' oEvent.ActionCommand
' oEvent.Source
'------------------------------------------------------------
'----------
' Call this to place a new button on the dialog box.
'
Sub DlgTool_Button( x As Long, y As Long, width As Long, height As Long, cName As String, cCaption As String,_
Optional cEventListenerName As String )
If x < 0 Then
x = oDialogModel.Width + x - width
EndIf
If y < 0 Then
y = oDialogModel.Height + y - height
EndIf
oButtonModel = oDialogModel.createInstance( "com.sun.star.awt.UnoControlButtonModel" )
' Initialize the button model's properties.
oButtonModel.PositionX = x
oButtonModel.PositionY = y
oButtonModel.Width = width
oButtonModel.Height = height
oButtonModel.Name = cName
oButtonModel.TabIndex = nNumControls
oButtonModel.Label = cCaption
oDialogModel.insertByName( cName, oButtonModel )
oButtonControl = oDialogControl.getControl( cName )
' Buttons always get an action listener.
' You must create a procedure with the right name to receive the event.
If IsMissing( cEventListenerName ) Then
cEventListenerName = cName
EndIf
oActionListener = CreateUnoListener( cEventListenerName + "_", "com.sun.star.awt.XActionListener" )
oButtonControl.addActionListener( oActionListener )
ReDim Preserve oControls( nNumControls, CTRL_NUM_COLUMNS-1 )
oControls( nNumControls, CTRL_NAME ) = cName
oControls( nNumControls, CTRL_MODEL ) = oButtonModel
oControls( nNumControls, CTRL_CONTROL ) = oButtonControl
nNumControls = nNumControls + 1
End Sub
'----------
' Call this to place a new button on the dialog box.
'
Sub DlgTool_Checkbox( x As Long, y As Long, width As Long, height As Long, cName As String, cCaption As String,_
Optional bChecked As Boolean,_
Optional cEventListenerName As String )
If x < 0 Then
x = oDialogModel.Width + x - width
EndIf
If y < 0 Then
y = oDialogModel.Height + y - height
EndIf
oButtonModel = oDialogModel.createInstance( "com.sun.star.awt.UnoControlCheckBoxModel" )
' Initialize the button model's properties.
oButtonModel.PositionX = x
oButtonModel.PositionY = y
oButtonModel.Width = width
oButtonModel.Height = height
oButtonModel.Name = cName
oButtonModel.TabIndex = nNumControls
oButtonModel.Label = cCaption
oButtonModel.State = 0
If bChecked Then
oButtonModel.State = 1
EndIf
oDialogModel.insertByName( cName, oButtonModel )
oButtonControl = oDialogControl.getControl( cName )
' Buttons always get an action listener.
' You must create a procedure with the right name to receive the event.
If IsMissing( cEventListenerName ) Then
cEventListenerName = cName
EndIf
oActionListener = CreateUnoListener( cEventListenerName + "_", "com.sun.star.awt.XActionListener" )
oButtonControl.addActionListener( oActionListener )
ReDim Preserve oControls( nNumControls, CTRL_NUM_COLUMNS-1 )
oControls( nNumControls, CTRL_NAME ) = cName
oControls( nNumControls, CTRL_MODEL ) = oButtonModel
oControls( nNumControls, CTRL_CONTROL ) = oButtonControl
nNumControls = nNumControls + 1
End Sub
'----------
' Call this to put a label onto the dialog box.
'
Sub DlgTool_Label( x As Long, y As Long, width As Long, height As Long, cName As String, cCaption As String )
If x < 0 Then
x = oDialogModel.Width + x - width
EndIf
If y < 0 Then
y = oDialogModel.Height + y - height
EndIf
oLabelModel = oDialogModel.createInstance( "com.sun.star.awt.UnoControlFixedTextModel" )
' Initialize the label model's properties.
oLabelModel.PositionX = x
oLabelModel.PositionY = y
oLabelModel.Width = width
oLabelModel.Height = height
oLabelModel.Name = cName
oLabelModel.TabIndex = nNumControls
oLabelModel.Label = cCaption
oDialogModel.insertByName( cName, oLabelModel )
oLabelControl = oDialogControl.getControl( cName )
ReDim Preserve oControls( nNumControls, CTRL_NUM_COLUMNS-1 )
oControls( nNumControls, CTRL_NAME ) = cName
oControls( nNumControls, CTRL_MODEL ) = oLabelModel
oControls( nNumControls, CTRL_CONTROL ) = oLabelControl
nNumControls = nNumControls + 1
End Sub
'----------
' Call this to display and start the dialog box.
'
Sub DlgTool_Execute()
oDialogControl.setVisible( True )
oDialogControl.execute()
End Sub
'----------
' Call this while the dialog box is executing to end the dialog box.
'
Sub DlgTool_EndExecute()
oDialogControl.endExecute()
oDialogControl.setVisible( False )
End Sub
|
I plan to build this into something much more elaborate in Java and Python. This way my Java and Python components can create native OOo dialogs so that my component appears to be truly integrated into OOo. _________________ Want to make OOo Drawings like the colored flower design to the left?
Last edited by DannyB on Wed Dec 01, 2004 9:13 am; edited 1 time in total |
|
| Back to top |
|
 |
WatchyPerry Guest
|
Posted: Mon Jun 21, 2004 2:32 pm Post subject: new CheckBox |
|
|
DannyB
I just copied the code from your post and ran it (wanting to start using some dialogs in some of my projects) and I get the error:
| Quote: |
Unknown data type for com.sun.star.awt.UnoControlDialogModel
|
Am I missing something
In your post you mentioned that some of the code was from the actual "Dialog ToolKit"... What does that refer to [/quote][/list] |
|
| Back to top |
|
 |
Liliana_mcm General User


Joined: 19 May 2004 Posts: 32 Location: Marinha Grande - Portugal
|
Posted: Tue Jun 22, 2004 3:26 am Post subject: |
|
|
Hi,
| Quote: |
WatchyPerry
I just copied the code from your post and ran it (wanting to start using some dialogs in some of my projects) and I get the error:
Unknown data type for com.sun.star.awt.UnoCntrolDialogModel
|
I have test the code and I get the same error, but I solve it just change the two lines above:
| Quote: | Private oDialogModel As com.sun.star.awt.UnoControlDialog
Private oDialogControl As com.sun.star.awt.UnoControlDialog
|
to this:
| Quote: | Private oDialogModel
Private oDialogControl |
Try it now, it works with me.
Liliana Matos.  |
|
| Back to top |
|
 |
WatchyPerry Guest
|
Posted: Tue Jun 22, 2004 9:05 am Post subject: new CheckBox |
|
|
Your right Liliana
When I changed the code it worked fine. THANKS. |
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 4021 Location: Lawrence, Kansas, USA
|
Posted: Sat Nov 20, 2004 3:07 pm Post subject: |
|
|
Just a few messages up....
| DannyB wrote: | | I plan to build this into something much more elaborate in Java and Python. This way my Java and Python components can create native OOo dialogs so that my component appears to be truly integrated into OOo |
Here is an example of how to create dialog boxes on the fly in Python. A dialog box toolkit for Python. This makes it easy to construct dialog boxes from Python, using OOo's user interface.
http://www.oooforum.org/forum/viewtopic.php?p=56027#56027
The code includes examples of how to use the toolkit. It is incomplete in that it doesn't yet implement all of the controlls that OOo offers. But I think you can see how to extend it.
Now that just leaves a Java version that needs built. _________________ Want to make OOo Drawings like the colored flower design to the left? |
|
| Back to top |
|
 |
etuardu General User

Joined: 29 Apr 2008 Posts: 13
|
Posted: Tue Apr 29, 2008 2:50 am Post subject: action listener on textbox |
|
|
Hi, I need to put a textbox on a dialog at runtime so I extended your code with a subroutine I called DlgTool_Text in wich I create the com.sun.star.awt.UnoControlEditModel instance just like the other subroutines do with the other controls.
Unfortunately, I got the basic runtime error: "property or method not found" on the line that assigns the action listener to the control:
| Code: |
oTextControl.addActionListener( oActionListener )
|
If I comment out that line, the dialog is spawn with the textbox inside as I would, but I can't handle any events for the control.
I need to perform operations when the text in the textbox gets changed... any helps?
Thank you! |
|
| Back to top |
|
 |
SergeM Super User

Joined: 09 Sep 2003 Posts: 3208 Location: Troyes France
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|