home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / XfeWidgets / Xfe / ShellUtil.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  7.6 KB  |  362 lines

  1. /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18. /*-----------------------------------------*/
  19. /*                                                                        */
  20. /* Name:        <Xfe/ShellUtil.h>                                        */
  21. /* Description:    Shell misc utilities source.                            */
  22. /* Author:        Ramiro Estrugo <ramiro@netscape.com>                    */
  23. /*                                                                        */
  24. /*----------------------------------------------------------------------*/
  25.  
  26.  
  27. #include <Xfe/XfeP.h>
  28. #include <Xfe/Cascade.h>
  29.  
  30. #include <Xm/AtomMgr.h>
  31. #include <Xm/Protocols.h>
  32.  
  33. #include <X11/ShellP.h>
  34.  
  35. /*----------------------------------------------------------------------*/
  36. /*                                                                        */
  37. /* Only the Shell widgets have visuals                                    */
  38. /*                                                                        */
  39. /*----------------------------------------------------------------------*/
  40. Visual *
  41. XfeVisual(Widget w)
  42. {
  43.     Widget shell;
  44.  
  45.     assert( w != NULL );
  46.  
  47.     shell = XfeAncestorFindByClass(w,shellWidgetClass,XfeFIND_ANY);
  48.  
  49.     assert( _XfeIsAlive(shell) );
  50.  
  51.     if (!_XfeIsAlive(w))
  52.     {
  53.         return NULL;
  54.     }
  55.  
  56.     return ((ShellWidget) shell) -> shell . visual;
  57. }
  58. /*----------------------------------------------------------------------*/
  59.  
  60. /*----------------------------------------------------------------------*/
  61. /*                                                                        */
  62. /* Misc shell functions                                                    */
  63. /*                                                                        */
  64. /*----------------------------------------------------------------------*/
  65. /* extern */ Boolean
  66. XfeShellIsPoppedUp(Widget shell)
  67. {
  68.     assert( XtIsShell(shell) );
  69.  
  70.     if (!_XfeIsAlive(shell) || !_XfeIsRealized(shell))
  71.     {
  72.         return False;
  73.     }
  74.  
  75.     return ((ShellWidget) shell)->shell.popped_up;
  76. }
  77. /*----------------------------------------------------------------------*/
  78. /* extern */ void
  79. XfeShellAddCloseCallback(Widget            shell,
  80.                          XtCallbackProc    callback,
  81.                          XtPointer        data)
  82. {
  83.     static Atom wm_delete_window = None;
  84.  
  85.     assert( XtIsShell(shell) );
  86.  
  87.     if (!_XfeIsAlive(shell))
  88.     {
  89.         return;
  90.     }
  91.  
  92.     if (wm_delete_window == None)
  93.     {
  94.         wm_delete_window = XmInternAtom(XtDisplay(shell),
  95.                                         "WM_DELETE_WINDOW",
  96.                                         False);
  97.     }
  98.         
  99.     XmAddWMProtocolCallback(shell,wm_delete_window,callback,data);
  100. }
  101. /*----------------------------------------------------------------------*/
  102. /* extern */ void
  103. XfeShellRemoveCloseCallback(Widget            shell,
  104.                             XtCallbackProc    callback,
  105.                             XtPointer        data)
  106. {
  107.     static Atom wm_delete_window = None;
  108.  
  109.     assert( XtIsShell(shell) );
  110.  
  111.     if (!_XfeIsAlive(shell))
  112.     {
  113.         return;
  114.     }
  115.  
  116.     if (wm_delete_window == None)
  117.     {
  118.         wm_delete_window = XmInternAtom(XtDisplay(shell),
  119.                                         "WM_DELETE_WINDOW",
  120.                                         False);
  121.     }
  122.         
  123.     XmRemoveWMProtocolCallback(shell,wm_delete_window,callback,data);
  124. }
  125. /*----------------------------------------------------------------------*/
  126. /* extern */ Boolean
  127. XfeShellGetDecorationOffset(Widget            shell,
  128.                             Position *        x_out,
  129.                             Position *        y_out)
  130. {
  131.     Position    x = 0;
  132.     Position    y = 0;
  133.     Boolean        result = False;
  134.  
  135.     assert( XtIsShell(shell) );
  136.     assert( x_out != NULL || y_out != NULL );
  137.  
  138.     if (_XfeIsAlive(shell))
  139.     {
  140.         Window            root;
  141.         Window            parent = None;
  142.         Window            parent2 = None;
  143.         Window *        children = NULL;
  144.         unsigned int     num_children;
  145.         
  146.         if (!XQueryTree(XtDisplay(shell),_XfeWindow(shell),
  147.                         &root,&parent,&children,&num_children))
  148.         {
  149.             parent2 = None;
  150.         }
  151.         
  152.         if (children)
  153.         {
  154.             XFree(children);
  155.         }
  156.  
  157.         if (children)
  158.         {
  159.             XFree(children);
  160.         }
  161.         
  162.         if (parent != None)
  163.         {
  164.             int                px;
  165.             int                py;
  166.             unsigned int    width;
  167.             unsigned int    height;
  168.             unsigned int    border;
  169.             unsigned int    depth;
  170.             
  171.             if (XGetGeometry(XtDisplay(shell),parent,&root,&px,&py,
  172.                              &width,&height,&border,&depth))
  173.             {
  174.                 x = px;
  175.                 y = py;
  176.  
  177.                 result = True;
  178.             }
  179.         }
  180.     }
  181.  
  182.     if (x_out)
  183.     {
  184.         *x_out = x;
  185.     }
  186.  
  187.     if (y_out)
  188.     {
  189.         *y_out = y;
  190.     }
  191.  
  192.     return result;
  193. }
  194. /*----------------------------------------------------------------------*/
  195. /* extern */ int
  196. XfeShellGetGeometryFromResource(Widget            shell,
  197.                                 Position *        x_out,
  198.                                 Position *        y_out,
  199.                                 Dimension *        width_out,
  200.                                 Dimension *        height_out)
  201. {
  202.     int                mask = 0;
  203.     int                x = 0;
  204.     int                y = 0;
  205.     unsigned int    width = 0;
  206.     unsigned int    height = 0;
  207.  
  208.     assert( XtIsShell(shell) );
  209.  
  210.     if (_XfeIsAlive(shell))
  211.     {
  212.         String geometry;
  213.  
  214.         XtVaGetValues(shell,XmNgeometry,&geometry,NULL);
  215.         
  216.         if (geometry)
  217.         {
  218.             mask = XParseGeometry(geometry,&x,&y,&width,&height);
  219.  
  220.             if (mask & XValue)
  221.             {
  222.                 if (mask & XNegative)
  223.                 {
  224.                     x = - XfeAbs(x);
  225.                 }
  226.             }
  227.             else
  228.             {
  229.                 x = 0;
  230.             }
  231.  
  232.             if (mask & YValue)
  233.             {
  234.                 if (mask & YNegative)
  235.                 {
  236.                     y = - XfeAbs(y);
  237.                 }
  238.             }
  239.             else
  240.             {
  241.                 y = 0;
  242.             }
  243.  
  244.             if (!(mask & WidthValue))
  245.             {
  246.                 width = 0;
  247.             }
  248.  
  249.             if (!(mask & HeightValue))
  250.             {
  251.                 height = 0;
  252.             }
  253.         }
  254.     }
  255.  
  256.     if (x_out)
  257.     {
  258.         *x_out = (Position) x;
  259.     }
  260.  
  261.     if (y_out)
  262.     {
  263.         *y_out = (Position) y;
  264.     }
  265.  
  266.     if (width_out)
  267.     {
  268.         *width_out = (Dimension) width;
  269.     }
  270.  
  271.     if (height_out)
  272.     {
  273.         *height_out = (Dimension) height;
  274.     }
  275.  
  276.     return mask;
  277. }
  278. /*----------------------------------------------------------------------*/
  279. /* extern */ void
  280. XfeShellSetIconicState(Widget shell,Boolean state)
  281. {
  282.   /*
  283.     Because of weirdness in Xt/Shell.c, one can't change the "iconic"
  284.     flag of a shell after it has been created but before it has been realized.
  285.     That resource is only checked when the shell is Initialized (ie, when
  286.     XtCreatePopupShell is called) instead of the more obvious times like:
  287.     when it is Realized (before the window is created) or when it is Managed
  288.     (before window is mapped).
  289.     
  290.     The Shell class's SetValues method does not modify wm_hints.initial_state
  291.     if the widget has not yet been realized - it ignores the request until
  292.     afterward, when it's too late.
  293.    */
  294.  
  295.     assert( XtIsWMShell(shell) );
  296.  
  297.     if (_XfeIsAlive(shell))
  298.     {
  299.         WMShellWidget wms = (WMShellWidget) shell;
  300.         
  301.         XtVaSetValues(shell,XtNiconic,state,NULL);
  302.         
  303.         wms->wm.wm_hints.flags |= StateHint;
  304.         wms->wm.wm_hints.initial_state = (state ? IconicState : NormalState);
  305.     }
  306. }
  307. /*----------------------------------------------------------------------*/
  308. /* extern */ Boolean
  309. XfeShellGetIconicState(Widget shell)
  310. {
  311.     Boolean state = False;
  312.  
  313.     assert( XtIsWMShell(shell) );
  314.  
  315.     if (_XfeIsAlive(shell))
  316.     {
  317.         XtVaGetValues(shell,XtNiconic,&state,NULL);
  318.     }
  319.  
  320.     return state;
  321. }
  322. /*----------------------------------------------------------------------*/
  323. /* extern */ void
  324. XfeShellPlaceAtLocation(Widget            shell,
  325.                         Widget            relative,
  326.                         unsigned char    location,
  327.                         Dimension        dx,
  328.                         Dimension        dy)
  329. {
  330.     int rx;
  331.     int ry;
  332.  
  333.     switch(location)
  334.     {
  335.     case XmLOCATION_EAST:
  336.         break;
  337.  
  338.     case XmLOCATION_NORTH:
  339.         break;
  340.  
  341.     case XmLOCATION_NORTH_EAST:
  342.         break;
  343.  
  344.     case XmLOCATION_NORTH_WEST:
  345.         break;
  346.  
  347.     case XmLOCATION_SOUTH:
  348.         break;
  349.  
  350.     case XmLOCATION_SOUTH_EAST:
  351.         break;
  352.  
  353.     case XmLOCATION_SOUTH_WEST:
  354.         break;
  355.  
  356.     case XmLOCATION_WEST:
  357.         break;
  358.  
  359.     }
  360. }
  361. /*----------------------------------------------------------------------*/
  362.