Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / ndp / fx / src / Designer / WinForms / System / WinForms / Design / EventHandlerService.cs / 1 / EventHandlerService.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- /* */ namespace System.Windows.Forms.Design { using System.Diagnostics; using System; using System.Windows.Forms; ////// /// /// public sealed class EventHandlerService : IEventHandlerService { // We cache the last requested handler for speed. // private object lastHandler; private Type lastHandlerType; // The handler stack // private HandlerEntry handlerHead; // Our change event // private EventHandler changedEvent; private readonly Control focusWnd; ////// /// public EventHandlerService(Control focusWnd) { this.focusWnd = focusWnd; } ///[To be supplied.] ////// /// public event EventHandler EventHandlerChanged { add { changedEvent += value; } remove { changedEvent -= value; } } ///[To be supplied.] ////// /// public Control FocusWindow { get { return focusWnd; } } ///[To be supplied.] ////// /// public object GetHandler(Type handlerType) { if (handlerType == lastHandlerType) { return lastHandler; } for (HandlerEntry entry = handlerHead; entry != null; entry = entry.next) { if (entry.handler != null && handlerType.IsInstanceOfType(entry.handler)) { lastHandlerType = handlerType; lastHandler = entry.handler; return entry.handler; } } return null; } ////// Gets the currently active event handler of the specified type. ////// /// Fires an OnEventHandlerChanged event. /// private void OnEventHandlerChanged(EventArgs e) { if (changedEvent != null) { ((EventHandler)changedEvent)(this, e); } } ////// /// public void PopHandler(object handler) { for (HandlerEntry entry = handlerHead; entry != null; entry = entry.next) { if (entry.handler == handler) { handlerHead = entry.next; lastHandler = null; lastHandlerType = null; OnEventHandlerChanged(EventArgs.Empty); return; } } Debug.Assert(handler == null || handlerHead == null, "Failed to locate handler to remove from list."); } ////// Pops /// the given handler off of the stack. ////// /// public void PushHandler(object handler) { handlerHead = new HandlerEntry(handler, handlerHead); // Update the handlerType if the Handler pushed is the same type as the last one .... // This is true when SplitContainer is on the form and Edit Properties pushed another handler. lastHandlerType = handler.GetType(); lastHandler = handlerHead.handler; OnEventHandlerChanged(EventArgs.Empty); } ///Pushes a new event handler on the stack. ////// /// Contains a single node of our handler stack. We typically /// have very few handlers, and the handlers are long-living, so /// I just implemented this as a linked list. /// private sealed class HandlerEntry { public object handler; public HandlerEntry next; ////// /// Creates a new handler entry objet. /// public HandlerEntry(object handler, HandlerEntry next) { this.handler = handler; this.next = next; } } } } // 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
- WebReference.cs
- CaseInsensitiveHashCodeProvider.cs
- _KerberosClient.cs
- StrongNamePublicKeyBlob.cs
- EncryptedReference.cs
- SoapSchemaExporter.cs
- DocumentViewer.cs
- ContentFileHelper.cs
- UTF32Encoding.cs
- EdmItemError.cs
- ColorTranslator.cs
- XmlSchemaInferenceException.cs
- WizardPanelChangingEventArgs.cs
- HebrewNumber.cs
- ThreadPool.cs
- MergeFilterQuery.cs
- TextTreeRootTextBlock.cs
- WriteLine.cs
- regiisutil.cs
- NotifyIcon.cs
- TreeNode.cs
- StorageEntitySetMapping.cs
- PropertyEntry.cs
- SudsCommon.cs
- _NestedMultipleAsyncResult.cs
- FileDialogPermission.cs
- MenuCommand.cs
- StyleHelper.cs
- AnonymousIdentificationModule.cs
- AccessViolationException.cs
- CharacterMetrics.cs
- DisplayMemberTemplateSelector.cs
- DataGridColumnCollection.cs
- _ProxyRegBlob.cs
- EllipticalNodeOperations.cs
- TraceListeners.cs
- SourceItem.cs
- Expressions.cs
- ExpressionLexer.cs
- BookmarkOptionsHelper.cs
- EdmSchemaAttribute.cs
- BrowserTree.cs
- BufferModeSettings.cs
- StorageComplexPropertyMapping.cs
- DataDocumentXPathNavigator.cs
- SoapHeaders.cs
- TablePattern.cs
- IndexOutOfRangeException.cs
- CqlGenerator.cs
- mansign.cs
- StatusBarItem.cs
- BamlTreeUpdater.cs
- PerfCounterSection.cs
- Color.cs
- FunctionNode.cs
- OperationInvokerBehavior.cs
- _Rfc2616CacheValidators.cs
- MessageQueueKey.cs
- SqlConnection.cs
- TreePrinter.cs
- Menu.cs
- StylesEditorDialog.cs
- CngProvider.cs
- ProfileService.cs
- TabControl.cs
- TdsParameterSetter.cs
- WindowsRichEditRange.cs
- CompiledRegexRunner.cs
- CodeNamespaceImportCollection.cs
- Double.cs
- ValueExpressions.cs
- ActivityTypeResolver.xaml.cs
- Calendar.cs
- EnterpriseServicesHelper.cs
- URIFormatException.cs
- SimpleHandlerFactory.cs
- GeneralTransform3DTo2D.cs
- DrawingCollection.cs
- xdrvalidator.cs
- ItemCheckedEvent.cs
- DefaultAsyncDataDispatcher.cs
- SqlTransaction.cs
- Processor.cs
- CachedBitmap.cs
- UndirectedGraph.cs
- FormsAuthenticationTicket.cs
- OdbcStatementHandle.cs
- XmlDocument.cs
- CodeGen.cs
- DataPagerField.cs
- HttpModuleAction.cs
- FileUtil.cs
- Task.cs
- Point3DAnimationUsingKeyFrames.cs
- UIElement3D.cs
- _SpnDictionary.cs
- Rotation3D.cs
- GlobalItem.cs
- Point3DIndependentAnimationStorage.cs
- Aggregates.cs