Ignore:
Timestamp:
Mar 9, 2011, 10:56:47 AM (14 years ago)
Author:
george
Message:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Docking/CoolDocking/UCoolDockLayout.pas

    r180 r181  
    77uses
    88  Classes, SysUtils, FileUtil, Contnrs, URectangle, Forms, UCoolDockCommon,
    9   DOM, XMLWrite, XMLRead;
     9  DOM, XMLWrite, XMLRead, Controls;
    1010
    1111type
     12  TCoolDockLayout = class;
    1213
    1314  { TCoolDockLayoutItem }
    1415
    1516  TCoolDockLayoutItem = class
     17    Parent: TCoolDockLayout;
    1618    Name: string;
     19    StoredClassName: string;
    1720    ParentName: string;
     21    HostDockSiteName: string;
    1822    Caption: string;
    1923    Visible: Boolean;
     
    2529    procedure SaveToNode(Node: TDOMNode);
    2630    procedure LoadFromNode(Node: TDOMNode);
     31    procedure Store(Form: TWinControl);
     32    procedure Restore(Form: TWinControl);
    2733    constructor Create;
    2834    destructor Destroy; override;
     
    3642    procedure SaveToNode(Node: TDOMNode);
    3743    procedure LoadFromNode(Node: TDOMNode);
     44    function FindByName(Name: string): TCoolDockLayoutItem;
    3845    constructor Create;
    3946    destructor Destroy; override;
     
    6067
    6168implementation
     69
     70uses
     71  UCoolDocking;
    6272
    6373procedure Register;
     
    180190  I := 0;
    181191  while (I < Items.Count) and (TCoolDockLayout(Items[I]).Name <> Name) do Inc(I);
    182   if I < Items.Count then Result := TCoolDockLayout(Items[I]) else Result := nil;
     192  if I < Items.Count then Result := TCoolDockLayout(Items[I])
     193    else Result := nil;
    183194end;
    184195
     
    196207    NewNode.TextContent := UTF8Decode(ParentName);
    197208    AppendChild(NewNode);
     209    NewNode := OwnerDocument.CreateElement('StoredClassName');
     210    NewNode.TextContent := UTF8Decode(StoredClassName);
     211    AppendChild(NewNode);
     212    NewNode := OwnerDocument.CreateElement('HostDockSiteName');
     213    NewNode.TextContent := UTF8Decode(HostDockSiteName);
     214    AppendChild(NewNode);
    198215    NewNode := OwnerDocument.CreateElement('Caption');
    199216    NewNode.TextContent := UTF8Decode(Caption);
     
    252269    if Assigned(NewNode) then
    253270      ParentName := UTF8Encode(NewNode.TextContent);
     271    NewNode := FindNode('StoredClassName');
     272    if Assigned(NewNode) then
     273      StoredClassName := UTF8Encode(NewNode.TextContent);
     274    NewNode := FindNode('HostDockSiteName');
     275    if Assigned(NewNode) then
     276      HostDockSiteName := UTF8Encode(NewNode.TextContent);
    254277    NewNode := FindNode('Caption');
    255278    if Assigned(NewNode) then
     
    294317    if Assigned(NewNode) then
    295318      RestoredRect.Height := StrToInt(NewNode.TextContent);
     319  end;
     320end;
     321
     322procedure TCoolDockLayoutItem.Store(Form: TWinControl);
     323var
     324  NewItem: TCoolDockLayoutItem;
     325begin
     326  Name := Form.Name;
     327  StoredClassName := Form.ClassName;
     328  Caption := Form.Caption;
     329  UndockSize.X := Form.UndockWidth;
     330  UndockSize.Y := Form.UndockHeight;
     331  Visible := Form.Visible;
     332  Rect.Left := Form.Left;
     333  Rect.Top := Form.Top;
     334  Rect.Width := Form.Width;
     335  Rect.Height := Form.Height;
     336  if Form is TForm then begin
     337    RestoredRect.Left := TForm(Form).RestoredLeft;
     338    RestoredRect.Top := TForm(Form).RestoredTop;
     339    RestoredRect.Width := TForm(Form).RestoredWidth;
     340    RestoredRect.Height := TForm(Form).RestoredHeight;
     341    WindowState := TForm(Form).WindowState;
     342  end;
     343  if Assigned(Form.Parent) then
     344    ParentName := Form.Parent.Name
     345    else ParentName := '';
     346  if Assigned(Form.HostDockSite) then begin
     347    if Assigned(Form.HostDockSite.Parent) and (Form.HostDockSite.Parent is TForm) then
     348    begin
     349      HostDockSiteName := Form.HostDockSite.Parent.Name;
     350      if not Assigned(Parent.FindByName(HostDockSiteName)) then begin
     351        NewItem := TCoolDockLayoutItem.Create;
     352        NewItem.Parent := Parent;
     353        NewItem.Store(Form.HostDockSite.Parent);
     354        Parent.Items.Add(NewItem);
     355      end;
     356    end;
     357  end else HostDockSiteName := '';
     358end;
     359
     360procedure TCoolDockLayoutItem.Restore(Form: TWinControl);
     361var
     362  ParentComponent: TComponent;
     363  ParentLayoutItem: TCoolDockLayoutItem;
     364  FormClass: TFormClass;
     365begin
     366  if Form is TForm then
     367  if WindowState = wsMaximized then begin
     368    TForm(Form).SetRestoredBounds(RestoredRect.Left, RestoredRect.Top,
     369      RestoredRect.Width, RestoredRect.Height);
     370    TForm(Form).WindowState := WindowState;
     371  end else begin
     372    TForm(Form).WindowState := WindowState;
     373    TForm(Form).SetRestoredBounds(RestoredRect.Left, RestoredRect.Top,
     374      RestoredRect.Width, RestoredRect.Height);
     375  end;
     376  Form.Name := Name;
     377  Form.Caption := Caption;
     378  Form.SetBounds(Rect.Left, Rect.Top, Rect.Width, Rect.Height);
     379  Form.UndockWidth := UndockSize.X;
     380  Form.UndockHeight := UndockSize.Y;
     381  Form.Visible := Visible;
     382  if HostDockSiteName <> '' then begin
     383    ParentComponent := FindGlobalComponent(HostDockSiteName);
     384    if not Assigned(ParentComponent) then begin
     385      ParentLayoutItem := Parent.FindByName(HostDockSiteName);
     386      if Assigned(ParentLayoutItem) then begin
     387        if ParentLayoutItem.StoredClassName <> '' then begin
     388          //ParentComponent := TComponent(FindClass(ParentLayoutItem.StoredClassName).Create);
     389          if (ParentLayoutItem.StoredClassName = 'TCoolDockConjoinForm') then begin
     390            FormClass := TFormClass(FindClass('TCoolDockConjoinForm'));
     391            if FormClass = TCoolDockConjoinForm then begin
     392              ParentComponent := TCoolDockConjoinForm.Create(Application);
     393              ParentLayoutItem.Restore(TWinControl(ParentComponent));
     394            end;
     395          end;
     396        end;
     397      end;
     398    end;
     399    if Assigned(ParentComponent) and (ParentComponent is TCoolDockConjoinForm) then
     400      Form.ManualDock(TCoolDockConjoinForm(ParentComponent).Panel);
    296401  end;
    297402end;
     
    349454      while Assigned(Child) do begin
    350455        NewItem := TCoolDockLayoutItem.Create;
     456        NewItem.Parent := Self;
    351457        NewItem.LoadFromNode(Child);
    352458        Items.Add(NewItem);
     
    357463end;
    358464
     465function TCoolDockLayout.FindByName(Name: string): TCoolDockLayoutItem;
     466var
     467  I: Integer;
     468begin
     469  I := 0;
     470  while (I < Items.Count) and (TCoolDockLayoutItem(Items[I]).Name <> Name) do Inc(I);
     471  if I < Items.Count then Result := TCoolDockLayoutItem(Items[I])
     472    else Result := nil;
     473end;
     474
    359475constructor TCoolDockLayout.Create;
    360476begin
     
    379495    Form := (Application.Components[I] as TForm);
    380496    NewItem := TCoolDockLayoutItem.Create;
    381     NewItem.Name := Form.Name;
    382     NewItem.Caption := Form.Caption;
    383     NewItem.UndockSize.X := Form.UndockWidth;
    384     NewItem.UndockSize.Y := Form.UndockHeight;
    385     NewItem.Visible := Form.Visible;
    386     NewItem.Rect.Left := Form.Left;
    387     NewItem.Rect.Top := Form.Top;
    388     NewItem.Rect.Width := Form.Width;
    389     NewItem.Rect.Height := Form.Height;
    390     NewItem.RestoredRect.Left := Form.RestoredLeft;
    391     NewItem.RestoredRect.Top := Form.RestoredTop;
    392     NewItem.RestoredRect.Width := Form.RestoredWidth;
    393     NewItem.RestoredRect.Height := Form.RestoredHeight;
    394     NewItem.WindowState := Form.WindowState;
     497    NewItem.Parent := Self;
     498    NewItem.Store(Form);
    395499    Items.Add(NewItem);
    396500  end;
     
    405509  with TCoolDockLayoutItem(Items[I]) do begin
    406510    Form := TForm(Application.FindComponent(Name));
    407     if WindowState = wsMaximized then begin
    408       Form.SetRestoredBounds(RestoredRect.Left, RestoredRect.Top,
    409         RestoredRect.Width, RestoredRect.Height);
    410       Form.WindowState := WindowState;
    411     end else begin
    412       Form.WindowState := WindowState;
    413       Form.SetRestoredBounds(RestoredRect.Left, RestoredRect.Top,
    414         RestoredRect.Width, RestoredRect.Height);
    415     end;
    416     Form.Caption := Caption;
    417     Form.SetBounds(Rect.Left, Rect.Top, Rect.Width, Rect.Height);
    418     Form.UndockWidth := UndockSize.X;
    419     Form.UndockHeight := UndockSize.Y;
    420     Form.Visible := Visible;
     511    if Assigned(Form) then Restore(Form);
    421512  end;
    422513end;
Note: See TracChangeset for help on using the changeset viewer.