SmeLine.c

Go to the documentation of this file.
00001 /* $XConsortium: SmeLine.c,v 1.15 94/04/17 20:12:51 eswu Exp $ */
00002 
00003 /*
00004 Copyright (c) 1989  X Consortium
00005 
00006 Permission is hereby granted, free of charge, to any person obtaining a copy
00007 of this software and associated documentation files (the "Software"), to deal
00008 in the Software without restriction, including without limitation the rights
00009 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00010 copies of the Software, and to permit persons to whom the Software is
00011 furnished to do so, subject to the following conditions:
00012 
00013 The above copyright notice and this permission notice shall be included in
00014 all copies or substantial portions of the Software.
00015 
00016 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00017 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00018 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
00019 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00020 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00021 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00022 
00023 Except as contained in this notice, the name of the X Consortium shall not be
00024 used in advertising or otherwise to promote the sale, use or other dealings
00025 in this Software without prior written authorization from the X Consortium.
00026  *
00027  * Author:  Chris D. Peterson, MIT X Consortium
00028  */
00029 
00030 /*
00031  * Sme.c - Source code for the generic menu entry
00032  *
00033  * Date:    September 26, 1989
00034  *
00035  * By:      Chris D. Peterson
00036  *          MIT X Consortium 
00037  *          kit@expo.lcs.mit.edu
00038  */
00039 
00040 #include <stdio.h>
00041 #include <X11/IntrinsicP.h>
00042 #include <X11/StringDefs.h>
00043 
00044 #include <X11/Xaw3d/XawInit.h>
00045 #include <X11/Xaw3d/SmeLineP.h>
00046 #include <X11/Xaw3d/Cardinals.h>
00047 
00048 #define offset(field) XtOffsetOf(SmeLineRec, sme_line.field)
00049 static XtResource resources[] = {
00050   {XtNlineWidth, XtCLineWidth, XtRDimension, sizeof(Dimension),
00051      offset(line_width), XtRImmediate, (XtPointer) 1},
00052   {XtNstipple, XtCStipple, XtRBitmap, sizeof(Pixmap),
00053      offset(stipple), XtRImmediate, (XtPointer) XtUnspecifiedPixmap},
00054   {XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel),
00055      offset(foreground), XtRString, XtDefaultForeground},
00056 };   
00057 #undef offset
00058 
00059 /*
00060  * Function definitions. 
00061  */
00062 
00063 static void Redisplay(), Initialize();
00064 static void DestroyGC(), CreateGC();
00065 static Boolean SetValues();
00066 static XtGeometryResult QueryGeometry();
00067 
00068 
00069 #define SUPERCLASS (&smeClassRec)
00070 
00071 SmeLineClassRec smeLineClassRec = {
00072   {
00073     /* superclass         */    (WidgetClass) SUPERCLASS,
00074     /* class_name         */    "SmeLine",
00075     /* size               */    sizeof(SmeLineRec),
00076     /* class_initialize   */    XawInitializeWidgetSet,
00077     /* class_part_initialize*/  NULL,
00078     /* Class init'ed      */    FALSE,
00079     /* initialize         */    Initialize,
00080     /* initialize_hook    */    NULL,
00081     /* realize            */    NULL,
00082     /* actions            */    NULL,
00083     /* num_actions        */    ZERO,
00084     /* resources          */    resources,
00085     /* resource_count     */    XtNumber(resources),
00086     /* xrm_class          */    NULLQUARK,
00087     /* compress_motion    */    FALSE, 
00088     /* compress_exposure  */    FALSE,
00089     /* compress_enterleave*/    FALSE,
00090     /* visible_interest   */    FALSE,
00091     /* destroy            */    DestroyGC,
00092     /* resize             */    NULL,
00093     /* expose             */    Redisplay,
00094     /* set_values         */    SetValues,
00095     /* set_values_hook    */    NULL,
00096     /* set_values_almost  */    XtInheritSetValuesAlmost,  
00097     /* get_values_hook    */    NULL,                   
00098     /* accept_focus       */    NULL,
00099     /* intrinsics version */    XtVersion,
00100     /* callback offsets   */    NULL,
00101     /* tm_table           */    NULL,
00102     /* query_geometry     */    QueryGeometry,
00103     /* display_accelerator*/    NULL,
00104     /* extension          */    NULL
00105   },{
00106     /* Menu Entry Fields */
00107       
00108     /* highlight */             XtInheritHighlight,
00109     /* unhighlight */           XtInheritUnhighlight,
00110     /* notify */                XtInheritNotify,                
00111     /* extension */             NULL                            
00112   },{
00113     /* Line Menu Entry Fields */
00114     /* extension */             NULL                            
00115   }
00116 };
00117 
00118 WidgetClass smeLineObjectClass = (WidgetClass) &smeLineClassRec;
00119 
00120 /************************************************************
00121  *
00122  * Semi-Public Functions.
00123  *
00124  ************************************************************/
00125 
00126 /*      Function Name: Initialize
00127  *      Description: Initializes the simple menu widget
00128  *      Arguments: request - the widget requested by the argument list.
00129  *                 new     - the new widget with both resource and non
00130  *                           resource values.
00131  *      Returns: none.
00132  */
00133 
00134 /* ARGSUSED */
00135 static void
00136 Initialize(request, new, args, num_args)
00137 Widget request, new;
00138 ArgList args;
00139 Cardinal *num_args;
00140 {
00141     SmeLineObject entry = (SmeLineObject) new;
00142 
00143     if (entry->rectangle.height == 0)
00144         entry->rectangle.height = entry->sme_line.line_width;
00145 
00146     CreateGC(new);
00147 }
00148 
00149 /*      Function Name: CreateGC
00150  *      Description: Creates the GC for the line entry widget.
00151  *      Arguments: w - the Line entry widget.
00152  *      Returns: none
00153  *
00154  *      We can only share the GC if there is no stipple, because
00155  *      we need to change the stipple origin when drawing.
00156  */
00157 
00158 static void
00159 CreateGC(w)
00160 Widget w;
00161 {
00162     SmeLineObject entry = (SmeLineObject) w;
00163     XGCValues values;
00164     XtGCMask mask = GCForeground | GCGraphicsExposures | GCLineWidth ;
00165     
00166     values.foreground = entry->sme_line.foreground;
00167     values.graphics_exposures = FALSE;
00168     values.line_width = entry->sme_line.line_width;
00169     
00170     if (entry->sme_line.stipple != XtUnspecifiedPixmap) {
00171         values.stipple = entry->sme_line.stipple;
00172         values.fill_style = FillStippled; 
00173         mask |= GCStipple | GCFillStyle;
00174         
00175         entry->sme_line.gc = XCreateGC(XtDisplayOfObject(w), 
00176                                       RootWindowOfScreen(XtScreenOfObject(w)),
00177                                       mask, &values);
00178     }
00179     else
00180         entry->sme_line.gc = XtGetGC(w, mask, &values);
00181 }
00182 
00183 /*      Function Name: DestroyGC
00184  *      Description: Destroys the GC when we are done with it.
00185  *      Arguments: w - the Line entry widget.
00186  *      Returns: none
00187  */
00188 
00189 static void
00190 DestroyGC(w)
00191 Widget w;
00192 {
00193     SmeLineObject entry = (SmeLineObject) w;
00194 
00195     if (entry->sme_line.stipple != XtUnspecifiedPixmap) 
00196         XFreeGC(XtDisplayOfObject(w), entry->sme_line.gc);
00197     else
00198         XtReleaseGC(w, entry->sme_line.gc);
00199 }
00200 
00201 /*      Function Name: Redisplay
00202  *      Description: Paints the Line
00203  *      Arguments: w - the menu entry.
00204  *                 event, region - NOT USED.
00205  *      Returns: none
00206  */
00207 
00208 /*ARGSUSED*/
00209 static void
00210 Redisplay(w, event, region)
00211 Widget w;
00212 XEvent * event;
00213 Region region;
00214 {
00215     SmeLineObject entry = (SmeLineObject) w;
00216     int y = entry->rectangle.y + 
00217             (int)(entry->rectangle.height - entry->sme_line.line_width) / 2;
00218 
00219     if (entry->sme_line.stipple != XtUnspecifiedPixmap) 
00220         XSetTSOrigin(XtDisplayOfObject(w), entry->sme_line.gc, 0, y);
00221 
00222     XFillRectangle(XtDisplayOfObject(w), XtWindowOfObject(w),
00223                    entry->sme_line.gc, 
00224                    0, y, (unsigned int) entry->rectangle.width, 
00225                    (unsigned int) entry->sme_line.line_width );
00226 }
00227 
00228 /*      Function Name: SetValues
00229  *      Description: Relayout the menu when one of the resources is changed.
00230  *      Arguments: current - current state of the widget.
00231  *                 request - what was requested.
00232  *                 new - what the widget will become.
00233  *      Returns: none
00234  */
00235 
00236 /* ARGSUSED */
00237 static Boolean
00238 SetValues(current, request, new, args, num_args)
00239 Widget current, request, new;
00240 ArgList args;
00241 Cardinal *num_args;
00242 {
00243     SmeLineObject entry = (SmeLineObject) new;
00244     SmeLineObject old_entry = (SmeLineObject) current;
00245   
00246     if ( (entry->sme_line.line_width != old_entry->sme_line.line_width) &&
00247          (entry->sme_line.stipple != old_entry->sme_line.stipple) ) {
00248         DestroyGC(current);
00249         CreateGC(new);
00250         return(TRUE);
00251     }
00252     return(FALSE);
00253 }
00254 
00255 /*      Function Name: QueryGeometry.
00256  *      Description: Returns the preferred geometry for this widget.
00257  *      Arguments: w - the menu entry object.
00258  *                 itended, return - the intended and return geometry info.
00259  *      Returns: A Geometry Result.
00260  *
00261  * See the Intrinsics manual for details on what this function is for.
00262  * 
00263  * I just return the height and a width of 1.
00264  */
00265 
00266 static XtGeometryResult
00267 QueryGeometry(w, intended, return_val) 
00268 Widget w;
00269 XtWidgetGeometry *intended, *return_val;
00270 {
00271     SmeObject entry = (SmeObject) w;
00272     Dimension width;
00273     XtGeometryResult ret_val = XtGeometryYes;
00274     XtGeometryMask mode = intended->request_mode;
00275 
00276     width = 1;                  /* we can be really small. */
00277 
00278     if ( ((mode & CWWidth) && (intended->width != width)) ||
00279          !(mode & CWWidth) ) {
00280         return_val->request_mode |= CWWidth;
00281         return_val->width = width;
00282         mode = return_val->request_mode;
00283         
00284         if ( (mode & CWWidth) && (width == entry->rectangle.width) )
00285             return(XtGeometryNo);
00286         return(XtGeometryAlmost);
00287     }
00288     return(ret_val);
00289 }

Generated on Sun Mar 4 15:03:55 2007 for Scilab [trunk] by  doxygen 1.5.1