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

        internal TextServicesPropertyRanges(
            TextStore textstore,
            Guid guid)
        {
            _guid      = guid;
            _textstore = textstore;
        }
Example #2
0
        internal override void WinEventProc(int eventId, IntPtr hwnd)
        {
            Invariant.Assert(eventId == NativeMethods.EVENT_SYSTEM_MOVESIZEEND);

            if (_arTextStore != null)
            {
                for (int i = 0; i < _arTextStore.Count; i++)
                {
                    bool      notified  = false;
                    TextStore textstore = (TextStore)_arTextStore[i];

                    IntPtr hwndTemp = textstore.CriticalSourceWnd;
                    while (hwndTemp != IntPtr.Zero)
                    {
                        if (hwnd == hwndTemp)
                        {
                            // Only when the parent window of the source of this TextStore is
                            // moved or resized, we notfiy to Cicero.
                            textstore.OnLayoutUpdated();
                            notified = true;
                            break;
                        }
                        hwndTemp = UnsafeNativeMethods.GetParent(new HandleRef(this, hwndTemp));
                    }
                    if (!notified)
                    {
                        textstore.MakeLayoutChangeOnGotFocus();
                    }
                }
            }
        }
Example #3
0
 private void Initialize()
 {
     RequestLine.Clear();
     HeaderList.Clear();
     MessageBody = null;
     c           = TextStore.ReadChar();
 }
Example #4
0
 internal override void WinEventProc(int eventId, IntPtr hwnd)
 {
     Invariant.Assert(eventId == 11);
     if (this._arTextStore != null)
     {
         for (int i = 0; i < this._arTextStore.Count; i++)
         {
             bool      flag      = false;
             TextStore textStore = (TextStore)this._arTextStore[i];
             IntPtr    intPtr    = textStore.CriticalSourceWnd;
             while (intPtr != IntPtr.Zero)
             {
                 if (hwnd == intPtr)
                 {
                     textStore.OnLayoutUpdated();
                     flag = true;
                     break;
                 }
                 intPtr = UnsafeNativeMethods.GetParent(new HandleRef(this, intPtr));
             }
             if (!flag)
             {
                 textStore.MakeLayoutChangeOnGotFocus();
             }
         }
     }
 }
        protected byte[] ReadToEOF()
        {
            const int INITIAL_SIZE = 4096;
            const int MIN_SPACE    = 1024;
            const int MAX_DELTA    = 65536;
            int       size         = INITIAL_SIZE;
            var       buf          = new byte[size];
            int       len          = 0;

            while (true)
            {
                if (len + MIN_SPACE > size)
                {
                    size += size < MAX_DELTA ? size : MAX_DELTA;
                    Array.Resize <byte>(ref buf, size);
                }
                int delta = TextStore.Read(buf, len, size - len);
                if (delta == -1)
                {
                    Array.Resize <byte>(ref buf, len);
                    return(buf);
                }
                len += delta;
            }
        }
Example #6
0
        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);
        }
 protected bool ParseQuotedString()
 {
     if (c == '\"')
     {
         sb.Clear();
         sb.Append('\"');
         c = TextStore.ReadChar();
     }
     else
     {
         return(false);
     }
     while (c != '\"')
     {
         if (ParseQuotedPair())
         {
             continue;
         }
         else if (ParseText())
         {
             continue;
         }
         else
         {
             throw new Exception(ERROR_MALFORMED_QUOTEDSTRING);
         }
     }
     sb.Append('\"');
     c = TextStore.ReadChar();
     return(true);
 }
 private void ParseChunkTrailer()
 {
     while (true)
     {
         var name = ParseFieldName();
         if (name == null)
         {
             return;
         }
         if (c == ':')
         {
             c = TextStore.ReadChar();
         }
         else
         {
             throw new Exception(string.Format(ERROR_MALFORMED_HEADER, Name));
         }
         try
         {
             var value = ParseFieldValue();
             ParseCRLF();
             ((HttpChunkedMessageBody)MessageBody).Trailer.Add(name, value.Trim());
         }
         catch (Exception ex)
         {
             throw new Exception(string.Format(ERROR_MALFORMED_HEADER, Name), ex);
         }
     }
 }
        protected bool ParseHeader()
        {
            var name = ParseFieldName();

            if (name == null)
            {
                return(false);
            }
            if (c == ':')
            {
                c = TextStore.ReadChar();
            }
            else
            {
                throw new Exception(string.Format(ERROR_MALFORMED_HEADER, Name));
            }
            try
            {
                var value = ParseFieldValue();
                ParseCRLF();
                var h = HeaderList.Add(name, value.Trim());
                if (h.Name == HttpHeaderContentType.NAME)
                {
                    CheckEncoding(((HttpHeaderContentType)h).CharSet);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format(ERROR_MALFORMED_HEADER, Name), ex);
            }
            return(true);
        }
Example #10
0
        public RatStore()
        {
            DataStore = new DatabaseStore();
            if (!DataStore.Connected())
            {
                DataStore = new TextStore();
            }

            DataStore.Initialize();

            try
            {
                ChangeLocation(1);
            }
            catch
            {
                // Add test location if none available
                Address    = "123 Test St, Everett, WA 98203";
                LocationId = 1;
                DataStore.AddLocation(this);
                DataStore.Save();

                ChangeLocation(1);
            }
        }
Example #11
0
        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);
        }
Example #12
0
 private void Initialize(HttpMethod method)
 {
     Method = method;
     StatusLine.Clear();
     HeaderList.Clear();
     MessageBody = null;
     c           = TextStore.ReadChar();
 }
Example #13
0
 // Token: 0x06003EF3 RID: 16115 RVA: 0x0011F480 File Offset: 0x0011D680
 internal void RegisterTextStore(TextStore textstore)
 {
     if (this._arTextStore == null)
     {
         this._arTextStore = new ArrayList(1);
     }
     this._arTextStore.Add(textstore);
 }
Example #14
0
            private bool AddReconversionItems(TextEditor textEditor)
            {
                MenuItem  menuItem;
                TextStore textStore = textEditor.TextStore;

                if (textStore == null)
                {
                    GC.SuppressFinalize(this);
                    return(false);
                }

                ReleaseCandidateList(null);
                _candidateList = new  SecurityCriticalDataClass <UnsafeNativeMethods.ITfCandidateList>(textStore.GetReconversionCandidateList());
                if (CandidateList == null)
                {
                    GC.SuppressFinalize(this);
                    return(false);
                }

                int count = 0;

                CandidateList.GetCandidateNum(out count);

                if (count > 0)
                {
                    // Like Winword, we show the first 5 candidates in the context menu.
                    int i;
                    for (i = 0; i < 5 && i < count; i++)
                    {
                        string suggestion;
                        UnsafeNativeMethods.ITfCandidateString candString;

                        CandidateList.GetCandidate(i, out candString);
                        candString.GetString(out suggestion);

                        menuItem                  = new ReconversionMenuItem(this, i);
                        menuItem.Header           = suggestion;
                        menuItem.InputGestureText = GetMenuItemDescription(suggestion);
                        this.Items.Add(menuItem);

                        Marshal.ReleaseComObject(candString);
                    }
                }

                // Like Winword, we show "More" menu to open TIP's candidate list if there are more
                // than 5 candidates.
                if (count > 5)
                {
                    menuItem         = new EditorMenuItem();
                    menuItem.Header  = SR.Get(SRID.TextBox_ContextMenu_More);
                    menuItem.Command = ApplicationCommands.CorrectionList;
                    this.Items.Add(menuItem);
                    menuItem.CommandTarget = textEditor.UiScope;
                }

                return((count > 0) ? true : false);
            }
Example #15
0
        public static async Task <Text> GetText(string keyword)
        {
            IDataStore <Text> regTextStore = new TextStore();
            IDataStore <Text> sosTextStore = new SOSTextStore();
            var  textStore = keyword == "text" ? regTextStore : sosTextStore;
            Text text      = await textStore.GetAsync(keyword);

            return(text);
        }
Example #16
0
 internal void RegisterWinEventSink(TextStore textstore)
 {
     if (this._winEvent == null)
     {
         this._winEvent = new MoveSizeWinEventHandler();
         this._winEvent.Start();
     }
     this._winEvent.RegisterTextStore(textstore);
 }
Example #17
0
 internal void UnregisterWinEventSink(TextStore textstore)
 {
     this._winEvent.UnregisterTextStore(textstore);
     if (this._winEvent.TextStoreCount == 0)
     {
         this._winEvent.Stop();
         this._winEvent.Clear();
         this._winEvent = null;
     }
 }
Example #18
0
 /// <summary>
 /// Construct full text state for formatting
 /// </summary>
 private FullTextState(
     TextStore store,
     TextStore markerStore,
     bool isSideways
     )
 {
     _isSideways  = isSideways;
     _store       = store;
     _markerStore = markerStore;
 }
Example #19
0
 private void ParseReasonPhrase()
 {
     sb.Clear();
     while (c != -1 && !HttpChar.IsControl(c))
     {
         sb.Append((char)c);
         c = TextStore.ReadChar();
     }
     StatusLine.ReasonPhrase = sb.ToString();
 }
Example #20
0
        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;
        }
 protected void ParseSP()
 {
     if (c == ' ')
     {
         c = TextStore.ReadChar();
     }
     else
     {
         throw new Exception(ERROR_MISSING_SP);
     }
 }
Example #22
0
        /// <summary>
        /// Map LSCP to host CP, and return the last LSRun
        /// before the specified limit.
        /// </summary>
        internal LSRun CountText(
            int lscpLim,
            int cpFirst,
            out int count
            )
        {
            LSRun lastRun = null;

            count = 0;

            int lsccp = lscpLim - _store.CpFirst;

            Debug.Assert(lsccp > 0, "Zero-length text line!");

            foreach (Span span in _store.PlsrunVector)
            {
                if (lsccp <= 0)
                {
                    break;
                }

                Plsrun plsrun = (Plsrun)span.element;

                // There should be no marker runs in _plsrunVector.
                Debug.Assert(!TextStore.IsMarker(plsrun));

                // Is it a normal, non-static, LSRun?
                if (plsrun >= Plsrun.FormatAnchor)
                {
                    // Get the run and remember the last run.
                    lastRun = _store.GetRun(plsrun);

                    // Accumulate the length.
                    int cpRun = lastRun.Length;
                    if (cpRun > 0)
                    {
                        if (lsccp < span.length && cpRun == span.length)
                        {
                            count += lsccp;
                            break;
                        }
                        count += cpRun;
                    }
                }

                lsccp -= span.length;
            }

            // make char count relative to cpFirst as the cpFirst of this metrics may not
            // be the same as the cpFirst of the store in optimal paragraph formatting.
            count = count - cpFirst + _store.CpFirst;

            return(lastRun);
        }
Example #23
0
        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);
        }
Example #24
0
 internal void UnregisterTextStore(TextStore textstore, bool finalizer)
 {
     if (!finalizer)
     {
         this.OnUnregisterTextStore(textstore);
         return;
     }
     if (!this._isDispatcherShutdownFinished)
     {
         base.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new DispatcherOperationCallback(this.OnUnregisterTextStore), textstore);
     }
 }
Example #25
0
        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;
            }
        }
Example #26
0
        //------------------------------------------------------
        //
        //  Private Method
        //
        //------------------------------------------------------

        #region Private Method

        // This is a callback in the dispacher thread to unregister TextStore.
        private object OnUnregisterTextStore(object arg)
        {
            UnsafeNativeMethods.ITfContext context;
            UnsafeNativeMethods.ITfSource  source;

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

            TextStore textstore = (TextStore)arg;

            // We don't have to release Dispatcher.
            // These Cicero COM calls could be marshalled when UnregisterTextStore is called from
            // TextEditor's Finalizer through TextStore.OnDetach. GC Thread does not take Dispatcher.
            if (textstore.ThreadFocusCookie != UnsafeNativeMethods.TF_INVALID_COOKIE)
            {
                source = _threadManager.Value as UnsafeNativeMethods.ITfSource;
                source.UnadviseSink(textstore.ThreadFocusCookie);
                textstore.ThreadFocusCookie = UnsafeNativeMethods.TF_INVALID_COOKIE;
            }

            textstore.DocumentManager.GetBase(out context);
            if (context != null)
            {
                if (textstore.EditSinkCookie != UnsafeNativeMethods.TF_INVALID_COOKIE)
                {
                    source = context as UnsafeNativeMethods.ITfSource;
                    source.UnadviseSink(textstore.EditSinkCookie);
                    textstore.EditSinkCookie = UnsafeNativeMethods.TF_INVALID_COOKIE;
                }
                Marshal.ReleaseComObject(context);
            }

            textstore.DocumentManager.Pop(UnsafeNativeMethods.PopFlags.TF_POPF_ALL);
            Marshal.ReleaseComObject(textstore.DocumentManager);
            textstore.DocumentManager = null;

            Debug.Assert(_registeredtextstorecount > 0, "Overrelease TextStore!");
            _registeredtextstorecount--;

            // If Dispatcher is finished and the last textstore
            // is unregistered, we don't need ThreadManager any more. Deactivate and release it.
            // We keep ThreadManager active as long as Dispatcher is alive even if
            // _registeredtextstorecount is 0.
            if (_isDispatcherShutdownFinished && (_registeredtextstorecount == 0))
            {
                DeactivateThreadManager();
            }

            return(null);
        }
Example #27
0
        public static async Task <string> GetConfigJson(string configName)
        {
            using (var store = new TextStore())
            {
                var cfgName = configName.ToLower();

                var pathFileExt = IsDebug && File.Exists(StorageUtils.PathCombine(AppDataPath, $"{cfgName}{DebugFileExt}")) ? DebugFileExt : LiveFileExt;

                var json = await store.ReadAsync(StorageUtils.PathCombine(AppDataPath, $"{cfgName}{pathFileExt}"));

                return(json);
            }
        }
Example #28
0
        public static async Task <string> GetConfigJsonAsync(string configName)
        {
            using (var store = new TextStore())
            {
                var cfgName = configName.ToLower();

                var liveFile = StorageUtils.PathCombine(AppDataPath, $"{cfgName}{LiveFileExt}");

                if (!File.Exists(liveFile))
                {
                    Logger.Log(LogLevel.Fatal, $"{cfgName}{LiveFileExt} is missing from {AppDataPath}");
                    throw new FileNotFoundException();
                }

                var liveJson = await store.ReadAsync(liveFile);

                if (!IsDebug)
                {
                    return(liveJson);
                }

                var debugFile = StorageUtils.PathCombine(AppDataPath, $"{cfgName}{DebugFileExt}");

                if (!File.Exists(debugFile))
                {
                    Logger.Log(LogLevel.Warn, $"{cfgName}{DebugFileExt} is missing from {AppDataPath}, using live config");
                    return(liveJson);
                }

                var debugJson = await store.ReadAsync(debugFile);

                var jObjLive  = JObject.Parse(liveJson);
                var jObjDebug = JObject.Parse(debugJson);

                foreach (var prop in jObjDebug.Properties())
                {
                    var targetProperty = jObjLive.Property(prop.Name);

                    if (targetProperty == null)
                    {
                        jObjDebug.Add(prop.Name, prop.Value);
                    }
                    else
                    {
                        targetProperty.Value = prop.Value;
                    }
                }

                return(jObjLive.ToString(Formatting.None));
            }
        }
Example #29
0
        // Token: 0x060064E9 RID: 25833 RVA: 0x001C5230 File Offset: 0x001C3430
        internal static bool IsComposing(TextBoxBase tbb)
        {
            if (tbb == null)
            {
                return(false);
            }
            TextEditor textEditor = tbb.TextEditor;

            if (textEditor == null)
            {
                return(false);
            }
            TextStore textStore = textEditor.TextStore;

            return(textStore != null && textStore.IsEffectivelyComposing);
        }
Example #30
0
 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);
         }
     }
 }
        /// <summary>
        /// Create a fulltext state object from formatting info for subsequent fulltext formatting
        /// e.g. fulltext line, mix/max computation, potential breakpoints for optimal paragraph formatting.
        /// </summary>
        internal static FullTextState Create(
            FormatSettings      settings,
            int                 cpFirst,
            int                 finiteFormatWidth
            )
        {
            // prepare text stores
            TextStore store = new TextStore(
                settings, 
                cpFirst, 
                0, 
                settings.GetFormatWidth(finiteFormatWidth)
                );

            ParaProp pap = settings.Pap;
            TextStore markerStore = null;

            if(     pap.FirstLineInParagraph
                &&  pap.TextMarkerProperties != null
                &&  pap.TextMarkerProperties.TextSource != null)
            {
                // create text store specifically for marker
                markerStore = new TextStore(
                    // create specialized settings for marker store e.g. with marker text source
                    new FormatSettings(
                        settings.Formatter,
                        pap.TextMarkerProperties.TextSource,
                        new TextRunCacheImp(),   // no cross-call run cache available for marker store
                        pap,                     // marker by default use the same paragraph properties
                        null,                    // not consider previousLineBreak
                        true,                    // isSingleLineFormatting
                        settings.TextFormattingMode,
                        settings.IsSideways
                        ),
                    0,                           // marker store always started with cp == 0
                    TextStore.LscpFirstMarker,   // first lscp value for marker text
                    Constants.IdealInfiniteWidth // formatWidth 
                    );
            }

            // construct a new fulltext state object
            return new FullTextState(store, markerStore, settings.IsSideways);
        }
 /// <summary>
 /// Construct full text state for formatting
 /// </summary>
 private FullTextState(
     TextStore       store,
     TextStore       markerStore,
     bool isSideways
     )
 {
     _isSideways = isSideways;
     _store = store;
     _markerStore = markerStore;
 }
            /// <summary>
            /// Prefetch the lsruns up to the point of the specified line length and map
            /// the specified length to the corresponding LSCP length.
            /// </summary>
            /// <remarks>
            /// See comment in the remark section of FullTextState.GetBreakpointInternalCp.
            /// </remarks>
            private int PrefetchLSRuns(
                TextStore   store,
                int         cpFirst,
                int         lineLength
                )
            {
                Debug.Assert(lineLength > 0);

                LSRun lsrun;
                int prefetchLength = 0;
                int lscpLineLength = 0;

                int lastSpanLength = 0;
                int lastRunLength = 0;

                do
                {
                    Plsrun plsrun;
                    int lsrunOffset;
                    int lsrunLength;

                    lsrun = store.FetchLSRun(
                        cpFirst + lscpLineLength,
                        _textFormattingMode,
                        false,
                        out plsrun,
                        out lsrunOffset,
                        out lsrunLength
                        );

                    if (lineLength == prefetchLength && lsrun.Type == Plsrun.Reverse)
                    {
                        break;
                    }

                    lastSpanLength = lsrunLength;
                    lastRunLength = lsrun.Length;

                    lscpLineLength += lastSpanLength;
                    prefetchLength += lastRunLength;

                } while (   !TextStore.IsNewline(lsrun.Type)
                        &&  lineLength >= prefetchLength
                    );

                // calibrate the LSCP length to the LSCP equivalence of the last CP of the line

                if (prefetchLength == lineLength || lastSpanLength == lastRunLength)
                    return lscpLineLength - prefetchLength + lineLength;

                Invariant.Assert(prefetchLength - lineLength == lastRunLength);
                return lscpLineLength - lastSpanLength;
            }