#include <X11/Xlib.h>
#include <Xmt/Xmt.h>

/*
**      xmui_manage manages a widget. If the widget is the child of a top level
**      shell, the shell is popped up, otherwise, we manage the child (assuming
**      it is the child of a dialog shell). In case it was already up, we raise
**      it to the top of the window stack.
*/
void xmui_manage(Widget id)
{
    Widget               shell;
    
    /*
    ** If the shell is top level, pop it up, otherwise manage the child.
    **
    ** If the shell isn't top level, we assume its a Motif dialog shell,
    ** which will pop itself up and down as its child is managed and
    ** unmanaged.
    */
    shell = XtParent(id);
    if(XtIsTopLevelShell(shell))XtPopup(shell, XtGrabNone);
    else XtManageChild(id);

    /*
    ** Raise the window in case it was already up but has been obscured.
    */
    XRaiseWindow(XtDisplay(shell), XtWindow(shell));
}

/*
**      xmui_unmanage unmanages a widget. If it is a top level widget, (see
**      xmui_manage) it is popped down instead.
*/
void xmui_unmanage(Widget id)
{
    Widget         shell;

    /*
    ** If the shell is top level, pop it down, otherwise unmanage the child.
    **
    ** If the shell isn't top level, we assume it's a Motif dialog shell,
    ** which will pop itself up and down as its child is managed and
    ** unmanaged.
    */
    shell = XtParent(id);
    if(XtIsTopLevelShell(shell))XtPopdown(shell);
    else XtUnmanageChild(id);
}
