Esempio n. 1
0
 public void CancelPaste()
 {
     if (FMode1 == WorkspaceMode1.Insert)
     {
         while (Designer.SelectedObjects.Count > 0)
         {
             Base c = Designer.SelectedObjects[0];
             Designer.SelectedObjects.Remove(c);
             Designer.Objects.Remove(c);
             c.Dispose();
         }
         FMode1 = WorkspaceMode1.Select;
         FMode2 = WorkspaceMode2.None;
         OnMouseUp(new MouseEventArgs(MouseButtons.None, 0, 0, 0, 0));
     }
 }
Esempio n. 2
0
        public void Paste(ObjectCollection list, InsertFrom source)
        {
            FInsertionSource = source;
            // find left-top edge of inserted objects
            float minLeft = 100000;
            float minTop  = 100000;

            foreach (Base c in list)
            {
                if (c is ComponentBase)
                {
                    ComponentBase c1 = c as ComponentBase;
                    if (c1.Left < minLeft)
                    {
                        minLeft = c1.Left;
                    }
                    if (c1.Top < minTop)
                    {
                        minTop = c1.Top;
                    }
                }
            }
            foreach (Base c in list)
            {
                // correct the left-top
                if (c is ComponentBase)
                {
                    ComponentBase c1 = c as ComponentBase;
                    c1.Left -= minLeft + Grid.SnapSize * 1000;
                    c1.Top  -= minTop + Grid.SnapSize * 1000;
                }
            }
            FMode1 = WorkspaceMode1.Insert;
            FMode2 = WorkspaceMode2.Move;
            FEventArgs.ActiveObject = null;
            OnMouseDown(new MouseEventArgs(MouseButtons.Left, 0,
                                           Offset.X + 10 - Grid.SnapSize * 1000, Offset.Y + 10 - Grid.SnapSize * 1000, 0));
        }
Esempio n. 3
0
        protected override void OnDragOver(DragEventArgs drgevent)
        {
            base.OnDragOver(drgevent);
            if (!Designer.cmdInsert.Enabled)
            {
                drgevent.Effect = DragDropEffects.None;
                return;
            }

            if (FMode1 != WorkspaceMode1.DragDrop)
            {
                DictionaryWindow.DraggedItem item = (DictionaryWindow.DraggedItem)drgevent.Data.GetData(
                    typeof(DictionaryWindow.DraggedItem));

                Type dataType = null;
                if (item.Obj is Column)
                {
                    dataType = (item.Obj as Column).DataType;
                }
                else if (item.Obj is Parameter)
                {
                    dataType = (item.Obj as Parameter).DataType;
                }

                // determine type of control to insert
                Type controlType = typeof(NumericUpDownControl);
                if (dataType == typeof(string) || dataType == typeof(char))
                {
                    controlType = typeof(TextBoxControl);
                }
                else if (dataType == typeof(DateTime) || dataType == typeof(TimeSpan))
                {
                    controlType = typeof(DateTimePickerControl);
                }
                else if (dataType == typeof(bool))
                {
                    controlType = typeof(CheckBoxControl);
                }
                else if (dataType == typeof(byte[]))
                {
                    controlType = null;
                }

                if (controlType == null)
                {
                    drgevent.Effect = DragDropEffects.None;
                    return;
                }

                // create label and control
                bool needCreateLabel = controlType != typeof(CheckBoxControl);
                if (needCreateLabel)
                {
                    Designer.InsertObject(new ObjectInfo[] {
                        RegisteredObjects.FindObject(controlType),
                        RegisteredObjects.FindObject(typeof(LabelControl))
                    }, InsertFrom.Dictionary);
                }
                else
                {
                    Designer.InsertObject(RegisteredObjects.FindObject(controlType), InsertFrom.Dictionary);
                }

                // setup control datafiltering
                DataFilterBaseControl control = Designer.SelectedObjects[0] as DataFilterBaseControl;
                control.Top += (16 / Grid.SnapSize) * Grid.SnapSize;
                if (item.Obj is Column)
                {
                    control.DataColumn = item.Text;
                }
                else if (item.Obj is Parameter)
                {
                    control.ReportParameter = item.Text;
                }

                // setup label text
                string labelText = "";
                if (item.Obj is Column)
                {
                    labelText = (item.Obj as Column).Alias;
                }
                else if (item.Obj is Parameter)
                {
                    labelText = (item.Obj as Parameter).Description;
                    if (String.IsNullOrEmpty(labelText))
                    {
                        labelText = (item.Obj as Parameter).Name;
                    }
                }

                if (needCreateLabel)
                {
                    LabelControl label = Designer.SelectedObjects[1] as LabelControl;
                    label.Text = labelText;
                }
                else
                {
                    control.Text = labelText;
                }

                FEventArgs.DragSource = control;
            }

            FMode1 = WorkspaceMode1.DragDrop;
            Point pt = PointToClient(new Point(drgevent.X, drgevent.Y));

            OnMouseMove(new MouseEventArgs(MouseButtons.Left, 0, pt.X, pt.Y, 0));
            drgevent.Effect = drgevent.AllowedEffect;
        }
Esempio n. 4
0
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);
            if (Locked)
            {
                return;
            }

            ObjectCollection selectedObjects = new ObjectCollection();

            Designer.SelectedObjects.CopyTo(selectedObjects);
            HideToolTip();

            FEventArgs.X       = e.X - Offset.X;
            FEventArgs.Y       = e.Y - Offset.Y;
            FEventArgs.Button  = e.Button;
            FEventArgs.Mode    = FMode2;
            FEventArgs.Handled = false;

            if (FMode2 == WorkspaceMode2.Move || FMode2 == WorkspaceMode2.Size)
            {
                // serve all objects
                for (int i = 0; i < Designer.Objects.Count; i++)
                {
                    ComponentBase c = Designer.Objects[i] as ComponentBase;
                    if (c != null)
                    {
                        c.HandleMouseUp(FEventArgs);
                    }
                }
                // remove objects with zero size
                if (FMode1 == WorkspaceMode1.Insert)
                {
                    int i = 0;
                    while (i < Designer.SelectedObjects.Count)
                    {
                        ComponentBase c = Designer.SelectedObjects[i] as ComponentBase;
                        if (c != null && c.Width == 0 && c.Height == 0)
                        {
                            Designer.Objects.Remove(c);
                            Designer.SelectedObjects.Remove(c);
                            c.Dispose();
                            i--;
                        }
                        i++;
                    }
                }
                if (FMode1 != WorkspaceMode1.Select)
                {
                    // during OnInsert call current context may be changed
                    WorkspaceMode1 saveMode = FMode1;
                    FMode1 = WorkspaceMode1.Select;
                    ObjectCollection insertedObjects = new ObjectCollection();
                    Designer.SelectedObjects.CopyTo(insertedObjects);
                    foreach (Base c in insertedObjects)
                    {
                        c.OnAfterInsert(FInsertionSource);
                    }
                    FMode1 = saveMode;
                }

                // check if we actually move a mouse after we clicked it
                if (FMouseMoved || FMode1 == WorkspaceMode1.Insert)
                {
                    Designer.SetModified(FPageDesigner,
                                         FMode1 == WorkspaceMode1.Insert ? "Insert" : FMode2 == WorkspaceMode2.Move ? "Move" : "Size");
                }
            }
            else if (FMode2 == WorkspaceMode2.SelectionRect)
            {
                FEventArgs.SelectionRect = NormalizeSelectionRect();
                if (FEventArgs.ActiveObject != null)
                {
                    FEventArgs.ActiveObject.HandleMouseUp(FEventArgs);
                }
            }
            else if (FMode2 == WorkspaceMode2.Custom)
            {
                if (FEventArgs.ActiveObject != null)
                {
                    FEventArgs.ActiveObject.HandleMouseUp(FEventArgs);
                }
            }

            bool needReset = FMode1 == WorkspaceMode1.Insert;

            if (!selectedObjects.Equals(Designer.SelectedObjects) || needReset)
            {
                Designer.SelectionChanged(FPageDesigner);
            }

            FMouseDown = false;
            FMode1     = WorkspaceMode1.Select;
            FMode2     = WorkspaceMode2.None;
            FGuides.ClearVirtualGuides();
            Refresh();
            if (needReset)
            {
                Designer.ResetObjectsToolbar(false);
            }

            if (e.Button == MouseButtons.Right && Designer.SelectedObjects.Count > 0)
            {
                ContextMenuBar menu = Designer.SelectedObjects[0].GetContextMenu();
                if (menu != null)
                {
                    PopupItem item = menu.Items[0] as PopupItem;
                    item.PopupMenu(PointToScreen(e.Location));
                }
            }
        }