/// <summary>
        /// Try to generate an unique id.
        /// </summary>
        /// <param name="shape">The shape.</param>
        /// <returns></returns>
        public string GetUniqueId(OoShapeObserver shape)
        {
            int    uidCount = 0;
            String uid      = String.Empty;

            if (shape != null && shape.Shape != null)
            {
                if (OoUtils.ElementSupportsService(shape.Shape, OO.Services.DRAW_SHAPE_TEXT))
                {
                    uid = shape.Name;
                    if (String.IsNullOrWhiteSpace(uid) ||
                        uid.Contains('\'') ||
                        uid.Contains(' '))
                    {
                        uid = shape.UINamePlural;
                        System.Diagnostics.Debug.WriteLine("______the start name for the text shape is now : '" + uid + "'");
                    }
                }
                else
                {
                    uid = shape.Name;
                }
                if (String.IsNullOrWhiteSpace(uid))
                {
                    if (shape is INameBuilder)
                    {
                        uid = ((INameBuilder)shape).BuildName();
                    }
                    else
                    {
                        uid = shape.UINameSingular + "_" + (++uidCount);
                    }
                }

                while (shapeIds.Contains(uid))
                {
                    if (shape is INameBuilder)
                    {
                        uid = ((INameBuilder)shape).RebuildName();
                    }
                    else
                    {
                        int i_ = uid.LastIndexOf('_');
                        if (i_ >= 0)
                        {
                            uid = uid.Substring(0, i_ + 1);
                        }
                        else
                        {
                            uid += "_";
                        }
                        uid += ++uidCount;
                    }
                }
                shapeIds.Add(uid);
            }
            Logger.Instance.Log(LogPriority.DEBUG, this, "new Shape with name: " + uid + " registered");
            return(uid);
        }
 /// <summary>
 /// Determines whether this Freeform is a Bezier defined form or not.
 /// </summary>
 /// <param name="cached">if set to <c>true</c> the previously cached result will be returned.</param>
 /// <returns>
 ///   <c>true</c> if the Freeform is a Bezier defined one; otherwise, <c>false</c>.
 /// </returns>
 virtual public bool IsBezier(bool cached = true)
 {
     if (IsValid() && !cached)
     {
         if (OoUtils.ElementSupportsService(Shape.Shape, OO.Services.DRAW_POLY_POLYGON_BEZIER_DESCRIPTOR))
         {
             _isBezier = true;
         }
     }
     return(_isBezier);
 }
Example #3
0
        /// <summary>
        /// Builds an Observer class for the specific shape type.
        /// </summary>
        /// <param name="s">The shape to observe.</param>
        /// <param name="page">The page the shape is placed on.</param>
        /// <param name="parent">The parent shape if the shape is part of a group.</param>
        /// <returns>
        /// An shape observer class for the specific shape type.
        /// </returns>
        internal static OoShapeObserver BuildShapeObserver(XShape s, OoDrawPageObserver page, OoShapeObserver parent)
        {
            if (s != null && page != null)
            {
                if (OoUtils.ElementSupportsService(s, OO.Services.DRAW_SHAPE_CUSTOM))
                {
                    return(new OoCustomShapeObserver(s, page, parent));
                }

                // normal shape
                return(new OoShapeObserver(s, page, parent));
            }
            return(null);
        }
        /// <summary>
        /// Determines whether this instance is valid.
        /// </summary>
        /// <param name="force">forces a revalidation; otherwise a revalidation is only applied every ~5 sec. to save performance - in such a case the last validation value will be returned. </param>
        /// <returns>
        ///   <c>true</c> if this instance is valid; otherwise, <c>false</c>.
        /// </returns>
        /// <remarks>Parts of this function are time limited to 100 ms.</remarks>
        virtual public bool IsValid(bool force = true)
        {
            if (!_valid)
            {
                return(false);
            }
            if (LockValidation)
            {
                return(_valid);
            }

            long ts = DateTime.UtcNow.Ticks;

            if (!force && (ts - _lastValidation < _validationTreshold))
            {
                return(_valid);
            }

            _valid = true;
            lock (SynchLock)
            {
                try
                {
                    if (!Disposed && Shape != null && Page != null)
                    {
                        TimeLimitExecutor.WaitForExecuteWithTimeLimit(100, () =>
                        {
                            try
                            {
                                var test1     = Shape.GetHashCode();
                                string uiName = UINameSingular;
                                if (test1 == 0 || String.IsNullOrEmpty(uiName))
                                {
                                    _valid = false;
                                    Dispose();
                                    return;
                                }

                                if (AcccessibleCounterpart != null)
                                {
                                    AcccessibleCounterpart.GetHashCode();
                                }
                                else
                                {
                                    Update();
                                }

                                if (!OoUtils.ElementSupportsService(Shape, OO.Services.DRAW_SHAPE))
                                {
                                    _valid = false;
                                    return;
                                }

                                //var services = util.Debug.GetAllServicesOfObject(Shape, false);
                                //if (services.Length == 0)
                                //{
                                //    valid = false;
                                //    return;
                                //}

                                //// test if a parent exists
                                //XShapes parent;
                                //bool parentSuccess = tryGetParentByXShape(out parent, Shape);
                                //if (parentSuccess && parent == null)
                                //{
                                //    valid = false;
                                //    // should bee disposed?!
                                //    Dispose();
                                //    return;
                                //}

                                _valid = true;
                            }
                            catch (System.Threading.ThreadAbortException) { DisableValidationTemporary(); }
                            catch (System.Threading.ThreadInterruptedException) { DisableValidationTemporary(); }
                        }, "ShapeValidation Shape " + _lastName);
                    }
                    else
                    {
                        _valid = false;
                    }
                }
                catch (unoidl.com.sun.star.lang.DisposedException)
                {
                    Dispose();
                }
                catch { }
            }

            _lastValidation = ts;
            return(_valid);
        }
Example #5
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); }
        }