Page 1 of 1

[Solved] Maximize a dialog in Calc at runtime (OpenBASIC)

Posted: Mon Sep 19, 2016 4:40 pm
by Davte
I would like to set the dimensions of a dialog so that it fits the screen.
I found something useful on this forum, but the .Width and .Height I get from the container window (see code below) are not ready to use.

Code: Select all

Dim a As Integer, b As Integer
a = ThisComponent.getCurrentController.getFrame.ContainerWindow.PosSize.Width
b = ThisComponent.getCurrentController.getFrame.ContainerWindow.PosSize.Height
In fact, when I assign this values to the Height and Width property of a dialog (see code below), I get an over-sized window.

Code: Select all

Dim oDialog As Object
DialogLibraries.LoadLibrary("Standard")
oDialog = CreateUnoDialog(DialogLibraries.Standard.MyDialog1)
oDialog.getModel.PositionX = 0
oDialog .getModel.PositionY = 0
oDialog.Model.Width = a
oDialog.Model.Height = b
I manually adjusted this (by errors and trials) and found that dividing these measures by a certain constant I get what I need on my screen:

Code: Select all

oDialog.Model.Width = a / 2.054
oDialog.Model.Height = b / 1.883
I'm wondering why: are these properties (ContainerWindow.PosSize.Width vs oDialog.Model.Width) expressed in terms of different units of measurement? Is the container windows actually larger than I suppose (i.e. than the screen)? Why are the two coefficients (for width 2.054 and for height 1.883) different from each other?
Ultimately, is there a better and cleaner way to write "dialog, get the dimensions of the screen"?
Thanks in advance,
Davide

Re: Maximize a dialog in Calc at runtime (OpenBASIC)

Posted: Tue Sep 20, 2016 5:03 pm
by hanya
The Width and Height properties are described in APPFONT unit but size of the dialog is in real pixels. See the following conversion between these units:

Code: Select all

Sub dialog1_test
  ' needs Dialog1
  d = CreateUnoDialog(DialogLibraries.Standard.Dialog1)
  width = d.Model.Width
  size = CreateUnoStruct("com.sun.star.awt.Size")
  size.Width = width
  w1 = d.convertSizeToPixel(size, com.sun.star.util.MeasureUnit.APPFONT).Width
  w2 = d.getPosSize().Width
  size.Width = w2
  w3 = d.convertSizeToLogic(size,  com.sun.star.util.MeasureUnit.APPFONT).Width
  msgbox "width: " & CStr(width) & chr(10) & _
      "w1: " & CStr(w1) & chr(10) & "w2: " & CStr(w2) & chr(10) & "w3: " & CStr(w3)
  d.execute()
End Sub
You can set the size of your dialog through setPosSize method on the dialog object in pixels.

Re: Maximize a dialog in Calc at runtime (OpenBASIC)

Posted: Tue Sep 20, 2016 5:47 pm
by Davte
Thank you a lot, in fact I can get the two coefficients I had empirically found by the following operations:

Code: Select all

Sub dialog1_test
	Dim d, width, height, size, w1, w2, w3
		d = CreateUnoDialog(DialogLibraries.Standard.dialArchivio)
		width = d.Model.Width
		size = CreateUnoStruct("com.sun.star.awt.Size")
	size.Width = width
	
	w1 = d.convertSizeToPixel(size, com.sun.star.util.MeasureUnit.APPFONT).Width
	w2 = d.getPosSize().Width
	size.Width = w2
	w3 = d.convertSizeToLogic(size,  com.sun.star.util.MeasureUnit.APPFONT).Width
	msgbox "The width coefficient is: " & w1/w3
	
	height = d.Model.height
	size = CreateUnoStruct("com.sun.star.awt.Size")
	size.height = height
	w1 = d.convertSizeToPixel(size, com.sun.star.util.MeasureUnit.APPFONT).height
	w2 = d.getPosSize().height
	size.height = w2
	w3 = d.convertSizeToLogic(size,  com.sun.star.util.MeasureUnit.APPFONT).height
	msgbox "The height coefficient is: " & w1/w3
End Sub
Or simply by

Code: Select all

CoeffWidth = d.getpossize.width / d.model.width
CoeffHeight = d.getpossize.height / d.model.height
Please tell me if I got this right:
- "d.Model.width" is expressed in logical units (APPFONT)
- "d.getpossize.width" is expressed in real pixels
- the conversion between these units of measurement may be performed through "convertSizeToPixel" and "convertSizeToLogic"
I haven't really figured out well how I should use the com.sun.star.util.MeasureUnit.APPFONT method (I tried to install MRI extension lots of times but I always get an error); could you please tell me how can I convert from real pixels to appfont units? I mean, if a=15 (real pixels), how can i get b (appfont units) and viceversa? The syntax of convertSizeTo... is still unclear to me, although this code worked.
Sorry about my ignorance, of course you gave me the right answer, but I can't understand it completely yet :oops:

EDIT:
Maybe I got it: this code makes the dialog as tall as the Calc window.

Code: Select all

oDial.Model.Height = frmArchivio.ConvertSizeToLogic(ThisComponent.getCurrentController.getFrame.ContainerWindow.Size, com.sun.star.util.MeasureUnit.APPFONT).Height
Before setting the topic to "SOLVED" I'll wait for your reassurance that I'm not totally wrong.

Re: Maximize a dialog in Calc at runtime (OpenBASIC)

Posted: Wed Sep 21, 2016 4:10 am
by hanya
It seems good.
APP_FONT unit contains both device resolution and zooming by the option. So you need some information to calculate it yourself without these methods. But we can use these methods to convert between pixcel and app_font units.

Re: Maximize a dialog in Calc at runtime (OpenBASIC)

Posted: Wed Sep 21, 2016 10:52 am
by Davte
Thanks a lot :)