Пример #1
0
        public static void SetFileDropList(StringCollection filePaths)
        {
            if (filePaths == null)
            {
                throw new ArgumentNullException(nameof(filePaths));
            }
            if (filePaths.Count == 0)
            {
                throw new ArgumentException(SR.CollectionEmptyException);
            }

            // Validate the paths to make sure they don't contain invalid characters
            foreach (string path in filePaths)
            {
                try
                {
                    Path.GetFullPath(path);
                }
                catch (Exception e) when(!ClientUtils.IsCriticalException(e))
                {
                    throw new ArgumentException(string.Format(SR.Clipboard_InvalidPath, path, "filePaths"), e);
                }
            }

            if (filePaths.Count > 0)
            {
                IDataObject dataObject = new DataObject();
                string[]    strings    = new string[filePaths.Count];
                filePaths.CopyTo(strings, 0);
                dataObject.SetData(DataFormats.FileDrop, true, strings);
                Clipboard.SetDataObject(dataObject, true);
            }
        }
            public override int GetHelpTopic(out string?fileName)
            {
                int topic = 0;

                QueryAccessibilityHelpEventHandler?handler = (QueryAccessibilityHelpEventHandler?)Owner.Events[s_queryAccessibilityHelpEvent];

                if (handler is null)
                {
                    return(base.GetHelpTopic(out fileName));
                }

                QueryAccessibilityHelpEventArgs args = new QueryAccessibilityHelpEventArgs();

                handler(Owner, args);

                fileName = args.HelpNamespace;

                try
                {
                    topic = int.Parse(args.HelpKeyword, CultureInfo.InvariantCulture);
                }
                catch (Exception e) when(!ClientUtils.IsCriticalException(e))
                {
                }

                return(topic);
            }
            /// <summary>
            ///  Disconnect the current connection point.  If the object is not connected,
            ///  this method will do nothing.
            /// </summary>
            public void Disconnect()
            {
                if (connectionPoint != null && cookie != 0)
                {
                    try
                    {
                        connectionPoint.Unadvise(cookie);
                    }
                    catch (Exception ex) when(!ClientUtils.IsCriticalException(ex))
                    {
                    }
                    finally
                    {
                        cookie = 0;
                    }

                    try
                    {
                        Marshal.ReleaseComObject(connectionPoint);
                    }
                    catch (Exception ex) when(!ClientUtils.IsCriticalException(ex))
                    {
                    }
                    finally
                    {
                        connectionPoint = null;
                    }
                }
            }
Пример #4
0
        public unsafe object InvokeScript(string scriptName, object[] args)
        {
            try
            {
                if (NativeHtmlDocument2.GetScript() is Oleaut32.IDispatch scriptObject)
                {
                    Guid             g      = Guid.Empty;
                    string[]         names  = new string[] { scriptName };
                    Ole32.DispatchID dispid = Ole32.DispatchID.UNKNOWN;
                    HRESULT          hr     = scriptObject.GetIDsOfNames(&g, names, 1, Kernel32.GetThreadLocale(), &dispid);
                    if (!hr.Succeeded() || dispid == Ole32.DispatchID.UNKNOWN)
                    {
                        return(null);
                    }

                    if (args != null)
                    {
                        // Reverse the arg order so that they read naturally after IDispatch.
                        Array.Reverse(args);
                    }

                    using var vectorArgs = new Oleaut32.VARIANTVector(args);
                    fixed(Oleaut32.VARIANT *pVariants = vectorArgs.Variants)
                    {
                        var dispParams = new Oleaut32.DISPPARAMS();

                        dispParams.rgvarg            = pVariants;
                        dispParams.cArgs             = (uint)vectorArgs.Variants.Length;
                        dispParams.rgdispidNamedArgs = null;
                        dispParams.cNamedArgs        = 0;

                        var retVals   = new object[1];
                        var excepInfo = new Oleaut32.EXCEPINFO();

                        hr = scriptObject.Invoke(
                            dispid,
                            &g,
                            Kernel32.GetThreadLocale(),
                            Oleaut32.DISPATCH.METHOD,
                            &dispParams,
                            retVals,
                            &excepInfo,
                            null);
                        if (hr == HRESULT.S_OK)
                        {
                            return(retVals[0]);
                        }
                    }
                }
            }
            catch (Exception ex) when(!ClientUtils.IsCriticalException(ex))
            {
            }

            return(null);
        }
Пример #5
0
 public object MarshalNativeToManaged(IntPtr pObj)
 {
     Ole32.IFont nativeFont = (Ole32.IFont)Marshal.GetObjectForIUnknown(pObj);
     try
     {
         return(Font.FromHfont(nativeFont.hFont));
     }
     catch (Exception e) when(!ClientUtils.IsCriticalException(e))
     {
         return(DefaultFont);
     }
 }
Пример #6
0
        /// <devdoc>
        ///     <para>Searches for Items by their Name property, builds up an array list
        ///           of all the items that match.
        ///     </para>
        /// </devdoc>
        /// <internalonly/>
        private ArrayList FindInternal(string key, bool searchAllChildren, ToolStripItemCollection itemsToLookIn, ArrayList foundItems)
        {
            if ((itemsToLookIn == null) || (foundItems == null))
            {
                return(null);  //
            }

            try
            {
                for (int i = 0; i < itemsToLookIn.Count; i++)
                {
                    if (itemsToLookIn[i] == null)
                    {
                        continue;
                    }

                    if (WindowsFormsUtils.SafeCompareStrings(itemsToLookIn[i].Name, key, /* ignoreCase = */ true))
                    {
                        foundItems.Add(itemsToLookIn[i]);
                    }
                }


                // Optional recurive search for controls in child collections.

                if (searchAllChildren)
                {
                    for (int j = 0; j < itemsToLookIn.Count; j++)
                    {
                        ToolStripDropDownItem item = itemsToLookIn[j] as ToolStripDropDownItem;
                        if (item == null)
                        {
                            continue;
                        }
                        if (item.HasDropDownItems)
                        {
                            // if it has a valid child collecion, append those results to our collection
                            foundItems = FindInternal(key, searchAllChildren, item.DropDownItems, foundItems);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                // Make sure we deal with non-critical failures gracefully.
                if (ClientUtils.IsCriticalException(e))
                {
                    throw;
                }
            }

            return(foundItems);
        }
Пример #7
0
        private ArrayList FindControls(Type baseType, bool searchAllChildren, Control.ControlCollection controlsToLookIn, ArrayList foundControls)
        {
            if ((controlsToLookIn == null) || (foundControls == null))
            {
                return(null);
            }

            try
            {
                // Perform breadth first search - as it's likely people will want controls belonging
                // to the same parent close to each other.

                for (int i = 0; i < controlsToLookIn.Count; i++)
                {
                    if (controlsToLookIn[i] == null)
                    {
                        continue;
                    }

                    if (baseType.IsAssignableFrom(controlsToLookIn[i].GetType()))
                    {
                        foundControls.Add(controlsToLookIn[i]);
                    }
                }

                // Optional recurive search for controls in child collections.

                if (searchAllChildren)
                {
                    for (int i = 0; i < controlsToLookIn.Count; i++)
                    {
                        if (controlsToLookIn[i] == null || controlsToLookIn[i] is Form)
                        {
                            continue;
                        }
                        if ((controlsToLookIn[i].Controls != null) && controlsToLookIn[i].Controls.Count > 0)
                        {
                            // if it has a valid child collecion, append those results to our collection
                            foundControls = FindControls(baseType, searchAllChildren, controlsToLookIn[i].Controls, foundControls);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                if (ClientUtils.IsCriticalException(e))
                {
                    throw;
                }
            }
            return(foundControls);
        }
Пример #8
0
            private ArrayList FindInternal(string key, bool searchAllChildren, ControlCollection controlsToLookIn, ArrayList foundControls)
            {
                if ((controlsToLookIn == null) || (foundControls == null))
                {
                    return(null);
                }

                try
                {
                    // Perform breadth first search - as it's likely people will want controls belonging
                    // to the same parent close to each other.
                    for (int i = 0; i < controlsToLookIn.Count; i++)
                    {
                        if (controlsToLookIn[i] == null)
                        {
                            continue;
                        }

                        if (WindowsFormsUtils.SafeCompareStrings(controlsToLookIn[i].Name, key, /* ignoreCase = */ true))
                        {
                            foundControls.Add(controlsToLookIn[i]);
                        }
                    }

                    // Optional recurive search for controls in child collections.

                    if (searchAllChildren)
                    {
                        for (int i = 0; i < controlsToLookIn.Count; i++)
                        {
                            if (controlsToLookIn[i] == null)
                            {
                                continue;
                            }
                            if ((controlsToLookIn[i].Controls != null) && controlsToLookIn[i].Controls.Count > 0)
                            {
                                // if it has a valid child collecion, append those results to our collection
                                foundControls = FindInternal(key, searchAllChildren, controlsToLookIn[i].Controls, foundControls);
                            }
                        }
                    }
                }
                catch (Exception e) when(!ClientUtils.IsCriticalException(e))
                {
                }
                return(foundControls);
            }
Пример #9
0
        private void FindControls<T>(bool searchAllChildren, Control.ControlCollection controlsToLookIn, List<T> foundControls)
            where T : Control
        {
            try
            {
                // Perform breadth first search - as it's likely people will want controls belonging
                // to the same parent close to each other.
                for (int i = 0; i < controlsToLookIn.Count; i++)
                {
                    if (controlsToLookIn[i] is null)
                    {
                        continue;
                    }

                    if (controlsToLookIn[i] is T control)
                    {
                        foundControls.Add(control);
                    }
                }

                // Optional recursive search for controls in child collections.
                if (searchAllChildren)
                {
                    for (int i = 0; i < controlsToLookIn.Count; i++)
                    {
                        if (controlsToLookIn[i] is null || controlsToLookIn[i] is Form)
                        {
                            continue;
                        }

                        if ((controlsToLookIn[i].Controls is not null) && controlsToLookIn[i].Controls.Count > 0)
                        {
                            // If it has a valid child collection, append those results to our collection.
                            FindControls(searchAllChildren, controlsToLookIn[i].Controls, foundControls);
                        }
                    }
                }
            }
            catch (Exception e) when (!ClientUtils.IsCriticalException(e))
            {
            }
        }
            private void FindInternal(string key, bool searchAllChildren, ControlCollection controlsToLookIn, List <Control> foundControls)
            {
                try
                {
                    // Perform breadth first search - as it's likely people will want controls belonging
                    // to the same parent close to each other.
                    for (int i = 0; i < controlsToLookIn.Count; i++)
                    {
                        if (controlsToLookIn[i] is null)
                        {
                            continue;
                        }

                        if (WindowsFormsUtils.SafeCompareStrings(controlsToLookIn[i].Name, key, ignoreCase: true))
                        {
                            foundControls.Add(controlsToLookIn[i]);
                        }
                    }

                    // Optional recursive search for controls in child collections.
                    if (searchAllChildren)
                    {
                        for (int i = 0; i < controlsToLookIn.Count; i++)
                        {
                            if (controlsToLookIn[i] is null)
                            {
                                continue;
                            }

                            if (controlsToLookIn[i].Controls.Count > 0)
                            {
                                // If it has a valid child collection, append those results to our collection.
                                FindInternal(key, true, controlsToLookIn[i].Controls, foundControls);
                            }
                        }
                    }
                }
                catch (Exception e) when(!ClientUtils.IsCriticalException(e))
                {
                }
            }
Пример #11
0
        private void FindInternal(string key, bool searchAllChildren, ToolStripItemCollection itemsToLookIn, List <ToolStripItem> foundItems)
        {
            try
            {
                for (int i = 0; i < itemsToLookIn.Count; i++)
                {
                    if (itemsToLookIn[i] is null)
                    {
                        continue;
                    }

                    if (WindowsFormsUtils.SafeCompareStrings(itemsToLookIn[i].Name, key, ignoreCase: true))
                    {
                        foundItems.Add(itemsToLookIn[i]);
                    }
                }

                // Optional recursive search for controls in child collections.
                if (searchAllChildren)
                {
                    for (int j = 0; j < itemsToLookIn.Count; j++)
                    {
                        if (itemsToLookIn[j] is not ToolStripDropDownItem item)
                        {
                            continue;
                        }

                        if (item.HasDropDownItems)
                        {
                            // If it has a valid child collection, append those results to our collection.
                            FindInternal(key, searchAllChildren, item.DropDownItems, foundItems);
                        }
                    }
                }
            }
            catch (Exception e) when(!ClientUtils.IsCriticalException(e))
            {
            }
        }
Пример #12
0
        internal void StartEvents()
        {
            if (connectionPoint != null)
            {
                return;
            }

            object nativeObject = Host.activeXInstance;

            if (nativeObject != null)
            {
                try
                {
                    connectionPoint = new AxHost.ConnectionPointCookie(nativeObject, this, typeof(Ole32.IPropertyNotifySink));
                }
                catch (Exception ex)
                {
                    if (ClientUtils.IsCriticalException(ex))
                    {
                        throw;
                    }
                }
            }
        }
Пример #13
0
        public unsafe DCMapping(Gdi32.HDC hdc, Rectangle bounds)
        {
            ArgumentNullException.ThrowIfNull(hdc);

            bool success;

            _hdc        = hdc;
            _savedState = Gdi32.SaveDC(hdc);

            // Retrieve the x-coordinates and y-coordinates of the viewport origin for the specified device context.
            success = Gdi32.GetViewportOrgEx(hdc, out Point viewportOrg).IsTrue();
            Debug.Assert(success, "GetViewportOrgEx() failed.");

            // Create a new rectangular clipping region based off of the bounds specified, shifted over by the x & y specified in the viewport origin.
            var hClippingRegion = new Gdi32.RegionScope(
                viewportOrg.X + bounds.Left,
                viewportOrg.Y + bounds.Top,
                viewportOrg.X + bounds.Right,
                viewportOrg.Y + bounds.Bottom);

            Debug.Assert(!hClippingRegion.IsNull, "CreateRectRgn() failed.");

            try
            {
                var hOriginalClippingRegion = new Gdi32.RegionScope(hdc);

                // Shift the viewpoint origin by coordinates specified in "bounds".
                var lastViewPort = new Point();
                success = Gdi32.SetViewportOrgEx(
                    hdc,
                    viewportOrg.X + bounds.Left,
                    viewportOrg.Y + bounds.Top,
                    &lastViewPort).IsTrue();
                Debug.Assert(success, "SetViewportOrgEx() failed.");

                RegionType originalRegionType;
                if (!hOriginalClippingRegion.IsNull)
                {
                    // Get the original clipping region so we can determine its type (we'll check later if we've restored the region back properly.)
                    RECT originalClipRect = new RECT();
                    originalRegionType = Gdi32.GetRgnBox(hOriginalClippingRegion, ref originalClipRect);
                    Debug.Assert(
                        originalRegionType != RegionType.ERROR,
                        "ERROR returned from SelectClipRgn while selecting the original clipping region..");

                    if (originalRegionType == RegionType.SIMPLEREGION)
                    {
                        // Find the intersection of our clipping region and the current clipping region (our parent's)

                        RegionType combineResult = Gdi32.CombineRgn(
                            hClippingRegion,
                            hClippingRegion,
                            hOriginalClippingRegion,
                            Gdi32.RGN.AND);

                        Debug.Assert(
                            (combineResult == RegionType.SIMPLEREGION) || (combineResult == RegionType.NULLREGION),
                            "SIMPLEREGION or NULLREGION expected.");
                    }
                }
                else
                {
                    // If there was no clipping region, then the result is a simple region.
                    originalRegionType = RegionType.SIMPLEREGION;
                }

                // Select the new clipping region; make sure it's a SIMPLEREGION or NULLREGION
                RegionType selectResult = Gdi32.SelectClipRgn(hdc, hClippingRegion);
                Debug.Assert(
                    selectResult == RegionType.SIMPLEREGION || selectResult == RegionType.NULLREGION,
                    "SIMPLEREGION or NULLLREGION expected.");
            }
            catch (Exception ex) when(!ClientUtils.IsCriticalException(ex))
            {
            }
        }
Пример #14
0
        public unsafe DCMapping(IntPtr hDC, Rectangle bounds)
        {
            if (hDC == IntPtr.Zero)
            {
                throw new ArgumentNullException(nameof(hDC));
            }

            bool success;

            _translatedBounds = bounds;
            _graphics = null;
            _dc = DeviceContext.FromHdc(hDC);
            _dc.SaveHdc();

            // Retrieve the x-coordinates and y-coordinates of the viewport origin for the specified device context.
            success = Gdi32.GetViewportOrgEx(hDC, out Point viewportOrg).IsTrue();
            Debug.Assert(success, "GetViewportOrgEx() failed.");

            // Create a new rectangular clipping region based off of the bounds specified, shifted over by the x & y specified in the viewport origin.
            var hClippingRegion = new Gdi32.RegionScope(
                viewportOrg.X + bounds.Left,
                viewportOrg.Y + bounds.Top,
                viewportOrg.X + bounds.Right,
                viewportOrg.Y + bounds.Bottom);
            Debug.Assert(!hClippingRegion.IsNull, "CreateRectRgn() failed.");

            try
            {
                // Create an empty region oriented at 0,0 so we can populate it with the original clipping region of the hDC passed in.
                var hOriginalClippingRegion = new Gdi32.RegionScope(0, 0, 0, 0);
                Debug.Assert(!hOriginalClippingRegion.IsNull, "CreateRectRgn() failed.");

                // Get the clipping region from the hDC: result = {-1 = error, 0 = no region, 1 = success} per MSDN
                int result = Gdi32.GetClipRgn(hDC, hOriginalClippingRegion);
                Debug.Assert(result != -1, "GetClipRgn() failed.");

                // Shift the viewpoint origint by coordinates specified in "bounds".
                var lastViewPort = new Point();
                success = Gdi32.SetViewportOrgEx(hDC, viewportOrg.X + bounds.Left, viewportOrg.Y + bounds.Top, &lastViewPort).IsTrue();
                Debug.Assert(success, "SetViewportOrgEx() failed.");

                RegionType originalRegionType;
                if (result != 0)
                {
                    // Get the origninal clipping region so we can determine its type (we'll check later if we've restored the region back properly.)
                    RECT originalClipRect = new RECT();
                    originalRegionType = Gdi32.GetRgnBox(hOriginalClippingRegion, ref originalClipRect);
                    Debug.Assert(
                        originalRegionType != RegionType.ERROR,
                        "ERROR returned from SelectClipRgn while selecting the original clipping region..");

                    if (originalRegionType == RegionType.SIMPLEREGION)
                    {
                        // Find the intersection of our clipping region and the current clipping region (our parent's)

                        RegionType combineResult = Gdi32.CombineRgn(
                            hClippingRegion,
                            hClippingRegion,
                            hOriginalClippingRegion,
                            Gdi32.CombineMode.RGN_AND);

                        Debug.Assert(
                            (combineResult == RegionType.SIMPLEREGION) || (combineResult == RegionType.NULLREGION),
                            "SIMPLEREGION or NULLREGION expected.");
                    }
                }
                else
                {
                    // If there was no clipping region, then the result is a simple region.
                    originalRegionType = RegionType.SIMPLEREGION;
                }

                // Select the new clipping region; make sure it's a SIMPLEREGION or NULLREGION
                RegionType selectResult = Gdi32.SelectClipRgn(hDC, hClippingRegion);
                Debug.Assert(
                    selectResult == RegionType.SIMPLEREGION || selectResult == RegionType.NULLREGION,
                    "SIMPLEREGION or NULLLREGION expected.");
            }
            catch (Exception ex) when (!ClientUtils.IsCriticalException(ex))
            {
                _dc.RestoreHdc();
                _dc.Dispose();
            }
        }