using System.Runtime.InteropServices.ComTypes; using static Vanara.PInvoke.Ole32; using HKL = System.IntPtr; using LPARAM = System.IntPtr; using TfClientId = System.UInt32; using TfEditCookie = System.UInt32; using WPARAM = System.IntPtr; namespace Vanara.PInvoke; public static partial class MSCTF { /// /// The ITfContextOwnerServices interface is implemented by the manager and used by a text service or application acting as /// context owners. The interface provides notification changes to sinks and other services to context owners that do not implement /// the ITextStoreACP or ITextStoreAnchor interfaces. Clients obtain this interface by calling the ITfContext::QueryInterface method. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nn-msctf-itfcontextownerservices [PInvokeData("msctf.h", MSDNShortId = "NN:msctf.ITfContextOwnerServices")] [ComImport, Guid("B23EB630-3E1C-11D3-A745-0050040AB407"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] public interface ITfContextOwnerServices { /// /// The ITfContextOwnerServices::OnLayoutChange method is called by the context owner when the on-screen representation /// of the text stream is updated during a composition. Text stream updates include when the position of the window that /// contains the text is changed or if the screen coordinates of the text change. /// /// /// /// A call to ITfContextOwnerServices::OnLayoutChange could be in response to a text edit, font size change, window /// movement/resizing, and so on. /// /// /// If a call to ITfContextView::GetTextExt or ITfContextOwner::GetACPFromPoint fails because the application did not calculate /// the screen layout (Return Value: TS_E_NOLAYOUT), the application must then call /// ITfContextOwnerServices::OnLayoutChange when the information is ready. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfcontextownerservices-onlayoutchange HRESULT OnLayoutChange(); void OnLayoutChange(); /// /// The ITfContextOwnerServices::OnStatusChange method is called by the context owner when the dwDynamicFlags /// member of the structure returned by the ITfContextOwner::GetStatus method changes. /// /// Specifies the dynamic status flag. // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfcontextownerservices-onstatuschange HRESULT // OnStatusChange( DWORD dwFlags ); void OnStatusChange(TS_SD dwFlags); /// Called by a context owner to generate notifications that a support attribute value changed. /// Specifies the GUID of the support attribute. /// /// A support attribute is a read-only property maintained by the context owner. The supported attributes are in the Tsattrs.h /// header file. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfcontextownerservices-onattributechange HRESULT // OnAttributeChange( REFGUID rguidAttribute ); void OnAttributeChange(in Guid rguidAttribute); /// /// The ITfContextOwnerServices::Serialize method obtains a property from a range of text and writes the property data /// into a stream object. This enables an application to store property data, for example, when writing the data to a file. /// /// Pointer to an ITfProperty interface that identifies the property to serialize. /// Pointer to an ITfRange interface that identifies the range that the property is obtained from. /// Pointer to a TF_PERSISTENT_PROPERTY_HEADER_ACP structure that receives the header data for the property. /// Pointer to an IStream object that the TSF manager will write the property data to. /// /// /// The property header data placed in pHdr is common to all properties and must be preserved with the data written into /// pStream. This same data pair must be passed to ITfContextOwnerServices::Unserialize to restore the property data. /// /// An application can save all of the properties for the entire document by performing the following steps. /// /// /// Enumerate all properties using ITfContext::EnumProperties. /// /// /// Within each property, enumerate the ranges using ITfReadOnlyProperty::EnumRanges. /// /// /// Pass the current property and range to this method. /// /// /// Write the data placed in pHdr to the file. /// /// /// Write the data added to pStream to the file. /// /// /// When calling this method, the application must be able to grant a synchronous read-only lock. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfcontextownerservices-serialize HRESULT Serialize( // ITfProperty *pProp, ITfRange *pRange, TF_PERSISTENT_PROPERTY_HEADER_ACP *pHdr, IStream *pStream ); void Serialize([In] ITfProperty pProp, [In] ITfRange pRange, out TF_PERSISTENT_PROPERTY_HEADER_ACP pHdr, [In] IStream pStream); /// Applies previously serialized property data to a property object. /// Pointer to an ITfProperty object that receives the property data. /// Pointer to a TF_PERSISTENT_PROPERTY_HEADER_ACP structure that contains the header data for the property. /// /// Pointer to an IStream object that contains the property data. This parameter can be NULL if pLoader is not /// NULL. This parameter is ignored if pLoader is not NULL. /// /// /// Pointer to an ITfPersistentPropertyLoaderACP object that the TSF manager uses to obtain the property data. This parameter /// can be NULL if pStream is not NULL. /// /// /// /// If pStream is specified rather than pLoader, the property data is read from pStream during the call to this method. If /// pLoader is specified rather than pStream, the property data is read from pLoader asynchronously. Using pStream can cause /// long delays if the property data is large. /// /// When calling this method, the application must be able to grant a synchronous read-only lock. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfcontextownerservices-unserialize HRESULT Unserialize( // ITfProperty *pProp, const TF_PERSISTENT_PROPERTY_HEADER_ACP *pHdr, IStream *pStream, ITfPersistentPropertyLoaderACP *pLoader ); void Unserialize([In] ITfProperty pProp, in TF_PERSISTENT_PROPERTY_HEADER_ACP pHdr, [In, Optional] IStream? pStream, [In, Optional] ITfPersistentPropertyLoaderACP? pLoader); /// Forces a property load. /// Pointer to an ITfProperty object that specifies the property to load. /// The application must be able to grant a synchronous read-only lock before calling this method. // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfcontextownerservices-forceloadproperty HRESULT // ForceLoadProperty( ITfProperty *pProp ); void ForceLoadProperty([In] ITfProperty pProp); /// /// The ITfContextOwnerServices::CreateRange method creates a new ranged based upon a specified character position. /// /// Specifies the starting character position of the range. /// Specifies the ending character position of the range. /// Receives a pointer to the range object within the specified starting and ending character positions. // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfcontextownerservices-createrange HRESULT CreateRange( // LONG acpStart, LONG acpEnd, ITfRangeACP **ppRange ); ITfRangeACP CreateRange(int acpStart, int acpEnd); } /// /// The ITfContextView interface is implemented by the TSF manager and used by a client (application or text service) to /// obtain information about a context view. Clients obtain this interface by calling the ITfContext::GetActiveView method which /// returns a pointer to the ITfContextView object. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nn-msctf-itfcontextview [PInvokeData("msctf.h", MSDNShortId = "NN:msctf.ITfContextView")] [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("2433BF8E-0F9B-435C-BA2C-180611978C30")] public interface ITfContextView { /// /// The ITfContextView::GetRangeFromPoint method converts a point, in screen coordinates, to an empty range of text /// positioned at a corresponding location. /// /// Specifies the edit cookie with read-only access. /// Specifies the point in screen coordinates. /// /// /// Specifies the range position to return based upon the screen coordinates of the point to a character bounding box. By /// default, the range position returned is the character bounding box containing the screen coordinates of the point. If the /// point is outside a character bounding box, the method returns NULL or TF_E_INVALIDPOINT. Other bit flags for this /// parameter are as follows. /// /// The bit flags can be combined. /// /// /// Value /// Meaning /// /// /// GXFPF_ROUND_NEAREST /// /// If the screen coordinates of the point are contained in a character bounding box, the range position returned is the /// bounding edge closest to the screen coordinates of the point. /// /// /// /// GXFPF_NEAREST /// /// If the screen coordinates of the point are not contained in a character bounding box, the closest range position is returned. /// /// /// /// /// Receives a pointer to the ITfRange interface. /// /// By default, the method will return a range positioned at 0 for point 1 and TF_E_INVALIDPOINT for point 2. If the dwFlags /// parameter is set to GXFPF_ROUND_NEAREST, the method returns range position 1 for point 1. If the dwFlags parameter is set to /// GXFPF_NEAREST then the method returns range position 2 for point 2. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfcontextview-getrangefrompoint HRESULT GetRangeFromPoint( // TfEditCookie ec, const POINT *ppt, DWORD dwFlags, ITfRange **ppRange ); ITfRange? GetRangeFromPoint([In] TfEditCookie ec, in POINT ppt, GXFPF dwFlags); /// /// The ITfContextView::GetTextExt method returns the bounding box, in screen coordinates, of a range of text. /// /// Specifies an edit cookie with read-only access. /// Specifies the range to query /// Receives the bounding box, in screen coordinates, of the range. /// /// Receives the Boolean value that specifies if the text in the bounding box has been clipped. If this parameter is /// TRUE, the bounding box contains clipped text and does not include the entire requested range. The bounding box is /// clipped because of the requested range is not visible. /// /// /// If the document window is minimized, or if the specified text is not currently visible, the method returns S_OK with the prc /// parameter set to {0,0,0,0}. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfcontextview-gettextext HRESULT GetTextExt( TfEditCookie // ec, ITfRange *pRange, RECT *prc, BOOL *pfClipped ); void GetTextExt([In] TfEditCookie ec, [In] ITfRange pRange, out RECT prc, [Out, MarshalAs(UnmanagedType.Bool)] out bool pfClipped); /// /// The ITfContextView::GetScreenExt method returns the bounding box, in screen coordinates, of the document display. /// /// Receives the bounding box, in screen coordinates, of the display surface. /// The prc parameter is cleared to {0,0,0,0} if the document is not currently displayed. // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfcontextview-getscreenext HRESULT GetScreenExt( RECT *prc ); RECT GetScreenExt(); /// The ITfContextView::GetWnd method returns the handle to a window that corresponds to the current document. /// Receives a pointer to the handle of the window that corresponds to the current document. /// /// A document might not have a corresponding window handle if the document is in memory but not displayed on the screen or if /// the document is a windowless control and the control does not have the window handle of the owner of the windowless /// controls. Callers cannot assume that the phwnd parameter will receive a non- NULL value even if the method is /// successful. Callers can also receive a NULL value for the phwnd parameter. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfcontextview-getwnd HRESULT GetWnd( HWND *phwnd ); HWND GetWnd(); } /// /// The ITfCreatePropertyStore interface is implemented by a text service to support persistence of property store data. The /// TSF manager uses this interface to determine if a property store can be serialized and to create a property store object for a /// serialized property. /// /// /// When a property store is unserialized, the TSF manager creates an object from the CLSID obtained from /// ITfPropertyStore::GetPropertyRangeCreator and obtain an ITfCreatePropertyStore interface pointer from it. The manager /// then uses ITfCreatePropertyStore::CreatePropertyStore to create the property store object. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nn-msctf-itfcreatepropertystore [PInvokeData("msctf.h", MSDNShortId = "NN:msctf.ITfCreatePropertyStore")] [ComImport, Guid("2463FBF0-B0AF-11D2-AFC5-00105A2799B5"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] public interface ITfCreatePropertyStore { /// Determines if a property store can be stored as persistent data. /// Contains the type identifier of the property. For more information, see ITfPropertyStore::GetType. /// Pointer to an ITfRange object that contains the text covered by the property store. /// Pointer to the ITfPropertyStore object. /// /// Pointer to a BOOL that receives a flag that indicates if the property store can be serialized. Receives nonzero if /// the property store can be serialized or zero otherwise. /// /// /// This method can return one of these values. /// /// /// Value /// Description /// /// /// S_OK /// The method was successful. /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfcreatepropertystore-isstoreserializable HRESULT // IsStoreSerializable( REFGUID guidProp, ITfRange *pRange, ITfPropertyStore *pPropStore, BOOL *pfSerializable ); [PreserveSig] HRESULT IsStoreSerializable(in Guid guidProp, [In] ITfRange pRange, [In] ITfPropertyStore pPropStore, [Out, MarshalAs(UnmanagedType.Bool)] out bool pfSerializable); /// Creates a property store object from serialized property store data. /// Contains the type identifier of the property. For more information, see ITfPropertyStore::GetType. /// Pointer to an ITfRange object that contains the text to be covered by the property store. /// Contains the size, in bytes, of the property store data contained in pStream. /// Pointer to an IStream object that contains the property store data. /// /// Pointer to an ITfPropertyStore interface pointer that receives the property store object created by this method. /// /// /// This method can return one of these values. /// /// /// Value /// Description /// /// /// S_OK /// The method was successful. /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfcreatepropertystore-createpropertystore HRESULT // CreatePropertyStore( REFGUID guidProp, ITfRange *pRange, ULONG cb, IStream *pStream, ITfPropertyStore **ppStore ); [PreserveSig] HRESULT CreatePropertyStore(in Guid guidProp, [In] ITfRange pRange, uint cb, [In] IStream pStream, out ITfPropertyStore ppStore); } /// /// The ITfDisplayAttributeInfo interface is implemented by a text service to provide display attribute data. This interface /// is used by any component, most often an application, that must determine how text displays. /// /// /// An application obtains an instance of this interface by calling ITfDisplayAttributeMgr::GetDisplayAttributeInfo or IEnumTfDisplayAttributeInfo::Next. /// A text service supplies an instance of this interface in its ITfDisplayAttributeProvider::GetDisplayAttributeInfo method. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nn-msctf-itfdisplayattributeinfo [PInvokeData("msctf.h", MSDNShortId = "NN:msctf.ITfDisplayAttributeInfo")] [ComImport, Guid("70528852-2F26-4AEA-8C96-215150578932"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] public interface ITfDisplayAttributeInfo { /// Obtains the GUID for the display attribute. /// Pointer to a GUID value that receives the GUID for the display attribute. /// /// This method can return one of these values. /// /// /// Value /// Description /// /// /// S_OK /// The method was successful. /// /// /// E_INVALIDARG /// pguid is invalid. /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfdisplayattributeinfo-getguid HRESULT GetGUID( GUID // *pguid ); [PreserveSig] HRESULT GetGUID(out Guid pguid); /// Obtains the description string of the display attribute. /// /// Pointer to a BSTR value that receives the description string. This value must be allocated using SysAllocString. The caller /// must free this memory using SysFreeString when it is no longer required. /// /// /// This method can return one of these values. /// /// /// Value /// Description /// /// /// S_OK /// The method was successful. /// /// /// E_INVALIDARG /// pbstrDesc is invalid. /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfdisplayattributeinfo-getdescription HRESULT // GetDescription( BSTR *pbstrDesc ); [PreserveSig] HRESULT GetDescription([Out, MarshalAs(UnmanagedType.BStr)] out string pbstrDesc); /// Obtains the display attribute data. /// Pointer to a TF_DISPLAYATTRIBUTE structure that receives display attribute data. /// /// This method can return one of these values. /// /// /// Value /// Description /// /// /// S_OK /// The method was successful. /// /// /// E_INVALIDARG /// pda is invalid. /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfdisplayattributeinfo-getattributeinfo HRESULT // GetAttributeInfo( TF_DISPLAYATTRIBUTE *pda ); [PreserveSig] HRESULT GetAttributeInfo(out TF_DISPLAYATTRIBUTE pda); /// Sets the new attribute data. /// Pointer to a TF_DISPLAYATTRIBUTE structure that contains the new display attribute data. /// /// This method can return one of these values. /// /// /// Value /// Description /// /// /// S_OK /// The method was successful. /// /// /// E_NOTIMPL /// The display attribute provider does not support attribute modification. /// /// /// E_INVALIDARG /// pda is invalid. /// /// /// /// /// The implementation of this method should not call ITfDisplayAttributeMgr::OnUpdateInfo in response to this method. The /// caller must do so. This avoids redundant notifications if more than one attribute is modified. The caller must eventually /// call ITfDisplayAttributeMgr::OnUpdateInfo so that other clients will receive an attribute update notification. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfdisplayattributeinfo-setattributeinfo HRESULT // SetAttributeInfo( const TF_DISPLAYATTRIBUTE *pda ); [PreserveSig] HRESULT SetAttributeInfo(in TF_DISPLAYATTRIBUTE pda); /// Resets the display attribute data to its default value. /// /// This method can return one of these values. /// /// /// Value /// Description /// /// /// S_OK /// The method was successful. /// /// /// E_NOTIMPL /// The display attribute provider does not support attribute modification. /// /// /// /// /// The implementation of this method should not call ITfDisplayAttributeMgr::OnUpdateInfo in response to this method. The /// caller must do so. This avoids redundant notifications if more than one attribute is modified. The caller must eventually /// call ITfDisplayAttributeMgr::OnUpdateInfo so that other clients will receive an attribute update notification. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfdisplayattributeinfo-reset HRESULT Reset(); [PreserveSig] HRESULT Reset(); } /// /// The ITfDisplayAttributeMgr interface is implemented by the TSF manager and used by an application to obtain and enumerate /// display attributes. Individual display attributes are accessed through the ITfDisplayAttributeInfo interface. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nn-msctf-itfdisplayattributemgr [PInvokeData("msctf.h", MSDNShortId = "NN:msctf.ITfDisplayAttributeMgr")] [ComImport, Guid("8DED7393-5DB1-475C-9E71-A39111B0FF67"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), CoClass(typeof(TF_DisplayAttributeMgr))] public interface ITfDisplayAttributeMgr { /// Called when a display attribute is changed. // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfdisplayattributemgr-onupdateinfo HRESULT OnUpdateInfo(); void OnUpdateInfo(); /// Obtains a display attribute enumerator object. /// Pointer to an IEnumTfDisplayAttributeInfo interface pointer that receives the enumerator object. // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfdisplayattributemgr-enumdisplayattributeinfo HRESULT // EnumDisplayAttributeInfo( IEnumTfDisplayAttributeInfo **ppEnum ); IEnumTfDisplayAttributeInfo EnumDisplayAttributeInfo(); /// Obtains a display attribute data object. /// /// Contains a GUID that identifies the display attribute data requested. This value is obtained by obtaining the /// GUID_PROP_ATTRIBUTE property for the range of text. For more information, see ITfContext::GetProperty and ITfContext::TrackProperties. /// /// Pointer to an ITfDisplayAttributeInfo interface pointer that receives the object. /// /// Pointer to a CLSID value that receives the CLSID of the display attribute provider. This parameter can be NULL if the /// CLSID is not required. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfdisplayattributemgr-getdisplayattributeinfo HRESULT // GetDisplayAttributeInfo( REFGUID guid, ITfDisplayAttributeInfo **ppInfo, CLSID *pclsidOwner ); void GetDisplayAttributeInfo(in Guid guid, out ITfDisplayAttributeInfo ppInfo, [NullAllowed] out Guid pclsidOwner); } /// /// The ITfDisplayAttributeNotifySink interface is implemented by an application to receive a notification when display /// attribute information is updated. This advise sink is installed by calling the TSF manager's ITfSource::AdviseSink with IID_ITfDisplayAttributeNotifySink. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nn-msctf-itfdisplayattributenotifysink [PInvokeData("msctf.h", MSDNShortId = "NN:msctf.ITfDisplayAttributeNotifySink")] [ComImport, Guid("AD56F402-E162-4F25-908F-7D577CF9BDA9"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] public interface ITfDisplayAttributeNotifySink { /// Called when display attribute information is updated. /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfdisplayattributenotifysink-onupdateinfo HRESULT OnUpdateInfo(); [PreserveSig] HRESULT OnUpdateInfo(); } /// /// /// The ITfDisplayAttributeProvider interface is implemented by a text service and is used by the TSF manager to enumerate /// and obtain individual display attribute information objects. /// /// /// The TSF manager obtains an instance of this interface by calling CoCreateInstance with the class identifier passed to /// ITfCategoryMgr::RegisterCategory with GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER and IID_ITfDisplayAttributeProvider. For more /// information, see Providing Display Attributes. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nn-msctf-itfdisplayattributeprovider [PInvokeData("msctf.h", MSDNShortId = "NN:msctf.ITfDisplayAttributeProvider")] [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("FEE47777-163C-4769-996A-6E9C50AD8F54")] public interface ITfDisplayAttributeProvider { /// Obtains an enumerator that contains all display attribute info objects supported by the display attribute provider. /// /// Pointer to an IEnumTfDisplayAttributeInfo interface pointer that receives the enumerator object. The caller must release /// this interface when it is no longer required. /// /// /// This method can return one of these values. /// /// /// Value /// Description /// /// /// S_OK /// The method was successful. /// /// /// E_FAIL /// An unspecified error occurred. /// /// /// E_INVALIDARG /// ppEnum is invalid. /// /// /// E_OUTOFMEMORY /// A memory allocation failure occurred. /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfdisplayattributeprovider-enumdisplayattributeinfo // HRESULT EnumDisplayAttributeInfo( IEnumTfDisplayAttributeInfo **ppEnum ); [PreserveSig] HRESULT EnumDisplayAttributeInfo(out IEnumTfDisplayAttributeInfo ppEnum); /// Obtains a display attribute provider object for a particular display attribute. /// /// Contains a GUID value that identifies the display attribute to obtain the display attribute information object for. The text /// service must publish these values and what they indicate. This identifier can also be obtained by enumerating the display /// attributes for a range of text. /// /// /// Pointer to an ITfDisplayAttributeInfo interface pointer that receives the display attribute information object. /// /// /// This method can return one of these values. /// /// /// Value /// Description /// /// /// S_OK /// The method was successful. /// /// /// E_FAIL /// An unspecified error occurred. /// /// /// E_INVALIDARG /// One or more parameters are invalid. /// /// /// E_OUTOFMEMORY /// A memory allocation failure occurred. /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfdisplayattributeprovider-getdisplayattributeinfo HRESULT // GetDisplayAttributeInfo( REFGUID guid, ITfDisplayAttributeInfo **ppInfo ); [PreserveSig] HRESULT GetDisplayAttributeInfo(in Guid guid, out ITfDisplayAttributeInfo? ppInfo); } /// /// The ITfDocumentMgr interface is implemented by the TSF manager and used by an application or text service to create and /// manage text contexts. To obtain an instance of this interface call ITfThreadMgr::CreateDocumentMgr. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nn-msctf-itfdocumentmgr [PInvokeData("msctf.h", MSDNShortId = "NN:msctf.ITfDocumentMgr")] [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("AA80E7F4-2021-11D2-93E0-0060B067B86E")] public interface ITfDocumentMgr { /// Creates a context object. /// /// The client identifier. For an application, this value is provided by a previous call to ITfThreadMgr::Activate. For a text /// service, this value is provided in the text service ITfTextInputProcessor::Activate method. /// /// Reserved, must be zero. /// /// Pointer to an object that supports the ITextStoreACP or ITfContextOwnerCompositionSink interfaces. This value can be NULL. /// /// Address of an ITfContext pointer that receives the context. /// /// Pointer to a TfEditCookie value that receives an edit cookie for the new context. This value identifies the context in /// various methods. /// /// /// All references to the punk parameter are released when the context is destroyed or when the context is removed from the /// stack with the ITfDocumentMgr::Pop method. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfdocumentmgr-createcontext HRESULT CreateContext( // TfClientId tidOwner, DWORD dwFlags, IUnknown *punk, ITfContext **ppic, TfEditCookie *pecTextStore ); void CreateContext([In] TfClientId tidOwner, [Optional] uint dwFlags, [In, Optional, MarshalAs(UnmanagedType.IUnknown)] object? punk, out ITfContext ppic, out TfEditCookie pecTextStore); /// Adds a context to the top of the context stack. /// /// Pointer to the ITfContext object to be added to the stack. This object is obtained from a previous call to ITfDocumentMgr::CreateContext. /// /// /// The first context added to the stack becomes the main document context. /// /// The TSF manager and text services only interact with the context at the top of the stack. Normally, only the main document /// context is on the stack. Occasionally, it is necessary to add a second context to the stack. For example, when a text /// service must display a modal UI, such as a candidate list. During this time, the text service will add its context to the /// stack. When the text service UI is no longer required, the text service removes the context from the stack. The main context /// then returns to the top of the stack. To simplify this process and prevent multiple modal UIs from being displayed, there is /// a maximum of two contexts allowed on the stack. /// /// /// This method causes the ITfThreadMgrEventSink::OnPushContext method of all installed thread manager event sinks to be called. /// If this is the first context to be added to the stack, this method causes the ITfThreadMgrEventSink::OnInitDocumentMgr /// method of all installed thread manager event sinks to be called. /// /// ITfDocumentMgr::Pop must be called to remove this context from the context stack. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfdocumentmgr-push HRESULT Push( ITfContext *pic ); void Push([In] ITfContext pic); /// Removes the context from the top of the context stack. /// /// If this value is 0, only the context at the top of the stack is removed. If this value is TF_POPF_ALL, all of the contexts /// are removed from the stack. /// /// /// This method must be called from the same thread as the corresponding ITfDocumentMgr::Push call. /// /// The first context added to the stack becomes the primary context. The primary context cannot be removed from the stack /// without using the TF_POPF_ALL flag. When the document is uninitialized, this method should be called with the TF_POPF_ALL /// flag. This causes the document manager to remove all contexts from the context stack and terminate any text service UI. Do /// not use the TF_POPF_ALL flag at any other time. /// /// /// This method causes the ITfThreadMgrEventSink::OnPopContext method of all installed thread manager event sinks to be called. /// If the last context is removed from the stack, this method causes the ITfThreadMgrEventSink::OnUninitDocumentMgr method of /// all installed thread manager event sinks to be called. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfdocumentmgr-pop HRESULT Pop( DWORD dwFlags ); void Pop([In] TF_POPF dwFlags); /// Obtains the context at the top of the context stack. /// Address of an ITfContext pointer that receives the context. // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfdocumentmgr-gettop HRESULT GetTop( ITfContext **ppic ); ITfContext GetTop(); /// Obtains the context at the base of the context stack. /// Address of an ITfContext pointer that receives the context. // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfdocumentmgr-getbase HRESULT GetBase( ITfContext **ppic ); ITfContext GetBase(); /// Obtains a context enumerator. /// Address of an IEnumTfContexts pointer that receives the enumerator. // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfdocumentmgr-enumcontexts HRESULT EnumContexts( // IEnumTfContexts **ppEnum ); IEnumTfContexts EnumContexts(); } /// /// The ITfEditRecord interface is implemented by the TSF manager and is used by a text edit sink to determine what was /// changed during an edit session. An instance of this interface is passed to the text edit sink when the /// ITfTextEditSink::OnEndEdit method is called. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nn-msctf-itfeditrecord [PInvokeData("msctf.h", MSDNShortId = "NN:msctf.ITfEditRecord")] [ComImport, Guid("42D4D099-7C1A-4A89-B836-6C6F22160DF0"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] public interface ITfEditRecord { /// Determines if the selection has changed during the edit session. /// /// Pointer to a BOOL value that receives a value that indicates if the selection changed due to an edit session. /// Receives a nonzero value if the selection changed or zero otherwise. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfeditrecord-getselectionstatus HRESULT // GetSelectionStatus( BOOL *pfChanged ); [return: MarshalAs(UnmanagedType.Bool)] bool GetSelectionStatus(); /// /// Obtains an enumerator that contains a collection of range objects that cover the specified properties and/or text that /// changed during the edit session. /// /// /// Contains a combination of the following values that specify the behavior of this method. /// /// /// Value /// Meaning /// /// /// 0 /// /// Specifies that the method will obtain a collection of range objects that cover the specified properties changed during the /// edit session. prgProperties cannot be NULL and cProperties must be greater than zero. /// /// /// /// TF_GTP_INCL_TEXT /// /// Specifies that the method will obtain the collection of range objects that cover the text changed during the edit session. /// /// /// /// /// /// /// Pointer to an array of GUID values that identify the properties to search for changes for. This method searches the /// properties that changed during the edit session and, if the property is contained in this array, a range object that covers /// the property that changed is added to ppEnum. /// /// This array must be at least cProperties elements in size. /// This parameter is ignored if dwFlags contains TF_GTP_INCL_TEXT and cProperties is zero. /// /// /// Specifies the number of elements in the prgProperties array. /// This parameter can be zero if dwFlags contains TF_GTP_INCL_TEXT. This indicates that no property changes are obtained. /// /// Pointer to an IEnumTfRanges interface pointer that receives the enumerator object. // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfeditrecord-gettextandpropertyupdates HRESULT // GetTextAndPropertyUpdates( DWORD dwFlags, const GUID **prgProperties, ULONG cProperties, IEnumTfRanges **ppEnum ); IEnumTfRanges GetTextAndPropertyUpdates([In] TF_GTP dwFlags, [In, Optional, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] Guid[]? prgProperties, [In, Optional] uint cProperties); } /// /// The ITfEditSession interface is implemented by a text service and used by the TSF manager to read and/or modify the text /// and properties of a context. /// /// /// /// A text service initiates an edit session by calling ITfContext::RequestEditSession, passing a pointer to the /// ITfEditSession interface. When the edit session is granted, the TSF manager calls DoEditSession. /// /// /// If the context is destroyed before the application grants a lock, or if the calling text service is deactivated before a lock is /// granted, the DoEditSession method is not called. For this reason, a text service should put cleanup operations for an /// edit session in the ITfEditSession interface destructor rather than in the DoEditSession method. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nn-msctf-itfeditsession [PInvokeData("msctf.h", MSDNShortId = "NN:msctf.ITfEditSession")] [ComImport, Guid("AA80E803-2021-11D2-93E0-0060B067B86E"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] public interface ITfEditSession { /// Called to enable a text service to read and/or modify the contents of a context. /// /// Contains a TfEditCookie value that uniquely identifies the edit session. This cookie is used to access the context with /// methods such as ITfRange::GetText. /// /// /// This method can return one of these values. /// /// /// Value /// Description /// /// /// S_OK /// The method was successful. /// /// /// E_FAIL /// An unspecified error occurred. /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfeditsession-doeditsession HRESULT DoEditSession( // TfEditCookie ec ); [PreserveSig] HRESULT DoEditSession([In] TfEditCookie ec); } /// /// The ITfEditTransactionSink interface is implemented by a text service and used by the TSF manager to support edit /// transactions. An edit transaction is a series of edits that use multiple document locks. A text service can optionally implement /// this interface. This advise sink is installed by calling ITfSource::AdviseSink with IID_ITfEditTransactionSink. /// /// /// An edit transaction involves multiple document locks, and usually includes multiple ITfTextEditSink::OnEndEdit method callbacks. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nn-msctf-itfedittransactionsink [PInvokeData("msctf.h", MSDNShortId = "NN:msctf.ITfEditTransactionSink")] [ComImport, Guid("708FBF70-B520-416B-B06C-2C41AB44F8BA"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] public interface ITfEditTransactionSink { /// Indicates the start of an edit transaction. /// Pointer to the ITfContext interface involved in the transaction. /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// /// The TSF manager calls this method at the start of an edit transaction. A text service might delay reevaluation of the /// changing context of the transaction due to the multiple ITfTextEditSink::OnEndEdit notifications until after receiving the /// corresponding ITfEditTransactionSink::OnEndEditTransaction callback. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfedittransactionsink-onstartedittransaction HRESULT // OnStartEditTransaction( ITfContext *pic ); [PreserveSig] HRESULT OnStartEditTransaction([In] ITfContext pic); /// Indicates the end of an edit transaction. /// Pointer to the ITfContext interface involved in the transaction. /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// /// The TSF manager calls this method at the end of an edit transaction. A text service can delay reevaluation of the changing /// context of the transaction due to the multiple ITfTextEditSink::OnEndEdit method notifications until after receiving this callback. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfedittransactionsink-onendedittransaction HRESULT // OnEndEditTransaction( ITfContext *pic ); [PreserveSig] HRESULT OnEndEditTransaction([In] ITfContext pic); } /// /// The ITfFunctionProvider interface is implemented by an application or text service to provide various function objects. /// /// /// A function provider is registered by calling ITFSourceSingle::AdviseSingleSink with IID_ITfFunctionProvider when the text /// service is activated. The text service should unregister its function provider with ITFSourceSingle::UnadviseSingleSink when it /// is deactivated. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nn-msctf-itffunctionprovider [PInvokeData("msctf.h", MSDNShortId = "NN:msctf.ITfFunctionProvider")] [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("101D6610-0990-11D3-8DF0-00105A2799B5")] public interface ITfFunctionProvider { /// Obtains the type identifier for the function provider. /// Pointer to a GUID value that receives the type identifier of the function provider. /// /// This method can return one of these values. /// /// /// Value /// Description /// /// /// S_OK /// The method was successful /// /// /// E_INVALIDARG /// pguid is invalid. /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itffunctionprovider-gettype HRESULT GetType( GUID *pguid ); [PreserveSig] HRESULT GetType(out Guid pguid); /// Obtains the description of the function provider. /// /// Pointer to a BSTR that receives the description string. This value must be allocated using SysAllocString. The caller must /// this memory using SysFreeString when it is no longer required. /// /// /// This method can return one of these values. /// /// /// Value /// Description /// /// /// S_OK /// The method was successful. /// /// /// E_OUTOFMEMORY /// A memory allocation failure occurred. /// /// /// E_INVALIDARG /// pbstrDesc is invalid. /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itffunctionprovider-getdescription HRESULT GetDescription( // BSTR *pbstrDesc ); [PreserveSig] HRESULT GetDescription([Out, MarshalAs(UnmanagedType.BStr)] out string? pbstrDesc); /// Obtains the specified function object. /// /// Contains a GUID value that identifies the function group that the requested function belongs to. This value can be GUID_NULL. /// /// /// Contains an interface identifier that identifies the requested function within the group specified by rguid. This value can /// be specified by the application, text service, or one of the IID_ITfFn* values. /// /// Pointer to an IUnknown interface pointer that receives the requested function interface. /// /// This method can return one of these values. /// /// /// Value /// Description /// /// /// S_OK /// The method was successful. /// /// /// E_NOINTERFACE /// The requested function is unsupported. /// /// /// E_OUTOFMEMORY /// A memory allocation failure occurred. /// /// /// E_INVALIDARG /// One or more parameters are invalid. /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itffunctionprovider-getfunction HRESULT GetFunction( // REFGUID rguid, REFIID riid, IUnknown **ppunk ); [PreserveSig] HRESULT GetFunction(in Guid rguid, in Guid riid, [Out, MarshalAs(UnmanagedType.IUnknown)] out object? ppunk); } /// /// The ITfInputProcessorProfileActivationSink interface is implemented by an application to receive notifications when the /// profile changes. /// /// /// To install this advise sink, obtain an ITfSource object from an ITfThreadMgr object by calling /// ITfThreadMgr::QueryInterface with IID_ ITfSource. Then call ITfSource::AdviseSink with IID_ITfInputProcessorProfileActivationSink. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nn-msctf-itfinputprocessorprofileactivationsink [PInvokeData("msctf.h", MSDNShortId = "NN:msctf.ITfInputProcessorProfileActivationSink")] [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("71C6E74E-0F28-11D8-A82A-00065B84435C")] public interface ITfInputProcessorProfileActivationSink { /// /// The ITfInputProcessorProfileActivationSink::OnActivated method is a callback that is called when an input processor profile /// is activated or deactivated. /// /// /// [in] The type of this profile. This is one of these values. /// /// /// Value /// Meaning /// /// /// TF_PROFILETYPE_INPUTPROCESSOR /// This is a text service. /// /// /// TF_PROFILETYPE_KEYBOARDLAYOUT /// This is a keyboard layout. /// /// /// /// [in] Specifies the language id of the profile. /// /// [in] Specifies the CLSID of the text service. If dwProfileType is TF_PROFILETYPE_KEYBOARDLAYOUT, this is CLSID_NULL. /// /// /// [in] Specifies the category of this text service. This category is GUID_TFCAT_TIP_KEYBOARD, GUID_TFCAT_TIP_SPEECH, /// GUID_TFCAT_TIP_HANDWRITING or something in GUID_TFCAT_CATEGORY_OF_TIP. If dwProfileType is TF_PROFILETYPE_KEYBOARDLAYOUT, /// this is GUID_NULL. /// /// /// [in] Specifies the GUID to identify the profile. If dwProfileType is TF_PROFILETYPE_KEYBOARDLAYOUT, this is GUID_NULL. /// /// /// [in] Specifies the keyboard layout handle of this profile. If dwProfileType is TF_PROFILETYPE_ INPUTPROCESSOR, this is NULL. /// /// /// [in] /// /// /// Value /// Meaning /// /// /// TF_IPSINK_FLAG_ACTIVE /// This is on if this profile is activated. /// /// /// /// The TSF manager ignores the return value of this method. // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfinputprocessorprofileactivationsink-onactivated HRESULT // OnActivated( DWORD dwProfileType, LANGID langid, REFCLSID clsid, REFGUID catid, REFGUID guidProfile, HKL hkl, DWORD dwFlags ); [PreserveSig] HRESULT OnActivated([In] TF_PROFILETYPE dwProfileType, [In] LANGID langid, in Guid clsid, in Guid catid, in Guid guidProfile, [In, Optional] HKL hkl, [In] TF_IPSINK_FLAG dwFlags); } /// /// The ITfInputProcessorProfileMgr interface is implemented by the TSF manager and used by an application or text service to /// manipulate the language profile of one or more text services. /// /// /// /// Unlike ITfInputProcessorProfiles, ITfInputProcessorProfileMgr can manage both keyboard layout and text services seamlessly. In /// Windows Vista, it is recommended to use this interface instead of using the following methods: /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nn-msctf-itfinputprocessorprofilemgr [PInvokeData("msctf.h", MSDNShortId = "NN:msctf.ITfInputProcessorProfileMgr")] [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("71C6E74C-0F28-11D8-A82A-00065B84435C"), CoClass(typeof(TF_InputProcessorProfiles))] public interface ITfInputProcessorProfileMgr { /// /// The ITfInputProcessorProfileMgr::ActivateProfile method activates the specified text service's profile or keyboard layout. /// /// /// [in] The type of this profile. This is one of these values. /// /// /// Value /// Meaning /// /// /// TF_PROFILETYPE_INPUTPROCESSOR /// This is a text service. /// /// /// TF_PROFILETYPE_KEYBOARDLAYOUT /// This is a keyboard layout. /// /// /// /// [in] The language id of the profile to be activated. /// /// [in] The CLSID of the text service of the profile to be activated. This must be CLSID_NULL if dwProfileType is TF_PROFILETYPE_KEYBOARDLAYOUT. /// /// /// [in] The guidProfile of the profile to be activated. This must be GUID_NULL if dwProfileType is TF_PROFILETYPE_KEYBOARDLAYOUT. /// /// [in] The handle of the keyboard layout. This must be NULL if dwProfileType is TF_PROFILETYPE_INPUTPROCESSOR. /// /// The combination of the following bits: /// /// /// Value /// Meaning /// /// /// TF_IPPMF_FORPROCESS /// Activate this profile for all threads in the process. /// /// /// TF_IPPMF_FORSESSION /// Activate this profile for all threads in the current desktop. /// /// /// TF_IPPMF_ENABLEPROFILE /// Update the registry to enable this profile for this user. /// /// /// TF_IPPMF_DISABLEPROFILE /// /// /// /// TF_IPPMF_DONTCARECURRENTINPUTLANGUAGE /// /// If the current input language does not match with the requested profile's language, TSF marks this profile to be activated /// when the requested input language is switched. If this flag is off and the current input language is not matched, this /// method fails. /// /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfinputprocessorprofilemgr-activateprofile HRESULT // ActivateProfile( DWORD dwProfileType, LANGID langid, REFCLSID clsid, REFGUID guidProfile, HKL hkl, DWORD dwFlags ); void ActivateProfile([In] TF_PROFILETYPE dwProfileType, [In] LANGID langid, in Guid clsid, in Guid guidProfile, [In, Optional] HKL hkl, [In] TF_IPPMF dwFlags); /// /// The ITfInputProcessorProfileMgr::DeactivateProfile method deactivates the specified text service's profile or /// keyboard layout. /// /// /// [in] The type of this profile. This is one of these values. /// /// /// Value /// Meaning /// /// /// TF_PROFILETYPE_INPUTPROCESSOR /// This is a text service. /// /// /// TF_PROFILETYPE_KEYBOARDLAYOUT /// This is a keyboard layout. /// /// /// /// [in] The language id of the profile to be activated. /// /// [in] The CLSID of the text service of the profile to be activated. This must be CLSID_NULL if dwProfileType is TF_PROFILETYPE_KEYBOARDLAYOUT. /// /// /// [in] The guidProfile of the profile to be activated. This must be GUID_NULL if dwProfileType is TF_PROFILETYPE_KEYBOARDLAYOUT. /// /// [in] The handle of the keyboard layout. This must be NULL if dwProfileType is TF_PROFILETYPE_INPUTPROCESSOR. /// /// The combination of the following bits: /// /// /// Value /// Meaning /// /// /// TF_IPPMF_FORPROCESS /// Deactivate this profile for all threads in the process. /// /// /// TF_IPPMF_FORSESSION /// Deactivate this profile for all threads in the current desktop. /// /// /// TF_IPPMF_DISABLEPROFILE /// /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfinputprocessorprofilemgr-deactivateprofile HRESULT // DeactivateProfile( DWORD dwProfileType, LANGID langid, REFCLSID clsid, REFGUID guidProfile, HKL hkl, DWORD dwFlags ); void DeactivateProfile([In] TF_PROFILETYPE dwProfileType, [In] LANGID langid, in Guid clsid, in Guid guidProfile, [In, Optional] HKL hkl, [In] TF_IPPMF dwFlags); /// /// The ITfInputProcessorProfileMgr::GetProfile method returns the information of the specified text service's profile or /// keyboard layout in TF_INPUTPROCESSORPROFILE structure. /// /// /// [in] The type of this profile. This is one of these values. /// /// /// Value /// Meaning /// /// /// TF_PROFILETYPE_INPUTPROCESSOR /// This is a text service. /// /// /// TF_PROFILETYPE_KEYBOARDLAYOUT /// This is a keyboard layout. /// /// /// /// [in] The language id of the profile to be activated. /// /// [in] The CLSID of the text service of the profile to be activated. This must be CLSID_NULL if dwProfileType is TF_PROFILETYPE_KEYBOARDLAYOUT. /// /// /// [in] The guidProfile of the profile to be activated. This must be GUID_NULL if dwProfileType is TF_PROFILETYPE_KEYBOARDLAYOUT. /// /// [in] The handle of the keyboard layout. This must be NULL if dwProfileType is TF_PROFILETYPE_INPUTPROCESSOR. /// [out] The buffer to receive TF_INPUTPROCESSORPROFILE. // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfinputprocessorprofilemgr-getprofile HRESULT GetProfile( // DWORD dwProfileType, LANGID langid, REFCLSID clsid, REFGUID guidProfile, HKL hkl, TF_INPUTPROCESSORPROFILE *pProfile ); TF_INPUTPROCESSORPROFILE GetProfile([In] TF_PROFILETYPE dwProfileType, [In] LANGID langid, in Guid clsid, in Guid guidProfile, [In, Optional] HKL hkl); /// The ITfInputProcessorProfileMgr::EnumProfiles method returns profiles to be enumerated. /// [in] langid of the profiles to be enumerated. If langid is 0, all profiles will be enumerated. /// [out] The pointer to receive a pointer of IEnumTfInputProcessorProfiles interface. // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfinputprocessorprofilemgr-enumprofiles HRESULT // EnumProfiles( LANGID langid, IEnumTfInputProcessorProfiles **ppEnum ); IEnumTfInputProcessorProfiles EnumProfiles([In] LANGID langid); /// /// The ITfInputProcessorProfileMgr::ReleaseInputProcessor method deactivates the profiles belonging to the text services /// of the specified CLSID and releases the instance of ITfTextInputProcessorEx interface. /// /// [in] CLSID of the textservice to be released. /// /// [in] /// /// /// Value /// Meaning /// /// /// TF_RIP_FLAG_FREEUNUSEDLIBRARIES /// /// If this bit is on, this method calls CoFreeUnusedLibrariesEx() so the text services DLL might be freed if it does not have /// any more COM/DLL reference. Warning: This flag could cause some other unrelated COM/DLL free. /// /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfinputprocessorprofilemgr-releaseinputprocessor HRESULT // ReleaseInputProcessor( REFCLSID rclsid, DWORD dwFlags ); void ReleaseInputProcessor(in Guid rclsid, [In] TF_RIP_FLAG dwFlags); /// /// The ITfInputProcessorProfileMgr::RegisterProfile method registers the text service and the profile. /// [in] CLSID of the text service. /// [in] The language id of the profile. /// [in] The GUID to identify the profile. /// [in, size_is(cchDesc)] The description of the profile. /// [in] The length of pchDesc. /// [in, size_is(cchFile] The full path of the icon file. /// [in] The length of pchIconFile. /// [in] The icon index of the icon file for this profile. /// [in] The substitute hkl of this profile. /// [in] Unused. this must be 0. /// [in] True if this profile is enabled by default. /// /// [in] The combination of the following bits: /// /// /// Value /// Meaning /// /// /// TF_RP_HIDDENINSETTINGUI /// This profile will not appear in the setting UI. /// /// /// TF_RP_LOCALPROCESS /// This profile is available only on the local process. /// /// /// TF_RP_LOCALTHREAD /// This profile is available only on the local thread. /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfinputprocessorprofilemgr-registerprofile HRESULT // RegisterProfile( REFCLSID rclsid, LANGID langid, REFGUID guidProfile, const WCHAR *pchDesc, ULONG cchDesc, const WCHAR // *pchIconFile, ULONG cchFile, ULONG uIconIndex, HKL hklsubstitute, DWORD dwPreferredLayout, BOOL bEnabledByDefault, DWORD // dwFlags ); void RegisterProfile(in Guid rclsid, [In] LANGID langid, in Guid guidProfile, [In, MarshalAs(UnmanagedType.LPWStr)] string pchDesc, uint cchDesc, [In, MarshalAs(UnmanagedType.LPWStr)] string pchIconFile, uint cchFile, uint uIconIndex, [In] HKL hklSubstitute, uint dwPreferredLayout, [In, MarshalAs(UnmanagedType.Bool)] bool bEnabledByDefault, [In] TF_RP dwFlags); /// The ITfInputProcessorProfileMgr::UnregisterProfile method unregisters the text service and the profile. /// [in] CLSID of the text service. /// [in] The language id of the profile. /// [in] The GUID to identify the profile. /// /// [in] The combination of the following bits: /// /// /// Value /// Meaning /// /// /// TF_URP_ALLPROFILES /// /// If this bit is on, UnregistrProfile unregisters all profiles of the rclsid parameter. The langid and guidProfile parameters /// are ignored. /// /// /// /// TF_URP_LOCALPROCESS /// The profile was registered on the local process. /// /// /// TF_URP_LOCALTHREAD /// The profile was registered on the local thread. /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfinputprocessorprofilemgr-unregisterprofile HRESULT // UnregisterProfile( REFCLSID rclsid, LANGID langid, REFGUID guidProfile, DWORD dwFlags ); void UnregisterProfile(in Guid rclsid, [In, Optional] LANGID langid, [Optional] in Guid guidProfile, [In] TF_URP dwFlags); /// This method returns the current active profile. /// /// [in] The category id for the profile. This must be GUID_TFCAT_TIP_KEYBOARD. Only GUID_TFCAT_TIP_KEYBOARD is supported. /// /// [out] The buffer to receive the profile information. // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfinputprocessorprofilemgr-getactiveprofile HRESULT // GetActiveProfile( REFGUID catid, TF_INPUTPROCESSORPROFILE *pProfile ); TF_INPUTPROCESSORPROFILE GetActiveProfile(in Guid catid); } /// /// The ITfInputProcessorProfiles interface is implemented by the TSF manager and used by an application or text service to /// manipulate the language profile of one or more text services. /// /// /// To obtain a pointer to this interface, call CoCreateInstance with CLSID_TF_InputProcessorProfiles. /// Examples /// ITfInputProcessorProfiles /// /// HRESULT hr; /// ITfInputProcessorProfiles *pProfiles; /// //Create the object. /// hr = CoCreateInstance( CLSID_TF_InputProcessorProfiles, NULL, CLSCTX_INPROC_SERVER, IID_ITfInputProcessorProfiles, (LPVOID*)&pProfiles); /// if(SUCCEEDED(hr)) { /// //Use the interface. /// //Release the interface. /// pProfiles->Release(); /// } /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nn-msctf-itfinputprocessorprofiles [PInvokeData("msctf.h", MSDNShortId = "NN:msctf.ITfInputProcessorProfiles")] [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("1F02B6C5-7842-4EE6-8A0B-9A24183A95CA"), CoClass(typeof(TF_InputProcessorProfiles))] public interface ITfInputProcessorProfiles { /// Adds a text service to Text Services Foundation (TSF). /// Contains the CLSID of the text service to register. // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfinputprocessorprofiles-register HRESULT Register( // REFCLSID rclsid ); void Register(in Guid rclsid); /// Removes a text service from TSF. /// Contains the text service CLSID to unregister. // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfinputprocessorprofiles-unregister HRESULT Unregister( // REFCLSID rclsid ); void Unregister(in Guid rclsid); /// Creates a language profile that consists of a specific text service and a specific language identifier. /// Contains the text service CLSID. /// /// Contains a LANGID value that specifies the language identifier of the profile that the text service is added to. If /// this contains -1, the text service is added to all languages. /// /// /// Contains a GUID value that identifies the language profile. This is the value obtained by /// ITfInputProcessorProfiles::GetActiveLanguageProfile when the profile is active. /// /// /// Pointer to a WCHAR buffer that contains the description string for the text service in the profile. This is the text /// service name displayed in the language bar. /// /// /// Contains the length, in characters, of the description string in pchDesc. If this contains -1, pchDesc is assumed to be a /// NULL-terminated string. /// /// /// /// Pointer to a WCHAR buffer that contains the path and file name of the file that contains the icon to be displayed in /// the language bar for the text service in the profile. This file can be an executable (.exe), DLL (.dll) or icon (.ico) file. /// /// This parameter is optional and can be NULL. In this case, a default icon is displayed for the text service. /// /// /// Contains the length, in characters, of the icon file string in pchIconFile. If this contains -1, pchIconFile is assumed to /// be a NULL-terminated string. This parameter is ignored if pchIconFile is NULL. /// /// /// Contains the zero-based index of the icon in pchIconFile to be displayed in the language bar for the text service in the /// profile. This parameter is ignored if pchIconFile is NULL. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfinputprocessorprofiles-addlanguageprofile HRESULT // AddLanguageProfile( REFCLSID rclsid, LANGID langid, REFGUID guidProfile, const WCHAR *pchDesc, ULONG cchDesc, const WCHAR // *pchIconFile, ULONG cchFile, ULONG uIconIndex ); void AddLanguageProfile(in Guid rclsid, [In] LANGID langid, in Guid guidProfile, [In, MarshalAs(UnmanagedType.LPWStr)] string pchDesc, uint cchDesc, [In, MarshalAs(UnmanagedType.LPWStr), Optional] string? pchIconFile, [Optional] uint cchFile, [Optional] uint uIconIndex); /// Removes a language profile. /// Contains the text service CLSID. /// Contains a LANGID value that specifies the language identifier of the profile. /// /// Contains a GUID value that identifies the language profile. This is the value specified in /// ITfInputProcessorProfiles::AddLanguageProfile when the profile was added. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfinputprocessorprofiles-removelanguageprofile HRESULT // RemoveLanguageProfile( REFCLSID rclsid, LANGID langid, REFGUID guidProfile ); void RemoveLanguageProfile(in Guid rclsid, [In] LANGID langid, in Guid guidProfile); /// Obtains an enumerator that contains the class identifiers of all registered text services. /// /// Pointer to an IEnumGUID interface pointer that receives the enumerator object. The enumerator contains the CLSID for /// each registered text service. The caller must release this object when it is no longer required. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfinputprocessorprofiles-enuminputprocessorinfo HRESULT // EnumInputProcessorInfo( IEnumGUID **ppEnum ); IEnumGUID EnumInputProcessorInfo(); /// Obtains the default profile for a specific language. /// Contains a LANGID value that specifies which language to obtain the default profile for. /// /// Contains a GUID value that identifies the category that the text service is registered under. This can be a user-defined /// category or one of the predefined category values. /// /// /// Pointer to a CLSID value that receives the class identifier of the default text service for the language. /// /// Pointer to a GUID value that receives the identifier of the default profile for the language. // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfinputprocessorprofiles-getdefaultlanguageprofile HRESULT // GetDefaultLanguageProfile( LANGID langid, REFGUID catid, CLSID *pclsid, GUID *pguidProfile ); void GetDefaultLanguageProfile([In] LANGID langid, in Guid catid, out Guid pclsid, out Guid pguidProfile); /// Sets the default profile for a specific language. /// Contains a LANGID value that specifies which language to set the default profile for. /// Contains the CLSID of the text service that will be the default for the language. /// Contains a GUID value that identifies the language profile that will be the default. // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfinputprocessorprofiles-setdefaultlanguageprofile HRESULT // SetDefaultLanguageProfile( LANGID langid, REFCLSID rclsid, REFGUID guidProfiles ); void SetDefaultLanguageProfile([In] LANGID langid, in Guid rclsid, in Guid guidProfiles); /// Sets the active text service for a specific language. /// Contains the CLSID of the text service to make active. /// /// Contains a LANGID value that specifies which language to set the default profile for. This method fails if this is /// not the currently active language. /// /// Contains a GUID value that identifies the language profile to make active. // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfinputprocessorprofiles-activatelanguageprofile HRESULT // ActivateLanguageProfile( REFCLSID rclsid, LANGID langid, REFGUID guidProfiles ); void ActivateLanguageProfile(in Guid rclsid, [In] LANGID langid, in Guid guidProfiles); /// Obtains the identifier of the currently active language profile for a specific text service. /// Contains the text service CLSID. /// Pointer to a LANGID value that receives the active profile language identifier. /// /// Pointer to a GUID value that receives the language profile identifier. This is the value specified in /// ITfInputProcessorProfiles::AddLanguageProfile when the profile was added. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfinputprocessorprofiles-getactivelanguageprofile HRESULT // GetActiveLanguageProfile( REFCLSID rclsid, LANGID *plangid, GUID *pguidProfile ); void GetActiveLanguageProfile(in Guid rclsid, out LANGID plangid, out Guid pguidProfile); /// Obtains the description string for a language profile. /// Contains the CLSID of the text service to obtain the profile description for. /// Contains a LANGID value that specifies which language to obtain the profile description for. /// Contains a GUID value that identifies the language to obtain the profile description for. /// /// Pointer to a BSTR value that receives the description string. The caller is responsible for freeing this memory using /// SysFreeString when it is no longer required. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfinputprocessorprofiles-getlanguageprofiledescription // HRESULT GetLanguageProfileDescription( REFCLSID rclsid, LANGID langid, REFGUID guidProfile, BSTR *pbstrProfile ); [return: MarshalAs(UnmanagedType.BStr)] string GetLanguageProfileDescription(in Guid rclsid, [In] LANGID langid, in Guid guidProfile); /// Obtains the identifier of the currently active language. /// Pointer to a LANGID value that receives the language identifier of the currently active language. // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfinputprocessorprofiles-getcurrentlanguage HRESULT // GetCurrentLanguage( LANGID *plangid ); LANGID GetCurrentLanguage(); /// Sets the currently active language. /// Contains the LANGID of the language to make active. // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfinputprocessorprofiles-changecurrentlanguage HRESULT // ChangeCurrentLanguage( LANGID langid ); void ChangeCurrentLanguage([In] LANGID langid); /// Obtains a list of the installed languages. /// /// Pointer to a LANGID pointer that receives the array of identifiers of the currently installed languages. The number /// of identifiers placed in this array is supplied in pulCount. The array is allocated by this method. The caller must free /// this memory when it is no longer required using CoTaskMemFree. /// /// Pointer to a ULONG value the receives the number of identifiers placed in the array at ppLangId. // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfinputprocessorprofiles-getlanguagelist HRESULT // GetLanguageList( LANGID **ppLangId, ULONG *pulCount ); void GetLanguageList(out SafeCoTaskMemHandle ppLangId, out uint pulCount); /// Obtains an enumerator that contains all of the profiles for a specific langauage. /// Contains a LANGID value that specifies the language to obtain an enumerator for. /// Pointer to an IEnumTfLanguageProfiles interface pointer that receives the enumerator object. // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfinputprocessorprofiles-enumlanguageprofiles HRESULT // EnumLanguageProfiles( LANGID langid, IEnumTfLanguageProfiles **ppEnum ); IEnumTfLanguageProfiles EnumLanguageProfiles([In] LANGID langid); /// Enables or disables a language profile for the current user. /// Contains the CLSID of the text service of the profile to be enabled or disabled. /// Contains a LANGID value that specifies the language of the profile to be enabled or disabled. /// Contains a GUID value that identifies the profile to be enabled or disabled. /// /// Contains a BOOL value that specifies if the profile will be enabled or disabled. If this contains a nonzero value, /// the profile will be enabled. If this contains zero, the profile will be disabled. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfinputprocessorprofiles-enablelanguageprofile HRESULT // EnableLanguageProfile( REFCLSID rclsid, LANGID langid, REFGUID guidProfile, BOOL fEnable ); void EnableLanguageProfile(in Guid rclsid, [In] LANGID langid, in Guid guidProfile, [In, MarshalAs(UnmanagedType.Bool)] bool fEnable); /// Determines if a specific language profile is enabled or disabled. /// Contains the CLSID of the text service of the profile in question. /// Contains a LANGID value that specifies the language of the profile in question. /// Contains a GUID value that identifies the profile in question. /// /// Pointer to a BOOL value that receives a value that specifies if the profile is enabled or disabled. If this receives /// a nonzero value, the profile is enabled. If this receives zero, the profile is disabled. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfinputprocessorprofiles-isenabledlanguageprofile HRESULT // IsEnabledLanguageProfile( REFCLSID rclsid, LANGID langid, REFGUID guidProfile, BOOL *pfEnable ); [return: MarshalAs(UnmanagedType.Bool)] bool IsEnabledLanguageProfile(in Guid rclsid, [In] LANGID langid, in Guid guidProfile); /// Enables or disables a language profile by default for all users. /// Contains the CLSID of the text service of the profile to be enabled or disabled. /// Contains a LANGID value that specifies the language of the profile to be enabled or disabled. /// Contains a GUID value that identifies the profile to be enabled or disabled. /// /// Contains a BOOL value that specifies if the profile is enabled or disabled. If this contains a nonzero value, the /// profile is enabled. If this contains zero, the profile is disabled. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfinputprocessorprofiles-enablelanguageprofilebydefault // HRESULT EnableLanguageProfileByDefault( REFCLSID rclsid, LANGID langid, REFGUID guidProfile, BOOL fEnable ); [return: MarshalAs(UnmanagedType.Bool)] bool EnableLanguageProfileByDefault(in Guid rclsid, [In] LANGID langid, in Guid guidProfile); /// Sets a substitute keyboard layout for the specified language profile. /// Contains the CLSID of the text service of the profile in question. /// Contains a LANGID value that specifies the language of the profile in question. /// Contains a GUID value that identifies the profile in question. /// /// Contains an HKL value that specifies the input locale identifier for the substitute keyboard. Obtain this value by /// calling LoadKeyboardLayout. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfinputprocessorprofiles-substitutekeyboardlayout HRESULT // SubstituteKeyboardLayout( REFCLSID rclsid, LANGID langid, REFGUID guidProfile, HKL hKL ); void SubstituteKeyboardLayout(in Guid rclsid, [In] LANGID langid, in Guid guidProfile, [In] HKL hKL); } /// /// This interface is implemented by the TSF manager and used by a text service or application to set the display description of the /// language profile. To obtain an instance of this interface, call ITfInputProcessorProfiles::QueryInterface with IID_ITfInputProcessorProfilesEx. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nn-msctf-itfinputprocessorprofilesex [PInvokeData("msctf.h", MSDNShortId = "NN:msctf.ITfInputProcessorProfilesEx")] [ComImport, Guid("892F230F-FE00-4A41-A98E-FCD6DE0D35EF"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), CoClass(typeof(TF_InputProcessorProfiles))] public interface ITfInputProcessorProfilesEx : ITfInputProcessorProfiles { /// Adds a text service to Text Services Foundation (TSF). /// Contains the CLSID of the text service to register. // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfinputprocessorprofiles-register HRESULT Register( // REFCLSID rclsid ); new void Register(in Guid rclsid); /// Removes a text service from TSF. /// Contains the text service CLSID to unregister. // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfinputprocessorprofiles-unregister HRESULT Unregister( // REFCLSID rclsid ); new void Unregister(in Guid rclsid); /// Creates a language profile that consists of a specific text service and a specific language identifier. /// Contains the text service CLSID. /// /// Contains a LANGID value that specifies the language identifier of the profile that the text service is added to. If /// this contains -1, the text service is added to all languages. /// /// /// Contains a GUID value that identifies the language profile. This is the value obtained by /// ITfInputProcessorProfiles::GetActiveLanguageProfile when the profile is active. /// /// /// Pointer to a WCHAR buffer that contains the description string for the text service in the profile. This is the text /// service name displayed in the language bar. /// /// /// Contains the length, in characters, of the description string in pchDesc. If this contains -1, pchDesc is assumed to be a /// NULL-terminated string. /// /// /// /// Pointer to a WCHAR buffer that contains the path and file name of the file that contains the icon to be displayed in /// the language bar for the text service in the profile. This file can be an executable (.exe), DLL (.dll) or icon (.ico) file. /// /// This parameter is optional and can be NULL. In this case, a default icon is displayed for the text service. /// /// /// Contains the length, in characters, of the icon file string in pchIconFile. If this contains -1, pchIconFile is assumed to /// be a NULL-terminated string. This parameter is ignored if pchIconFile is NULL. /// /// /// Contains the zero-based index of the icon in pchIconFile to be displayed in the language bar for the text service in the /// profile. This parameter is ignored if pchIconFile is NULL. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfinputprocessorprofiles-addlanguageprofile HRESULT // AddLanguageProfile( REFCLSID rclsid, LANGID langid, REFGUID guidProfile, const WCHAR *pchDesc, ULONG cchDesc, const WCHAR // *pchIconFile, ULONG cchFile, ULONG uIconIndex ); new void AddLanguageProfile(in Guid rclsid, [In] LANGID langid, in Guid guidProfile, [In, MarshalAs(UnmanagedType.LPWStr)] string pchDesc, uint cchDesc, [In, MarshalAs(UnmanagedType.LPWStr), Optional] string? pchIconFile, [Optional] uint cchFile, [Optional] uint uIconIndex); /// Removes a language profile. /// Contains the text service CLSID. /// Contains a LANGID value that specifies the language identifier of the profile. /// /// Contains a GUID value that identifies the language profile. This is the value specified in /// ITfInputProcessorProfiles::AddLanguageProfile when the profile was added. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfinputprocessorprofiles-removelanguageprofile HRESULT // RemoveLanguageProfile( REFCLSID rclsid, LANGID langid, REFGUID guidProfile ); new void RemoveLanguageProfile(in Guid rclsid, [In] LANGID langid, in Guid guidProfile); /// Obtains an enumerator that contains the class identifiers of all registered text services. /// /// Pointer to an IEnumGUID interface pointer that receives the enumerator object. The enumerator contains the CLSID for /// each registered text service. The caller must release this object when it is no longer required. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfinputprocessorprofiles-enuminputprocessorinfo HRESULT // EnumInputProcessorInfo( IEnumGUID **ppEnum ); new IEnumGUID EnumInputProcessorInfo(); /// Obtains the default profile for a specific language. /// Contains a LANGID value that specifies which language to obtain the default profile for. /// /// Contains a GUID value that identifies the category that the text service is registered under. This can be a user-defined /// category or one of the predefined category values. /// /// /// Pointer to a CLSID value that receives the class identifier of the default text service for the language. /// /// Pointer to a GUID value that receives the identifier of the default profile for the language. // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfinputprocessorprofiles-getdefaultlanguageprofile HRESULT // GetDefaultLanguageProfile( LANGID langid, REFGUID catid, CLSID *pclsid, GUID *pguidProfile ); new void GetDefaultLanguageProfile([In] LANGID langid, in Guid catid, out Guid pclsid, out Guid pguidProfile); /// Sets the default profile for a specific language. /// Contains a LANGID value that specifies which language to set the default profile for. /// Contains the CLSID of the text service that will be the default for the language. /// Contains a GUID value that identifies the language profile that will be the default. // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfinputprocessorprofiles-setdefaultlanguageprofile HRESULT // SetDefaultLanguageProfile( LANGID langid, REFCLSID rclsid, REFGUID guidProfiles ); new void SetDefaultLanguageProfile([In] LANGID langid, in Guid rclsid, in Guid guidProfiles); /// Sets the active text service for a specific language. /// Contains the CLSID of the text service to make active. /// /// Contains a LANGID value that specifies which language to set the default profile for. This method fails if this is /// not the currently active language. /// /// Contains a GUID value that identifies the language profile to make active. // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfinputprocessorprofiles-activatelanguageprofile HRESULT // ActivateLanguageProfile( REFCLSID rclsid, LANGID langid, REFGUID guidProfiles ); new void ActivateLanguageProfile(in Guid rclsid, [In] LANGID langid, in Guid guidProfiles); /// Obtains the identifier of the currently active language profile for a specific text service. /// Contains the text service CLSID. /// Pointer to a LANGID value that receives the active profile language identifier. /// /// Pointer to a GUID value that receives the language profile identifier. This is the value specified in /// ITfInputProcessorProfiles::AddLanguageProfile when the profile was added. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfinputprocessorprofiles-getactivelanguageprofile HRESULT // GetActiveLanguageProfile( REFCLSID rclsid, LANGID *plangid, GUID *pguidProfile ); new void GetActiveLanguageProfile(in Guid rclsid, out LANGID plangid, out Guid pguidProfile); /// Obtains the description string for a language profile. /// Contains the CLSID of the text service to obtain the profile description for. /// Contains a LANGID value that specifies which language to obtain the profile description for. /// Contains a GUID value that identifies the language to obtain the profile description for. /// /// Pointer to a BSTR value that receives the description string. The caller is responsible for freeing this memory using /// SysFreeString when it is no longer required. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfinputprocessorprofiles-getlanguageprofiledescription // HRESULT GetLanguageProfileDescription( REFCLSID rclsid, LANGID langid, REFGUID guidProfile, BSTR *pbstrProfile ); [return: MarshalAs(UnmanagedType.BStr)] new string GetLanguageProfileDescription(in Guid rclsid, [In] LANGID langid, in Guid guidProfile); /// Obtains the identifier of the currently active language. /// Pointer to a LANGID value that receives the language identifier of the currently active language. // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfinputprocessorprofiles-getcurrentlanguage HRESULT // GetCurrentLanguage( LANGID *plangid ); new LANGID GetCurrentLanguage(); /// Sets the currently active language. /// Contains the LANGID of the language to make active. // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfinputprocessorprofiles-changecurrentlanguage HRESULT // ChangeCurrentLanguage( LANGID langid ); new void ChangeCurrentLanguage([In] LANGID langid); /// Obtains a list of the installed languages. /// /// Pointer to a LANGID pointer that receives the array of identifiers of the currently installed languages. The number /// of identifiers placed in this array is supplied in pulCount. The array is allocated by this method. The caller must free /// this memory when it is no longer required using CoTaskMemFree. /// /// Pointer to a ULONG value the receives the number of identifiers placed in the array at ppLangId. // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfinputprocessorprofiles-getlanguagelist HRESULT // GetLanguageList( LANGID **ppLangId, ULONG *pulCount ); new void GetLanguageList(out SafeCoTaskMemHandle ppLangId, out uint pulCount); /// Obtains an enumerator that contains all of the profiles for a specific langauage. /// Contains a LANGID value that specifies the language to obtain an enumerator for. /// Pointer to an IEnumTfLanguageProfiles interface pointer that receives the enumerator object. // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfinputprocessorprofiles-enumlanguageprofiles HRESULT // EnumLanguageProfiles( LANGID langid, IEnumTfLanguageProfiles **ppEnum ); new IEnumTfLanguageProfiles EnumLanguageProfiles([In] LANGID langid); /// Enables or disables a language profile for the current user. /// Contains the CLSID of the text service of the profile to be enabled or disabled. /// Contains a LANGID value that specifies the language of the profile to be enabled or disabled. /// Contains a GUID value that identifies the profile to be enabled or disabled. /// /// Contains a BOOL value that specifies if the profile will be enabled or disabled. If this contains a nonzero value, /// the profile will be enabled. If this contains zero, the profile will be disabled. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfinputprocessorprofiles-enablelanguageprofile HRESULT // EnableLanguageProfile( REFCLSID rclsid, LANGID langid, REFGUID guidProfile, BOOL fEnable ); new void EnableLanguageProfile(in Guid rclsid, [In] LANGID langid, in Guid guidProfile, [In, MarshalAs(UnmanagedType.Bool)] bool fEnable); /// Determines if a specific language profile is enabled or disabled. /// Contains the CLSID of the text service of the profile in question. /// Contains a LANGID value that specifies the language of the profile in question. /// Contains a GUID value that identifies the profile in question. /// /// Pointer to a BOOL value that receives a value that specifies if the profile is enabled or disabled. If this receives /// a nonzero value, the profile is enabled. If this receives zero, the profile is disabled. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfinputprocessorprofiles-isenabledlanguageprofile HRESULT // IsEnabledLanguageProfile( REFCLSID rclsid, LANGID langid, REFGUID guidProfile, BOOL *pfEnable ); [return: MarshalAs(UnmanagedType.Bool)] new bool IsEnabledLanguageProfile(in Guid rclsid, [In] LANGID langid, in Guid guidProfile); /// Enables or disables a language profile by default for all users. /// Contains the CLSID of the text service of the profile to be enabled or disabled. /// Contains a LANGID value that specifies the language of the profile to be enabled or disabled. /// Contains a GUID value that identifies the profile to be enabled or disabled. /// /// Contains a BOOL value that specifies if the profile is enabled or disabled. If this contains a nonzero value, the /// profile is enabled. If this contains zero, the profile is disabled. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfinputprocessorprofiles-enablelanguageprofilebydefault // HRESULT EnableLanguageProfileByDefault( REFCLSID rclsid, LANGID langid, REFGUID guidProfile, BOOL fEnable ); [return: MarshalAs(UnmanagedType.Bool)] new bool EnableLanguageProfileByDefault(in Guid rclsid, [In] LANGID langid, in Guid guidProfile); /// Sets a substitute keyboard layout for the specified language profile. /// Contains the CLSID of the text service of the profile in question. /// Contains a LANGID value that specifies the language of the profile in question. /// Contains a GUID value that identifies the profile in question. /// /// Contains an HKL value that specifies the input locale identifier for the substitute keyboard. Obtain this value by /// calling LoadKeyboardLayout. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfinputprocessorprofiles-substitutekeyboardlayout HRESULT // SubstituteKeyboardLayout( REFCLSID rclsid, LANGID langid, REFGUID guidProfile, HKL hKL ); new void SubstituteKeyboardLayout(in Guid rclsid, [In] LANGID langid, in Guid guidProfile, [In] HKL hKL); /// /// Redistributable: Requires TSF 1.0 on Windows 2000. /// Header: Declared in Msctf.idl and Msctf.h. /// Library: Included as a resource in Msctf.dll. /// /// /// /// /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfinputprocessorprofilesex-setlanguageprofiledisplayname // HRESULT SetLanguageProfileDisplayName( REFCLSID rclsid, LANGID langid, REFGUID guidProfile, const WCHAR *pchFile, ULONG // cchFile, ULONG uResId ); void SetLanguageProfileDisplayName(in Guid rclsid, [In] LANGID langid, in Guid guidProfile, [In, MarshalAs(UnmanagedType.LPWStr)] string pchFile, uint cchFile, uint uResId); } /// /// This interface is implemented by the TSF manager and is used by an application or text service to manipulate the substitute /// input locale identifier (keyboard layout) of a text service profile. The interface ID is IID_ITfInputProcessorProfileSubstituteLayout. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nn-msctf-itfinputprocessorprofilesubstitutelayout [PInvokeData("msctf.h", MSDNShortId = "NN:msctf.ITfInputProcessorProfileSubstituteLayout")] [ComImport, Guid("4FD67194-1002-4513-BFF2-C0DDF6258552"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] public interface ITfInputProcessorProfileSubstituteLayout { /// Retrieves the input locale identifier (keyboard layout). /// Contains the class identifier of the text service. /// Specifies the language of the profile. See Language Identifiers. /// Identifies the profile GUID. /// Pointer to an HKL value that specifies the substitute input locale identifier. /// /// This method can return one of these values. /// /// /// Value /// Description /// /// /// S_OK /// The method was successful. /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfinputprocessorprofilesubstitutelayout-getsubstitutekeyboardlayout // HRESULT GetSubstituteKeyboardLayout( REFCLSID rclsid, LANGID langid, REFGUID guidProfile, HKL *phKL ); [PreserveSig] HRESULT GetSubstituteKeyboardLayout(in Guid rclsid, [In] LANGID langid, in Guid guidProfile, out HKL phKL); } /// /// The ITfInsertAtSelection interface is implemented by the manager and is used by a text service to insert text or an /// embedded object in a context. The text service obtains this interface by calling ITfContext::QueryInterface. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nn-msctf-itfinsertatselection [PInvokeData("msctf.h", MSDNShortId = "NN:msctf.ITfInsertAtSelection")] [ComImport, Guid("55CE16BA-3014-41C1-9CEB-FADE1446AC6C"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] public interface ITfInsertAtSelection { /// Inserts text at the selection or insertion point. /// Identifies the edit context. This is obtained from ITfDocumentMgr::CreateContext or ITfEditSession::DoEditSession. /// /// Bit field with one of the following values. /// /// /// Value /// Meaning /// /// /// TF_IAS_NOQUERY /// ppRange is NULL. This flag cannot be combined with the TF_IAS_QUERYONLY flag. /// /// /// TF_IAS_QUERYONLY /// /// The context is not modified, but ppRange is set as if the insert had occurred. Read-only access is sufficient. If this flag /// is not set, ec must have read/write access. This flag cannot be combined with the TF_IAS_NOQUERY flag. /// /// /// /// TF_IAS_NO_DEFAULT_COMPOSITION /// /// The manager will not create a default composition if a composition is required. The caller must create a composition object /// that covers the inserted text before releasing the context lock. /// /// /// /// /// Specifies the text to insert. /// Specifies the character count of the text in pchText. /// Receives the position of the inserted object. /// To insert an IDataObject object instead of text, use ITfInsertAtSelection::InsertEmbeddedAtSelection. // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfinsertatselection-inserttextatselection HRESULT // InsertTextAtSelection( TfEditCookie ec, DWORD dwFlags, const WCHAR *pchText, LONG cch, ITfRange **ppRange ); ITfRange? InsertTextAtSelection([In] TfEditCookie ec, [In] TF_IAS dwFlags, [In, MarshalAs(UnmanagedType.LPWStr)] string pchText, int cch); /// /// The ITfInsertAtSelection::InsertEmbeddedAtSelection method inserts an IDataObject object at the selection or /// insertion point. /// /// Identifies the edit context. This is obtained from ITfDocumentMgr::CreateContext or ITfEditSession::DoEditSession. /// /// Bit field with one of the following values: /// TF_IAS_NOQUERY /// The ppRange parameter is NULL on exit. /// TF_IAS_QUERYONLY /// /// Context is not modified but the ppRange parameter is set as if the insert occurred. Read-only access is sufficient. If this /// flag is not set, the ec parameter must have read/write access. /// /// TF_IAS_NO_DEFAULT_COMPOSITION /// /// The TSF manager does not create a default composition if a composition is required. The caller must create a composition /// object that covers the inserted text before releasing the context lock. /// /// /// Pointer to object to insert. /// Position of the inserted object. Optional. /// /// /// Callers can use the ITfQueryEmbedded::QueryInsertEmbedded method to determine if a particular object type is likely to be /// accepted by this method. /// /// To insert text instead of an IDataObject object, use the ITfInsertAtSelection::InsertTextAtSelection method. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfinsertatselection-insertembeddedatselection HRESULT // InsertEmbeddedAtSelection( TfEditCookie ec, DWORD dwFlags, IDataObject *pDataObject, ITfRange **ppRange ); ITfRange? InsertEmbeddedAtSelection([In] TfEditCookie ec, [In] TF_IAS dwFlags, [In, Optional] IDataObject? pDataObject); } /// /// The ITfKeyEventSink interface is implemented by a text service to receive keyboard and focus event notifications. To /// install this event sink, call ITfKeystrokeMgr::AdviseKeyEventSink. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nn-msctf-itfkeyeventsink [PInvokeData("msctf.h", MSDNShortId = "NN:msctf.ITfKeyEventSink")] [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("AA80E7F5-2021-11D2-93E0-0060B067B86E")] public interface ITfKeyEventSink { /// Called when a TSF text service receives or loses the keyboard focus. /// If TRUE, the test service receives the focus. Otherwise the text service loses the focus. /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfkeyeventsink-onsetfocus HRESULT OnSetFocus( BOOL // fForeground ); [PreserveSig] HRESULT OnSetFocus([In, MarshalAs(UnmanagedType.Bool)] bool fForeground); /// Called to determine if a text service will handle a key down event. /// Pointer to the input context that receives the key event. /// /// Specifies the virtual-key code of the key. For more information about this parameter, see the wParam parameter in WM_KEYDOWN. /// /// /// Specifies the repeat count, scan code, extended-key flag, context code, previous key-state flag, and transition-state flag /// of the key. For more information about this parameter, see the lParam parameter in WM_KEYDOWN. /// /// /// Pointer to a BOOL that, on exit, indicates if the key event would be handled. If this value receives TRUE, the key /// event would be handled. If this value is FALSE, the key event would not be handled. /// /// /// This method can return one of these values. /// /// /// Value /// Description /// /// /// S_OK /// The method was successful. /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfkeyeventsink-ontestkeydown HRESULT OnTestKeyDown( // ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten ); [PreserveSig] HRESULT OnTestKeyDown([In] ITfContext pic, [In] WPARAM wParam, [In] LPARAM lParam, [Out, MarshalAs(UnmanagedType.Bool)] out bool pfEaten); /// Called to determine if a text service will handle a key up event. /// Pointer to the input context that receives the key event. /// /// Specifies the virtual-key code of the key. For more information about this parameter, see the wParam parameter in WM_KEYUP. /// /// /// Specifies the repeat count, scan code, extended-key flag, context code, previous key-state flag, and transition-state flag /// of the key. For more information about this parameter, see the lParam parameter in WM_KEYUP. /// /// /// Pointer to a BOOL that, on exit, indicates if the key event would be handled. If this value receives TRUE, the key /// event would be handled. If this value receives FALSE, the key event would not be handled. /// /// /// This method can return one of these values. /// /// /// Value /// Description /// /// /// S_OK /// The method was successful. /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfkeyeventsink-ontestkeyup HRESULT OnTestKeyUp( ITfContext // *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten ); [PreserveSig] HRESULT OnTestKeyUp([In] ITfContext pic, [In] WPARAM wParam, [In] LPARAM lParam, [Out, MarshalAs(UnmanagedType.Bool)] out bool pfEaten); /// Called when a key down event occurs. /// Pointer to the input context that receives the key event. /// /// Specifies the virtual-key code of the key. For more information about this parameter, see the wParam parameter in WM_KEYDOWN. /// /// /// Specifies the repeat count, scan code, extended-key flag, context code, previous key-state flag, and transition-state flag /// of the key. For more information about this parameter, see the lParam parameter in WM_KEYDOWN. /// /// /// Pointer to a BOOL that, on exit, indicates if the key event was handled. If this value receives TRUE, the key event /// was handled. If this value is FALSE, the key event was not handled. /// /// /// This method can return one of these values. /// /// /// Value /// Description /// /// /// S_OK /// The method was successful. /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfkeyeventsink-onkeydown HRESULT OnKeyDown( ITfContext // *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten ); [PreserveSig] HRESULT OnKeyDown([In] ITfContext pic, [In] WPARAM wParam, [In] LPARAM lParam, [Out, MarshalAs(UnmanagedType.Bool)] out bool pfEaten); /// Called when a key up event occurs. /// Pointer to the input context that receives the key event. /// /// Specifies the virtual-key code of the key. For more information about this parameter, see the wParam parameter in WM_KEYUP. /// /// /// Specifies the repeat count, scan code, extended-key flag, context code, previous key-state flag, and transition-state flag /// of the key. For more information about this parameter, see the lParam parameter in WM_KEYUP. /// /// /// Pointer to a BOOL that, on exit, indicates if the key event was handled. If this value receives TRUE, the key event /// was handled. If this value receives FALSE, the key event was not handled. /// /// /// This method can return one of these values. /// /// /// Value /// Description /// /// /// S_OK /// The method was successful. /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfkeyeventsink-onkeyup HRESULT OnKeyUp( ITfContext *pic, // WPARAM wParam, LPARAM lParam, BOOL *pfEaten ); [PreserveSig] HRESULT OnKeyUp([In] ITfContext pic, [In] WPARAM wParam, [In] LPARAM lParam, [Out, MarshalAs(UnmanagedType.Bool)] out bool pfEaten); /// Called when a preserved key event occurs. /// Pointer to the input context that receives the key event. /// Contains the command GUID of the preserved key. /// /// Pointer to a BOOL value that, on exit, indicates if the preserved key event was handled. If this value receives TRUE, /// the preserved key event was handled. If this value receives FALSE, the preserved key event was not handled. /// /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfkeyeventsink-onpreservedkey HRESULT OnPreservedKey( // ITfContext *pic, REFGUID rguid, BOOL *pfEaten ); [PreserveSig] HRESULT OnPreservedKey([In] ITfContext pic, in Guid rguid, [Out, MarshalAs(UnmanagedType.Bool)] out bool pfEaten); } /// /// The ITfKeystrokeMgr interface is implemented by the TSF manager and used by applications and text services to interact /// with the keyboard manager. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nn-msctf-itfkeystrokemgr [PInvokeData("msctf.h", MSDNShortId = "NN:msctf.ITfKeystrokeMgr")] [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("AA80E7F0-2021-11D2-93E0-0060B067B86E")] public interface ITfKeystrokeMgr { /// Installs a key event sink to receive keyboard events. /// Identifier of the client that owns the key event sink. This value is obtained by a previous call to ITfThreadMgr::Activate. /// Pointer to a ITfKeyEventSink interface. /// /// Specifies if this key event sink is made the foreground key event sink. If this is TRUE, this key event sink is made /// the foreground key event sink. Otherwise, this key event sink does not become the foreground key event sink. /// /// /// The foreground key event sink receives all keyboard events. A non-foreground key event sink only receives preserved keys and /// key events that occur over text that marked owned by the client identifier. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfkeystrokemgr-advisekeyeventsink HRESULT // AdviseKeyEventSink( TfClientId tid, ITfKeyEventSink *pSink, BOOL fForeground ); void AdviseKeyEventSink([In] TfClientId tid, [In] ITfKeyEventSink pSink, [In, MarshalAs(UnmanagedType.Bool)] bool fForeground); /// Removes a key event sink. /// /// Identifier of the client that owns the key event sink. This value was passed when the advise sink was installed using ITfKeystrokeMgr::AdviseKeyEventSink. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfkeystrokemgr-unadvisekeyeventsink HRESULT // UnadviseKeyEventSink( TfClientId tid ); void UnadviseKeyEventSink([In] TfClientId tid); /// Obtains the class identifier of the foreground TSF text service. /// Pointer to a CLSID that receives the class identifier of the foreground TSF text service. // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfkeystrokemgr-getforeground HRESULT GetForeground( CLSID // *pclsid ); Guid GetForeground(); /// Determines if the keystroke manager will handle a key down event. /// /// Specifies the virtual-key code of the key. For more information about this parameter, see the wParam parameter in WM_KEYDOWN. /// /// /// Specifies the repeat count, scan code, extended-key flag, context code, previous key-state flag, and transition-state flag /// of the key. For more information about this parameter, see the lParam parameter in WM_KEYDOWN. /// /// /// Pointer to a BOOL that indicates if the key event would be handled. If this value receives TRUE, the key event would /// be handled and the event should not be forwarded to the application. If this value is FALSE, the key event would not /// be handled and the event should be forwarded to the application. /// /// /// /// An application can determine if a key event will be handled by the keystroke manager with this method. If this method is /// successful and pfEaten receives TRUE, the application should call ITfKeystrokeMgr::KeyDown. If this method does not /// return S_OK or pfEaten receives FALSE, the application should not call ITfKeystrokeMgr::KeyDown . The /// following is an example of how this is implemented. /// /// /// if(msg.message == WM_KEYDOWN) { if( pKeyboardMgr->TestKeyDown(msg.wParam, msg.lParam, &fEaten) == S_OK && fEaten && pKeyboardMgr->KeyDown(msg.wParam, msg.lParam, &fEaten) == S_OK && fEaten) { //The key was handled by the keystroke manager or a TSF text service. Do not pass the key to the application. continue; } else { //Let the application process the key. } } /// /// /// If the keystroke manager does not handle the key event, it passes the key event to the TSF text services by calling the text /// service ITfKeyEventSink::OnTestKeyDown method. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfkeystrokemgr-testkeydown HRESULT TestKeyDown( WPARAM // wParam, LPARAM lParam, BOOL *pfEaten ); [return: MarshalAs(UnmanagedType.Bool)] bool TestKeyDown([In] WPARAM wParam, [In] LPARAM lParam); /// Determines if the keystroke manager will handle a key up event. /// /// Specifies the virtual-key code of the key. For more information about this parameter, see the wParam parameter in WM_KEYUP. /// /// /// Specifies the repeat count, scan code, extended-key flag, context code, previous key-state flag, and transition-state flag /// of the key. For more information about this parameter, see the lParam parameter in WM_KEYUP. /// /// /// Pointer to a BOOL that indicates if the key event is handled. If this value receives TRUE, the key event is handled /// and the event should not be forwarded to the application. If this value is FALSE, the key event is not handled and /// the event should be forwarded to the application. /// /// /// /// An application can determine if a key event is handled by the keystroke manager with this method. If this method is /// successful and pfEaten receives TRUE, the application should call ITfKeystrokeMgr::KeyUp. If this method does not /// return S_OK or pfEaten receives FALSE, the application should not call ITfKeystrokeMgr::KeyUp . The following /// is an example of how this is implemented. /// /// /// if(msg.message == WM_KEYUP) { if( pKeyboardMgr->TestKeyUp(msg.wParam, msg.lParam, &fEaten) == S_OK && fEaten && pKeyboardMgr->KeyUp(msg.wParam, msg.lParam, &fEaten) == S_OK && fEaten) { The key was handled by the keystroke manager or a text service. Do not pass the key to the application. continue; } else { //Let the application process the key. } } /// /// /// If the keystroke manager does not handle the key event, it passes the key event to the TSF text service by calling the TSF /// text service ITfKeyEventSink::OnTestKeyUp method. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfkeystrokemgr-testkeyup HRESULT TestKeyUp( WPARAM wParam, // LPARAM lParam, BOOL *pfEaten ); [return: MarshalAs(UnmanagedType.Bool)] bool TestKeyUp([In] WPARAM wParam, [In] LPARAM lParam); /// Passes a key down event to the keystroke manager. /// /// Specifies the virtual-key code of the key. For more information about this parameter, see the wParam parameter in WM_KEYDOWN. /// /// /// Specifies the repeat count, scan code, extended-key flag, context code, previous key-state flag, and transition-state flag /// of the key. For more information about this parameter, see the lParam parameter in WM_KEYDOWN. /// /// /// Pointer to a BOOL that, on exit, indicates if the key event was handled. If this value receives TRUE, the key event /// was handled and the event should not be forwarded to the application. If this value is FALSE, the key event was not /// handled and the event should be forwarded to the application. /// /// /// /// If this method is successful and pfEaten receives TRUE, the application should not process the key down event. If /// this method does not return S_OK or pfEaten receives FALSE, the application should process the key down event. The /// following is an example of how this is implemented. /// /// /// if(msg.message == WM_KEYDOWN) { if( pKeyboardMgr->TestKeyDown(msg.wParam, msg.lParam, &fEaten) == S_OK && fEaten && pKeyboardMgr->KeyDown(msg.wParam, msg.lParam, &fEaten) == S_OK && fEaten) { //The key was handled by the keystroke manager or a TSF text service. Do not pass the key to the application. continue; } else { //Let the application process the key. } } /// /// /// If the keystroke manager does not handle the key event, it passes the key event to TSF text services by calling the TSF text /// service ITfKeyEventSink::OnKeyDown method. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfkeystrokemgr-keydown HRESULT KeyDown( WPARAM wParam, // LPARAM lParam, BOOL *pfEaten ); [return: MarshalAs(UnmanagedType.Bool)] bool KeyDown([In] WPARAM wParam, [In] LPARAM lParam); /// Passes a key up event to the keystroke manager. /// /// Specifies the virtual-key code of the key. For more information about this parameter, see the wParam parameter in WM_KEYUP. /// /// /// Specifies the repeat count, scan code, extended-key flag, context code, previous key-state flag, and transition-state flag /// of the key. For more information about this parameter, see the lParam parameter in WM_KEYUP. /// /// /// Pointer to a BOOL that, on exit, indicates if the key event will be handled. If this value receives TRUE, the key /// event would be handled and the event should not be forwarded to the application. If this value is FALSE, the key /// event would not be handled and the event should be forwarded to the application. /// /// /// /// If this method is successful and pfEaten receives TRUE, the application should not process the key down event. If /// this method does not return S_OK or pfEaten receives FALSE, the application should process the key down event. The /// following is an example of how this is implemented. /// /// /// if(msg.message == WM_KEYUP) { if( pKeyboardMgr->TestKeyUp(msg.wParam, msg.lParam, &fEaten) == S_OK && fEaten && pKeyboardMgr->KeyUp(msg.wParam, msg.lParam, &fEaten) == S_OK && fEaten) { //The key was handled by the keystroke manager or a TSF text service. Do not pass the key to the application. continue; } else { //Let the application process the key. } } /// /// /// If the keystroke manager does not handle the key event, it passes the key event to the text services by a call to the text /// service ITfKeyEventSink::OnKeyUp method. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfkeystrokemgr-keyup HRESULT KeyUp( WPARAM wParam, LPARAM // lParam, BOOL *pfEaten ); [return: MarshalAs(UnmanagedType.Bool)] bool KeyUp([In] WPARAM wParam, [In] LPARAM lParam); /// Obtains the command GUID for a preserved key. /// Pointer to the application context. This value is returned by a previous call to ITfDocumentMgr::CreateContext. /// /// Pointer to a TF_PRESERVEDKEY structure that identifies the preserved key to obtain. The uVKey member contains the /// virtual key code and the uModifiers member identifies the modifiers of the preserved key. The uVKey member /// must be less than 256. /// /// /// Pointer to a GUID value that receives the command GUID of the preserved key. This is the GUID passed in the TSF text service /// call to ITfKeystrokeMgr::PreserveKey. This value receives GUID_NULL if the preserved key is not found. /// /// /// Preserved keys are registered by TSF text services and used to provide keyboard shortcuts to common commands implemented by /// the TSF text service. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfkeystrokemgr-getpreservedkey HRESULT GetPreservedKey( // ITfContext *pic, const TF_PRESERVEDKEY *pprekey, GUID *pguid ); Guid GetPreservedKey([In] ITfContext pic, in TF_PRESERVEDKEY pprekey); /// Determines if a command GUID and key combination is a preserved key. /// /// Specifies the command GUID of the preserved key. This is the GUID passed in the text service call to ITfKeystrokeMgr::PreserveKey. /// /// /// Pointer to a TF_PRESERVEDKEY structure that identifies the preserved key. The uVKey member contains the virtual key /// code and the uModifiers member identifies the modifiers of the preserved key. The uVKey member must be less /// than 256. /// /// /// Pointer to a BOOL that receives TRUE if the command GUID and key combination is a registered preserved key, or /// FALSE otherwise. /// /// /// Preserved keys are registered by TSF text services and provide keyboard shortcuts to common commands implemented by the TSF /// text service. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfkeystrokemgr-ispreservedkey HRESULT IsPreservedKey( // REFGUID rguid, const TF_PRESERVEDKEY *pprekey, BOOL *pfRegistered ); [return: MarshalAs(UnmanagedType.Bool)] bool IsPreservedKey(in Guid rguid, in TF_PRESERVEDKEY pprekey); /// Registers a preserved key. /// /// Contains the client identifier of the TSF text service. This value is passed to the TSF text service in its /// ITfTextInputProcessor::Activate method. /// /// /// Contains the command GUID of the preserved key. This value is passed to the TSF text service ITfKeyEventSink::OnPreservedKey /// method to identify the preserved key when the preserved key is activated. /// /// /// Pointer to a TF_PRESERVEDKEY structure that specifies the preserved key. The uVKey member contains the virtual key /// code and the uModifiers member identifies the modifiers of the preserved key. /// /// /// Pointer to a Unicode string that contains the description of the preserved key. This cannot be NULL unless cchDesc is zero. /// /// /// Specifies the number of characters in pchDesc. Pass zero for this parameter if no description is required. /// /// /// Preserved keys are registered by TSF text services and provide keyboard shortcuts to common commands implemented by the TSF /// text service. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfkeystrokemgr-preservekey HRESULT PreserveKey( TfClientId // tid, REFGUID rguid, const TF_PRESERVEDKEY *prekey, const WCHAR *pchDesc, ULONG cchDesc ); void PreserveKey([In] TfClientId tid, in Guid rguid, in TF_PRESERVEDKEY prekey, [In, MarshalAs(UnmanagedType.LPWStr)] string pchDesc, uint cchDesc); /// Unregisters a preserved key. /// Contains the command GUID of the preserved key. /// /// Pointer to a TF_PRESERVEDKEY structure that specifies the preserved key. The uVKey member contains the virtual key code and /// the uModifiers member identifies the modifiers of the preserved key. /// /// /// Preserved keys are registered by TSF text services and provide keyboard shortcuts to common commands implemented by the TSF /// text service. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfkeystrokemgr-unpreservekey HRESULT UnpreserveKey( // REFGUID rguid, const TF_PRESERVEDKEY *pprekey ); void UnpreserveKey(in Guid rguid, in TF_PRESERVEDKEY pprekey); /// Modifies the description string of an existing preserved key. /// Contains the command GUID of the preserved key. /// /// Pointer to a Unicode string that contains the new description of the preserved key. This cannot be NULL unless /// cchDesc is zero. /// /// Number of characters in pchDesc. Pass zero for this parameter if no description is required. /// /// Preserved keys are registered by TSF text services and provide keyboard shortcuts to common commands implemented by the TSF /// text service. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfkeystrokemgr-setpreservedkeydescription HRESULT // SetPreservedKeyDescription( REFGUID rguid, const WCHAR *pchDesc, ULONG cchDesc ); void SetPreservedKeyDescription(in Guid rguid, [In, MarshalAs(UnmanagedType.LPWStr)] string pchDesc, uint cchDesc); /// Obtains the description string of an existing preserved key. /// Contains the command GUID of the preserved key. /// Pointer to a BSTR value the receives the description string. The caller must free this memory using SysFreeString. /// /// Preserved keys are registered by TSF text services and provide keyboard shortcuts to common commands implemented by the TSF /// text service. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfkeystrokemgr-getpreservedkeydescription HRESULT // GetPreservedKeyDescription( REFGUID rguid, BSTR *pbstrDesc ); [return: MarshalAs(UnmanagedType.BStr)] string GetPreservedKeyDescription(in Guid rguid); /// Simulates the execution of a preserved key sequence. /// Pointer to the application context. This value was returned by a previous call to ITfDocumentMgr::CreateContext. /// Contains the command GUID of the preserved key. /// /// Pointer to a BOOL that indicates if the key event was handled. If this value receives TRUE, the key event was /// handled. If this value is FALSE, the key event was not handled. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfkeystrokemgr-simulatepreservedkey HRESULT // SimulatePreservedKey( ITfContext *pic, REFGUID rguid, BOOL *pfEaten ); void SimulatePreservedKey([In] ITfContext pic, in Guid rguid, [Out, MarshalAs(UnmanagedType.Bool)] out bool pfEaten); } /// /// The ITfKeyTraceEventSink interface is implemented by an application or text service to receive key stroke event /// notifications before the event is processed by the target. This advise sink is installed by calling the thread manager /// ITfSource::AdviseSink method with IID_ITfKeyTraceEventSink. /// /// /// /// The difference between ITfKeyTraceEventSink and ITfKeyEventSink events is that ITfKeyTraceEventSink events occur /// before any filtering or processing of the key event occurs. The ITfKeyTraceEventSink events also occur before the target /// application can process the key event. /// /// Examples /// /// HRESULT hr; ITfSource *pSource; hr = pThreadMgr->QueryInterface(IID_ITfSource, (LPVOID*)&pSource); if(SUCCEEDED(hr)) { hr = pSource->AdviseSink(IID_ITfKeyTraceEventSink, pKeyTraceEventSink, &m_dwKeyTraveEventSinkCookie); pSource->Release(); } /// /// /// HRESULT hr; ITfSource *pSource; hr = pThreadMgr->QueryInterface(IID_ITfSource, (LPVOID*)&pSource); if(SUCCEEDED(hr)) { hr = pSource->UnadviseSink(m_dwKeyTraveEventSinkCookie); pSource->Release(); } /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nn-msctf-itfkeytraceeventsink [PInvokeData("msctf.h", MSDNShortId = "NN:msctf.ITfKeyTraceEventSink")] [ComImport, Guid("1CD4C13B-1C36-4191-A70A-7F3E611F367D"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] public interface ITfKeyTraceEventSink { /// Called when a key down event occurs. /// /// The WPARAM of the key event. For more information about this parameter, see the wParam parameter in WM_KEYDOWN. /// /// /// The LPARAM of the key event. For more information about this parameter, see the lParam parameter in WM_KEYDOWN. /// /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfkeytraceeventsink-onkeytracedown HRESULT OnKeyTraceDown( // WPARAM wParam, LPARAM lParam ); [PreserveSig] HRESULT OnKeyTraceDown([In] WPARAM wParam, [In] LPARAM lParam); /// Called when a key up event occurs. /// /// The WPARAM of the key event. For more information about this parameter, see the wParam parameter in WM_KEYUP. /// /// /// The LPARAM of the key event. For more information about this parameter, see the lParam parameter in WM_KEYUP. /// /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfkeytraceeventsink-onkeytraceup HRESULT OnKeyTraceUp( // WPARAM wParam, LPARAM lParam ); [PreserveSig] HRESULT OnKeyTraceUp([In] WPARAM wParam, [In] LPARAM lParam); } /// /// /// The ITfLanguageProfileNotifySink interface is implemented by an application to receive notifications when the language /// profile changes. /// /// /// To install this advise sink, obtain an ITfSource object from an ITfInputProcessorProfiles object by calling /// ITfInputProcessorProfiles::QueryInterface with IID_ITfSource. Then call ITfSource::AdviseSink with IID_ITfLanguageProfileNotifySink. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nn-msctf-itflanguageprofilenotifysink [PInvokeData("msctf.h", MSDNShortId = "NN:msctf.ITfLanguageProfileNotifySink")] [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("43C9FE15-F494-4C17-9DE2-B8A4AC350AA8")] public interface ITfLanguageProfileNotifySink { /// Called when the language profile is about to change. /// Contains a LANGID value the identifies the new language profile. /// /// Pointer to a BOOL value that receives a flag that permits or prevents the language profile change. Receives zero to /// prevent the language profile change or nonzero to permit the language profile change. /// /// /// This method can return one of these values. /// /// /// Value /// Description /// /// /// S_OK /// The method was successful. /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itflanguageprofilenotifysink-onlanguagechange HRESULT // OnLanguageChange( LANGID langid, BOOL *pfAccept ); [PreserveSig] HRESULT OnLanguageChange([In] LANGID langid, [Out, MarshalAs(UnmanagedType.Bool)] out bool pfAccept); /// Called after the language profile has changed. /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itflanguageprofilenotifysink-onlanguagechanged HRESULT OnLanguageChanged(); [PreserveSig] HRESULT OnLanguageChanged(); } /// /// The ITfMessagePump interface is implemented by the TSF manager and is used by an application to obtain messages from the /// application message queue. The methods of this interface are wrappers for the GetMessage and PeekMessage functions. This /// interface enables the TSF manager to perform any necessary pre-message or post-message processing. /// /// /// /// If the application is Unicode, it should use the PeekMessageW and GetMessageW methods. Otherwise, the application should use the /// PeekMessageA and GetMessageA methods. /// /// Examples /// ITfThreadMgr /// /// HRESULT hr; ITfMessagePump *pMessagePump; hr = pThreadManager->QueryInterface(IID_ITfMessagePump, (LPVOID*)&pMessagePump); if(SUCCEEDED(hr)) { //Use the ITfMessagePump interface. //Release the ITfMessagePump interface. pMessagePump->Release(); } /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nn-msctf-itfmessagepump [PInvokeData("msctf.h", MSDNShortId = "NN:msctf.ITfMessagePump")] [ComImport, Guid("8F1B8AD8-0B6B-4874-90C5-BD76011E8F7C"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] public interface ITfMessagePump { /// /// Obtains a message from the message queue and returns if no message is obtained. This is the ANSI version of this method. /// /// Pointer to a MSG structure that receives message data. /// /// Handle to the window whose messages are obtained. The window must belong to the current thread. If this value is /// NULL, this method obtains messages for any window owned by the calling thread. /// /// Specifies the lowest message value to obtain. /// Specifies the highest message value to obtain. /// Specifies how messages are handled. For more information, see the PeekMessage function. /// Pointer to a BOOL that receives the return value from the PeekMessage function. /// /// If wMsgFilterMin and wMsgFilterMax are both zero, this method returns all available messages; that is, no range filtering is performed. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfmessagepump-peekmessagea HRESULT PeekMessageA( LPMSG // pMsg, HWND hwnd, UINT wMsgFilterMin, UINT wMsgFilterMax, UINT wRemoveMsg, BOOL *pfResult ); [return: MarshalAs(UnmanagedType.Bool)] bool PeekMessageA(out MSG pMsg, [In, Optional] HWND hwnd, [In, Optional] uint wMsgFilterMin, [In, Optional] uint wMsgFilterMax, User32.PM wRemoveMsg); /// /// Obtains a message from the message queue and does not return until a message is obtained. This is the ANSI version of this method. /// /// Pointer to a MSG structure that receives message data. /// /// Handle to the window whose messages are obtained. The window must belong to the current thread. If this value is /// NULL, this method obtains messages for any window that belongs to the calling thread. /// /// Specifies the lowest message value obtained. /// Specifies the highest message value obtained. /// Pointer to a BOOL value that receives the return value from the GetMessage function. /// /// If wMsgFilterMin and wMsgFilterMax are both zero, this method returns all available messages; that is, no range filtering is performed. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfmessagepump-getmessagea HRESULT GetMessageA( LPMSG pMsg, // HWND hwnd, UINT wMsgFilterMin, UINT wMsgFilterMax, BOOL *pfResult ); [return: MarshalAs(UnmanagedType.Bool)] bool GetMessageA(out MSG pMsg, [In, Optional] HWND hwnd, [In, Optional] uint wMsgFilterMin, [In, Optional] uint wMsgFilterMax); /// /// Obtains a message from the message queue and returns if no message is obtained. This is the Unicode version of this method. /// /// Pointer to a MSG structure that receives message data. /// /// Handle to the window whose messages are obtained. The window must belong to the current thread. If this value is /// NULL, this method obtains messages for any window that belongs to the calling thread. /// /// Specifies the lowest message value to obtain. /// Specifies the highest message value to obtain. /// Specifies how messages are handled. For more information, see the PeekMessage function. /// Pointer to a BOOL that receives the return value from the PeekMessage function. /// /// If wMsgFilterMin and wMsgFilterMax are both zero, this method returns all available messages; that is, no range filtering is performed. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfmessagepump-peekmessagew HRESULT PeekMessageW( LPMSG // pMsg, HWND hwnd, UINT wMsgFilterMin, UINT wMsgFilterMax, UINT wRemoveMsg, BOOL *pfResult ); [return: MarshalAs(UnmanagedType.Bool)] bool PeekMessageW(out MSG pMsg, [In, Optional] HWND hwnd, [In, Optional] uint wMsgFilterMin, [In, Optional] uint wMsgFilterMax, User32.PM wRemoveMsg); /// /// Obtains a message from the message queue and does not return until a message is obtained. This is the Unicode version of /// this method. /// /// Pointer to a MSG structure that receives message data. /// /// Handle to the window whose messages are obtained. The window must belong to the current thread. If this value is /// NULL, this method obtains messages for any window owned by the calling thread. /// /// Specifies the lowest message value to obtain. /// Specifies the highest message value to obtain. /// Pointer to a BOOL that receives the return value from the GetMessage function. /// /// If wMsgFilterMin and wMsgFilterMax are both zero, this method returns all available messages; that is, no range filtering is performed. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfmessagepump-getmessagew HRESULT GetMessageW( LPMSG pMsg, // HWND hwnd, UINT wMsgFilterMin, UINT wMsgFilterMax, BOOL *pfResult ); [return: MarshalAs(UnmanagedType.Bool)] bool GetMessageW(out MSG pMsg, [In, Optional] HWND hwnd, [In, Optional] uint wMsgFilterMin, [In, Optional] uint wMsgFilterMax); } /// /// The ITfMouseSink interface is implemented by a text service to receive mouse event notifications. A mouse event sink is /// installed with the ITfMouseTracker::AdviseMouseSink method of one of the ITfMouseTracker interfaces. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nn-msctf-itfmousesink [PInvokeData("msctf.h", MSDNShortId = "NN:msctf.ITfMouseSink")] [ComImport, Guid("A1ADAAA2-3A24-449D-AC96-5183E7F5C217"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] public interface ITfMouseSink { /// Called when a mouse event occurs over a range of text. /// /// Contains the offset, in characters, of the mouse position from the start of the range of text. For more information, see the /// Remarks section. /// /// /// Contains the zero-based quadrant index, relative to the edge, that the mouse position lies in. For more information, see the /// Remarks section. /// /// /// Indicates the mouse button state at the time of the event. See the wParam parameter of the WM_MOUSEMOVE message for possible values. /// /// /// Pointer to a BOOL that, on exit, indicates if the mouse event was handled. If this value receives TRUE, the mouse /// event was handled. If this value is FALSE, the mouse event was not handled. /// /// /// This method can return one of these values. /// /// /// Value /// Description /// /// /// S_OK /// The method was successful. /// /// /// /// /// /// The caller should translate double-click events into multiple mouse button down events. This enables a text service to /// detect double-click events even if the context window does not support double-clicks. /// /// /// uEdge contains the offset, in characters, of the mouse position from the start of the text range. The mouse position is /// always rounded to the closest edge. Each edge is divided into four equal quadrants with two quadrants preceding the edge and /// two quadrants following the edge. uQuadrant contains the zero-based quadrant index of the mouse position. In the figure /// below, point "X" is in quadrant 2 of edge 1 and point "Y" is in quadrant 1 of edge 3. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfmousesink-onmouseevent HRESULT OnMouseEvent( ULONG // uEdge, ULONG uQuadrant, DWORD dwBtnStatus, BOOL *pfEaten ); [PreserveSig] HRESULT OnMouseEvent(uint uEdge, uint uQuadrant, MouseButtonState dwBtnStatus, [Out, MarshalAs(UnmanagedType.Bool)] out bool pfEaten); } /// /// The ITfMouseTracker interface is implemented by the TSF manager and is used by a text service to manage mouse event /// notification sinks. An instance of this interface is obtained by querying an ITfContext object for IID_ITfMouseTracker. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nn-msctf-itfmousetracker [PInvokeData("msctf.h", MSDNShortId = "NN:msctf.ITfMouseTracker")] [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("09D146CD-A544-4132-925B-7AFA8EF322D0")] public interface ITfMouseTracker { /// Installs a mouse event sink. /// /// Pointer to an ITfRange interface that specifies the range of text that the mouse sink is installed for. /// /// Pointer to the ITfMouseSink interface. /// Pointer to a DWORD value that receives a cookie that identifies the mouse event sink. /// /// /// When the advise sink is installed, a mouse event that occurs over the range specified by range will result in the mouse /// event sink ITfMouseSink::OnMouseEvent call. /// /// /// The value placed in pdwCookie must be saved and passed to ITfMouseTracker::UnadviseMouseSink to remove the mouse event sink. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfmousetracker-advisemousesink HRESULT AdviseMouseSink( // ITfRange *range, ITfMouseSink *pSink, DWORD *pdwCookie ); void AdviseMouseSink([In] ITfRange range, [In] ITfMouseSink pSink, out uint pdwCookie); /// Uninstalls a mouse event sink. /// Specifies the mouse advise sink identifier. This value is obtained by a call to ITfMouseTracker::AdviseMouseSink. // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfmousetracker-unadvisemousesink HRESULT // UnadviseMouseSink( DWORD dwCookie ); void UnadviseMouseSink(uint dwCookie); } /// /// The ITfMouseTrackerACP interface is implemented by an application to support mouse event sinks. This interface is used by /// the TSF manager to add and remove mouse event sinks in an ACP-based application. The TSF manager obtains this interface by /// calling the application's ITextStoreACP::QueryInterface with IID_ITfMouseTrackerACP. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nn-msctf-itfmousetrackeracp [PInvokeData("msctf.h", MSDNShortId = "NN:msctf.ITfMouseTrackerACP")] [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("3BDD78E2-C16E-47FD-B883-CE6FACC1A208")] public interface ITfMouseTrackerACP { /// Called to install a mouse event sink. /// /// Pointer to an ITfRange interface that specifies the range of text that the mouse sink is installed for. /// /// /// Pointer to the ITfMouseSink interface. The application must increment this object reference count and save the interface. /// /// Pointer to a DWORD that receives a cookie that identifies the mouse event sink. /// /// This method can return one of these values. /// /// /// Value /// Description /// /// /// S_OK /// The method was successful. /// /// /// E_INVALIDARG /// One or more parameters are invalid. /// /// /// E_NOTIMPL /// The application does not support mouse event sinks. /// /// /// /// /// /// When this advise sink is installed, a mouse event that occurs over the range specified by range will result in the mouse /// event sink ITfMouseSink::OnMouseEvent method being called. /// /// /// The value placed in pdwCookie will be saved by the caller and passed to the ITfMouseTrackerACP::UnadviseMouseSink method to /// remove the mouse event sink. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfmousetrackeracp-advisemousesink HRESULT AdviseMouseSink( // ITfRangeACP *range, ITfMouseSink *pSink, DWORD *pdwCookie ); [PreserveSig] HRESULT AdviseMouseSink([In] ITfRangeACP range, [In] ITfMouseSink pSink, out uint pdwCookie); /// Called to remove a mouse event sink. /// Specifies the mouse advise sink identifier. This value is obtained by a call to ITfMouseTrackerACP::AdviseMouseSink. /// /// This method can return one of these values. /// /// /// Value /// Description /// /// /// S_OK /// The method was successful. /// /// /// E_NOTIMPL /// The application does not support mouse event sinks. /// /// /// /// /// The application must release the ITfMouseSink supplied in the ITfMouseTrackerACP::AdviseMouseSink call associated /// with dwCookie. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfmousetrackeracp-unadvisemousesink HRESULT // UnadviseMouseSink( DWORD dwCookie ); [PreserveSig] HRESULT UnadviseMouseSink(uint dwCookie); } /// /// The ITfPersistentPropertyLoaderACP interface is implemented by an application and used by the TSF manager to load /// properties asynchronously. An application passes an instance of this interface when calling ITextStoreACPServices::Unserialize. /// When properties are loaded by a call to ITextStoreACPServices::Unserialize , this interface is used to load properties /// when required rather than all at once. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nn-msctf-itfpersistentpropertyloaderacp [PInvokeData("msctf.h", MSDNShortId = "NN:msctf.ITfPersistentPropertyLoaderACP")] [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("4EF89150-0807-11D3-8DF0-00105A2799B5")] public interface ITfPersistentPropertyLoaderACP { /// Called to load a property. /// /// Pointer to a TF_PERSISTENT_PROPERTY_HEADER_ACP structure that identifies the property to load. This structure contains the /// same data as the structure passed to ITextStoreACPServices::Unserialize. /// /// Pointer to an IStream interface pointer that receives the stream object. /// /// This method can return one of these values. /// /// /// Value /// Description /// /// /// S_OK /// The method was successful. /// /// /// E_INVALIDARG /// One or more parameters are invalid. /// /// /// E_OUTOFMEMORY /// A memory allocation failure occurred. /// /// /// /// /// Only property data is written to the stream. The header data is not written to the stream. /// /// Obtain the original position of the stream before writing to the stream. The original position should be restored in the /// stream before returning from this method. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfpersistentpropertyloaderacp-loadproperty HRESULT // LoadProperty( const TF_PERSISTENT_PROPERTY_HEADER_ACP *pHdr, IStream **ppStream ); [PreserveSig] HRESULT LoadProperty(in TF_PERSISTENT_PROPERTY_HEADER_ACP pHdr, out IStream? ppStream); } /// /// The ITfPreservedKeyNotifySink interface is implemented by an application or TSF text service to receive notifications /// when keys are preserved, unpreserved, or when a preserved key description changes. This advise sink is installed by calling the /// TSF manager ITfSource::AdviseSink with IID_ITfPreservedKeyNotifySink. /// /// Preserved keys are keyboard shortcuts that an application or TSF text service can register with the TSF manager. // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nn-msctf-itfpreservedkeynotifysink [PInvokeData("msctf.h", MSDNShortId = "NN:msctf.ITfPreservedKeyNotifySink")] [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("6F77C993-D2B1-446E-853E-5912EFC8A286")] public interface ITfPreservedKeyNotifySink { /// Called when a key is preserved, unpreserved, or when a preserved key description changes. /// Pointer to a TF_PRESERVEDKEY structure that contains data about the key. /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// /// To determine if the key is unpreserved, call ITfKeystrokeMgr::IsPreservedKey, passing pprekey. If the key is not found, it /// is unpreserved. If the key is found, it is either preserved or the description has changed. Unless you keep track of the /// current key description and compare the previous description with the current description in response to this notification, /// there is no way to determine if this notification is in response to a key preserved or the description changed. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfpreservedkeynotifysink-onupdated HRESULT OnUpdated( // const TF_PRESERVEDKEY *pprekey ); [PreserveSig] HRESULT OnUpdated(in TF_PRESERVEDKEY pprekey); } /// /// The ITfProperty interface is implemented by the TSF manager and used by a client (application or text service) to modify /// a property value. /// /// An instance of this interface is obtained in various ways, such as ITfContext::GetProperty or IEnumTfProperties::Next. // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nn-msctf-itfproperty [PInvokeData("msctf.h", MSDNShortId = "NN:msctf.ITfProperty")] [ComImport, Guid("E2449660-9542-11D2-BF46-00105A2799B5"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] public interface ITfProperty : ITfReadOnlyProperty { /// Obtains the property identifier. /// /// /// Pointer to a GUID value that receives the property type identifier. This is the value that the property provider /// passed to ITfCategoryMgr::RegisterCategory when the property was registered. This can be one of the following values. /// /// /// /// Value /// Meaning /// /// /// GUID_TFCAT_PROPSTYLE_STATIC /// The property is a static property. /// /// /// GUID_TFCAT_PROPSTYLE_STATICCOMPACT /// The property is a static-compact property. /// /// /// GUID_TFCAT_PROPSTYLE_CUSTOM /// The property is a custom property. /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfreadonlyproperty-gettype HRESULT GetType( GUID *pguid ); new Guid GetType(); /// Obtains an enumeration of ranges that contain unique values of the property within the given range. /// /// Contains an edit cookie that identifies the edit context. This is obtained from ITfDocumentMgr::CreateContext or ITfEditSession::DoEditSession. /// /// /// Pointer to an IEnumTfRanges interface pointer that receives the enumerator object. The caller must release this object when /// it is no longer required. /// /// /// Pointer to an ITfRange interface that specifies the range to scan for unique property values. This parameter is optional and /// can be NULL. For more information, see the Remarks section. /// /// /// /// Note: If an application does not implement ITextStoreACP::FindNextAttrTransition, /// ITfReadOnlyProperty::EnumRanges fails with E_FAIL. /// /// /// The enumerator obtained by this method will contain a range for each unique value, including empty values, of the specified /// property. For example, a hypothetical color property can be applied to the following marked up text: /// /// /// COLOR: RR GGGGGGGG TEXT: this is some colored text /// /// /// When ITfReadOnlyProperty::EnumRanges is called with pTargetRange set to this range, the enumerator will contain five ranges. /// /// /// /// Range Index /// Color Property Value /// Range Text /// /// /// 0 /// <empty> /// "this " /// /// /// 1 /// R /// "is" /// /// /// 2 /// <empty> /// " some " /// /// /// 3 /// G /// "colored " /// /// /// 4 /// <empty> /// "text" /// /// /// /// If pTargetRange is NULL, then the enumerator will begin and end with the first and last range that contains a /// non-empty property value in the context. Specifying NULL for pTargetRange in the above example would result in an /// enumerator with three ranges. /// /// /// /// Range Index /// Color Property Value /// Text Within Range /// /// /// 0 /// R /// "is" /// /// /// 1 /// <empty> /// " some " /// /// /// 2 /// G /// "colored " /// /// /// /// The enumerated ranges will begin and end with the start and end anchors of pTargetRange, even if either anchor is positioned /// in the middle of a property. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfreadonlyproperty-enumranges HRESULT EnumRanges( // TfEditCookie ec, IEnumTfRanges **ppEnum, ITfRange *pTargetRange ); new void EnumRanges([In] TfEditCookie ec, out IEnumTfRanges ppEnum, [In, Optional] ITfRange? pTargetRange); /// Obtains the value of the property for a range of text. /// /// Contains an edit cookie that identifies the edit context. This is obtained from ITfDocumentMgr::CreateContext or ITfEditSession::DoEditSession. /// /// Pointer to an ITfRange interface that specifies the range to obtain the property for. /// /// Pointer to a VARIANT value that receives the property value. The data type and contents of this value is defined by /// the property owner and must be recognized by the caller in order to use this value. The caller must release this data, when /// it is no longer required, by passing this value to the VariantClear API. /// /// /// /// If the property has no value over pRange, pRange contains more than one value for the property or the property does not /// completely cover pRange, pvarValue receives a VT_EMPTY value and the method returns S_FALSE. /// /// /// COLOR: RR GGGGGGGG TEXT: this is some colored text range-->||<- /// /// /// COLOR: RR GGGGGGGG TEXT: this is some colored text range-->| |<- /// /// /// COLOR: RR GGGGGGGG TEXT: this is some colored text range-->| |<- /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfreadonlyproperty-getvalue HRESULT GetValue( TfEditCookie // ec, ITfRange *pRange, VARIANT *pvarValue ); [return: MarshalAs(UnmanagedType.Struct)] new object GetValue([In] TfEditCookie ec, [In] ITfRange pRange); /// Obtains the context object for the property. /// /// Pointer to an ITfContext interface pointer that receives the context object. The caller must release this object when it is /// no longer required. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfreadonlyproperty-getcontext HRESULT GetContext( // ITfContext **ppContext ); new ITfContext GetContext(); /// Obtains a range that covers the text that contains a non-empty value for the property. /// /// Contains an edit cookie that identifies the edit context. This is obtained from ITfDocumentMgr::CreateContext or ITfEditSession::DoEditSession. /// /// /// Pointer to an ITfRange interface that contains the point to obtain the property range for. The point will either be the /// start anchor or end anchor of this range, based upon the value of aPos. /// /// Pointer to an ITfRange interface pointer that receives the requested range object. /// /// Contains one of the TfAnchor values which specifies which anchor of pRange is used as the point to obtain the property range for. /// /// /// /// This method obtains a range of text that contains a non-empty value for the property. If the property has no value at the /// specified point, ppRange receives NULL and the method returns S_FALSE. In the following example, if aPos contains /// TF_ANCHOR_START, the returned range would contain "is". If aPos contains TF_ANCHOR_END, the method would return S_FALSE /// because the property does not exist at the end point of the range. /// /// /// COLOR: RRRRR RR GGGGGGGG TEXT: this <a>is som</a>e colored text /// /// /// If aPos contains TF_ANCHOR_START, this method ignores property ranges that end immediately before the start anchor. /// Likewise, if aPos contains TF_ANCHOR_END, this method ignores property ranges that start immediately after the end anchor. /// In the following example, if aPos contains TF_ANCHOR_START, the returned range would contain "colored " and not "some " /// because the R value property ends at the start anchor point and the G value property begins at the start anchor. If aPos /// contains TF_ANCHOR_END, the returned range would contain "colored " and not "text". /// /// /// COLOR: RRRRR GGGGGGGG BBBB TEXT: this is some <a>colored </a>text /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfproperty-findrange HRESULT FindRange( TfEditCookie ec, // ITfRange *pRange, ITfRange **ppRange, TfAnchor aPos ); void FindRange([In] TfEditCookie ec, [In] ITfRange pRange, out ITfRange? ppRange, [In] TfAnchor aPos); /// Sets the value of the property for a range of text using a property store object. /// /// Contains an edit cookie that identifies the edit context. This is obtained from ITfDocumentMgr::CreateContext or ITfEditSession::DoEditSession. /// /// /// Pointer to an ITfRange interface that contains the range that the property value is set for. This parameter cannot be /// NULL. This method fails if pRange is empty. /// /// Pointer to an ITfPropertyStore interface that obtains the property data. /// /// /// Property values set with ITfProperty::SetValue will be discarded when the text that the property value covers is modified. /// To gain control over what happens to a property value when the text is modified, use ITfProperty::SetValueStore . /// /// /// Values set with ITfProperty::SetValue will be serialized, except for values of type VT_UNKNOWN, which are not /// serialized. If a property value of type VT_UNKNOWN must be serialized, use ITfProperty::SetValueStore instead. /// /// Overlapping property values of the same type are unsupported. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfproperty-setvaluestore HRESULT SetValueStore( // TfEditCookie ec, ITfRange *pRange, ITfPropertyStore *pPropStore ); void SetValueStore([In] TfEditCookie ec, [In] ITfRange pRange, [In] ITfPropertyStore pPropStore); /// Sets the value of the property for a range. /// /// Contains an edit cookie that identifies the edit context. This is obtained from ITfDocumentMgr::CreateContext or ITfEditSession::DoEditSession. /// /// /// Pointer to an ITfRange interface that contains the range that the property value is set for. This parameter cannot be /// NULL. This method will fail if pRange is empty. /// /// /// Pointer to a VARIANT structure that contains the new property value. Only values of type VT_I4, VT_UNKNOWN, VT_BSTR /// and VT_EMPTY are supported. /// /// /// /// Property values set with this method will be discarded when the text that the property value covers is modified. To gain /// custom control over a value response to text edits, use ITfProperty::SetValueStore. /// /// /// Values set with this method are serialized, except for values of type VT_UNKNOWN, which are not serialized. If a property /// value of type VT_UNKNOWN must be serialized, use ITfProperty::SetValueStore instead. /// /// Overlapping property values of the same type are unsupported. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfproperty-setvalue HRESULT SetValue( TfEditCookie ec, // ITfRange *pRange, const VARIANT *pvarValue ); void SetValue([In] TfEditCookie ec, [In] ITfRange pRange, [In, MarshalAs(UnmanagedType.Struct)] object pvarValue); /// Empties the property value over the specified range. /// /// Contains an edit cookie that identifies the edit context. This is obtained from ITfDocumentMgr::CreateContext or ITfEditSession::DoEditSession. /// /// /// Pointer to an ITfRange interface that contains the range that the property is cleared for. If this parameter is NULL, /// all values for this property over the entire edit context are cleared. /// /// /// It is not necessary to call this method when a context is about to be destroyed. The TSF manager will clear all properties /// when the context is removed from the context stack. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfproperty-clear HRESULT Clear( TfEditCookie ec, ITfRange // *pRange ); void Clear([In] TfEditCookie ec, [In, Optional] ITfRange? pRange); } /// /// The ITfPropertyStore interface is implemented by a text service and used by the TSF manager to provide non-static /// property values. An instance of this interface is passed to ITfProperty::SetValueStore. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nn-msctf-itfpropertystore [PInvokeData("msctf.h", MSDNShortId = "NN:msctf.ITfPropertyStore")] [ComImport, Guid("6834B120-88CB-11D2-BF45-00105A2799B5"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] public interface ITfPropertyStore { /// Obtains the property identifier. /// Pointer to a GUID value that receives the property identifier. /// /// This method can return one of these values. /// /// /// Value /// Description /// /// /// S_OK /// The method was successful. /// /// /// E_INVALIDARG /// pguid is invalid. /// /// /// E_FAIL /// An unspecified error occurred. /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfpropertystore-gettype HRESULT GetType( GUID *pguid ); [PreserveSig] HRESULT GetType(out Guid pguid); /// This method is reserved, but must be implemented. /// /// Pointer to a DWORD value the receives the data type. This parameter is reserved and must be set to zero. /// /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfpropertystore-getdatatype HRESULT GetDataType( DWORD // *pdwReserved ); [PreserveSig] HRESULT GetDataType(out uint pdwReserved); /// Obtains the property store data. /// Pointer to a VARIANT value that receives property data. /// /// This method can return one of these values. /// /// /// Value /// Description /// /// /// S_OK /// The method was successful. /// /// /// E_INVALIDARG /// pvarValue is invalid. /// /// /// E_FAIL /// An unspecified error occurred. /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfpropertystore-getdata HRESULT GetData( VARIANT // *pvarValue ); [PreserveSig] HRESULT GetData([Out, MarshalAs(UnmanagedType.Struct)] out object pvarValue); /// Called when the text that the property store applies to is modified. /// /// /// Contains a set of flags that provide additional information about the text change. This can be zero or the following value. /// /// /// /// Value /// Meaning /// /// /// TF_TU_CORRECTION /// /// The text change is the result of a correction. This implies that the semantics of the text have not changed. An example of /// this is when the spelling checker corrects a misspelled word. /// /// /// /// /// Pointer to an ITfRange interface that contains the range of text modified. /// /// Pointer to a BOOL variable that receives a value that indicates if the property store should be retained. Receives a /// nonzero value if the property store should be retained or zero if the property store should be discarded. If the property /// store is discarded, the TSF manager will set the property value to VT_EMPTY and release the property store. /// /// /// This method can return one of these values. /// /// /// Value /// Description /// /// /// S_OK /// The method was successful. /// /// /// /// If this method returns any value other than S_OK, the property store is discarded. // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfpropertystore-ontextupdated HRESULT OnTextUpdated( DWORD // dwFlags, ITfRange *pRangeNew, BOOL *pfAccept ); [PreserveSig] HRESULT OnTextUpdated(uint dwFlags, [In] ITfRange pRangeNew, [Out, MarshalAs(UnmanagedType.Bool)] out bool pfAccept); /// Called when the text that the property store applies to is truncated. /// Pointer to an ITfRange interface that contains the truncated range. /// /// Pointer to a BOOL variable that receives a value that indicates if the property store should be retained. Receives a /// nonzero value if the property store should be retained or zero if the property store should be discarded. If the property /// store is discarded, the TSF manager will set the property value to VT_EMPTY and release the property store. /// /// /// This method can return one of these values. /// /// /// Value /// Description /// /// /// S_OK /// The method was successful. /// /// /// /// If this method returns a value other than S_OK, the property store is discarded. // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfpropertystore-shrink HRESULT Shrink( ITfRange // *pRangeNew, BOOL *pfFree ); [PreserveSig] HRESULT Shrink([In] ITfRange pRangeNew, [Out, MarshalAs(UnmanagedType.Bool)] out bool pfFree); /// Called when the text covered by the property is split into two ranges. /// /// Pointer to an ITfRange object that contains the range that the property store now covers. This will be the range of text /// closest to the beginning of the context. /// /// /// Pointer to an ITfRange object that contains the range that the new property store will cover. This will be the range of text /// closest to the end of the context. /// /// /// Pointer to an ITfPropertyStore interface pointer that receives a new property store object that will cover the range /// specified by pRangeNew. /// /// /// This method can return one of these values. /// /// /// Value /// Description /// /// /// S_OK /// The method was successful. /// /// /// /// /// /// This method creates a new property store object to cover pRangeNew and returns the pointer to this object in ppPropStore. If /// no new property store is returned, the original property store is discarded and the property store for both ranges is set to empty. /// /// If this method returns any value other than S_OK, the original property store is discarded. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfpropertystore-divide HRESULT Divide( ITfRange // *pRangeThis, ITfRange *pRangeNew, ITfPropertyStore **ppPropStore ); [PreserveSig] HRESULT Divide([In] ITfRange pRangeThis, [In] ITfRange pRangeNew, out ITfPropertyStore ppPropStore); /// Creates an exact copy of the property store object. /// Pointer to an ITfPropertyStore interface pointer that receives the new property store object. /// /// This method can return one of these values. /// /// /// Value /// Description /// /// /// S_OK /// The method was successful. /// /// /// E_OUTOFMEMORY /// A memory allocation failure occurred. /// /// /// /// /// This method creates a new property store object and initializes the new object so that it will operate as an exact copy of /// the original property store object. The new object must be completely independent of the original object. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfpropertystore-clone HRESULT Clone( ITfPropertyStore // **pPropStore ); [PreserveSig] HRESULT Clone(out ITfPropertyStore pPropStore); /// Obtains the class identifier of the property store owner. /// /// Pointer to a CLSID that receives the class identifier of the registered text service that implements /// ITfCreatePropertyStore. The method can return CLSID_NULL for this parameter if property store persistence is unsupported. /// /// /// This method can return one of these values. /// /// /// Value /// Description /// /// /// S_OK /// The method was successful. /// /// /// /// /// When the property store is unserialized, the TSF manager creates an object of this CLSID and obtains an /// ITfCreatePropertyStore interface pointer from it. The manager then uses the ITfCreatePropertyStore object to /// create the property store object. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfpropertystore-getpropertyrangecreator HRESULT // GetPropertyRangeCreator( CLSID *pclsid ); [PreserveSig] HRESULT GetPropertyRangeCreator(out Guid pclsid); /// Called to write the property store data into a stream for serialization. /// Pointer to an IStream object that the property store data is written to. /// Pointer to a ULONG value that receives the number of bytes written to the stream. /// /// This method can return one of these values. /// /// /// Value /// Description /// /// /// S_OK /// The method was successful. /// /// /// E_INVALIDARG /// One or more parameters are invalid. /// /// /// /// /// The method must not move the stream insertion point before writing to the stream. The method must leave the insertion point /// at the end of the data written by the method. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfpropertystore-serialize HRESULT Serialize( IStream // *pStream, ULONG *pcb ); [PreserveSig] HRESULT Serialize([In] IStream pStream, out uint pcb); } /// /// The ITfQueryEmbedded interface is implemented by the TSF manager and used by a text service to determine if a context can /// accept an embedded object. /// /// /// To obtain an instance of this interface, call the ITfContext::QueryInterface method with IID_ITfQueryEmbedded. /// Examples /// ITfContext /// /// HRESULT hr; ITfQueryEmbedded *pQueryEmbedded; hr = pContext->QueryInterface(IID_ITfQueryEmbedded, (LPVOID*)&pQueryEmbedded); if(SUCCEEDED(hr)) { //Use the ITfQueryEmbedded interface. pQueryEmbedded->Release(); } /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nn-msctf-itfqueryembedded [PInvokeData("msctf.h", MSDNShortId = "NN:msctf.ITfQueryEmbedded")] [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("0FAB9BDB-D250-4169-84E5-6BE118FDD7A8")] public interface ITfQueryEmbedded { /// Determines if the active context can accept an embedded object. /// /// A GUID that identifies the service associated with the object. This value can be NULL if pFormatEtc is valid. /// /// /// Pointer to a FORMATETC structure that contains data about the object to be embedded. This value can be NULL if /// pguidService is valid. /// /// /// Pointer to a Boolean value that receives the query result. This value receives a nonzero value if the object can be /// embedded, or zero otherwise. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfqueryembedded-queryinsertembedded HRESULT // QueryInsertEmbedded( const GUID *pguidService, const FORMATETC *pFormatEtc, BOOL *pfInsertable ); [return: MarshalAs(UnmanagedType.Bool)] unsafe bool QueryInsertEmbedded([In, Optional] Guid* pguidService, [In, Optional] FORMATETC* pFormatEtc); } /// /// The ITfRange interface is used by text services and applications to reference and manipulate text within a given context. /// The interface ID is IID_ITfRange. /// /// /// /// The TSF manager implements this interface. For more information about ranges, anchors, embedded objects, and other text /// properties used by TSF, see Ranges, Embedded Objects, and other topics within Using Text Services Framework. /// /// Examples /// /// Once an ITfComposition composition object is instantiated, a pointer to an ITfRange interface pointer can be obtained by /// calling the ITfComposition::GetRange method, as shown in the following code example. /// /// /// HRESULT hr; ITfComposition *pComposition; ITfRange *pRange; WCHAR *achBuffer[64]; // Buffer to receive text. ULONG cch; hr = pComposition->GetRange(&pRange); if(SUCCEEDED(hr)) { // Loop to scan text: do { cch = ARRAYSIZE(achBuffer); hr = pRange->GetText(ec, TF_TF_MOVESTART | TF_TF_IGNOREEND, achBuffer, cch, &cch); if(SUCCEEDED(hr)) { // Do something with the text. pRange->Release(); } } while (cch == ARRAYSIZE(achBuffer)); pComposition->Release(); } /// /// A pointer to a current ITfRange object can be obtained from the <range> element of the TF_SELECTION structure. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nn-msctf-itfrange [PInvokeData("msctf.h", MSDNShortId = "NN:msctf.ITfRange")] [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("AA80E7FF-2021-11D2-93E0-0060B067B86E")] public interface ITfRange { /// The ITfRange::GetText method obtains the content covered by this range of text. /// Edit cookie that identifies the edit context obtained from ITfDocumentMgr::CreateContext or ITfEditSession::DoEditSession. /// /// Bit fields that specify optional behavior. /// /// /// Value /// Meaning /// /// /// TF_TF_MOVESTART /// Start anchor of the range is advanced to the position after the last character returned. /// /// /// TF_TF_IGNOREEND /// /// Method attempts to fill pchText with the maximum number of characters, instead of halting the copy at the position occupied /// by the end anchor of the range. /// /// /// /// /// Pointer to a buffer to receive the text in the range. /// Maximum size of the text buffer. /// Pointer to a ULONG representing the number of characters written to the pchText text buffer. // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfrange-gettext HRESULT GetText( TfEditCookie ec, DWORD // dwFlags, WCHAR *pchText, ULONG cchMax, ULONG *pcch ); void GetText([In] TfEditCookie ec, [In] TF_TF dwFlags, [Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pchText, uint cchMax, out uint pcch); /// /// The ITfRange::SetText method replaces the content covered by the range of text. For an empty range object, the method /// results in an insertion at the location of the range. If the new content is an empty string (cch = 0), the method deletes /// the existing content within the range. /// /// Identifies the edit context obtained from ITfDocumentMgr::CreateContext or ITfEditSession::DoEditSession. /// /// Specifies optional behavior for correction of content. If set to the value of TF_ST_CORRECTION, then the operation is a /// correction of the existing content, not a creation of new content, and original text properties are preserved. /// /// Pointer to a buffer that contains the text to replace the range contents. /// Contains the number of characters in pchText. /// /// /// When a range covers multiple regions, call ITfRange::SetText on each region separately. Otherwise, the method can fail. /// /// /// By default, text services start and end a temporary composition that covers the range, to ensure that context owners /// consistently recognize compositions over edited text. If the composition owner rejects a default composition, then the /// method returns TF_E_COMPOSITION_REJECTED. Default compositions are only created if the caller has not already started one. /// If the caller has an active composition, the call fails. /// /// /// The TF_CHAR_EMBEDDED object placeholder character might not be passed into this method. ITfRange::InsertEmbedded should be /// used instead. /// /// /// For inserting text, the ITFInsertAtSelection:InsertTextAtSelection method does not require a selection range to be /// allocated, and avoids the requirement that the range match the selection. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfrange-settext HRESULT SetText( TfEditCookie ec, DWORD // dwFlags, const WCHAR *pchText, LONG cch ); void SetText([In] TfEditCookie ec, [In] TF_ST dwFlags, [In, MarshalAs(UnmanagedType.LPWStr)] string pchText, int cch); /// /// The ITfRange::GetFormattedText method obtains formatted content contained within a range of text. The content is /// packaged in an object that supports the IDataObject interface. /// /// Edit cookie obtained from ITfDocumentMgr::CreateContext or ITfEditSession::DoEditSession. /// /// Pointer to an IDataObject pointer that receives an object that contains the formatted content. The formatted content /// is obtained using a STGMEDIUM global memory handle. /// /// The format and storage type of the IDataObject are determined by the application to which the range belongs. // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfrange-getformattedtext HRESULT GetFormattedText( // TfEditCookie ec, IDataObject **ppDataObject ); IDataObject GetFormattedText([In] TfEditCookie ec); /// /// The ITfRange::GetEmbedded method obtains content that corresponds to a TS_CHAR_EMBEDDED character in the text stream. /// The start anchor of the range of text is positioned just before the character of interest. /// /// Edit cookie obtained from ITfDocumentMgr::CreateContext or ITfEditSession::DoEditSession. /// /// Identifier that specifies how the embedded content is obtained. /// /// /// Value /// Meaning /// /// /// GUID_TS_SERVICE_ACCESSIBLE /// Output should be an Accessible object. /// /// /// GUID_TS_SERVICE_ACTIVEX /// Caller requires a direct pointer to the object that supports the interface specified by riid. /// /// /// GUID_TS_SERVICE_DATAOBJECT /// /// Content should be obtained as an IDataObject data transfer object, with riid being IID_IDataObject. Clients should specify /// this option when a copy of the content is required. /// /// /// /// Caller-defined /// Text services and context owners can define custom GUIDs. /// /// /// /// UUID of the interface of the requested object. /// Pointer to the object. It can be cast to match riid. /// /// While the obtained object might not support certain interfaces, it is likely that the object will support those interfaces /// associated with embedded documents or controls such as IOleObject, IDataObject, IViewObject, /// IPersistStorage, IOleCache, or IDispatch. The caller must use QueryInterface to probe for any /// interesting interface. If the method succeeds but riid is NULL, the application indicates the presence of an embedded /// object but does not expose the object itself. Text processors can still benefit from a notification about the potential word break. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfrange-getembedded HRESULT GetEmbedded( TfEditCookie ec, // REFGUID rguidService, REFIID riid, IUnknown **ppunk ); [return: MarshalAs(UnmanagedType.IUnknown)] object? GetEmbedded([In] TfEditCookie ec, in Guid rguidService, in Guid riid); /// /// The ITfRange::InsertEmbedded method inserts an object at the location of the start anchor of the range of text. /// /// Edit cookie obtained from ITfDocumentMgr::CreateContext or ITfEditSession::DoEditSession. /// /// Bit fields that specify how insertion should occur. If TF_IE_CORRECTION is set, the operation is a correction, so that other /// text services can preserve data associated with the original text. /// /// Pointer to the data transfer object to be inserted. /// /// /// Use this method to insert objects into the text stream, because the TF_CHAR_EMBEDDED object placeholder character cannot be /// passed into ITfRange::SetText. This method is modeled after the OLE clipboard API, with applications using pDataObject as /// they would an IDataObject returned from OleGetClipboard. /// /// /// When a range covers multiple regions, the method should be called on each region separately. Otherwise, the method might fail. /// /// /// By default, text services start and end a temporary composition that covers the range, to ensure that context owners /// consistently recognize compositions over edited text. If the composition owner rejects a default composition, then the /// method returns TF_E_COMPOSITION_REJECTED. Default compositions are only created if the caller has not already started one. /// If the caller has an active composition, the call fails. /// /// To determine in advance whether a context owner supports insertion of a particular object, use ITfQueryEmbedded::QueryInsertEmbedded. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfrange-insertembedded HRESULT InsertEmbedded( // TfEditCookie ec, DWORD dwFlags, IDataObject *pDataObject ); void InsertEmbedded([In] TfEditCookie ec, [In] TF_IE dwFlags, [In] IDataObject pDataObject); /// Moves the start anchor of the range. /// /// Contains an edit cookie that identifies the edit context. This is obtained from ITfDocumentMgr::CreateContext or ITfEditSession::DoEditSession. /// /// /// Contains the number of characters the start anchor is shifted. A negative value causes the anchor to move backward and a /// positive value causes the anchor to move forward. /// /// Pointer to a LONG value that receives the number of characters the anchor was shifted. /// /// Pointer to a TF_HALTCOND structure that contains conditions about the shift. This parameter is optional and can be NULL. /// /// /// The start and end positions of a range are called anchors. /// /// This method cannot move an anchor beyond a region boundary. If the shift reaches a region boundary, the number of characters /// actually shifted will be less than requested. ITfRange::ShiftStartRegion is used to shift the anchor to an adjacent region. /// /// /// If the shift operation causes the range start anchor to move past the end anchor, the end anchor is moved to the same /// location as the start anchor. /// /// /// ITfRange::ShiftStart can be a lengthy operation. For better performance, use ITfRange::ShiftStartToRange when possible. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfrange-shiftstart HRESULT ShiftStart( TfEditCookie ec, // LONG cchReq, LONG *pcch, const TF_HALTCOND *pHalt ); void ShiftStart([In] TfEditCookie ec, int cchReq, out int pcch, [In, Optional] TF_HALTCOND pHalt); /// Moves the end anchor of the range. /// /// Contains an edit cookie that identifies the edit context. This is obtained from ITfDocumentMgr::CreateContext or ITfEditSession::DoEditSession. /// /// /// Contains the number of characters that the end anchor is shifted. A negative value causes the anchor to move backward and a /// positive value causes the anchor to move forward. /// /// Pointer to a LONG value that receives the number of characters the anchor shifted. /// /// Pointer to a TF_HALTCOND structure that contains conditions on the shift. This parameter is optional and can be NULL. /// /// /// The start and end positions of a range are called anchors. /// /// This method cannot move an anchor beyond a region boundary. If the shift reaches a region boundary, the number of characters /// actually shifted will be less than requested. ITfRange::ShiftEndRegion is used to shift the anchor to an adjacent region. /// /// /// If the shift operation causes the range end anchor to move past the start anchor, the start anchor is moved to the same /// location as the end anchor. /// /// ITfRange::ShiftEnd can be a lengthy operation. For better performance, use ITfRange::ShiftEndToRange when possible. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfrange-shiftend HRESULT ShiftEnd( TfEditCookie ec, LONG // cchReq, LONG *pcch, const TF_HALTCOND *pHalt ); void ShiftEnd([In] TfEditCookie ec, int cchReq, out int pcch, [In, Optional] TF_HALTCOND pHalt); /// Moves the start anchor of this range to an anchor within another range. /// /// Contains an edit cookie that identifies the edit context obtained from ITfDocumentMgr::CreateContext or ITfEditSession::DoEditSession. /// /// Pointer to an ITfRange interface that contains the anchor that the start anchor is moved to. /// /// Contains one of the TfAnchor values that specifies which anchor of pRange the start anchor is moved to. /// /// /// The start and end positions of a range are called anchors. /// /// If the shift operation causes the range start anchor to move past the end anchor, the end anchor is moved to the same /// location as the start anchor. /// /// This method is more efficient than ITfRange::ShiftStart and should be used when possible. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfrange-shiftstarttorange HRESULT ShiftStartToRange( // TfEditCookie ec, ITfRange *pRange, TfAnchor aPos ); void ShiftStartToRange([In] TfEditCookie ec, [In] ITfRange pRange, [In] TfAnchor aPos); /// Moves the end anchor of this range to an anchor within another range. /// /// Contains an edit cookie that identifies the edit context obtained from ITfDocumentMgr::CreateContext or ITfEditSession::DoEditSession. /// /// Pointer to an ITfRange interface that contains the anchor that the end anchor is moved to. /// /// Contains one of the TfAnchor values that specify which anchor of pRange the end anchor will get moved to. /// /// /// The start and end positions of a range are called anchors. /// /// If the shift operation causes the range end anchor to move past the start anchor, the start anchor is moved to the same /// location as the end anchor. /// /// This method is more efficient than ITfRange::ShiftEnd and should be used. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfrange-shiftendtorange HRESULT ShiftEndToRange( // TfEditCookie ec, ITfRange *pRange, TfAnchor aPos ); void ShiftEndToRange([In] TfEditCookie ec, [In] ITfRange pRange, [In] TfAnchor aPos); /// Moves the start anchor into an adjacent region. /// /// Contains an edit cookie that identifies the edit context obtained from ITfDocumentMgr::CreateContext or ITfEditSession::DoEditSession. /// /// /// Contains one of the TfShiftDir values that specifies which adjacent region the start anchor is moved to. /// /// /// Pointer to a BOOL that receives a flag that indicates if the anchor is positioned adjacent to another region. /// Receives a nonzero value if the anchor is not adjacent to another region or zero otherwise. /// /// /// The start and end positions of a range are called anchors. /// /// The anchor must be positioned adjacent to the desired region prior to calling this method. If it is not, then pfNoRegion /// receives a nonzero value and the anchor is not moved. If the anchor is adjacent to the desired region, pfNoRegion receives /// zero and the anchor is moved to the region. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfrange-shiftstartregion HRESULT ShiftStartRegion( // TfEditCookie ec, TfShiftDir dir, BOOL *pfNoRegion ); [return: MarshalAs(UnmanagedType.Bool)] bool ShiftStartRegion([In] TfEditCookie ec, [In] TfShiftDir dir); /// Moves the end anchor into an adjacent region. /// /// Contains an edit cookie that identifies the edit context obtained from ITfDocumentMgr::CreateContext or ITfEditSession::DoEditSession. /// /// Contains one of the TfShiftDir values that specify which adjacent region the end anchor is moved to. /// /// Pointer to a BOOL value that receives a flag that indicates if the anchor is positioned adjacent to another region. /// Receives a nonzero value if the anchor is not adjacent to another region or zero otherwise. /// /// /// The start and end positions of a range are known as anchors. /// /// The anchor must be positioned adjacent to the desired region prior to calling this method. If it is not, then pfNoRegion /// receives a nonzero value and the anchor is not moved. If the anchor is adjacent to the desired region, pfNoRegion receives /// zero and the anchor is moved into the region. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfrange-shiftendregion HRESULT ShiftEndRegion( // TfEditCookie ec, TfShiftDir dir, BOOL *pfNoRegion ); [return: MarshalAs(UnmanagedType.Bool)] bool ShiftEndRegion([In] TfEditCookie ec, [In] TfShiftDir dir); /// /// The ITfRange::IsEmpty method verifies that the range of text is empty because the start and end anchors occupy the /// same position. /// /// Edit cookie that identifies the edit context. It is obtained from ITfDocumentMgr::CreateContext or ITfEditSession::DoEditSession. /// /// Pointer to a Boolean value. TRUE indicates the range is empty; FALSE indicates the range is not empty. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfrange-isempty HRESULT IsEmpty( TfEditCookie ec, BOOL // *pfEmpty ); [return: MarshalAs(UnmanagedType.Bool)] bool IsEmpty([In] TfEditCookie ec); /// /// The ITfRange::Collapse method clears the range of text by moving its start anchor and end anchor to the same position. /// /// Edit cookie obtained from ITfDocumentMgr::CreateContext or ITfEditSession::DoEditSession. /// /// TfAnchor enumeration that describes how to collapse the range. /// /// /// Value /// Meaning /// /// /// TF_ANCHOR_START /// The end anchor is moved to the location of the start anchor. /// /// /// TF_ANCHOR_END /// The start anchor is moved to the location of the end anchor. /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfrange-collapse HRESULT Collapse( TfEditCookie ec, // TfAnchor aPos ); void Collapse([In] TfEditCookie ec, [In] TfAnchor aPos); /// /// The ITfRange::IsEqualStart method verifies that the start anchor of this range of text matches an anchor of another /// specified range. /// /// Edit cookie obtained from ITfDocumentMgr::CreateContext or ITfEditSession::DoEditSession. /// Pointer to a specified range in which an anchor is to be compared to this range start anchor. /// /// Enumeration element that indicates which anchor of the specified pWith range to compare to this range start anchor. /// /// /// Value /// Meaning /// /// /// TF_ANCHOR_START /// Compares this range start anchor with the specified range start anchor. /// /// /// TF_ANCHOR_END /// Compares this range start anchor with the specified range end anchor. /// /// /// /// /// Pointer to a Boolean value. Upon return, TRUE indicates that the specified pWith range anchor matches this range /// start anchor. FALSE indicates otherwise. /// /// This method is identical to, but more efficient than, ITfRange::CompareStart. // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfrange-isequalstart HRESULT IsEqualStart( TfEditCookie // ec, ITfRange *pWith, TfAnchor aPos, BOOL *pfEqual ); [return: MarshalAs(UnmanagedType.Bool)] bool IsEqualStart([In] TfEditCookie ec, [In] ITfRange pWith, [In] TfAnchor aPos); /// /// The ITfRange::IsEqualStart method verifies that the end anchor of this range of text matches an anchor of another specified range. /// /// Edit cookie obtained from ITfDocumentMgr::CreateContext or ITfEditSession::DoEditSession. /// Pointer to a specified range in which an anchor is to be compared to this range end anchor. /// /// Enumeration element that indicates which anchor of the specified pWith range to compare with this range end anchor. /// /// /// Value /// Meaning /// /// /// TF_ANCHOR_START /// Compares this range end anchor with the specified range start anchor. /// /// /// TF_ANCHOR_END /// Compares this range end anchor with the specified range end anchor. /// /// /// /// /// Pointer to a Boolean value. Upon return, TRUE indicates that the specified pWith range anchor matches this range end /// anchor. FALSE indicates otherwise. /// /// /// /// This method is identical to ITfRange::IsEqualStart, except that the end anchor of this range is compared to an anchor /// of another specified range. /// /// This method is functionally equivalent to, but more efficient than, ITfRange::CompareEnd. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfrange-isequalend HRESULT IsEqualEnd( TfEditCookie ec, // ITfRange *pWith, TfAnchor aPos, BOOL *pfEqual ); [return: MarshalAs(UnmanagedType.Bool)] bool IsEqualEnd([In] TfEditCookie ec, [In] ITfRange pWith, [In] TfAnchor aPos); /// /// The ITfRange::CompareStart method compares the start anchor position of this range of text to an anchor in another range. /// /// Edit cookie obtained from ITfDocumentMgr::CreateContext or ITfEditSession::DoEditSession. /// Pointer to a specified range in which an anchor is to be compared to this range start anchor. /// /// Enumeration element that indicates which anchor of the specified pWith range to compare to this range start anchor. /// /// /// Value /// Meaning /// /// /// TF_ANCHOR_START /// Compare this range start anchor with the specified range start anchor. /// /// /// TF_ANCHOR_END /// Compare this range start anchor with the specified range end anchor. /// /// /// /// /// Pointer to the result of the comparison between this range start anchor and the specified pWith range anchor. /// /// /// Value /// Meaning /// /// /// -1 /// /// This start anchor is behind the anchor of the specified range (position of this start anchor < position of the anchor of /// the specified range). /// /// /// /// 0 /// This start anchor is at the same position as the anchor of the specified range. /// /// /// +1 /// /// This start anchor is ahead of the anchor of the specified range (position of this start anchor > position of the anchor /// of the specified range). /// /// /// /// /// /// This method will never return 0 unless the two anchors are in a single region. If the caller only requires information about /// whether the two anchors are positioned at the same location, ITfRange::IsEqualStart is more efficient. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfrange-comparestart HRESULT CompareStart( TfEditCookie // ec, ITfRange *pWith, TfAnchor aPos, LONG *plResult ); int CompareStart([In] TfEditCookie ec, [In] ITfRange pWith, [In] TfAnchor aPos); /// /// The ITfRange::CompareEnd method compares the end anchor position of this range of text to an anchor in another range. /// /// Edit cookie obtained from ITfDocumentMgr::CreateContext or ITfEditSession::DoEditSession. /// Pointer to a specified range in which an anchor is to be compared with this range end anchor. /// /// Enumeration element that indicates which anchor of the specified pWith range to compare with this range end anchor. /// /// /// Value /// Meaning /// /// /// TF_ANCHOR_START /// Compare this range end anchor with the specified range start anchor. /// /// /// TF_ANCHOR_END /// Compare this range end anchor with the specified range end anchor. /// /// /// /// /// Pointer to the result of the comparison between this range end anchor and the anchor of the specified pWith range. /// /// /// Value /// Meaning /// /// /// -1 /// /// This end anchor is behind the anchor of the specified range (position of this end anchor < position of the anchor of the /// specified range). /// /// /// /// 0 /// This end anchor is at the same position as the anchor of the specified range. /// /// /// +1 /// /// This end anchor is ahead of the anchor of the specified range (position of this end anchor > position of the anchor of /// the specified range). /// /// /// /// /// /// /// This method will never return 0 unless the two anchors are in a single region. If the caller only requires information about /// whether the two anchors are positioned at the same location, ITfRange::IsEqualEnd is more efficient. /// /// /// This method is identical to ITfRange::CompareStart, except that the end anchor of this range is compared to an anchor of /// another specified range. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfrange-compareend HRESULT CompareEnd( TfEditCookie ec, // ITfRange *pWith, TfAnchor aPos, LONG *plResult ); int CompareEnd([In] TfEditCookie ec, [In] ITfRange pWith, [In] TfAnchor aPos); /// The ITfRange::AdjustForInsert method expands or contracts a range of text to adjust for text insertion. /// Edit cookie obtained from ITfDocumentMgr::CreateContext or ITfEditSession::DoEditSession. /// /// Character count of the inserted text. This count is used in a futurecall to ITfRange::SetText. If the character count is /// unknown, 0 can be used. /// /// /// Pointer to a flag that indicates whether the context owner will accept ( TRUE) or reject ( FALSE) the insertion. /// /// /// /// This method should be used to prepare a range to initiate a new composition, before editing begins. It should be used only /// when the text is not inserted at the current selection. ITFInsertAtSelection:InsertTextAtSelection or /// ITfInsertAtSelection::InsertEmbeddedAtSelection are the correct methods to use when text is inserted at the current selection. /// /// /// The context owner can use this method to preserve behavior and help maintain a consistent user experience. For example, /// certain characters or objects in the context can be preserved from modifications, or overtyping can be supported. /// /// /// This method is not necessary when modifying an existing composition. It is acceptable to call ITfRange::SetText /// directly to modify text previously entered by the caller. /// /// /// On exit, if *pfInsertOk is set to FALSE, a future call to ITfRange::SetText or ITfRange::InsertEmbedded with /// this range is likely to fail. Otherwise, *pfInsertOk will be set to TRUE, and the range start anchor or end anchor /// can be repositioned at the discretion of the context owner. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfrange-adjustforinsert HRESULT AdjustForInsert( // TfEditCookie ec, ULONG cchInsert, BOOL *pfInsertOk ); [return: MarshalAs(UnmanagedType.Bool)] bool AdjustForInsert([In] TfEditCookie ec, uint cchInsert); /// Obtains the gravity of the anchors in the object. /// Pointer to a TfGravity value that receives the gravity of the start anchor. /// Pointer to a TfGravity value that receives the gravity of the end anchor. // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfrange-getgravity HRESULT GetGravity( TfGravity *pgStart, // TfGravity *pgEnd ); void GetGravity(out TfGravity pgStart, out TfGravity pgEnd); /// Sets the gravity of the anchors in the object. /// /// Contains an edit cookie that identifies the edit context obtained from ITfDocumentMgr::CreateContext or ITfEditSession::DoEditSession. /// /// Contains one of the TfGravity values that specifies the gravity of the start anchor. /// Contains one of the TfGravity values that specifies the gravity of the end anchor. // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfrange-setgravity HRESULT SetGravity( TfEditCookie ec, // TfGravity gStart, TfGravity gEnd ); void SetGravity([In] TfEditCookie ec, [In] TfGravity gStart, [In] TfGravity gEnd); /// The ITfRange::Clone method duplicates this range of text. /// Pointer to a new range object that references this range. /// /// /// The resulting new range object can be modified without affecting the original. However, modifying the document that contains /// the new range might cause the original range's anchors to be repositioned. /// /// The gravity of the original is preserved in the new range. /// // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfrange-clone HRESULT Clone( ITfRange **ppClone ); ITfRange Clone(); /// Obtains the context object to which the range belongs. /// Pointer to an ITfContext interface pointer that receives the context object that the range belongs to. // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfrange-getcontext HRESULT GetContext( ITfContext // **ppContext ); ITfContext GetContext(); } /// Obtains the specified function object. /// The type of the requested function within the group specified by rguid. /// The ITfFunctionProvider instance. /// /// Contains a GUID value that identifies the function group that the requested function belongs to. This value can be GUID_NULL. /// /// An interface of that receives the requested function interface. public static T? GetFunction(this ITfFunctionProvider fp, Guid rguid = default) where T : class { HRESULT hr = fp.GetFunction(rguid, typeof(T).GUID, out var obj); return hr.Succeeded ? (T)obj! : (hr == HRESULT.E_NOINTERFACE ? null : throw hr.GetException()!); } /// The ITfRange::GetText method obtains the content covered by this range of text. /// The ITfRange instance. /// Edit cookie that identifies the edit context obtained from ITfDocumentMgr::CreateContext or ITfEditSession::DoEditSession. /// /// Bit fields that specify optional behavior. /// /// /// Value /// Meaning /// /// /// TF_TF_MOVESTART /// Start anchor of the range is advanced to the position after the last character returned. /// /// /// TF_TF_IGNOREEND /// /// Method attempts to fill pchText with the maximum number of characters, instead of halting the copy at the position occupied by /// the end anchor of the range. /// /// /// /// /// The text in the range. // https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-itfrange-gettext HRESULT GetText( TfEditCookie ec, DWORD // dwFlags, WCHAR *pchText, ULONG cchMax, ULONG *pcch ); public static string GetText(this ITfRange range, [In] TfEditCookie ec, TF_TF dwFlags = 0) { var sb = new StringBuilder(Kernel32.MAX_PATH * 2); range.GetText(ec, dwFlags, sb, (uint)sb.Capacity, out var len); sb.Length = (int)len; return sb.ToString(); } }