Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / wpf / src / Core / CSharp / MS / Internal / TextFormatting / TextPenaltyModule.cs / 1 / TextPenaltyModule.cs
//------------------------------------------------------------------------
//
// Microsoft Windows Client Platform
// Copyright (C) Microsoft Corporation
//
// File: TextPenaltyModule.cs
//
// Contents: Critical handle wrapping unmanaged text penalty module for
// penalty calculation of optimal paragraph vis PTS direct access.
//
// Spec: http://team/sites/Avalon/Specs/Text%20Formatting%20API.doc
//
// Created: 4-4-2006 Worachai Chaoweeraprasit (Wchao)
//
//-----------------------------------------------------------------------
using System;
using System.Security;
using System.Windows.Media;
using System.Windows.Media.TextFormatting;
using System.Runtime.InteropServices;
using MS.Internal.PresentationCore;
using SR = MS.Internal.PresentationCore.SR;
using SRID = MS.Internal.PresentationCore.SRID;
namespace MS.Internal.TextFormatting
{
///
/// Critical handle wrapper of unmanaged text penalty module. This class
/// is used exclusively by Framework thru friend-access. It provides direct
/// access to the underlying dangerous handle to the unmanaged resource whose
/// lifetime is bound to the the underlying LS context.
///
[FriendAccessAllowed] // used by Framework
internal sealed class TextPenaltyModule : IDisposable
{
private SecurityCriticalDataForSet _ploPenaltyModule; // Pointer to LS penalty module
private bool _isDisposed;
///
/// This constructor is called by PInvoke when returning the critical handle
///
///
/// Critical - as this calls the setter of _ploPenaltyModule.
/// Safe - as it does not set the value arbitrarily from the value it receives from caller.
///
[SecurityCritical, SecurityTreatAsSafe]
internal TextPenaltyModule(SecurityCriticalDataForSet ploc)
{
IntPtr ploPenaltyModule;
LsErr lserr = UnsafeNativeMethods.LoAcquirePenaltyModule(ploc.Value, out ploPenaltyModule);
if (lserr != LsErr.None)
{
TextFormatterContext.ThrowExceptionFromLsError(SR.Get(SRID.AcquirePenaltyModuleFailure, lserr), lserr);
}
_ploPenaltyModule.Value = ploPenaltyModule;
}
///
/// Finalize penalty module
///
~TextPenaltyModule()
{
Dispose(false);
}
///
/// Explicitly clean up penalty module
///
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
///
/// Critical - as this calls method to dispose unmanaged penalty module.
/// Safe - as it does not arbitrarily set critical data.
///
[SecurityCritical, SecurityTreatAsSafe]
private void Dispose(bool disposing)
{
if (_ploPenaltyModule.Value != IntPtr.Zero)
{
UnsafeNativeMethods.LoDisposePenaltyModule(_ploPenaltyModule.Value);
_ploPenaltyModule.Value = IntPtr.Zero;
_isDisposed = true;
GC.KeepAlive(this);
}
}
///
/// This method should only be called by Framework to authorize direct access to
/// unsafe LS penalty module for exclusive use of PTS during optimal paragraph
/// penalty calculation.
///
///
/// Critical - as this returns pointer to unmanaged memory owned by LS.
///
[SecurityCritical]
internal IntPtr DangerousGetHandle()
{
if (_isDisposed)
{
throw new ObjectDisposedException(SR.Get(SRID.TextPenaltyModuleHasBeenDisposed));
}
IntPtr penaltyModuleInternalHandle;
LsErr lserr = UnsafeNativeMethods.LoGetPenaltyModuleInternalHandle(_ploPenaltyModule.Value, out penaltyModuleInternalHandle);
if (lserr != LsErr.None)
TextFormatterContext.ThrowExceptionFromLsError(SR.Get(SRID.GetPenaltyModuleHandleFailure, lserr), lserr);
GC.KeepAlive(this);
return penaltyModuleInternalHandle;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------------------
//
// Microsoft Windows Client Platform
// Copyright (C) Microsoft Corporation
//
// File: TextPenaltyModule.cs
//
// Contents: Critical handle wrapping unmanaged text penalty module for
// penalty calculation of optimal paragraph vis PTS direct access.
//
// Spec: http://team/sites/Avalon/Specs/Text%20Formatting%20API.doc
//
// Created: 4-4-2006 Worachai Chaoweeraprasit (Wchao)
//
//-----------------------------------------------------------------------
using System;
using System.Security;
using System.Windows.Media;
using System.Windows.Media.TextFormatting;
using System.Runtime.InteropServices;
using MS.Internal.PresentationCore;
using SR = MS.Internal.PresentationCore.SR;
using SRID = MS.Internal.PresentationCore.SRID;
namespace MS.Internal.TextFormatting
{
///
/// Critical handle wrapper of unmanaged text penalty module. This class
/// is used exclusively by Framework thru friend-access. It provides direct
/// access to the underlying dangerous handle to the unmanaged resource whose
/// lifetime is bound to the the underlying LS context.
///
[FriendAccessAllowed] // used by Framework
internal sealed class TextPenaltyModule : IDisposable
{
private SecurityCriticalDataForSet _ploPenaltyModule; // Pointer to LS penalty module
private bool _isDisposed;
///
/// This constructor is called by PInvoke when returning the critical handle
///
///
/// Critical - as this calls the setter of _ploPenaltyModule.
/// Safe - as it does not set the value arbitrarily from the value it receives from caller.
///
[SecurityCritical, SecurityTreatAsSafe]
internal TextPenaltyModule(SecurityCriticalDataForSet ploc)
{
IntPtr ploPenaltyModule;
LsErr lserr = UnsafeNativeMethods.LoAcquirePenaltyModule(ploc.Value, out ploPenaltyModule);
if (lserr != LsErr.None)
{
TextFormatterContext.ThrowExceptionFromLsError(SR.Get(SRID.AcquirePenaltyModuleFailure, lserr), lserr);
}
_ploPenaltyModule.Value = ploPenaltyModule;
}
///
/// Finalize penalty module
///
~TextPenaltyModule()
{
Dispose(false);
}
///
/// Explicitly clean up penalty module
///
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
///
/// Critical - as this calls method to dispose unmanaged penalty module.
/// Safe - as it does not arbitrarily set critical data.
///
[SecurityCritical, SecurityTreatAsSafe]
private void Dispose(bool disposing)
{
if (_ploPenaltyModule.Value != IntPtr.Zero)
{
UnsafeNativeMethods.LoDisposePenaltyModule(_ploPenaltyModule.Value);
_ploPenaltyModule.Value = IntPtr.Zero;
_isDisposed = true;
GC.KeepAlive(this);
}
}
///
/// This method should only be called by Framework to authorize direct access to
/// unsafe LS penalty module for exclusive use of PTS during optimal paragraph
/// penalty calculation.
///
///
/// Critical - as this returns pointer to unmanaged memory owned by LS.
///
[SecurityCritical]
internal IntPtr DangerousGetHandle()
{
if (_isDisposed)
{
throw new ObjectDisposedException(SR.Get(SRID.TextPenaltyModuleHasBeenDisposed));
}
IntPtr penaltyModuleInternalHandle;
LsErr lserr = UnsafeNativeMethods.LoGetPenaltyModuleInternalHandle(_ploPenaltyModule.Value, out penaltyModuleInternalHandle);
if (lserr != LsErr.None)
TextFormatterContext.ThrowExceptionFromLsError(SR.Get(SRID.GetPenaltyModuleHandleFailure, lserr), lserr);
GC.KeepAlive(this);
return penaltyModuleInternalHandle;
}
}
}
// 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
- ObjectItemConventionAssemblyLoader.cs
- FormattedTextSymbols.cs
- TableCell.cs
- SchemaCompiler.cs
- FunctionCommandText.cs
- Baml2006ReaderSettings.cs
- InputProviderSite.cs
- TimelineGroup.cs
- CommandDevice.cs
- BamlLocalizerErrorNotifyEventArgs.cs
- AnnotationStore.cs
- ExpressionValueEditor.cs
- CodeDelegateCreateExpression.cs
- TagPrefixCollection.cs
- ReadOnlyAttribute.cs
- SqlFunctionAttribute.cs
- CdpEqualityComparer.cs
- Codec.cs
- Viewport3DVisual.cs
- ImageSourceConverter.cs
- ImportContext.cs
- PropertyConverter.cs
- AlternationConverter.cs
- AssertSection.cs
- CellRelation.cs
- MulticastDelegate.cs
- AvTraceDetails.cs
- TranslateTransform.cs
- HtmlFormWrapper.cs
- QueryOutputWriter.cs
- SettingsPropertyIsReadOnlyException.cs
- VarRefManager.cs
- PageSetupDialog.cs
- AutomationEventArgs.cs
- XmlSchemaExternal.cs
- TrackingServices.cs
- Stroke2.cs
- MinimizableAttributeTypeConverter.cs
- Transform.cs
- FixedSOMGroup.cs
- XmlResolver.cs
- CalendarKeyboardHelper.cs
- RTTrackingProfile.cs
- DataGridViewComboBoxEditingControl.cs
- translator.cs
- EDesignUtil.cs
- SqlUtil.cs
- XmlCountingReader.cs
- SizeFConverter.cs
- Queue.cs
- BoundPropertyEntry.cs
- MethodImplAttribute.cs
- DataServiceQueryOfT.cs
- ToolStripGripRenderEventArgs.cs
- XamlDesignerSerializationManager.cs
- DockPattern.cs
- COM2EnumConverter.cs
- MimeBasePart.cs
- EventHandlerService.cs
- CriticalFinalizerObject.cs
- FixedTextView.cs
- BaseDataBoundControl.cs
- DBParameter.cs
- MarkupObject.cs
- TdsParserSessionPool.cs
- BitmapPalettes.cs
- SchemaMapping.cs
- RoleService.cs
- XmlLoader.cs
- TextEditorTyping.cs
- PropertyMapper.cs
- KeyValuePair.cs
- SmiEventSink.cs
- StrokeIntersection.cs
- XPathPatternParser.cs
- sitestring.cs
- FrameDimension.cs
- UserMapPath.cs
- ButtonChrome.cs
- DataGridPageChangedEventArgs.cs
- Span.cs
- ActiveXContainer.cs
- DesignerCommandAdapter.cs
- RowUpdatingEventArgs.cs
- ClientFormsAuthenticationMembershipProvider.cs
- ListSourceHelper.cs
- LineGeometry.cs
- ValidationSummaryDesigner.cs
- WebBrowserHelper.cs
- ContentPosition.cs
- ControlDesigner.cs
- TransformCollection.cs
- PropertyItem.cs
- Point4DValueSerializer.cs
- EditorZoneBase.cs
- FormsAuthenticationModule.cs
- EditableRegion.cs
- RawAppCommandInputReport.cs
- CookieHandler.cs
- DataGridViewCellCollection.cs