[Solved] Popup Form

Creating and using forms

[Solved] Popup Form

Postby gkick » Wed Aug 14, 2019 8:26 am


Is there a way to either limit the size of a form aka the size of a dialog or could a dialog be used as a form without all that macro stuff ? And is there a way to position the form at a specific location aka xml coordinates ?
I have some forms with lots of listboxes and if an additional entry is required in the underlying reference table, I do not want to open a full sized form on top.
Last edited by Hagar Delest on Thu Aug 15, 2019 10:46 am, edited 1 time in total.
Reason: tagged solved
OpenOffice 3.1 on Windows 10
Posts: 13
Joined: Wed Aug 07, 2019 5:24 pm

Re: Popup Form

Postby UnklDonald418 » Thu Aug 15, 2019 5:10 am

Dialogs are not data aware and they can only be opened with a macro.
Open a form document in the Edit/Design mode and adjust the size to your liking. Save and exit. The next time you open that form document it will open at the same size you saved it.
When Base opens a form document it calculates what it considers to be the optimal position (centered) and positions it there, you have no control over that.
The only recourse is a macro to reposition it. Here is one I use.

Code: Select all   Expand viewCollapse view
REM  *****  BASIC  *****
REM  run this macro from Tools>Customize>Events>Open Document

Sub MoveForm

Dim iFlag as integer
Dim Xpos as integer, Ypos as integer
Dim FormWid as integer, FormHt as integer
Dim Formname as string
Dim oDoc as object

oDoc = ThisComponent
Formname = Split(oDoc.Title," : ")(1)
select case Formname
case "FormName1"
     Xpos = 40
     Ypos = 300
case "FormName2"
    Xpos = 440
    Ypos = 137
case "FormName3"
    Xpos = 320
    Ypos = 390
case else
    Xpos = 0
    Ypos = 0
end select

iFlag = com.sun.star.awt.PosSize.POS   ' 3

FormWid = 0  'no change
FormHt = 0   'no change
if xpos > 0 then

End Sub

Below is an associated macro. Position your form document where you want it to appear and Run this macro to display the Position values needed for the MoveForm macro.

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

Sub ShowScreenPosition
Dim iFlag as integer
Dim Xpos as Long, Ypos as Long
Dim FormWid as Long, FormHt as Long
Dim vRect As New com.sun.star.awt.Rectangle

vRect = ThisComponent.CurrentController.Frame.ContainerWindow.getPosSize()

Xpos = vRect.X
Ypos = vRect.Y
FormWid = vRect.Width
FormHt = vRect.Height
Print "X= " + Xpos + "   Y= " + Ypos + "   Width= " + FormWid + "   Height= " + FormHt

End Sub

It also displays the size values, but the MoveForm macro would need a few modifications to use those values.
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 - Windows 10 Professional
Posts: 1194
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Popup Form

Postby gkick » Thu Aug 15, 2019 8:48 am

Thank you for the prompt reply, much appreciated :D
Now is there a way to strip the form of the menubar?
OpenOffice 3.1 on Windows 10
Posts: 13
Joined: Wed Aug 07, 2019 5:24 pm

Re: [Solved] Popup Form

Postby Villeroy » Thu Aug 15, 2019 11:00 am

I like this useful pair of macros and tried to improve it by making it more generic without hard code values and names.

Save the code in some global library under "My Macros".
Open the form document (or any other Writer, Calc, Impress, Draw document) for editing and drag the window to the wanted position/size.
Call macro Save_ScreenPositionSize. It stores the position/size values in the custom properties (see menu:File>Properties>Custom...)
 Edit: Call menu:Tools>Customize... and assign event "View Created" "Open Document" to "Set_ScreenPositionSize". 

Save and close the document.
Reopen the document.
If the macro fails to do its job, I found out that some delay helps. Open the document for editing and set custom property "Window_Wait_ms" to 1000 milliseconds.
For some reason, Base always centers a form window on screen. I did not find out how to overcome this. Does not happen with the right event which seems to be "Open Document" as advised by UnklDonald418

Code: Select all   Expand viewCollapse view
REM  *****  BASIC  *****
Option Explicit
Sub Save_ScreenPositionSize()
Dim vRect As New com.sun.star.awt.Rectangle
Dim oUDP, oInfo
Dim unoLong As Variant
   unoLong = CreateUnoValue( "long", 0)
   vRect = ThisComponent.CurrentController.Frame.ContainerWindow.getPosSize()
   oUDP = ThisComponent.DocumentProperties.UserDefinedProperties
   oInfo = oUDP.PropertySetInfo
   if not oInfo.hasPropertyByName("Window_X") then oUDP.addProperty("Window_X", 128, unoLong)
   if not oInfo.hasPropertyByName("Window_Y") then oUDP.addProperty("Window_Y", 128, unoLong)
   if not oInfo.hasPropertyByName("Window_Width") then oUDP.addProperty("Window_Width", 128, unoLong)
   if not oInfo.hasPropertyByName("Window_Height") then oUDP.addProperty("Window_Height", 128, unoLong)
   if not oInfo.hasPropertyByName("Window_Wait_ms") then oUDP.addProperty("Window_Wait_ms", 128, unoLong)
   oUDP.Window_X = vRect.X
   oUDP.Window_Y = vRect.Y
   oUDP.Window_Width = vRect.Width
   oUDP.Window_Height = vRect.Height
End Sub

Sub Set_ScreenPositionSize()
Dim oUDP, oInfo, oFrame, oWin
Dim iMilliSeconds As Integer
Dim iFlag as integer
Dim Xpos as integer, Ypos as integer
Dim FormWid as integer, FormHt as integer
   'oFrame = StarDesktop.ActiveFrame
   oWin = ThisComponent.CurrentController.Frame.ContainerWindow
   oUDP = ThisComponent.DocumentProperties.UserDefinedProperties
   oInfo = oUDP.PropertySetInfo
   if oInfo.hasPropertyByName("Window_X") then iFlag = iFlag +1 : Xpos = oUDP.Window_X
   if oInfo.hasPropertyByName("Window_Y") then iFlag = iFlag +2 : Ypos = oUDP.Window_Y
   if oInfo.hasPropertyByName("Window_Width") then iFlag = iFlag +4 : FormWid = oUDP.Window_Width
   if oInfo.hasPropertyByName("Window_Height") then iFlag = iFlag +8 : FormHt = oUDP.Window_Height
   if oInfo.hasPropertyByName("Window_Wait_ms") then iMilliSeconds = oUDP.Window_Wait_ms
   wait iMilliSeconds
End Sub
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, no OpenOffice, LibreOffice 6.x
User avatar
Posts: 26966
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Solved] Popup Form

Postby gkick » Fri Aug 16, 2019 12:31 am

Thank you
OpenOffice 3.1 on Windows 10
Posts: 13
Joined: Wed Aug 07, 2019 5:24 pm

Return to Forms

Who is online

Users browsing this forum: No registered users and 2 guests