-// Get the value of this edge or dimension, or if this
-// is not determinable, -1.
-int wxIndividualLayoutConstraint::GetEdge(wxEdge which, wxWindow *thisWin, wxWindow *other)
-{
- // If the edge or dimension belongs to the parent, then we
- // know the dimension is obtainable immediately.
- // E.g. a wxExpandSizer may contain a button (but the button's
- // true parent is a panel, not the sizer)
- if (other->GetChildren()->Member(thisWin))
- {
- switch (which)
- {
- case wxLeft:
- {
- return wxSizerMarginX(other);
- }
- case wxTop:
- {
- return wxSizerMarginY(other);
- }
- case wxRight:
- {
- int w, h;
- other->GetClientSizeConstraint(&w, &h);
- return w - wxSizerMarginX(other);
- }
- case wxBottom:
- {
- int w, h;
- other->GetClientSizeConstraint(&w, &h);
- return h - wxSizerMarginY(other);
- }
- case wxWidth:
- {
- int w, h;
- other->GetClientSizeConstraint(&w, &h);
- return w - 2*wxSizerMarginX(other);
- }
- case wxHeight:
- {
- int w, h;
- other->GetClientSizeConstraint(&w, &h);
- return h - 2*wxSizerMarginY(other);
- }
- case wxCentreX:
- case wxCentreY:
- {
- int w, h;
- other->GetClientSizeConstraint(&w, &h);
- if (which == wxCentreX)
- return (int)(w/2);
- else
- return (int)(h/2);
- }
- default:
- return -1;
- }
- }
- switch (which)
- {
- case wxLeft:
- {
- wxLayoutConstraints *constr = other->GetConstraints();
- // If no constraints, it means the window is not dependent
- // on anything, and therefore we know its value immediately
- if (constr)
- {
- if (constr->left.GetDone())
- return constr->left.GetValue();
- else
- return -1;
- }
- else
- {
- int x, y;
- other->GetPosition(&x, &y);
- return x;
- }
- }
- case wxTop:
- {
- wxLayoutConstraints *constr = other->GetConstraints();
- // If no constraints, it means the window is not dependent
- // on anything, and therefore we know its value immediately
- if (constr)
- {
- if (constr->top.GetDone())
- return constr->top.GetValue();
- else
- return -1;
- }
- else
- {
- int x, y;
- other->GetPosition(&x, &y);
- return y;
- }
- }
- case wxRight:
- {
- wxLayoutConstraints *constr = other->GetConstraints();
- // If no constraints, it means the window is not dependent
- // on anything, and therefore we know its value immediately
- if (constr)
- {
- if (constr->right.GetDone())
- return constr->right.GetValue();
- else
- return -1;
- }
- else
- {
- int x, y, w, h;
- other->GetPosition(&x, &y);
- other->GetSize(&w, &h);
- return (int)(x + w);
- }
- }
- case wxBottom:
- {
- wxLayoutConstraints *constr = other->GetConstraints();
- // If no constraints, it means the window is not dependent
- // on anything, and therefore we know its value immediately
- if (constr)
- {
- if (constr->bottom.GetDone())
- return constr->bottom.GetValue();
- else
- return -1;
- }
- else
- {
- int x, y, w, h;
- other->GetPosition(&x, &y);
- other->GetSize(&w, &h);
- return (int)(y + h);
- }
- }
- case wxWidth:
- {
- wxLayoutConstraints *constr = other->GetConstraints();
- // If no constraints, it means the window is not dependent
- // on anything, and therefore we know its value immediately
- if (constr)
- {
- if (constr->width.GetDone())
- return constr->width.GetValue();
- else
- return -1;
- }
- else
- {
- int w, h;
- other->GetSize(&w, &h);
- return w;
- }
- }
- case wxHeight:
- {
- wxLayoutConstraints *constr = other->GetConstraints();
- // If no constraints, it means the window is not dependent
- // on anything, and therefore we know its value immediately
- if (constr)
- {
- if (constr->height.GetDone())
- return constr->height.GetValue();
- else
- return -1;
- }
- else
- {
- int w, h;
- other->GetSize(&w, &h);
- return h;
- }
- }
- case wxCentreX:
- {
- wxLayoutConstraints *constr = other->GetConstraints();
- // If no constraints, it means the window is not dependent
- // on anything, and therefore we know its value immediately
- if (constr)
- {
- if (constr->centreX.GetDone())
- return constr->centreX.GetValue();
- else
- return -1;
- }
- else
- {
- int x, y, w, h;
- other->GetPosition(&x, &y);
- other->GetSize(&w, &h);
- return (int)(x + (w/2));
- }
- }
- case wxCentreY:
- {
- wxLayoutConstraints *constr = other->GetConstraints();
- // If no constraints, it means the window is not dependent
- // on anything, and therefore we know its value immediately
- if (constr)
- {
- if (constr->centreY.GetDone())
- return constr->centreY.GetValue();
- else
- return -1;
- }
- else
- {
- int x, y, w, h;
- other->GetPosition(&x, &y);
- other->GetSize(&w, &h);
- return (int)(y + (h/2));
- }
- }
- default:
- break;
- }
- return -1;
-}
-
-wxLayoutConstraints::wxLayoutConstraints(void)
-{
- left.SetEdge(wxLeft);
- top.SetEdge(wxTop);
- right.SetEdge(wxRight);
- bottom.SetEdge(wxBottom);
- centreX.SetEdge(wxCentreX);
- centreY.SetEdge(wxCentreY);
- width.SetEdge(wxWidth);
- height.SetEdge(wxHeight);
-}
-
-wxLayoutConstraints::~wxLayoutConstraints(void)
-{
-}
-
-bool wxLayoutConstraints::SatisfyConstraints(wxWindow *win, int *nChanges)
-{
- int noChanges = 0;
-
- bool done = width.GetDone();
- bool newDone = (done ? TRUE : width.SatisfyConstraint(this, win));
- if (newDone != done)
- noChanges ++;
-
- done = height.GetDone();
- newDone = (done ? TRUE : height.SatisfyConstraint(this, win));
- if (newDone != done)
- noChanges ++;
-
- done = left.GetDone();
- newDone = (done ? TRUE : left.SatisfyConstraint(this, win));
- if (newDone != done)
- noChanges ++;
-
- done = top.GetDone();
- newDone = (done ? TRUE : top.SatisfyConstraint(this, win));
- if (newDone != done)
- noChanges ++;
-
- done = right.GetDone();
- newDone = (done ? TRUE : right.SatisfyConstraint(this, win));
- if (newDone != done)
- noChanges ++;
-
- done = bottom.GetDone();
- newDone = (done ? TRUE : bottom.SatisfyConstraint(this, win));
- if (newDone != done)
- noChanges ++;
-
- done = centreX.GetDone();
- newDone = (done ? TRUE : centreX.SatisfyConstraint(this, win));
- if (newDone != done)
- noChanges ++;
-
- done = centreY.GetDone();
- newDone = (done ? TRUE : centreY.SatisfyConstraint(this, win));
- if (newDone != done)
- noChanges ++;
-
- *nChanges = noChanges;
-
- return (left.GetDone() && top.GetDone() && right.GetDone() && bottom.GetDone() &&
- centreX.GetDone() && centreY.GetDone());
-}
-
-/*
- * Main constrained layout algorithm. Look at all the child
- * windows, and their constraints (if any).
- * The idea is to keep iterating through the constraints
- * until all left, right, bottom and top edges, and widths and heights,
- * are known (or no change occurs and we've failed to resolve all
- * constraints).
- *
- * If the user has not specified a dimension or edge, it will be
- * be calculated from the other known values. E.g. If we know
- * the right hand edge and the left hand edge, we now know the width.
- * The snag here is that this means we must specify absolute dimensions
- * twice (in constructor and in constraint), if we wish to use the
- * constraint notation to just set the position, for example.
- * Otherwise, if we only set ONE edge and no dimension, it would never
- * find the other edge.
- *
- * Algorithm:
-
- Mark all constraints as not done.
-
- iterations = 0;
- until no change or iterations >= max iterations
- For each child:
- {
- Calculate all constraints
- }
- iterations ++;
-
- For each child
- Set each calculated position and size
-
- */
-
-bool wxOldDoLayout(wxWindow *win)
-{
- // Make sure this isn't called recursively from below
- static wxList doneSoFar;
-
- if (doneSoFar.Member(win))
- return TRUE;
-
- doneSoFar.Append(win);
-
- wxNode *node = win->GetChildren()->First();
- while (node)
- {
- wxWindow *child = (wxWindow *)node->Data();
- wxLayoutConstraints *constr = child->GetConstraints();
- if (constr)
- {
- constr->left.SetDone(FALSE);
- constr->top.SetDone(FALSE);
- constr->right.SetDone(FALSE);
- constr->bottom.SetDone(FALSE);
- constr->width.SetDone(FALSE);
- constr->height.SetDone(FALSE);
- constr->centreX.SetDone(FALSE);
- constr->centreY.SetDone(FALSE);
- }
- node = node->Next();
- }
- int noIterations = 0;
- int maxIterations = 500;
- int noChanges = 1;
-
- while ((noChanges > 0) && (noIterations < maxIterations))
- {
- noChanges = 0;
- wxNode *node = win->GetChildren()->First();
- while (node)
- {
- wxWindow *child = (wxWindow *)node->Data();
- wxLayoutConstraints *constr = child->GetConstraints();
- if (constr)
- {
- int tempNoChanges = 0;
- (void) constr->SatisfyConstraints(child, &tempNoChanges);
- noChanges += tempNoChanges;
- }
- node = node->Next();
- }
- noIterations ++;
- }
-/*
- // Would be nice to have a test here to see _which_ constraint(s)
- // failed, so we can print a specific diagnostic message.
- if (noFailures > 0)
- {
- wxDebugMsg("wxWindow::Layout() failed.\n");
- }
-*/
- // Now set the sizes and positions of the children, and
- // recursively call Layout().
- node = win->GetChildren()->First();
- while (node)
- {
- wxWindow *child = (wxWindow *)node->Data();
- wxLayoutConstraints *constr = child->GetConstraints();
- if (constr && constr->left.GetDone() && constr->right.GetDone() &&
- constr->width.GetDone() && constr->height.GetDone())
- {
- int x = constr->left.GetValue();
- int y = constr->top.GetValue();
- int w = constr->width.GetValue();
- int h = constr->height.GetValue();
-
- // If we don't want to resize this window, just move it...
- if ((constr->width.GetRelationship() != wxAsIs) ||
- (constr->height.GetRelationship() != wxAsIs))
- {
- // _Should_ call Layout() recursively.
- child->SetSize(x, y, w, h);
- }
- else
- {
- child->Move(x, y);
- }
- }
- else
- child->Layout();
- node = node->Next();
- }
- doneSoFar.DeleteObject(win);
-
- return TRUE;
-}
-
-wxSizer::wxSizer(void)
-{
- sizerBehaviour = wxSizerNone;
- borderX = 2;
- borderY = 2;
- sizerX = 0;
- sizerY = 0;
- sizerWidth = 0;
- sizerHeight = 0;
-}