Vendor.c revision 7a84e134
1/* $Xorg: Vendor.c,v 1.4 2001/02/09 02:03:47 xorgcvs Exp $ */ 2 3/*********************************************************** 4 5Copyright 1987, 1988, 1994, 1998 The Open Group 6 7Permission to use, copy, modify, distribute, and sell this software and its 8documentation for any purpose is hereby granted without fee, provided that 9the above copyright notice appear in all copies and that both that 10copyright notice and this permission notice appear in supporting 11documentation. 12 13The above copyright notice and this permission notice shall be included in 14all copies or substantial portions of the Software. 15 16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 20AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 23Except as contained in this notice, the name of The Open Group shall not be 24used in advertising or otherwise to promote the sale, use or other dealings 25in this Software without prior written authorization from The Open Group. 26 27 28Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts. 29 30 All Rights Reserved 31 32Permission to use, copy, modify, and distribute this software and its 33documentation for any purpose and without fee is hereby granted, 34provided that the above copyright notice appear in all copies and that 35both that copyright notice and this permission notice appear in 36supporting documentation, and that the name of Digital not be 37used in advertising or publicity pertaining to distribution of the 38software without specific, written prior permission. 39 40DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 41ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 42DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 43ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 44WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 45ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 46SOFTWARE. 47 48******************************************************************/ 49/* $XFree86: xc/lib/Xaw/Vendor.c,v 1.8 2001/12/14 19:54:45 dawes Exp $ */ 50 51/* 52 * This is a copy of Xt/Vendor.c with an additional ClassInitialize 53 * procedure to register Xmu resource type converters, and all the 54 * monkey business associated with input methods... 55 * 56 */ 57 58/* Make sure all wm properties can make it out of the resource manager */ 59 60#ifdef HAVE_CONFIG_H 61#include <config.h> 62#endif 63#include <stdio.h> 64#include <X11/IntrinsicP.h> 65#include <X11/StringDefs.h> 66#include <X11/ShellP.h> 67#include <X11/VendorP.h> 68#include <X11/Xmu/Converters.h> 69#include <X11/Xmu/Atoms.h> 70#include <X11/Xmu/Editres.h> 71#include <X11/Xmu/ExtAgent.h> 72 73/* The following two headers are for the input method. */ 74 75#include <X11/Xaw/VendorEP.h> 76#include <X11/Xaw/XawImP.h> 77 78/* 79 * Class Methods 80 */ 81static void XawVendorShellChangeManaged(Widget); 82static Boolean XawCvtCompoundTextToString(Display*, XrmValuePtr, Cardinal*, 83 XrmValue*, XrmValue*, XtPointer*); 84static void XawVendorShellClassInitialize(void); 85static XtGeometryResult XawVendorShellGeometryManager(Widget, 86 XtWidgetGeometry*, 87 XtWidgetGeometry*); 88static void XawVendorShellExtClassInitialize(void); 89static void XawVendorShellExtDestroy(Widget); 90static void XawVendorShellExtInitialize(Widget, Widget, ArgList, Cardinal*); 91void XawVendorShellExtResize(Widget); 92static Boolean XawVendorShellExtSetValues(Widget, Widget, Widget, 93 ArgList, Cardinal*); 94static void XawVendorShellClassPartInit(WidgetClass); 95static void XawVendorShellInitialize(Widget, Widget, ArgList, Cardinal*); 96static void XawVendorShellRealize(Widget, Mask*, XSetWindowAttributes*); 97static Boolean XawVendorShellSetValues(Widget, Widget, Widget, 98 ArgList, Cardinal*); 99 100/* 101 * External 102 */ 103void XawVendorStructureNotifyHandler(Widget, XtPointer, XEvent*, Boolean*); 104 105static XtResource resources[] = { 106 {XtNinput, XtCInput, XtRBool, sizeof(Bool), 107 XtOffsetOf(VendorShellRec, wm.wm_hints.input), 108 XtRImmediate, (XtPointer)True} 109}; 110 111/*************************************************************************** 112 * 113 * Vendor shell class record 114 * 115 ***************************************************************************/ 116 117#if defined(__UNIXOS2__) || defined(__CYGWIN__) 118/* to fix the EditRes problem because of wrong linker semantics */ 119extern WidgetClass vendorShellWidgetClass; /* from Xt/Vendor.c */ 120extern VendorShellClassRec _XawVendorShellClassRec; 121extern void _XawFixupVendorShell(); 122 123#if defined(__UNIXOS2__) 124unsigned long _DLL_InitTerm(unsigned long mod,unsigned long flag) 125{ 126 switch (flag) { 127 case 0: /*called on init*/ 128 _CRT_init(); 129 vendorShellWidgetClass = (WidgetClass)(&_XawVendorShellClassRec); 130 _XawFixupVendorShell(); 131 return 1; 132 case 1: /*called on exit*/ 133 return 1; 134 default: 135 return 0; 136 } 137} 138#endif 139 140#if defined(__CYGWIN__) 141int __stdcall 142DllMain(unsigned long mod_handle, unsigned long flag, void *routine) 143{ 144 switch (flag) 145 { 146 case 1: /* DLL_PROCESS_ATTACH - process attach */ 147 vendorShellWidgetClass = (WidgetClass)(&_XawVendorShellClassRec); 148 _XawFixupVendorShell(); 149 break; 150 case 0: /* DLL_PROCESS_DETACH - process detach */ 151 break; 152 } 153 return 1; 154} 155#endif 156 157#define vendorShellClassRec _XawVendorShellClassRec 158 159#endif 160 161static CompositeClassExtensionRec vendorCompositeExt = { 162 /* next_extension */ NULL, 163 /* record_type */ NULLQUARK, 164 /* version */ XtCompositeExtensionVersion, 165 /* record_size */ sizeof (CompositeClassExtensionRec), 166 /* accepts_objects */ TRUE, 167 /* allows_change_managed_set */ FALSE 168}; 169 170#define SuperClass (&wmShellClassRec) 171externaldef(vendorshellclassrec) VendorShellClassRec vendorShellClassRec = { 172 { 173 /* superclass */ (WidgetClass)SuperClass, 174 /* class_name */ "VendorShell", 175 /* size */ sizeof(VendorShellRec), 176 /* class_initialize */ XawVendorShellClassInitialize, 177 /* class_part_init */ XawVendorShellClassPartInit, 178 /* Class init'ed ? */ FALSE, 179 /* initialize */ XawVendorShellInitialize, 180 /* initialize_hook */ NULL, 181 /* realize */ XawVendorShellRealize, 182 /* actions */ NULL, 183 /* num_actions */ 0, 184 /* resources */ resources, 185 /* resource_count */ XtNumber(resources), 186 /* xrm_class */ NULLQUARK, 187 /* compress_motion */ FALSE, 188 /* compress_exposure */ TRUE, 189 /* compress_enterleave*/ FALSE, 190 /* visible_interest */ FALSE, 191 /* destroy */ NULL, 192 /* resize */ XawVendorShellExtResize, 193 /* expose */ NULL, 194 /* set_values */ XawVendorShellSetValues, 195 /* set_values_hook */ NULL, 196 /* set_values_almost */ XtInheritSetValuesAlmost, 197 /* get_values_hook */ NULL, 198 /* accept_focus */ NULL, 199 /* intrinsics version */ XtVersion, 200 /* callback offsets */ NULL, 201 /* tm_table */ NULL, 202 /* query_geometry */ NULL, 203 /* display_accelerator*/ NULL, 204 /* extension */ NULL 205 },{ 206 /* geometry_manager */ XawVendorShellGeometryManager, 207 /* change_managed */ XawVendorShellChangeManaged, 208 /* insert_child */ XtInheritInsertChild, 209 /* delete_child */ XtInheritDeleteChild, 210 /* extension */ (XtPointer) &vendorCompositeExt 211 },{ 212 /* extension */ NULL 213 },{ 214 /* extension */ NULL 215 },{ 216 /* extension */ NULL 217 } 218}; 219 220#ifndef __UNIXOS2__ 221externaldef(vendorshellwidgetclass) WidgetClass vendorShellWidgetClass = 222 (WidgetClass) (&vendorShellClassRec); 223#endif 224 225/*************************************************************************** 226 * 227 * The following section is for the Vendor shell Extension class record 228 * 229 ***************************************************************************/ 230 231static XtResource ext_resources[] = { 232 {XtNinputMethod, XtCInputMethod, XtRString, sizeof(String), 233 XtOffsetOf(XawVendorShellExtRec, vendor_ext.im.input_method), 234 XtRString, (XtPointer)NULL}, 235 {XtNpreeditType, XtCPreeditType, XtRString, sizeof(String), 236 XtOffsetOf(XawVendorShellExtRec, vendor_ext.im.preedit_type), 237 XtRString, (XtPointer)"OverTheSpot,OffTheSpot,Root"}, 238 {XtNopenIm, XtCOpenIm, XtRBoolean, sizeof(Boolean), 239 XtOffsetOf(XawVendorShellExtRec, vendor_ext.im.open_im), 240 XtRImmediate, (XtPointer)TRUE}, 241 {XtNsharedIc, XtCSharedIc, XtRBoolean, sizeof(Boolean), 242 XtOffsetOf(XawVendorShellExtRec, vendor_ext.ic.shared_ic), 243 XtRImmediate, (XtPointer)FALSE} 244}; 245 246externaldef(vendorshellextclassrec) XawVendorShellExtClassRec 247 xawvendorShellExtClassRec = { 248 { 249 /* superclass */ (WidgetClass)&objectClassRec, 250 /* class_name */ "VendorShellExt", 251 /* size */ sizeof(XawVendorShellExtRec), 252 /* class_initialize */ XawVendorShellExtClassInitialize, 253 /* class_part_initialize*/ NULL, 254 /* Class init'ed ? */ FALSE, 255 /* initialize */ XawVendorShellExtInitialize, 256 /* initialize_hook */ NULL, 257 /* pad */ NULL, 258 /* pad */ NULL, 259 /* pad */ 0, 260 /* resources */ ext_resources, 261 /* resource_count */ XtNumber(ext_resources), 262 /* xrm_class */ NULLQUARK, 263 /* pad */ FALSE, 264 /* pad */ FALSE, 265 /* pad */ FALSE, 266 /* pad */ FALSE, 267 /* destroy */ XawVendorShellExtDestroy, 268 /* pad */ NULL, 269 /* pad */ NULL, 270 /* set_values */ XawVendorShellExtSetValues, 271 /* set_values_hook */ NULL, 272 /* pad */ NULL, 273 /* get_values_hook */ NULL, 274 /* pad */ NULL, 275 /* version */ XtVersion, 276 /* callback_offsets */ NULL, 277 /* pad */ NULL, 278 /* pad */ NULL, 279 /* pad */ NULL, 280 /* extension */ NULL 281 },{ 282 /* extension */ NULL 283 } 284}; 285 286externaldef(xawvendorshellwidgetclass) WidgetClass 287 xawvendorShellExtWidgetClass = (WidgetClass) (&xawvendorShellExtClassRec); 288 289 290/*ARGSUSED*/ 291static Boolean 292XawCvtCompoundTextToString(Display *dpy, XrmValuePtr args, Cardinal *num_args, 293 XrmValue *fromVal, XrmValue *toVal, 294 XtPointer *cvt_data) 295{ 296 XTextProperty prop; 297 char **list; 298 int count; 299 static char *mbs = NULL; 300 int len; 301 302 prop.value = (unsigned char *)fromVal->addr; 303 prop.encoding = XA_COMPOUND_TEXT(dpy); 304 prop.format = 8; 305 prop.nitems = fromVal->size; 306 307 if(XmbTextPropertyToTextList(dpy, &prop, &list, &count) < Success) { 308 XtAppWarningMsg(XtDisplayToApplicationContext(dpy), 309 "converter", "XmbTextPropertyToTextList", "XawError", 310 "conversion from CT to MB failed.", NULL, 0); 311 return False; 312 } 313 len = strlen(*list); 314 toVal->size = len; 315 mbs = XtRealloc(mbs, len + 1); /* keep buffer because no one call free :( */ 316 strcpy(mbs, *list); 317 XFreeStringList(list); 318 toVal->addr = (XtPointer)mbs; 319 return True; 320} 321 322static void 323XawVendorShellClassInitialize(void) 324{ 325 static XtConvertArgRec screenConvertArg[] = { 326 {XtWidgetBaseOffset, (XtPointer) XtOffsetOf(WidgetRec, core.screen), 327 sizeof(Screen *)} 328 }; 329 330 XtAddConverter(XtRString, XtRCursor, XmuCvtStringToCursor, 331 screenConvertArg, XtNumber(screenConvertArg)); 332 333 XtAddConverter(XtRString, XtRBitmap, XmuCvtStringToBitmap, 334 screenConvertArg, XtNumber(screenConvertArg)); 335 336 XtSetTypeConverter("CompoundText", XtRString, XawCvtCompoundTextToString, 337 NULL, 0, XtCacheNone, NULL); 338} 339 340static void 341XawVendorShellClassPartInit(WidgetClass cclass) 342{ 343 CompositeClassExtension ext; 344 VendorShellWidgetClass vsclass = (VendorShellWidgetClass)cclass; 345 346 if ((ext = (CompositeClassExtension) 347 XtGetClassExtension (cclass, 348 XtOffsetOf(CompositeClassRec, 349 composite_class.extension), 350 NULLQUARK, 1L, (Cardinal) 0)) == NULL) { 351 ext = (CompositeClassExtension) XtNew (CompositeClassExtensionRec); 352 if (ext != NULL) { 353 ext->next_extension = vsclass->composite_class.extension; 354 ext->record_type = NULLQUARK; 355 ext->version = XtCompositeExtensionVersion; 356 ext->record_size = sizeof (CompositeClassExtensionRec); 357 ext->accepts_objects = TRUE; 358 ext->allows_change_managed_set = FALSE; 359 vsclass->composite_class.extension = (XtPointer) ext; 360 } 361 } 362} 363 364#if defined(__osf__) || defined(__UNIXOS2__) || defined(__CYGWIN__) 365/* stupid OSF/1 shared libraries have the wrong semantics */ 366/* symbols do not get resolved external to the shared library */ 367void _XawFixupVendorShell() 368{ 369 transientShellWidgetClass->core_class.superclass = 370 (WidgetClass) &vendorShellClassRec; 371 topLevelShellWidgetClass->core_class.superclass = 372 (WidgetClass) &vendorShellClassRec; 373} 374#endif 375 376/* ARGSUSED */ 377static void 378XawVendorShellInitialize(Widget req, Widget cnew, 379 ArgList args, Cardinal *num_args) 380{ 381 XtAddEventHandler(cnew, (EventMask) 0, TRUE, _XEditResCheckMessages, NULL); 382 XtAddEventHandler(cnew, (EventMask) 0, TRUE, XmuRegisterExternalAgent, NULL); 383 XtCreateWidget("shellext", xawvendorShellExtWidgetClass, 384 cnew, args, *num_args); 385} 386 387/* ARGSUSED */ 388static Boolean 389XawVendorShellSetValues(Widget old, Widget ref, Widget cnew, 390 ArgList args, Cardinal *num_args) 391{ 392 return FALSE; 393} 394 395static void 396XawVendorShellRealize(Widget wid, Mask *vmask, XSetWindowAttributes *attr) 397{ 398 WidgetClass super = wmShellWidgetClass; 399 400 /* Make my superclass do all the dirty work */ 401 402 (*super->core_class.realize) (wid, vmask, attr); 403 _XawImRealize(wid); 404} 405 406 407static void 408XawVendorShellExtClassInitialize(void) 409{ 410} 411 412/* ARGSUSED */ 413static void 414XawVendorShellExtInitialize(Widget req, Widget cnew, 415 ArgList args, Cardinal *num_args) 416{ 417 _XawImInitialize(cnew->core.parent, cnew); 418} 419 420/* ARGSUSED */ 421static void 422XawVendorShellExtDestroy(Widget w) 423{ 424 _XawImDestroy( w->core.parent, w ); 425} 426 427/* ARGSUSED */ 428static Boolean 429XawVendorShellExtSetValues(Widget old, Widget ref, Widget cnew, 430 ArgList args, Cardinal *num_args) 431{ 432 return FALSE; 433} 434 435void 436XawVendorShellExtResize(Widget w) 437{ 438 ShellWidget sw = (ShellWidget) w; 439 Widget childwid; 440 Cardinal i; 441 int core_height; 442 443 _XawImResizeVendorShell( w ); 444 core_height = _XawImGetShellHeight( w ); 445 for( i = 0; i < sw->composite.num_children; i++ ) { 446 if( XtIsManaged( sw->composite.children[ i ] ) ) { 447 childwid = sw->composite.children[ i ]; 448 XtResizeWidget( childwid, sw->core.width, core_height, 449 childwid->core.border_width ); 450 } 451 } 452} 453 454/*ARGSUSED*/ 455void 456XawVendorStructureNotifyHandler(Widget w, XtPointer closure, XEvent *event, 457 Boolean *continue_to_dispatch) 458{ 459 XawVendorShellExtResize(w); 460} 461 462/*ARGSUSED*/ 463static XtGeometryResult 464XawVendorShellGeometryManager(Widget wid, XtWidgetGeometry *request, 465 XtWidgetGeometry *reply) 466{ 467 ShellWidget shell = (ShellWidget)(wid->core.parent); 468 XtWidgetGeometry my_request; 469 470 if(shell->shell.allow_shell_resize == FALSE && XtIsRealized(wid)) 471 return(XtGeometryNo); 472 473 if (request->request_mode & (CWX | CWY)) 474 return(XtGeometryNo); 475 476 /* %%% worry about XtCWQueryOnly */ 477 my_request.request_mode = 0; 478 if (request->request_mode & CWWidth) { 479 my_request.width = request->width; 480 my_request.request_mode |= CWWidth; 481 } 482 if (request->request_mode & CWHeight) { 483 my_request.height = request->height 484 + _XawImGetImAreaHeight( wid ); 485 my_request.request_mode |= CWHeight; 486 } 487 if (request->request_mode & CWBorderWidth) { 488 my_request.border_width = request->border_width; 489 my_request.request_mode |= CWBorderWidth; 490 } 491 if (XtMakeGeometryRequest((Widget)shell, &my_request, NULL) 492 == XtGeometryYes) { 493 /* assert: if (request->request_mode & CWWidth) then 494 * shell->core.width == request->width 495 * assert: if (request->request_mode & CWHeight) then 496 * shell->core.height == request->height 497 * 498 * so, whatever the WM sized us to (if the Shell requested 499 * only one of the two) is now the correct child size 500 */ 501 502 wid->core.width = shell->core.width; 503 wid->core.height = shell->core.height; 504 if (request->request_mode & CWBorderWidth) { 505 wid->core.x = wid->core.y = -request->border_width; 506 } 507 _XawImCallVendorShellExtResize(wid); 508 return XtGeometryYes; 509 } else return XtGeometryNo; 510} 511 512static void 513XawVendorShellChangeManaged(Widget wid) 514{ 515 ShellWidget w = (ShellWidget) wid; 516 Widget* childP; 517 int i; 518 519 (*SuperClass->composite_class.change_managed)(wid); 520 for (i = w->composite.num_children, childP = w->composite.children; 521 i; i--, childP++) { 522 if (XtIsManaged(*childP)) { 523 XtSetKeyboardFocus(wid, *childP); 524 break; 525 } 526 } 527} 528