mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-12-08 19:47:30 +01:00
IDE: refactor duplicate code into SetNewBounds method. Set Applied and set FForm without setter to solve issue #20368
git-svn-id: trunk@33497 -
This commit is contained in:
parent
3017016146
commit
93cdd2d825
@ -139,7 +139,6 @@ begin
|
||||
|
||||
if FShowSimpleLayout then begin
|
||||
// Window Positions
|
||||
FLayouts.Assign(IDEWindowCreators.SimpleLayoutStorage);
|
||||
WindowPositionsGroupBox.Parent:=Self;
|
||||
WindowPositionsGroupBox.Caption := dlgWinPos;
|
||||
WindowPositionsListBox.Items.BeginUpdate;
|
||||
@ -300,32 +299,9 @@ var
|
||||
NewBounds: TRect;
|
||||
begin
|
||||
SaveLayout;
|
||||
if (Layout<>nil) and (Layout.Form<>nil) and (Layout.Form.Parent=nil)
|
||||
then begin
|
||||
if (Layout.WindowPlacement in [iwpCustomPosition,iwpRestoreWindowGeometry])
|
||||
then begin
|
||||
if (Layout.CustomCoordinatesAreValid) then begin
|
||||
// explicit position
|
||||
NewBounds:=Bounds(Layout.Left,Layout.Top,Layout.Width,Layout.Height);
|
||||
// set minimum size
|
||||
if NewBounds.Right-NewBounds.Left<20 then
|
||||
NewBounds.Right:=NewBounds.Left+20;
|
||||
if NewBounds.Bottom-NewBounds.Top<20 then
|
||||
NewBounds.Bottom:=NewBounds.Top+20;
|
||||
// move to visible area
|
||||
if NewBounds.Right<20 then
|
||||
OffsetRect(NewBounds,20-NewBounds.Right,0);
|
||||
if NewBounds.Bottom<20 then
|
||||
OffsetRect(NewBounds,0,20-NewBounds.Bottom);
|
||||
if NewBounds.Left>Screen.DesktopWidth-20 then
|
||||
OffsetRect(NewBounds,NewBounds.Left-(Screen.DesktopWidth-20),0);
|
||||
if NewBounds.Top>Screen.DesktopHeight-20 then
|
||||
OffsetRect(NewBounds,NewBounds.Top-(Screen.DesktopHeight-20),0);
|
||||
Layout.Form.SetBounds(
|
||||
NewBounds.Left,NewBounds.Top,
|
||||
NewBounds.Right-NewBounds.Left,NewBounds.Bottom-NewBounds.Top);
|
||||
end;
|
||||
end;
|
||||
if (Layout<>nil) and (Layout.Form<>nil) and (Layout.Form.Parent=nil) then begin
|
||||
if (Layout.WindowPlacement in [iwpCustomPosition,iwpRestoreWindowGeometry]) then
|
||||
Layout.SetNewBounds; // Adjust bounds to screen area and apply them.
|
||||
Layout.ApplyDivider(True);
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -233,6 +233,7 @@ type
|
||||
procedure SaveToConfig(Config: TConfigStorage; const Path: string);
|
||||
function CustomCoordinatesAreValid: boolean;
|
||||
procedure CloseForm;
|
||||
function SetNewBounds: Boolean;
|
||||
public
|
||||
property FormID: string read GetFormID write FFormID;
|
||||
function FormBaseID(out SubIndex: Integer): String; // split FormID into name+number
|
||||
@ -1029,8 +1030,8 @@ var
|
||||
begin
|
||||
inherited Create(nil);
|
||||
FDividers := TSimpleWindowLayoutDividerPosList.Create;
|
||||
FormID:=AFormID;
|
||||
fDefaultWindowPlacement:=iwpRestoreWindowGeometry;
|
||||
FormID := AFormID;
|
||||
fDefaultWindowPlacement := iwpRestoreWindowGeometry;
|
||||
Clear;
|
||||
Creator := IDEWindowCreators.FindWithName(AFormID);
|
||||
if Creator <> nil then
|
||||
@ -1132,6 +1133,51 @@ begin
|
||||
Form:=nil;
|
||||
end;
|
||||
|
||||
function TSimpleWindowLayout.SetNewBounds: Boolean;
|
||||
var
|
||||
i: Integer;
|
||||
NewBounds: TRect;
|
||||
begin
|
||||
// No need to check coordinate validity because they will be adjusted.
|
||||
// explicit position
|
||||
NewBounds := Bounds(Left, Top, Width, Height);
|
||||
// set minimum size
|
||||
if NewBounds.Right - NewBounds.Left < 60 then
|
||||
NewBounds.Right := NewBounds.Left + 60;
|
||||
if NewBounds.Bottom - NewBounds.Top < 60 then
|
||||
NewBounds.Bottom := NewBounds.Top + 60;
|
||||
|
||||
// Move to visible area :
|
||||
// window is out at left side of screen
|
||||
if NewBounds.Right < Screen.DesktopLeft + 60 then
|
||||
OffsetRect(NewBounds, Screen.DesktopLeft + 60 - NewBounds.Right, 0);
|
||||
|
||||
// window is out above the screen
|
||||
if NewBounds.Bottom < Screen.DesktopTop+60 then
|
||||
OffsetRect(NewBounds, 0, Screen.DesktopTop + 60 - NewBounds.Bottom);
|
||||
|
||||
// window is out at right side of screen, i = right edge of screen - 60
|
||||
i := Screen.DesktopWidth + Screen.DesktopLeft - 60;
|
||||
if NewBounds.Left > i then begin
|
||||
NewBounds.Left := i;
|
||||
NewBounds.Right := NewBounds.Right + i - NewBounds.Left;
|
||||
end;
|
||||
|
||||
// window is out below the screen, i = bottom edge of screen - 60
|
||||
i := Screen.DesktopHeight + Screen.DesktopTop - 60;
|
||||
if NewBounds.Top > i then begin
|
||||
NewBounds.Top := i;
|
||||
NewBounds.Bottom := NewBounds.Bottom + i - NewBounds.Top;
|
||||
end;
|
||||
|
||||
// set bounds (do not use SetRestoredBounds - that flickers with the current LCL implementation)
|
||||
FForm.SetBounds(NewBounds.Left, NewBounds.Top,
|
||||
NewBounds.Right - NewBounds.Left,
|
||||
NewBounds.Bottom - NewBounds.Top);
|
||||
Applied := True;
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
function TSimpleWindowLayout.FormBaseID(out SubIndex: Integer): String;
|
||||
var
|
||||
i: Integer;
|
||||
@ -1225,7 +1271,7 @@ procedure TSimpleWindowLayout.Assign(Layout: TSimpleWindowLayout);
|
||||
begin
|
||||
Clear;
|
||||
FApplied:=Layout.Applied;
|
||||
Form:=Layout.Form;
|
||||
FForm:=Layout.FForm;
|
||||
fWindowPlacement:=Layout.fWindowPlacement;
|
||||
fLeft:=Layout.fLeft;
|
||||
fTop:=Layout.fTop;
|
||||
@ -1245,7 +1291,7 @@ var
|
||||
begin
|
||||
Creator:=IDEWindowCreators.FindWithName(FormID);
|
||||
if (Creator = nil) or (Creator.OnGetDividerSize = nil) then exit;
|
||||
if fForm = nil then exit;;
|
||||
if fForm = nil then exit;
|
||||
for i := 0 to FDividers.Count - 1 do begin
|
||||
if FDividers[i].FId < 0 then continue;
|
||||
f := AForce;
|
||||
@ -1274,9 +1320,6 @@ begin
|
||||
end;
|
||||
|
||||
function TSimpleWindowLayout.Apply: Boolean;
|
||||
var
|
||||
NewBounds: TRect;
|
||||
i: Integer;
|
||||
begin
|
||||
Result := False;
|
||||
if fForm = nil then exit;
|
||||
@ -1284,8 +1327,7 @@ begin
|
||||
{$IFDEF VerboseIDEDocking}
|
||||
debugln(['TSimpleWindowLayoutList.ApplyAndShow restore ',
|
||||
FormID,' ',IDEWindowPlacementNames[WindowPlacement],
|
||||
' Valid=',CustomCoordinatesAreValid,' ',Left,',',
|
||||
Top,',',Width,',',Height]);
|
||||
' ',Left,',',Top,',',Width,',',Height]);
|
||||
{$ENDIF}
|
||||
|
||||
case WindowPlacement of
|
||||
@ -1296,46 +1338,7 @@ begin
|
||||
iwsMinimized: FForm.WindowState:=wsMinimized;
|
||||
iwsMaximized: FForm.WindowState:=wsMaximized;
|
||||
end;
|
||||
|
||||
if (CustomCoordinatesAreValid) then begin
|
||||
// explicit position
|
||||
NewBounds:=Bounds(Left,Top,Width,Height);
|
||||
// set minimum size
|
||||
if NewBounds.Right-NewBounds.Left<60 then
|
||||
NewBounds.Right:=NewBounds.Left+60;
|
||||
if NewBounds.Bottom-NewBounds.Top<60 then
|
||||
NewBounds.Bottom:=NewBounds.Top+60;
|
||||
|
||||
// Move to visible area :
|
||||
// window is out at left side of screen
|
||||
if NewBounds.Right<Screen.DesktopLeft+60 then
|
||||
OffsetRect(NewBounds,Screen.DesktopLeft+60-NewBounds.Right,0);
|
||||
|
||||
// window is out above the screen
|
||||
if NewBounds.Bottom<Screen.DesktopTop+60 then
|
||||
OffsetRect(NewBounds,0,Screen.DesktopTop+60-NewBounds.Bottom);
|
||||
|
||||
// window is out at right side of screen, i = right edge of screen - 60
|
||||
i:=Screen.DesktopWidth+Screen.DesktopLeft-60;
|
||||
if NewBounds.Left > i then begin
|
||||
NewBounds.Left := i;
|
||||
NewBounds.Right := NewBounds.Right + i - NewBounds.Left;
|
||||
end;
|
||||
|
||||
// window is out below the screen, i = bottom edge of screen - 60
|
||||
i:=Screen.DesktopHeight+Screen.DesktopTop-60;
|
||||
if NewBounds.Top > i then begin
|
||||
NewBounds.Top := i;
|
||||
NewBounds.Bottom := NewBounds.Bottom + i - NewBounds.Top;
|
||||
end;
|
||||
|
||||
// set bounds (do not use SetRestoredBounds - that flickers with the current LCL implementation)
|
||||
FForm.SetBounds(NewBounds.Left,NewBounds.Top,
|
||||
NewBounds.Right-NewBounds.Left,
|
||||
NewBounds.Bottom-NewBounds.Top);
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
Result := SetNewBounds; // Adjust bounds to screen area and apply them.
|
||||
if WindowState in [iwsMinimized, iwsMaximized] then
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user