/// <summary>
        /// Executes a dispatch.
        /// The dispatch call is executed in a time limited way <see cref="TimeLimitExecutor"/> (200 ms).
        /// </summary>
        /// <param name="commandUrl">The command URL to dispatch. Describes the
        /// feature which should be supported by internally used dispatch object.
        /// <see cref="https://wiki.openoffice.org/wiki/Framework/Article/OpenOffice.org_2.x_Commands#Draw.2FImpress_commands"/></param>
        /// <param name="docViewContrl">The document view controller. Points to
        /// the provider, which should be asked for valid dispatch objects.</param>
        /// <param name="_frame">Specifies the frame which should be the target
        /// for this request.</param>
        /// <param name="_sFlag">Optional search parameter for finding the frame
        /// if no special TargetFrameName was used.</param>
        /// <param name="args">Optional arguments for this request They depend on
        /// the real implementation of the dispatch object.</param>
        /// <remarks>This function is time limited to 200 ms.</remarks>
        internal static bool CallDispatch(string commandUrl, XDispatchProvider docViewContrl, String _frame = "", int _sFlag = 0, PropertyValue[] args = null)
        {
            bool successs = false;

            if (!String.IsNullOrWhiteSpace(commandUrl))
            {
                bool abort = TimeLimitExecutor.WaitForExecuteWithTimeLimit(
                    200,
                    new Action(() =>
                {
                    var disp = GetDispatcher(OO.GetMultiServiceFactory());
                    if (disp != null)
                    {
                        // A possible result of the executed internal dispatch.
                        // The information behind this any depends on the dispatch!
                        var result = disp.executeDispatch(docViewContrl, commandUrl, _frame, _sFlag, args);

                        if (result.hasValue() && result.Value is unoidl.com.sun.star.frame.DispatchResultEvent)
                        {
                            var val = result.Value as unoidl.com.sun.star.frame.DispatchResultEvent;
                            if (val != null && val.State == (short)DispatchResultState.SUCCESS)
                            {
                                successs = true;
                            }
                        }
                    }
                }),
                    "Dispatch Call");
                successs &= abort;
            }

            return(successs);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Dispatch an URL to given frame.
        /// Caller can register himself for following result events for dispatched
        /// URL too. Notifications are guaranteed (instead of dispatch())
        /// Returning of the dispatch object isn't necessary.
        /// Nobody must hold it alive longer the dispatch needs.
        /// </summary>
        /// <param name="xFrame">frame wich should be the target of this dispatch</param>
        /// <param name="aUrl">full parsed and converted office URL for dispatch</param>
        /// <param name="lProperties">optional arguments for dispatch</param>
        /// <param name="xListener">
        /// optional listener which is registered automatically for status events
        /// (Note: Deregistration is not supported. Dispatcher does it automatically.)
        /// </param>
        public static void ExecuteWithNotification(XFrame xFrame, URL aUrl, PropertyValue[] lProperties, XDispatchResultListener xListener)
        {
            try
            {
                // Query the frame for right interface which provides access to all available dispatch objects.
                XDispatchProvider xProvider = (XDispatchProvider)xFrame;

                // Ask him for right dispatch object for given URL.
                // Force THIS frame as target for following dispatch.
                // Attention: The interface XNotifyingDispatch is an optional one!
                XDispatch          xDispatcher          = xProvider.queryDispatch(aUrl, "", 0);
                XNotifyingDispatch xNotifyingDispatcher = (XNotifyingDispatch)xDispatcher;

                // Dispatch the URL.
                if (xNotifyingDispatcher != null)
                {
                    xNotifyingDispatcher.dispatchWithNotification(aUrl, lProperties, xListener);
                }
            }
            catch (RuntimeException exUno)
            {
                // Any UNO method of this scope can throw this exception.
                // But there is nothing we can do then.
                System.Diagnostics.Debug.WriteLine(exUno);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Dispatch an URL to given frame.
        /// Caller can register himself for following status events for dispatched
        /// URL too. But nobody guarantee that such notifications will occur.
        /// (see dispatchWithNotification() if you interest on that)
        /// The returned dispatch object should be hold alive by caller
        /// till he doesn't need it any longer. Otherwise the dispatcher can(!)
        /// die by decreasing his refcount.
        /// (Note: Deregistration is part of this listener himself!)
        /// </summary>
        /// <param name="xFrame">frame wich should be the target of this dispatch</param>
        /// <param name="aUrl">full parsed and converted office URL for dispatch</param>
        /// <param name="lProperties">optional arguments for dispatch</param>
        /// <param name="xListener">optional listener which is registered automaticly for status events</param>
        /// <returns>
        /// It's the used dispatch object and can be used for deregistration of an optional listener.
        /// Otherwise caller can ignore it.
        /// </returns>
        public static XDispatch Execute(XFrame xFrame, URL aUrl, PropertyValue[] lProperties, XStatusListener xListener)
        {
            XDispatch xDispatcher;

            try
            {
                // Query the frame for right interface which provides access to all available dispatch objects.
                XDispatchProvider xProvider = (XDispatchProvider)xFrame;

                // Ask him for right dispatch object for given URL.
                // Force given frame as target for following dispatch by using "".
                // It means the same like "_self".
                xDispatcher = xProvider.queryDispatch(aUrl, "", 0);

                // Dispatch the URL into the frame.
                if (xDispatcher != null)
                {
                    if (xListener != null)
                    {
                        xDispatcher.addStatusListener(xListener, aUrl);
                    }

                    xDispatcher.dispatch(aUrl, lProperties);
                }
            }
            catch (RuntimeException exUno)
            {
                // Any UNO method of this scope can throw this exception.
                // But there will be nothing to do then - because
                // we haven't changed anything inside the remote objects
                // except method "addStatusListener().
                // But in this case the source of this exception has to
                // rollback all his operations. There is no chance to
                // make anything right then.
                // Reset the return value to a default - that's it.
                System.Diagnostics.Debug.WriteLine(exUno);
                xDispatcher = null;
            }

            return(xDispatcher);
        }
        /// <summary>
        /// Executes a dispatch on a previously (GUI) selected object.
        /// </summary>
        /// <param name="obj">The object.</param>
        /// <param name="docSelSuppl">The document sel suppl.</param>
        /// <param name="commandUrl">The command URL.</param>
        /// <param name="docViewContrl">The document view contrl.</param>
        /// <param name="_frame">The frame.</param>
        /// <param name="_sFlag">The s flag.</param>
        /// <param name="args">The arguments.</param>
        /// <exception cref="System.ArgumentException">Objects could not be selected. - obj</exception>
        internal static bool CallDispatchOnObject(
            Object obj, XSelectionSupplier docSelSuppl,
            string commandUrl, XDispatchProvider docViewContrl,
            String _frame = "", int _sFlag = 0, PropertyValue[] args = null)
        {
            if (obj != null && docSelSuppl != null &&
                docViewContrl != null && !String.IsNullOrWhiteSpace(commandUrl))
            {
                // you have to select objects to call commands
                try
                {
                    docSelSuppl.select(Any.Get(obj));
                }
                catch (Exception ex)
                {
                    throw new ArgumentException("Objects could not be selected.", "obj", ex);
                }

                return(CallDispatch(commandUrl, docViewContrl, _frame, _sFlag, args));
            }
            return(false);
        }
Ejemplo n.º 5
0
        public void InsertGraphic(string imgpath)
        {
            Object            dispatchHelper    = mxMSFactory.createInstance("com.sun.star.frame.DispatchHelper");
            XDispatchHelper   dispatcher        = dispatchHelper as XDispatchHelper;
            XModel            xModel            = mxDocument as XModel;
            XFrame            xFrame            = xModel.getCurrentController().getFrame();
            XDispatchProvider xDispatchProvider = xFrame as XDispatchProvider;

            unoidl.com.sun.star.beans.PropertyValue[] MyProp = new unoidl.com.sun.star.beans.PropertyValue[4];
            MyProp[0]       = new unoidl.com.sun.star.beans.PropertyValue();
            MyProp[0].Name  = "FileName";
            MyProp[0].Value = new uno.Any(PathConverter(imgpath));
            MyProp[1]       = new unoidl.com.sun.star.beans.PropertyValue();
            MyProp[1].Name  = "FilterName";
            MyProp[1].Value = new uno.Any("<Tous les formats>");
            MyProp[2]       = new unoidl.com.sun.star.beans.PropertyValue();
            MyProp[2].Name  = "AsLink";
            MyProp[2].Value = new uno.Any(false);
            MyProp[3]       = new unoidl.com.sun.star.beans.PropertyValue();
            MyProp[3].Name  = "Style";
            MyProp[3].Value = new uno.Any("Image");
            dispatcher.executeDispatch(xDispatchProvider, ".uno:InsertGraphic", "", 0, MyProp);
        }
        /// <summary>
        /// Executes a dispatch.
        /// </summary>
        /// <param name="commandUrl">The command URL to dispatch. Describes the 
        /// feature which should be supported by internally used dispatch object. 
        /// <see cref="https://wiki.openoffice.org/wiki/Framework/Article/OpenOffice.org_2.x_Commands#Draw.2FImpress_commands"/></param>
        /// <param name="docViewContrl">The document view controller. Points to 
        /// the provider, which should be asked for valid dispatch objects.</param>
        /// <param name="_frame">Specifies the frame which should be the target 
        /// for this request.</param>
        /// <param name="_sFlag">Optional search parameter for finding the frame 
        /// if no special TargetFrameName was used.</param>
        /// <param name="args">Optional arguments for this request They depend on 
        /// the real implementation of the dispatch object.</param>
        internal static bool CallDispatch(string commandUrl, XDispatchProvider docViewContrl, String _frame = "", int _sFlag = 0, PropertyValue[] args = null)
        {
            if (!String.IsNullOrWhiteSpace(commandUrl))
            {
                var disp = GetDispatcher(OO.GetMultiServiceFactory());
                if (disp != null)
                {
                    // A possible result of the executed internal dispatch. 
                    // The information behind this any depends on the dispatch!
                    var result = disp.executeDispatch(docViewContrl, commandUrl, _frame, _sFlag, args);

                    if (result.hasValue() && result.Value is unoidl.com.sun.star.frame.DispatchResultEvent)
                    {
                        var val = result.Value as unoidl.com.sun.star.frame.DispatchResultEvent;
                        if (val != null && val.State == (short)DispatchResultState.SUCCESS)
                        {
                            return true;
                        }
                    }
                }
            }

            return false;
        }
        /// <summary>
        /// Executes a dispatch on a previously (GUI) selected object.
        /// </summary>
        /// <param name="obj">The object.</param>
        /// <param name="docSelSuppl">The document sel suppl.</param>
        /// <param name="commandUrl">The command URL.</param>
        /// <param name="docViewContrl">The document view contrl.</param>
        /// <param name="_frame">The frame.</param>
        /// <param name="_sFlag">The s flag.</param>
        /// <param name="args">The arguments.</param>
        /// <exception cref="System.ArgumentException">Objects could not be selected. - obj</exception>
        internal static bool CallDispatchOnObject(
            Object obj, XSelectionSupplier docSelSuppl,
            string commandUrl, XDispatchProvider docViewContrl,
            String _frame = "", int _sFlag = 0, PropertyValue[] args = null)
        {

            if (obj != null && docSelSuppl != null
                && docViewContrl != null && !String.IsNullOrWhiteSpace(commandUrl))
            {
                // you have to select objects to call commands
                try
                {
                    docSelSuppl.select(Any.Get(obj));
                }
                catch (Exception ex)
                {
                    throw new ArgumentException("Objects could not be selected.", "obj", ex);
                }

                return CallDispatch(commandUrl, docViewContrl, _frame, _sFlag, args);
            }
            return false;
        }