+// Try to satisfy constraint
+bool wxIndividualLayoutConstraint::SatisfyConstraint(wxLayoutConstraints *constraints, wxWindowBase *win)
+{
+ if (relationship == wxAbsolute)
+ {
+ done = true;
+ return true;
+ }
+
+ switch (myEdge)
+ {
+ case wxLeft:
+ {
+ switch (relationship)
+ {
+ case wxLeftOf:
+ {
+ // We can know this edge if: otherWin is win's
+ // parent, or otherWin has a satisfied constraint,
+ // or otherWin has no constraint.
+ int edgePos = GetEdge(otherEdge, win, otherWin);
+ if (edgePos != -1)
+ {
+ value = edgePos - margin;
+ done = true;
+ return true;
+ }
+ else
+ return false;
+ }
+ case wxRightOf:
+ {
+ int edgePos = GetEdge(otherEdge, win, otherWin);
+ if (edgePos != -1)
+ {
+ value = edgePos + margin;
+ done = true;
+ return true;
+ }
+ else
+ return false;
+ }
+ case wxPercentOf:
+ {
+ int edgePos = GetEdge(otherEdge, win, otherWin);
+ if (edgePos != -1)
+ {
+ value = (int)(edgePos*(((float)percent)*0.01) + margin);
+ done = true;
+ return true;
+ }
+ else
+ return false;
+ }
+ case wxUnconstrained:
+ {
+ // We know the left-hand edge position if we know
+ // the right-hand edge and we know the width; OR if
+ // we know the centre and the width.
+ if (constraints->right.GetDone() && constraints->width.GetDone())
+ {
+ value = (constraints->right.GetValue() - constraints->width.GetValue() + margin);
+ done = true;
+ return true;
+ }
+ else if (constraints->centreX.GetDone() && constraints->width.GetDone())
+ {
+ value = (int)(constraints->centreX.GetValue() - (constraints->width.GetValue()/2) + margin);
+ done = true;
+ return true;
+ }
+ else
+ return false;
+ }
+ case wxAsIs:
+ {
+ int y;
+ win->GetPosition(&value, &y);
+ done = true;
+ return true;
+ }
+ default:
+ break;
+ }
+ break;
+ }
+ case wxRight:
+ {
+ switch (relationship)
+ {
+ case wxLeftOf:
+ {
+ // We can know this edge if: otherWin is win's
+ // parent, or otherWin has a satisfied constraint,
+ // or otherWin has no constraint.
+ int edgePos = GetEdge(otherEdge, win, otherWin);
+ if (edgePos != -1)
+ {
+ value = edgePos - margin;
+ done = true;
+ return true;
+ }
+ else
+ return false;
+ }
+ case wxRightOf:
+ {
+ int edgePos = GetEdge(otherEdge, win, otherWin);
+ if (edgePos != -1)
+ {
+ value = edgePos + margin;
+ done = true;
+ return true;
+ }
+ else
+ return false;
+ }
+ case wxPercentOf:
+ {
+ int edgePos = GetEdge(otherEdge, win, otherWin);
+ if (edgePos != -1)
+ {
+ value = (int)(edgePos*(((float)percent)*0.01) - margin);
+ done = true;
+ return true;
+ }
+ else
+ return false;
+ }
+ case wxUnconstrained:
+ {
+ // We know the right-hand edge position if we know the
+ // left-hand edge and we know the width, OR if we know the
+ // centre edge and the width.
+ if (constraints->left.GetDone() && constraints->width.GetDone())
+ {
+ value = (constraints->left.GetValue() + constraints->width.GetValue() - margin);
+ done = true;
+ return true;
+ }
+ else if (constraints->centreX.GetDone() && constraints->width.GetDone())
+ {
+ value = (int)(constraints->centreX.GetValue() + (constraints->width.GetValue()/2) - margin);
+ done = true;
+ return true;
+ }
+ else
+ return false;
+ }
+ case wxAsIs:
+ {
+ int x, y;
+ int w, h;
+ win->GetBestSize(&w, &h);
+ win->GetPosition(&x, &y);
+ value = x + w;
+ done = true;
+ return true;
+ }
+ default:
+ break;
+ }
+ break;
+ }
+ case wxTop:
+ {
+ switch (relationship)
+ {
+ case wxAbove:
+ {
+ // We can know this edge if: otherWin is win's
+ // parent, or otherWin has a satisfied constraint,
+ // or otherWin has no constraint.
+ int edgePos = GetEdge(otherEdge, win, otherWin);
+ if (edgePos != -1)
+ {
+ value = edgePos - margin;
+ done = true;
+ return true;
+ }
+ else
+ return false;
+ }
+ case wxBelow:
+ {
+ int edgePos = GetEdge(otherEdge, win, otherWin);
+ if (edgePos != -1)
+ {
+ value = edgePos + margin;
+ done = true;
+ return true;
+ }
+ else
+ return false;
+ }
+ case wxPercentOf:
+ {
+ int edgePos = GetEdge(otherEdge, win, otherWin);
+ if (edgePos != -1)
+ {
+ value = (int)(edgePos*(((float)percent)*0.01) + margin);
+ done = true;
+ return true;
+ }
+ else
+ return false;
+ }
+ case wxUnconstrained:
+ {
+ // We know the top edge position if we know the bottom edge
+ // and we know the height; OR if we know the centre edge and
+ // the height.
+ if (constraints->bottom.GetDone() && constraints->height.GetDone())
+ {
+ value = (constraints->bottom.GetValue() - constraints->height.GetValue() + margin);
+ done = true;
+ return true;
+ }
+ else if (constraints->centreY.GetDone() && constraints->height.GetDone())
+ {
+ value = (constraints->centreY.GetValue() - (constraints->height.GetValue()/2) + margin);
+ done = true;
+ return true;
+ }
+ else
+ return false;
+ }
+ case wxAsIs:
+ {
+ int x;
+ win->GetPosition(&x, &value);
+ done = true;
+ return true;
+ }
+ default:
+ break;
+ }
+ break;
+ }
+ case wxBottom:
+ {
+ switch (relationship)
+ {
+ case wxAbove:
+ {
+ // We can know this edge if: otherWin is win's parent,
+ // or otherWin has a satisfied constraint, or
+ // otherWin has no constraint.
+ int edgePos = GetEdge(otherEdge, win, otherWin);
+ if (edgePos != -1)
+ {
+ value = edgePos + margin;
+ done = true;
+ return true;
+ }
+ else
+ return false;
+ }
+ case wxBelow:
+ {
+ int edgePos = GetEdge(otherEdge, win, otherWin);
+ if (edgePos != -1)
+ {
+ value = edgePos - margin;
+ done = true;
+ return true;
+ }
+ else
+ return false;
+ }
+ case wxPercentOf:
+ {
+ int edgePos = GetEdge(otherEdge, win, otherWin);
+ if (edgePos != -1)
+ {
+ value = (int)(edgePos*(((float)percent)*0.01) - margin);
+ done = true;
+ return true;
+ }
+ else
+ return false;
+ }
+ case wxUnconstrained:
+ {
+ // We know the bottom edge position if we know the top edge
+ // and we know the height; OR if we know the centre edge and
+ // the height.
+ if (constraints->top.GetDone() && constraints->height.GetDone())
+ {
+ value = (constraints->top.GetValue() + constraints->height.GetValue() - margin);
+ done = true;
+ return true;
+ }
+ else if (constraints->centreY.GetDone() && constraints->height.GetDone())
+ {
+ value = (constraints->centreY.GetValue() + (constraints->height.GetValue()/2) - margin);
+ done = true;
+ return true;
+ }
+ else
+ return false;
+ }
+ case wxAsIs:
+ {
+ int x, y;
+ int w, h;
+ win->GetBestSize(&w, &h);
+ win->GetPosition(&x, &y);
+ value = h + y;
+ done = true;
+ return true;
+ }
+ default:
+ break;
+ }
+ break;
+ }
+ case wxCentreX:
+ {
+ switch (relationship)
+ {
+ case wxLeftOf:
+ {
+ // We can know this edge if: otherWin is win's parent, or
+ // otherWin has a satisfied constraint, or otherWin has no
+ // constraint.
+ int edgePos = GetEdge(otherEdge, win, otherWin);
+ if (edgePos != -1)
+ {
+ value = edgePos - margin;
+ done = true;
+ return true;
+ }
+ else
+ return false;
+ }
+ case wxRightOf:
+ {
+ int edgePos = GetEdge(otherEdge, win, otherWin);
+ if (edgePos != -1)
+ {
+ value = edgePos + margin;
+ done = true;
+ return true;
+ }
+ else
+ return false;
+ }
+ case wxPercentOf:
+ {
+ int edgePos = GetEdge(otherEdge, win, otherWin);
+ if (edgePos != -1)
+ {
+ value = (int)(edgePos*(((float)percent)*0.01) + margin);
+ done = true;
+ return true;
+ }
+ else
+ return false;
+ }
+ case wxUnconstrained:
+ {
+ // We know the centre position if we know
+ // the left-hand edge and we know the width, OR
+ // the right-hand edge and the width
+ if (constraints->left.GetDone() && constraints->width.GetDone())
+ {
+ value = (int)(constraints->left.GetValue() + (constraints->width.GetValue()/2) + margin);
+ done = true;
+ return true;
+ }
+ else if (constraints->right.GetDone() && constraints->width.GetDone())
+ {
+ value = (int)(constraints->left.GetValue() - (constraints->width.GetValue()/2) + margin);
+ done = true;
+ return true;
+ }
+ else
+ return false;
+ }
+ default:
+ break;
+ }
+ break;
+ }
+ case wxCentreY:
+ {
+ switch (relationship)
+ {
+ case wxAbove:
+ {
+ // We can know this edge if: otherWin is win's parent,
+ // or otherWin has a satisfied constraint, or otherWin
+ // has no constraint.
+ int edgePos = GetEdge(otherEdge, win, otherWin);
+ if (edgePos != -1)
+ {
+ value = edgePos - margin;
+ done = true;
+ return true;
+ }
+ else
+ return false;
+ }
+ case wxBelow:
+ {
+ int edgePos = GetEdge(otherEdge, win, otherWin);
+ if (edgePos != -1)
+ {
+ value = edgePos + margin;
+ done = true;
+ return true;
+ }
+ else
+ return false;
+ }
+ case wxPercentOf:
+ {
+ int edgePos = GetEdge(otherEdge, win, otherWin);
+ if (edgePos != -1)
+ {
+ value = (int)(edgePos*(((float)percent)*0.01) + margin);
+ done = true;
+ return true;
+ }
+ else
+ return false;
+ }
+ case wxUnconstrained:
+ {
+ // We know the centre position if we know
+ // the top edge and we know the height, OR
+ // the bottom edge and the height.
+ if (constraints->bottom.GetDone() && constraints->height.GetDone())
+ {
+ value = (int)(constraints->bottom.GetValue() - (constraints->height.GetValue()/2) + margin);
+ done = true;
+ return true;
+ }
+ else if (constraints->top.GetDone() && constraints->height.GetDone())
+ {
+ value = (int)(constraints->top.GetValue() + (constraints->height.GetValue()/2) + margin);
+ done = true;
+ return true;
+ }
+ else
+ return false;
+ }
+ default:
+ break;
+ }
+ break;
+ }
+ case wxWidth:
+ {
+ switch (relationship)
+ {
+ case wxPercentOf:
+ {
+ int edgePos = GetEdge(otherEdge, win, otherWin);
+ if (edgePos != -1)
+ {
+ value = (int)(edgePos*(((float)percent)*0.01));
+ done = true;
+ return true;
+ }
+ else
+ return false;
+ }
+ case wxAsIs:
+ {
+ if (win)
+ {
+ int h;
+ win->GetBestSize(&value, &h);
+ done = true;
+ return true;
+ }
+ else return false;
+ }
+ case wxUnconstrained:
+ {
+ // We know the width if we know the left edge and the right edge, OR
+ // if we know the left edge and the centre, OR
+ // if we know the right edge and the centre
+ if (constraints->left.GetDone() && constraints->right.GetDone())
+ {
+ value = constraints->right.GetValue() - constraints->left.GetValue();
+ done = true;
+ return true;
+ }
+ else if (constraints->centreX.GetDone() && constraints->left.GetDone())
+ {
+ value = (int)(2*(constraints->centreX.GetValue() - constraints->left.GetValue()));
+ done = true;
+ return true;
+ }
+ else if (constraints->centreX.GetDone() && constraints->right.GetDone())
+ {
+ value = (int)(2*(constraints->right.GetValue() - constraints->centreX.GetValue()));
+ done = true;
+ return true;
+ }
+ else
+ return false;
+ }
+ default:
+ break;
+ }
+ break;
+ }
+ case wxHeight:
+ {
+ switch (relationship)
+ {
+ case wxPercentOf:
+ {
+ int edgePos = GetEdge(otherEdge, win, otherWin);
+ if (edgePos != -1)
+ {
+ value = (int)(edgePos*(((float)percent)*0.01));
+ done = true;
+ return true;
+ }
+ else
+ return false;
+ }
+ case wxAsIs:
+ {
+ if (win)
+ {
+ int w;
+ win->GetBestSize(&w, &value);
+ done = true;
+ return true;
+ }
+ else return false;
+ }
+ case wxUnconstrained:
+ {
+ // We know the height if we know the top edge and the bottom edge, OR
+ // if we know the top edge and the centre, OR
+ // if we know the bottom edge and the centre
+ if (constraints->top.GetDone() && constraints->bottom.GetDone())
+ {
+ value = constraints->bottom.GetValue() - constraints->top.GetValue();
+ done = true;
+ return true;
+ }
+ else if (constraints->top.GetDone() && constraints->centreY.GetDone())
+ {
+ value = (int)(2*(constraints->centreY.GetValue() - constraints->top.GetValue()));
+ done = true;
+ return true;
+ }
+ else if (constraints->bottom.GetDone() && constraints->centreY.GetDone())
+ {
+ value = (int)(2*(constraints->bottom.GetValue() - constraints->centreY.GetValue()));
+ done = true;
+ return true;
+ }
+ else
+ return false;
+ }
+ default:
+ break;
+ }
+ break;