-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathItemsSelectForm.pas
291 lines (252 loc) · 7.5 KB
/
ItemsSelectForm.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
unit ItemsSelectForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, CheckLst, Menus,
CountedDynArrayInteger,
InflatablesList_Manager;
type
TfItemsSelectForm = class(TForm)
clbItems: TCheckListBox;
lblItems: TLabel;
pmItemsMenu: TPopupMenu;
mniIM_CheckSelected: TMenuItem;
mniIM_UncheckSelected: TMenuItem;
mniIM_InvertSelected: TMenuItem;
N1: TMenuItem;
mniIM_CheckAll: TMenuItem;
mniIM_UncheckAll: TMenuItem;
mniIM_InvertAll: TMenuItem;
btnAccept: TButton;
btnClose: TButton;
procedure FormCreate(Sender: TObject);
procedure clbItemsClick(Sender: TObject);
procedure clbItemsMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure mniIM_CheckSelectedClick(Sender: TObject);
procedure mniIM_UncheckSelectedClick(Sender: TObject);
procedure mniIM_InvertSelectedClick(Sender: TObject);
procedure mniIM_CheckAllClick(Sender: TObject);
procedure mniIM_UncheckAllClick(Sender: TObject);
procedure mniIM_InvertAllClick(Sender: TObject);
procedure btnAcceptClick(Sender: TObject);
procedure btnCloseClick(Sender: TObject);
private
fILManager: TILManager;
fAccepted: Boolean;
protected
procedure UpdateIndex;
procedure SelectItem(Index: Integer);
public
procedure Initialize(ILManager: TILManager);
procedure Finalize;
procedure ShowItemsSelect(const Title: String; var Indices: TCountedDynArrayInteger);
end;
var
fItemsSelectForm: TfItemsSelectForm;
implementation
uses
InflatablesList_Utils;
{$R *.dfm}
procedure TfItemsSelectForm.UpdateIndex;
begin
If clbItems.SelCount <= 1 then
begin
If clbItems.Count > 0 then
lblItems.Caption := IL_Format('Items (%d/%d):',[clbItems.ItemIndex + 1,clbItems.Count])
else
lblItems.Caption := 'Items:';
end
else lblItems.Caption := IL_Format('Items (%d/%d)(%d):',[clbItems.ItemIndex + 1,clbItems.Count,clbItems.SelCount])
end;
//------------------------------------------------------------------------------
procedure TfItemsSelectForm.SelectItem(Index: Integer);
var
i: Integer;
begin
clbItems.ItemIndex := Index;
clbItems.Items.BeginUpdate;
try
For i := 0 to Pred(clbItems.Count) do
clbItems.Selected[i] := i = Index;
finally
clbItems.Items.EndUpdate;
end;
end;
//==============================================================================
procedure TfItemsSelectForm.Initialize(ILManager: TILManager);
begin
fILManager := ILManager;
end;
//------------------------------------------------------------------------------
procedure TfItemsSelectForm.Finalize;
begin
// nothing to do here
end;
//------------------------------------------------------------------------------
procedure TfItemsSelectForm.ShowItemsSelect(const Title: String; var Indices: TCountedDynArrayInteger);
var
i: Integer;
TempStr: String;
begin
fAccepted := False;
Caption := Title;
// fill list
clbItems.Items.BeginUpdate;
try
clbItems.Clear;
For i := fIlManager.ItemLowIndex to fILManager.ItemHighIndex do
begin
If Length(fILManager[i].SizeStr) > 0 then
TempStr := IL_Format('%s (%s - %s)',[fILManager[i].TitleStr,fILManager[i].TypeStr,fILManager[i].SizeStr])
else
TempStr := IL_Format('%s (%s)',[fILManager[i].TitleStr,fILManager[i].TypeStr]);
// user id
If Length(fILManager[i].UserID) > 0 then
TempStr := IL_Format('[%s] %s',[fILManager[i].UserID,TempStr]);
// text tag
If Length(fILManager[i].TextTag) > 0 then
TempStr := TempStr + IL_Format(' {%s}',[fILManager[i].TextTag]);
// num tag
If fILManager[i].NumTag <> 0 then
TempStr := TempStr + IL_Format(' [%d]',[fILManager[i].NumTag]);
clbItems.Items.Add(TempStr);
end;
For i := CDA_Low(Indices) to CDA_High(Indices) do
If (CDA_GetItem(Indices,i) >= 0) and (CDA_GetItem(Indices,i) < clbItems.Items.Count) then
clbItems.Checked[CDA_GetItem(Indices,i)] := True;
finally
clbItems.Items.EndUpdate;
end;
If clbItems.Count > 0 then
SelectItem(0);
clbItems.OnClick(nil);
UpdateIndex;
ShowModal;
CDA_Clear(Indices);
If fAccepted then
For i := 0 to Pred(clbItems.Count) do
If clbItems.Checked[i] then
CDA_Add(Indices,i);
end;
//==============================================================================
procedure TfItemsSelectForm.FormCreate(Sender: TObject);
begin
clbItems.MultiSelect := True; // cannot be set design-time
end;
//------------------------------------------------------------------------------
procedure TfItemsSelectForm.clbItemsClick(Sender: TObject);
begin
UpdateIndex;
end;
//------------------------------------------------------------------------------
procedure TfItemsSelectForm.clbItemsMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
Index: Integer;
begin
If Button = mbRight then
begin
Index := clbItems.ItemAtPos(Point(X,Y),True);
If Index >= 0 then
begin
If clbItems.SelCount <= 1 then
SelectItem(Index);
clbItems.OnClick(nil);
end;
end;
end;
//------------------------------------------------------------------------------
procedure TfItemsSelectForm.mniIM_CheckSelectedClick(Sender: TObject);
var
i: Integer;
begin
clbItems.Items.BeginUpdate;
try
For i := 0 to Pred(clbItems.Count) do
If clbItems.Selected[i] then
clbItems.Checked[i] := True;
finally
clbItems.Items.EndUpdate;
end;
end;
//------------------------------------------------------------------------------
procedure TfItemsSelectForm.mniIM_UncheckSelectedClick(Sender: TObject);
var
i: Integer;
begin
clbItems.Items.BeginUpdate;
try
For i := 0 to Pred(clbItems.Count) do
If clbItems.Selected[i] then
clbItems.Checked[i] := False;
finally
clbItems.Items.EndUpdate;
end;
end;
//------------------------------------------------------------------------------
procedure TfItemsSelectForm.mniIM_InvertSelectedClick(Sender: TObject);
var
i: Integer;
begin
clbItems.Items.BeginUpdate;
try
For i := 0 to Pred(clbItems.Count) do
If clbItems.Selected[i] then
clbItems.Checked[i] := not clbItems.Checked[i];
finally
clbItems.Items.EndUpdate;
end;
end;
//------------------------------------------------------------------------------
procedure TfItemsSelectForm.mniIM_CheckAllClick(Sender: TObject);
var
i: Integer;
begin
clbItems.Items.BeginUpdate;
try
For i := 0 to Pred(clbItems.Count) do
clbItems.Checked[i] := True;
finally
clbItems.Items.EndUpdate;
end;
end;
//------------------------------------------------------------------------------
procedure TfItemsSelectForm.mniIM_UncheckAllClick(Sender: TObject);
var
i: Integer;
begin
clbItems.Items.BeginUpdate;
try
For i := 0 to Pred(clbItems.Count) do
clbItems.Checked[i] := False;
finally
clbItems.Items.EndUpdate;
end;
end;
//------------------------------------------------------------------------------
procedure TfItemsSelectForm.mniIM_InvertAllClick(Sender: TObject);
var
i: Integer;
begin
clbItems.Items.BeginUpdate;
try
For i := 0 to Pred(clbItems.Count) do
clbItems.Checked[i] := not clbItems.Checked[i];
finally
clbItems.Items.EndUpdate;
end;
end;
//------------------------------------------------------------------------------
procedure TfItemsSelectForm.btnAcceptClick(Sender: TObject);
begin
fAccepted := True;
Close;
end;
//------------------------------------------------------------------------------
procedure TfItemsSelectForm.btnCloseClick(Sender: TObject);
begin
fAccepted := False;
Close;
end;
end.