-
Notifications
You must be signed in to change notification settings - Fork 2
/
uMain.pas
110 lines (92 loc) · 2.39 KB
/
uMain.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
unit uMain;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.StdCtrls;
type
TfMain = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormPaint(Sender: TObject);
private
procedure DrawTaskList;
procedure TaskLaunchButtonClick(Sender: TObject);
public
end;
var
fMain: TfMain;
implementation
{$R *.dfm}
uses
uTask;
procedure TfMain.DrawTaskList;
function CreateYearBox(const Year: Integer): TGroupBox;
begin
Result := TGroupBox.Create(Application);
with Result do
begin
Left := 2000;
Parent := fMain;
Caption := 'Year ' + IntToStr(Year);
Align := alLeft;
AlignWithMargins := True;
Width := 300;
end;
end;
function CreateTaskButton(const Task: TTask; const Box: TGroupBox; const TaskIndex: Integer): TButton;
begin
Result := TButton.Create(Application);
with Result do
begin
Parent := Box;
Left := 8;
Top := 16 + Height * (Task.Number - 1);
Caption := Format('Task %0.2d (%s)', [ Task.Number, Task.Name ]);
OnClick := TaskLaunchButtonClick;
Width := Box.Width - 16;
Tag := TaskIndex;
end;
end;
var
I, Year, FormWidth, FormHeight: Integer;
YearBox: TGroupBox;
begin
FormWidth := 16;
FormHeight := 0;
Year := -1;
YearBox := nil;
with TTaskHost.Tasks do
for I := 0 to Count - 1 do
begin
if Year <> Items[I].Year then
begin
Year := Items[I].Year;
YearBox := CreateYearBox(Year);
Inc(FormWidth, YearBox.Width + 6);
end;
with CreateTaskButton(Items[I], YearBox, I) do
if FormHeight < 68 + Top + Height then
FormHeight := 68 + Top + 8;
end;
if FormWidth > Screen.DesktopWidth - 100 then
begin
fMain.HorzScrollBar.Range := FormWidth - 6;
FormWidth := Screen.DesktopWidth - 100;
end;
fMain.Width := FormWidth;
fMain.Height := FormHeight + 16;
end;
procedure TfMain.FormCreate(Sender: TObject);
begin
DrawTaskList;
end;
procedure TfMain.FormPaint(Sender: TObject);
begin
fMain.HorzScrollBar.Position := 4092;
fMain.OnPaint := nil;
end;
procedure TfMain.TaskLaunchButtonClick(Sender: TObject);
begin
with TButton(Sender) do
TTaskHost.Tasks[Tag].Run;
end;
end.