Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / wpf / src / Core / CSharp / System / Windows / ReverseInheritProperty.cs / 1 / ReverseInheritProperty.cs
using System;
using System.Collections;
using System.Windows.Media;
using System.Windows.Input;
using MS.Internal;
namespace System.Windows
{
internal abstract class ReverseInheritProperty
{
internal ReverseInheritProperty(
DependencyPropertyKey flagKey,
CoreFlags flagCache,
CoreFlags flagChanged)
{
FlagKey = flagKey;
FlagCache = flagCache;
FlagChanged = flagChanged;
}
internal abstract void FireNotifications(UIElement uie, ContentElement ce, UIElement3D uie3D, bool oldValue);
internal void OnOriginValueChanged(DependencyObject oldOrigin, DependencyObject newOrigin, ref DeferredElementTreeState oldTreeState)
{
DeferredElementTreeState treeStateLocalCopy = oldTreeState;
oldTreeState = null;
// Step #1
// Update the cache flags for all elements in the ancestry
// of the element that got turned off and record the changed nodes
if (oldOrigin != null)
{
SetCacheFlagInAncestry(oldOrigin, false, treeStateLocalCopy);
}
// Step #2
// Update the cache flags for all elements in the ancestry
// of the element that got turned on and record the changed nodes
if (newOrigin != null)
{
SetCacheFlagInAncestry(newOrigin, true, null);
}
// Step #3
// Fire value changed on elements in the ancestry of the element that got turned off.
if (oldOrigin != null)
{
FirePropertyChangeInAncestry(oldOrigin, true /* oldValue */, treeStateLocalCopy);
}
// Step #4
// Fire value changed on elements in the ancestry of the element that got turned on.
if (newOrigin != null)
{
FirePropertyChangeInAncestry(newOrigin, false /* oldValue */, null);
}
if (oldTreeState == null && treeStateLocalCopy != null)
{
// Now that we have applied the old tree state, throw it away.
treeStateLocalCopy.Clear();
oldTreeState = treeStateLocalCopy;
}
}
void SetCacheFlagInAncestry(DependencyObject element, bool newValue, DeferredElementTreeState treeState)
{
// If the cache flag value is undergoing change, record it and
// propagate the change to the ancestors.
if ((!newValue && IsFlagSet(element, FlagCache)) ||
(newValue && !IsFlagSet(element, FlagCache)))
{
SetFlag(element, FlagCache, newValue);
// NOTE: we toggle the changed flag instead of setting it so that that way common
// ancestors show resultant unchanged and do not receive any change notification.
SetFlag(element, FlagChanged, !IsFlagSet(element, FlagChanged));
// Check for block reverse inheritance flag, elements like popup want to set this.
{
UIElement uie = element as UIElement;
if (uie != null)
{
if (uie.BlockReverseInheritance())
{
return;
}
}
ContentElement ce = element as ContentElement;
if (ce != null)
{
if (ce.BlockReverseInheritance())
{
return;
}
}
UIElement3D ui3D = element as UIElement3D;
if (ui3D != null)
{
if (ui3D.BlockReverseInheritance())
{
return;
}
}
}
// Propagate the flag up the visual and logical trees. Note our
// minimal optimization check to avoid walking both the core
// and logical parents if they are the same.
{
DependencyObject coreParent = DeferredElementTreeState.GetInputElementParent(element, treeState);
DependencyObject logicalParent = DeferredElementTreeState.GetLogicalParent(element, treeState);
if (coreParent != null)
{
SetCacheFlagInAncestry(coreParent, newValue, treeState);
}
if (logicalParent != null && logicalParent != coreParent)
{
SetCacheFlagInAncestry(logicalParent, newValue, treeState);
}
}
}
}
void FirePropertyChangeInAncestry(DependencyObject element, bool oldValue, DeferredElementTreeState treeState)
{
// If the cache value on the owner has been changed fire changed event
if (IsFlagSet(element, FlagChanged))
{
SetFlag(element, FlagChanged, false);
if (oldValue)
{
element.ClearValue(FlagKey);
}
else
{
element.SetValue(FlagKey, true);
}
UIElement uie = element as UIElement;
ContentElement ce = (uie != null) ? null : element as ContentElement;
UIElement3D uie3D = (uie != null || ce != null) ? null : element as UIElement3D;
FireNotifications(uie, ce, uie3D, oldValue);
// Check for block reverse inheritance flag, elements like popup want to set this.
if (uie != null)
{
if (uie.BlockReverseInheritance())
{
return;
}
}
else if (ce != null)
{
if (ce.BlockReverseInheritance())
{
return;
}
}
else if (uie3D != null)
{
if (uie3D.BlockReverseInheritance())
{
return;
}
}
// Call FirePropertyChange up the visual and logical trees.
// Note our minimal optimization check to avoid walking both
// the core and logical parents if they are the same.
{
DependencyObject coreParent = DeferredElementTreeState.GetInputElementParent(element, treeState);
DependencyObject logicalParent = DeferredElementTreeState.GetLogicalParent(element, treeState);
if (coreParent != null)
{
FirePropertyChangeInAncestry(coreParent, oldValue, treeState);
}
if (logicalParent != null && logicalParent != coreParent)
{
FirePropertyChangeInAncestry(logicalParent, oldValue, treeState);
}
}
}
}
/////////////////////////////////////////////////////////////////////
void SetFlag(DependencyObject o, CoreFlags flag, bool value)
{
UIElement uie = o as UIElement;
ContentElement ce = (uie != null) ? null : o as ContentElement;
UIElement3D uie3D = (uie != null || ce != null) ? null : o as UIElement3D;
if (uie != null)
{
uie.WriteFlag(flag, value);
}
else if (ce != null)
{
ce.WriteFlag(flag, value);
}
else if (uie3D != null)
{
uie3D.WriteFlag(flag, value);
}
}
/////////////////////////////////////////////////////////////////////
bool IsFlagSet(DependencyObject o, CoreFlags flag)
{
UIElement uie = o as UIElement;
ContentElement ce = (uie != null) ? null : o as ContentElement;
UIElement3D uie3D = (uie != null || ce != null) ? null : o as UIElement3D;
if (uie != null)
{
return uie.ReadFlag(flag);
}
else if (ce != null)
{
return ce.ReadFlag(flag);
}
else if (uie3D != null)
{
return uie3D.ReadFlag(flag);
}
return false;
}
/////////////////////////////////////////////////////////////////////
internal DependencyPropertyKey FlagKey;
internal CoreFlags FlagCache, FlagChanged;
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
using System;
using System.Collections;
using System.Windows.Media;
using System.Windows.Input;
using MS.Internal;
namespace System.Windows
{
internal abstract class ReverseInheritProperty
{
internal ReverseInheritProperty(
DependencyPropertyKey flagKey,
CoreFlags flagCache,
CoreFlags flagChanged)
{
FlagKey = flagKey;
FlagCache = flagCache;
FlagChanged = flagChanged;
}
internal abstract void FireNotifications(UIElement uie, ContentElement ce, UIElement3D uie3D, bool oldValue);
internal void OnOriginValueChanged(DependencyObject oldOrigin, DependencyObject newOrigin, ref DeferredElementTreeState oldTreeState)
{
DeferredElementTreeState treeStateLocalCopy = oldTreeState;
oldTreeState = null;
// Step #1
// Update the cache flags for all elements in the ancestry
// of the element that got turned off and record the changed nodes
if (oldOrigin != null)
{
SetCacheFlagInAncestry(oldOrigin, false, treeStateLocalCopy);
}
// Step #2
// Update the cache flags for all elements in the ancestry
// of the element that got turned on and record the changed nodes
if (newOrigin != null)
{
SetCacheFlagInAncestry(newOrigin, true, null);
}
// Step #3
// Fire value changed on elements in the ancestry of the element that got turned off.
if (oldOrigin != null)
{
FirePropertyChangeInAncestry(oldOrigin, true /* oldValue */, treeStateLocalCopy);
}
// Step #4
// Fire value changed on elements in the ancestry of the element that got turned on.
if (newOrigin != null)
{
FirePropertyChangeInAncestry(newOrigin, false /* oldValue */, null);
}
if (oldTreeState == null && treeStateLocalCopy != null)
{
// Now that we have applied the old tree state, throw it away.
treeStateLocalCopy.Clear();
oldTreeState = treeStateLocalCopy;
}
}
void SetCacheFlagInAncestry(DependencyObject element, bool newValue, DeferredElementTreeState treeState)
{
// If the cache flag value is undergoing change, record it and
// propagate the change to the ancestors.
if ((!newValue && IsFlagSet(element, FlagCache)) ||
(newValue && !IsFlagSet(element, FlagCache)))
{
SetFlag(element, FlagCache, newValue);
// NOTE: we toggle the changed flag instead of setting it so that that way common
// ancestors show resultant unchanged and do not receive any change notification.
SetFlag(element, FlagChanged, !IsFlagSet(element, FlagChanged));
// Check for block reverse inheritance flag, elements like popup want to set this.
{
UIElement uie = element as UIElement;
if (uie != null)
{
if (uie.BlockReverseInheritance())
{
return;
}
}
ContentElement ce = element as ContentElement;
if (ce != null)
{
if (ce.BlockReverseInheritance())
{
return;
}
}
UIElement3D ui3D = element as UIElement3D;
if (ui3D != null)
{
if (ui3D.BlockReverseInheritance())
{
return;
}
}
}
// Propagate the flag up the visual and logical trees. Note our
// minimal optimization check to avoid walking both the core
// and logical parents if they are the same.
{
DependencyObject coreParent = DeferredElementTreeState.GetInputElementParent(element, treeState);
DependencyObject logicalParent = DeferredElementTreeState.GetLogicalParent(element, treeState);
if (coreParent != null)
{
SetCacheFlagInAncestry(coreParent, newValue, treeState);
}
if (logicalParent != null && logicalParent != coreParent)
{
SetCacheFlagInAncestry(logicalParent, newValue, treeState);
}
}
}
}
void FirePropertyChangeInAncestry(DependencyObject element, bool oldValue, DeferredElementTreeState treeState)
{
// If the cache value on the owner has been changed fire changed event
if (IsFlagSet(element, FlagChanged))
{
SetFlag(element, FlagChanged, false);
if (oldValue)
{
element.ClearValue(FlagKey);
}
else
{
element.SetValue(FlagKey, true);
}
UIElement uie = element as UIElement;
ContentElement ce = (uie != null) ? null : element as ContentElement;
UIElement3D uie3D = (uie != null || ce != null) ? null : element as UIElement3D;
FireNotifications(uie, ce, uie3D, oldValue);
// Check for block reverse inheritance flag, elements like popup want to set this.
if (uie != null)
{
if (uie.BlockReverseInheritance())
{
return;
}
}
else if (ce != null)
{
if (ce.BlockReverseInheritance())
{
return;
}
}
else if (uie3D != null)
{
if (uie3D.BlockReverseInheritance())
{
return;
}
}
// Call FirePropertyChange up the visual and logical trees.
// Note our minimal optimization check to avoid walking both
// the core and logical parents if they are the same.
{
DependencyObject coreParent = DeferredElementTreeState.GetInputElementParent(element, treeState);
DependencyObject logicalParent = DeferredElementTreeState.GetLogicalParent(element, treeState);
if (coreParent != null)
{
FirePropertyChangeInAncestry(coreParent, oldValue, treeState);
}
if (logicalParent != null && logicalParent != coreParent)
{
FirePropertyChangeInAncestry(logicalParent, oldValue, treeState);
}
}
}
}
/////////////////////////////////////////////////////////////////////
void SetFlag(DependencyObject o, CoreFlags flag, bool value)
{
UIElement uie = o as UIElement;
ContentElement ce = (uie != null) ? null : o as ContentElement;
UIElement3D uie3D = (uie != null || ce != null) ? null : o as UIElement3D;
if (uie != null)
{
uie.WriteFlag(flag, value);
}
else if (ce != null)
{
ce.WriteFlag(flag, value);
}
else if (uie3D != null)
{
uie3D.WriteFlag(flag, value);
}
}
/////////////////////////////////////////////////////////////////////
bool IsFlagSet(DependencyObject o, CoreFlags flag)
{
UIElement uie = o as UIElement;
ContentElement ce = (uie != null) ? null : o as ContentElement;
UIElement3D uie3D = (uie != null || ce != null) ? null : o as UIElement3D;
if (uie != null)
{
return uie.ReadFlag(flag);
}
else if (ce != null)
{
return ce.ReadFlag(flag);
}
else if (uie3D != null)
{
return uie3D.ReadFlag(flag);
}
return false;
}
/////////////////////////////////////////////////////////////////////
internal DependencyPropertyKey FlagKey;
internal CoreFlags FlagCache, FlagChanged;
}
}
// 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
- CLSCompliantAttribute.cs
- OdbcRowUpdatingEvent.cs
- ModelUIElement3D.cs
- WindowsStreamSecurityBindingElement.cs
- BlockCollection.cs
- XmlReturnWriter.cs
- Viewport2DVisual3D.cs
- EditingCommands.cs
- _ConnectionGroup.cs
- DecoderExceptionFallback.cs
- ScriptManagerProxy.cs
- UrlPropertyAttribute.cs
- StorageBasedPackageProperties.cs
- TimeSpanConverter.cs
- WindowsStatic.cs
- CollectionConverter.cs
- OutputCacheSettingsSection.cs
- AsyncResult.cs
- ProcessStartInfo.cs
- MethodResolver.cs
- WebPartVerb.cs
- MetroSerializationManager.cs
- WebBrowser.cs
- xamlnodes.cs
- RectangleHotSpot.cs
- CollectionBuilder.cs
- DeviceFilterEditorDialog.cs
- DataSourceExpression.cs
- DateTimeHelper.cs
- RawMouseInputReport.cs
- XPathNodeHelper.cs
- ArgumentNullException.cs
- ScriptManagerProxy.cs
- DbTransaction.cs
- DataListItemEventArgs.cs
- DynamicMetaObject.cs
- RuntimeArgumentHandle.cs
- PersonalizationProviderCollection.cs
- HttpServerVarsCollection.cs
- SkipQueryOptionExpression.cs
- Storyboard.cs
- UmAlQuraCalendar.cs
- KnownTypeAttribute.cs
- TextEditorTables.cs
- DataGridViewRowHeightInfoPushedEventArgs.cs
- SystemFonts.cs
- BindingSource.cs
- DtrList.cs
- BasicExpressionVisitor.cs
- ListBoxAutomationPeer.cs
- Int32CollectionValueSerializer.cs
- MediaScriptCommandRoutedEventArgs.cs
- SpecialFolderEnumConverter.cs
- KeyedCollection.cs
- ContextStaticAttribute.cs
- XmlWrappingReader.cs
- XmlLinkedNode.cs
- SmtpNegotiateAuthenticationModule.cs
- UserControlCodeDomTreeGenerator.cs
- TraceProvider.cs
- FixedSOMTableRow.cs
- InstanceKeyNotReadyException.cs
- SamlAdvice.cs
- _LocalDataStoreMgr.cs
- ContextMarshalException.cs
- SqlInternalConnection.cs
- DataObjectFieldAttribute.cs
- SignatureToken.cs
- SqlRowUpdatedEvent.cs
- DataGridViewToolTip.cs
- AsymmetricAlgorithm.cs
- DateTimeFormatInfoScanner.cs
- XmlNodeChangedEventArgs.cs
- TypedRowHandler.cs
- RawMouseInputReport.cs
- SqlDataSourceSelectingEventArgs.cs
- EntityKeyElement.cs
- oledbconnectionstring.cs
- HostedBindingBehavior.cs
- NamespaceTable.cs
- FormViewCommandEventArgs.cs
- PersonalizablePropertyEntry.cs
- Atom10FormatterFactory.cs
- DesignerLoader.cs
- PopOutPanel.cs
- ExtensionFile.cs
- XPathDocumentBuilder.cs
- RouteData.cs
- StylusPoint.cs
- WhitespaceSignificantCollectionAttribute.cs
- GridViewCommandEventArgs.cs
- ContractCodeDomInfo.cs
- RoleService.cs
- TemplatedMailWebEventProvider.cs
- TrackingServices.cs
- SqlLiftWhereClauses.cs
- WebResourceAttribute.cs
- ExpressionNormalizer.cs
- LambdaCompiler.ControlFlow.cs
- CallSiteHelpers.cs