Пример #1
0
        public virtual void Connect()
        {
            Logger.Debug("connecting");
            try
            {
                EnvUtils.InitUno();
                SocketUtils.Connect();
                //var sock = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP);
                XComponentContext localContext = Bootstrap.bootstrap();
                //XComponentContext localContext = Bootstrap.defaultBootstrap_InitialComponentContext();
                XMultiComponentFactory localServiceManager = localContext.getServiceManager();
                XConnector             connector           = (XConnector)localServiceManager.createInstanceWithContext("com.sun.star.connection.Connector", localContext);
                XConnection            connection          = connector.connect(_connectionString);
                XBridgeFactory         bridgeFactory       = (XBridgeFactory)localServiceManager.createInstanceWithContext("com.sun.star.bridge.BridgeFactory", localContext);
                _bridge          = bridgeFactory.createBridge("", "urp", connection, null);
                _bridgeComponent = (XComponent)_bridge;
                _bridgeComponent.addEventListener(this);
                _serviceManager = (XMultiComponentFactory)_bridge.getInstance("StarOffice.ServiceManager");
                XPropertySet properties = (XPropertySet)_serviceManager;
                // Get the default context from the office server.
                var oDefaultContext = properties.getPropertyValue("DefaultContext");

                _componentContext = (XComponentContext)oDefaultContext.Value;
                _connected        = true;
                Logger.Info("connected");
            }
            catch (NoConnectException connectException)
            {
                throw new OpenOfficeException("connection failed: " + _connectionString + ": " + connectException.Message);
            }
            catch (Exception exception)
            {
                throw new OpenOfficeException("connection failed: " + _connectionString, exception);
            }
        }
 /// <summary>
 /// Try to get all available XDrawPagesSuppliers.
 /// </summary>
 /// <param name="factory">The XMultiComponentFactory.</param>
 /// <param name="xContext">The XComponentContext.</param>
 /// <returns>A list of all available XDrawPagesSupplier</returns>
 public static List<XDrawPagesSupplier> GetDrawPageSuppliers(XMultiComponentFactory factory, XComponentContext xContext)
 {
     //lock (_dpsLock)
     {
         return GetDrawPageSuppliers(OO.GetDesktop(factory, xContext));
     }
 }
        /// <summary>
        /// News the doc component.
        /// </summary>
        /// <param name="docType">Type of the doc.</param>
        /// <param name="xMsFactory"> </param>
        /// <param name="xContext"> </param>
        /// <returns></returns>
        public static XComponent OpenNewDocumentComponent(String docType, XComponentContext xContext = null, XMultiComponentFactory xMsFactory = null)
        {
            try
            {
                if (xContext == null)
                {
                    xContext = OO.GetContext();
                }

                if (xMsFactory == null)
                {
                    xMsFactory = OO.GetMultiComponentFactory(xContext);
                }

                var desktop = xMsFactory.createInstanceWithContext(OO.Services.FRAME_DESKTOP, xContext);
                var mxCompLoader = desktop as XComponentLoader;

                String loadUrl = OO.DocTypes.DOC_TYPE_BASE + docType;
                var loadProps = new unoidl.com.sun.star.beans.PropertyValue[0];
                if (mxCompLoader != null) 
                    return mxCompLoader.loadComponentFromURL(loadUrl, "_blank", 0, loadProps);
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Desktop to XComponentLoader cast Exeption: " + ex);
            }
            return null;
        }
 /// <summary>
 /// Try to get all available XDrawPagesSuppliers.
 /// </summary>
 /// <param name="factory">The XMultiComponentFactory.</param>
 /// <returns>A list of all available XDrawPagesSupplier</returns>
 public static List<XDrawPagesSupplier> GetDrawPageSuppliers(XMultiComponentFactory factory)
 {
     //lock (_dpsLock)
     {
         return GetDrawPageSuppliers(factory, OO.GetContext());
     }
 }
 protected MenueBase(XComponentContext xContext, XMultiComponentFactory xMcf, XTopWindow xWindow, XMenuListener xMListener, XMenuBar xMenuBar = null)
 {
     _xContext = xContext;
     _xMCF = xMcf;
     _xWindow = xWindow;
     _xMenuListener = xMListener;
     _xMenuBar = xMenuBar != null ? xMenuBar : AddMenuBar();
 }
 protected MenueBase(XComponentContext xContext, XMultiComponentFactory xMcf, XTopWindow xWindow, XMenuListener xMListener, XMenuBar xMenuBar = null)
 {
     _xContext      = xContext;
     _xMCF          = xMcf;
     _xWindow       = xWindow;
     _xMenuListener = xMListener;
     _xMenuBar      = xMenuBar != null ? xMenuBar : AddMenuBar();
 }
    private static void ConvertToPDF(string serverHost, int serverPort, Uri inputFile, Uri outputFile)
    {
        // FIX: Workaround for a known bug: XUnoUrlResolver forgets to call WSAStartup. We can use dummy Socket for that:
        using (var dummySocket = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP))
        {
            // First, initialize local service manager (IoC container of some kind):
            XComponentContext      componentContext    = Bootstrap.bootstrap();
            XMultiComponentFactory localServiceManager = componentContext.getServiceManager();
            XUnoUrlResolver        urlResolver         = (XUnoUrlResolver)localServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", componentContext);

            // Connect to LibreOffice server
            // URL format explained here: https://wiki.openoffice.org/wiki/Documentation/DevGuide/ProUNO/Starting_OpenOffice.org_in_Listening_Mode
            string connectionString = string.Format("uno:socket,host={0},port={1};urp;StarOffice.ComponentContext", serverHost, serverPort);
            object initialObject    = urlResolver.resolve(connectionString);

            // Retrieve remote service manager:
            XComponentContext      remoteContext          = (XComponentContext)initialObject;
            XMultiComponentFactory remoteComponentFactory = remoteContext.getServiceManager();

            // Request our own instance of LibreOffice Writer from the server:
            object           oDesktop = remoteComponentFactory.createInstanceWithContext("com.sun.star.frame.Desktop", remoteContext);
            XComponentLoader xCLoader = (XComponentLoader)oDesktop;

            var loaderArgs = new PropertyValue[1];
            loaderArgs[0]       = new PropertyValue();
            loaderArgs[0].Name  = "Hidden"; // No GUI
            loaderArgs[0].Value = new Any(true);

            string inputFileUrl = inputFile.AbsoluteUri;

            // WARNING: LibreOffice .NET API uses .NET Remoting and does NOT throw clean and actionable errors,
            //          so, if server crashes or input file is locked or whatever, you will get nulls after casting.
            //          For example, `(XStorable)xCLoader` cast may produce null.
            //          This is counter-intuitive, I know; be more careful in production-grade code and check for nulls after every cast.

            XStorable xStorable = (XStorable)xCLoader.loadComponentFromURL(inputFileUrl, "_blank", 0, loaderArgs);

            var writerArgs = new PropertyValue[2];
            writerArgs[0]       = new PropertyValue();
            writerArgs[0].Name  = "Overwrite"; // Overwrite outputFile if it already exists
            writerArgs[0].Value = new Any(true);
            writerArgs[1]       = new PropertyValue();
            writerArgs[1].Name  = "FilterName";
            writerArgs[1].Value = new Any("writer_pdf_Export");  // Important! This filter is doing all PDF stuff.

            string outputFileUrl = outputFile.AbsoluteUri;

            xStorable.storeToURL(outputFileUrl, writerArgs);

            XCloseable xCloseable = (XCloseable)xStorable;
            if (xCloseable != null)
            {
                xCloseable.close(false);
            }
        }
    }
 /// <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;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="DocumentListener"/> class.
 /// </summary>
 /// <param name="xMcf">The XMultiComponentFactory.</param>
 public DocumentListener(XMultiComponentFactory xMcf = null)
 {
     XMcf = xMcf;
     if (XDesktop != null)
     {
         var xF = XDesktop as XFrame;
         if (xF != null)
         {
             xF.addFrameActionListener(this);
         }
     }
 }
Пример #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ToolBar"/> class.
        /// </summary>
        /// <param name="xMsf">the XMultiComponentFactory.</param>
        /// <param name="name">The UIName Parameter of the ToolBar.</param>
        /// <param name="documentModluleIdentifier">The document modlule identifier for the ToolBar.
        /// E.g. "com.sun.star.text.TextDocument" to add the ToolBar to all text documents</param>
        public ToolBar(string name, string documentModluleIdentifier, XMultiComponentFactory xMsf = null)
        {
            if (name.Trim().Length < 1)
            {
                throw new NullReferenceException("Name for ToolBar creation is empty");
            }

            XMcf        = xMsf ?? OO.GetMultiComponentFactory();
            Name        = name;
            RecourceUrl = GetToolBarUrl(name);

            // Retrieve the module configuration manager supplier to  get
            // the configuration setting from the module
            _xModCfgMgrSupplier =
                (XModuleUIConfigurationManagerSupplier)
                XMcf.createInstanceWithContext(OO.Services.UI_MOD_UI_CONF_MGR_SUPPLIER, OO.GetContext());

            // Retrieve the module configuration manager
            XCfgMgr =
                _xModCfgMgrSupplier.getUIConfigurationManager(documentModluleIdentifier);

            if (XCfgMgr.hasSettings(RecourceUrl) == false)
            {
                // Creates a copy of the user interface configuration manager
                Settings = XCfgMgr.createSettings();

                // Defines the name of the toolbar
                var xToolbarProperties = (XPropertySet)Settings;
                xToolbarProperties.setPropertyValue("UIName", Any.Get(name));

                // Makes the toolbar to the UI manager available
                try
                {
                    XCfgMgr.insertSettings(RecourceUrl, Settings);
                }
                catch (ElementExistException)
                {
                    Settings = XCfgMgr.getSettings(RecourceUrl, true) as XIndexContainer;
                }
            }
            else
            {
                Settings = XCfgMgr.getSettings(RecourceUrl, true) as XIndexContainer;
            }
        }
        public static XControlContainer createDialog(XMultiComponentFactory xMultiComponentFactory, XComponentContext xContext,
            int posX, int posY, int width, int height, string title
            )
        {
            try
            {
            Object oDialogModel = xMultiComponentFactory.createInstanceWithContext("com.sun.star.awt.UnoControlDialogModel", xContext);

                // The XMultiServiceFactory of the dialog model is needed to instantiate the controls...
                var MXMsfDialogModel = (XMultiServiceFactory)oDialogModel;

                // The named container is used to insert the created controls into...
                var MXDlgModelNameContainer = (XNameContainer)oDialogModel;

                // create the dialog...
                Object oUnoDialog = xMultiComponentFactory.createInstanceWithContext("com.sun.star.awt.UnoControlDialog", xContext);
                var MXDialogControl = (XControl)oUnoDialog;

                // The scope of the control container is public...
                var MXDlgContainer = (XControlContainer)oUnoDialog;

                var MXTopWindow = (XTopWindow)MXDlgContainer;

                // link the dialog and its model...
                XControlModel xControlModel = (XControlModel)oDialogModel;
                MXDialogControl.setModel(xControlModel);
            }
            catch (unoidl.com.sun.star.uno.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("uno.Exception:");
                System.Diagnostics.Debug.WriteLine(ex);
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("System.Exception:");
                System.Diagnostics.Debug.WriteLine(ex);
            }


            //xMultiPropertySet.setPropertyValues(PropertyNames, Any.Get(PropertyValues));

            return null;

        }
        public static XControlContainer createDialog(XMultiComponentFactory xMultiComponentFactory, XComponentContext xContext,
                                                     int posX, int posY, int width, int height, string title
                                                     )
        {
            try
            {
                Object oDialogModel = xMultiComponentFactory.createInstanceWithContext("com.sun.star.awt.UnoControlDialogModel", xContext);

                // The XMultiServiceFactory of the dialog model is needed to instantiate the controls...
                var MXMsfDialogModel = (XMultiServiceFactory)oDialogModel;

                // The named container is used to insert the created controls into...
                var MXDlgModelNameContainer = (XNameContainer)oDialogModel;

                // create the dialog...
                Object oUnoDialog      = xMultiComponentFactory.createInstanceWithContext("com.sun.star.awt.UnoControlDialog", xContext);
                var    MXDialogControl = (XControl)oUnoDialog;

                // The scope of the control container is public...
                var MXDlgContainer = (XControlContainer)oUnoDialog;

                var MXTopWindow = (XTopWindow)MXDlgContainer;

                // link the dialog and its model...
                XControlModel xControlModel = (XControlModel)oDialogModel;
                MXDialogControl.setModel(xControlModel);
            }
            catch (unoidl.com.sun.star.uno.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("uno.Exception:");
                System.Diagnostics.Debug.WriteLine(ex);
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("System.Exception:");
                System.Diagnostics.Debug.WriteLine(ex);
            }


            //xMultiPropertySet.setPropertyValues(PropertyNames, Any.Get(PropertyValues));

            return(null);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ToolBar"/> class.
        /// </summary>
        /// <param name="xMsf">the XMultiComponentFactory.</param>
        /// <param name="name">The UIName Parameter of the ToolBar.</param>
        /// <param name="documentModluleIdentifier">The document modlule identifier for the ToolBar. 
        /// E.g. "com.sun.star.text.TextDocument" to add the ToolBar to all text documents</param>
        public ToolBar(string name, string documentModluleIdentifier, XMultiComponentFactory xMsf = null)
        {
            if (name.Trim().Length < 1)
                throw new NullReferenceException("Name for ToolBar creation is empty");

            XMcf = xMsf ?? OO.GetMultiComponentFactory();
            Name = name;
            RecourceUrl = GetToolBarUrl(name);

            // Retrieve the module configuration manager supplier to  get
            // the configuration setting from the module
            _xModCfgMgrSupplier =
                (XModuleUIConfigurationManagerSupplier)
                XMcf.createInstanceWithContext(OO.Services.UI_MOD_UI_CONF_MGR_SUPPLIER, OO.GetContext());

            // Retrieve the module configuration manager
            XCfgMgr =
                _xModCfgMgrSupplier.getUIConfigurationManager(documentModluleIdentifier);

            if (XCfgMgr.hasSettings(RecourceUrl) == false)
            {
                // Creates a copy of the user interface configuration manager
                Settings = XCfgMgr.createSettings();

                // Defines the name of the toolbar 
                var xToolbarProperties = (XPropertySet)Settings;
                xToolbarProperties.setPropertyValue("UIName", Any.Get(name));

                // Makes the toolbar to the UI manager available
                try
                {
                    XCfgMgr.insertSettings(RecourceUrl, Settings);
                }
                catch (ElementExistException)
                {
                    Settings = XCfgMgr.getSettings(RecourceUrl, true) as XIndexContainer;
                }
            }
            else
            {
                Settings = XCfgMgr.getSettings(RecourceUrl, true) as XIndexContainer;
            }
        }
Пример #14
0
        private bool VerifyRedirectParameter(ref XTextGraphicObjectsSupplier comp, string imageName)
        {
            logger.Debug("VerifyRedirectParameter");
            // Get old image
            Object       xImageObject = comp.getGraphicObjects().getByName(imageName).Value;
            XTextContent xImage       = (XTextContent)xImageObject;

            // Get property set object of the existing image (XContent)
            //  We will use this property set object to set the new Graphic property of the old image
            // to be the new image stream
            XPropertySet xPropSet = (XPropertySet)xImage;
            // Get XMCF to create a graphic provider component
            XMultiComponentFactory xMCF = localContext.getServiceManager();

            // Assign the new graphic image to existent page object
            //xPropSet.setPropertyValue("Graphic", new uno.Any(typeof(UNOIDL.graphic.XGraphic), xNewGraphic));
            //var crop = (UNOIDL.container.XIndexContainer) xPropSet.getPropertyValue("ImageMap").Value;
            var  size        = (Size)xPropSet.getPropertyValue("ActualSize").Value;
            var  url         = xPropSet.getPropertyValue("GraphicURL").Value as string;
            bool elementFind = false;

            if (ConfigurationManager.AppSettings["RedirectSizeFilter"] != null && size != null)
            {
                var sizeFilter      = ConfigurationManager.AppSettings["RedirectSizeFilter"].ToString().Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                var arrOfSizeFilter = sizeFilter.Select(p => new { Width = int.Parse(p.Split(',')[0]), Height = int.Parse(p.Split(',')[1]) });
                if (arrOfSizeFilter.Count() > 0)
                {
                    elementFind = arrOfSizeFilter.Any(x => x.Width == size.Width && x.Height == size.Height);
                }
            }
            if (ConfigurationManager.AppSettings["RedirectUrlFilter"] != null && size != null)
            {
                var urlFilter = ConfigurationManager.AppSettings["RedirectUrlFilter"].ToString().Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                if (urlFilter.Count() > 0)
                {
                    elementFind = urlFilter.Contains(url);
                }
            }
            return(elementFind);
        }
        /// <summary>
        /// Creates the dialog model and container.
        /// Variables MXMsfDialogModel, MXDlgModelNameContainer, MXDialogControl, MXDlgContainer and MXTopWindow are created.
        /// Properties: Height, Name, PositionX, PositionY, Step, TabIndex, Tag, Width, BackgroundColor, Closeable, Enabled, FontDescriptor, FontEmphasisMark, FontRelief, HelpText, HelpURL, Moveable, Sizeable, TextColor, TextLineColor, Title
        /// </summary>
        /// <param name="XMcf">The XMultiComponentFactory to use.</param>
        protected virtual void CreateDialog(XMultiComponentFactory XMcf)
        {
            try
            {
                Object oDialogModel = XMcf.createInstanceWithContext(OO.Services.AWT_CONTROL_DIALOG_MODEL, MXContext);

                // The XMultiServiceFactory of the dialog model is needed to instantiate the controls...
                MXMsfDialogModel = (XMultiServiceFactory)oDialogModel;

                // The named container is used to insert the created controls into...
                MXDlgModelNameContainer = (XNameContainer)oDialogModel;

                // create the dialog...
                Object oUnoDialog = XMcf.createInstanceWithContext(OO.Services.AWT_CONTROL_DIALOG, MXContext);
                MXDialogControl = (XControl)oUnoDialog;

                // The scope of the control container is public...
                MXDlgContainer = (XControlContainer)oUnoDialog;

                MXTopWindow = (XTopWindow)MXDlgContainer;

                // link the dialog and its model...
                XControlModel xControlModel = (XControlModel)oDialogModel;
                MXDialogControl.setModel(xControlModel);
            }
            catch (unoidl.com.sun.star.uno.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("uno.Exception:");
                System.Diagnostics.Debug.WriteLine(ex);
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("System.Exception:");
                System.Diagnostics.Debug.WriteLine(ex);
            }
        }
Пример #16
0
 public WriterDocument(XTextDocument xTextDocument, XComponentContext xContext = null, XMultiComponentFactory xMcFactory = null)
 {
     this.xContext   = xContext;
     this.xMcFactory = xMcFactory;
     doc             = xTextDocument;
 }
Пример #17
0
 public WriterDocument(XComponentContext xContext = null, XMultiComponentFactory xMcFactory = null)
 {
     this.xContext   = xContext;
     this.xMcFactory = xMcFactory;
     doc             = OOoDocument.OpenNewDocumentComponent(OO.DocTypes.SWRITER, xContext, xMcFactory);
 }
 public WriterDocument(XTextDocument xTextDocument, XComponentContext xContext = null, XMultiComponentFactory xMcFactory = null)
 {
     this.xContext = xContext;
     this.xMcFactory = xMcFactory;
     doc = xTextDocument;
 }
 public WriterDocument(XComponentContext xContext = null, XMultiComponentFactory xMcFactory = null)
 {
     this.xContext = xContext;
     this.xMcFactory = xMcFactory;
     doc = OOoDocument.OpenNewDocumentComponent(OO.DocTypes.SWRITER, xContext, xMcFactory);
 }
        // use MultiService factory

        public ScrollableContainer(XControlContainer parent, XNameContainer nameContainer, XComponentContext context = null, XMultiComponentFactory parentMCF = null)
        {
            MXDlgModelNameContainer = nameContainer;
            if (context != null) MXContext = context;
            parentCnt = parent;
            this.parentMCF = parentMCF;
        }
        /// <summary>
        /// Gets the ExtendedToolkit.
        /// </summary>
        /// <param name="xMcf">The ServiceManager.</param>
        /// <param name="xContext">The context.</param>
        /// <returns></returns>
        public static XExtendedToolkit GetExtTooklkit(XMultiComponentFactory xMcf = null,
                                                      XComponentContext xContext = null)
        {
            if (_xToolkit == null)
            {
                Logger.Instance.Log(LogPriority.DEBUG, "Oo.BasicObjects", "renew XExtendedToolkit");
                try
                {
                    if (xContext == null)
                    {
                        xContext = GetContext();
                    }

                    if (xMcf == null)
                    {
                        xMcf = GetMultiComponentFactory(xContext);
                    }

                    object toolkit = xMcf.createInstanceWithContext(Services.VCLX_EXT_TOOLKIT, xContext);
                    _xToolkit = toolkit as XExtendedToolkit;
                    addListener(_xToolkit);

                }
                catch (Exception ex)
                {
                    Logger.Instance.Log(LogPriority.ALWAYS, "Can't create ExtendedToolkit ", ex);
                    return null;
                }
            }
            return _xToolkit;
        }
Пример #22
0
        /// <summary>
        /// News the doc component.
        /// </summary>
        /// <param name="docType">Type of the doc.</param>
        /// <param name="xMsFactory"> </param>
        /// <param name="xContext"> </param>
        /// <returns></returns>
        public static XComponent OpenNewDocumentComponent(String docType, XComponentContext xContext = null, XMultiComponentFactory xMsFactory = null)
        {
            try
            {
                if (xContext == null)
                {
                    xContext = OO.GetContext();
                }

                if (xMsFactory == null)
                {
                    xMsFactory = OO.GetMultiComponentFactory(xContext);
                }

                var desktop      = xMsFactory.createInstanceWithContext(OO.Services.FRAME_DESKTOP, xContext);
                var mxCompLoader = desktop as XComponentLoader;

                String loadUrl   = OO.DocTypes.DOC_TYPE_BASE + docType;
                var    loadProps = new unoidl.com.sun.star.beans.PropertyValue[0];
                if (mxCompLoader != null)
                {
                    return(mxCompLoader.loadComponentFromURL(loadUrl, "_blank", 0, loadProps));
                }
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Desktop to XComponentLoader cast Exeption: " + ex);
            }
            return(null);
        }
        /// <summary>
        /// Gets the multi service factory.
        /// DEPRECATED: for libre office this is always <c>NULL</c>. Use <see cref="XMultiComponentFactory"/> instead.
        /// </summary>
        /// <param name="xCompContext">The x comp context.</param>
        /// <param name="xMcf">The x MCF.</param>
        /// <returns></returns>
        public static XMultiServiceFactory GetMultiServiceFactory(XComponentContext xCompContext = null,
                                                                  XMultiComponentFactory xMcf = null)
        {
            if (_xMsf == null)
            {
                if (xCompContext == null)
                {
                    xCompContext = GetContext();
                }
                if (xMcf == null)
                {
                    xMcf = GetMultiComponentFactory(xCompContext);
                }

                if (_xMsf == null)
                {
                    if (xCompContext != null && xCompContext is XComponentContext)
                    {
                        _xMsf = ((XComponentContext)xCompContext).getServiceManager() as XMultiServiceFactory;
                    }
                }

                if (_xMsf == null) {
                    _xMsf = xMcf.createInstanceWithContext(Services.MULTI_SERVICE_FACTORY, xCompContext) as XMultiServiceFactory;
                }

                addListener(_xMsf);

            }
            return _xMsf;
        }
        /// <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;
        }
Пример #25
0
        // use MultiService factory

        public ScrollableContainer(XControlContainer parent, XNameContainer nameContainer, XComponentContext context = null, XMultiComponentFactory parentMCF = null)
        {
            MXDlgModelNameContainer = nameContainer;
            if (context != null)
            {
                MXContext = context;
            }
            parentCnt      = parent;
            this.parentMCF = parentMCF;
        }
        /// <summary>
        /// Creates the dialog model and container.
        /// Variables MXMsfDialogModel, MXDlgModelNameContainer, MXDialogControl, MXDlgContainer and MXTopWindow are created.
        /// Properties: Height, Name, PositionX, PositionY, Step, TabIndex, Tag, Width, BackgroundColor, Closeable, Enabled, FontDescriptor, FontEmphasisMark, FontRelief, HelpText, HelpURL, Moveable, Sizeable, TextColor, TextLineColor, Title
        /// </summary>
        /// <param name="XMcf">The XMultiComponentFactory to use.</param>
        protected virtual void CreateDialog(XMultiComponentFactory XMcf)
        {
            try
            {
                Object oDialogModel = XMcf.createInstanceWithContext(OO.Services.AWT_CONTROL_DIALOG_MODEL, MXContext);

                // The XMultiServiceFactory of the dialog model is needed to instantiate the controls...
                MXMsfDialogModel = (XMultiServiceFactory)oDialogModel;

                // The named container is used to insert the created controls into...
                MXDlgModelNameContainer = (XNameContainer)oDialogModel;

                // create the dialog...
                Object oUnoDialog = XMcf.createInstanceWithContext(OO.Services.AWT_CONTROL_DIALOG, MXContext);
                MXDialogControl = (XControl)oUnoDialog;

                // The scope of the control container is public...
                MXDlgContainer = (XControlContainer)oUnoDialog;

                MXTopWindow = (XTopWindow)MXDlgContainer;

                // link the dialog and its model...
                XControlModel xControlModel = (XControlModel)oDialogModel;
                MXDialogControl.setModel(xControlModel);
            }
            catch (unoidl.com.sun.star.uno.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("uno.Exception:");
                System.Diagnostics.Debug.WriteLine(ex);
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("System.Exception:");
                System.Diagnostics.Debug.WriteLine(ex);
            }
        }
        public static XControlContainer createDialog(XMultiComponentFactory xMultiComponentFactory, XComponentContext xContext,
                                                     int posX, int posY, int width, int height, string title
                                                     )
        {
            //dialog model
            Object oDialogModel = xMultiComponentFactory.createInstanceWithContext(
                "com.sun.star.awt.UnoControlDialogModel", xContext);


            XPropertySet xPSetDialog = (XPropertySet)oDialogModel;

            xPSetDialog.setPropertyValue("PositionX", Any.Get(posX));
            xPSetDialog.setPropertyValue("PositionY", Any.Get(posY));
            xPSetDialog.setPropertyValue("Width", Any.Get(width));
            xPSetDialog.setPropertyValue("Height", Any.Get(height));
            xPSetDialog.setPropertyValue("Title", Any.Get(title));

            // get service manager from  dialog model
            XMultiServiceFactory MXMsfDialogModel = (XMultiServiceFactory)oDialogModel;

            // dialog control model
            Object oUnoDialog = xMultiComponentFactory.createInstanceWithContext(
                "com.sun.star.awt.UnoControlDialog", xContext);


            XControl      MXDialogControl = (XControl)oUnoDialog;
            XControlModel xControlModel   = (XControlModel)oDialogModel;

            MXDialogControl.setModel(xControlModel);



            XToolkit xToolkit = (XToolkit)xMultiComponentFactory
                                .createInstanceWithContext("com.sun.star.awt.Toolkit",
                                                           xContext);

            WindowDescriptor aDescriptor = new WindowDescriptor();

            aDescriptor.Type = WindowClass.TOP;
            aDescriptor.WindowServiceName = "";
            aDescriptor.ParentIndex       = -1;
            aDescriptor.Parent            = xToolkit.getDesktopWindow();
            aDescriptor.Bounds            = new Rectangle(100, 200, 300, 400);

            aDescriptor.WindowAttributes = WindowAttribute.BORDER
                                           | WindowAttribute.MOVEABLE | WindowAttribute.SIZEABLE
                                           | WindowAttribute.CLOSEABLE;

            XWindowPeer xPeer = xToolkit.createWindow(aDescriptor);

            XWindow xWindow = (XWindow)xPeer;

            xWindow.setVisible(false);
            MXDialogControl.createPeer(xToolkit, xPeer);

            // execute the dialog
            XDialog xDialog = (XDialog)oUnoDialog;

            xDialog.execute();

            // dispose the dialog
            XComponent xComponent = (XComponent)oUnoDialog;

            xComponent.dispose();

            return(oUnoDialog as XControlContainer);
        }
Пример #28
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);
             */
        }
        /// <summary>
        /// Gets the Multi Component Factory (ServiceManager).
        /// </summary>
        /// <param name="xContext">The context.</param>
        /// <returns></returns>
        public static XMultiComponentFactory GetMultiComponentFactory(XComponentContext xContext = null, bool renew = false)
        {
            if (_xMcf != null && !renew)
                return _xMcf;
            try
            {
                if (xContext == null)
                {
                    xContext = GetContext();
                }

                if (xContext != null)
                {
                    TimeLimitExecutor.WaitForExecuteWithTimeLimit(300, () =>
                    {
                        _xMcf = xContext.getServiceManager();
                        addListener(_xMcf);
                    }, "GetMultiComponentFactory");

                    return _xMcf;
                }
                else
                {
                    Logger.Instance.Log(LogPriority.DEBUG, "OO","[ERROR] Could not create a XMultiComponentFactory because the XContext is NULL");
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Can't create ServiceManager factory: " + ex);
            }
            return null;
        }
Пример #30
0
        public void CreateScrollableContainer(int _nPosX, int _nPosY, int _nWidth, int _nHeight, String sName)
        {
            try
            {
                // create a unique id by means of an own implementation...
                if (String.IsNullOrWhiteSpace(sName))
                {
                    sName = AbstactUnoDialogBase.createUniqueName(MXDlgModelNameContainer, "SCROLL_CONTAINER");
                }
                else
                {
                    sName = AbstactUnoDialogBase.createUniqueName(MXDlgModelNameContainer, sName);
                }

                //XMultiServiceFactory _xMSF = OO.GetMultiServiceFactory(MXContext);
                XMultiComponentFactory _xMcf = OO.GetMultiComponentFactory(MXContext, true);

                #region Outer Container

                // create a UnoControlContainerModel. A thing which differs from other dialog-controls in many aspects
                // Position and size of the model have no effect, so we apply setPosSize() on it's view later.
                // Unlike a dialog-model the container-model can not have any control-models.
                // As an instance of a dialog-model it can have the property "Step"(among other things),
                // provided by service awt.UnoControlDialogElement, without actually supporting this service!

                // create a control model at the multi service factory of the dialog model...
                outerScrlContrModel = _xMcf.createInstanceWithContext(AWT_UNO_CONTROL_CONTAINER_Model, MXContext) as XControlModel;
                OuterScrlContr      = _xMcf.createInstanceWithContext(AWT_UNO_CONTROL_CONTAINER, MXContext) as XControl;


                if (OuterScrlContr != null && outerScrlContrModel != null)
                {
                    OuterScrlContr.setModel(outerScrlContrModel);
                }

                XMultiPropertySet xoScrlContMPSet = outerScrlContrModel as XMultiPropertySet;

                if (xoScrlContMPSet != null)
                {
                    // Set the properties at the model - keep in mind to pass the property names in alphabetical order!
                    xoScrlContMPSet.setPropertyValues(
                        new String[] { "Height", "Name", "PositionX", "PositionY", "State", "Width" },
                        Any.Get(new Object[] { 0, sName, 0, 0, ((short)0), 0, 0 }));
                }

                //add to the dialog
                XControlContainer xCntrCont = parentCnt as XControlContainer;
                if (xCntrCont != null)
                {
                    xCntrCont.addControl(sName, OuterScrlContr as XControl);
                }

                #endregion

                #region Scroll bars

                //insert scroll bars
                HorizontalScrlBar = insertHorizontalScrollBar(this, _nPosX, _nPosY + _nHeight, _nWidth);
                VerticalScrlBar   = insertVerticalScrollBar(this, _nPosX + _nWidth, _nPosY, _nHeight);

                #endregion

                #region Set Size of outer Container

                //make the outer container pos and size via the pos and size of the scroll bars
                if (HorizontalScrlBar is XWindow)
                {
                    Rectangle hSBPos = ((XWindow)HorizontalScrlBar).getPosSize();
                    _width = hSBPos.Width;
                    _posX  = hSBPos.X;
                }
                if (VerticalScrlBar is XWindow)
                {
                    Rectangle vSBPos = ((XWindow)VerticalScrlBar).getPosSize();
                    _height = vSBPos.Height;
                    _posY   = vSBPos.Y;
                }

                // Set the size of the surrounding container
                if (OuterScrlContr is XWindow)
                {
                    ((XWindow)OuterScrlContr).setPosSize(PosX, PosY, Width, Height, PosSize.POSSIZE);
                    ((XWindow)OuterScrlContr).addMouseListener(this);
                }
                #endregion

                #region inner Container


                // create a control model at the multi service factory of the dialog model...
                innerScrlContrModel = _xMcf.createInstanceWithContext(AWT_UNO_CONTROL_CONTAINER_Model, MXContext) as XControlModel;
                InnerScrlContr      = _xMcf.createInstanceWithContext(AWT_UNO_CONTROL_CONTAINER, MXContext) as XControl;


                if (InnerScrlContr != null && innerScrlContrModel != null)
                {
                    InnerScrlContr.setModel(innerScrlContrModel);
                }

                XMultiPropertySet xinnerScrlContMPSet = innerScrlContrModel as XMultiPropertySet;

                if (xinnerScrlContMPSet != null)
                {
                    xinnerScrlContMPSet.setPropertyValues(
                        new String[] { "Name", "State" },
                        Any.Get(new Object[] { sName + "_S", ((short)0) }));
                }

                //// FIXME: only for fixing

                //util.Debug.GetAllServicesOfObject(parentCnt);

                //Object oDialogModel = OO.GetMultiComponentFactory().createInstanceWithContext(OO.Services.AWT_CONTROL_DIALOG_MODEL, MXContext);

                //// The named container is used to insert the created controls into...
                //MXDlgModelNameContainer = (XNameContainer)oDialogModel;

                //System.Diagnostics.Debug.WriteLine("_________");

                //util.Debug.GetAllServicesOfObject(MXDlgModelNameContainer);

                //// END

                //add inner container to the outer scroll container
                XControlContainer outerCntrCont = OuterScrlContr as XControlContainer;
                if (outerCntrCont != null)
                {
                    outerCntrCont.addControl(sName + "_S", InnerScrlContr as XControl);

                    InnerWidth  = Width;
                    InnerHeight = Height;

                    // Set the size of the surrounding container
                    if (InnerScrlContr is XWindow)
                    {
                        ((XWindow)InnerScrlContr).setPosSize(0, 0, InnerWidth, InnerHeight, PosSize.POSSIZE);
                        ((XWindow)InnerScrlContr).addMouseListener(this);
                    }
                }

                #endregion
            }
            catch (System.Exception) { }
        }
 /// <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;
 }
 public AbstactUnoDialogBase(XComponentContext xContext, XMultiComponentFactory xMcf)
 {
     MXContext = xContext;
     MXMcf     = xMcf;
     CreateDialog();
 }
        public static XControlContainer createDialog(XMultiComponentFactory xMultiComponentFactory, XComponentContext xContext,
            int posX, int posY, int width, int height, string title
            )
        {

            //dialog model
            Object oDialogModel = xMultiComponentFactory.createInstanceWithContext(
                  "com.sun.star.awt.UnoControlDialogModel", xContext);


            XPropertySet xPSetDialog = (XPropertySet)oDialogModel;
            xPSetDialog.setPropertyValue("PositionX", Any.Get(posX));
            xPSetDialog.setPropertyValue("PositionY", Any.Get(posY));
            xPSetDialog.setPropertyValue("Width", Any.Get(width));
            xPSetDialog.setPropertyValue("Height", Any.Get(height));
            xPSetDialog.setPropertyValue("Title", Any.Get(title));

            // get service manager from  dialog model
            XMultiServiceFactory MXMsfDialogModel = (XMultiServiceFactory)oDialogModel;

            // dialog control model
            Object oUnoDialog = xMultiComponentFactory.createInstanceWithContext(
                  "com.sun.star.awt.UnoControlDialog", xContext);


            XControl MXDialogControl = (XControl)oUnoDialog;
            XControlModel xControlModel = (XControlModel)oDialogModel;
            MXDialogControl.setModel(xControlModel);



            XToolkit xToolkit = (XToolkit)xMultiComponentFactory
                        .createInstanceWithContext("com.sun.star.awt.Toolkit",
                             xContext);

            WindowDescriptor aDescriptor = new WindowDescriptor();
            aDescriptor.Type = WindowClass.TOP;
            aDescriptor.WindowServiceName = "";
            aDescriptor.ParentIndex = -1;
            aDescriptor.Parent = xToolkit.getDesktopWindow();
            aDescriptor.Bounds = new Rectangle(100, 200, 300, 400);

            aDescriptor.WindowAttributes = WindowAttribute.BORDER
                  | WindowAttribute.MOVEABLE | WindowAttribute.SIZEABLE
                  | WindowAttribute.CLOSEABLE;

            XWindowPeer xPeer = xToolkit.createWindow(aDescriptor);

            XWindow xWindow = (XWindow)xPeer;
            xWindow.setVisible(false);
            MXDialogControl.createPeer(xToolkit, xPeer);

            // execute the dialog
            XDialog xDialog = (XDialog)oUnoDialog;
            xDialog.execute();

            // dispose the dialog
            XComponent xComponent = (XComponent)oUnoDialog;
            xComponent.dispose();

            return oUnoDialog as XControlContainer;
        }
 public AbstactUnoDialogBase(XComponentContext xContext, XMultiComponentFactory xMcf)
 {
     MXContext = xContext;
     MXMcf = xMcf;
     CreateDialog();
 }
        /// <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){ }
        }
 /// <summary>
 /// Create a new instance of UnoDialogSample
 /// </summary>
 /// <param name="xContext"></param>
 /// <param name="xMcf"></param>
 public UnoDialogSample(XComponentContext xContext, XMultiComponentFactory xMcf)
     : base(xContext, xMcf) { }
 /// <summary>
 /// Initializes a new instance of the <see cref="DocumentListener"/> class.
 /// </summary>
 /// <param name="xMcf">The XMultiComponentFactory.</param>
 public DocumentListener(XMultiComponentFactory xMcf = null)
 {
     XMcf = xMcf;
     if (XDesktop != null)
     {
         var xF = XDesktop as XFrame;
         if (xF != null) { xF.addFrameActionListener(this); }
     }
 }