Esempio n. 1
0
        /// <summary>
        /// Inserts the data object into the context</summary>
        /// <param name="insertingObject">Data to insert; e.g., System.Windows.Forms.IDataObject</param>
        public void Insert(object insertingObject)
        {
            Point           center          = new Point(m_viewingContext.Control.Width / 2, m_viewingContext.Control.Height / 2);
            DragDropAdapter dragDropAdapter = m_viewingContext.Control.As <DragDropAdapter>();

            if (dragDropAdapter != null && dragDropAdapter.IsDropping)
            {
                center = dragDropAdapter.MousePosition;
            }
            Insert(insertingObject, center);
        }
Esempio n. 2
0
        /// <summary>
        /// Inserts object into statechart at the center of the canvas or last selected state if there was one</summary>
        /// <param name="insertingObject">Object to insert</param>
        public void Insert(object insertingObject)
        {
            Statechart       insertionPoint  = m_statechart; // default is root statechart
            AdaptableControl control         = m_viewingContext.Control;
            DragDropAdapter  dragDropAdapter = control.As <DragDropAdapter>();
            Matrix           transform       = control.As <ITransformAdapter>().Transform;

            Point center; // in world coordinates

            if (dragDropAdapter != null && dragDropAdapter.IsDropping)
            {
                insertionPoint = FindStatechartUnder(dragDropAdapter.MousePosition);
                center         = GdiUtil.InverseTransform(transform, dragDropAdapter.MousePosition);
            }
            else // paste into last selected state
            {
                State state = Selection.GetLastSelected <State>();
                if (state != null)
                {
                    insertionPoint = GetStatechart(state);
                    Rectangle stateBounds = m_viewingContext.GetBounds(state);
                    center = new Point(
                        stateBounds.X + stateBounds.Width / 2,
                        stateBounds.Y + stateBounds.Height / 2);
                    center = GdiUtil.InverseTransform(transform, center);
                }
                else
                {
                    center = GdiUtil.InverseTransform(transform,
                                                      new Point(
                                                          control.Width / 2,
                                                          control.Height / 2));
                }
            }

            Insert(insertingObject, center, insertionPoint);
        }