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
|
{
*****************************************************************************
See the file COPYING.modifiedLGPL.txt, included in this distribution,
for details about the license.
*****************************************************************************
Author: Sven Barth
Abstract:
This unit contains selection editors for various LCL components.
}
unit SelEdits;
{$mode objfpc}{$H+}
interface
uses
// RTL / FCL
SysUtils, TypInfo,
// LCL
Controls, ExtCtrls,
// IdeIntf
PropEdits;
type
{ TFlowPanelControlIndexEditor }
TFlowPanelControlIndexEditor = class(TSelectionEditor)
public
function GetAttributes: TSelectionEditorAttributes; override;
procedure FilterProperties(ASelection: TPersistentSelectionList;
AProperties: TPropertyEditorList); override;
end;
implementation
type
{ TFlowPanelControlIndexProperty }
TFlowPanelControlIndexProperty = class(TPropertyEditor)
private
FPanel: TCustomFlowPanel;
FControl: TControl;
FPropInfo: TPropInfo;
FPropType: PTypeInfo;
public
constructor Create(APanel: TCustomFlowPanel; AControl: TControl; AHook: TPropertyEditorHook); reintroduce;
function GetAttributes: TPropertyAttributes; override;
function GetValue: ansistring; override;
procedure SetValue(const NewValue: ansistring); override;
end;
{ TFlowPanelControlIndexProperty }
constructor TFlowPanelControlIndexProperty.Create(APanel: TCustomFlowPanel;
AControl: TControl; AHook: TPropertyEditorHook);
begin
inherited Create(AHook, 1);
FPanel := APanel;
FControl := AControl;
FPropType := TypeInfo(Integer);
{$if FPC_FULLVERSION<30101}
FPropInfo.PropType := FPropType;
{$else}
FPropInfo.PropTypeRef := @FPropType;
{$endif}
FPropInfo.Name := 'ControlIndex';
SetPropEntry(0, Nil, @FPropInfo);
end;
function TFlowPanelControlIndexProperty.GetAttributes: TPropertyAttributes;
begin
Result := [];
end;
function TFlowPanelControlIndexProperty.GetValue: ansistring;
begin
Result := IntToStr(FPanel.GetControlIndex(FControl));
end;
procedure TFlowPanelControlIndexProperty.SetValue(const NewValue: ansistring);
var
idx: Integer;
begin
if not TryStrToInt(NewValue, idx) then
Exit;
FPanel.SetControlIndex(FControl, idx);
end;
{ TFlowPanelControlIndexEditor }
function TFlowPanelControlIndexEditor.GetAttributes: TSelectionEditorAttributes;
begin
Result := [seaFilterProperties];
end;
procedure TFlowPanelControlIndexEditor.FilterProperties(
ASelection: TPersistentSelectionList; AProperties: TPropertyEditorList);
var
ctrl: TControl;
i: LongInt;
todelete: array[0..1] of LongInt;
propname: ShortString;
begin
if not Assigned(ASelection) or not Assigned(AProperties) then
Exit;
if ASelection.Count <> 1 then
Exit;
todelete[0] := -1;
todelete[1] := -1;
for i := 0 to AProperties.Count - 1 do begin
if AProperties[i] is TFlowPanelControlIndexProperty then
Exit;
propname := AProperties[i].GetName;
if CompareText(propname, 'CONTROLINDEX') = 0 then
Exit
else if CompareText(propname, 'LEFT') = 0 then
todelete[0] := i
else if CompareText(propname, 'TOP') = 0 then
todelete[1] := i;
end;
if not (ASelection[0] is TControl) then
Exit;
ctrl := TControl(ASelection[0]);
if not (ctrl.Parent is TCustomFlowPanel) then
Exit;
if todelete[0] < todelete[1] then begin
i := todelete[0];
todelete[0] := todelete[1];
todelete[1] := i;
end;
for i := Low(todelete) to High(todelete) do
if todelete[i] >= 0 then
AProperties.Delete(todelete[i]);
AProperties.Add(TFlowPanelControlIndexProperty.Create(TCustomFlowPanel(ctrl.Parent), ctrl, Hook));
end;
initialization
{ we need to register this for TControl as this is applied to each control
that is placed on a TFlowPanel }
RegisterSelectionEditor(TControl, TFlowPanelControlIndexEditor);
end.
|