15#if defined(__BORLANDC__)
31 TDeferWinPos(
int numWindows);
33 bool DeferWindowPos(HWND hwnd, HWND after,
int x,
int y,
int cx,
int cy,
35 bool EndDeferWindowPos();
45TDeferWinPos::TDeferWinPos(
int numWindows)
47 Hdwp = numWindows ? ::BeginDeferWindowPos(numWindows) : 0;
54TDeferWinPos::DeferWindowPos(HWND hwnd, HWND after,
int x,
int y,
55 int cx,
int cy,
uint flags)
58 TRACEX(OwlLayout, 0,
_T(
"DeferWindowPos(x => ") << x <<
_T(
", y => ") << y <<
_T(
", cx => ") << cx <<
_T(
", cy => ") << cy);
59 Hdwp = ::DeferWindowPos(Hdwp, hwnd, after, x, y, cx, cy, flags);
68TDeferWinPos::EndDeferWindowPos()
71 if (::EndDeferWindowPos(Hdwp)) {
81TDeferWinPos::~TDeferWinPos()
109 TVariable* Inputs[3];
111 TFixedPoint OrderedCombination[4];
118 int NumActualInputs();
122 return os << static_cast<int>(
const_cast<TFixedPoint&
>(p));
125 return os << _T('(') << static_cast<void*>(c.
RelWin) << dec
130 return os <<
_T(
'(') << m.
X <<
_T(
',') << m.
Y <<
_T(
'x') << m.
Width <<
134 return os << _T('(') << static_cast<const void*>(c.Inputs)
135 <<
_T(
',') <<
static_cast<void*
>(c.Output) <<
_T(
',') << c.OrderedCombination[0]
136 <<
_T(
',') << c.OrderedCombination[1] <<
_T(
',') << c.OrderedCombination[2]
137 << c.OrderedCombination[3] <<
_T(
',') <<
static_cast<void*
>(c.Next) <<
_T(
')');
142 TConstraint* DeterminedBy;
145 TVariable() {Value = 0; DeterminedBy =
nullptr; Resolved =
false;}
148 return os <<
_T(
'(') << v.Value <<
_T(
',') <<
static_cast<void*
>(v.DeterminedBy)
149 <<
_T(
"->") << (v.Resolved?
_T(
"Resolved"):
_T(
"No Resolved")) <<
_T(
')');
157struct TChildMetrics {
159 bool GeneratedConstraints;
161 TLayoutMetrics Metrics;
162 TVariable Variables[4];
165 TChildMetrics(TWindow& child,
const TLayoutMetrics& metrics);
168 return os <<
_T(
'(') << (m.GeneratedConstraints ?
_T(
"true") :
_T(
"false"))
169 <<
_T(
',') <<
static_cast<void*
>(m.Child) <<
_T(
',') <<
170 m.Metrics <<
_T(
',') << m.Variables[0] <<
_T(
',') << m.Variables[1] <<
_T(
',')
171 << m.Variables[2] <<
_T(
',') << m.Variables[3] <<
_T(
',') <<
static_cast<void*
>(m.Next)
265 :
TWindow(parent, title, module)
267 Init(parent, title, module);
274 :
TWindow(parent, title, module)
276 Init(parent, title.c_str(), module);
286 ChildMetrics =
nullptr;
287 Constraints =
nullptr;
290 ClientSize.cx = ClientSize.cy = 0;
297 Variables =
new TVariable[4];
298 Variables[0].Resolved =
true;
299 Variables[1].Resolved =
true;
300 Variables[2].Resolved =
true;
301 Variables[3].Resolved =
true;
313 for (TChildMetrics* childMetrics = ChildMetrics; childMetrics;) {
314 TChildMetrics* tmp = childMetrics;
315 childMetrics = childMetrics->Next;
319 ChildMetrics =
nullptr;
325 for (TConstraint* c = Constraints; c;) {
326 TConstraint* tmp = c;
331 Constraints =
nullptr;
334static bool hasBorder(
TWindow* win)
354 TChildMetrics* childMetrics;
360 Variables[2].Value = ClientSize.cx - 1;
361 Variables[3].Value = ClientSize.cy - 1;
362 TRACEX(OwlLayout, 0,
_T(
"Layout() ClientSize: ") << ClientSize);
364 if (hasBorder(
this)) {
368 Variables[0].Value = -cxBorder;
369 Variables[1].Value = -cyBorder;
370 Variables[2].Value += cxBorder;
371 Variables[3].Value += cyBorder;
374 Variables[0].Value = 0;
375 Variables[1].Value = 0;
377 TRACEX(OwlLayout, 1,
_T(
"Layout() Variables: 0=>") << Variables[0] <<
_T(
", 1=>") << Variables[1]<<
_T(
", 2=>") << Variables[2]<<
_T(
", 3=>") << Variables[3]);
384 for (childMetrics = ChildMetrics; childMetrics;
385 childMetrics = childMetrics->Next)
386 BuildConstraints(*childMetrics);
394#if !defined(OWL_NO_DEFERWINDOWPOS_LAYOUT)
399 for (childMetrics = ChildMetrics; childMetrics; childMetrics = childMetrics->Next) {
400 TWindow* win = childMetrics->Child;
407 TDeferWinPos dwp(numWindows);
413 for (childMetrics = ChildMetrics; childMetrics; childMetrics = childMetrics->Next) {
414 TWindow* win = childMetrics->Child;
415 TVariable* variables = childMetrics->Variables;
416 TRACEX(OwlLayout, 0,
_T(
"Layout() variables: ") << variables[0] <<
_T(
',') <<
417 variables[1] <<
_T(
',') << variables[2] <<
_T(
',') << variables[3]);
421#if defined(OWL_NO_DEFERWINDOWPOS_LAYOUT)
426 variables[2].Value - variables[0].Value + 1,
427 variables[3].Value - variables[1].Value + 1,
428 SWP_NOACTIVATE | SWP_NOZORDER
431 dwp.DeferWindowPos(*win, 0,
434 variables[2].Value - variables[0].Value + 1,
435 variables[3].Value - variables[1].Value + 1,
436 SWP_NOACTIVATE | SWP_NOZORDER);
442 win->
GetWindowAttr().
W = variables[2].Value - variables[0].Value + 1;
443 win->
GetWindowAttr().
H = variables[3].Value - variables[1].Value + 1;
476 for (TChildMetrics* childMetrics = ChildMetrics; childMetrics;
477 childMetrics = childMetrics->Next) {
478 if (childMetrics->Child == &child) {
479 childMetrics->Child = &child;
480 childMetrics->Metrics = metrics;
484 RemoveConstraints(*childMetrics);
490 TChildMetrics* childMetrics =
new TChildMetrics(child, metrics);
491 childMetrics->Next = ChildMetrics;
492 ChildMetrics = childMetrics;
504 TChildMetrics* childMetrics = GetChildMetrics(child);
506 metrics = childMetrics->Metrics;
520 if (!r)
throw TXOwl{
_T(
"TLayoutWindow::GetChildLayoutMetrics failed")};
533 for (TChildMetrics** childMetrics = &ChildMetrics; *childMetrics;
534 childMetrics = &(*childMetrics)->Next) {
535 if ((*childMetrics)->Child == &child) {
539 TChildMetrics* tmp = *childMetrics;
540 *childMetrics = tmp->Next;
541 RemoveConstraints(*tmp);
551 for (TChildMetrics* cm = ChildMetrics; cm; cm = cm->Next) {
552 if (cm->Metrics.X.RelWin == &child) {
553 RemoveConstraints(*cm);
554 cm->Metrics.X.RelWin = tmp->Metrics.X.RelWin;
555 if (cm->Metrics.X.RelWin ==
lmParent)
556 cm->Metrics.X.OtherEdge = tmp->Metrics.X.OtherEdge;
558 if (cm->Metrics.Y.RelWin == &child) {
559 RemoveConstraints(*cm);
560 cm->Metrics.Y.RelWin = tmp->Metrics.Y.RelWin;
561 if (cm->Metrics.Y.RelWin ==
lmParent)
562 cm->Metrics.Y.OtherEdge = tmp->Metrics.Y.OtherEdge;
564 if (cm->Metrics.Width.RelWin == &child) {
565 RemoveConstraints(*cm);
566 if (cm->Metrics.Width.MyEdge ==
lmWidth)
567 cm->Metrics.Width.Relationship =
lmAsIs;
569 if (tmp->Metrics.Width.MyEdge ==
lmWidth) {
570 cm->Metrics.Width.RelWin = tmp->Metrics.X.RelWin;
571 if (cm->Metrics.Width.RelWin ==
lmParent)
572 cm->Metrics.Width.OtherEdge = tmp->Metrics.X.OtherEdge;
575 cm->Metrics.Width.RelWin = tmp->Metrics.Width.RelWin;
576 if (cm->Metrics.Width.RelWin ==
lmParent)
577 cm->Metrics.Width.OtherEdge = tmp->Metrics.Width.OtherEdge;
581 if (cm->Metrics.Height.RelWin == &child) {
582 RemoveConstraints(*cm);
583 if (cm->Metrics.Height.MyEdge ==
lmHeight)
584 cm->Metrics.Height.Relationship =
lmAsIs;
586 if (tmp->Metrics.Height.MyEdge ==
lmHeight) {
587 cm->Metrics.Height.RelWin = tmp->Metrics.Y.RelWin;
588 if (cm->Metrics.Height.RelWin ==
lmParent)
589 cm->Metrics.Height.OtherEdge = tmp->Metrics.Y.OtherEdge;
592 cm->Metrics.Height.RelWin = tmp->Metrics.Height.RelWin;
593 if (cm->Metrics.Height.RelWin ==
lmParent)
594 cm->Metrics.Height.OtherEdge = tmp->Metrics.Height.OtherEdge;
619 if (sizeType != SIZE_MINIMIZED &&
621 size != ClientSize) {
672TLayoutWindow::GetChildMetrics(
const TWindow& child)
676 for (TChildMetrics* childMetrics = ChildMetrics; childMetrics;
677 childMetrics = childMetrics->Next)
678 if (childMetrics->Child == &child)
688TLayoutWindow::ExecutePlan()
690 for (TConstraint* c = Plan; c; c = c->Next){
691 c->Output->Value = c->Evaluate();
692 TRACEX(OwlLayout, 1,
_T(
"ExecutePlan() c->Output => ") << *c->Output);
700TLayoutWindow::ClearPlan()
711 for (c = Constraints; c->Next; c = c->Next)
725TLayoutWindow::BuildPlan()
727 TChildMetrics* childMetrics;
728 TConstraint* lastInPlan = 0;
734 for (childMetrics = ChildMetrics; childMetrics; childMetrics = childMetrics->Next) {
735 TVariable* variable = childMetrics->Variables;
736 variable->Resolved = variable->DeterminedBy ? false :
true;
738 variable->Resolved = variable->DeterminedBy ? false :
true;
740 variable->Resolved = variable->DeterminedBy ? false :
true;
742 variable->Resolved = variable->DeterminedBy ? false :
true;
743 TRACEX(OwlLayout, 1,
_T(
"BuildPlan() variables: ") << childMetrics->Variables[0]
744 <<
_T(
',') << childMetrics->Variables[1] <<
_T(
',') << childMetrics->Variables[2]
745 <<
_T(
',') << childMetrics->Variables[3]);
757 for (
bool foundOne =
true; foundOne;) {
758 TConstraint* c = Constraints;
759 TConstraint* previous = 0;
764 TRACEX(OwlLayout, 1,
_T(
"BuildPlan() *c ") << *c);
765 if (c->IsResolved()) {
766 TConstraint* resolved = c;
768 c->Output->Resolved =
true;
774 previous->Next = c->Next;
777 Constraints = c->Next;
784 lastInPlan->Next = resolved;
789 lastInPlan = resolved;
808findInput(TConstraint* simplify, TVariable* input)
810 for (
int i = 0; i < 3; i++)
811 if (simplify->Inputs[i] == input)
830Simplify(TConstraint* simplify, TVariable* output, TConstraint* _using)
835 int outputOfSimplify = findInput(_using, simplify->Output);
836 int target = findInput(simplify, output);
838 if (outputOfSimplify != -1 && target != -1) {
840 int numInputsOfUsing = _using->NumActualInputs();
845 for (i = 0; i < numInputsOfUsing; i++)
846 commonInputs[i] = findInput(simplify, _using->Inputs[i]);
853 int numInputsOfSimplify = simplify->NumActualInputs() - 1;
858 for (i = 0; i < numInputsOfUsing; i++)
859 if (commonInputs[i] == -1 && i != outputOfSimplify)
862 if (numInputsOfSimplify + newInputs > 3)
865 TFixedPoint m = simplify->OrderedCombination[target];
869 simplify->OrderedCombination[3] += m * _using->OrderedCombination[3];
873 for (i = 0; i < numInputsOfUsing; i++)
874 if (commonInputs[i] != -1)
875 simplify->OrderedCombination[commonInputs[i]] +=
876 m * _using->OrderedCombination[i];
878 simplify->Inputs[target] =
nullptr;
879 TRACEX(OwlLayout, 1,
_T(
"Simplify() simplify->Inputs[") << target <<
_T(
"]=> 0"));
884 for (i = target + 1; i < 3; i++)
885 if (simplify->Inputs[i]) {
886 simplify->Inputs[i - 1] = simplify->Inputs[i];
887 simplify->Inputs[i] =
nullptr;
888 TRACEX(OwlLayout, 1,
_T(
"Simplify() simplify->Inputs[") << i <<
_T(
" - 1]=> ") <<
889 *simplify->Inputs[i - 1] <<
_T(
", simplify->Inputs[") << i <<
_T(
"]=> 0"));
890 simplify->OrderedCombination[i - 1] = simplify->OrderedCombination[i];
895 for (i = 0; i < numInputsOfUsing; i++)
896 if (commonInputs[i] == -1 && i != outputOfSimplify) {
897 simplify->Inputs[numInputsOfSimplify] = _using->Inputs[i];
898 TRACEX(OwlLayout, 1,
_T(
"Simplify() simplify->Inputs[") << numInputsOfSimplify
899 <<
_T(
"]=> ") << *simplify->Inputs[numInputsOfSimplify]);
900 simplify->OrderedCombination[numInputsOfSimplify] =
901 m * _using->OrderedCombination[i];
902 numInputsOfSimplify++;
909 simplify->OrderedCombination[3] /= f;
910 for (i = 0; i < numInputsOfSimplify; i++)
911 simplify->OrderedCombination[i] /= f;
919TLayoutWindow::AddConstraint(TChildMetrics& metrics,
921 TWhichConstraint whichConstraint)
925 TConstraint* result =
new TConstraint;
929 if (whichConstraint == XConstraint && metrics.Metrics.X.MyEdge ==
lmRight){
930 output = &metrics.Variables[2];
931 TRACEX(OwlLayout, 1,
_T(
"AddConstraint() output =>") << *output);
934 else if (whichConstraint == YConstraint && metrics.Metrics.Y.MyEdge ==
lmBottom){
935 output = &metrics.Variables[3];
936 TRACEX(OwlLayout, 1,
_T(
"AddConstraint() output =>") << *output);
940 output = &metrics.Variables[whichConstraint];
941 TRACEX(OwlLayout, 1,
_T(
"AddConstraint() output =>") << *output);
946 if ((
static_cast<int>(c->Relationship) !=
lmAbsolute) && (
static_cast<int>(c->Relationship) !=
lmAsIs)) {
947 TVariable* variables;
950 variables = Variables;
951 TRACEX(OwlLayout, 1,
_T(
"AddConstraint() variables =>") << *variables);
955 TChildMetrics* relWinMetrics = GetChildMetrics(*c->RelWin);
956 if (!relWinMetrics) {
960 variables = relWinMetrics->Variables;
961 TRACEX(OwlLayout, 1,
_T(
"AddConstraint() variables =>") << *variables);
964 switch (c->OtherEdge) {
969 result->Inputs[0] = &variables[c->OtherEdge];
970 TRACEX(OwlLayout, 1,
_T(
"AddConstraint() result->Inputs[0]=> ") <<
980 result->Inputs[1] = &variables[c->OtherEdge -
lmWidth+
lmLeft];
981 TRACEX(OwlLayout, 1,
_T(
"AddConstraint() result->Inputs[0]=> ") <<
982 *result->Inputs[0] <<
_T(
", result->Inputs[1]=> ") << *result->Inputs[1]);
983 result->OrderedCombination[1] = -1;
984 result->OrderedCombination[3] = 1;
988 switch (whichConstraint) {
990 case WidthConstraint:
993 result->Inputs[0] = &variables[0];
994 result->Inputs[1] = &variables[2];
995 TRACEX(OwlLayout, 1,
_T(
"AddConstraint() result->Inputs[0]=> ") <<
996 *result->Inputs[0] <<
_T(
", result->Inputs[1]=> ") << *result->Inputs[1]);
1000 case HeightConstraint:
1003 result->Inputs[0] = &variables[1];
1004 result->Inputs[1] = &variables[3];
1005 TRACEX(OwlLayout, 1,
_T(
"AddConstraint() result->Inputs[0]=> ") <<
1006 *result->Inputs[0] <<
_T(
", result->Inputs[1]=> ") << *result->Inputs[1]);
1009 result->OrderedCombination[0] = result->OrderedCombination[1] =
TFixedPoint(1,2);
1021 switch (c->Relationship) {
1023 result->OrderedCombination[3] += whichConstraint == WidthConstraint ?
1024 metrics.Child->GetWindowAttr().W :
1025 metrics.Child->GetWindowAttr().H;
1032 int value = c->Units ==
lmPixels ? c->Value : LayoutUnitsToPixels(c->Value);
1034 if (c->Relationship ==
lmAbove)
1037 else if (c->Relationship ==
lmBelow)
1040 result->OrderedCombination[3] += value;
1045 TFixedPoint percent = c->Percent;
1048 result->OrderedCombination[0] *= percent;
1049 result->OrderedCombination[3] *= percent;
1051 switch (c->OtherEdge) {
1055 result->OrderedCombination[1] *= percent;
1065 if (result->Inputs[0])
1066 index = result->Inputs[1] ? 2 : 1;
1071 switch (c->MyEdge) {
1073 if (whichConstraint == XConstraint || metrics.Metrics.X.MyEdge ==
lmRight) {
1076 for (
int i = 0; i < index; i++)
1077 result->OrderedCombination[i] = -result->OrderedCombination[i];
1079 result->OrderedCombination[3] = -result->OrderedCombination[3];
1080 (result->OrderedCombination[3])++;
1081 result->Inputs[index] = &(metrics.Variables[2]);
1082 TRACEX(OwlLayout, 1,
_T(
"AddConstraint() result->Inputs[") <<
1083 index <<
_T(
"]=> ") << *result->Inputs[index]);
1085 if (whichConstraint == WidthConstraint){
1086 output = &(metrics.Variables[XConstraint]);
1087 TRACEX(OwlLayout, 1,
_T(
"AddConstraint() output=> ") << *output);
1093 result->Inputs[index] = &(metrics.Variables[0]);
1094 TRACEX(OwlLayout, 1,
_T(
"AddConstraint() result->Inputs[") <<
1095 index <<
_T(
"]=> ") << *result->Inputs[index]);
1096 (result->OrderedCombination[3])--;
1098 Simplify(metrics.Variables[0].DeterminedBy, output, result);
1103 if (whichConstraint == YConstraint || metrics.Metrics.Y.MyEdge ==
lmBottom) {
1106 for (
int i = 0; i < index; i++)
1107 result->OrderedCombination[i] = -(result->OrderedCombination[i]);
1109 result->OrderedCombination[3] = -(result->OrderedCombination[3]);
1110 (result->OrderedCombination[3])++;
1111 result->Inputs[index] = &(metrics.Variables[3]);
1112 TRACEX(OwlLayout, 1,
_T(
"AddConstraint() result->Inputs[") <<
1113 index <<
_T(
"]=> ") << *result->Inputs[index]);
1115 if (whichConstraint == HeightConstraint){
1116 output = &metrics.Variables[YConstraint];
1117 TRACEX(OwlLayout, 1,
_T(
"AddConstraint() lmHeight: output =>") << *output);
1123 result->Inputs[index] = &metrics.Variables[1];
1124 TRACEX(OwlLayout, 1,
_T(
"AddConstraint() result->Inputs[") <<
1125 index <<
_T(
"]=> ") << *result->Inputs[index]);
1126 result->OrderedCombination[3]--;
1127 TRACEX(OwlLayout, 1,
_T(
"AddConstraint() lmHeight: result->Inputs[") <<
1128 index <<
_T(
"] =>") << *result->Inputs[index]);
1130 Simplify(metrics.Variables[1].DeterminedBy, output, result);
1135 TVariable* input = &metrics.Variables[0];
1137 switch (whichConstraint) {
1142 TRACEX(OwlLayout, 1,
_T(
"AddConstraint() XConstraint: input =>") << *input);
1149 TRACEX(OwlLayout, 1,
_T(
"AddConstraint() YConstraint: input =>") << *input);
1152 case WidthConstraint:
1157 if (metrics.Metrics.X.MyEdge ==
lmRight) {
1159 output = &metrics.Variables[XConstraint];
1160 TRACEX(OwlLayout, 1,
_T(
"AddConstraint() WidthConstraint: input =>") <<
1161 *input <<
_T(
",output => ") << *output);
1165 case HeightConstraint:
1170 if (metrics.Metrics.Y.MyEdge !=
lmBottom)
1175 output = &metrics.Variables[XConstraint];
1177 TRACEX(OwlLayout, 1,
_T(
"AddConstraint() HeightConstraint: input =>") <<
1178 *input <<
_T(
",output => ") << *output);
1181 result->Inputs[index] = input;
1182 TRACEX(OwlLayout, 1,
_T(
"AddConstraint() result->Inputs[") << index <<
1183 _T(
"]=> ") << *result->Inputs[index]);
1184 for (
int i = 0; i < index; i++)
1185 result->OrderedCombination[i] <<= 1;
1187 result->OrderedCombination[3] <<= 1;
1188 result->OrderedCombination[index] = -1;
1194 output->DeterminedBy = result;
1195 result->Output = output;
1199 result->Next = Constraints;
1200 Constraints = result;
1207TLayoutWindow::RemoveConstraints(TChildMetrics& childMetrics)
1209 TVariable* variable = childMetrics.Variables;
1213 childMetrics.GeneratedConstraints =
false;
1215 for (
int i = 0; i < 4; i++) {
1216 TConstraint* constraint = variable->DeterminedBy;
1218 variable->Value = 0;
1224 if (Constraints == constraint)
1225 Constraints = constraint->Next;
1228 for (TConstraint* c = Constraints; c->Next; c = c->Next)
1229 if (c->Next == constraint) {
1230 c->Next = constraint->Next;
1235 variable->DeterminedBy =
nullptr;
1246TLayoutWindow::BuildConstraints(TChildMetrics& childMetrics)
1252 if (!childMetrics.GeneratedConstraints) {
1253 TLayoutConstraint* c = &childMetrics.Metrics.X;
1254 TRACEX(OwlLayout, 1,
_T(
"BuildConstraints() childMetrics.Metrics.X =>") << *c);
1256 childMetrics.GeneratedConstraints =
true;
1260 if (c->Relationship ==
lmAsIs){
1261 if (c->MyEdge ==
lmLeft){
1262 childMetrics.Variables[0].Value = childMetrics.Child->GetWindowAttr().X;
1263 TRACEX(OwlLayout, 1,
_T(
"BuildConstraints() childMetrics.Variables[0] =>") <<
1264 childMetrics.Variables[0]);
1267 childMetrics.Variables[2].Value = childMetrics.Child->GetWindowAttr().X +
1268 childMetrics.Child->GetWindowAttr().W - 1;
1269 TRACEX(OwlLayout, 1,
_T(
"BuildConstraints() childMetrics.Variables[2] =>") <<
1270 childMetrics.Variables[2]);
1274 int value = c->Units ==
lmPixels ? c->Value : LayoutUnitsToPixels(c->Value);
1276 childMetrics.Variables[c->MyEdge ==
lmLeft ? 0 : 2].Value = value;
1277 TRACEX(OwlLayout, 1,
_T(
"BuildConstraints() childMetrics.Variables[") <<
1278 (c->MyEdge ==
lmLeft ? 0 : 2)<<
_T(
"] =>") << childMetrics.Variables[c->MyEdge ==
lmLeft ? 0 : 2]);
1281 AddConstraint(childMetrics, c, XConstraint);
1282 TRACEX(OwlLayout, 1,
_T(
"BuildConstraints() after Add constraints childMetrics.Metrics.X =>") << *c);
1287 c = &childMetrics.Metrics.Y;
1288 TRACEX(OwlLayout, 1,
_T(
"BuildConstraints() childMetrics.Metrics.Y =>") << *c);
1290 if (c->Relationship ==
lmAsIs){
1291 if (c->MyEdge ==
lmTop){
1292 childMetrics.Variables[1].Value = childMetrics.Child->GetWindowAttr().Y;
1293 TRACEX(OwlLayout, 1,
_T(
"BuildConstraints() childMetrics.Variables[1] =>") <<
1294 childMetrics.Variables[1]);
1297 childMetrics.Variables[3].Value = childMetrics.Child->GetWindowAttr().Y +
1298 childMetrics.Child->GetWindowAttr().H - 1;
1299 TRACEX(OwlLayout, 1,
_T(
"BuildConstraints() childMetrics.Variables[3] =>") <<
1300 childMetrics.Variables[3]);
1304 int value = c->Units ==
lmPixels ? c->Value : LayoutUnitsToPixels(c->Value);
1306 childMetrics.Variables[c->MyEdge ==
lmTop ? 1 : 3].Value = value;
1307 TRACEX(OwlLayout, 1,
_T(
"BuildConstraints() childMetrics.Variables[") <<
1308 (c->MyEdge ==
lmTop ? 1 : 3) <<
_T(
"] =>") <<
1309 childMetrics.Variables[c->MyEdge ==
lmTop ? 1 : 3]);
1312 AddConstraint(childMetrics, c, YConstraint);
1313 TRACEX(OwlLayout, 1,
_T(
"BuildConstraints() after AddConstraint childMetrics.Metrics.Y =>") << *c);
1318 c = &childMetrics.Metrics.Width;
1319 TRACEX(OwlLayout, 1,
_T(
"BuildConstraints() childMetrics.Metrics.Width =>") << *c);
1322 childMetrics.Variables[2].Value = c->Relationship ==
lmAsIs ?
1323 childMetrics.Child->GetWindowAttr().X +
1324 childMetrics.Child->GetWindowAttr().W - 1 :
1325 c->Units ==
lmPixels ? c->Value : LayoutUnitsToPixels(c->Value);
1326 TRACEX(OwlLayout, 1,
_T(
"BuildConstraints() childMetrics.Variables[2] =>") <<
1327 childMetrics.Variables[2]);
1330 AddConstraint(childMetrics, c, WidthConstraint);
1331 TRACEX(OwlLayout, 1,
_T(
"BuildConstraints() after AddConstraint childMetrics.Metrics.Width =>") << *c);
1336 c = &childMetrics.Metrics.Height;
1337 TRACEX(OwlLayout, 1,
_T(
"BuildConstraints() childMetrics.Metrics.Height =>") << *c);
1340 childMetrics.Variables[3].Value = c->Relationship ==
lmAsIs ?
1341 childMetrics.Child->GetWindowAttr().Y +
1342 childMetrics.Child->GetWindowAttr().H - 1 :
1343 c->Units ==
lmPixels ? c->Value : LayoutUnitsToPixels(c->Value);
1344 TRACEX(OwlLayout, 1,
_T(
"BuildConstraints() childMetrics.Variables[3] =>") << childMetrics.Variables[3]);
1347 AddConstraint(childMetrics, c, HeightConstraint);
1348 TRACEX(OwlLayout, 1,
_T(
"BuildConstraints() after AddConstraint childMetrics.Metrics.Height =>") << *c);
1357TLayoutWindow::LayoutUnitsToPixels(
int value)
1359 const long UnitsPerEM = 8;
1361 return int((
long(value) * FontHeight + UnitsPerEM / 2) / UnitsPerEM);
1368TLayoutWindow::GetFontHeight()
1379 hFont = HFONT(GetStockObject(SYSTEM_FONT));
1383 FontHeight = font.GetHeight();
1389#if OWL_PERSISTENT_STREAMS
1404TLayoutWindow::Streamer::Write(opstream&)
const
1415TChildMetrics::TChildMetrics(
TWindow& child,
1421 GeneratedConstraints =
false;
1428TConstraint::TConstraint()
1430 Inputs[0] = Inputs[1] = Inputs[2] =
nullptr;
1431 OrderedCombination[0] = OrderedCombination[1] = OrderedCombination[2] = 1;
1442TConstraint::IsResolved()
1444 return (!Inputs[0] || Inputs[0]->Resolved) &&
1445 (!Inputs[1] || Inputs[1]->Resolved) &&
1446 (!Inputs[2] || Inputs[2]->Resolved);
1453TConstraint::Evaluate()
1455 TFixedPoint value = OrderedCombination[3];
1456 TRACEX(OwlLayout, 1,
_T(
"Evaluate() value ") << value);
1459 value += OrderedCombination[0] * Inputs[0]->Value;
1460 TRACEX(OwlLayout, 1,
_T(
"Evaluate() value ") << value <<
1461 _T(
", OrderedCombination[0] => ") << OrderedCombination[0] <<
1462 _T(
", Inputs[0]->Value => ") << Inputs[0]->Value);
1466 value += OrderedCombination[1] * Inputs[1]->Value;
1467 TRACEX(OwlLayout, 1,
_T(
"Evaluate() value ") << value <<
1468 _T(
", OrderedCombination[1] => ") << OrderedCombination[1] <<
1469 _T(
", Inputs[1]->Value => ") << Inputs[1]->Value);
1473 value += OrderedCombination[2] * Inputs[2]->Value;
1474 TRACEX(OwlLayout, 1,
_T(
"Evaluate() value ") << value <<
1475 _T(
", OrderedCombination[2] => ") << OrderedCombination[1] <<
1476 _T(
", Inputs[2]->Value => ") << Inputs[2]->Value);
1485TConstraint::NumActualInputs()
1488 for (i = 0; i < 3; i++)
1600 Y.MyEdge =
Y.OtherEdge =
lmTop;
1605 Width.RelWin =
nullptr;
#define PRECONDITION(condition)
#define TRACEX(group, level, message)
When specifying the layout metrics for a window, four layout constraints are needed.
TEdgeConstraint Y
Y contains the Y (top, center, bottom) edge constraint of the window.
TEdgeOrWidthConstraint Width
Contains the width size constraint, center edge constraint, or right edge (lmRight) constraint of the...
TEdgeOrHeightConstraint Height
Contains the height size constraint, center edge constraint, or bottom edge constraint of the window.
void SetMeasurementUnits(TMeasurementUnits units)
TEdgeConstraint X
X contains the X (left, center, right) edge constraint of the window.
TLayoutMetrics()
Defaults each co: RelWin=0, MyEdge=(1st from above), Relationship=AsIs.
Derived from TWindow, TLayoutWindow provides functionality for defining the layout metrics for a wind...
void EvSetFont(HFONT, bool redraw)
Updates the window layout, if "redraw" is true.
TLayoutWindow(TWindow *parent, LPCTSTR title=0, TModule *module=0)
Creates a TLayoutWindow object with specified parent, window caption, and library ID.
void EvSize(uint sizeType, const TSize &size)
Responds to a change in size by calling Layout() to resize the window.
virtual void Layout()
Causes the window to resize and position its children according to the specified metrics.
bool GetChildLayoutMetrics(const TWindow &child, TLayoutMetrics &metrics)
Gets the layout metrics of the child window.
void SetChildLayoutMetrics(TWindow &child, const TLayoutMetrics &metrics)
Sets the metrics for the window and removes any existing ones.
void RemoveChild(TWindow *) override
Overrides TWindow virtual to allow cleanup of child metrics.
bool RemoveChildLayoutMetrics(const TWindow &child)
Removes child (layout) metrics for a given child (if found) and updates other children as necessary.
~TLayoutWindow() override
Deletes variables and frees the child metrics and constraints.
void Init(TWindow *parent, LPCTSTR title, TModule *module)
ObjectWindows dynamic-link libraries (DLLs) construct an instance of TModule, which acts as an object...
The tagSIZE struct is defined as.
static const TUIMetric CyBorder
static const TUIMetric CxBorder
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
TWindow(TWindow *parent, LPCTSTR title=nullptr, TModule *module=nullptr)
Adds this to the child list of parent if nonzero, and calls EnableAutoCreate so that this will be cre...
bool SetWindowPos(HWND hWndInsertAfter, const TRect &rect, uint flags)
Changes the size of the window pointed to by rect.
virtual void RemoveChild(TWindow *child)
Removes a child window.
void Init(TWindow *parent, LPCTSTR title, TModule *module)
Normal initialization of a default constructed TWindow.
TWindowAttr & GetWindowAttr()
Returns the TWindowAttr structure, which contains the window's creation attributes.
TResult HandleMessage(TMsgId, TParam1=0, TParam2=0)
Dispatches the given message using the response table.
void EvSize(uint sizeType, const TSize &size)
Response method for an incoming WM_SIZE message.
HFONT EvGetFont()
The default message handler for WM_GETFONT.
void EvSetFont(HFONT hFont, bool redraw)
The default message handler for WM_SETFONT.
HWND GetHandle() const
Returns the handle of the window.
TXOwl is root class of the ObjectWindows exception hierarchy.
static void Raise(TWindow *win=nullptr, uint resourceId=IDS_INVALIDWINDOW)
Creates the TXWindow exception and throws it.
ipstream, a specialized input stream derivative of pstream, is the base class for reading (extracting...
#define DEFINE_RESPONSE_TABLE1(cls, base)
Macro to define a response table for a class with one base.
Simple fixed point class that maintains numbers as 16.16 Fixed by Bidus Yura to work with Micro$oft V...
TMeasurementUnits
Used by the TLayoutConstraint struct, TMeasurementUnits enumerates the measurement units (lmPixels or...
#define lmParent
Use to represent the parent in layout metrics.
@ lmTop
The top edge of the window.
@ lmBottom
The bottom edge of the window.
@ lmCenter
The center of the window.
@ lmRight
The right edge of the window.
@ lmLeft
The left edge of the window.
Definition of classes TLayoutMetrics & TLayoutWindow.
Object Windows Library (OWLNext Core).
owl::opstream & operator<<(owl::opstream &os, const TColor &c)
Insert the color value into a persistent output stream.
DIAG_DEFINE_GROUP_INIT(OWL_INI, OwlApp, 1, 0)
IMPLEMENT_STREAMABLE1(TApplication, TModule)
General definitions used by all ObjectWindows programs.
ObjectWindows exception class & function definitions.
TLayoutConstraint is a structure that defines a relationship (a layout constraint) between an edge or...
TWindow * RelWin
RelWin is a pointer to the sibling windows or lmParent if the child is a proportion of the parent's d...
uint MyEdge
MyEdge contains the name of the edge or size constraint (lmTop, lmBottom, lmLeft, lmRight,...
TRelationship Relationship
Relationship specifies the type of relationship that exists between the two windows (that is,...
TMeasurementUnits Units
Units enumerates the units of measurement (either pixels or layout units) used to measure the height ...
uint OtherEdge
OtherEdge contains the name of the edge or size constraint (lmTop, lmBottom, lmLeft,...
int X
horizontal position of top left corenr of the window
int H
height of the window
int Y
vertical position of top left corenr of the window
uint32 Style
Contains the values that define the style, shape, and size of your window.
Definition of TUIMetric, a UI metrics provider class.