dockmanager example: fixed resize bug in reload layout

git-svn-id: trunk@25326 -
This commit is contained in:
dodi 2010-05-12 05:19:02 +00:00
parent e2bde5f2a6
commit 7684d0756d
5 changed files with 69 additions and 17 deletions

View File

@ -55,8 +55,10 @@ end;
procedure TMasterSite.buRestoreClick(Sender: TObject); procedure TMasterSite.buRestoreClick(Sender: TObject);
begin begin
if ms <> nil then if ms <> nil then begin
ms.Position := 0; //rewind
DockMaster.LoadFromStream(ms); DockMaster.LoadFromStream(ms);
end;
end; end;
procedure TMasterSite.buSaveClick(Sender: TObject); procedure TMasterSite.buSaveClick(Sender: TObject);

View File

@ -123,7 +123,8 @@ type
FTree: TEasyTree; FTree: TEasyTree;
FFirstChild, FFirstChild,
FNextSibling, FPrevSibling, FParent: TEasyZone; FNextSibling, FPrevSibling, FParent: TEasyZone;
FOrientation: TDockOrientation; FZoneOrientation, //true orientation
FOrientation: TDockOrientation; //Delphi compatible (doNone when containing a control)
procedure SetControl(Control: TControl); procedure SetControl(Control: TControl);
procedure SetOrientation(NewOrientation: TDockOrientation); procedure SetOrientation(NewOrientation: TDockOrientation);
function GetLeft: Integer; function GetLeft: Integer;
@ -139,8 +140,10 @@ type
procedure SetBounds(TLBR: TRect); procedure SetBounds(TLBR: TRect);
function GetHandle: HWND; function GetHandle: HWND;
{$IFDEF visibility} //to be redesigned
function GetVisible: boolean; function GetVisible: boolean;
function GetVisibleControl: TControl; function GetVisibleControl: TControl;
{$ENDIF}
function GetPartRect(APart: TEasyZonePart): TRect; function GetPartRect(APart: TEasyZonePart): TRect;
function GetStyle: TEasyHeaderStyle; function GetStyle: TEasyHeaderStyle;
public public
@ -163,7 +166,7 @@ type
property Parent: TEasyZone read FParent write SetParent; property Parent: TEasyZone read FParent write SetParent;
property Orientation: TDockOrientation read FOrientation write SetOrientation; property Orientation: TDockOrientation read FOrientation write SetOrientation;
property Style: TEasyHeaderStyle read GetStyle; property Style: TEasyHeaderStyle read GetStyle;
property Visible: boolean read GetVisible; //property Visible: boolean read GetVisible;
property Bottom: integer read BR.Y; property Bottom: integer read BR.Y;
property Left: integer read GetLeft; property Left: integer read GetLeft;
@ -982,10 +985,18 @@ begin
Control.Visible := False; Control.Visible := False;
DockSite.Invalidate; DockSite.Invalidate;
{$ELSE} {$ELSE}
(* Definitely close a form, but other controls???
*)
if Control is TCustomForm then begin
TCustomForm(Control).Close;
Control.ManualDock(nil, nil, alNone); //do float Control.ManualDock(nil, nil, alNone); //do float
TWinControlAccess(Control).DoEndDock(nil, Control.Left, Control.Top);
end else begin
{ TODO -cLCL : OnEndDock not called by ManualDock? } { TODO -cLCL : OnEndDock not called by ManualDock? }
//TWinControlAccess(Control).DoEndDock(nil, Control.Left, Control.Top); Control.ManualDock(nil, nil, alNone); //do float
TWinControlAccess(Control).DoEndDock(nil, Control.Left, Control.Top);
Control.Visible := False; Control.Visible := False;
end;
{$ENDIF} {$ENDIF}
end; end;
end; end;
@ -1196,6 +1207,7 @@ procedure TEasyTree.LoadFromStream(Stream: TStream);
PrevZone, NewZone: TEasyZone; PrevZone, NewZone: TEasyZone;
PrevLvl, NewLvl: byte; PrevLvl, NewLvl: byte;
NewCtl: TControl; NewCtl: TControl;
r: TRect;
begin begin
PrevZone := FTopZone; PrevZone := FTopZone;
PrevLvl := 1; PrevLvl := 1;
@ -1218,9 +1230,13 @@ procedure TEasyTree.LoadFromStream(Stream: TStream);
NewZone.ChildControl := NewCtl; NewZone.ChildControl := NewCtl;
SetReplacingControl(NewCtl); //prevent DockManager actions SetReplacingControl(NewCtl); //prevent DockManager actions
NewCtl.ManualDock(DockSite); NewCtl.ManualDock(DockSite);
NewCtl.Width := ZoneRec.BottomRight.x; //NewCtl.DisableAutoSizing; //forever?
NewCtl.Height := ZoneRec.BottomRight.y; r := NewZone.GetPartRect(zpClient);
NewCtl.BoundsRect := r;
DebugLn('?NewCtl w=%d=%d h=%d=%d', [NewCtl.Width, ZoneRec.BottomRight.x,NewCtl.Height, ZoneRec.BottomRight.y]);
NewCtl.Visible := True; NewCtl.Visible := True;
//NewCtl.EnableAutoSizing;
DebugLn('!NewCtl w=%d=%d h=%d=%d', [NewCtl.Width, ZoneRec.BottomRight.x,NewCtl.Height, ZoneRec.BottomRight.y]);
end; end;
{$IFDEF oldOrient} {$IFDEF oldOrient}
{$ELSE} {$ELSE}
@ -1243,19 +1259,23 @@ procedure TEasyTree.LoadFromStream(Stream: TStream);
end; end;
begin begin
(* Problem: what if site doesn't match zone extent?
*)
//remove all docked controls //remove all docked controls
ClearSite; ClearSite;
//read record //read record
if GetRec > 0 then begin if GetRec > 0 then begin
FSiteRect.BottomRight := ZoneRec.BottomRight; //stored extent, not current one!
FTopZone.BR := ZoneRec.BottomRight; FTopZone.BR := ZoneRec.BottomRight;
FTopZone.Orientation := ZoneRec.Orientation; FTopZone.Orientation := ZoneRec.Orientation;
MakeZones; MakeZones;
//now make the zone fit the current extent, and position all child controls
//DebugLn('fit zone ', DbgS(FTopZone.BR), ' into site ', DbgS(FDockSite.ClientRect.BottomRight));
ResetBounds(True); //always position controls!
//finish?
//remove all leafs without a child control?
end; end;
//finish? //assure everything is visible (recursive, until topmost parent)
//remove all leafs without a child control?
//refresh the site
ResetBounds(True);
//assure everything is visible
MakeVisible(FDockSite); MakeVisible(FDockSite);
end; end;
@ -1574,6 +1594,8 @@ begin
Result := FTree.FDockSite; Result := FTree.FDockSite;
end; end;
{$IFDEF visibility}
function TEasyZone.GetVisible: boolean; function TEasyZone.GetVisible: boolean;
begin begin
Result := GetVisibleControl <> nil; Result := GetVisibleControl <> nil;
@ -1598,6 +1620,7 @@ begin
zone := zone.NextSibling; zone := zone.NextSibling;
end; end;
end; end;
{$ENDIF}
function TEasyZone.GetPartRect(APart: TEasyZonePart): TRect; function TEasyZone.GetPartRect(APart: TEasyZonePart): TRect;
begin begin
@ -1810,6 +1833,7 @@ end;
procedure TEasyZone.SetOrientation(NewOrientation: TDockOrientation); procedure TEasyZone.SetOrientation(NewOrientation: TDockOrientation);
begin begin
FZoneOrientation := NewOrientation; //independent from ChildControl
if ChildControl = nil then if ChildControl = nil then
FOrientation := NewOrientation FOrientation := NewOrientation
else else
@ -1830,7 +1854,12 @@ begin
if (fTop = (zone.Parent.Orientation = doVertical)) then begin if (fTop = (zone.Parent.Orientation = doVertical)) then begin
prev := zone.PrevSibling; prev := zone.PrevSibling;
while prev <> nil do begin while prev <> nil do begin
if prev.Visible then begin {$IFDEF visibility}
if prev.Visible then
{$ELSE}
//zones are always visible
{$ENDIF}
begin
if fTop then if fTop then
Result := prev.Bottom Result := prev.Bottom
else else

View File

@ -3,6 +3,8 @@ object FloatingSite: TFloatingSite
Height = 265 Height = 265
Top = 498 Top = 498
Width = 377 Width = 377
HorzScrollBar.Visible = False
VertScrollBar.Visible = False
Caption = 'FloatingSite' Caption = 'FloatingSite'
DockSite = True DockSite = True
OnClose = FormClose OnClose = FormClose

View File

@ -147,6 +147,7 @@ Fix: disallow TControls to become floating.
*) *)
//try to distinguish between TControl and TWinControl (TCustomForm?) //try to distinguish between TControl and TWinControl (TCustomForm?)
Allow := (NewTarget <> nil) or (Client is TWinControl); //seems to be safe Allow := (NewTarget <> nil) or (Client is TWinControl); //seems to be safe
DebugLn('TFloatingSite undodock, allow ', DbgS(Allow));
if not Allow then if not Allow then
exit; //all done exit; //all done

View File

@ -463,7 +463,9 @@ Notebooks?
//adjust host form //adjust host form
if site.DockManager = nil then if site.DockManager = nil then
TAppDockManager.Create(site); TAppDockManager.Create(site);
site.DisableAutoSizing;
site.DockManager.LoadFromStream(Stream); site.DockManager.LoadFromStream(Stream);
site.EnableAutoSizing;
site.Show; site.Show;
end; end;
end; end;
@ -739,6 +741,7 @@ const
hds: boolean; hds: boolean;
Site: TWinControl; Site: TWinControl;
j: integer; j: integer;
r: TRect;
begin begin
ctl := ASite; ctl := ASite;
s := Format('Site=%s (%d,%d)[%d,%d]', [SiteName(ctl), s := Format('Site=%s (%d,%d)[%d,%d]', [SiteName(ctl),
@ -747,8 +750,13 @@ const
hds := ctl.HostDockSite <> nil; hds := ctl.HostDockSite <> nil;
if hds then begin if hds then begin
Site := ctl.HostDockSite; Site := ctl.HostDockSite;
if Site <> nil then if Site <> nil then begin
n := ' in ' + SiteName(Site) + '@' + OrientString[ctl.DockOrientation]; n := ' in ' + SiteName(Site) + '@' + OrientString[ctl.DockOrientation];
if assigned(Site.DockManager) then begin
Site.DockManager.GetControlBounds(ctl, r);
n := n + Format(' in [%d,%d]', [r.Right, r.Bottom]);
end;
end;
end else begin end else begin
Site := ctl.Parent; Site := ctl.Parent;
if Site <> nil then if Site <> nil then
@ -767,6 +775,12 @@ const
s := OrientString[ctl.DockOrientation]; s := OrientString[ctl.DockOrientation];
DebugLn(' %s.Client=%s.%s@%s (%d,%d)[%d,%d]', [SiteName(ASite), ctl.Owner.Name, SiteName(ctl), s, DebugLn(' %s.Client=%s.%s@%s (%d,%d)[%d,%d]', [SiteName(ASite), ctl.Owner.Name, SiteName(ctl), s,
ctl.Left, ctl.Top, ctl.Width, ctl.Height]); ctl.Left, ctl.Top, ctl.Width, ctl.Height]);
if assigned(Site.DockManager) then begin
Site.DockManager.GetControlBounds(ctl, r);
//n := Format(' in [%d,%d]', [r.Right, r.Bottom]);
//DebugLn(n);
DebugLn(' in ', DbgS(r));
end;
//if ctl is TFloatingSite then //if ctl is TFloatingSite then
if (ctl is TWinControl) and wc.DockSite then if (ctl is TWinControl) and wc.DockSite then
DumpSite(wc); DumpSite(wc);
@ -778,6 +792,8 @@ var
cmp: TComponent; cmp: TComponent;
wc: TWinControl absolute cmp; wc: TWinControl absolute cmp;
ctl: TControl absolute cmp; ctl: TControl absolute cmp;
//zone: TEasyZone;
r: TRect;
begin begin
(* Dump registered docking sites. (* Dump registered docking sites.
Elastic panels have no name. Elastic panels have no name.
@ -795,8 +811,10 @@ begin
if (cmp is TWinControl) and wc.DockSite then if (cmp is TWinControl) and wc.DockSite then
DumpSite(wc) DumpSite(wc)
else if ctl is TControl then begin else if ctl is TControl then begin
DebugLn('Client=%s in %s (%d,%d)[%d,%d]', [SiteName(ctl), SiteName(ctl.HostDockSite), wc.DockManager.GetControlBounds(ctl, r);
ctl.Left, ctl.Top, ctl.Width, ctl.Height]); DebugLn('Client=%s in %s (%d,%d)[%d,%d] in [%d,%d]', [SiteName(ctl), SiteName(ctl.HostDockSite),
ctl.Left, ctl.Top, ctl.Width, ctl.Height,
r.Right, r.Bottom]);
end; end;
end; end;
DebugLn('--- dump forms ---'); DebugLn('--- dump forms ---');