home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / l / libxtgeo.zip / libgeo17 / geoShell.c < prev    next >
C/C++ Source or Header  |  1992-10-06  |  70KB  |  2,227 lines

  1. /* $XConsortium: Shell.c,v 1.127 92/06/08 14:28:33 converse Exp $ */
  2.  
  3. /***********************************************************
  4. Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts,
  5. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  6.  
  7.                         All Rights Reserved
  8.  
  9. Permission to use, copy, modify, and distribute this software and its 
  10. documentation for any purpose and without fee is hereby granted, 
  11. provided that the above copyright notice appear in all copies and that
  12. both that copyright notice and this permission notice appear in 
  13. supporting documentation, and that the names of Digital or MIT not be
  14. used in advertising or publicity pertaining to distribution of the
  15. software without specific, written prior permission.  
  16.  
  17. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  18. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  19. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  20. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  21. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  22. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  23. SOFTWARE.
  24.  
  25. ******************************************************************/
  26.  
  27. #define SHELL
  28.  
  29. #ifndef DEFAULT_WM_TIMEOUT
  30. #define DEFAULT_WM_TIMEOUT 5000
  31. #endif
  32.  
  33. #include "IntrinsicI.h"
  34. #include "StringDefs.h"
  35. #include "Shell.h"
  36. #include "ShellP.h"
  37. #include "Vendor.h"
  38. #include "VendorP.h"
  39. #include <X11/Xatom.h>
  40. #include <X11/Xlocale.h>
  41. #include <stdio.h>
  42.  
  43. #include "geoTattler.h"
  44.  
  45. #ifndef NO_EDITRES
  46. #include <X11/Xmu/Editres.h>
  47. #endif
  48.  
  49. /***************************************************************************
  50.  *
  51.  * Note: per the Xt spec, the Shell geometry management assumes in
  52.  * several places that there is only one managed child.  This is
  53.  * *not* a bug.  Any subclass that assumes otherwise is broken.
  54.  *
  55.  ***************************************************************************/
  56.  
  57. #define WM_CONFIGURE_DENIED(w) (((WMShellWidget) (w))->wm.wm_configure_denied)
  58. #define WM_MOVED(w) (((WMShellWidget) (w))->wm.wm_moved)
  59.  
  60. #define BIGSIZE ((Dimension)32767)
  61.  
  62. /***************************************************************************
  63.  *
  64.  * Default values for resource lists
  65.  *
  66.  ***************************************************************************/
  67.  
  68. #ifdef CRAY
  69. void _XtShellDepth();
  70. void _XtShellColormap();
  71. void _XtShellAncestorSensitive();
  72. void _XtTitleEncoding();
  73. #else
  74. static void _XtShellDepth();
  75. static void _XtShellColormap();
  76. static void _XtShellAncestorSensitive();
  77. static void _XtTitleEncoding();
  78. #endif
  79.  
  80. /***************************************************************************
  81.  *
  82.  * Shell class record
  83.  *
  84.  ***************************************************************************/
  85.  
  86. #define Offset(x)    (XtOffsetOf(ShellRec, x))
  87. static XtResource shellResources[]=
  88. {
  89.     {XtNx, XtCPosition, XtRPosition, sizeof(Position),
  90.         Offset(core.x), XtRImmediate, (XtPointer)BIGSIZE},
  91.     {XtNy, XtCPosition, XtRPosition, sizeof(Position),
  92.         Offset(core.y), XtRImmediate, (XtPointer)BIGSIZE},
  93.     { XtNdepth, XtCDepth, XtRInt, sizeof(int),
  94.         Offset(core.depth), XtRCallProc, (XtPointer) _XtShellDepth},
  95.     { XtNcolormap, XtCColormap, XtRColormap, sizeof(Colormap),
  96.         Offset(core.colormap), XtRCallProc, (XtPointer) _XtShellColormap},
  97.     { XtNancestorSensitive, XtCSensitive, XtRBoolean, sizeof(Boolean),
  98.         Offset(core.ancestor_sensitive), XtRCallProc,
  99.         (XtPointer) _XtShellAncestorSensitive},
  100.     { XtNallowShellResize, XtCAllowShellResize, XtRBoolean,
  101.         sizeof(Boolean), Offset(shell.allow_shell_resize),
  102.         XtRImmediate, (XtPointer)False},
  103.     { XtNgeometry, XtCGeometry, XtRString, sizeof(String), 
  104.         Offset(shell.geometry), XtRString, (XtPointer)NULL},
  105.     { XtNcreatePopupChildProc, XtCCreatePopupChildProc, XtRFunction,
  106.         sizeof(XtCreatePopupChildProc), Offset(shell.create_popup_child_proc),
  107.         XtRFunction, NULL},
  108.     { XtNsaveUnder, XtCSaveUnder, XtRBoolean, sizeof(Boolean),
  109.         Offset(shell.save_under), XtRImmediate, (XtPointer)False},
  110.     { XtNpopupCallback, XtCCallback, XtRCallback, sizeof(XtCallbackList),
  111.         Offset(shell.popup_callback), XtRCallback, (XtPointer) NULL},
  112.     { XtNpopdownCallback, XtCCallback, XtRCallback, sizeof(XtCallbackList),
  113.         Offset(shell.popdown_callback), XtRCallback, (XtPointer) NULL},
  114.     { XtNoverrideRedirect, XtCOverrideRedirect,
  115.         XtRBoolean, sizeof(Boolean), Offset(shell.override_redirect),
  116.         XtRImmediate, (XtPointer)False},
  117.     { XtNvisual, XtCVisual, XtRVisual, sizeof(Visual*),
  118.         Offset(shell.visual), XtRImmediate, CopyFromParent}
  119. };
  120.  
  121. static void ClassPartInitialize(), Initialize();
  122. static void Realize();
  123. static void Resize();
  124. static Boolean SetValues();
  125. static void GetValuesHook();
  126. static void ChangeManaged(); /* XXX */
  127. static XtGeometryResult GeometryManager(), RootGeometryManager();
  128. static void Destroy();
  129.  
  130. static ShellClassExtensionRec shellClassExtRec = {
  131.     NULL,
  132.     NULLQUARK,
  133.     XtShellExtensionVersion,
  134.     sizeof(ShellClassExtensionRec),
  135.     RootGeometryManager
  136. };
  137.  
  138. externaldef(shellclassrec) ShellClassRec shellClassRec = {
  139.   {   /* Core */
  140.     /* superclass      */    (WidgetClass) &compositeClassRec,
  141.     /* class_name      */    "Shell",
  142.     /* size          */    sizeof(ShellRec),
  143.     /* Class Initializer  */    NULL,
  144.     /* class_part_initialize*/    ClassPartInitialize,
  145.     /* Class init'ed ?      */    FALSE,
  146.     /* initialize      */    Initialize,
  147.     /* initialize_notify  */    NULL,        
  148.     /* realize          */    Realize,
  149.     /* actions          */    NULL,
  150.     /* num_actions      */    0,
  151.     /* resources      */    shellResources,
  152.     /* resource_count      */    XtNumber(shellResources),
  153.     /* xrm_class      */    NULLQUARK,
  154.     /* compress_motion      */    FALSE,
  155.     /* compress_exposure  */    TRUE,
  156.     /* compress_enterleave*/    FALSE,
  157.     /* visible_interest      */    FALSE,
  158.     /* destroy          */    Destroy,
  159.     /* resize          */    Resize,
  160.     /* expose          */    NULL,
  161.     /* set_values      */    SetValues,
  162.     /* set_values_hook      */    NULL,            
  163.     /* set_values_almost  */    XtInheritSetValuesAlmost,  
  164.     /* get_values_hook      */    GetValuesHook,            
  165.     /* accept_focus      */    NULL,
  166.     /* intrinsics version */    XtVersion,
  167.     /* callback offsets      */    NULL,
  168.     /* tm_table          */    NULL,
  169.     /* query_geometry      */    NULL,
  170.     /* display_accelerator*/    NULL,
  171.     /* extension      */    NULL
  172.   },{ /* Composite */
  173.     /* geometry_manager      */    GeometryManager,
  174.     /* change_managed      */    ChangeManaged,
  175.     /* insert_child      */    XtInheritInsertChild,
  176.     /* delete_child      */    XtInheritDeleteChild,
  177.     /* extension      */    NULL
  178.   },{ /* Shell */
  179.     /* extension      */    (XtPointer)&shellClassExtRec
  180.   }
  181. };
  182.  
  183. externaldef(shellwidgetclass) WidgetClass shellWidgetClass = (WidgetClass) (&shellClassRec);
  184.  
  185. /***************************************************************************
  186.  *
  187.  * OverrideShell class record
  188.  *
  189.  ***************************************************************************/
  190.  
  191. static XtResource overrideResources[]=
  192. {
  193.     { XtNoverrideRedirect, XtCOverrideRedirect,
  194.         XtRBoolean, sizeof(Boolean), Offset(shell.override_redirect),
  195.         XtRImmediate, (XtPointer)True},
  196.     { XtNsaveUnder, XtCSaveUnder, XtRBoolean, sizeof(Boolean),
  197.         Offset(shell.save_under), XtRImmediate, (XtPointer)True},
  198. };
  199.  
  200. externaldef(overrideshellclassrec) OverrideShellClassRec overrideShellClassRec = {
  201.   {
  202.     /* superclass         */    (WidgetClass) &shellClassRec,
  203.     /* class_name         */    "OverrideShell",
  204.     /* size               */    sizeof(OverrideShellRec),
  205.     /* Class Initializer  */    NULL,
  206.     /* class_part_initialize*/    NULL,
  207.     /* Class init'ed ?    */    FALSE,
  208.     /* initialize         */    NULL,
  209.     /* initialize_notify    */    NULL,        
  210.     /* realize            */    XtInheritRealize,
  211.     /* actions            */    NULL,
  212.     /* num_actions        */    0,
  213.     /* resources          */    overrideResources,
  214.     /* resource_count     */    XtNumber(overrideResources),
  215.     /* xrm_class          */    NULLQUARK,
  216.     /* compress_motion    */    FALSE,
  217.     /* compress_exposure  */    TRUE,
  218.     /* compress_enterleave*/     FALSE,
  219.     /* visible_interest   */    FALSE,
  220.     /* destroy            */    NULL,
  221.     /* resize             */    XtInheritResize,
  222.     /* expose             */    NULL,
  223.     /* set_values         */    NULL,
  224.     /* set_values_hook      */    NULL,            
  225.     /* set_values_almost    */    XtInheritSetValuesAlmost,  
  226.     /* get_values_hook      */    NULL,            
  227.     /* accept_focus       */    NULL,
  228.     /* intrinsics version */    XtVersion,
  229.     /* callback offsets   */    NULL,
  230.     /* tm_table            */  NULL,
  231.     /* query_geometry        */  NULL,
  232.     /* display_accelerator  */  NULL,
  233.     /* extension        */  NULL
  234.   },{
  235.     /* geometry_manager   */    XtInheritGeometryManager,
  236.     /* change_managed     */    XtInheritChangeManaged,
  237.     /* insert_child      */    XtInheritInsertChild,
  238.     /* delete_child      */    XtInheritDeleteChild,
  239.     /* extension        */  NULL
  240.   },{
  241.     /* extension        */  NULL
  242.   },{
  243.     /* extension        */  NULL
  244.   }
  245. };
  246.  
  247. externaldef(overrideshellwidgetclass) WidgetClass overrideShellWidgetClass = 
  248.     (WidgetClass) (&overrideShellClassRec);
  249.  
  250. /***************************************************************************
  251.  *
  252.  * WMShell class record
  253.  *
  254.  ***************************************************************************/
  255.  
  256. #undef Offset
  257. #define Offset(x)    (XtOffsetOf(WMShellRec, x))
  258.  
  259. static int default_unspecified_shell_int = XtUnspecifiedShellInt;
  260. /*
  261.  * Warning, casting XtUnspecifiedShellInt (which is -1) to an (XtPointer)
  262.  * can result is loss of bits on some machines (i.e. crays)
  263.  */
  264.  
  265. static XtResource wmResources[]=
  266. {
  267.     { XtNtitle, XtCTitle, XtRString, sizeof(String),
  268.         Offset(wm.title), XtRString, NULL},
  269.     { XtNtitleEncoding, XtCTitleEncoding, XtRAtom, sizeof(Atom),
  270.         Offset(wm.title_encoding),
  271.         XtRCallProc, (XtPointer) _XtTitleEncoding},
  272.     { XtNwmTimeout, XtCWmTimeout, XtRInt, sizeof(int),
  273.         Offset(wm.wm_timeout), XtRImmediate,(XtPointer)DEFAULT_WM_TIMEOUT},
  274.     { XtNwaitForWm, XtCWaitForWm, XtRBoolean, sizeof(Boolean),
  275.         Offset(wm.wait_for_wm), XtRImmediate, (XtPointer)True},
  276.     { XtNtransient, XtCTransient, XtRBoolean, sizeof(Boolean),
  277.         Offset(wm.transient), XtRImmediate, (XtPointer)False},
  278. /* size_hints minus things stored in core */
  279.     { XtNbaseWidth, XtCBaseWidth, XtRInt, sizeof(int),
  280.         Offset(wm.base_width),
  281.         XtRInt, (XtPointer) &default_unspecified_shell_int},
  282.     { XtNbaseHeight, XtCBaseHeight, XtRInt, sizeof(int),
  283.         Offset(wm.base_height),
  284.         XtRInt, (XtPointer) &default_unspecified_shell_int},
  285.     { XtNwinGravity, XtCWinGravity, XtRInt, sizeof(int),
  286.         Offset(wm.win_gravity),
  287.         XtRInt, (XtPointer) &default_unspecified_shell_int},
  288.     { XtNminWidth, XtCMinWidth, XtRInt, sizeof(int),
  289.         Offset(wm.size_hints.min_width),
  290.         XtRInt, (XtPointer) &default_unspecified_shell_int},
  291.     { XtNminHeight, XtCMinHeight, XtRInt, sizeof(int),
  292.         Offset(wm.size_hints.min_height),
  293.         XtRInt, (XtPointer) &default_unspecified_shell_int},
  294.     { XtNmaxWidth, XtCMaxWidth, XtRInt, sizeof(int),
  295.         Offset(wm.size_hints.max_width),
  296.         XtRInt, (XtPointer) &default_unspecified_shell_int},
  297.     { XtNmaxHeight, XtCMaxHeight, XtRInt, sizeof(int),
  298.         Offset(wm.size_hints.max_height),
  299.         XtRInt, (XtPointer) &default_unspecified_shell_int},
  300.     { XtNwidthInc, XtCWidthInc, XtRInt, sizeof(int),
  301.         Offset(wm.size_hints.width_inc),
  302.         XtRInt, (XtPointer) &default_unspecified_shell_int},
  303.     { XtNheightInc, XtCHeightInc, XtRInt, sizeof(int),
  304.         Offset(wm.size_hints.height_inc),
  305.         XtRInt, (XtPointer) &default_unspecified_shell_int},
  306.     { XtNminAspectX, XtCMinAspectX, XtRInt, sizeof(int),
  307.         Offset(wm.size_hints.min_aspect.x),
  308.         XtRInt, (XtPointer) &default_unspecified_shell_int},
  309.     { XtNminAspectY, XtCMinAspectY, XtRInt, sizeof(int),
  310.         Offset(wm.size_hints.min_aspect.y),
  311.         XtRInt, (XtPointer) &default_unspecified_shell_int},
  312.     { XtNmaxAspectX, XtCMaxAspectX, XtRInt, sizeof(int),
  313.         Offset(wm.size_hints.max_aspect.x),
  314.         XtRInt, (XtPointer) &default_unspecified_shell_int},
  315.     { XtNmaxAspectY, XtCMaxAspectY, XtRInt, sizeof(int),
  316.         Offset(wm.size_hints.max_aspect.y),
  317.         XtRInt, (XtPointer) &default_unspecified_shell_int},
  318. /* wm_hints */
  319.     { XtNinput, XtCInput, XtRBool, sizeof(Bool),
  320.         Offset(wm.wm_hints.input), XtRImmediate, (XtPointer)False},
  321.     { XtNinitialState, XtCInitialState, XtRInitialState, sizeof(int),
  322.         Offset(wm.wm_hints.initial_state),
  323.         XtRImmediate, (XtPointer)NormalState},
  324.     { XtNiconPixmap, XtCIconPixmap, XtRBitmap, sizeof(Pixmap),
  325.         Offset(wm.wm_hints.icon_pixmap), XtRPixmap, NULL},
  326.     { XtNiconWindow, XtCIconWindow, XtRWindow, sizeof(Window),
  327.         Offset(wm.wm_hints.icon_window), XtRWindow,   (XtPointer) NULL},
  328.     { XtNiconX, XtCIconX, XtRInt, sizeof(int),
  329.         Offset(wm.wm_hints.icon_x),
  330.         XtRInt, (XtPointer) &default_unspecified_shell_int},
  331.     { XtNiconY, XtCIconY, XtRInt, sizeof(int),
  332.         Offset(wm.wm_hints.icon_y),
  333.         XtRInt, (XtPointer) &default_unspecified_shell_int},
  334.     { XtNiconMask, XtCIconMask, XtRBitmap, sizeof(Pixmap),
  335.         Offset(wm.wm_hints.icon_mask), XtRPixmap, NULL},
  336.     { XtNwindowGroup, XtCWindowGroup, XtRWindow, sizeof(Window),
  337.         Offset(wm.wm_hints.window_group),
  338.         XtRImmediate, (XtPointer)XtUnspecifiedWindow}
  339. };
  340.  
  341. static void WMInitialize();
  342. static void WMInitialize();
  343. static Boolean WMSetValues();
  344. static void WMDestroy();
  345.  
  346. externaldef(wmshellclassrec) WMShellClassRec wmShellClassRec = {
  347.   {
  348.     /* superclass         */    (WidgetClass) &shellClassRec,
  349.     /* class_name         */    "WMShell",
  350.     /* size               */    sizeof(WMShellRec),
  351.     /* Class Initializer  */    NULL,
  352.     /* class_part_initialize*/    NULL,
  353.     /* Class init'ed ?    */    FALSE,
  354.     /* initialize         */    WMInitialize,
  355.     /* initialize_notify    */    NULL,        
  356.     /* realize            */    XtInheritRealize,
  357.     /* actions            */    NULL,
  358.     /* num_actions        */    0,
  359.     /* resources          */    wmResources,
  360.     /* resource_count     */    XtNumber(wmResources),
  361.     /* xrm_class          */    NULLQUARK,
  362.     /* compress_motion    */    FALSE,
  363.     /* compress_exposure  */    TRUE,
  364.     /* compress_enterleave*/    FALSE,
  365.     /* visible_interest   */    FALSE,
  366.     /* destroy            */    WMDestroy,
  367.     /* resize             */    XtInheritResize,
  368.     /* expose             */    NULL,
  369.     /* set_values         */    WMSetValues,
  370.     /* set_values_hook      */    NULL,            
  371.     /* set_values_almost    */    XtInheritSetValuesAlmost,  
  372.     /* get_values_hook      */    NULL,            
  373.     /* accept_focus       */    NULL,
  374.     /* intrinsics version */    XtVersion,
  375.     /* callback offsets   */    NULL,
  376.     /* tm_table            */  NULL,
  377.     /* query_geometry        */  NULL,
  378.     /* display_accelerator  */  NULL,
  379.     /* extension        */  NULL
  380.   },{
  381.     /* geometry_manager   */    XtInheritGeometryManager,
  382.     /* change_managed     */    XtInheritChangeManaged,
  383.     /* insert_child      */    XtInheritInsertChild,
  384.     /* delete_child      */    XtInheritDeleteChild,
  385.     /* extension        */  NULL
  386.   },{
  387.     /* extension        */  NULL
  388.   },{
  389.     /* extension        */  NULL
  390.   }
  391. };
  392.  
  393. externaldef(wmshellwidgetclass) WidgetClass wmShellWidgetClass = (WidgetClass) (&wmShellClassRec);
  394.  
  395. /***************************************************************************
  396.  *
  397.  * TransientShell class record
  398.  *
  399.  ***************************************************************************/
  400.  
  401. #undef Offset
  402. #define Offset(x)    (XtOffsetOf(TransientShellRec, x))
  403.  
  404. static XtResource transientResources[]=
  405. {
  406.     { XtNtransient, XtCTransient, XtRBoolean, sizeof(Boolean),
  407.         Offset(wm.transient), XtRImmediate, (XtPointer)True},
  408.     { XtNtransientFor, XtCTransientFor, XtRWidget, sizeof(Widget),
  409.         Offset(transient.transient_for), XtRWidget, NULL},
  410.     { XtNsaveUnder, XtCSaveUnder, XtRBoolean, sizeof(Boolean),
  411.         Offset(shell.save_under), XtRImmediate, (XtPointer)True},
  412. };
  413.  
  414. static void TransientRealize();
  415. static Boolean TransientSetValues();
  416.  
  417. externaldef(transientshellclassrec) TransientShellClassRec transientShellClassRec = {
  418.   {
  419.     /* superclass      */    (WidgetClass) &vendorShellClassRec,
  420.     /* class_name      */    "TransientShell",
  421.     /* size          */    sizeof(TransientShellRec),
  422.     /* Class Initializer  */    NULL,
  423.     /* class_part_initialize*/    NULL,
  424.     /* Class init'ed ?      */    FALSE,
  425.     /* initialize      */    NULL,
  426.     /* initialize_notify  */    NULL,        
  427.     /* realize          */    TransientRealize,
  428.     /* actions          */    NULL,
  429.     /* num_actions      */    0,
  430.     /* resources      */    transientResources,
  431.     /* resource_count      */    XtNumber(transientResources),
  432.     /* xrm_class      */    NULLQUARK,
  433.     /* compress_motion      */    FALSE,
  434.     /* compress_exposure  */    TRUE,
  435.     /* compress_enterleave*/    FALSE,
  436.     /* visible_interest      */    FALSE,
  437.     /* destroy          */    NULL,
  438.     /* resize          */    XtInheritResize,
  439.     /* expose          */    NULL,
  440.     /* set_values      */    TransientSetValues,
  441.     /* set_values_hook      */    NULL,            
  442.     /* set_values_almost  */    XtInheritSetValuesAlmost,  
  443.     /* get_values_hook      */    NULL,            
  444.     /* accept_focus      */    NULL,
  445.     /* intrinsics version */    XtVersion,
  446.     /* callback offsets      */    NULL,
  447.     /* tm_table          */    XtInheritTranslations,
  448.     /* query_geometry      */    NULL,
  449.     /* display_accelerator*/    NULL,
  450.     /* extension      */    NULL
  451.   },{
  452.     /* geometry_manager      */    XtInheritGeometryManager,
  453.     /* change_managed      */    XtInheritChangeManaged,
  454.     /* insert_child      */    XtInheritInsertChild,
  455.     /* delete_child      */    XtInheritDeleteChild,
  456.     /* extension      */    NULL
  457.   },{
  458.     /* extension      */    NULL
  459.   },{
  460.     /* extension      */    NULL
  461.   },{
  462.     /* extension      */    NULL
  463.   },{
  464.     /* extension      */    NULL
  465.   }
  466. };
  467.  
  468. externaldef(transientshellwidgetclass) WidgetClass transientShellWidgetClass =
  469.     (WidgetClass) (&transientShellClassRec);
  470.  
  471. /***************************************************************************
  472.  *
  473.  * TopLevelShell class record
  474.  *
  475.  ***************************************************************************/
  476.  
  477. #undef Offset
  478. #define Offset(x)    (XtOffsetOf(TopLevelShellRec, x))
  479.  
  480. static XtResource topLevelResources[]=
  481. {
  482.     { XtNiconName, XtCIconName, XtRString, sizeof(String),
  483.         Offset(topLevel.icon_name), XtRString, (XtPointer) NULL},
  484.     { XtNiconNameEncoding, XtCIconNameEncoding, XtRAtom, sizeof(Atom),
  485.         Offset(topLevel.icon_name_encoding),
  486.         XtRCallProc, (XtPointer) _XtTitleEncoding},
  487.     { XtNiconic, XtCIconic, XtRBoolean, sizeof(Boolean),
  488.         Offset(topLevel.iconic), XtRImmediate, (XtPointer)False}
  489. };
  490.  
  491. static void TopLevelInitialize();
  492. static Boolean TopLevelSetValues();
  493. static void TopLevelDestroy();
  494.  
  495. externaldef(toplevelshellclassrec) TopLevelShellClassRec topLevelShellClassRec = {
  496.   {
  497.     /* superclass         */    (WidgetClass) &vendorShellClassRec,
  498.     /* class_name         */    "TopLevelShell",
  499.     /* size               */    sizeof(TopLevelShellRec),
  500.     /* Class Initializer  */    NULL,
  501.     /* class_part_initialize*/    NULL,
  502.     /* Class init'ed ?    */    FALSE,
  503.     /* initialize         */    TopLevelInitialize,
  504.     /* initialize_notify    */    NULL,        
  505.     /* realize            */    XtInheritRealize,
  506.     /* actions            */    NULL,
  507.     /* num_actions        */    0,
  508.     /* resources          */    topLevelResources,
  509.     /* resource_count     */    XtNumber(topLevelResources),
  510.     /* xrm_class          */    NULLQUARK,
  511.     /* compress_motion    */    FALSE,
  512.     /* compress_exposure  */    TRUE,
  513.     /* compress_enterleave*/     FALSE,
  514.     /* visible_interest   */    FALSE,
  515.     /* destroy            */    TopLevelDestroy,
  516.     /* resize             */    XtInheritResize,
  517.     /* expose             */    NULL,
  518.     /* set_values         */    TopLevelSetValues,
  519.     /* set_values_hook      */    NULL,            
  520.     /* set_values_almost    */    XtInheritSetValuesAlmost,  
  521.     /* get_values_hook      */    NULL,            
  522.     /* accept_focus       */    NULL,
  523.     /* intrinsics version */    XtVersion,
  524.     /* callback offsets   */    NULL,
  525.     /* tm_table            */  XtInheritTranslations,
  526.     /* query_geometry        */  NULL,
  527.     /* display_accelerator  */  NULL,
  528.     /* extension        */  NULL
  529.   },{
  530.     /* geometry_manager   */    XtInheritGeometryManager,
  531.     /* change_managed     */    XtInheritChangeManaged,
  532.     /* insert_child      */    XtInheritInsertChild,
  533.     /* delete_child      */    XtInheritDeleteChild,
  534.     /* extension        */  NULL
  535.   },{
  536.     /* extension        */  NULL
  537.   },{
  538.     /* extension        */  NULL
  539.   },{
  540.     /* extension        */  NULL
  541.   },{
  542.     /* extension        */  NULL
  543.   }
  544. };
  545.  
  546. externaldef(toplevelshellwidgetclass) WidgetClass topLevelShellWidgetClass =
  547.     (WidgetClass) (&topLevelShellClassRec);
  548.  
  549. /***************************************************************************
  550.  *
  551.  * ApplicationShell class record
  552.  *
  553.  ***************************************************************************/
  554.  
  555. #undef Offset
  556. #define Offset(x)    (XtOffsetOf(ApplicationShellRec, x))
  557.  
  558. static XtResource applicationResources[]=
  559. {
  560.     { XtNargc, XtCArgc, XtRInt, sizeof(int),
  561.         Offset(application.argc), XtRImmediate, (XtPointer)0}, 
  562.     { XtNargv, XtCArgv, XtRStringArray, sizeof(String*),
  563.         Offset(application.argv), XtRPointer, (XtPointer) NULL}
  564. };
  565.  
  566. static void ApplicationInitialize();
  567. static void ApplicationDestroy();
  568. static void ApplicationShellInsertChild();
  569.  
  570. static CompositeClassExtensionRec compositeClassExtension = {
  571.     /* next_extension    */    NULL,
  572.     /* record_type    */    NULLQUARK,
  573.     /* version        */    XtCompositeExtensionVersion,
  574.     /* record_size    */    sizeof(CompositeClassExtensionRec),
  575.     /* accepts_objects    */    TRUE
  576. };
  577.  
  578.  
  579. externaldef(applicationshellclassrec) ApplicationShellClassRec applicationShellClassRec = {
  580.   {
  581.     /* superclass         */    (WidgetClass) &topLevelShellClassRec,
  582.     /* class_name         */    "ApplicationShell",
  583.     /* size               */    sizeof(ApplicationShellRec),
  584.     /* Class Initializer  */    NULL,
  585.     /* class_part_initialize*/    NULL,
  586.     /* Class init'ed ?    */    FALSE,
  587.     /* initialize         */    ApplicationInitialize,
  588.     /* initialize_notify  */    NULL,        
  589.     /* realize            */    XtInheritRealize,
  590.     /* actions            */    NULL,
  591.     /* num_actions        */    0,
  592.     /* resources          */    applicationResources,
  593.     /* resource_count     */    XtNumber(applicationResources),
  594.     /* xrm_class          */    NULLQUARK,
  595.     /* compress_motion    */    FALSE,
  596.     /* compress_exposure  */    TRUE,
  597.     /* compress_enterleave*/    FALSE,
  598.     /* visible_interest   */    FALSE,
  599.     /* destroy            */    ApplicationDestroy,
  600.     /* resize             */    XtInheritResize,
  601.     /* expose             */    NULL,
  602.     /* set_values         */    NULL,
  603.     /* set_values_hook    */    NULL,            
  604.     /* set_values_almost  */    XtInheritSetValuesAlmost,
  605.     /* get_values_hook    */    NULL,            
  606.     /* accept_focus       */    NULL,
  607.     /* intrinsics version */    XtVersion,
  608.     /* callback offsets   */    NULL,
  609.     /* tm_table          */    XtInheritTranslations,
  610.     /* query_geometry      */    NULL,
  611.     /* display_accelerator*/    NULL,
  612.     /* extension      */    NULL
  613.   },{
  614.     /* geometry_manager   */    XtInheritGeometryManager,
  615.     /* change_managed     */    XtInheritChangeManaged,
  616.     /* insert_child      */    ApplicationShellInsertChild,
  617.     /* delete_child      */    XtInheritDeleteChild,
  618.     /* extension      */    (XtPointer)&compositeClassExtension
  619.   },{
  620.     /* extension      */    NULL
  621.   },{
  622.     /* extension      */    NULL
  623.   },{
  624.     /* extension      */    NULL
  625.   },{
  626.     /* extension      */    NULL
  627.   },{
  628.     /* extension      */    NULL
  629.   }
  630. };
  631.  
  632. externaldef(applicationshellwidgetclass) WidgetClass applicationShellWidgetClass =
  633.     (WidgetClass) (&applicationShellClassRec);
  634.  
  635. /****************************************************************************
  636.  * Whew!
  637.  ****************************************************************************/
  638.  
  639. static void ComputeWMSizeHints(w, hints)
  640.     WMShellWidget w;
  641.     XSizeHints *hints;
  642. {
  643.     register long flags;
  644.     hints->flags = flags = w->wm.size_hints.flags;
  645. #define copy(field) hints->field = w->wm.size_hints.field
  646.     if (flags & (USPosition | PPosition)) {
  647.     copy(x);
  648.     copy(y);
  649.     }
  650.     if (flags & (USSize | PSize)) {
  651.     copy(width);
  652.     copy(height);
  653.     }
  654.     if (flags & PMinSize) {
  655.     copy(min_width);
  656.     copy(min_height);
  657.     }
  658.     if (flags & PMaxSize) {
  659.     copy(max_width);
  660.     copy(max_height);
  661.     }
  662.     if (flags & PResizeInc) {
  663.     copy(width_inc);
  664.     copy(height_inc);
  665.     }
  666.     if (flags & PAspect) {
  667.     copy(min_aspect.x);
  668.     copy(min_aspect.y);
  669.     copy(max_aspect.x);
  670.     copy(max_aspect.y);
  671.     }
  672. #undef copy
  673. #define copy(field) hints->field = w->wm.field
  674.     if (flags & PBaseSize) {
  675.     copy(base_width);
  676.     copy(base_height);
  677.     }
  678.     if (flags & PWinGravity)
  679.     copy(win_gravity);
  680. #undef copy
  681. }
  682.  
  683. static void _SetWMSizeHints(w)
  684.     WMShellWidget w;
  685. {
  686.     XSizeHints *size_hints = XAllocSizeHints();
  687.  
  688.     if (size_hints == NULL) _XtAllocError("XAllocSizeHints");
  689.     ComputeWMSizeHints(w, size_hints);
  690.     XSetWMNormalHints(XtDisplay((Widget)w), XtWindow((Widget)w), size_hints);
  691.     XFree((char*)size_hints);
  692. }
  693.  
  694. static ShellClassExtension _FindClassExtension(widget_class)
  695.     WidgetClass widget_class;
  696. {
  697.     ShellClassExtension ext;
  698.     for (ext = (ShellClassExtension)((ShellWidgetClass)widget_class)
  699.            ->shell_class.extension;
  700.      ext != NULL && ext->record_type != NULLQUARK;
  701.      ext = (ShellClassExtension)ext->next_extension);
  702.  
  703.     if (ext != NULL) {
  704.     if (  ext->version == XtShellExtensionVersion
  705.           && ext->record_size == sizeof(ShellClassExtensionRec)) {
  706.         /* continue */
  707.     } else {
  708.         String params[1];
  709.         Cardinal num_params = 1;
  710.         params[0] = widget_class->core_class.class_name;
  711.         XtErrorMsg( "invalidExtension", "shellClassPartInitialize",
  712.                 XtCXtToolkitError,
  713.          "widget class %s has invalid ShellClassExtension record",
  714.          params, &num_params);
  715.     }
  716.     }
  717.     return ext;
  718. }
  719.  
  720. static void ClassPartInitialize(widget_class)
  721.     WidgetClass widget_class;
  722. {
  723.     ShellClassExtension ext = _FindClassExtension(widget_class);
  724.     if (ext != NULL) {
  725.     if (ext->root_geometry_manager == XtInheritRootGeometryManager) {
  726.         ext->root_geometry_manager =
  727.         _FindClassExtension(widget_class->core_class.superclass)
  728.             ->root_geometry_manager;
  729.     }
  730.     } else {
  731.     /* if not found, spec requires XtInheritRootGeometryManager */
  732.     XtPointer *extP
  733.         = &((ShellWidgetClass)widget_class)->shell_class.extension;
  734.     ext = XtNew(ShellClassExtensionRec);
  735.     bcopy((char*)_FindClassExtension(widget_class->core_class.superclass),
  736.           (char*)ext,
  737.           sizeof(ShellClassExtensionRec));
  738.     ext->next_extension = *extP;
  739.     *extP = (XtPointer)ext;
  740.     }
  741. }
  742.  
  743.  
  744. static void EventHandler();
  745. static void _popup_set_prop();
  746.  
  747.  
  748. /*ARGSUSED*/
  749. static void XtCopyDefaultDepth(widget, offset, value)
  750.     Widget      widget;
  751.     int        offset;
  752.     XrmValue    *value;
  753. {
  754.     value->addr = (XPointer)(&DefaultDepthOfScreen(XtScreenOfObject(widget)));
  755. }
  756.  
  757. #ifndef CRAY
  758. static
  759. #endif
  760. void _XtShellDepth(widget,closure,value)
  761.     Widget widget;
  762.     int closure;
  763.     XrmValue *value;
  764. {
  765.    if (widget->core.parent == NULL) XtCopyDefaultDepth(widget,closure,value);
  766.    else _XtCopyFromParent (widget,closure,value);
  767. }
  768.  
  769. /*ARGSUSED*/
  770. static void XtCopyDefaultColormap(widget, offset, value)
  771.     Widget      widget;
  772.     int        offset;
  773.     XrmValue    *value;
  774. {
  775.     value->addr = (XPointer)(&DefaultColormapOfScreen(XtScreenOfObject(widget)));
  776. }
  777.  
  778. #ifndef CRAY
  779. static
  780. #endif
  781. void _XtShellColormap(widget,closure,value)
  782.     Widget widget;
  783.     int closure;
  784.     XrmValue *value;
  785. {
  786.    if (widget->core.parent == NULL)
  787.        XtCopyDefaultColormap(widget,closure,value);
  788.    else _XtCopyFromParent (widget,closure,value);
  789. }
  790.  
  791. #ifndef CRAY
  792. static
  793. #endif
  794. void _XtShellAncestorSensitive(widget,closure,value)
  795.     Widget widget;
  796.     int closure;
  797.     XrmValue *value;
  798. {
  799.    static Boolean true = True;
  800.    if (widget->core.parent == NULL) value->addr = (XPointer)(&true);
  801.    else _XtCopyFromParent (widget,closure,value);
  802. }
  803.  
  804. /*ARGSUSED*/
  805. #ifndef CRAY
  806. static
  807. #endif
  808. void _XtTitleEncoding(widget, offset, value)
  809.     Widget widget;
  810.     int offset;
  811.     XrmValue *value;
  812. {
  813.     static Atom atom;
  814.     if (XtWidgetToApplicationContext(widget)->langProcRec.proc) atom = None;
  815.     else atom = XA_STRING;
  816.     value->addr = (XPointer) &atom;
  817. }
  818.  
  819.  
  820. /* ARGSUSED */
  821. static void Initialize(req, new, args, num_args)
  822.     Widget req, new;
  823.     ArgList args;        /* unused */
  824.     Cardinal *num_args;    /* unused */
  825. {
  826.     ShellWidget w = (ShellWidget) new;
  827.  
  828.     w->shell.popped_up = FALSE;
  829.     w->shell.client_specified =
  830.         _XtShellNotReparented | _XtShellPositionValid;
  831.  
  832.     if (w->core.x == BIGSIZE) {
  833.         w->core.x = 0;
  834.         if (w->core.y == BIGSIZE) w->core.y = 0;
  835.     } else {
  836.         if (w->core.y == BIGSIZE) w->core.y = 0;
  837.         else w->shell.client_specified |= _XtShellPPositionOK;
  838.     }
  839.  
  840.     XtAddEventHandler(new, (EventMask) StructureNotifyMask,
  841.         TRUE, EventHandler, (XtPointer) NULL);
  842. #ifndef NO_EDITRES
  843.     XtAddEventHandler(new, (EventMask) 0, TRUE, 
  844.               _XEditResCheckMessages, NULL);
  845. #endif
  846.  
  847. }
  848.  
  849. /* ARGSUSED */
  850. static void WMInitialize(req, new, args, num_args)
  851.     Widget req,new;
  852.     ArgList args;        /* unused */
  853.     Cardinal *num_args;    /* unused */
  854. {
  855.     WMShellWidget w = (WMShellWidget) new;
  856.     TopLevelShellWidget tls = (TopLevelShellWidget) new;    /* maybe */
  857.  
  858.     if(w->wm.title == NULL) {
  859.         if (XtIsTopLevelShell(new) &&
  860.             tls->topLevel.icon_name != NULL &&
  861.             strlen(tls->topLevel.icon_name) != 0) {
  862.         w->wm.title = XtNewString(tls->topLevel.icon_name);
  863.         } else {
  864.         w->wm.title = XtNewString(w->core.name);
  865.         }
  866.     } else {
  867.         w->wm.title = XtNewString(w->wm.title);
  868.     }
  869.     w->wm.size_hints.flags = 0;
  870.     w->wm.wm_hints.flags = 0;
  871.  
  872.     /* Find the values of the atoms, somewhere... */
  873.  
  874.     for (new = new->core.parent;
  875.         new != NULL && !XtIsWMShell(new);
  876.         new = new->core.parent) {}
  877.     if (new == NULL) {
  878.         w->wm.wm_configure_denied =
  879.             XInternAtom(XtDisplay(w), "WM_CONFIGURE_DENIED", FALSE);
  880.         w->wm.wm_moved = XInternAtom(XtDisplay(w), "WM_MOVED", FALSE);
  881.     } else {
  882.         w->wm.wm_configure_denied = WM_CONFIGURE_DENIED(new);
  883.         w->wm.wm_moved = WM_MOVED(new);
  884.     }
  885. }
  886.  
  887.  
  888. /* ARGSUSED */
  889. static void TopLevelInitialize(req, new, args, num_args)
  890.     Widget req, new;
  891.     ArgList args;        /* unused */
  892.     Cardinal *num_args;    /* unused */
  893. {
  894.     TopLevelShellWidget w = (TopLevelShellWidget) new;
  895.  
  896.     if (w->topLevel.icon_name == NULL) {
  897.         w->topLevel.icon_name = XtNewString(w->core.name);
  898.     } else {
  899.         w->topLevel.icon_name = XtNewString(w->topLevel.icon_name);
  900.     }
  901.  
  902.     if (w->topLevel.iconic)
  903.         w->wm.wm_hints.initial_state = IconicState;
  904. }
  905.  
  906. /* ARGSUSED */
  907. static void ApplicationInitialize(req, new, args, num_args)
  908.     Widget req, new;
  909.     ArgList args;        /* unused */
  910.     Cardinal *num_args;        /* unused */
  911. {
  912.     ApplicationShellWidget w = (ApplicationShellWidget)new;
  913.     /* copy the argv if passed */
  914.     if (w->application.argc > 0) {
  915.     int i = w->application.argc;
  916.     char **argv = (char**)XtMalloc( (unsigned)i*sizeof(char*) );
  917.     char **argp = w->application.argv + i;
  918.     while (--i >= 0) {
  919.         argv[i] = *--argp;
  920.     }
  921.     w->application.argv = argv;
  922.     }
  923. }
  924.  
  925. static void Resize(w)
  926.     Widget w;
  927. {
  928.     register ShellWidget sw = (ShellWidget)w;    
  929.     Widget childwid;
  930.     int i;
  931.     for(i = 0; i < sw->composite.num_children; i++) {
  932.         if (XtIsManaged(sw->composite.children[i])) {
  933.              childwid = sw->composite.children[i];
  934.              XtResizeWidget(childwid, sw->core.width, sw->core.height,
  935.                            childwid->core.border_width);
  936.          break;        /* can only be one managed child */
  937.         }
  938.     }
  939. }
  940.  
  941. static void GetGeometry();
  942.  
  943. static void Realize(wid, vmask, attr)
  944.     Widget wid;
  945.     Mask *vmask;
  946.     XSetWindowAttributes *attr;
  947. {
  948.     ShellWidget w = (ShellWidget) wid;
  949.         Mask mask = *vmask;
  950.  
  951.     if (! (w->shell.client_specified & _XtShellGeometryParsed)) {
  952.         /* we'll get here only if there was no child the first
  953.            time we were realized.  If the shell was Unrealized
  954.            and then re-Realized, we probably don't want to
  955.            re-evaluate the defaults anyway.
  956.          */
  957.         GetGeometry(wid, (Widget)NULL);
  958.     }
  959.     else if (w->core.background_pixmap == XtUnspecifiedPixmap) {
  960.         /* I attempt to inherit my child's background to avoid screen flash
  961.          * if there is latency between when I get resized and when my child
  962.          * is resized.  Background=None is not satisfactory, as I want the
  963.          * user to get immediate feedback on the new dimensions (most
  964.          * particularly in the case of a non-reparenting wm).  It is
  965.          * especially important to have the server clear any old cruft
  966.          * from the display when I am resized larger.
  967.          */
  968.         register Widget *childP = w->composite.children;
  969.         int i;
  970.         for (i = w->composite.num_children; i; i--, childP++) {
  971.         if (XtIsWidget(*childP) && XtIsManaged(*childP)) {
  972.             if ((*childP)->core.background_pixmap
  973.                 != XtUnspecifiedPixmap) {
  974.             mask &= ~(CWBackPixel);
  975.             mask |= CWBackPixmap;
  976.             attr->background_pixmap =
  977.                 w->core.background_pixmap =
  978.                 (*childP)->core.background_pixmap;
  979.             } else {
  980.             attr->background_pixel = 
  981.                 w->core.background_pixel = 
  982.                 (*childP)->core.background_pixel;
  983.             }
  984.             break;
  985.         }
  986.         }
  987.     }
  988.  
  989.     if(w->shell.save_under) {
  990.         mask |= CWSaveUnder;
  991.         attr->save_under = TRUE;
  992.     }
  993.     if(w->shell.override_redirect) {
  994.         mask |= CWOverrideRedirect;
  995.         attr->override_redirect = TRUE;
  996.     }
  997.     if (wid->core.width == 0 || wid->core.height == 0) {
  998.         Cardinal count = 1;
  999.         XtErrorMsg("invalidDimension", "shellRealize", XtCXtToolkitError,
  1000.                "Shell widget %s has zero width and/or height",
  1001.                &wid->core.name, &count);
  1002.     }
  1003.     wid->core.window = XCreateWindow(XtDisplay(wid),
  1004.         wid->core.screen->root, (int)wid->core.x, (int)wid->core.y,
  1005.         (unsigned int)wid->core.width, (unsigned int)wid->core.height,
  1006.         (unsigned int)wid->core.border_width, (int) wid->core.depth,
  1007.         (unsigned int) InputOutput, w->shell.visual,
  1008.         mask, attr);
  1009.  
  1010.     _popup_set_prop(w);
  1011. }
  1012.  
  1013.  
  1014. static void _SetTransientForHint(w, delete)
  1015.      TransientShellWidget w;
  1016.      Boolean delete;
  1017. {
  1018.     Window window_group;
  1019.  
  1020.     if (w->wm.transient) {
  1021.     if (w->transient.transient_for != NULL
  1022.         && XtIsRealized(w->transient.transient_for))
  1023.         window_group = XtWindow(w->transient.transient_for);
  1024.     else if ((window_group = w->wm.wm_hints.window_group)
  1025.          == XtUnspecifiedWindowGroup) {
  1026.         if (delete)
  1027.         XDeleteProperty( XtDisplay((Widget)w),
  1028.                  XtWindow((Widget)w),
  1029.                  XA_WM_TRANSIENT_FOR
  1030.                 );
  1031.         return;
  1032.     }
  1033.  
  1034.     XSetTransientForHint( XtDisplay((Widget)w),
  1035.                   XtWindow((Widget)w),
  1036.                   window_group
  1037.                  );
  1038.     }
  1039. }
  1040.  
  1041.  
  1042. static void TransientRealize(w, vmask, attr)
  1043.      Widget w;
  1044.      Mask *vmask;
  1045.      XSetWindowAttributes *attr;
  1046. {
  1047.     (*transientShellWidgetClass->core_class.superclass->
  1048.      core_class.realize) (w, vmask, attr);
  1049.  
  1050.     _SetTransientForHint((TransientShellWidget)w, False);
  1051. }
  1052.  
  1053.  
  1054. static void EvaluateWMHints(w)
  1055.     WMShellWidget w;
  1056. {
  1057.     XWMHints *hintp = &w->wm.wm_hints;
  1058.  
  1059.     hintp->flags = StateHint | InputHint;
  1060.  
  1061.     if (hintp->icon_x == XtUnspecifiedShellInt)
  1062.         hintp->icon_x = -1;
  1063.     else
  1064.         hintp->flags |= IconPositionHint;
  1065.  
  1066.     if (hintp->icon_y == XtUnspecifiedShellInt)
  1067.         hintp->icon_y = -1;
  1068.     else
  1069.         hintp->flags |= IconPositionHint;
  1070.  
  1071.     if (hintp->icon_pixmap != None) hintp->flags |= IconPixmapHint;
  1072.     if (hintp->icon_mask != None)   hintp->flags |= IconMaskHint;
  1073.     if (hintp->icon_window != None) hintp->flags |= IconWindowHint;
  1074.  
  1075.     if (hintp->window_group == XtUnspecifiedWindow) {
  1076.         if(w->core.parent) {
  1077.         Widget p;
  1078.         for (p = w->core.parent; p->core.parent; p = p->core.parent);
  1079.         if (XtIsRealized(p)) {
  1080.             hintp->window_group = XtWindow(p);
  1081.             hintp->flags |=  WindowGroupHint;
  1082.         }
  1083.         }
  1084.     } else if (hintp->window_group != XtUnspecifiedWindowGroup)
  1085.         hintp->flags |=  WindowGroupHint;
  1086. }
  1087.  
  1088.  
  1089. static void EvaluateSizeHints(w)
  1090.     WMShellWidget w;
  1091. {
  1092.     struct _OldXSizeHints *sizep = &w->wm.size_hints;
  1093.  
  1094.     sizep->x = w->core.x;
  1095.     sizep->y = w->core.y;
  1096.     sizep->width = w->core.width;
  1097.     sizep->height = w->core.height;
  1098.  
  1099.     if (sizep->flags & USSize) {
  1100.         if (sizep->flags & PSize) sizep->flags &= ~PSize;
  1101.     } else
  1102.         sizep->flags |= PSize;
  1103.  
  1104.     if (sizep->flags & USPosition) {
  1105.         if (sizep->flags & PPosition) sizep->flags &= ~PPosition;
  1106.     } else if (w->shell.client_specified & _XtShellPPositionOK)
  1107.         sizep->flags |= PPosition;
  1108.  
  1109.     if (sizep->min_aspect.x != XtUnspecifiedShellInt
  1110.         || sizep->min_aspect.y != XtUnspecifiedShellInt
  1111.         || sizep->max_aspect.x != XtUnspecifiedShellInt
  1112.         || sizep->max_aspect.y != XtUnspecifiedShellInt) {
  1113.         sizep->flags |= PAspect;
  1114.     }
  1115.     if(w->wm.base_width != XtUnspecifiedShellInt
  1116.        || w->wm.base_height != XtUnspecifiedShellInt) {
  1117.         sizep->flags |= PBaseSize;
  1118.         if (w->wm.base_width == XtUnspecifiedShellInt)
  1119.         w->wm.base_width = 0;
  1120.         if (w->wm.base_height == XtUnspecifiedShellInt)
  1121.         w->wm.base_height = 0;
  1122.     }
  1123.     if (sizep->width_inc != XtUnspecifiedShellInt
  1124.         || sizep->height_inc != XtUnspecifiedShellInt) {
  1125.         if (sizep->width_inc < 1) sizep->width_inc = 1;
  1126.         if (sizep->height_inc < 1) sizep->height_inc = 1;
  1127.         sizep->flags |= PResizeInc;
  1128.     }
  1129.     if (sizep->max_width != XtUnspecifiedShellInt
  1130.         || sizep->max_height != XtUnspecifiedShellInt) {
  1131.         sizep->flags |= PMaxSize;
  1132.         if (sizep->max_width == XtUnspecifiedShellInt)
  1133.         sizep->max_width = BIGSIZE;
  1134.         if (sizep->max_height == XtUnspecifiedShellInt)
  1135.         sizep->max_height = BIGSIZE;
  1136.     }
  1137.     if(sizep->min_width != XtUnspecifiedShellInt
  1138.        || sizep->min_height != XtUnspecifiedShellInt) {
  1139.         sizep->flags |= PMinSize;
  1140.         if (sizep->min_width == XtUnspecifiedShellInt)
  1141.         sizep->min_width = 1;
  1142.         if (sizep->min_height == XtUnspecifiedShellInt)
  1143.         sizep->min_height = 1;
  1144.     }
  1145. }
  1146.  
  1147. static void _popup_set_prop(w)
  1148.     ShellWidget w;
  1149. {
  1150.     Widget p;
  1151.     WMShellWidget wmshell = (WMShellWidget) w;
  1152.     TopLevelShellWidget tlshell = (TopLevelShellWidget) w;
  1153.     ApplicationShellWidget appshell = (ApplicationShellWidget) w;
  1154.     XTextProperty icon_name;
  1155.     XTextProperty window_name;
  1156.     char **argv;
  1157.     int argc;
  1158.     XSizeHints *size_hints;
  1159.     Window window_group;
  1160.     XClassHint classhint;
  1161.     Boolean copied_iname, copied_wname;
  1162.  
  1163.     if (!XtIsWMShell((Widget)w) || w->shell.override_redirect) return;
  1164.  
  1165.     if ((size_hints = XAllocSizeHints()) == NULL)
  1166.         _XtAllocError("XAllocSizeHints");
  1167.  
  1168.     copied_iname = copied_wname = False;
  1169.         if (wmshell->wm.title_encoding == None &&
  1170.         XmbTextListToTextProperty(XtDisplay((Widget)w),
  1171.                       (char**)&wmshell->wm.title,
  1172.                       1, XStdICCTextStyle,
  1173.                       &window_name) >= Success) {
  1174.         copied_wname = True;
  1175.     } else {
  1176.         window_name.value = (unsigned char*)wmshell->wm.title;
  1177.         window_name.encoding = wmshell->wm.title_encoding;
  1178.         window_name.format = 8;
  1179.         window_name.nitems = strlen((char *)window_name.value);
  1180.     }
  1181.  
  1182.     if (XtIsTopLevelShell((Widget)w)) {
  1183.             if (tlshell->topLevel.icon_name_encoding == None &&
  1184.         XmbTextListToTextProperty(XtDisplay((Widget)w),
  1185.                       (char**)&tlshell->topLevel.icon_name,
  1186.                       1, XStdICCTextStyle,
  1187.                       &icon_name) >= Success) {
  1188.         copied_iname = True;
  1189.         } else {
  1190.         icon_name.value = (unsigned char*)tlshell->topLevel.icon_name;
  1191.         icon_name.encoding = tlshell->topLevel.icon_name_encoding;
  1192.         icon_name.format = 8;
  1193.         icon_name.nitems = strlen((char *)icon_name.value);
  1194.         }
  1195.     }
  1196.  
  1197.     EvaluateWMHints(wmshell);
  1198.     EvaluateSizeHints(wmshell);
  1199.     ComputeWMSizeHints(wmshell, size_hints);
  1200.  
  1201.     if (wmshell->wm.transient
  1202.         && !XtIsTransientShell((Widget)w)
  1203.         && (window_group = wmshell->wm.wm_hints.window_group)
  1204.            != XtUnspecifiedWindowGroup) {
  1205.  
  1206.         XSetTransientForHint(XtDisplay((Widget)w),
  1207.                  XtWindow((Widget)w),
  1208.                  window_group
  1209.                  );
  1210.     }
  1211.  
  1212.     classhint.res_name = w->core.name;
  1213.     /* For the class, look up to the top of the tree */
  1214.     for (p = (Widget)w; p->core.parent != NULL; p = p->core.parent);
  1215.     if (XtIsApplicationShell(p)) {
  1216.         classhint.res_class =
  1217.         ((ApplicationShellWidget)p)->application.class;
  1218.     } else classhint.res_class = XtClass(p)->core_class.class_name;
  1219.  
  1220.     if (XtIsApplicationShell((Widget)w)
  1221.         && (argc = appshell->application.argc) != -1)
  1222.         argv = (char**)appshell->application.argv;
  1223.     else {
  1224.         argv = NULL;
  1225.         argc = 0;
  1226.     }
  1227.  
  1228.     XSetWMProperties(XtDisplay((Widget)w), XtWindow((Widget)w),
  1229.              &window_name,
  1230.              (XtIsTopLevelShell((Widget)w)) ? &icon_name : NULL,
  1231.              argv, argc,
  1232.              size_hints,
  1233.              &wmshell->wm.wm_hints,
  1234.              &classhint);
  1235.     XFree((char*)size_hints);
  1236.     if (copied_wname)
  1237.         XFree((XPointer)window_name.value);
  1238.     if (copied_iname)
  1239.         XFree((XPointer)icon_name.value);
  1240.  
  1241.     if (XtWidgetToApplicationContext((Widget)w)->langProcRec.proc) {
  1242.         char *locale = setlocale(LC_CTYPE, (char *)NULL);
  1243.         if (locale)
  1244.         XChangeProperty(XtDisplay((Widget)w), XtWindow((Widget)w),
  1245.                 XInternAtom(XtDisplay((Widget)w),
  1246.                         "WM_LOCALE_NAME", False),
  1247.                 XA_STRING, 8, PropModeReplace,
  1248.                 (unsigned char *)locale, strlen(locale));
  1249.     }
  1250. }
  1251.  
  1252. /* ARGSUSED */
  1253. static void EventHandler(wid, closure, event, continue_to_dispatch)
  1254.     Widget wid;
  1255.     XtPointer closure;    /* unused */
  1256.     XEvent *event;
  1257.         Boolean *continue_to_dispatch; /* unused */
  1258. {
  1259.     register ShellWidget w = (ShellWidget) wid;
  1260.     WMShellWidget wmshell = (WMShellWidget) w;
  1261.     Boolean  sizechanged = FALSE;
  1262.     unsigned int width, height, border_width, tmpdepth;
  1263.     int tmpx, tmpy, tmp2x, tmp2y;
  1264.     Window tmproot, tmpchild;
  1265.  
  1266.     if(w->core.window != event->xany.window) {
  1267.         XtAppErrorMsg(XtWidgetToApplicationContext(wid),
  1268.             "invalidWindow","eventHandler",XtCXtToolkitError,
  1269.                         "Event with wrong window",
  1270.             (String *)NULL, (Cardinal *)NULL);
  1271.         return;
  1272.     }
  1273.  
  1274.     switch(event->type) {
  1275.         case ConfigureNotify:
  1276.             if (w->core.window != event->xconfigure.window)
  1277.             return;  /* in case of SubstructureNotify */
  1278. #define NEQ(x)    ( w->core.x != event->xconfigure.x )
  1279.         if( NEQ(width) || NEQ(height) || NEQ(border_width) ) {
  1280.             sizechanged = TRUE;
  1281. #undef NEQ
  1282.             w->core.width = event->xconfigure.width;
  1283.             w->core.height = event->xconfigure.height;
  1284.             w->core.border_width = event->xconfigure.border_width;
  1285.         }
  1286.         if (event->xany.send_event /* ICCCM compliant synthetic ev */
  1287.             /* || w->shell.override_redirect */
  1288.             || w->shell.client_specified & _XtShellNotReparented)
  1289.             {
  1290.             w->core.x = event->xconfigure.x;
  1291.             w->core.y = event->xconfigure.y;
  1292.             w->shell.client_specified |= _XtShellPositionValid;
  1293.         }
  1294.         else w->shell.client_specified &= ~_XtShellPositionValid;
  1295.         if (XtIsWMShell(wid) && !wmshell->wm.wait_for_wm) {
  1296.             /* Consider trusting the wm again */
  1297.             register struct _OldXSizeHints *hintp
  1298.             = &wmshell->wm.size_hints;
  1299. #define EQ(x) (hintp->x == w->core.x)
  1300.             if (EQ(x) && EQ(y) && EQ(width) && EQ(height)) {
  1301.             wmshell->wm.wait_for_wm = TRUE;
  1302.             }
  1303. #undef EQ
  1304.         }            
  1305.         break;
  1306.  
  1307.         case ClientMessage:
  1308.         if( event->xclient.message_type == WM_CONFIGURE_DENIED(wid)
  1309.             && XtIsWMShell(wid)) {
  1310.  
  1311.             /* 
  1312.              * UT Oh! the window manager has come back alive
  1313.              * This means either I didn't wait long enough or
  1314.              * The WM is sick.
  1315.              * Query my real size and position, and adjust my child
  1316.              * it needs be.
  1317.              */
  1318.  
  1319.             if(wmshell->wm.wait_for_wm) {
  1320.             XtAppWarningMsg(XtWidgetToApplicationContext(wid),
  1321.                 "communicationError","windowManager",
  1322.                                   XtCXtToolkitError,
  1323.                                   "Window Manager is confused",
  1324.                   (String *)NULL, (Cardinal *)NULL);
  1325.             }
  1326.             wmshell->wm.wait_for_wm = TRUE;
  1327.             (void) XGetGeometry(XtDisplay(w), XtWindow(w), &tmproot,
  1328.                 &tmpx, &tmpy, &width, &height, &border_width,
  1329.                 &tmpdepth);
  1330.             (void) XTranslateCoordinates(XtDisplay(w), XtWindow(w), 
  1331.                 tmproot, (int) tmpx, (int) tmpy,
  1332.                 &tmp2x, &tmp2y, &tmpchild);
  1333.             w->core.x = tmp2x;
  1334.             w->core.y = tmp2y;
  1335.             if( width != w->core.width || height != w->core.height
  1336.                || border_width != w->core.border_width ) {
  1337.                 w->core.width = width;
  1338.                 w->core.height = height;
  1339.                 w->core.border_width = border_width;
  1340.                 sizechanged = TRUE;
  1341.             }
  1342.  
  1343.             break;
  1344.         }
  1345.         if(event->xclient.message_type == WM_MOVED(wid)) {
  1346.             w->core.x = event->xclient.data.s[0];
  1347.             w->core.y  = event->xclient.data.s[1];
  1348.             if (XtIsWMShell((Widget)w)) {
  1349.             WMShellWidget wmshell = (WMShellWidget) w;
  1350.             /* Any window manager which sends this must be 
  1351.                good guy.  Let's reset our flag. */
  1352.             wmshell->wm.wait_for_wm = TRUE;
  1353.             }
  1354.         }
  1355.         break;
  1356.  
  1357.           case ReparentNotify:
  1358.         if (event->xreparent.window == XtWindow(w)) {
  1359.            if (event->xreparent.parent != RootWindowOfScreen(XtScreen(w)))
  1360.                w->shell.client_specified &= ~_XtShellNotReparented;
  1361.            else
  1362.                w->shell.client_specified |= _XtShellNotReparented;
  1363.            w->shell.client_specified &= ~_XtShellPositionValid;
  1364.             }
  1365.         return;
  1366.            case UnmapNotify:
  1367.          {
  1368.              XtPerDisplayInput    pdi;
  1369.              XtDevice        device;
  1370.              Widget        p;
  1371.  
  1372.              pdi = _XtGetPerDisplayInput(event->xunmap.display);
  1373.  
  1374.              device = &pdi->pointer;
  1375.              if (device->grabType == XtPassiveServerGrab) {
  1376.              p = device->grab.widget;
  1377.              while (p && !(XtIsShell(p)))
  1378.                  p = p->core.parent;
  1379.              if (p == wid)
  1380.                  device->grabType = XtNoServerGrab;
  1381.              }
  1382.  
  1383.              device = &pdi->keyboard;
  1384.              if (IsEitherPassiveGrab(device->grabType)) {
  1385.              p = device->grab.widget;
  1386.              while (p && !(XtIsShell(p)))
  1387.                  p = p->core.parent;
  1388.              if (p == wid) {
  1389.                  device->grabType = XtNoServerGrab;
  1390.                  pdi->activatingKey = 0;
  1391.              }
  1392.              }
  1393.  
  1394.              return;
  1395.          }
  1396.  
  1397.           default:
  1398.          return;
  1399.      } 
  1400.  
  1401.      if (sizechanged && 
  1402.                  XtClass(wid)->core_class.resize != (XtWidgetProc) NULL) {
  1403.          _GeoPrintTrace((Widget)w,"Shell \"%s\" is being resized to %d %d.\n", XtName(wid), wid->core.width, wid->core.height );
  1404.          (*(XtClass(wid)->core_class.resize))(wid);
  1405.      }
  1406.  
  1407. }
  1408.  
  1409. static void Destroy(wid)
  1410.     Widget wid;
  1411. {
  1412.     if (XtIsRealized(wid))
  1413.         XDestroyWindow( XtDisplay(wid), XtWindow(wid) );
  1414. }
  1415.  
  1416. static void WMDestroy(wid)
  1417.     Widget wid;
  1418. {
  1419.     WMShellWidget w = (WMShellWidget) wid;
  1420.  
  1421.     XtFree((char *) w->wm.title);
  1422. }
  1423.  
  1424. static void TopLevelDestroy(wid)
  1425.     Widget wid;
  1426. {
  1427.     TopLevelShellWidget w = (TopLevelShellWidget) wid;
  1428.  
  1429.     XtFree((char *) w->topLevel.icon_name);
  1430. }
  1431.  
  1432. static void ApplicationDestroy(wid)
  1433.     Widget wid;
  1434. {
  1435.     ApplicationShellWidget w = (ApplicationShellWidget) wid;
  1436.  
  1437.     if(w->application.argv != NULL) XtFree((char *) w->application.argv);
  1438.     w->application.argv = NULL;
  1439. }
  1440.  
  1441. /*
  1442.  * If the Shell has a width and a height which are zero, and as such
  1443.  * suspect, and it has not yet been realized then it will grow to
  1444.  * match the child before parsing the geometry resource.
  1445.  *
  1446.  */
  1447. static void GetGeometry(W, child)
  1448.     Widget W, child;
  1449. {
  1450.     register ShellWidget w = (ShellWidget)W;
  1451.     Boolean is_wmshell = XtIsWMShell(W);
  1452.     int x, y, width, height, win_gravity = -1, flag;
  1453.     XSizeHints hints;
  1454.  
  1455.     if (child != NULL) {
  1456.     /* we default to our child's size */
  1457.     if (is_wmshell && (w->core.width == 0 || w->core.height == 0))
  1458.         ((WMShellWidget)W)->wm.size_hints.flags |= PSize;
  1459.     if (w->core.width == 0)        w->core.width = child->core.width;
  1460.     if (w->core.height == 0)    w->core.height = child->core.height;
  1461.     }
  1462.     if(w->shell.geometry != NULL) {
  1463.     char def_geom[64];
  1464.     x = w->core.x;
  1465.     y = w->core.y;
  1466.     width = w->core.width;
  1467.     height = w->core.height;
  1468.     if (is_wmshell) {
  1469.         WMShellPart* wm = &((WMShellWidget)w)->wm;
  1470.         EvaluateSizeHints((WMShellWidget)w);
  1471.         bcopy((char*)&wm->size_hints, (char*)&hints,
  1472.           sizeof(struct _OldXSizeHints));
  1473.         hints.win_gravity = wm->win_gravity;
  1474.         if (wm->size_hints.flags & PBaseSize) {
  1475.         width -= wm->base_width;
  1476.         height -= wm->base_height;
  1477.         hints.base_width = wm->base_width;
  1478.         hints.base_height = wm->base_height;
  1479.         }
  1480.         else if (wm->size_hints.flags & PMinSize) {
  1481.         width -= wm->size_hints.min_width;
  1482.         height -= wm->size_hints.min_height;
  1483.         }
  1484.         if (wm->size_hints.flags & PResizeInc) {
  1485.         width /= wm->size_hints.width_inc;
  1486.         height /= wm->size_hints.height_inc;
  1487.         }
  1488.     }
  1489.     else hints.flags = 0;
  1490.  
  1491.     sprintf( def_geom, "%dx%d+%d+%d", width, height, x, y );
  1492.     flag = XWMGeometry( XtDisplay(W),
  1493.                 XScreenNumberOfScreen(XtScreen(W)),
  1494.                 w->shell.geometry, def_geom,
  1495.                 (unsigned int)w->core.border_width,
  1496.                 &hints, &x, &y, &width, &height,
  1497.                 &win_gravity
  1498.                );
  1499.     if (flag) {
  1500.         if (flag & XValue) w->core.x = (Position)x;
  1501.         if (flag & YValue) w->core.y = (Position)y;
  1502.         if (flag & WidthValue) w->core.width = (Dimension)width;
  1503.         if (flag & HeightValue) w->core.height = (Dimension)height;
  1504.     }
  1505.     else {
  1506.         String params[2];
  1507.         Cardinal num_params = 2;
  1508.         params[0] = XtName(W);
  1509.         params[1] = w->shell.geometry;
  1510.         XtAppWarningMsg(XtWidgetToApplicationContext(W),
  1511.        "badGeometry", "shellRealize", XtCXtToolkitError,
  1512.        "Shell widget \"%s\" has an invalid geometry specification: \"%s\"",
  1513.                 params, &num_params);
  1514.     }
  1515.     }
  1516.     else
  1517.     flag = 0;
  1518.  
  1519.     if (is_wmshell) {
  1520.     WMShellWidget wmshell = (WMShellWidget) w;
  1521.     if (wmshell->wm.win_gravity == XtUnspecifiedShellInt) {
  1522.         if (win_gravity != -1)
  1523.         wmshell->wm.win_gravity = win_gravity;
  1524.         else
  1525.         wmshell->wm.win_gravity = NorthWestGravity;
  1526.     }
  1527.     wmshell->wm.size_hints.flags |= PWinGravity;
  1528.     if ((flag & (XValue|YValue)) == (XValue|YValue))
  1529.         wmshell->wm.size_hints.flags |= USPosition;
  1530.     if ((flag & (WidthValue|HeightValue)) == (WidthValue|HeightValue))
  1531.         wmshell->wm.size_hints.flags |= USSize;
  1532.     }
  1533.     w->shell.client_specified |= _XtShellGeometryParsed;
  1534. }
  1535.  
  1536.  
  1537. static void ChangeManaged(wid)
  1538.     Widget wid;
  1539. {
  1540.     ShellWidget w = (ShellWidget) wid;
  1541.     Widget child = NULL;
  1542.     int i;
  1543.  
  1544.     for (i = 0; i < w->composite.num_children; i++) {
  1545.     if (XtIsManaged(w->composite.children[i])) {
  1546.         child = w->composite.children[i];
  1547.         break;        /* there can only be one of them! */
  1548.     }
  1549.     }
  1550.         
  1551.     if (!XtIsRealized (wid))    /* then we're about to be realized... */
  1552.     GetGeometry(wid, child);
  1553.  
  1554. /* we're already realized and allowShellResize is True, so
  1555.    pay attention to our child preferred size and ask the RGM
  1556.    to become this size ------------
  1557.  
  1558.         else if (w->shell.allow_shell_resize && child) {
  1559.  
  1560.     XtWidgetGeometry child_reply;
  1561.  
  1562.     (void) XtQueryGeometry (child, NULL, &child_reply);
  1563.     (void) XtMakeResizeRequest(w, child_reply.width, child_reply.height, 
  1564.                    NULL, NULL);
  1565.     }
  1566. */
  1567.     if (child != NULL)
  1568.     XtConfigureWidget (child, (Position)0, (Position)0,
  1569.                w->core.width, w->core.height, (Dimension)0 );
  1570. }
  1571.  
  1572. /*
  1573.  * This is gross, I can't wait to see if the change happened so I will ask
  1574.  * the window manager to change my size and do the appropriate X work.
  1575.  * I will then tell the requester that he can.  Care must be taken because
  1576.  * it is possible that some time in the future the request will be
  1577.  * asynchronusly denied and the window reverted to it's old size/shape.
  1578.  */
  1579.  
  1580. /*ARGSUSED*/
  1581. static XtGeometryResult GeometryManager( wid, request, reply )
  1582.     Widget wid;
  1583.     XtWidgetGeometry *request;
  1584.     XtWidgetGeometry *reply;
  1585. {
  1586.     ShellWidget shell = (ShellWidget)(wid->core.parent);
  1587.     XtWidgetGeometry my_request;
  1588.  
  1589.     if(shell->shell.allow_shell_resize == FALSE && XtIsRealized(wid))
  1590.         return(XtGeometryNo);
  1591.  
  1592.     if (request->request_mode & (CWX | CWY))
  1593.         return(XtGeometryNo);
  1594.  
  1595.     /* %%% worry about XtCWQueryOnly */
  1596.     my_request.request_mode = 0;
  1597.     if (request->request_mode & CWWidth) {
  1598.         my_request.width = request->width;
  1599.         my_request.request_mode |= CWWidth;
  1600.     }
  1601.     if (request->request_mode & CWHeight) {
  1602.         my_request.height = request->height;
  1603.         my_request.request_mode |= CWHeight;
  1604.     }
  1605.     if (request->request_mode & CWBorderWidth) {
  1606.         my_request.border_width = request->border_width;
  1607.         my_request.request_mode |= CWBorderWidth;
  1608.     }
  1609.     if (XtMakeGeometryRequest((Widget)shell, &my_request, NULL)
  1610.         == XtGeometryYes) {
  1611.         /* assert: if (request->request_mode & CWWidth) then
  1612.          *           shell->core.width == request->width
  1613.          * assert: if (request->request_mode & CWHeight) then
  1614.          *           shell->core.height == request->height
  1615.          *
  1616.          * so, whatever the WM sized us to (if the Shell requested
  1617.          * only one of the two) is now the correct child size
  1618.          */
  1619.         
  1620.         wid->core.width = shell->core.width;
  1621.         wid->core.height = shell->core.height;
  1622.         if (request->request_mode & CWBorderWidth) {
  1623.         wid->core.x = wid->core.y = -request->border_width;
  1624.         }
  1625.         return XtGeometryYes;
  1626.     } else return XtGeometryNo;
  1627. }
  1628.  
  1629. typedef struct {
  1630.     Widget  w;
  1631.     unsigned long request_num;
  1632.     Boolean done;
  1633. } QueryStruct;
  1634.  
  1635. static Bool isMine(dpy, event, arg)
  1636.     Display *dpy;
  1637.     register XEvent  *event;
  1638.     char *arg;
  1639. {
  1640.     QueryStruct *q = (QueryStruct *) arg;
  1641.     register Widget w = q->w;
  1642.  
  1643.     if ( (dpy != XtDisplay(w)) || (event->xany.window != XtWindow(w)) ) {
  1644.         return FALSE;
  1645.     }
  1646.     if (event->xany.serial >= q->request_num) {
  1647.         if (event->type == ConfigureNotify) {
  1648.                 q->done = TRUE;
  1649.         return TRUE;
  1650.         } else
  1651.         /* This is draft-ICCCM stuff; here for compatibility */
  1652.         if (event->type == ClientMessage &&
  1653.             (event->xclient.message_type == WM_CONFIGURE_DENIED(w) ||
  1654.              event->xclient.message_type == WM_MOVED(w))) {
  1655.             q->done = TRUE;
  1656.             return TRUE;
  1657.         }
  1658.     }
  1659.     else if (event->type == ConfigureNotify ||
  1660.          (event->type == ClientMessage &&
  1661.           (event->xclient.message_type == WM_CONFIGURE_DENIED(w) ||
  1662.            event->xclient.message_type == WM_MOVED(w)))) {
  1663.         return TRUE;    /* flush old events */
  1664. }
  1665.     if (event->type == ReparentNotify
  1666.          && event->xreparent.window == XtWindow(w)) {
  1667.         /* we might get ahead of this event, so just in case someone
  1668.          * asks for coordinates before this event is dispatched...
  1669.          */
  1670.         register ShellWidget s = (ShellWidget)w;
  1671.         if (event->xreparent.parent != RootWindowOfScreen(XtScreen(w)))
  1672.         s->shell.client_specified &= ~_XtShellNotReparented;
  1673.         else
  1674.         s->shell.client_specified |= _XtShellNotReparented;
  1675.     }
  1676.     return FALSE;
  1677. }
  1678.  
  1679. static _wait_for_response(w, event, request_num)
  1680.     ShellWidget    w;
  1681.     XEvent        *event;
  1682.         unsigned long    request_num;
  1683. {
  1684.     XtAppContext app = XtWidgetToApplicationContext((Widget) w);
  1685.     QueryStruct q;
  1686.     unsigned long timeout;
  1687.  
  1688.     if (XtIsWMShell((Widget)w))
  1689.         timeout = ((WMShellWidget)w)->wm.wm_timeout;
  1690.     else
  1691.         timeout = DEFAULT_WM_TIMEOUT;
  1692.  
  1693.     XFlush(XtDisplay(w));
  1694.     q.w = (Widget) w;
  1695.     q.request_num = request_num;
  1696.     q.done = FALSE;
  1697.     
  1698.     for(;;) {
  1699.          /*
  1700.           * look for match event and discard all prior configures
  1701.           */
  1702.         if (XCheckIfEvent( XtDisplay(w), event, isMine, (char*)&q)) {
  1703.         if (q.done)
  1704.             return TRUE;
  1705.         else
  1706.             continue;    /* flush old events */
  1707.         }
  1708.  
  1709.         if (_XtwaitForSomething(TRUE, TRUE, FALSE, TRUE, &timeout, app)
  1710.         != -1) continue;
  1711.         if (timeout == 0)
  1712.         return FALSE;
  1713.     }
  1714. }
  1715.  
  1716. /*ARGSUSED*/
  1717. static XtGeometryResult RootGeometryManager(gw, request, reply)
  1718.     Widget gw;
  1719.     XtWidgetGeometry *request, *reply;
  1720. {
  1721.     register ShellWidget w = (ShellWidget)gw;
  1722.     XWindowChanges values;
  1723.     unsigned int mask = request->request_mode;
  1724.     XEvent event;
  1725.     Boolean wm;
  1726.     register struct _OldXSizeHints *hintp;
  1727.     int oldx, oldy, oldwidth, oldheight, oldborder_width;
  1728.     unsigned long request_num;
  1729.  
  1730.     _GeoTabTrace();
  1731.     
  1732.     if (XtIsWMShell(gw)) {
  1733.     wm = True;
  1734.     hintp = &((WMShellWidget)w)->wm.size_hints;
  1735.     /* for draft-ICCCM wm's, need to make sure hints reflect
  1736.        (current) reality so client can move and size separately. */
  1737.       hintp->x = w->core.x;
  1738.       hintp->y = w->core.y;
  1739.       hintp->width = w->core.width;
  1740.        hintp->height = w->core.height;
  1741.     } else
  1742.     wm = False;
  1743.     
  1744.     oldx = w->core.x;
  1745.     oldy = w->core.y;
  1746.     oldwidth = w->core.width;
  1747.     oldheight = w->core.height;
  1748.     oldborder_width = w->core.border_width;
  1749.  
  1750. #define PutBackGeometry() \
  1751.     { w->core.x = oldx; \
  1752.       w->core.y = oldy; \
  1753.       w->core.width = oldwidth; \
  1754.       w->core.height = oldheight; \
  1755.       w->core.border_width = oldborder_width; }
  1756.  
  1757.     if (mask & CWX) {
  1758.         if (w->core.x == request->x) mask &= ~CWX;
  1759.         else {
  1760.         w->core.x = values.x = request->x;
  1761.         if (wm) {
  1762.             hintp->flags &= ~USPosition;
  1763.             hintp->flags |= PPosition;
  1764.             hintp->x = values.x;
  1765.         }
  1766.         }
  1767.     }
  1768.     if (mask & CWY) {
  1769.         if (w->core.y == request->y) mask &= ~CWY;
  1770.         else {
  1771.         w->core.y = values.y = request->y;
  1772.         if (wm) {
  1773.             hintp->flags &= ~USPosition;
  1774.             hintp->flags |= PPosition;
  1775.             hintp->y = values.y;
  1776.         }
  1777.         }
  1778.     }
  1779.     if (mask & CWBorderWidth) {
  1780.         if (w->core.border_width == request->border_width) {
  1781.             mask &= ~CWBorderWidth;
  1782.         } else
  1783.         w->core.border_width =
  1784.             values.border_width =
  1785.             request->border_width;
  1786.     }
  1787.     if (mask & CWWidth) {
  1788.         if (w->core.width == request->width) mask &= ~CWWidth;
  1789.         else {
  1790.         w->core.width = values.width = request->width;
  1791.         if (wm) {
  1792.             hintp->flags &= ~USSize;
  1793.             hintp->flags |= PSize;
  1794.             hintp->width = values.width;
  1795.         }
  1796.         }
  1797.     }
  1798.     if (mask & CWHeight) {
  1799.         if (w->core.height == request->height) mask &= ~CWHeight;
  1800.         else {
  1801.         w->core.height = values.height = request->height;
  1802.         if (wm) {
  1803.             hintp->flags &= ~USSize;
  1804.             hintp->flags |= PSize;
  1805.             hintp->height = values.height;
  1806.         }
  1807.         }
  1808.     }
  1809.     if (mask & CWStackMode) {
  1810.     values.stack_mode = request->stack_mode;
  1811.     if (mask & CWSibling)
  1812.         values.sibling = XtWindow(request->sibling);
  1813.     }
  1814.  
  1815.  
  1816.     if (!XtIsRealized((Widget)w)) {
  1817.  
  1818.     _GeoPrintTrace((Widget)w,
  1819.                "Shell \"%s\" is not realized, return XtGeometryYes.\n", 
  1820.                XtName((Widget)w));
  1821.         _GeoUnTabTrace();
  1822.     return XtGeometryYes;
  1823.     }
  1824.  
  1825.     request_num = NextRequest(XtDisplay(w));
  1826.  
  1827.     _GeoPrintTrace((Widget)w,"XConfiguring the Shell X window :\n");
  1828.     _GeoTabTrace();
  1829.     if (mask & CWX) { _GeoPrintTrace((Widget)w,"x = %d\n",values.x);}
  1830.     if (mask & CWY) { _GeoPrintTrace((Widget)w,"y = %d\n",values.y);}
  1831.     if (mask & CWWidth) { _GeoPrintTrace((Widget)w,"width = %d\n",values.width);}
  1832.     if (mask & CWHeight) { _GeoPrintTrace((Widget)w,"height = %d\n",values.height);}
  1833.     if (mask & CWBorderWidth) { _GeoPrintTrace((Widget)w,"border_width = %d\n",values.border_width);}
  1834.     _GeoUnTabTrace();
  1835.     
  1836.  
  1837.     XConfigureWindow(XtDisplay((Widget)w), XtWindow((Widget)w), mask,&values);
  1838.  
  1839.     if (wm && !w->shell.override_redirect
  1840.     && mask & (CWX | CWY | CWWidth | CWHeight | CWBorderWidth)) {
  1841.     _SetWMSizeHints((WMShellWidget)w);
  1842.     }
  1843.  
  1844.     if (w->shell.override_redirect) {
  1845.     _GeoPrintTrace((Widget)w,"Shell \"%s\" is override redirect, return XtGeometryYes.\n", XtName((Widget)w));
  1846.         _GeoUnTabTrace();
  1847.     return XtGeometryYes;
  1848.     }
  1849.  
  1850.     /* If no non-stacking bits are set, there's no way to tell whether
  1851.        or not this worked, so assume it did */
  1852.  
  1853.     if (!(mask & ~(CWStackMode | CWSibling))) return XtGeometryYes;
  1854.  
  1855.     if (wm && ((WMShellWidget)w)->wm.wait_for_wm == FALSE) {
  1856.         /* the window manager is sick
  1857.          * so I will do the work and 
  1858.          * say no so if a new WM starts up,
  1859.          * or the current one recovers
  1860.          * my size requests will be visible
  1861.          */
  1862.     _GeoPrintTrace((Widget)w,"Shell \"%s\" has wait_for_wm == FALSE, return XtGeometryNo.\n", XtName((Widget)w));
  1863.         _GeoUnTabTrace();
  1864.  
  1865.     PutBackGeometry();
  1866.     return XtGeometryNo;
  1867.     }
  1868.  
  1869.     if (_wait_for_response(w, &event, request_num)) {
  1870.     /* got an event */
  1871.     if (event.type == ConfigureNotify) {
  1872.  
  1873. #define NEQ(x, msk) ((mask & msk) && (values.x != event.xconfigure.x))    
  1874.         if (NEQ(x, CWX) ||
  1875.         NEQ(y, CWY) ||
  1876.         NEQ(width, CWWidth) ||
  1877.         NEQ(height, CWHeight) ||
  1878.         NEQ(border_width, CWBorderWidth)) {
  1879.  
  1880.         if (NEQ(x, CWX)) {
  1881.             _GeoPrintTrace((Widget)w,"received Configure X %d\n", 
  1882.                     event.xconfigure.x);}
  1883.         if (NEQ(y, CWY)) {
  1884.             _GeoPrintTrace((Widget)w,"received Configure Y %d\n", 
  1885.                     event.xconfigure.y);}
  1886.         if (NEQ(width, CWWidth)) {
  1887.             _GeoPrintTrace((Widget)w,"received Configure Width %d\n", 
  1888.                     event.xconfigure.width);}
  1889.         if (NEQ(height, CWHeight)) {
  1890.             _GeoPrintTrace((Widget)w,"received Configure Height %d\n", 
  1891.                     event.xconfigure.height);}
  1892.         if (NEQ(border_width, CWBorderWidth)) {
  1893.             _GeoPrintTrace((Widget)w,"received Configure BorderWidth %d\n", 
  1894.                     event.xconfigure.border_width);}
  1895.         
  1896. #undef NEQ
  1897.         XPutBackEvent(XtDisplay(w), &event);
  1898.         PutBackGeometry();
  1899.         /*
  1900.          * We just potentially re-ordered the event queue
  1901.          * w.r.t. ConfigureNotifies with some trepidation.
  1902.          * But this is probably a Good Thing because we
  1903.          * will know the new true state of the world sooner
  1904.          * this way.
  1905.          */
  1906.         _GeoPrintTrace((Widget)w,"ConfigureNotify failed, return XtGeometryNo.\n");
  1907.         _GeoUnTabTrace();
  1908.  
  1909.         return XtGeometryNo;
  1910.         }
  1911.         else {
  1912.         w->core.width = event.xconfigure.width;
  1913.         w->core.height = event.xconfigure.height;
  1914.         w->core.border_width = event.xconfigure.border_width;
  1915.         if (event.xany.send_event || /* ICCCM compliant synth */
  1916.             w->shell.client_specified & _XtShellNotReparented) {
  1917.  
  1918.             w->core.x = event.xconfigure.x;
  1919.             w->core.y = event.xconfigure.y;
  1920.             w->shell.client_specified |= _XtShellPositionValid;
  1921.         }
  1922.         else w->shell.client_specified &= ~_XtShellPositionValid;
  1923.  
  1924.         _GeoPrintTrace((Widget)w,"ConfigureNotify succeed, return XtGeometryYes.\n");
  1925.         _GeoUnTabTrace();
  1926.         return XtGeometryYes;
  1927.         }
  1928.     } else if (!wm ||
  1929.            (event.type == ClientMessage &&
  1930.             event.xclient.message_type == WM_CONFIGURE_DENIED(w))) {
  1931.         PutBackGeometry();
  1932.  
  1933.         _GeoPrintTrace((Widget)w,"No ConfigureNotify event, return XtGeometryNo.\n");
  1934.         _GeoUnTabTrace();
  1935.  
  1936.         return XtGeometryNo;
  1937.     } else if (event.type == ClientMessage &&
  1938.             event.xclient.message_type == WM_MOVED(w)) {
  1939.         w->core.x = event.xclient.data.s[0];
  1940.         w->core.y = event.xclient.data.s[1];
  1941.         w->shell.client_specified |= _XtShellPositionValid;
  1942.         _GeoPrintTrace((Widget)w,"ClientMessage ok, return XtGeometryYes.\n");
  1943.         _GeoUnTabTrace();
  1944.         return XtGeometryYes;
  1945.     } else XtAppWarningMsg(XtWidgetToApplicationContext((Widget)w),
  1946.                    "internalError", "shell", XtCXtToolkitError,
  1947.                    "Shell's window manager interaction is broken",
  1948.                    (String *)NULL, (Cardinal *)NULL);
  1949.     } else if (wm) { /* no event */ 
  1950.     ((WMShellWidget)w)->wm.wait_for_wm = FALSE; /* timed out; must be broken */
  1951.     }
  1952.     PutBackGeometry();
  1953. #undef PutBackGeometry
  1954.  
  1955.     _GeoPrintTrace((Widget)w,"Timeout passed?, return XtGeometryNo.\n");
  1956.     _GeoUnTabTrace();
  1957.  
  1958.     return XtGeometryNo;
  1959. }
  1960.  
  1961. /* ARGSUSED */
  1962. static Boolean SetValues(old, ref, new, args, num_args)
  1963.     Widget old, ref, new;
  1964.     ArgList args;        /* unused */
  1965.     Cardinal *num_args;    /* unused */
  1966. {
  1967.     ShellWidget nw = (ShellWidget) new;
  1968.     ShellWidget ow = (ShellWidget) old;
  1969.     Mask mask = 0;
  1970.     XSetWindowAttributes attr;
  1971.  
  1972.     if (ow->shell.save_under != nw->shell.save_under) {
  1973.         mask = CWSaveUnder;
  1974.         attr.save_under = nw->shell.save_under;
  1975.     }
  1976.  
  1977.     if (ow->shell.override_redirect != nw->shell.override_redirect) {
  1978.         mask |= CWOverrideRedirect;
  1979.         attr.override_redirect = nw->shell.override_redirect;
  1980.     }
  1981.  
  1982.     if (mask && XtIsRealized(new)) {
  1983.         XChangeWindowAttributes(XtDisplay(new),XtWindow(new), mask, &attr);
  1984.         if ((mask & CWOverrideRedirect) && !nw->shell.override_redirect)
  1985.         _popup_set_prop(nw);
  1986.     }
  1987.     return FALSE;
  1988. }
  1989.  
  1990. /* ARGSUSED */
  1991. static Boolean WMSetValues(old, ref, new, args, num_args)
  1992.     Widget old, ref, new;
  1993.     ArgList args;        /* unused */
  1994.     Cardinal *num_args;    /* unused */
  1995. {
  1996.     WMShellWidget nwmshell = (WMShellWidget) new;
  1997.     WMShellWidget owmshell = (WMShellWidget) old;
  1998.     Boolean set_prop
  1999.         = XtIsRealized(new) && !nwmshell->shell.override_redirect;
  2000.     Boolean title_changed;
  2001.  
  2002.     EvaluateSizeHints(nwmshell);
  2003.  
  2004. #define NEQ(f) (nwmshell->wm.size_hints.f != owmshell->wm.size_hints.f)
  2005.  
  2006.     if (set_prop
  2007.         && (NEQ(flags) || NEQ(min_width) || NEQ(min_height)
  2008.         || NEQ(max_width) || NEQ(max_height)
  2009.         || NEQ(width_inc) || NEQ(height_inc)
  2010.         || NEQ(min_aspect.x) || NEQ(min_aspect.y)
  2011.         || NEQ(max_aspect.x) || NEQ(max_aspect.y)
  2012. #undef NEQ
  2013. #define NEQ(f) (nwmshell->wm.f != owmshell->wm.f)
  2014.  
  2015.         || NEQ(base_width) || NEQ(base_height) || NEQ(win_gravity))) {
  2016.         _SetWMSizeHints(nwmshell);
  2017.     }
  2018. #undef NEQ
  2019.  
  2020.     if (nwmshell->wm.title != owmshell->wm.title) {
  2021.         XtFree(owmshell->wm.title);
  2022.         if (! nwmshell->wm.title) nwmshell->wm.title = "";
  2023.         nwmshell->wm.title = XtNewString(nwmshell->wm.title);
  2024.         title_changed = True;
  2025.     } else
  2026.         title_changed = False;
  2027.  
  2028.     if (set_prop
  2029.         && (title_changed ||
  2030.         nwmshell->wm.title_encoding != owmshell->wm.title_encoding)) {
  2031.  
  2032.         XTextProperty title;
  2033.         Boolean copied = False;
  2034.  
  2035.             if (nwmshell->wm.title_encoding == None &&
  2036.         XmbTextListToTextProperty(XtDisplay(new),
  2037.                       (char**)&nwmshell->wm.title,
  2038.                       1, XStdICCTextStyle,
  2039.                       &title) >= Success) {
  2040.         copied = True;
  2041.         } else {
  2042.         title.value = (unsigned char*)nwmshell->wm.title;
  2043.         title.encoding = nwmshell->wm.title_encoding;
  2044.         title.format = 8;
  2045.         title.nitems = strlen(nwmshell->wm.title);
  2046.         }
  2047.         XSetWMName(XtDisplay(new), XtWindow(new), &title);
  2048.         if (copied)
  2049.         XFree((XPointer)title.value);
  2050.     }
  2051.  
  2052.     EvaluateWMHints(nwmshell);
  2053.  
  2054. #define NEQ(f)    (nwmshell->wm.wm_hints.f != owmshell->wm.wm_hints.f)
  2055.  
  2056.     if (set_prop
  2057.         && (NEQ(flags) || NEQ(input) || NEQ(initial_state)
  2058.         || NEQ(icon_x) || NEQ(icon_y)
  2059.         || NEQ(icon_pixmap) || NEQ(icon_mask) || NEQ(icon_window)
  2060.         || NEQ(window_group))) {
  2061.  
  2062.         XSetWMHints(XtDisplay(new), XtWindow(new), &nwmshell->wm.wm_hints);
  2063.     }
  2064. #undef NEQ
  2065.  
  2066.      if (set_prop && nwmshell->wm.transient != owmshell->wm.transient) {
  2067.          if (nwmshell->wm.transient) {
  2068.         if (!XtIsTransientShell(new) &&
  2069.             nwmshell->wm.wm_hints.window_group != 
  2070.                XtUnspecifiedWindowGroup)
  2071.             XSetTransientForHint(XtDisplay(new), XtWindow(new),
  2072.                      nwmshell->wm.wm_hints.window_group);
  2073.         }
  2074.          else XDeleteProperty(XtDisplay(new), XtWindow(new),
  2075.                   XA_WM_TRANSIENT_FOR);
  2076.      }
  2077.     
  2078.     return FALSE;
  2079. }
  2080.  
  2081. /*ARGSUSED*/
  2082. static Boolean TransientSetValues(oldW, refW, newW, args, num_args)
  2083.      Widget oldW, refW, newW;
  2084.      ArgList args;        /* unused */
  2085.      Cardinal *num_args;    /* unused */
  2086. {
  2087.     TransientShellWidget old = (TransientShellWidget)oldW;
  2088.     TransientShellWidget new = (TransientShellWidget)newW;
  2089.     
  2090.     if (XtIsRealized(newW)
  2091.     && ((new->transient.transient_for != old->transient.transient_for)
  2092.         || (new->transient.transient_for == NULL
  2093.         && (new->wm.wm_hints.window_group
  2094.             != old->wm.wm_hints.window_group)))) {
  2095.  
  2096.     _SetTransientForHint(new, True);
  2097.     }
  2098.     return False;
  2099. }
  2100.  
  2101.  
  2102. /* ARGSUSED */
  2103. static Boolean TopLevelSetValues(oldW, refW, newW, args, num_args)
  2104.      Widget oldW, refW, newW;
  2105.      ArgList args;        /* unused */
  2106.      Cardinal *num_args;    /* unused */
  2107. {
  2108.     TopLevelShellWidget old = (TopLevelShellWidget)oldW;
  2109.     TopLevelShellWidget new = (TopLevelShellWidget)newW;
  2110.     Boolean name_changed;
  2111.  
  2112.     if (old->topLevel.icon_name != new->topLevel.icon_name) {
  2113.     XtFree((XtPointer)old->topLevel.icon_name);
  2114.     if (! new->topLevel.icon_name) new->topLevel.icon_name = "";
  2115.     new->topLevel.icon_name = XtNewString(new->topLevel.icon_name);
  2116.     name_changed = True;
  2117.     } else
  2118.     name_changed = False;
  2119.  
  2120.     if (XtIsRealized(newW)) {
  2121.     if (new->topLevel.iconic != old->topLevel.iconic) {
  2122.         if (new->topLevel.iconic)
  2123.         XIconifyWindow(XtDisplay(newW),
  2124.                    XtWindow(newW),
  2125.                    XScreenNumberOfScreen(XtScreen(newW))
  2126.                    );
  2127.         else {
  2128.         Boolean map = new->shell.popped_up;
  2129.         XtPopup(newW, XtGrabNone);
  2130.         if (map) XMapWindow(XtDisplay(newW), XtWindow(newW));
  2131.          }
  2132.     }
  2133.  
  2134.     if (!new->shell.override_redirect &&
  2135.         (name_changed ||
  2136.          (old->topLevel.icon_name_encoding
  2137.           != new->topLevel.icon_name_encoding))) {
  2138.  
  2139.         XTextProperty icon_name;
  2140.         Boolean copied = False;
  2141.  
  2142.             if (new->topLevel.icon_name_encoding == None &&
  2143.         XmbTextListToTextProperty(XtDisplay(newW),
  2144.                       (char**) &new->topLevel.icon_name,
  2145.                       1, XStdICCTextStyle,
  2146.                       &icon_name) >= Success) {
  2147.         copied = True;
  2148.         } else {
  2149.         icon_name.value = (unsigned char *)new->topLevel.icon_name;
  2150.         icon_name.encoding = new->topLevel.icon_name_encoding;
  2151.         icon_name.format = 8;
  2152.         icon_name.nitems = strlen((char *)icon_name.value);
  2153.         }
  2154.         XSetWMIconName(XtDisplay(newW), XtWindow(newW), &icon_name);
  2155.         if (copied)
  2156.         XFree((XPointer)icon_name.value);
  2157.     }
  2158.     }
  2159.     return False;
  2160. }
  2161.  
  2162.  
  2163. void _XtShellGetCoordinates( widget, x, y)
  2164.     Widget widget;
  2165.     Position* x;
  2166.     Position* y;
  2167. {
  2168.     ShellWidget w = (ShellWidget)widget;
  2169.     if (!(w->shell.client_specified & _XtShellPositionValid)) {
  2170.     int tmpx, tmpy;
  2171.     Window tmpchild;
  2172.     (void) XTranslateCoordinates(XtDisplay(w), XtWindow(w), 
  2173.                      RootWindowOfScreen(XtScreen(w)),
  2174.                      (int) -w->core.border_width,
  2175.                      (int) -w->core.border_width,
  2176.                      &tmpx, &tmpy, &tmpchild);
  2177.     w->core.x = tmpx;
  2178.     w->core.y = tmpy;
  2179.     w->shell.client_specified |= _XtShellPositionValid;
  2180.     }
  2181.     *x = w->core.x;
  2182.     *y = w->core.y;
  2183. }
  2184.  
  2185.  
  2186. static void GetValuesHook(widget, args, num_args)
  2187.     Widget    widget;
  2188.     ArgList    args;
  2189.     Cardinal*    num_args;
  2190. {
  2191.     ShellWidget w = (ShellWidget) widget;
  2192.     extern void _XtCopyToArg();
  2193.  
  2194.     /* x and y resource values may be invalid after a shell resize */
  2195.     if (! (w->shell.client_specified & _XtShellPositionValid)) {
  2196.     Cardinal    n;
  2197.     Position    x, y;
  2198.  
  2199.     for (n = *num_args; n; n--, args++) {
  2200.         if (strcmp(XtNx, args->name) == 0) {
  2201.          if (! (w->shell.client_specified & _XtShellPositionValid))
  2202.              _XtShellGetCoordinates(widget, &x, &y);
  2203.         _XtCopyToArg((char *) &x, &args->value, sizeof(Position));
  2204.         } else if (strcmp(XtNy, args->name) == 0) {
  2205.          if (! (w->shell.client_specified & _XtShellPositionValid))
  2206.              _XtShellGetCoordinates(widget, &x, &y);
  2207.         _XtCopyToArg((char *) &y, &args->value, sizeof(Position));
  2208.         }
  2209.     }
  2210.     }
  2211. }
  2212.   
  2213. static void ApplicationShellInsertChild(widget)
  2214.     Widget widget;
  2215. {
  2216.     if (! XtIsWidget(widget) && XtIsRectObj(widget)) {
  2217.     XtAppWarningMsg(XtWidgetToApplicationContext(widget),
  2218.            "invalidClass", "applicationShellInsertChild", XtCXtToolkitError,
  2219.            "ApplicationShell does not accept RectObj children; ignored",
  2220.            (String*)NULL, (Cardinal*)NULL);
  2221.     }
  2222.     else {
  2223.     (*((CompositeWidgetClass)applicationShellClassRec.core_class.
  2224.        superclass)->composite_class.insert_child) (widget);
  2225.     }
  2226. }
  2227.