Example 5-2. Repainting objects within a damaged region (continued)
XChangeGC(display, gc, GCClipMask, &gc_val);
XDrawLine(display, xwin, gc, 0, 0, width, height);
Because this routine sets the clip mask of the GC, we want to be sure that we do not use the
default GC of the screen as we did in Example 5-2 or it will interfere with other programs
(such as the window manager). The GC shown here is declared as extern, assuming that
the application has created it somewhere else using XCreateGC().
5.4 Controlling Canvas Sizes
The size of the canvas subwindow is usually determined by the frame window. Thus, the
canvas changes as the user resizes the frame. Applications largely concern themselves with
the size of the paint window.* The paint window does not affect the size of the viewable
canvas, but the viewable portion of the paint window is important.
Although the width and height of the canvas subwindow can be set explicitly, unless done so,
the default size of the subwindow and the paint window is determined by the parent frame. If
the frame resizes, the canvas object resizes proportionally according to how the frame
chooses to resize the canvas. If several other windows (canvases, panels, whatever) are in
the frame, the frame might choose to lay out and size those subwindows differently (accord-
ing to available and required space from other windows). The canvas window itself, as well
as all window objects, can be sized using
XV_WIDTH and XV_HEIGHT.
5.4.1 Automatic Canvas Sizing
The paint window’s size may ﬂuctuate with that of the canvas subwindow’s size. The attri-
butes CANVAS_AUTO_EXPAND and CANVAS_AUTO_SHRINK maintain the relation of the canvas
subwindow and paint window in the event of any kind of window resizing. Both of these
attributes default to TRUE, allowing the paint window to always correspond to the size of the
canvas subwindow. If the canvas subwindow becomes larger, the paint window size changes
to that size. If the frame changes size, the canvas subwindow changes size and so does the
paint window. This happens regardless of how many view windows there are. The size of
view windows does not affect the size of the paint window.
CANVAS_AUTO_EXPAND is TRUE, then the width and height of the paint win-
dow cannot be less than that of the canvas subwindow. Setting the attribute
CANVAS_AUTO_EXPAND allows the paint window to grow bigger as the user stretches the win-
dow. If a resize of the subwindow occurs such that the size of the paint window is less than
the size of the canvas subwindow, the paint window is expanded to be at least that size.
*There may be more than one paint window to a canvas; but all paint windows in a canvas are the same size, so it’s a
98 XView Programming Manual