[Solved] Maximize grid

Creating and using forms

[Solved] Maximize grid

Postby JoseJuan » Mon May 07, 2018 6:26 pm

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.
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
User avatar
JoseJuan
 
Posts: 16
Joined: Sun Apr 29, 2018 10:16 am

Re: Maximize grid

Postby RPG » Mon May 07, 2018 7:07 pm

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 6.2.5.2 on openSUSE Leap 15
RPG
Volunteer
 
Posts: 2172
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: Maximize grid

Postby JoseJuan » Mon May 07, 2018 7:41 pm

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
User avatar
JoseJuan
 
Posts: 16
Joined: Sun Apr 29, 2018 10:16 am

Re: Maximize grid

Postby UnklDonald418 » Fri May 11, 2018 1:04 am

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
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.6 & LibreOffice 6.1.5.2 - Windows 10 Professional
UnklDonald418
Volunteer
 
Posts: 1236
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Maximize grid

Postby UnklDonald418 » Fri May 11, 2018 5:05 pm

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()
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.6 & LibreOffice 6.1.5.2 - Windows 10 Professional
UnklDonald418
Volunteer
 
Posts: 1236
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Maximize grid

Postby RoryOF » Fri May 11, 2018 5:09 pm

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.7 on Xubuntu 18.04.3 (mostly 64 bit version) and very infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 29738
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Maximize grid

Postby JoseJuan » Fri May 11, 2018 11:35 pm

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
User avatar
JoseJuan
 
Posts: 16
Joined: Sun Apr 29, 2018 10:16 am

Re: Maximize grid

Postby UnklDonald418 » Sat May 12, 2018 3:18 am

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.6 & LibreOffice 6.1.5.2 - Windows 10 Professional
UnklDonald418
Volunteer
 
Posts: 1236
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Maximize grid

Postby JoseJuan » Sat May 12, 2018 7:38 pm

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.
LibreOffice 6.1 on Windows 7 / LibreOffice 5.4 on Windows XP
User avatar
JoseJuan
 
Posts: 16
Joined: Sun Apr 29, 2018 10:16 am


Return to Forms

Who is online

Users browsing this forum: No registered users and 1 guest