Пример #1
0
		public ISite CreateSite(IComponent comp, String name)
		{
			ISite site = new DesignerSite(_host, comp, this, name);
			Add(comp, name);
			comp.Site = site;
			_sites.Add(site);
			return site;
		}
Пример #2
0
        public ISite CreateSite(IComponent comp, String name)
        {
            ISite site = new DesignerSite(_host, comp, this, name);

            Add(comp, name);
            comp.Site = site;
            _sites.Add(site);
            return(site);
        }
Пример #3
0
        internal DesignerHost(BrowserTree objTree, Panel imagePanel)
        {
            _imagePanel = imagePanel;
            if (_host == null)
            {
                _host             = this;
                _serviceContainer = new ServiceContainer();
                _serviceContainer.AddService(typeof(IDesignerHost), _host);
                _serviceContainer.AddService(typeof(IUIService), _host);
                _serviceContainer.AddService(typeof(ISelectionService), _host);
                _serviceContainer.AddService(typeof(IToolboxService), new ToolboxService());
            }

            _container   = new DesignerContainer(this);
            _defaultSite = new DesignerSite(this, null, _container, "Default site");

            _designSurfaceSite = (DesignerSite)_container.CreateSite(_imagePanel, "Design Surface");

            // Hook the design surface to the ParentControlDesigner
            _parentControlDesigner      = new DummyDesigner();
            _imagePanel.Site            = _designSurfaceSite;
            _designSurfaceSite.Designer = _parentControlDesigner;
            _parentControlDesigner.Initialize(_imagePanel);

            // Used to make sure we don't give a designer for anything higher
            // than the design surface (GetDesigner is called on the
            // surface's parent)
            _designSurfaceParent = ((Control)_imagePanel).Parent;

            // Get the type for the UI selection service, since its private
            // the compiler will not let us see it
            _typeISelectionUIService = ReflectionHelper.GetType("System.Windows.Forms.Design.ISelectionUIService");

            // This is required to get an instance of the selection
            // UI service installed, we don't actually use this
            // designer for anything
            _fakePanel = new Panel();
            IDesigner compDes = new ComponentDocumentDesigner();

            _fakePanel.Site = _container.CreateSite(_fakePanel, "Fake Design Surface");
            compDes.Initialize(_fakePanel);

            // Make the size of the selection service cover the design
            // surface panel so that it will see all of the events
            _selUIService = (Control)GetService(_typeISelectionUIService);
            ObjectBrowser.ImagePanel.ResetSize(_selUIService);
            _imagePanel.Controls.Add(_selUIService);
            _imagePanel.SizeChanged += new EventHandler(ImagePanelSizeChange);

            DesignMode = true;

            // So we change the object selected when a control is selected
            SelectionChanged += new EventHandler(objTree.ControlSelectionChanged);
        }
Пример #4
0
		internal DesignerHost(BrowserTree objTree, Panel imagePanel)
		{
			_imagePanel = imagePanel;
			if (_host == null) {
				_host = this;
				_serviceContainer = new ServiceContainer();
				_serviceContainer.AddService(typeof(IDesignerHost), _host);
				_serviceContainer.AddService(typeof(IUIService), _host);
				_serviceContainer.AddService(typeof(ISelectionService), _host);
				_serviceContainer.AddService(typeof(IToolboxService), new ToolboxService());
			}

			_container = new DesignerContainer(this);
			_defaultSite = new DesignerSite(this, null, _container,	"Default site");

			_designSurfaceSite = (DesignerSite)_container.CreateSite(_imagePanel, "Design Surface");

			// Hook the design surface to the ParentControlDesigner
			_parentControlDesigner = new DummyDesigner();
			_imagePanel.Site = _designSurfaceSite;
			_designSurfaceSite.Designer = _parentControlDesigner;
			_parentControlDesigner.Initialize(_imagePanel);

			// Used to make sure we don't give a designer for anything higher
			// than the design surface (GetDesigner is called on the 
			// surface's parent)
			_designSurfaceParent = ((Control)_imagePanel).Parent;

			// Get the type for the UI selection service, since its private
			// the compiler will not let us see it
			_typeISelectionUIService = ReflectionHelper.GetType("System.Windows.Forms.Design.ISelectionUIService");

			// This is required to get an instance of the selection 
			// UI service installed, we don't actually use this 
			// designer for anything
			_fakePanel = new Panel();
			IDesigner compDes = new ComponentDocumentDesigner();
			_fakePanel.Site = _container.CreateSite(_fakePanel, "Fake Design Surface");
			compDes.Initialize(_fakePanel);

			// Make the size of the selection service cover the design
			// surface panel so that it will see all of the events
			_selUIService = (Control)GetService(_typeISelectionUIService);
			ObjectBrowser.ImagePanel.ResetSize(_selUIService);
			_imagePanel.Controls.Add(_selUIService);
			_imagePanel.SizeChanged += new EventHandler(ImagePanelSizeChange);

			DesignMode = true;

			// So we change the object selected when a control is selected
			SelectionChanged += new EventHandler(objTree.ControlSelectionChanged);
		}
Пример #5
0
        internal IDesigner GetDesigner(IComponent comp, ObjectInfo objInfo)
        {
            Console.WriteLine("Designer - GetDesigner - start  " + comp + " " + objInfo + " ");
            DesignerAttribute da = null;

            if (comp == null)
            {
                return(null);
            }

            // For sites that are not ours, we don't treat them, unless
            // we are adding controls, we use our site instead
            if (comp.Site != null && !(comp.Site is DesignerSite))
            {
                if (_addingControls)
                {
                    comp.Site = null;
                }
                else
                {
                    Console.WriteLine("Designer - GetDesigner - not ours " + comp.Site);
                    return(null);
                }
            }

            DesignerSite site = (DesignerSite)comp.Site;

            // Don't allow getting a designer for anything higher than the
            // design surface
            if (comp == _designSurfaceParent)
            {
                return(null);
            }

            if (site == null)
            {
                String name;
                if (objInfo != null)
                {
                    name = objInfo.ObjectName;
                }
                else
                {
                    name = CompNumber.GetCompName(comp.GetType());
                }
                Console.WriteLine("Comp.name: ", name);
                site = (DesignerSite)_container.CreateSite(comp, name);
            }

            if (site.Designer != null)
            {
                return(site.Designer);
            }

            IList attrs = Attribute.GetCustomAttributes(comp.GetType(), typeof(DesignerAttribute));
            bool  found = false;

            foreach (Attribute attr in attrs)
            {
                da = attr as DesignerAttribute;
                Console.WriteLine("Designer - GetDesigner da "
                                  + da.DesignerBaseTypeName
                                  + " " + da.DesignerTypeName);
                if (da.DesignerBaseTypeName.StartsWith("System.ComponentModel.Design.IRootDesigner"))
                {
                    found = true;
                    break;
                }
            }

            // Just take the first one if we did not find a root designer
            if (!found && attrs.Count > 0)
            {
                da = attrs[0] as DesignerAttribute;
            }

            if (da != null)
            {
                Type t = GetType(da.DesignerTypeName);
                Console.WriteLine("DesignerType: " + t.FullName);
                IDesigner d = (IDesigner)Activator.CreateInstance(t);
                if (_addingControls)
                {
                    d.Initialize(comp);
                }
                site.Designer = d;
                if (comp is Control)
                {
                    site.DesignWindowTarget = ((Control)comp).WindowTarget;
                }
                Console.WriteLine("Designer  - GetDesigner " + site + " " + d);
                return(d);
            }
            Console.WriteLine("Designer  - GetDesigner NOT FOUND " + comp);
            return(null);
        }