Beispiel #1
0
        private void handleAccessibleChildEvent(OoAccessibleDocWnd doc, object p, uno.Any newValue, uno.Any oldValue)
        {
            Task t = new Task(() =>
            {
                util.Debug.GetAllInterfacesOfObject(p);
                if (doc != null && !newValue.hasValue() && oldValue.hasValue())
                {
                    // shape was deleted!

                    var oldShapeAcc = oldValue.Value;

                    util.Debug.GetAllInterfacesOfObject(oldShapeAcc);


                    if (p != null && p is XAccessibleComponent)
                    {
                        var shapeObs = doc.GetRegisteredShapeObserver(p as XAccessibleComponent);
                        if (shapeObs != null && !shapeObs.IsValid(true))
                        {
                            shapeObs.Dispose();
                        }
                        else
                        {
                            doc.Update();
                        }
                    }
                }
            });

            t.Start();
        }
        /// <summary>
        /// Gets all named elements of the object.
        /// </summary>
        /// <param name="obj">The obj.</param>
        /// <param name="debug">if set to <c>true</c> the named children will be printed
        /// to the System.Diagnostics.Debug output.</param>
        /// <returns>
        /// A dictionary with the named elements. The name is the key an the value
        /// is set as uno.Any. You can access the real value by using uno.Any.Value
        /// </returns>
        public static Dictionary <string, uno.Any> GetAllNamedElements(XNameAccess obj, bool debug = true)
        {
            Dictionary <string, uno.Any> elements = new Dictionary <string, uno.Any>();

            if (obj != null)
            {
                string[] names = obj.getElementNames();

                if (debug)
                {
                    System.Diagnostics.Debug.WriteLine("Object [" + obj + "] has " + names.Length + " Properties:");
                }

                foreach (var name in names)
                {
                    uno.Any element = obj.getByName(name);
                    elements.Add(name, element);

                    if (debug)
                    {
                        try
                        {
                            System.Diagnostics.Debug.WriteLine("\tProperty: " + name + " = " + element);
                        }
                        catch (System.Exception)
                        {
                            System.Diagnostics.Debug.WriteLine("Can't get property - " + name);
                        }
                    }
                }
            }
            return(elements);
        }
Beispiel #3
0
        private PropertyValue CreateProperty(string name, uno.Any value)
        {
            PropertyValue prop = new PropertyValue();

            prop.Name  = name;
            prop.Value = value;
            return(prop);
        }
Beispiel #4
0
        public static uno.Any Get(Object o)
        {
            if (o is uno.Any)
            {
                return((uno.Any)o);
            }
            var a = new uno.Any(o != null ? o.GetType() : (new Object()).GetType(), o);

            return(a);
        }
Beispiel #5
0
        public static uno.Any[] Get(Array i)
        {
            var a = new uno.Any[i.Length];

            for (int j = 0; j < i.Length; j++)
            {
                a[j] = Get(i.GetValue(j));
            }

            return(a);
        }
        public static uno.Any[] Get(Array i)
        {
            var a = new uno.Any[i.Length];
            for (int j = 0; j < i.Length; j++)
            {
                a[j] = Get(i.GetValue(j));
            }

            return a;

        }
Beispiel #7
0
        /** Activates a scenario.
         * @param xSheet           The XSpreadsheet interface of the spreadsheet.
         * @param aScenarioName    The name of the scenario. */
        public void showScenario(
            unoidl.com.sun.star.sheet.XSpreadsheet xSheet,
            String aScenarioName)
        {
            // get the scenario set
            unoidl.com.sun.star.sheet.XScenariosSupplier xScenSupp =
                (unoidl.com.sun.star.sheet.XScenariosSupplier)xSheet;
            unoidl.com.sun.star.sheet.XScenarios xScenarios =
                xScenSupp.getScenarios();

            // get the scenario and activate it
            uno.Any aScenarioObj = xScenarios.getByName(aScenarioName);
            unoidl.com.sun.star.sheet.XScenario xScenario =
                (unoidl.com.sun.star.sheet.XScenario)aScenarioObj.Value;
            xScenario.apply();
        }
        private void handleChild(object sender, uno.Any newValue, uno.Any oldValue)
        {
            System.Diagnostics.Debug.WriteLine("[INFO] OoDrawPagesObserver: handle accessible child ID");

            if (newValue.hasValue())
            {
                if (oldValue.hasValue()) // change
                {
                    //System.Diagnostics.Debug.WriteLine("child changed");
                }
                else // added
                {
                    addNewShape(newValue.Value as XAccessible);
                }
            }
            //else if (oldValue.hasValue() && oldValue.Value is XAccessible)
            //{

            //    // FIXME: this does not work properly because sometimes the page itself do this and there is no way to check if this is the page.
            //    //          So we have to leave the corresponding shape and its observer as a dead body in the lists ...
            //    //          Maybe the OoShapeObeservers can detect their disposing by their own and handle a clean up of the lists

            //    //// child deleted;
            //    ////System.Diagnostics.Debug.WriteLine("child deleted");

            //    //XAccessible oldValAcc = oldValue.Value as XAccessible;

            //    //if (oldValAcc != null)
            //    //{
            //    //    if (accshapes.ContainsKey((oldValAcc.getAccessibleContext())))
            //    //    {
            //    //        //TODO: remove ....
            //    //        System.Diagnostics.Debug.WriteLine("have to remove observer");
            //    //    }
            //    //    else
            //    //    {
            //    //        string Name = OoAccessibility.GetAccessibleName(oldValAcc);
            //    //        if (shapes.ContainsKey(Name))
            //    //        {
            //    //            removeChild(shapes[Name]);
            //    //        }
            //    //    }
            //    //}

            //}
        }
Beispiel #9
0
        /// <summary>
        /// Returns a list of addresses of all cell ranges contained in thecollection.
        /// </summary>
        /// <param name="unoidl.com.sun.star.container.XIndexAccess">The XIndexAccess interface of the collection.</param>
        /// <returns>A string containing the cell range address list.</returns>
        public String getCellRangeListString(unoidl.com.sun.star.container.XIndexAccess xRangesIA)
        {
            String aStr   = "";
            int    nCount = xRangesIA.getCount();

            for (int nIndex = 0; nIndex < nCount; ++nIndex)
            {
                if (nIndex > 0)
                {
                    aStr += " ";
                }
                uno.Any aRangeObj = xRangesIA.getByIndex(nIndex);
                unoidl.com.sun.star.sheet.XSheetCellRange xCellRange =
                    (unoidl.com.sun.star.sheet.XSheetCellRange)aRangeObj.Value;
                aStr += getCellRangeAddressString(xCellRange, false);
            }
            return(aStr);
        }
Beispiel #10
0
        internal static bool SetAllProperties(Object obj, Dictionary <String, uno.Any> props)
        {
            try
            {
                if (obj is XMultiPropertySet)
                {
                    String[] keys = new String[props.Count];
                    props.Keys.CopyTo(keys, 0);
                    uno.Any[] vals = new uno.Any[props.Count];
                    props.Values.CopyTo(vals, 0);

                    ((XMultiPropertySet)obj).setPropertyValues(keys, vals);
                }
            }
            catch (Exception ex) { }

            return(false);
        }
Beispiel #11
0
        /** All samples regarding the service com.sun.star.sheet.SheetCellRange. */
        public void doCellRangeSamples()
        {
            unoidl.com.sun.star.sheet.XSpreadsheet     xSheet        = getSpreadsheet(0);
            unoidl.com.sun.star.table.XCellRange       xCellRange    = null;
            unoidl.com.sun.star.beans.XPropertySet     xPropSet      = null;
            unoidl.com.sun.star.table.CellRangeAddress aRangeAddress = null;

            // Preparation
            setFormula(xSheet, "B5", "First cell");
            setFormula(xSheet, "B6", "Second cell");
            // Get cell range B5:B6 by position - (column, row, column, row)
            xCellRange = xSheet.getCellRangeByPosition(1, 4, 1, 5);


            // --- Change cell range properties. ---
            xPropSet = (unoidl.com.sun.star.beans.XPropertySet)xCellRange;
            // from com.sun.star.styles.CharacterProperties
            xPropSet.setPropertyValue(
                "CharColor", new uno.Any((Int32)0x003399));
            xPropSet.setPropertyValue(
                "CharHeight", new uno.Any((Single)20.0));
            // from com.sun.star.styles.ParagraphProperties
            xPropSet.setPropertyValue(
                "ParaLeftMargin", new uno.Any((Int32)500));
            // from com.sun.star.table.CellProperties
            xPropSet.setPropertyValue(
                "IsCellBackgroundTransparent", new uno.Any(false));
            xPropSet.setPropertyValue(
                "CellBackColor", new uno.Any((Int32)0x99CCFF));


            // --- Replace text in all cells. ---
            unoidl.com.sun.star.util.XReplaceable xReplace =
                (unoidl.com.sun.star.util.XReplaceable)xCellRange;
            unoidl.com.sun.star.util.XReplaceDescriptor xReplaceDesc =
                xReplace.createReplaceDescriptor();
            xReplaceDesc.setSearchString("cell");
            xReplaceDesc.setReplaceString("text");
            // property SearchWords searches for whole cells!
            xReplaceDesc.setPropertyValue("SearchWords", new uno.Any(false));
            int nCount = xReplace.replaceAll(xReplaceDesc);

            // --- Merge cells. ---
            xCellRange = xSheet.getCellRangeByName("F3:G6");
            prepareRange(xSheet, "E1:H7", "XMergeable");
            unoidl.com.sun.star.util.XMergeable xMerge =
                (unoidl.com.sun.star.util.XMergeable)xCellRange;
            xMerge.merge(true);


            // --- Column properties. ---
            xCellRange = xSheet.getCellRangeByName("B1");
            unoidl.com.sun.star.table.XColumnRowRange xColRowRange =
                (unoidl.com.sun.star.table.XColumnRowRange)xCellRange;
            unoidl.com.sun.star.table.XTableColumns xColumns =
                xColRowRange.getColumns();

            uno.Any aColumnObj = xColumns.getByIndex(0);
            xPropSet = (unoidl.com.sun.star.beans.XPropertySet)aColumnObj.Value;
            xPropSet.setPropertyValue("Width", new uno.Any((Int32)6000));

            unoidl.com.sun.star.container.XNamed xNamed =
                (unoidl.com.sun.star.container.XNamed)aColumnObj.Value;

            // --- Cell range data ---
            prepareRange(xSheet, "A9:C30", "XCellRangeData");

            xCellRange = xSheet.getCellRangeByName("A10:C30");
            unoidl.com.sun.star.sheet.XCellRangeData xData =
                (unoidl.com.sun.star.sheet.XCellRangeData)xCellRange;
            uno.Any [][] aValues =
            {
                new uno.Any [] { new uno.Any("Name"),
                                 new uno.Any("Fruit"),
                                 new uno.Any("Quantity") },
                new uno.Any [] { new uno.Any("Alice"),
                                 new uno.Any("Apples"),
                                 new uno.Any((Double)3.0) },
                new uno.Any [] { new uno.Any("Alice"),
                                 new uno.Any("Oranges"),
                                 new uno.Any((Double)7.0) },
                new uno.Any [] { new uno.Any("Bob"),
                                 new uno.Any("Apples"),
                                 new uno.Any((Double)3.0) },
                new uno.Any [] { new uno.Any("Alice"),
                                 new uno.Any("Apples"),
                                 new uno.Any((Double)9.0) },
                new uno.Any [] { new uno.Any("Bob"),
                                 new uno.Any("Apples"),
                                 new uno.Any((Double)5.0) },
                new uno.Any [] { new uno.Any("Bob"),
                                 new uno.Any("Oranges"),
                                 new uno.Any((Double)6.0) },
                new uno.Any [] { new uno.Any("Alice"),
                                 new uno.Any("Oranges"),
                                 new uno.Any((Double)3.0) },
                new uno.Any [] { new uno.Any("Alice"),
                                 new uno.Any("Apples"),
                                 new uno.Any((Double)8.0) },
                new uno.Any [] { new uno.Any("Alice"),
                                 new uno.Any("Oranges"),
                                 new uno.Any((Double)1.0) },
                new uno.Any [] { new uno.Any("Bob"),
                                 new uno.Any("Oranges"),
                                 new uno.Any((Double)2.0) },
                new uno.Any [] { new uno.Any("Bob"),
                                 new uno.Any("Oranges"),
                                 new uno.Any((Double)7.0) },
                new uno.Any [] { new uno.Any("Bob"),
                                 new uno.Any("Apples"),
                                 new uno.Any((Double)1.0) },
                new uno.Any [] { new uno.Any("Alice"),
                                 new uno.Any("Apples"),
                                 new uno.Any((Double)8.0) },
                new uno.Any [] { new uno.Any("Alice"),
                                 new uno.Any("Oranges"),
                                 new uno.Any((Double)8.0) },
                new uno.Any [] { new uno.Any("Alice"),
                                 new uno.Any("Apples"),
                                 new uno.Any((Double)7.0) },
                new uno.Any [] { new uno.Any("Bob"),
                                 new uno.Any("Apples"),
                                 new uno.Any((Double)1.0) },
                new uno.Any [] { new uno.Any("Bob"),
                                 new uno.Any("Oranges"),
                                 new uno.Any((Double)9.0) },
                new uno.Any [] { new uno.Any("Bob"),
                                 new uno.Any("Oranges"),
                                 new uno.Any((Double)3.0) },
                new uno.Any [] { new uno.Any("Alice"),
                                 new uno.Any("Oranges"),
                                 new uno.Any((Double)4.0) },
                new uno.Any [] { new uno.Any("Alice"),
                                 new uno.Any("Apples"),
                                 new uno.Any((Double)9.0) }
            };
            xData.setDataArray(aValues);


            // --- Get cell range address. ---
            unoidl.com.sun.star.sheet.XCellRangeAddressable xRangeAddr =
                (unoidl.com.sun.star.sheet.XCellRangeAddressable)xCellRange;
            aRangeAddress = xRangeAddr.getRangeAddress();

            // --- Sheet operation. ---
            // uses the range filled with XCellRangeData
            unoidl.com.sun.star.sheet.XSheetOperation xSheetOp =
                (unoidl.com.sun.star.sheet.XSheetOperation)xData;
            double fResult = xSheetOp.computeFunction(
                unoidl.com.sun.star.sheet.GeneralFunction.AVERAGE);

            // --- Fill series ---
            // Prepare the example
            setValue(xSheet, "E10", 1);
            setValue(xSheet, "E11", 4);
            setDate(xSheet, "E12", 30, 1, 2002);
            setFormula(xSheet, "I13", "Text 10");
            setFormula(xSheet, "E14", "Jan");
            setValue(xSheet, "K14", 10);
            setValue(xSheet, "E16", 1);
            setValue(xSheet, "F16", 2);
            setDate(xSheet, "E17", 28, 2, 2002);
            setDate(xSheet, "F17", 28, 1, 2002);
            setValue(xSheet, "E18", 6);
            setValue(xSheet, "F18", 4);
        }
        internal static bool SetAllProperties(Object obj, Dictionary<String, uno.Any> props)
        {
            try
            {
                if (obj is XMultiPropertySet)
                {

                    String[] keys = new String[props.Count];
                    props.Keys.CopyTo(keys, 0);
                    uno.Any[] vals = new uno.Any[props.Count];
                    props.Values.CopyTo(vals, 0);

                    ((XMultiPropertySet)obj).setPropertyValues(keys, vals);
                }
            }
            catch (Exception ex) { }

            return false;
        }
Beispiel #13
0
        static void Main(string[] args)
        {
            InitOpenOfficeEnvironment();
            XMultiServiceFactory multiServiceFactory = Connect();
            XComponent           xComponent          = null;

            string docFileName = @"C:\test3.doc";

            try
            {
                XComponentLoader componentLoader =
                    (XComponentLoader)multiServiceFactory
                    .createInstance("com.sun.star.frame.Desktop");
                //set the property
                PropertyValue[] propertyValue = new PropertyValue[1];
                PropertyValue   aProperty     = new PropertyValue();
                aProperty.Name   = "Hidden";
                aProperty.Value  = new uno.Any(false);
                propertyValue[0] = aProperty;
                xComponent       =
                    componentLoader
                    .loadComponentFromURL(PathConverter(docFileName),
                                          "_blank", 0, propertyValue);
                XTextDocument      xTextDocument      = ((XTextDocument)xComponent);
                XEnumerationAccess xEnumerationAccess =
                    (XEnumerationAccess)xTextDocument.getText();
                XEnumeration xParagraphEnumeration =
                    xEnumerationAccess.createEnumeration();
                while (xParagraphEnumeration.hasMoreElements())
                {
                    uno.Any      element = xParagraphEnumeration.nextElement();
                    XServiceInfo xinfo   = (XServiceInfo)element.Value;
                    if (xinfo.supportsService("com.sun.star.text.TextTable"))
                    {
                        Console.WriteLine("Found Table!");

                        XTextTable xTextTable = (XTextTable)element.Value;
                        String[]   cellNames  = xTextTable.getCellNames();

                        for (int i = 0; i < cellNames.Length; i++)
                        {
                            XCell  xCell     = xTextTable.getCellByName(cellNames[i]);
                            XText  xTextCell = (XText)xCell;
                            String strText   = xTextCell.getString();
                            Console.WriteLine(strText);
                        }
                    }
                    else
                    {
                        XTextContent       xTextElement           = (XTextContent)element.Value;
                        XEnumerationAccess xParaEnumerationAccess =
                            (XEnumerationAccess)xTextElement;
                        // create another enumeration to get all text portions of
                        //the paragraph
                        XEnumeration xTextPortionEnum =
                            xParaEnumerationAccess.createEnumeration();
                        //step 3  Through the Text portions Enumeration, get interface
                        //to each individual text portion
                        while (xTextPortionEnum.hasMoreElements())
                        {
                            XTextRange xTextPortion =
                                (XTextRange)xTextPortionEnum.nextElement().Value;
                            Console.Write(xTextPortion.getString());
                        }
                    }
                }
            }
            catch (unoidl.com.sun.star.uno.Exception exp1)
            {
                Console.WriteLine(exp1.Message);
                Console.WriteLine(exp1.StackTrace);
            }
            catch (System.Exception exp2)
            {
                Console.WriteLine(exp2.Message);
                Console.WriteLine(exp2.StackTrace);
            }
            finally
            {
                xComponent.dispose();
                xComponent = null;
            }
            Console.WriteLine("Done.");
            Console.ReadLine();
        }
 public static uno.Any Get(Object o)
 {
     if (o is uno.Any) return (uno.Any) o;
     var a = new uno.Any(o != null ? o.GetType() : (new Object()).GetType(), o);
     return a; 
 }