Example #1
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            sHelp = "";
            if (curDrawing != null)
            {
                float x1, y1;
                bool  bAdded;
                systemToCustomerXY(e.X, e.Y, out x1, out y1);
                System.Windows.Forms.MouseEventArgs e1  = new System.Windows.Forms.MouseEventArgs(e.Button, e.Clicks, (int)x1, (int)y1, e.Delta);
                System.Windows.Forms.DialogResult   ret = curDrawing.CallDlgDrawingsMouseDown(this, e1, ref nStep, this);
                switch (ret)
                {
                case System.Windows.Forms.DialogResult.OK:
                    if (nType == 0)
                    {
                        bAdded = this.DrawingLayers[0].AddDrawing(curDrawing);
                    }
                    else
                    {
                        bAdded = lstShapes.AddDrawing(curDrawing);
                        hs.SetDrawings(lstShapes);
                        formHS.Show();
                        formHS.TopMost = true;
                        formHS.Invalidate();
                    }
                    if (bAdded)
                    {
                        AddDrawing(curDrawing);
                    }
                    else
                    {
                    }
                    editor.SelectItem(curDrawing);
                    curDrawing.FinishDesign();
                    curDrawing = null;
                    nStep      = 0;
                    editor.Show();
                    break;

                case System.Windows.Forms.DialogResult.Cancel:
                    curDrawing.FinishDesign();
                    curDrawing = null;
                    nStep      = 0;
                    editor.Show();
                    break;

                case System.Windows.Forms.DialogResult.Retry:
                    nStep = 0;
                    break;

                case System.Windows.Forms.DialogResult.None:
                    break;
                }
                this.Invalidate();
            }
            else
            {
                Point       p    = new Point(e.X, e.Y);
                DrawingItem item = HitTest(p);
                if (item != null)
                {
                    SetItemSelection(item);
                    if (e.Button == MouseButtons.Right)
                    {
                        MenuItem[] menus = item.GetContextMenuItems(p);
                        if (menus != null && menus.Length > 0)
                        {
                            ContextMenu cm = new ContextMenu();
                            cm.MenuItems.AddRange(menus);
                            cm.Show(this, p);
                        }
                    }
                }
                else
                {
                    ClearMarks();
                    if ((e.Button & MouseButtons.Left) == MouseButtons.Left)
                    {
                        Type t = _toolBox.SelectedToolboxItem;
                        if (t != null)
                        {
                            DrawingItem newObj = (DrawingItem)Activator.CreateInstance(t);
                            if (_defaultDrawings == null)
                            {
                                _defaultDrawings = new DefaultDrawings();
                            }
                            DrawingItem def = _defaultDrawings.GetDefaultDrawing(newObj.GetType());
                            if (def != null)
                            {
                                newObj.Copy(def);
                            }
                            _toolBox.ClearToolboxSelection();
                            newObj.ResetGuid();
                            makeNewName(newObj);
                            newObj.Page     = this;
                            newObj.Location = p;
                            AddDrawing(newObj);
                            editor.SelectItem(newObj);
                            editor.RefreshPropertyGrids();
                            _newObj = newObj;
                            SetItemSelection(newObj);
                        }
                    }
                }
            }
        }