private void UnadviseNotifySink()
        {
            Debug.Assert(_cookie != UnsafeNativeMethods.TF_INVALID_COOKIE, "Cookie is not set.");

            UnsafeNativeMethods.ITfSource source = _ipp.Value as UnsafeNativeMethods.ITfSource;

            source.UnadviseSink(_cookie);

            _cookie = UnsafeNativeMethods.TF_INVALID_COOKIE;
        }
        private void AdviseNotifySink(object o)
        {
            Debug.Assert(_cookie == UnsafeNativeMethods.TF_INVALID_COOKIE, "Cookie is already set.");

            UnsafeNativeMethods.ITfSource source = _ipp.Value as UnsafeNativeMethods.ITfSource;

            // workaround because I can't pass a ref to a readonly constant
            Guid guid = UnsafeNativeMethods.IID_ITfLanguageProfileNotifySink;

            source.AdviseSink(ref guid, o, out _cookie);
        }
示例#3
0
        private void _RegisterTextStore(TextStore textstore)
        {
            int editCookie        = -1;
            int threadFocusCookie = -1;
            int editSinkCookie    = -1;

            if (this._threadManager == null)
            {
                this._threadManager = new SecurityCriticalDataClass <UnsafeNativeMethods.ITfThreadMgr>(TextServicesLoader.Load());
                if (this._threadManager.Value == null)
                {
                    this._threadManager = null;
                    return;
                }
                int value;
                this._threadManager.Value.Activate(out value);
                this._clientId = new SecurityCriticalData <int>(value);
                base.Dispatcher.ShutdownFinished += this.OnDispatcherShutdownFinished;
            }
            UnsafeNativeMethods.ITfDocumentMgr tfDocumentMgr;
            this._threadManager.Value.CreateDocumentMgr(out tfDocumentMgr);
            UnsafeNativeMethods.ITfContext tfContext;
            tfDocumentMgr.CreateContext(this._clientId.Value, (UnsafeNativeMethods.CreateContextFlags) 0, textstore, out tfContext, out editCookie);
            tfDocumentMgr.Push(tfContext);
            if (textstore != null)
            {
                Guid guid = UnsafeNativeMethods.IID_ITfThreadFocusSink;
                UnsafeNativeMethods.ITfSource tfSource = this._threadManager.Value as UnsafeNativeMethods.ITfSource;
                tfSource.AdviseSink(ref guid, textstore, out threadFocusCookie);
            }
            if (textstore != null)
            {
                Guid guid = UnsafeNativeMethods.IID_ITfTextEditSink;
                UnsafeNativeMethods.ITfSource tfSource = tfContext as UnsafeNativeMethods.ITfSource;
                tfSource.AdviseSink(ref guid, textstore, out editSinkCookie);
            }
            Marshal.ReleaseComObject(tfContext);
            textstore.DocumentManager   = tfDocumentMgr;
            textstore.ThreadFocusCookie = threadFocusCookie;
            textstore.EditSinkCookie    = editSinkCookie;
            textstore.EditCookie        = editCookie;
            if (textstore.UiScope.IsKeyboardFocused)
            {
                textstore.OnGotFocus();
            }
            this._registeredtextstorecount++;
        }
示例#4
0
        /// <summary>
        ///     Unadvise the notify sink of the compartment update.
        /// </summary>
        internal void UnadviseNotifySink()
        {
            Debug.Assert(_cookie != UnsafeNativeMethods.TF_INVALID_COOKIE, "cookie is not set.");

            UnsafeNativeMethods.ITfCompartment compartment = GetITfCompartment();
            if (compartment == null)
            {
                return;
            }

            UnsafeNativeMethods.ITfSource source = compartment as UnsafeNativeMethods.ITfSource;
            source.UnadviseSink(_cookie);
            _cookie = UnsafeNativeMethods.TF_INVALID_COOKIE;

            Marshal.ReleaseComObject(compartment);
            Marshal.ReleaseComObject(source);
        }
示例#5
0
        private object OnUnregisterTextStore(object arg)
        {
            if (this._threadManager == null || this._threadManager.Value == null)
            {
                return(null);
            }
            SecurityPermission securityPermission = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
            TextStore          textStore          = (TextStore)arg;

            if (textStore.ThreadFocusCookie != -1)
            {
                UnsafeNativeMethods.ITfSource tfSource = this._threadManager.Value as UnsafeNativeMethods.ITfSource;
                tfSource.UnadviseSink(textStore.ThreadFocusCookie);
                textStore.ThreadFocusCookie = -1;
            }
            UnsafeNativeMethods.ITfContext tfContext;
            textStore.DocumentManager.GetBase(out tfContext);
            if (tfContext != null)
            {
                if (textStore.EditSinkCookie != -1)
                {
                    UnsafeNativeMethods.ITfSource tfSource = tfContext as UnsafeNativeMethods.ITfSource;
                    tfSource.UnadviseSink(textStore.EditSinkCookie);
                    textStore.EditSinkCookie = -1;
                }
                Marshal.ReleaseComObject(tfContext);
            }
            securityPermission.Assert();
            try
            {
                textStore.DocumentManager.Pop(UnsafeNativeMethods.PopFlags.TF_POPF_ALL);
            }
            finally
            {
                CodeAccessPermission.RevertAssert();
            }
            Marshal.ReleaseComObject(textStore.DocumentManager);
            textStore.DocumentManager = null;
            this._registeredtextstorecount--;
            if (this._isDispatcherShutdownFinished && this._registeredtextstorecount == 0)
            {
                this.DeactivateThreadManager();
            }
            return(null);
        }
示例#6
0
        //------------------------------------------------------
        //
        //  Public Methods
        //
        //------------------------------------------------------

        #region Public Methods
        #endregion Public Methods

        //------------------------------------------------------
        //
        //  Public Operators
        //
        //------------------------------------------------------


        //------------------------------------------------------
        //
        //  Public Properties
        //
        //------------------------------------------------------


        //------------------------------------------------------
        //
        //  Public Events
        //
        //------------------------------------------------------


        //------------------------------------------------------
        //
        //  Protected Methods
        //
        //------------------------------------------------------


        //------------------------------------------------------
        //
        //  Internal Methods
        //
        //------------------------------------------------------

        #region Internal Methods

        /// <summary>
        ///     Advise the notify sink of the compartment update.
        /// </summary>
        internal void AdviseNotifySink(UnsafeNativeMethods.ITfCompartmentEventSink sink)
        {
            Debug.Assert(_cookie == UnsafeNativeMethods.TF_INVALID_COOKIE, "cookie is already set.");

            UnsafeNativeMethods.ITfCompartment compartment = GetITfCompartment();
            if (compartment == null)
            {
                return;
            }

            UnsafeNativeMethods.ITfSource source = compartment as UnsafeNativeMethods.ITfSource;

            // workaround because I can't pass a ref to a readonly constant
            Guid guid = UnsafeNativeMethods.IID_ITfCompartmentEventSink;

            source.AdviseSink(ref guid, sink, out _cookie);
            Marshal.ReleaseComObject(compartment);
            Marshal.ReleaseComObject(source);
        }
示例#7
0
        internal static void StartTransitoryExtension(TextStore textstore)
        {
            UnsafeNativeMethods.ITfCompartmentMgr tfCompartmentMgr = textstore.DocumentManager as UnsafeNativeMethods.ITfCompartmentMgr;
            Guid guid = UnsafeNativeMethods.GUID_COMPARTMENT_TRANSITORYEXTENSION;

            UnsafeNativeMethods.ITfCompartment tfCompartment;
            tfCompartmentMgr.GetCompartment(ref guid, out tfCompartment);
            object obj = 2;

            tfCompartment.SetValue(0, ref obj);
            guid = UnsafeNativeMethods.IID_ITfTransitoryExtensionSink;
            UnsafeNativeMethods.ITfSource tfSource = textstore.DocumentManager as UnsafeNativeMethods.ITfSource;
            if (tfSource != null)
            {
                int transitoryExtensionSinkCookie;
                tfSource.AdviseSink(ref guid, textstore, out transitoryExtensionSinkCookie);
                textstore.TransitoryExtensionSinkCookie = transitoryExtensionSinkCookie;
            }
            Marshal.ReleaseComObject(tfCompartment);
        }
示例#8
0
        internal static void StopTransitoryExtension(TextStore textstore)
        {
            UnsafeNativeMethods.ITfCompartmentMgr tfCompartmentMgr = textstore.DocumentManager as UnsafeNativeMethods.ITfCompartmentMgr;
            if (textstore.TransitoryExtensionSinkCookie != -1)
            {
                UnsafeNativeMethods.ITfSource tfSource = textstore.DocumentManager as UnsafeNativeMethods.ITfSource;
                if (tfSource != null)
                {
                    tfSource.UnadviseSink(textstore.TransitoryExtensionSinkCookie);
                }
                textstore.TransitoryExtensionSinkCookie = -1;
            }
            Guid guid_COMPARTMENT_TRANSITORYEXTENSION = UnsafeNativeMethods.GUID_COMPARTMENT_TRANSITORYEXTENSION;

            UnsafeNativeMethods.ITfCompartment tfCompartment;
            tfCompartmentMgr.GetCompartment(ref guid_COMPARTMENT_TRANSITORYEXTENSION, out tfCompartment);
            object obj = 0;

            tfCompartment.SetValue(0, ref obj);
            Marshal.ReleaseComObject(tfCompartment);
        }