home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 26 / AACD 26.iso / AACD / Online / x3270 / unix_files / CmeLine.c < prev    next >
Encoding:
C/C++ Source or Header  |  2008-07-05  |  9.1 KB  |  289 lines

  1. /* (from) $XConsortium: SmeLine.c,v 1.13 91/07/23 12:23:21 rws Exp $ */
  2.  
  3. /*
  4.  * Modifications Copyright 1995, 1999 by Paul Mattes.
  5.  *  Permission to use, copy, modify, and distribute this software and its
  6.  *  documentation for any purpose and without fee is hereby granted,
  7.  *  provided that the above copyright notice appear in all copies and that
  8.  *  both that copyright notice and this permission notice appear in
  9.  *  supporting documentation.
  10.  *
  11.  * Copyright 1989 Massachusetts Institute of Technology
  12.  *
  13.  * Permission to use, copy, modify, distribute, and sell this software and its
  14.  * documentation for any purpose is hereby granted without fee, provided that
  15.  * the above copyright notice appear in all copies and that both that
  16.  * copyright notice and this permission notice appear in supporting
  17.  * documentation, and that the name of M.I.T. not be used in advertising or
  18.  * publicity pertaining to distribution of the software without specific,
  19.  * written prior permission.  M.I.T. makes no representations about the
  20.  * suitability of this software for any purpose.  It is provided "as is"
  21.  * without express or implied warranty.
  22.  *
  23.  * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  24.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
  25.  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  26.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  27.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
  28.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  29.  *
  30.  * Author:  Chris D. Peterson, MIT X Consortium
  31.  */
  32.  
  33. /*
  34.  * Cme.c - Source code for the generic menu entry
  35.  * (from) Sme.c - Source code for the generic menu entry
  36.  *
  37.  * Date:    September 26, 1989
  38.  *
  39.  * By:      Chris D. Peterson
  40.  *          MIT X Consortium 
  41.  *          kit@expo.lcs.mit.edu
  42.  */
  43.  
  44. #include "globals.h"
  45. #if defined(X3270_MENUS) /*[*/
  46.  
  47. #include <stdio.h>
  48. #include <X11/IntrinsicP.h>
  49. #include <X11/StringDefs.h>
  50.  
  51. #include <X11/Xaw/XawInit.h>
  52. #include "CmeLineP.h"
  53. #include <X11/Xaw/Cardinals.h>
  54.  
  55. #define offset(field) XtOffsetOf(CmeLineRec, cme_line.field)
  56. static XtResource resources[] = {
  57.   {XtNlineWidth, XtCLineWidth, XtRDimension, sizeof(Dimension),
  58.      offset(line_width), XtRImmediate, (XtPointer) 1},
  59.   {XtNstipple, XtCStipple, XtRBitmap, sizeof(Pixmap),
  60.      offset(stipple), XtRImmediate, (XtPointer) XtUnspecifiedPixmap},
  61.   {XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel),
  62.      offset(foreground), XtRString, XtDefaultForeground},
  63. };   
  64. #undef offset
  65.  
  66. /*
  67.  * Function definitions. 
  68.  */
  69.  
  70. static void Redisplay(Widget, XEvent *, Region);
  71. static void Initialize(Widget, Widget, ArgList, Cardinal *);
  72. static void DestroyGC(Widget);
  73. static void CreateGC(Widget);
  74. static Boolean SetValues(Widget, Widget, Widget, ArgList, Cardinal *);
  75. static XtGeometryResult QueryGeometry(Widget, XtWidgetGeometry *,
  76.     XtWidgetGeometry *);
  77.  
  78.  
  79. #define SUPERCLASS (&cmeClassRec)
  80.  
  81. CmeLineClassRec cmeLineClassRec = {
  82.   {
  83.     /* superclass         */    (WidgetClass) SUPERCLASS,
  84.     /* class_name         */    "CmeLine",
  85.     /* size               */    sizeof(CmeLineRec),
  86.     /* class_initialize   */    XawInitializeWidgetSet,
  87.     /* class_part_initialize*/    NULL,
  88.     /* Class init'ed      */    FALSE,
  89.     /* initialize         */    Initialize,
  90.     /* initialize_hook    */    NULL,
  91.     /* realize            */    NULL,
  92.     /* actions            */    NULL,
  93.     /* num_actions        */    ZERO,
  94.     /* resources          */    resources,
  95.     /* resource_count     */    XtNumber(resources),
  96.     /* xrm_class          */    NULLQUARK,
  97.     /* compress_motion    */    FALSE, 
  98.     /* compress_exposure  */    FALSE,
  99.     /* compress_enterleave*/     FALSE,
  100.     /* visible_interest   */    FALSE,
  101.     /* destroy            */    DestroyGC,
  102.     /* resize             */    NULL,
  103.     /* expose             */    Redisplay,
  104.     /* set_values         */    SetValues,
  105.     /* set_values_hook    */    NULL,
  106.     /* set_values_almost  */    XtInheritSetValuesAlmost,  
  107.     /* get_values_hook    */    NULL,            
  108.     /* accept_focus       */    NULL,
  109.     /* intrinsics version */    XtVersion,
  110.     /* callback offsets   */    NULL,
  111.     /* tm_table          */    NULL,
  112.     /* query_geometry      */    QueryGeometry,
  113.     /* display_accelerator*/    NULL,
  114.     /* extension      */    NULL
  115.   },{
  116.     /* Menu Entry Fields */
  117.       
  118.     /* highlight */             XtInheritHighlight,
  119.     /* unhighlight */           XtInheritUnhighlight,
  120.     /* notify */        XtInheritNotify,        
  121.     /* extension */             NULL                
  122.   },{
  123.     /* Line Menu Entry Fields */
  124.     /* extension */             NULL                
  125.   }
  126. };
  127.  
  128. WidgetClass cmeLineObjectClass = (WidgetClass) &cmeLineClassRec;
  129.  
  130. /************************************************************
  131.  *
  132.  * Semi-Public Functions.
  133.  *
  134.  ************************************************************/
  135.  
  136. /*      Function Name: Initialize
  137.  *      Description: Initializes the complex menu widget
  138.  *      Arguments: request - the widget requested by the argument list.
  139.  *                 new     - the new widget with both resource and non
  140.  *                           resource values.
  141.  *      Returns: none.
  142.  */
  143.  
  144. static void
  145. Initialize(Widget request unused, Widget new, ArgList args unused,
  146.     Cardinal *num_args unused)
  147. {
  148.     CmeLineObject entry = (CmeLineObject) new;
  149.  
  150.     if (entry->rectangle.height == 0)
  151.     entry->rectangle.height = entry->cme_line.line_width;
  152.  
  153.     CreateGC(new);
  154. }
  155.  
  156. /*    Function Name: CreateGC
  157.  *    Description: Creates the GC for the line entry widget.
  158.  *    Arguments: w - the Line entry widget.
  159.  *    Returns: none
  160.  *
  161.  *      We can only share the GC if there is no stipple, because
  162.  *      we need to change the stipple origin when drawing.
  163.  */
  164.  
  165. static void
  166. CreateGC(Widget w)
  167. {
  168.     CmeLineObject entry = (CmeLineObject) w;
  169.     XGCValues values;
  170.     XtGCMask mask = GCForeground | GCGraphicsExposures | GCLineWidth ;
  171.     
  172.     values.foreground = entry->cme_line.foreground;
  173.     values.graphics_exposures = FALSE;
  174.     values.line_width = entry->cme_line.line_width;
  175.     
  176.     if (entry->cme_line.stipple != XtUnspecifiedPixmap) {
  177.     values.stipple = entry->cme_line.stipple;
  178.     values.fill_style = FillStippled; 
  179.     mask |= GCStipple | GCFillStyle;
  180.     
  181.     entry->cme_line.gc = XCreateGC(XtDisplayOfObject(w), 
  182.                       RootWindowOfScreen(XtScreenOfObject(w)),
  183.                       mask, &values);
  184.     }
  185.     else
  186.     entry->cme_line.gc = XtGetGC(w, mask, &values);
  187. }
  188.  
  189. /*    Function Name: DestroyGC
  190.  *    Description: Destroys the GC when we are done with it.
  191.  *    Arguments: w - the Line entry widget.
  192.  *    Returns: none
  193.  */
  194.  
  195. static void
  196. DestroyGC(Widget w)
  197. {
  198.     CmeLineObject entry = (CmeLineObject) w;
  199.  
  200.     if (entry->cme_line.stipple != XtUnspecifiedPixmap) 
  201.     XFreeGC(XtDisplayOfObject(w), entry->cme_line.gc);
  202.     else
  203.     XtReleaseGC(w, entry->cme_line.gc);
  204. }
  205.  
  206. /*    Function Name: Redisplay
  207.  *    Description: Paints the Line
  208.  *    Arguments: w - the menu entry.
  209.  *                 event, region - NOT USED.
  210.  *    Returns: none
  211.  */
  212.  
  213. static void
  214. Redisplay(Widget w, XEvent *event unused, Region region unused)
  215. {
  216.     CmeLineObject entry = (CmeLineObject) w;
  217.     int y = entry->rectangle.y + 
  218.         (int)(entry->rectangle.height - entry->cme_line.line_width) / 2;
  219.  
  220.     if (entry->cme_line.stipple != XtUnspecifiedPixmap) 
  221.     XSetTSOrigin(XtDisplayOfObject(w), entry->cme_line.gc, 0, y);
  222.  
  223.     XFillRectangle(XtDisplayOfObject(w), XtWindowOfObject(w),
  224.            entry->cme_line.gc, 
  225.            0, y, (unsigned int) entry->rectangle.width, 
  226.            (unsigned int) entry->cme_line.line_width );
  227. }
  228.  
  229. /*      Function Name: SetValues
  230.  *      Description: Relayout the menu when one of the resources is changed.
  231.  *      Arguments: current - current state of the widget.
  232.  *                 request - what was requested.
  233.  *                 new - what the widget will become.
  234.  *      Returns: none
  235.  */
  236.  
  237. static Boolean
  238. SetValues(Widget current, Widget request unused, Widget new,
  239.     ArgList args unused, Cardinal *num_args unused)
  240. {
  241.     CmeLineObject entry = (CmeLineObject) new;
  242.     CmeLineObject old_entry = (CmeLineObject) current;
  243.   
  244.     if ( (entry->cme_line.line_width != old_entry->cme_line.line_width) &&
  245.      (entry->cme_line.stipple != old_entry->cme_line.stipple) ) {
  246.     DestroyGC(current);
  247.     CreateGC(new);
  248.     return(TRUE);
  249.     }
  250.     return(FALSE);
  251. }
  252.  
  253. /*    Function Name: QueryGeometry.
  254.  *    Description: Returns the preferred geometry for this widget.
  255.  *    Arguments: w - the menu entry object.
  256.  *                 itended, return - the intended and return geometry info.
  257.  *    Returns: A Geometry Result.
  258.  *
  259.  * See the Intrinsics manual for details on what this function is for.
  260.  * 
  261.  * I just return the height and a width of 1.
  262.  */
  263.  
  264. static XtGeometryResult
  265. QueryGeometry(Widget w, XtWidgetGeometry *intended,
  266.     XtWidgetGeometry *return_val)
  267. {
  268.     CmeObject entry = (CmeObject) w;
  269.     Dimension width;
  270.     XtGeometryResult ret_val = XtGeometryYes;
  271.     XtGeometryMask mode = intended->request_mode;
  272.  
  273.     width = 1;            /* we can be really small. */
  274.  
  275.     if ( ((mode & CWWidth) && (intended->width != width)) ||
  276.      !(mode & CWWidth) ) {
  277.     return_val->request_mode |= CWWidth;
  278.     return_val->width = width;
  279.     mode = return_val->request_mode;
  280.     
  281.     if ( (mode & CWWidth) && (width == entry->rectangle.width) )
  282.         return(XtGeometryNo);
  283.     return(XtGeometryAlmost);
  284.     }
  285.     return(ret_val);
  286. }
  287.  
  288. #endif /*]*/
  289.