internal void OnEndEdit(
            UnsafeNativeMethods.ITfContext context, 
            int ecReadOnly,
            UnsafeNativeMethods.ITfEditRecord editRecord)
        {
            if (_propertyRanges == null)
            {
                _propertyRanges = new TextServicesDisplayAttributePropertyRanges(_textstore);
            }

            _propertyRanges.OnEndEdit(context, ecReadOnly, editRecord);
        }
        internal DynamicScriptObject(UnsafeNativeMethods.IDispatch scriptObject)
        {
            if (scriptObject == null)
            {
                throw new ArgumentNullException("scriptObject");
            }

            _scriptObject = scriptObject;

            // In the case of IE, we use IDispatchEx for enhanced security (see InvokeOnScriptObject).
            _scriptObjectEx = _scriptObject as UnsafeNativeMethods.IDispatchEx;
        }
예제 #3
0
        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);
        }
        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);
                }
            }
        }
 internal void OpenColorProfile(ref UnsafeNativeMethods.PROFILE profile)
 {
     // No need to get rid of the old handle as it will get GC'ed
     _profileHandle = UnsafeNativeMethodsMilCoreApi.Mscms.OpenColorProfile(
         ref profile,
         NativeMethods.PROFILE_READ,     // DesiredAccess
         NativeMethods.FILE_SHARE_READ,  // ShareMode
         NativeMethods.OPEN_EXISTING     // CreationMode
         );
 }
예제 #6
0
파일: TextStore.cs 프로젝트: mind0n/hive
        public void AdviseSink(ref Guid riid, object obj, UnsafeNativeMethods.AdviseFlags flags)
        {
            UnsafeNativeMethods.ITextStoreACPSink sink;

            if (riid != UnsafeNativeMethods.IID_ITextStoreACPSink)
            {
                throw new COMException(SR.Get(SRID.TextStore_CONNECT_E_CANNOTCONNECT), unchecked((int)0x80040202));
            }

            sink = obj as UnsafeNativeMethods.ITextStoreACPSink;
            if (sink == null)
            {
                throw new COMException(SR.Get(SRID.TextStore_E_NOINTERFACE), unchecked((int)0x80004002));
            }

            // It's legal to replace existing sink.
            if (HasSink)
            {
                Marshal.ReleaseComObject(_sink);
            }
            else
            {
                // Start tracking window movement for _sink.
                _textservicesHost.RegisterWinEventSink(this);
            }

            _sink = sink;

        }
        internal bool GetColorProfileHeader(out UnsafeNativeMethods.PROFILEHEADER header)
        {
            if (IsInvalid)
            {
                throw new InvalidOperationException(SR.Get(SRID.Image_ColorContextInvalid));
            }

            return UnsafeNativeMethodsMilCoreApi.Mscms.GetColorProfileHeader(_profileHandle, out header);
        }
        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;
        }
예제 #9
0
파일: TextStore.cs 프로젝트: mind0n/hive
        // See msdn's ITextStoreACP documentation for a full description.
        public void SetText(UnsafeNativeMethods.SetTextFlags flags, int startIndex, int endIndex, char[] text, int cch, out UnsafeNativeMethods.TS_TEXTCHANGE change)
        {
            if (this.IsReadOnly)
            {
                throw new COMException(SR.Get(SRID.TextStore_TS_E_READONLY), UnsafeNativeMethods.TS_E_READONLY);
            }

            ITextPointer start;
            ITextPointer end;

            GetNormalizedRange(startIndex, endIndex, out start, out end);

            while (start != null && TextPointerBase.IsBeforeFirstTable(start))
            {
                start = start.GetNextInsertionPosition(LogicalDirection.Forward);
            }

            if (start == null)
            {
                throw new COMException(SR.Get(SRID.TextStore_CompositionRejected), NativeMethods.E_FAIL);
            }

            if (start.CompareTo(end) > 0)
            {
                end = start;
            }

            string filteredText = FilterCompositionString(new string(text), start.GetOffsetToPosition(end)); // does NOT filter MaxLength.
            if (filteredText == null)
            {
                throw new COMException(SR.Get(SRID.TextStore_CompositionRejected), NativeMethods.E_FAIL);
            }

            // Openes a composition undo unit for the composition undo.
            CompositionParentUndoUnit unit = OpenCompositionUndoUnit();
            UndoCloseAction undoCloseAction = UndoCloseAction.Rollback;

            try
            {
                ITextRange range = new TextRange(start, end, true /* ignoreTextUnitBoundaries */);

                this.TextEditor.SetText(range, filteredText, InputLanguageManager.Current.CurrentInputLanguage);

                change.start = startIndex;
                change.oldEnd = endIndex;
                change.newEnd = endIndex + text.Length - (endIndex - startIndex);

                ValidateChange(change);
                VerifyTextStoreConsistency();

                undoCloseAction = UndoCloseAction.Commit;
            }
            finally
            {
                // Closes compsotion undo unit with commit to add the composition undo unit into the undo stack.
                CloseTextParentUndoUnit(unit, undoCloseAction);
            }
        }
예제 #10
0
 int UnsafeNativeMethods.IDocHostUIHandler.GetDropTarget(UnsafeNativeMethods.IOleDropTarget pDropTarget, out UnsafeNativeMethods.IOleDropTarget ppDropTarget) 
 {
     //
     // Set to null no matter what we return, to prevent the marshaller
     // from going crazy if the pointer points to random stuff.
     ppDropTarget = null;
     return NativeMethods.E_NOTIMPL;
 }
예제 #11
0
 public static extern void DoDragDrop(IComDataObject dataObject, UnsafeNativeMethods.IOleDropSource dropSource, int allowedEffects, int[] finalEffect);
예제 #12
0
파일: TextStore.cs 프로젝트: mind0n/hive
        // See msdn's ITextStoreACP documentation for a full description.
        public int RequestAttrsAtPosition(int index, int count, Guid[] filterAttributes, UnsafeNativeMethods.AttributeFlags flags)
        {
            ITextPointer position;

            position = CreatePointerAtCharOffset(index, LogicalDirection.Forward);

            PrepareAttributes((InputScope)position.GetValue(InputMethod.InputScopeProperty),
                              (double)position.GetValue(TextElement.FontSizeProperty),
                              (FontFamily)position.GetValue(TextElement.FontFamilyProperty),
                              (XmlLanguage)position.GetValue(FrameworkContentElement.LanguageProperty),
                              null,
                              count, filterAttributes);

            if (_preparedattributes.Count == 0)
                return NativeMethods.S_FALSE;

            return NativeMethods.S_OK;
        }
예제 #13
0
파일: TextStore.cs 프로젝트: mind0n/hive
 // See msdn's ITextStoreACP documentation for a full description.
 public void RequestAttrsTransitioningAtPosition(int position, int count, Guid[] filterAttributes, UnsafeNativeMethods.AttributeFlags flags)
 {
     throw new COMException(SR.Get(SRID.TextStore_E_NOTIMPL), unchecked((int)0x80004001));
 }
예제 #14
0
파일: TextStore.cs 프로젝트: mind0n/hive
        // See msdn's ITextStoreACP documentation for a full description.
        public void InsertEmbeddedAtSelection(UnsafeNativeMethods.InsertAtSelectionFlags flags, object obj, out int startIndex, out int endIndex, out UnsafeNativeMethods.TS_TEXTCHANGE change)
        {
            startIndex = -1;
            endIndex = -1;

            change.start = 0;
            change.oldEnd = 0;
            change.newEnd = 0;

            if (IsReadOnly)
            {
                throw new COMException(SR.Get(SRID.TextStore_TS_E_READONLY), UnsafeNativeMethods.TS_E_READONLY);
            }

#if ENABLE_INK_EMBEDDING
            IComDataObject data;

            if (IsReadOnly)
            {
                throw new COMException(SR.Get(SRID.TextStore_TS_E_READONLY), UnsafeNativeMethods.TS_E_READONLY);
            }

            if (!TextSelection.HasConcreteTextContainer)
            {
                throw new COMException(SR.Get(SRID.TextStore_TS_E_FORMAT), UnsafeNativeMethods.TS_E_FORMAT);
            }

            // The object must have IOldDataObject internface.
            // The obj param of InsertEmbedded is IDataObject in Win32 definition.
            data = obj as IComDataObject;
            if (data == null)
            {
                throw new COMException(SR.Get(SRID.TextStore_BadObject), NativeMethods.E_INVALIDARG);
            }

            // Do the insert.
            if ((flags & UnsafeNativeMethods.InsertAtSelectionFlags.TS_IAS_QUERYONLY) == 0)
            {
                InsertEmbeddedAtRange((TextPointer)this.TextSelection.Start, (TextPointer)this.TextSelection.End, data, out change);
            }

            if ((flags & UnsafeNativeMethods.InsertAtSelectionFlags.TS_IAS_NOQUERY) == 0)
            {
                startIndex = this.TextSelection.Start.Offset;
                endIndex = this.TextSelection.End.Offset;
            }
#else
            throw new COMException(SR.Get(SRID.TextStore_TS_E_FORMAT), UnsafeNativeMethods.TS_E_FORMAT);
#endif
        }
예제 #15
0
파일: TextStore.cs 프로젝트: mind0n/hive
        // See msdn's ITextStoreACP documentation for a full description.
        public int RequestSupportedAttrs(UnsafeNativeMethods.AttributeFlags flags, int count, Guid[] filterAttributes)
        {

            // return the default app property value, which target is Scope.
            PrepareAttributes((InputScope)UiScope.GetValue(InputMethod.InputScopeProperty),
                              (double)UiScope.GetValue(TextElement.FontSizeProperty),
                              (FontFamily)UiScope.GetValue(TextElement.FontFamilyProperty),
                              (XmlLanguage)UiScope.GetValue(FrameworkContentElement.LanguageProperty),
                              UiScope as Visual,
                              count, filterAttributes);

            if (_preparedattributes.Count == 0)
                return NativeMethods.S_FALSE;

            return NativeMethods.S_OK;
        }
예제 #16
0
파일: TextStore.cs 프로젝트: mind0n/hive
        // See msdn's ITextStoreACP documentation for a full description.
        public void InsertTextAtSelection(UnsafeNativeMethods.InsertAtSelectionFlags flags, char[] text, int cch, out int startIndex, out int endIndex, out UnsafeNativeMethods.TS_TEXTCHANGE change)
        {
            ITextPointer startNavigator;
            ITextPointer endNavigator;
            int selectionStartIndex;
            int selectionEndIndex;

            startIndex = -1;
            endIndex = -1;

            change.start = 0;
            change.oldEnd = 0;
            change.newEnd = 0;

            if (IsReadOnly)
            {
                throw new COMException(SR.Get(SRID.TextStore_TS_E_READONLY), UnsafeNativeMethods.TS_E_READONLY);
            }

            //
            // 






            ITextRange range = new TextRange(this.TextSelection.AnchorPosition, this.TextSelection.MovingPosition);
            range.ApplyTypingHeuristics(false /* overType */);

            ITextPointer start;
            ITextPointer end;

            GetAdjustedSelection(range.Start, range.End, out start, out end);

            // Someone might change the default selection gravity, so use our
            // own TextPositions to track the insert.
            startNavigator = start.CreatePointer();
            startNavigator.SetLogicalDirection(LogicalDirection.Backward);
            endNavigator = end.CreatePointer();
            endNavigator.SetLogicalDirection(LogicalDirection.Forward);

            selectionStartIndex = startNavigator.CharOffset;
            selectionEndIndex = endNavigator.CharOffset;

            // Do the insert.
            if ((flags & UnsafeNativeMethods.InsertAtSelectionFlags.TS_IAS_QUERYONLY) == 0)
            {
                // Opene a composition undo unit for the composition undo.
                CompositionParentUndoUnit unit = OpenCompositionUndoUnit();
                UndoCloseAction undoCloseAction = UndoCloseAction.Rollback;

                try
                {
                    VerifyTextStoreConsistency();

                    change.oldEnd = selectionEndIndex;

                    string filteredText = FilterCompositionString(new string(text), range.Start.GetOffsetToPosition(range.End)); // does NOT filter MaxLength.
                    if (filteredText == null)
                    {
                        throw new COMException(SR.Get(SRID.TextStore_CompositionRejected), NativeMethods.E_FAIL);
                    }

                    // We still need to call ApplyTypingHeuristics, even though
                    // we already did the work above, because it might need
                    // to spring load formatting.
                    this.TextSelection.ApplyTypingHeuristics(false /* overType */);

                    //Invariant.Assert(this.TextSelection.Start.CompareTo(range.Start) == 0 && this.TextSelection.End.CompareTo(range.End) == 0);
                    // We cannot make this Assertion because TextRange will normalize
                    // differently around Floater/Inline edges.  This is probably
                    // not desired behavior.  To repro,
                    //
                    // <StackPanel xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
                    //  <RichTextBox FontSize="24" Height="150">
                    //      <FlowDocument>
                    //          <Paragraph>
                    //              <Run>para</Run>
                    //              <Floater HorizontalAlignment="Right" Width="100" Background="#FFFF0000">
                    //                  <Paragraph><Run>Floater</Run></Paragraph>
                    //              </Floater>
                    //              <Run> </Run>
                    //          </Paragraph>
                    //      </FlowDocument>
                    //  </RichTextBox>
                    // </StackPanel>
                    //
                    // 1. Put the caret before the Floater.
                    // 2. Shift-right to select the entire Floater.
                    // 3. Activate the chinese pinyin IME, and press 'a'.

                    // Avoid calling Select when the selection doesn't need a
                    // final reposition to preserve any spring loaded formatting
                    // from ApplyTypingHeuristics.
                    if (start.CompareTo(this.TextSelection.Start) != 0 ||
                        end.CompareTo(this.TextSelection.End) != 0)
                    {
                        this.TextSelection.Select(start, end);
                    }

                    if (!_isComposing && _previousCompositionStartOffset == -1)
                    {
                        // IMEs have the option (TF_IAS_NO_DEFAULT_COMPOSITION)
                        // of inserting text (via this method only) without first
                        // starting a composition.  If that happens, we need
                        // to remember where the composition started, from the
                        // point of view of the application listening to events
                        // we will raise in the future.
                        _previousCompositionStartOffset = this.TextSelection.Start.Offset;
                        _previousCompositionEndOffset = this.TextSelection.End.Offset;
                    }

                    this.TextEditor.SetSelectedText(filteredText, InputLanguageManager.Current.CurrentInputLanguage);

                    change.start = startNavigator.CharOffset;
                    change.newEnd = endNavigator.CharOffset;

                    ValidateChange(change);
                    VerifyTextStoreConsistency();

                    undoCloseAction = UndoCloseAction.Commit;
                }
                finally
                {
                    // Close a composition undo unit with commit to add the composition undo unit into the undo stack.
                    CloseTextParentUndoUnit(unit, undoCloseAction);
                }
            }

            // Report the location of the new text.
            if ((flags & UnsafeNativeMethods.InsertAtSelectionFlags.TS_IAS_NOQUERY) == 0)
            {
                startIndex = selectionStartIndex;
                endIndex = endNavigator.CharOffset;
            }
        }
예제 #17
0
파일: TextStore.cs 프로젝트: mind0n/hive
        // See msdn's ITextStoreACP documentation for a full description.
        public void InsertEmbedded(UnsafeNativeMethods.InsertEmbeddedFlags flags, int startIndex, int endIndex, object obj, out UnsafeNativeMethods.TS_TEXTCHANGE change)
        {
            if (IsReadOnly)
            {
                throw new COMException(SR.Get(SRID.TextStore_TS_E_READONLY), UnsafeNativeMethods.TS_E_READONLY);
            }

            // Disable embedded object temporarily.
#if ENABLE_INK_EMBEDDING
            if (!TextSelection.HasConcreteTextContainer)
            {
                throw new COMException(SR.Get(SRID.TextStore_TS_E_FORMAT), UnsafeNativeMethods.TS_E_FORMAT);
            }

            TextContainer container;
            TextPointer startPosition;
            TextPointer endPosition;
            IComDataObject data;

            // The object must have IOldDataObject internface.
            // The obj param of InsertEmbedded is IDataObject in Win32 definition.
            data = obj as IComDataObject;
            if (data == null)
            {
                throw new COMException(SR.Get(SRID.TextStore_BadObject), NativeMethods.E_INVALIDARG);
            }

            container = (TextContainer)this.TextContainer;

            startPosition = container.CreatePointerAtOffset(startIndex, LogicalDirection.Backward);
            endPosition = container.CreatePointerAtOffset(endIndex, LogicalDirection.Forward);

            InsertEmbeddedAtRange(startPosition, endPosition, data, out change);
#else
            throw new COMException(SR.Get(SRID.TextStore_TS_E_FORMAT), UnsafeNativeMethods.TS_E_FORMAT);
#endif
        }
예제 #18
0
파일: TextStore.cs 프로젝트: mind0n/hive
 internal MouseSink(UnsafeNativeMethods.ITfRangeACP range, UnsafeNativeMethods.ITfMouseSink sink, int cookie)
 {
     _range = new SecurityCriticalDataClass<UnsafeNativeMethods.ITfRangeACP>(range);
     _sink = new SecurityCriticalDataClass<UnsafeNativeMethods.ITfMouseSink>(sink);
     _cookie = cookie;
 }
예제 #19
0
 int UnsafeNativeMethods.IDocHostUIHandler.ShowUI(int dwID, UnsafeNativeMethods.IOleInPlaceActiveObject activeObject, 
         NativeMethods.IOleCommandTarget commandTarget, UnsafeNativeMethods.IOleInPlaceFrame frame, 
         UnsafeNativeMethods.IOleInPlaceUIWindow doc) 
 {
     return NativeMethods.E_NOTIMPL;
 }
예제 #20
0
파일: TextStore.cs 프로젝트: mind0n/hive
 // See msdn's ITextStoreACP documentation for a full description.
 public void FindNextAttrTransition(int startIndex, int haltIndex, int count, Guid[] filterAttributes, UnsafeNativeMethods.AttributeFlags flags, out int acpNext, out bool found, out int foundOffset)
 {
     acpNext = 0;
     found = false;
     foundOffset = 0;
 }
예제 #21
0
 int UnsafeNativeMethods.IDocHostUIHandler.ResizeBorder(NativeMethods.COMRECT rect, UnsafeNativeMethods.IOleInPlaceUIWindow doc, bool fFrameWindow) 
 {
     return NativeMethods.E_NOTIMPL;
 }
예제 #22
0
        // wrapper for GetTitleBarInfo
        internal static bool ProxyGetTitleBarInfo(IntPtr hwnd, out UnsafeNativeMethods.TITLEBARINFO ti)
        {
            ti = new UnsafeNativeMethods.TITLEBARINFO();
            ti.cbSize = Marshal.SizeOf(ti.GetType());

            bool result = UnsafeNativeMethods.GetTitleBarInfo(hwnd, ref ti);
            int lastWin32Error = Marshal.GetLastWin32Error();

            if (!result)
            {
                ThrowWin32ExceptionsIfError(lastWin32Error);
                return false;
            }
            return true;
        }
예제 #23
0
 public static extern int RegisterDragDrop(HandleRef hwnd, UnsafeNativeMethods.IOleDropTarget target);
예제 #24
0
        // ------------------------------------------------------
        //
        // Private Methods
        //
        // ------------------------------------------------------

        #region Private Methods

        private static bool EnumToolTipWindows(IntPtr hwnd, ref UnsafeNativeMethods.ENUMTOOLTIPWINDOWINFO lParam)
        {
            // Use ProxyGetClassName here instead of GetClassName(),
            // since for a [....] tooltip the latter will return
            // "WindowsForms10.tooltips_class32.app.0.b7ab7b".
            // Instead, ProxyGetClassName uses WM_GETOBJECT with
            // OBJID_QUERYCLASSNAMEIDX, which will return the correct answer.
            if (!ProxyGetClassName(hwnd).Equals("tooltips_class32"))
            {
                return true;
            }

            NativeMethods.TOOLINFO tool = new NativeMethods.TOOLINFO();
            tool.Init(Marshal.SizeOf(typeof(NativeMethods.TOOLINFO)));
            // For tooltips with ids of 0, MFC will create the tooltip with the flag of TTF_IDISHWND.
            // TTF_IDISHWND indicates that the uId member is the window handle to the tool.
            if (lParam.id == 0)
            {
                tool.hwnd = Misc.GetParent(lParam.hwnd);
                tool.uId = unchecked((int)lParam.hwnd);
                tool.uFlags = NativeMethods.TTF_IDISHWND;
            }
            else
            {
                tool.hwnd = lParam.hwnd;
                tool.uId = lParam.id;
            }

            string name = XSendMessage.GetItemText(hwnd, tool);

            // Didn't get anything - continue looking...
            if (string.IsNullOrEmpty(name))
            {
                return true;
            }

            lParam.name = name;

            // Got it - can stop iterating now.
            return false;
        }
        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);
        }
예제 #26
0
        public HwndWrapper(
            int classStyle,
            int style,
            int exStyle,
            int x,
            int y,
            int width,
            int height,
            string name,
            IntPtr parent,
            HwndWrapperHook[] hooks)
        {
            _ownerThreadID = new SecurityCriticalDataForSet <int>(Thread.CurrentThread.ManagedThreadId);


            // First, add the set of hooks.  This allows the hooks to receive the
            // messages sent to the window very early in the process.
            if (hooks != null)
            {
                for (int i = 0, iEnd = hooks.Length; i < iEnd; i++)
                {
                    if (null != hooks[i])
                    {
                        AddHook(hooks[i]);
                    }
                }
            }


            _wndProc = new SecurityCriticalData <HwndWrapperHook>(new HwndWrapperHook(WndProc));

            // We create the HwndSubclass object so that we can use its
            // window proc directly.  We will not be "subclassing" the
            // window we create.
            HwndSubclass hwndSubclass = new HwndSubclass(_wndProc.Value);

            // Register a unique window class for this instance.
            NativeMethods.WNDCLASSEX_D wc_d = new NativeMethods.WNDCLASSEX_D();

            IntPtr hNullBrush = UnsafeNativeMethods.CriticalGetStockObject(NativeMethods.NULL_BRUSH);

            if (hNullBrush == IntPtr.Zero)
            {
                throw new System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error());
            }

            IntPtr hInstance = UnsafeNativeMethods.GetModuleHandle(null);

            // We need to keep the Delegate object alive through the call to CreateWindowEx().
            // Subclass.WndProc will install a better delegate (to the same function) when it
            // processes the first message.
            // But this first delegate needs be held alive until then.
            NativeMethods.WndProc initialWndProc = new NativeMethods.WndProc(hwndSubclass.SubclassWndProc);

            // The class name is a concat of AppName, ThreadName, and RandomNumber.
            // Register will fail if the string gets over 255 in length.
            // So limit each part to a reasonable amount.
            string appName;

            if (null != AppDomain.CurrentDomain.FriendlyName && 128 <= AppDomain.CurrentDomain.FriendlyName.Length)
            {
                appName = AppDomain.CurrentDomain.FriendlyName.Substring(0, 128);
            }
            else
            {
                appName = AppDomain.CurrentDomain.FriendlyName;
            }

            string threadName;

            if (null != Thread.CurrentThread.Name && 64 <= Thread.CurrentThread.Name.Length)
            {
                threadName = Thread.CurrentThread.Name.Substring(0, 64);
            }
            else
            {
                threadName = Thread.CurrentThread.Name;
            }

            // Create a suitable unique class name.
            _classAtom = 0;
            string randomName = Guid.NewGuid().ToString();
            string className  = String.Format(CultureInfo.InvariantCulture, "HwndWrapper[{0};{1};{2}]", appName, threadName, randomName);

            wc_d.cbSize        = Marshal.SizeOf(typeof(NativeMethods.WNDCLASSEX_D));
            wc_d.style         = classStyle;
            wc_d.lpfnWndProc   = initialWndProc;
            wc_d.cbClsExtra    = 0;
            wc_d.cbWndExtra    = 0;
            wc_d.hInstance     = hInstance;
            wc_d.hIcon         = IntPtr.Zero;
            wc_d.hCursor       = IntPtr.Zero;
            wc_d.hbrBackground = hNullBrush;
            wc_d.lpszMenuName  = "";
            wc_d.lpszClassName = className;
            wc_d.hIconSm       = IntPtr.Zero;

            // Register the unique class for this instance.
            // Note we use a GUID in the name so we are confident that
            // the class name should be unique.  And RegisterClassEx won't
            // fail (for that reason).
            _classAtom = UnsafeNativeMethods.RegisterClassEx(wc_d);

            // call CreateWindow
            _isInCreateWindow = true;
            try {
                _handle = new SecurityCriticalDataClass <IntPtr>(UnsafeNativeMethods.CreateWindowEx(exStyle,
                                                                                                    className,
                                                                                                    name,
                                                                                                    style,
                                                                                                    x,
                                                                                                    y,
                                                                                                    width,
                                                                                                    height,
                                                                                                    new HandleRef(null, parent),
                                                                                                    new HandleRef(null, IntPtr.Zero),
                                                                                                    new HandleRef(null, IntPtr.Zero),
                                                                                                    null));
            }
            finally
            {
                _isInCreateWindow = false;
                if (_handle == null || _handle.Value == IntPtr.Zero)
                {
                    new UIPermission(UIPermissionWindow.AllWindows).Assert(); //BlessedAssert to call Dispose
                    try
                    {
                        // Because the HwndSubclass is pinned, but the HWND creation failed,
                        // we need to manually clean it up.
                        hwndSubclass.Dispose();
                    }
                    finally
                    {
                        CodeAccessPermission.RevertAssert();
                    }
                }
            }
            GC.KeepAlive(initialWndProc);
        }
예제 #27
0
파일: TextStore.cs 프로젝트: mind0n/hive
        // See msdn's ITextStoreACP documentation for a full description.
        public void RetrieveRequestedAttrs(int count, UnsafeNativeMethods.TS_ATTRVAL[] attributeVals, out int fetched)
        {
            fetched = 0;
            int i;

            for (i = 0; i < count; i++)
            {
                if (i >= _preparedattributes.Count)
                    break;

                attributeVals[i] = ((UnsafeNativeMethods.TS_ATTRVAL)_preparedattributes[i]);
                fetched++;
            }

            // clear _preparedattributes now so we can keep the ref count of val if it is VT_UNKNOWN.
            _preparedattributes.Clear();
            _preparedattributes = null;
        }
예제 #28
0
파일: TextStore.cs 프로젝트: mind0n/hive
        // Detects errors in the change notifications we send TSF.
        private void ValidateChange(UnsafeNativeMethods.TS_TEXTCHANGE change)
        {
            Invariant.Assert(change.start >= 0, "Bad StartIndex");
            Invariant.Assert(change.start <= change.oldEnd, "Bad oldEnd index");
            Invariant.Assert(change.start <= change.newEnd, "Bad newEnd index");

            _netCharCount += (change.newEnd - change.oldEnd);
            Invariant.Assert(_netCharCount >= 0, "Negative _netCharCount!");
        }
예제 #29
0
 internal static bool ProxyGetTitleBarInfoEx(IntPtr hwnd, out UnsafeNativeMethods.TITLEBARINFOEX ti)
 {
     ti = new UnsafeNativeMethods.TITLEBARINFOEX();
     ti.cbSize = Marshal.SizeOf(ti.GetType());
     IntPtr result;
     IntPtr resultSendMessage = UnsafeNativeMethods.SendMessageTimeout(hwnd, NativeMethods.WM_GETTITLEBARINFOEX, IntPtr.Zero, ref ti, _sendMessageFlags, _sendMessageTimeoutValue, out result);
     int lastWin32Error = Marshal.GetLastWin32Error();
     if (resultSendMessage == IntPtr.Zero)
     {
         //Window owner failed to process the message WM_GETTITLEBARINFOEX
         EvaluateSendMessageTimeoutError(lastWin32Error);
     }
     return true;
 }
예제 #30
0
파일: TextStore.cs 프로젝트: mind0n/hive
        public void GetACPFromPoint(int viewCookie, ref UnsafeNativeMethods.POINT tsfPoint, UnsafeNativeMethods.GetPositionFromPointFlags flags, out int positionCP)
        {
            SecurityHelper.DemandUnmanagedCode();

            PresentationSource source;
            IWin32Window win32Window;
            CompositionTarget compositionTarget;
            ITextView view;
            Point milPoint;
            ITextPointer position;
            NativeMethods.POINT point;

            point = new NativeMethods.POINT(tsfPoint.x, tsfPoint.y);
            GetVisualInfo(out source, out win32Window, out view);
            compositionTarget = source.CompositionTarget;

            // Convert to client coordinates.
            SafeNativeMethods.ScreenToClient(new HandleRef(null,win32Window.Handle), point);

            // Convert to mil measure units.
            milPoint = new Point(point.x, point.y);
            milPoint = compositionTarget.TransformFromDevice.Transform(milPoint);

            // Convert to local coordinates.
            GeneralTransform transform = compositionTarget.RootVisual.TransformToDescendant(RenderScope);
            if (transform != null)
            {
                // 
                transform.TryTransform(milPoint, out milPoint);
            }

            // Validate layout information on TextView
            if (!view.Validate(milPoint))
            {
                throw new COMException(SR.Get(SRID.TextStore_TS_E_NOLAYOUT), UnsafeNativeMethods.TS_E_NOLAYOUT);
            }

            // Do the hittest.
            position = view.GetTextPositionFromPoint(milPoint, (flags & UnsafeNativeMethods.GetPositionFromPointFlags.GXFPF_NEAREST) != 0 /* snapToText */);
            if (position == null)
            {
                // GXFPF_ROUND_NEAREST was clear and we didn't hit a char.
                throw new COMException(SR.Get(SRID.TextStore_TS_E_INVALIDPOINT), UnsafeNativeMethods.TS_E_INVALIDPOINT);
            }

            positionCP = position.CharOffset;
            if ((flags & UnsafeNativeMethods.GetPositionFromPointFlags.GXFPF_ROUND_NEAREST) == 0)
            {
                // Check if the point is on the backward position of the TextPosition.
                Rect rectCur;
                Rect rectPrev;
                Point milPointTopLeft;
                Point milPointBottomRight;

                ITextPointer positionCur = position.CreatePointer(LogicalDirection.Backward);
                ITextPointer positionPrev = position.CreatePointer(LogicalDirection.Forward);
                positionPrev.MoveToNextInsertionPosition(LogicalDirection.Backward);

                rectCur = view.GetRectangleFromTextPosition(positionCur);
                rectPrev = view.GetRectangleFromTextPosition(positionPrev);

                // Take the "extended" union of the previous char's bounding box.
                milPointTopLeft = new Point(Math.Min(rectPrev.Left, rectCur.Left), Math.Min(rectPrev.Top, rectCur.Top));
                milPointBottomRight = new Point(Math.Max(rectPrev.Left, rectCur.Left), Math.Max(rectPrev.Bottom, rectCur.Bottom));

                // The rect of the previous char.
                Rect rectTest = new Rect(milPointTopLeft, milPointBottomRight);
                if (rectTest.Contains(milPoint))
                    positionCP--;
            }
        }
예제 #31
0
파일: TextStore.cs 프로젝트: mind0n/hive
        void UnsafeNativeMethods.ITextStoreACP.GetTextExt(int viewCookie, int startIndex, int endIndex, out UnsafeNativeMethods.RECT rect, out bool clipped)
        {
            PresentationSource source;
            IWin32Window win32Window;
            CompositionTarget compositionTarget;
            ITextView view;
            ITextPointer startPointer;
            ITextPointer endPointer;
            GeneralTransform transform;
            Point milPointTopLeft;
            Point milPointBottomRight;

            // We need to update the layout before getting rect. It could be dirty by SetText call of TIP.
            _isInUpdateLayout = true;
            UiScope.UpdateLayout();
            _isInUpdateLayout = false;

            // (Dev11 721274) if UpdateLayout caused a text change, startIndex
            // and endIndex are no longer valid.  Handling this correctly is quite
            // difficult - Cicero assumes that the text can't change while it
            // owns the lock.  Instead, we artificially reset the char count (to
            // keep VerifyTextStoreConsistency happy), and return TS_R_NOLAYOUT
            // to the caller; this seems to be good enough (i.e. avoids crashes)
            // in practice.
            if (_hasTextChangedInUpdateLayout)
            {
                _netCharCount = this.TextContainer.IMECharCount;
                throw new COMException(SR.Get(SRID.TextStore_TS_E_NOLAYOUT), UnsafeNativeMethods.TS_E_NOLAYOUT);
            }

            rect = new UnsafeNativeMethods.RECT();
            clipped = false;
            GetVisualInfo(out source, out win32Window, out view);
            compositionTarget = source.CompositionTarget;

            // We use local coordinates.
            startPointer = CreatePointerAtCharOffset(startIndex, LogicalDirection.Forward);
            startPointer.MoveToInsertionPosition(LogicalDirection.Forward);

            if (!this.TextView.IsValid)
            {
                // We can not get the visual. Return TS_R_NOLAYOUT to the caller.
                throw new COMException(SR.Get(SRID.TextStore_TS_E_NOLAYOUT), UnsafeNativeMethods.TS_E_NOLAYOUT);
            }

            if (startIndex == endIndex)
            {
                Rect rectStart = startPointer.GetCharacterRect(LogicalDirection.Forward);
                milPointTopLeft = rectStart.TopLeft;
                milPointBottomRight = rectStart.BottomRight;
            }
            else
            {
                Rect rectBound = new Rect(Size.Empty);
                ITextPointer navigator = startPointer.CreatePointer();
                endPointer = CreatePointerAtCharOffset(endIndex, LogicalDirection.Backward);
                endPointer.MoveToInsertionPosition(LogicalDirection.Backward);
                bool moved;

                do
                {
                    // Compute the textSegment bounds line by line.
                    TextSegment lineRange = this.TextView.GetLineRange(navigator);
                    ITextPointer end;
                    Rect lineRect;

                    // Skip any BlockUIContainer or any other content that is not treated as a line by TextView.
                    if (!lineRange.IsNull)
                    {
                        ITextPointer start = (lineRange.Start.CompareTo(startPointer) <= 0) ? startPointer : lineRange.Start;
                        end = (lineRange.End.CompareTo(endPointer) >= 0) ? endPointer : lineRange.End;

                        lineRect = GetLineBounds(start, end);
                        moved = (navigator.MoveToLineBoundary(1) != 0) ? true : false;

                    }
                    else
                    {
                        lineRect = navigator.GetCharacterRect(LogicalDirection.Forward);
                        moved = navigator.MoveToNextInsertionPosition(LogicalDirection.Forward);
                        end = navigator;
                    }

                    if (lineRect.IsEmpty == false)
                    {
                        rectBound.Union(lineRect);
                    }

                    if (end.CompareTo(endPointer) == 0)
                    {
                        break;
                    }
                }
                while (moved);

                // Invariant.Assert(rectBound.IsEmpty == false);

                milPointTopLeft = rectBound.TopLeft;
                milPointBottomRight = rectBound.BottomRight;
            }

            // Transform to root visual coordinates.
            transform = UiScope.TransformToAncestor(compositionTarget.RootVisual);

            // 
            transform.TryTransform(milPointTopLeft, out milPointTopLeft);
            transform.TryTransform(milPointBottomRight, out milPointBottomRight);

            rect = TransformRootRectToScreenCoordinates(milPointTopLeft, milPointBottomRight, win32Window, source);
        }
예제 #32
0
 static HwndWrapper()
 {
     s_msgGCMemory = UnsafeNativeMethods.RegisterWindowMessage("HwndWrapper.GetGCMemMessage");
 }