Example #1
0
        private bool GetFnReconv(ITextPointer textStart, ITextPointer textEnd, out UnsafeNativeMethods.ITfFnReconversion funcReconv, out UnsafeNativeMethods.ITfRange rangeNew)
        {
            UnsafeNativeMethods.ITfContext context;
            UnsafeNativeMethods.ITfRange range;
            UnsafeNativeMethods.ITfRangeACP rangeACP;
            bool fReconvertable = false;

            funcReconv = null;
            rangeNew = null;

            // Create ITfRangeACP for the current selection.
            //  1. Get the context from the document manager and call GetStart to get the instance of
            //     ITfRange.
            //  2. QI the ITfRange to get ITfRangeACP.
            //  3. Get start and end of the current selection from TextContainer.
            //  4. Set extent of the ITfRangeACP.
            DocumentManager.GetBase(out context);
            context.GetStart(EditCookie, out range);
            rangeACP = range as UnsafeNativeMethods.ITfRangeACP;
            int start = textStart.CharOffset;
            int end = textEnd.CharOffset;
            rangeACP.SetExtent(start, end - start);

            // Readonly fields can not be passed ref to the interface methods.
            // Create pads for them.
            Guid guidSysFunc = UnsafeNativeMethods.GUID_SYSTEM_FUNCTIONPROVIDER;
            Guid guidNull = UnsafeNativeMethods.Guid_Null;
            Guid iidFnReconv = UnsafeNativeMethods.IID_ITfFnReconversion;

            UnsafeNativeMethods.ITfFunctionProvider functionPrv;

            // ThreadMgr Method call will be marshalled to the dispatcher thread since Ciecro is STA.
            _textservicesHost.ThreadManager.GetFunctionProvider(ref guidSysFunc, out functionPrv);

            object obj;

            // ITfFnReconversion is always available in SystemFunctionProvider.
            functionPrv.GetFunction(ref guidNull, ref iidFnReconv, out obj);
            funcReconv = obj as UnsafeNativeMethods.ITfFnReconversion;
            funcReconv.QueryRange(range, out rangeNew, out fReconvertable);


            // release objects.
            Marshal.ReleaseComObject(functionPrv);

            if (!fReconvertable)
            {
                Marshal.ReleaseComObject(funcReconv);
                funcReconv = null;
            }

            Marshal.ReleaseComObject(range);
            Marshal.ReleaseComObject(context);

            return fReconvertable;
        }