Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Core / CSharp / System / Windows / Input / TextServicesCompartmentContext.cs / 1305600 / TextServicesCompartmentContext.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.Internal;
using MS.Utility;
using MS.Win32;
namespace System.Windows.Input
{
//-----------------------------------------------------
//
// TextServicesCompartmentContext class
//
//-----------------------------------------------------
internal class TextServicesCompartmentContext
{
//------------------------------------------------------
//
// Constructors
//
//-----------------------------------------------------
///
/// private constructer to avoid from creating instance outside.
///
private TextServicesCompartmentContext()
{
}
//------------------------------------------------------
//
// Internal Methods
//
//------------------------------------------------------
#region Internal Methods
///
/// Get the compartment of the given input method state.
///
///
/// Critical - retrieves message pump/input manager wrapper class
/// TreatAsSafe - returns safe wrapper for property request
///
[SecurityCritical, SecurityTreatAsSafe]
internal TextServicesCompartment GetCompartment(InputMethodStateType statetype)
{
for (int i = 0; i < InputMethodEventTypeInfo.InfoList.Length; i++)
{
InputMethodEventTypeInfo iminfo = InputMethodEventTypeInfo.InfoList[i];
if (iminfo.Type == statetype)
{
if (iminfo.Scope == CompartmentScope.Thread)
return GetThreadCompartment(iminfo.Guid);
else if (iminfo.Scope == CompartmentScope.Global)
return GetGlobalCompartment(iminfo.Guid);
}
}
return null;
}
///
/// Get the thread compartment of the Guid.
///
///
/// Critical - manipulates input manager/message pump
///
[SecurityCritical]
internal TextServicesCompartment GetThreadCompartment(Guid guid)
{
// No TextServices are installed so that the compartment won't work.
if (!TextServicesLoader.ServicesInstalled ||
TextServicesContext.DispatcherCurrent == null)
return null;
UnsafeNativeMethods.ITfThreadMgr threadmgr = TextServicesContext.DispatcherCurrent.ThreadManager;
if (threadmgr == null)
return null;
if (_compartmentTable == null)
_compartmentTable = new Hashtable();
TextServicesCompartment compartment;
compartment = _compartmentTable[guid] as TextServicesCompartment;
if (compartment == null)
{
compartment = new TextServicesCompartment(guid,
threadmgr as UnsafeNativeMethods.ITfCompartmentMgr);
_compartmentTable[guid] = compartment;
}
return compartment;
}
///
/// Get the global compartment of the Guid.
///
///
/// Critical - access input manager directly
///
[SecurityCritical]
internal TextServicesCompartment GetGlobalCompartment(Guid guid)
{
// No TextServices are installed so that the compartment won't work.
if (!TextServicesLoader.ServicesInstalled ||
TextServicesContext.DispatcherCurrent == null)
return null;
if (_globalcompartmentTable == null)
_globalcompartmentTable = new Hashtable();
if (_globalcompartmentmanager == null)
{
UnsafeNativeMethods.ITfThreadMgr threadmgr = TextServicesContext.DispatcherCurrent.ThreadManager;
if (threadmgr == null)
return null;
threadmgr.GetGlobalCompartment(out _globalcompartmentmanager);
}
TextServicesCompartment compartment = null;
compartment = _globalcompartmentTable[guid] as TextServicesCompartment;
if (compartment == null)
{
compartment = new TextServicesCompartment(guid, _globalcompartmentmanager);
_globalcompartmentTable[guid] = compartment;
}
return compartment;
}
#endregion Internal Methods
//-----------------------------------------------------
//
// Internal Properties
//
//------------------------------------------------------
///
/// Create and get thread local compartment context.
///
internal static TextServicesCompartmentContext Current
{
get
{
// TextServicesCompartmentContext for the current Dispatcher is stored in InputMethod of
// the current Dispatcher.
if (InputMethod.Current.TextServicesCompartmentContext == null)
InputMethod.Current.TextServicesCompartmentContext = new TextServicesCompartmentContext();
return InputMethod.Current.TextServicesCompartmentContext;
}
}
//-----------------------------------------------------
//
// Private Fields
//
//-----------------------------------------------------
// cache of ITfCompartments
private Hashtable _compartmentTable;
private Hashtable _globalcompartmentTable;
// cache of the global compartment manager
private UnsafeNativeMethods.ITfCompartmentMgr _globalcompartmentmanager;
}
}
// 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.Internal;
using MS.Utility;
using MS.Win32;
namespace System.Windows.Input
{
//-----------------------------------------------------
//
// TextServicesCompartmentContext class
//
//-----------------------------------------------------
internal class TextServicesCompartmentContext
{
//------------------------------------------------------
//
// Constructors
//
//-----------------------------------------------------
///
/// private constructer to avoid from creating instance outside.
///
private TextServicesCompartmentContext()
{
}
//------------------------------------------------------
//
// Internal Methods
//
//------------------------------------------------------
#region Internal Methods
///
/// Get the compartment of the given input method state.
///
///
/// Critical - retrieves message pump/input manager wrapper class
/// TreatAsSafe - returns safe wrapper for property request
///
[SecurityCritical, SecurityTreatAsSafe]
internal TextServicesCompartment GetCompartment(InputMethodStateType statetype)
{
for (int i = 0; i < InputMethodEventTypeInfo.InfoList.Length; i++)
{
InputMethodEventTypeInfo iminfo = InputMethodEventTypeInfo.InfoList[i];
if (iminfo.Type == statetype)
{
if (iminfo.Scope == CompartmentScope.Thread)
return GetThreadCompartment(iminfo.Guid);
else if (iminfo.Scope == CompartmentScope.Global)
return GetGlobalCompartment(iminfo.Guid);
}
}
return null;
}
///
/// Get the thread compartment of the Guid.
///
///
/// Critical - manipulates input manager/message pump
///
[SecurityCritical]
internal TextServicesCompartment GetThreadCompartment(Guid guid)
{
// No TextServices are installed so that the compartment won't work.
if (!TextServicesLoader.ServicesInstalled ||
TextServicesContext.DispatcherCurrent == null)
return null;
UnsafeNativeMethods.ITfThreadMgr threadmgr = TextServicesContext.DispatcherCurrent.ThreadManager;
if (threadmgr == null)
return null;
if (_compartmentTable == null)
_compartmentTable = new Hashtable();
TextServicesCompartment compartment;
compartment = _compartmentTable[guid] as TextServicesCompartment;
if (compartment == null)
{
compartment = new TextServicesCompartment(guid,
threadmgr as UnsafeNativeMethods.ITfCompartmentMgr);
_compartmentTable[guid] = compartment;
}
return compartment;
}
///
/// Get the global compartment of the Guid.
///
///
/// Critical - access input manager directly
///
[SecurityCritical]
internal TextServicesCompartment GetGlobalCompartment(Guid guid)
{
// No TextServices are installed so that the compartment won't work.
if (!TextServicesLoader.ServicesInstalled ||
TextServicesContext.DispatcherCurrent == null)
return null;
if (_globalcompartmentTable == null)
_globalcompartmentTable = new Hashtable();
if (_globalcompartmentmanager == null)
{
UnsafeNativeMethods.ITfThreadMgr threadmgr = TextServicesContext.DispatcherCurrent.ThreadManager;
if (threadmgr == null)
return null;
threadmgr.GetGlobalCompartment(out _globalcompartmentmanager);
}
TextServicesCompartment compartment = null;
compartment = _globalcompartmentTable[guid] as TextServicesCompartment;
if (compartment == null)
{
compartment = new TextServicesCompartment(guid, _globalcompartmentmanager);
_globalcompartmentTable[guid] = compartment;
}
return compartment;
}
#endregion Internal Methods
//-----------------------------------------------------
//
// Internal Properties
//
//------------------------------------------------------
///
/// Create and get thread local compartment context.
///
internal static TextServicesCompartmentContext Current
{
get
{
// TextServicesCompartmentContext for the current Dispatcher is stored in InputMethod of
// the current Dispatcher.
if (InputMethod.Current.TextServicesCompartmentContext == null)
InputMethod.Current.TextServicesCompartmentContext = new TextServicesCompartmentContext();
return InputMethod.Current.TextServicesCompartmentContext;
}
}
//-----------------------------------------------------
//
// Private Fields
//
//-----------------------------------------------------
// cache of ITfCompartments
private Hashtable _compartmentTable;
private Hashtable _globalcompartmentTable;
// cache of the global compartment manager
private UnsafeNativeMethods.ITfCompartmentMgr _globalcompartmentmanager;
}
}
// 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
- ToolStripGripRenderEventArgs.cs
- SvcMapFileLoader.cs
- AuthenticationConfig.cs
- VectorConverter.cs
- DeclarationUpdate.cs
- AggregateNode.cs
- HttpCapabilitiesSectionHandler.cs
- SortedList.cs
- ToolStripTextBox.cs
- GridView.cs
- HtmlTableRow.cs
- IndentTextWriter.cs
- OutKeywords.cs
- Translator.cs
- XPathBinder.cs
- SafeThemeHandle.cs
- NativeMethods.cs
- InsufficientMemoryException.cs
- ColumnWidthChangingEvent.cs
- QueryCacheKey.cs
- RouteParser.cs
- BindingMemberInfo.cs
- WasEndpointConfigContainer.cs
- ClassicBorderDecorator.cs
- DataObjectPastingEventArgs.cs
- Cell.cs
- NameSpaceEvent.cs
- XPathConvert.cs
- Table.cs
- CorePropertiesFilter.cs
- SqlParameterizer.cs
- CompilationLock.cs
- ButtonPopupAdapter.cs
- SamlNameIdentifierClaimResource.cs
- BorderSidesEditor.cs
- CollectionViewGroup.cs
- ServiceDescriptionSerializer.cs
- TypedRowHandler.cs
- ParenthesizePropertyNameAttribute.cs
- ThreadStartException.cs
- DropShadowEffect.cs
- DataBindingCollection.cs
- KeyValuePair.cs
- ToolStripRenderer.cs
- GenericAuthenticationEventArgs.cs
- ObjectStateEntryDbUpdatableDataRecord.cs
- Material.cs
- PasswordBoxAutomationPeer.cs
- ItemType.cs
- Variable.cs
- LambdaCompiler.cs
- ExistsInCollection.cs
- Size3DConverter.cs
- WebResourceUtil.cs
- ChannelServices.cs
- PackWebResponse.cs
- PagerStyle.cs
- cookie.cs
- RadioButtonList.cs
- DataGridViewLinkColumn.cs
- HotCommands.cs
- FlowLayout.cs
- WindowsSysHeader.cs
- ParallelEnumerableWrapper.cs
- ReadOnlyDataSource.cs
- NoResizeHandleGlyph.cs
- CodeDelegateInvokeExpression.cs
- WaitHandle.cs
- AppendHelper.cs
- ScriptingRoleServiceSection.cs
- ExpressionQuoter.cs
- DataBindingList.cs
- UIHelper.cs
- SiteMapSection.cs
- DictionaryItemsCollection.cs
- GenericUriParser.cs
- NamedPipeProcessProtocolHandler.cs
- TimeoutValidationAttribute.cs
- SHA384.cs
- ValidatorCompatibilityHelper.cs
- SubtreeProcessor.cs
- DataGridViewCellStyleConverter.cs
- SiteMap.cs
- PropertyBuilder.cs
- XmlnsDefinitionAttribute.cs
- ListManagerBindingsCollection.cs
- ParameterBuilder.cs
- SubpageParagraph.cs
- DependencyObjectType.cs
- Win32Exception.cs
- KernelTypeValidation.cs
- OleDbInfoMessageEvent.cs
- WebFormsRootDesigner.cs
- WebPartConnectionsConnectVerb.cs
- SystemIcmpV4Statistics.cs
- HwndTarget.cs
- printdlgexmarshaler.cs
- CleanUpVirtualizedItemEventArgs.cs
- VarRemapper.cs
- SetterBaseCollection.cs