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

Keyboard macros or custom scripts

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

Postby Davte » Mon Sep 19, 2016 4:40 pm

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   Expand viewCollapse view
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   Expand viewCollapse view
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   Expand viewCollapse view
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
Last edited by Davte on Wed Sep 21, 2016 10:52 am, edited 1 time in total.
OpenOffice 4.1.2 on Windows 10
Davte
 
Posts: 16
Joined: Sat Sep 10, 2016 11:29 pm
Location: Italy

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

Postby hanya » Tue Sep 20, 2016 5:03 pm

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   Expand viewCollapse view
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.
Please, edit this thread's initial post and add "[Solved]" to the subject line if your problem has been solved.
Apache OpenOffice 4-dev on Xubuntu 14.04
hanya
Volunteer
 
Posts: 885
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan

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

Postby Davte » Tue Sep 20, 2016 5:47 pm

Thank you a lot, in fact I can get the two coefficients I had empirically found by the following operations:
Code: Select all   Expand viewCollapse view
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   Expand viewCollapse view
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   Expand viewCollapse view
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.
OpenOffice 4.1.2 on Windows 10
Davte
 
Posts: 16
Joined: Sat Sep 10, 2016 11:29 pm
Location: Italy

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

Postby hanya » Wed Sep 21, 2016 4:10 am

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.
Please, edit this thread's initial post and add "[Solved]" to the subject line if your problem has been solved.
Apache OpenOffice 4-dev on Xubuntu 14.04
hanya
Volunteer
 
Posts: 885
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan

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

Postby Davte » Wed Sep 21, 2016 10:52 am

Thanks a lot :)
OpenOffice 4.1.2 on Windows 10
Davte
 
Posts: 16
Joined: Sat Sep 10, 2016 11:29 pm
Location: Italy


Return to OpenOffice Basic, Python, BeanShell, JavaScript

Who is online

Users browsing this forum: Google Feedfetcher and 6 guests