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