1/* 2Copyright 1989, 1994, 1998 The Open Group 3 4Permission to use, copy, modify, distribute, and sell this software and its 5documentation for any purpose is hereby granted without fee, provided that 6the above copyright notice appear in all copies and that both that 7copyright notice and this permission notice appear in supporting 8documentation. 9 10The above copyright notice and this permission notice shall be included in 11all copies or substantial portions of the Software. 12 13THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 17AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 20Except as contained in this notice, the name of The Open Group shall not be 21used in advertising or otherwise to promote the sale, use or other dealings 22in this Software without prior written authorization from The Open Group. 23 */ 24 25/* 26 * Date: September 26, 1989 27 * 28 * By: Chris D. Peterson 29 * MIT X Consortium 30 * kit@expo.lcs.mit.edu 31 */ 32 33#ifdef HAVE_CONFIG_H 34#include <config.h> 35#endif 36#include <stdio.h> 37#include <X11/IntrinsicP.h> 38#include <X11/StringDefs.h> 39#include <X11/Xaw/Cardinals.h> 40#include <X11/Xaw/SmeP.h> 41#include <X11/Xaw/XawInit.h> 42#include "Private.h" 43 44/* 45 * Class Methods 46 */ 47static void Highlight(Widget); 48static void Notify(Widget); 49static void Unhighlight(Widget); 50static void XawSmeClassPartInitialize(WidgetClass); 51static void XawSmeInitialize(Widget, Widget, ArgList, Cardinal*); 52static XtGeometryResult XawSmeQueryGeometry(Widget, XtWidgetGeometry*, 53 XtWidgetGeometry*); 54 55/* 56 * Initialization 57 */ 58#define offset(field) XtOffsetOf(SmeRec, sme.field) 59static XtResource resources[] = { 60 { 61 XtNcallback, 62 XtCCallback, 63 XtRCallback, 64 sizeof(XtPointer), 65 offset(callbacks), 66 XtRCallback, 67 NULL 68 }, 69 { 70 XtNinternational, 71 XtCInternational, 72 XtRBoolean, 73 sizeof(Boolean), 74 offset(international), 75 XtRImmediate, 76 (XtPointer)False 77 }, 78}; 79#undef offset 80 81#define Superclass (&rectObjClassRec) 82SmeClassRec smeClassRec = { 83 /* rectangle */ 84 { 85 (WidgetClass)Superclass, /* superclass */ 86 "Sme", /* class_name */ 87 sizeof(SmeRec), /* widget_size */ 88 XawInitializeWidgetSet, /* class_initialize */ 89 XawSmeClassPartInitialize, /* class_part_initialize */ 90 False, /* class_initialized */ 91 XawSmeInitialize, /* initialize */ 92 NULL, /* initialize_hook */ 93 NULL, /* realize */ 94 NULL, /* actions */ 95 0, /* num_actions */ 96 resources, /* resources */ 97 XtNumber(resources), /* num_resources */ 98 NULLQUARK, /* xrm_class */ 99 False, /* compress_motion */ 100 False, /* compress_exposure */ 101 False, /* compress_enterleave */ 102 False, /* visible_interest */ 103 NULL, /* destroy */ 104 NULL, /* resize */ 105 NULL, /* expose */ 106 NULL, /* set_values */ 107 NULL, /* set_values_hook */ 108 XtInheritSetValuesAlmost, /* set_values_almost */ 109 NULL, /* get_values_hook */ 110 NULL, /* accept_focus */ 111 XtVersion, /* intrinsics_version */ 112 NULL, /* callback offsets */ 113 NULL, /* tm_table */ 114 XawSmeQueryGeometry, /* query_geometry */ 115 NULL, /* display_accelerator */ 116 NULL, /* extension */ 117 }, 118 /* sme */ 119 { 120 Highlight, /* highlight */ 121 Unhighlight, /* unhighlight */ 122 Notify, /* notify */ 123 NULL, /* extension */ 124 } 125}; 126 127WidgetClass smeObjectClass = (WidgetClass)&smeClassRec; 128 129/* 130 * Implementation 131 */ 132/* 133 * Function: 134 * XawSmeClassPartInitialize 135 * 136 * Parameters: 137 * cclass - widget class of this widget 138 * 139 * Description: 140 * Handles inheritance of class functions. 141 */ 142static void 143XawSmeClassPartInitialize(WidgetClass cclass) 144{ 145 SmeObjectClass m_ent, superC; 146 147 m_ent = (SmeObjectClass)cclass; 148 superC = (SmeObjectClass)m_ent->rect_class.superclass; 149 150 if (m_ent->sme_class.highlight == XtInheritHighlight) 151 m_ent->sme_class.highlight = superC->sme_class.highlight; 152 153 if (m_ent->sme_class.unhighlight == XtInheritUnhighlight) 154 m_ent->sme_class.unhighlight = superC->sme_class.unhighlight; 155 156 if (m_ent->sme_class.notify == XtInheritNotify) 157 m_ent->sme_class.notify = superC->sme_class.notify; 158} 159 160/* 161 * Function: 162 * XawSmeInitialize 163 * 164 * Parameters: 165 * request - widget requested by the argument list 166 * cnew - new widget with both resource and non resource values 167 * 168 * Description: 169 * Initializes the simple menu widget entry 170 */ 171/*ARGSUSED*/ 172static void 173XawSmeInitialize(Widget request _X_UNUSED, Widget cnew, 174 ArgList args _X_UNUSED, Cardinal *num_args _X_UNUSED) 175{ 176 SmeObject entry = (SmeObject)cnew; 177 178 entry->rectangle.border_width = 0; 179} 180 181/* 182 * Function: 183 * Highlight 184 * 185 * Parameters: 186 * w - menu entry 187 * 188 * Description: 189 * Default highlight procedure for menu entries. 190 */ 191/*ARGSUSED*/ 192static void 193Highlight(Widget w _X_UNUSED) 194{ 195} 196 197/* 198 * Function: 199 * Unhighlight 200 * 201 * Parameters: 202 * w - menu entry 203 * 204 * Description: 205 * Default unhighlight procedure for menu entries. 206 */ 207/*ARGSUSED*/ 208static void 209Unhighlight(Widget w _X_UNUSED) 210{ 211} 212 213/* 214 * Function: 215 * Notify 216 * 217 * Parameters: 218 * w - menu entry 219 * 220 * Description: 221 * Calls the callback procedures for this entry. 222 */ 223static void 224Notify(Widget w) 225{ 226 XtCallCallbacks(w, XtNcallback, NULL); 227} 228 229/* 230 * Function: 231 * QueryGeometry 232 * 233 * Parameeters: 234 * w - menu entry object 235 * itended - intended and return geometry info 236 * return_val - 237 * 238 * Description: 239 * Returns the preferred geometry for this widget. 240 * 241 * Returns: 242 * Geometry Result 243 * 244 * Note: 245 * See the Intrinsics manual for details on what this function is for. 246 */ 247static XtGeometryResult 248XawSmeQueryGeometry(Widget w, XtWidgetGeometry *intended, 249 XtWidgetGeometry *return_val) 250{ 251 SmeObject entry = (SmeObject)w; 252 Dimension width; 253 XtGeometryResult ret_val = XtGeometryYes; 254 XtGeometryMask mode = intended->request_mode; 255 256 width = 1; 257 258 if (((mode & CWWidth) && intended->width != width) || !(mode & CWWidth)) { 259 return_val->request_mode |= CWWidth; 260 return_val->width = width; 261 mode = return_val->request_mode; 262 263 if ((mode & CWWidth) && width == XtWidth(entry)) 264 return (XtGeometryNo); 265 return (XtGeometryAlmost); 266 } 267 268 return (ret_val); 269} 270