1 | /* (from) $XConsortium: SmeLine.c,v 1.13 91/07/23 12:23:21 rws Exp $ */ |
---|
2 | |
---|
3 | /* |
---|
4 | * Modifications Copyright 1995 by Paul Mattes. |
---|
5 | * Permission to use, copy, modify, and distribute this software and its |
---|
6 | * documentation for any purpose and without fee is hereby granted, |
---|
7 | * provided that the above copyright notice appear in all copies and that |
---|
8 | * both that copyright notice and this permission notice appear in |
---|
9 | * supporting documentation. |
---|
10 | * |
---|
11 | * Copyright 1989 Massachusetts Institute of Technology |
---|
12 | * |
---|
13 | * Permission to use, copy, modify, distribute, and sell this software and its |
---|
14 | * documentation for any purpose is hereby granted without fee, provided that |
---|
15 | * the above copyright notice appear in all copies and that both that |
---|
16 | * copyright notice and this permission notice appear in supporting |
---|
17 | * documentation, and that the name of M.I.T. not be used in advertising or |
---|
18 | * publicity pertaining to distribution of the software without specific, |
---|
19 | * written prior permission. M.I.T. makes no representations about the |
---|
20 | * suitability of this software for any purpose. It is provided "as is" |
---|
21 | * without express or implied warranty. |
---|
22 | * |
---|
23 | * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL |
---|
24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T. |
---|
25 | * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
---|
26 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
---|
27 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
---|
28 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
---|
29 | * |
---|
30 | * Author: Chris D. Peterson, MIT X Consortium |
---|
31 | */ |
---|
32 | |
---|
33 | /* |
---|
34 | * Cme.c - Source code for the generic menu entry |
---|
35 | * (from) Sme.c - Source code for the generic menu entry |
---|
36 | * |
---|
37 | * Date: September 26, 1989 |
---|
38 | * |
---|
39 | * By: Chris D. Peterson |
---|
40 | * MIT X Consortium |
---|
41 | * kit@expo.lcs.mit.edu |
---|
42 | */ |
---|
43 | |
---|
44 | #include <stdio.h> |
---|
45 | #include <X11/IntrinsicP.h> |
---|
46 | #include <X11/StringDefs.h> |
---|
47 | |
---|
48 | #include <X11/Xaw/XawInit.h> |
---|
49 | #include "CmeLineP.h" |
---|
50 | #include <X11/Xaw/Cardinals.h> |
---|
51 | |
---|
52 | #define offset(field) XtOffsetOf(CmeLineRec, cme_line.field) |
---|
53 | static XtResource resources[] = { |
---|
54 | {XtNlineWidth, XtCLineWidth, XtRDimension, sizeof(Dimension), |
---|
55 | offset(line_width), XtRImmediate, (XtPointer) 1}, |
---|
56 | {XtNstipple, XtCStipple, XtRBitmap, sizeof(Pixmap), |
---|
57 | offset(stipple), XtRImmediate, (XtPointer) XtUnspecifiedPixmap}, |
---|
58 | {XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel), |
---|
59 | offset(foreground), XtRString, XtDefaultForeground}, |
---|
60 | }; |
---|
61 | #undef offset |
---|
62 | |
---|
63 | /* |
---|
64 | * Function definitions. |
---|
65 | */ |
---|
66 | |
---|
67 | static void Redisplay(), Initialize(); |
---|
68 | static void DestroyGC(), CreateGC(); |
---|
69 | static Boolean SetValues(); |
---|
70 | static XtGeometryResult QueryGeometry(); |
---|
71 | |
---|
72 | |
---|
73 | #define SUPERCLASS (&cmeClassRec) |
---|
74 | |
---|
75 | CmeLineClassRec cmeLineClassRec = { |
---|
76 | { |
---|
77 | /* superclass */ (WidgetClass) SUPERCLASS, |
---|
78 | /* class_name */ "CmeLine", |
---|
79 | /* size */ sizeof(CmeLineRec), |
---|
80 | /* class_initialize */ XawInitializeWidgetSet, |
---|
81 | /* class_part_initialize*/ NULL, |
---|
82 | /* Class init'ed */ FALSE, |
---|
83 | /* initialize */ Initialize, |
---|
84 | /* initialize_hook */ NULL, |
---|
85 | /* realize */ NULL, |
---|
86 | /* actions */ NULL, |
---|
87 | /* num_actions */ ZERO, |
---|
88 | /* resources */ resources, |
---|
89 | /* resource_count */ XtNumber(resources), |
---|
90 | /* xrm_class */ NULLQUARK, |
---|
91 | /* compress_motion */ FALSE, |
---|
92 | /* compress_exposure */ FALSE, |
---|
93 | /* compress_enterleave*/ FALSE, |
---|
94 | /* visible_interest */ FALSE, |
---|
95 | /* destroy */ DestroyGC, |
---|
96 | /* resize */ NULL, |
---|
97 | /* expose */ Redisplay, |
---|
98 | /* set_values */ SetValues, |
---|
99 | /* set_values_hook */ NULL, |
---|
100 | /* set_values_almost */ XtInheritSetValuesAlmost, |
---|
101 | /* get_values_hook */ NULL, |
---|
102 | /* accept_focus */ NULL, |
---|
103 | /* intrinsics version */ XtVersion, |
---|
104 | /* callback offsets */ NULL, |
---|
105 | /* tm_table */ NULL, |
---|
106 | /* query_geometry */ QueryGeometry, |
---|
107 | /* display_accelerator*/ NULL, |
---|
108 | /* extension */ NULL |
---|
109 | },{ |
---|
110 | /* Menu Entry Fields */ |
---|
111 | |
---|
112 | /* highlight */ XtInheritHighlight, |
---|
113 | /* unhighlight */ XtInheritUnhighlight, |
---|
114 | /* notify */ XtInheritNotify, |
---|
115 | /* extension */ NULL |
---|
116 | },{ |
---|
117 | /* Line Menu Entry Fields */ |
---|
118 | /* extension */ NULL |
---|
119 | } |
---|
120 | }; |
---|
121 | |
---|
122 | WidgetClass cmeLineObjectClass = (WidgetClass) &cmeLineClassRec; |
---|
123 | |
---|
124 | /************************************************************ |
---|
125 | * |
---|
126 | * Semi-Public Functions. |
---|
127 | * |
---|
128 | ************************************************************/ |
---|
129 | |
---|
130 | /* Function Name: Initialize |
---|
131 | * Description: Initializes the complex menu widget |
---|
132 | * Arguments: request - the widget requested by the argument list. |
---|
133 | * new - the new widget with both resource and non |
---|
134 | * resource values. |
---|
135 | * Returns: none. |
---|
136 | */ |
---|
137 | |
---|
138 | /* ARGSUSED */ |
---|
139 | static void |
---|
140 | Initialize(request, new) |
---|
141 | Widget request, new; |
---|
142 | { |
---|
143 | CmeLineObject entry = (CmeLineObject) new; |
---|
144 | |
---|
145 | if (entry->rectangle.height == 0) |
---|
146 | entry->rectangle.height = entry->cme_line.line_width; |
---|
147 | |
---|
148 | CreateGC(new); |
---|
149 | } |
---|
150 | |
---|
151 | /* Function Name: CreateGC |
---|
152 | * Description: Creates the GC for the line entry widget. |
---|
153 | * Arguments: w - the Line entry widget. |
---|
154 | * Returns: none |
---|
155 | * |
---|
156 | * We can only share the GC if there is no stipple, because |
---|
157 | * we need to change the stipple origin when drawing. |
---|
158 | */ |
---|
159 | |
---|
160 | static void |
---|
161 | CreateGC(w) |
---|
162 | Widget w; |
---|
163 | { |
---|
164 | CmeLineObject entry = (CmeLineObject) w; |
---|
165 | XGCValues values; |
---|
166 | XtGCMask mask = GCForeground | GCGraphicsExposures | GCLineWidth ; |
---|
167 | |
---|
168 | values.foreground = entry->cme_line.foreground; |
---|
169 | values.graphics_exposures = FALSE; |
---|
170 | values.line_width = entry->cme_line.line_width; |
---|
171 | |
---|
172 | if (entry->cme_line.stipple != XtUnspecifiedPixmap) { |
---|
173 | values.stipple = entry->cme_line.stipple; |
---|
174 | values.fill_style = FillStippled; |
---|
175 | mask |= GCStipple | GCFillStyle; |
---|
176 | |
---|
177 | entry->cme_line.gc = XCreateGC(XtDisplayOfObject(w), |
---|
178 | RootWindowOfScreen(XtScreenOfObject(w)), |
---|
179 | mask, &values); |
---|
180 | } |
---|
181 | else |
---|
182 | entry->cme_line.gc = XtGetGC(w, mask, &values); |
---|
183 | } |
---|
184 | |
---|
185 | /* Function Name: DestroyGC |
---|
186 | * Description: Destroys the GC when we are done with it. |
---|
187 | * Arguments: w - the Line entry widget. |
---|
188 | * Returns: none |
---|
189 | */ |
---|
190 | |
---|
191 | static void |
---|
192 | DestroyGC(w) |
---|
193 | Widget w; |
---|
194 | { |
---|
195 | CmeLineObject entry = (CmeLineObject) w; |
---|
196 | |
---|
197 | if (entry->cme_line.stipple != XtUnspecifiedPixmap) |
---|
198 | XFreeGC(XtDisplayOfObject(w), entry->cme_line.gc); |
---|
199 | else |
---|
200 | XtReleaseGC(w, entry->cme_line.gc); |
---|
201 | } |
---|
202 | |
---|
203 | /* Function Name: Redisplay |
---|
204 | * Description: Paints the Line |
---|
205 | * Arguments: w - the menu entry. |
---|
206 | * event, region - NOT USED. |
---|
207 | * Returns: none |
---|
208 | */ |
---|
209 | |
---|
210 | /*ARGSUSED*/ |
---|
211 | static void |
---|
212 | Redisplay(w, event, region) |
---|
213 | Widget w; |
---|
214 | XEvent * event; |
---|
215 | Region region; |
---|
216 | { |
---|
217 | CmeLineObject entry = (CmeLineObject) w; |
---|
218 | int y = entry->rectangle.y + |
---|
219 | (int)(entry->rectangle.height - entry->cme_line.line_width) / 2; |
---|
220 | |
---|
221 | if (entry->cme_line.stipple != XtUnspecifiedPixmap) |
---|
222 | XSetTSOrigin(XtDisplayOfObject(w), entry->cme_line.gc, 0, y); |
---|
223 | |
---|
224 | XFillRectangle(XtDisplayOfObject(w), XtWindowOfObject(w), |
---|
225 | entry->cme_line.gc, |
---|
226 | 0, y, (unsigned int) entry->rectangle.width, |
---|
227 | (unsigned int) entry->cme_line.line_width ); |
---|
228 | } |
---|
229 | |
---|
230 | /* Function Name: SetValues |
---|
231 | * Description: Relayout the menu when one of the resources is changed. |
---|
232 | * Arguments: current - current state of the widget. |
---|
233 | * request - what was requested. |
---|
234 | * new - what the widget will become. |
---|
235 | * Returns: none |
---|
236 | */ |
---|
237 | |
---|
238 | /* ARGSUSED */ |
---|
239 | static Boolean |
---|
240 | SetValues(current, request, new) |
---|
241 | Widget current, request, new; |
---|
242 | { |
---|
243 | CmeLineObject entry = (CmeLineObject) new; |
---|
244 | CmeLineObject old_entry = (CmeLineObject) current; |
---|
245 | |
---|
246 | if ( (entry->cme_line.line_width != old_entry->cme_line.line_width) && |
---|
247 | (entry->cme_line.stipple != old_entry->cme_line.stipple) ) { |
---|
248 | DestroyGC(current); |
---|
249 | CreateGC(new); |
---|
250 | return(TRUE); |
---|
251 | } |
---|
252 | return(FALSE); |
---|
253 | } |
---|
254 | |
---|
255 | /* Function Name: QueryGeometry. |
---|
256 | * Description: Returns the preferred geometry for this widget. |
---|
257 | * Arguments: w - the menu entry object. |
---|
258 | * itended, return - the intended and return geometry info. |
---|
259 | * Returns: A Geometry Result. |
---|
260 | * |
---|
261 | * See the Intrinsics manual for details on what this function is for. |
---|
262 | * |
---|
263 | * I just return the height and a width of 1. |
---|
264 | */ |
---|
265 | |
---|
266 | static XtGeometryResult |
---|
267 | QueryGeometry(w, intended, return_val) |
---|
268 | Widget w; |
---|
269 | XtWidgetGeometry *intended, *return_val; |
---|
270 | { |
---|
271 | CmeObject entry = (CmeObject) w; |
---|
272 | Dimension width; |
---|
273 | XtGeometryResult ret_val = XtGeometryYes; |
---|
274 | XtGeometryMask mode = intended->request_mode; |
---|
275 | |
---|
276 | width = 1; /* we can be really small. */ |
---|
277 | |
---|
278 | if ( ((mode & CWWidth) && (intended->width != width)) || |
---|
279 | !(mode & CWWidth) ) { |
---|
280 | return_val->request_mode |= CWWidth; |
---|
281 | return_val->width = width; |
---|
282 | mode = return_val->request_mode; |
---|
283 | |
---|
284 | if ( (mode & CWWidth) && (width == entry->rectangle.width) ) |
---|
285 | return(XtGeometryNo); |
---|
286 | return(XtGeometryAlmost); |
---|
287 | } |
---|
288 | return(ret_val); |
---|
289 | } |
---|