コード例 #1
0
        public void CreateNewDocumentAndDoAPrintOut()
        {
            string fileToPrint = AARunMeFirstAndOnce.outPutFolder + "fileToPrint.odt";

            //Create a new text document
            TextDocument document = new TextDocument();

            document.New();
            //Create a standard paragraph using the ParagraphBuilder
            Paragraph paragraph = ParagraphBuilder.CreateStandardTextParagraph(document);

            //Add some simple text
            paragraph.TextContent.Add(new SimpleText(document, "Some simple text!"));
            //Add the paragraph to the document
            document.Content.Add(paragraph);
            //Save empty
            document.SaveTo(fileToPrint);

            //Now print the new document via the OpenOfficeLib
            //Get the Component Context
            XComponentContext xComponentContext = Connector.GetComponentContext();
            //Get a MultiServiceFactory
            XMultiServiceFactory xMultiServiceFactory = Connector.GetMultiServiceFactory(xComponentContext);
            //Get a Dektop instance
            XDesktop xDesktop = Connector.GetDesktop(xMultiServiceFactory);

            //Convert a windows path to an OpenOffice one
            fileToPrint = Component.PathConverter(fileToPrint);
            //Load the document you want to print
            XComponent xComponent = Component.LoadDocument(
                (XComponentLoader)xDesktop, fileToPrint, "_blank");

            //Print the XComponent
            Printer.Print(xComponent);
        }
コード例 #2
0
        public void terminate()
        {
            XModifiable xMod = (XModifiable)mxDocument;

            if (xMod != null)
            {
                xMod.setModified(false);
            }
            XDesktop aDesktop = (XDesktop)
                                mxMSFactory.createInstance("com.sun.star.frame.Desktop");

            if (aDesktop != null)
            {
                try
                {
                    aDesktop.terminate();
                }
                catch (DisposedException d)
                {
                    //This exception may be thrown because shutting down OOo using
                    //XDesktop terminate does not really work. In the case of the
                    //Exception OOo will still terminate.
                }
            }
        }
コード例 #3
0
 /// <summary>
 /// Führt anwendungsspezifische Aufgaben durch, die mit der Freigabe, der Zurückgabe oder dem Zurücksetzen von nicht verwalteten Ressourcen zusammenhängen.
 /// </summary>
 public void Dispose()
 {
     serach = false;
     if (serachThread != null)
     {
         serachThread.Abort();
     }
     _desktopChilds = null;
     _xCc           = null;
     _xDesktop      = null;
     _xMcf          = null;
 }
コード例 #4
0
        private void searchForDocs()
        {
            while (serach)
            {
                try
                {
                    if (XDesktop != null)
                    {
                        XEnumerationAccess xEnumerationAccess = XDesktop.getComponents();
                        XEnumeration       enummeraration     = xEnumerationAccess.createEnumeration();

                        var _uids = DesktopDocumentComponents.Keys;

                        while (enummeraration.hasMoreElements())
                        {
                            Any        anyelemet = enummeraration.nextElement();
                            XComponent element   = anyelemet.Value as XComponent;
                            if (element != null)
                            {
                                //FIXME: for debugging
                                //System.Diagnostics.Debug.WriteLine("Window from Desktop found _________________");
                                //Debug.GetAllInterfacesOfObject(element);
                                //System.Diagnostics.Debug.WriteLine("\tProperties _________________");
                                //Debug.GetAllProperties(element);
                                XPropertySet ps = element as XPropertySet;
                                if (ps != null)
                                {
                                    var uid = OoUtils.GetStringProperty(ps, "RuntimeUID");
                                    if (uid != null && !uid.Equals(""))
                                    {
                                        if (!DesktopDocumentComponents.ContainsKey(uid))
                                        {
                                            //FIXME: for fixing
                                            Console.WriteLine("Found new Desktop child with uid:" + uid);
                                            DesktopDocumentComponents.Add(uid, element);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                catch (DisposedException dex) {
                    this.Dispose();
                    throw dex;
                }
                catch (System.Exception) { }


                //Console.WriteLine("\t\tSearch for Docs");
                Thread.Sleep(WAIT_TIME);
            }
        }
コード例 #5
0
        void PerformLoad()
        {
            // Start LibreOffice and load file
            unoidl.com.sun.star.uno.XComponentContext     localContext        = uno.util.Bootstrap.bootstrap();
            unoidl.com.sun.star.lang.XMultiServiceFactory multiServiceFactory = (unoidl.com.sun.star.lang.XMultiServiceFactory)localContext.getServiceManager();
            desktop = (XDesktop)multiServiceFactory.createInstance("com.sun.star.frame.Desktop");
            var componentLoader = (XComponentLoader)desktop;

            component = componentLoader.loadComponentFromURL(CreateFileUrl(file.FullName), "_blank", 0, new PropertyValue[] { });

            // TODO: while/before loading, set the viewsettings ViewId:=view1, PageKind:=0 to reset to the default view
            // (instead of notes or outline view). Unfortunately these settings aren't accesible in the API ...

            // Get the main window's handle and hide the window
            document = (XModel)component;
            XWindow window = document.getCurrentController().getFrame().getContainerWindow();

            window.setVisible(false);
            XSystemDependentWindowPeer xWindowPeer = (XSystemDependentWindowPeer)(window);

            mainHandle = new IntPtr((int)xWindowPeer.getWindowHandle(new byte[] { }, SystemDependent.SYSTEM_WIN32).Value);
            //ShowWindow(mainHandle, 0);

            presentation = (XPresentation2)((XPresentationSupplier)component).getPresentation();

            CreateThumbnails();

            listener.SlideTransitionStarted += (sender, args) =>
            {
                OnSlideIndexChanged();
            };

            Start();
            controller.gotoSlideIndex(0);

            LoadPreviewProvider();

            base.OnLoaded(true);
        }
コード例 #6
0
        void PerformLoad()
        {
            // Start LibreOffice and load file
            unoidl.com.sun.star.uno.XComponentContext localContext = uno.util.Bootstrap.bootstrap();
            unoidl.com.sun.star.lang.XMultiServiceFactory multiServiceFactory = (unoidl.com.sun.star.lang.XMultiServiceFactory)localContext.getServiceManager();
            desktop = (XDesktop)multiServiceFactory.createInstance("com.sun.star.frame.Desktop");
            var componentLoader = (XComponentLoader)desktop;
            component = componentLoader.loadComponentFromURL(CreateFileUrl(file.FullName), "_blank", 0, new PropertyValue[] { });

            // TODO: while/before loading, set the viewsettings ViewId:=view1, PageKind:=0 to reset to the default view
            // (instead of notes or outline view). Unfortunately these settings aren't accesible in the API ...

            // Get the main window's handle and hide the window
            document = (XModel)component;
            XWindow window = document.getCurrentController().getFrame().getContainerWindow();
            window.setVisible(false);
            XSystemDependentWindowPeer xWindowPeer = (XSystemDependentWindowPeer)(window);
            mainHandle = new IntPtr((int)xWindowPeer.getWindowHandle(new byte[] { }, SystemDependent.SYSTEM_WIN32).Value);
            //ShowWindow(mainHandle, 0);

            presentation = (XPresentation2)((XPresentationSupplier)component).getPresentation();

            CreateThumbnails();

            listener.SlideTransitionStarted += (sender, args) =>
            {
                OnSlideIndexChanged();
            };

            Start();
            controller.gotoSlideIndex(0);

            LoadPreviewProvider();

            base.OnLoaded(true);
        }
コード例 #7
0
ファイル: OOUtils.cs プロジェクト: PeletonSoft/Orders
 public static void CloseDesktop(XDesktop XDesktop)
 {
     if (!XDesktop.getComponents().createEnumeration().hasMoreElements())
         XDesktop.terminate();
 }
コード例 #8
0
 /// <summary>
 /// Führt anwendungsspezifische Aufgaben durch, die mit der Freigabe, der Zurückgabe oder dem Zurücksetzen von nicht verwalteten Ressourcen zusammenhängen.
 /// </summary>
 public void Dispose()
 {
     serach = false;
     if (serachThread != null)
         serachThread.Abort();
     _desktopChilds = null;
     _xCc = null;
     _xDesktop = null;
     _xMcf = null;
 }
コード例 #9
0
        static void Main(string[] args)
        {
            Socket
                s = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP);

            string
                sUnoIni = "file:///c:/OpenOffice.org%203/URE/bin/uno.ini";

            XComponentContext
            //xLocalContext = uno.util.Bootstrap.defaultBootstrap_InitialComponentContext(sUnoIni, null);
                xLocalContext = uno.util.Bootstrap.defaultBootstrap_InitialComponentContext();

            XMultiComponentFactory
                xLocalServiceManager = xLocalContext.getServiceManager();

            XUnoUrlResolver
                xUrlResolver = (XUnoUrlResolver)xLocalServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", xLocalContext);

            XMultiServiceFactory
                xRemoteServiceManager = (XMultiServiceFactory)xUrlResolver.resolve("uno:socket,host=localhost,port=8100;urp;StarOffice.ServiceManager");

            XDesktop
                Desktop = (XDesktop)xRemoteServiceManager.createInstance("com.sun.star.frame.Desktop");

            /*
             * XDesktop
             *      remoteDesktop = (XDesktop)xRemoteServiceManager.createInstance("com.sun.star.frame.Desktop");
             *
             * XComponentLoader
             *      Desktop = (XComponentLoader)remoteDesktop; // (XComponentLoader)multiServiceFactory.createInstance("com.sun.star.frame.Desktop");
             *
             * XComponent
             *      Document = Desktop.loadComponentFromURL("private:factory/swriter", "_blank", 0, new unoidl.com.sun.star.beans.PropertyValue[0]);
             *
             * XText
             *      Text = ((XTextDocument)Document).getText();
             *
             * Text.setString("Hello I'm the first text!");
             *
             * XTextCursor
             *      Cursor = Text.createTextCursor();
             *
             * Text.insertString(Cursor, "Line# 1\n", false);
             * Text.insertString(Cursor, "Line# 2", false);
             *
             * XTextTable
             *      Table;
             *
             * if ((Table = (XTextTable)multiServiceFactory.createInstance("com.sun.star.text.TextTable")) != null)
             * {
             *      Table.initialize(2, 2);
             *      Text.insertTextContent(Text.getEnd(), Table, false);
             * }
             *
             *
             * unoidl.com.sun.star.beans.PropertyValue[]
             *      Params = new unoidl.com.sun.star.beans.PropertyValue[2];
             *
             * unoidl.com.sun.star.beans.PropertyValue
             *      Param = new unoidl.com.sun.star.beans.PropertyValue();
             *
             * Param.Name = "FilterName";
             * Param.Value = new uno.Any("writer_pdf_Export");
             * Params[0] = Param;
             *
             * Param = new unoidl.com.sun.star.beans.PropertyValue();
             * Param.Name = "CompressionMode";
             * Param.Value = new uno.Any("1");
             * Params[1] = Param;
             *
             * string
             *      CurrentDirectory = System.IO.Directory.GetCurrentDirectory(),
             *      DocumentDestName;
             *
             * CurrentDirectory = CurrentDirectory.Substring(0, CurrentDirectory.LastIndexOf("bin", CurrentDirectory.Length - 1));
             *
             * if (File.Exists(DocumentDestName = (CurrentDirectory + "test_out.pdf")))
             *      File.Delete(DocumentDestName);
             *
             * DocumentDestName = DocumentDestName.Replace(Path.DirectorySeparatorChar, '/').Replace("#", "%23");
             *
             * ((XStorable)Document).storeToURL("file:///" + DocumentDestName, Params);
             */
        }
コード例 #10
0
        /// <summary>
        /// Try to get all available XDrawPagesSuppliers.
        /// </summary>
        /// <param name="xDesktop">The XDesktop.</param>
        /// <returns>A list of all available XDrawPagesSupplier</returns>
        public static List<XDrawPagesSupplier> GetDrawPageSuppliers(XDesktop xDesktop)
        {
            //lock (_dpsLock)
            {
                var dpsList = new List<XDrawPagesSupplier>();
                //cause by OpenOffice Version 3
                if (xDesktop == null)
                {
                    return dpsList;
                }

                XEnumeration enummeraration = null;

                TimeLimitExecutor.WaitForExecuteWithTimeLimit(200, () =>
                {
                    try
                    {
                        XEnumerationAccess xEnumerationAccess = xDesktop.getComponents();
                        enummeraration = xEnumerationAccess.createEnumeration();
                    }
                    catch { }
                }, "GetOjectsFromDesktop");

                while (enummeraration != null && enummeraration.hasMoreElements())
                {
                    Any anyelemet = enummeraration.nextElement();
                    XComponent element = (XComponent)anyelemet.Value;

                    if (element is XDrawPagesSupplier)
                    {
                        dpsList.Add(element as XDrawPagesSupplier);

                        XModel model = element as XModel;
                        if (model != null)
                        {
                            int i = 0;
                            //model.lockControllers();
                            try
                            {
                                while (!TimeLimitExecutor.WaitForExecuteWithTimeLimit
                                    (1000,
                                        () =>
                                        {
                                            var controller = model.getCurrentController();
                                            if (controller != null && controller is XSelectionSupplier)
                                            {
                                                tud.mci.tangram.controller.OoSelectionObserver.Instance.RegisterListenerToElement(controller);
                                                //try { ((XSelectionSupplier)controller).removeSelectionChangeListener(tud.mci.tangram.controller.OoSelectionObserver.Instance); }
                                                //catch { }
                                                //try { ((XSelectionSupplier)controller).addSelectionChangeListener(tud.mci.tangram.controller.OoSelectionObserver.Instance); }
                                                //catch
                                                //{
                                                //    try { ((XSelectionSupplier)controller).addSelectionChangeListener(tud.mci.tangram.controller.OoSelectionObserver.Instance); }
                                                //    catch { }
                                                //}
                                            }
                                        },
                                        "AddSelectionListenerToDrawPagesSupplier"
                                    )
                                    && i++ < 5) { Thread.Sleep(100); }
                            }
                            catch (System.Exception ex)
                            {
                                Logger.Instance.Log(LogPriority.DEBUG, "OoDrawUtils", "[ERROR] Can't add Selection listener to draw pages supplier: " + ex);
                            }
                            //model.unlockControllers();

                        }
                    }
                }
                return dpsList;
            }
        }
コード例 #11
0
        /// <summary>
        /// Resets this instance. And kills the OpenOffice process. 
        /// BE CAREFULL!!
        /// </summary>
        static void reset()
        {
            Logger.Instance.Log(LogPriority.OFTEN, "OO", "Request for OpenOffice connection reset");
            try
            {
                _context = null;
                kill();
                _xMcf = null;
                _xDesktop = null;
                _xToolkit = null;
               // _xMsf = null;
                _xDesktop = GetDesktop();

                addListener(GetContext());

            }
            catch (System.Exception){ }
        }
コード例 #12
0
        /// <summary>
        /// Gets the desktop.
        /// </summary>
        /// <param name="xMcf">The x MCF.</param>
        /// <param name="xContext">The x context.</param>
        /// <returns></returns>
        public static XDesktop GetDesktop(XMultiComponentFactory xMcf = null, XComponentContext xContext = null)
        {
            if (_xDesktop == null)
            {
                if (xContext == null)
                    xContext = GetContext();

                if (xMcf == null)
                    xMcf = GetMultiComponentFactory(xContext);
                if (xMcf != null)
                {
                    try
                    {
                        object oDesktop = xMcf.createInstanceWithContext(Services.FRAME_DESKTOP, xContext);
                        _xDesktop = oDesktop as XDesktop;
                        addListener(_xDesktop);

                    }
                    catch (Exception e)
                    {
                        System.Diagnostics.Debug.WriteLine("Can't create xDesktop: " + e);
                    }
                }
            }
            return _xDesktop;
        }