//------------------------------------------------------
        //
        //  Constructors
        //
        //------------------------------------------------------

        internal TextServicesPropertyRanges(
            TextStore textstore,
            Guid guid)
        {
            _guid = guid;
            _textstore = textstore;
        }
        //------------------------------------------------------
        //
        //  Internal Methods
        //
        //------------------------------------------------------

        #region Internal Methods

        // Register text store that will receive move/sice event.
        internal void RegisterTextStore(TextStore textstore)
        {
            if (_arTextStore == null)
            {
               _arTextStore = new ArrayList(1);
            }

            _arTextStore.Add(textstore);
        }
        internal void RegisterTextStore(TextStore textstore)
        {
            // VerifyAccess();

            Debug.Assert(Thread.CurrentThread.GetApartmentState() == ApartmentState.STA, "OnRegisterTextStore must be called on STA thread");

            // Register textstore and advise sinks.
            _RegisterTextStore((TextStore)textstore);

            _thread = Thread.CurrentThread;
        }
 // Unregister text store.
 internal void UnregisterTextStore(TextStore textstore)
 {
     _arTextStore.Remove(textstore);
 }
        //------------------------------------------------------
        //
        //  Constructors
        //
        //------------------------------------------------------

        #region Constructors

        internal TextServicesDisplayAttributePropertyRanges(TextStore textstore)
            : base(textstore, UnsafeNativeMethods.GUID_PROP_ATTRIBUTE)
        { 
        }
        //------------------------------------------------------
        //
        //  Constructors
        //
        //------------------------------------------------------

        #region Constructors

        internal TextServicesProperty(TextStore textstore)
        {
            _textstore = textstore;
        }
 internal void UnregisterTextStore(TextStore textstore, bool finalizer)
 {
     if (!finalizer)
     {
         OnUnregisterTextStore(textstore);
     }
     else
     {
         // GC Finalizer is detaching TextStore and the dispatcher thread could be already
         // terminated or Dispatcher is already finished.
         if (!_isDispatcherShutdownFinished)
         {
             Dispatcher.BeginInvoke(DispatcherPriority.Normal, new DispatcherOperationCallback(OnUnregisterTextStore), textstore);
         }
     }
 }
        private void _RegisterTextStore(TextStore textstore)
        {
            UnsafeNativeMethods.ITfDocumentMgr doc;
            UnsafeNativeMethods.ITfContext context;
            UnsafeNativeMethods.ITfSource source;
            int editCookie = UnsafeNativeMethods.TF_INVALID_COOKIE;
            int threadFocusCookie = UnsafeNativeMethods.TF_INVALID_COOKIE;
            int editSinkCookie = UnsafeNativeMethods.TF_INVALID_COOKIE;
            Guid guid;

            Debug.Assert(CheckAccess(), "RegisterTextStore called on bad thread!");

            // Get ITfThreadMgr
            if (_threadManager == null)
            {
                Debug.Assert(_isDispatcherShutdownFinished == false, "Was this dispather finished?");
                Debug.Assert(_registeredtextstorecount == 0, "TextStore was registered without ThreadMgr?");

                // TextServicesLoader.Load() might return null if no text services are installed or enabled.
                _threadManager = new SecurityCriticalDataClass<UnsafeNativeMethods.ITfThreadMgr>(TextServicesLoader.Load());

                if (_threadManager.Value == null)
                {
                    _threadManager = null;
                    return;
                }

                // Activate TSF on this thread if this is the first TextStore.
                int clientIdTemp;
                _threadManager.Value.Activate(out clientIdTemp);
                _clientId = new SecurityCriticalData<int>(clientIdTemp);

                // We want to get the notification when Dispatcher is finished.
                Dispatcher.ShutdownFinished += new EventHandler(OnDispatcherShutdownFinished);
            }

            // Create a TSF document.
            _threadManager.Value.CreateDocumentMgr(out doc);
            doc.CreateContext(_clientId.Value, 0 /* flags */, textstore, out context, out editCookie);
            doc.Push(context);

            // Attach a thread focus sink.
            if (textstore is UnsafeNativeMethods.ITfThreadFocusSink)
            {
                guid = UnsafeNativeMethods.IID_ITfThreadFocusSink;
                source = _threadManager.Value as UnsafeNativeMethods.ITfSource;
                source.AdviseSink(ref guid, textstore, out threadFocusCookie);
            }

            // Attach an edit sink.
            if (textstore is UnsafeNativeMethods.ITfTextEditSink)
            {
                guid = UnsafeNativeMethods.IID_ITfTextEditSink;
                source = context as UnsafeNativeMethods.ITfSource;
                source.AdviseSink(ref guid, textstore, out editSinkCookie);
            }

            // Release any native resources we're done with.
            Marshal.ReleaseComObject(context);

            textstore.DocumentManager = doc;
            textstore.ThreadFocusCookie = threadFocusCookie;
            textstore.EditSinkCookie = editSinkCookie;
            textstore.EditCookie = editCookie;

            // If Scope of this textstore already has a focus, we need to call SetFocus()
            // in order to put this DIM on Cicero's focus. TextStore.OnGotFocus() calls
            // ITfThreadMgr::SetFocus();
            if (textstore.UiScope.IsKeyboardFocused)
            {
                textstore.OnGotFocus();
            }

            _registeredtextstorecount++;
        }
        internal static void StopTransitoryExtension(TextStore textstore)
        {
            Guid guid;
            Object var;
            UnsafeNativeMethods.ITfCompartmentMgr compmgr;
            UnsafeNativeMethods.ITfCompartment comp;

            compmgr = textstore.DocumentManager as UnsafeNativeMethods.ITfCompartmentMgr;

            // Unadvice the transitory extension sink.
            if (textstore.TransitoryExtensionSinkCookie != UnsafeNativeMethods.TF_INVALID_COOKIE)
            {
                UnsafeNativeMethods.ITfSource source;
                source = textstore.DocumentManager as UnsafeNativeMethods.ITfSource;
                if (source != null)
                {
                    // DocumentManager only supports ITfSource on Longhorn, XP does not support it
                    source.UnadviseSink(textstore.TransitoryExtensionSinkCookie);
                }
                textstore.TransitoryExtensionSinkCookie = UnsafeNativeMethods.TF_INVALID_COOKIE;
            }

            // Reset GUID_COMPARTMENT_TRANSITORYEXTENSION
            guid = UnsafeNativeMethods.GUID_COMPARTMENT_TRANSITORYEXTENSION;
            compmgr.GetCompartment(ref guid, out comp);
            var = (int)0;
            comp.SetValue(0, ref var);

            Marshal.ReleaseComObject(comp);
        }
        internal static void StartTransitoryExtension(TextStore textstore)
        {
            Guid guid;
            Object var;
            UnsafeNativeMethods.ITfCompartmentMgr compmgr;
            UnsafeNativeMethods.ITfCompartment comp;
            UnsafeNativeMethods.ITfSource source;
            int transitoryExtensionSinkCookie;

            // Start TransitryExtension
            compmgr = textstore.DocumentManager as UnsafeNativeMethods.ITfCompartmentMgr;

            // Set GUID_COMPARTMENT_TRANSITORYEXTENSION
            guid = UnsafeNativeMethods.GUID_COMPARTMENT_TRANSITORYEXTENSION;
            compmgr.GetCompartment(ref guid, out comp);
            var = (int)2; // Use level 2
            comp.SetValue(0, ref var);

            // Advise TransitoryExtension Sink and store the cookie.
            guid = UnsafeNativeMethods.IID_ITfTransitoryExtensionSink;
            source = textstore.DocumentManager as UnsafeNativeMethods.ITfSource;
            if (source != null)
            {
                // DocumentManager only supports ITfSource on Longhorn, XP does not support it
                source.AdviseSink(ref guid, textstore, out transitoryExtensionSinkCookie);
                textstore.TransitoryExtensionSinkCookie = transitoryExtensionSinkCookie;
            }

            Marshal.ReleaseComObject(comp);
        }
        internal void UnregisterWinEventSink(TextStore textstore)
        {
            _winEvent.UnregisterTextStore(textstore);

            // If the registerd text store count is 0, we don't need WinEvent hook any more.
            if (_winEvent.TextStoreCount == 0)
            {
                _winEvent.Stop();
                _winEvent.Clear();
                _winEvent = null;
            }
        }
        internal void RegisterWinEventSink(TextStore textstore)
        {
            // Start WinEvent hook to listen windows move/size event.
            // We need to call ITextStoreACPSink::OnLayoutChange() whenever the window is moved.
            if (_winEvent == null)
            {
                _winEvent = new MoveSizeWinEventHandler();
                _winEvent.Start();
            }

            _winEvent.RegisterTextStore(textstore);
        }
Beispiel #13
0
        private object InitTextStore(object o)
        { 
            // We might have been detached before this callback got dispatched. 
            if (!_pendingTextStoreInit)
            { 
                return null;
            }

            // Init a TSF TextStore if any TIPs/IMEs are installed. 
            if (_textContainer is TextContainer && TextServicesHost.Current != null)
            { 
                // We need to make sure we get back a valid thread manager first since it's possible for 
                // TextServicesLoader.ServicesInstalled to return true without TSF being usable.
                UnsafeNativeMethods.ITfThreadMgr threadManager = TextServicesLoader.Load(); 
                if (threadManager != null)
                {
                    // Demand create the TextStore.
                    if (_textstore == null) 
                    {
                        _textstore = new TextStore(this); 
                        _weakThis = new TextEditorShutDownListener(this); 
                    }
 
                    _textstore.OnAttach();
                    Marshal.ReleaseComObject(threadManager);
                }
            } 

            _pendingTextStoreInit = false; 
 
            return null;
        }