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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
| ///////////////////////////////////////////////////////////////////////////
// //
// Copyright (c) 2015 by Charta Software B.V. //
// All rights reserved //
// //
// Version: 1.7.0.83525 //
// Web site: https://pascal.chartasoftware.com/ //
// //
// This code and information are provided "as is" without warranty of //
// any kind. Dissemination of this information or reproduction of //
// this material is strictly forbidden unless prior written permission //
// is obtained from Charta Software B.V.. //
// //
///////////////////////////////////////////////////////////////////////////
unit Application.Default;
interface
{$SCOPEDENUMS ON}
uses
Application,
Authorization.Manager,
AutomatedTest.Session,
AutomatedTest.Suite,
Boolean,
Collection.List,
Dom.Element,
Event,
Geometry._2d.Integer32.Point,
Object_.Base,
Object_.Model.Factory,
Percentage.Model.Static,
{$IF not Defined(FPC)}
Sql.Database.Connector,
Sql.Table.Set_.Registration,
{$ENDIF}
Table.Model,
Table.Model.Factory,
Text,
Timer,
UserInterface.Control,
UserInterface.Control.Button,
UserInterface.Control.Event,
UserInterface.Control.Panel.Paged,
UserInterface.Control.Panel.Split,
UserInterface.Control.Panel.Split.SingleDimension.Horizontal,
UserInterface.Control.Panel.Split.SingleDimension.Vertical,
UserInterface.Control.Panel.Stack,
UserInterface.Control.Table,
UserInterface.Control.Text.SingleLine,
UserInterface.Control.Tree,
UserInterface.Object_.Action.Factory,
UserInterface.User.Level,
Uuid,
Value,
Windows.Control.Window;
type
TDefaultApplicationStyleSheet = (Normal, Night);
TDefaultApplication = class(TApplication)
protected
function GetProductId(): TUuid; virtual;
protected
TableFactory: TTableModelFactory;
ObjectModelFactory: TObjectModelFactory;
function CreateObjectModelFactory(): TObjectModelFactory; virtual;
function CreateTableFactory(): TTableModelFactory; virtual;
function CreateControlFactory(): TControlFactory; virtual;
function CreateObjectActionFactory(): TObjectActionFactory; virtual;
function GetInitialUserLevel(): TUserLevel; virtual;
procedure ShowContextMenuForControl(Control: TControl; const Position: TInteger32Point);
protected
WindowFactory: TWindowFactory;
MainSplitPanel: TSplitPanel;
LeftPanel: TVerticalSplitPanel;
Toolbar: THorizontalStackPanel;
CurrentStyleSheet: TDefaultApplicationStyleSheet;
procedure AddToolBarButtons(ToolBar: THorizontalStackPanel); virtual;
function CreateLanguageToolBar(): TControl; virtual;
procedure InstallHotKeys(); virtual;
function CreateProblemsControl(): TControl; virtual;
function CreateMainPanel(): TControl; virtual;
function CreateToolBar(): TControl;
function CreateTopBar(): TControl;
function CreateButton(Caption: TText; Listener: TBaseObject): TButton;
function CreateDefaultTable(Model: TTableModel; Caption: TText): TTableControl;
function CreateTasksControl(): TTableControl;
protected
ExplorerPagedPanel: TPagedPanel;
function GetApplicationExplorerRoot(): TValue; virtual; abstract;
function GetExplorerRoot(): TValue; virtual;
function CreateExplorerPanel(): TControl; virtual;
function CreateExplorerTreeControl(const Root: TValue): TTreeControl;
procedure CreateExplorerPagedPanel();
procedure AssureExplorerPagedPanelExists();
function CreateExplorerControl(): TTreeControl;
function CreateExplorerDetailsPanel(): THorizontalSplitPanel;
protected
ProgressLabel: TSingleLineTextControl;
ProgressModel: TStaticPercentageModel;
ProgressTimer: TTimer;
function CreateProgressPanel(): TControl;
procedure HandleProgressTimer();
protected
{$IF not Defined(FPC)}
DatabaseConnectors: TList<TSqlDatabaseConnector>;
procedure RegisterTableSets(TableSetRegistration: TSqlTableSetRegistration); virtual; deprecated 'Please use TSqlDatabaseSetup';
procedure InitializeDatabaseConnectors(Configuration: TDomElement); virtual;
procedure CreateSqlConnectionControl();
{$ENDIF}
protected
AuthorizationManager: TAuthorizationManager;
function CreateAuthorizationManager(): TAuthorizationManager; virtual;
protected
function CreateWindow(): TWindow; override;
function GetDefaultWindowState(): TWindowState; virtual;
function DetermineWindowState(): TWindowState; virtual;
function IncludeVersionInCaption(): TBoolean; virtual;
function GetCaption(): TText; virtual;
function GetCompany(): TText; virtual;
function GetApplicationCaption(): TText; virtual;
function DisplaySplashScreen(const Caption: TText): TControl;
procedure CreateAndShowMainWindow(MainPanel: TControl);
protected
TestSession: TAutomatedTestSession;
function CreateTestSuite(): TAutomatedTestSuite; virtual;
procedure ExecuteTests();
protected
function HandleContextMenuEvent(ContextMenuEvent: TControlContextMenuEvent): TBoolean;
function HandleDefaultActionExecutedEvent(Event: TControlDefaultActionExecutedEvent): TBoolean;
function HandleTimerFired(TimerFired: TTimerFired): TBoolean;
protected
procedure CloseUserInterface(); override;
procedure Initialize(Configuration: TDomElement); virtual;
procedure InitializeControls(); virtual;
protected
function GetDefaultWindowClass(): TWindowClass; virtual;
function TextToWindowClass(const Type_: TText): TWindowClass;
procedure InitializeWindowFactory(Element: TDomElement);
public
constructor Create(); override;
destructor Destroy(); override;
procedure AfterConstruction(); override;
function HandleEvent(Event: TEvent): TBoolean; override;
procedure OpenExplorer();
procedure OpenTasks();
procedure OpenTests();
procedure SwitchStyleSheet();
end;
implementation
uses
Application.Default.Action,
Application.Default.Factory.Action,
Application.Default.Factory.Control,
Application.Default.Factory.Model.Object_,
Application.Default.Factory.Model.Table,
Application.Explorer.Model,
Authorization.Manager.AllowAll,
AutomatedTest.Run,
AutomatedTest.Task,
Color.Constants,
Configuration,
Drawing.Fill,
Event.DistributionCenter,
Exception.Enumeration,
Executable.VersionInformation,
File_,
Geometry._2d.Integer32.Rectangle,
Geometry._2d.Integer32.Size,
Iterator,
Iterator.Tree,
Language.Translator,
Object_.List,
Object_.Reference,
Object_.Reference.Type_,
OpenGl.Window,
Platform,
Process.Current,
Reference.User,
{$IF not Defined(FPC)}
Sql.Connection.Settings,
Sql.Database.Logical.Versioned.Table.Set_,
Sql.Database.Management.Table.Set_,
{$ENDIF}
Task.Scheduler,
Task.Status,
Task.Status.Model.Table,
Tests,
UserInterface.Control.Panel.Information,
UserInterface.Control.Percentage,
UserInterface.Control.SplashScreen.Logo,
UserInterface.Control.Style,
UserInterface.Device.Monitor,
UserInterface.Keyboard.HotKey,
UserInterface.Keyboard.Key,
UserInterface.Language.TranslationMap,
UserInterface.Object_.Action,
UserInterface.Object_.Action.Model.Table,
UserInterface.Object_.Selection,
{$IF not Defined(FPC)}
UserManagement.Table.Set_,
{$ENDIF}
Value.Path,
Windows.Api.Messages,
Windows.Direct2d.Window,
Windows.Gdi.Window;
{ TDefaultApplication }
procedure TDefaultApplication.AddToolbarButtons(ToolBar: THorizontalStackPanel);
begin
ToolBar.AddControl(CreateButton(TTranslator.Default.Translate(UserInterfaceTranslation.Explorer), TOpenExplorerAction.Create(Self)));
ToolBar.AddControl(CreateButton(TTranslator.Default.Translate(UserInterfaceTranslation.Tasks), TOpenTasksAction.Create(Self)));
{$IF Defined(DEBUG)}
ToolBar.AddControl(CreateButton(TTranslator.Default.Translate(UserInterfaceTranslation.Tests), TOpenTestsAction.Create(Self)));
{$ENDIF}
end;
procedure TDefaultApplication.AfterConstruction();
begin
inherited AfterConstruction();
ProgressTimer.Schedule(Self);
{$IF Defined(DEBUG)}
ExecuteTests();
{$ENDIF}
end;
procedure TDefaultApplication.AssureExplorerPagedPanelExists();
begin
if ExplorerPagedPanel = nil then
CreateExplorerPagedPanel();
end;
procedure TDefaultApplication.CloseUserInterface();
begin
ProgressTimer.Free();
ProgressModel.ReleaseReference();
inherited CloseUserInterface();
TableFactory.Free();
ObjectModelFactory.Free();
ObjectActionFactory.Free();
end;
constructor TDefaultApplication.Create();
var
MainPanel: TControl;
SplashScreen: TControl;
Configuration: TDomElement;
begin
inherited Create();
{$IF not Defined(FPC)}
DatabaseConnectors := TObjectList<TSqlDatabaseConnector>.Create();
{$ENDIF FPC}
SplashScreen := DisplaySplashScreen(GetCaption());
Configuration := LoadDefaultConfiguration();
Initialize(Configuration);
Configuration.Free();
TestSession := TAutomatedTestSession.Create();
TestSession.Tests := CreateTestSuite();
AuthorizationManager := CreateAuthorizationManager();
ObjectModelFactory := CreateObjectModelFactory();
TableFactory := CreateTableFactory();
ObjectActionFactory := CreateObjectActionFactory();
FControlFactory := CreateControlFactory();
FControlFactory.UserLevel := GetInitialUserLevel();
MainPanel := CreateMainPanel();
MainPanel.Caption := GetApplicationCaption();
ProgressTimer := TLowResolutionSynchronousTimer.Create();
ProgressTimer.Delay_Milliseconds := 500;
InstallHotKeys();
TEventDistributionCenter.Instance.SubscribeEvent(Self);
CreateAndShowMainWindow(MainPanel);
InitializeControls();
SplashScreen.Free();
MainWindow.State := DetermineWindowState();
end;
procedure TDefaultApplication.CreateAndShowMainWindow(MainPanel: TControl);
var
Monitor: TMonitor;
MonitorBounds: TInteger32Rectangle;
begin
MainWindow := CreateWindow();
MainWindow.ClipBoard := ClipBoard;
MainWindow.MouseManager := MouseManager;
MainWindow.FocusManager := FocusManager;
MainWindow.NavigationManager := NavigationManager;
MainWindow.Size := TInteger32Size.New(1200, 800);
Monitor := MainWindow.CreateNearestMonitor(TInteger32Point.New(0, 0));
MonitorBounds := Monitor.WorkBounds;
MainWindow.Size := MainWindow.Size.ConfineTo(MonitorBounds.Size);
MainWindow.Position := MainWindow.Bounds.CenterIn(MonitorBounds);
MainWindow.ParentHandle := 0;
MainWindow.Control := MainPanel;
Monitor.Free();
end;
function TDefaultApplication.CreateAuthorizationManager(): TAuthorizationManager;
begin
Result := TAllowAllAuthorizationManager.Create();
end;
function TDefaultApplication.CreateButton(Caption: TText; Listener: TBaseObject): TButton;
begin
Result := TButton.Create();
Result.Caption := Caption;
Result.Listeners.Add(Listener);
end;
function TDefaultApplication.CreateControlFactory(): TControlFactory;
var
DefaultControlFactory: TDefaultControlFactory;
begin
DefaultControlFactory := TDefaultControlFactory.Create();
DefaultControlFactory.ObjectModelFactory := ObjectModelFactory;
DefaultControlFactory.TableFactory := TableFactory;
Result := DefaultControlFactory;
end;
function TDefaultApplication.CreateDefaultTable(Model: TTableModel; Caption: TText): TTableControl;
begin
Result := TTableControl.Create();
Result.Model := Model;
Result.Caption := Caption;
Result.RowHeadersControl.Width := 45;
end;
function TDefaultApplication.CreateExplorerControl(): TTreeControl;
begin
Result := CreateExplorerTreeControl(GetApplicationExplorerRoot());
end;
function TDefaultApplication.CreateExplorerDetailsPanel(): THorizontalSplitPanel;
var
ExplorerPanel: TControl;
ExplorerTarget: TPagedPanel;
begin
Result := THorizontalSplitPanel.Create();
Result.Caption := TTranslator.Default.Translate(UserInterfaceTranslation.Explorer);
Result.PanelCount := 2;
Result.CaptionVisible := False;
ExplorerTarget := TPagedPanel.Create();
ExplorerTarget.Caption := TTranslator.Default.Translate(UserInterfaceTranslation.Details);
ExplorerTarget.CaptionVisible := False;
ExplorerTarget.IsExplorerTarget := True;
ExplorerTarget.Style.Width.Value := TControlSize.Available;
ExplorerPanel := CreateExplorerPanel();
ExplorerPanel.Style.Width.Value := TControlSizeFixed.Create(250);
Result.Panels[0] := ExplorerPanel;
Result.Panels[1] := ExplorerTarget;
end;
procedure TDefaultApplication.CreateExplorerPagedPanel();
var
Explorer: TControl;
begin
Explorer := LeftPanel.Panels[0];
LeftPanel.Panels[0] := nil;
ExplorerPagedPanel := TPagedPanel.Create();
ExplorerPagedPanel.Style.Height.Value := TControlSize.Available;
ExplorerPagedPanel.Caption := TTranslator.Default.Translate(UserInterfaceTranslation.Explorer);
ExplorerPagedPanel.AddPage(Explorer);
LeftPanel.Panels[0] := ExplorerPagedPanel;
end;
function TDefaultApplication.CreateExplorerPanel(): TControl;
var
InformationPanel: TInformationPanel;
ExplorerControl: TControl;
begin
ExplorerControl := CreateExplorerControl();
ExplorerControl.Style.Height.Value := TControlSize.Available;
InformationPanel := TInformationPanel.Create();
InformationPanel.Caption := TTranslator.Default.Translate(UserInterfaceTranslation.Preview);
InformationPanel.FocusManager := FocusManager;
InformationPanel.Style.Height.Value := TControlSize.Available;
LeftPanel := TVerticalSplitPanel.Create();
LeftPanel.PanelCount := 2;
LeftPanel.CaptionVisible := False;
LeftPanel.Panels[0] := ExplorerControl;
LeftPanel.Panels[1] := InformationPanel;
Result := LeftPanel;
end;
function TDefaultApplication.CreateExplorerTreeControl(const Root: TValue): TTreeControl;
var
ExplorerModel: TApplicationExplorerModel;
begin
ExplorerModel := TApplicationExplorerModel.Create();
ExplorerModel.TableFactory := TableFactory;
ExplorerModel.Root := TValuePath.Create([Root]);
Result := TTreeControl.Create();
Result.Caption := Root.ToText();
Result.Model := ExplorerModel;
end;
function TDefaultApplication.CreateLanguageToolBar(): TControl;
begin
Result := nil;
end;
function TDefaultApplication.CreateMainPanel(): TControl;
var
ExplorerPanel: THorizontalSplitPanel;
TopBar: TControl;
Problems: TControl;
begin
MainSplitPanel := TVerticalSplitPanel.Create();
MainSplitPanel.PanelCount := 4;
TopBar := CreateTopBar();
ExplorerPanel := CreateExplorerDetailsPanel();
ExplorerPanel.Style.Height.Value := TControlSize.Available;
Problems := CreateProblemsControl();
if Problems <> nil then
Problems.Style.Height.Value := TControlSizeFixed.Create(131);
MainSplitPanel.Panels[0] := TopBar;
MainSplitPanel.Panels[1] := ExplorerPanel;
MainSplitPanel.Panels[2] := Problems;
MainSplitPanel.Panels[3] := CreateProgressPanel();
MainSplitPanel.CloseEmptyPanels();
Result := MainSplitPanel;
end;
function TDefaultApplication.CreateObjectActionFactory(): TObjectActionFactory;
begin
Result := TDefaultActionFactory.Create();
end;
function TDefaultApplication.CreateObjectModelFactory(): TObjectModelFactory;
begin
Result := TDefaultObjectModelFactory.Create();
end;
function TDefaultApplication.CreateProblemsControl(): TControl;
begin
Result := nil;
end;
function TDefaultApplication.CreateProgressPanel(): TControl;
var
ProgressBar: TPercentageControl;
ProgressPanel: TVerticalStackPanel;
begin
ProgressPanel := TVerticalStackPanel.Create();
ProgressPanel.Caption := TTranslator.Default.Translate(UserInterfaceTranslation.Progress);
ProgressLabel := TSingleLineTextControl.CreateCaptionControl(TTranslator.Default.Translate(UserInterfaceTranslation.Ready));
ProgressLabel.Style.Height.Value := TControlSizeFixed.Create(18);
ProgressModel := TStaticPercentageModel.Create();
ProgressModel.AddReference();
ProgressBar := TPercentageControl.Create();
ProgressBar.Model := ProgressModel;
ProgressBar.Style.Height.Value := TControlSizeFixed.Create(15);
ProgressPanel.AddControl(ProgressLabel);
ProgressPanel.AddControl(ProgressBar);
Result := ProgressPanel;
end;
{$IF not Defined(FPC)}
procedure TDefaultApplication.CreateSqlConnectionControl();
begin
if DatabaseConnectors.Count > 0 then
begin
AssureExplorerPagedPanelExists();
Old_OpenControlForValue(TObjectReference.Create(DatabaseConnectors, TReferenceType.RefersTo), False, ExplorerPagedPanel);
end;
end;
{$ENDIF}
function TDefaultApplication.CreateTableFactory(): TTableModelFactory;
var
DefaultTableModelFactory: TDefaultTableModelFactory;
begin
DefaultTableModelFactory := TDefaultTableModelFactory.Create();
DefaultTableModelFactory.ObjectModelFactory := ObjectModelFactory;
Result := DefaultTableModelFactory;
end;
function TDefaultApplication.CreateTasksControl(): TTableControl;
begin
Result := TTableControl.Create();
Result.RowHeadersControl.Width := 45;
Result.Model := TTaskStatusTableModel.Create();
Result.Caption := TTranslator.Default.Translate(UserInterfaceTranslation.Tasks);
Result.AutoRefreshInterval := 500;
Result.AutoSizeAction := nil;
Result.Columns.SetItemSize(0, 290, False);
Result.Columns.SetItemSize(1, 130, False);
Result.Columns.SetItemSize(2, 110, False);
Result.Columns.SetItemSize(3, 86, False);
Result.Columns.SetItemSize(4, 86, False);
Result.Columns.SetItemSize(5, 176, False);
end;
function TDefaultApplication.CreateTestSuite(): TAutomatedTestSuite;
begin
Result := TDefaultTestSuite.Create('Tests');
end;
function TDefaultApplication.CreateToolBar(): TControl;
begin
Toolbar := THorizontalStackPanel.Create();
Toolbar.CaptionVisible := False;
Toolbar.InterControlSpace := 8;
AddToolbarButtons(Toolbar);
Result := Toolbar;
end;
function TDefaultApplication.CreateTopBar(): TControl;
var
LanguageToolBar: TControl;
TopSplitPanel: THorizontalSplitPanel;
ToolBar: TControl;
begin
ToolBar := CreateToolBar();
ToolBar.Style.Width.Value := TControlSize.Available;
LanguageToolBar := CreateLanguageToolBar();
if LanguageToolBar <> nil then
begin
TopSplitPanel := THorizontalSplitPanel.Create();
TopSplitPanel.PanelCount := 2;
TopSplitPanel.Panels[0] := ToolBar;
TopSplitPanel.Panels[1] := LanguageToolBar;
Result := TopSplitPanel;
end
else
Result := ToolBar;
end;
function TDefaultApplication.CreateWindow(): TWindow;
begin
Result := WindowFactory.CreateWindow();
end;
destructor TDefaultApplication.Destroy();
begin
TestSession.Free();
AuthorizationManager.Free();
TEventDistributionCenter.Instance.UnsubscribeEvent(Self);
WindowFactory.Free();
{$IF not Defined(FPC)}
TableSetRegistration.Free();
DatabaseConnectors.Free();
{$ENDIF}
inherited Destroy();
end;
function TDefaultApplication.DetermineWindowState(): TWindowState;
begin
Result := GetDefaultWindowState();
end;
function TDefaultApplication.DisplaySplashScreen(const Caption: TText): TControl;
var
SplashScreen: TLogoSplashScreen;
Monitor: TMonitor;
begin
SplashScreen := TLogoSplashScreen.Create();
SplashScreen.ApplicationName := Caption;
Monitor := SplashScreen.CreateNearestMonitor(TInteger32Point.New(0, 0));
SplashScreen.Position := SplashScreen.Bounds.CenterIn(Monitor.WorkBounds);
SplashScreen.ParentHandle := 0;
Monitor.Free();
SendMessage(SplashScreen.Handle, WM_PAINT, 0, 0);
Result := SplashScreen;
end;
procedure TDefaultApplication.ExecuteTests();
var
Run: TAutomatedTestRun;
begin
Run := TAutomatedTestRun.Create();
TestSession.Runs.Add(Run);
TTaskScheduler.Instance.Execute(TAutomatedTestTask.Create(TestSession.Tests, Run));
end;
function TDefaultApplication.GetApplicationCaption(): TText;
var
File_: TFile;
VersionInformation: TExecutableVersionInformation;
Company: TText;
begin
Result := GetCaption();
if IncludeVersionInCaption() then
begin
File_ := TFile.Create(TCurrentProcess.Instance.Path);
VersionInformation := TPlatform.Instance.GetExecutableVersionInformation(File_);
if VersionInformation <> nil then
Result := Result + ' ' + VersionInformation.ProductVersion;
File_.Free();
VersionInformation.Free();
end;
Company := GetCompany();
if Company.Count > 0 then
Result := Result + ' - ' + Company;
end;
function TDefaultApplication.GetCaption(): TText;
begin
Result := TCurrentProcess.Instance.Path.ToText();
end;
function TDefaultApplication.GetCompany(): TText;
begin
Result := 'Charta Software';
end;
function TDefaultApplication.GetDefaultWindowClass(): TWindowClass;
begin
Result := TDirect2dWindow;
end;
function TDefaultApplication.GetDefaultWindowState(): TWindowState;
begin
Result := TWindowState.Normal;
end;
function TDefaultApplication.GetExplorerRoot(): TValue;
begin
Result := GetApplicationExplorerRoot();
end;
function TDefaultApplication.GetInitialUserLevel(): TUserLevel;
begin
Result := ulDeveloper;
end;
function TDefaultApplication.GetProductId(): TUuid;
begin
Result := TUuid.Unknown;
end;
function TDefaultApplication.HandleContextMenuEvent(ContextMenuEvent: TControlContextMenuEvent): TBoolean;
begin
ShowContextMenuForControl(ContextMenuEvent.GetControl(), ContextMenuEvent.Position);
Result := True;
end;
function TDefaultApplication.HandleDefaultActionExecutedEvent(Event: TControlDefaultActionExecutedEvent): TBoolean;
var
Control: TControl;
FocusedObject: TValuePath;
Object_: TObject;
begin
Result := True;
Control := Event.GetControl();
FocusedObject := Control.GetFocusedObject();
FocusedObject.AddReference();
try
if FocusedObject.Length > 0 then
begin
Object_ := FocusedObject.ExtractLastObject();
if Object_ is TObjectAction then
(Object_ as TObjectAction).Execute(FocusManager.FocusedControl)
else
OpenControlForValue(FocusedObject, True);
end
else if Control.Path.Length > 0 then
OpenControlForValue(Control.Path, True);
finally
FocusedObject.ReleaseReference();
end;
end;
function TDefaultApplication.HandleEvent(Event: TEvent): TBoolean;
begin
if Event is TControlContextMenuEvent then
Result := HandleContextMenuEvent(Event as TControlContextMenuEvent)
else if Event is TControlDefaultActionExecutedEvent then
Result := HandleDefaultActionExecutedEvent(Event as TControlDefaultActionExecutedEvent)
else if Event is TTimerFired then
Result := HandleTimerFired(Event as TTimerFired)
else
Result := inherited HandleEvent(Event);
end;
procedure TDefaultApplication.HandleProgressTimer();
var
Statuses: TList<TTaskStatus>;
ExecutingStatuses: TList<TTaskStatus>;
Status: TTaskStatus;
begin
// Progress updates should be decoupled using listeners and functionality that should be monitored
// for progress should be executed in a different thread than the main thread.
Statuses := TTaskScheduler.Instance.GetStatuses();
ExecutingStatuses := TObjectList<TTaskStatus>.Create();
ExecutingStatuses.ElementManager := TReferenceUser<TTaskStatus>.Create();
ExecutingStatuses.FilterFrom(Statuses, TTaskStatus.TWithState.Create(TTaskState.Executing));
if ExecutingStatuses.Count > 0 then
begin
Status := ExecutingStatuses[0];
ProgressLabel.Text := Status.Name;
ProgressModel.Value := 100 * Status.Progress.ToFloatingPoint64();
if MainWindow.TaskBar <> nil then
begin
MainWindow.TaskBar.SetEnabled(True);
MainWindow.TaskBar.SetProgress(Status.Progress);
end;
end
else
begin
ProgressLabel.Text := TTranslator.Default.Translate(UserInterfaceTranslation.Ready);
ProgressModel.Value := 0;
if MainWindow.TaskBar <> nil then
MainWindow.TaskBar.SetEnabled(False);
end;
ExecutingStatuses.Free();
Statuses.Free();
ProgressTimer.Schedule(Self);
end;
function TDefaultApplication.HandleTimerFired(TimerFired: TTimerFired): TBoolean;
begin
Result := True;
if TimerFired.Timer = ProgressTimer then
HandleProgressTimer()
else
Result := False;
end;
function TDefaultApplication.IncludeVersionInCaption(): TBoolean;
begin
Result := True;
end;
procedure TDefaultApplication.Initialize(Configuration: TDomElement);
begin
{$IF not Defined(FPC)}
TableSetRegistration := TSqlTableSetRegistration.Create();
RegisterTableSets(TableSetRegistration);
TableSetRegistration.Initialize();
InitializeDatabaseConnectors(Configuration);
{$ENDIF}
if Configuration <> nil then
InitializeWindowFactory(Configuration.ElementWithName('Window'))
else
InitializeWindowFactory(nil);
end;
procedure TDefaultApplication.InitializeControls();
begin
{$IF not Defined(FPC)}
CreateSqlConnectionControl();
{$ENDIF}
end;
{$IF not Defined(FPC)}
procedure TDefaultApplication.InitializeDatabaseConnectors(Configuration: TDomElement);
var
Element: TDomElement;
Iterator: TIterator<TDomElement>;
begin
if Configuration <> nil then
Element := Configuration.ElementWithName('Databases')
else
Element := nil;
if Element <> nil then
begin
Iterator := Element.CreateElementWithNameIterator('Database');
while Iterator.IsValid() do
begin
DatabaseConnectors.Add(TSqlDatabaseConnector.CreateFor(TSqlConnectionSettings.CreateFromElement(Iterator.Current)));
Iterator.GotoNext();
end;
Iterator.Free();
end;
end;
{$ENDIF}
procedure TDefaultApplication.InitializeWindowFactory(Element: TDomElement);
var
Type_: TText;
begin
WindowFactory := TWindowFactory.Create();
if Element <> nil then
begin
Type_ := Element.Attributes.Get('Type').AsText();
WindowFactory.WindowClass := TextToWindowClass(Type_);
WindowFactory.DebugUpdateRegion := Element.Attributes.GetOptional('DebugUpdateRegion').AsBooleanWithDefault(False);
if WindowFactory.WindowClass = nil then
raise EUnknownEnumerationValue.Create('Unknown window type: ' + Type_);
end
else
WindowFactory.WindowClass := GetDefaultWindowClass();
end;
procedure TDefaultApplication.InstallHotKeys();
var
HotKey: THotKey;
begin
HotKey := TActionHotKey.Create(TSwitchStyleSheetAction.Create(Self));
HotKey.Configure(TKey.F12, []);
HotKeyManager.Add(HotKey);
end;
procedure TDefaultApplication.OpenTests();
begin
Old_OpenControlForValue(TObjectReference.Create(TestSession, TReferenceType.RefersTo), True);
end;
procedure TDefaultApplication.OpenExplorer();
begin
OpenControl(CreateExplorerTreeControl(GetExplorerRoot()), True);
end;
procedure TDefaultApplication.OpenTasks();
begin
OpenControl(CreateTasksControl(), True);
end;
{$IF not Defined(FPC)}
procedure TDefaultApplication.RegisterTableSets(TableSetRegistration: TSqlTableSetRegistration);
begin
TableSetRegistration.Register(DatabaseManagementTableSet);
TableSetRegistration.Register(UserManagementTableSet);
TableSetRegistration.Register(VersionedDatabaseTableSet);
end;
{$ENDIF}
procedure TDefaultApplication.ShowContextMenuForControl(Control: TControl; const Position: TInteger32Point);
var
TableModel: TObjectActionTableModel;
Actions: TList<TObjectAction>;
Path: TValuePath;
Selection: TObjectSelection;
begin
Actions := nil;
Selection := Control.GetObjectSelection();
Selection.AddReference();
if Selection <> nil then
Actions := ObjectActionFactory.CreateActionsForObjects(Selection)
else
begin
Path := Control.GetFocusedObject();
Path.AddReference();
try
if Path.Length > 0 then
begin
Selection := TObjectSelection.Create();
Selection.AddReference();
Selection.Objects.Add(Path);
Actions := ObjectActionFactory.CreateActionsForObjects(Selection);
end;
finally
Path.ReleaseReference();
end;
end;
Selection.ReleaseReference();
if (Actions <> nil) and (Actions.Count > 0) then
begin
TableModel := TObjectActionTableModel.Create();
TableModel.Objects := Actions;
MainWindow.ContextMenuControl.TableControl.Model := TableModel;
MainWindow.ContextMenuControl.SizeAndShow(Control.RelativeToScreen(Position), 200);
end
else
Actions.Free();
end;
procedure TDefaultApplication.SwitchStyleSheet();
var
Iterator: TIterator<TControl>;
Control: TControl;
begin
if CurrentStyleSheet < High(TDefaultApplicationStyleSheet) then
Inc(CurrentStyleSheet)
else
CurrentStyleSheet := Low(TDefaultApplicationStyleSheet);
case CurrentStyleSheet of
TDefaultApplicationStyleSheet.Normal:
begin
Iterator := MainWindow.CreateSubtreeIterator(TTreeVerticalOrder.TopDown);
while Iterator.IsValid() do
begin
Control := Iterator.Current;
Control.Style.Background.Fill := TFill.Create(TNamedColor.White);
Control.Style.PanelBackground.Fill := TFill.Create(TPurposeColor.Panel);
Iterator.GotoNext();
end;
Iterator.Free();
end;
TDefaultApplicationStyleSheet.Night:
begin
Iterator := MainWindow.CreateSubtreeIterator(TTreeVerticalOrder.TopDown);
while Iterator.IsValid() do
begin
Control := Iterator.Current;
Control.Style.Background.Fill := TFill.Create(TNamedColor.LightGray);
Control.Style.PanelBackground.Fill := TFill.Create(TNamedColor.DarkGray);
Iterator.GotoNext();
end;
Iterator.Free();
end
else
raise EUnknownEnumerationValue.Create('Unknown style sheet');
end;
end;
function TDefaultApplication.TextToWindowClass(const Type_: TText): TWindowClass;
begin
if Type_ = 'GDI' then
Result := TGdiWindow
else if Type_ = 'Direct2D' then
Result := TDirect2dWindow
else if Type_ = 'OpenGL' then
Result := TOpenGlWindow
else
Result := nil;
end;
end.
|