SIZE property

All controls, and system control. The System Monitor.

Returns or sets the size and position of the specified control.

Handling layout for scaled forms

One of the main issues with handling scaling is: How do you get and set layout properties like SIZE for a scaled form? What units are used?

There are basically two choices available:

* Use Device Independent Pixels (DIPs): With this method all coordinates are treated as though the form is scaled at 96 DPI with a scale factor of 1. The system is then responsible for mapping them to actual pixels at runtime.

* Use Pixels (PX): With this method the coordinates passed are treated as actual screen pixels regardless of the DPI scale factor.

Using DIPs may seem at first, especially in terms of backwards compatibility with existing code, but it does have some drawbacks:

* Positioning can be imprecise due to integer rounding, and you may sometimes find a case where you need complete accuracy.

* Some properties and events cannot use DIPs at all (mainly those that relate to screen coordinates), thereby leading to the need for some type of dual coordinate system, resulting in added complexity and possible confusion.

So, to keep things simple, OpenInsight operates in Pixel mode by default, which means it keeps a single and accurate coordinate system. Remember, scaling is an "opt-in" system, meaning that none of your existing forms will scale unless you specify otherwise (via the DPISCALING and SCALEFACTOR properties), so you can review your code before enabling it and ensure that you don not encounter any problems.

However, even though the default coordinate system is Pixels we do not want to remove the choice of using DIPs if you prefer, so forms now support a new SCALEUNITS property that allows properties like SIZE to operate in either DIP or Pixel mode.

objectsize = Get_Property(objectname, "SIZE")

existingprop = Set_Property(objectname, "SIZE", newsize)

Values passed in Set_Property:

ValueDescription
newsizex:@FM:y:@FM:w:@FM:h:@fm:v

Values returned by both Get_Property and Set_Property:

ValueDescription
objectsizex:@FM:y:@FM:w:@FM:h[:@fm:v]
existingpropSize and position, when Set_Property was run.

Set_Property values are:

ValueDescription
XOffset from the left side of the window.
YOffset from the top of the window.
WWidth (rightward extension) of the control.
HHeight (downward extension) of the control, where the top of the control is the y position.
VVisible. If set to -1 and the VISIBLE property of the window is false, the window will remain invisible.

Get_Property returns x:@FM:y:@FM:w:@FM:h, where:

ValueDescription
XOffset from the left side of the window.
YOffset from the top of the window.
WWidth (rightward extension) of the control.
HHeight (downward extension) of the control, where the top of the control is the y position.

The SIZE property for SYSTEM returns:

ValueDescription
<1>Screen width.
<2>Screen height.
<3>Maximum window client area width.
<4>Maximum window client area height.

Set_Property sets the size and position of the specified control. Set any of the four arguments to equal 32,768, if you want to ensure that the dimension does not change.

Note: If the control was hidden, applying the SIZE property makes it visible, except when setting the 5th field to -1.

subroutine PlaceDialog(xPos, yPos)

* this subroutine places a dialog on the screen using the
* same information that Popup uses to determine its
* placement;
* xPos and yPos are passed in as:
*   -2     - center of screen
*   -1     - center of window
*   other  - offset to window
*
* assumes @window is the dialog id, which is true if this is
* called from an event, like the CREATE event, of a dialog

declare function   Get_Property
declare subroutine Set_Property

ScreenSize = Get_Property("SYSTEM", "SIZE")
DialogSize = Get_Property(@window, "SIZE")
Parent     = Get_Property(@window, "PARENT")
ParentSize = Get_Property(Parent, "SIZE")

wScreen    = ScreenSize<3>   ;* width of screen
hScreen    = ScreenSize<4>   ;* height of screen
xDialog    = DialogSize<1>   ;* position of dialog
yDialog    = DialogSize<2>   ;* position of dialog
wDialog    = DialogSize<3>   ;* width of dialog
hDialog    = DialogSize<4>   ;* height of dialog
xParent    = ParentSize<1>   ;* position of parent
yParent    = ParentSize<2>   ;* position of parent
wParent    = ParentSize<3>   ;* width of parent
hParent    = ParentSize<4>   ;* height of parent

* calculate position for the dialog begin case
  * center w.r.t. screen
  case xPos = -2 or yPos = -2
    xDialog = (wScreen - wDialog) / 2
    yDialog = (hScreen - hDialog) / 2
  * center w.r.t. parent
  case xPos = -1 or yPos = -1
    xDialog = xParent + (wParent - wDialog) / 2
    yDialog = yParent + (hParent - hDialog) / 2
  * position w.r.t. parent
  case 1
    xDialog = xParent + xPos
    yDialog = yParent + yPos
end case

* make sure that the dialog is on the screen
if xDialog < 0                 then xDialog = 0
if yDialog < 0                 then yDialog = 0
if xDialog + wDialog > wScreen then xDialog = wScreen -
Dialog
if yDialog + hDialog > hScreen then yDialog = hScreen - hDialog
  NewSize = xDialog: @fm: yDialog: @fm: wDialog: @fm: hDialog
  Set_Property(@window, "SIZE", NewSize)

return
  • guides/programming/programmers_reference_manual/size.txt
  • Last modified: 2024/06/19 20:20
  • by 127.0.0.1