mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-12-09 10:18:04 +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
|
if FShowSimpleLayout then begin
|
||||||
// Window Positions
|
// Window Positions
|
||||||
FLayouts.Assign(IDEWindowCreators.SimpleLayoutStorage);
|
|
||||||
WindowPositionsGroupBox.Parent:=Self;
|
WindowPositionsGroupBox.Parent:=Self;
|
||||||
WindowPositionsGroupBox.Caption := dlgWinPos;
|
WindowPositionsGroupBox.Caption := dlgWinPos;
|
||||||
WindowPositionsListBox.Items.BeginUpdate;
|
WindowPositionsListBox.Items.BeginUpdate;
|
||||||
@ -300,32 +299,9 @@ var
|
|||||||
NewBounds: TRect;
|
NewBounds: TRect;
|
||||||
begin
|
begin
|
||||||
SaveLayout;
|
SaveLayout;
|
||||||
if (Layout<>nil) and (Layout.Form<>nil) and (Layout.Form.Parent=nil)
|
if (Layout<>nil) and (Layout.Form<>nil) and (Layout.Form.Parent=nil) then begin
|
||||||
then begin
|
if (Layout.WindowPlacement in [iwpCustomPosition,iwpRestoreWindowGeometry]) then
|
||||||
if (Layout.WindowPlacement in [iwpCustomPosition,iwpRestoreWindowGeometry])
|
Layout.SetNewBounds; // Adjust bounds to screen area and apply them.
|
||||||
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;
|
|
||||||
Layout.ApplyDivider(True);
|
Layout.ApplyDivider(True);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|||||||
@ -233,6 +233,7 @@ type
|
|||||||
procedure SaveToConfig(Config: TConfigStorage; const Path: string);
|
procedure SaveToConfig(Config: TConfigStorage; const Path: string);
|
||||||
function CustomCoordinatesAreValid: boolean;
|
function CustomCoordinatesAreValid: boolean;
|
||||||
procedure CloseForm;
|
procedure CloseForm;
|
||||||
|
function SetNewBounds: Boolean;
|
||||||
public
|
public
|
||||||
property FormID: string read GetFormID write FFormID;
|
property FormID: string read GetFormID write FFormID;
|
||||||
function FormBaseID(out SubIndex: Integer): String; // split FormID into name+number
|
function FormBaseID(out SubIndex: Integer): String; // split FormID into name+number
|
||||||
@ -1029,8 +1030,8 @@ var
|
|||||||
begin
|
begin
|
||||||
inherited Create(nil);
|
inherited Create(nil);
|
||||||
FDividers := TSimpleWindowLayoutDividerPosList.Create;
|
FDividers := TSimpleWindowLayoutDividerPosList.Create;
|
||||||
FormID:=AFormID;
|
FormID := AFormID;
|
||||||
fDefaultWindowPlacement:=iwpRestoreWindowGeometry;
|
fDefaultWindowPlacement := iwpRestoreWindowGeometry;
|
||||||
Clear;
|
Clear;
|
||||||
Creator := IDEWindowCreators.FindWithName(AFormID);
|
Creator := IDEWindowCreators.FindWithName(AFormID);
|
||||||
if Creator <> nil then
|
if Creator <> nil then
|
||||||
@ -1132,6 +1133,51 @@ begin
|
|||||||
Form:=nil;
|
Form:=nil;
|
||||||
end;
|
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;
|
function TSimpleWindowLayout.FormBaseID(out SubIndex: Integer): String;
|
||||||
var
|
var
|
||||||
i: Integer;
|
i: Integer;
|
||||||
@ -1225,7 +1271,7 @@ procedure TSimpleWindowLayout.Assign(Layout: TSimpleWindowLayout);
|
|||||||
begin
|
begin
|
||||||
Clear;
|
Clear;
|
||||||
FApplied:=Layout.Applied;
|
FApplied:=Layout.Applied;
|
||||||
Form:=Layout.Form;
|
FForm:=Layout.FForm;
|
||||||
fWindowPlacement:=Layout.fWindowPlacement;
|
fWindowPlacement:=Layout.fWindowPlacement;
|
||||||
fLeft:=Layout.fLeft;
|
fLeft:=Layout.fLeft;
|
||||||
fTop:=Layout.fTop;
|
fTop:=Layout.fTop;
|
||||||
@ -1245,7 +1291,7 @@ var
|
|||||||
begin
|
begin
|
||||||
Creator:=IDEWindowCreators.FindWithName(FormID);
|
Creator:=IDEWindowCreators.FindWithName(FormID);
|
||||||
if (Creator = nil) or (Creator.OnGetDividerSize = nil) then exit;
|
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
|
for i := 0 to FDividers.Count - 1 do begin
|
||||||
if FDividers[i].FId < 0 then continue;
|
if FDividers[i].FId < 0 then continue;
|
||||||
f := AForce;
|
f := AForce;
|
||||||
@ -1274,9 +1320,6 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function TSimpleWindowLayout.Apply: Boolean;
|
function TSimpleWindowLayout.Apply: Boolean;
|
||||||
var
|
|
||||||
NewBounds: TRect;
|
|
||||||
i: Integer;
|
|
||||||
begin
|
begin
|
||||||
Result := False;
|
Result := False;
|
||||||
if fForm = nil then exit;
|
if fForm = nil then exit;
|
||||||
@ -1284,8 +1327,7 @@ begin
|
|||||||
{$IFDEF VerboseIDEDocking}
|
{$IFDEF VerboseIDEDocking}
|
||||||
debugln(['TSimpleWindowLayoutList.ApplyAndShow restore ',
|
debugln(['TSimpleWindowLayoutList.ApplyAndShow restore ',
|
||||||
FormID,' ',IDEWindowPlacementNames[WindowPlacement],
|
FormID,' ',IDEWindowPlacementNames[WindowPlacement],
|
||||||
' Valid=',CustomCoordinatesAreValid,' ',Left,',',
|
' ',Left,',',Top,',',Width,',',Height]);
|
||||||
Top,',',Width,',',Height]);
|
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
|
||||||
case WindowPlacement of
|
case WindowPlacement of
|
||||||
@ -1296,46 +1338,7 @@ begin
|
|||||||
iwsMinimized: FForm.WindowState:=wsMinimized;
|
iwsMinimized: FForm.WindowState:=wsMinimized;
|
||||||
iwsMaximized: FForm.WindowState:=wsMaximized;
|
iwsMaximized: FForm.WindowState:=wsMaximized;
|
||||||
end;
|
end;
|
||||||
|
Result := SetNewBounds; // Adjust bounds to screen area and apply them.
|
||||||
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;
|
|
||||||
|
|
||||||
if WindowState in [iwsMinimized, iwsMaximized] then
|
if WindowState in [iwsMinimized, iwsMaximized] then
|
||||||
Result := True;
|
Result := True;
|
||||||
end;
|
end;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user