home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / freeWAIS-sf-1.1 / x / MyList.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-08  |  5.9 KB  |  205 lines

  1. /* Based on: */
  2. /* XConsortium: List.c,v 1.34 91/09/27 18:35:07 converse Exp */
  3.  
  4. /*
  5.  * Copyright 1989 Massachusetts Institute of Technology
  6.  *
  7.  * Permission to use, copy, modify, distribute, and sell this software and its
  8.  * documentation for any purpose is hereby granted without fee, provided that
  9.  * the above copyright notice appear in all copies and that both that
  10.  * copyright notice and this permission notice appear in supporting
  11.  * documentation, and that the name of M.I.T. not be used in advertising or
  12.  * publicity pertaining to distribution of the software without specific,
  13.  * written prior permission.  M.I.T. makes no representations about the
  14.  * suitability of this software for any purpose.  It is provided "as is"
  15.  * without express or implied warranty.
  16.  *
  17.  * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  18.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
  19.  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  20.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  21.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
  22.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  23.  *
  24.  */
  25.  
  26. /* Copyright (c) CNIDR (see ../COPYRIGHT) */
  27.  
  28.  
  29. static char MyList_c_rcsid[] =
  30.   "$Id: MyList.c,v 1.3 1994/09/08 16:43:50 pfeifer Exp $";
  31.  
  32. #include "../ir/cdialect.h"
  33. #include <stdio.h>
  34. /* #include <ctype.h> */
  35.  
  36. #include <X11/IntrinsicP.h>
  37. #include <X11/StringDefs.h>
  38.  
  39. #include <X11/Xaw/XawInit.h>
  40. #include "MyListP.h"
  41.  
  42. static char MyListP_h_rcsid[] =
  43.   MyListP_id;
  44.  
  45. /*
  46.  * Full class record constant
  47.  */
  48.  
  49. static void Notify();
  50.  
  51. static XtActionsRec actions[] = {
  52.   { "Notify",    Notify}
  53. };
  54.  
  55. static char defaultTranslations[] =
  56.   "<Btn1Down>:    Set()\n<Btn1Up>:    Notify()";
  57.  
  58. MyListClassRec myListClassRec = {
  59. {
  60.   (WidgetClass)&listClassRec,    /* superclass */
  61.   "MyList",            /* class name */
  62.   sizeof(MyListRec),        /* widget size */
  63.   0,                /* class initialize */
  64.   0,                /* class part initialize */
  65.   FALSE,            /* class inited */
  66.   0,                /* initialize */
  67.   0,                /* initialize hook */
  68.   XtInheritRealize,        /* realize */
  69.   actions,            /* actions */
  70.   XtNumber(actions),        /* num actions */
  71.   0,                /* resources */
  72.   0,                /* num resources */
  73.   NULLQUARK,            /* xrm class */
  74.   TRUE,                /* compress motion */
  75.   FALSE,            /* compress exposure */
  76.   TRUE,                /* compress enterleave */
  77.   FALSE,            /* visible interest */
  78.   0,                /* destroy */
  79.   XtInheritResize,        /* resize */
  80.   XtInheritExpose,        /* expose */
  81.   0,                /* set values */
  82.   0,                /* set values hook */
  83.   XtInheritSetValuesAlmost,    /* set values almost */
  84.   0,                /* get values hook */
  85.   XtInheritAcceptFocus,        /* accept focus */
  86.   XtVersion,            /* version */
  87.   0,                /* callback private */
  88.   defaultTranslations,        /* default translations */
  89.   XtInheritQueryGeometry    /* query geometry */
  90.   },
  91. {
  92.   XtInheritChangeSensitive,    /* change sensitive */
  93. }
  94. };
  95.  
  96. WidgetClass myListWidgetClass = (WidgetClass)&myListClassRec;
  97.  
  98. /* From List.c... */
  99.  
  100. /*    Function Name: CvtToItem
  101.  *    Description: Converts Xcoord to item number of item containing that
  102.  *                   point.
  103.  *    Arguments: w - the list widget.
  104.  *                 xloc, yloc - x location, and y location.
  105.  *    Returns: the item number.
  106.  */
  107.  
  108. static int
  109. CvtToItem(w, xloc, yloc, item)
  110. Widget w;
  111. int xloc, yloc;
  112. int *item;
  113. {
  114.     int one, another;
  115.     ListWidget lw = (ListWidget) w;
  116.     int ret_val = OKAY;
  117.  
  118.     if (lw->list.vertical_cols) {
  119.         one = lw->list.nrows * ((xloc - (int) lw->list.internal_width)
  120.         / lw->list.col_width);
  121.         another = (yloc - (int) lw->list.internal_height) 
  122.             / lw->list.row_height;
  123.      /* If out of range, return minimum possible value. */
  124.     if (another >= lw->list.nrows) {
  125.         another = lw->list.nrows - 1;
  126.         ret_val = OUT_OF_RANGE;
  127.     }
  128.     }
  129.     else {
  130.         one = (lw->list.ncols * ((yloc - (int) lw->list.internal_height) 
  131.               / lw->list.row_height)) ;
  132.     /* If in right margin handle things right. */
  133.         another = (xloc - (int) lw->list.internal_width) / lw->list.col_width;
  134.     if (another >= lw->list.ncols) {
  135.         another = lw->list.ncols - 1; 
  136.         ret_val = OUT_OF_RANGE;
  137.     }
  138.     }  
  139.     if ((xloc < 0) || (yloc < 0))
  140.         ret_val = OUT_OF_RANGE;
  141.     if (one < 0) one = 0;
  142.     if (another < 0) another = 0;
  143.     *item = one + another;
  144.     if (*item >= lw->list.nitems) return(OUT_OF_RANGE);
  145.     return(ret_val);
  146. }
  147.  
  148.  
  149. /*    Function Name: Notify
  150.  *    Description: Notifies the user that a button has been pressed, and
  151.  *                   calles the callback, if the XtNpasteBuffer resource
  152.  *                   is true then the name of the item is also put in the
  153.  *                   X cut buffer ( buf (0) ).
  154.  *    Arguments: w - the widget that the notify occured in.
  155.  *                 event - event that caused this notification.
  156.  *                 params, num_params - not used.
  157.  *    Returns: none.
  158.  */
  159.  
  160. /* ARGSUSED */
  161. static void
  162. Notify(w, event, params, num_params)
  163. Widget w;
  164. XEvent * event;
  165. String * params;
  166. Cardinal *num_params;
  167. {
  168.     ListWidget lw = ( ListWidget ) w;
  169.     int item, item_len;
  170.     XawListReturnStruct ret_value;
  171.  
  172. /* 
  173.  * Find item and if out of range then unhighlight and tell the
  174.  * client that we have done so, via the callback.
  175.  * 
  176.  * If the current item is unhighlighted then the user has aborted the
  177.  * notify, so unhighlight and return.
  178.  */
  179.  
  180.     if ( ((CvtToItem(w, event->xbutton.x, event->xbutton.y, &item))
  181.       == OUT_OF_RANGE) || (lw->list.highlight != item) ) {
  182.         XawListUnhighlight(w);
  183.  
  184.     ret_value.string = NULL;
  185.     ret_value.list_index = -1;
  186.     XtCallCallbacks( w, XtNcallback, (XtPointer)&ret_value);
  187.         return;
  188.     }
  189.  
  190.     item_len = strlen(lw->list.list[item]);
  191.  
  192.     if ( lw->list.paste )    /* if XtNpasteBuffer set then paste it. */
  193.         XStoreBytes(XtDisplay(w), lw->list.list[item], item_len);
  194.  
  195. /* 
  196.  * Call Callback function.
  197.  */
  198.  
  199.     ret_value.string = lw->list.list[item];
  200.     ret_value.list_index = item;
  201.     
  202.     XtCallCallbacks( w, XtNcallback, (XtPointer) &ret_value);
  203. }
  204.  
  205.