Hello. I've cobbled together some code that lets me populate a form with buttons via a macro as sort of a poor-man's image map of garden plots for a little application I'm writing. The user defines the dimensions of the bed in a database. When that bed is clicked, my code builds a "drawing" of it using a command button for each square foot "plot". When the user clicks on a plot, the code opens a form with 144 "sub-plot" buttons (one for each square inch in the selected square-foot plot). Each of these buttons can be populated with a plant ID (by selecting the plant by name from a drop-down list and then clicking on all of the square-inch buttons where you're planting that particular species). When you're done, it writes all the changes to a database, along with the date planted and some other information. I've got this all working except for the part where clicking one of the buttons the code drew getting you to the "sub-plot" screen. I can add an event (using the GUI) to one of the code-created buttons and that works, but I want to be able to include the event action in the button properties when they're created. I've found lots of information about adding event listeners, etc, but 1) they seem more complicated than what I'm trying to do should be, and 2) even if I were going to use that method, I can't seem to find a way to list the "event" properties for one of my manually edited controls to see how the event is defined there, so I can copy it. I can't find any properties or methods using xray which seem to apply. Any suggestions? Can I add an event to the form the buttons are on somehow, and then use something like:
Code: Select all
oThisDoc = thisComponent.getDrawPage()
oForms =oThisDoc.getForms()
oForm = oForms.getByName("Standard")
oPlantList = oForm.getByName("PlantList")
oShovel = oForm.getByName("btnShovel")
to identify the button that was clicked (they all have unique names based on the plot they represent) and do it that way? Suggestions would be much appreciated.
Code: Select all
Sub AddButton(Xsize as integer,Ysize as integer,color as integer, oButtonName as string, Xpos as integer, Ypos as integer)
Dim frm
Dim oPage
Dim pt as new com.sun.star.awt.Point ' a point structure that will be used to demonstrate
' how to move the created listbox after it has been placed on the spreadsheet
oPage = thisComponent.getDrawPage()
frm = oPage.Forms.getByIndex(0)
oButtonModel = createUnoService("com.sun.star.form.component.CommandButton")
'xray oButtonModel
PropNames = Array( "Name", "Enabled", "BackgroundColor" )
PropValues = Array(oButtonName,True,color)
setProperties(oButtonModel,PropNames,PropValues)
oShape = thisComponent.createInstance("com.sun.star.drawing.ControlShape")
Dim pos as new com.sun.star.awt.Point
pos.X = Xpos
pos.Y = Ypos
oShape.Position = pos
Erase pos
Dim size as New com.sun.star.awt.Size
size.Width = Xsize
size.Height = Ysize
oShape.Size = size
Erase size
'Assign the model to the shape
oShape.Control = oButtonModel
oShape.AnchorType=0
'insert the control model into the first form of the forms collection of the draw page for the document
frm.insertByIndex(0,oButtonModel)
'Add the shape to the drawpage
oPage.add(oShape)
'xray oShape
End Sub