Skip to content

Specialized DPI aware management

António Lopes edited this page Mar 10, 2023 · 5 revisions

Specialized DPI-aware management

The DPI-aware manager may grant the application forms or any of their objects full or partial control of the management process.

Besides not processing an object when it is required due to changes in the display environment when the object sets its property DPIAware = .F., the manager may give the object the opportunity of preparing or react to the changes in a specialized manner.

The DPIAwareSelfControl property

As the manager processes the object tree, it queries the presence of the DPIAwareSelfControl property at every control. If it is not present, the manager continues the process in full.

When DPIAwareSelfControl = 1, the manager calls a method of the object named DPIAwareSaveOriginalInfo(), while preparing the management, and the DPIAwareSelfManager() method, passing the values of the current and future values of the DPI scale, while reacting to a text scale change. For instance, the equivalent of m.obj.DPIAwareSelfManager(100, 150). The methods must have been defined at some point in the subclassing hierarchy of the control.

When DPIAwareSelfControl = 2, the manager calls a method of the form containing the object named DPIAwareSaveOriginalInfo(), passing a reference to the object, while preparing the management, and the DPIAwareControlsManager() method, passing the values of the current and future values of the DPI scale, and a reference to the object, while reacting to a text scale change. For instance, the equivalent of m.frm.DPIAwareControlsManager(100, 150, m.obj). The methods must be defined in the form, and as it happens with VFP forms this does not require an explicit subclassing.

When DPIAwareSelfControl = 3, the manager calls a method of a specialized _Screen object named DPIAwareScreenManager.DPIAwareSaveOriginalInfo(), passing a reference to the object, while preparing the management, and the DPIAwareScreenManager.DPIAwareControlsManager() method, passing the values of the current and future values of the DPI scale, and a reference to the object. For instance, the equivalent of _Screen.DPIAwareScreenManager.DPIAwareControlsManager(100, 150, m.obj). The DPIAwareScreenManager object instantiates the DPIAwareScreenManager class, defined in the same program file as the DPI-aware manager.

In any case, when the methods return .T. the manager continues to process the object and its contained objects if it is a container.

If the methods return .F., the manager will stop the management process for the object and its sub-controls.

Example

In the example form of the testing project, the lblhWnd label initializes by declaring to the manager that it's self-controlled:

* the form manages the DPI awareness of this label
This.AddProperty("DPIAwareSelfControl", 2)

The form defines the following DPIAwareControlsManager method:

LPARAMETERS DPIScale AS Integer, DPINewScale AS Integer, Ctrl AS Object

DO CASE

CASE m.Ctrl = This.Label1

	IF m.DPINewScale = 100
		This.Label1.ResetToDefault("ForeColor")
		This.Label1.FontBold = .F.
	ELSE
		This.Label1.ForeColor = RGB(255,128,0)
		This.Label1.FontBold = .T.
	ENDIF

ENDCASE

RETURN .T.

When the form is displayed on a monitor with a scale not equal to 100%, the label will be rendered in bold and orange. Since the method returns .T., the manager will continue the processing of the label, which means that it will be scaled up or down, depending on the current and future scales.

The DPI awareness environment

The manager provides information to the managed _Screen and forms regarding the current and new DPI conditions.

The following properties are added to each managed form if they are not defined already:

DPIAware = .T.
DPIAwareManager = <a reference to the manager>
DPIScale = <the current monitor scale>
DPINewScale = m.frm.DPIScale
DPIAutoConstraint = <automatic constraints applied to the position or dimension>
DPIScaling = <indicates if the manager is scaling a form>
hMonitor = <the monitor handle on which the form is displayed>

When the DPI conditions change, the scales and the monitor handle will reflect what has been altered. This gives the forms and the application, via its _Screen, an opportunity to evaluate the conditions of the environment and act accordingly.

Example

The Here.com location platform provides map imagery in different resolutions. When requesting an image from the platform, a VFP application running as a DPI-aware application may query the manager for the rendering conditions and choose the most appropriate resolution:

a) an image requested by a VFP application at the Here.com standard resolution of 72 DPI:

Rendered map @ 72 DPI

b) the same map and route requested by a VFP application at the Here.com higher resolution of 320 DPI:

Rendered map @ 320 DPI