[JEDI.NET-commits] dev/jedi_mbe/run Jedi.Collections.pas,NONE,1.1 Jedi.Drawing.pas,NONE,1.1 Jedi.Sys
Status: Pre-Alpha
Brought to you by:
jedi_mbe
From: Marcel B. <jed...@us...> - 2004-06-12 18:31:48
|
Update of /cvsroot/jedidotnet/dev/jedi_mbe/run In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22719/dev/jedi_mbe/run Added Files: Jedi.Collections.pas Jedi.Drawing.pas Jedi.System.pas Jedi.Windows.Forms.Hmi.Leds.pas Log Message: not working yet (need more changes in Jedi.Collections). --- NEW FILE: Jedi.System.pas --- {--------------------------------------------------------------------------------------------------- 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/MPL-1.1.html Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for the specific language governing rights and limitations under the License. The Original Code is: Jedi.System.pas, released on 2004-05-20. The Initial Developer of the Original Code is Marcel Bestebroer Portions created by Marcel Bestebroer are Copyright (C) 2004 Marcel Bestebroer All Rights Reserved. Contributor(s): Last Modified: 2004-05-20 You may retrieve the latest version of this file at the Project JEDI's JWFL home page, located at http://jwfl.sourceforge.net Known Issues: ---------------------------------------------------------------------------------------------------} unit Jedi.System; interface {$REGION 'interface uses'} {$ENDREGION} {$REGION 'Inline collection editing attributes'} type { Provides info for collections that can be edited inline in a property grid. Requires the InlineCollectionEditor and InlineCollectionConverter (both located in Jedi.Windows.Forms.Design) to work. } [AttributeUsage(AttributeTargets.Class)] InlineCollectionAttribute = class abstract (Attribute) strict private _canAddItems: Boolean; _displayValue: string; _newItemName: string; public constructor Create; { Flag to indicate if items can be added. Defaults to True, but will be ignored for collection types that do not allow adding/deleting of items. } property CanAddItems: Boolean read _canAddItems write _canAddItems; { Name to display as the collection's value. If not specified, defaults to standard value for CollectionBase. } property DisplayValue: string read _displayValue write _displayValue; { Name to use for the 'new' item. When not specified, defaults to 'New'. Ignored if CanAddItems is False or the collection type does not allow items to be added. } property NewItemName: string read _newItemName write _newItemName; end; { Provides info for collections that can be edited inline in a property grid. Requires the InlineCollectionEditor and InlineCollectionConverter (both located in Jedi.Windows.Forms.Design) to work. } InlineListAttribute = class (InlineCollectionAttribute) strict private _itemType: System.Type; _nameMember: string; _scanForDefaultProperty: Boolean; _valueProperty: string; public constructor Create; { Item type to use for the 'new' item in the editor. If not specified, the collection type is scanned for an Item or Items property and use it's type instead. } property ItemType: System.Type read _itemType write _itemType; (* Name of the member that will provide the item's display name. If not specified, item names will be formatted as 'Item {0}'. *) property NameMember: string read _nameMember write _nameMember; { When set to True, specifies that each item type is scanned for the DefaultProperty attribute. } property ScanForDefaultProperty: Boolean read _scanForDefaultProperty write _scanForDefaultProperty; { Name of the primary property of an item. If ScanForDefaultProperty is set to True this property can be an empty string. } property ValueProperty: string read _valueProperty write _valueProperty; end; {$ENDREGION} implementation {$REGION 'implementation uses'} uses System.Resources; {$ENDREGION} {$REGION 'InlineCollectionAttribute'} constructor InlineCollectionAttribute.Create; var rm: ResourceManager; begin inherited Create; rm := ResourceManager.Create('System', TypeOf(Uri).Module.Assembly); try _displayValue := rm.GetString('CollectionConverterText'); finally rm.Free; end; _canAddItems := True; _newItemName := '(new)'; end; {$ENDREGION} {$REGION 'InlineListAttribute'} constructor InlineListAttribute.Create; begin inherited Create; _itemType := nil; _nameMember := ''; _scanForDefaultProperty := True; _valueProperty := ''; end; {$ENDREGION} end. --- NEW FILE: Jedi.Drawing.pas --- {--------------------------------------------------------------------------------------------------- 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/MPL-1.1.html Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for the specific language governing rights and limitations under the License. The Original Code is: Jedi.Drawing.pas, released on 2004-05-16. The Initial Developer of the Original Code is Marcel Bestebroer Portions created by Marcel Bestebroer are Copyright (C) 2004 Marcel Bestebroer All Rights Reserved. Contributor(s): Last Modified: 2004-05-16 You may retrieve the latest version of this file at the Project JEDI's JWFL home page, located at http://jwfl.sourceforge.net Known Issues: ---------------------------------------------------------------------------------------------------} unit Jedi.Drawing; interface uses System.Drawing; type ColorHandling = class sealed (System.Object) public { Blends two colors. The resulting color will be a mix of the two colors. The percentage parameter determines how much of the second color will be present. } class function Blend(firstColor, secondColor: Color; percentage: Integer): Color; static; { Brightens a color. The resulting color will be a mix of the base color and pure white. The percentage parameter determines how much white will be present. } class function Brighten(baseColor: Color; percentage: Integer): Color; static; { Darkens a color. The resulting color will be a mix of the base color and pure black. The percentage parameter determines how much black will be present. } class function Darken(baseColor: Color; percentage: Integer): Color; static; end; implementation {$REGION 'ColorHandling'} class function ColorHandling.Blend(firstColor, secondColor: Color; percentage: Integer): Color; begin Result := Color.FromArgb( firstColor.R + (secondColor.R - firstColor.R) * percentage div 100, firstColor.G + (secondColor.G - firstColor.G) * percentage div 100, firstColor.B + (secondColor.B - firstColor.B) * percentage div 100 ); end; class function ColorHandling.Brighten(baseColor: Color; percentage: Integer): Color; begin Result := ColorHandling.Blend(baseColor, Color.White, percentage); end; class function ColorHandling.Darken(baseColor: Color; percentage: Integer): Color; begin Result := ColorHandling.Blend(baseColor, Color.Black, percentage); end; {$ENDREGION} end. --- NEW FILE: Jedi.Windows.Forms.Hmi.Leds.pas --- {--------------------------------------------------------------------------------------------------- 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/MPL-1.1.html Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for the specific language governing rights and limitations under the License. The Original Code is: Jedi.Windows.Forms.Hmi.Leds.pas, released on 2004-05-16. The Initial Developer of the Original Code is Marcel Bestebroer Portions created by Marcel Bestebroer are Copyright (C) 2004 Marcel Bestebroer All Rights Reserved. Contributor(s): Last Modified: 2004-06-09 [...1719 lines suppressed...] i: Integer; begin if not ReferenceEquals(mLedStyle, value) then begin mLedStyle.Free; mLedStyle := value; Include(mLedStyle.SettingsChanged, Style_SettingsChanged); Include(mLedStyle.SizeChanged, Style_SizeChanged); Include(mLedStyle.StateAdded, Style_StateAdded); Include(mLedStyle.StateRemoved, Style_StateRemoved); for i := 0 to mInitializeCount - 1 do mLedStyle.BeginInit; if not IsInitializing and (mLedStateIdx >= mLedStyle.States.Count) then mLedStateIdx := mLedStyle.States.Count - 1; mLedStyle.InvalidateSize; end; end; {$ENDREGION} end. --- NEW FILE: Jedi.Collections.pas --- {--------------------------------------------------------------------------------------------------- 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/MPL-1.1.html Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for the specific language governing rights and limitations under the License. The Original Code is: Jedi.Collections.pas, released on 2004-06-12. The Initial Developer of the Original Code is Marcel Bestebroer Portions created by Marcel Bestebroer are Copyright (C) 2004 Marcel Bestebroer All Rights Reserved. Contributor(s): You may retrieve the latest version of this file at the Project JEDI's JWFL home page, located at http://jwfl.sourceforge.net Known Issues: ---------------------------------------------------------------------------------------------------} // $Id: Jedi.Collections.pas,v 1.1 2004/06/12 18:31:38 jedi_mbe Exp $ unit Jedi.Collections; interface {$REGION 'interface uses'} uses System.Collections, System.Collections.Specialized, System.ComponentModel, System.Drawing.Design, System.Globalization, System.Reflection; {$ENDREGION} type AttributeArray = array of Attribute; {$REGION 'Inline collection editing'} type InlineCollectionUtils = class (System.Object) strict private class var _collectionValue: string; public { Retrieves the default text of the collection converter. } class function CollectionConverterText: string; static; { Creates a property descriptor that will function as a 'new item' property. The property will get the specified name and description. } class function CreateNewItemProperty(baseDescriptor: PropertyDescriptor; name, description: string; propertyId: System.Object): PropertyDescriptor; overload; static; { Creates a property descriptor that will function as a 'new item' property. The property will get the specified name and description. } class function CreateNewItemProperty(info: PropertyInfo; name, description: string; propertyId: System.Object): PropertyDescriptor; overload; static; { Creates a property descriptor that will function as a 'new item' property. The property will get the specified name and description. } class function CreateNewItemProperty(componentType, propertyType: System.Type; attributes: AttributeArray; name, description: string; propertyId: System.Object): PropertyDescriptor; overload; static; { Creates a property descriptor for an item in the specified collection. The property will get the specified name and description. Depending on the ignoreDefaultProperty parameter, the resulting property will be either the instance in the collection, or it's DefaultProperty (if it has one). } class function CreateItemProperty(info: PropertyInfo; component: System.Object; name, description: string; index, emptyValue: System.Object; ignoreDefaultProperty: Boolean = False): PropertyDescriptor; overload; static; class function CreateItemProperty(propertyType: System.Type; attributes: AttributeArray; component: System.Object; name, description: string; index, emptyValue: System.Object): PropertyDescriptor; overload; static; end; IInlineCollection = interface { string to show in the property grid for the collection itself. } function GetCollectionValue: string; { retrieve a list of semi properties that allow to add items to the collection. Because a list is used, you have the ability to add different kinds of items. } function GetNewItemProperties: PropertyDescriptorCollection; { retrieve a collection of semi properties representing the items in the collection. } function GetItemProperties: PropertyDescriptorCollection; { add an item to the collection. This method is used by the 'new item' semi property when a new value should be added. This value need not be the actual object added to the collection. } procedure AddItem(value: System.Object; addPropertyId: System.Object); { Retrieve the specified service } function GetService(serviceType: System.Type): System.Object; end; InlineCollectionConverter = class (System.ComponentModel.CollectionConverter) { when converting to a string uses IInlineCollection.GetCollectionValue. } function ConvertTo(context: ITypeDescriptorContext; culture: CultureInfo; value: System.Object; destinationType: System.Type): System.Object; override; { returns True if the instance supports IInlineCollection. } function GetPropertiesSupported(context: ITypeDescriptorContext): Boolean; override; { returns the union of IInlineCollection.GetNewItemProperties and IInlineCollection.GetItemProperties or an empty PropertyDescriptorCollection if the instance does not support IInlineCollectionConverter. } function GetProperties(context: ITypeDescriptorContext; value: System.Object; attributes: AttributeArray): PropertyDescriptorCollection; override; end; InlineCollectionEditor = class (UITypeEditor) function GetEditStyle(context: ITypeDescriptorContext): UITypeEditorEditStyle; override; function EditValue(context: ITypeDescriptorContext; provider: IServiceProvider; value: System.Object): System.Object; override; end; {$ENDREGION} {$REGION 'Inline collection base classes'} type [TypeConverter(TypeOf(InlineCollectionConverter)), Editor(TypeOf(InlineCollectionEditor), TypeOf(UITypeEditor))] InlineCollectionBase = class abstract (CollectionBase, IInlineCollection) strict private _indexerInfo: PropertyInfo; strict protected {$REGION 'IInlineCollection methods'} procedure AddItem(value: System.Object; addPropertyId: System.Object); virtual; function GetCollectionValue: string; virtual; function GetNewItemProperties: PropertyDescriptorCollection; virtual; function GetItemProperties: PropertyDescriptorCollection; virtual; function GetService(serviceType: System.Type): System.Object; virtual; {$ENDREGION} function GetItemDescription(index: integer): string; virtual; function GetItemEmptyValue(index: Integer): System.Object; virtual; function GetItemIgnoreDefaultProperty(index: Integer): Boolean; virtual; function GetItemName(index: integer): string; virtual; function GetItemProperty(index: Integer): PropertyDescriptor; virtual; function IndexerInfo: PropertyInfo; end; type [TypeConverter(TypeOf(InlineCollectionConverter)), Editor(TypeOf(InlineCollectionEditor), TypeOf(UITypeEditor))] InlineDictionaryBase = class abstract (DictionaryBase, IInlineCollection) strict protected {$REGION 'IInlineCollection methods'} procedure AddItem(value: System.Object; addPropertyId: System.Object); virtual; function GetCollectionValue: string; virtual; function GetNewItemProperties: PropertyDescriptorCollection; virtual; function GetItemProperties: PropertyDescriptorCollection; virtual; function GetService(serviceType: System.Type): System.Object; virtual; {$ENDREGION} function GetItemDescription(key: System.Object): string; virtual; function GetItemEmptyValue(key: System.Object): System.Object; virtual; function GetItemProperty(key, value: System.Object): PropertyDescriptor; virtual; end; {$ENDREGION} implementation {$AUTOBOX ON} {$REGION 'implementation uses'} uses System.ComponentModel.Design, System.Resources; {$ENDREGION} {$REGION 'SimplePropertyDescriptor'} type SimplePropertyDescriptor = class (PropertyDescriptor) strict private _componentType: System.Type; _propertyType: System.Type; public constructor Create(componentType: System.Type; name: string; propertyType: System.Type; attributes: AttributeArray); function CanResetValue(component: System.Object): Boolean; override; procedure ResetValue(component: System.Object); override; function ShouldSerializeValue(component: System.Object): Boolean; override; function get_ComponentType: System.Type; override; function get_PropertyType: System.Type; override; function get_IsReadOnly: Boolean; override; end; constructor SimplePropertyDescriptor.Create(componentType: System.Type; name: string; propertyType: System.Type; attributes: AttributeArray); var i: Integer; begin i := High(attributes); while (i >= 0) and not TypeOf(RefreshPropertiesAttribute).IsAssignableFrom(attributes[i].GetType) do Dec(i); if i >= 0 then attributes[i] := RefreshPropertiesAttribute.All else begin SetLength(attributes, Length(attributes) + 1); attributes[High(attributes)] := RefreshPropertiesAttribute.All; end; inherited Create(name, attributes); _componentType := componentType; _propertyType := propertyType; end; function SimplePropertyDescriptor.CanResetValue(component: System.Object): Boolean; begin Result := False; end; procedure SimplePropertyDescriptor.ResetValue(component: System.Object); begin end; function SimplePropertyDescriptor.ShouldSerializeValue(component: System.Object): Boolean; begin Result := False; end; function SimplePropertyDescriptor.get_ComponentType: System.Type; begin Result := _componentType; end; function SimplePropertyDescriptor.get_PropertyType: System.Type; begin Result := _propertyType; end; function SimplePropertyDescriptor.get_IsReadOnly: Boolean; begin Result := Attributes.Contains(ReadOnlyAttribute.Yes); end; {$ENDREGION} {$REGION 'NewItemPropertyDescriptor'} type NewItemPropertyDescriptor = class (SimplePropertyDescriptor) strict private _propertyId: System.Object; strict protected property PropertyId: System.Object read _propertyId; public constructor Create(componentType: System.Type; name: string; propertyType: System.Type; attributes: AttributeArray; propertyId: System.Object); function GetValue(component: System.Object): System.Object; override; procedure SetValue(component, value: System.Object); override; end; constructor NewItemPropertyDescriptor.Create(componentType: System.Type; name: string; propertyType: System.Type; attributes: AttributeArray; propertyId: System.Object); begin inherited Create(componentType, name, propertyType, attributes); _propertyId := propertyId; end; function NewItemPropertyDescriptor.GetValue(component: System.Object): System.Object; begin Result := ''; end; procedure NewItemPropertyDescriptor.SetValue(component, value: System.Object); var ccs: IComponentChangeService; begin ccs := IComponentChangeService(IInlineCollection(component).GetService(TypeOf(IComponentChangeService))); if Assigned(ccs) then ccs.OnComponentChanging(component, nil); IInlineCollection(component).AddItem(value, _propertyId); if Assigned(ccs) then ccs.OnComponentChanged(component, nil, nil, nil); end; {$ENDREGION} {$REGION 'ItemPropertyDescriptor'} type ItemPropertyDescriptor = class (SimplePropertyDescriptor) strict private _emptyValue: System.Object; _index: System.Object; strict protected property EmptyValue: System.Object read _emptyValue; property Index: System.Object read _index; public constructor Create(componentType: System.Type; name: string; propertyType: System.Type; attributes: AttributeArray; emptyValue: System.Object; index: System.Object); function GetValue(component: System.Object): System.Object; override; procedure SetValue(component, value: System.Object); override; function ItemInstance(component: System.Object): System.Object; end; function ItemPropertyDescriptor.ItemInstance(component: System.Object): System.Object; begin if component is IList then Result := IList(component).Item[Integer(_index)] else if component is IDictionary then Result := IDictionary(component).Item[_index] else Result := nil; end; constructor ItemPropertyDescriptor.Create(componentType: System.Type; name: string; propertyType: System.Type; attributes: AttributeArray; emptyValue: System.Object; index: System.Object); begin inherited Create(componentType, name, propertyType, attributes); _emptyValue := emptyValue; _index := index; end; function ItemPropertyDescriptor.GetValue(component: System.Object): System.Object; begin Result := ItemInstance(component); end; procedure ItemPropertyDescriptor.SetValue(component, value: System.Object); var ccs: IComponentChangeService; begin if component is IList then begin if value = _emptyValue then begin ccs := IComponentChangeService(IInlineCollection(component).GetService(TypeOf(IComponentChangeService))); if Assigned(ccs) then ccs.OnComponentChanging(component, nil); IList(component).RemoveAt(Integer(_index)); if Assigned(ccs) then ccs.OnComponentChanged(component, nil, nil, nil); end else IList(component).Item[Integer(_index)] := value; end else if component is IDictionary then begin if value = _emptyValue then begin ccs := IComponentChangeService(IInlineCollection(component).GetService(TypeOf(IComponentChangeService))); if Assigned(ccs) then ccs.OnComponentChanging(component, nil); IDictionary(component).Remove(_index); if Assigned(ccs) then ccs.OnComponentChanged(component, nil, nil, nil); end else IDictionary(component).Item[_index] := value; end; end; {$ENDREGION} {$REGION 'ItemSubPropertyDescriptor'} type ItemSubPropertyDescriptor = class (ItemPropertyDescriptor) strict private _realDescriptor: PropertyDescriptor; public constructor Create(componentType: System.Type; name, description: string; &property: PropertyDescriptor; itemType: System.Type; emptyValue, index: System.Object); function CanResetValue(component: System.Object): Boolean; override; function GetValue(component: System.Object): System.Object; override; procedure ResetValue(component: System.Object); override; procedure SetValue(component, value: System.Object); override; function ShouldSerializeValue(component: System.Object): Boolean; override; function get_PropertyType: System.Type; override; function get_IsReadOnly: Boolean; override; property RealDescriptor: PropertyDescriptor read _realDescriptor; end; {$REGION 'SubPropertyTypeConverter'} (*type SubPropertyTypeConverter = class (TypeConverter) strict private _propertyConverter: TypeConverter; _instanceConverter: TypeConverter; strict protected function PropertyConverter(context: ITypeDescriptorContext): TypeConverter; function InstanceConverter(context: ITypeDescriptorContext): TypeConverter; public function CanConvertFrom(context: ITypeDescriptorContext; sourceType: System.Type): Boolean; override; function CanConvertTo(context: ITypeDescriptorContext; destinationType: System.Type): Boolean; override; function ConvertFrom(context: ITypeDescriptorContext; culture: CultureInfo; value: System.Object): System.Object; override; function ConvertTo(context: ITypeDescriptorContext; culture: CultureInfo; value: System.Object; destinationType: System.Type): System.Object; override; function CreateInstance(context: ITypeDescriptorContext; propertyValues: IDictionary): System.Object; override; function GetCreateInstanceSupported(context: ITypeDescriptorContext): Boolean; override; function GetProperties(context: ITypeDescriptorContext; value: System.Object; attributes: AttributeArray): PropertyDescriptorCollection; override; function GetPropertiesSupported(context: ITypeDescriptorContext): Boolean; override; function GetStandardValues(context: ITypeDescriptorContext): TypeConverter.StandardValuesCollection; override; function GetStandardValuesExclusive(context: ITypeDescriptorContext): Boolean; override; function GetStandardValuesSupported(context: ITypeDescriptorContext): Boolean; override; function IsValid(context: ITypeDescriptorContext; value: System.Object): Boolean; override; end; function SubPropertyTypeConverter.PropertyConverter(context: ITypeDescriptorContext): TypeConverter; begin if not Assigned(_propertyConverter) and Assigned(context) and Assigned(context.PropertyDescriptor) then _propertyConverter := ItemSubPropertyDescriptor(context.PropertyDescriptor).RealDescriptor.Converter; Result := _propertyConverter; end; function SubPropertyTypeConverter.InstanceConverter(context: ITypeDescriptorContext): TypeConverter; begin if not Assigned(_instanceConverter) and Assigned(context) and Assigned(context.PropertyDescriptor) then _instanceConverter := TypeDescriptor.GetConverter(ItemSubPropertyDescriptor( context.PropertyDescriptor).ItemInstance(context.Instance)); Result := _instanceConverter; end; function SubPropertyTypeConverter.CanConvertFrom(context: ITypeDescriptorContext; sourceType: System.Type): Boolean; begin if Assigned(PropertyConverter(context)) then Result := _propertyConverter.CanConvertFrom(context, sourceType) else Result := inherited CanConvertFrom(context, sourceType); end; function SubPropertyTypeConverter.CanConvertTo(context: ITypeDescriptorContext; destinationType: System.Type): Boolean; begin if Assigned(PropertyConverter(context)) then Result := _propertyConverter.CanConvertTo(context, destinationType) else Result := inherited CanConvertTo(context, destinationType); end; function SubPropertyTypeConverter.ConvertFrom(context: ITypeDescriptorContext; culture: CultureInfo; value: System.Object): System.Object; begin if Assigned(PropertyConverter(context)) then Result := _propertyConverter.ConvertFrom(context, culture, value) else Result := inherited ConvertFrom(context, culture, value); end; function SubPropertyTypeConverter.ConvertTo(context: ITypeDescriptorContext; culture: CultureInfo; value: System.Object; destinationType: System.Type): System.Object; begin if Assigned(PropertyConverter(context)) then Result := _propertyConverter.ConvertTo(context, culture, value, destinationType) else Result := inherited ConvertTo(context, culture, value, destinationType); end; function SubPropertyTypeConverter.CreateInstance(context: ITypeDescriptorContext; propertyValues: IDictionary): System.Object; begin if Assigned(PropertyConverter(context)) then Result := _propertyConverter.CreateInstance(context, propertyValues) else Result := inherited CreateInstance(context, propertyValues); end; function SubPropertyTypeConverter.GetCreateInstanceSupported(context: ITypeDescriptorContext): Boolean; begin if Assigned(PropertyConverter(context)) then Result := _propertyConverter.GetCreateInstanceSupported(context) else Result := inherited GetCreateInstanceSupported(context); end; function SubPropertyTypeConverter.GetProperties(context: ITypeDescriptorContext; value: System.Object; attributes: AttributeArray): PropertyDescriptorCollection; var propPropColl: PropertyDescriptorCollection; itemInst: System.Object; instPropColl: PropertyDescriptorCollection; begin if Assigned(value) then propPropColl := TypeDescriptor.GetProperties(value, attributes) else if Assigned(context) and Assigned(context.PropertyDescriptor) then propPropColl := TypeDescriptor.GetProperties(context.PropertyDescriptor.PropertyType, attributes) else propPropColl := PropertyDescriptorCollection.Empty; if Assigned(context) and Assigned(context.PropertyDescriptor) and Assigned(context.Instance) then begin itemInst := ItemPropertyDescriptor(context.PropertyDescriptor).ItemInstance(context.Instance); if Assigned(itemInst) then instPropColl := TypeDescriptor.GetProperties(itemInst, attributes) else instPropColl := PropertyDescriptorCollection.Empty; end else begin itemInst := nil; instPropColl := PropertyDescriptorCollection.Empty; end; if Assigned(context) and Assigned(ItemSubPropertyDescriptor(context.PropertyDescriptor)) then instPropColl.Remove(ItemSubPropertyDescriptor(context.PropertyDescriptor).RealDescriptor); end; function SubPropertyTypeConverter.GetPropertiesSupported(context: ITypeDescriptorContext): Boolean; begin Result := (Assigned(PropertyConverter(context)) and _propertyConverter.GetPropertiesSupported(context)) or ((Assigned(InstanceConverter(context)) and _instanceConverter.GetPropertiesSupported(context))); end; function SubPropertyTypeConverter.GetStandardValues( context: ITypeDescriptorContext): TypeConverter.StandardValuesCollection; begin if Assigned(PropertyConverter(context)) then Result := _propertyConverter.GetStandardValues(context) else Result := inherited GetStandardValues(context); end; function SubPropertyTypeConverter.GetStandardValuesExclusive(context: ITypeDescriptorContext): Boolean; begin if Assigned(PropertyConverter(context)) then Result := _propertyConverter.GetStandardValuesExclusive(context) else Result := inherited GetStandardValuesExclusive(context); end; function SubPropertyTypeConverter.GetStandardValuesSupported(context: ITypeDescriptorContext): Boolean; begin if Assigned(PropertyConverter(context)) then Result := _propertyConverter.GetStandardValuesSupported(context) else Result := inherited GetStandardValuesSupported(context); end; function SubPropertyTypeConverter.IsValid(context: ITypeDescriptorContext; value: System.Object): Boolean; begin if Assigned(PropertyConverter(context)) then Result := _propertyConverter.IsValid(context, value) else Result := inherited IsValid(context, value); end;*) {$ENDREGION} constructor ItemSubPropertyDescriptor.Create(componentType: System.Type; name, description: string; &property: PropertyDescriptor; itemType: System.Type; emptyValue, index: System.Object); var attrs: ArrayList; i: Integer; begin if not Assigned(&property) then raise ArgumentNullException.Create('property'); attrs := ArrayList.Create(&property.Attributes); if description <> '' then begin i := attrs.Count - 1; while (i >= 0) and (attrs.Item[i].GetType <> TypeOf(DescriptionAttribute)) do Dec(i); if i >= 0 then attrs.RemoveAt(i); attrs.Add(DescriptionAttribute.Create(description)); end; inherited Create(componentType, name, itemType, Jedi.Collections.AttributeArray(attrs.ToArray(TypeOf(Attribute))), emptyValue, index); _realDescriptor := &property; end; function ItemSubPropertyDescriptor.CanResetValue(component: System.Object): Boolean; var item: System.Object; begin item := ItemInstance(component); if Assigned(item) then Result := RealDescriptor.CanResetValue(item) else Result := False; end; function ItemSubPropertyDescriptor.GetValue(component: System.Object): System.Object; (*var item: System.Object;*) begin Result := ItemInstance(component); (*if Assigned(item) then Result := RealDescriptor.GetValue(item) else Result := nil;*) end; procedure ItemSubPropertyDescriptor.ResetValue(component: System.Object); var item: System.Object; ccs: IComponentChangeService; begin item := ItemInstance(component); if Assigned(item) then begin ccs := IComponentChangeService(IInlineCollection(component).GetService(TypeOf(IComponentChangeService))); if Assigned(ccs) then ccs.OnComponentChanging(component, nil); RealDescriptor.ResetValue(item); if Assigned(ccs) then ccs.OnComponentChanged(component, nil, nil, nil); end end; procedure ItemSubPropertyDescriptor.SetValue(component, value: System.Object); var ccs: IComponentChangeService; item: System.Object; begin ccs := IComponentChangeService(IInlineCollection(component).GetService(TypeOf(IComponentChangeService))); if Assigned(ccs) then ccs.OnComponentChanging(component, nil); if RealDescriptor.GetValue(Value) = EmptyValue then begin if component is IList then IList(component).RemoveAt(Integer(Index)) else if component is IDictionary then IDictionary(component).Remove(Index); end; (* else begin item := ItemInstance(component); if Assigned(item) then RealDescriptor.SetValue(item, value); end;*) if Assigned(ccs) then ccs.OnComponentChanged(component, nil, nil, nil); end; function ItemSubPropertyDescriptor.ShouldSerializeValue(component: System.Object): Boolean; var item: System.Object; begin item := ItemInstance(component); if Assigned(item) then Result := RealDescriptor.CanResetValue(item) else Result := False; end; function ItemSubPropertyDescriptor.get_PropertyType: System.Type; begin Result := RealDescriptor.PropertyType; end; function ItemSubPropertyDescriptor.get_IsReadOnly: Boolean; begin Result := RealDescriptor.IsReadOnly; end; {$ENDREGION} {$REGION 'InlineCollectionUtils'} class function InlineCollectionUtils.CollectionConverterText: string; var rm: ResourceManager; begin if _collectionValue = System.String.Empty then begin rm := ResourceManager.Create('System', TypeOf(Uri).Module.Assembly); try _collectionValue := rm.GetString('CollectionConverterText'); finally rm.Free; end; end; Result := _collectionValue; end; class function InlineCollectionUtils.CreateNewItemProperty(baseDescriptor: PropertyDescriptor; name, description: string; propertyId: System.Object): PropertyDescriptor; var attrs: ArrayList; begin if not Assigned(baseDescriptor) then raise ArgumentNullException.Create('baseDescriptor'); if not Assigned(name) or (name = '') then name := baseDescriptor.Name; attrs := ArrayList.Create(baseDescriptor.Attributes); Result := NewItemPropertyDescriptor.Create(baseDescriptor.ComponentType, name, baseDescriptor.PropertyType, AttributeArray(attrs.ToArray(TypeOf(Attribute))), propertyId); end; class function InlineCollectionUtils.CreateNewItemProperty(info: PropertyInfo; name, description: string; propertyId: System.Object): PropertyDescriptor; var mattrs: array of System.Object; attrs: AttributeArray; begin if not Assigned(info) then raise ArgumentNullException.Create('info'); if not Assigned(name) or (name = '') then name := info.Name; mattrs := info.GetCustomAttributes(True); attrs := new(AttributeArray, Length(mattrs)); System.Array.Copy(mattrs, attrs, Length(mattrs)); Result := InlineCollectionUtils.CreateNewItemProperty(info.DeclaringType, info.PropertyType, attrs, name, description, propertyId); end; class function InlineCollectionUtils.CreateNewItemProperty(componentType, propertyType: System.Type; attributes: AttributeArray; name, description: string; propertyId: System.Object): PropertyDescriptor; var attrs: ArrayList; i: Integer; begin attrs := ArrayList.Create; for i := 0 to High(attributes) do begin if (description = '') or (attributes[i].GetType <> TypeOf(DescriptionAttribute)) then attrs.Add(attributes[i]); end; if description <> '' then attrs.Add(DescriptionAttribute.Create(description)); Result := NewItemPropertyDescriptor.Create(componentType, name, propertyType, AttributeArray(attrs.ToArray(TypeOf(Attribute))), propertyId); end; class function InlineCollectionUtils.CreateItemProperty(info: PropertyInfo; component: System.Object; name, description: string; index, emptyValue: System.Object; ignoreDefaultProperty: Boolean): PropertyDescriptor; var itemInstance: System.Object; itemType: System.Type; defaultProperty: PropertyDescriptor; mattrs: array of System.Object; attrs: ArrayList; i: Integer; begin if not Assigned(info) then raise ArgumentNullException.Create('info'); if not Assigned(component) then raise ArgumentNullException.Create('component'); itemInstance := info.GetValue(component, [index]); defaultProperty := nil; if not ignoreDefaultProperty then begin if Assigned(itemInstance) then begin itemType := itemInstance.GetType; defaultProperty := TypeDescriptor.GetDefaultProperty(itemInstance); end else begin itemType := info.PropertyType; defaultProperty := TypeDescriptor.GetDefaultProperty(info.PropertyType); end end; if Assigned(defaultProperty) then Result := ItemSubPropertyDescriptor.Create(info.DeclaringType, name, description, defaultProperty, itemType, emptyValue, index) else begin mattrs := info.GetCustomAttributes(True); attrs := ArrayList.Create; for i := 0 to High(mattrs) do begin if mattrs[i].GetType <> TypeOf(DescriptionAttribute) then attrs.Add(mattrs[i]); end; attrs.Add(DescriptionAttribute.Create(description)); Result := ItemPropertyDescriptor.Create(info.DeclaringType, name, itemInstance.GetType, AttributeArray(attrs.ToArray(TypeOf(Attribute))), emptyValue, index); end; end; class function InlineCollectionUtils.CreateItemProperty(propertyType: System.Type; attributes: AttributeArray; component: System.Object; name, description: string; index, emptyValue: System.Object): PropertyDescriptor; var attrs: ArrayList; i: Integer; begin if not Assigned(propertyType) then raise ArgumentNullException.Create('propertyType'); if not Assigned(component) then raise ArgumentNullException.Create('component'); attrs := ArrayList.Create; for i := 0 to High(attributes) do begin if (description = '') or (attributes[i].GetType <> TypeOf(DescriptionAttribute)) then attrs.Add(attributes[i]); end; if description <> '' then attrs.Add(DescriptionAttribute.Create(description)); Result := ItemPropertyDescriptor.Create(component.GetType, name, propertyType, AttributeArray(attrs.ToArray(TypeOf(Attribute))), emptyValue, index); end; {$ENDREGION} {$REGION 'InlineCollectionConverter'} function InlineCollectionConverter.ConvertTo(context: ITypeDescriptorContext; culture: CultureInfo; value: System.Object; destinationType: System.Type): System.Object; begin if (destinationType = TypeOf(string)) and (value.GetType <> TypeOf(string)) and (value is IInlineCollection) then Result := IInlineCollection(value).GetCollectionValue else Result := inherited ConvertTo(context, culture, value, destinationType); end; function InlineCollectionConverter.GetPropertiesSupported(context: ITypeDescriptorContext): Boolean; begin Result := Assigned(context) and Assigned(context.PropertyDescriptor) and Assigned(context.Instance) and (context.PropertyDescriptor.GetValue(context.Instance) is IInlineCollection); end; function InlineCollectionConverter.GetProperties(context: ITypeDescriptorContext; value: System.Object; attributes: AttributeArray): PropertyDescriptorCollection; var pdc: PropertyDescriptorCollection; i: Integer; begin if value is IInlineCollection then begin Result := IInlineCollection(value).GetNewItemProperties; if not Assigned(Result) then Result := IInlineCollection(value).GetItemProperties else begin pdc := IInlineCollection(value).GetItemProperties; for i := 0 to pdc.Count - 1 do Result.Add(pdc.Item[i]); end; end else Result := PropertyDescriptorCollection.Create(nil); end; {$ENDREGION} {$REGION 'InlineCollectionEditor'} function InlineCollectionEditor.GetEditStyle(context: ITypeDescriptorContext): UITypeEditorEditStyle; begin Result := UITypeEditorEditStyle.Modal; end; function InlineCollectionEditor.EditValue(context: ITypeDescriptorContext; provider: IServiceProvider; value: System.Object): System.Object; var ccs: IComponentChangeService; begin Result := value; if value is IInlineCollection then begin ccs := provider.GetService(TypeOf(IComponentChangeService)); if ccs <> nil then ccs.OnComponentChanging(value, nil); if value is IList then IList(value).Clear else if value is IDictionary then IDictionary(value).Clear; if ccs <> nil then ccs.OnComponentChanged(value, nil, nil, nil); end; end; {$ENDREGION} {$REGION 'InlineCollectionBase'} function InlineCollectionBase.GetItemDescription(index: integer): string; begin Result := ''; end; function InlineCollectionBase.GetItemEmptyValue(index: Integer): System.Object; begin Result := nil; end; function InlineCollectionBase.GetItemIgnoreDefaultProperty(index: Integer): Boolean; begin Result := False; end; function InlineCollectionBase.GetItemName(index: integer): string; begin Result := System.String.Format('[{0}]', index); end; function InlineCollectionBase.GetItemProperty(index: Integer): PropertyDescriptor; begin Result := InlineCollectionUtils.CreateItemProperty(IndexerInfo, Self, GetItemName(index), GetItemDescription(index), index, GetItemEmptyValue(index), GetItemIgnoreDefaultProperty(index)); end; function InlineCollectionBase.IndexerInfo: PropertyInfo; begin if not Assigned(_indexerInfo) then begin _indexerInfo := GetType.GetProperty('Item', [TypeOf(Integer)]); if not Assigned(_indexerInfo) then _indexerInfo := GetType.GetProperty('Items', [TypeOf(Integer)]); if not Assigned(_indexerInfo) then raise MissingMemberException.Create('The collection does not have an indexer called Item or Items'); end; Result := _indexerInfo; end; procedure InlineCollectionBase.AddItem(value: System.Object; addPropertyId: System.Object); begin List.Add(value); end; function InlineCollectionBase.GetCollectionValue: string; begin Result := InlineCollectionUtils.CollectionConverterText; end; function InlineCollectionBase.GetNewItemProperties: PropertyDescriptorCollection; begin Result := PropertyDescriptorCollection.Create(nil); Result.Add(InlineCollectionUtils.CreateNewItemProperty(IndexerInfo, '(new)', 'Adds a new item to the collection', 0)); end; function InlineCollectionBase.GetItemProperties: PropertyDescriptorCollection; var i: Integer; begin Result := PropertyDescriptorCollection.Create(nil); for i := 0 to IList(Self).Count - 1 do Result.Add(GetItemProperty(i)); end; function InlineCollectionBase.GetService(serviceType: System.Type): System.Object; begin Result := nil; end; {$ENDREGION} {$REGION 'InlineDictionaryBase'} function InlineDictionaryBase.GetItemDescription(key: System.Object): string; begin Result := ''; end; function InlineDictionaryBase.GetItemEmptyValue(key: System.Object): System.Object; begin Result := nil; end; function InlineDictionaryBase.GetItemProperty(key, value: System.Object): PropertyDescriptor; begin Result := InlineCollectionUtils.CreateItemProperty(value.GetType, AttributeArray.Create(), Self, key.ToString, GetItemDescription(key), key, GetItemEmptyValue(key)); end; procedure InlineDictionaryBase.AddItem(value: System.Object; addPropertyId: System.Object); begin Dictionary.Add(value, nil); end; function InlineDictionaryBase.GetCollectionValue: string; begin Result := InlineCollectionUtils.CollectionConverterText; end; function InlineDictionaryBase.GetNewItemProperties: PropertyDescriptorCollection; begin Result := PropertyDescriptorCollection.Create(nil); Result.Add(InlineCollectionUtils.CreateNewItemProperty(TypeOf(Self), TypeOf(string), AttributeArray.Create(), '(new)', 'Adds a new item to the collection using the specified key', 0)); end; function InlineDictionaryBase.GetItemProperties: PropertyDescriptorCollection; var di: IDictionaryEnumerator; begin Result := PropertyDescriptorCollection.Create(nil); di := GetEnumerator; while di.MoveNext do Result.Add(GetItemProperty(di.Key, di.Value)); end; function InlineDictionaryBase.GetService(serviceType: System.Type): System.Object; begin Result := nil; end; {$ENDREGION} end. |