@@ -68,6 +68,27 @@ TClipboardFormatsProperty = class(TStringListProperty, ICustomPropertyDrawing)
6868 procedure PropDrawValue (ACanvas: TCanvas; const ARect: TRect; ASelected: Boolean);
6969 end ;
7070
71+ TColumnOptionsProperty = class (VCLEditors.TSetProperty)
72+ public
73+ procedure GetProperties (Proc: TGetPropProc); override;
74+ function GetValue : string; override;
75+ end ;
76+
77+ TVTColumnOptionsElementsProperty = class (VCLEditors.TSetElementProperty,
78+ ICustomPropertyMessage
79+ )
80+ private
81+ FBit: TBit;
82+ FPropList: TArray<TInstProp>;
83+ protected
84+ constructor Create(Parent: TPropertyEditor; AElement: Integer); reintroduce;
85+ procedure UpdateOrdValue ;
86+ public
87+ // ICustomPropertyMessage
88+ procedure MouseUp (Button: TMouseButton; Shift: TShiftState; X, Y: Integer;
89+ InNameRect: Boolean; const ItemRect: TRect; var Handled: Boolean);
90+ end ;
91+
7192 resourcestring
7293 sVTHeaderCategoryName = ' Header' ;
7394 sVTPaintingCategoryName = ' Custom painting' ;
@@ -292,10 +313,108 @@ procedure TClipboardFormatsProperty.PropDrawValue(ACanvas: TCanvas; const ARect:
292313
293314// ----------------------------------------------------------------------------------------------------------------------
294315
316+ procedure TColumnOptionsProperty.GetProperties (Proc: TGetPropProc);
317+ var
318+ I: integer;
319+ E: IProperty;
320+ begin
321+ with GetTypeData(GetTypeData(GetPropType)^.CompType^)^ do
322+ begin
323+ for I := MinValue to MaxValue do
324+ begin
325+ E := TVTColumnOptionsElementsProperty.Create(Self, I);
326+ Proc(E);
327+ E := nil ;
328+ end ;
329+ end ;
330+ end ;
331+
332+ function TColumnOptionsProperty.GetValue : string;
333+ var
334+ I : integer;
335+ S: TIntegerSet;
336+ begin
337+ Integer(S) := GetOrdValue;
338+ Result := ' ' ;
339+ for I := 0 to SizeOf(Integer) * 8 - 1 do
340+ if I in S then
341+ Result := Result + GetEnumName(TypeInfo(TVTColumnOption), I) + ' ,' ;
342+ if Result.EndsWith(' ,' ) then
343+ Delete(Result, Length(Result), 1 );
344+ Result := ' [' + Result + ' ]' ;
345+ end ;
346+
347+ type
348+ TPropertyEditorHack = class (TBasePropertyEditor)
349+ protected
350+ FDesigner: IDesigner;
351+ FPropList: PInstPropList;
352+ FPropCount: Integer;
353+ end ;
354+
355+ constructor TVTColumnOptionsElementsProperty.Create(Parent: TPropertyEditor; AElement: Integer);
356+ var
357+ MinValue: integer;
358+ begin
359+ inherited Create(Parent, AElement);
360+ MinValue := GetTypeData(GetTypeData(GetPropType).CompType^).MinValue;
361+ FBit := AElement - MinValue;
362+ SetLength(FPropList, Parent.PropCount);
363+ for var I := 0 to High(FPropList) do
364+ FPropList[I] := TPropertyEditorHack(Parent).FPropList^[I];
365+ end ;
366+
367+ procedure TVTColumnOptionsElementsProperty.UpdateOrdValue ;
368+ var
369+ S: TIntegerSet;
370+ I: Integer;
371+ begin
372+ // Changes only the specific bit in the set
373+ for I := 0 to TPropertyEditorHack(Self).FPropCount - 1 do
374+ begin
375+ Integer(S) := GetOrdProp(FPropList[I].Instance, FPropList[I].PropInfo);
376+ if FBit in S then
377+ Exclude(S, FBit)
378+ else
379+ Include(S, FBit);
380+ SetOrdProp(FPropList[I].Instance, FPropList[I].PropInfo, NativeInt(S));
381+ end ;
382+ Modified;
383+ end ;
384+
385+ procedure TVTColumnOptionsElementsProperty.MouseUp (Button: TMouseButton;
386+ Shift: TShiftState; X, Y: Integer; InNameRect: Boolean; const ItemRect: TRect;
387+ var Handled: Boolean);
388+ begin
389+ Handled := False;
390+ if paReadOnly in GetAttributes then
391+ Exit;
392+ if PtInRect(CBRect(ItemRect), Point(x,y)) then
393+ begin
394+ UpdateOrdValue;
395+ Handled := True;
396+ end ;
397+ end ;
398+
399+ // for sets, the VCLDesigner code always makes the property editor back to the
400+ // standard set property editor: VclEditors.TSetProperty, so we need to make
401+ // OUR set property's map to our editor implementation and not the standard
402+ // set property editor.
403+ function SetColumnOptionsPropertyMapper (Obj: TPersistent; PropInfo: PPropInfo): TPropertyEditorClass;
404+ begin
405+ Result := nil ;
406+ if Assigned(Obj) and (Obj.ClassType <> TVirtualTreeColumn) then
407+ Exit;
408+ if (PropInfo.PropType^.Kind = tkSet) and (PropInfo.PropType^ = TypeInfo(TVTColumnOptions)) then
409+ Result := TColumnOptionsProperty;
410+ end ;
411+
412+ // ----------------------------------------------------------------------------------------------------------------------
295413procedure Register ;
296414
297415begin
298416 RegisterComponents(' Virtual Controls' , [TVirtualStringTree, TVirtualDrawTree, TVTHeaderPopupMenu]);
417+ RegisterPropertyMapper(SetColumnOptionsPropertyMapper);
299418 RegisterComponentEditor(TVirtualStringTree, TVirtualTreeEditor);
300419 RegisterComponentEditor(TVirtualDrawTree, TVirtualTreeEditor);
301420 RegisterPropertyEditor(TypeInfo(TClipboardFormats), nil , ' ' , TClipboardFormatsProperty);
0 commit comments