17a84e134Smrg/* 27a84e134SmrgCopyright 1989, 1998 The Open Group 37a84e134Smrg 47a84e134SmrgPermission to use, copy, modify, distribute, and sell this software and its 57a84e134Smrgdocumentation for any purpose is hereby granted without fee, provided that 67a84e134Smrgthe above copyright notice appear in all copies and that both that 77a84e134Smrgcopyright notice and this permission notice appear in supporting 87a84e134Smrgdocumentation. 97a84e134Smrg 107a84e134SmrgThe above copyright notice and this permission notice shall be included in 117a84e134Smrgall copies or substantial portions of the Software. 127a84e134Smrg 137a84e134SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 147a84e134SmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 157a84e134SmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 167a84e134SmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 177a84e134SmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 187a84e134SmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 197a84e134Smrg 207a84e134SmrgExcept as contained in this notice, the name of The Open Group shall not be 217a84e134Smrgused in advertising or otherwise to promote the sale, use or other dealings 227a84e134Smrgin this Software without prior written authorization from The Open Group. 237a84e134Smrg * 247a84e134Smrg * Author: Chris D. Peterson, MIT X Consortium 257a84e134Smrg */ 267a84e134Smrg 277a84e134Smrg/* 287a84e134Smrg * Sme.c - Source code for the generic menu entry 297a84e134Smrg * 307a84e134Smrg * Date: September 26, 1989 317a84e134Smrg * 327a84e134Smrg * By: Chris D. Peterson 33421c997bSmrg * MIT X Consortium 347a84e134Smrg * kit@expo.lcs.mit.edu 357a84e134Smrg */ 367a84e134Smrg 377a84e134Smrg#ifdef HAVE_CONFIG_H 387a84e134Smrg#include <config.h> 397a84e134Smrg#endif 407a84e134Smrg#include <stdio.h> 417a84e134Smrg#include <X11/IntrinsicP.h> 427a84e134Smrg#include <X11/StringDefs.h> 437a84e134Smrg#include <X11/Xaw/Cardinals.h> 447a84e134Smrg#include <X11/Xaw/SmeLineP.h> 457a84e134Smrg#include <X11/Xaw/XawInit.h> 467a84e134Smrg#include "Private.h" 477a84e134Smrg 487a84e134Smrg/* 497a84e134Smrg * Class Methods 507a84e134Smrg */ 517a84e134Smrgstatic void XawSmeLineDestroy(Widget); 527a84e134Smrgstatic void XawSmeLineInitialize(Widget, Widget, ArgList, Cardinal*); 537a84e134Smrgstatic void XawSmeLineRedisplay(Widget, XEvent*, Region); 547a84e134Smrgstatic Boolean XawSmeLineSetValues(Widget, Widget, Widget, 557a84e134Smrg ArgList, Cardinal*); 567a84e134Smrg 577a84e134Smrg/* 587a84e134Smrg * Prototypes 597a84e134Smrg */ 607a84e134Smrgstatic void CreateGC(Widget); 617a84e134Smrgstatic void DestroyGC(Widget); 627a84e134Smrg 637a84e134Smrg/* 647a84e134Smrg * Initialization 657a84e134Smrg */ 667a84e134Smrg#define offset(field) XtOffsetOf(SmeLineRec, sme_line.field) 677a84e134Smrgstatic XtResource resources[] = { 687a84e134Smrg { 697a84e134Smrg XtNlineWidth, 707a84e134Smrg XtCLineWidth, 717a84e134Smrg XtRDimension, 727a84e134Smrg sizeof(Dimension), 737a84e134Smrg offset(line_width), 747a84e134Smrg XtRImmediate, 757a84e134Smrg (XtPointer)1 767a84e134Smrg }, 777a84e134Smrg { 787a84e134Smrg XtNstipple, 797a84e134Smrg XtCStipple, 807a84e134Smrg XtRBitmap, 817a84e134Smrg sizeof(Pixmap), 827a84e134Smrg offset(stipple), 837a84e134Smrg XtRImmediate, 847a84e134Smrg (XtPointer)XtUnspecifiedPixmap 857a84e134Smrg }, 867a84e134Smrg { 877a84e134Smrg XtNforeground, 887a84e134Smrg XtCForeground, 897a84e134Smrg XtRPixel, 907a84e134Smrg sizeof(Pixel), 917a84e134Smrg offset(foreground), 927a84e134Smrg XtRString, 935ec34c4cSmrg (XtPointer)XtDefaultForeground 947a84e134Smrg }, 957a84e134Smrg}; 967a84e134Smrg#undef offset 977a84e134Smrg 987a84e134Smrg#define Superclass (&smeClassRec) 997a84e134SmrgSmeLineClassRec smeLineClassRec = { 1007a84e134Smrg /* rectangle */ 1017a84e134Smrg { 1027a84e134Smrg (WidgetClass)Superclass, /* superclass */ 1037a84e134Smrg "SmeLine", /* class_name */ 1047a84e134Smrg sizeof(SmeLineRec), /* widget_size */ 1057a84e134Smrg XawInitializeWidgetSet, /* class_initialize */ 1067a84e134Smrg NULL, /* class_part_initialize */ 1077a84e134Smrg False, /* class inited */ 1087a84e134Smrg XawSmeLineInitialize, /* initialize */ 1097a84e134Smrg NULL, /* initialize_hook */ 1107a84e134Smrg NULL, /* realize */ 1117a84e134Smrg NULL, /* actions */ 1127a84e134Smrg 0, /* num_actions */ 1137a84e134Smrg resources, /* resources */ 1147a84e134Smrg XtNumber(resources), /* num_resources */ 1157a84e134Smrg NULLQUARK, /* xrm_class */ 1167a84e134Smrg False, /* compress_motion */ 1177a84e134Smrg False, /* compress_exposure */ 1187a84e134Smrg False, /* compress_enterleave */ 1197a84e134Smrg False, /* visible_interest */ 1207a84e134Smrg XawSmeLineDestroy, /* destroy */ 1217a84e134Smrg NULL, /* resize */ 1227a84e134Smrg XawSmeLineRedisplay, /* expose */ 1237a84e134Smrg XawSmeLineSetValues, /* set_values */ 1247a84e134Smrg NULL, /* set_values_hook */ 1257a84e134Smrg XtInheritSetValuesAlmost, /* set_values_almost */ 1267a84e134Smrg NULL, /* get_values_hook */ 1277a84e134Smrg NULL, /* accept_focus */ 1287a84e134Smrg XtVersion, /* intrinsics version */ 1297a84e134Smrg NULL, /* callback offsets */ 1307a84e134Smrg NULL, /* tm_table */ 1317a84e134Smrg XtInheritQueryGeometry, /* query_geometry */ 1327a84e134Smrg NULL, /* display_accelerator */ 1337a84e134Smrg NULL, /* extension */ 1347a84e134Smrg }, 1357a84e134Smrg /* sme */ 1367a84e134Smrg { 1377a84e134Smrg XtInheritHighlight, /* highlight */ 1387a84e134Smrg XtInheritUnhighlight, /* unhighlight */ 1397a84e134Smrg XtInheritNotify, /* notify */ 1407a84e134Smrg NULL, /* extension */ 1417a84e134Smrg }, 1427a84e134Smrg /* sme_line */ 1437a84e134Smrg { 1447a84e134Smrg NULL, /* extension */ 1457a84e134Smrg } 1467a84e134Smrg}; 1477a84e134Smrg 1487a84e134SmrgWidgetClass smeLineObjectClass = (WidgetClass)&smeLineClassRec; 1497a84e134Smrg 1507a84e134Smrg/* 1517a84e134Smrg * Implementation 1527a84e134Smrg */ 1537a84e134Smrg/*ARGSUSED*/ 1547a84e134Smrgstatic void 1555ec34c4cSmrgXawSmeLineInitialize(Widget request _X_UNUSED, Widget cnew, 1565ec34c4cSmrg ArgList args _X_UNUSED, Cardinal *num_args _X_UNUSED) 1577a84e134Smrg{ 1587a84e134Smrg SmeLineObject entry = (SmeLineObject)cnew; 1597a84e134Smrg 1607a84e134Smrg if (XtHeight(entry) == 0) 1617a84e134Smrg XtHeight(entry) = entry->sme_line.line_width; 1627a84e134Smrg 1637a84e134Smrg CreateGC(cnew); 1647a84e134Smrg} 1657a84e134Smrg 1667a84e134Smrg/* 1677a84e134Smrg * Function: 1687a84e134Smrg * CreateGC 1697a84e134Smrg * 1707a84e134Smrg * Parameters: 1717a84e134Smrg * w - Line entry widget 1727a84e134Smrg * 1737a84e134Smrg * Description: 1747a84e134Smrg * Creates the GC for the line entry widget. 1757a84e134Smrg * 1767a84e134Smrg * Note: 1777a84e134Smrg * We can only share the GC if there is no stipple, because 1787a84e134Smrg * we need to change the stipple origin when drawing 1797a84e134Smrg */ 1807a84e134Smrgstatic void 1817a84e134SmrgCreateGC(Widget w) 1827a84e134Smrg{ 1837a84e134Smrg SmeLineObject entry = (SmeLineObject)w; 1847a84e134Smrg XtGCMask mask = GCForeground | GCGraphicsExposures | GCLineWidth; 185efbcb2bfSmrg XGCValues values = { 186efbcb2bfSmrg .foreground = entry->sme_line.foreground, 187efbcb2bfSmrg .graphics_exposures = False, 188efbcb2bfSmrg .line_width = entry->sme_line.line_width 189efbcb2bfSmrg }; 190421c997bSmrg 1917a84e134Smrg if (entry->sme_line.stipple != XtUnspecifiedPixmap) { 1927a84e134Smrg values.stipple = entry->sme_line.stipple; 193421c997bSmrg values.fill_style = FillStippled; 1947a84e134Smrg mask |= GCStipple | GCFillStyle; 195421c997bSmrg 196421c997bSmrg entry->sme_line.gc = XCreateGC(XtDisplayOfObject(w), 1977a84e134Smrg RootWindowOfScreen(XtScreenOfObject(w)), 1987a84e134Smrg mask, &values); 1997a84e134Smrg } 2007a84e134Smrg else 2017a84e134Smrg entry->sme_line.gc = XtGetGC(w, mask, &values); 2027a84e134Smrg} 2037a84e134Smrg 2047a84e134Smrgstatic void 2057a84e134SmrgXawSmeLineDestroy(Widget w) 2067a84e134Smrg{ 2077a84e134Smrg DestroyGC(w); 2087a84e134Smrg} 2097a84e134Smrg 2107a84e134Smrgstatic void 2117a84e134SmrgDestroyGC(Widget w) 2127a84e134Smrg{ 2137a84e134Smrg SmeLineObject entry = (SmeLineObject)w; 2147a84e134Smrg 215421c997bSmrg if (entry->sme_line.stipple != XtUnspecifiedPixmap) 2167a84e134Smrg XFreeGC(XtDisplayOfObject(w), entry->sme_line.gc); 2177a84e134Smrg else 2187a84e134Smrg XtReleaseGC(w, entry->sme_line.gc); 2197a84e134Smrg} 2207a84e134Smrg 2217a84e134Smrg/*ARGSUSED*/ 2227a84e134Smrgstatic void 2235ec34c4cSmrgXawSmeLineRedisplay(Widget w, XEvent *event _X_UNUSED, Region region _X_UNUSED) 2247a84e134Smrg{ 2257a84e134Smrg SmeLineObject entry = (SmeLineObject)w; 2267a84e134Smrg int y = XtY(w) + (((int)XtHeight(w) - entry->sme_line.line_width) >> 1); 2277a84e134Smrg 228421c997bSmrg if (entry->sme_line.stipple != XtUnspecifiedPixmap) 2297a84e134Smrg XSetTSOrigin(XtDisplayOfObject(w), entry->sme_line.gc, 0, y); 2307a84e134Smrg 2317a84e134Smrg XFillRectangle(XtDisplayOfObject(w), XtWindowOfObject(w), 2327a84e134Smrg entry->sme_line.gc, XtX(w), y, 2337a84e134Smrg XtWidth(w), entry->sme_line.line_width); 2347a84e134Smrg} 2357a84e134Smrg 2367a84e134Smrg/* 2377a84e134Smrg * Function: 2387a84e134Smrg * XawSmeLineSetValues 2397a84e134Smrg * 2407a84e134Smrg * Parameters: 2417a84e134Smrg * current - current state of the widget 2427a84e134Smrg * request - what was requested 2437a84e134Smrg * cnew - what the widget will become 2447a84e134Smrg * 2457a84e134Smrg * Description: 2467a84e134Smrg * Relayout the menu when one of the resources is changed. 2477a84e134Smrg */ 2487a84e134Smrg/*ARGSUSED*/ 2497a84e134Smrgstatic Boolean 2505ec34c4cSmrgXawSmeLineSetValues(Widget current, Widget request _X_UNUSED, Widget cnew, 2515ec34c4cSmrg ArgList args _X_UNUSED, Cardinal *num_args _X_UNUSED) 2527a84e134Smrg{ 2537a84e134Smrg SmeLineObject entry = (SmeLineObject)cnew; 2547a84e134Smrg SmeLineObject old_entry = (SmeLineObject)current; 255421c997bSmrg 2567a84e134Smrg if (entry->sme_line.line_width != old_entry->sme_line.line_width && 2577a84e134Smrg entry->sme_line.stipple != old_entry->sme_line.stipple) { 2587a84e134Smrg DestroyGC(current); 2597a84e134Smrg CreateGC(cnew); 2607a84e134Smrg return (True); 2617a84e134Smrg } 2627a84e134Smrg 2637a84e134Smrg return (False); 2647a84e134Smrg} 265