home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / XfeWidgets / Xfe / DialogUtil.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  5.6 KB  |  184 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/DialogUtil.h>                                        */
  21. /* Description:    Dialog utilities source.                                */
  22. /* Author:        Ramiro Estrugo <ramiro@netscape.com>                    */
  23. /*                                                                        */
  24. /*----------------------------------------------------------------------*/
  25.  
  26.  
  27. #include <Xfe/XfeP.h>
  28. #include <Xfe/ManagerP.h>
  29.  
  30. /*----------------------------------------------------------------------*/
  31. /*                                                                        */
  32. /* Dialogs                                                                */
  33. /*                                                                        */
  34. /*----------------------------------------------------------------------*/
  35. /*
  36.  *    From the Motif FAQ:
  37.  *
  38.  *    217) How can I force a dialog window to display?
  39.  *
  40.  *    I manage a "working" dialog, and do some computing, but the dialog window
  41.  *    appears blank until the work has finished.  How can I force it to be
  42.  *    displayed?
  43.  *
  44.  *    [Last modified: Dec '94]
  45.  *
  46.  *    Answer:  David Brooks <dbrooks@ics.com> writes: The dialog window won't
  47.  *    get expose events until the window manager has fielded the map
  48.  *    request, done the reparenting with all that entails, and finally
  49.  *    convinced the server that the window is for real.  The safe way of
  50.  *    doing it is [below].
  51.  *
  52.  *    Use this.  (David Brooks, Systems Engineering, Open Software Foundation)
  53.  */
  54.  
  55. /*
  56.  * This procedure will ensure that, if a dialog window is being mapped,
  57.  * its contents become visible before returning.  It is intended to be
  58.  * used just before a bout of computing that doesn't service the display.
  59.  * You should still call XmUpdateDisplay() at intervals during this
  60.  * computing if possible.
  61.  *
  62.  * The monitoring of window states is necessary because attempts to map
  63.  * the dialog are redirected to the window manager (if there is one) and
  64.  * this introduces a significant delay before the window is actually mapped
  65.  * and exposed.  This code works under mwm, twm, uwm, and no-wm.  It
  66.  * doesn't work (but doesn't hang) with olwm if the mainwindow is iconified.
  67.  *
  68.  * The argument to ForceDialog is any widget in the dialog (often it
  69.  * will be the BulletinBoard child of a DialogShell).
  70.  */
  71. /* extern */ void
  72. XfeUpdateDisplay(Widget shell)
  73. {
  74.     Widget diashell, topshell;
  75.     Window diawindow, topwindow;
  76.     Display *dpy;
  77.     XWindowAttributes xwa;
  78.     XEvent event;
  79.     XtAppContext cxt;
  80.  
  81.     assert( _XfeIsAlive(shell) );
  82.  
  83.     /* Locate the shell we are interested in.  In a particular instance, you
  84.      * may know these shells already.
  85.      */
  86.  
  87.     for (diashell = shell;
  88.          !XtIsShell(diashell);
  89.          diashell = XtParent(diashell))
  90.         ;
  91.  
  92.     /* Locate its primary window's shell (which may be the same) */
  93.  
  94.     for (topshell = diashell;
  95.          !XtIsTopLevelShell(topshell);
  96.          topshell = XtParent(topshell))
  97.         ;
  98.  
  99.     if (XtIsRealized(diashell) && XtIsRealized(topshell)) {
  100.         dpy = XtDisplay(topshell);
  101.         diawindow = _XfeWindow(diashell);
  102.         topwindow = _XfeWindow(topshell);
  103.         cxt = XtWidgetToApplicationContext(diashell);
  104.  
  105.         /* Wait for the dialog to be mapped. 
  106.            It's guaranteed to become so unless... */
  107.  
  108.         while (XGetWindowAttributes(dpy, diawindow, &xwa),
  109.                xwa.map_state != IsViewable) {
  110.  
  111.             /* ...if the primary is (or becomes) unviewable or unmapped, it's
  112.                probably iconified, and nothing will happen. */
  113.  
  114.             if (XGetWindowAttributes(dpy, topwindow, &xwa),
  115.                 xwa.map_state != IsViewable)
  116.                 break;
  117.  
  118.             /* At this stage, we are guaranteed there will be an event of
  119.                some kind.
  120.                Beware; we are presumably in a callback, so this can recurse. */
  121.  
  122.             XtAppNextEvent(cxt, &event);
  123.             XtDispatchEvent(&event);
  124.         }
  125.     }
  126.  
  127.     /* The next XSync() will get an expose event if the dialog was unmapped. */
  128.  
  129.     XmUpdateDisplay(topshell);
  130. }
  131.  
  132. /*----------------------------------------------------------------------*/
  133. /*                                                                        */
  134. /* Find the parent dialog for a widget                                    */
  135. /*                                                                        */
  136. /*----------------------------------------------------------------------*/
  137. /* extern */ Widget
  138. XfeGetParentDialog(Widget w)
  139. {
  140.     Widget mainw = w;
  141.  
  142.  
  143.     int i;
  144.     /* If any modal dialog is already up we will cascade these dialogs. Thus this
  145.      * dialog will be the child of the last popped up modal dialog.
  146.      */
  147.     i = _XfeNumPopups(mainw);
  148.  
  149.     while (i>0)
  150.     {
  151.         Widget popup = _XfePopupListIndex(mainw,i - 1);
  152.         
  153.         if ( XmIsDialogShell(popup) && 
  154.              XfeShellIsPoppedUp(popup) &&
  155.              (_XfemNumChildren(popup) > 0) )
  156.         {
  157.             Widget            newmainw = popup;
  158.             Widget            popup_child = _XfeChildrenIndex(popup,0);
  159.             unsigned char    dialog_style = XmDIALOG_MODELESS;
  160.             
  161.             XtVaGetValues(popup_child,
  162.                           XmNdialogStyle, &dialog_style,
  163.                           NULL);
  164.             
  165.             if (dialog_style != XmDIALOG_MODELESS)
  166.             {
  167.                 mainw = newmainw;
  168.                 i = _XfeNumPopups(mainw);
  169.             }
  170.             else
  171.             {
  172.                 i --;
  173.             }
  174.         }
  175.         else
  176.         {
  177.             i--;
  178.         }
  179.     }
  180.     
  181.     return mainw;
  182. }
  183. /*----------------------------------------------------------------------*/
  184.