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 / TextServicesCompartment.cs / 1 / TextServicesCompartment.cs
//----------------------------------------------------------------------------
//
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
//
// Description: Manages Text Services Compartment.
//
// History:
// 07/30/2003 : yutakas - Ported from .net tree.
//
//---------------------------------------------------------------------------
using System;
using System.Runtime.InteropServices;
using System.Windows.Threading;
using System.Security;
using System.Security.Permissions;
using System.Diagnostics;
using System.Collections;
using MS.Utility;
using MS.Win32;
using MS.Internal;
namespace System.Windows.Input
{
//-----------------------------------------------------
//
// TextServicesCompartment class
//
//-----------------------------------------------------
internal class TextServicesCompartment
{
//------------------------------------------------------
//
// Constructors
//
//-----------------------------------------------------
///
/// Critical - directly calls unmanaged code based on guid
///
[SecurityCritical]
internal TextServicesCompartment(Guid guid, UnsafeNativeMethods.ITfCompartmentMgr compartmentmgr)
{
_guid = guid;
_compartmentmgr = new SecurityCriticalData(compartmentmgr);
_cookie = UnsafeNativeMethods.TF_INVALID_COOKIE;
}
//------------------------------------------------------
//
// Public Methods
//
//------------------------------------------------------
#region Public Methods
#endregion Public Methods
//-----------------------------------------------------
//
// Public Operators
//
//------------------------------------------------------
//-----------------------------------------------------
//
// Public Properties
//
//-----------------------------------------------------
//-----------------------------------------------------
//
// Public Events
//
//------------------------------------------------------
//-----------------------------------------------------
//
// Protected Methods
//
//------------------------------------------------------
//------------------------------------------------------
//
// Internal Methods
//
//-----------------------------------------------------
#region Internal Methods
///
/// Advise the notify sink of the compartment update.
///
///
/// Critical - wires up multiple unmanaged objects together
///
[SecurityCritical]
internal void AdviseNotifySink(UnsafeNativeMethods.ITfCompartmentEventSink sink)
{
Debug.Assert(_cookie == UnsafeNativeMethods.TF_INVALID_COOKIE, "cookie is already set.");
UnsafeNativeMethods.ITfCompartment compartment = GetITfCompartment();
if (compartment == null)
return;
UnsafeNativeMethods.ITfSource source = compartment as UnsafeNativeMethods.ITfSource;
// workaround because I can't pass a ref to a readonly constant
Guid guid = UnsafeNativeMethods.IID_ITfCompartmentEventSink;
source.AdviseSink(ref guid, sink, out _cookie);
Marshal.ReleaseComObject(compartment);
Marshal.ReleaseComObject(source);
}
///
/// Unadvise the notify sink of the compartment update.
///
///
/// Critical - wires up multiple unmanaged objects together
///
[SecurityCritical]
internal void UnadviseNotifySink()
{
Debug.Assert(_cookie != UnsafeNativeMethods.TF_INVALID_COOKIE, "cookie is not set.");
UnsafeNativeMethods.ITfCompartment compartment = GetITfCompartment();
if (compartment == null)
return;
UnsafeNativeMethods.ITfSource source = compartment as UnsafeNativeMethods.ITfSource;
source.UnadviseSink(_cookie);
_cookie = UnsafeNativeMethods.TF_INVALID_COOKIE;
Marshal.ReleaseComObject(compartment);
Marshal.ReleaseComObject(source);
}
///
/// Retrieve ITfCompartment
///
///
/// Critical - returns critical resource
///
[SecurityCritical]
internal UnsafeNativeMethods.ITfCompartment GetITfCompartment()
{
UnsafeNativeMethods.ITfCompartment itfcompartment;
_compartmentmgr.Value.GetCompartment(ref _guid, out itfcompartment);
return itfcompartment;
}
#endregion Internal methods
//------------------------------------------------------
//
// Internal Properties
//
//-----------------------------------------------------
#region Internal Properties
///
/// Cast the compartment variant to bool.
///
internal bool BooleanValue
{
get
{
object obj = Value;
if (obj == null)
return false;
if ((int)obj != 0)
return true;
return false;
}
set
{
Value = value ? 1 : 0;
}
}
///
/// Cast the compartment variant to int.
///
internal int IntValue
{
get
{
object obj = Value;
if (obj == null)
return 0;
return (int)obj;
}
set
{
Value = value;
}
}
///
/// Get the compartment variant.
///
///
/// Critical - access unmanaged code
/// TreatAsSafe - returns "safe" variant based value from the store
///
internal object Value
{
[SecurityCritical, SecurityTreatAsSafe]
get
{
UnsafeNativeMethods.ITfCompartment compartment = GetITfCompartment();
if (compartment == null)
return null;
object obj;
compartment.GetValue(out obj);
Marshal.ReleaseComObject(compartment);
return obj;
}
[SecurityCritical, SecurityTreatAsSafe]
set
{
UnsafeNativeMethods.ITfCompartment compartment = GetITfCompartment();
if (compartment == null)
return;
compartment.SetValue(0 /* clientid */, ref value);
Marshal.ReleaseComObject(compartment);
}
}
#endregion Internal Properties
//-----------------------------------------------------
//
// Private Methods
//
//-----------------------------------------------------
//------------------------------------------------------
//
// Private Fields
//
//-----------------------------------------------------
#region Private Fields
///
/// Critical: UnsafeNativeMethods.ITfCompartmentMgr has methods with SuppressUnmanagedCodeSecurity.
///
private readonly SecurityCriticalData _compartmentmgr;
private Guid _guid;
private int _cookie;
#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: Manages Text Services Compartment.
//
// History:
// 07/30/2003 : yutakas - Ported from .net tree.
//
//---------------------------------------------------------------------------
using System;
using System.Runtime.InteropServices;
using System.Windows.Threading;
using System.Security;
using System.Security.Permissions;
using System.Diagnostics;
using System.Collections;
using MS.Utility;
using MS.Win32;
using MS.Internal;
namespace System.Windows.Input
{
//-----------------------------------------------------
//
// TextServicesCompartment class
//
//-----------------------------------------------------
internal class TextServicesCompartment
{
//------------------------------------------------------
//
// Constructors
//
//-----------------------------------------------------
///
/// Critical - directly calls unmanaged code based on guid
///
[SecurityCritical]
internal TextServicesCompartment(Guid guid, UnsafeNativeMethods.ITfCompartmentMgr compartmentmgr)
{
_guid = guid;
_compartmentmgr = new SecurityCriticalData(compartmentmgr);
_cookie = UnsafeNativeMethods.TF_INVALID_COOKIE;
}
//------------------------------------------------------
//
// Public Methods
//
//------------------------------------------------------
#region Public Methods
#endregion Public Methods
//-----------------------------------------------------
//
// Public Operators
//
//------------------------------------------------------
//-----------------------------------------------------
//
// Public Properties
//
//-----------------------------------------------------
//-----------------------------------------------------
//
// Public Events
//
//------------------------------------------------------
//-----------------------------------------------------
//
// Protected Methods
//
//------------------------------------------------------
//------------------------------------------------------
//
// Internal Methods
//
//-----------------------------------------------------
#region Internal Methods
///
/// Advise the notify sink of the compartment update.
///
///
/// Critical - wires up multiple unmanaged objects together
///
[SecurityCritical]
internal void AdviseNotifySink(UnsafeNativeMethods.ITfCompartmentEventSink sink)
{
Debug.Assert(_cookie == UnsafeNativeMethods.TF_INVALID_COOKIE, "cookie is already set.");
UnsafeNativeMethods.ITfCompartment compartment = GetITfCompartment();
if (compartment == null)
return;
UnsafeNativeMethods.ITfSource source = compartment as UnsafeNativeMethods.ITfSource;
// workaround because I can't pass a ref to a readonly constant
Guid guid = UnsafeNativeMethods.IID_ITfCompartmentEventSink;
source.AdviseSink(ref guid, sink, out _cookie);
Marshal.ReleaseComObject(compartment);
Marshal.ReleaseComObject(source);
}
///
/// Unadvise the notify sink of the compartment update.
///
///
/// Critical - wires up multiple unmanaged objects together
///
[SecurityCritical]
internal void UnadviseNotifySink()
{
Debug.Assert(_cookie != UnsafeNativeMethods.TF_INVALID_COOKIE, "cookie is not set.");
UnsafeNativeMethods.ITfCompartment compartment = GetITfCompartment();
if (compartment == null)
return;
UnsafeNativeMethods.ITfSource source = compartment as UnsafeNativeMethods.ITfSource;
source.UnadviseSink(_cookie);
_cookie = UnsafeNativeMethods.TF_INVALID_COOKIE;
Marshal.ReleaseComObject(compartment);
Marshal.ReleaseComObject(source);
}
///
/// Retrieve ITfCompartment
///
///
/// Critical - returns critical resource
///
[SecurityCritical]
internal UnsafeNativeMethods.ITfCompartment GetITfCompartment()
{
UnsafeNativeMethods.ITfCompartment itfcompartment;
_compartmentmgr.Value.GetCompartment(ref _guid, out itfcompartment);
return itfcompartment;
}
#endregion Internal methods
//------------------------------------------------------
//
// Internal Properties
//
//-----------------------------------------------------
#region Internal Properties
///
/// Cast the compartment variant to bool.
///
internal bool BooleanValue
{
get
{
object obj = Value;
if (obj == null)
return false;
if ((int)obj != 0)
return true;
return false;
}
set
{
Value = value ? 1 : 0;
}
}
///
/// Cast the compartment variant to int.
///
internal int IntValue
{
get
{
object obj = Value;
if (obj == null)
return 0;
return (int)obj;
}
set
{
Value = value;
}
}
///
/// Get the compartment variant.
///
///
/// Critical - access unmanaged code
/// TreatAsSafe - returns "safe" variant based value from the store
///
internal object Value
{
[SecurityCritical, SecurityTreatAsSafe]
get
{
UnsafeNativeMethods.ITfCompartment compartment = GetITfCompartment();
if (compartment == null)
return null;
object obj;
compartment.GetValue(out obj);
Marshal.ReleaseComObject(compartment);
return obj;
}
[SecurityCritical, SecurityTreatAsSafe]
set
{
UnsafeNativeMethods.ITfCompartment compartment = GetITfCompartment();
if (compartment == null)
return;
compartment.SetValue(0 /* clientid */, ref value);
Marshal.ReleaseComObject(compartment);
}
}
#endregion Internal Properties
//-----------------------------------------------------
//
// Private Methods
//
//-----------------------------------------------------
//------------------------------------------------------
//
// Private Fields
//
//-----------------------------------------------------
#region Private Fields
///
/// Critical: UnsafeNativeMethods.ITfCompartmentMgr has methods with SuppressUnmanagedCodeSecurity.
///
private readonly SecurityCriticalData _compartmentmgr;
private Guid _guid;
private int _cookie;
#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
- EncodingInfo.cs
- NCryptNative.cs
- TargetFrameworkAttribute.cs
- Section.cs
- XsltFunctions.cs
- UserControl.cs
- SqlConnection.cs
- ByteStreamMessage.cs
- SessionStateModule.cs
- ColorConverter.cs
- PropertyDescriptorCollection.cs
- AccessText.cs
- StylusButton.cs
- QueryOutputWriter.cs
- DnsEndpointIdentity.cs
- FtpWebResponse.cs
- XamlSerializationHelper.cs
- AuthenticationConfig.cs
- GeometryHitTestResult.cs
- Oid.cs
- ResourceReferenceExpressionConverter.cs
- XmlReflectionMember.cs
- DiscoveryDocumentSearchPattern.cs
- HandlerFactoryCache.cs
- TextElementCollection.cs
- DataGridViewColumnHeaderCell.cs
- StandardOleMarshalObject.cs
- ISAPIRuntime.cs
- SubMenuStyleCollection.cs
- ListBoxAutomationPeer.cs
- FixedSOMGroup.cs
- RangeValidator.cs
- WsdlBuildProvider.cs
- FixUp.cs
- WebPartMovingEventArgs.cs
- sqlser.cs
- DataGridViewAutoSizeModeEventArgs.cs
- NotCondition.cs
- AccessedThroughPropertyAttribute.cs
- ObfuscateAssemblyAttribute.cs
- PersonalizationStateInfo.cs
- DateTimeConstantAttribute.cs
- TypedColumnHandler.cs
- XmlNodeChangedEventManager.cs
- TypeNameHelper.cs
- StreamAsIStream.cs
- SafeNativeMethods.cs
- SocketInformation.cs
- WindowsTooltip.cs
- OutputCacheModule.cs
- UnsafeNetInfoNativeMethods.cs
- ScrollBar.cs
- FunctionImportMapping.cs
- ListViewSelectEventArgs.cs
- XamlToRtfWriter.cs
- RoutedEvent.cs
- CalendarAutoFormatDialog.cs
- ControlPropertyNameConverter.cs
- OpCodes.cs
- UTF32Encoding.cs
- Tool.cs
- SystemIcmpV6Statistics.cs
- VerticalConnector.xaml.cs
- DecimalKeyFrameCollection.cs
- CodeTypeOfExpression.cs
- odbcmetadatafactory.cs
- DispatcherExceptionFilterEventArgs.cs
- StrongTypingException.cs
- PartBasedPackageProperties.cs
- TypeLoadException.cs
- SQLResource.cs
- SqlConnectionManager.cs
- Int32.cs
- Verify.cs
- OdbcInfoMessageEvent.cs
- TemplateAction.cs
- ConfigurationCollectionAttribute.cs
- EventLogEntry.cs
- SHA1CryptoServiceProvider.cs
- PriorityQueue.cs
- CreateUserWizard.cs
- CodeSubDirectoriesCollection.cs
- CompilationSection.cs
- XmlSchemaFacet.cs
- SafeLocalMemHandle.cs
- LinqDataSourceContextData.cs
- CheckBox.cs
- ScrollBarRenderer.cs
- ForceCopyBuildProvider.cs
- CommandEventArgs.cs
- DataControlFieldCollection.cs
- XmlSchemaNotation.cs
- ACL.cs
- PointAnimationBase.cs
- ColorTransformHelper.cs
- lengthconverter.cs
- XPathParser.cs
- MemberMaps.cs
- DecimalFormatter.cs
- Operator.cs