Exemplo n.º 1
0
        /// <summary>
        /// collects all XShapes of this page and create a ShapeObserer for each one.
        /// </summary>
        private void handleChildren()
        {
            if (_updating)
            {
                return;
            }
            _updating = true;
            try
            {
                if (DrawPage != null)
                {
                    XIndexAccess ia = DrawPage as XIndexAccess;
                    if (ia != null)
                    {
                        int childs = ia.getCount();

                        for (int i = 0; i < childs; i++)
                        {
                            // Attention -> in asynchronous handling the index pointer i can be increased before the
                            // thread was handled. So clone them to make sure that it is not changing while handling!
                            int j = i;
                            handleChild(j, ia);
                        }

                        //FIXME: use this if OpenOffice stops falling into dead lock while using this faster function
                        //Parallel.For(0, ia.getCount(), (i) => { handleChild(i, ref ia); });
                    }
                }
            }
            catch { }
            finally { _updating = false; }
        }
Exemplo n.º 2
0
        protected XDrawPagesSupplier UseDraw()
        {
            try
            {
                //create new draw document and insert rectangle shape
                XComponent         xDrawComponent     = NewDocComponent("sdraw");
                XDrawPagesSupplier xDrawPagesSupplier = xDrawComponent as XDrawPagesSupplier;

                Object       drawPages         = xDrawPagesSupplier.getDrawPages();
                XIndexAccess xIndexedDrawPages = drawPages as XIndexAccess;

                Object drawPage = xIndexedDrawPages.getByIndex(0).Value;

                System.Diagnostics.Debug.WriteLine(xIndexedDrawPages.getCount());

                if (drawPage is XDrawPage)
                {
                    XDrawPage xDrawPage = (XDrawPage)drawPage;

                    if (xDrawPage is XComponent)
                    {
                        (xDrawPage as XComponent).addEventListener(new TestOOoEventListerner());
                    }

                    // get internal service factory of the document
                    XMultiServiceFactory xDrawFactory = xDrawComponent as XMultiServiceFactory;

                    Object drawShape = xDrawFactory.createInstance(
                        "com.sun.star.drawing.RectangleShape");
                    XShape xDrawShape = drawShape as XShape;
                    xDrawShape.setSize(new Size(10000, 20000));
                    xDrawShape.setPosition(new Point(5000, 5000));
                    xDrawPage.add(xDrawShape);

                    // XText xShapeText = (XText)drawShape // COMMENTED BY CODEIT.RIGHT;
                    XPropertySet xShapeProps = (XPropertySet)drawShape;

                    // wrap text inside shape
                    xShapeProps.setPropertyValue("TextContourFrame", new uno.Any(true));
                    return(xDrawPagesSupplier);
                }
                else
                {
                    //TODO: handle if no drwapage was found
                    System.Diagnostics.Debug.WriteLine("no XDrawPage found");
                    System.Diagnostics.Debug.WriteLine(drawPage);
                }
            }
            catch (unoidl.com.sun.star.lang.DisposedException e)
            { //works from Patch 1
                MXContext = null;
                throw e;
            }

            return(null);
        }
Exemplo n.º 3
0
        public Worksheet this[int idx]
        {
            get
            {
                XIndexAccess xsheetsIA = (XIndexAccess)Peer;

                if (idx >= xsheetsIA.getCount())
                {
                    throw new IndexOutOfRangeException();
                }

                return(new Worksheet(owner, (XSpreadsheet)xsheetsIA.getByIndex(idx).Value));
            }
        }
        private IList <T> GetAllObjectsFromXIndexAccess <T>(XIndexAccess container) where T : class
        {
            IList <T> list = new List <T>();

            if (container != null && container.hasElements())
            {
                for (int i = 0; i < container.getCount(); i++)
                {
                    var child = container.getByIndex(i).Value;
                    if (child != null && (child is T))
                    {
                        list.Add(child as T);
                    }
                }
            }
            return(list);
        }
 private IList <Object> GetAllObjectsFromXIndexAccess(XIndexAccess container)
 {
     return(GetAllObjectsFromXIndexAccess <Object>(container));
 }
        public static void ExportExcelLO(string FileName, DataSet ds)
        {
            try
            {
                string unoPath = @"C:\Program Files (x86)\LibreOffice 5\program";
                Environment.SetEnvironmentVariable("UNO_PATH", unoPath, EnvironmentVariableTarget.Process);
                Environment.SetEnvironmentVariable("PATH", Environment.GetEnvironmentVariable("PATH") + @";"
                                                   + unoPath, EnvironmentVariableTarget.Process);

                XComponentContext    oStrap   = uno.util.Bootstrap.bootstrap();
                XMultiServiceFactory oServMan = (XMultiServiceFactory)oStrap.getServiceManager();
                XComponentLoader     desktop  = (XComponentLoader)oServMan.createInstance("com.sun.star.frame.Desktop");
                string          url           = @"private:factory/scalc";
                PropertyValue[] loadProps     = new PropertyValue[3];
                loadProps[0] = new PropertyValue()
                {
                    Name  = "Hidden",
                    Value = new uno.Any(true)
                };

                loadProps[1] = new PropertyValue()
                {
                    Name  = "FilterName",
                    Value = new uno.Any("MS Excel 97")
                };

                loadProps[2] = new PropertyValue()
                {
                    Name  = "ReadOnly",
                    Value = new uno.Any(false)
                };

                XComponent    document = desktop.loadComponentFromURL(url, "_blank", 0, loadProps);
                XSpreadsheets oSheets = ((XSpreadsheetDocument)document).getSheets();
                XIndexAccess  oSheetsIA = (XIndexAccess)oSheets;
                XSpreadsheet  sheet = (XSpreadsheet)oSheetsIA.getByIndex(0).Value;
                int           ii = 0; XCell celija = null;
                foreach (DataColumn kol in ds.Tables[0].Columns)
                {
                    celija = sheet.getCellByPosition(ii, 0);
                    ((XText)celija).setString(kol.ColumnName);
                    //((XPropertySet)celija).setPropertyValue("CellBackColor", new uno.Any(654321));
                    //((XPropertySet)celija).setPropertyValue("CharColor", new uno.Any(333444));
                    ii++;
                }
                ds.Tables[0].AcceptChanges(); ii = 0;
                foreach (DataRow red in ds.Tables[0].Rows)
                {
                    int jj = 0; ii++;
                    foreach (object ob in red.ItemArray)
                    {
                        celija = sheet.getCellByPosition(jj, ii);
                        ((XText)celija).setString(ob.ToString());
                        //((XPropertySet)celija).setPropertyValue("CellBackColor", new uno.Any(888777));
                        jj++;
                    }
                }
                ((XStorable)document).storeToURL("file:///" + FileName.Replace(@"\", "/"), loadProps);
                System.Diagnostics.Process.Start(FileName);
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }
 protected static IList <Object> GetAllObjectsFromXIndexAccess(XIndexAccess container)
 {
     return(GetAllObjectsFromXIndexAccess <Object>(container));
 }
        private void handleChild(int i, XIndexAccess ia)
        {
            //System.Diagnostics.Debug.WriteLine("[UPDATE] --- handle child [" + i + "]");
            try
            {
                if (PagesObserver != null)
                {
                    lock (_childHandleLock)
                    {
                        var anyShape = ia.getByIndex(i);
                        if (anyShape.hasValue() && anyShape.Value is XShape)
                        {
                            if (PagesObserver.ShapeAlreadyRegistered(anyShape.Value as XShape, this))
                            {
                                //System.Diagnostics.Debug.WriteLine("[UPDATE] Shape " + anyShape.Value + " already exists ");

                                OoShapeObserver so = PagesObserver.GetRegisteredShapeObserver(anyShape.Value as XShape, this);
                                if (so != null) so.UpdateChildren();
                                else
                                {
                                    Logger.Instance.Log(LogPriority.DEBUG, this, "[ERROR] Shape should exist but could not been found!!!");

                                    so = new OoShapeObserver(anyShape.Value as XShape, this);
                                    //shapeList.Add(so);
                                }
                            }
                            else
                            {
                                //System.Diagnostics.Debug.WriteLine("[UPDATE] New Shape " + anyShape.Value + " will be registered ");
                                OoShapeObserver so = null;
                                try
                                {
                                    if (OoUtils.ElementSupportsService(anyShape.Value, OO.Services.DRAW_SHAPE_TEXT))
                                    {
                                        so = new OoShapeObserver(anyShape.Value as XShape, this);
                                    }
                                    else
                                    {
                                        so = new OoShapeObserver(anyShape.Value as XShape, this);
                                        //System.Diagnostics.Debug.WriteLine("[UPDATE] Shape: " + so.Name + " will be registered");
                                    }
                                }
                                catch (unoidl.com.sun.star.uno.RuntimeException ex)
                                {
                                    Logger.Instance.Log(LogPriority.IMPORTANT, this, "[ERROR]  internal while register ShapeObserver", ex);
                                }
                                catch (Exception ex)
                                {
                                    Logger.Instance.Log(LogPriority.IMPORTANT, this, "[FATAL ERROR] can not register ShapeObserver", ex);
                                }
                                //finally
                                //{
                                //    if (so != null) shapeList.Add(so);
                                //}
                            }
                        }
                    }
                }
                else
                {
                    Logger.Instance.Log(LogPriority.DEBUG, this, "[ERROR] PagesObserver is null");
                }
            }
            catch (System.Threading.ThreadAbortException ex) { Logger.Instance.Log(LogPriority.DEBUG, this, "[OO Deadlock] can't get access to children via child handling in DrawPageObserver", ex); }
            catch (Exception ex) { Logger.Instance.Log(LogPriority.DEBUG, this, "can't get access to children via child handling in DrawPageObserver", ex); }
        }
Exemplo n.º 9
0
        private void handleChild(int i, XIndexAccess ia)
        {
            //System.Diagnostics.Debug.WriteLine("[UPDATE] --- handle child [" + i + "]");
            try
            {
                if (PagesObserver != null)
                {
                    lock (_childHandleLock)
                    {
                        var anyShape = ia.getByIndex(i);
                        if (anyShape.hasValue() && anyShape.Value is XShape)
                        {
                            if (PagesObserver.ShapeAlreadyRegistered(anyShape.Value as XShape, this))
                            {
                                //System.Diagnostics.Debug.WriteLine("[UPDATE] Shape " + anyShape.Value + " already exists ");

                                OoShapeObserver so = PagesObserver.GetRegisteredShapeObserver(anyShape.Value as XShape, this);
                                if (so != null)
                                {
                                    so.UpdateChildren();
                                }
                                else
                                {
                                    Logger.Instance.Log(LogPriority.DEBUG, this, "[ERROR] Shape should exist but could not been found!!!");

                                    so = OoShapeObserverFactory.BuildShapeObserver(anyShape.Value, this);  //new OoShapeObserver(anyShape.Value as XShape, this);
                                    //shapeList.Add(so);
                                }
                            }
                            else
                            {
                                //System.Diagnostics.Debug.WriteLine("[UPDATE] New Shape " + anyShape.Value + " will be registered ");
                                OoShapeObserver so = null;
                                try
                                {
                                    if (OoUtils.ElementSupportsService(anyShape.Value, OO.Services.DRAW_SHAPE_TEXT))
                                    {
                                        so = OoShapeObserverFactory.BuildShapeObserver(anyShape.Value, this);  //new OoShapeObserver(anyShape.Value as XShape, this);
                                    }
                                    else
                                    {
                                        so = OoShapeObserverFactory.BuildShapeObserver(anyShape.Value, this);  //new OoShapeObserver(anyShape.Value as XShape, this);
                                        //System.Diagnostics.Debug.WriteLine("[UPDATE] Shape: " + so.Name + " will be registered");
                                    }
                                }
                                catch (unoidl.com.sun.star.uno.RuntimeException ex)
                                {
                                    Logger.Instance.Log(LogPriority.IMPORTANT, this, "[ERROR]  internal while register ShapeObserver", ex);
                                }
                                catch (Exception ex)
                                {
                                    Logger.Instance.Log(LogPriority.IMPORTANT, this, "[FATAL ERROR] can not register ShapeObserver", ex);
                                }
                                //finally
                                //{
                                //    if (so != null) shapeList.Add(so);
                                //}
                            }
                        }
                    }
                }
                else
                {
                    Logger.Instance.Log(LogPriority.DEBUG, this, "[ERROR] PagesObserver is null");
                }
            }
            catch (System.Threading.ThreadAbortException ex) { Logger.Instance.Log(LogPriority.DEBUG, this, "[OO Deadlock] can't get access to children via child handling in DrawPageObserver", ex); }
            catch (Exception ex) { Logger.Instance.Log(LogPriority.DEBUG, this, "can't get access to children via child handling in DrawPageObserver", ex); }
        }