Hello,
What you are asking for is a lot of information as so many things interact with each other. Will present what may be just a start for information.
First, you discuss the model, inserting and setting position and size of a control. From StarOffice 7 Basic Programmers Guide:
The Three Aspects of a Control Element Form
A control element of a form has three
aspects:
-
First, there is the Model of the control element. This is the key
object for the StarOffice
Basic-programmer when working with
control element forms.
-
The counterpart to this is the View of the control element, which
administers the display information.
-
Since control element forms within the documents are administered like a
special drawing element, there is also
a Shape object which reflects the
drawing element-specific properties of
the control element (in particular its
position and size).
The StarOffice guide PDF is here → https://www.mitomap.org/foswiki/pub/MITOWIKI/ArchivedProjectDataCuration/StarOffice_7_Basic_Programmers_Guide.pdf
A few other good references:
OpenOffice macros explained by Andrew Pitonyak → http://www.pitonyak.org/OOME_3_0.pdf
Andrew Base → http://www.pitonyak.org/database/AndrewBase.pdf
There is also some code in regard to you question. See → Creating Buttons and Assigning Code from Macro
Now that contains the instance for a command button. Here is a page with other controls (including image control) → com::sun::form::component Module Reference
This should be enough to get you started in the right direction.
Edit:
Here is the code from my comment and the pieces needed from the link and the control for image button:
Option Explicit
Sub CreateButton
Dim oDoc As Object
Dim oSheet As Object
Dim oDrawPage As Object
Dim oButtonModel As Object
Dim sScriptURL As String
DeleteControl
oDoc = ThisComponent
oSheet = oDoc.Sheets.getByIndex(0)
oDrawPage = oSheet.DrawPage
sScriptURL = "vnd.sun.star.script:Standard.Module1.ButtonPushEvent?language=Basic&location=document"
oButtonModel = AddNewButton("Button_1", "Button_1", oDoc, oDrawPage)
End Sub
Function AddNewButton(sName As String, sLabel As String, oDoc As Object, oDrawPage As Object) As Object
Dim oControlShape As Object
Dim aPoint
Dim aSize
Dim oButtonModel As Object
oControlShape = oDoc.createInstance("com.sun.star.drawing.ControlShape")
aPoint = CreateUnoStruct("com.sun.star.awt.Point")
aSize = CreateUnoStruct("com.sun.star.awt.Size")
aPoint.X = 1000
aPoint.Y = 1000
aSize.Width = 3000
aSize.Height = 1000
oControlShape.setPosition(aPoint)
oControlShape.setSize(aSize)
oButtonModel = CreateUnoService("com.sun.star.form.component.ImageButton")
oButtonModel.Name = sName
oButtonModel.imageURL = "YOUR_IMAGE_LOCATION_HERE"
oControlShape.setControl(oButtonModel)
oDrawPage.add(oControlShape)
AddNewButton = oButtonModel
End Function
Sub DeleteControl
Dim Doc As Object
Dim Shape as Object
Dim Sheet as Object
Dim DrawPage as Object
Dim I as integer
Doc = ThisComponent
Sheet = Doc.Sheets.getByIndex(0)
DrawPage = Sheet.DrawPage
For i = 0 to DrawPage.Count - 1
Shape = DrawPage(i)
If HasUnoInterfaces(Shape, "com.sun.star.drawing.XControlShape") Then
If Shape.Control.Name = "Button_1" Then
DrawPage.remove(Shape)
Exit For
End If
End If
Next
End Sub
This now deletes previous image button on first sheet and inserts a new one. You must insert your location for the image button. Will delete comment code relating to the deleting of the control.
Edit #2:
Also be aware there is an open bug report → tdf#46579