Set Window Size Of Form Using Size Of A Template Shape (wip)

Aim = resize window frame on opening a form to ‘match’ a template shape on that form …
Could be useful for others in creating and modifying Forms, but I can’t get it finished …
Here is sample test code, any ideas gratefully received:

sub SetWindowSizeUsingSizeOfTemplateShapeOnForm(ev) REM on open doc event
REM why? on some linux systems scrolling on a form can corrupt display of multi-line text boxes - i have forms designed for NOT scrolling and sized using the Resize function on opening (also HideToolbars), But if the window frame size is too small then user can still scroll and corrupt text boxes …
REM … therefore i am trying to use a ‘template shape’ like a group box to define and set a form window frame to fit it nice and tightly … some issues are a)identifying the “template-shape” correctly ,b) getting the offset and scaling right …
Dim Size As New com.sun.star.awt.Size
Dim N As string
frm = ev.Source
doc = getParentObject(frm, “com.sun.star.document.OfficeDocument”)
view = doc.CurrentController
win = view.Frame.ContainerWindow
oDrawPage = ThisComponent.getDrawPage()

‘Get total # of objects on DrawPage’
iCount = oDrawPage.Count
‘Cycle through objects’
msgbox(icount)
for x = 0 to iCount -1
oImage = oDrawPage.getByIndex(x)
N = oImage.Name
‘Check for wanted shape’
’ If N = “TemplateShape” Then REM i cant get it to find eg “MyControlName” …therefore testing with index values :frowning:
If x = 0 Then
msgbox(N)
msgbox(x)
Shape = oImage
Size = Shape.Size
Width = Size.Width /22.5 REM what is relationship between shape width (in mm?) and values of widow width (pixels?) — the number here is an arbitrary approximation only …:frowning:
Height = Size.Height / 22.5
msgbox(Width)
msgbox(Height)
win.setPosSize(1, 1, Width, Height,15)
Else

End If
Next x

end sub