// Add a cursor at the given index (in the context of the block layout.)
        // Return the new cursor.
        private StripCursor AddCursorAtBlockLayoutIndex(int index)
        {
            StripCursor cursor = new StripCursor();

            cursor.SetHeight(mBlockHeight);
            cursor.ColorSettings = ColorSettings;
            cursor.TabStop       = false;
            cursor.SetAccessibleNameForIndex(index / 2);
            mBlockLayout.Controls.Add(cursor);
            mBlockLayout.Controls.SetChildIndex(cursor, index);
            return(cursor);
        }
        /// <summary>
        /// Set the selection from a strip cursor to its index. This gets passed to the content view.
        /// </summary>
        public void SetSelectedIndexFromStripCursor(StripCursor cursor)
        {
            int index = mBlockLayout.Controls.IndexOf(cursor) / 2;

            mContentView.SelectionFromStrip = new StripIndexSelection(Node, mContentView, index);
        }
        private Block AddBlockForNode_Internal(EmptyNode node)
        {
            if (mBlockLayout.Controls.Count == 0)
            {
                StripCursor cursor = AddCursorAtBlockLayoutIndex(0);
            }
            Block block = null; //@

            if (m_EmptyNode_BlocksMap.ContainsKey(node))
            {
                block = m_EmptyNode_BlocksMap[node];
            }
            else
            {
                block = node is PhraseNode ? new AudioBlock((PhraseNode)node, this) : new Block(node, this);
                m_EmptyNode_BlocksMap.Add(node, block);    //@
            }
            // avoid re adding of blocks, this is temporary fix till dynamic adding and removing stablizes
            if (mBlockLayout.Controls.Contains(block))
            {
                // this problem is now fixed so this if block should be removed in future.
                return(block);
            }

            mBlockLayout.Controls.Add(block);

            //mBlockLayout.Controls.SetChildIndex(block, 1 + 2 * node.Index);
            AddCursorAtBlockLayoutIndex(2 + 2 * node.Index);
            // set all index with each add. this is heavy operation so should be removed after experiments
            if (mBlockLayout.Controls.Count > 3)
            {
                List <int> indexList = new List <int> ();
                Dictionary <int, Block> blocksMap = new Dictionary <int, Block> ();
                foreach (Control c in mBlockLayout.Controls)
                {
                    if (c is Block)
                    {
                        int bIndex = ((Block)c).Node.Index;
                        indexList.Add(bIndex);
                        blocksMap.Add(bIndex, (Block)c);
                    }
                }
                indexList.Sort();
                int firstNodeIndex = indexList[0];
                Console.WriteLine("first index " + firstNodeIndex.ToString());
                foreach (int i in indexList)
                {
                    mBlockLayout.Controls.SetChildIndex(blocksMap[i], 1 + 2 * (i - firstNodeIndex));
                    Console.WriteLine("Block is added at " + (1 + 2 * (i - firstNodeIndex)).ToString());
                }
            }
            else
            {
                mBlockLayout.Controls.SetChildIndex(block, 1);
                //AddCursorAtBlockLayoutIndex ( 2 );
            }
            //
            block.SetZoomFactorAndHeight(mContentView.ZoomFactor, mBlockHeight);
            block.Cursor       = Cursor;
            block.SizeChanged += new EventHandler(Block_SizeChanged);
            Resize_Blocks();
            //UpdateStripCursorsAccessibleName(2 + 2 * node.Index); @ temprorary disabled for experiments
            CheckControlTypeAtINdex();

            RemoveBlockDynamically(block);
            return(block);
        }