mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-17 07:09:28 +02:00
test: added scrollbox range check
git-svn-id: trunk@29145 -
This commit is contained in:
parent
082b57515a
commit
ba63597f8e
@ -103,6 +103,8 @@ var
|
|||||||
Panel1: TPanel;
|
Panel1: TPanel;
|
||||||
IntfPreferredWidth: integer;
|
IntfPreferredWidth: integer;
|
||||||
IntfPreferredHeight: integer;
|
IntfPreferredHeight: integer;
|
||||||
|
MaxPrefWidth: Integer;
|
||||||
|
MaxPrefHeight: Integer;
|
||||||
begin
|
begin
|
||||||
// create a scrollbox with AutoScroll=true on a form and put a small panel into the box
|
// create a scrollbox with AutoScroll=true on a form and put a small panel into the box
|
||||||
Form1:=TForm.Create(nil);
|
Form1:=TForm.Create(nil);
|
||||||
@ -124,38 +126,56 @@ begin
|
|||||||
IntfPreferredHeight:=0;
|
IntfPreferredHeight:=0;
|
||||||
TWSWinControlClass(ScrollBox1.WidgetSetClass).GetPreferredSize(ScrollBox1,
|
TWSWinControlClass(ScrollBox1.WidgetSetClass).GetPreferredSize(ScrollBox1,
|
||||||
IntfPreferredWidth, IntfPreferredHeight, false);
|
IntfPreferredWidth, IntfPreferredHeight, false);
|
||||||
AssertEquals('ScrollBox must have small interface preferred width',true,IntfPreferredWidth<8);
|
MaxPrefWidth:=ScrollBox1.Width-ScrollBox1.ClientWidth;
|
||||||
AssertEquals('ScrollBox must have small interface preferred height',true,IntfPreferredHeight<8);
|
MaxPrefHeight:=ScrollBox1.Width-ScrollBox1.ClientWidth;
|
||||||
|
AssertEquals('ScrollBox must have small interface preferred width',true,
|
||||||
|
IntfPreferredWidth<=MaxPrefWidth);
|
||||||
|
AssertEquals('ScrollBox must have small interface preferred height',true,
|
||||||
|
IntfPreferredHeight<=MaxPrefHeight);
|
||||||
|
|
||||||
//writeln('TTestPreferredSize.TestScrollBoxOneChildPanel Range=',ScrollBox1.HorzScrollBar.Range,' ',ScrollBox1.HorzScrollBar.Page,' ',ScrollBox1.HorzScrollBar.Visible);
|
//writeln('TTestPreferredSize.TestScrollBoxOneChildPanel Range=',ScrollBox1.HorzScrollBar.Range,' ',ScrollBox1.HorzScrollBar.Page,' ',ScrollBox1.HorzScrollBar.Visible);
|
||||||
AssertEquals('ScrollBox1.HorzScrollBar.Range should be the needed Right of all childs 60',60,ScrollBox1.HorzScrollBar.Range);
|
AssertEquals('ScrollBox1.HorzScrollBar.Range should be the needed Right of all childs 60',
|
||||||
AssertEquals('ScrollBox1.VertScrollBar.Range should be the needed Bottom of all childs 50',50,ScrollBox1.VertScrollBar.Range);
|
60,ScrollBox1.HorzScrollBar.Range);
|
||||||
AssertEquals('ScrollBox shows HorzScrollBar for empty box',false,ScrollBox1.HorzScrollBar.IsScrollBarVisible);
|
AssertEquals('ScrollBox1.VertScrollBar.Range should be the needed Bottom of all childs 50',
|
||||||
AssertEquals('ScrollBox shows VertScrollBar for empty box',false,ScrollBox1.VertScrollBar.IsScrollBarVisible);
|
50,ScrollBox1.VertScrollBar.Range);
|
||||||
|
AssertEquals('ScrollBox shows HorzScrollBar for empty box',false,
|
||||||
|
ScrollBox1.HorzScrollBar.IsScrollBarVisible);
|
||||||
|
AssertEquals('ScrollBox shows VertScrollBar for empty box',false,
|
||||||
|
ScrollBox1.VertScrollBar.IsScrollBarVisible);
|
||||||
|
|
||||||
// now enlarge the panel, so that a HorzScrollBar is needed
|
// now enlarge the panel, so that a HorzScrollBar is needed
|
||||||
Panel1.Width:=150;
|
Panel1.Width:=150;
|
||||||
Application.ProcessMessages;
|
Application.ProcessMessages;
|
||||||
|
|
||||||
AssertEquals('ScrollBox1.HorzScrollBar.Range should be the needed Right of all childs 150',150,ScrollBox1.HorzScrollBar.Range);
|
AssertEquals('ScrollBox1.HorzScrollBar.Range should be the needed Right of all childs 150',
|
||||||
AssertEquals('ScrollBox1.VertScrollBar.Range should be the needed Bottom of all childs 50',50,ScrollBox1.VertScrollBar.Range);
|
150,ScrollBox1.HorzScrollBar.Range);
|
||||||
AssertEquals('ScrollBox must show HorzScrollBar for oversized panel',true,ScrollBox1.HorzScrollBar.IsScrollBarVisible);
|
AssertEquals('ScrollBox1.VertScrollBar.Range should be the needed Bottom of all childs 50',
|
||||||
AssertEquals('ScrollBox shows VertScrollBar for small panel',false,ScrollBox1.VertScrollBar.IsScrollBarVisible);
|
50,ScrollBox1.VertScrollBar.Range);
|
||||||
|
AssertEquals('ScrollBox must show HorzScrollBar for oversized panel',true,
|
||||||
|
ScrollBox1.HorzScrollBar.IsScrollBarVisible);
|
||||||
|
AssertEquals('ScrollBox shows VertScrollBar for small panel',false,
|
||||||
|
ScrollBox1.VertScrollBar.IsScrollBarVisible);
|
||||||
|
|
||||||
// now Align the panel, so that the panel fills the whole client area
|
// now Align the panel, so that the panel fills the whole client area
|
||||||
// no scrollbars should be visible
|
// no scrollbars should be visible
|
||||||
Panel1.Align:=alClient;
|
Panel1.Align:=alClient;
|
||||||
Application.ProcessMessages;
|
Application.ProcessMessages;
|
||||||
|
|
||||||
writeln('TTestPreferredSize.TestScrollBoxOneChildPanel Panel1.BoundsRect=',dbgs(Panel1.BoundsRect),' ScrollBox1.ClientRect=',dbgs(ScrollBox1.ClientRect));
|
//writeln('TTestPreferredSize.TestScrollBoxOneChildPanel Panel1.BoundsRect=',dbgs(Panel1.BoundsRect),' ScrollBox1.ClientRect=',dbgs(ScrollBox1.ClientRect));
|
||||||
AssertEquals('Panel1.Align=alClient, Panel1.Left should be 0',0,Panel1.Left);
|
AssertEquals('Panel1.Align=alClient, Panel1.Left should be 0',0,Panel1.Left);
|
||||||
AssertEquals('Panel1.Align=alClient, Panel1.Top should be 0',0,Panel1.Top);
|
AssertEquals('Panel1.Align=alClient, Panel1.Top should be 0',0,Panel1.Top);
|
||||||
AssertEquals('Panel1.Align=alClient, Panel1.Right should be ScrollBox1.ClientWidth',ScrollBox1.ClientWidth,Panel1.Left+Panel1.Width);
|
AssertEquals('Panel1.Align=alClient, Panel1.Right should be ScrollBox1.ClientWidth',
|
||||||
AssertEquals('Panel1.Align=alClient, Panel1.Bottom should be ScrollBox1.ClientHeight',ScrollBox1.ClientHeight,Panel1.Top+Panel1.Height);
|
ScrollBox1.ClientWidth,Panel1.Left+Panel1.Width);
|
||||||
AssertEquals('ScrollBox shows HorzScrollBar for fitting panel',false,ScrollBox1.HorzScrollBar.IsScrollBarVisible);
|
AssertEquals('Panel1.Align=alClient, Panel1.Bottom should be ScrollBox1.ClientHeight',
|
||||||
AssertEquals('ScrollBox shows VertScrollBar for fitting panel',false,ScrollBox1.VertScrollBar.IsScrollBarVisible);
|
ScrollBox1.ClientHeight,Panel1.Top+Panel1.Height);
|
||||||
AssertEquals('ScrollBox1.HorzScrollBar.Range should be the needed Right of all childs',Panel1.Constraints.MinWidth,ScrollBox1.HorzScrollBar.Range);
|
AssertEquals('ScrollBox shows HorzScrollBar for fitting panel',false,
|
||||||
AssertEquals('ScrollBox1.VertScrollBar.Range should be the needed Bottom of all childs',Panel1.Constraints.MinHeight,ScrollBox1.VertScrollBar.Range);
|
ScrollBox1.HorzScrollBar.IsScrollBarVisible);
|
||||||
|
AssertEquals('ScrollBox shows VertScrollBar for fitting panel',false,
|
||||||
|
ScrollBox1.VertScrollBar.IsScrollBarVisible);
|
||||||
|
AssertEquals('ScrollBox1.HorzScrollBar.Range should be the needed Right of all childs',
|
||||||
|
Panel1.Constraints.MinWidth,ScrollBox1.HorzScrollBar.Range);
|
||||||
|
AssertEquals('ScrollBox1.VertScrollBar.Range should be the needed Bottom of all childs',
|
||||||
|
Panel1.Constraints.MinHeight,ScrollBox1.VertScrollBar.Range);
|
||||||
|
|
||||||
|
|
||||||
Form1.Free;
|
Form1.Free;
|
||||||
@ -166,17 +186,74 @@ procedure TTestPreferredSize.TestScrollBoxRange;
|
|||||||
var
|
var
|
||||||
Form1: TForm;
|
Form1: TForm;
|
||||||
ScrollBox1: TScrollBox;
|
ScrollBox1: TScrollBox;
|
||||||
|
IntfPreferredWidth: Integer;
|
||||||
|
IntfPreferredHeight: Integer;
|
||||||
|
MaxPrefWidth: Integer;
|
||||||
|
MaxPrefHeight: Integer;
|
||||||
|
Panel1: TPanel;
|
||||||
begin
|
begin
|
||||||
// create an empty scrollbox on a form
|
// create an empty scrollbox on a form
|
||||||
Form1:=TForm.Create(nil);
|
Form1:=TForm.Create(nil);
|
||||||
Form1.SetBounds(100,100,300,300);
|
Form1.SetBounds(100,100,300,250);
|
||||||
ScrollBox1:=TScrollBox.Create(Form1);
|
ScrollBox1:=TScrollBox.Create(Form1);
|
||||||
ScrollBox1.SetBounds(10,10,100,100);
|
ScrollBox1.SetBounds(10,10,150,100);
|
||||||
ScrollBox1.AutoScroll:=true;
|
ScrollBox1.AutoScroll:=true;
|
||||||
ScrollBox1.Parent:=Form1;
|
ScrollBox1.Parent:=Form1;
|
||||||
Form1.Show;
|
Form1.Show;
|
||||||
Application.ProcessMessages;
|
Application.ProcessMessages;
|
||||||
|
|
||||||
|
AssertEquals('TScrollBox: Empty, AutoScroll=true, but HorzScrollBar.Range<>0',
|
||||||
|
0,ScrollBox1.HorzScrollBar.Range);
|
||||||
|
AssertEquals('TScrollBox: Empty, AutoScroll=true, but VertScrollBar.Range<>0',
|
||||||
|
0,ScrollBox1.VertScrollBar.Range);
|
||||||
|
AssertEquals('TScrollBox: Empty, AutoScroll=true, but HorzScrollBar.Position<>0',
|
||||||
|
0,ScrollBox1.HorzScrollBar.Position);
|
||||||
|
AssertEquals('TScrollBox: Empty, AutoScroll=true, but VertScrollBar.Position<>0',
|
||||||
|
0,ScrollBox1.VertScrollBar.Position);
|
||||||
|
AssertEquals('TScrollBox: Empty, AutoScroll=true, but HorzScrollBar.Page<>ClientWidth',
|
||||||
|
ScrollBox1.ClientWidth,ScrollBox1.HorzScrollBar.Page);
|
||||||
|
AssertEquals('TScrollBox: Empty, AutoScroll=true, but VertScrollBar.Page<>ClientHeight',
|
||||||
|
ScrollBox1.ClientHeight,ScrollBox1.VertScrollBar.Page);
|
||||||
|
|
||||||
|
// now add a panel
|
||||||
|
Panel1:=TPanel.Create(Form1);
|
||||||
|
Panel1.Caption:='Panel1';
|
||||||
|
Panel1.SetBounds(0,0,60,50);
|
||||||
|
Panel1.Constraints.MinWidth:=10;
|
||||||
|
Panel1.Constraints.MinHeight:=10;
|
||||||
|
Panel1.Parent:=ScrollBox1;
|
||||||
|
|
||||||
|
Application.ProcessMessages;
|
||||||
|
|
||||||
|
IntfPreferredWidth:=0;
|
||||||
|
IntfPreferredHeight:=0;
|
||||||
|
TWSWinControlClass(ScrollBox1.WidgetSetClass).GetPreferredSize(ScrollBox1,
|
||||||
|
IntfPreferredWidth, IntfPreferredHeight, false);
|
||||||
|
MaxPrefWidth:=ScrollBox1.Width-ScrollBox1.ClientWidth;
|
||||||
|
MaxPrefHeight:=ScrollBox1.Width-ScrollBox1.ClientWidth;
|
||||||
|
AssertEquals('ScrollBox must have small interface preferred width',true,
|
||||||
|
IntfPreferredWidth<=MaxPrefWidth);
|
||||||
|
AssertEquals('ScrollBox must have small interface preferred height',true,
|
||||||
|
IntfPreferredHeight<=MaxPrefHeight);
|
||||||
|
|
||||||
|
//writeln('TTestPreferredSize.TestScrollBoxOneChildPanel Range=',ScrollBox1.HorzScrollBar.Range,' ',ScrollBox1.HorzScrollBar.Page,' ',ScrollBox1.HorzScrollBar.Visible);
|
||||||
|
AssertEquals('ScrollBox1.HorzScrollBar.Range should be the needed Right of all childs 60',
|
||||||
|
60,ScrollBox1.HorzScrollBar.Range);
|
||||||
|
AssertEquals('ScrollBox1.VertScrollBar.Range should be the needed Bottom of all childs 50',
|
||||||
|
50,ScrollBox1.VertScrollBar.Range);
|
||||||
|
AssertEquals('TScrollBox: small panel, HorzScrollBar.Position<>0',
|
||||||
|
0,ScrollBox1.HorzScrollBar.Position);
|
||||||
|
AssertEquals('TScrollBox: small panel, VertScrollBar.Position<>0',
|
||||||
|
0,ScrollBox1.VertScrollBar.Position);
|
||||||
|
AssertEquals('TScrollBox: small panel, HorzScrollBar.Page<>ClientWidth',
|
||||||
|
ScrollBox1.ClientWidth,ScrollBox1.HorzScrollBar.Page);
|
||||||
|
AssertEquals('TScrollBox: small panel, VertScrollBar.Page<>ClientHeight',
|
||||||
|
ScrollBox1.ClientHeight,ScrollBox1.VertScrollBar.Page);
|
||||||
|
|
||||||
|
// now enlarge the panel, so that a HorzScrollBar is needed
|
||||||
|
Panel1.Width:=200;
|
||||||
|
Application.ProcessMessages;
|
||||||
|
|
||||||
with ScrollBox1.HorzScrollBar do begin
|
with ScrollBox1.HorzScrollBar do begin
|
||||||
writeln('TTestPreferredSize.TestScrollBoxRange Horz: Visible=',Visible,
|
writeln('TTestPreferredSize.TestScrollBoxRange Horz: Visible=',Visible,
|
||||||
' HandleVisible=',IsScrollBarVisible,
|
' HandleVisible=',IsScrollBarVisible,
|
||||||
@ -184,7 +261,47 @@ begin
|
|||||||
' ClientWidth=',ScrollBox1.ClientWidth);
|
' ClientWidth=',ScrollBox1.ClientWidth);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// ToDo: check range
|
AssertEquals('ScrollBox1.HorzScrollBar.Range should be the needed Right of all childs 200',
|
||||||
|
200,ScrollBox1.HorzScrollBar.Range);
|
||||||
|
AssertEquals('ScrollBox1.VertScrollBar.Range should be the needed Bottom of all childs 50',
|
||||||
|
50,ScrollBox1.VertScrollBar.Range);
|
||||||
|
AssertEquals('ScrollBox must show HorzScrollBar for oversized panel',
|
||||||
|
true,ScrollBox1.HorzScrollBar.IsScrollBarVisible);
|
||||||
|
AssertEquals('TScrollBox: HorzScrollBar.Position<>0',
|
||||||
|
0,ScrollBox1.HorzScrollBar.Position);
|
||||||
|
AssertEquals('TScrollBox: VertScrollBar.Position<>0',
|
||||||
|
0,ScrollBox1.VertScrollBar.Position);
|
||||||
|
AssertEquals('TScrollBox: HorzScrollBar.Page<>ClientWidth',
|
||||||
|
ScrollBox1.ClientWidth,ScrollBox1.HorzScrollBar.Page);
|
||||||
|
AssertEquals('TScrollBox: VertScrollBar.Page<>ClientHeight',
|
||||||
|
ScrollBox1.ClientHeight,ScrollBox1.VertScrollBar.Page);
|
||||||
|
|
||||||
|
// now Align the panel, so that the panel fills the whole client area
|
||||||
|
Panel1.Align:=alClient;
|
||||||
|
Application.ProcessMessages;
|
||||||
|
AssertEquals('ScrollBox1.HorzScrollBar.Range should be the needed Right of all childs 200',
|
||||||
|
200,ScrollBox1.HorzScrollBar.Range);
|
||||||
|
AssertEquals('ScrollBox1.VertScrollBar.Range should be the needed Bottom of all childs 50',
|
||||||
|
50,ScrollBox1.VertScrollBar.Range);
|
||||||
|
AssertEquals('TScrollBox: HorzScrollBar.Position<>0',
|
||||||
|
0,ScrollBox1.HorzScrollBar.Position);
|
||||||
|
AssertEquals('TScrollBox: VertScrollBar.Position<>0',
|
||||||
|
0,ScrollBox1.VertScrollBar.Position);
|
||||||
|
AssertEquals('TScrollBox: HorzScrollBar.Page<>ClientWidth',
|
||||||
|
ScrollBox1.ClientWidth,ScrollBox1.HorzScrollBar.Page);
|
||||||
|
AssertEquals('TScrollBox: VertScrollBar.Page<>ClientHeight',
|
||||||
|
ScrollBox1.ClientHeight,ScrollBox1.VertScrollBar.Page);
|
||||||
|
// check range
|
||||||
|
AssertEquals('ScrollBox1.HorzScrollBar.Range should be the needed Right of all childs',
|
||||||
|
Panel1.Left+Panel1.Width,ScrollBox1.HorzScrollBar.Range);
|
||||||
|
AssertEquals('ScrollBox1.VertScrollBar.Range should be the needed Bottom of all childs',
|
||||||
|
Panel1.Top+Panel1.Height,ScrollBox1.VertScrollBar.Range);
|
||||||
|
// Panel should fill the ClientRect
|
||||||
|
AssertEquals('Panel1.Align=alClient but Panel1.Width<>ScrollBox1.ClientWidth',
|
||||||
|
Panel1.Width,ScrollBox1.ClientWidth);
|
||||||
|
AssertEquals('Panel1.Align=alClient but Panel1.Height<>ScrollBox1.ClientHeight',
|
||||||
|
Panel1.Height,ScrollBox1.ClientHeight);
|
||||||
|
|
||||||
|
|
||||||
Form1.Free;
|
Form1.Free;
|
||||||
Application.ProcessMessages;
|
Application.ProcessMessages;
|
||||||
|
Loading…
Reference in New Issue
Block a user