-
Notifications
You must be signed in to change notification settings - Fork 1
/
frmLegendForm.pas
189 lines (170 loc) · 5.54 KB
/
frmLegendForm.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
unit frmLegendForm;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Grids, System.IniFiles,
wbInterface;
type
TfrmLegend = class(TForm)
dgLegend: TDrawGrid;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormDestroy(Sender: TObject);
procedure FormHide(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure dgLegendDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);
procedure FormShow(Sender: TObject);
private
CellSizeCalc: Integer;
public
Settings: TMemIniFile;
end;
var
frmLegend: TfrmLegend;
implementation
{$R *.dfm}
uses
Math,
frmViewMain;
procedure TfrmLegend.dgLegendDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);
var
s: string;
i, j: Integer;
ConflictAll : TConflictAll;
ConflictThis : TConflictThis;
begin
case CellSizeCalc of
0: begin
CellSizeCalc := 1;
j := 0;
with dgLegend.Canvas do
for i := 1 to Pred(dgLegend.RowCount) do
j := Max(j, TextWidth(wbNameConflictAll[TConflictAll(i)]+'oo'));
dgLegend.ColWidths[0] := j;
with dgLegend.Canvas do
for i := 1 to Pred(dgLegend.ColCount) do
dgLegend.ColWidths[i] := TextWidth(wbNameConflictThis[TConflictThis(i)]+'oo');
CellSizeCalc := 2;
with dgLegend, CellRect(Pred(ColCount), Pred(RowCount)) do begin
Self.ClientWidth := Right+2;
Self.ClientHeight := Bottom+2;
end;
dgLegend.Invalidate;
end;
1: dgLegend.Canvas.FillRect(Rect);
2: begin
with dgLegend.Canvas do begin
if aCol = 0 then begin
s := wbNameConflictAll[TConflictAll(aRow)];
TextRect(Rect, s, [tfCenter, tfVerticalCenter, tfSingleLine]);
end else begin
s := wbNameConflictThis[TConflictThis(aCol)];
if ARow > 0 then begin
ConflictAll := TConflictAll(aRow);
ConflictThis := TConflictThis(aCol);
if ConflictAll >= caNoConflict then
Brush.Color := wbLighter(ConflictAllToColor(ConflictAll), 0.85)
else
Brush.Color := clWindow;
Font.Color := wbDarker(ConflictThisToColor(ConflictThis));
FillRect(Rect);
end;
TextRect(Rect, s, [tfCenter, tfVerticalCenter, tfSingleLine]);
end;
if not (gdFocused in State) then
if (aRow = dgLegend.Row) and (aCol = dgLegend.Col) then
DrawFocusRect(Rect);
end;
end;
end;
end;
procedure TfrmLegend.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caHide;
end;
procedure TfrmLegend.FormCreate(Sender: TObject);
var
lLeft, lTop, lWidth, lHeight : Integer;
lRect: TRect;
begin
DoubleBuffered := True;
dgLegend.DoubleBuffered := True;
wbApplyFontAndScale(Self);
Settings := frmMain.Settings;
if Assigned(Settings) then begin
lLeft := Settings.ReadInteger(Name, 'Left', 0);
lTop := Settings.ReadInteger(Name, 'Top', 0);
lWidth := Settings.ReadInteger(Name, 'Width', 0);
lHeight := Settings.ReadInteger(Name, 'Height', 0);
if (lWidth > 100) and (lHeight > 100) then begin
lRect := Screen.DesktopRect;
if (lLeft+16 >= lRect.Left) and
(lTop+16 >= lRect.Top) and
((lLeft + lWidth)-16 <= lRect.Right) and
((lTop + lHeight)-16 <= lRect.Bottom)
then begin
Left := lLeft;
Top := lTop;
Width := lWidth;
Height := lHeight;
Position := poDesigned;
end;
end;
WindowState := TWindowState(Settings.ReadInteger(Name, 'WindowState', Integer(WindowState)));
if WindowState = wsMaximized then
Position := poDesigned;
end;
dgLegend.Align := alNone;
dgLegend.BoundsRect := Rect(0, 0, 6000, 3000);
dgLegend.ColCount := Succ(Ord(High(TConflictThis)));
dgLegend.RowCount := Succ(Ord(High(TConflictAll)));
end;
procedure TfrmLegend.FormDestroy(Sender: TObject);
begin
if frmLegend = Self then
frmLegend := nil;
end;
procedure TfrmLegend.FormHide(Sender: TObject);
begin
if Assigned(frmMain) then begin
frmMain.bnLegend.Down := False;
if Assigned(Settings) then begin
if WindowState <> wsMinimized then
Settings.WriteInteger(Name, 'WindowState', Integer(WindowState));
if WindowState = wsNormal then begin
Settings.WriteInteger(Name, 'Left', Left);
Settings.WriteInteger(Name, 'Top', Top);
Settings.WriteInteger(Name, 'Width', Width);
Settings.WriteInteger(Name, 'Height', Height);
end;
Settings.UpdateFile;
end;
end;
end;
procedure TfrmLegend.FormShow(Sender: TObject);
var
lLeft, lTop, lWidth, lHeight : Integer;
lRect: TRect;
begin
if Assigned(Settings) then begin
lLeft := Settings.ReadInteger(Name, 'Left', 0);
lTop := Settings.ReadInteger(Name, 'Top', 0);
lWidth := Settings.ReadInteger(Name, 'Width', 0);
lHeight := Settings.ReadInteger(Name, 'Height', 0);
if (lWidth > 100) and (lHeight > 100) then begin
lRect := Screen.DesktopRect;
if (lLeft+16 >= lRect.Left) and
(lTop+16 >= lRect.Top) and
((lLeft + lWidth)-16 <= lRect.Right) and
((lTop + lHeight)-16 <= lRect.Bottom)
then begin
Left := lLeft;
Top := lTop;
Position := poDesigned;
end;
end;
WindowState := TWindowState(Settings.ReadInteger(Name, 'WindowState', Integer(WindowState)));
if WindowState = wsMaximized then
Position := poDesigned;
end;
end;
end.