forked from douglasimcabral/pyscripter
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJvDockInfo.pas
1139 lines (1046 loc) · 39.2 KB
/
JvDockInfo.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{-----------------------------------------------------------------------------
The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/MPL-1.1.html
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for
the specific language governing rights and limitations under the License.
The Original Code is: JvDockInfo.pas, released on 2003-12-31.
The Initial Developer of the Original Code is luxiaoban.
Portions created by luxiaoban are Copyright (C) 2002,2003 luxiaoban.
All Rights Reserved.
Contributor(s):
You may retrieve the latest version of this file at the Project JEDI's JVCL home page,
located at http://jvcl.delphi-jedi.org
Known Issues:
-----------------------------------------------------------------------------}
// $Id$
unit JvDockInfo;
{$I jvcl.inc}
interface
uses
{$IFDEF UNITVERSIONING}
JclUnitVersioning,
{$ENDIF UNITVERSIONING}
Windows, IniFiles, Registry, Classes, Controls, Forms,
JvAppStorage, JvDockControlForm, JvDockSupportClass, JvDockSupportProc;
type
TJvDockInfoTree = class;
TJvDockFormStyle = (dsNormal, dsConjoin, dsTab, dsDockPanel);
TJvDockInfoZone = class(TJvDockBaseZone)
private
FDockFormName: string;
FParentName: string;
FDockRect: TRect;
FLastDockSiteName: string;
FUnDockLeft: Integer;
FUnDockTop: Integer;
FLRDockWidth: Integer;
FTBDockHeight: Integer;
FUnDockWidth: Integer;
FUnDockHeight: Integer;
FVSPaneWidth: Integer;
FVisible: Boolean;
FBorderStyle: TBorderStyle;
FFormStyle: TFormStyle;
FWindowState: TWindowState;
FCanDocked: Boolean;
FEachOtherDocked: Boolean;
FLeftDocked: Boolean;
FTopDocked: Boolean;
FRightDocked: Boolean;
FBottomDocked: Boolean;
FCustomDocked: Boolean; {NEW! Contains custom dock panel! }
FDockFormStyle: TJvDockFormStyle;
FDockClientData: string;
FDockControl: TWinControl;
function GetChildControlCount: Integer;
public
procedure SetDockInfoFromControlToNode(Control: TControl); virtual;
procedure SetDockInfoFromNodeToControl(Control: TControl); virtual;
procedure SetDockInfoFromDockControlToNode(DockControl: TJvDockBaseControl); virtual;
procedure SetDockInfoFromNodeToDockControl(DockControl: TJvDockBaseControl); virtual;
property DockFormName: string read FDockFormName write FDockFormName;
property ParentName: string read FParentName write FParentName;
property DockRect: TRect read FDockRect write FDockRect;
property LastDockSiteName: string read FLastDockSiteName write FLastDockSiteName;
property UnDockLeft: Integer read FUnDockLeft write FUnDockLeft;
property UnDockTop: Integer read FUnDockTop write FUnDockTop;
property LRDockWidth: Integer read FLRDockWidth write FLRDockWidth;
property TBDockHeight: Integer read FTBDockHeight write FTBDockHeight;
property UnDockWidth: Integer read FUnDockWidth write FUnDockWidth;
property UnDockHeight: Integer read FUnDockHeight write FUnDockHeight;
property VSPaneWidth: Integer read FVSPaneWidth write FVSPaneWidth;
property BorderStyle: TBorderStyle read FBorderStyle write FBorderStyle;
property FormStyle: TFormStyle read FFormStyle write FFormStyle;
property WindowState: TWindowState read FWindowState write FWindowState;
property Visible: Boolean read FVisible write FVisible;
property CanDocked: Boolean read FCanDocked write FCanDocked;
property EachOtherDocked: Boolean read FEachOtherDocked write FEachOtherDocked;
property LeftDocked: Boolean read FLeftDocked write FLeftDocked;
property TopDocked: Boolean read FTopDocked write FTopDocked;
property RightDocked: Boolean read FRightDocked write FRightDocked;
property BottomDocked: Boolean read FBottomDocked write FBottomDocked;
property CustomDocked: Boolean read FCustomDocked write FCustomDocked; {NEW! Contains custom dock panel! }
property DockFormStyle: TJvDockFormStyle read FDockFormStyle write FDockFormStyle;
property DockClientData: string read FDockClientData write FDockClientData;
property DockControl: TWinControl read FDockControl write FDockControl;
end;
// TJvDockInfoStyle enumerates the mode that is used when you call
// TJvDockInfoTree.ScanTreeZone. This is a part of the code used to
// implement persistence (loading and saving of docking layouts).
//
TJvDockInfoStyle =
(isNone, { No mode set }
isJVCLReadInfo, { Mode for this scan is JVCL App Storage Load }
isJVCLWriteInfo, { Mode for this scan is JVCL App Storage Save }
isReadFileInfo, { Mode for this scan is Text File Read. Backwards compatible. }
isWriteFileInfo, { Mode for this scan is Text File Write. Backwards compatible. }
isReadRegInfo, { Mode for this scan is registry Read }
isWriteRegInfo); { Mode for this scan is registry Write }
{ JvDockInfoTree contains information about the docking tree. It is created
as part of the persistence framework for the JvDocking components. In order
to save or load docking layout you must create one of these objects and use
it to store the information about the set of docked forms being managed by
JvDocking. }
TJvDockInfoTree = class(TJvDockBaseTree)
private
FAppStorage: TJvCustomAppStorage;
FAppStoragePath: string;
FDockInfoIni: TCustomIniFile;
FDockInfoReg: TRegistry;
FRegName: string;
FJvDockInfoStyle: TJvDockInfoStyle; { Which action to do when doing a ScanTreeZone() recursive operation over the document tree. }
FDataStream: TMemoryStream;
function FindDockForm(const FormName: string): TCustomForm;
function CreateHostControl(ATreeZone: TJvDockInfoZone): TWinControl;
protected
procedure ScanTreeZone(TreeZone: TJvDockBaseZone); override;
procedure CreateZoneAndAddInfoFromAppStorage; virtual;
procedure CreateZoneAndAddInfoFromIni; virtual;
procedure CreateZoneAndAddInfoFromReg; virtual;
procedure SetDockControlInfo(ATreeZone: TJvDockInfoZone); virtual;
public
constructor Create(TreeZone: TJvDockTreeZoneClass); override;
destructor Destroy; override;
// This is the most important function in this class, it basically
// puts the important information from the application form into this
// object.
procedure CreateZoneAndAddInfoFromApp(Control: TControl); virtual;
procedure ReadInfoFromAppStorage;
procedure WriteInfoToAppStorage;
property AppStorage: TJvCustomAppStorage read FAppStorage write FAppStorage;
property AppStoragePath: string read FAppStoragePath write FAppStoragePath;
procedure ReadInfoFromIni;
procedure ReadInfoFromReg(const RegName: string);
procedure WriteInfoToIni;
procedure WriteInfoToReg(const RegName: string);
property DockInfoIni: TCustomIniFile read FDockInfoIni write FDockInfoIni;
property DockInfoReg: TRegistry read FDockInfoReg write FDockInfoReg;
end;
{$IFDEF UNITVERSIONING}
const
UnitVersioning: TUnitVersionInfo = (
RCSfile: '$URL$';
Revision: '$Revision$';
Date: '$Date$';
LogPath: 'JVCL\run'
);
{$ENDIF UNITVERSIONING}
implementation
uses
SysUtils,
JvDockGlobals, JvDockVSNetStyle;
//=== Local procedures =======================================================
function FindDockForm(const FormName: string): TCustomForm;
begin
if Pos(RsDockJvDockInfoSplitter, FormName) > 0 then
Result := nil
else
Result := JvDockFindDockFormWithName(FormName);
end;
function FindDockPanel(const ControlName: string): TWinControl;
var
Index: Word;
DockServer: TJvDockServer;
begin
Result := nil;
Index := Pos(RsDockJvDockInfoSplitter, ControlName);
if Index = 0 then
Exit;
Result := FindDockForm(Copy(ControlName, 1, Index - 1));
if Result <> nil then
begin
DockServer := FindDockServer(Result);
if DockServer <> nil then
with DockServer do
begin
if Pos('TopDockPanel', ControlName) > Index then
Result := TopDockPanel
else
if Pos('LeftDockPanel', ControlName) > Index then
Result := LeftDockPanel
else
if Pos('BottomDockPanel', ControlName) > Index then
Result := BottomDockPanel
else
if Pos('RightDockPanel', ControlName) > Index then
Result := RightDockPanel
else
if Pos('CustomDockPanel', ControlName) > Index then
Result := CustomDockPanel;
// Mantis 3603: No more AV, Result may not always be a TJvDockVSNETPanel
if (Result is TJvDockVSNETPanel) and (Pos('PopupPanel', ControlName) > 20) then
Result := (Result as TJvDockVSNETPanel).VSChannel.VSPopupPanel;
end;
end;
end;
function FindDockHost(const ControlName: string): TWinControl;
begin
Result := FindDockForm(ControlName);
if Result = nil then
Result := FindDockPanel(ControlName);
end;
//=== { TJvDockInfoTree } ====================================================
constructor TJvDockInfoTree.Create(TreeZone: TJvDockTreeZoneClass);
begin
inherited Create(TreeZone);
FJvDockInfoStyle := isNone;
FDataStream := TMemoryStream.Create;
end;
destructor TJvDockInfoTree.Destroy;
begin
inherited Destroy;
FreeAndNil(FDataStream);
end;
{ Create an TJvDockConjoinHostForm or TJvDockTabHostForm when restoring a docking layout }
function TJvDockInfoTree.CreateHostControl(ATreeZone: TJvDockInfoZone): TWinControl;
var
Form: TForm;
ADockClient: TJvDockClient;
begin
{ The dockinfo data that is saved, contains names of the values of ChildZone.DockControl
Thus on loading it can be that no form with that DockControl name can be found;
then DockControl will be nil
}
Result := nil;
case ATreeZone.DockFormStyle of
dsConjoin:
if Assigned(TJvDockInfoZone(ATreeZone.ChildZone).DockControl) then
begin
Form := TJvDockConjoinHostForm.Create(Application);
ADockClient := FindDockClient(TJvDockInfoZone(ATreeZone.ChildZone).DockControl);
Result := ADockClient.CreateConjoinPanelClass(Form).Parent;
//TJvDockConjoinHostFormCreatedEvent: Added by KV
if Assigned(ADockClient.OnConjoinHostFormCreated) then
ADockClient.OnConjoinHostFormCreated(ADockClient, TJvDockConjoinHostForm(Form));
end;
dsTab:
if Assigned(TJvDockInfoZone(ATreeZone.ChildZone).DockControl) then
begin
Form := TJvDockTabHostForm.Create(Application);
ADockClient := FindDockClient(TJvDockInfoZone(ATreeZone.ChildZone).DockControl);
Result := ADockClient.CreateTabDockClass(Form).Parent;
//TJvDockTabHostFormCreatedEvent: Added by KV
if Assigned(ADockClient.OnTabHostFormCreated) then
ADockClient.OnTabHostFormCreated(ADockClient, TJvDockTabHostForm(Form));
end;
end;
if Result <> nil then
Result.Name := ATreeZone.DockFormName;
end;
// CreateZoneAndAddInfoFromApp
//
// Control: TControl - note this is probably actually a TForm
// descendant, since this library only supports form docking.
//
// This is the most important function in this class, it basically
// puts the important information from the application form into this
// object.
//
// This is used to take a form that is docked somewhere and extract all the
// docking layout information contained inside it, and add it to this JvDockInfoTree
// object, which can then be iterated through, stored to disk, etc. }
procedure TJvDockInfoTree.CreateZoneAndAddInfoFromApp(Control: TControl);
var
I: TJvDockPosition; {was TAlign}
J: Integer;
TreeZone: TJvDockInfoZone;
DockBaseControl: TJvDockBaseControl;
TmpDockPanel: TJvDockPanel;
begin
TreeZone := TJvDockInfoZone(AddChildZone(CurrTreeZone, nil));
with TreeZone do
begin
ParentName := TJvDockInfoZone(CurrTreeZone).DockFormName;
SetDockInfoFromControlToNode(Control);
if Control is TJvDockPanel then
DockFormName := TJvDockInfoZone(CurrTreeZone).DockFormName +
RsDockJvDockInfoSplitter + Control.Name
else
DockFormName := Control.Name;
FDataStream.Clear;
if Control is TJvDockTabHostForm then
TJvDockTabHostForm(Control).PageControl.SaveToStream(FDataStream)
else
if Control is TJvDockConjoinHostForm then
TJvDockConjoinHostForm(Control).Panel.DockManager.SaveToStream(FDataStream)
else
if Control is TJvDockPanel then
TJvDockPanel(Control).DockManager.SaveToStream(FDataStream);
DockClientData := JvDockStreamDataToString(FDataStream);
DockBaseControl := FindDockBaseControl(Control);
if DockBaseControl <> nil then
begin
SetDockInfoFromDockControlToNode(DockBaseControl);
if Control is TJvDockTabHostForm then
DockFormStyle := dsTab
else
if Control is TJvDockConjoinHostForm then
DockFormStyle := dsConjoin
else
DockFormStyle := dsNormal;
if DockBaseControl is TJvDockClient then
begin
if Control is TJvDockableForm then
with TJvDockableForm(Control).DockableControl do
for J := 0 to DockClientCount - 1 do
begin
CurrTreeZone := TreeZone;
CreateZoneAndAddInfoFromApp(DockClients[J]);
CurrTreeZone := TreeZone.GetParentZone;
end;
end
else
begin
// Changed to persist ALL DockPanels, not just Top,Left,Right,Bottom.
// This is a hardcoded assumption throughout the component that is
// proving hard to overcome.
for I := Low(TJvDockPosition) to High(TJvDockPosition) do // There are 5 TJvDockPositions now ! {NEW!}
begin
CurrTreeZone := TreeZone;
TmpDockPanel := TJvDockServer(DockBaseControl).DockPanel[I];
if Assigned(TmpDockPanel) then
begin
CreateZoneAndAddInfoFromApp(TmpDockPanel);
if TmpDockPanel is TJvDockVSNETPanel then // JvDockVSNetStyle specific:
CreateZoneAndAddInfoFromApp(TJvDockVSNETPanel(TmpDockPanel).VSChannel.VSPopupPanel);
end;
CurrTreeZone := TreeZone.GetParentZone;
end;
end;
end;
if Control is TJvDockPanel then
begin
DockFormStyle := dsDockPanel;
if Control is TJvDockVSPopupPanel then
with TJvDockVSPopupPanel(Control) do
for J := 0 to DockClientCount - 1 do
begin
CurrTreeZone := TreeZone;
CreateZoneAndAddInfoFromApp(TWinControl(DockClients[J]));
CurrTreeZone := TreeZone.GetParentZone;
end
else
with TJvDockPanel(Control) do
for J := 0 to DockClientCount - 1 do
begin
CurrTreeZone := TreeZone;
CreateZoneAndAddInfoFromApp(TWinControl(DockClients[J]));
CurrTreeZone := TreeZone.GetParentZone;
end;
end;
end;
end;
procedure TJvDockInfoTree.CreateZoneAndAddInfoFromAppStorage;
var
FormList: TStringList;
CP, CP1: PChar;
S: string;
I: Integer;
OldPath: string;
OldDefaultIfValueNotExists : Boolean;
procedure CreateZoneAndAddInfo(Index: Integer);
var
I: Integer;
TreeZone: TJvDockInfoZone;
begin
if FAppStorage.PathExists(FormList[Index]) then
begin
TreeZone := TJvDockInfoZone(AddChildZone(CurrTreeZone, nil));
with TreeZone, FAppStorage do
begin
{ Move down into the folder of the form.. }
Path := ConcatPaths([Path, FormList[Index]]);
DockFormName := FormList[Index];
ParentName := ReadString('ParentName');
DockRect := Rect(ReadInteger('DockLeft'), ReadInteger('DockTop'),
ReadInteger('DockRight'), ReadInteger('DockBottom'));
LRDockWidth := ReadInteger('LRDockWidth');
LastDockSiteName := ReadString('LastDockSiteName');
UnDockLeft := ReadInteger('UnDockLeft');
UnDockTop := ReadInteger('UnDockTop');
TBDockHeight := ReadInteger('TBDockHeight');
UnDockWidth := ReadInteger('UnDockWidth');
UnDockHeight := ReadInteger('UnDockHeight');
VSPaneWidth := ReadInteger('VSPaneWidth');
Visible := ReadBoolean('Visible');
BorderStyle := TBorderStyle(ReadInteger('BorderStyle'));
FormStyle := TFormStyle(ReadInteger('FormStyle'));
WindowState := TWindowState(ReadInteger('WindowState'));
DockFormStyle := TJvDockFormStyle(ReadInteger('DockFormStyle'));
CanDocked := ReadBoolean('CanDocked');
EachOtherDocked := ReadBoolean('EachOtherDocked');
LeftDocked := ReadBoolean('LeftDocked');
TopDocked := ReadBoolean('TopDocked');
RightDocked := ReadBoolean('RightDocked');
BottomDocked := ReadBoolean('BottomDocked');
CustomDocked := ReadBoolean('CustomDocked'); {NEW}
DockClientData := ReadString('DockClientData');
{ ..and move up a level }
Path := ConcatPaths([Path, '..']);
end;
for I := Index - 1 downto 0 do
begin
{ Search for forms that have this form (FormList[I]) as parent }
if FAppStorage.ReadString(FAppStorage.ConcatPaths([FormList[I], 'ParentName'])) = FormList[Index] then
begin
CurrTreeZone := TreeZone;
CreateZoneAndAddInfo(I);
CurrTreeZone := TreeZone.GetParentZone;
end;
end;
end;
end;
var
FormName: string;
begin
FormList := TStringList.Create;
FJvDockInfoStyle := isJVCLReadInfo; // set mode for Scan.
try
{ Normally, we wouldn't find duplicate names, but if so ignore them otherwise havoc }
FormList.Duplicates := dupIgnore;
OldPath := FAppStorage.Path;
OldDefaultIfValueNotExists := FAppStorage.StorageOptions.DefaultIfValueNotExists;
FAppStorage.StorageOptions.DefaultIfValueNotExists := True;
try
FAppStorage.Path := FAppStorage.ConcatPaths([FAppStorage.Path, AppStoragePath, 'Forms']);
if FAppStorage.ValueStored('FormNames') then
begin
S := FAppStorage.ReadString('FormNames');
CP := PChar(S);
CP1 := StrPos(CP, ';');
while CP1 <> nil do
begin
SetString(FormName, CP, CP1 - CP);
// (Mantis #4293) Avoid restoration of not instantiated forms => DockFormStyle == dsNormal
if TJvDockFormStyle(FAppStorage.ReadInteger(
FAppStorage.ConcatPaths([FormName, 'DockFormStyle']))) = dsNormal then
begin
for I := 0 to Screen.FormCount - 1 do
begin
if Screen.Forms[I].Name = FormName then
begin
FormList.Add(FormName);
Break;
end;
end;
end
else
FormList.Add(FormName);
CP := CP1 + 1;
CP1 := StrPos(CP, ';');
end;
for I := FormList.Count - 1 downto 0 do
if FAppStorage.ReadString(FAppStorage.ConcatPaths([FormList[I], 'ParentName'])) = '' then
CreateZoneAndAddInfo(I);
end;
finally
FAppStorage.Path := OldPath;
FAppStorage.StorageOptions.DefaultIfValueNotExists := OldDefaultIfValueNotExists;
end;
finally
FormList.Free;
FJvDockInfoStyle := isNone;
end;
end;
procedure TJvDockInfoTree.CreateZoneAndAddInfoFromIni;
var
I: Integer;
Sections: TStringList;
TempDockInfoZoneArray: array of TJvDockInfoZone;
procedure CreateTempDockInfoZoneArray;
var
I: Integer;
begin
SetLength(TempDockInfoZoneArray, SizeOf(TJvDockInfoZone) * Sections.Count);
for I := 0 to Sections.Count - 1 do
begin
TempDockInfoZoneArray[I] := TJvDockInfoZone.Create(nil);
with TempDockInfoZoneArray[I], DockInfoIni do
begin
DockFormName := Sections[I];
ParentName := ReadString(DockFormName, 'ParentName', 'ERROR');
DockRect := Rect(ReadInteger(DockFormName, 'DockLeft', 0),
ReadInteger(DockFormName, 'DockTop', 0),
ReadInteger(DockFormName, 'DockRight', 100),
ReadInteger(DockFormName, 'DockBottom', 100));
LastDockSiteName := ReadString(DockFormName, 'LastDockSiteName', 'ERROR');
UnDockLeft := ReadInteger(DockFormName, 'UnDockLeft', 100);
UnDockTop := ReadInteger(DockFormName, 'UnDockTop', 100);
LRDockWidth := ReadInteger(DockFormName, 'LRDockWidth', 100);
TBDockHeight := ReadInteger(DockFormName, 'TBDockHeight', 100);
UnDockWidth := ReadInteger(DockFormName, 'UnDockWidth', 100);
UnDockHeight := ReadInteger(DockFormName, 'UnDockHeight', 100);
VSPaneWidth := ReadInteger(DockFormName, 'VSPaneWidth', 100);
Visible := ReadBool(DockFormName, 'Visible', True);
BorderStyle := TBorderStyle(ReadInteger(DockFormName, 'BorderStyle', 0));
FormStyle := TFormStyle(ReadInteger(DockFormName, 'FormStyle', 0));
WindowState := TWindowState(ReadInteger(DockFormName, 'WindowState', 0));
DockFormStyle := TJvDockFormStyle(ReadInteger(DockFormName, 'DockFormStyle', 0));
CanDocked := ReadBool(DockFormName, 'CanDocked', True);
EachOtherDocked := ReadBool(DockFormName, 'EachOtherDocked', True);
LeftDocked := ReadBool(DockFormName, 'LeftDocked', LeftDocked);
TopDocked := ReadBool(DockFormName, 'TopDocked', True);
RightDocked := ReadBool(DockFormName, 'RightDocked', True);
BottomDocked := ReadBool(DockFormName, 'BottomDocked', True);
CustomDocked := ReadBool(DockFormName, 'CustomDocked', True);
DockClientData := ReadString(DockFormName, 'DockClientData', '');
end;
end;
end;
procedure DestroyTempDockInfoZoneArray;
var
I: Integer;
begin
for I := Sections.Count - 1 downto 0 do
TempDockInfoZoneArray[I].Free;
end;
procedure CreateZoneAndAddInfo(Index: Integer);
var
I: Integer;
TreeZone: TJvDockInfoZone;
begin
TreeZone := TJvDockInfoZone(AddChildZone(CurrTreeZone, nil));
with TempDockInfoZoneArray[Index] do
begin
TreeZone.DockFormName := DockFormName;
TreeZone.ParentName := ParentName;
TreeZone.DockRect := DockRect;
TreeZone.LastDockSiteName := LastDockSiteName;
TreeZone.UnDockLeft := UnDockLeft;
TreeZone.UnDockTop := UnDockTop;
TreeZone.LRDockWidth := LRDockWidth;
TreeZone.TBDockHeight := TBDockHeight;
TreeZone.UnDockWidth := UnDockWidth;
TreeZone.UnDockHeight := UnDockHeight;
TreeZone.VSPaneWidth := VSPaneWidth;
TreeZone.Visible := Visible;
TreeZone.BorderStyle := BorderStyle;
TreeZone.FormStyle := FormStyle;
TreeZone.WindowState := WindowState;
TreeZone.DockFormStyle := DockFormStyle;
TreeZone.CanDocked := CanDocked;
TreeZone.EachOtherDocked := EachOtherDocked;
TreeZone.LeftDocked := LeftDocked;
TreeZone.TopDocked := TopDocked;
TreeZone.RightDocked := RightDocked;
TreeZone.BottomDocked := BottomDocked;
TreeZone.CustomDocked := CustomDocked; {NEW!}
TreeZone.DockClientData := DockClientData;
end;
for I := Index - 1 downto 0 do
if TempDockInfoZoneArray[I].ParentName = Sections[Index] then
begin
CurrTreeZone := TreeZone;
CreateZoneAndAddInfo(I);
CurrTreeZone := TreeZone.GetParentZone;
end;
end;
begin
Sections := TStringList.Create;
try
DockInfoIni.ReadSections(Sections);
CreateTempDockInfoZoneArray;
for I := Sections.Count - 1 downto 0 do
if TempDockInfoZoneArray[I].ParentName = '' then
CreateZoneAndAddInfo(I);
FJvDockInfoStyle := isNone;
finally
DestroyTempDockInfoZoneArray;
Sections.Free;
end;
end;
procedure TJvDockInfoTree.CreateZoneAndAddInfoFromReg;
var
FormList: TStringList;
CP, CP1: PChar;
I: Integer;
S: string;
procedure CreateZoneAndAddInfo(Index: Integer);
var
I: Integer;
TreeZone: TJvDockInfoZone;
begin
DockInfoReg.OpenKey(FRegName, False);
if DockInfoReg.KeyExists(FormList[Index]) then
begin
DockInfoReg.OpenKey(FRegName + '\' + FormList[Index], False);
TreeZone := TJvDockInfoZone(AddChildZone(CurrTreeZone, nil));
with TreeZone, DockInfoReg do
begin
DockFormName := FormList[Index];
ParentName := ReadString('ParentName');
DockRect := Rect(ReadInteger('DockLeft'), ReadInteger('DockTop'),
ReadInteger('DockRight'), ReadInteger('DockBottom'));
LRDockWidth := ReadInteger('LRDockWidth');
LastDockSiteName := ReadString('LastDockSiteName');
UnDockLeft := ReadInteger('UnDockLeft');
UnDockTop := ReadInteger('UnDockTop');
TBDockHeight := ReadInteger('TBDockHeight');
UnDockWidth := ReadInteger('UnDockWidth');
UnDockHeight := ReadInteger('UnDockHeight');
VSPaneWidth := ReadInteger('VSPaneWidth');
Visible := ReadBool('Visible');
BorderStyle := TBorderStyle(ReadInteger('BorderStyle'));
FormStyle := TFormStyle(ReadInteger('FormStyle'));
WindowState := TWindowState(ReadInteger('WindowState'));
DockFormStyle := TJvDockFormStyle(ReadInteger('DockFormStyle'));
CanDocked := ReadBool('CanDocked');
EachOtherDocked := ReadBool('EachOtherDocked');
LeftDocked := ReadBool('LeftDocked');
TopDocked := ReadBool('TopDocked');
RightDocked := ReadBool('RightDocked');
BottomDocked := ReadBool('BottomDocked');
CustomDocked := ReadBool('CustomDocked'); {NEW!}
DockClientData := ReadString('DockClientData');
end;
for I := Index - 1 downto 0 do
begin
DockInfoReg.OpenKey(FRegName + '\' + FormList[I], False);
if DockInfoReg.ReadString('ParentName') = FormList[Index] then
begin
CurrTreeZone := TreeZone;
CreateZoneAndAddInfo(I);
CurrTreeZone := TreeZone.GetParentZone;
end;
end;
end;
end;
begin
FormList := TStringList.Create;
try
if DockInfoReg.OpenKey(FRegName, False) then
begin
S := DockInfoReg.ReadString('FormNames');
CP := PChar(S);
CP1 := StrPos(CP, '\');
while CP1 <> nil do
begin
CP1^ := #0;
FormList.Add(CP);
CP := CP1 + 1;
CP1 := StrPos(CP, '\');
end;
FJvDockInfoStyle := isReadFileInfo;
for I := FormList.Count - 1 downto 0 do
begin
DockInfoReg.OpenKey(FRegName + '\' + FormList[I], False);
if DockInfoReg.ReadString('ParentName') = '' then
CreateZoneAndAddInfo(I);
end;
FJvDockInfoStyle := isNone;
end;
finally
DockInfoReg.CloseKey;
FormList.Free;
end;
end;
function TJvDockInfoTree.FindDockForm(const FormName: string): TCustomForm;
begin
if Pos(RsDockJvDockInfoSplitter, FormName) > 0 then
Result := nil
else
Result := JvDockFindDockFormWithName(FormName);
end;
procedure TJvDockInfoTree.ReadInfoFromAppStorage;
begin
AppStorage.BeginUpdate;
try
CreateZoneAndAddInfoFromAppStorage;
DoFloatAllForm;
// (rom) this is disputable
Application.ProcessMessages;
try
FJvDockInfoStyle := isJVCLReadInfo;
MiddleScanTree(TopTreeZone);
finally
FJvDockInfoStyle := isNone;
end;
finally
AppStorage.EndUpdate;
end;
end;
procedure TJvDockInfoTree.ReadInfoFromIni;
begin
CreateZoneAndAddInfoFromIni;
DoFloatAllForm;
// (rom) this is disputable
Application.ProcessMessages;
FJvDockInfoStyle := isJVCLReadInfo;
MiddleScanTree(TopTreeZone);
FJvDockInfoStyle := isNone;
end;
procedure TJvDockInfoTree.ReadInfoFromReg(const RegName: string);
begin
FRegName := RegName;
CreateZoneAndAddInfoFromReg;
DoFloatAllForm;
// (rom) this is disputable
Application.ProcessMessages;
FJvDockInfoStyle := isReadRegInfo;
MiddleScanTree(TopTreeZone);
FJvDockInfoStyle := isNone;
end;
procedure TJvDockInfoTree.ScanTreeZone(TreeZone: TJvDockBaseZone);
var
I: Integer;
OldPath: string;
procedure WriteIntegerIfNonZero(const Path: string; Value: Integer);
begin
if Value <> 0 then
fAppStorage.WriteInteger(Path, Value);
end;
procedure WriteBooleanIfFalse(const Path: string; Value: Boolean);
begin
if not Value then
fAppStorage.WriteBoolean(Path, Value);
end;
begin
if FJvDockInfoStyle = isJVCLReadInfo then { JVCL Mode persistance : READ }
begin
for I := 0 to TreeZone.GetChildCount - 1 do
with TJvDockInfoZone(TreeZone.GetChildZone(I)) do
DockControl := FindDockForm(DockFormName);
SetDockControlInfo(TJvDockInfoZone(TreeZone));
end
else
if FJvDockInfoStyle = isJVCLWriteInfo then { JVCL Mode persistance : WRITE }
begin
if TreeZone <> TopTreeZone then
with TJvDockInfoZone(TreeZone), FAppStorage do
begin
OldPath := Path;
try
Path := ConcatPaths([Path, AppStoragePath, 'Forms']);
WriteString('FormNames', ReadString('FormNames') + DockFormName + ';');
Path := ConcatPaths([Path, DockFormName]);
WriteString('ParentName', ParentName);
WriteIntegerIfNonZero('DockLeft', DockRect.Left);
WriteIntegerIfNonZero('DockTop', DockRect.Top);
WriteIntegerIfNonZero('DockRight', DockRect.Right);
WriteIntegerIfNonZero('DockBottom', DockRect.Bottom);
WriteString('LastDockSiteName', LastDockSiteName);
WriteIntegerIfNonZero('UnDockLeft', UnDockLeft);
WriteIntegerIfNonZero('UnDockTop', UnDockTop);
WriteIntegerIfNonZero('LRDockWidth', LRDockWidth);
WriteIntegerIfNonZero('TBDockHeight', TBDockHeight);
WriteIntegerIfNonZero('UnDockWidth', UnDockWidth);
WriteIntegerIfNonZero('UnDockHeight', UnDockHeight);
WriteIntegerIfNonZero('VSPaneWidth', VSPaneWidth);
WriteBooleanIfFalse('Visible', Visible);
WriteIntegerIfNonZero('BorderStyle', Integer(BorderStyle));
WriteIntegerIfNonZero('FormStyle', Integer(FormStyle));
WriteIntegerIfNonZero('WindowState', Integer(WindowState));
WriteIntegerIfNonZero('DockFormStyle', Integer(DockFormStyle));
WriteBooleanIfFalse('CanDocked', CanDocked);
WriteBooleanIfFalse('EachOtherDocked', EachOtherDocked);
WriteBooleanIfFalse('LeftDocked', LeftDocked);
WriteBooleanIfFalse('TopDocked', TopDocked);
WriteBooleanIfFalse('RightDocked', RightDocked);
WriteBooleanIfFalse('BottomDocked', BottomDocked);
WriteBooleanIfFalse('CustomDocked', CustomDocked); {NEW!}
WriteString('DockClientData', DockClientData);
finally
FAppStorage.Path := OldPath;
end;
end;
end;
inherited ScanTreeZone(TreeZone);
end;
procedure TJvDockInfoTree.SetDockControlInfo(ATreeZone: TJvDockInfoZone);
var
DockBaseControl: TJvDockBaseControl;
Host: TWinControl;
begin
with ATreeZone do
begin
if DockFormName = '' then
Exit;
Host := FindDockHost(DockFormName);
if (Host = nil) and (ATreeZone.GetChildControlCount > 1) then
Host := CreateHostControl(ATreeZone);
if (Host <> nil) and (DockClientData <> '') and (FDataStream <> nil) then
begin
FDataStream.Clear;
JvDockStringToStreamData(FDataStream, DockClientData);
FDataStream.Position := 0;
if Host is TJvDockTabHostForm then
begin
with TJvDockTabHostForm(Host).PageControl do
begin
DisableAlign;
try
LoadFromStream(FDataStream);
finally
EnableAlign;
end;
end;
end
else
if Host is TJvDockConjoinHostForm then
begin
with TJvDockConjoinHostForm(Host).Panel do
begin
DisableAlign;
try
DockManager.LoadFromStream(FDataStream);
finally
EnableAlign;
end;
end;
end
else
if Host is TJvDockPanel then
begin
with TJvDockPanel(Host) do
begin
DisableAlign;
try
DockManager.LoadFromStream(FDataStream);
finally
EnableAlign;
end;
end;
end;
end;
if Host <> nil then
begin
SetDockInfoFromNodeToControl(Host);
DockBaseControl := FindDockBaseControl(Host);
if DockBaseControl <> nil then
SetDockInfoFromNodeToDockControl(DockBaseControl);
end;
end;
end;
procedure TJvDockInfoTree.WriteInfoToAppStorage;
begin
AppStorage.BeginUpdate;
try
AppStorage.DeleteSubTree(AppStoragePath);
try
FJvDockInfoStyle := isJVCLWriteInfo;
MiddleScanTree(TopTreeZone);
finally
FJvDockInfoStyle := isNone;
end;
finally
AppStorage.EndUpdate;
end;
end;
procedure TJvDockInfoTree.WriteInfoToIni;
var
Sections: TStringList;
I: Integer;
begin
Sections := TStringList.Create;
try
DockInfoIni.ReadSections(Sections);
for I := 0 to Sections.Count - 1 do
DockInfoIni.EraseSection(Sections[I]);
finally
Sections.Free;
end;
FJvDockInfoStyle := isJVCLWriteInfo;
MiddleScanTree(TopTreeZone);
FJvDockInfoStyle := isNone;
end;
procedure TJvDockInfoTree.WriteInfoToReg(const RegName: string);
begin
try
if DockInfoReg.OpenKey(RegName, False) then
DockInfoReg.DeleteKey(RegName);
DockInfoReg.CreateKey(RegName);
DockInfoReg.CloseKey;
FRegName := RegName;
FJvDockInfoStyle := isWriteRegInfo;
MiddleScanTree(TopTreeZone);
FJvDockInfoStyle := isNone;
finally
DockInfoReg.CloseKey;
end;
end;
//=== { TJvDockInfoZone } ====================================================
function TJvDockInfoZone.GetChildControlCount: Integer;
var
Zone: TJvDockBaseZone;
begin
Result := 0;
if ChildZone <> nil then
begin
Inc(Result);
Zone := ChildZone;
while Zone.NextSibling <> nil do
begin
Zone := Zone.NextSibling;
if TJvDockInfoZone(Zone).DockControl <> nil then
Inc(Result);
end;
end;
end;
procedure TJvDockInfoZone.SetDockInfoFromControlToNode(Control: TControl);
begin
DockRect := Control.BoundsRect;
UnDockWidth := Control.UnDockWidth;
UnDockHeight := Control.UnDockHeight;
if Control is TJvDockVSPopupPanel then
Control.Visible := False
else
Visible := Control.Visible;
if Control is TForm then
begin
BorderStyle := TForm(Control).BorderStyle;
FormStyle := TForm(Control).FormStyle;
WindowState := TForm(Control).WindowState;
LRDockWidth := Control.LRDockWidth;
TBDockHeight := Control.TBDockHeight;
end;
end;
procedure TJvDockInfoZone.SetDockInfoFromDockControlToNode(DockControl: TJvDockBaseControl);
function GetLastDockSiteName(AControl: TControl): string;