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