Canvases are inherently platform-specific. OpenDoc canvas objects are basically wrappers for structures that differ across platforms. This section discusses how to use canvas objects regardless of the platform for which you are developing.
The class ODCanvas is OpenDoc's wrapper for a platform-specific (or graphics-system-specific) object that represents a drawing environment. A drawing canvas can refer to anything from a bit map or a structured display list to a stream of PostScript code. It represents the destination for drawing commands, the environment for constructing a rendered image; it has a coordinate system and may retain state information (such as pen color) that influences how drawing commands are interpreted.
A canvas object holds a reference to a system-specific object called a platform canvas, and that object is not deleted when the canvas is released. If you create a canvas, you must create the platform canvas separately, and you are responsible for deleting it when the canvas is deleted.
The platform canvas is a SOM class which you create using the ODFacet method CreatePlatformCanvas. An onscreen dynamic canvas is created for every facet for which the parent facet has an onscreen dynamic canvas.
The platform canvas, ODPlatformCanvas, is a platform-independent SOM base class for other objects which wrap the platform-specific drawing context. The methods of ODPlatformCanvas provide generic information about the type of subclass. You can use these methods to determine how to downcast a pointer to an ODPlatformCanvas into the platform canvas object appropriate for that platform. For instance, on the Windows platform, once you have a pointer to an ODPlatformCanvas object you can use GetSystemType and GetPlatformCanvasType to determine whether to downcast to ODWin32StandardCanvas or to ODWin32WindowCanvas. You must downcast to call methods which allow access to the device context (DC), such as GetDC and ReleaseDC. You can also downcast to their parent class, ODWin32Canvas, since they all have exactly the same methods.
On each platform, the unique platform canvas subclasses expose the drawing context and other related information in a platform-specific manner.
There are two types of platform canvases, standard and window. The difference between the two is simply whether the drawing context is associated with a window or not. A standard platform canvas is typically used when drawing offscreen and is initialized directly with a platform-specific drawing context. A window platform canvas is used when drawing onscreen and is initialized with a reference to the window associated with the drawing context. In other words, the drawing context is inferred by the window itself. A window platform canvas is created for you by CreateEmbeddedFacet of ODFacet when you specify kODNULL for the canvas parameter. There are very few instances when you will need to create a window platform canvas yourself.
You can create platform canvases several ways. One method is to use the CreateConcreteCanvas method of the ODPlatformCanvas class or one of the platform-specific base classes such as ODWin32Canvas on the Windows platform. When you use this method you must downcast the pointer of the new ODPlatformCanvas to one of its subclasses and call the appropriate initialization method. Use the InitPlatformCanvas method to initialize a standard platform canvas, while the InitPlatformWindowCanvas methods to initialize a window platform canvas. You can also create a standard platform canvas by using the ODFacet method CreatePlatformCanvas and passing a platform-specific drawing context.
Canvases can be dynamic or static, meaning that they are used for video display or printing display, respectively. Your part editor can determine whether it is drawing to a static or dynamic canvas and can adjust its procedures accordingly.
Canvases can be onscreen or offscreen. Your part editor can create special effects or improve performance by drawing a complex image to an offscreen cache and then quickly transferring the completed image to the screen. For added convenience, offscreen canvases maintain clipping and updating information that mirrors their onscreen equivalents.
Canvases are attached to individual facets. In Figure 26, for example, which shows the same document with the same facet hierarchy as in Figure 23, the document has two attached canvases:
Figure 26. Facets and Canvases
If a particular facet in a window's facet hierarchy has an attached canvas, all of its embedded facets (and their embedded facets, and so on) draw to that canvas. In Figure 26, for example, any drawing done to the text facet uses text canvas, draw facet uses draw canvas, and clock facet uses clock canvas.
OpenDoc creates an onscreen dynamic canvas for every facet for which the parent facet has an onscreen dynamic canvas. However, if a particular part needs an offscreen canvas, for itself or for an embedded part, it can attach a canvas to a facet anywhere within the hierarchy. Any drawing done to the movie facet in Figure 26, for example, is rendered on the offscreen canvas.
For each platform, a window canvas consists of a platform-specific window heirarchy that parallels the facet hierarchy. On the OS/2 platform, there is a Presentation Manager (PM) window for each facet in the window canvas. Similarly, on Windows and AIX, sibling windows are created for each facet in the window canvas.
Every canvas has an owner, a part that is responsible for transferring images drawn on its canvas to the parent of that canvas. In Figure 26, for example, the movie images drawn to the offscreen canvas must be transferred to the window canvas in order to be viewed onscreen. The owner decides when and how to transfer images from a canvas to its parent. The owner of the offscreen canvas in Figure 26 might be the movie part or the text part that contains the movie part.
This section describes how to create and delete canvases for your parts. For specific information on using canvases for offscreen drawing, see "Offscreen Drawing". If you want to create a canvas and attach it to a facet, take these steps:
To remove a canvas from a facet, take these steps: