Box.c File Reference

#include <X11/IntrinsicP.h>
#include <X11/StringDefs.h>
#include <X11/Xmu/Misc.h>
#include <X11/Xaw3d/XawInit.h>
#include <X11/Xaw3d/BoxP.h>

Include dependency graph for Box.c:

Go to the source code of this file.

Functions

static void ClassInitialize ()
static void Initialize ()
static void Realize ()
static void Resize ()
static Boolean SetValues ()
static XtGeometryResult GeometryManager ()
static void ChangeManaged ()
static XtGeometryResult PreferredSize ()
static void DoLayout (BoxWidget bbw, Dimension width, Dimension height, Dimension *reply_width, Dimension *reply_height, Boolean position)
static XtGeometryResult PreferredSize (Widget widget, XtWidgetGeometry *constraint, XtWidgetGeometry *preferred)
static void Resize (Widget w)
static Boolean TryNewLayout (BoxWidget bbw)
static XtGeometryResult GeometryManager (Widget w, XtWidgetGeometry *request, XtWidgetGeometry *reply)
static void ChangeManaged (Widget w)
static void Initialize (Widget request, Widget new, ArgList args, Cardinal *num_args)
static void Realize (Widget w, Mask *valueMask, XSetWindowAttributes *attributes)
static Boolean SetValues (Widget current, Widget request, Widget new, ArgList args, Cardinal *num_args)

Variables

static XtResource resources []
BoxClassRec boxClassRec
WidgetClass boxWidgetClass = (WidgetClass)&boxClassRec


Function Documentation

static void ChangeManaged ( Widget  w  )  [static]

Definition at line 565 of file Box.c.

References Resize(), TryNewLayout(), void(), and w.

00567 {
00568     /* Reconfigure the box */
00569     (void) TryNewLayout((BoxWidget)w);
00570     Resize(w);
00571 }

Here is the call graph for this function:

static void ChangeManaged (  )  [static]

Referenced by SetValues().

Here is the caller graph for this function:

static void ClassInitialize (  )  [static]

Definition at line 573 of file Box.c.

00574 {
00575     XawInitializeWidgetSet();
00576     XtAddConverter( XtRString, XtROrientation, XmuCvtStringToOrientation,
00577                     (XtConvertArgList)NULL, (Cardinal)0 );
00578 }

static void DoLayout ( BoxWidget  bbw,
Dimension  width,
Dimension  height,
Dimension *  reply_width,
Dimension *  reply_height,
Boolean  position 
) [static]

Definition at line 160 of file Box.c.

References AssignMax, h, i, lw, w, and XtorientVertical.

Referenced by PreferredSize(), Resize(), and TryNewLayout().

00165 {
00166     Boolean vbox = (bbw->box.orientation == XtorientVertical);
00167     Cardinal  i;
00168     Dimension w, h;     /* Width and height needed for box              */
00169     Dimension lw, lh;   /* Width and height needed for current line     */
00170     Dimension bw, bh;   /* Width and height needed for current widget   */
00171     Dimension h_space;  /* Local copy of bbw->box.h_space               */
00172     Widget widget;      /* Current widget                               */
00173     int num_mapped_children = 0;
00174  
00175     /* Box width and height */
00176     h_space = bbw->box.h_space;
00177 
00178     w = 0;
00179     for (i = 0; i < bbw->composite.num_children; i++) {
00180         if ( bbw->composite.children[i]->core.width > w )
00181             w = bbw->composite.children[i]->core.width;
00182     }
00183     w += h_space;
00184     if ( w > width ) width = w;
00185     h = bbw->box.v_space;
00186    
00187     /* Line width and height */
00188     lh = 0;
00189     lw = h_space;
00190   
00191     for (i = 0; i < bbw->composite.num_children; i++) {
00192         widget = bbw->composite.children[i];
00193         if (widget->core.managed) {
00194             if (widget->core.mapped_when_managed) num_mapped_children++;
00195             /* Compute widget width */
00196             bw = widget->core.width + 2*widget->core.border_width + h_space;
00197             if ((Dimension)(lw + bw) > width) {
00198                 if (lw > h_space) {
00199                     /* At least one widget on this line, and
00200                      * can't fit any more.  Start new line if vbox.
00201                      */
00202                     AssignMax(w, lw);
00203                     if (vbox) {
00204                         h += lh + bbw->box.v_space;
00205                         lh = 0;
00206                         lw = h_space;
00207                     }
00208                 }
00209                 else if (!position) {
00210                     /* too narrow for this widget; we'll assume we can grow */
00211                     DoLayout(bbw, lw + bw, height, reply_width,
00212                              reply_height, position);
00213                     return;
00214                 }
00215             }
00216             if (position && (lw != (Dimension)widget->core.x || h != (Dimension)widget->core.y)) {
00217                 /* It would be nice to use window gravity, but there isn't
00218                  * sufficient fine-grain control to nicely handle all
00219                  * situations (e.g. when only the height changes --
00220                  * a common case).  Explicit unmapping is a cheap hack
00221                  * to speed things up & avoid the visual jitter as
00222                  * things slide around.
00223                  *
00224                  * %%% perhaps there should be a client resource to
00225                  * control this.  If so, we'll have to optimize to
00226                  * perform the moves from the correct end so we don't
00227                  * force extra exposures as children occlude each other.
00228                  */
00229                 if (XtIsRealized(widget) && widget->core.mapped_when_managed)
00230                     XUnmapWindow( XtDisplay(widget), XtWindow(widget) );
00231                 XtMoveWidget(widget, (int)lw, (int)h);
00232             }
00233             lw += bw;
00234             bh = widget->core.height + 2*widget->core.border_width;
00235             AssignMax(lh, bh);
00236         } /* if managed */
00237     } /* for */
00238 
00239     if (!vbox && width && lw > width && lh < height) {
00240         /* reduce width if too wide and height not filled */
00241         Dimension sw = lw, sh = lh;
00242         Dimension width_needed = 0;
00243         XtOrientation orientation = bbw->box.orientation;
00244         bbw->box.orientation = XtorientVertical;
00245         while (sh < height && sw > width) {
00246             width_needed = sw;
00247             DoLayout(bbw, sw-1, height, &sw, &sh, False);
00248         }
00249         if (sh < height) width_needed = sw;
00250         if (width_needed != lw) {
00251             DoLayout(bbw,width_needed,height,reply_width,reply_height,position);
00252             bbw->box.orientation = orientation;
00253             return;
00254         }
00255         bbw->box.orientation = orientation;
00256     }
00257    if ( vbox && ( ( width < w ) || ( width < lw ) ) ) {
00258         AssignMax(w, lw);
00259         DoLayout( bbw, w, height, reply_width, reply_height, position );
00260         return;
00261     }
00262     if (position && XtIsRealized((Widget)bbw)) {
00263         if (bbw->composite.num_children == num_mapped_children)
00264             XMapSubwindows( XtDisplay((Widget)bbw), XtWindow((Widget)bbw) );
00265         else {
00266             int i = bbw->composite.num_children;
00267             Widget *childP = bbw->composite.children;
00268             for (; i > 0; childP++, i--)
00269                 if (XtIsRealized(*childP) && XtIsManaged(*childP) &&
00270                     (*childP)->core.mapped_when_managed)
00271                     XtMapWidget(*childP);
00272         }
00273     }
00274 
00275     /* Finish off last line */
00276     if (lw > h_space) {
00277         AssignMax(w, lw);
00278         h += lh + bbw->box.v_space;
00279     }
00280 
00281     *reply_width = Max(w, 1);
00282     *reply_height = Max(h, 1);
00283 }

Here is the caller graph for this function:

static XtGeometryResult GeometryManager ( Widget  w,
XtWidgetGeometry *  request,
XtWidgetGeometry *  reply 
) [static]

Definition at line 501 of file Box.c.

References borderWidth, _BoxRec::core, height, and TryNewLayout().

00506 {
00507     Dimension   width, height, borderWidth;
00508     BoxWidget bbw;
00509 
00510     /* Position request always denied */
00511     if ((request->request_mode & CWX && request->x != w->core.x) ||
00512         (request->request_mode & CWY && request->y != w->core.y))
00513         return (XtGeometryNo);
00514 
00515     /* Size changes must see if the new size can be accomodated */
00516     if (request->request_mode & (CWWidth | CWHeight | CWBorderWidth)) {
00517 
00518         /* Make all three fields in the request valid */
00519         if ((request->request_mode & CWWidth) == 0)
00520             request->width = w->core.width;
00521         if ((request->request_mode & CWHeight) == 0)
00522             request->height = w->core.height;
00523         if ((request->request_mode & CWBorderWidth) == 0)
00524             request->border_width = w->core.border_width;
00525 
00526         /* Save current size and set to new size */
00527         width = w->core.width;
00528         height = w->core.height;
00529         borderWidth = w->core.border_width;
00530         w->core.width = request->width;
00531         w->core.height = request->height;
00532         w->core.border_width = request->border_width;
00533 
00534         /* Decide if new layout works: (1) new widget is smaller,
00535            (2) new widget fits in existing Box, (3) Box can be
00536            expanded to allow new widget to fit */
00537 
00538         bbw = (BoxWidget) w->core.parent;
00539 
00540 /* whenever a child changes his geometry, we attempt to
00541  * change ours to be the minimum enclosing size...
00542         if (((request->width + request->border_width <= width + borderWidth) &&
00543             (request->height + request->border_width <= height + borderWidth))
00544         || bbw->box.preferred_width < bbw->core.width
00545         || bbw->box.preferred_height < bbw->core.height
00546         || TryNewLayout(bbw)) {
00547  */
00548         if (TryNewLayout(bbw)) {
00549             /* Fits in existing or new space, relayout */
00550             (*XtClass((Widget)bbw)->core_class.resize)((Widget)bbw);
00551             return (XtGeometryYes);
00552         } else {
00553             /* Cannot satisfy request, change back to original geometry */
00554             w->core.width = width;
00555             w->core.height = height;
00556             w->core.border_width = borderWidth;
00557             return (XtGeometryNo);
00558         }
00559     }; /* if any size changes requested */
00560 
00561     /* Any stacking changes don't make a difference, so allow if that's all */
00562     return (XtGeometryYes);
00563 }

Here is the call graph for this function:

static XtGeometryResult GeometryManager (  )  [static]

static void Initialize ( Widget  request,
Widget  new,
ArgList  args,
Cardinal *  num_args 
) [static]

Definition at line 581 of file Box.c.

References _BoxRec::box, _BoxRec::core, BoxPart::h_space, BoxPart::last_query_height, BoxPart::last_query_mode, BoxPart::last_query_width, Max, BoxPart::preferred_height, BoxPart::preferred_width, and BoxPart::v_space.

00585 {
00586     BoxWidget newbbw = (BoxWidget)new;
00587 
00588     newbbw->box.last_query_mode = CWWidth | CWHeight;
00589     newbbw->box.last_query_width = newbbw->box.last_query_height = 0;
00590     newbbw->box.preferred_width = Max(newbbw->box.h_space, 1);
00591     newbbw->box.preferred_height = Max(newbbw->box.v_space, 1);
00592 
00593     if (newbbw->core.width == 0)
00594         newbbw->core.width = newbbw->box.preferred_width;
00595 
00596     if (newbbw->core.height == 0)
00597         newbbw->core.height = newbbw->box.preferred_height;
00598 
00599 } /* Initialize */

static void Initialize (  )  [static]

Definition at line 26 of file javasci_globals.c.

00027 {
00028   static char env[1024];
00029   static char initstr[]="exec(\"SCI/etc/scilab.start\",-1);quit;";
00030   static int iflag=-1, stacksize = 1000000, ierr=0;
00031 
00032   #ifdef _MSC_VER
00033     static char JavaSciInterf[]="javasci";
00034     static char nw[]="-nw";
00035     static char nb[]="-nb";
00036   #endif
00037 
00038   
00039   char *p1 = (char*)getenv ("SCI");
00040   
00041   
00042   #ifdef _MSC_VER
00043   /* Supprime le mode windows et la baniere */
00044     add_sci_argv(JavaSciInterf);
00045     add_sci_argv(nb);
00046   #endif
00047   
00048   #ifdef _MSC_VER 
00049     if ( p1== NULL )
00050     {
00051                 /* Detection Scilab path */
00052                 char modname[MAX_PATH+1];
00053                 if (!GetModuleFileName (GetModuleHandle("javasci.dll"), modname, MAX_PATH))
00054                 {
00055                         MessageBox(NULL,"javasci.dll not found","Warning",MB_ICONWARNING);
00056                 }
00057                 else
00058                 {
00059                         char *p;
00060                         if ((p = strrchr (modname, '\\')) == NULL) exit(1); /* remove \javasci.dll from modname */
00061                         else
00062                         {
00063                                 *p='\0';
00064                                 if ((p = strrchr (modname, '\\')) == NULL) exit(1); /* remove \bin from modname */
00065                                 else
00066                                 {
00067                                         *p='\0';
00068                                         set_sci_env(modname);
00069                                 }
00070                         }
00071                 }
00072     }
00073     else 
00074         {
00075                 char *pathSCI=(char*)MALLOC((strlen(p1)+1)*sizeof(char));
00076                 sprintf(pathSCI,"%s",p1);
00077                 set_sci_env(pathSCI);
00078                 if (pathSCI) {FREE(pathSCI);pathSCI=NULL;}
00079         }
00080   #else
00081    if (p1==NULL)
00082    {
00083         fprintf(stderr,"Please define SCI environment variable\n");
00084         sprintf (env, "%s=%s", "SCI",SCI);
00085         setSCIpath(SCI);
00086         putenv (env);
00087    }
00088   #endif
00089   /* set TMPDIR */
00090   C2F(settmpdir)();
00091   /* Scilab Initialization */
00092   C2F(inisci)(&iflag,&stacksize,&ierr);
00093   if ( ierr > 0 ) 
00094     {
00095       fprintf(stderr,"Scilab initialization failed !\n");
00096       exit(1);
00097     }
00098 
00099 
00100   /* Initialisation fenetre graphique */
00101   #ifdef _MSC_VER
00102     InitWindowGraphDll();
00103   #endif
00104 
00105   /* pour initialisation de la primitive scilab : fromjava() */
00106   SetFromJavaToON();
00107 
00108   /* Chargement de Scilab.start */
00109   C2F(scirun)(initstr,(int)strlen(initstr));
00110  
00111 }

static XtGeometryResult PreferredSize ( Widget  widget,
XtWidgetGeometry *  constraint,
XtWidgetGeometry *  preferred 
) [static]

Definition at line 291 of file Box.c.

References DoLayout(), FALSE, height, and w.

00294 {
00295     BoxWidget w = (BoxWidget)widget;
00296     Dimension width /*, height */;
00297     Dimension preferred_width = w->box.preferred_width;
00298     Dimension preferred_height = w->box.preferred_height;
00299 
00300     constraint->request_mode &= CWWidth | CWHeight;
00301 
00302     if (constraint->request_mode == 0)
00303         /* parent isn't going to change w or h, so nothing to re-compute */
00304         return XtGeometryYes;
00305 
00306     if (constraint->request_mode == w->box.last_query_mode &&
00307         (!(constraint->request_mode & CWWidth) ||
00308          constraint->width == w->box.last_query_width) &&
00309         (!(constraint->request_mode & CWHeight) ||
00310          constraint->height == w->box.last_query_height)) {
00311         /* same query; current preferences are still valid */
00312         preferred->request_mode = CWWidth | CWHeight;
00313         preferred->width = preferred_width;
00314         preferred->height = preferred_height;
00315         if (constraint->request_mode == (CWWidth | CWHeight) &&
00316             constraint->width == preferred_width &&
00317             constraint->height == preferred_height)
00318             return XtGeometryYes;
00319         else
00320             return XtGeometryAlmost;
00321     }
00322         
00323     /* else gotta do it the long way...
00324        I have a preference for tall and narrow, so if my width is
00325        constrained, I'll accept it; otherwise, I'll compute the minimum
00326        width that will fit me within the height constraint */
00327 
00328     w->box.last_query_mode = constraint->request_mode;
00329     w->box.last_query_width = constraint->width;
00330     w->box.last_query_height= constraint->height;
00331 
00332     if (constraint->request_mode & CWWidth)
00333         width = constraint->width;
00334     else /* if (constraint->request_mode & CWHeight) */ {
00335          /* let's see if I can become any narrower */
00336         width = 0;
00337         constraint->width = 65535;
00338     }
00339 
00340     /* height is currently ignored by DoLayout.
00341        height = (constraint->request_mode & CWHeight) ? constraint->height
00342                        : *preferred_height;
00343      */
00344     DoLayout(w, width, (Dimension)0,
00345              &preferred_width, &preferred_height, FALSE);
00346 
00347     if (constraint->request_mode & CWHeight &&
00348         preferred_height > constraint->height) {
00349         /* find minimum width for this height */
00350         if (preferred_width > constraint->width) {
00351             /* punt; over-constrained */
00352         }
00353         else {
00354             width = preferred_width;
00355             do { /* find some width big enough to stay within this height */
00356                 width *= 2;
00357                 if (width > constraint->width) width = constraint->width;
00358                 DoLayout(w, width, 0, &preferred_width, &preferred_height, FALSE);
00359             } while (preferred_height > constraint->height &&
00360                      width < constraint->width);
00361             if (width != constraint->width) {
00362                 do { /* find minimum width */
00363                     width = preferred_width;
00364                     DoLayout(w, preferred_width-1, 0,
00365                              &preferred_width, &preferred_height, FALSE);
00366                 } while (preferred_height < constraint->height);
00367                 /* one last time */
00368                 DoLayout(w, width, 0, &preferred_width, &preferred_height, FALSE);
00369             }
00370         }
00371     }
00372 
00373     preferred->request_mode = CWWidth | CWHeight;
00374     preferred->width = w->box.preferred_width = preferred_width;
00375     preferred->height = w->box.preferred_height = preferred_height;
00376 
00377     if (constraint->request_mode == (CWWidth|CWHeight)
00378         && constraint->width == preferred_width
00379         && constraint->height == preferred_height)
00380         return XtGeometryYes;
00381     else
00382         return XtGeometryAlmost;
00383 
00384 }

Here is the call graph for this function:

static XtGeometryResult PreferredSize (  )  [static]

Referenced by TryNewLayout().

Here is the caller graph for this function:

static void Realize ( Widget  w,
Mask *  valueMask,
XSetWindowAttributes *  attributes 
) [static]

Definition at line 601 of file Box.c.

00605 {
00606     attributes->bit_gravity = NorthWestGravity;
00607     *valueMask |= CWBitGravity;
00608 
00609     XtCreateWindow( w, (unsigned)InputOutput, (Visual *)CopyFromParent,
00610                     *valueMask, attributes);
00611 } /* Realize */

static void Realize (  )  [static]

Referenced by externaldef().

Here is the caller graph for this function:

static void Resize ( Widget  w  )  [static]

Definition at line 392 of file Box.c.

References DoLayout(), TRUE, and w.

00394 {
00395     Dimension junk;
00396 
00397     DoLayout((BoxWidget)w, w->core.width, w->core.height, &junk, &junk, TRUE);
00398 
00399 } /* Resize */

Here is the call graph for this function:

static void Resize (  )  [static]

Referenced by ChangeManaged(), and SetValuesAlmost().

Here is the caller graph for this function:

static Boolean SetValues ( Widget  current,
Widget  request,
Widget  new,
ArgList  args,
Cardinal *  num_args 
) [static]

Definition at line 614 of file Box.c.

00618 {
00619    /* need to relayout if h_space or v_space change */
00620 
00621     return False;
00622 }

static Boolean SetValues (  )  [static]

static Boolean TryNewLayout ( BoxWidget  bbw  )  [static]

Definition at line 410 of file Box.c.

References DoLayout(), FALSE, PreferredSize(), TRUE, and void().

Referenced by ChangeManaged(), and GeometryManager().

00412 {
00413     Dimension   preferred_width, preferred_height;
00414     Dimension   proposed_width, proposed_height;
00415     int         iterations;
00416 
00417     DoLayout( bbw, bbw->core.width, bbw->core.height,
00418               &preferred_width, &preferred_height, FALSE );
00419 
00420     /* at this point, preferred_width is guaranteed to not be greater
00421        than bbw->core.width unless some child is larger, so there's no
00422        point in re-computing another layout */
00423 
00424     if ((bbw->core.width == preferred_width) &&
00425         (bbw->core.height == preferred_height)) {
00426         /* Same size */
00427         return (TRUE);
00428     }
00429 
00430     /* let's see if our parent will go for a new size. */
00431     iterations = 0;
00432     proposed_width = preferred_width;
00433     proposed_height = preferred_height;
00434     do {
00435         switch (XtMakeResizeRequest((Widget)bbw,proposed_width,proposed_height,
00436                                      &proposed_width, &proposed_height))
00437         {
00438             case XtGeometryYes:
00439                 return (TRUE);
00440 
00441             case XtGeometryNo:
00442                 if (iterations > 0)
00443                     /* protect from malicious parents who change their minds */
00444                     DoLayout( bbw, bbw->core.width, bbw->core.height,
00445                               &preferred_width, &preferred_height, FALSE );
00446                 if ((preferred_width <= bbw->core.width) &&
00447                     (preferred_height <= bbw->core.height))
00448                     return (TRUE);
00449                 else
00450                     return (FALSE);
00451 
00452             case XtGeometryAlmost:
00453                 if (proposed_height >= preferred_height &&
00454                     proposed_width >= preferred_width) {
00455 
00456                     /*
00457                      * Take it, and assume the parent knows what it is doing.
00458                      *
00459                      * The parent must accept this since it was returned in
00460                      * almost.
00461                      *
00462                      */
00463                     (void) XtMakeResizeRequest( (Widget)bbw,
00464                                        proposed_width, proposed_height,
00465                                        &proposed_width, &proposed_height);
00466                     return(TRUE);
00467                 }
00468                 else if (proposed_width != preferred_width) {
00469                     /* recalc bounding box; height might change */
00470                     DoLayout(bbw, proposed_width, 0,
00471                              &preferred_width, &preferred_height, FALSE);
00472                     proposed_height = preferred_height;
00473                 }
00474                 else { /* proposed_height != preferred_height */
00475                     XtWidgetGeometry constraints, reply;
00476                     constraints.request_mode = CWHeight;
00477                     constraints.height = proposed_height;
00478                     (void)PreferredSize((Widget)bbw, &constraints, &reply);
00479                     proposed_width = preferred_width;
00480                 }
00481                 break;
00482 
00483             case XtGeometryDone: /* ??? */
00484             default:
00485                 break;
00486         }
00487         iterations++;
00488     } while (iterations < 10);
00489     return (FALSE);
00490 }

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

BoxClassRec boxClassRec

Definition at line 96 of file Box.c.

WidgetClass boxWidgetClass = (WidgetClass)&boxClassRec

Definition at line 144 of file Box.c.

XtResource resources[] [static]

Initial value:

 {
    { XtNhSpace, XtCHSpace, XtRDimension, sizeof(Dimension),
                XtOffsetOf(BoxRec, box.h_space),
                XtRImmediate, (XtPointer)4 },
    { XtNvSpace, XtCVSpace, XtRDimension, sizeof(Dimension),
                XtOffsetOf(BoxRec, box.v_space),
                XtRImmediate, (XtPointer)4 },
    { XtNorientation, XtCOrientation, XtROrientation, sizeof(XtOrientation),
                XtOffsetOf(BoxRec, box.orientation),
                XtRImmediate, (XtPointer)XtorientVertical },
}

Definition at line 69 of file Box.c.


Generated on Sun Mar 4 16:01:01 2007 for Scilab [trunk] by  doxygen 1.5.1