PositionX & PositionY no longer working for Dialog position on screen

I create dialogs in Libreoffice Calc, using basic. My version is 7.4.7.2. All my dialogs are positioned on the screen using the PositionX & PositionY properties… and work perfect.

However, when I upgrade libreoffice to a newer version… these properties stop working. The 1st dialog loaded positions correctly, but additional dialogs opened on top of 1st dialog, ALWAYS snap to grid, and are positioned in the upper left corner of screen.

Does PositionX & PositionY no longer work with newer versions? If so, what properties or methods do I need to use to position dialog where I want it on screen?

I’m running Windows 10, build 19045.3803

Please file a bug report with a specific code (a file with a macro and a dialog) that used to work, but now doesn’t.

Welcome ktrain!

here’s a piece of code I use under Linux with LibreOffice v.7.5.8.2 and which works OK:

TheDlg.setPosSize(ThePosX, ThePosY, 0, 0, com.sun.star.awt.PosSize.POS)

HTH

Please upload the full macro code and all of other resources (dialogs) embedded in a sample ODF file.

Are the dialogs created by the macro code or do you predefined them graphically?

So, it appears with the newer versions of Libreoffice, You can ONLY manually position, one Dialog at a time. If you attempt to open a 2nd dialog (pop up dialog) on top of 1st dialog… the PositionX & PositionY, and TheDlg.setPosSize don’t work. The 2nd dialog will always automatically be positioned at 0, 0

I’m not sure what the answer to this is.

@mikekaganski,

I will create a small file that opens 2 macros, that I use, that no longer work. Thanks.

@jfn, thanks for the code. It works perfect for the 1st dialog, but not the pop up dialogs.

@Zizi64, I “predefine” all of my dialogs by drawing them in the Calc Basic IDE environment, and adding the controls I need. Here are 2 macros from my application, the 1st macro is launched at program start, and the 2nd one is opened from a command button on the 1st dialog opened.

Sub Budget_Menu()
DialogLibraries.loadLibrary( “Library1” )
’ (DialogLibraries.“Name of load library”.“Name of Dialog”)
oBudget = CreateUnoDialog(DialogLibraries.Library1.Budget)

oBudget.Model.PositionX = 225  ' Position dialog  
oBudget.Model.PositionY = 35     

oBudget.Execute()  rem MUST be last line    

End Sub

Sub oBudget_AddSavIncomeMsgbox
DialogLibraries.loadLibrary( “Library1” )
’ (DialogLibraries.“Name of document library”.“Name of Dialog”)
oAddSavIncome = CreateUnoDialog(DialogLibraries.Library1.AddSavIncome)

oAddSavIncome.Model.PositionX = oBudget.Model.PositionX + 180 ' Position relevant to Main Menu 
oAddSavIncome.Model.PositionY = oBudget.Model.PositionY + 63

oAddSavIncome.Execute()  rem MUST be last line

End Sub

Upload a sample FILE, please. We will not (we can not) reconstruate the state what you have in your ODF file based on this minimal information.
.
Why you want to open more than one dialogs in same time???

@Zizi64, Sorry about that. My file is an application I created to track my monthly expenses. I’ve created a sample for Dec 2023, with dummy data, that will allow the program to be fully functional. It is the entire program with all of the macros included. The “Edit” button and most of buttons on right side of dialog, will open a 2nd dialog. I don’t create dialogs & macros to do simple table calculations… I create entire applications using Libreoffice Calc basic. It is well suited to my needs. I open more than one dialog at a time so I don’t have to close & reopen the main form constantly.

Budget Form 2024 - Sample.ods (152.6 KB)

It is raised two silly questions in my mind:

  • Why you not use a real programming graphics IDE instead of the Calc and StarBasic+API (is you want not use the existing built-in features of the LibreOffice )?? For example the Lazarus Project or other…

  • Why you not use a real DataBase and a relevant application to handle it?

Hi Charles,

a happy New Year!

Here’s the code I’m actually using to center secondary dialogues on caller ones:

Sub CenterDialog(ByRef pDlg As Object, Optional ByRef pCallerWindow As Object)
'centers a given dialog in front of a "owning" dialog or screen.
'Input:
'-- pDlg: the dialogue to be centered.
'-- pCallerWindow: (optional) the window that owns the dialog.
'                  If not specified, the owner is the LibO module frame.

	Dim lo_Ctnr As Object		'the container object
	Dim l_VOffset As Long
	Dim l_HOffset As Long
	Dim X As Long
	Dim Y As Long
	
	If IsMissing(pCallerWindow) Then pCallerWindow = ThisComponent.CurrentController.Frame

	'check caller container
	If pCallerWindow.SupportsService("com.sun.star.frame.Frame") Then
		'module frame
		lo_Ctnr = pCallerWindow.ContainerWindow
	ElseIf pCallerWindow.SupportsService("com.sun.star.awt.UnoControlDialog") Then
		'dialogue
		lo_Ctnr = pCallerWindow
	Else
		'not something we know of
		Exit Sub
	End If
	
	'set new position
	l_HOffset = (lo_Ctnr.PosSize.Width  - pDlg.PosSize.Width) \ 2
	l_VOffset = (lo_Ctnr.PosSize.Height - pDlg.PosSize.Height) \ 2
	X = lo_Ctnr.PosSize.X + l_HOffset
	Y = lo_Ctnr.PosSize.Y + l_VOffset
	pDlg.setPosSize(X, Y, 0, 0, com.sun.star.awt.PosSize.POS)

End Sub 'CenterDialog

Calling sample (in a commandbutton event):
`CenterDialog(oDlg, pEvt.Source.Context)`

HTH,

@ktrain You can also look to How to set a dialog always at the center of the screen?

1 Like

@jfn, Thanks for code, works perfect in 7.4.7.2… but does not work in 7.5.9.2.

Thanks everyone for the help.

Charles,

works for me under Linux, with:


Version: 7.5.8.2 (X86_64) / LibreOffice Community
Build ID: f718d63693263970429a68f568db6046aaa9df01
CPU threads: 4; OS: Linux 5.15; UI render: default; VCL: gtk3
Locale: fr-FR (fr_FR.UTF-8); UI: fr-FR
Calc: threaded


What is the OS and what doesn’t work for you? I’ve noticed a dysfunction with Windows 10, where the dialog is not centered above the top window. It seems the top window and dialog X/Y references are not handled the same under Linux and under Windows. If anyone’s got an idea, I’d be very glad for that.

It seems it is bug. If there is used the method .isMinimized=True for Container window, then the function .setPosSize isn’t functional for positioning of Dialog X & Y.
I tested Dialog Notes1 by click to button Notes.




I changed the Sub Hide_TopForm & Sub Show_TopForm, there is comment with bug.
Budget Form 2024 - Sample.ods (151.9 kB)


Version: 7.6.4.1 (X86_64) / LibreOffice Community Build ID: e19e193f88cd6c0525a17fb7a176ed8e6a3e2aa1 CPU threads: 8; OS: Windows 10.0 Build 17763; UI render: Skia/Raster; VCL: win Locale: cs-CZ (cs_CZ); UI: cs-CZ Calc: CL threaded

@KamilLanda,

Wow! You solved the issue, it now works properly in latest version. I was also positive that it was a bug with the newer version, since my program worked perfectly before I upgraded.

How did you figure out it was the “.isMinimized=true / false” ??

Also, I like how you reduced my code down to just one line for the Hide_TopForm & Show TopForm subs. Thanks so much for your help.

By debugging and trial-and-error :-). I also work with Dialogs and I used the positioning and hiding/showing the Dialogs more times, so I remember some variants for it.

@KamilLanda ,

Another benefit to using “.Visible” I see… is the spreadsheet does not pop up in the background if you click outside of the top Dialog.

I always use the “Model.PositionX / Y” method to position my dialogs. I use the “setPosSize” when creating an object on the fly.

Once again, thanks for your help.

@ktrain Hidden window isn’t solution for non-functional .setPosSize in minimized window.
I reported bug 159003.
You can confirm it and add the info about functional vesion of LibreOffice.

1 Like