private void Update(XDrawPagesSupplier dps)
        {
            var shapeList = new List <OoShapeObserver>(this.domshapes.Values);

            if (shapeList != null && shapeList.Count > 0)
            {
                foreach (var shapeObs in shapeList)
                {
                    if (shapeObs != null)
                    {
                        shapeObs.Update();
                    }
                }
            }

            List <XDrawPage> dpL = OoDrawUtils.DrawDocGetXDrawPageList(dps);

            Parallel.ForEach(dpL, (drawPage) =>
            {
                if (DrawPageobservers.ContainsKey(drawPage))
                {
                    System.Diagnostics.Debug.WriteLine("[UPDATE] Draw page known");
                    var obs = DrawPageobservers[drawPage];
                    obs.Update();
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("[UPDATE] Draw page NOT known !!!");
                    OoDrawPageObserver dpobs = new OoDrawPageObserver(drawPage, this);
                    RegisterDrawPage(dpobs);
                }
            });
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="OoDrawPagesObserver"/> class.
        /// </summary>
        /// <param name="dp">The Draw document.</param>
        /// <param name="doc">The document related accessibility component.</param>
        /// <param name="docWnd">The related document accessible window component.</param>
        public OoDrawPagesObserver(XDrawPagesSupplier dp, OoAccComponent doc, OoAccessibleDocWnd docWnd = null)
        {
            this.PagesSupplier = dp;
            Document           = doc;
            DocWnd             = docWnd;

            // get Zoom and ViewOffset first time
            if (Controller != null)
            {
                if (Controller is XPropertySet)
                {
                    refreshDrawViewProperties((XPropertySet)(Controller));
                }
                // try to get dpi settings from openoffice
                XWindow componentWindow = Controller.ComponentWindow;
                if (componentWindow != null && componentWindow is XDevice)
                {
                    DeviceInfo deviceInfo = (DeviceInfo)((XDevice)componentWindow).getInfo();
                    if (deviceInfo != null)
                    {
                        PixelPerMeterX = deviceInfo.PixelPerMeterX;
                        PixelPerMeterY = deviceInfo.PixelPerMeterY;
                    }
                }
            }
            // register for Zoom and ViewOffset updates
            addVisibleAreaPropertyChangeListener();

            if (this.PagesSupplier != null)
            {
                List <XDrawPage> dpL = OoDrawUtils.DrawDocGetXDrawPageList(dp);

                if (PagesSupplier is unoidl.com.sun.star.frame.XTitle)
                {
                    Title = ((unoidl.com.sun.star.frame.XTitle)PagesSupplier).getTitle();
                }

                Logger.Instance.Log(LogPriority.DEBUG, this, "create DrawPagesObserver for supplier " + dp.GetHashCode() + " width title '" + Title + "' - having " + dpL.Count + " pages");

                //FIXME: Do this if the api enable parallel access
                //Parallel.ForEach(dpL, (drawPage) =>
                //{
                //    OoDrawPageObserver dpobs = new OoDrawPageObserver(drawPage, this);
                //    DrawPageobservers[drawPage] = dpobs;
                //    DrawPages.Add(dpobs);
                //});

                foreach (var drawPage in dpL)
                {
                    OoDrawPageObserver dpobs = new OoDrawPageObserver(drawPage, this);
                    RegisterDrawPage(dpobs);
                }

                XModifyBroadcaster mdfBc = PagesSupplier as XModifyBroadcaster;
                if (mdfBc != null)
                {
                    mdfBc.addModifyListener(eventForwarder);
                }
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="DescriptionMapper"/> class.
 /// </summary>
 /// <param name="xDrawPagesSupplier">The x draw pages supplier.</param>
 /// <param name="xContext">The x context. (optional)</param>
 public DescriptionMapper(XDrawPagesSupplier xDrawPagesSupplier, XComponentContext xContext = null)
 {
     if (xContext != null)
     {
         this.xContext = xContext;
     }
     this.xDrawPagesSupplier = xDrawPagesSupplier;
 }
Example #4
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);
        }
        private void Update(XDrawPagesSupplier dps)
        {
            List<XDrawPage> dpL = OoDrawUtils.DrawDocGetXDrawPageList(dps);

            Parallel.ForEach(dpL, (drawPage) =>
            {
                if (DrawPageobservers.ContainsKey(drawPage))
                {
                    System.Diagnostics.Debug.WriteLine("[UPDATE] Draw page known");
                    var obs = DrawPageobservers[drawPage];
                    obs.Update();
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("[UPDATE] Draw page NOT known !!!");
                    OoDrawPageObserver dpobs = new OoDrawPageObserver(drawPage, this);
                    RegisterDrawPage(dpobs);
                }
            });
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="OoDrawPagesObserver"/> class.
        /// </summary>
        /// <param name="dp">The Draw document.</param>
        /// <param name="doc">The document related accessibility component.</param>
        /// <param name="docWnd">The related document accessible window component.</param>
        public OoDrawPagesObserver(XDrawPagesSupplier dp, OoAccComponent doc, OoAccessibleDocWnd docWnd = null)
        {
            this.PagesSupplier = dp;
            Document = doc;
            DocWnd = docWnd;

            // get Zoom and ViewOffset first time
            if (Controller != null)
            {
                if (Controller is XPropertySet)
                {
                    refreshDrawViewProperties((XPropertySet)(Controller));
                }
                // try to get dpi settings from openoffice
                XWindow componentWindow = Controller.ComponentWindow;
                if (componentWindow != null && componentWindow is XDevice)
                {
                    DeviceInfo deviceInfo = (DeviceInfo)((XDevice)componentWindow).getInfo();
                    if (deviceInfo != null)
                    {
                        PixelPerMeterX = deviceInfo.PixelPerMeterX;
                        PixelPerMeterY = deviceInfo.PixelPerMeterY;
                    }
                }
            }
            // register for Zoom and ViewOffset updates
            addVisibleAreaPropertyChangeListener();

            if (this.PagesSupplier != null)
            {
                List<XDrawPage> dpL = OoDrawUtils.DrawDocGetXDrawPageList(dp);

                if (PagesSupplier is unoidl.com.sun.star.frame.XTitle)
                {
                    Title = ((unoidl.com.sun.star.frame.XTitle)PagesSupplier).getTitle();
                }

                Logger.Instance.Log(LogPriority.DEBUG, this, "create DrawPagesObserver for supplier " + dp.GetHashCode() + " width title '" + Title + "' - having " + dpL.Count + " pages");

                //FIXME: Do this if the api enable parallel access
                //Parallel.ForEach(dpL, (drawPage) =>
                //{
                //    OoDrawPageObserver dpobs = new OoDrawPageObserver(drawPage, this);
                //    DrawPageobservers[drawPage] = dpobs;
                //    DrawPages.Add(dpobs);
                //});

                foreach (var drawPage in dpL)
                {
                    OoDrawPageObserver dpobs = new OoDrawPageObserver(drawPage, this);
                    RegisterDrawPage(dpobs);
                }

                XModifyBroadcaster mdfBc = PagesSupplier as XModifyBroadcaster;
                if (mdfBc != null)
                {
                    mdfBc.addModifyListener(eventForwarder);
                }
            }
        }
        /// <summary>
        /// Hack to activate the accessibility events for selection.
        /// </summary>
        /// <param name="item">The item.</param>
        private void prepareForSelection(XDrawPagesSupplier item)
        {
            // adding and deleting one shape to the document so the selections 
            // will be activated for notify events of the XAccessibleEventBroadcaster
            // FIXME: remove this hack - if the event works properly

            if (item != null)
            {

                TimeLimitExecutor.ExecuteWithTimeLimit(
                        () =>
                        {
                            var shape = OoDrawUtils.CreateEllipseShape(item, 0, 0, 3000, 3000);
                            var page = OoDrawUtils.GetCurrentPage(item);
                            if (page != null && shape != null)
                            {
                                OoDrawUtils.AddShapeToDrawPage(shape, page);
                                OoDrawUtils.RemoveShapeFromDrawPage(shape, page);
                            }
                        }
                    );
            }
            else
            {
                Logger.Instance.Log(LogPriority.IMPORTANT, this, "[FATAL ERROR] Cannot add shapes for activating selection events");
            }
        }
 protected static List<XDrawPage> GetAllDrawPages(XDrawPagesSupplier xDrawPagesSupplier)
 {
     return GetAllObjectsFromXIndexAccess<XDrawPage>(xDrawPagesSupplier != null ? xDrawPagesSupplier.getDrawPages() as XIndexAccess : null) as List<XDrawPage>;
 }
 /// <summary>
 /// Gets the current page.
 /// </summary>
 /// <param name="drawDoc">The draw doc.</param>
 /// <returns></returns>
 internal static XDrawPage GetCurrentPage(XDrawPagesSupplier drawDoc)
 {
     if (drawDoc != null)
     {
         XModel xModel = drawDoc as XModel;
         if (xModel != null)
         {
             XController xController = xModel.getCurrentController();
             if (xController != null)
             {
                 XPropertySet xPropSet = xController as XPropertySet;
                 if (xPropSet != null)
                 {
                     try
                     {
                         XDrawPage xDrawPg = xPropSet.getPropertyValue("CurrentPage").Value as XDrawPage;
                         return xDrawPg;
                     }
                     catch
                     {
                         Logger.Instance.Log(LogPriority.DEBUG, "OoDrawUtils", "can't get current page");
                     }
                 }
             }
         }
     }
     return null;
 }
 /// <summary>
 /// Adds a shape to a draw page or an other shape group.
 /// </summary>
 /// <param name="shape">The shape.</param>
 /// <param name="page">The page.</param>
 internal static void AddShapeToDrawPage(XShape shape, XDrawPagesSupplier drawDoc)
 {
     if (shape != null && drawDoc != null)
     {
         try
         {
             AddShapeToDrawPage(shape, GetCurrentPage(drawDoc));
         }
         catch { }
     }
 }
        //public static void convertIntoUnit(int size, unoidl.com.sun.star.util.MeasureUnit targetUnit)
        //{
        //    //    unoidl.com.sun.star.util      
        //}

        #region General Functions

        /// <summary>
        /// Gets the XAccessible from a draw pages supplier.
        /// </summary>
        /// <param name="dps">The DPS.</param>
        /// <returns>the corresponding XAccessible if possible otherwise <c>null</c></returns>
        internal static XAccessible GetXAccessibleFromDrawPagesSupplier(XDrawPagesSupplier dps)
        {
            XAccessible acc = null;
            if (dps != null && dps is XModel2)
            {
                var controller = ((XModel2)dps).getCurrentController();
                if (controller != null)
                {
                    Object componenetWindow = ((XController2)controller).ComponentWindow;
                    // is unoidl.com.sun.star.accessibility.XAccessible :D

                    if (componenetWindow != null && componenetWindow is XAccessible)
                        acc = componenetWindow as XAccessible;
                }
            }
            return acc;
        }
Example #12
0
 protected static List <XDrawPage> GetAllDrawPages(XDrawPagesSupplier xDrawPagesSupplier)
 {
     return(GetAllObjectsFromXIndexAccess <XDrawPage>(xDrawPagesSupplier != null ? xDrawPagesSupplier.getDrawPages() as XIndexAccess : null) as List <XDrawPage>);
 }