Changeset 181 for Docking/CoolDocking/UCoolDockLayout.pas
- Timestamp:
- Mar 9, 2011, 10:56:47 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Docking/CoolDocking/UCoolDockLayout.pas
r180 r181 7 7 uses 8 8 Classes, SysUtils, FileUtil, Contnrs, URectangle, Forms, UCoolDockCommon, 9 DOM, XMLWrite, XMLRead ;9 DOM, XMLWrite, XMLRead, Controls; 10 10 11 11 type 12 TCoolDockLayout = class; 12 13 13 14 { TCoolDockLayoutItem } 14 15 15 16 TCoolDockLayoutItem = class 17 Parent: TCoolDockLayout; 16 18 Name: string; 19 StoredClassName: string; 17 20 ParentName: string; 21 HostDockSiteName: string; 18 22 Caption: string; 19 23 Visible: Boolean; … … 25 29 procedure SaveToNode(Node: TDOMNode); 26 30 procedure LoadFromNode(Node: TDOMNode); 31 procedure Store(Form: TWinControl); 32 procedure Restore(Form: TWinControl); 27 33 constructor Create; 28 34 destructor Destroy; override; … … 36 42 procedure SaveToNode(Node: TDOMNode); 37 43 procedure LoadFromNode(Node: TDOMNode); 44 function FindByName(Name: string): TCoolDockLayoutItem; 38 45 constructor Create; 39 46 destructor Destroy; override; … … 60 67 61 68 implementation 69 70 uses 71 UCoolDocking; 62 72 63 73 procedure Register; … … 180 190 I := 0; 181 191 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; 183 194 end; 184 195 … … 196 207 NewNode.TextContent := UTF8Decode(ParentName); 197 208 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); 198 215 NewNode := OwnerDocument.CreateElement('Caption'); 199 216 NewNode.TextContent := UTF8Decode(Caption); … … 252 269 if Assigned(NewNode) then 253 270 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); 254 277 NewNode := FindNode('Caption'); 255 278 if Assigned(NewNode) then … … 294 317 if Assigned(NewNode) then 295 318 RestoredRect.Height := StrToInt(NewNode.TextContent); 319 end; 320 end; 321 322 procedure TCoolDockLayoutItem.Store(Form: TWinControl); 323 var 324 NewItem: TCoolDockLayoutItem; 325 begin 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 := ''; 358 end; 359 360 procedure TCoolDockLayoutItem.Restore(Form: TWinControl); 361 var 362 ParentComponent: TComponent; 363 ParentLayoutItem: TCoolDockLayoutItem; 364 FormClass: TFormClass; 365 begin 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); 296 401 end; 297 402 end; … … 349 454 while Assigned(Child) do begin 350 455 NewItem := TCoolDockLayoutItem.Create; 456 NewItem.Parent := Self; 351 457 NewItem.LoadFromNode(Child); 352 458 Items.Add(NewItem); … … 357 463 end; 358 464 465 function TCoolDockLayout.FindByName(Name: string): TCoolDockLayoutItem; 466 var 467 I: Integer; 468 begin 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; 473 end; 474 359 475 constructor TCoolDockLayout.Create; 360 476 begin … … 379 495 Form := (Application.Components[I] as TForm); 380 496 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); 395 499 Items.Add(NewItem); 396 500 end; … … 405 509 with TCoolDockLayoutItem(Items[I]) do begin 406 510 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); 421 512 end; 422 513 end;
Note:
See TracChangeset
for help on using the changeset viewer.