Objective Toolkit : Chapter 18 View Classes : Using the View Classes
Using the View Classes
Because the Objective Toolkit zooming and panning classes are based on the MFC document/view paradigm, you first need to make sure that your application is using a CScrollView. If not, we suggest you generate a new project using the VisualC++ | MFC AppWizard and use the generated code to add document/views to your application.
Because SECPanView is derived from SECZoomView, it also supports zooming. With this hierarchy, use SECZoomView only if you want zooming and use SECPanView if you want zooming and panning. If you want panning only, use SECPanView with zooming turned off.
NOTE >> SECZoomView and SECPanView work correctly only if the MM_ANISOTROPIC mapping mode is set. SECZoomView sets the mapping mode to MM_ANISOTRPIC in its override of OnPrepareDC(). Any attempt to change the GDI mapping mode in the application impacts the rendering.
The following section describes how to add zooming support to your MFC applications. If you want to add both panning and zooming, see “To incorporate panning support into an application.”
To incorporate zooming support into an application
1. Derive your view class from SECZoomView instead of CScrollView. For example:
 
class CMyScrollView : public SECZoomView
2. Change the inheritance specified in the IMPLEMENT_DYNCREATE() and BEGIN_MESSAGE_MAP macros.
3. In your view constructor, call SetZoomMode() to set either SEC_ZOOMNORMAL or SEC_ZOOMFIT.
4. Add a zooming user interface to your application that calls the SECZoomView zooming functions, such as ZoomPercent(), ZoomIn() and ZoomOut().
5. If you want to display a zoom value, override SECZoomView::ZoomLevelChanged().
NOTE >> SECZoomView requires the MM_ANISOTROPIC mapping mode. It sets this mode in its OnPrepareDC() method. If you set a different mapping mode, problems may occur.
To incorporate panning support into an application
1. Derive your view class from SECPanView instead of CScrollView. For example:
 
class CMyScrollView : public SECPanView
2. Change the inheritance specified in the IMPLEMENT_DYNCREATE()andBEGIN_MESSAGE_MAP macros.
3. If you want to have both panning and zooming support, in your view constructor add a call to SetZoomMode() with either SEC_ZOOMNORMAL or SEC_ZOOMFIT.
If you only want to add panning support, do not call SetZoomMode(). The default zoom mode is SEC_ZOOMOFF. When this mode is set, SECPanView performs no zooming. You can call SetPanMode() to change the panning mode from the default (SEC_PANDELAY) to SEC_PANINSTANT.
4. Add the panning and zooming user interface. To enable panning, call StartPan() with the current starting point. To continue panning in pan instant mode, call ContinuePan() with the current panning point. When the user is done panning, call EndPan().
To incorporate a panning overview window to an application
1. Call ShowOverviewWnd() with a rectangle specifying the size of the overview window.
2. Because SECPanWnd is not a CView derivative, call SECPanView::UpdateOverviewWnd() whenever you call CView::UpdateAllViews().
3. Provide an SECPanView::OnUpdateOverview() routine that is similar to your CView::OnUpdate() override. The last argument to this function is a pointer to the overview window that you can use to call CWnd routines for drawing update logic.
NOTE >> Like print preview, the panning overview window only works with one view. If you have several views for which you want to have overview windows, you need to create an SECPanWnd derivative and implement a custom solution for your specific situation.
Key Zooming Methods
Here’s a quick reference to some of the key SECZoomView methods. For more information, refer to the Objective Toolkit Class Reference.
Table 47 – Key Methods for SECZoomView 
Zooming method
Description
GetZoomLevel()
Retrieves the current zoom level.
GetZoomMode()
Retrieves the current zoom mode.
SetZoomLevel()
Sets the current zoom level.
SetZoomMode()
Sets the zoom mode.
ZoomFit()
Prompts the view to zoom to the size of the client window.
ZoomIn()
Increases the zoom level. This method is overloaded to accept either a rectangle or a point parameter. The ZoomIn() overload that accepts a rectangle parameter zooms the view to fit in the rectangle. The overload that accepts a point uses the point as the center of the zoom-in operation.
ZoomLevelChanged()
Override this member to detect when the zoom level has changed. This is useful for keeping a displayed zoom level up-to-date.
ZoomOriginal()
Zooms the view to the original size (100%).
ZoomOut()
Decreases the zoom level. This method is overloaded to accept either a rectangle or a point parameter.
ZoomOutOfRange()
Specifies a floor and a ceiling to restrict the zoom level. The defaults for the floor and ceiling are the maximum allowed that does not let the zoom level wrap.
ZoomPercent()
Zooms the view by a percent instead of a floating-point zoom level—for example, 50 = 50%.
 
Key Panning Methods
The following table provides descriptions of SECPanView’s key methods.
Table 48 – Key Methods for SECPanView 
Panning mode methods
Description
GetPanMode()
Retrieves the pan mode.
SetPanMode()
Sets the pan mode.
StartPan()
Starts panning. Takes a point that is used to calculate the amount of panning.
ContinuePan()
Usually called while moving the mouse to cause the view to update in pan instant mode. Takes a point which is compared to the point passed to StartPan() in order to calculate an amount to pan.
EndPan()
Call EndPan() when panning is over. The view will pan if the pan mode is pan delay. If pan instant mode is active, the view will pan, but only the amount specified since the last call to ContinuePan().
IsPanning()
You can call IsPanning() at any time to determine if the view is between a StartPan()/EndPan() sequence. For example, you could use this if you wanted your view’s OnDraw() to behave differently during panning.
Table 49 – Key Methods for the Overview Window 
Overview window methods
Description
ShowOverviewWnd()
Displays the overview window.
HideOverviewWnd()
Hides the overview window.
UpdateOverviewWnd()
Call to update the overview window. This member function is usually called near calls to CView::UpdateAllViews().
IsOverviewShown()
Call to determine if the overview window is visible.