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