AnchorDocking: Fixed second bug with option FloatingWindowsOnTop - a loaded layout doesn't encounter option on visible windows. Issue #19272

git-svn-id: trunk@65046 -
This commit is contained in:
michl 2021-04-21 20:51:22 +00:00
parent 15fda0e828
commit db4bb52bc2

View File

@ -90,6 +90,8 @@
unit AnchorDocking; unit AnchorDocking;
{$mode objfpc}{$H+} {$mode objfpc}{$H+}
{$modeswitch advancedrecords}
{$modeswitch typehelpers}
// better use this definitions in project options, as it used in other units too // better use this definitions in project options, as it used in other units too
{ $DEFINE VerboseAnchorDockRestore} { $DEFINE VerboseAnchorDockRestore}
@ -586,6 +588,23 @@ type
var AControl: TControl; DoDisableAutoSizing: boolean) of object; var AControl: TControl; DoDisableAutoSizing: boolean) of object;
TADShowDockMasterOptionsEvent = function(aDockMaster: TAnchorDockMaster): TModalResult; TADShowDockMasterOptionsEvent = function(aDockMaster: TAnchorDockMaster): TModalResult;
{ TStyleOfForm }
TStyleOfForm = record
Form: TCustomForm;
FormStyle: TFormStyle;
class operator = (Item1, Item2: TStyleOfForm): Boolean;
end;
{ TFormStyles }
TFormStyles = class(specialize TFPGList<TStyleOfForm>)
public
procedure AddForm(const AForm: TCustomForm);
function IndexOfForm(const AForm: TCustomForm): Integer;
procedure RemoveForm(const AForm: TCustomForm);
end;
TAnchorDockMaster = class(TComponent) TAnchorDockMaster = class(TComponent)
private private
FAllowDragging: boolean; FAllowDragging: boolean;
@ -594,6 +613,7 @@ type
FDockParentMargin: integer; FDockParentMargin: integer;
FDragTreshold: integer; FDragTreshold: integer;
FFloatingWindowsOnTop: boolean; FFloatingWindowsOnTop: boolean;
FFormStyles: TFormStyles;
FHeaderAlignLeft: integer; FHeaderAlignLeft: integer;
FHeaderAlignTop: integer; FHeaderAlignTop: integer;
FHeaderClass: TAnchorDockHeaderClass; FHeaderClass: TAnchorDockHeaderClass;
@ -650,6 +670,7 @@ type
procedure MapTreeToControls(Tree: TAnchorDockLayoutTree); procedure MapTreeToControls(Tree: TAnchorDockLayoutTree);
function RestoreLayout(Tree: TAnchorDockLayoutTree; Scale: boolean): boolean; function RestoreLayout(Tree: TAnchorDockLayoutTree; Scale: boolean): boolean;
procedure ScreenFormAdded(Sender: TObject; Form: TCustomForm); procedure ScreenFormAdded(Sender: TObject; Form: TCustomForm);
procedure ScreenRemoveForm(Sender: TObject; Form: TCustomForm);
procedure SetMinimizedState(Tree: TAnchorDockLayoutTree); procedure SetMinimizedState(Tree: TAnchorDockLayoutTree);
procedure UpdateHeaders; procedure UpdateHeaders;
procedure SetNodeMinimizedState(ANode: TAnchorDockLayoutTreeNode); procedure SetNodeMinimizedState(ANode: TAnchorDockLayoutTreeNode);
@ -1588,6 +1609,45 @@ begin
SplitterWidth := Config.GetValue(Path+'SplitterWidth',4); SplitterWidth := Config.GetValue(Path+'SplitterWidth',4);
end; end;
{ TStyleOfForm }
class operator TStyleOfForm. = (Item1, Item2: TStyleOfForm): Boolean;
begin
Result := (Item1.Form = Item2.Form) and
(Item1.FormStyle = Item2.FormStyle);
end;
{ TFormStyles }
procedure TFormStyles.AddForm(const AForm: TCustomForm);
var
AStyleOfForm: TStyleOfForm;
begin
if not Assigned(AForm) then Exit;
if IndexOfForm(AForm) >= 0 then Exit;
AStyleOfForm.Form := AForm;
AStyleOfForm.FormStyle := AForm.FormStyle;
Add(AStyleOfForm);
end;
function TFormStyles.IndexOfForm(const AForm: TCustomForm): Integer;
var
i: Integer;
begin
for i := 0 to Count - 1 do
if Self[i].Form = AForm then Exit(i);
Result := -1;
end;
procedure TFormStyles.RemoveForm(const AForm: TCustomForm);
var
AIndex: Integer;
begin
AIndex := IndexOfForm(AForm);
if AIndex < 0 then Exit;
Delete(AIndex);
end;
{ TAnchorDockMaster } { TAnchorDockMaster }
function TAnchorDockMaster.GetControls(Index: integer): TControl; function TAnchorDockMaster.GetControls(Index: integer): TControl;
@ -2366,9 +2426,15 @@ end;
procedure TAnchorDockMaster.ScreenFormAdded(Sender: TObject; Form: TCustomForm); procedure TAnchorDockMaster.ScreenFormAdded(Sender: TObject; Form: TCustomForm);
begin begin
FFormStyles.AddForm(Form);
Form.AddHandlerFirstShow(@FormFirstShow); Form.AddHandlerFirstShow(@FormFirstShow);
end; end;
procedure TAnchorDockMaster.ScreenRemoveForm(Sender: TObject; Form: TCustomForm);
begin
FFormStyles.RemoveForm(Form);
end;
function TAnchorDockMaster.DoCreateControl(aName: string; function TAnchorDockMaster.DoCreateControl(aName: string;
DisableAutoSizing: boolean): TControl; DisableAutoSizing: boolean): TControl;
begin begin
@ -2718,24 +2784,37 @@ end;
procedure TAnchorDockMaster.SetFloatingWindowsOnTop(AValue: boolean); procedure TAnchorDockMaster.SetFloatingWindowsOnTop(AValue: boolean);
var var
i: Integer; i, AIndex: Integer;
AWinControl: TWinControl; AForm, ParentForm: TCustomForm;
IsMainForm: Boolean;
AFormStyle: TFormStyle;
begin begin
if FFloatingWindowsOnTop = AValue then Exit; if FFloatingWindowsOnTop = AValue then Exit;
FFloatingWindowsOnTop := AValue; FFloatingWindowsOnTop := AValue;
for i:=0 to Screen.FormCount-1 do for i:=0 to Screen.FormCount-1 do
begin begin
AWinControl := Screen.Forms[i]; AForm := Screen.Forms[i];
while Assigned(AWinControl) and not (AWinControl is TAnchorDockHostSite) do ParentForm := GetParentForm(AForm);
AWinControl := AWinControl.Parent; IsMainForm := (AForm = Application.MainForm)
if not (AWinControl is TAnchorDockHostSite) then Continue; or (AForm.IsParentOf(Application.MainForm))
or (ParentForm = Application.MainForm);
if IsMainForm then Continue;
if AValue then if AValue then
TAnchorDockHostSite(AWinControl).FormStyle := fsStayOnTop AFormStyle := fsStayOnTop
else else begin
begin AIndex := FFormStyles.IndexOfForm(AForm);
TAnchorDockHostSite(AWinControl).FormStyle := fsNormal; if AIndex >= 0 then
TAnchorDockHostSite(AWinControl).CheckFormStyle; AFormStyle := FFormStyles[AIndex].FormStyle
else
AFormStyle := fsNormal;
end; end;
if ParentForm is TAnchorDockHostSite then
begin
ParentForm.FormStyle := AFormStyle;
TAnchorDockHostSite(ParentForm).CheckFormStyle;
Continue;
end;
AForm.FormStyle := AFormStyle;
end; end;
OptionsChanged; OptionsChanged;
end; end;
@ -2944,6 +3023,7 @@ end;
constructor TAnchorDockMaster.Create(AOwner: TComponent); constructor TAnchorDockMaster.Create(AOwner: TComponent);
begin begin
inherited Create(AOwner); inherited Create(AOwner);
FFormStyles:=TFormStyles.Create;
FControls:=TFPList.Create; FControls:=TFPList.Create;
FAllowDragging:=true; FAllowDragging:=true;
FDragTreshold:=4; FDragTreshold:=4;
@ -2979,6 +3059,7 @@ begin
FAllClosing:=False; FAllClosing:=False;
FHeaderStyleName2ADHeaderStyle:=THeaderStyleName2ADHeaderStylesMap.create; FHeaderStyleName2ADHeaderStyle:=THeaderStyleName2ADHeaderStylesMap.create;
Screen.AddHandlerFormAdded(@ScreenFormAdded); Screen.AddHandlerFormAdded(@ScreenFormAdded);
Screen.AddHandlerRemoveForm(@ScreenRemoveForm);
end; end;
destructor TAnchorDockMaster.Destroy; destructor TAnchorDockMaster.Destroy;
@ -2986,6 +3067,8 @@ var
AControl: TControl; AControl: TControl;
i, j: Integer; i, j: Integer;
begin begin
Screen.RemoveHandlerFormAdded(@ScreenFormAdded);
Screen.RemoveHandlerRemoveForm(@ScreenRemoveForm);
QueueSimplify:=false; QueueSimplify:=false;
FreeAndNil(FRestoreLayouts); FreeAndNil(FRestoreLayouts);
FreeAndNil(fPopupMenu); FreeAndNil(fPopupMenu);
@ -3014,6 +3097,7 @@ begin
end; end;
end; end;
FreeAndNil(FHeaderStyleName2ADHeaderStyle); FreeAndNil(FHeaderStyleName2ADHeaderStyle);
FreeAndNil(FFormStyles);
inherited Destroy; inherited Destroy;
end; end;