home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / lib / Xaw / Sme.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-17  |  6.7 KB  |  237 lines

  1. /* $XConsortium: Sme.c,v 1.9 91/02/17 16:44:14 rws Exp $ */
  2.  
  3. /*
  4.  * Copyright 1989 Massachusetts Institute of Technology
  5.  *
  6.  * Permission to use, copy, modify, distribute, and sell this software and its
  7.  * documentation for any purpose is hereby granted without fee, provided that
  8.  * the above copyright notice appear in all copies and that both that
  9.  * copyright notice and this permission notice appear in supporting
  10.  * documentation, and that the name of M.I.T. not be used in advertising or
  11.  * publicity pertaining to distribution of the software without specific,
  12.  * written prior permission.  M.I.T. makes no representations about the
  13.  * suitability of this software for any purpose.  It is provided "as is"
  14.  * without express or implied warranty.
  15.  *
  16.  * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  17.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
  18.  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  19.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  20.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
  21.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22.  */
  23.  
  24. /*
  25.  * Sme.c - Source code for the generic menu entry
  26.  *
  27.  * Date:    September 26, 1989
  28.  *
  29.  * By:      Chris D. Peterson
  30.  *          MIT X Consortium 
  31.  *          kit@expo.lcs.mit.edu
  32.  */
  33.  
  34. #include <stdio.h>
  35. #include <X11/IntrinsicP.h>
  36. #include <X11/StringDefs.h>
  37.  
  38. #include <X11/Xaw/XawInit.h>
  39. #include <X11/Xaw/SmeP.h>
  40. #include <X11/Xaw/Cardinals.h>
  41.  
  42. #define offset(field) XtOffsetOf(SmeRec, sme.field)
  43. static XtResource resources[] = {
  44.   {XtNcallback, XtCCallback, XtRCallback, sizeof(XtPointer),
  45.      offset(callbacks), XtRCallback, (XtPointer)NULL},
  46. };   
  47. #undef offset
  48.  
  49. /*
  50.  * Semi Public function definitions. 
  51.  */
  52.  
  53. static void Unhighlight(), Highlight(), Notify(), ClassPartInitialize();
  54. static void Initialize();
  55. static XtGeometryResult QueryGeometry();
  56.  
  57. #define SUPERCLASS (&rectObjClassRec)
  58.  
  59. SmeClassRec smeClassRec = {
  60.   {
  61.     /* superclass         */    (WidgetClass) SUPERCLASS,
  62.     /* class_name         */    "Sme",
  63.     /* size               */    sizeof(SmeRec),
  64.     /* class_initialize   */    XawInitializeWidgetSet,
  65.     /* class_part_initialize*/    ClassPartInitialize,
  66.     /* Class init'ed      */    FALSE,
  67.     /* initialize         */    Initialize,
  68.     /* initialize_hook    */    NULL,
  69.     /* realize            */    NULL,
  70.     /* actions            */    NULL,
  71.     /* num_actions        */    ZERO,
  72.     /* resources          */    resources,
  73.     /* resource_count     */    XtNumber(resources),
  74.     /* xrm_class          */    NULLQUARK,
  75.     /* compress_motion    */    FALSE, 
  76.     /* compress_exposure  */    FALSE,
  77.     /* compress_enterleave*/     FALSE,
  78.     /* visible_interest   */    FALSE,
  79.     /* destroy            */    NULL,
  80.     /* resize             */    NULL,
  81.     /* expose             */    NULL,
  82.     /* set_values         */    NULL,
  83.     /* set_values_hook    */    NULL,
  84.     /* set_values_almost  */    XtInheritSetValuesAlmost,  
  85.     /* get_values_hook    */    NULL,            
  86.     /* accept_focus       */    NULL,
  87.     /* intrinsics version */    XtVersion,
  88.     /* callback offsets   */    NULL,
  89.     /* tm_table          */    NULL,
  90.     /* query_geometry      */    QueryGeometry,
  91.     /* display_accelerator*/    NULL,
  92.     /* extension      */    NULL
  93.   },{
  94.     /* Simple Menu Entry Fields */
  95.       
  96.     /* highlight */             Highlight,
  97.     /* unhighlight */           Unhighlight,
  98.     /* notify */        Notify,        
  99.     /* extension */             NULL                
  100.   }
  101. };
  102.  
  103. WidgetClass smeObjectClass = (WidgetClass) &smeClassRec;
  104.  
  105. /************************************************************
  106.  *
  107.  * Semi-Public Functions.
  108.  *
  109.  ************************************************************/
  110.  
  111. /*    Function Name: ClassPartInitialize
  112.  *    Description: handles inheritance of class functions.
  113.  *    Arguments: class - the widget classs of this widget.
  114.  *    Returns: none.
  115.  */
  116.  
  117. static void
  118. ClassPartInitialize(class)
  119. WidgetClass class;
  120. {
  121.     SmeObjectClass m_ent, superC;
  122.  
  123.     m_ent = (SmeObjectClass) class;
  124.     superC = (SmeObjectClass) m_ent->rect_class.superclass;
  125.  
  126. /* 
  127.  * We don't need to check for null super since we'll get to TextSink
  128.  * eventually.
  129.  */
  130.  
  131.     if (m_ent->sme_class.highlight == XtInheritHighlight) 
  132.     m_ent->sme_class.highlight = superC->sme_class.highlight;
  133.  
  134.     if (m_ent->sme_class.unhighlight == XtInheritUnhighlight)
  135.     m_ent->sme_class.unhighlight = superC->sme_class.unhighlight;
  136.  
  137.     if (m_ent->sme_class.notify == XtInheritNotify) 
  138.     m_ent->sme_class.notify = superC->sme_class.notify;
  139. }
  140.  
  141. /*      Function Name: Initialize
  142.  *      Description: Initializes the simple menu widget
  143.  *      Arguments: request - the widget requested by the argument list.
  144.  *                 new     - the new widget with both resource and non
  145.  *                           resource values.
  146.  *      Returns: none.
  147.  * 
  148.  * MENU ENTRIES CANNOT HAVE BORDERS.
  149.  */
  150.  
  151. /* ARGSUSED */
  152. static void
  153. Initialize(request, new)
  154. Widget request, new;
  155. {
  156.     SmeObject entry = (SmeObject) new;
  157.  
  158.     entry->rectangle.border_width = 0;
  159. }
  160.  
  161. /*    Function Name: Highlight
  162.  *    Description: The default highlight proceedure for menu entries.
  163.  *    Arguments: w - the menu entry.
  164.  *    Returns: none.
  165.  */
  166.  
  167. /* ARGSUSED */
  168. static void
  169. Highlight(w)
  170. Widget w;
  171. {
  172. /* This space intentionally left blank. */
  173. }
  174.  
  175. /*    Function Name: Unhighlight
  176.  *    Description: The default unhighlight proceedure for menu entries.
  177.  *    Arguments: w - the menu entry.
  178.  *    Returns: none.
  179.  */
  180.  
  181. /* ARGSUSED */
  182. static void
  183. Unhighlight(w)
  184. Widget w;
  185. {
  186. /* This space intentionally left blank. */
  187. }
  188.  
  189. /*    Function Name: Notify
  190.  *    Description: calls the callback proceedures for this entry.
  191.  *    Arguments: w - the menu entry.
  192.  *    Returns: none.
  193.  */
  194.  
  195. static void
  196. Notify(w) 
  197. Widget w;
  198. {
  199.     XtCallCallbacks(w, XtNcallback, NULL);
  200. }
  201.  
  202. /*    Function Name: QueryGeometry.
  203.  *    Description: Returns the preferred geometry for this widget.
  204.  *    Arguments: w - the menu entry object.
  205.  *                 itended, return - the intended and return geometry info.
  206.  *    Returns: A Geometry Result.
  207.  *
  208.  * See the Intrinsics manual for details on what this function is for.
  209.  * 
  210.  * I just return the height and a width of 1.
  211.  */
  212.  
  213. static XtGeometryResult
  214. QueryGeometry(w, intended, return_val) 
  215. Widget w;
  216. XtWidgetGeometry *intended, *return_val;
  217. {
  218.     SmeObject entry = (SmeObject) w;
  219.     Dimension width;
  220.     XtGeometryResult ret_val = XtGeometryYes;
  221.     XtGeometryMask mode = intended->request_mode;
  222.  
  223.     width = 1;            /* we can be really small. */
  224.  
  225.     if ( ((mode & CWWidth) && (intended->width != width)) ||
  226.      !(mode & CWWidth) ) {
  227.     return_val->request_mode |= CWWidth;
  228.     return_val->width = width;
  229.     mode = return_val->request_mode;
  230.     
  231.     if ( (mode & CWWidth) && (width == entry->rectangle.width) )
  232.         return(XtGeometryNo);
  233.     return(XtGeometryAlmost);
  234.     }
  235.     return(ret_val);
  236. }
  237.