Programming Guide: FocusLib Utility

# Programming Guide

## FocusLib Utility

FocusLib is a samples utility library that assists in setting up the native drawing context for the following:

- To a window (for OS/2, Windows, and AIX platforms).
- To a printer (for OS/2 and Windows platforms).
- To a metafile (for Windows platforms).

A unique version of FocusLib.cpp and FocusLib.h exists for the OS/2, AIX, Windows platforms. The external interfaces to the FocusLib functions are similiar on all three platforms but the internal implementation of the FocusLib functions differs on the various platforms. The FocusLib utility is written to set up and return the following:

- A handle to presentation space (HPS), on the OS/2 platform.
- A handle to device context (HDC), on the Windows platform
- An X-Windows graphics context (GC), on the AIX platform.

If you use any other graphics libraries, such as OpenGL, you may have to implement your own version of FocusLib for that graphics library. In this case, you should use the provided FocusLib utilities as an example of the steps necessary to set up the drawing context properly.

The example FocusLib utility sets up the clipping region and the window/viewport transformations for the returned device context. Use the FocusLib utility by calling its constructor, CFocus, passing it the facet, and optionally passing it a shape in which to draw. Declaring the CFocus object sets up the drawing context and stores the old state in the CFocus object itself (on the stack.) When its scope exits, the CFocus object's destructor is called, which restores the old state.

The following lists the FocusLib constructors available to sample parts on the various platforms.

### OS/2 Platform

      CFocus::CFocus(ODFacet *facet, ODShape* invalShape, HPS *theHPS )
      CFocus::CFocus(ODFacet *facet, ODShape* invalShape, HPS *theHPS,
                     HRGN *theClipRgn)

CFocus example for the OS/2 platform:

    void DrawSomething( ODFacet *facet , ODShape *invalidShape)
    {
    #ifdef _PLATFORM_OS2_
    HPS hps;
    CFocus focus(facet, invalidShape, &hps);    // Creates a CFocus object on the
                                                // stack, which changes the focus
                                                // but stores the old state
    ...drawing code...(uses returned hps)...
    #endif
    }

### Windows Platform

      CFocus::CFocus( ODFacet *facet, ODShape* invalShape, HDC *theHDC )

CFocus example for the Windows platform:

    void DrawSomething( ODFacet *facet , ODShape *invalidShape)
    {
    #ifdef _PLATFORM_WIN32_
    HDC hdc;
    CFocus focus(facet, invalidShape, &hdc);    // Creates a CFocus object on the
                                                // stack, which changes the focus
                                                // but stores the old state
    ...drawing code...(uses returned hdc)...
    #endif
    }

### AIX Platform

      CFocus::CFocus( ODFacet *facet, ODShape* invalShape, GC *theGC )

CFocus example for the AIX platform:

    void DrawSomething( ODFacet *facet , ODShape *invalidShape)
    {
    #ifdef _PLATFORM_UNIX_
    GC gc;
    CFocus focus(facet, invalidShape, &gc);     // Creates a CFocus object on the
                                                // stack, which changes the focus
                                                // but stores the old state
    ...drawing code...(uses returned gc)...
    #endif
    }

[ Top | Previous | Next | Contents | Index | Documentation Homepage ]