rust/cargo-c: update to 0.10.7+cargo-0.84.0
[oi-userland.git] / components / x11 / libXaw4 / src / Xaw3_1SmeLine.c
blobe8385d1cd359721570bd1aaf5917a3e895d47c39
1 #if ( !defined(lint) && !defined(SABER) )
2 static char Xrcsid[] = "$XConsortium: SmeLine.c,v 1.8 90/02/08 13:50:13 jim Exp $";
3 #endif
5 /*
6 * Copyright 1989 Massachusetts Institute of Technology
8 * Permission to use, copy, modify, distribute, and sell this software and its
9 * documentation for any purpose is hereby granted without fee, provided that
10 * the above copyright notice appear in all copies and that both that
11 * copyright notice and this permission notice appear in supporting
12 * documentation, and that the name of M.I.T. not be used in advertising or
13 * publicity pertaining to distribution of the software without specific,
14 * written prior permission. M.I.T. makes no representations about the
15 * suitability of this software for any purpose. It is provided "as is"
16 * without express or implied warranty.
18 * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
20 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
21 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
22 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
23 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
25 * Author: Chris D. Peterson, MIT X Consortium
29 * Sme.c - Source code for the generic menu entry
31 * Date: September 26, 1989
33 * By: Chris D. Peterson
34 * MIT X Consortium
35 * kit@expo.lcs.mit.edu
38 #include <stdio.h>
39 #include <X11/IntrinsicP.h>
40 #include <X11/StringDefs.h>
42 #include <./Xaw3_1XawInit.h>
43 #include <./Xaw3_1SmeLineP.h>
44 #include <./Xaw3_1Cardinals.h>
46 #define offset(field) XtOffset(SmeLineObject, sme_line.field)
47 static XtResource resources[] = {
48 {XtNlineWidth, XtCLineWidth, XtRDimension, sizeof(Dimension),
49 offset(line_width), XtRImmediate, (XtPointer) 1},
50 {XtNstipple, XtCStipple, XtRBitmap, sizeof(Pixmap),
51 offset(stipple), XtRImmediate, (XtPointer) XtUnspecifiedPixmap},
52 {XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel),
53 offset(foreground), XtRString, "XtDefaultForeground"},
54 };
55 #undef offset
58 * Function definitions.
61 static void Redisplay(), ClassInitialize(), Initialize();
62 static void DestroyGC(), CreateGC();
63 static Boolean SetValues();
64 static XtGeometryResult QueryGeometry();
67 #define SUPERCLASS (&smeClassRec)
69 SmeLineClassRec smeLineClassRec = {
71 /* superclass */ (WidgetClass) SUPERCLASS,
72 /* class_name */ "SmeLine",
73 /* size */ sizeof(SmeLineRec),
74 /* class_initialize */ ClassInitialize,
75 /* class_part_initialize*/ NULL,
76 /* Class init'ed */ FALSE,
77 /* initialize */ Initialize,
78 /* initialize_hook */ NULL,
79 /* realize */ NULL,
80 /* actions */ NULL,
81 /* num_actions */ ZERO,
82 /* resources */ resources,
83 /* resource_count */ XtNumber(resources),
84 /* xrm_class */ NULLQUARK,
85 /* compress_motion */ FALSE,
86 /* compress_exposure */ FALSE,
87 /* compress_enterleave*/ FALSE,
88 /* visible_interest */ FALSE,
89 /* destroy */ DestroyGC,
90 /* resize */ NULL,
91 /* expose */ Redisplay,
92 /* set_values */ SetValues,
93 /* set_values_hook */ NULL,
94 /* set_values_almost */ XtInheritSetValuesAlmost,
95 /* get_values_hook */ NULL,
96 /* accept_focus */ NULL,
97 /* intrinsics version */ XtVersion,
98 /* callback offsets */ NULL,
99 /* tm_table */ NULL,
100 /* query_geometry */ QueryGeometry,
101 /* display_accelerator*/ NULL,
102 /* extension */ NULL
104 /* Menu Entry Fields */
106 /* highlight */ XtInheritHighlight,
107 /* unhighlight */ XtInheritUnhighlight,
108 /* notify */ XtInheritNotify,
109 /* extension */ NULL
111 /* Line Menu Entry Fields */
112 /* extension */ NULL
116 WidgetClass smeLineObjectClass = (WidgetClass) &smeLineClassRec;
118 /************************************************************
120 * Semi-Public Functions.
122 ************************************************************/
124 /* Function Name: ClassInitialize
125 * Description: The Line Menu Entry Object's class initialization proc.
126 * Arguments: none.
127 * Returns: none.
130 static void
131 ClassInitialize()
133 static XtConvertArgRec screenConvertArg[] = {
134 {XtWidgetBaseOffset, (caddr_t) XtOffset(Widget, core.screen),
135 sizeof(Screen *)}
138 XawInitializeWidgetSet();
139 XtAddConverter(XtRString, XtRBitmap, XmuCvtStringToBitmap,
140 screenConvertArg, XtNumber(screenConvertArg));
143 /* Function Name: Initialize
144 * Description: Initializes the simple menu widget
145 * Arguments: request - the widget requested by the argument list.
146 * new - the new widget with both resource and non
147 * resource values.
148 * Returns: none.
151 /* ARGSUSED */
152 static void
153 Initialize(request, new)
154 Widget request, new;
156 SmeLineObject entry = (SmeLineObject) new;
158 if (entry->rectangle.height == 0)
159 entry->rectangle.height = entry->sme_line.line_width;
161 CreateGC(new);
164 /* Function Name: CreateGC
165 * Description: Creates the GC for the line entry widget.
166 * Arguments: w - the Line entry widget.
167 * Returns: none
169 * We can only share the GC if there is no stipple, because
170 * we need to change the stipple origin when drawing.
173 static void
174 CreateGC(w)
175 Widget w;
177 SmeLineObject entry = (SmeLineObject) w;
178 XGCValues values;
179 XtGCMask mask = GCForeground | GCGraphicsExposures | GCLineWidth ;
181 values.foreground = entry->sme_line.foreground;
182 values.graphics_exposures = FALSE;
183 values.line_width = entry->sme_line.line_width;
185 if (entry->sme_line.stipple != XtUnspecifiedPixmap) {
186 values.stipple = entry->sme_line.stipple;
187 values.fill_style = FillStippled;
188 mask |= GCStipple | GCFillStyle;
190 entry->sme_line.gc = XCreateGC(XtDisplayOfObject(w),
191 RootWindowOfScreen(XtScreenOfObject(w)),
192 mask, &values);
194 else
195 entry->sme_line.gc = XtGetGC(w, mask, &values);
198 /* Function Name: DestroyGC
199 * Description: Destroys the GC when we are done with it.
200 * Arguments: w - the Line entry widget.
201 * Returns: none
204 static void
205 DestroyGC(w)
206 Widget w;
208 SmeLineObject entry = (SmeLineObject) w;
210 if (entry->sme_line.stipple != XtUnspecifiedPixmap)
211 XFreeGC(XtDisplayOfObject(w), entry->sme_line.gc);
212 else
213 XtReleaseGC(w, entry->sme_line.gc);
216 /* Function Name: Redisplay
217 * Description: Paints the Line
218 * Arguments: w - the menu entry.
219 * event, region - NOT USED.
220 * Returns: none
223 static void
224 Redisplay(w, event, region)
225 Widget w;
226 XEvent * event;
227 Region region;
229 SmeLineObject entry = (SmeLineObject) w;
230 int y = entry->rectangle.y +
231 (entry->rectangle.height - entry->sme_line.line_width) / 2;
233 if (entry->sme_line.stipple != XtUnspecifiedPixmap)
234 XSetTSOrigin(XtDisplayOfObject(w), entry->sme_line.gc, 0, y);
236 XFillRectangle(XtDisplayOfObject(w), XtWindowOfObject(w),
237 entry->sme_line.gc,
238 0, y, (unsigned int) entry->rectangle.width,
239 (unsigned int) entry->sme_line.line_width );
242 /* Function Name: SetValues
243 * Description: Relayout the menu when one of the resources is changed.
244 * Arguments: current - current state of the widget.
245 * request - what was requested.
246 * new - what the widget will become.
247 * Returns: none
250 /* ARGSUSED */
251 static Boolean
252 SetValues(current, request, new)
253 Widget current, request, new;
255 SmeLineObject entry = (SmeLineObject) new;
256 SmeLineObject old_entry = (SmeLineObject) current;
258 if ( (entry->sme_line.line_width != old_entry->sme_line.line_width) &&
259 (entry->sme_line.stipple != old_entry->sme_line.stipple) ) {
260 DestroyGC(current);
261 CreateGC(new);
262 return(TRUE);
264 return(FALSE);
267 /* Function Name: QueryGeometry.
268 * Description: Returns the preferred geometry for this widget.
269 * Arguments: w - the menu entry object.
270 * itended, return - the intended and return geometry info.
271 * Returns: A Geometry Result.
273 * See the Intrinsics manual for details on what this function is for.
275 * I just return the height and a width of 1.
278 static XtGeometryResult
279 QueryGeometry(w, intended, return_val)
280 Widget w;
281 XtWidgetGeometry *intended, *return_val;
283 SmeObject entry = (SmeObject) w;
284 Dimension width;
285 XtGeometryResult ret_val = XtGeometryYes;
286 XtGeometryMask mode = intended->request_mode;
288 width = 1; /* we can be really small. */
290 if ( ((mode & CWWidth) && (intended->width != width)) ||
291 !(mode & CWWidth) ) {
292 return_val->request_mode |= CWWidth;
293 return_val->width = width;
294 mode = return_val->request_mode;
296 if ( (mode & CWWidth) && (width == entry->rectangle.width) )
297 return(XtGeometryNo);
298 return(XtGeometryAlmost);
300 return(ret_val);