Blame lib/Xm/ShellE.c

Packit b099d7
/* 
Packit b099d7
 * Motif
Packit b099d7
 *
Packit b099d7
 * Copyright (c) 1987-2012, The Open Group. All rights reserved.
Packit b099d7
 *
Packit b099d7
 * These libraries and programs are free software; you can
Packit b099d7
 * redistribute them and/or modify them under the terms of the GNU
Packit b099d7
 * Lesser General Public License as published by the Free Software
Packit b099d7
 * Foundation; either version 2 of the License, or (at your option)
Packit b099d7
 * any later version.
Packit b099d7
 *
Packit b099d7
 * These libraries and programs are distributed in the hope that
Packit b099d7
 * they will be useful, but WITHOUT ANY WARRANTY; without even the
Packit b099d7
 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
Packit b099d7
 * PURPOSE. See the GNU Lesser General Public License for more
Packit b099d7
 * details.
Packit b099d7
 *
Packit b099d7
 * You should have received a copy of the GNU Lesser General Public
Packit b099d7
 * License along with these librararies and programs; if not, write
Packit b099d7
 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
Packit b099d7
 * Floor, Boston, MA 02110-1301 USA
Packit b099d7
*/ 
Packit b099d7
/* 
Packit b099d7
 * HISTORY
Packit b099d7
*/ 
Packit b099d7
#ifdef HAVE_CONFIG_H
Packit b099d7
#include <config.h>
Packit b099d7
#endif
Packit b099d7
Packit b099d7
Packit b099d7
#ifdef REV_INFO
Packit b099d7
#ifndef lint
Packit b099d7
static char rcsid[] = "$XConsortium: ShellE.c /main/10 1995/10/25 20:19:54 cde-sun $"
Packit b099d7
#endif
Packit b099d7
#endif
Packit b099d7
/*
Packit b099d7
*  (c) Copyright 1987, 1988, 1989, 1990, 1991, 1992 HEWLETT-PACKARD COMPANY */
Packit b099d7
/*
Packit b099d7
*  (c) Copyright 1987, 1988, DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS. */
Packit b099d7
/*
Packit b099d7
*  (c) Copyright 1988 MASSACHUSETTS INSTITUTE OF TECHNOLOGY */
Packit b099d7
Packit b099d7
#include <Xm/ShellEP.h>
Packit b099d7
#include <X11/ShellP.h>
Packit b099d7
#include <Xm/VendorSEP.h>
Packit b099d7
#include <Xm/ScreenP.h>
Packit b099d7
#include "XmI.h"
Packit b099d7
Packit b099d7
Packit b099d7
/********    Static Function Declarations    ********/
Packit b099d7
Packit b099d7
static void ShellClassPartInitialize( 
Packit b099d7
                        WidgetClass w) ;
Packit b099d7
static void StructureNotifyHandler( 
Packit b099d7
                        Widget wid,
Packit b099d7
                        XtPointer closure,
Packit b099d7
                        XEvent *event,
Packit b099d7
                        Boolean *continue_to_dispatch) ;
Packit b099d7
Packit b099d7
/********    End Static Function Declarations    ********/
Packit b099d7
Packit b099d7
Packit b099d7
/***************************************************************************
Packit b099d7
 *
Packit b099d7
 * Class Record
Packit b099d7
 *
Packit b099d7
 ***************************************************************************/
Packit b099d7
Packit b099d7
#define Offset(field) XtOffsetOf( struct _XmShellExtRec, shell.field)
Packit b099d7
Packit b099d7
static XtResource shellResources[] =
Packit b099d7
{    
Packit b099d7
    {
Packit b099d7
	XmNuseAsyncGeometry, XmCUseAsyncGeometry, XmRBoolean, 
Packit b099d7
	sizeof(Boolean), Offset(useAsyncGeometry),
Packit b099d7
	XmRImmediate, FALSE,
Packit b099d7
    },
Packit b099d7
};
Packit b099d7
#undef Offset
Packit b099d7
Packit b099d7
externaldef(xmshellextclassrec)
Packit b099d7
XmShellExtClassRec xmShellExtClassRec = {
Packit b099d7
    {	
Packit b099d7
	(WidgetClass) &xmDesktopClassRec,/* superclass		*/   
Packit b099d7
	"Shell",			/* class_name 		*/   
Packit b099d7
	sizeof(XmShellExtRec),	 	/* size 		*/   
Packit b099d7
	NULL,		 		/* Class Initializer 	*/   
Packit b099d7
	ShellClassPartInitialize, 	/* class_part_init 	*/ 
Packit b099d7
	FALSE, 				/* Class init'ed ? 	*/   
Packit b099d7
	NULL,				/* initialize         	*/   
Packit b099d7
	NULL, 				/* initialize_notify    */ 
Packit b099d7
	NULL,	 			/* realize            	*/   
Packit b099d7
	NULL,	 			/* actions            	*/   
Packit b099d7
	0,				/* num_actions        	*/   
Packit b099d7
	shellResources,			/* resources          	*/   
Packit b099d7
	XtNumber(shellResources),	/* resource_count     	*/   
Packit b099d7
	NULLQUARK, 			/* xrm_class          	*/   
Packit b099d7
	FALSE, 				/* compress_motion    	*/   
Packit b099d7
	FALSE, 				/* compress_exposure  	*/   
Packit b099d7
	FALSE, 				/* compress_enterleave	*/   
Packit b099d7
	FALSE, 				/* visible_interest   	*/   
Packit b099d7
	NULL,				/* destroy            	*/   
Packit b099d7
	NULL,		 		/* resize             	*/   
Packit b099d7
	NULL, 				/* expose             	*/   
Packit b099d7
	NULL,		 		/* set_values         	*/   
Packit b099d7
	NULL, 				/* set_values_hook      */ 
Packit b099d7
	NULL,			 	/* set_values_almost    */ 
Packit b099d7
	NULL,				/* get_values_hook      */ 
Packit b099d7
	NULL, 				/* accept_focus       	*/   
Packit b099d7
	XtVersion, 			/* intrinsics version 	*/   
Packit b099d7
	NULL, 				/* callback offsets   	*/   
Packit b099d7
	NULL,				/* tm_table           	*/   
Packit b099d7
	NULL, 				/* query_geometry       */ 
Packit b099d7
	NULL, 				/* display_accelerator  */ 
Packit b099d7
	NULL, 				/* extension            */ 
Packit b099d7
    },	
Packit b099d7
    {					/* ext */
Packit b099d7
	NULL,				/* synthetic resources	*/
Packit b099d7
	0,				/* num syn resources	*/
Packit b099d7
	NULL,				/* extension		*/
Packit b099d7
    },
Packit b099d7
    {					/* desktop		*/
Packit b099d7
	NULL,				/* child_class		*/
Packit b099d7
	XtInheritInsertChild,		/* insert_child		*/
Packit b099d7
	XtInheritDeleteChild,		/* delete_child		*/
Packit b099d7
	NULL,				/* extension		*/
Packit b099d7
    },
Packit b099d7
    {					/* shell ext		*/
Packit b099d7
	StructureNotifyHandler,	        /* structureNotify*/
Packit b099d7
	NULL,				/* extension		*/
Packit b099d7
    },
Packit b099d7
};
Packit b099d7
Packit b099d7
externaldef(xmShellExtobjectclass) WidgetClass 
Packit b099d7
  xmShellExtObjectClass = (WidgetClass) (&xmShellExtClassRec);
Packit b099d7
Packit b099d7
Packit b099d7
/************************************************************************
Packit b099d7
 *
Packit b099d7
 *  ClassPartInitialize
Packit b099d7
 *    Set up the inheritance mechanism for the routines exported by
Packit b099d7
 *    vendorShells class part.
Packit b099d7
 *
Packit b099d7
 ************************************************************************/
Packit b099d7
static void 
Packit b099d7
ShellClassPartInitialize(
Packit b099d7
        WidgetClass w )
Packit b099d7
{
Packit b099d7
    XmShellExtObjectClass wc = (XmShellExtObjectClass) w;
Packit b099d7
    XmShellExtObjectClass sc =
Packit b099d7
      (XmShellExtObjectClass) wc->object_class.superclass;
Packit b099d7
    
Packit b099d7
    if (wc == (XmShellExtObjectClass)xmShellExtObjectClass)
Packit b099d7
      return;
Packit b099d7
Packit b099d7
    if (wc->shell_class.structureNotifyHandler == XmInheritEventHandler)
Packit b099d7
      wc->shell_class.structureNotifyHandler = 
Packit b099d7
	sc->shell_class.structureNotifyHandler;
Packit b099d7
}
Packit b099d7
Packit b099d7
/************************************************************************
Packit b099d7
 *
Packit b099d7
 *  StructureNotifyHandler
Packit b099d7
 *
Packit b099d7
 ************************************************************************/
Packit b099d7
/* ARGSUSED */
Packit b099d7
static void 
Packit b099d7
StructureNotifyHandler(
Packit b099d7
        Widget wid,
Packit b099d7
        XtPointer closure,
Packit b099d7
        XEvent *event,
Packit b099d7
        Boolean *continue_to_dispatch )
Packit b099d7
{
Packit b099d7
    register ShellWidget 	w = (ShellWidget) wid;
Packit b099d7
    WMShellWidget 		wmshell = (WMShellWidget) w;
Packit b099d7
    Boolean  			sizechanged = FALSE;
Packit b099d7
    Position 			tmpx, tmpy;
Packit b099d7
    XmShellExtObject		shellExt = (XmShellExtObject) closure;
Packit b099d7
    XmVendorShellExtObject	vendorExt = (XmVendorShellExtObject)closure;
Packit b099d7
    XmVendorShellExtPart	*vePPtr;
Packit b099d7
    XmScreen			xmScreen;
Packit b099d7
Packit b099d7
    /*
Packit b099d7
     *  for right now if this is being used by overrides bug out
Packit b099d7
     */
Packit b099d7
    if (!XmIsVendorShell(wid))
Packit b099d7
      return;
Packit b099d7
    else
Packit b099d7
      vePPtr = (XmVendorShellExtPart *) &(vendorExt->vendor);
Packit b099d7
Packit b099d7
    if (XmIsScreen(vendorExt->desktop.parent))
Packit b099d7
      xmScreen = (XmScreen) (vendorExt->desktop.parent);
Packit b099d7
    else
Packit b099d7
      xmScreen = (XmScreen) XmGetXmScreen(XtScreen(wid));
Packit b099d7
Packit b099d7
    switch(event->type) {
Packit b099d7
      case MapNotify:
Packit b099d7
	break;
Packit b099d7
      case UnmapNotify:
Packit b099d7
	/*
Packit b099d7
	 * try to keep the pop up field synced up so it won't disallow
Packit b099d7
	 * a new pop up request.
Packit b099d7
	 */
Packit b099d7
	/* 
Packit b099d7
	 * make sure we have good coords
Packit b099d7
	 */
Packit b099d7
	XtTranslateCoords((Widget) w, 0, 0, &tmpx, &tmpy);
Packit b099d7
	/*
Packit b099d7
	 * if the offsets match up, then offset our values so we'll go in
Packit b099d7
	 * the same place the next time.
Packit b099d7
	 */
Packit b099d7
	if ((vePPtr->xAtMap != w->core.x) ||
Packit b099d7
	    (vePPtr->yAtMap != w->core.y))
Packit b099d7
	  {
Packit b099d7
	      if (xmScreen->screen.mwmPresent)
Packit b099d7
		{
Packit b099d7
		    if (vePPtr->lastOffsetSerial &&
Packit b099d7
			(vePPtr->lastOffsetSerial >= 
Packit b099d7
			 vendorExt->shell.lastConfigureRequest) &&
Packit b099d7
			((vePPtr->xOffset + vePPtr->xAtMap) == w->core.x) &&
Packit b099d7
			((vePPtr->yOffset + vePPtr->yAtMap) == w->core.y))
Packit b099d7
		      {
Packit b099d7
			  w->core.x -= vePPtr->xOffset;
Packit b099d7
			  w->core.y -= vePPtr->yOffset;
Packit b099d7
			  w->shell.client_specified &= ~_XtShellPositionValid;
Packit b099d7
Packit b099d7
			  vePPtr->externalReposition = False;
Packit b099d7
		      }
Packit b099d7
		    else
Packit b099d7
		      {
Packit b099d7
			  vePPtr->externalReposition = True;
Packit b099d7
		      }
Packit b099d7
		}
Packit b099d7
	      else
Packit b099d7
		vePPtr->externalReposition = True;
Packit b099d7
	  }
Packit b099d7
	break;
Packit b099d7
Packit b099d7
      case ConfigureNotify:
Packit b099d7
	/*
Packit b099d7
	 * only process configureNotifies that aren't stale
Packit b099d7
	 */
Packit b099d7
	if (event->xany.serial <
Packit b099d7
	    shellExt->shell.lastConfigureRequest)
Packit b099d7
	  {
Packit b099d7
	      /*
Packit b099d7
	       *  make sure the hard wired event handler in shell is not called
Packit b099d7
	       */
Packit b099d7
	      if (shellExt->shell.useAsyncGeometry)
Packit b099d7
		*continue_to_dispatch = False;
Packit b099d7
	  }
Packit b099d7
	else
Packit b099d7
	  {
Packit b099d7
#define NEQ(x)	( w->core.x != event->xconfigure.x )
Packit b099d7
	      if( NEQ(width) || NEQ(height) || NEQ(border_width) ) {
Packit b099d7
		  sizechanged = TRUE;
Packit b099d7
	      }
Packit b099d7
#undef NEQ
Packit b099d7
	      w->core.width = event->xconfigure.width;
Packit b099d7
	      w->core.height = event->xconfigure.height;
Packit b099d7
	      w->core.border_width = event->xconfigure.border_width;
Packit b099d7
	      if (event->xany.send_event /* ICCCM compliant synthetic ev */
Packit b099d7
		  /* || w->shell.override_redirect */
Packit b099d7
		  || w->shell.client_specified & _XtShellNotReparented)
Packit b099d7
		{
Packit b099d7
		    w->core.x = event->xconfigure.x;
Packit b099d7
		    w->core.y = event->xconfigure.y;
Packit b099d7
		    w->shell.client_specified |= _XtShellPositionValid;
Packit b099d7
		}
Packit b099d7
	      else w->shell.client_specified &= ~_XtShellPositionValid;
Packit b099d7
	      if (XtIsWMShell(wid) && !wmshell->wm.wait_for_wm) {
Packit b099d7
		  /* Consider trusting the wm again */
Packit b099d7
		  register WMShellPart *wmp = &(wmshell->wm);
Packit b099d7
#define EQ(x) (wmp->size_hints.x == w->core.x)
Packit b099d7
		  if (EQ(x) && EQ(y) && EQ(width) && EQ(height)) {
Packit b099d7
		      wmshell->wm.wait_for_wm = TRUE;
Packit b099d7
		  }
Packit b099d7
#undef EQ
Packit b099d7
	      }
Packit b099d7
	  }		    
Packit b099d7
	break;
Packit b099d7
      case ReparentNotify:
Packit b099d7
	if (event->xreparent.window == XtWindow(w)) {
Packit b099d7
	    if (event->xreparent.parent != RootWindowOfScreen(XtScreen(w)))
Packit b099d7
	      {
Packit b099d7
		  w->shell.client_specified &= ~_XtShellNotReparented;
Packit b099d7
		  /*
Packit b099d7
		   * check to see if it's mwm
Packit b099d7
		   */
Packit b099d7
		  if (!(xmScreen->screen.numReparented++))
Packit b099d7
		    xmScreen->screen.mwmPresent = 
Packit b099d7
		      XmIsMotifWMRunning( (Widget) w);
Packit b099d7
	      }
Packit b099d7
	    else
Packit b099d7
	      {
Packit b099d7
		  w->core.x = event->xreparent.x;
Packit b099d7
		  w->core.y = event->xreparent.y;
Packit b099d7
		  w->shell.client_specified |= _XtShellNotReparented;
Packit b099d7
		  xmScreen->screen.numReparented--;
Packit b099d7
	      }
Packit b099d7
	    w->shell.client_specified &= ~_XtShellPositionValid;
Packit b099d7
	}
Packit b099d7
	return;
Packit b099d7
	
Packit b099d7
      default:
Packit b099d7
	return;
Packit b099d7
    }
Packit b099d7
    
Packit b099d7
    if (sizechanged) {
Packit b099d7
      XtWidgetProc resize;
Packit b099d7
Packit b099d7
      _XmProcessLock();
Packit b099d7
      resize = XtClass(w)->core_class.resize;
Packit b099d7
      _XmProcessUnlock();
Packit b099d7
Packit b099d7
      if (resize != (XtWidgetProc) NULL)
Packit b099d7
	(*resize)((Widget) w);
Packit b099d7
    }
Packit b099d7
}