Page 1 of 1

[Solved] Maximize grid

PostPosted: Mon May 07, 2018 6:26 pm
by JoseJuan
Hello everyone,
I have a form with a grid control. When opening the form it is maximized, I need that the grid control is maximized to the area inside the form, leaving its top left position fixed.
I have managed to adjust the size but the operation of the mouse is not correct. When the mouse passes over the area that the grid originally had, it resizes it to reduce it to that previous size, as if it did not like its new size. :D

Code: Select all   Expand viewCollapse view
FormDoc = ThisDatabaseDocument.FormDocuments.GetByName(NomForm)
FormDoc.Component.CurrentController.Frame.ContainerWindow.IsMaximized = True      
FormLista = FormDoc.Component.Drawpage.Forms.getByIndex(0)

Dim Fld as Object, Ctl as Object      
Dim Ventana As Object, RectVentana As New com.sun.star.awt.Rectangle, RectCtl As New com.sun.star.awt.Rectangle

Ventana = FormDoc.Component.CurrentController.ComponentWindow   
RectVentana = Ventana.getPosSize   

Fld = FormLista.getByName("Lista")      
Ctl = FormDoc.Component.getCurrentController().getControl(Fld)
RectCtl = Ctl.getPosSize()   

Ctl.setPosSize(RectCtl.X, RectCtl.Y, RectVentana.Width - RectCtl.X, RectVentana.Height - RectCtl.Y, com.sun.star.awt.PosSize.SIZE)

Any ideas?

Thanks.

Re: Maximize grid

PostPosted: Mon May 07, 2018 7:07 pm
by RPG
When you want only have a grid-control in a formdocument and want also want to resize the gridcontrol in the form on the same moment when you resize the complete form document then it is maybe better to display the information in the standard table-view for a table or query.

Romke

Re: Maximize grid

PostPosted: Mon May 07, 2018 7:41 pm
by JoseJuan
The form also has some buttons like a small navigation bar.
In addition, the grid captures a double-click event, simulated by code, to open the form for the edition of the record.
Thanks.

Re: Maximize grid

PostPosted: Fri May 11, 2018 1:04 am
by UnklDonald418
It appears you are trying to modify the Grid control properties, but according to "OpenOffice.org Base Macro Programming" By Andrew Pitonyak, “To change the size or location of a control, find the corresponding control shape and modify it.”
As a test I created a form document with a small Grid control and a Button. When I press the Button it runs the following macro which moves the Grid control to a new location, doubles its size and those changes persist regardless where I move the mouse.

Code: Select all   Expand viewCollapse view
REM  *****  BASIC  *****

Sub ResizeMoveTableGrid (oEv as object)

Dim oDoc
Dim oDrawPage
Dim oShape
Dim cPosition as New com.sun.star.awt.Point
Dim cSize as New com.sun.star.awt.Size

oDoc = ThisComponent
oDrawPage = oDoc.getDrawPage()
oShape = oDrawpage.getByIndex(0)

cPosition = oShape.getPosition()
cSize = oShape.getSize
cPosition.X = 100
cPosition.Y = 100
cSize.Width = cSize.Width * 2
cSize.Height = cSize.Height * 2
oShape.setSize(csize)
oShape.setPosition(cPosition)

End Sub

Re: Maximize grid

PostPosted: Fri May 11, 2018 5:05 pm
by UnklDonald418
Using your macro code I was able to get the shape
Code: Select all   Expand viewCollapse view
oShape = FormDoc.Component.Drawpage.getByIndex(0)

Shapes don't have getPosSize() or setPosSize() methods but they do have getSize()/setSize() and getPosition()/setPosition().
The measurement units for Shapes is twips instead of pixels. There are two functions that can help with that conversion.
TwipsPerPixelX()
TwipsPerPixelY()

Re: Maximize grid

PostPosted: Fri May 11, 2018 5:09 pm
by RoryOF
For information, in OO a Twip means 1/20 of a point, and a point is 1/72 of an inch. So a twip is 1/1440 of an inch.

Re: Maximize grid

PostPosted: Fri May 11, 2018 11:35 pm
by JoseJuan
Thank you for presenting me the Shape object, it is new for me. It starts to work.
Now I'm fighting with both TwipsPerPixel, my machine gives a value of 15 but it's not right, I think it should be around 26, almost double.

Re: Maximize grid

PostPosted: Sat May 12, 2018 3:18 am
by UnklDonald418

Re: Maximize grid

PostPosted: Sat May 12, 2018 7:38 pm
by JoseJuan
Thanks to all, it is working correctly.
The process of adjusting the size of the grid, together with the maximize of the window and the hiding of the toolbars generate an unpleasant visual effect during form loading.
I go to search to open hidden, if I do not solve it I will put it in another thread.

This is the final code in new function:
Code: Select all   Expand viewCollapse view
Public Sub AjustarLista(FormDoc as Object)
    Dim FormForma as Object
    Dim Ventana As Object, RectVentana As New com.sun.star.awt.Rectangle
    Dim cPosition as New com.sun.star.awt.Point, cSize as New com.sun.star.awt.Size
   
    FormForma = FormDoc.Component.Drawpage.getByIndex(0)   
    Ventana = FormDoc.Component.CurrentController.ComponentWindow   
    RectVentana = Ventana.getPosSize   
   
    cPosition = FormForma.getPosition()
   '    cPosition.X = 100
   '    cPosition.Y = 100
   '    FormForma.setPosition(cPosition)       ' The origin position does not change
   
    cSize = FormForma.getSize
    cSize.Width = (RectVentana.Width * 100000 / Ventana.getInfo.PixelPerMeterX) - cPosition.X
    cSize.Height =  (RectVentana.Height * 100000 / Ventana.getInfo.PixelPerMeterY) - cPosition.Y - 50 
    FormForma.setSize(cSize)

End Sub

Gretings.