GenView: 4.5 Advanced Concepts and Uses: Document Scaling

Up: GEOS SDK TechDocs | Up | Prev: 4.4 Document and View Size | Next: 4.6 Children of the View
GVI_scaleFactor, MSG_GEN_VIEW_GET_SCALE_FACTOR, MSG_GEN_VIEW_SET_SCALE_FACTOR, MSG_GEN_VIEW_SCALE_LOW, ATTR_GEN_VIEW_PAGE_SIZE, ATTR_GEN_VIEW_SCALE_TO_FIT_BASED_ON_X, ATTR_GEN_VIEW_SCALE_TO_FIT_BOTH_DIMENSIONS

Many applications implement scaling to allow users to view and modify their documents at various scale factors. This scaling behavior, apart from the implementation of the view menu, is almost entirely internal to the view. The application simply needs to instruct the view in what scale factor to use; the view will provide the proper geometry and math involved in displaying, scrolling, and resizing your document.

Every view has a scale factor stored as a PointWWFixed structure in the GVI_scaleFactor instance field. The default scale factor is one, or 100 percent. A scale factor of two means that your document will appear twice as large to the user (200 percent normal size). You can set the scale factor in your Goc code and change it with MSG_GEN_VIEW_SET_SCALE_FACTOR .

The PointWWFixed structure contains two fields, each of which is a WWFixed structure. Both WWFixed and PointWWFixed are shown below.

    typedef struct {
	word		WWF_frac;		/* 16 bits decimal */
	word		WWF_int;		/* 16 bits integral */
} WWFixed;
typedef struct {
	WWFixed		PF_x;		/* x scale factor */
	WWFixed		PF_y;		/* y scale factor */
} PointWWFixed;

A scale factor of 2.5 (250%) in both dimensions would be declared as follows:

GVI_scaleFactor = {{5, 2}, {5, 2}};

A scale factor of 100% in the horizontal and 250% in the vertical would be declared as follows:

GVI_scaleFactor = {{0, 1}, {5, 2}};

To change the scale factor at run-time (for example, when a user clicks on a Zoom button), send MSG_GEN_VIEW_SET_SCALE_FACTOR to the view, passing the proper scale factors. Additionally, you may choose a point on the screen around which to scale. You may also retrieve the current scale factor of a view with the message MSG_GEN_VIEW_GET_SCALE_FACTOR . Note that the GenViewControl has many interactive scaling and zoom features and tools available.

Another way to ensure a certain point is on the screen after scaling is to force it there by causing the view to scroll after scaling. You can suspend the window update, scale the view, then cause the view to scroll with a MSG_GEN_VIEW_MAKE_RECT_VISIBLE . When you then unsuspend the window update, the view will draw with the proper point in the proper place. See Scrolling for an in-depth discussion of scrolling the view.

In addition to the dynamic scaling described above, you can have your view scale itself automatically to fit the entire document in its window. To do so, set the GVI_attrs flag GVA_SCALE_TO_FIT. This will cause the view to scale itself so the entire document fits vertically in the view; the horizontal scale factor will change to correspond with the new vertical scale factor. You can alter this behavior with three different vardata attributes:

ATTR_GEN_VIEW_PAGE_SIZE
This attribute takes an argument of type XYSize (shown below). The view will scale itself to fit this page size rather than its entire document size.
  typedef struct {
    word		XYS_width;		/* width of page */
    word		XYS_height;		/* height of page */
} XYSize;
ATTR_GEN_VIEW_SCALE_TO_FIT_BASED_ON_X
This attribute causes the view to scale itself based on the horizontal size rather than the vertical size. The vertical scale factor will follow the horizontal scale factor.
ATTR_GEN_VIEW_SCALE_TO_FIT_BOTH_DIMENSIONS
This attribute causes the view to scale both dimensions independently when scaling to fit. The horizontal and vertical scale factors may end up different.

MSG_GEN_VIEW_SET_SCALE_FACTOR

void	MSG_GEN_VIEW_SET_SCALE_FACTOR(@stack
        sdword	yOrigin,			/* New Y origin coordinate after scaling */
        sdword	xOrigin,			/* New X origin coordinate after scaling */
        ScaleViewType scaleType,				/* Determines Positioning after scaling */
        WWFixedAsDWord yScaleFactor,						/* New scale factor on Y axis */
        WWFixedAsDWord xScaleFactor);						/* New scale factor on X axis */

This message changes the view's scale factor, causing it to redraw at the new scale. The view will continue to display your document at the new scale until it is either shut down or instructed to change the scale factor again.

Source: Unrestricted.

Destination: Any GenView object.

Parameters: yOrigin New vertical origin of the view window after scaling, if SVT_AROUND_POINT is passed in scaleType . Ignored otherwise.

xOrigin
New horizontal origin of the view window after scaling, if SVT_AROUND_POINT is passed in scaleType . Ignored otherwise.
scaleType
A value of ScaleViewType indicating how the view is to react after scaling. The three allowable values are described below, under "Structures."
yScaleFactor
The new vertical scale factor. To create a WWFixedAsDWord structure, use the macro MakeWWFixed() .
xScaleFactor
The new horizontal scale factor. To create a WWFixedAsDWord structure, use the macro MakeWWFixed() .

Return: Nothing.

Interception: Generally not intercepted. If you want to alter scaling behavior, you may intercept this message to change the parameters. Be sure to call the superclass at the end of the handler.

Structures: The type ScaleViewType defines the way the view will be scaled. It is an enumerated type with three possible values:

SVT_AROUND_UPPER_LEFT
Scale the view around the upper-left corner, and keep the origin the same before and after scaling. The xOrigin and yOrigin parameters will be ignored.
SVT_AROUND_CENTER
Scale the view around its center, keeping the point that is central in the view before scaling in the center after scaling. The xOrigin and yOrigin parameters will be ignored.
SVT_AROUND_POINT
Scale the view around the document point whose coordinates are provided in yOrigin and xOrigin , making sure the new coordinates are set as the view's new origin.

MSG_GEN_VIEW_GET_SCALE_FACTOR

void	MSG_GEN_VIEW_GET_SCALE_FACTOR(
        GetScaleParams *retValue);

This message returns the current scale factors of the view.

Source: Unrestricted.

Destination: Any GenView object.

Parameters: retValue A pointer to an empty GetScaleParams structure to be filled in by the method.

Return: The structure pointed to by retValue will be filled with the current scale factor of the view.

Interception: Generally not intercepted.

Structures: The GetScaleParams structure is made up of two WWFixedAsDWord values. The high word of each represents the fractional (decimal) portion of the scale factor, and the low word represents the integral portion. The GetScaleParams structure definition is shown below:

typedef struct {
	WWFixedAsDWord			GSP_yScaleFactor;			/* y */
	WWFixedAsDWord			GSP_xScaleFactor;			/* x */
} GetScaleParams;

MSG_GEN_VIEW_SCALE_LOW

void	MSG_GEN_VIEW_SCALE_LOW(@stack
        sdword		yOrigin,
        sdword		xOrigin,
        ScaleViewType		scaleType,
        WWFixedAsDWord		yScaleFactor,
        WWFixedAsDWord		xScaleFactor);

This low-level message is similar to MSG_GEN_VIEW_SET_SCALE_FACTOR except that it does not propagate to linked views. It is generally encapsulated by the GenView when another scaling message is received, then dispatched to linked views later.

Source: Sent by the GenView to itself.

Destination: Any GenView object.

Parameters: See MSG_GEN_VIEW_SET_SET_SCALE_FACTOR .

Return: Nothing.

Interception: Should not be intercepted.


Up: GEOS SDK TechDocs | Up | Prev: 4.4 Document and View Size | Next: 4.6 Children of the View