SmeLine.c revision 749
0N/A/* $XConsortium: SmeLine.c,v 1.15 94/04/17 20:12:51 eswu Exp $ */
579N/A
0N/A/*
0N/ACopyright (c) 1989 X Consortium
0N/A
0N/APermission is hereby granted, free of charge, to any person obtaining a copy
0N/Aof this software and associated documentation files (the "Software"), to deal
0N/Ain the Software without restriction, including without limitation the rights
0N/Ato use, copy, modify, merge, publish, distribute, sublicense, and/or sell
0N/Acopies of the Software, and to permit persons to whom the Software is
0N/Afurnished to do so, subject to the following conditions:
0N/A
0N/AThe above copyright notice and this permission notice shall be included in
0N/Aall copies or substantial portions of the Software.
0N/A
0N/ATHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0N/AIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0N/AFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
0N/AX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
0N/AAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
0N/ACONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
0N/A
0N/AExcept as contained in this notice, the name of the X Consortium shall not be
0N/Aused in advertising or otherwise to promote the sale, use or other dealings
0N/Ain this Software without prior written authorization from the X Consortium.
0N/A *
0N/A * Author: Chris D. Peterson, MIT X Consortium
0N/A */
0N/A
0N/A/*
0N/A * Sme.c - Source code for the generic menu entry
0N/A *
0N/A * Date: September 26, 1989
0N/A *
0N/A * By: Chris D. Peterson
0N/A * MIT X Consortium
0N/A * kit@expo.lcs.mit.edu
0N/A */
0N/A
0N/A#include <stdio.h>
0N/A#include <X11/IntrinsicP.h>
0N/A#include <X11/StringDefs.h>
0N/A
0N/A#include <X11/Xaw/XawInit.h>
0N/A#include <X11/Xaw/SmeLineP.h>
0N/A#include <X11/Xaw/Cardinals.h>
0N/A
0N/A#define offset(field) XtOffsetOf(SmeLineRec, sme_line.field)
0N/Astatic XtResource resources[] = {
0N/A {XtNlineWidth, XtCLineWidth, XtRDimension, sizeof(Dimension),
0N/A offset(line_width), XtRImmediate, (XtPointer) 1},
0N/A {XtNstipple, XtCStipple, XtRBitmap, sizeof(Pixmap),
0N/A offset(stipple), XtRImmediate, (XtPointer) XtUnspecifiedPixmap},
0N/A {XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel),
0N/A offset(foreground), XtRString, XtDefaultForeground},
0N/A};
0N/A#undef offset
0N/A
0N/A/*
0N/A * Function definitions.
0N/A */
0N/A
0N/Astatic void Redisplay(), Initialize();
0N/Astatic void DestroyGC(), CreateGC();
0N/Astatic Boolean SetValues();
0N/Astatic XtGeometryResult QueryGeometry();
0N/A
0N/A
0N/A#define SUPERCLASS (&smeClassRec)
0N/A
0N/ASmeLineClassRec smeLineClassRec = {
0N/A {
0N/A /* superclass */ (WidgetClass) SUPERCLASS,
0N/A /* class_name */ "SmeLine",
0N/A /* size */ sizeof(SmeLineRec),
0N/A /* class_initialize */ XawInitializeWidgetSet,
0N/A /* class_part_initialize*/ NULL,
0N/A /* Class init'ed */ FALSE,
0N/A /* initialize */ Initialize,
0N/A /* initialize_hook */ NULL,
0N/A /* realize */ NULL,
0N/A /* actions */ NULL,
0N/A /* num_actions */ ZERO,
0N/A /* resources */ resources,
0N/A /* resource_count */ XtNumber(resources),
0N/A /* xrm_class */ NULLQUARK,
0N/A /* compress_motion */ FALSE,
0N/A /* compress_exposure */ FALSE,
0N/A /* compress_enterleave*/ FALSE,
0N/A /* visible_interest */ FALSE,
0N/A /* destroy */ DestroyGC,
0N/A /* resize */ NULL,
0N/A /* expose */ Redisplay,
0N/A /* set_values */ SetValues,
0N/A /* set_values_hook */ NULL,
0N/A /* set_values_almost */ XtInheritSetValuesAlmost,
0N/A /* get_values_hook */ NULL,
0N/A /* accept_focus */ NULL,
0N/A /* intrinsics version */ XtVersion,
0N/A /* callback offsets */ NULL,
0N/A /* tm_table */ NULL,
0N/A /* query_geometry */ QueryGeometry,
0N/A /* display_accelerator*/ NULL,
0N/A /* extension */ NULL
0N/A },{
0N/A /* Menu Entry Fields */
518N/A
0N/A /* highlight */ XtInheritHighlight,
0N/A /* unhighlight */ XtInheritUnhighlight,
0N/A /* notify */ XtInheritNotify,
0N/A /* extension */ NULL
0N/A },{
0N/A /* Line Menu Entry Fields */
0N/A /* extension */ NULL
0N/A }
0N/A};
0N/A
0N/AWidgetClass smeLineObjectClass = (WidgetClass) &smeLineClassRec;
0N/A
0N/A/************************************************************
0N/A *
0N/A * Semi-Public Functions.
0N/A *
0N/A ************************************************************/
0N/A
0N/A/* Function Name: Initialize
0N/A * Description: Initializes the simple menu widget
0N/A * Arguments: request - the widget requested by the argument list.
0N/A * new - the new widget with both resource and non
0N/A * resource values.
0N/A * Returns: none.
0N/A */
0N/A
0N/A/* ARGSUSED */
0N/Astatic void
0N/AInitialize(request, new, args, num_args)
0N/AWidget request, new;
0N/AArgList args;
0N/ACardinal *num_args;
0N/A{
0N/A SmeLineObject entry = (SmeLineObject) new;
0N/A
0N/A if (entry->rectangle.height == 0)
0N/A entry->rectangle.height = entry->sme_line.line_width;
0N/A
0N/A CreateGC(new);
0N/A}
0N/A
0N/A/* Function Name: CreateGC
0N/A * Description: Creates the GC for the line entry widget.
0N/A * Arguments: w - the Line entry widget.
0N/A * Returns: none
0N/A *
0N/A * We can only share the GC if there is no stipple, because
0N/A * we need to change the stipple origin when drawing.
0N/A */
0N/A
0N/Astatic void
0N/ACreateGC(w)
0N/AWidget w;
0N/A{
0N/A SmeLineObject entry = (SmeLineObject) w;
0N/A XGCValues values;
0N/A XtGCMask mask = GCForeground | GCGraphicsExposures | GCLineWidth ;
0N/A
0N/A values.foreground = entry->sme_line.foreground;
0N/A values.graphics_exposures = FALSE;
0N/A values.line_width = entry->sme_line.line_width;
0N/A
0N/A if (entry->sme_line.stipple != XtUnspecifiedPixmap) {
0N/A values.stipple = entry->sme_line.stipple;
0N/A values.fill_style = FillStippled;
0N/A mask |= GCStipple | GCFillStyle;
0N/A
0N/A entry->sme_line.gc = XCreateGC(XtDisplayOfObject(w),
0N/A RootWindowOfScreen(XtScreenOfObject(w)),
0N/A mask, &values);
0N/A }
0N/A else
0N/A entry->sme_line.gc = XtGetGC(w, mask, &values);
0N/A}
0N/A
0N/A/* Function Name: DestroyGC
0N/A * Description: Destroys the GC when we are done with it.
0N/A * Arguments: w - the Line entry widget.
0N/A * Returns: none
0N/A */
0N/A
0N/Astatic void
0N/ADestroyGC(w)
0N/AWidget w;
0N/A{
0N/A SmeLineObject entry = (SmeLineObject) w;
0N/A
0N/A if (entry->sme_line.stipple != XtUnspecifiedPixmap)
0N/A XFreeGC(XtDisplayOfObject(w), entry->sme_line.gc);
0N/A else
0N/A XtReleaseGC(w, entry->sme_line.gc);
0N/A}
0N/A
0N/A/* Function Name: Redisplay
0N/A * Description: Paints the Line
0N/A * Arguments: w - the menu entry.
0N/A * event, region - NOT USED.
0N/A * Returns: none
0N/A */
0N/A
0N/A/*ARGSUSED*/
0N/Astatic void
0N/ARedisplay(w, event, region)
0N/AWidget w;
0N/AXEvent * event;
0N/ARegion region;
0N/A{
0N/A SmeLineObject entry = (SmeLineObject) w;
0N/A int y = entry->rectangle.y +
0N/A (int)(entry->rectangle.height - entry->sme_line.line_width) / 2;
0N/A
0N/A if (entry->sme_line.stipple != XtUnspecifiedPixmap)
0N/A XSetTSOrigin(XtDisplayOfObject(w), entry->sme_line.gc, 0, y);
0N/A
0N/A XFillRectangle(XtDisplayOfObject(w), XtWindowOfObject(w),
0N/A entry->sme_line.gc,
0N/A 0, y, (unsigned int) entry->rectangle.width,
0N/A (unsigned int) entry->sme_line.line_width );
0N/A}
0N/A
0N/A/* Function Name: SetValues
0N/A * Description: Relayout the menu when one of the resources is changed.
0N/A * Arguments: current - current state of the widget.
0N/A * request - what was requested.
0N/A * new - what the widget will become.
0N/A * Returns: none
0N/A */
0N/A
0N/A/* ARGSUSED */
0N/Astatic Boolean
0N/ASetValues(current, request, new, args, num_args)
0N/AWidget current, request, new;
0N/AArgList args;
0N/ACardinal *num_args;
0N/A{
0N/A SmeLineObject entry = (SmeLineObject) new;
0N/A SmeLineObject old_entry = (SmeLineObject) current;
0N/A
0N/A if ( (entry->sme_line.line_width != old_entry->sme_line.line_width) &&
0N/A (entry->sme_line.stipple != old_entry->sme_line.stipple) ) {
0N/A DestroyGC(current);
0N/A CreateGC(new);
0N/A return(TRUE);
0N/A }
0N/A return(FALSE);
0N/A}
0N/A
0N/A/* Function Name: QueryGeometry.
0N/A * Description: Returns the preferred geometry for this widget.
0N/A * Arguments: w - the menu entry object.
0N/A * itended, return - the intended and return geometry info.
0N/A * Returns: A Geometry Result.
0N/A *
0N/A * See the Intrinsics manual for details on what this function is for.
0N/A *
0N/A * I just return the height and a width of 1.
0N/A */
0N/A
0N/Astatic XtGeometryResult
0N/AQueryGeometry(w, intended, return_val)
0N/AWidget w;
0N/AXtWidgetGeometry *intended, *return_val;
0N/A{
0N/A SmeObject entry = (SmeObject) w;
0N/A Dimension width;
0N/A XtGeometryResult ret_val = XtGeometryYes;
0N/A XtGeometryMask mode = intended->request_mode;
0N/A
0N/A width = 1; /* we can be really small. */
518N/A
518N/A if ( ((mode & CWWidth) && (intended->width != width)) ||
0N/A !(mode & CWWidth) ) {
0N/A return_val->request_mode |= CWWidth;
0N/A return_val->width = width;
0N/A mode = return_val->request_mode;
0N/A
0N/A if ( (mode & CWWidth) && (width == entry->rectangle.width) )
0N/A return(XtGeometryNo);
0N/A return(XtGeometryAlmost);
0N/A }
0N/A return(ret_val);
0N/A}
0N/A