Changeset 191 for Docking/CoolDocking/UCDLayout.pas
- Timestamp:
- Mar 11, 2011, 10:07:38 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Docking/CoolDocking/UCDLayout.pas
r189 r191 21 21 HostDockSiteName: string; 22 22 Caption: string; 23 Visible: Boolean;23 Visible: boolean; 24 24 Rect: TRectangle; 25 25 RestoredRect: TRectangle; … … 27 27 UndockSize: TPoint; 28 28 DockStyle: TCDStyleType; 29 Processed: Boolean;29 Processed: boolean; 30 30 procedure SaveToNode(Node: TDOMNode); 31 31 procedure LoadFromNode(Node: TDOMNode); … … 79 79 function FindGlobalComponentDeep(Name: string): TComponent; 80 80 var 81 I: Integer; 82 begin 83 for I := 0 to Application.ComponentCount - 1 do begin 81 I: integer; 82 begin 83 for I := 0 to Application.ComponentCount - 1 do 84 begin 84 85 Result := Application.Components[I]; 85 if Result.Name = Name then Exit 86 else begin 87 Result := Result.FindComponent(Name); 88 if Assigned(Result) and (Result.Name = Name) then Exit; 89 end; 86 if Result.Name = Name then 87 Exit 88 else 89 begin 90 Result := Result.FindComponent(Name); 91 if Assigned(Result) and (Result.Name = Name) then 92 Exit; 93 end; 90 94 end; 91 95 end; … … 116 120 ReadXMLFile(Doc, Stream); 117 121 Items.Clear; 118 with Doc.DocumentElement do begin 122 with Doc.DocumentElement do 123 begin 119 124 NewNode := FindNode('Items'); 120 125 if Assigned(NewNode) then 121 with NewNode do begin 122 Child := FirstChild; 123 while Assigned(Child) do begin 124 NewItem := TCDLayout.Create; 125 NewItem.LoadFromNode(Child); 126 Items.Add(NewItem); 127 Child := Child.NextSibling; 126 with NewNode do 127 begin 128 Child := FirstChild; 129 while Assigned(Child) do 130 begin 131 NewItem := TCDLayout.Create; 132 NewItem.LoadFromNode(Child); 133 Items.Add(NewItem); 134 Child := Child.NextSibling; 135 end; 128 136 end; 129 end;130 137 end; 131 138 finally … … 138 145 Doc: TXMLDocument; 139 146 RootNode: TDOMNode; 140 I: Integer;147 I: integer; 141 148 NewNode: TDOMNode; 142 149 NewNode2: TDOMNode; … … 144 151 try 145 152 Doc := TXMLDocument.Create; 146 with Doc do begin 153 with Doc do 154 begin 147 155 RootNode := CreateElement('CoolDockLayout'); 148 156 AppendChild(RootNode); 149 with RootNode do begin 157 with RootNode do 158 begin 150 159 NewNode := OwnerDocument.CreateElement('Items'); 151 160 with NewNode do 152 for I := 0 to Items.Count - 1 do begin 153 NewNode2 := OwnerDocument.CreateElement('Layout'); 154 TCDLayout(Items[I]).SaveToNode(NewNode2); 155 AppendChild(NewNode2); 156 end; 161 for I := 0 to Items.Count - 1 do 162 begin 163 NewNode2 := OwnerDocument.CreateElement('Layout'); 164 TCDLayout(Items[I]).SaveToNode(NewNode2); 165 AppendChild(NewNode2); 166 end; 157 167 AppendChild(NewNode); 158 168 end; … … 181 191 begin 182 192 try 183 if FileExistsUTF8(FileName) then Stream := TFileStream.Create(FileName, fmOpenReadWrite) 184 else Stream := TFileStream.Create(FileName, fmCreate); 193 if FileExistsUTF8(FileName) then 194 Stream := TFileStream.Create(FileName, fmOpenReadWrite) 195 else 196 Stream := TFileStream.Create(FileName, fmCreate); 185 197 Stream.Size := 0; 186 198 SaveToStream(Stream); … … 192 204 procedure TCDLayoutList.PopulateStringList(List: TStrings); 193 205 var 194 I: Integer;206 I: integer; 195 207 begin 196 208 List.Clear; … … 201 213 function TCDLayoutList.FindByName(Name: string): TCDLayout; 202 214 var 203 I: Integer;215 I: integer; 204 216 begin 205 217 I := 0; 206 while (I < Items.Count) and (TCDLayout(Items[I]).Name <> Name) do Inc(I); 207 if I < Items.Count then Result := TCDLayout(Items[I]) 208 else Result := nil; 218 while (I < Items.Count) and (TCDLayout(Items[I]).Name <> Name) do 219 Inc(I); 220 if I < Items.Count then 221 Result := TCDLayout(Items[I]) 222 else 223 Result := nil; 209 224 end; 210 225 … … 215 230 NewNode: TDOMNode; 216 231 begin 217 with Node do begin 232 with Node do 233 begin 218 234 NewNode := OwnerDocument.CreateElement('Name'); 219 235 NewNode.TextContent := UTF8Decode(Name); … … 232 248 AppendChild(NewNode); 233 249 NewNode := OwnerDocument.CreateElement('WindowState'); 234 NewNode.TextContent := IntToStr( Integer(WindowState));250 NewNode.TextContent := IntToStr(integer(WindowState)); 235 251 AppendChild(NewNode); 236 252 NewNode := OwnerDocument.CreateElement('UndockWidth'); … … 256 272 AppendChild(NewNode); 257 273 NewNode := OwnerDocument.CreateElement('DockStyle'); 258 NewNode.TextContent := IntToStr( Integer(DockStyle));274 NewNode.TextContent := IntToStr(integer(DockStyle)); 259 275 AppendChild(NewNode); 260 276 NewNode := OwnerDocument.CreateElement('RestoredWidth'); … … 277 293 NewNode: TDOMNode; 278 294 begin 279 with TDOMElement(Node) do begin 295 with TDOMElement(Node) do 296 begin 280 297 NewNode := FindNode('Name'); 281 298 if Assigned(NewNode) then … … 349 366 Rect.Width := Form.Width; 350 367 Rect.Height := Form.Height; 351 if Form is TForm then begin 368 if Form is TForm then 369 begin 352 370 RestoredRect.Left := TForm(Form).RestoredLeft; 353 371 RestoredRect.Top := TForm(Form).RestoredTop; … … 358 376 if Assigned(Form.Parent) then 359 377 ParentName := Form.Parent.Name 360 else ParentName := ''; 361 if Assigned(Form.HostDockSite) then begin 378 else 379 ParentName := ''; 380 if Assigned(Form.HostDockSite) then 381 begin 362 382 if Assigned(Form.HostDockSite) then 363 383 begin 364 384 HostDockSiteName := Form.HostDockSite.Name; 365 if not Assigned(Parent.FindByName(HostDockSiteName)) then begin 385 if not Assigned(Parent.FindByName(HostDockSiteName)) then 386 begin 366 387 NewItem := TCDLayoutItem.Create; 367 388 NewItem.Parent := Parent; … … 371 392 end; 372 393 end; 373 end else HostDockSiteName := ''; 394 end 395 else 396 HostDockSiteName := ''; 374 397 end; 375 398 … … 381 404 begin 382 405 if Form is TForm then 383 if WindowState = wsMaximized then begin 384 TForm(Form).SetRestoredBounds(RestoredRect.Left, RestoredRect.Top, 385 RestoredRect.Width, RestoredRect.Height); 386 TForm(Form).WindowState := WindowState; 387 end else begin 388 TForm(Form).WindowState := WindowState; 389 TForm(Form).SetRestoredBounds(RestoredRect.Left, RestoredRect.Top, 390 RestoredRect.Width, RestoredRect.Height); 391 end; 406 if WindowState = wsMaximized then 407 begin 408 TForm(Form).SetRestoredBounds(RestoredRect.Left, RestoredRect.Top, 409 RestoredRect.Width, RestoredRect.Height); 410 TForm(Form).WindowState := WindowState; 411 end 412 else 413 begin 414 TForm(Form).WindowState := WindowState; 415 TForm(Form).SetRestoredBounds(RestoredRect.Left, RestoredRect.Top, 416 RestoredRect.Width, RestoredRect.Height); 417 end; 392 418 Form.Name := Name; 393 419 Form.Caption := Caption; … … 396 422 Form.UndockHeight := UndockSize.Y; 397 423 Form.Visible := Visible; 398 if HostDockSiteName <> '' then begin 424 if HostDockSiteName <> '' then 425 begin 399 426 ParentComponent := FindGlobalComponentDeep(HostDockSiteName); 400 if not Assigned(ParentComponent) then begin 427 if not Assigned(ParentComponent) then 428 begin 401 429 ParentLayoutItem := Parent.FindByName(HostDockSiteName); 402 if Assigned(ParentLayoutItem) then begin 403 if ParentLayoutItem.StoredClassName <> '' then begin 430 if Assigned(ParentLayoutItem) then 431 begin 432 if ParentLayoutItem.StoredClassName <> '' then 433 begin 404 434 //ParentComponent := TComponent(FindClass(ParentLayoutItem.StoredClassName).Create); 405 if (ParentLayoutItem.StoredClassName = 'TCoolDockConjoinForm') then begin 406 FormClass := TFormClass(FindClass('TCoolDockConjoinForm')); 407 if FormClass = TCDConjoinForm then begin 435 if (ParentLayoutItem.StoredClassName = 'TCDConjoinForm') then 436 begin 437 FormClass := TFormClass(FindClass('TCDConjoinForm')); 438 if FormClass = TCDConjoinForm then 439 begin 408 440 ParentComponent := TCDManager(Form.DockManager).CreateContainer(alNone); 409 TCDManager(TCDConjoinForm(ParentComponent).DockManager).DockStyle := ParentLayoutItem.DockStyle; 441 TCDManager(TCDConjoinForm(ParentComponent).DockManager).DockStyle := 442 ParentLayoutItem.DockStyle; 410 443 ParentLayoutItem.Restore(TWinControl(ParentComponent)); 411 444 end; … … 439 472 NewNode: TDOMNode; 440 473 NewNode2: TDOMNode; 441 I: Integer; 442 begin 443 with Node do begin 474 I: integer; 475 begin 476 with Node do 477 begin 444 478 NewNode := OwnerDocument.CreateElement('Name'); 445 479 NewNode.TextContent := UTF8Decode(Name); … … 447 481 NewNode := OwnerDocument.CreateElement('Items'); 448 482 with NewNode do 449 for I := 0 to Items.Count - 1 do begin 450 NewNode2 := OwnerDocument.CreateElement('Form'); 451 TCDLayoutItem(Items[I]).SaveToNode(NewNode2); 452 AppendChild(NewNode2); 453 end; 483 for I := 0 to Items.Count - 1 do 484 begin 485 NewNode2 := OwnerDocument.CreateElement('Form'); 486 TCDLayoutItem(Items[I]).SaveToNode(NewNode2); 487 AppendChild(NewNode2); 488 end; 454 489 AppendChild(NewNode); 455 490 end; … … 462 497 NewItem: TCDLayoutItem; 463 498 begin 464 with Node do begin 499 with Node do 500 begin 465 501 NewNode := FindNode('Name'); 466 502 if Assigned(NewNode) then … … 468 504 NewNode := FindNode('Items'); 469 505 if Assigned(NewNode) then 470 with NewNode do begin 471 Child := FirstChild; 472 while Assigned(Child) do begin 473 NewItem := TCDLayoutItem.Create; 474 NewItem.Parent := Self; 475 NewItem.LoadFromNode(Child); 476 Items.Add(NewItem); 477 Child := Child.NextSibling; 506 with NewNode do 507 begin 508 Child := FirstChild; 509 while Assigned(Child) do 510 begin 511 NewItem := TCDLayoutItem.Create; 512 NewItem.Parent := Self; 513 NewItem.LoadFromNode(Child); 514 Items.Add(NewItem); 515 Child := Child.NextSibling; 516 end; 478 517 end; 479 end;480 518 end; 481 519 end; … … 483 521 function TCDLayout.FindByName(Name: string): TCDLayoutItem; 484 522 var 485 I: Integer;523 I: integer; 486 524 begin 487 525 I := 0; 488 while (I < Items.Count) and (TCDLayoutItem(Items[I]).Name <> Name) do Inc(I); 489 if I < Items.Count then Result := TCDLayoutItem(Items[I]) 490 else Result := nil; 526 while (I < Items.Count) and (TCDLayoutItem(Items[I]).Name <> Name) do 527 Inc(I); 528 if I < Items.Count then 529 Result := TCDLayoutItem(Items[I]) 530 else 531 Result := nil; 491 532 end; 492 533 … … 504 545 procedure TCDLayout.Store; 505 546 var 506 I: Integer;547 I: integer; 507 548 Form: TForm; 508 549 NewItem: TCDLayoutItem; … … 510 551 Items.Clear; 511 552 for I := 0 to Application.ComponentCount - 1 do 512 if (Application.Components[I] is TForm) then begin 513 Form := (Application.Components[I] as TForm); 514 NewItem := TCDLayoutItem.Create; 515 NewItem.Parent := Self; 516 NewItem.Store(Form); 517 Items.Add(NewItem); 518 end; 553 if (Application.Components[I] is TForm) then 554 begin 555 Form := (Application.Components[I] as TForm); 556 NewItem := TCDLayoutItem.Create; 557 NewItem.Parent := Self; 558 NewItem.Store(Form); 559 Items.Add(NewItem); 560 end; 519 561 end; 520 562 … … 522 564 var 523 565 Form: TForm; 524 I: Integer;566 I: integer; 525 567 begin 526 568 // Undock all forms 527 569 I := 0; 528 while (I < Application.ComponentCount) do begin 529 if (Application.Components[I] is TForm) then begin 570 while (I < Application.ComponentCount) do 571 begin 572 if (Application.Components[I] is TForm) then 573 begin 530 574 Form := (Application.Components[I] as TForm); 531 575 if Assigned(Form.HostDockSite) then 532 Form.ManualFloat(Rect(Form.Left, Form.Top, Form.Left + Form.Width, Form.Top + Form.Height)); 576 Form.ManualFloat(Rect(Form.Left, Form.Top, Form.Left + 577 Form.Width, Form.Top + Form.Height)); 533 578 end; 534 579 Inc(I); … … 536 581 537 582 for I := 0 to Items.Count - 1 do 538 with TCDLayoutItem(Items[I]) do539 Processed := False;583 with TCDLayoutItem(Items[I]) do 584 Processed := False; 540 585 541 586 for I := 0 to Items.Count - 1 do 542 with TCDLayoutItem(Items[I]) do begin 543 Form := TForm(Application.FindComponent(Name)); 544 if Assigned(Form) and (not Assigned(Form.HostDockSite)) and (not Processed) then Restore(Form); 545 end; 587 with TCDLayoutItem(Items[I]) do 588 begin 589 Form := TForm(Application.FindComponent(Name)); 590 if Assigned(Form) and (not Assigned(Form.HostDockSite)) and (not Processed) then 591 Restore(Form); 592 end; 546 593 end; 547 594
Note:
See TracChangeset
for help on using the changeset viewer.