private static OoAccComponent moveToPrevComponent(OoAccComponent comp) { if (comp != null && comp.IsValid()) { //-------------------------- // try to get the parent OoAccComponent parent = comp.GetParent(); if (parent != null) { int pIndex = comp.IndexInParent; int pcCount = parent.ChildCount; int npIndex = mod(pIndex - 1, pcCount); if (pIndex != npIndex) { // get prev sibling var prevSibling = parent.GetChild(npIndex); if (prevSibling != null) { System.Diagnostics.Debug.WriteLine("[MOVE PREV] ---> return prev sibling: " + prevSibling); return(prevSibling); } } } } return(null); }
/// <summary> /// Moves to prev component. /// </summary> /// <param name="comp">The comp.</param> /// <param name="handleChildren">if set to <c>true</c> [handle children].</param> /// <returns></returns> private static OoAccComponent moveDeterministicToPrevComponent(OoAccComponent comp, bool handleChildren = true) { if (comp != null) { //walk through the children and back to the parent //check if has children if (handleChildren && comp.HasChildren) // should have children --> go deeper { //TODO: check if we accept this children - e.g. Text ??? // try get the first child OoAccComponent child = comp.GetChild(comp.ChildCount - 1); if (child != null) { System.Diagnostics.Debug.WriteLine("[MOVE PREV] ---> return child: " + child); return(child); } } // if has no children --> go to prev sibling //-------------------------- // try to get the parent OoAccComponent parent = comp.GetParent(); if (parent != null) { int pIndex = comp.IndexInParent; if (pIndex >= 0) { int pcCount = parent.ChildCount; if (pIndex > 0) // is not the first child { // get prev sibling var prevSibling = parent.GetChild(pIndex - 1); if (prevSibling != null) { System.Diagnostics.Debug.WriteLine("[MOVE PREV] ---> return prev sibling: " + prevSibling); return(prevSibling); } } else // is first element --> go higher { return(moveDeterministicToPrevComponent(parent, false)); } } else { // ERROR - this happens e.g. when the parent object is invalid AudioRenderer.Instance.PlayWaveImmediately(StandardSounds.Error); Logger.Instance.Log(LogPriority.OFTEN, "AccDomWalker", "[ERROR] Index in parent is negative"); } } } return(null); }
private static OoAccComponent moveToChildComponent(OoAccComponent comp, ref int index) { if (comp != null && comp.IsValid() && comp.HasChildren) { try { int childNumber = comp.ChildCount; index = index % childNumber; return(comp.GetChild(index)); } catch { } } return(null); }