1 /* (from) $XConsortium: Sme.c,v 1.9 91/02/17 16:44:14 rws Exp $ */
2
3 /*
4 * Copyright (c) 1995-2009, 2014 Paul Mattes.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * * Neither the name of Paul Mattes nor his contributors may be used
16 * to endorse or promote products derived from this software without
17 * specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY PAUL MATTES "AS IS" AND ANY EXPRESS
20 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL PAUL MATTES BE LIABLE FOR ANY DIRECT,
23 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
28 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 *
31 * Copyright 1989 Massachusetts Institute of Technology
32 *
33 * Permission to use, copy, modify, distribute, and sell this software and its
34 * documentation for any purpose is hereby granted without fee, provided that
35 * the above copyright notice appear in all copies and that both that
36 * copyright notice and this permission notice appear in supporting
37 * documentation, and that the name of M.I.T. not be used in advertising or
38 * publicity pertaining to distribution of the software without specific,
39 * written prior permission. M.I.T. makes no representations about the
40 * suitability of this software for any purpose. It is provided "as is"
41 * without express or implied warranty.
42 *
43 * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
44 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
45 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
46 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
47 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
48 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
49 */
50
51 /*
52 * Cme.c - Source code for the generic menu entry
53 * (from) Sme.c - Source code for the generic menu entry
54 *
55 * Date: September 26, 1989
56 *
57 * By: Chris D. Peterson
58 * MIT X Consortium
59 * kit@expo.lcs.mit.edu
60 */
61
62 #include "globals.h"
63
64 #include <stdio.h>
65 #include <X11/IntrinsicP.h>
66 #include <X11/StringDefs.h>
67
68 #include <X11/Xaw/XawInit.h>
69 #include "CmeP.h"
70 #include <X11/Xaw/Cardinals.h>
71
72 #define offset(field) XtOffsetOf(CmeRec, cme.field)
73 static XtResource resources[] = {
74 {XtNcallback, XtCCallback, XtRCallback, sizeof(XtPointer),
75 offset(callbacks), XtRCallback, NULL},
76 };
77 #undef offset
78
79 /*
80 * Semi Public function definitions.
81 */
82
83 static void Highlight(Widget);
84 static void Unhighlight(Widget);
85 static void Notify(Widget);
86 static void ClassPartInitialize(WidgetClass);
87 static void Initialize(Widget, Widget, ArgList, Cardinal *);
88 static XtGeometryResult QueryGeometry(Widget, XtWidgetGeometry *,
89 XtWidgetGeometry *);
90
91 #define SUPERCLASS (&rectObjClassRec)
92
93 CmeClassRec cmeClassRec = {
94 {
95 /* superclass */ (WidgetClass) SUPERCLASS,
96 /* class_name */ "Cme",
97 /* size */ sizeof(CmeRec),
98 /* class_initialize */ XawInitializeWidgetSet,
99 /* class_part_initialize*/ ClassPartInitialize,
100 /* Class init'ed */ FALSE,
101 /* initialize */ Initialize,
102 /* initialize_hook */ NULL,
103 /* realize */ NULL,
104 /* actions */ NULL,
105 /* num_actions */ ZERO,
106 /* resources */ resources,
107 /* resource_count */ XtNumber(resources),
108 /* xrm_class */ NULLQUARK,
109 /* compress_motion */ FALSE,
110 /* compress_exposure */ FALSE,
111 /* compress_enterleave*/ FALSE,
112 /* visible_interest */ FALSE,
113 /* destroy */ NULL,
114 /* resize */ NULL,
115 /* expose */ NULL,
116 /* set_values */ NULL,
117 /* set_values_hook */ NULL,
118 /* set_values_almost */ XtInheritSetValuesAlmost,
119 /* get_values_hook */ NULL,
120 /* accept_focus */ NULL,
121 /* intrinsics version */ XtVersion,
122 /* callback offsets */ NULL,
123 /* tm_table */ NULL,
124 /* query_geometry */ QueryGeometry,
125 /* display_accelerator*/ NULL,
126 /* extension */ NULL
127 },{
128 /* Complex Menu Entry Fields */
129
130 /* highlight */ Highlight,
131 /* unhighlight */ Unhighlight,
132 /* notify */ Notify,
133 /* extension */ NULL
134 }
135 };
136
137 WidgetClass cmeObjectClass = (WidgetClass) &cmeClassRec;
138
139 /************************************************************
140 *
141 * Semi-Public Functions.
142 *
143 ************************************************************/
144
145 /* Function Name: ClassPartInitialize
146 * Description: handles inheritance of class functions.
147 * Arguments: class - the widget classs of this widget.
148 * Returns: none.
149 */
150
151 static void
ClassPartInitialize(WidgetClass class)152 ClassPartInitialize(WidgetClass class)
153 {
154 CmeObjectClass m_ent, superC;
155
156 m_ent = (CmeObjectClass) class;
157 superC = (CmeObjectClass) m_ent->rect_class.superclass;
158
159 /*
160 * We don't need to check for null super since we'll get to TextSink
161 * eventually.
162 */
163
164 if (m_ent->cme_class.highlight == XtInheritHighlight)
165 m_ent->cme_class.highlight = superC->cme_class.highlight;
166
167 if (m_ent->cme_class.unhighlight == XtInheritUnhighlight)
168 m_ent->cme_class.unhighlight = superC->cme_class.unhighlight;
169
170 if (m_ent->cme_class.notify == XtInheritNotify)
171 m_ent->cme_class.notify = superC->cme_class.notify;
172 }
173
174 /* Function Name: Initialize
175 * Description: Initializes the complex menu widget
176 * Arguments: request - the widget requested by the argument list.
177 * new - the new widget with both resource and non
178 * resource values.
179 * Returns: none.
180 *
181 * MENU ENTRIES CANNOT HAVE BORDERS.
182 */
183
184 static void
Initialize(Widget request _is_unused,Widget new,ArgList args _is_unused,Cardinal * num_args _is_unused)185 Initialize(Widget request _is_unused, Widget new, ArgList args _is_unused,
186 Cardinal *num_args _is_unused)
187 {
188 CmeObject entry = (CmeObject) new;
189
190 entry->rectangle.border_width = 0;
191 }
192
193 /* Function Name: Highlight
194 * Description: The default highlight proceedure for menu entries.
195 * Arguments: w - the menu entry.
196 * Returns: none.
197 */
198
199 static void
Highlight(Widget w _is_unused)200 Highlight(Widget w _is_unused)
201 {
202 /* This space intentionally left blank. */
203 }
204
205 /* Function Name: Unhighlight
206 * Description: The default unhighlight proceedure for menu entries.
207 * Arguments: w - the menu entry.
208 * Returns: none.
209 */
210
211 static void
Unhighlight(Widget w _is_unused)212 Unhighlight(Widget w _is_unused)
213 {
214 /* This space intentionally left blank. */
215 }
216
217 /* Function Name: Notify
218 * Description: calls the callback proceedures for this entry.
219 * Arguments: w - the menu entry.
220 * Returns: none.
221 */
222
223 static void
Notify(Widget w)224 Notify(Widget w)
225 {
226 XtCallCallbacks(w, XtNcallback, NULL);
227 }
228
229 /* Function Name: QueryGeometry.
230 * Description: Returns the preferred geometry for this widget.
231 * Arguments: w - the menu entry object.
232 * itended, return - the intended and return geometry info.
233 * Returns: A Geometry Result.
234 *
235 * See the Intrinsics manual for details on what this function is for.
236 *
237 * I just return the height and a width of 1.
238 */
239
240 static XtGeometryResult
QueryGeometry(Widget w,XtWidgetGeometry * intended,XtWidgetGeometry * return_val)241 QueryGeometry(Widget w, XtWidgetGeometry *intended,
242 XtWidgetGeometry *return_val)
243 {
244 CmeObject entry = (CmeObject) w;
245 Dimension width;
246 XtGeometryResult ret_val = XtGeometryYes;
247 XtGeometryMask mode = intended->request_mode;
248
249 width = 1; /* we can be really small. */
250
251 if ( ((mode & CWWidth) && (intended->width != width)) ||
252 !(mode & CWWidth) ) {
253 return_val->request_mode |= CWWidth;
254 return_val->width = width;
255 mode = return_val->request_mode;
256
257 if ( (mode & CWWidth) && (width == entry->rectangle.width) )
258 return(XtGeometryNo);
259 return(XtGeometryAlmost);
260 }
261 return(ret_val);
262 }
263