Ejemplo n.º 1
0
/************************************************************************
 *
 *  ChangeManaged
 *	Process a changed in managed state of the child.  If its
 *	size is out of sync with the frame, make a resize request
 *	to change the size of the frame.
 *	Note: called before ConstraintDestroy.
 *
 ************************************************************************/
static void 
ChangeManaged(
        Widget wid )
{
   XmFrameWidget fw = (XmFrameWidget) wid ;

   Widget title_area = (fw->frame.title_area &&
			XtIsManaged(fw->frame.title_area)) ?
			fw->frame.title_area : (Widget) NULL;
   Dimension t_w = 0;
   Dimension t_h = 0;
   Dimension t_bw = (title_area) ? title_area->core.border_width : 0;

   Widget work_area = (fw->frame.work_area &&
			XtIsManaged(fw->frame.work_area)) ?
			fw->frame.work_area : (Widget) NULL;

   Dimension w_w = (work_area) ? work_area->core.width : 0;
   Dimension w_h = (work_area) ? work_area->core.height : 0;
   Dimension w_bw = (work_area) ? work_area->core.border_width : 0;
   Dimension fwWidth, fwHeight;

   if (title_area) 
   {                                          
	/* We don't want the current size of the title object -- width/height
	** may have been set on it. Because we'll be forcing it to the size we
	** want (see ConfigureChildren), we must use the "natural" size here,
	** so query its value now. (Use current border_width.)
        */
	XtWidgetGeometry title_reply;                           
	XtQueryGeometry (title_area, NULL, &title_reply);      
	t_w = (title_reply.request_mode & CWWidth) ?          
		title_reply.width : title_area->core.width;   
	t_h = (title_reply.request_mode & CWHeight) ?       
		title_reply.height : title_area->core.height;
   }                             

   /* need to  check on initial sizing (not null) */
   if (XtIsRealized((Widget)fw) || (XtWidth(fw) == 0) || (XtHeight(fw) == 0)) {
       CalcFrameSize (fw, t_w, t_h, t_bw, w_w, w_h, w_bw,
		      &fwWidth, &fwHeight);

       while (XtMakeResizeRequest ((Widget) fw, 
				   fwWidth, fwHeight,
				   &fwWidth, &fwHeight) == XtGeometryAlmost) 
	 /*EMPTY*/;
       ClearShadow(fw);
   }
 
   ConfigureChildren(fw, NULL, NULL);

   DrawShadow(fw);

   XmeNavigChangeManaged((Widget) fw);
}
Ejemplo n.º 2
0
void
EmacsManagerChangeSize (Widget w, Dimension width, Dimension height)
{
  if (width == 0)
    width = w->core.width;
  if (height == 0)
    height = w->core.height;

  /* do nothing if we're already that size */
  if (w->core.width != width || w->core.height != height)
    {
      XtGeometryResult result =
	XtMakeResizeRequest (w, width, height, &w->core.width, &w->core.height);
      if (result == XtGeometryNo)
	return;
      if (result == XtGeometryAlmost)
	XtMakeResizeRequest (w, w->core.width, w->core.height, NULL, NULL);
      Resize (w);
    }
}
Ejemplo n.º 3
0
Archivo: Tree.c Proyecto: aosm/X11libs
static void
set_tree_size(TreeWidget tw, Bool insetvalues,
	      unsigned int width, unsigned int height)
{
    if (insetvalues) {
	tw->core.width = width;
	tw->core.height = height;
    } else {
	Dimension replyWidth = 0, replyHeight = 0;
	XtGeometryResult result = XtMakeResizeRequest ((Widget) tw,
						       width, height,
						       &replyWidth,
						       &replyHeight);
	/*
	 * Accept any compromise.
	 */
	if (result == XtGeometryAlmost)
	  XtMakeResizeRequest ((Widget) tw, replyWidth, replyHeight,
			       (Dimension *) NULL, (Dimension *) NULL);
    }
    return;
}
Ejemplo n.º 4
0
/*
 * Font and internal_border can be changed on the fly.
 *
 * The entire widget is redrawn if any of those parameters change (all
 * can potentially have effects that spans the whole widget).
 *
 * Color changes are handled elsewhere.
 *
 * This function is very underspecified, in terms of how these changes can
 * occur, and what is true about the various AngbandWidget's passed in.  It
 * is very likely that this code no longer works.
 */
static Boolean SetValues(AngbandWidget current, AngbandWidget request,
                         AngbandWidget wnew, ArgList args,
                         Cardinal *num_args)
{
	Display *dpy = XtDisplay(wnew);

	Boolean font_changed = FALSE;
	Boolean border_changed = FALSE;
	int height, width;
	int i;


	/* Handle font change */
	if (wnew->angband.font != current->angband.font)
	{
		/* Check if the font exists */
		wnew->angband.fnt = getFont(wnew, wnew->angband.font, FALSE);

		/* The font didn't exist */
		if (wnew->angband.fnt == NULL)
		{
			wnew->angband.fnt = current->angband.fnt;
			wnew->angband.font = current->angband.font;
			XtWarning("Couldn't find the requested font!");
		}
		else
		{
			font_changed = TRUE;

			/* Free the old font */
			XFreeFont(XtDisplay((Widget)wnew), current->angband.fnt);
			/* Update font information */
			wnew->angband.fontheight = wnew->angband.fnt->ascent +
				wnew->angband.fnt->descent;
			wnew->angband.fontwidth = wnew->angband.fnt->max_bounds.width;
			wnew->angband.fontascent = wnew->angband.fnt->ascent;
		}
	}

	/* Handle font change */
	if (font_changed)
	{
		/* Update all GC's */
		for (i = 0; i < NUM_COLORS; i++)
		{
			/* Steal the old GC */
			wnew->angband.gc[i] = current->angband.gc[i];
			current->angband.gc[i] = NULL;

			/* Be sure the correct font is ready */
			XSetFont(dpy, wnew->angband.gc[i], wnew->angband.fnt->fid);
		}

		/* Steal the old GC */
		wnew->angband.gc[NUM_COLORS] = current->angband.gc[NUM_COLORS];
		current->angband.gc[NUM_COLORS] = NULL;
	}


	/* Check if internal border width has changed, used later */
	if (current->angband.internal_border != wnew->angband.internal_border)
	{
		border_changed = TRUE;
	}


	/* If the font or the internal border has changed, all geometry */
	/* has to be recalculated */
	if (font_changed || border_changed)
	{
		/* Change window size */
		height = ((current->core.height - 2 * current->angband.internal_border) /
		          current->angband.fontheight * wnew->angband.fontheight +
		          2 * current->angband.internal_border);
		width = ((current->core.width -  2 * current->angband.internal_border) /
		         current->angband.fontwidth * wnew->angband.fontwidth +
		         2 * wnew->angband.internal_border);

		/* Get the new width */
		if (XtMakeResizeRequest((Widget)wnew, width, height, NULL, NULL) ==
		    XtGeometryNo)
		{
			/* Not allowed */
			XtWarning("Size change denied!");
		}
		else
		{
			/* Recalculate size hints */
			calculateSizeHints(wnew);
		}
	}

	/* Tell it to redraw the widget if anything has changed */
	return (font_changed || border_changed);
}
Ejemplo n.º 5
0
/****************************************************************
 * Calculate the size needed for the Manager
 * Request a change in size from parent if needed.
 ****************/
Boolean 
_XmGMDoLayout(XmManagerWidget manager,
#if NeedWidePrototypes
            int margin_width,
            int margin_height,        
#else
            Dimension margin_width,
            Dimension margin_height,        
#endif /* NeedWidePrototypes */
            int resize_policy,
#if NeedWidePrototypes
            int queryonly
#else
            Boolean queryonly
#endif /* NeedWidePrototypes */
)
{
    /* return:
         True means that the layout is accepted, either with no request
       to the parent, or with a successfull serie of requests. 
       No means that the layout is denied, without request (NONE
       policy for instance) or with request (parent does not accept the
       change in size or proposes something unacceptable).
       Note that when the parent returns almost, since this function returns
       either true or false (see below), we don't handle almost reply 
       to the instigator. 
       The queryonly flag just controls the "reality" of the parent request
       and the call to resize.
    */

    XtWidgetGeometry request ;
    XtWidgetGeometry reply ;
    XtWidgetProc resize;


    request.request_mode = CWWidth|CWHeight ;
    if (queryonly) request.request_mode |= XtCWQueryOnly ;

    _XmGMCalcSize(manager, margin_width, margin_height, 
                &request.width, &request.height);
    
    /* no change, just accept it */
    if ((XtWidth(manager) == request.width) && 
      (XtHeight(manager) == request.height)) 
      return (True);   

    /* the current manager sizes are bigger than the new ones and
       we don't want to strink, just accept the layout as is, since
       it already fits */
    if ((resize_policy == XmRESIZE_GROW ||
       resize_policy == XmRESIZE_NONE) &&
      ((XtWidth(manager) >= request.width) && 
       (XtHeight(manager) >= request.height)) )
      return (True);

    /* the previous test passes over, so one of the needed sizes must be 
       bigger than one of the current, and we can't do that with NONE */
    if (resize_policy == XmRESIZE_NONE )
      return (False);

    /* we can't shrink on one side while growing on the other, just
       overwrite the shrinking side */
    if(resize_policy == XmRESIZE_GROW    ) {   
      if(request.width < XtWidth(manager)) 
          request.width = XtWidth(manager) ;
        if(request.height < XtHeight(manager)) 
          request.height = XtHeight(manager) ;
    } 

    _XmProcessLock();
    resize = XtCoreProc(manager,resize);
    _XmProcessUnlock();
    
    /* now the request */
    switch(XtMakeGeometryRequest((Widget)manager, 
                               &request,
                               &reply)) {
    case XtGeometryYes:
      if (!queryonly) 
             /* call the resize proc, since the widget set has now
                a Yes policy */
          (*resize)((Widget)manager) ;
      return(True) ;
    case XtGeometryAlmost:  
         /* The following behavior is based on the shrink wrapper
            behavior of this manager. What we have asked is the minimum.
            If the almost returned size is smaller than the 
            requested one, refuse, since it will always clip something */
      if ((reply.width < request.width) || 
          (reply.height < request.height)) {   
          return( False) ;
      } else {
         /* if almost returned a bigger size than requested, 
            accept it since it cannot hurt the shrink wrap behavior,
            neither the Grow policy (requested always > current).
            Apply it if not queryonly. If queryonly, we don't 
            have to re-request something, since no change is needed 
            and we already know it's OK */
          if (!queryonly) {
              (void) XtMakeResizeRequest((Widget)manager, 
                                        reply.width, 
                                        reply.height, 
                                        NULL, NULL) ;
              (*resize)((Widget)manager) ;
          }
          return(True) ;
      }
    case XtGeometryNo:
    default:
      break ;
    }
    return( False) ;
}
Ejemplo n.º 6
0
/*
 * Initialize a term_data
 */
static errr term_data_init(term_data *td, Widget topLevel,
                           int key_buf, String name,
                           ArgList widget_arg, Cardinal widget_arg_no, int i)
{
	Widget parent;
	term *t = &td->t;

	int cols = 80;
	int rows = 24;

	char buf[80];
	cptr str;

	int val;

	/* Create the shell widget */
	parent = XtCreatePopupShell(name, topLevelShellWidgetClass, topLevel,
	                            NULL, 0);

	/* Window specific cols */
	sprintf(buf, "ANGBAND_X11_COLS_%d", i);
	str = getenv(buf);
	val = (str != NULL) ? atoi(str) : -1;
	if (val > 0) cols = val;

	/* Window specific rows */
	sprintf(buf, "ANGBAND_X11_ROWS_%d", i);
	str = getenv(buf);
	val = (str != NULL) ? atoi(str) : -1;
	if (val > 0) rows = val;

	/* Hack the main window must be at least 80x24 */
	if (i == 0)
	{
		if (cols < 80) cols = 80;
		if (rows < 24) rows = 24;
	}

	/* Reset the initial size */
	widget_arg[0].value = rows;
	widget_arg[1].value = cols;

	/* Hack  ox==oy in xaw port */

	/* Window specific inner border offset (ox) */
	sprintf(buf, "ANGBAND_X11_IBOX_%d", i);
	str = getenv(buf);
	val = (str != NULL) ? atoi(str) : -1;
	if (val > 0) widget_arg[6].value = val;

	/* Window specific inner border offset (oy) */
	sprintf(buf, "ANGBAND_X11_IBOY_%d", i);
	str = getenv(buf);
	val = (str != NULL) ? atoi(str) : -1;
	if (val > 0) widget_arg[6].value = val;

	/* Create the interior widget */
	td->widget = (AngbandWidget)
	XtCreateManagedWidget(name, angbandWidgetClass,
	                      parent, widget_arg, widget_arg_no);

	/* Initialize the term (full size) */
	term_init(t, cols, rows, key_buf);

	/* Use a "soft" cursor */
	t->soft_cursor = TRUE;

	/* Erase with "white space" */
	t->attr_blank = TERM_WHITE;
	t->char_blank = ' ';

	/* Hooks */
	t->xtra_hook = Term_xtra_xaw;
	t->curs_hook = Term_curs_xaw;
	t->wipe_hook = Term_wipe_xaw;
	t->text_hook = Term_text_xaw;

	/* Save the data */
	t->data = td;

	/* Register the keypress event handler */
	XtAddEventHandler((Widget)td->widget, KeyPressMask,
	                  False, (XtEventHandler) handle_event, td);

	/* Redraw callback */
	XtAddCallback((Widget)td->widget, XtNredrawCallback,
	              react_redraw, td);

	/* Realize the widget */
	XtRealizeWidget(parent);

	/* Have we redefined the font? */
	if (streq(td->widget->angband.font, DEFAULT_X11_FONT))
	{
		XFontStruct *fnt;

		/* Check if the font exists */
		fnt = getFont(td->widget, (String) get_default_font(i), FALSE);

		/* The font didn't exist */
		if (fnt == NULL)
		{
			XtWarning("Couldn't find the requested font!");
		}
		else
		{
			int height, width;

			/* Free the old font */
			XFreeFont(XtDisplay((Widget)td->widget), td->widget->angband.fnt);

			/* Update font information */
			td->widget->angband.fontheight = fnt->ascent + fnt->descent;
			td->widget->angband.fontwidth = fnt->max_bounds.width;
			td->widget->angband.fontascent = fnt->ascent;

			for (i = 0; i < NUM_COLORS; i++)
			{
				/* Be sure the correct font is ready */
				XSetFont(XtDisplay((Widget)td->widget),
					 td->widget->angband.gc[i], fnt->fid);
			}

			/* Get the window shape */
			height = (td->widget->angband.start_rows *
				td->widget->angband.fontheight +
				2 * td->widget->angband.internal_border);
			width = (td->widget->angband.start_columns *
				td->widget->angband.fontwidth +
				2 * td->widget->angband.internal_border);

			/* Request a change to the new shape */
			if (XtMakeResizeRequest((Widget)td->widget,
				 width, height, NULL, NULL) == XtGeometryNo)
			{
				/* Not allowed */
				XtWarning("Size change denied!");
			}
			else
			{
				/* Recalculate size hints */
				calculateSizeHints(td->widget);
			}
		}
	}

	/* Make it visible */
	XtPopup(parent, XtGrabNone);

	/* Activate (important) */
	Term_activate(t);


	Resize_term(td->widget);

	return 0;
}
Ejemplo n.º 7
0
static void ResizeScreen(XtermWidget xw,int min_width,int min_height )
{
    register TScreen *screen = &xw->screen;
#ifndef nothack

    XSizeHints sizehints;
    long supp;
#endif

    XtGeometryResult geomreqresult;
    Dimension reqWidth, reqHeight, repWidth, repHeight;

    /*
     * I'm going to try to explain, as I understand it, why we
     * have to do XGetWMNormalHints and XSetWMNormalHints here,
     * although I can't guarantee that I've got it right.
     *
     * In a correctly written toolkit program, the Shell widget
     * parses the user supplied geometry argument.  However,
     * because of the way xterm does things, the VT100 widget does
     * the parsing of the geometry option, not the Shell widget.
     * The result of this is that the Shell widget doesn't set the
     * correct window manager hints, and doesn't know that the
     * user has specified a geometry.
     *
     * The XtVaSetValues call below tells the Shell widget to
     * change its hints.  However, since it's confused about the
     * hints to begin with, it doesn't get them all right when it
     * does the SetValues -- it undoes some of what the VT100
     * widget did when it originally set the hints.
     *
     * To fix this, we do the following:
     *
     * 1. Get the sizehints directly from the window, going around
     *    the (confused) shell widget.
     * 2. Call XtVaSetValues to let the shell widget know which
     *    hints have changed.  Note that this may not even be
     *    necessary, since we're going to right ahead after that
     *    and set the hints ourselves, but it's good to put it
     *    here anyway, so that when we finally do fix the code so
     *    that the Shell does the right thing with hints, we
     *    already have the XtVaSetValues in place.
     * 3. We set the sizehints directly, this fixing up whatever
     *    damage was done by the Shell widget during the
     *    XtVaSetValues.
     *
     * Gross, huh?
     *
     * The correct fix is to redo VTRealize, VTInitialize and
     * VTSetValues so that font processing happens early enough to
     * give back responsibility for the size hints to the Shell.
     *
     * Someday, we hope to have time to do this.  Someday, we hope
     * to have time to completely rewrite xterm.
     */

#ifndef nothack
    /*
     * NOTE: If you change the way any of the hints are calculated
     * below, make sure you change the calculation both in the
     * sizehints assignments and in the XtVaSetValues.
     */

    if (! XGetWMNormalHints(screen->display, XtWindow(XtParent(xw)),
                            &sizehints, &supp))
        sizehints.flags = 0;
    sizehints.base_width = min_width;
    sizehints.base_height = min_height;
    sizehints.width_inc = FontWidth(screen);
    sizehints.height_inc = FontHeight(screen);
    sizehints.min_width = sizehints.base_width + sizehints.width_inc;
    sizehints.min_height = sizehints.base_height + sizehints.height_inc;
    sizehints.flags |= (PBaseSize|PMinSize|PResizeInc);
    /* These are obsolete, but old clients may use them */
    sizehints.width = (screen->max_col + 1) * FontWidth(screen)
                      + min_width;
    sizehints.height = (screen->max_row + 1) * FontHeight(screen)
                       + min_height;
#endif

    /*
     * Note: width and height are not set here because they are 
     * obsolete.       
     */
    XtVaSetValues(XtParent(xw),
                  XtNbaseWidth, min_width,
                  XtNbaseHeight, min_height,
                  XtNwidthInc, FontWidth(screen),
                  XtNheightInc, FontHeight(screen),
                  XtNminWidth, min_width + FontWidth(screen),
                  XtNminHeight, min_height + FontHeight(screen),
                  NULL);

    reqWidth = (screen->max_col + 1) * FontWidth(screen) + min_width;
    reqHeight = FontHeight(screen) * (screen->max_row + 1) + min_height;
    geomreqresult = XtMakeResizeRequest ((Widget)xw, reqWidth, reqHeight,
                                         &repWidth, &repHeight);

    if (geomreqresult == XtGeometryAlmost)
    {
        geomreqresult = XtMakeResizeRequest ((Widget)xw, repWidth,
                                             repHeight, NULL, NULL);
    }

#ifndef nothack
    XSetWMNormalHints(screen->display, XtWindow(XtParent(xw)), &sizehints);
#endif
}
Ejemplo n.º 8
0
/************************************************************************
 *
 *  Geometry Manager
 *	Take the requested geometry, calculate the needed size for
 *	the frame and make a request to the frames parent.
 *      Requests to change x, y position are always denied.
 *
 ************************************************************************/
static XtGeometryResult 
GeometryManager(
        Widget w,
        XtWidgetGeometry *request,
        XtWidgetGeometry *reply )
{
   XmFrameWidget fw = (XmFrameWidget) XtParent(w);
   Widget title_area = fw->frame.title_area;
   Widget work_area = fw->frame.work_area;
   Dimension req_width, req_height, req_bw;
   Boolean query_only = False;
   Boolean almost = False;
   Dimension title_width = (title_area)?title_area->core.width:0;
   Dimension title_height = (title_area)?title_area->core.height:0;
   Dimension title_bw = (title_area)?title_area->core.border_width:0;
   Dimension work_width = (work_area)?work_area->core.width:0;
   Dimension work_height = (work_area)?work_area->core.height:0;
   Dimension work_bw = (work_area)?work_area->core.border_width:0;
   Dimension frame_width, frame_height;
   XtWidgetGeometry parent_request;
   XtWidgetGeometry parent_reply;
   Dimension almost_width;
   Dimension almost_height;

   if (fw->frame.processing_constraints)
   {
      fw->frame.processing_constraints = False;
      request -> border_width -= 1;
   }

   /*  Set up the calculation variables according to the  */
   /*  contents of the requested geometry.                */

   if (request -> request_mode & XtCWQueryOnly)
      query_only = True;

   if ((request -> request_mode & CWX) || (request -> request_mode & CWY))
      almost = True;

   if (request -> request_mode & CWWidth) req_width = request -> width;
   else req_width = w -> core.width;

   if (request -> request_mode & CWHeight) req_height = request -> height;
   else req_height = w -> core.height;

   if (request -> request_mode & CWBorderWidth)
       req_bw = request -> border_width;
   else req_bw = w -> core.border_width;

   if (w == title_area)
   {
      title_width = req_width;
      title_height = req_height;
      title_bw = req_bw;
   }
   if (w == work_area)
   {
      work_width = req_width;
      work_height = req_height;
      work_bw = req_bw;
   }

   /* find the frame size based on the children preferred geometry */

   CalcFrameSize (fw, title_width, title_height, title_bw,
		  work_width, work_height, work_bw,
		  &frame_width, &frame_height);

   parent_request.request_mode = CWWidth | CWHeight;
   if (almost || query_only) parent_request.request_mode |= XtCWQueryOnly;
   parent_request.width = frame_width;
   parent_request.height = frame_height;

   switch (XtMakeGeometryRequest ((Widget)fw, 
				  &parent_request, &parent_reply)) {
   case XtGeometryYes:
       if (!almost) {
	   if (!query_only) {
	       ClearShadow(fw);
	       ConfigureChildren(fw, w, request);
	       DrawShadow(fw);
	   }
	   return (XtGeometryYes);
         } else {
	     almost_width = request->width;
	     almost_height = request->height;
	 }
       break;
   case XtGeometryNo:
	 if (w == title_area) { 
	     /* we got a No, try to honor the title request anyway,
	        by resizing the work_area child */
	     if (!almost) {
		 if (!query_only) {
		     ClearShadow(fw);
		     ConfigureChildren(fw, w, request);
		     DrawShadow(fw);
		 }
		 return (XtGeometryYes);
	     } else {
		 almost_width = request->width;
		 almost_height = request->height;
	     }
	 } else return (XtGeometryNo);
         break;

   case XtGeometryAlmost:
	 if (w == title_area) {
	     /* we got an Almost, try to honor the title request anyway,
	        by accepting the deal and resizing the work_area child */
	     if (!almost) {
		 if (!query_only) {
		     ClearShadow(fw);
		     XtMakeResizeRequest((Widget)fw, parent_reply.width,
					 parent_reply.height, NULL, NULL); 
		     ConfigureChildren(fw, w, request);
		 }
		 return (XtGeometryYes);
	     } else {
		 almost_width = request->width;
		 almost_height = request->height;
	     }
	 } else {
	     /* we got an Almost, accept the deal and 
		compute the work_area size */
	     CalcWorkAreaSize (fw, &almost_width, &almost_height,
			       req_bw, parent_reply.width, 
			       parent_reply.height);
	 }
         break;
   default:
         return (XtGeometryNo);
	 break;
   }


   /*  Fallen through to an almost condition.  Clear the x and y  */
   /*  and set the width, height, and border.                     */


   if (reply != NULL) {
      reply -> request_mode = request -> request_mode & ~(CWX | CWY);
      reply -> width = almost_width;
      reply -> height = almost_height;
      reply -> border_width = req_bw;
      if (request -> request_mode & CWSibling)
               reply -> sibling = request -> sibling;
      if (request -> request_mode & CWStackMode)
               reply -> stack_mode = request -> stack_mode;
      return (XtGeometryAlmost);
   }

   return (XtGeometryNo);
}