-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathOWClassProperty.pas
More file actions
463 lines (415 loc) · 16.6 KB
/
Copy pathOWClassProperty.pas
File metadata and controls
463 lines (415 loc) · 16.6 KB
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
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
unit OWClassProperty;
REMOVED !
interface
uses
{$IFDEF __VSDESIGN__}
VSDesign,
{$ELSE}
DesignEditors, DesignIntf,
{$ENDIF}
Classes, TypInfo, Contnrs;
type TOWClassPropertyEditor = class(TBasePropertyEditor, IProperty, IPropertyKind, IProperty70)
protected
function GetEditValue(out Value: String): Boolean; virtual;
function HasInstance(Instance: TPersistent): Boolean; virtual;
public
procedure Activate(); virtual;
procedure Initialize(); override;
function AllEqual(): Boolean; virtual;
function AutoFill(): Boolean; virtual;
function GetPropInfo(): PPropInfo; virtual;
{$IFDEF __VSDESIGN__}
function GetPropType(): PTypeInfo; override;
function GetOrdValue() : Longint; override;
{$ELSE}
function GetPropType(): PTypeInfo; virtual;
{$ENDIF}
function GetKind(): TTypeKind; virtual;
function GetIsDefault(): Boolean; virtual;
procedure Revert(); virtual;
procedure Modified(); virtual;
procedure SetPropEntry(Index: Integer; AInstance: TPersistent; APropInfo: PPropInfo); override;
public
{$IFDEF __VSDESIGN__}
function GetEditLimit(): Integer; override;
procedure GetProperties(Proc: TGetPropProc); override;
function ValueAvailable(): Boolean; override;
function GetName(): String; override;
function GetAttributes(): TPropertyAttributes; override;
procedure GetValues(Proc: TGetStrProc); override;
procedure SetValue(const Value: String); override;
function GetValue(): String; override;
procedure Edit(); override;
{$ELSE}
function GetEditLimit(): Integer; virtual;
procedure GetProperties(Proc: TGetPropProc); virtual;
function ValueAvailable(): Boolean; virtual;
function GetName(): String; virtual;
function GetAttributes(): TPropertyAttributes; virtual;
procedure GetValues(Proc: TGetStrProc); virtual;
procedure SetValue(const Value: String); virtual;
function GetValue(): String; virtual;
procedure Edit(); virtual;
{$ENDIF}
protected
FDesigner : IDesigner;
public
constructor CreateEx( const ADesigner: IDesigner );
public
property Designer : IDesigner read FDesigner;
end;
type TOWComponentEditorEvent = procedure of object;
type TOWComponentEditorEvabledEvent = function() : Boolean of object;
//---------------------------------------------------------------------------
type TOWComponentEditorItem = class
private
FMenuText : String;
FPropertyName : String;
FFilter : TTypeKinds;
FCallback : TOWComponentEditorEvent;
FOnEnabledCallback : TOWComponentEditorEvabledEvent;
public
constructor Create( AMenuText : String; ACallback : TOWComponentEditorEvent; AOnEnabledCallback : TOWComponentEditorEvabledEvent; AFilter : TTypeKinds; APropertyName : String );
public
function GetEnabled() : Boolean;
end;
//---------------------------------------------------------------------------
type
TOWComponentEditorItems = class
private
FList : TObjectList;
private
function GetCount() : Integer;
function GetItem( AIndex : Integer ) : TOWComponentEditorItem;
procedure SetItem( AIndex : Integer; AValue : TOWComponentEditorItem );
public
procedure Add( AMenuText : String; ACallback : TOWComponentEditorEvent; AFilter: TTypeKinds; APropertyName : String );
procedure AddEnable( AMenuText : String; ACallback : TOWComponentEditorEvent; AOnEnabledCallback : TOWComponentEditorEvabledEvent; AFilter: TTypeKinds; APropertyName : String );
public
constructor Create();
destructor Destroy(); override;
public
property Count : Integer read GetCount;
property Items[ Index : Integer ] : TOWComponentEditorItem read GetItem write SetItem; default;
end;
//---------------------------------------------------------------------------
type
TOWComponentEditor = class( TComponentEditor )
protected
LastIProp : IProperty;
FTargetProperty : String;
FMenuItems : TOWComponentEditorItems;
protected
procedure GetPropProc(const Prop: IProperty);
function GetIProperty( Comp : TComponent; AFilter: TTypeKinds; PropertyName : String ) : IProperty;
procedure EditProperty( PropertyName : String ); overload;
procedure EditProperty( AFilter: TTypeKinds; PropertyName : String ); overload;
procedure AddMenuItem( AMenuText : String; ACallback : TOWComponentEditorEvent; AOnEnabledCallback : TOWComponentEditorEvabledEvent ); overload;
procedure AddMenuItem( AMenuText : String; ACallback : TOWComponentEditorEvent ); overload;
procedure AddMenuItem( AMenuText : String; APropertyName : String ); overload;
procedure AddMenuItem( AMenuText : String; AFilter: TTypeKinds; APropertyName : String ); overload;
procedure InitMenu(); virtual;
public
procedure ExecuteVerb(Index: Integer); override;
function GetVerb(Index: Integer) : String; override;
function GetVerbCount() : Integer; override;
public
procedure AfterConstruction(); override;
public
constructor Create(AComponent: TComponent; ADesigner: IDesigner); override;
destructor Destroy(); override;
end;
implementation
{$IFNDEF FPC}
uses OWDesignSelectionsList;
constructor TOWClassPropertyEditor.CreateEx( const ADesigner: IDesigner );
begin
inherited Create( ADesigner, 1 );
FDesigner := ADesigner;
end;
//------------------------------------------------------------------------------
function TOWClassPropertyEditor.GetName(): String;
begin
Result := 'Unknown';
end;
//---------------------------------------------------------------------------
function TOWClassPropertyEditor.GetAttributes() : TPropertyAttributes;
begin
Result := [];
end;
//---------------------------------------------------------------------------
procedure TOWClassPropertyEditor.GetValues(Proc: TGetStrProc);
begin
end;
//---------------------------------------------------------------------------
procedure TOWClassPropertyEditor.SetValue(const Value: String);
begin
end;
//---------------------------------------------------------------------------
function TOWClassPropertyEditor.GetValue() : String;
begin
Result := '';
end;
//---------------------------------------------------------------------------
function TOWClassPropertyEditor.GetEditValue(out Value: String): Boolean;
begin
Value := GetValue();
Result := True;
end;
//---------------------------------------------------------------------------
function TOWClassPropertyEditor.HasInstance(Instance: TPersistent): Boolean;
begin
Result := True;
end;
//---------------------------------------------------------------------------
procedure TOWClassPropertyEditor.Activate();
begin
end;
//---------------------------------------------------------------------------
procedure TOWClassPropertyEditor.Initialize();
begin
end;
//---------------------------------------------------------------------------
function TOWClassPropertyEditor.AllEqual() : Boolean;
begin
Result := True;
end;
//---------------------------------------------------------------------------
function TOWClassPropertyEditor.AutoFill() : Boolean;
begin
Result := False;
end;
//---------------------------------------------------------------------------
function TOWClassPropertyEditor.GetEditLimit() : Integer;
begin
Result := 255;
end;
//---------------------------------------------------------------------------
procedure TOWClassPropertyEditor.GetProperties(Proc: TGetPropProc);
begin
end;
//---------------------------------------------------------------------------
function TOWClassPropertyEditor.GetPropInfo() : PPropInfo;
begin
Result := NIL;
end;
//---------------------------------------------------------------------------
function TOWClassPropertyEditor.GetPropType() : PTypeInfo;
begin
Result := TypeInfo( TPersistent );
end;
//---------------------------------------------------------------------------
{$IFDEF __VSDESIGN__}
function TOWClassPropertyEditor.GetOrdValue() : Longint;
begin
Result := 0;
end;
{$ENDIF}
//---------------------------------------------------------------------------
function TOWClassPropertyEditor.GetKind() : TTypeKind;
begin
Result := GetPropType().Kind;
end;
//---------------------------------------------------------------------------
function TOWClassPropertyEditor.GetIsDefault() : Boolean;
begin
Result := False;
end;
//---------------------------------------------------------------------------
procedure TOWClassPropertyEditor.SetPropEntry( Index: Integer; AInstance: TPersistent; APropInfo: PPropInfo);
begin
end;
//---------------------------------------------------------------------------
procedure TOWClassPropertyEditor.Revert();
begin
end;
//---------------------------------------------------------------------------
function TOWClassPropertyEditor.ValueAvailable() : Boolean;
begin
Result := True;
end;
//---------------------------------------------------------------------------
procedure TOWClassPropertyEditor.Edit();
begin
end;
//---------------------------------------------------------------------------
procedure TOWClassPropertyEditor.Modified();
begin
if( FDesigner <> NIL ) then
FDesigner.Modified();
end;
{$ENDIF}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
function TOWComponentEditor.GetIProperty( Comp : TComponent; AFilter: TTypeKinds; PropertyName : String ) : IProperty;
var
SelectionListI : IDesignerSelections;
SelectionList : TOWDesignerSelectionList;
begin
LastIProp := NIL;
if( Comp = NIL ) then
Exit( NIL );
if( PropertyName = '' ) then
Exit( NIL );
SelectionList := TOWDesignerSelectionList.Create();
SelectionListI := SelectionList as IDesignerSelections;
SelectionList.Add( Comp );
FTargetProperty := PropertyName;
GetComponentProperties( SelectionListI, AFilter, Designer, GetPropProc );
Result := LastIProp;
end;
//---------------------------------------------------------------------------
constructor TOWComponentEditor.Create(AComponent: TComponent; ADesigner: IDesigner);
begin
inherited;
FMenuItems := TOWComponentEditorItems.Create();
end;
//---------------------------------------------------------------------------
destructor TOWComponentEditor.Destroy();
begin
FMenuItems.Free();
inherited;
end;
//---------------------------------------------------------------------------
procedure TOWComponentEditor.AfterConstruction();
begin
inherited;
InitMenu();
end;
//---------------------------------------------------------------------------
procedure TOWComponentEditor.InitMenu();
begin
end;
//---------------------------------------------------------------------------
procedure TOWComponentEditor.EditProperty( PropertyName : String );
begin
EditProperty( tkProperties, PropertyName );
end;
//---------------------------------------------------------------------------
procedure TOWComponentEditor.EditProperty( AFilter: TTypeKinds; PropertyName : String );
var
PropIProp : IProperty;
begin
PropIProp := GetIProperty( Component, AFilter, PropertyName );
if( PropIProp <> NIL ) then
PropIProp.Edit();
end;
//---------------------------------------------------------------------------
procedure TOWComponentEditor.GetPropProc(const Prop: IProperty);
begin
if( Prop.GetName() = FTargetProperty ) then
LastIProp := Prop;
end;
//---------------------------------------------------------------------------
procedure TOWComponentEditor.AddMenuItem( AMenuText : String; ACallback : TOWComponentEditorEvent; AOnEnabledCallback : TOWComponentEditorEvabledEvent );
begin
FMenuItems.AddEnable( AMenuText, ACallback, AOnEnabledCallback, [], '' );
end;
//---------------------------------------------------------------------------
procedure TOWComponentEditor.AddMenuItem( AMenuText : String; ACallback : TOWComponentEditorEvent );
begin
FMenuItems.Add( AMenuText, ACallback, [], '' );
end;
//---------------------------------------------------------------------------
procedure TOWComponentEditor.AddMenuItem( AMenuText : String; APropertyName : String );
begin
AddMenuItem( AMenuText, tkProperties, APropertyName );
end;
//---------------------------------------------------------------------------
procedure TOWComponentEditor.AddMenuItem( AMenuText : String; AFilter: TTypeKinds; APropertyName : String );
begin
FMenuItems.Add( AMenuText, NIL, AFilter, APropertyName );
end;
//---------------------------------------------------------------------------
procedure TOWComponentEditor.ExecuteVerb(Index: Integer);
begin
if( Assigned( FMenuItems[ Index ].FCallback )) then
FMenuItems[ Index ].FCallback()
else
EditProperty( FMenuItems[ Index ].FFilter, FMenuItems[ Index ].FPropertyName );
end;
//---------------------------------------------------------------------------
function TOWComponentEditor.GetVerb(Index: Integer): String;
var
I : Integer;
begin
for I := 0 to FMenuItems.Count - 1 do
if( not FMenuItems[ I ].GetEnabled() ) then
Inc( Index );
Result := FMenuItems[ Index ].FMenuText;
end;
//---------------------------------------------------------------------------
function TOWComponentEditor.GetVerbCount() : Integer;
var
I : Integer;
begin
Result := 0;
for I := 0 to FMenuItems.Count - 1 do
if( FMenuItems[ I ].GetEnabled() ) then
Inc( Result );
end;
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
constructor TOWComponentEditorItems.Create();
begin
inherited;
FList := TObjectList.Create( True );
end;
//---------------------------------------------------------------------------
destructor TOWComponentEditorItems.Destroy();
begin
FList.Free();
inherited;
end;
//---------------------------------------------------------------------------
function TOWComponentEditorItems.GetCount() : Integer;
begin
Result := FList.Count;
end;
//---------------------------------------------------------------------------
function TOWComponentEditorItems.GetItem( AIndex : Integer ) : TOWComponentEditorItem;
begin
Result := TOWComponentEditorItem( FList[ AIndex ] );
end;
//---------------------------------------------------------------------------
procedure TOWComponentEditorItems.SetItem( AIndex : Integer; AValue : TOWComponentEditorItem );
begin
FList[ AIndex ] := AValue;
end;
//---------------------------------------------------------------------------
procedure TOWComponentEditorItems.Add( AMenuText : String; ACallback : TOWComponentEditorEvent; AFilter: TTypeKinds; APropertyName : String );
begin
FList.Add( TOWComponentEditorItem.Create( AMenuText, ACallback, NIL, AFilter, APropertyName ));
end;
//---------------------------------------------------------------------------
procedure TOWComponentEditorItems.AddEnable( AMenuText : String; ACallback : TOWComponentEditorEvent; AOnEnabledCallback : TOWComponentEditorEvabledEvent; AFilter: TTypeKinds; APropertyName : String );
begin
FList.Add( TOWComponentEditorItem.Create( AMenuText, ACallback, AOnEnabledCallback, AFilter, APropertyName ));
end;
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
constructor TOWComponentEditorItem.Create( AMenuText : String; ACallback : TOWComponentEditorEvent; AOnEnabledCallback : TOWComponentEditorEvabledEvent; AFilter : TTypeKinds; APropertyName : String );
begin
inherited Create;
FMenuText := AMenuText;
FCallback := ACallback;
FOnEnabledCallback := AOnEnabledCallback;
FFilter := AFilter;
FPropertyName := APropertyName;
end;
//---------------------------------------------------------------------------
function TOWComponentEditorItem.GetEnabled() : Boolean;
begin
if( Assigned( FOnEnabledCallback )) then
Result := FOnEnabledCallback()
else
Result := True;
end;
//---------------------------------------------------------------------------
end.