home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / windows / x / motif / 5697 < prev    next >
Encoding:
Text File  |  1992-08-19  |  6.0 KB  |  186 lines

  1. Path: sparky!uunet!charon.amdahl.com!pacbell.com!mips!sdd.hp.com!hplabs!ucbvax!FEDEX.MSFC.NASA.GOV!patrick%ess2.span
  2. From: patrick%ess2.span@FEDEX.MSFC.NASA.GOV (Patrick E. Meyer (205)544-2265)
  3. Newsgroups: comp.windows.x.motif
  4. Subject: Help!: Double Click and Rubberbanding
  5. Message-ID: <920819101906.d15@Fedex.Msfc.Nasa.Gov>
  6. Date: 19 Aug 92 15:19:06 GMT
  7. Sender: usenet@ucbvax.BERKELEY.EDU
  8. Lines: 176
  9.  
  10. I have two of what I believe should be simple questions.
  11.  
  12. 1) The easiest first:  The Selection Box widget has a XmNdefaultCallback which
  13.    is activated via double clicking MB1 on your selection. I would like to add a
  14.    double click callback to a Drawing Area widget.  What are my options:
  15.       a. Do I add a translation -, if so what <Btn1Dn>,<Btn1up>,<Btn1Dn>,
  16.          <Btn1Up>?
  17.       b. Do I create a callback that checks the time between clicks using
  18.          the XmNinputCallback -
  19.          I would like to use the mwm's defined double click rate.
  20.  
  21. 2) Using the Rubberbanding technique in Young p. 259, I am making a utility
  22.    that allow you to create cross hairs the span the four sides of a given
  23.    window. In other words, drawing lines from 0 to width through mouse y and
  24.    0 to height through mouse x.
  25.  
  26.    My problem is recieving mouse grabbed events when crossing children of the
  27.    selected window.
  28.  
  29.    Example: I have a form with drawing area's, paned windows, and text lists
  30.    for children.  When the grabbed sprite leaves the text list and enters
  31.    the drawing area, I no longer recieve motion notifies.
  32.  
  33.    I have tried XSelectInput on the parent form to no avail.  Does my crosshair
  34.    routine have to know its children and request their motion notifies when
  35.    they don't allow propagation (sp?). Maybe this is not even the problem.
  36.  
  37. Any help is greatly appreciated.
  38.  
  39. Patrick Meyer
  40. Please email to ... patrick%ess2.span@Fedex.Msfc.Nasa.Gov
  41.  
  42. /*******************************************************
  43. *
  44. * Library routine to create a cross hair grab for window 
  45. */
  46. #include <X11/Xlib.h>
  47. #include <X11/StringDefs.h>
  48. #include <X11/Intrinsic.h> 
  49. #include <X11/cursorfont.h>
  50. #include <Xm/Xm.h>
  51. #include <Xm/ScrollBar.h>
  52.  
  53. typedef struct {
  54.     Boolean vertical;
  55.     Boolean horizontal;
  56.     Position vert_x;
  57.     Position vert_y;
  58.     Position hori_x;
  59.     Position hori_y;
  60.     GC  gc;
  61. } cross_hair_data;
  62.  
  63. void XessStartCrosshairs();
  64. void XessEndCrosshairs();
  65. void XessTrackCrosshairs();
  66.  
  67.  
  68. void XessCreateCrosshairs(Widget w, Boolean vertical, Boolean horizontal) {
  69.  
  70.   static cross_hair_data data;
  71.   Arg       args[2];
  72.   unsigned long gc_valuemask;
  73.   XGCValues values;
  74.  
  75.   /* Set which lines will be drawn */
  76.   data.vertical = vertical;
  77.   data.horizontal = horizontal;
  78.  
  79.   /* Add call backs to draw cross hairs */
  80.   XtAddEventHandler(w, ButtonPressMask,   FALSE, XessStartCrosshairs, &data);
  81.   XtAddEventHandler(w, Button3MotionMask, FALSE, XessTrackCrosshairs, &data);
  82.   XtAddEventHandler(w, ButtonReleaseMask, FALSE, XessEndCrosshairs,   &data);
  83.  
  84.   XSelectInput(XtDisplay(w), XRootWindowOfScreen(XtScreen(w)),
  85.                       Button3MotionMask);
  86.  
  87.   /* Force mouse to stay in users window */
  88.   XGrabButton(XtDisplay(w), Button3, ShiftMask, XtWindow(w), TRUE, 
  89.               ButtonPressMask | Button3MotionMask | ButtonReleaseMask,
  90.               GrabModeAsync, GrabModeAsync,
  91.               XtWindow(w), 
  92.               XCreateFontCursor(XtDisplay(w), XC_crosshair));
  93.  
  94.   XtSetArg(args[0], XtNforeground, &values.foreground);
  95.   XtSetArg(args[1], XtNbackground, &values.background);
  96.   XtGetValues(w, args,2);
  97.  
  98.  
  99.   values.foreground = values.foreground ^ values.background;
  100.   values.line_style = LineSolid;
  101.   values.function   = GXxor;
  102.   values.subwindow_mode = IncludeInferiors;
  103.   data.gc = XtGetGC(w, GCForeground | GCBackground | GCSubwindowMode |
  104.                GCFunction | GCLineStyle, &values);
  105. }
  106.  
  107. void XessStartCrosshairs(Widget w, cross_hair_data *data, XEvent *event) {
  108.   Arg args[2];
  109.  
  110.   if (event->xbutton.button == Button3) {
  111.      data->vert_x = event->xbutton.x;
  112.      data->hori_y = event->xbutton.y;
  113.  
  114.      XtSetArg(args[0], XmNheight, &data->vert_y);
  115.      XtSetArg(args[1], XmNwidth, &data->hori_x);
  116.      XtGetValues(w, args, 2);
  117.  
  118.      if(data->vertical)
  119.         XDrawLine(XtDisplay(w), XtWindow(w), data->gc,
  120.                   data->vert_x, 0, 
  121.                   data->vert_x, data->vert_y);
  122.      if(data->horizontal)
  123.         XDrawLine(XtDisplay(w), XtWindow(w), data->gc,
  124.                   0, data->hori_y,
  125.                   data->hori_x, data->hori_y);
  126.   }
  127. }
  128.  
  129. void XessTrackCrosshairs(Widget w, cross_hair_data *data, XEvent *event) {
  130.   Arg args[2];
  131.  
  132.  
  133.      /*
  134.       * Draw once to clear the previous line.
  135.       */
  136.      if(data->vertical)
  137.         XDrawLine(XtDisplay(w), XtWindow(w), data->gc,
  138.                   data->vert_x, 0, 
  139.                   data->vert_x, data->vert_y);
  140.      if(data->horizontal)
  141.         XDrawLine(XtDisplay(w), XtWindow(w), data->gc,
  142.                   0, data->hori_y,
  143.                   data->hori_x, data->hori_y);
  144.      /*
  145.       * Update the endpoints.
  146.       */
  147.      XtSetArg(args[0], XmNheight, &data->vert_y);
  148.      XtSetArg(args[1], XmNwidth, &data->hori_x);
  149.      XtGetValues(w, args, 2);
  150.  
  151.      data->vert_x = event->xbutton.x;
  152.      data->hori_y = event->xbutton.y;
  153.      /*
  154.       * Draw the new line.
  155.       */
  156.      if(data->vertical)
  157.         XDrawLine(XtDisplay(w), XtWindow(w), data->gc,
  158.                   data->vert_x, 0, 
  159.                   data->vert_x, data->vert_y);
  160.      if(data->horizontal)
  161.         XDrawLine(XtDisplay(w), XtWindow(w), data->gc,
  162.                   0, data->hori_y,
  163.                   data->hori_x, data->hori_y);
  164. }
  165.  
  166. void XessEndCrosshairs(Widget w, cross_hair_data *data, XEvent *event) {
  167.   Arg args[2];
  168.  
  169.  /*
  170.   * Clear the current line and update the endpoint info.
  171.   */
  172.   if (event->xbutton.button == Button3) {
  173.      if(data->vertical)
  174.         XDrawLine(XtDisplay(w), XtWindow(w), data->gc,
  175.                   data->vert_x, 0, 
  176.                   data->vert_x, data->vert_y);
  177.      if(data->horizontal)
  178.         XDrawLine(XtDisplay(w), XtWindow(w), data->gc,
  179.                   0, data->hori_y,
  180.                   data->hori_x, data->hori_y);
  181.   }
  182. }
  183.  
  184. Thanks again...
  185. Please email to ... patrick%ess2.span@Fedex.Msfc.Nasa.Gov
  186.