Unit LOPanel

*****************************************************} { } { Delphi Visual Component Library } { } { Copyright (c) 1996 Anna B. Sotnichenko } { } { TLayoutPanel - panel that can } { layout its children } { } {

Classes

TChildMetrics - TConstraint} the layout metrics represent four equations.
TConstraint - constraints can have up to three input variables the method for solving the constraint is represented as an ordered linear combination of the inputs and the constant with the constant expressed last
TLayoutPanel -

Functions

AboveConstraint - RightOfConstraint} {--------------------------------------- AboveConstraint
AbsoluteConstraint - PercentOfConstraint} {--------------------------------------- AbsoluteConstraint } { setting an edge to a fixed value
AssignConstraint - SetConstraint} {--------------------------------------- AssignConstraint } { Assign one constraint to anoter one
AssignLayoutMetrics - WriteConstraint } {--------------------------------------- AssignLayoutMetrics } { Assign values to the fields of TLayoutMetrics
BelowConstraint - AboveConstraint} {--------------------------------------- BelowConstraint
Flush - SetMeasurementUnits} {--------------------------------------- Flush } { Destroy all items in the list if they are proved to be Objects
InitLayoutMetrics - AssignLayoutMetrics} {--------------------------------------- InitLayoutMetrics } { Initialize layout metrtics
LeftOfConstraint - SetConstraint} these four procedures can be used to position your window with respective to a sibling window.
PercentOfConstraint - SameAsConstraint} {--------------------------------------- PercentOfConstraint
ReadConstraint - AbsoluteConstraint} {--------------------------------------- ReadConstraint } { read constraint from stream
RightOfConstraint - LeftOfConstraint} {--------------------------------------- RightOfConstraint
SameAsConstraint - BelowConstraint} { these two work on the same edge, e.
SetConstraint - TLayoutPanel

Common functions } {--------------------------------------- SetConstraint } { Setting arbitrary edge constraints
SetMeasurementUnits - InitLayoutMetrics} {--------------------------------------- SetMeasurementUnits
WriteConstraint - ReadConstraint } {--------------------------------------- WriteConstraint } { write constraint from stream

Types

PLayoutConstraint
PLayoutMetrics
PVariable
TEdge
TEdgeVariables
TLayoutConstraint
TLayoutMetrics
TMeasurementUnits
TRelationship
TVariable
TWhichConstraint

Constants

Format10
lmLeftOf
lmParent
lmRightOf
ParentNum

Variables

DontCareAboutRelMetrics


Functions


procedure AboveConstraint( var constraint : TLayoutConstraint; sibling : TControl; margin : integer );

RightOfConstraint} {--------------------------------------- AboveConstraint

procedure AbsoluteConstraint( var constraint : TLayoutConstraint; edge : TEdge; val : integer );

PercentOfConstraint} {--------------------------------------- AbsoluteConstraint } { setting an edge to a fixed value

procedure AssignConstraint( var constraint : TLayoutConstraint; otherConstraint : TLayoutConstraint );

SetConstraint} {--------------------------------------- AssignConstraint } { Assign one constraint to anoter one

procedure AssignLayoutMetrics( var metrics : TLayoutMetrics; otherMetrics : TLayoutMetrics );

WriteConstraint } {--------------------------------------- AssignLayoutMetrics } { Assign values to the fields of TLayoutMetrics

procedure BelowConstraint( var constraint : TLayoutConstraint; sibling : TControl; margin : integer );

AboveConstraint} {--------------------------------------- BelowConstraint

procedure Flush( Lst : TList );

SetMeasurementUnits} {--------------------------------------- Flush } { Destroy all items in the list if they are proved to be Objects

procedure InitLayoutMetrics( var metrics : TLayoutMetrics );

AssignLayoutMetrics} {--------------------------------------- InitLayoutMetrics } { Initialize layout metrtics

procedure LeftOfConstraint( var constraint : TLayoutConstraint; sibling : TControl; margin : integer );

SetConstraint} these four procedures can be used to position your window with respective to a sibling window. you specify the sibling window and an optional margin between the two windows {--------------------------------------- LeftOfConstraint

procedure PercentOfConstraint( var constraint : TLayoutConstraint; otherWin : TControl; edge : TEdge; percent : integer );

SameAsConstraint} {--------------------------------------- PercentOfConstraint

procedure ReadConstraint( var constraint : TLayoutConstraint; Reader : TReader );

AbsoluteConstraint} {--------------------------------------- ReadConstraint } { read constraint from stream

procedure RightOfConstraint( var constraint : TLayoutConstraint; sibling : TControl; margin : integer );

LeftOfConstraint} {--------------------------------------- RightOfConstraint

procedure SameAsConstraint( var constraint : TLayoutConstraint; otherWin : TControl; edge : TEdge );

BelowConstraint} { these two work on the same edge, e.g. "SameAs(win, lmLeft)" means that your left edge should be the same as the left edge of "otherWin" } {--------------------------------------- SameAsConstraint

procedure SetConstraint( var constraint : TLayoutConstraint; edge : TEdge; rel : TRelationship; otherWin : TControl; otherEdge : TEdge; value : integer );

TLayoutPanel

Common functions } {--------------------------------------- SetConstraint } { Setting arbitrary edge constraints


procedure SetMeasurementUnits( var metrics : TLayoutMetrics; units : TMeasurementUnits );

InitLayoutMetrics} {--------------------------------------- SetMeasurementUnits

procedure WriteConstraint( var constraint : TLayoutConstraint; Writer : TWriter; Panel : TLayoutPanel);

ReadConstraint } {--------------------------------------- WriteConstraint } { write constraint from stream

Types


PLayoutConstraint = ^TLayoutConstraint

PLayoutMetrics = ^TLayoutMetrics
TVariable
PVariable = ^TVariable

TEdge = (lmLeft, lmTop, lmRight, lmBottom, lmCenter, lmWidth, lmHeight);
Relative control has no layout metrics } { Edge and size - had to merge them into one type
TEdgeVariables = array [0..3] of TVariable;

TLayoutConstraint = record
RelWin : TControl;
MyEdge : TEdge;
Units : TMeasurementUnits;
OtherEdge : TEdge;
end;
record TLayoutConstraint ------ ----------------- layout constraints are specified as a relationship between an edge/size of one window and an edge/size of one of the window's siblings or parent it is acceptable for a control to have one of its sizes depend on the size of the opposite dimension (e.g. width is twice height) distances can be specified in either pixels or layout units a layout unit is defined by dividing the font "em" quad into 8 vertical and 8 horizontal segments. we get the font by self-sending WM_GETFONT (we use the system font if WM_GETFONT returns 0) "lmAbove", "lmBelow', "lmLeftOf", and "lmRightOf" are only used with edge constraints. they place the window 1 pixel to the indicated side(i.e. adjacent to the other window) and then adjust it by "Margin"(e.g. above window "A" by 6) NOTE: "Margin" is either added to ("lmAbove" and "lmLeftOf") or subtracted from("lmBelow" and "lmRightOf") depending on the relationship "lmSameAs" can be used with either edges or sizes, and it doesn't offset by 1 pixel like the above four relationships did. it also uses "Value" (e.g. same width as window "A" plus 10) NOTE: "Value" is always *added*. use a negative number if you want the effect to be subtractive
TLayoutMetrics = record
X : TLayoutConstraint;
Y : TLayoutConstraint;
Width : TLayoutConstraint;
Height : TLayoutConstraint;
MinW : integer;
MaxW : integer;
MinH : integer;
MaxH : integer;
end;
TLayoutConstraint} { record TLayoutMetrics ----- -------------- when specifying the layout metrics for a window you specify four layout constraints
TMeasurementUnits = (lmPixels, lmLayoutUnits);
Unit identifier
TRelationship = (lmAsIs, lmPercentOf, lmAbove, lmBelow, lmSameAs, lmAbsolute);
Relationship between controls
TVariable = record
Value : integer;
DeterminedBy : TConstraint;
Resolved : Boolean;
end;
Variable represents control's Left, Top, Right or Bottom edge
TWhichConstraint = (XConstraint, YConstraint, WidthConstraint, HeightConstraint);
TChildMetrics} class TLayoutPanel ----- ------------- when specifying the layout metrics for a window, there are several options: e.g. in the horizontal direction, Two Edge Constraints in X and Width 1. left edge and right edge 2. center edge and right edge 3. left edge and center edge Edge Constraint and Size constraint in X and Width 4. left edge and size 5. right edge and size 6. center edge and size the same holds true in the vertical direction for Y and Height it is also possible to specify "lmAsIs" in which case we use the windows current value specifying "lmAbsolute" means that we will use whatever is in data member "Value" we just name the fields "X" and "Width" and "Y" and "Height", although its okay to place a right or center edge constraint in the "Width" field and its also okay to place a right edge constraint in the "X" field (i.e. option #3) however, it's NOT okay to place a width constraint in the "X" or "Height" fields or a height constraint in the "Y" or "Width" fields.

Constants

Format10 = -10

Parent's number

lmLeftOf = lmAbove

lmParent = nil

lmRightOf = lmBelow

Aliases

ParentNum = -1

Parent (myself) pointer

Variables

DontCareAboutRelMetrics : boolean

This flag works at design time only It prevents function SetChildLayoutMetrics from testing the existance and setting AsIs LayoutMetrics for relative control This flag is set in TLayoutForm.FormClose to guarantee the right order in FMetrics list (at design time FMetrics[i] must belong to Control[i])