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 / InputLanguageSource.cs / 1 / InputLanguageSource.cs
//----------------------------------------------------------------------------
//
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
//
//
// Description: The source of the input language of the thread.
//
// History:
// 07/30/2003 : yutakas - ported from dotnet tree.
//
//---------------------------------------------------------------------------
using System.Security;
using System.Security.Permissions;
using System.Collections;
using System.Globalization;
using System.Windows.Threading;
using System.Windows.Input;
using System.Windows.Media;
using System.Runtime.InteropServices;
using System.Diagnostics;
using MS.Win32;
using MS.Utility;
namespace System.Windows.Input
{
//-----------------------------------------------------
//
// InputLanguageSource class
//
//-----------------------------------------------------
///
/// This is an internal. The source for input languages.
///
internal sealed class InputLanguageSource : IInputLanguageSource, IDisposable
{
//------------------------------------------------------
//
// Constructors
//
//-----------------------------------------------------
///
/// This is an internal. The source for input languages.
///
internal InputLanguageSource(InputLanguageManager inputlanguagemanager)
{
_inputlanguagemanager = inputlanguagemanager;
// initialize the current input language.
_langid = (short)NativeMethods.IntPtrToInt32(SafeNativeMethods.GetKeyboardLayout(0));
// store the dispatcher thread id. This will be used to call GetKeyboardLayout() from
// other thread.
_dispatcherThreadId = SafeNativeMethods.GetCurrentThreadId();
// Register source
_inputlanguagemanager.RegisterInputLanguageSource(this);
}
//------------------------------------------------------
//
// Public Methods
//
//------------------------------------------------------
#region Public Methods
///
/// Dispose method.
///
public void Dispose()
{
if (_ipp != null)
Uninitialize();
}
///
/// IIInputLanguageSource.Initialize()
/// This creates ITfInputProcessorProfile object and advice sink.
///
public void Initialize()
{
EnsureInputProcessorProfile();
}
///
/// IIInputLanguageSource.Uninitialize()
/// This releases ITfInputProcessorProfile object and unadvice sink.
///
public void Uninitialize()
{
if (_ipp != null)
{
_ipp.Uninitialize();
_ipp = null;
}
}
#endregion Public Methods
//-----------------------------------------------------
//
// Public Properties
//
//------------------------------------------------------
///
/// returns the current input language of this win32 thread.
///
public CultureInfo CurrentInputLanguage
{
get
{
return new CultureInfo(_CurrentInputLanguage);
}
set
{
_CurrentInputLanguage = (short)value.LCID;
}
}
///
/// returns the list of the available input languages of this win32 thread.
///
public IEnumerable InputLanguageList
{
get
{
EnsureInputProcessorProfile();
if (_ipp == null)
{
ArrayList al = new ArrayList();
al.Add(CurrentInputLanguage);
return al;
}
return _ipp.InputLanguageList;
}
}
//-----------------------------------------------------
//
// Internal Methods
//
//-----------------------------------------------------
///
/// The input language change call back from the sink.
///
internal bool OnLanguageChange(short langid)
{
if (_langid != langid)
{
// Call InputLanguageManager if its current source is this.
if (InputLanguageManager.Current.Source == this)
{
return InputLanguageManager.Current.ReportInputLanguageChanging(new CultureInfo(langid), new CultureInfo(_langid));
}
}
return true;
}
///
/// The input language changed call back from the sink.
///
internal void OnLanguageChanged()
{
short langid = _CurrentInputLanguage;
if (_langid != langid)
{
short prevlangid = _langid;
_langid = langid;
// Call InputLanguageManager if its current source is this.
if (InputLanguageManager.Current.Source == this)
{
InputLanguageManager.Current.ReportInputLanguageChanged(new CultureInfo(langid), new CultureInfo(prevlangid));
}
}
}
//-----------------------------------------------------
//
// Private Method
//
//------------------------------------------------------
///
/// This creates ITfInputProcessorProfile object and advice sink.
///
///
/// Critical - calls unmanaged code (initializing input)
/// TreatAsSafe - ok to call any number of times
///
[SecurityCritical, SecurityTreatAsSafe]
private void EnsureInputProcessorProfile()
{
// _ipp has been initialzied. Don't do this again.
if (_ipp != null)
return;
// We don't need to initialize _ipp if there is onlyone keyboard layout.
// Only one input language is available.
if (SafeNativeMethods.GetKeyboardLayoutList(0, null) <= 1)
return;
Debug.Assert(_ipp == null, "_EnsureInputProcesoorProfile has been called.");
InputLanguageProfileNotifySink lpns;
lpns = new InputLanguageProfileNotifySink(this);
_ipp= new InputProcessorProfiles();
if (!_ipp.Initialize(lpns))
{
_ipp = null;
}
}
//-----------------------------------------------------
//
// Private Properties
//
//------------------------------------------------------
///
/// The current input language in LANGID of this win32 thread.
///
private short _CurrentInputLanguage
{
get
{
// Return input language of the dispatcher thread.
return (short)NativeMethods.IntPtrToInt32(SafeNativeMethods.GetKeyboardLayout(_dispatcherThreadId));
}
set
{
EnsureInputProcessorProfile();
if (_ipp != null)
{
_ipp.CurrentInputLanguage = value;
}
}
}
//------------------------------------------------------
//
// Private Fields
//
//-----------------------------------------------------
#region Private Fields
// the current input language in LANGID.
private short _langid;
// The dispatcher thread id.
private int _dispatcherThreadId;
// the connected input language manager.
InputLanguageManager _inputlanguagemanager;
// the reference to ITfInputProcessorProfile.
InputProcessorProfiles _ipp;
#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: The source of the input language of the thread.
//
// History:
// 07/30/2003 : yutakas - ported from dotnet tree.
//
//---------------------------------------------------------------------------
using System.Security;
using System.Security.Permissions;
using System.Collections;
using System.Globalization;
using System.Windows.Threading;
using System.Windows.Input;
using System.Windows.Media;
using System.Runtime.InteropServices;
using System.Diagnostics;
using MS.Win32;
using MS.Utility;
namespace System.Windows.Input
{
//-----------------------------------------------------
//
// InputLanguageSource class
//
//-----------------------------------------------------
///
/// This is an internal. The source for input languages.
///
internal sealed class InputLanguageSource : IInputLanguageSource, IDisposable
{
//------------------------------------------------------
//
// Constructors
//
//-----------------------------------------------------
///
/// This is an internal. The source for input languages.
///
internal InputLanguageSource(InputLanguageManager inputlanguagemanager)
{
_inputlanguagemanager = inputlanguagemanager;
// initialize the current input language.
_langid = (short)NativeMethods.IntPtrToInt32(SafeNativeMethods.GetKeyboardLayout(0));
// store the dispatcher thread id. This will be used to call GetKeyboardLayout() from
// other thread.
_dispatcherThreadId = SafeNativeMethods.GetCurrentThreadId();
// Register source
_inputlanguagemanager.RegisterInputLanguageSource(this);
}
//------------------------------------------------------
//
// Public Methods
//
//------------------------------------------------------
#region Public Methods
///
/// Dispose method.
///
public void Dispose()
{
if (_ipp != null)
Uninitialize();
}
///
/// IIInputLanguageSource.Initialize()
/// This creates ITfInputProcessorProfile object and advice sink.
///
public void Initialize()
{
EnsureInputProcessorProfile();
}
///
/// IIInputLanguageSource.Uninitialize()
/// This releases ITfInputProcessorProfile object and unadvice sink.
///
public void Uninitialize()
{
if (_ipp != null)
{
_ipp.Uninitialize();
_ipp = null;
}
}
#endregion Public Methods
//-----------------------------------------------------
//
// Public Properties
//
//------------------------------------------------------
///
/// returns the current input language of this win32 thread.
///
public CultureInfo CurrentInputLanguage
{
get
{
return new CultureInfo(_CurrentInputLanguage);
}
set
{
_CurrentInputLanguage = (short)value.LCID;
}
}
///
/// returns the list of the available input languages of this win32 thread.
///
public IEnumerable InputLanguageList
{
get
{
EnsureInputProcessorProfile();
if (_ipp == null)
{
ArrayList al = new ArrayList();
al.Add(CurrentInputLanguage);
return al;
}
return _ipp.InputLanguageList;
}
}
//-----------------------------------------------------
//
// Internal Methods
//
//-----------------------------------------------------
///
/// The input language change call back from the sink.
///
internal bool OnLanguageChange(short langid)
{
if (_langid != langid)
{
// Call InputLanguageManager if its current source is this.
if (InputLanguageManager.Current.Source == this)
{
return InputLanguageManager.Current.ReportInputLanguageChanging(new CultureInfo(langid), new CultureInfo(_langid));
}
}
return true;
}
///
/// The input language changed call back from the sink.
///
internal void OnLanguageChanged()
{
short langid = _CurrentInputLanguage;
if (_langid != langid)
{
short prevlangid = _langid;
_langid = langid;
// Call InputLanguageManager if its current source is this.
if (InputLanguageManager.Current.Source == this)
{
InputLanguageManager.Current.ReportInputLanguageChanged(new CultureInfo(langid), new CultureInfo(prevlangid));
}
}
}
//-----------------------------------------------------
//
// Private Method
//
//------------------------------------------------------
///
/// This creates ITfInputProcessorProfile object and advice sink.
///
///
/// Critical - calls unmanaged code (initializing input)
/// TreatAsSafe - ok to call any number of times
///
[SecurityCritical, SecurityTreatAsSafe]
private void EnsureInputProcessorProfile()
{
// _ipp has been initialzied. Don't do this again.
if (_ipp != null)
return;
// We don't need to initialize _ipp if there is onlyone keyboard layout.
// Only one input language is available.
if (SafeNativeMethods.GetKeyboardLayoutList(0, null) <= 1)
return;
Debug.Assert(_ipp == null, "_EnsureInputProcesoorProfile has been called.");
InputLanguageProfileNotifySink lpns;
lpns = new InputLanguageProfileNotifySink(this);
_ipp= new InputProcessorProfiles();
if (!_ipp.Initialize(lpns))
{
_ipp = null;
}
}
//-----------------------------------------------------
//
// Private Properties
//
//------------------------------------------------------
///
/// The current input language in LANGID of this win32 thread.
///
private short _CurrentInputLanguage
{
get
{
// Return input language of the dispatcher thread.
return (short)NativeMethods.IntPtrToInt32(SafeNativeMethods.GetKeyboardLayout(_dispatcherThreadId));
}
set
{
EnsureInputProcessorProfile();
if (_ipp != null)
{
_ipp.CurrentInputLanguage = value;
}
}
}
//------------------------------------------------------
//
// Private Fields
//
//-----------------------------------------------------
#region Private Fields
// the current input language in LANGID.
private short _langid;
// The dispatcher thread id.
private int _dispatcherThreadId;
// the connected input language manager.
InputLanguageManager _inputlanguagemanager;
// the reference to ITfInputProcessorProfile.
InputProcessorProfiles _ipp;
#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
- NavigationPropertyEmitter.cs
- AsmxEndpointPickerExtension.cs
- AesManaged.cs
- PocoPropertyAccessorStrategy.cs
- DiffuseMaterial.cs
- QueryValue.cs
- InvalidAsynchronousStateException.cs
- GenericRootAutomationPeer.cs
- TabControlAutomationPeer.cs
- KnowledgeBase.cs
- ExternalException.cs
- CompilerGeneratedAttribute.cs
- GeneralTransform.cs
- ExecutionEngineException.cs
- TypeBuilderInstantiation.cs
- DataGridAutoFormatDialog.cs
- XpsS0ValidatingLoader.cs
- DBDataPermissionAttribute.cs
- MetadataItem.cs
- MediaElementAutomationPeer.cs
- FileDialog.cs
- Int32EqualityComparer.cs
- SelectionEditingBehavior.cs
- CommandTreeTypeHelper.cs
- MatrixAnimationBase.cs
- httpstaticobjectscollection.cs
- MonitoringDescriptionAttribute.cs
- StorageEntityContainerMapping.cs
- ContentPosition.cs
- IndexerHelper.cs
- DataGridViewTopRowAccessibleObject.cs
- ReferentialConstraintRoleElement.cs
- HtmlInputSubmit.cs
- TableLayoutPanelBehavior.cs
- DataKey.cs
- util.cs
- LayoutEngine.cs
- webproxy.cs
- ExpressionBindingCollection.cs
- InvalidAsynchronousStateException.cs
- oledbmetadatacollectionnames.cs
- RNGCryptoServiceProvider.cs
- FixedSOMSemanticBox.cs
- OuterGlowBitmapEffect.cs
- ExponentialEase.cs
- ExpressionQuoter.cs
- ListItemCollection.cs
- ICollection.cs
- SchemaEntity.cs
- SmtpException.cs
- BindingManagerDataErrorEventArgs.cs
- WindowsButton.cs
- FontFamily.cs
- SudsCommon.cs
- DtcInterfaces.cs
- XmlHierarchyData.cs
- RepeaterItemCollection.cs
- UnknownWrapper.cs
- HtmlTextViewAdapter.cs
- PrintSchema.cs
- DataGridViewColumnConverter.cs
- DataGridTableCollection.cs
- EncoderExceptionFallback.cs
- SqlParameterCollection.cs
- RectIndependentAnimationStorage.cs
- MethodBody.cs
- SafeRightsManagementPubHandle.cs
- ListViewItem.cs
- HMACSHA256.cs
- NativeMethods.cs
- FormViewRow.cs
- StylusCollection.cs
- DesigntimeLicenseContextSerializer.cs
- MissingFieldException.cs
- XmlAttribute.cs
- LicenseException.cs
- EntityCommand.cs
- SplitterCancelEvent.cs
- InProcStateClientManager.cs
- QualifiedCellIdBoolean.cs
- SQLBinary.cs
- MeshGeometry3D.cs
- TextDecoration.cs
- ZoneMembershipCondition.cs
- HandlerFactoryWrapper.cs
- LinkLabel.cs
- TextPatternIdentifiers.cs
- DataGridViewSelectedCellCollection.cs
- SharedPerformanceCounter.cs
- TreeNode.cs
- CodeNamespace.cs
- MultiView.cs
- ParagraphVisual.cs
- InputReportEventArgs.cs
- TrailingSpaceComparer.cs
- WizardStepCollectionEditor.cs
- DeclarativeCatalogPart.cs
- SourceItem.cs
- InheritanceAttribute.cs
- HttpServerUtilityBase.cs