Dialog reposition/resize in named frame

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
ElFlamencoLoco
Posts: 20
Joined: Mon Dec 28, 2015 8:45 pm

Dialog reposition/resize in named frame

Post by ElFlamencoLoco »

Context
Writing a set of OOBasic-macros, embedded in a document template (.ott), I need a lot of different dialog boxes, all created in the OOBASIC IDE.

Problem allready solved
At any moment, I want to retrieve the active dialog box, using StarDeskTop.FindFrame. This function, however, expects each dialog box running in a named Frame:

Code: Select all

'Named frame allready exists?
oFrame=StarDesktop.findFrame("ActiveDialog", _
  com.sun.star.frame.FrameSearchFlag.GLOBAL)

'No, so create it.
IF isNull(oFrame) THEN
  oFrame=CreateUnoService("com.sun.star.frame.Frame")
  oFrame.Initialize(StarDesktop.ActiveFrame.ContainerWindow)
  oFrame.Name="ActiveDialog"
  StarDesktop.Frames.append(oFrame)
END IF

'Link dialog to named frame.
oFrame.setComponent(oDialog,null)
This works fine.

Retrieving the dialog is now quite easy, anytime, anywhere:

Code: Select all

oFrame=StarDesktop.findFrame("ActiveDialog", _
  com.sun.star.frame.FrameSearchFlag.GLOBAL)
oDialog=oFrame.ComponentWindow
This also works perfect. Now the actual problem.

Problem to solve
Running the dialog:

Code: Select all

oDialog.Execute
The dialog works fine, but...

... covers (almost) the entire screen!

My approach, before calling .Execute:

Code: Select all

'The values are arbitrary - only for testing purposes.
WITH Dia.Model
  .Width=400
  .Height=300
  .PositionX=20
  .PositionY=20
END WITH
This does not work; the dialog still covers the entire screen.

My request
I would be grateful if anybody knows how to reposition/resize the dialog window, or how to maintain the values set while creating the dialog in the OOBASIC IDE.
Windows 10
OpenOffice 4.1.2
UnklDonald418
Volunteer
Posts: 1544
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Dialog reposition/resize in named frame

Post by UnklDonald418 »

Rather than changing the values in the Dialog's Model I believe you need to use the setPosSize() method available in the View.
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
ElFlamencoLoco
Posts: 20
Joined: Mon Dec 28, 2015 8:45 pm

Re: Dialog reposition/resize in named frame

Post by ElFlamencoLoco »

So, I've tried both...

Code: Select all

oDia.setPosSize(30,30,400,300,15)
oDia.Execute
... and...

Code: Select all

oDia.View.setPosSize(30,30,400,300,15)
oDia.Execute
But... no avail! Nevertheless, thanks for your quick reply.

Other suggestions?
Windows 10
OpenOffice 4.1.2
User avatar
RoryOF
Moderator
Posts: 34586
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Dialog reposition/resize in named frame

Post by RoryOF »

Any messages when these are used?
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
ElFlamencoLoco
Posts: 20
Joined: Mon Dec 28, 2015 8:45 pm

Re: Dialog reposition/resize in named frame

Post by ElFlamencoLoco »

Forgive me, but I do not understand your request?
Windows 10
OpenOffice 4.1.2
User avatar
RoryOF
Moderator
Posts: 34586
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Dialog reposition/resize in named frame

Post by RoryOF »

Any error message when the macro code using these structures is run?
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
UnklDonald418
Volunteer
Posts: 1544
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Dialog reposition/resize in named frame

Post by UnklDonald418 »

Code: Select all

oDia.setPosSize(30,30,400,300,15)
oDia.Execute 
should generate an exception because a Dialog does not have a setPosSize() method
But in my tests

Code: Select all

oDia.View.setPosSize(30,30,400,300,com.sun.star.awt.PosSize.POSSIZE)
oDia.Execute 
resizes and relocates the Dialog immediately on opening.
Also in my tests

Code: Select all

oDia.setPosSize(30,30,400,300,com.sun.star.awt.PosSize.POSSIZE)
works in an event handler while the dialog is active.
Be aware that changing the size doesn't shrink or grow the Dialog, it only adjusts the area on the screen to display the Dialog. If the Dialog is designed to be larger than the size in your macro code then part of the Dialog will not display.
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
ElFlamencoLoco
Posts: 20
Joined: Mon Dec 28, 2015 8:45 pm

Re: Dialog reposition/resize in named frame

Post by ElFlamencoLoco »

RoryOF wrote:Any error message when the macro code using these structures is run?
O sorry, no idea you're mentioning error messages. ;)

Not at all, the code runs cleanly, exept the repositioning/resizing.
Windows 10
OpenOffice 4.1.2
ElFlamencoLoco
Posts: 20
Joined: Mon Dec 28, 2015 8:45 pm

Re: Dialog reposition/resize in named frame

Post by ElFlamencoLoco »

UnklDonald418 wrote:...in my tests

Code: Select all

oDia.View.setPosSize(30,30,400,300,com.sun.star.awt.PosSize.POSSIZE)
oDia.Execute 
resizes and relocates the Dialog immediately on opening.
Also in my tests

Code: Select all

oDia.setPosSize(30,30,400,300,com.sun.star.awt.PosSize.POSSIZE)
works in an event handler while the dialog is active.
Be aware that changing the size doesn't shrink or grow the Dialog, it only adjusts the area on the screen to display the Dialog. If the Dialog is designed to be larger than the size in your macro code then part of the Dialog will not display.
The problem might be caused by the alternative technique I use to create the dialog. The standard technique:

Code: Select all

oDialog=CreateUNODialog(DialogLibraries.Name_of_lib.Name_of_dialog)
The technique I prefer:

Code: Select all

oDoc.DialogLibraries.loadLibrary(Name_of_lib)
oLib=oDoc.DialogLibraries.getByName(Name_of_lib)
oDiaScript=oLib.getByName(Name_of_dialog)
oDialog=createUnoDialog(oDiaScript)
This technique allows writing a function "createMyDialog" with parameters:
  • the component's URL (the application existing of several .ott-files)
  • the name of the library
  • the name of the dialog
By searching the URL in the StarDesktop, retrieving the component is easy. A call might look like this:

Code: Select all

oDialog=createMyDialog(URL_of_service_module,StatisticLib,SyntheseDia)
Anybody an idea?
Windows 10
OpenOffice 4.1.2
UnklDonald418
Volunteer
Posts: 1544
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Dialog reposition/resize in named frame

Post by UnklDonald418 »

The problem might be caused by the alternative technique I use to create the dialog.

I don't think that is the problem because when I use

Code: Select all

oDoc.DialogLibraries.loadLibrary(Name_of_lib)
oLib=oDoc.DialogLibraries.getByName(Name_of_lib)
oDiaScript=oLib.getByName(Name_of_dialog)
oDialog=createUnoDialog(oDiaScript) 
oDialog.View.setPosSize(30,30,400,300,com.sun.star.awt.PosSize.POSSIZE)
oDialog.Execute 
on my test dialog, it opens at the specified size and position
Perhaps the problem is with the Dialog. Have you tried more than one?
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
Post Reply