Changeset 179 for Docking/CoolDocking/UCoolDockLayout.pas
- Timestamp:
- Mar 8, 2011, 12:58:28 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Docking/CoolDocking/UCoolDockLayout.pas
r178 r179 19 19 Visible: Boolean; 20 20 Rect: TRectangle; 21 FormState: TFormState; 21 RestoredRect: TRectangle; 22 WindowState: TWindowState; 22 23 UndockSize: TPoint; 23 24 DockStyle: TDockStyle; 24 25 procedure SaveToNode(Node: TDOMNode); 25 26 procedure LoadFromNode(Node: TDOMNode); 27 constructor Create; 28 destructor Destroy; override; 26 29 end; 27 30 … … 35 38 constructor Create; 36 39 destructor Destroy; override; 40 procedure Store; 41 procedure Restore; 37 42 end; 38 43 … … 46 51 procedure LoadFromFile(FileName: string); 47 52 procedure SaveToFile(FileName: string); 53 procedure PopulateStringList(List: TStrings); 48 54 constructor Create(AOwner: TComponent); override; 49 55 destructor Destroy; override; … … 78 84 Doc: TXMLDocument; 79 85 Child: TDOMNode; 80 NewItem: TCoolDockLayout Item;86 NewItem: TCoolDockLayout; 81 87 NewNode: TDOMNode; 82 88 begin … … 88 94 if Assigned(NewNode) then 89 95 with NewNode do begin 90 Child := Doc.DocumentElement.FirstChild;96 Child := FirstChild; 91 97 while Assigned(Child) do begin 92 NewItem := TCoolDockLayout Item.Create;98 NewItem := TCoolDockLayout.Create; 93 99 NewItem.LoadFromNode(Child); 94 100 Items.Add(NewItem); … … 117 123 with RootNode do begin 118 124 NewNode := OwnerDocument.CreateElement('Items'); 125 with NewNode do 119 126 for I := 0 to Items.Count - 1 do begin 120 127 NewNode2 := OwnerDocument.CreateElement('Layout'); … … 150 157 if FileExistsUTF8(FileName) then Stream := TFileStream.Create(FileName, fmOpenReadWrite) 151 158 else Stream := TFileStream.Create(FileName, fmCreate); 159 Stream.Size := 0; 152 160 SaveToStream(Stream); 153 161 finally … … 156 164 end; 157 165 166 procedure TCoolDockLayoutList.PopulateStringList(List: TStrings); 167 var 168 I: Integer; 169 begin 170 List.Clear; 171 for I := 0 to Items.Count - 1 do 172 List.AddObject(TCoolDockLayout(Items[I]).Name, TCoolDockLayout(Items[I])); 173 end; 174 158 175 { TCoolDockLayoutItem } 159 176 … … 172 189 NewNode.TextContent := UTF8Decode(Caption); 173 190 AppendChild(NewNode); 174 NewNode := OwnerDocument.CreateElement(' FormState');175 NewNode.TextContent := IntToStr(Integer( FormState));191 NewNode := OwnerDocument.CreateElement('WindowState'); 192 NewNode.TextContent := IntToStr(Integer(WindowState)); 176 193 AppendChild(NewNode); 177 194 NewNode := OwnerDocument.CreateElement('UndockWidth'); … … 199 216 NewNode.TextContent := IntToStr(Integer(DockStyle)); 200 217 AppendChild(NewNode); 218 NewNode := OwnerDocument.CreateElement('RestoredWidth'); 219 NewNode.TextContent := IntToStr(RestoredRect.Width); 220 AppendChild(NewNode); 221 NewNode := OwnerDocument.CreateElement('RestoredHeight'); 222 NewNode.TextContent := IntToStr(RestoredRect.Height); 223 AppendChild(NewNode); 224 NewNode := OwnerDocument.CreateElement('RestoredTop'); 225 NewNode.TextContent := IntToStr(RestoredRect.Top); 226 AppendChild(NewNode); 227 NewNode := OwnerDocument.CreateElement('RestoredLeft'); 228 NewNode.TextContent := IntToStr(RestoredRect.Left); 229 AppendChild(NewNode); 201 230 end; 202 231 end; … … 216 245 if Assigned(NewNode) then 217 246 Caption := UTF8Encode(NewNode.TextContent); 218 NewNode := FindNode(' FormState');219 if Assigned(NewNode) then 220 FormState := TFormState(StrToInt(NewNode.TextContent));247 NewNode := FindNode('WindowState'); 248 if Assigned(NewNode) then 249 WindowState := TWindowState(StrToInt(NewNode.TextContent)); 221 250 NewNode := FindNode('UndockWidth'); 222 251 if Assigned(NewNode) then … … 243 272 if Assigned(NewNode) then 244 273 DockStyle := TDockStyle(StrToInt(NewNode.TextContent)); 245 end; 274 NewNode := FindNode('RestoredTop'); 275 if Assigned(NewNode) then 276 RestoredRect.Top := StrToInt(NewNode.TextContent); 277 NewNode := FindNode('RestoredLeft'); 278 if Assigned(NewNode) then 279 RestoredRect.Left := StrToInt(NewNode.TextContent); 280 NewNode := FindNode('RestoredWidth'); 281 if Assigned(NewNode) then 282 RestoredRect.Width := StrToInt(NewNode.TextContent); 283 NewNode := FindNode('RestoredHeight'); 284 if Assigned(NewNode) then 285 RestoredRect.Height := StrToInt(NewNode.TextContent); 286 end; 287 end; 288 289 constructor TCoolDockLayoutItem.Create; 290 begin 291 Rect := TRectangle.Create; 292 RestoredRect := TRectangle.Create; 293 end; 294 295 destructor TCoolDockLayoutItem.Destroy; 296 begin 297 Rect.Free; 298 RestoredRect.Free; 299 inherited Destroy; 246 300 end; 247 301 … … 259 313 AppendChild(NewNode); 260 314 NewNode := OwnerDocument.CreateElement('Items'); 315 with NewNode do 261 316 for I := 0 to Items.Count - 1 do begin 262 317 NewNode2 := OwnerDocument.CreateElement('Form'); … … 303 358 end; 304 359 360 procedure TCoolDockLayout.Store; 361 var 362 I: Integer; 363 Form: TForm; 364 NewItem: TCoolDockLayoutItem; 365 begin 366 Items.Clear; 367 for I := 0 to Application.ComponentCount - 1 do 368 if (Application.Components[I] is TForm) then begin 369 Form := (Application.Components[I] as TForm); 370 NewItem := TCoolDockLayoutItem.Create; 371 NewItem.Name := Form.Name; 372 NewItem.Caption := Form.Caption; 373 NewItem.UndockSize.X := Form.UndockWidth; 374 NewItem.UndockSize.Y := Form.UndockHeight; 375 NewItem.Visible := Form.Visible; 376 NewItem.Rect.Left := Form.Left; 377 NewItem.Rect.Top := Form.Top; 378 NewItem.Rect.Width := Form.Width; 379 NewItem.Rect.Height := Form.Height; 380 NewItem.RestoredRect.Left := Form.RestoredLeft; 381 NewItem.RestoredRect.Top := Form.RestoredTop; 382 NewItem.RestoredRect.Width := Form.RestoredWidth; 383 NewItem.RestoredRect.Height := Form.RestoredHeight; 384 NewItem.WindowState := Form.WindowState; 385 Items.Add(NewItem); 386 end; 387 end; 388 389 procedure TCoolDockLayout.Restore; 390 var 391 Form: TForm; 392 I: Integer; 393 begin 394 for I := 0 to Items.Count - 1 do 395 with TCoolDockLayoutItem(Items[I]) do begin 396 Form := TForm(Application.FindComponent(Name)); 397 if WindowState = wsMaximized then begin 398 Form.SetRestoredBounds(RestoredRect.Left, RestoredRect.Top, 399 RestoredRect.Width, RestoredRect.Height); 400 Form.WindowState := WindowState; 401 end else begin 402 Form.WindowState := WindowState; 403 Form.SetRestoredBounds(RestoredRect.Left, RestoredRect.Top, 404 RestoredRect.Width, RestoredRect.Height); 405 end; 406 Form.Caption := Caption; 407 Form.SetBounds(Rect.Left, Rect.Top, Rect.Width, Rect.Height); 408 Form.UndockWidth := UndockSize.X; 409 Form.UndockHeight := UndockSize.Y; 410 Form.Visible := Visible; 411 end; 412 end; 413 305 414 end. 306 415
Note:
See TracChangeset
for help on using the changeset viewer.