forked from TES5Edit/TES3Edit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cxVTEditors.pas
369 lines (304 loc) · 9.87 KB
/
cxVTEditors.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
{*******************************************************************************
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/
Software distributed under the License is distributed on an "AS IS"
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
License for the specific language governing rights and limitations
under the License.
*******************************************************************************}
unit cxVTEditors;
interface
uses
Windows,
SysUtils,
Controls,
VTEditors, VirtualTrees,
cxEdit, cxTextEdit, cxDropDownEdit,cxCheckComboBox,
cxLookAndFeelPainters;
type
TcxCustomEditLink = class(TCustomEditLink)
end;
TcxCustomTextEditLink = class(TcxCustomEditLink)
protected
function GetHookableWindowProc: TWndMethod; override;
procedure SetHookableWindowProc(const Value: TWndMethod); override;
procedure SetBounds(R: TRect); override;
end;
TcxTextEditLink = class(TcxCustomTextEditLink)
protected {private}
telProperties: TcxTextEditProperties;
function telGetProperties: TcxTextEditProperties;
procedure telSetProperties(const Value: TcxTextEditProperties);
procedure KeyPress(Sender: TObject; var Key: Char);
protected
function CreateEditControl: TWinControl; override;
function GetEditText: WideString; override;
procedure SetEditText(const Value: WideString); override;
procedure PrepareEditControl; override;
function IsMultiLine: Boolean; override;
procedure AfterBeginEdit; override;
public
destructor Destroy; override;
published
property Properties: TcxTextEditProperties
read telGetProperties
write telSetProperties;
end;
TcxCustomMaskEditLink = class(TcxCustomTextEditLink)
end;
TcxCustomDropDownEditLink = class(TcxCustomMaskEditLink)
end;
TcxCustomComboBoxLink = class(TcxCustomDropDownEditLink)
end;
TcxComboEditLink = class(TcxCustomComboBoxLink)
protected {private}
celProperties: TcxComboBoxProperties;
function celGetProperties: TcxComboBoxProperties;
procedure celSetProperties(const Value: TcxComboBoxProperties);
procedure KeyPress(Sender: TObject; var Key: Char);
protected
function CreateEditControl: TWinControl; override;
function GetEditText: WideString; override;
procedure SetEditText(const Value: WideString); override;
procedure PrepareEditControl; override;
function IsMultiLine: Boolean; override;
procedure AfterBeginEdit; override;
public
destructor Destroy; override;
published
property Properties: TcxComboBoxProperties
read celGetProperties
write celSetProperties;
end;
TcxCustomCheckComboBoxLink = class(TcxCustomComboBoxLink)
end;
TcxCheckComboEditLink = class(TcxCustomCheckComboBoxLink)
protected {private}
ccelProperties: TcxCheckComboBoxProperties;
function ccelGetProperties: TcxCheckComboBoxProperties;
procedure ccelSetProperties(const Value: TcxCheckComboBoxProperties);
procedure KeyPress(Sender: TObject; var Key: Char);
protected
function CreateEditControl: TWinControl; override;
function GetEditText: WideString; override;
procedure SetEditText(const aValue: WideString); override;
procedure PrepareEditControl; override;
function IsMultiLine: Boolean; override;
procedure AfterBeginEdit; override;
public
destructor Destroy; override;
published
property Properties: TcxCheckComboBoxProperties
read ccelGetProperties
write ccelSetProperties;
end;
implementation
type
TcxCustomEditHacker = class(TcxCustomEdit);
TcxCustomTextEditHacker = class(TcxCustomTextEdit);
{ TcxComboEditLink }
procedure TcxComboEditLink.AfterBeginEdit;
begin
inherited;
TcxComboBox(EditControl).SelectAll;
end;
function TcxComboEditLink.celGetProperties: TcxComboBoxProperties;
begin
if not Assigned(celProperties) then
celProperties := TcxComboBoxProperties.Create(Self);
Result := celProperties;
end;
procedure TcxComboEditLink.celSetProperties(const Value: TcxComboBoxProperties);
begin
if not Assigned(celProperties) then
celProperties := TcxComboBoxProperties.Create(Self);
celGetProperties.Assign(Value);
end;
function TcxComboEditLink.CreateEditControl: TWinControl;
begin
Result := TcxComboBox.Create(nil, True);
end;
destructor TcxComboEditLink.Destroy;
begin
FreeAndNil(celProperties);
inherited;
end;
function TcxComboEditLink.GetEditText: WideString;
begin
Result := TcxComboBox(EditControl).Text;
end;
function TcxComboEditLink.IsMultiLine: Boolean;
begin
Result := True;
end;
procedure TcxComboEditLink.KeyPress(Sender: TObject; var Key: Char);
begin
if Key in [#13, #27] then Key := #0; // Eliminate beep
end;
procedure TcxComboEditLink.PrepareEditControl;
begin
inherited;
with TcxComboBox(EditControl) do begin
if Assigned(celProperties) then
Properties := celProperties;
OnKeyPress := KeyPress;
end;
end;
procedure TcxComboEditLink.SetEditText(const Value: WideString);
begin
TcxComboBox(EditControl).Text := Value;
end;
{ TcxCustomTextEditLink }
function TcxCustomTextEditLink.GetHookableWindowProc: TWndMethod;
begin
Result := TcxCustomTextEditHacker(EditControl).InnerTextEdit.Control.WindowProc
end;
procedure TcxCustomTextEditLink.SetBounds(R: TRect);
begin
if not FStopping then begin
with R do begin
// Set the edit's bounds but make sure there's a minimum width and the right border does not
// extend beyond the parent's left/right border.
Dec(Left, FTree.TextMargin);
if Left < 0 then
Left := 0;
Dec(Right);
if Right - Left < 30 then
Right := Left + 30;
if Right > FTree.ClientWidth then
Right := FTree.ClientWidth;
FEdit.BoundsRect := R;
R.Left := FTree.TextMargin * 2;
R.Top := -1;
R.Right := 0;
R.Bottom := 0;
TcxCustomTextEditHacker(EditControl).ContentParams.Offsets := R;
end;
end;
end;
procedure TcxCustomTextEditLink.SetHookableWindowProc(const Value: TWndMethod);
begin
TcxCustomTextEditHacker(EditControl).InnerTextEdit.Control.WindowProc := Value;
end;
{ TcxCheckComboEditLink }
procedure TcxCheckComboEditLink.AfterBeginEdit;
begin
inherited;
with TcxCheckComboBox(EditControl) do
DroppedDown := True;
end;
function TcxCheckComboEditLink.ccelGetProperties: TcxCheckComboBoxProperties;
begin
if not Assigned(ccelProperties) then
ccelProperties := TcxCheckComboBoxProperties.Create(Self);
Result := ccelProperties;
end;
procedure TcxCheckComboEditLink.ccelSetProperties(const Value: TcxCheckComboBoxProperties);
begin
if not Assigned(ccelProperties) then
ccelProperties := TcxCheckComboBoxProperties.Create(Self);
ccelProperties.Assign(ccelProperties);
end;
function TcxCheckComboEditLink.CreateEditControl: TWinControl;
begin
Result := TcxCheckComboBox.Create(nil, True);
end;
destructor TcxCheckComboEditLink.Destroy;
begin
FreeAndNil(ccelProperties);
inherited;
end;
function TcxCheckComboEditLink.GetEditText: WideString;
var
i : Integer;
begin
with TcxCheckComboBox(EditControl) do begin
Result := StringOfChar('0', Properties.Items.Count);
for i := 0 to Pred(Properties.Items.Count) do
if States[i] = cbsChecked then
Result[Succ(i)] := '1';
end;
end;
function TcxCheckComboEditLink.IsMultiLine: Boolean;
begin
Result := True;
end;
procedure TcxCheckComboEditLink.KeyPress(Sender: TObject; var Key: Char);
begin
if Key in [#13, #27] then Key := #0; // Eliminate beep
end;
procedure TcxCheckComboEditLink.PrepareEditControl;
begin
inherited;
with TcxCheckComboBox(EditControl) do begin
if Assigned(ccelProperties) then
Properties := ccelProperties;
OnKeyPress := KeyPress;
end;
end;
procedure TcxCheckComboEditLink.SetEditText(const aValue: WideString);
var
i : Integer;
begin
with TcxCheckComboBox(EditControl) do
for i := 0 to Pred(Properties.Items.Count) do
if (Succ(i) <= Length(aValue)) and (aValue[Succ(i)] = '1') then
States[i] := cbsChecked
else
States[i] := cbsUnchecked;
end;
{ TcxTextEditLink }
procedure TcxTextEditLink.AfterBeginEdit;
begin
inherited;
TcxTextEdit(EditControl).SelectAll;
end;
function TcxTextEditLink.CreateEditControl: TWinControl;
begin
Result := TcxTextEdit.Create(nil, True);
end;
destructor TcxTextEditLink.Destroy;
begin
FreeAndNil(telProperties);
inherited;
end;
function TcxTextEditLink.GetEditText: WideString;
begin
Result := TcxTextEdit(EditControl).Text;
end;
function TcxTextEditLink.IsMultiLine: Boolean;
begin
Result := True;
end;
procedure TcxTextEditLink.KeyPress(Sender: TObject; var Key: Char);
begin
if Key in [#13, #27] then Key := #0; // Eliminate beep
end;
procedure TcxTextEditLink.PrepareEditControl;
begin
inherited;
with TcxTextEdit(EditControl) do begin
if Assigned(telProperties) then
Properties := telProperties;
OnKeyPress := KeyPress;
end;
end;
procedure TcxTextEditLink.SetEditText(const Value: WideString);
begin
TcxTextEdit(EditControl).Text := Value;
end;
function TcxTextEditLink.telGetProperties: TcxTextEditProperties;
begin
if not Assigned(telProperties) then
telProperties := TcxTextEditProperties.Create(Self);
Result := telProperties;
end;
procedure TcxTextEditLink.telSetProperties(const Value: TcxTextEditProperties);
begin
if not Assigned(telProperties) then
telProperties := TcxTextEditProperties.Create(Self);
telGetProperties.Assign(Value);
end;
end.