-
Notifications
You must be signed in to change notification settings - Fork 86
/
uEditors.pas
296 lines (270 loc) · 7.21 KB
/
uEditors.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
unit uEditors;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, VirtualTrees, ExtDlgs, ImgList, Buttons, ExtCtrls, ComCtrls,
Mask, uSharedGlobals;
type
TValueType = (
vtNone,
vtString,
vtPickString,
vtNumber,
vtPickNumber,
vtMemo,
vtDate
);
type
// PPropertyData = ^TPropertyData;
// TPropertyData = record
// ValueType: TValueType;
// Value: UnicodeString;
// Changed: Boolean;
// end;
TPropertyEditLink = class(TInterfacedObject, IVTEditLink)
private
FEdit: TWinControl; // One of the property editor classes.
FTree: TVirtualStringTree; // A back reference to the tree calling.
FNode: PVirtualNode; // The node being edited.
FColumn: Integer; // The column of the node being edited.
protected
procedure EditKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure EditKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
public
destructor Destroy; override;
function BeginEdit: Boolean; stdcall;
function CancelEdit: Boolean; stdcall;
function EndEdit: Boolean; stdcall;
function GetBounds: TRect; stdcall;
function PrepareEdit(Tree: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex): Boolean; stdcall;
procedure ProcessMessage(var Message: TMessage); stdcall;
procedure SetBounds(R: TRect); stdcall;
end;
type
TPropertyTextKind = (
ptkText,
ptkHint
);
implementation
destructor TPropertyEditLink.Destroy;
begin
if FEdit.HandleAllocated then
PostMessage(FEdit.Handle, CM_RELEASE, 0, 0);
inherited;
end;
procedure TPropertyEditLink.EditKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
var
CanAdvance: Boolean;
begin
CanAdvance := true;
case Key of
VK_ESCAPE:
begin
Key := 0;//ESC will be handled in EditKeyUp()
end;
VK_RETURN:
if CanAdvance then
begin
FTree.EndEditNode;
Key := 0;
end;
VK_UP,
VK_DOWN:
begin
// Consider special cases before finishing edit mode.
CanAdvance := Shift = [];
if FEdit is TComboBox then
CanAdvance := CanAdvance and not TComboBox(FEdit).DroppedDown;
if FEdit is TDateTimePicker then
CanAdvance := CanAdvance and not TDateTimePicker(FEdit).DroppedDown;
if CanAdvance then
begin
// Forward the keypress to the tree. It will asynchronously change the focused node.
PostMessage(FTree.Handle, WM_KEYDOWN, Key, 0);
Key := 0;
end;
end;
end;
end;
procedure TPropertyEditLink.EditKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
case Key of
VK_ESCAPE:
begin
FTree.CancelEditNode;
Key := 0;
end;//VK_ESCAPE
VK_RETURN:
begin
FTree.EndEditNode;
Key := 0;
end;
end;//case
end;
function TPropertyEditLink.BeginEdit: Boolean;
begin
Result := True;
FEdit.Show;
FEdit.SetFocus;
end;
function TPropertyEditLink.CancelEdit: Boolean;
begin
Result := True;
FEdit.Hide;
FTree.SetFocus;
end;
function TPropertyEditLink.EndEdit: Boolean;
var
//Data: PPropertyData;
Data: PFunctionData;
Buffer: array[0..1024] of Char;
S: UnicodeString;
begin
Result := True;
Data := FTree.GetNodeData(FNode);
// if FEdit is TComboBox then
// S := TComboBox(FEdit).Text
// else
// begin
GetWindowText(FEdit.Handle, Buffer, 1024);
S := Buffer;
// end;
if S <> Data.ExportAs then
begin
Data.ExportAs := S;
// Data.Changed := True;
FTree.InvalidateNode(FNode);
end;
FEdit.Hide;
FTree.SetFocus;
end;
function TPropertyEditLink.GetBounds: TRect;
begin
Result := FEdit.BoundsRect;
end;
function TPropertyEditLink.PrepareEdit(Tree: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex): Boolean;
var
//Data: PPropertyData;
Data: PFunctionData;
begin
Result := True;
FTree := Tree as TVirtualStringTree;
FNode := Node;
FColumn := Column;
// // determine what edit type actually is needed
FEdit.Free;
FEdit := nil;
Data := FTree.GetNodeData(Node);
FEdit := TEdit.Create(nil);
with FEdit as TEdit do
begin
Visible := False;
Parent := Tree;
Text := Data.ExportAs;
OnKeyDown := EditKeyDown;
OnKeyUp := EditKeyUp;
end;
// case Data.ValueType of
// vtString:
// begin
// FEdit := TEdit.Create(nil);
// with FEdit as TEdit do
// begin
// Visible := False;
// Parent := Tree;
// Text := Data.Value;
// OnKeyDown := EditKeyDown;
// OnKeyUp := EditKeyUp;
// end;
// end;
// vtPickString:
// begin
// FEdit := TComboBox.Create(nil);
// with FEdit as TComboBox do
// begin
// Visible := False;
// Parent := Tree;
// Text := Data.Value;
// Items.Add(Text);
// Items.Add('Standard');
// Items.Add('Additional');
// Items.Add('Win32');
// OnKeyDown := EditKeyDown;
// OnKeyUp := EditKeyUp;
// end;
// end;
// vtNumber:
// begin
// FEdit := TMaskEdit.Create(nil);
// with FEdit as TMaskEdit do
// begin
// Visible := False;
// Parent := Tree;
// EditMask := '9999';
// Text := Data.Value;
// OnKeyDown := EditKeyDown;
// OnKeyUp := EditKeyUp;
// end;
// end;
// vtPickNumber:
// begin
// FEdit := TComboBox.Create(nil);
// with FEdit as TComboBox do
// begin
// Visible := False;
// Parent := Tree;
// Text := Data.Value;
// OnKeyDown := EditKeyDown;
// OnKeyUp := EditKeyUp;
// end;
// end;
// vtMemo:
// begin
// FEdit := TComboBox.Create(nil);
// // In reality this should be a drop down memo but this requires
// // a special control.
// with FEdit as TComboBox do
// begin
// Visible := False;
// Parent := Tree;
// Text := Data.Value;
// Items.Add(Data.Value);
// OnKeyDown := EditKeyDown;
// OnKeyUp := EditKeyUp;
// end;
// end;
// vtDate:
// begin
// FEdit := TDateTimePicker.Create(nil);
// with FEdit as TDateTimePicker do
// begin
// Visible := False;
// Parent := Tree;
// CalColors.MonthBackColor := clWindow;
// CalColors.TextColor := clBlack;
// CalColors.TitleBackColor := clBtnShadow;
// CalColors.TitleTextColor := clBlack;
// CalColors.TrailingTextColor := clBtnFace;
// Date := StrToDate(Data.Value);
// OnKeyDown := EditKeyDown;
// OnKeyUp := EditKeyUp;
// end;
// end;
// else
// Result := False;
// end;
end;
procedure TPropertyEditLink.ProcessMessage(var Message: TMessage);
begin
FEdit.WindowProc(Message);
end;
procedure TPropertyEditLink.SetBounds(R: TRect);
var
Dummy: Integer;
begin
// Since we don't want to activate grid extensions in the tree (this would influence how the selection is drawn)
// we have to set the edit's width explicitly to the width of the column.
FTree.Header.Columns.GetColumnBounds(FColumn, Dummy, R.Right);
FEdit.BoundsRect := R;
end;
end.