Example #1
0
 public void Remove( GuiObject obj )
 {
     if( !obj.selected )
         throw new ArgumentException( "item is not from the collection" );
     obj.selected = false;
     obj.SelectionChanged();
     obj.Invalidate();
     objs.Remove( obj );
 }
Example #2
0
 public int Add( GuiObject value )
 {
     if( objs.Contains( value ) )
         return 0;
     if( value == null || value.selected )
         throw new ArgumentException( "wrong item for collection" );
     value.selected = true;
     value.SelectionChanged();
     value.Invalidate();
     return objs.Add( value );
 }
Example #3
0
 public void Remove(GuiObject obj)
 {
     if (!obj.selected)
     {
         throw new ArgumentException("item is not from the collection");
     }
     obj.selected = false;
     obj.SelectionChanged();
     obj.Invalidate();
     objs.Remove(obj);
 }
Example #4
0
 public int Add(GuiObject value)
 {
     if (objs.Contains(value))
     {
         return(0);
     }
     if (value == null || value.selected)
     {
         throw new ArgumentException("wrong item for collection");
     }
     value.selected = true;
     value.SelectionChanged();
     value.Invalidate();
     return(objs.Add(value));
 }
        public override void MouseDown(int x, int y, MouseButtons b, Keys modif, int realx, int realy)
        {
            // Left mouse button

            if (action != MouseAction.None)
            {
                return;
            }

            if (b == MouseButtons.Left)
            {
                if (current_operation == MouseOperation.DrawComment || current_operation == MouseOperation.DrawPackage)
                {
                    switch (current_operation)
                    {
                    case MouseOperation.DrawComment:
                        moveitem = GuiElementFactory.CreateMemo(parent, x, y);
                        break;

                    case MouseOperation.DrawPackage:
                        moveitem = GuiElementFactory.CreatePackage(parent, x, y);
                        break;
                    }

                    first_move = true;
                    moveux     = 0;
                    moveuy     = 0;
                    action     = MouseAction.Move;
                }
                else if ((modif & Keys.Control) == Keys.Control || current_operation == MouseOperation.DrawConnection)
                {
                    conn_item = parent.FindItem(x, y, out moveux, out moveuy, true) as IAcceptConnection;
                    if (conn_item == null)
                    {
                        action = MouseAction.Scroll;
                        selx   = x;
                        sely   = y;
                        return;
                    }

                    int   ux;
                    float uy;
                    conn_item.coord_nearest(x, y, out ux, out uy);
                    action = MouseAction.CreateConnection;

                    conn = new GuiConnection(new GuiConnectionPoint(conn_item, ux, uy, 0), new GuiConnectionPoint(x, y, 1), conn_type, parent, conn_type == UmlRelationType.Attachment ? GuiConnectionStyle.Line : conn_style);
                    conn.first.item.coord_nearest(x, y, out conn.first.ux, out conn.first.uy);
                    conn.first.UpdatePosition(true);
                    conn.DoCreationFixup();
                    conn.InvalidateTemporary();
                    conn.Invalidate();
                }
                else if ((modif & Keys.Shift) == Keys.Shift)
                {
                    GuiObject obj = parent.FindItem(x, y, false);
                    if (obj != null)
                    {
                        parent.SelectedObjects.Add(obj);
                        obj.Invalidate();
                    }
                }
                else
                {
                    //   Left button click:
                    //      select
                    //      move, move multiple

                    GuiObject s = parent.FindItem(x, y, out moveux, out moveuy, false);
                    if (s == null)
                    {
                        parent.SelectedObjects.Clear();
                        action = MouseAction.Select;
                        selx   = x;
                        sely   = y;
                        return;
                    }

                    if (!s.selected)
                    {
                        parent.SelectedObjects.Clear();
                        parent.SelectedObjects.Add(s);
                    }

                    // deciding: to move, or not ...

                    moveitem = null;
                    movelist = null;
                    movestates.Clear();
                    original_selected = null;
                    GuiObject t = parent.FindItem(x, y, out moveux, out moveuy, true);
                    if (t != null)
                    {
                        if (t is IMoveRedirect)
                        {
                            if (t.selected)
                            {
                                original_selected = t;
                            }
                            moveitem = (t as IMoveRedirect).MoveRedirect(ref moveux, ref moveuy);
                        }
                        else if (t is IMoveMultiple && (t as IMoveMultiple).CanMoveInGroup)
                        {
                            movelist = new ArrayList();
                            if (!t.selected)
                            {
                                movelist.Add(t);
                            }
                            foreach (GuiObject o in parent.SelectedObjects)
                            {
                                if (o is IMoveMultiple && (o as IMoveMultiple).CanMoveInGroup)
                                {
                                    movelist.Add(o);
                                }
                            }
                            selx = x;
                            sely = y;
                        }
                        else if (t is IMoveable && (t as IMoveable).IsMoveable(x, y))
                        {
                            moveitem = t as IMoveable;
                        }

                        if (moveitem != null || movelist != null)
                        {
                            first_move = true;
                            action     = MouseAction.Move;
                        }
                        else if (t is IClickable)
                        {
                            (t as IClickable).LeftClick(false, x, y);
                        }
                    }
                }
            }
            else if (b == MouseButtons.Right)
            {
                ISelectable obj = parent.FindItem(x, y, true) as ISelectable;
                if (obj != null)
                {
                    if (obj is IDropMenu)
                    {
                        parent.SelectedObjects.Clear();
                        parent.SelectedObjects.Add(obj as GuiObject);

                        System.Windows.Forms.ContextMenu m = new ContextMenu();
                        (obj as IDropMenu).AddMenuItems(m, x, y);
                        if (m.MenuItems.Count > 0)
                        {
                            m.Show(parent.cview, new Point(realx, realy));
                        }
                    }
                }
                else
                {
                    action         = MouseAction.Scroll;
                    Cursor.Current = Cursors.Hand;
                    selx           = x;
                    sely           = y;
                    menurealx      = realx;
                    menurealy      = realy;
                    first_move     = true;
                }
            }
        }