Пример #1
0
        internal void InitializeHost(HostSurface hostSurface)
        {
            try
            {
                if (hostSurface == null)
                {
                    return;
                }

                _hostSurface = hostSurface;

                Control control = _hostSurface.View as Control;

                control.Parent      = this;
                control.Dock        = DockStyle.Fill;
                control.Visible     = true;
                control.MouseEnter += new EventHandler(HostControl_MouseEnter);
                //
                if (!(DesignerHost.RootComponent is Control) && !(DesignerHost.RootComponent is NewComponentPrompt))
                {
                    if (control.Controls.Count > 0)
                    {
                        if (control.Controls[0] != null)
                        {
                            control.Controls[0].Text   = "";
                            control.Controls[0].Paint += new PaintEventHandler(HostControl_Paint);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.ToString());
            }
        }
Пример #2
0
        public HostControl3(HostSurface hostSurface, LimnorXmlDesignerLoader2 loader)
        {
            _loader    = loader;
            _pane      = new MultiPanes();
            _pane.Dock = DockStyle.Fill;
            FormViewer fv = new FormViewer(hostSurface.View as Control);

            _pane.AddViewer(fv);
        }
Пример #3
0
 public HostControl3(HostSurface hostSurface)
 {
     // This call is required by the Windows.Forms Form Designer.
     InitializeComponent();
     InitializeHost(hostSurface);
     //
     _componentTextFormat               = new StringFormat();
     _componentTextFormat.Alignment     = StringAlignment.Center;
     _componentTextFormat.LineAlignment = StringAlignment.Center;
     _componentTextFormat.Trimming      = StringTrimming.None;
     _componentTextFormat.FormatFlags   = StringFormatFlags.MeasureTrailingSpaces;
     //
     _componentTextFont = new Font("Times New Roman", 12);
 }
        private void mi_addComponent(object sender, EventArgs e)
        {
            IDesignerHost host = (IDesignerHost)this.GetService(typeof(IDesignerHost));

            if (host != null)
            {
                HostSurface surface = host.GetService(typeof(DesignSurface)) as HostSurface;
                if (surface != null)
                {
                    ClassPointer root = surface.Loader.GetRootId();
                    if (root != null)
                    {
                        root.AddComponent(null);
                    }
                }
            }
        }
        private void editWebPage(object sender, EventArgs e)
        {
            MenuItem mi = sender as MenuItem;

            if (mi != null)
            {
                IWebPage page = mi.Tag as IWebPage;
                if (page != null)
                {
                    IDesignerHost host = (IDesignerHost)this.GetService(typeof(IDesignerHost));
                    if (host != null)
                    {
                        HostSurface surface = host.GetService(typeof(DesignSurface)) as HostSurface;
                        if (surface != null)
                        {
                            ClassPointer root = surface.Loader.GetRootId();
                            root.EditWebPage();
                        }
                    }
                }
            }
        }
        private void mi_loadDrawing(object sender, EventArgs e)
        {
            MenuItem mi = sender as MenuItem;

            if (mi != null)
            {
                IDrawDesignControl drc = mi.Tag as IDrawDesignControl;
                if (drc != null && drc.Item != null)
                {
                    IDesignerHost host = (IDesignerHost)this.GetService(typeof(IDesignerHost));
                    if (host != null)
                    {
                        HostSurface surface = host.GetService(typeof(DesignSurface)) as HostSurface;
                        if (surface != null)
                        {
                            ClassPointer root = surface.Loader.GetRootId();
                            if (root != null)
                            {
                                ILimnorDesignerLoader ldp = root.GetDesignerLoader();
                                if (ldp != null)
                                {
                                    IDesignPane    idp = ldp.DesignPane as IDesignPane;
                                    OpenFileDialog dlg = new OpenFileDialog();
                                    dlg.CheckFileExists = true;
                                    dlg.DefaultExt      = ".xml";
                                    dlg.Filter          = "XML files|*.xml";
                                    dlg.Title           = "Select XML file for loading drawing";
                                    if (dlg.ShowDialog(drc.Item.Page) == DialogResult.OK)
                                    {
                                        drc.Item.LoadDrawingsFromFile(dlg.FileName, idp, drc);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        private void showDrawingBoard(object sender, EventArgs e)
        {
            MenuItem mi = sender as MenuItem;

            if (mi != null)
            {
                DrawingPage page = mi.Tag as DrawingPage;
                if (page != null)
                {
                    IDesignerHost host = (IDesignerHost)this.GetService(typeof(IDesignerHost));
                    if (host != null)
                    {
                        HostSurface surface = host.GetService(typeof(DesignSurface)) as HostSurface;
                        if (surface != null)
                        {
                            ClassPointer           root   = surface.Loader.GetRootId();
                            DrawingLayerCollection layers = page.ShowDrawingsEditor();
                            if (layers != null)
                            {
                                //layers0 is the existing layer collections
                                DrawingLayerCollection layers0 = page.DrawingLayers;
                                //for layers0 if a drawing object's guid does not exist in layers then
                                //the object has been deleted
                                List <DrawingItem> deleted = new List <DrawingItem>();
                                foreach (DrawingLayer l0 in layers0)
                                {
                                    DrawingItem d = null;
                                    for (int i = 0; i < l0.Count; i++)
                                    {
                                        DrawingItem d0 = l0[i];
                                        d = layers.GetDrawingItemById(d0.DrawingId);
                                        if (d != null)
                                        {
                                            d0.Copy(d);                                            //not deleted
                                            //move and resize the IDrawDesignControl
                                            foreach (Control c in page.Controls)
                                            {
                                                IDrawDesignControl dc0 = c as IDrawDesignControl;
                                                if (dc0 != null)
                                                {
                                                    if (dc0.Item == d0)
                                                    {
                                                        c.Location = d0.Location;
                                                        c.Size     = d0.Bounds.Size;
                                                        break;
                                                    }
                                                }
                                            }
                                        }
                                        else
                                        {
                                            deleted.Add(d0);                                             //deleted
                                        }
                                    }
                                }
                                if (deleted.Count > 0)
                                {
                                    //check to see if each deleted item has usages
                                    List <DrawingItem> ls = new List <DrawingItem>();
                                    foreach (DrawingItem d0 in deleted)
                                    {
                                        for (int i = 0; i < page.Controls.Count; i++)
                                        {
                                            IDrawDesignControl dc = page.Controls[i] as IDrawDesignControl;
                                            if (dc != null)
                                            {
                                                if (dc.DrawingId == d0.DrawingId)
                                                {
                                                    uint id = root.ObjectList.GetObjectID(dc);
                                                    if (id == 0)
                                                    {
                                                        DesignUtil.WriteToOutputWindow("id not found on deleting component {0}", dc.Name);
                                                    }
                                                    else
                                                    {
                                                        List <ObjectTextID> list = root.GetComponentUsage(id);
                                                        if (list.Count > 0)
                                                        {
                                                            dlgObjectUsage dlg = new dlgObjectUsage();
                                                            dlg.LoadData("Cannot delete this component. It is being used by the following objects", string.Format("Component - {0}", dc.Name), list);
                                                            dlg.ShowDialog();
                                                            ls.Add(d0);
                                                        }
                                                    }
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                    if (ls.Count > 0)
                                    {
                                        foreach (DrawingItem d0 in ls)
                                        {
                                            deleted.Remove(d0);
                                        }
                                    }
                                    foreach (DrawingItem d0 in deleted)
                                    {
                                        for (int i = 0; i < page.Controls.Count; i++)
                                        {
                                            IDrawDesignControl dc = page.Controls[i] as IDrawDesignControl;
                                            if (dc != null)
                                            {
                                                if (dc.DrawingId == d0.DrawingId)
                                                {
                                                    surface.Loader.DeleteComponent(page.Controls[i]);
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                }
                                //for a drawing object in layers if its guid does not exist in layers0 then
                                //it is a new object
                                //reset zorder according to the new layers
                                List <Control> ctrls = new List <Control>();
                                foreach (DrawingLayer l in layers)
                                {
                                    int zOrder = 0;
                                    foreach (DrawingItem d in l)
                                    {
                                        DrawingItem d0 = layers0.GetDrawingItemById(d.DrawingId);
                                        if (d0 == null)
                                        {
                                            //add a new drawing
                                            string name         = d.Name + Guid.NewGuid().GetHashCode().ToString("x");
                                            Type   designerType = TypeMappingAttribute.GetMappedType(d.GetType());
                                            if (designerType == null)
                                            {
                                                throw new DesignerException("Drawing type {0} does not have a designer", d.GetType());
                                            }
                                            Control            dc  = (Control)surface.Loader.CreateComponent(designerType, name);
                                            IDrawDesignControl ddc = (IDrawDesignControl)dc;
                                            ddc.Item    = d;
                                            dc.Location = d.Location;
                                            dc.Size     = d.Bounds.Size;
                                            ctrls.Add(dc);
                                            ddc.ZOrder = zOrder;
                                        }
                                        else
                                        {
                                            for (int k = 0; k < page.Controls.Count; k++)
                                            {
                                                IDrawDesignControl dc = page.Controls[k] as IDrawDesignControl;
                                                if (dc != null)
                                                {
                                                    if (dc.Item == d0)
                                                    {
                                                        dc.ZOrder = zOrder;
                                                        break;
                                                    }
                                                }
                                            }
                                        }
                                        zOrder += 10;
                                    }
                                }
                                if (ctrls.Count > 0)
                                {
                                    page.Controls.AddRange(ctrls.ToArray());
                                }
                                page.LoadData(layers, false);
                                page.Refresh();
                                surface.SetModified();
                                surface.Loader.NotifyChanges();
                            }
                        }
                    }
                }
            }
        }
        /// This is called whenever the user right-clicks on a designer. It removes any local verbs
        /// added by a previous, different selection and adds the local verbs for the current (primary)
        /// selection. Then it displays the ContextMenu.
        public override void ShowContextMenu(CommandID menuID, int x, int y)
        {
            ISelectionService ss = this.GetService(typeof(ISelectionService)) as ISelectionService;

            if (ss == null || ss.PrimarySelection == null)
            {
                return;
            }
            IDesignerHost host = (IDesignerHost)this.GetService(typeof(IDesignerHost));

            //
            if (host != null)
            {
                HostSurface surface = host.GetService(typeof(DesignSurface)) as HostSurface;
                if (surface != null)
                {
                    ContextMenu menu = new ContextMenu();
                    if (host.RootComponent != ss.PrimarySelection && ss.PrimarySelection is Control)
                    {
                        MenuItem mi = new MenuItem("Bring to front", menu_bringToFront);
                        mi.Tag = ss.PrimarySelection;
                        menu.MenuItems.Add(mi);
                        //
                        mi     = new MenuItem("Send to back", menu_sendToBack);
                        mi.Tag = ss.PrimarySelection;
                        menu.MenuItems.Add(mi);
                        //
                        menu.MenuItems.Add("-");
                    }
                    if (host.RootComponent != ss.PrimarySelection)
                    {
                        MenuItem mi = new MenuItem("Copy", menu_cmd);
                        mi.Tag = StandardCommands.Copy;
                        menu.MenuItems.Add(mi);
                        //
                        mi     = new MenuItem("Cut", menu_cmd);
                        mi.Tag = StandardCommands.Cut;
                        menu.MenuItems.Add(mi);
                        //
                        mi     = new MenuItem("Delete", menu_cmd);
                        mi.Tag = StandardCommands.Delete;
                        menu.MenuItems.Add(mi);
                        //
                        if (ss.SelectionCount == 1)
                        {
                            MenuItem mi2 = new MenuItemWithBitmap("Add to toolbar", addToToolbar, Resource1._toolbar.ToBitmap());
                            IXType   ix  = ss.PrimarySelection as IXType;
                            if (ix != null)
                            {
                                mi2.Tag = ix.ValueType;
                            }
                            else
                            {
                                mi2.Tag = ss.PrimarySelection.GetType();
                            }
                            menu.MenuItems.Add(mi2);
                        }
                    }
                    else
                    {
                        MenuItem mi = new MenuItem("Undo", menu_cmd);
                        mi.Tag = StandardCommands.Undo;
                        menu.MenuItems.Add(mi);
                        //
                        mi     = new MenuItem("Redo", menu_cmd);
                        mi.Tag = StandardCommands.Redo;
                        menu.MenuItems.Add(mi);
                        //
                        mi     = new MenuItem("Paste", menu_cmd);
                        mi.Tag = StandardCommands.Paste;
                        menu.MenuItems.Add(mi);
                    }
                    //
                    DrawingPage dp = ss.PrimarySelection as DrawingPage;
                    if (dp != null)
                    {
                        MenuItem mi2 = new MenuItem("-");
                        menu.MenuItems.Add(mi2);
                        //
                        mi2     = new MenuItemWithBitmap("Drawing Board", showDrawingBoard, Resource1._paint.ToBitmap());
                        mi2.Tag = dp;
                        menu.MenuItems.Add(mi2);
                    }
                    else
                    {
                        IDrawDesignControl drc = ss.PrimarySelection as IDrawDesignControl;
                        if (drc != null)
                        {
                            MenuItem midrc = new MenuItemWithBitmap("Copy to Clipboard as bitmap image", mi_copyDrawing, Resource1._copy.ToBitmap());
                            midrc.Tag = drc;
                            menu.MenuItems.Add(midrc);
                            midrc     = new MenuItemWithBitmap("Save to XML file", mi_savedrawing, Resource1._savefile.ToBitmap());
                            midrc.Tag = drc;
                            menu.MenuItems.Add(midrc);
                            midrc     = new MenuItemWithBitmap("Load from XML file", mi_loadDrawing, Resource1._loadfile.ToBitmap());
                            midrc.Tag = drc;
                            menu.MenuItems.Add(midrc);
                        }
                    }
                    MenuItem mi20 = new MenuItem("-");
                    menu.MenuItems.Add(mi20);
                    MenuItem miAddComponent = new MenuItemWithBitmap("Add component", mi_addComponent, Resource1._newIcon.ToBitmap());
                    menu.MenuItems.Add(miAddComponent);
                    //
                    LimnorContextMenuCollection mdata = surface.GetObjectMenuData(ss.PrimarySelection);
                    if (mdata != null)
                    {
                        if (menu.MenuItems.Count > 0)
                        {
                            menu.MenuItems.Add("-");
                        }
                        mdata.CreateContextMenu(menu, new Point(0, 0), surface.Loader.ViewerHolder);
                    }

                    if (menu.MenuItems.Count > 0)
                    {
                        Control ps = surface.View as Control;
                        if (ps != null)
                        {
                            LimnorXmlDesignerLoader2.MenuPoint = new Point(x, y);
                            Point s = ps.PointToClient(LimnorXmlDesignerLoader2.MenuPoint);
                            menu.Show(ps, s);
                        }
                        else
                        {
                            ps = ss.PrimarySelection as Control;
                            if (ps != null)
                            {
                                LimnorXmlDesignerLoader2.MenuPoint = new Point(x, y);
                                Point s = ps.PointToScreen(new Point(0, 0));
                                menu.Show(ps, new Point(x - s.X, y - s.Y));
                            }
                        }
                    }
                }
            }
        }
        public ILimnorDesignPane CreateDesigner(ClassData classData)
        {
            ILimnorDesignPane limnorXmlPane = null;

            try
            {
                DesignUtil.LogIdeProfile("Create designer loader");
                LimnorXmlDesignerLoader2 designerLoader = new LimnorXmlDesignerLoader2(classData);
                DesignUtil.LogIdeProfile("Create designer surface");
                HostSurface designSurface = (HostSurface)this.CreateDesignSurface(this.ServiceContainer);

                IDesignerHost dh = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));

                dh.AddService(typeof(INameCreationService), new NameCreationService());

                IServiceContainer serviceContainer = dh.GetService(typeof(ServiceContainer)) as IServiceContainer;
                DesignUtil.LogIdeProfile("Load designer surface");
                designSurface.Loader = designerLoader;
                designSurface.BeginLoad(designerLoader);
                if (VPLUtil.Shutingdown)
                {
                    return(null);
                }
                DesignUtil.LogIdeProfile("Add designer services");
                XMenuCommandService menuServices = new XMenuCommandService(serviceContainer);
                dh.AddService(typeof(IMenuCommandService), menuServices);
                menuServices.AddVerb(new DesignerVerb("Cut", null, StandardCommands.Cut));
                menuServices.AddVerb(new DesignerVerb("Copy", null, StandardCommands.Copy));
                menuServices.AddVerb(new DesignerVerb("Paste", null, StandardCommands.Paste));
                menuServices.AddVerb(new DesignerVerb("Delete", null, StandardCommands.Delete));
                menuServices.AddVerb(new DesignerVerb("Undo", null, StandardCommands.Undo));
                menuServices.AddVerb(new DesignerVerb("Redo", null, StandardCommands.Redo));

                if (dh.GetService(typeof(IDesignerSerializationService)) == null)
                {
                    dh.AddService(typeof(IDesignerSerializationService), new DesignerSerializationService(serviceContainer));
                }

                if (dh.GetService(typeof(ComponentSerializationService)) == null)
                {
                    //DesignerSerializationService uses CodeDomComponentSerializationService
                    CodeDomComponentSerializationService codeDomComponentSerializationService = new CodeDomComponentSerializationService(serviceContainer);
                    dh.AddService(typeof(ComponentSerializationService), codeDomComponentSerializationService);
                }
                VOB.UndoEngineImpl undoEngine = new VOB.UndoEngineImpl(serviceContainer);
                undoEngine.Enabled = false;
                dh.AddService(typeof(UndoEngine), undoEngine);

                designerLoader.AddComponentChangeEventHandler();
                DesignUtil.LogIdeProfile("Create designer pane");
                limnorXmlPane = new LimnorXmlPane2(designSurface, designerLoader);
                if (designerLoader.IsSetup)
                {
                }
                else
                {
                    DesignUtil.LogIdeProfile("Apply config");
                    if (limnorXmlPane.Loader.ObjectMap != null)
                    {
                        limnorXmlPane.BeginApplyConfig();
                    }
                }
                DesignUtil.LogIdeProfile("Initialize designer surface");
                designSurface.Initialize();
                ILimnorToolbox toolbox = (ILimnorToolbox)GetService(typeof(IToolboxService));
                toolbox.Host             = dh;
                this.ActiveDesignSurface = designSurface;
                //
            }
            catch (Exception ex)
            {
                MathNode.Log(TraceLogClass.MainForm, ex);
                // Just rethrow for now
                throw;
            }
            DesignUtil.LogIdeProfile("Finish creating designer");
            return(limnorXmlPane);
        }