motifdeveloper.com
Sponsored by IST Limited
Formerly MW3: Motif on the World Wide Web [MW3 Logo]
Last Updated
November 18, 2002
 


X-Designer - The Leading X/Motif GUI Builder - Click to download a FREE evaluation
 

motifdeveloper.com
Home
About the site
Bulletin Board
News Archive
OpenGroup News
Events
Search
Frequently Asked Questions
The Motif FAQ
X/Motif FAQs
General FAQs
Ask Antony
Latest Q & A
All Q & As
Submit Question
Tips & Pointers
Code Examples
Software
OpenMotif
Widget Sets
GUI Toolkits & Libraries
Motif suppliers
Non-commercial S/W
Commercial Software
Multimedia
Miscellaneous
Organizations
Docs & Pubs
X/Motif Newsgroups
Security
Internationalization
Feedback
Feedback Form
Contributors
 

How do I pop down all currently displayed dialogs?

20-May-02 10:00 GMT

Question: My application has a large number of dialogs many of which can be displayed at any one time. I'd like to be able to pop down all currently displayed dialogs in my application simultaneously.

There is a way to do this but it involves a little low level coding. You will basically have to poke into the widget structure to extract the list of "popup" shells associated with any given dialog.

The following code should give you everything you need to implement this in your own application. The code contains the following routines:

void PopdownAllShells(Widget shell, Boolean include_me)
the main routine, which pops down all shells that hang off "shell" recursively.
Example. If you want to popdown everything except the application shell (or session shell, if you are using one of these instead), then call:
PopdownAllShells(application_shell, False) ;
If you want to popdown absolutely everything, then call:
PopdownAllShells(application_shell, True)
There is also the following subsidiary routine:
void PopdownShell(Widget shell)
this arranges to pop down a shell, irrespective of its type. This is not recursive.

For your convenience, I have also defined:
void PopupShell(Widget shell, Boolean de_iconify)
which arranges to pop up the given shell (but not recursively), irrespective of its type. If de_iconify is true, it also arranges to map it from the iconic state if that is the state it finds itself in.
The code follows. However if you are going to use the code we would recommend that you download it, as the file popshells.c, - just right click on the link and select 'Save Target As' or 'Save Link As' depending on your browser.
#include <X11/Intrinsic.h>
#include <X11/IntrinsicP.h>
#include <X11/Core.h>
#include <X11/CoreP.h>
#include <Xm/Xm.h>
#include <Xm/DialogS.h>

#ifndef   _NO_PROTO
static void PopdownApplicationShell(Widget shell)
#else  /* _NO_PROTO */
static void PopdownApplicationShell(shell)
	 Widget  shell ;
#endif /* _NO_PROTO */
{
     if ((shell != (Widget) 0) && !shell->core.being_destroyed) {
	 if (XtIsRealized(shell)) {
	     Display *display = XtDisplay(shell) ;
	     Window   window  = XtWindow(shell) ;
	     Screen  *screen  = XtScreen(shell) ;

	     (void) XWithdrawWindow(display, window,
				 XScreenNumberOfScreen(screen)) ;
	 }
     }
}

#ifndef   _NO_PROTO
static void PopdownDialogShell(Widget shell)
#else  /* _NO_PROTO */
static void PopdownDialogShell(shell)
     Widget  shell ;
#endif /* _NO_PROTO */
{
     if ((shell != (Widget) 0) && !shell->core.being_destroyed) {
	 WidgetList children     = (WidgetList) 0 ;
	 Cardinal   num_children = 0 ;
	 Widget     child        = (Widget) 0 ;

	 XtVaGetValues(shell, XmNchildren, &children,
			     XmNnumChildren, &num_children, NULL) ;

	 if (num_children > 0) {
	     if ((child = children[0]) != (Widget) 0) {
		 if (!child->core.being_destroyed) {
		     XtUnmanageChild(child) ;
		 }
	     }
	 }
     }
}

#ifndef   _NO_PROTO
static void PopdownGeneralShell(Widget shell)
#else  /* _NO_PROTO */
static void PopdownGeneralShell(shell)
     Widget  shell ;
#endif /* _NO_PROTO */
{
     if ((shell != (Widget) 0) && !shell->core.being_destroyed) {
	 if (XtIsRealized(shell)) {
	     XtPopdown(shell) ;
	 }
     }
}

#ifndef   _NO_PROTO
void PopdownShell(Widget shell)
#else  /* _NO_PROTO */
void PopdownShell(shell)
     Widget  shell ;
#endif /* _NO_PROTO */
{
     if ((shell != (Widget) 0) && !shell->core.being_destroyed) {
	 if (XmIsDialogShell(shell)) {
	     PopdownDialogShell(shell) ;
	 }
	 else if (XtIsApplicationShell(shell)) {
	     PopdownApplicationShell(shell) ;
	 }
	 else if (XtIsShell(shell)) {
	     PopdownGeneralShell(shell) ;
	 }
     }
}

#ifndef   _NO_PROTO
void PopdownAllShells(Widget shell, Boolean include_me)
#else  /* _NO_PROTO */
void PopdownAllShells(shell, include_me)
     Widget  shell ;
     Boolean include_me ;
#endif /* _NO_PROTO */
{
     WidgetList popups     = (WidgetList) 0 ;
     Cardinal   num_popups = (Cardinal) 0 ;
     Widget     popup ;
     int        i ;

     if (shell != (Widget) 0) {
	 popups     = shell->core.popup_list ;
	 num_popups = shell->core.num_popups ;

	 for (i = 0 ; i < num_popups ; i++) {
	     popup = popups[i] ;

	     if (popup != (Widget) 0) {
		 PopdownAllShells(popup, True) ;
	     }
	 }

	 if (include_me == True) {
	     PopdownShell(shell) ;
	 }
     }
}

#ifndef   _NO_PROTO
static void PopupApplicationShell(Widget shell, Boolean de_iconify)
#else  /* _NO_PROTO */
static void PopupApplicationShell(shell, de_iconify)
     Widget  shell ;
     Boolean de_iconify ;
#endif /* _NO_PROTO */
{
     if ((shell != (Widget) 0) && !shell->core.being_destroyed) {
	 Boolean iconic = False ;

	 if (XtIsRealized(shell)) {
	     XtMapWidget(shell) ;
	 }

	 XtRealizeWidget(shell) ;

	 if (de_iconify == True) {
	     XtVaGetValues(shell, XmNiconic, &iconic, NULL) ;

	     if (iconic == True) {
		 XtVaSetValues(shell, XmNiconic, False, NULL) ;

		 XRaiseWindow(XtDisplay(shell), XtWindow(shell)) ;
	     }
	 }
     }
}

#ifndef   _NO_PROTO
static void PopupDialogShell(Widget shell)
#else  /* _NO_PROTO */
static void PopupDialogShell(shell)
     Widget  shell ;
#endif /* _NO_PROTO */
{
     if ((shell != (Widget) 0) && !shell->core.being_destroyed) {
	 WidgetList children     = (WidgetList) 0 ;
	 Cardinal   num_children = 0 ;
	 Widget     child        = (Widget) 0 ;

	 XtVaGetValues(shell, XmNchildren, &children,
			    XmNnumChildren, &num_children, NULL) ;

	 if (num_children > 0) {
	     if ((child = children[0]) != (Widget) 0) {
		 if (!child->core.being_destroyed) {
		     XtManageChild(child) ;
		 }
	     }
	 }
     }
}

#ifndef   _NO_PROTO
static void PopupGeneralShell(Widget shell, Boolean de_iconify)
#else  /* _NO_PROTO */
static void PopupGeneralShell(shell, de_iconify)
     Widget  shell ;
     Boolean de_iconify ;
#endif /* _NO_PROTO */
{
     if ((shell != (Widget) 0) && !shell->core.being_destroyed) {
	 Boolean iconic = False ;

	 if (XtIsRealized(shell)) {
	     XtPopup(shell, XtGrabNone) ;
	 }
	 else {
	     XtRealizeWidget(shell) ;
	     XtPopup(shell, XtGrabNone) ;
	 }

	 if (de_iconify == True) {
	     XtVaGetValues(shell, XmNiconic, &iconic, NULL) ;

	     if (iconic == True) {
		 XtVaSetValues(shell, XmNiconic, False, NULL) ;

		 XtMapWidget(shell) ;
		 XRaiseWindow(XtDisplay(shell), XtWindow(shell)) ;
	     }
	 }
     }
}

#ifndef   _NO_PROTO
void PopupShell(Widget shell, Boolean de_iconify)
#else  /* _NO_PROTO */
void PopupShell(shell, de_iconify)
     Widget  shell ;
     Boolean de_iconify ;
#endif /* _NO_PROTO */
{
     if ((shell != (Widget) 0) && !shell->core.being_destroyed) {
	 if (XmIsDialogShell(shell)) {
	     PopupDialogShell(shell) ;
	 }
	 else if (XtIsApplicationShell(shell)) {
	     PopupApplicationShell(shell, de_iconify) ;
	 }
	 else if (XtIsShell(shell)) {
	     PopupGeneralShell(shell, de_iconify) ;
	 }
     }
}

 



Sponsored by X-Designer - The Leading X/Motif GUI Builder - Click to download a FREE evaluation

 

Goto top of page

 

[IST Limited]
IST Limited is the
proud sponsor of motifdeveloper.com.
 

Thanks to all the contributors to these pages.

Privacy Policy

 
"Motif" is a registered trademark of The Open Group. All other trademarks are the property of their respective owners.

Some articles/papers here have their own copyright notice. All other information is copyright ©1999-2008 IST Limited

[CommerceOne] MW3 site originally by Ken Sall of Commerce One (formerly Century Computing).