[Solved] Maximize grid

Creating and using forms
Post Reply
User avatar
JoseJuan
Posts: 16
Joined: Sun Apr 29, 2018 10:16 am

[Solved] Maximize grid

Post 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

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.
Last edited by JoseJuan on Sat May 12, 2018 7:38 pm, edited 1 time in total.
LibreOffice 6.1 on Windows 7 / LibreOffice 5.4 on Windows XP
RPG
Volunteer
Posts: 2250
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: Maximize grid

Post 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
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
User avatar
JoseJuan
Posts: 16
Joined: Sun Apr 29, 2018 10:16 am

Re: Maximize grid

Post 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.
LibreOffice 6.1 on Windows 7 / LibreOffice 5.4 on Windows XP
UnklDonald418
Volunteer
Posts: 1544
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Maximize grid

Post 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

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
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
UnklDonald418
Volunteer
Posts: 1544
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Maximize grid

Post by UnklDonald418 »

Using your macro code I was able to get the shape

Code: Select all

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()
Last edited by UnklDonald418 on Fri May 11, 2018 5:18 pm, edited 1 time in total.
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
User avatar
RoryOF
Moderator
Posts: 34586
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Maximize grid

Post 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.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
User avatar
JoseJuan
Posts: 16
Joined: Sun Apr 29, 2018 10:16 am

Re: Maximize grid

Post 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.
LibreOffice 6.1 on Windows 7 / LibreOffice 5.4 on Windows XP
UnklDonald418
Volunteer
Posts: 1544
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Maximize grid

Post by UnklDonald418 »

Sorry, they are not Twips. The units are 1/100 mm
https://www.openoffice.org/api/docs/com ... Shape.html
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
User avatar
JoseJuan
Posts: 16
Joined: Sun Apr 29, 2018 10:16 am

Re: Maximize grid

Post 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

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.
LibreOffice 6.1 on Windows 7 / LibreOffice 5.4 on Windows XP
Post Reply