15#if defined(__BORLANDC__)
35 bool EndDeferWindowPos();
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();
126 <<
_T(
',') <<
c.MyEdge <<
_T(
',') <<
static_cast<int>(
c.Relationship) <<
_T(
',') <<
static_cast<int>(
c.Units)
127 <<
_T(
',') <<
c.OtherEdge <<
_T(
',') <<
c.Value <<
_T(
')');
130 return os <<
_T(
'(') <<
m.X <<
_T(
',') <<
m.Y <<
_T(
'x') <<
m.Width <<
131 _T(
',') <<
m.Height <<
_T(
')');
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)
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;
319 ChildMetrics =
nullptr;
325 for (TConstraint*
c = Constraints;
c;) {
326 TConstraint*
tmp =
c;
331 Constraints =
nullptr;
334static bool hasBorder(
TWindow* win)
360 Variables[2].Value = ClientSize.cx - 1;
361 Variables[3].Value = ClientSize.cy - 1;
364 if (hasBorder(
this)) {
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]);
394#if !defined(OWL_NO_DEFERWINDOWPOS_LAYOUT)
421#if defined(OWL_NO_DEFERWINDOWPOS_LAYOUT)
431 dwp.DeferWindowPos(*win, 0,
519 auto r = GetChildLayoutMetrics(
child,
m);
520 if (!
r)
throw TXOwl{
_T(
"TLayoutWindow::GetChildLayoutMetrics failed")};
535 if ((*childMetrics)->Child == &
child) {
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;
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;
562 cm->Metrics.Y.OtherEdge =
tmp->Metrics.Y.OtherEdge;
564 if (
cm->Metrics.Width.RelWin == &
child) {
565 RemoveConstraints(*
cm);
567 cm->Metrics.Width.Relationship =
lmAsIs;
570 cm->Metrics.Width.RelWin =
tmp->Metrics.X.RelWin;
572 cm->Metrics.Width.OtherEdge =
tmp->Metrics.X.OtherEdge;
575 cm->Metrics.Width.RelWin =
tmp->Metrics.Width.RelWin;
577 cm->Metrics.Width.OtherEdge =
tmp->Metrics.Width.OtherEdge;
581 if (
cm->Metrics.Height.RelWin == &
child) {
582 RemoveConstraints(*
cm);
584 cm->Metrics.Height.Relationship =
lmAsIs;
587 cm->Metrics.Height.RelWin =
tmp->Metrics.Y.RelWin;
589 cm->Metrics.Height.OtherEdge =
tmp->Metrics.Y.OtherEdge;
592 cm->Metrics.Height.RelWin =
tmp->Metrics.Height.RelWin;
594 cm->Metrics.Height.OtherEdge =
tmp->Metrics.Height.OtherEdge;
621 size != ClientSize) {
688TLayoutWindow::ExecutePlan()
690 for (TConstraint*
c = Plan;
c;
c =
c->Next){
691 c->Output->Value =
c->Evaluate();
700TLayoutWindow::ClearPlan()
711 for (
c = Constraints;
c->Next;
c =
c->Next)
725TLayoutWindow::BuildPlan()
758 TConstraint*
c = Constraints;
765 if (
c->IsResolved()) {
768 c->Output->Resolved =
true;
777 Constraints =
c->Next;
810 for (
int i = 0;
i < 3;
i++)
889 *
simplify->Inputs[
i - 1] <<
_T(
", simplify->Inputs[") <<
i <<
_T(
"]=> 0"));
907 TFixedPoint f = 1 -
m;
909 simplify->OrderedCombination[3] /= f;
919TLayoutWindow::AddConstraint(TChildMetrics&
metrics,
920 TLayoutConstraint*
c,
925 TConstraint* result =
new TConstraint;
946 if ((
static_cast<int>(
c->Relationship) !=
lmAbsolute) && (
static_cast<int>(
c->Relationship) !=
lmAsIs)) {
964 switch (
c->OtherEdge) {
982 *result->Inputs[0] <<
_T(
", result->Inputs[1]=> ") << *result->Inputs[1]);
983 result->OrderedCombination[1] = -1;
984 result->OrderedCombination[3] = 1;
990 case WidthConstraint:
996 *result->Inputs[0] <<
_T(
", result->Inputs[1]=> ") << *result->Inputs[1]);
1000 case HeightConstraint:
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) {
1024 metrics.Child->GetWindowAttr().W :
1025 metrics.Child->GetWindowAttr().H;
1032 int value =
c->Units ==
lmPixels ?
c->Value : LayoutUnitsToPixels(
c->Value);
1037 else if (
c->Relationship ==
lmBelow)
1040 result->OrderedCombination[3] +=
value;
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) {
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]);
1083 index <<
_T(
"]=> ") << *result->Inputs[index]);
1093 result->Inputs[index] = &(
metrics.Variables[0]);
1095 index <<
_T(
"]=> ") << *result->Inputs[index]);
1096 (result->OrderedCombination[3])--;
1098 Simplify(
metrics.Variables[0].DeterminedBy,
output, result);
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]);
1113 index <<
_T(
"]=> ") << *result->Inputs[index]);
1123 result->Inputs[index] = &
metrics.Variables[1];
1125 index <<
_T(
"]=> ") << *result->Inputs[index]);
1126 result->OrderedCombination[3]--;
1128 index <<
_T(
"] =>") << *result->Inputs[index]);
1130 Simplify(
metrics.Variables[1].DeterminedBy,
output, result);
1152 case WidthConstraint:
1165 case HeightConstraint:
1181 result->Inputs[index] =
input;
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;
1199 result->Next = Constraints;
1200 Constraints = result;
1207TLayoutWindow::RemoveConstraints(TChildMetrics&
childMetrics)
1215 for (
int i = 0;
i < 4;
i++) {
1228 for (TConstraint*
c = Constraints;
c->Next;
c =
c->Next)
1246TLayoutWindow::BuildConstraints(TChildMetrics&
childMetrics)
1260 if (
c->Relationship ==
lmAsIs){
1274 int value =
c->Units ==
lmPixels ?
c->Value : LayoutUnitsToPixels(
c->Value);
1282 TRACEX(
OwlLayout, 1,
_T(
"BuildConstraints() after Add constraints childMetrics.Metrics.X =>") << *
c);
1290 if (
c->Relationship ==
lmAsIs){
1304 int value =
c->Units ==
lmPixels ?
c->Value : LayoutUnitsToPixels(
c->Value);
1308 (
c->MyEdge ==
lmTop ? 1 : 3) <<
_T(
"] =>") <<
1313 TRACEX(
OwlLayout, 1,
_T(
"BuildConstraints() after AddConstraint childMetrics.Metrics.Y =>") << *
c);
1325 c->Units ==
lmPixels ?
c->Value : LayoutUnitsToPixels(
c->Value);
1331 TRACEX(
OwlLayout, 1,
_T(
"BuildConstraints() after AddConstraint childMetrics.Metrics.Width =>") << *
c);
1343 c->Units ==
lmPixels ?
c->Value : LayoutUnitsToPixels(
c->Value);
1348 TRACEX(
OwlLayout, 1,
_T(
"BuildConstraints() after AddConstraint childMetrics.Metrics.Height =>") << *
c);
1357TLayoutWindow::LayoutUnitsToPixels(
int value)
1368TLayoutWindow::GetFontHeight()
1383 FontHeight =
font.GetHeight();
1389#if OWL_PERSISTENT_STREAMS
1404TLayoutWindow::Streamer::Write(opstream&)
const
1415TChildMetrics::TChildMetrics(TWindow&
child,
1416 const TLayoutMetrics&
metrics)
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];
1459 value += OrderedCombination[0] * Inputs[0]->Value;
1461 _T(
", OrderedCombination[0] => ") << OrderedCombination[0] <<
1462 _T(
", Inputs[0]->Value => ") << Inputs[0]->Value);
1466 value += OrderedCombination[1] * Inputs[1]->Value;
1468 _T(
", OrderedCombination[1] => ") << OrderedCombination[1] <<
1469 _T(
", Inputs[1]->Value => ") << Inputs[1]->Value);
1473 value += OrderedCombination[2] * Inputs[2]->Value;
1475 _T(
", OrderedCombination[2] => ") << OrderedCombination[1] <<
1476 _T(
", Inputs[2]->Value => ") << Inputs[2]->Value);
1485TConstraint::NumActualInputs()
1488 for (
i = 0;
i < 3;
i++)
1591TLayoutMetrics::TLayoutMetrics()
1594 X.MyEdge = X.OtherEdge =
lmLeft;
1600 Y.MyEdge = Y.OtherEdge =
lmTop;
1605 Width.RelWin =
nullptr;
1606 Width.MyEdge = Width.OtherEdge =
lmWidth;
1607 Width.Relationship =
lmAsIs;
1611 Height.RelWin =
nullptr;
1612 Height.MyEdge = Height.OtherEdge =
lmHeight;
1613 Height.Relationship =
lmAsIs;
1624 X.Units = Y.Units = Width.Units = Height.Units =
units;
#define PRECONDITION(condition)
#define TRACEX(group, level, message)
#define DIAG_DEFINE_GROUP_INIT(f, g, e, l)
When specifying the layout metrics for a window, four layout constraints are needed.
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.
auto EvGetFont() -> HFONT
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...
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.
#define IMPLEMENT_STREAMABLE1(cls, base1)
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.
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...
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.