2    Copyright (C) 1996 Scott W. Sadler
 
  10       03-Mar-96 1.0; Scott W. Sadler (ssadler@cisco.com)
 
  17 #include <X11/StringDefs.h>
 
  18 #include "XsOutline.h"
 
  22 XsOutline::XsOutline (Widget w)
 
  30 // Get window dimensions
 
  32    unsigned int moreJunk;
 
  36    XGetGeometry (XtDisplay (_w), XtWindow (_w), &junk, &_x, &_y, &uw, &uh, &moreJunk, &moreJunk);
 
  41 // Get initial settings
 
  45    _savedH = _savedW = 0;
 
  47 // Create the graphics context
 
  50    unsigned long valuemask;
 
  52    Display *dpy = XtDisplay (_w);
 
  54    valuemask = GCFunction | GCLineWidth | GCSubwindowMode;
 
  55    values.function = GXinvert;
 
  56    values.line_width = 0;
 
  57    values.subwindow_mode = IncludeInferiors;
 
  59    _gc = XCreateGC (dpy, XtWindow (_w), valuemask, &values);
 
  64 XsOutline::~XsOutline ( )
 
  66    XFreeGC (XtDisplay (_w), _gc);
 
  71 Boolean XsOutline::go (Boolean drawInitial)
 
  73    XtAppContext appContext = XtWidgetToApplicationContext (_w);
 
  79    if (_grabPointer ( ) == False)
 
  82 // Draw the initial box (if requested)
 
  87 // Process the events locally
 
  91       XtAppNextEvent (appContext, &event);
 
  98 // Clear the outline and break
 
 108 // Process only the last motion event
 
 110             while (XPending (XtDisplay (_w)) > 0)
 
 112                XPeekEvent (XtDisplay (_w), &next);
 
 113                if (next.type != MotionNotify)
 
 115                XtAppNextEvent (appContext, &event);
 
 120             _motionHandler (&event);
 
 126             XtDispatchEvent (&event);
 
 132 // Ungrab the pointer
 
 141 void XsOutline::_drawOutline (Boolean clear)
 
 144 // Clear the current outline
 
 146    if (_savedH || _savedW)
 
 147       _drawIt (_savedX, _savedY, _savedW, _savedH);
 
 149 // Save current values
 
 151    _savedX = _x; _savedY = _y;
 
 152    _savedW = _width; _savedH = _height;
 
 154 // Draw the new outline (unless flagged to just clear)
 
 157       _drawIt (_x, _y, _width, _height);      
 
 162 Cursor XsOutline::_getCursor ( ) const
 
 169 Boolean XsOutline::_grabPointer ( )
 
 172 // Sync everything up before being grabby
 
 174    XSync (XtDisplay (_w), False);   
 
 178    if (XGrabPointer (XtDisplay (_w), XtWindow (_w), False, GrabEventMask, 
 
 179       GrabModeAsync, GrabModeAsync, XtWindow (XtParent (_w)), _getCursor ( ), 
 
 180       CurrentTime) != GrabSuccess)
 
 182       XBell (XtDisplay (_w), 100);
 
 191 void XsOutline::_ungrabPointer ( )
 
 194 // Ungrab the pointer
 
 196    XUngrabPointer (XtDisplay (_w), CurrentTime);
 
 201 void XsOutline::_drawIt (int x, int y, int w, int h)
 
 204    XSegment    segs[nsegs];
 
 208    segs[0].x1 = x; segs[0].y1 = y;
 
 209    segs[0].x2 = x + w - 1; segs[0].y2 = y;
 
 211    segs[1].x1 = x + BorderSize; segs[1].y1 = y + BorderSize;
 
 212    segs[1].x2 = x + w - BorderSize - 1; segs[1].y2 = y + BorderSize;
 
 216    segs[2].x1 = x + w - 1; segs[2].y1 = y + 1;
 
 217    segs[2].x2 = x + w - 1; segs[2].y2 = y + h - 1;
 
 219    segs[3].x1 = x + w - BorderSize - 1; segs[3].y1 = y + BorderSize + 1;
 
 220    segs[3].x2 = x + w - BorderSize - 1; segs[3].y2 = y + h - BorderSize - 1;
 
 224    segs[4].x1 = x + 1; segs[4].y1 = y + h - 1;
 
 225    segs[4].x2 = x + w - 2; segs[4].y2 = y + h - 1;
 
 227    segs[5].x1 = x + BorderSize + 1; segs[5].y1 = y + h - BorderSize - 1;
 
 228    segs[5].x2 = x + w - BorderSize - 2; segs[5].y2 = y + h - BorderSize - 1;
 
 232    segs[6].x1 = x; segs[6].y1 = y + h - 1;
 
 233    segs[6].x2 = x; segs[6].y2 = y + 1;
 
 235    segs[7].x1 = x + BorderSize; segs[7].y1 = y + h - BorderSize - 1;
 
 236    segs[7].x2 = x + BorderSize; segs[7].y2 = y + BorderSize + 1;
 
 240    XDrawSegments (XtDisplay (_w), XtWindow (XtParent (_w)), _gc, segs, nsegs);