GenView: 2.3 Getting Started: View Basics: Handling View Messages

Up: GEOS SDK TechDocs | Up | Prev: 2.2 Defining the Basic View | Next: 3 Basic View Attributes

After defining the GenView, you must create the method that will handle MSG_META_EXPOSED sent by the view in order to draw in the view's window. This is absolutely necessary, even if your view is not scrollable; the view will send MSG_META_EXPOSED when any part of its display window becomes invalid--this includes when the view is first instantiated and its window is first displayed.

In this simple model, MSG_META_EXPOSED is the only message your application will need to handle relating to the view. If you are managing large documents, then you may also have to handle a few others pertaining primarily to input. A sample handler for MSG_META_EXPOSED --one you can modify and put in your own code--is shown in MSG_META_EXPOSED Handler .

If you are planning on displaying visible objects in the view (as opposed to having your Process object draw graphics), you should instead pay attention to MSG_VIS_DRAW . This message is defined by VisClass and is sent by a VisContent object to itself as the default behavior for MSG_META_EXPOSED . For full information on MSG_VIS_DRAW and visible objects, see the VisClass chapter.

Code Display 9-2 MSG_META_EXPOSED Handler

/* Each time some part of the view window becomes invalid, the view will send a
 * MSG_META_EXPOSED to its content object. When MSG_META_EXPOSED is received,
 * the content must draw the document to a newly-created GState, then pass the
 * GState to the windowing system for drawing to the screen. */
/* The format of this message is
 * 	void MSG_META_EXPOSED(WindowHandle win);
 * The passed value is the window handle of the view window; it will be used in
 * conjunction with the temporary GState for drawing. */
@method	MyProcessClass, MSG_META_EXPOSED {
    /* Set up a temporary GState handle variable for our document. */
    GStateHandle tempGState;
    /* Initialize the GState to the default. */
    tempGState = GrCreateState(win);
    /* Now start a window update. The routine GrBeginUpdate() notifies the window
     * system that we are in the process of drawing in the region in the window
     * that was invalidated. GrBeginUpdate() allows drawing to be clipped to only
     * the region that was invalidated. */
    GrBeginUpdate(tempGState);
    /* Now that we have a GState and have notified the windowing system that we
     * intend to draw, we can draw our document. Here, your method should call
     * whatever routines are appropriate for drawing the entire document.
     * A good hint here relates also to printing: Because printing and drawing to a
     * view are essentially the same operation, you might want to consolidate all
     * your drawing into a single routine that is called by both this method and
     * your printing method. This is what is done here; the routine called
     * MyDrawingRoutine() draws the document we wish displayed. MyDrawingRoutine()
     * will also be called by our printing method with a different GState. */
    MyDrawingRoutine(tempGState);
    /* Now that we have finished drawing the document, we must inform the window
     * system that we are done. Additionally, we must now destroy the temporary
     * GState we used to draw the document. This is essential as not destroying
     * gstates causes small locked blocks to remain on the heap, eroding system
     * performance quickly and eventually making the system run out of handles. */
    GrEndUpdate(tempGState);
    GrDestroyState(tempGState);
}

Up: GEOS SDK TechDocs | Up | Prev: 2.2 Defining the Basic View | Next: 3 Basic View Attributes