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