internal virtual void OnEndEdit(UnsafeNativeMethods.ITfContext context, int ecReadOnly, UnsafeNativeMethods.ITfEditRecord editRecord) { UnsafeNativeMethods.ITfProperty tfProperty = null; UnsafeNativeMethods.IEnumTfRanges propertyUpdate = this.GetPropertyUpdate(editRecord); UnsafeNativeMethods.ITfRange[] array = new UnsafeNativeMethods.ITfRange[1]; int num; while (propertyUpdate.Next(1, array, out num) == 0) { ITextPointer textPointer; ITextPointer textPointer2; this.ConvertToTextPosition(array[0], out textPointer, out textPointer2); if (tfProperty == null) { context.GetProperty(ref this._guid, out tfProperty); } UnsafeNativeMethods.IEnumTfRanges enumTfRanges; if (tfProperty.EnumRanges(ecReadOnly, out enumTfRanges, array[0]) == 0) { UnsafeNativeMethods.ITfRange[] array2 = new UnsafeNativeMethods.ITfRange[1]; while (enumTfRanges.Next(1, array2, out num) == 0) { this.OnRange(tfProperty, ecReadOnly, array2[0]); Marshal.ReleaseComObject(array2[0]); } Marshal.ReleaseComObject(enumTfRanges); } Marshal.ReleaseComObject(array[0]); } Marshal.ReleaseComObject(propertyUpdate); if (tfProperty != null) { Marshal.ReleaseComObject(tfProperty); } }
//------------------------------------------------------ // // Internal Events // //------------------------------------------------------ //------------------------------------------------------ // // Private Methods // //------------------------------------------------------ // get the text from ITfRange. private string StringFromITfRange(UnsafeNativeMethods.ITfRange range, int ecReadOnly) { // Transitory Document uses ther TextStore, which is ACP base. UnsafeNativeMethods.ITfRangeACP rangeacp = (UnsafeNativeMethods.ITfRangeACP)range; int start; int count; int countRet; rangeacp.GetExtent(out start, out count); char[] text = new char[count]; rangeacp.GetText(ecReadOnly, 0, text, count, out countRet); return(new string(text)); }
internal virtual void OnEndEdit(UnsafeNativeMethods.ITfContext context, int ecReadOnly, UnsafeNativeMethods.ITfEditRecord editRecord) { int fetched; UnsafeNativeMethods.IEnumTfRanges ranges; UnsafeNativeMethods.ITfProperty prop = null; ranges = GetPropertyUpdate(editRecord); UnsafeNativeMethods.ITfRange [] outRanges; outRanges = new UnsafeNativeMethods.ITfRange[1]; while (ranges.Next(1, outRanges, out fetched) == 0) { // // check the element has enabled dynamic property. // ITextPointer start; ITextPointer end; ConvertToTextPosition(outRanges[0], out start, out end); if (prop == null) { context.GetProperty(ref _guid, out prop); } UnsafeNativeMethods.IEnumTfRanges rangesProp; if (prop.EnumRanges(ecReadOnly, out rangesProp, outRanges[0]) == 0) { UnsafeNativeMethods.ITfRange [] outRangesProp; outRangesProp = new UnsafeNativeMethods.ITfRange[1]; while (rangesProp.Next(1, outRangesProp, out fetched) == 0) { OnRange(prop, ecReadOnly, outRangesProp[0]); Marshal.ReleaseComObject(outRangesProp[0]); } Marshal.ReleaseComObject(rangesProp); } Marshal.ReleaseComObject(outRanges[0]); } Marshal.ReleaseComObject(ranges); if (prop != null) { Marshal.ReleaseComObject(prop); } }
protected void ConvertToTextPosition(UnsafeNativeMethods.ITfRange range, out ITextPointer start, out ITextPointer end) { UnsafeNativeMethods.ITfRangeACP tfRangeACP = range as UnsafeNativeMethods.ITfRangeACP; int num; int num2; tfRangeACP.GetExtent(out num, out num2); if (num2 < 0) { start = null; end = null; return; } start = this._textstore.CreatePointerAtCharOffset(num, LogicalDirection.Forward); end = this._textstore.CreatePointerAtCharOffset(num + num2, LogicalDirection.Forward); }
internal override void OnEndEdit(UnsafeNativeMethods.ITfContext context, int ecReadOnly, UnsafeNativeMethods.ITfEditRecord editRecord) { if (this._compositionAdorner != null) { this._compositionAdorner.Uninitialize(); this._compositionAdorner = null; } Guid guid = base.Guid; UnsafeNativeMethods.ITfProperty tfProperty; context.GetProperty(ref guid, out tfProperty); UnsafeNativeMethods.IEnumTfRanges enumTfRanges; if (tfProperty.EnumRanges(ecReadOnly, out enumTfRanges, null) == 0) { UnsafeNativeMethods.ITfRange[] array = new UnsafeNativeMethods.ITfRange[1]; int num; while (enumTfRanges.Next(1, array, out num) == 0) { int int32Value = this.GetInt32Value(ecReadOnly, tfProperty, array[0]); TextServicesDisplayAttribute displayAttribute = TextServicesDisplayAttributePropertyRanges.GetDisplayAttribute(int32Value); if (displayAttribute != null && !displayAttribute.IsEmptyAttribute()) { ITextPointer textPointer; ITextPointer end; base.ConvertToTextPosition(array[0], out textPointer, out end); if (textPointer != null) { if (this._compositionAdorner == null) { this._compositionAdorner = new CompositionAdorner(base.TextStore.TextView); this._compositionAdorner.Initialize(base.TextStore.TextView); } this._compositionAdorner.AddAttributeRange(textPointer, end, displayAttribute); } } Marshal.ReleaseComObject(array[0]); } if (this._compositionAdorner != null) { base.TextStore.RenderScope.UpdateLayout(); this._compositionAdorner.InvalidateAdorner(); } Marshal.ReleaseComObject(enumTfRanges); } Marshal.ReleaseComObject(tfProperty); }
//------------------------------------------------------ // // Internal Methods // //------------------------------------------------------ #region Internal Methods /// <summary> /// Apply attribute for the range and display attribute property. /// </summary> internal override void OnRange( UnsafeNativeMethods.ITfProperty property, int ecReadOnly, UnsafeNativeMethods.ITfRange range) { Int32 guidatom = GetInt32Value(ecReadOnly, property, range); if (guidatom != 0) { TextServicesDisplayAttribute attr; attr = GetDisplayAttribute(guidatom); if (attr != null) { ITextPointer start; ITextPointer end; ConvertToTextPosition(range, out start, out end); attr.Apply(start, end); } } }
protected void ConvertToTextPosition(UnsafeNativeMethods.ITfRange range, out ITextPointer start, out ITextPointer end) { UnsafeNativeMethods.ITfRangeACP rangeACP; int startIndex; int length; rangeACP = range as UnsafeNativeMethods.ITfRangeACP; rangeACP.GetExtent(out startIndex, out length); if (length < 0) { // Cicero bug! Length should never be less than zero. start = null; end = null; } else { start = _textstore.CreatePointerAtCharOffset(startIndex, LogicalDirection.Forward); end = _textstore.CreatePointerAtCharOffset(startIndex + length, LogicalDirection.Forward); } }
internal virtual void OnRange(UnsafeNativeMethods.ITfProperty property, int ecReadonly, UnsafeNativeMethods.ITfRange range) { }
protected static Object GetValue(int ecReadOnly, UnsafeNativeMethods.ITfProperty property, UnsafeNativeMethods.ITfRange range) { if (property == null) { return(null); } Object obj; property.GetValue(ecReadOnly, range, out obj); return(obj); }
internal override void OnRange(UnsafeNativeMethods.ITfProperty property, int ecReadOnly, UnsafeNativeMethods.ITfRange range) { int int32Value = this.GetInt32Value(ecReadOnly, property, range); if (int32Value != 0) { TextServicesDisplayAttribute displayAttribute = TextServicesDisplayAttributePropertyRanges.GetDisplayAttribute(int32Value); if (displayAttribute != null) { ITextPointer start; ITextPointer end; base.ConvertToTextPosition(range, out start, out end); displayAttribute.Apply(start, end); } } }
private int GetInt32Value(int ecReadOnly, UnsafeNativeMethods.ITfProperty property, UnsafeNativeMethods.ITfRange range) { object value = TextServicesPropertyRanges.GetValue(ecReadOnly, property, range); if (value == null) { return(0); } return((int)value); }
//------------------------------------------------------ // // Public Methods - ITfTransitoryExtensionSink // //------------------------------------------------------ #region ITfTransitoryExtensionSink // Transitory Document has been updated. // This is the notification of the changes of the result string and the composition string. public void OnTransitoryExtensionUpdated(UnsafeNativeMethods.ITfContext context, int ecReadOnly, UnsafeNativeMethods.ITfRange rangeResult, UnsafeNativeMethods.ITfRange rangeComposition, out bool fDeleteResultRange) { fDeleteResultRange = true; TextCompositionManager compmgr = InputManager.Current.PrimaryKeyboardDevice.TextCompositionManager; if (rangeResult != null) { string result = StringFromITfRange(rangeResult, ecReadOnly); if (result.Length > 0) { if (_composition == null) { // We don't have the composition now and we got the result string. // The result text is result and automatic termination is true. _composition = new DefaultTextStoreTextComposition(InputManager.Current, Keyboard.FocusedElement, result, TextCompositionAutoComplete.On); TextCompositionManager.StartComposition(_composition); // relese composition. _composition = null; } else { // Finalize the composition. _composition.SetCompositionText(""); _composition.SetText(result); // We don't call _composition.Complete() here. We just want to generate // TextInput events. TextCompositionManager.CompleteComposition(_composition); // relese composition. _composition = null; } } } if (rangeComposition != null) { string comp = StringFromITfRange(rangeComposition, ecReadOnly); if (comp.Length > 0) { if (_composition == null) { // Start the new composition. _composition = new DefaultTextStoreTextComposition(InputManager.Current, Keyboard.FocusedElement, "", TextCompositionAutoComplete.Off); _composition.SetCompositionText(comp); TextCompositionManager.StartComposition(_composition); } else { // Update the current composition. _composition.SetCompositionText(comp); _composition.SetText(""); TextCompositionManager.UpdateComposition(_composition); } } } }
public void OnUpdateComposition(UnsafeNativeMethods.ITfCompositionView view, UnsafeNativeMethods.ITfRange rangeNew) { }
/// <summary> /// Calback function for TextEditSink /// we track the property change here. /// </summary> internal override void OnEndEdit(UnsafeNativeMethods.ITfContext context, int ecReadOnly, UnsafeNativeMethods.ITfEditRecord editRecord) { Guid displayAttributeGuid; UnsafeNativeMethods.ITfProperty displayAttributeProperty; UnsafeNativeMethods.IEnumTfRanges attributeRangeEnumerator; UnsafeNativeMethods.ITfRange[] attributeRanges; int fetched; int guidAtom; TextServicesDisplayAttribute displayAttribute; ITextPointer start; ITextPointer end; // // Remove any existing display attribute highlights. // #if UNUSED_IME_HIGHLIGHT_LAYER if (_highlightLayer != null) { this.TextStore.TextContainer.Highlights.RemoveLayer(_highlightLayer); _highlightLayer = null; } #endif // // Remove any existing composition adorner for display attribute. // if (_compositionAdorner != null) { _compositionAdorner.Uninitialize(); _compositionAdorner = null; } // // Look for new ones. // // Get the DisplayAttributeProperty. displayAttributeGuid = Guid; context.GetProperty(ref displayAttributeGuid, out displayAttributeProperty); // Get a range enumerator for the property. if (displayAttributeProperty.EnumRanges(ecReadOnly, out attributeRangeEnumerator, null) == NativeMethods.S_OK) { attributeRanges = new UnsafeNativeMethods.ITfRange[1]; // Walk each range. while (attributeRangeEnumerator.Next(1, attributeRanges, out fetched) == NativeMethods.S_OK) { // Get a DisplayAttribute for this range. guidAtom = GetInt32Value(ecReadOnly, displayAttributeProperty, attributeRanges[0]); displayAttribute = GetDisplayAttribute(guidAtom); if (displayAttribute != null && !displayAttribute.IsEmptyAttribute()) { // Set a matching highlight for the attribute range. ConvertToTextPosition(attributeRanges[0], out start, out end); if (start != null) { #if UNUSED_IME_HIGHLIGHT_LAYER // Demand create the highlight layer. if (_highlightLayer == null) { _highlightLayer = new DisplayAttributeHighlightLayer(); } #endif if (_compositionAdorner == null) { _compositionAdorner = new CompositionAdorner(this.TextStore.TextView); _compositionAdorner.Initialize(this.TextStore.TextView); } #if UNUSED_IME_HIGHLIGHT_LAYER // Need to pass the foreground and background color of the composition _highlightLayer.Add(start, end, /*TextDecorationCollection:*/ null); #endif // Add the attribute range into CompositionAdorner. _compositionAdorner.AddAttributeRange(start, end, displayAttribute); } } Marshal.ReleaseComObject(attributeRanges[0]); } #if UNUSED_IME_HIGHLIGHT_LAYER if (_highlightLayer != null) { this.TextStore.TextContainer.Highlights.AddLayer(_highlightLayer); } #endif if (_compositionAdorner != null) { // Update the layout to get the acurated rectangle from calling GetRectangleFromTextPosition this.TextStore.RenderScope.UpdateLayout(); // Invalidate the composition adorner to render the composition attribute ranges. _compositionAdorner.InvalidateAdorner(); } Marshal.ReleaseComObject(attributeRangeEnumerator); } Marshal.ReleaseComObject(displayAttributeProperty); }
private Int32 GetInt32Value(int ecReadOnly, UnsafeNativeMethods.ITfProperty property, UnsafeNativeMethods.ITfRange range) { Object obj = GetValue(ecReadOnly, property, range); if (obj == null) { return(0); } return((Int32)obj); }
protected static object GetValue(int ecReadOnly, UnsafeNativeMethods.ITfProperty property, UnsafeNativeMethods.ITfRange range) { if (property == null) { return(null); } object result; property.GetValue(ecReadOnly, range, out result); return(result); }
internal override void OnEndEdit(UnsafeNativeMethods.ITfContext context, int ecReadOnly, UnsafeNativeMethods.ITfEditRecord editRecord) { Guid displayAttributeGuid; UnsafeNativeMethods.ITfProperty displayAttributeProperty; UnsafeNativeMethods.IEnumTfRanges attributeRangeEnumerator; UnsafeNativeMethods.ITfRange[] attributeRanges; int fetched; int guidAtom; TextServicesDisplayAttribute displayAttribute; ITextPointer start; ITextPointer end; // // Remove any existing display attribute highlights. // #if UNUSED_IME_HIGHLIGHT_LAYER if (_highlightLayer != null) { this.TextStore.TextContainer.Highlights.RemoveLayer(_highlightLayer); _highlightLayer = null; } #endif // // Remove any existing composition adorner for display attribute. // if (_compositionAdorner != null) { _compositionAdorner.Uninitialize(); _compositionAdorner = null; } // // Look for new ones. // // Get the DisplayAttributeProperty. displayAttributeGuid = Guid; context.GetProperty(ref displayAttributeGuid, out displayAttributeProperty); // Get a range enumerator for the property. if (displayAttributeProperty.EnumRanges(ecReadOnly, out attributeRangeEnumerator, null) == NativeMethods.S_OK) { attributeRanges = new UnsafeNativeMethods.ITfRange[1]; // Walk each range. while (attributeRangeEnumerator.Next(1, attributeRanges, out fetched) == NativeMethods.S_OK) { // Get a DisplayAttribute for this range. guidAtom = GetInt32Value(ecReadOnly, displayAttributeProperty, attributeRanges[0]); displayAttribute = GetDisplayAttribute(guidAtom); if (displayAttribute != null && !displayAttribute.IsEmptyAttribute()) { // Set a matching highlight for the attribute range. ConvertToTextPosition(attributeRanges[0], out start, out end); if (start != null) { #if UNUSED_IME_HIGHLIGHT_LAYER // Demand create the highlight layer. if (_highlightLayer == null) { _highlightLayer = new DisplayAttributeHighlightLayer(); } #endif if (_compositionAdorner == null) { _compositionAdorner = new CompositionAdorner(this.TextStore.TextView); _compositionAdorner.Initialize(this.TextStore.TextView); } #if UNUSED_IME_HIGHLIGHT_LAYER // ToDo: Need to pass the foreground and background color of the composition _highlightLayer.Add(start, end, /*TextDecorationCollection:*/null); #endif // Add the attribute range into CompositionAdorner. _compositionAdorner.AddAttributeRange(start, end, displayAttribute); } } Marshal.ReleaseComObject(attributeRanges[0]); } #if UNUSED_IME_HIGHLIGHT_LAYER if (_highlightLayer != null) { this.TextStore.TextContainer.Highlights.AddLayer(_highlightLayer); } #endif if (_compositionAdorner != null) { // Update the layout to get the acurated rectangle from calling GetRectangleFromTextPosition this.TextStore.RenderScope.UpdateLayout(); // Invalidate the composition adorner to render the composition attribute ranges. _compositionAdorner.InvalidateAdorner(); } Marshal.ReleaseComObject(attributeRangeEnumerator); } Marshal.ReleaseComObject(displayAttributeProperty); }
internal virtual void OnEndEdit(UnsafeNativeMethods.ITfContext context, int ecReadOnly, UnsafeNativeMethods.ITfEditRecord editRecord) { int fetched; UnsafeNativeMethods.IEnumTfRanges ranges; UnsafeNativeMethods.ITfProperty prop = null; ranges = GetPropertyUpdate(editRecord); UnsafeNativeMethods.ITfRange [] outRanges; outRanges = new UnsafeNativeMethods.ITfRange[1]; while (ranges.Next(1, outRanges, out fetched) == 0) { // // check the element has enabled dynamic property. // ITextPointer start; ITextPointer end; ConvertToTextPosition(outRanges[0], out start, out end); if (prop == null) context.GetProperty(ref _guid, out prop); UnsafeNativeMethods.IEnumTfRanges rangesProp; if (prop.EnumRanges(ecReadOnly, out rangesProp, outRanges[0]) == 0) { UnsafeNativeMethods.ITfRange [] outRangesProp; outRangesProp = new UnsafeNativeMethods.ITfRange[1]; while (rangesProp.Next(1, outRangesProp, out fetched) == 0) { OnRange(prop, ecReadOnly, outRangesProp[0]); Marshal.ReleaseComObject(outRangesProp[0]); } Marshal.ReleaseComObject(rangesProp); } Marshal.ReleaseComObject(outRanges[0]); } Marshal.ReleaseComObject(ranges); if (prop != null) Marshal.ReleaseComObject(prop); }