[JEDI.NET-commits] dev/jedi_mbe/run Jedi.Windows.Forms.Hmi.Leds.pas,1.1,1.2
Status: Pre-Alpha
Brought to you by:
jedi_mbe
From: Marcel B. <jed...@us...> - 2004-06-15 19:33:42
|
Update of /cvsroot/jedidotnet/dev/jedi_mbe/run In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19954/dev/jedi_mbe/run Modified Files: Jedi.Windows.Forms.Hmi.Leds.pas Log Message: Updated to changes in inline collection editing Index: Jedi.Windows.Forms.Hmi.Leds.pas =================================================================== RCS file: /cvsroot/jedidotnet/dev/jedi_mbe/run/Jedi.Windows.Forms.Hmi.Leds.pas,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Jedi.Windows.Forms.Hmi.Leds.pas 12 Jun 2004 18:31:38 -0000 1.1 --- Jedi.Windows.Forms.Hmi.Leds.pas 15 Jun 2004 19:33:19 -0000 1.2 *************** *** 16,21 **** Contributor(s): - Last Modified: 2004-06-09 - You may retrieve the latest version of this file at the Project JEDI's JWFL home page, located at http://jwfl.sourceforge.net --- 16,19 ---- *************** *** 23,27 **** Known Issues: ---------------------------------------------------------------------------------------------------} ! unit Jedi.Windows.Forms.Hmi.Leds; --- 21,25 ---- Known Issues: ---------------------------------------------------------------------------------------------------} ! // $Id$ unit Jedi.Windows.Forms.Hmi.Leds; *************** *** 53,85 **** LedFrameStyle = (None, Flush, Sunken, Raised); - (*LedStateCollectionConverter = class(System.ComponentModel.TypeConverter) - public - type - LedStateItemProperty = class(System.ComponentModel.TypeConverter.SimplePropertyDescriptor) - strict private - mCollection: LedStateCollection; - mItem: LedStateBase; - public - constructor Create(collection: LedStateCollection; ledState: LedStateBase); - function GetValue(component: System.Object): System.Object; override; - procedure SetValue(component, value: System.Object); override; - function GetChildProperties(instance: System.Object; - filter: array of Attribute): PropertyDescriptorCollection; override; - end; - function CanConvertTo(context: ITypeDescriptorContext; destinationType: System.Type): Boolean; override; - function ConvertTo(context: ITypeDescriptorContext; culture: CultureInfo; value: System.Object; - destinationType: System.Type): System.Object; override; - function GetPropertiesSupported(context: ITypeDescriptorContext): Boolean; override; - function GetProperties(context: ITypeDescriptorContext; value: System.Object; - attributes: array of Attribute): PropertyDescriptorCollection; override; - end; - - LedStateCollectionEditor = class (System.Drawing.Design.UITypeEditor) - function GetEditStyle(context: ITypeDescriptorContext): UITypeEditorEditStyle; override; - function EditValue(context: ITypeDescriptorContext; provider: IServiceProvider; - value: System.Object): System.Object; override; - end;*) - - // [TypeConverter(TypeOf(LedStateCollectionConverter)), Editor(TypeOf(LedStateCollectionEditor), TypeOf(UITypeEditor))] LedStateCollection = class sealed (InlineCollectionBase) strict private --- 51,54 ---- *************** *** 88,91 **** --- 57,62 ---- function GetItem(index: Integer): LedStateBase; procedure SetItem(index: Integer; value: LedStateBase); + procedure OnClear; override; + procedure OnClearComplete; override; procedure OnInsert(index: Integer; value: System.Object); override; procedure OnInsertComplete(index: Integer; value: System.Object); override; *************** *** 95,101 **** procedure OnValidate(value: System.Object); override; procedure AddItem(value: System.Object; addPropertyId: System.Object); override; function GetCollectionValue: string; override; function GetNewItemProperties: PropertyDescriptorCollection; override; - function GetItemDescription(index: integer): string; override; function GetItemEmptyValue(index: Integer): System.Object; override; function GetItemName(index: integer): string; override; --- 66,72 ---- procedure OnValidate(value: System.Object); override; procedure AddItem(value: System.Object; addPropertyId: System.Object); override; + function GetAllowRemove(key: System.Object): Boolean; override; function GetCollectionValue: string; override; function GetNewItemProperties: PropertyDescriptorCollection; override; function GetItemEmptyValue(index: Integer): System.Object; override; function GetItemName(index: integer): string; override; *************** *** 112,118 **** LedStateConverter = class (System.ComponentModel.TypeConverter) public - function CanConvertFrom(context: ITypeDescriptorContext; sourceType: System.Type): Boolean; override; - function ConvertFrom(context: ITypeDescriptorContext; culture: CultureInfo; - value: System.Object): System.Object; override; function CanConvertTo(context: ITypeDescriptorContext; destinationType: System.Type): Boolean; override; function ConvertTo(context: ITypeDescriptorContext; culture: CultureInfo; value: System.Object; --- 83,86 ---- *************** *** 121,131 **** function GetProperties(context: ITypeDescriptorContext; value: System.Object; attributes: array of Attribute): PropertyDescriptorCollection; override; - function GetStandardValues(context: ITypeDescriptorContext): TypeConverter.StandardValuesCollection; override; - function GetStandardValuesSupported(context: ITypeDescriptorContext): Boolean; override; end; ! [TypeConverter(TypeOf(LedStateConverter)), DefaultProperty('Color') ! // Editor('Jedi.Windows.Forms.Hmi.Leds.Design.LedStateEditor,Jedi.Windows.Forms.Hmi.Design', TypeOf(UITypeEditor)) ! ] LedStateBase = class abstract (System.Object) strict private --- 89,95 ---- function GetProperties(context: ITypeDescriptorContext; value: System.Object; attributes: array of Attribute): PropertyDescriptorCollection; override; end; ! [TypeConverter(TypeOf(LedStateConverter)), DefaultProperty('Color')] LedStateBase = class abstract (System.Object) strict private *************** *** 155,161 **** --- 119,127 ---- { Marks the bitmap as invalid and notifies the owning LedStyle instance. } procedure Invalidate; + [Description('Color for this led state.'), Browsable(False)] property Color: System.Drawing.Color read mColor; property ColorChanged: EventHandler add mColorChanged remove mColorChanged; published + [Description('Name of this led state.'), RefreshProperties(System.ComponentModel.RefreshProperties.All)] property Name: string read mName; end; *************** *** 244,247 **** --- 210,214 ---- procedure EndInit; function IsInitializing: Boolean; + procedure CreateDefaultStates; virtual; { Render the specified state into a new bitmap. The method is usually called by the specified state object (the LedStateBase.GetBitmap method calls it to render itself and stores the resulting bitmap internally for reuse *************** *** 311,319 **** function GetInstDescMemberInfo: MemberInfo; override; function GetInstDescArguments: ArrayList; override; - procedure LedStyleInit; override; function GetOffPercentage: Integer; function GetLitColor: System.Drawing.Color; procedure SetOffPercentage(value: Integer); procedure SetLitColor(value: System.Drawing.Color); public constructor Create; overload; --- 278,287 ---- function GetInstDescMemberInfo: MemberInfo; override; function GetInstDescArguments: ArrayList; override; function GetOffPercentage: Integer; function GetLitColor: System.Drawing.Color; procedure SetOffPercentage(value: Integer); procedure SetLitColor(value: System.Drawing.Color); + protected + procedure CreateDefaultStates; override; public constructor Create; overload; *************** *** 329,333 **** function GetInstDescMemberInfo: MemberInfo; override; function GetInstDescArguments: ArrayList; override; ! procedure LedStyleInit; override; public constructor Create; overload; --- 297,302 ---- function GetInstDescMemberInfo: MemberInfo; override; function GetInstDescArguments: ArrayList; override; ! protected ! procedure CreateDefaultStates; override; public constructor Create; overload; *************** *** 474,478 **** SetName('Off'); end; - {$ENDREGION} --- 443,446 ---- *************** *** 494,497 **** --- 462,477 ---- end; + procedure LedStateCollection.OnClear; + begin + mLedStyle.OnStateRemoved(-1); + inherited OnClear; + end; + + procedure LedStateCollection.OnClearComplete; + begin + inherited OnClearComplete; + mLedStyle.CreateDefaultStates; + end; + procedure LedStateCollection.OnInsert(index: Integer; value: System.Object); begin *************** *** 546,549 **** --- 526,534 ---- end; + function LedStateCollection.GetAllowRemove(key: System.Object): Boolean; + begin + Result := not ((Integer(key) = 0) or (Count = 2)); + end; + function LedStateCollection.GetCollectionValue: string; begin *************** *** 558,566 **** end; - function LedStateCollection.GetItemDescription(index: integer): string; - begin - Result := 'Color for this item state.'; - end; - function LedStateCollection.GetItemEmptyValue(index: Integer): System.Object; begin --- 543,546 ---- *************** *** 607,791 **** {$ENDREGION} - {$REGION 'LedStateCollectionConverter'} - (* - {$REGION 'LedStateCollectionConverter.LedStateItemProperty'} - type - TAttributeArray = array of Attribute; - - constructor LedStateCollectionConverter.LedStateItemProperty.Create(collection: LedStateCollection; - ledState: LedStateBase); - begin - if not Assigned(collection) then - raise ArgumentNullException.Create('collection'); - if Assigned(ledState) and not collection.Contains(ledState) then - raise ArgumentOutOfRangeException.Create('ledState', - 'Specified state does not belong to the specified collection'); - if Assigned(ledState) then - inherited Create(TypeOf(LedStateCollection), ledState.Name, TypeOf(LedStateBase), nil) - else - inherited Create(TypeOf(LedStateCollection), '(new)', TypeOf(Color)); - mCollection := collection; - mItem := ledState; - end; - - function LedStateCollectionConverter.LedStateItemProperty.GetValue(component: System.Object): System.Object; - begin - if Assigned(mItem) then - Result := mItem - else - Result := ''; - end; - - procedure LedStateCollectionConverter.LedStateItemProperty.SetValue(component, value: System.Object); - begin - if (not Assigned(value) or ((value.GetType = TypeOf(string)) and (string(value) = '')) or - ((value.GetType = TypeOf(Color)) and (Color(value) = Color.Empty))) and Assigned(mItem) then - begin - if mCollection.IndexOf(mItem) = 0 then - raise Exception.Create('You can not remove the off state'); - if mCollection.Count = 2 then - raise Exception.Create('At least two states must be present at all times.'); - mCollection.Remove(mItem); - end; - if Assigned(value) and (string(value) <> '') then - begin - if not Assigned(mItem) then - begin - mItem := LedState.Create(Color.FromName(string(value)), string(value)); - mCollection.Add(mItem); - end - else - LedState(mItem).Color := Color.FromName(string(value)); - end; - if Assigned(value) and (value is Color) then - begin - if not Assigned(mItem) then - begin - mItem := LedState.Create(Color(value), Color(value).Name); - mCollection.Add(mItem); - end - else - LedState(mItem).Color := Color(value); - end; - end; - - function LedStateCollectionConverter.LedStateItemProperty.GetChildProperties(instance: System.Object; - filter: array of Attribute): PropertyDescriptorCollection; - var - colorProp: PropertyDescriptor; - begin - raise Exception.Create('Getting properties for state failed.'); - if Assigned(instance) then - begin - Result := TypeDescriptor.GetProperties(instance); - colorProp := Result.Find('Color', True); - if Assigned(colorProp) then - Result.Remove(colorProp); - end - else - Result := PropertyDescriptorCollection.Empty; - end; - {$ENDREGION} - function LedStateCollectionConverter.CanConvertTo(context: ITypeDescriptorContext; - destinationType: System.Type): Boolean; - begin - Result := (destinationType = TypeOf(string)) or inherited CanConvertTo(context, destinationType); - end; - - function LedStateCollectionConverter.ConvertTo(context: ITypeDescriptorContext; culture: CultureInfo; - value: System.Object; destinationType: System.Type): System.Object; - begin - if (destinationType = TypeOf(string)) and (value.GetType <> TypeOf(string)) then - Result := '(led states)' - else - Result := inherited ConvertTo(context, culture, value, destinationType); - end; - - function LedStateCollectionConverter.GetPropertiesSupported(context: ITypeDescriptorContext): Boolean; - begin - Result := True; - end; - - type - TStringArray = array of string; - - function LedStateCollectionConverter.GetProperties(context: ITypeDescriptorContext; value: System.Object; - attributes: array of Attribute): PropertyDescriptorCollection; - var - coll: LedStateCollection; - i: Integer; - begin - coll := LedStateCollection(value); - Result := PropertyDescriptorCollection.Create(nil); - Result.Add(LedStateCollectionConverter.LedStateItemProperty.Create(coll, nil)); - for i := 0 to coll.Count - 1 do - Result.Add(LedStateCollectionConverter.LedStateItemProperty.Create(coll, coll[i])); - end;*) - {$ENDREGION} - - {$REGION 'LedStateCollectionEditor'} - (*function LedStateCollectionEditor.GetEditStyle(context: ITypeDescriptorContext): UITypeEditorEditStyle; - begin - Result := UITypeEditorEditStyle.Modal; - end; - - function LedStateCollectionEditor.EditValue(context: ITypeDescriptorContext; provider: IServiceProvider; - value: System.Object): System.Object; - var - ccs: IComponentChangeService; - begin - ccs := provider.GetService(TypeOf(IComponentChangeService)); - if ccs <> nil then - ccs.OnComponentChanging(value, nil); - Result := value; - with LedStateCollection(value) do - while Count > 2 do - RemoveAt(Count - 1); - if ccs <> nil then - ccs.OnComponentChanged(value, nil, nil, nil); - end;*) - {$ENDREGION} - {$REGION 'LedStateConverter'} - function LedStateConverter.CanConvertFrom(context: ITypeDescriptorContext; sourceType: System.Type): Boolean; - begin - Result := (sourceType = TypeOf(string)) or (sourceType = TypeOf(Color)) or - inherited CanConvertFrom(context, sourceType); - end; - - function LedStateConverter.ConvertFrom(context: ITypeDescriptorContext; culture: CultureInfo; value: System.Object): System.Object; - var - ls: System.Object; - ccs: IComponentChangeService; - begin - if value.GetType = TypeOf(string) then - value := TypeDescriptor.GetConverter(TypeOf(Color)).ConvertFrom(value); - if value.GetType = TypeOf(Color) then - begin - if Assigned(context) and Assigned(context.Instance) and Assigned(context.PropertyDescriptor) then - begin - ls := context.PropertyDescriptor.GetValue(context.Instance); - ccs := context.GetService(TypeOf(IComponentChangeService)); - if ls is LedState then - begin - if Assigned(ccs) then - ccs.OnComponentChanging(ls, nil); - LedState(ls).Color := Color(value); - if Assigned(ccs) then - ccs.OnComponentChanged(ls, nil, nil, nil); - end; - Result := ls; - end - else - Result := nil; - end - else - Result := inherited ConvertFrom(context, culture, value); - end; - function LedStateConverter.CanConvertTo(context: ITypeDescriptorContext; destinationType: System.Type): Boolean; begin ! Result := (destinationType = TypeOf(InstanceDescriptor)) or (destinationType = TypeOf(string)) or ! inherited CanConvertTo(context, destinationType); end; --- 587,594 ---- {$ENDREGION} {$REGION 'LedStateConverter'} function LedStateConverter.CanConvertTo(context: ITypeDescriptorContext; destinationType: System.Type): Boolean; begin ! Result := (destinationType = TypeOf(InstanceDescriptor)) or inherited CanConvertTo(context, destinationType); end; *************** *** 796,802 **** Result := LedStateBase(value).GetInstanceDescriptor else - if (destinationType = TypeOf(string)) and (value.GetType <> TypeOf(string)) then - Result := TypeDescriptor.GetConverter(TypeOf(Color)).ConvertTo(context, culture, LedStateBase(value).Color, destinationType) - else Result := inherited ConvertTo(context, culture, value, destinationType); end; --- 599,602 ---- *************** *** 817,830 **** Result.Remove(pd); end; - - function LedStateConverter.GetStandardValues(context: ITypeDescriptorContext): TypeConverter.StandardValuesCollection; - begin - Result := TypeDescriptor.GetConverter(TypeOf(Color)).GetStandardValues(context); - end; - - function LedStateConverter.GetStandardValuesSupported(context: ITypeDescriptorContext): Boolean; - begin - Result := True; - end; {$ENDREGION} --- 617,620 ---- *************** *** 855,874 **** if value <> mColor then begin ! if (value = Color.Empty) and Assigned(mLedStyle) then ! begin ! if mLedStyle.States.IndexOf(Self) = 0 then ! raise Exception.Create('You can not remove the off state'); ! if mLedStyle.States.Count = 2 then ! raise Exception.Create('At least two states must be present at all times.'); ! mLedStyle.States.Remove(Self); ! end ! else ! begin ! mColor := value; ! mBitmapValid := False; ! OnColorChanged(EventArgs.Empty); ! if Assigned(mLedStyle) then ! mLedStyle.InvalidateSettings; ! end; end; end; --- 645,653 ---- if value <> mColor then begin ! mColor := value; ! mBitmapValid := False; ! OnColorChanged(EventArgs.Empty); ! if Assigned(mLedStyle) then ! mLedStyle.InvalidateSettings; end; end; *************** *** 1049,1053 **** Styles.Remove(value); end; - {$ENDREGION} --- 828,831 ---- *************** *** 1080,1083 **** --- 858,862 ---- begin mStates := LedStateCollection.Create(Self); + CreateDefaultStates end; *************** *** 1159,1162 **** --- 938,945 ---- end; + procedure LedStyleBase.CreateDefaultStates; + begin + end; + procedure LedStyleBase.InvalidateState(index: Integer); begin *************** *** 1253,1259 **** ColorHandling.Darken(BackColor, 20), ColorHandling.Brighten(BackColor, 80), LinearGradientMode.ForwardDiagonal); TmpPen := Pen.Create(TmpBr, 2); ! TmpGr.DrawEllipse(TmpPen, 1, 1, mDiameter - 2, mDiameter - 2); ! TmpGr.DrawEllipse(TmpPen, 2, 2, mDiameter - 2, mDiameter - 2); ! TmpPth.AddEllipse(3, 3, mDiameter - 4, mDiameter - 4); TmpPen.Free; TmpBr.Free; --- 1036,1042 ---- ColorHandling.Darken(BackColor, 20), ColorHandling.Brighten(BackColor, 80), LinearGradientMode.ForwardDiagonal); TmpPen := Pen.Create(TmpBr, 2); ! TmpGr.DrawEllipse(TmpPen, 1, 1, mDiameter - 3, mDiameter - 3); ! TmpGr.DrawEllipse(TmpPen, 2, 2, mDiameter - 3, mDiameter - 3); ! TmpPth.AddEllipse(3, 3, mDiameter - 5, mDiameter - 5); TmpPen.Free; TmpBr.Free; *************** *** 1264,1270 **** ColorHandling.Brighten(BackColor, 80), ColorHandling.Darken(BackColor, 20), LinearGradientMode.ForwardDiagonal); TmpPen := Pen.Create(TmpBr, 2); ! TmpGr.DrawEllipse(TmpPen, 0, 0, mDiameter - 2, mDiameter - 2); ! TmpGr.DrawEllipse(TmpPen, 1, 1, mDiameter - 2, mDiameter - 2); ! TmpPth.AddEllipse(1, 1, mDiameter - 4, mDiameter - 4); TmpPen.Free; TmpBr.Free; --- 1047,1053 ---- ColorHandling.Brighten(BackColor, 80), ColorHandling.Darken(BackColor, 20), LinearGradientMode.ForwardDiagonal); TmpPen := Pen.Create(TmpBr, 2); ! TmpGr.DrawEllipse(TmpPen, 0, 0, mDiameter - 3, mDiameter - 3); ! TmpGr.DrawEllipse(TmpPen, 1, 1, mDiameter - 3, mDiameter - 3); ! TmpPth.AddEllipse(1, 1, mDiameter - 5, mDiameter - 5); TmpPen.Free; TmpBr.Free; *************** *** 1275,1280 **** ColorHandling.Darken(BackColor, 20), ColorHandling.Brighten(BackColor, 80), LinearGradientMode.ForwardDiagonal); TmpPen := Pen.Create(TmpBr, 2); ! TmpGr.DrawEllipse(TmpPen, 1, 1, mDiameter - 2, mDiameter - 2); ! TmpPth.AddEllipse(2, 2, mDiameter - 4, mDiameter - 4); TmpPen.Free; TmpBr.Free; --- 1058,1063 ---- ColorHandling.Darken(BackColor, 20), ColorHandling.Brighten(BackColor, 80), LinearGradientMode.ForwardDiagonal); TmpPen := Pen.Create(TmpBr, 2); ! TmpGr.DrawEllipse(TmpPen, 1, 1, mDiameter - 3, mDiameter - 3); ! TmpPth.AddEllipse(2, 2, mDiameter - 5, mDiameter - 5); TmpPen.Free; TmpBr.Free; *************** *** 1362,1366 **** if Assigned(FrameClipRegion) then TmpGr.SetClip(FrameClipRegion, CombineMode.Intersect); ! TmpGr.FillEllipse(TmpBrush, 2 + Offset, 2 + Offset, LedSize - 4, LedSize - 4); TmpGr.Free; TmpBrush.Free; --- 1145,1149 ---- if Assigned(FrameClipRegion) then TmpGr.SetClip(FrameClipRegion, CombineMode.Intersect); ! TmpGr.FillEllipse(TmpBrush, 2 + Offset, 2 + Offset, LedSize - 3, LedSize - 3); TmpGr.Free; TmpBrush.Free; *************** *** 1372,1376 **** inherited Create; end; - {$ENDREGION} --- 1155,1158 ---- *************** *** 1389,1403 **** end; - procedure SingleColorNormalLedStyle.LedStyleInit; - begin - inherited LedStyleInit; - States.Add(PercentageOffLedState.Create); - States.Add(LedState.Create); - LedState(States[1]).Name := 'On'; - Include(States[1].ColorChanged, PercentageOffLedState(States[0]).LitColor_Changed); - OffPercentage := 25; - LitColor := System.Drawing.Color.Lime; - end; - function SingleColorNormalLedStyle.GetOffPercentage: Integer; begin --- 1171,1174 ---- *************** *** 1420,1423 **** --- 1191,1204 ---- end; + procedure SingleColorNormalLedStyle.CreateDefaultStates; + begin + States.Add(PercentageOffLedState.Create); + States.Add(LedState.Create); + LedState(States[1]).Name := 'On'; + Include(States[1].ColorChanged, PercentageOffLedState(States[0]).LitColor_Changed); + OffPercentage := 25; + LitColor := System.Drawing.Color.Lime; + end; + constructor SingleColorNormalLedStyle.Create; begin *************** *** 1460,1466 **** end; ! procedure MultiColorNormalLedStyle.LedStyleInit; begin - inherited LedStyleInit; States.Add(LedState.Create(Color.Black, 'Off')); States.Add(LedState.Create(Color.Lime, 'Lime')); --- 1241,1246 ---- end; ! procedure MultiColorNormalLedStyle.CreateDefaultStates; begin States.Add(LedState.Create(Color.Black, 'Off')); States.Add(LedState.Create(Color.Lime, 'Lime')); *************** *** 1656,1663 **** procedure SingleLed.Style_StateRemoved(sender: System.Object; e: StateChangedEventArgs); begin ! if e.Index < mLedStateIdx then Dec(mLedStateIdx) else ! if e.Index = mLedStateIdx then mLedStateIdx := 0; Invalidate; --- 1436,1443 ---- procedure SingleLed.Style_StateRemoved(sender: System.Object; e: StateChangedEventArgs); begin ! if (e.Index > -1) and (e.Index < mLedStateIdx) then Dec(mLedStateIdx) else ! if (e.Index = mLedStateIdx) or (e.Index = -1) then mLedStateIdx := 0; Invalidate; |