Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / wpf / src / Core / CSharp / System / Windows / Input / Command / InputBindingCollection.cs / 1 / InputBindingCollection.cs
//---------------------------------------------------------------------------- // //// Copyright (C) Microsoft Corporation. All rights reserved. // // // // Description: InputBindingCollection serves the purpose of Storing/Retrieving InputBindings // // See spec at : http://avalon/coreui/Specs/Commanding(new).mht // // // History: // 04/02/2004 : chandras - Created // //--------------------------------------------------------------------------- using System; using System.Collections; using System.Diagnostics; using System.Collections.Specialized; using System.Windows; using System.Windows.Input; using SR=MS.Internal.PresentationCore.SR; using SRID=MS.Internal.PresentationCore.SRID; namespace System.Windows.Input { ////// InputBindingCollection - Collection of InputBindings. /// Stores the InputBindings Sequentially in an System.Collections.Generic.List"InputBinding"a. /// Will be changed to generic List implementation once the /// parser supports generic collections. /// public sealed class InputBindingCollection : IList { //----------------------------------------------------- // // Constructors // //----------------------------------------------------- #region Constructors ////// Constructor /// public InputBindingCollection() { } ////// InputBindingCollection /// /// InputBinding array public InputBindingCollection(IList inputBindings) { if (inputBindings != null && inputBindings.Count > 0) { this.AddRange(inputBindings as ICollection); } } #endregion Constructors //------------------------------------------------------ // // Public Methods // //----------------------------------------------------- #region Public Methods #region Implementation of IList #region Implementation of ICollection ////// CopyTo - to copy the entire collection into an array /// /// generic object array /// void ICollection.CopyTo(System.Array array, int index) { if (_innerBindingList != null) { ((ICollection)_innerBindingList).CopyTo(array, index); } } #endregion Implementation of ICollection ////// IList.Contains /// /// key ///true - if found, false - otherwise bool IList.Contains(object key) { return this.Contains(key as InputBinding); } ////// IndexOf - returns the index of the item in the list /// /// item whose index is sought ///index of the item or -1 int IList.IndexOf(object value) { InputBinding inputBinding = value as InputBinding; return ((inputBinding != null) ? this.IndexOf(inputBinding) : -1); } ////// Insert /// /// /// void IList.Insert(int index, object value) { this.Insert(index, value as InputBinding); } ////// Add - appends the given inputbinding to the current list. /// /// InputBinding object to add int IList.Add(object inputBinding) { this.Add(inputBinding as InputBinding); return 0; // ICollection.Add no longer returns the indice } ////// Remove - removes the given inputbinding from the current list. /// /// InputBinding object to remove void IList.Remove(object inputBinding) { this.Remove(inputBinding as InputBinding); } ////// Indexing operator /// object IList.this[int index] { get { return this[index]; } set { InputBinding inputBinding = value as InputBinding; if (inputBinding == null) throw new NotSupportedException(SR.Get(SRID.CollectionOnlyAcceptsInputBindings)); this[index] = inputBinding; } } #endregion Implementation of IList ////// Indexing operator /// public InputBinding this[int index] { get { // disable PreSharp warning about throwing exceptions in getter; // this is allowed in an indexed property. (First disable C# // warning about unknown warning numbers.) #pragma warning disable 1634, 1691 #pragma warning disable 6503 if (_innerBindingList != null) { return _innerBindingList[index]; } else { throw new ArgumentOutOfRangeException("index"); } #pragma warning restore 6503 #pragma warning restore 1634, 1691 } set { if (_innerBindingList != null) { _innerBindingList[index] = value; } else { throw new ArgumentOutOfRangeException("index"); } } } ////// Add /// /// public int Add(InputBinding inputBinding) { if (inputBinding != null) { if (_innerBindingList == null) _innerBindingList = new System.Collections.Generic.List(1); _innerBindingList.Add(inputBinding); return 0; // ICollection.Add no longer returns the indice } else { throw new NotSupportedException(SR.Get(SRID.CollectionOnlyAcceptsInputBindings)); } } /// /// ICollection.IsSynchronized /// public bool IsSynchronized { get { if (_innerBindingList != null) return ((IList)_innerBindingList).IsSynchronized; return false; } } ////// IndexOf /// /// ///public int IndexOf(InputBinding value) { return (_innerBindingList != null) ? _innerBindingList.IndexOf(value) : -1; } /// /// Adds the elements of the given collection to the end of this list. If /// required, the capacity of the list is increased to twice the previous /// capacity or the new size, whichever is larger. /// /// collection to append public void AddRange(ICollection collection) { if (collection == null) { throw new ArgumentNullException("collection"); } if ( collection.Count > 0) { if (_innerBindingList == null) _innerBindingList = new System.Collections.Generic.List(collection.Count); IEnumerator collectionEnum = collection.GetEnumerator(); while(collectionEnum.MoveNext()) { InputBinding inputBinding = collectionEnum.Current as InputBinding; if (inputBinding != null) { _innerBindingList.Add(inputBinding); } else { throw new NotSupportedException(SR.Get(SRID.CollectionOnlyAcceptsInputBindings)); } } } } /// /// Insert at given index /// /// index at which to insert the given item /// inputBinding to insert public void Insert(int index, InputBinding inputBinding) { if (inputBinding == null) { throw new NotSupportedException(SR.Get(SRID.CollectionOnlyAcceptsInputBindings)); } if (_innerBindingList != null) { _innerBindingList.Insert(index, inputBinding); } } ////// Remove /// /// public void Remove(InputBinding inputBinding) { if (_innerBindingList != null && inputBinding != null) _innerBindingList.Remove(inputBinding as InputBinding); } ////// RemoveAt /// /// index at which the item needs to be removed public void RemoveAt(int index) { if (_innerBindingList != null) _innerBindingList.RemoveAt(index); } ////// IsFixedSize - if readonly - fixed, else false. /// public bool IsFixedSize { get { return IsReadOnly; } } ////// Count /// public int Count { get { return (_innerBindingList != null ? _innerBindingList.Count : 0); } } ////// ICollection.SyncRoot /// public object SyncRoot { get { return this; } } ////// Clears the Entire InputBindingCollection /// public void Clear() { if (_innerBindingList != null) { _innerBindingList.Clear(); _innerBindingList = null; } } #region Implementation of Enumerable ////// IEnumerable.GetEnumerator - For Enumeration purposes /// ///public IEnumerator GetEnumerator() { if (_innerBindingList != null) return _innerBindingList.GetEnumerator(); System.Collections.Generic.List list = new System.Collections.Generic.List (0); return list.GetEnumerator(); } #endregion Implementation of IEnumberable /// /// IList.IsReadOnly - Tells whether this is readonly Collection. /// public bool IsReadOnly { get { return _isReadOnly; } } ////// Contains /// /// key ///true - if found, false - otherwise public bool Contains(InputBinding key) { if (_innerBindingList != null && key != null) { return _innerBindingList.Contains(key); } return false; } ////// CopyTo - to copy the entire collection into an array /// /// type-safe InputBinding array /// start index in the current list to copy public void CopyTo(InputBinding[] inputBindings, int index) { if (_innerBindingList != null) { _innerBindingList.CopyTo(inputBindings, index); } } #endregion Public #region internal internal InputBinding FindMatch(object targetElement, InputEventArgs inputEventArgs) { for (int i = Count - 1; i >= 0; i--) { InputBinding inputBinding = this[i]; if ((inputBinding.Command != null) && (inputBinding.Gesture != null) && inputBinding.Gesture.Matches(targetElement, inputEventArgs)) { return inputBinding; } } return null; } #endregion internal //------------------------------------------------------ // // Protected Methods // //------------------------------------------------------ //----------------------------------------------------- // // Private Methods // //------------------------------------------------------ //----------------------------------------------------- // // Private Fields // //----------------------------------------------------- #region Private Fields private System.Collections.Generic.List_innerBindingList; private bool _isReadOnly = false; #endregion Private Fields } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. //---------------------------------------------------------------------------- // // // Copyright (C) Microsoft Corporation. All rights reserved. // // // // Description: InputBindingCollection serves the purpose of Storing/Retrieving InputBindings // // See spec at : http://avalon/coreui/Specs/Commanding(new).mht // // // History: // 04/02/2004 : chandras - Created // //--------------------------------------------------------------------------- using System; using System.Collections; using System.Diagnostics; using System.Collections.Specialized; using System.Windows; using System.Windows.Input; using SR=MS.Internal.PresentationCore.SR; using SRID=MS.Internal.PresentationCore.SRID; namespace System.Windows.Input { ////// InputBindingCollection - Collection of InputBindings. /// Stores the InputBindings Sequentially in an System.Collections.Generic.List"InputBinding"a. /// Will be changed to generic List implementation once the /// parser supports generic collections. /// public sealed class InputBindingCollection : IList { //----------------------------------------------------- // // Constructors // //----------------------------------------------------- #region Constructors ////// Constructor /// public InputBindingCollection() { } ////// InputBindingCollection /// /// InputBinding array public InputBindingCollection(IList inputBindings) { if (inputBindings != null && inputBindings.Count > 0) { this.AddRange(inputBindings as ICollection); } } #endregion Constructors //------------------------------------------------------ // // Public Methods // //----------------------------------------------------- #region Public Methods #region Implementation of IList #region Implementation of ICollection ////// CopyTo - to copy the entire collection into an array /// /// generic object array /// void ICollection.CopyTo(System.Array array, int index) { if (_innerBindingList != null) { ((ICollection)_innerBindingList).CopyTo(array, index); } } #endregion Implementation of ICollection ////// IList.Contains /// /// key ///true - if found, false - otherwise bool IList.Contains(object key) { return this.Contains(key as InputBinding); } ////// IndexOf - returns the index of the item in the list /// /// item whose index is sought ///index of the item or -1 int IList.IndexOf(object value) { InputBinding inputBinding = value as InputBinding; return ((inputBinding != null) ? this.IndexOf(inputBinding) : -1); } ////// Insert /// /// /// void IList.Insert(int index, object value) { this.Insert(index, value as InputBinding); } ////// Add - appends the given inputbinding to the current list. /// /// InputBinding object to add int IList.Add(object inputBinding) { this.Add(inputBinding as InputBinding); return 0; // ICollection.Add no longer returns the indice } ////// Remove - removes the given inputbinding from the current list. /// /// InputBinding object to remove void IList.Remove(object inputBinding) { this.Remove(inputBinding as InputBinding); } ////// Indexing operator /// object IList.this[int index] { get { return this[index]; } set { InputBinding inputBinding = value as InputBinding; if (inputBinding == null) throw new NotSupportedException(SR.Get(SRID.CollectionOnlyAcceptsInputBindings)); this[index] = inputBinding; } } #endregion Implementation of IList ////// Indexing operator /// public InputBinding this[int index] { get { // disable PreSharp warning about throwing exceptions in getter; // this is allowed in an indexed property. (First disable C# // warning about unknown warning numbers.) #pragma warning disable 1634, 1691 #pragma warning disable 6503 if (_innerBindingList != null) { return _innerBindingList[index]; } else { throw new ArgumentOutOfRangeException("index"); } #pragma warning restore 6503 #pragma warning restore 1634, 1691 } set { if (_innerBindingList != null) { _innerBindingList[index] = value; } else { throw new ArgumentOutOfRangeException("index"); } } } ////// Add /// /// public int Add(InputBinding inputBinding) { if (inputBinding != null) { if (_innerBindingList == null) _innerBindingList = new System.Collections.Generic.List(1); _innerBindingList.Add(inputBinding); return 0; // ICollection.Add no longer returns the indice } else { throw new NotSupportedException(SR.Get(SRID.CollectionOnlyAcceptsInputBindings)); } } /// /// ICollection.IsSynchronized /// public bool IsSynchronized { get { if (_innerBindingList != null) return ((IList)_innerBindingList).IsSynchronized; return false; } } ////// IndexOf /// /// ///public int IndexOf(InputBinding value) { return (_innerBindingList != null) ? _innerBindingList.IndexOf(value) : -1; } /// /// Adds the elements of the given collection to the end of this list. If /// required, the capacity of the list is increased to twice the previous /// capacity or the new size, whichever is larger. /// /// collection to append public void AddRange(ICollection collection) { if (collection == null) { throw new ArgumentNullException("collection"); } if ( collection.Count > 0) { if (_innerBindingList == null) _innerBindingList = new System.Collections.Generic.List(collection.Count); IEnumerator collectionEnum = collection.GetEnumerator(); while(collectionEnum.MoveNext()) { InputBinding inputBinding = collectionEnum.Current as InputBinding; if (inputBinding != null) { _innerBindingList.Add(inputBinding); } else { throw new NotSupportedException(SR.Get(SRID.CollectionOnlyAcceptsInputBindings)); } } } } /// /// Insert at given index /// /// index at which to insert the given item /// inputBinding to insert public void Insert(int index, InputBinding inputBinding) { if (inputBinding == null) { throw new NotSupportedException(SR.Get(SRID.CollectionOnlyAcceptsInputBindings)); } if (_innerBindingList != null) { _innerBindingList.Insert(index, inputBinding); } } ////// Remove /// /// public void Remove(InputBinding inputBinding) { if (_innerBindingList != null && inputBinding != null) _innerBindingList.Remove(inputBinding as InputBinding); } ////// RemoveAt /// /// index at which the item needs to be removed public void RemoveAt(int index) { if (_innerBindingList != null) _innerBindingList.RemoveAt(index); } ////// IsFixedSize - if readonly - fixed, else false. /// public bool IsFixedSize { get { return IsReadOnly; } } ////// Count /// public int Count { get { return (_innerBindingList != null ? _innerBindingList.Count : 0); } } ////// ICollection.SyncRoot /// public object SyncRoot { get { return this; } } ////// Clears the Entire InputBindingCollection /// public void Clear() { if (_innerBindingList != null) { _innerBindingList.Clear(); _innerBindingList = null; } } #region Implementation of Enumerable ////// IEnumerable.GetEnumerator - For Enumeration purposes /// ///public IEnumerator GetEnumerator() { if (_innerBindingList != null) return _innerBindingList.GetEnumerator(); System.Collections.Generic.List list = new System.Collections.Generic.List (0); return list.GetEnumerator(); } #endregion Implementation of IEnumberable /// /// IList.IsReadOnly - Tells whether this is readonly Collection. /// public bool IsReadOnly { get { return _isReadOnly; } } ////// Contains /// /// key ///true - if found, false - otherwise public bool Contains(InputBinding key) { if (_innerBindingList != null && key != null) { return _innerBindingList.Contains(key); } return false; } ////// CopyTo - to copy the entire collection into an array /// /// type-safe InputBinding array /// start index in the current list to copy public void CopyTo(InputBinding[] inputBindings, int index) { if (_innerBindingList != null) { _innerBindingList.CopyTo(inputBindings, index); } } #endregion Public #region internal internal InputBinding FindMatch(object targetElement, InputEventArgs inputEventArgs) { for (int i = Count - 1; i >= 0; i--) { InputBinding inputBinding = this[i]; if ((inputBinding.Command != null) && (inputBinding.Gesture != null) && inputBinding.Gesture.Matches(targetElement, inputEventArgs)) { return inputBinding; } } return null; } #endregion internal //------------------------------------------------------ // // Protected Methods // //------------------------------------------------------ //----------------------------------------------------- // // Private Methods // //------------------------------------------------------ //----------------------------------------------------- // // Private Fields // //----------------------------------------------------- #region Private Fields private System.Collections.Generic.List_innerBindingList; private bool _isReadOnly = false; #endregion Private Fields } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- PageParser.cs
- DataGridViewLayoutData.cs
- LinqDataSourceUpdateEventArgs.cs
- XmlReturnWriter.cs
- APCustomTypeDescriptor.cs
- Substitution.cs
- InputLangChangeRequestEvent.cs
- SetterBaseCollection.cs
- SpellerStatusTable.cs
- COM2TypeInfoProcessor.cs
- InfoCardRSAPKCS1SignatureDeformatter.cs
- DataFieldConverter.cs
- PropertyConverter.cs
- DataGridViewTopLeftHeaderCell.cs
- DetailsViewInsertEventArgs.cs
- XmlResolver.cs
- WSMessageEncoding.cs
- StrongNameMembershipCondition.cs
- XPathBinder.cs
- basevalidator.cs
- ReadOnlyCollectionBase.cs
- SharedPersonalizationStateInfo.cs
- RuleInfoComparer.cs
- XmlValidatingReader.cs
- GetPageNumberCompletedEventArgs.cs
- NativeMethodsOther.cs
- SerialErrors.cs
- TrustLevelCollection.cs
- HScrollProperties.cs
- SafeBitVector32.cs
- FrameSecurityDescriptor.cs
- UnknownMessageReceivedEventArgs.cs
- GeneralTransform.cs
- SessionEndingCancelEventArgs.cs
- objectresult_tresulttype.cs
- PasswordDeriveBytes.cs
- RuleProcessor.cs
- NumberAction.cs
- TextTreeUndoUnit.cs
- CaseKeyBox.xaml.cs
- ListViewCommandEventArgs.cs
- DataReceivedEventArgs.cs
- EllipseGeometry.cs
- FileDialog.cs
- ContentDefinition.cs
- PngBitmapDecoder.cs
- LayoutTableCell.cs
- RtfToXamlLexer.cs
- SendMailErrorEventArgs.cs
- DbCommandDefinition.cs
- GlyphsSerializer.cs
- AbstractSvcMapFileLoader.cs
- GeneralTransform3D.cs
- ObjectMaterializedEventArgs.cs
- ListViewDeletedEventArgs.cs
- QuaternionValueSerializer.cs
- CrossAppDomainChannel.cs
- WizardPanelChangingEventArgs.cs
- IListConverters.cs
- DirectoryObjectSecurity.cs
- UInt32Storage.cs
- WebPartTransformer.cs
- DataRowCollection.cs
- SkinIDTypeConverter.cs
- ToolStripSplitStackLayout.cs
- addressfiltermode.cs
- ActivationWorker.cs
- PrefixQName.cs
- _CacheStreams.cs
- AnimationStorage.cs
- ExtendedPropertyCollection.cs
- TaskDesigner.cs
- DiscreteKeyFrames.cs
- GrammarBuilderRuleRef.cs
- ZipIOBlockManager.cs
- DataSvcMapFileSerializer.cs
- StyleHelper.cs
- WindowsContainer.cs
- GridViewColumnCollection.cs
- ImageSource.cs
- HostingEnvironment.cs
- BoundColumn.cs
- Group.cs
- SparseMemoryStream.cs
- ToolStripSeparator.cs
- WebPageTraceListener.cs
- TextParaClient.cs
- BinHexEncoder.cs
- IPPacketInformation.cs
- SqlDataSourceSelectingEventArgs.cs
- ProcessHostConfigUtils.cs
- ToolStripGripRenderEventArgs.cs
- WebServiceParameterData.cs
- ActivityExecutionFilter.cs
- XmlAnyElementAttribute.cs
- ExpanderAutomationPeer.cs
- EntityDesignerBuildProvider.cs
- ZoneMembershipCondition.cs
- ObjectDataSourceFilteringEventArgs.cs
- PropertyTabAttribute.cs