Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Framework / MS / Internal / PtsHost / MbpInfo.cs / 1305600 / MbpInfo.cs
//---------------------------------------------------------------------------- // // Copyright (C) Microsoft Corporation. All rights reserved. // // File: MbpInfo.cs // // Description: Provides paragraph level margin collapsing support. // //--------------------------------------------------------------------------- using System; using System.Windows; // DependencyObject using System.Windows.Documents; // Block using MS.Internal.Text; // TextDpi using System.Windows.Media; // Brush using MS.Internal.PtsHost.UnsafeNativeMethods; // Pts namespace MS.Internal.PtsHost { ////// Provides services for MBP handling. /// internal sealed class MbpInfo { ////// Get MbpInfo from DependencyObject. /// /// DependencyObject for which MBP properties are retrieved. internal static MbpInfo FromElement(DependencyObject o) { if (o is Block || o is AnchoredBlock || o is TableCell || o is ListItem) { MbpInfo mbp = new MbpInfo((TextElement)o); double lineHeight = DynamicPropertyReader.GetLineHeightValue(o); if (mbp.IsMarginAuto) { ResolveAutoMargin(mbp, o, lineHeight); } if (mbp.IsPaddingAuto) { ResolveAutoPadding(mbp, o, lineHeight); } return mbp; } return _empty; } ////// Mirrors margin /// internal void MirrorMargin() { ReverseFlowDirection(ref _margin); } ////// Mirrors border and padding /// internal void MirrorBP() { ReverseFlowDirection(ref _border); ReverseFlowDirection(ref _padding); } ////// Reverses flow direction for a given thickness /// private static void ReverseFlowDirection(ref Thickness thickness) { double temp = thickness.Left; thickness.Left = thickness.Right; thickness.Right = temp; } ////// Static constructor. /// static MbpInfo() { _empty = new MbpInfo(); } ////// Private constructor. /// private MbpInfo() { _margin = new Thickness(); _border = new Thickness(); _padding = new Thickness(); _borderBrush = new SolidColorBrush(); } ////// Constructor. /// /// Block for which MBP properties are retrieved. private MbpInfo(TextElement block) { _margin = (Thickness)block.GetValue(Block.MarginProperty); _border = (Thickness)block.GetValue(Block.BorderThicknessProperty); _padding = (Thickness)block.GetValue(Block.PaddingProperty); _borderBrush = (Brush)block.GetValue(Block.BorderBrushProperty); } ////// Resolve Auto values for Margin. /// private static void ResolveAutoMargin(MbpInfo mbp, DependencyObject o, double lineHeight) { Thickness defaultMargin; if (o is Paragraph) { DependencyObject parent = ((Paragraph)o).Parent; if (parent is ListItem || parent is TableCell || parent is AnchoredBlock) { defaultMargin = new Thickness(0); } else { defaultMargin = new Thickness(0, lineHeight, 0, lineHeight); } } else if (o is Table || o is List) { defaultMargin = new Thickness(0, lineHeight, 0, lineHeight); } else if (o is Figure || o is Floater) { defaultMargin = new Thickness(0.5 * lineHeight); } else { defaultMargin = new Thickness(0); } mbp.Margin = new Thickness( Double.IsNaN(mbp.Margin.Left) ? defaultMargin.Left : mbp.Margin.Left, Double.IsNaN(mbp.Margin.Top) ? defaultMargin.Top : mbp.Margin.Top, Double.IsNaN(mbp.Margin.Right) ? defaultMargin.Right : mbp.Margin.Right, Double.IsNaN(mbp.Margin.Bottom) ? defaultMargin.Bottom : mbp.Margin.Bottom); } ////// Resolve Auto values for Padding. /// private static void ResolveAutoPadding(MbpInfo mbp, DependencyObject o, double lineHeight) { Thickness defaultPadding; if (o is Figure || o is Floater) { defaultPadding = new Thickness(0.5 * lineHeight); } else if (o is List) { defaultPadding = ListMarkerSourceInfo.CalculatePadding((List)o, lineHeight); } else { defaultPadding = new Thickness(0); } mbp.Padding = new Thickness( Double.IsNaN(mbp.Padding.Left) ? defaultPadding.Left : mbp.Padding.Left, Double.IsNaN(mbp.Padding.Top) ? defaultPadding.Top : mbp.Padding.Top, Double.IsNaN(mbp.Padding.Right) ? defaultPadding.Right : mbp.Padding.Right, Double.IsNaN(mbp.Padding.Bottom) ? defaultPadding.Bottom : mbp.Padding.Bottom); } ////// Combined value of left Margin, Border and Padding. /// internal int MBPLeft { get { return TextDpi.ToTextDpi(_margin.Left) + TextDpi.ToTextDpi(_border.Left) + TextDpi.ToTextDpi(_padding.Left); } } ////// Combined value of right Margin, Border and Padding. /// internal int MBPRight { get { return TextDpi.ToTextDpi(_margin.Right) + TextDpi.ToTextDpi(_border.Right) + TextDpi.ToTextDpi(_padding.Right); } } ////// Combined value of top Margin, Border and Padding. /// internal int MBPTop { get { return TextDpi.ToTextDpi(_margin.Top) + TextDpi.ToTextDpi(_border.Top) + TextDpi.ToTextDpi(_padding.Top); } } ////// Combined value of top Margin, Border and Padding. /// internal int MBPBottom { get { return TextDpi.ToTextDpi(_margin.Bottom) + TextDpi.ToTextDpi(_border.Bottom) + TextDpi.ToTextDpi(_padding.Bottom); } } ////// Combined value of left Border and Padding. /// internal int BPLeft { get { return TextDpi.ToTextDpi(_border.Left) + TextDpi.ToTextDpi(_padding.Left); } } ////// Combined value of right Border and Padding. /// internal int BPRight { get { return TextDpi.ToTextDpi(_border.Right) + TextDpi.ToTextDpi(_padding.Right); } } ////// Combined value of top Border and Padding. /// internal int BPTop { get { return TextDpi.ToTextDpi(_border.Top) + TextDpi.ToTextDpi(_padding.Top); } } ////// Combined value of bottom Border and Padding. /// internal int BPBottom { get { return TextDpi.ToTextDpi(_border.Bottom) + TextDpi.ToTextDpi(_padding.Bottom); } } ////// Left Border /// internal int BorderLeft { get { return TextDpi.ToTextDpi(_border.Left); } } ////// Right Border /// internal int BorderRight { get { return TextDpi.ToTextDpi(_border.Right); } } ////// Top Border /// internal int BorderTop { get { return TextDpi.ToTextDpi(_border.Top); } } ////// Bottom Border /// internal int BorderBottom { get { return TextDpi.ToTextDpi(_border.Bottom); } } ////// Left margin. /// internal int MarginLeft { get { return TextDpi.ToTextDpi(_margin.Left); } } ////// Right margin. /// internal int MarginRight { get { return TextDpi.ToTextDpi(_margin.Right); } } ////// top margin. /// internal int MarginTop { get { return TextDpi.ToTextDpi(_margin.Top); } } ////// Bottom margin. /// internal int MarginBottom { get { return TextDpi.ToTextDpi(_margin.Bottom); } } ////// Margin thickness. /// internal Thickness Margin { get { return _margin; } set { _margin = value; } } ////// Border thickness. /// internal Thickness Border { get { return _border; } set { _border = value; } } internal Thickness Padding { get { return _padding; } set { _padding = value; } } ////// Border brush. /// internal Brush BorderBrush { get { return _borderBrush; } } ////// Whether any padding value is Auto. /// private bool IsPaddingAuto { get { return ( Double.IsNaN(_padding.Left) || Double.IsNaN(_padding.Right) || Double.IsNaN(_padding.Top) || Double.IsNaN(_padding.Bottom)); } } ////// Whether any margin value is Auto. /// private bool IsMarginAuto { get { return ( Double.IsNaN(_margin.Left) || Double.IsNaN(_margin.Right) || Double.IsNaN(_margin.Top) || Double.IsNaN(_margin.Bottom)); } } ////// Margin thickness. /// private Thickness _margin; ////// Border thickness. /// private Thickness _border; ////// Padding thickness. /// private Thickness _padding; ////// Border brush. /// private Brush _borderBrush; ////// Empty MBPInfo instance. /// private static MbpInfo _empty; } } // 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. // // File: MbpInfo.cs // // Description: Provides paragraph level margin collapsing support. // //--------------------------------------------------------------------------- using System; using System.Windows; // DependencyObject using System.Windows.Documents; // Block using MS.Internal.Text; // TextDpi using System.Windows.Media; // Brush using MS.Internal.PtsHost.UnsafeNativeMethods; // Pts namespace MS.Internal.PtsHost { ////// Provides services for MBP handling. /// internal sealed class MbpInfo { ////// Get MbpInfo from DependencyObject. /// /// DependencyObject for which MBP properties are retrieved. internal static MbpInfo FromElement(DependencyObject o) { if (o is Block || o is AnchoredBlock || o is TableCell || o is ListItem) { MbpInfo mbp = new MbpInfo((TextElement)o); double lineHeight = DynamicPropertyReader.GetLineHeightValue(o); if (mbp.IsMarginAuto) { ResolveAutoMargin(mbp, o, lineHeight); } if (mbp.IsPaddingAuto) { ResolveAutoPadding(mbp, o, lineHeight); } return mbp; } return _empty; } ////// Mirrors margin /// internal void MirrorMargin() { ReverseFlowDirection(ref _margin); } ////// Mirrors border and padding /// internal void MirrorBP() { ReverseFlowDirection(ref _border); ReverseFlowDirection(ref _padding); } ////// Reverses flow direction for a given thickness /// private static void ReverseFlowDirection(ref Thickness thickness) { double temp = thickness.Left; thickness.Left = thickness.Right; thickness.Right = temp; } ////// Static constructor. /// static MbpInfo() { _empty = new MbpInfo(); } ////// Private constructor. /// private MbpInfo() { _margin = new Thickness(); _border = new Thickness(); _padding = new Thickness(); _borderBrush = new SolidColorBrush(); } ////// Constructor. /// /// Block for which MBP properties are retrieved. private MbpInfo(TextElement block) { _margin = (Thickness)block.GetValue(Block.MarginProperty); _border = (Thickness)block.GetValue(Block.BorderThicknessProperty); _padding = (Thickness)block.GetValue(Block.PaddingProperty); _borderBrush = (Brush)block.GetValue(Block.BorderBrushProperty); } ////// Resolve Auto values for Margin. /// private static void ResolveAutoMargin(MbpInfo mbp, DependencyObject o, double lineHeight) { Thickness defaultMargin; if (o is Paragraph) { DependencyObject parent = ((Paragraph)o).Parent; if (parent is ListItem || parent is TableCell || parent is AnchoredBlock) { defaultMargin = new Thickness(0); } else { defaultMargin = new Thickness(0, lineHeight, 0, lineHeight); } } else if (o is Table || o is List) { defaultMargin = new Thickness(0, lineHeight, 0, lineHeight); } else if (o is Figure || o is Floater) { defaultMargin = new Thickness(0.5 * lineHeight); } else { defaultMargin = new Thickness(0); } mbp.Margin = new Thickness( Double.IsNaN(mbp.Margin.Left) ? defaultMargin.Left : mbp.Margin.Left, Double.IsNaN(mbp.Margin.Top) ? defaultMargin.Top : mbp.Margin.Top, Double.IsNaN(mbp.Margin.Right) ? defaultMargin.Right : mbp.Margin.Right, Double.IsNaN(mbp.Margin.Bottom) ? defaultMargin.Bottom : mbp.Margin.Bottom); } ////// Resolve Auto values for Padding. /// private static void ResolveAutoPadding(MbpInfo mbp, DependencyObject o, double lineHeight) { Thickness defaultPadding; if (o is Figure || o is Floater) { defaultPadding = new Thickness(0.5 * lineHeight); } else if (o is List) { defaultPadding = ListMarkerSourceInfo.CalculatePadding((List)o, lineHeight); } else { defaultPadding = new Thickness(0); } mbp.Padding = new Thickness( Double.IsNaN(mbp.Padding.Left) ? defaultPadding.Left : mbp.Padding.Left, Double.IsNaN(mbp.Padding.Top) ? defaultPadding.Top : mbp.Padding.Top, Double.IsNaN(mbp.Padding.Right) ? defaultPadding.Right : mbp.Padding.Right, Double.IsNaN(mbp.Padding.Bottom) ? defaultPadding.Bottom : mbp.Padding.Bottom); } ////// Combined value of left Margin, Border and Padding. /// internal int MBPLeft { get { return TextDpi.ToTextDpi(_margin.Left) + TextDpi.ToTextDpi(_border.Left) + TextDpi.ToTextDpi(_padding.Left); } } ////// Combined value of right Margin, Border and Padding. /// internal int MBPRight { get { return TextDpi.ToTextDpi(_margin.Right) + TextDpi.ToTextDpi(_border.Right) + TextDpi.ToTextDpi(_padding.Right); } } ////// Combined value of top Margin, Border and Padding. /// internal int MBPTop { get { return TextDpi.ToTextDpi(_margin.Top) + TextDpi.ToTextDpi(_border.Top) + TextDpi.ToTextDpi(_padding.Top); } } ////// Combined value of top Margin, Border and Padding. /// internal int MBPBottom { get { return TextDpi.ToTextDpi(_margin.Bottom) + TextDpi.ToTextDpi(_border.Bottom) + TextDpi.ToTextDpi(_padding.Bottom); } } ////// Combined value of left Border and Padding. /// internal int BPLeft { get { return TextDpi.ToTextDpi(_border.Left) + TextDpi.ToTextDpi(_padding.Left); } } ////// Combined value of right Border and Padding. /// internal int BPRight { get { return TextDpi.ToTextDpi(_border.Right) + TextDpi.ToTextDpi(_padding.Right); } } ////// Combined value of top Border and Padding. /// internal int BPTop { get { return TextDpi.ToTextDpi(_border.Top) + TextDpi.ToTextDpi(_padding.Top); } } ////// Combined value of bottom Border and Padding. /// internal int BPBottom { get { return TextDpi.ToTextDpi(_border.Bottom) + TextDpi.ToTextDpi(_padding.Bottom); } } ////// Left Border /// internal int BorderLeft { get { return TextDpi.ToTextDpi(_border.Left); } } ////// Right Border /// internal int BorderRight { get { return TextDpi.ToTextDpi(_border.Right); } } ////// Top Border /// internal int BorderTop { get { return TextDpi.ToTextDpi(_border.Top); } } ////// Bottom Border /// internal int BorderBottom { get { return TextDpi.ToTextDpi(_border.Bottom); } } ////// Left margin. /// internal int MarginLeft { get { return TextDpi.ToTextDpi(_margin.Left); } } ////// Right margin. /// internal int MarginRight { get { return TextDpi.ToTextDpi(_margin.Right); } } ////// top margin. /// internal int MarginTop { get { return TextDpi.ToTextDpi(_margin.Top); } } ////// Bottom margin. /// internal int MarginBottom { get { return TextDpi.ToTextDpi(_margin.Bottom); } } ////// Margin thickness. /// internal Thickness Margin { get { return _margin; } set { _margin = value; } } ////// Border thickness. /// internal Thickness Border { get { return _border; } set { _border = value; } } internal Thickness Padding { get { return _padding; } set { _padding = value; } } ////// Border brush. /// internal Brush BorderBrush { get { return _borderBrush; } } ////// Whether any padding value is Auto. /// private bool IsPaddingAuto { get { return ( Double.IsNaN(_padding.Left) || Double.IsNaN(_padding.Right) || Double.IsNaN(_padding.Top) || Double.IsNaN(_padding.Bottom)); } } ////// Whether any margin value is Auto. /// private bool IsMarginAuto { get { return ( Double.IsNaN(_margin.Left) || Double.IsNaN(_margin.Right) || Double.IsNaN(_margin.Top) || Double.IsNaN(_margin.Bottom)); } } ////// Margin thickness. /// private Thickness _margin; ////// Border thickness. /// private Thickness _border; ////// Padding thickness. /// private Thickness _padding; ////// Border brush. /// private Brush _borderBrush; ////// Empty MBPInfo instance. /// private static MbpInfo _empty; } } // 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
- ToolStripItemDataObject.cs
- _OverlappedAsyncResult.cs
- MeasurementDCInfo.cs
- DataGridViewLinkColumn.cs
- ProcessHost.cs
- WorkflowApplicationCompletedException.cs
- AutomationElementIdentifiers.cs
- UTF32Encoding.cs
- DocumentPage.cs
- OracleTransaction.cs
- JsonReaderWriterFactory.cs
- XmlLanguage.cs
- ExpressionBuilder.cs
- WebChannelFactory.cs
- InteropBitmapSource.cs
- clipboard.cs
- SamlAuthorizationDecisionClaimResource.cs
- ToolStripItemGlyph.cs
- GridItemCollection.cs
- ProcessInfo.cs
- RegexWorker.cs
- XmlValidatingReaderImpl.cs
- AnnotationAdorner.cs
- ClientCultureInfo.cs
- LicFileLicenseProvider.cs
- BoundColumn.cs
- Grammar.cs
- ValidationErrorCollection.cs
- MemberExpression.cs
- ElementUtil.cs
- SupportsPreviewControlAttribute.cs
- SqlConnectionStringBuilder.cs
- ViewStateException.cs
- DiscoveryEndpoint.cs
- Paragraph.cs
- DecimalStorage.cs
- BackStopAuthenticationModule.cs
- ParsedAttributeCollection.cs
- FormatterServicesNoSerializableCheck.cs
- ClientTargetCollection.cs
- figurelength.cs
- XmlNamespaceManager.cs
- _ShellExpression.cs
- TrackingConditionCollection.cs
- _NegoStream.cs
- DebuggerAttributes.cs
- ExpanderAutomationPeer.cs
- EventToken.cs
- SiteMapPath.cs
- XPathChildIterator.cs
- MimePart.cs
- UiaCoreProviderApi.cs
- FormsAuthenticationConfiguration.cs
- OdbcInfoMessageEvent.cs
- EndpointInfo.cs
- HwndTarget.cs
- DynamicResourceExtensionConverter.cs
- MatrixValueSerializer.cs
- CallTemplateAction.cs
- WebPartManager.cs
- DataColumnCollection.cs
- CodeEventReferenceExpression.cs
- TreeViewHitTestInfo.cs
- SplitterEvent.cs
- Vector3DIndependentAnimationStorage.cs
- SafeNativeMethods.cs
- ComMethodElementCollection.cs
- SslStream.cs
- PaginationProgressEventArgs.cs
- SmiGettersStream.cs
- TextRunProperties.cs
- ImmutableObjectAttribute.cs
- GroupBox.cs
- IIS7WorkerRequest.cs
- linebase.cs
- StorageConditionPropertyMapping.cs
- TargetControlTypeCache.cs
- XamlStream.cs
- CultureMapper.cs
- _ConnectOverlappedAsyncResult.cs
- NavigationProgressEventArgs.cs
- HijriCalendar.cs
- TextHidden.cs
- TextShapeableCharacters.cs
- DigitalSignatureProvider.cs
- DataKey.cs
- PageParser.cs
- ReadOnlyDictionary.cs
- WindowsTitleBar.cs
- VisualStateManager.cs
- WsatConfiguration.cs
- WebZone.cs
- SafeNativeMethodsOther.cs
- RenderOptions.cs
- WebServiceFault.cs
- ThicknessAnimationBase.cs
- RowParagraph.cs
- EventMappingSettings.cs
- DirectoryObjectSecurity.cs
- DocumentPaginator.cs