implemented TWinControl.DoAutoSize for aligned and parent anchored child controls

git-svn-id: trunk@8178 -
This commit is contained in:
mattias 2005-11-16 18:47:41 +00:00
parent d763eedda9
commit 740bdda6ff
3 changed files with 124 additions and 66 deletions

View File

@ -1433,7 +1433,52 @@ begin
end;
end;
Procedure TWinControl.DoAutoSize;
{-------------------------------------------------------------------------------
procedure TWinControl.DoAutoSize;
Shrink or enlarge to fit childs.
-------------------------------------------------------------------------------}
procedure TWinControl.DoAutoSize;
function FindChildFixatedSides: TAnchors;
// Returns all sides, that has a child control keeping distance to.
// These sides should not be moved.
var
i: Integer;
CurControl: TControl;
a: TAnchorKind;
Side: TAnchorSide;
begin
Result:=[];
for i:=0 to ControlCount-1 do begin
CurControl:=Controls[i];
if not CurControl.IsControlVisible then continue;
for a:=Low(TAnchorKind) to High(TAnchorKind) do begin
Side:=CurControl.AnchorSide[a];
if (a in CurControl.Anchors) and (Side.Control=Self)
then begin
// CurControl is anchored to its parent = this control
if a in [akLeft,akRight] then begin
case Side.Side of
asrLeft: Include(Result,akLeft);
asrCenter: Result:=Result+[akLeft,akRight];
asrRight: Include(Result,akRight);
end;
end else begin
case Side.Side of
asrTop: Include(Result,akTop);
asrCenter: Result:=Result+[akTop,akBottom];
asrBottom: Include(Result,akBottom);
end;
end;
end;
end;
if CurControl.Align in [alLeft,alRight,alTop,alBottom,alClient] then
// CurControl is aligned to its parent = this control
Result:=Result+AnchorAlign[CurControl.Align];
end;
end;
var
I : Integer;
AControl: TControl;
@ -1448,6 +1493,7 @@ var
CurClientRect: TRect;
dx: Integer;
dy: Integer;
ChildFixedSides: TAnchors;
begin
{$IFDEF VerboseAutoSize}
debugln('TWinControl.DoAutoSize ',DbgSName(Self));
@ -1465,6 +1511,8 @@ begin
// test if resizing is possible
CurAnchors:=Anchors;
if Align<>alNone then CurAnchors:=CurAnchors+AnchorAlign[Align];
ChildFixedSides:=FindChildFixatedSides;
CurAnchors:=CurAnchors+ChildFixedSides;
WidthIsFixed:=(CurAnchors*[akLeft,akRight]=[akLeft,akRight])
or ((ChildSizing.EnlargeHorizontal<>crsAnchorAligning)
or (ChildSizing.ShrinkHorizontal<>crsAnchorAligning));
@ -1479,10 +1527,14 @@ begin
CurClientRect:=ClientRect;
AdjustClientRect(CurClientRect);
if WidthIsFixed then dx:=0
else dx:=CurClientRect.Left-ChildBounds.Left;
if HeightIsFixed then dy:=0
else dy:=CurClientRect.Top-ChildBounds.Top;
if (akLeft in ChildFixedSides) then
dx:=0
else
dx:=CurClientRect.Left-ChildBounds.Left;
if (akTop in ChildFixedSides) then
dy:=0
else
dy:=CurClientRect.Top-ChildBounds.Top;
if (dx<>0) or (dy<>0) then begin
// move all childs to left and top of client area

View File

@ -1,14 +1,14 @@
object LazDockControlEditorDlg: TLazDockControlEditorDlg
ActiveControl = UndockButton
Caption = 'LazDockControlEditorDlg'
ClientHeight = 315
ClientHeight = 328
ClientWidth = 310
OnCreate = FormCreate
PixelsPerInch = 112
HorzScrollBar.Page = 309
VertScrollBar.Page = 314
VertScrollBar.Page = 327
Left = 286
Height = 315
Height = 328
Top = 202
Width = 310
object UndockGroupBox: TGroupBox
@ -17,11 +17,11 @@ object LazDockControlEditorDlg: TLazDockControlEditorDlg
Caption = 'UndockGroupBox'
ChildSizing.LeftRightSpacing = 5
ChildSizing.TopBottomSpacing = 5
ClientHeight = 30
ClientHeight = 34
ClientWidth = 291
TabOrder = 0
Left = 8
Height = 47
Height = 51
Top = 8
Width = 295
object UndockButton: TButton
@ -32,21 +32,24 @@ object LazDockControlEditorDlg: TLazDockControlEditorDlg
TabOrder = 0
Left = 6
Height = 26
Top = 5
Width = 87
end
end
object DockGroupBox: TGroupBox
Anchors = [akTop, akLeft, akRight]
AutoSize = True
BorderSpacing.Top = 6
Caption = 'DockGroupBox'
ChildSizing.LeftRightSpacing = 5
ChildSizing.TopBottomSpacing = 5
ClientHeight = 180
ClientHeight = 190
ClientWidth = 291
TabOrder = 1
AnchorSideTop.Control = UndockGroupBox
Left = 8
Height = 197
Top = 56
Height = 207
Top = 65
Width = 295
object DockControlLabel: TLabel
BorderSpacing.Around = 2
@ -57,7 +60,7 @@ object LazDockControlEditorDlg: TLazDockControlEditorDlg
AnchorSideTop.Side = asrCenter
Left = 10
Height = 13
Top = 6
Top = 11
Width = 101
end
object DockLeftButton: TButton
@ -70,7 +73,7 @@ object LazDockControlEditorDlg: TLazDockControlEditorDlg
AnchorSideTop.Control = DockControlComboBox
Left = 6
Height = 26
Top = 30
Top = 35
Width = 94
end
object DockRightButton: TButton
@ -85,7 +88,7 @@ object LazDockControlEditorDlg: TLazDockControlEditorDlg
AnchorSideTop.Control = DockLeftButton
Left = 6
Height = 26
Top = 61
Top = 66
Width = 102
end
object DockTopButton: TButton
@ -100,7 +103,7 @@ object LazDockControlEditorDlg: TLazDockControlEditorDlg
AnchorSideTop.Control = DockRightButton
Left = 6
Height = 26
Top = 92
Top = 97
Width = 95
end
object DockBottomButton: TButton
@ -115,7 +118,7 @@ object LazDockControlEditorDlg: TLazDockControlEditorDlg
AnchorSideTop.Control = DockTopButton
Left = 6
Height = 26
Top = 123
Top = 128
Width = 111
end
object DockPageButton: TButton
@ -130,7 +133,7 @@ object LazDockControlEditorDlg: TLazDockControlEditorDlg
AnchorSideTop.Control = DockBottomButton
Left = 6
Height = 26
Top = 154
Top = 159
Width = 103
end
object DockControlComboBox: TComboBox
@ -143,6 +146,7 @@ object LazDockControlEditorDlg: TLazDockControlEditorDlg
AnchorSideLeft.Control = DockControlLabel
Left = 115
Height = 25
Top = 5
Width = 171
end
end
@ -156,7 +160,7 @@ object LazDockControlEditorDlg: TLazDockControlEditorDlg
AnchorSideTop.Control = DockGroupBox
Left = 112
Height = 26
Top = 263
Top = 282
Width = 85
end
end

View File

@ -3,54 +3,56 @@
LazarusResources.Add('TLazDockControlEditorDlg','FORMDATA',[
'TPF0'#24'TLazDockControlEditorDlg'#23'LazDockControlEditorDlg'#13'ActiveCont'
+'rol'#7#12'UndockButton'#7'Caption'#6#23'LazDockControlEditorDlg'#12'ClientH'
+'eight'#3';'#1#11'ClientWidth'#3'6'#1#8'OnCreate'#7#10'FormCreate'#13'Pixels'
+'PerInch'#2'p'#18'HorzScrollBar.Page'#3'5'#1#18'VertScrollBar.Page'#3':'#1#4
+'Left'#3#30#1#6'Height'#3';'#1#3'Top'#3#202#0#5'Width'#3'6'#1#0#9'TGroupBox'
+'eight'#3'H'#1#11'ClientWidth'#3'6'#1#8'OnCreate'#7#10'FormCreate'#13'Pixels'
+'PerInch'#2'p'#18'HorzScrollBar.Page'#3'5'#1#18'VertScrollBar.Page'#3'G'#1#4
+'Left'#3#30#1#6'Height'#3'H'#1#3'Top'#3#202#0#5'Width'#3'6'#1#0#9'TGroupBox'
+#14'UndockGroupBox'#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRight'#0#8'AutoSize'
+#9#7'Caption'#6#14'UndockGroupBox'#28'ChildSizing.LeftRightSpacing'#2#5#28'C'
+'hildSizing.TopBottomSpacing'#2#5#12'ClientHeight'#2#30#11'ClientWidth'#3'#'
+#1#8'TabOrder'#2#0#4'Left'#2#8#6'Height'#2'/'#3'Top'#2#8#5'Width'#3''''#1#0#7
+'hildSizing.TopBottomSpacing'#2#5#12'ClientHeight'#2'"'#11'ClientWidth'#3'#'
+#1#8'TabOrder'#2#0#4'Left'#2#8#6'Height'#2'3'#3'Top'#2#8#5'Width'#3''''#1#0#7
+'TButton'#12'UndockButton'#8'AutoSize'#9#25'BorderSpacing.InnerBorder'#2#2#7
+'Caption'#6#12'UndockButton'#7'OnClick'#7#17'UndockButtonClick'#8'TabOrder'#2
+#0#4'Left'#2#6#6'Height'#2#26#5'Width'#2'W'#0#0#0#9'TGroupBox'#12'DockGroupB'
+'ox'#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRight'#0#8'AutoSize'#9#7'Caption'#6
+#12'DockGroupBox'#28'ChildSizing.LeftRightSpacing'#2#5#28'ChildSizing.TopBot'
+'tomSpacing'#2#5#12'ClientHeight'#3#180#0#11'ClientWidth'#3'#'#1#8'TabOrder'
+#2#1#4'Left'#2#8#6'Height'#3#197#0#3'Top'#2'8'#5'Width'#3''''#1#0#6'TLabel'
+#16'DockControlLabel'#20'BorderSpacing.Around'#2#2#7'Caption'#6#16'DockContr'
+'olLabel'#5'Color'#7#6'clNone'#11'ParentColor'#8#21'AnchorSideTop.Control'#7
+#19'DockControlComboBox'#18'AnchorSideTop.Side'#7#9'asrCenter'#4'Left'#2#10#6
+'Height'#2#13#3'Top'#2#6#5'Width'#2'e'#0#0#7'TButton'#14'DockLeftButton'#8'A'
+'utoSize'#9#17'BorderSpacing.Top'#2#5#25'BorderSpacing.InnerBorder'#2#2#7'Ca'
+'ption'#6#14'DockLeftButton'#7'OnClick'#7#19'DockLeftButtonClick'#8'TabOrder'
+#2#0#21'AnchorSideTop.Control'#7#19'DockControlComboBox'#4'Left'#2#6#6'Heigh'
+'t'#2#26#3'Top'#2#30#5'Width'#2'^'#0#0#7'TButton'#15'DockRightButton'#8'Auto'
+'Size'#9#17'BorderSpacing.Top'#2#5#25'BorderSpacing.InnerBorder'#2#2#7'Capti'
+'on'#6#15'DockRightButton'#7'OnClick'#7#20'DockRightButtonClick'#8'TabOrder'
+#2#1#22'AnchorSideLeft.Control'#7#14'DockLeftButton'#19'AnchorSideLeft.Side'
+#7#6'asrTop'#21'AnchorSideTop.Control'#7#14'DockLeftButton'#4'Left'#2#6#6'He'
+'ight'#2#26#3'Top'#2'='#5'Width'#2'f'#0#0#7'TButton'#13'DockTopButton'#8'Aut'
+'oSize'#9#17'BorderSpacing.Top'#2#5#25'BorderSpacing.InnerBorder'#2#2#7'Capt'
+'ion'#6#13'DockTopButton'#7'OnClick'#7#18'DockTopButtonClick'#8'TabOrder'#2#2
+#22'AnchorSideLeft.Control'#7#14'DockLeftButton'#19'AnchorSideLeft.Side'#7#6
+'asrTop'#21'AnchorSideTop.Control'#7#15'DockRightButton'#4'Left'#2#6#6'Heigh'
+'t'#2#26#3'Top'#2'\'#5'Width'#2'_'#0#0#7'TButton'#16'DockBottomButton'#8'Aut'
+'oSize'#9#17'BorderSpacing.Top'#2#5#25'BorderSpacing.InnerBorder'#2#2#7'Capt'
+'ion'#6#16'DockBottomButton'#7'OnClick'#7#21'DockBottomButtonClick'#8'TabOrd'
+'er'#2#3#22'AnchorSideLeft.Control'#7#14'DockLeftButton'#19'AnchorSideLeft.S'
+'ide'#7#6'asrTop'#21'AnchorSideTop.Control'#7#13'DockTopButton'#4'Left'#2#6#6
+'Height'#2#26#3'Top'#2'{'#5'Width'#2'o'#0#0#7'TButton'#14'DockPageButton'#8
+'AutoSize'#9#17'BorderSpacing.Top'#2#5#25'BorderSpacing.InnerBorder'#2#2#7'C'
+'aption'#6#14'DockPageButton'#7'OnClick'#7#19'DockPageButtonClick'#8'TabOrde'
+'r'#2#4#22'AnchorSideLeft.Control'#7#14'DockLeftButton'#19'AnchorSideLeft.Si'
+'de'#7#6'asrTop'#21'AnchorSideTop.Control'#7#16'DockBottomButton'#4'Left'#2#6
+#6'Height'#2#26#3'Top'#3#154#0#5'Width'#2'g'#0#0#9'TComboBox'#19'DockControl'
+'ComboBox'#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRight'#0#18'BorderSpacing.Le'
+'ft'#2#4#9'MaxLength'#2#0#13'OnEditingDone'#7#30'DockControlComboBoxEditingD'
+'one'#8'TabOrder'#2#5#4'Text'#6#19'DockControlComboBox'#22'AnchorSideLeft.Co'
+'ntrol'#7#16'DockControlLabel'#4'Left'#2's'#6'Height'#2#25#5'Width'#3#171#0#0
+#0#0#7'TButton'#12'CancelButton'#7'Anchors'#11#5'akTop'#0#8'AutoSize'#9#17'B'
+'orderSpacing.Top'#2#10#25'BorderSpacing.InnerBorder'#2#2#7'Caption'#6#12'Ca'
+'ncelButton'#8'TabOrder'#2#2#21'AnchorSideTop.Control'#7#12'DockGroupBox'#4
+'Left'#2'p'#6'Height'#2#26#3'Top'#3#7#1#5'Width'#2'U'#0#0#0
+#0#4'Left'#2#6#6'Height'#2#26#3'Top'#2#5#5'Width'#2'W'#0#0#0#9'TGroupBox'#12
+'DockGroupBox'#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRight'#0#8'AutoSize'#9#17
+'BorderSpacing.Top'#2#6#7'Caption'#6#12'DockGroupBox'#28'ChildSizing.LeftRig'
+'htSpacing'#2#5#28'ChildSizing.TopBottomSpacing'#2#5#12'ClientHeight'#3#190#0
+#11'ClientWidth'#3'#'#1#8'TabOrder'#2#1#21'AnchorSideTop.Control'#7#14'Undoc'
+'kGroupBox'#4'Left'#2#8#6'Height'#3#207#0#3'Top'#2'A'#5'Width'#3''''#1#0#6'T'
+'Label'#16'DockControlLabel'#20'BorderSpacing.Around'#2#2#7'Caption'#6#16'Do'
+'ckControlLabel'#5'Color'#7#6'clNone'#11'ParentColor'#8#21'AnchorSideTop.Con'
+'trol'#7#19'DockControlComboBox'#18'AnchorSideTop.Side'#7#9'asrCenter'#4'Lef'
+'t'#2#10#6'Height'#2#13#3'Top'#2#11#5'Width'#2'e'#0#0#7'TButton'#14'DockLeft'
+'Button'#8'AutoSize'#9#17'BorderSpacing.Top'#2#5#25'BorderSpacing.InnerBorde'
+'r'#2#2#7'Caption'#6#14'DockLeftButton'#7'OnClick'#7#19'DockLeftButtonClick'
+#8'TabOrder'#2#0#21'AnchorSideTop.Control'#7#19'DockControlComboBox'#4'Left'
+#2#6#6'Height'#2#26#3'Top'#2'#'#5'Width'#2'^'#0#0#7'TButton'#15'DockRightBut'
+'ton'#8'AutoSize'#9#17'BorderSpacing.Top'#2#5#25'BorderSpacing.InnerBorder'#2
+#2#7'Caption'#6#15'DockRightButton'#7'OnClick'#7#20'DockRightButtonClick'#8
+'TabOrder'#2#1#22'AnchorSideLeft.Control'#7#14'DockLeftButton'#19'AnchorSide'
+'Left.Side'#7#6'asrTop'#21'AnchorSideTop.Control'#7#14'DockLeftButton'#4'Lef'
+'t'#2#6#6'Height'#2#26#3'Top'#2'B'#5'Width'#2'f'#0#0#7'TButton'#13'DockTopBu'
+'tton'#8'AutoSize'#9#17'BorderSpacing.Top'#2#5#25'BorderSpacing.InnerBorder'
+#2#2#7'Caption'#6#13'DockTopButton'#7'OnClick'#7#18'DockTopButtonClick'#8'Ta'
+'bOrder'#2#2#22'AnchorSideLeft.Control'#7#14'DockLeftButton'#19'AnchorSideLe'
+'ft.Side'#7#6'asrTop'#21'AnchorSideTop.Control'#7#15'DockRightButton'#4'Left'
+#2#6#6'Height'#2#26#3'Top'#2'a'#5'Width'#2'_'#0#0#7'TButton'#16'DockBottomBu'
+'tton'#8'AutoSize'#9#17'BorderSpacing.Top'#2#5#25'BorderSpacing.InnerBorder'
+#2#2#7'Caption'#6#16'DockBottomButton'#7'OnClick'#7#21'DockBottomButtonClick'
+#8'TabOrder'#2#3#22'AnchorSideLeft.Control'#7#14'DockLeftButton'#19'AnchorSi'
+'deLeft.Side'#7#6'asrTop'#21'AnchorSideTop.Control'#7#13'DockTopButton'#4'Le'
+'ft'#2#6#6'Height'#2#26#3'Top'#3#128#0#5'Width'#2'o'#0#0#7'TButton'#14'DockP'
+'ageButton'#8'AutoSize'#9#17'BorderSpacing.Top'#2#5#25'BorderSpacing.InnerBo'
+'rder'#2#2#7'Caption'#6#14'DockPageButton'#7'OnClick'#7#19'DockPageButtonCli'
+'ck'#8'TabOrder'#2#4#22'AnchorSideLeft.Control'#7#14'DockLeftButton'#19'Anch'
+'orSideLeft.Side'#7#6'asrTop'#21'AnchorSideTop.Control'#7#16'DockBottomButto'
+'n'#4'Left'#2#6#6'Height'#2#26#3'Top'#3#159#0#5'Width'#2'g'#0#0#9'TComboBox'
+#19'DockControlComboBox'#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRight'#0#18'Bo'
+'rderSpacing.Left'#2#4#9'MaxLength'#2#0#13'OnEditingDone'#7#30'DockControlCo'
+'mboBoxEditingDone'#8'TabOrder'#2#5#4'Text'#6#19'DockControlComboBox'#22'Anc'
+'horSideLeft.Control'#7#16'DockControlLabel'#4'Left'#2's'#6'Height'#2#25#3'T'
+'op'#2#5#5'Width'#3#171#0#0#0#0#7'TButton'#12'CancelButton'#7'Anchors'#11#5
+'akTop'#0#8'AutoSize'#9#17'BorderSpacing.Top'#2#10#25'BorderSpacing.InnerBor'
+'der'#2#2#7'Caption'#6#12'CancelButton'#8'TabOrder'#2#2#21'AnchorSideTop.Con'
+'trol'#7#12'DockGroupBox'#4'Left'#2'p'#6'Height'#2#26#3'Top'#3#26#1#5'Width'
+#2'U'#0#0#0
]);