예제 #1
0
 public void SetDesigner(IRootDesigner document)
 {
     if (this.designerView != null)
     {
         base.Controls.Clear();
         this.designerView.Dispose();
         this.designerView = null;
     }
     if (document != null)
     {
         ViewTechnology[] technologies        = document.SupportedTechnologies;
         bool             supportedTechnology = false;
         foreach (ViewTechnology tech in technologies)
         {
             if (tech == ViewTechnology.WindowsForms)
             {
                 {
                     this.designerView      = (Control)document.GetView(ViewTechnology.WindowsForms);
                     this.designerView.Dock = DockStyle.Fill;
                     base.Controls.Add(this.designerView);
                     supportedTechnology = true;
                 }
             }
             if (supportedTechnology)
             {
                 break;
             }
         }
         if (!supportedTechnology)
         {
             throw new Exception("Unsupported Technology " + this.designerHost.RootComponent.GetType().FullName);
         }
     }
 }
 public void SetDesigner(IRootDesigner document)
 {
     if (this.designerView != null)
     {
         base.Controls.Clear();
         this.designerView.Dispose();
         this.designerView = null;
     }
     if (document != null)
     {
         ViewTechnology[] technologies = document.SupportedTechnologies;
         bool supportedTechnology = false;
         foreach (ViewTechnology tech in technologies)
         {
             if(tech==ViewTechnology.WindowsForms)
             {
                 {
                     this.designerView = (Control) document.GetView(ViewTechnology.WindowsForms);
                     this.designerView.Dock = DockStyle.Fill;
                     base.Controls.Add(this.designerView);
                     supportedTechnology = true;
                 }
             }
             if (supportedTechnology)
             {
                 break;
             }
         }
         if (!supportedTechnology)
         {
             throw new Exception("Unsupported Technology " + this.designerHost.RootComponent.GetType().FullName);
         }
     }
 }
예제 #3
0
        public void ReloadWorkflowOutline()
        {
            this.OnBeginUpdate();
            this.treeView.BeginUpdate();
            try
            {
                this.treeView.Nodes.Clear();
                this.activityToNodeMapping.Clear();
                IRootDesigner safeRootDesigner = ActivityDesigner.GetSafeRootDesigner(this.serviceProvider);
                if (((safeRootDesigner != null) && (safeRootDesigner.Component != null)) && (safeRootDesigner.Component is Activity))
                {
                    this.InsertDocOutlineNode(null, safeRootDesigner.Component as Activity, 0, true);
                }
                if (this.NeedsExpandAll)
                {
                    this.treeView.ExpandAll();
                }
            }
            finally
            {
                this.treeView.EndUpdate();
            }
            this.IsDirty = false;
            ISelectionService service = this.GetService(typeof(ISelectionService)) as ISelectionService;

            if ((service != null) && (service.PrimarySelection != null))
            {
                this.treeView.SelectedNode = this.activityToNodeMapping[service.PrimarySelection] as WorkflowOutlineNode;
                if (this.treeView.SelectedNode != null)
                {
                    this.treeView.SelectedNode.EnsureVisible();
                }
            }
            this.OnEndUpdate();
        }
예제 #4
0
        private void Initialize()
        {
            // Initialise service container and designer host
            serviceContainer = new ServiceContainer();
            serviceContainer.AddService(typeof(INameCreationService), new NameCreationService());
            serviceContainer.AddService(typeof(IUIService), new UIService(this));
            host = new DesignerHost(serviceContainer);

            // Add toolbox service
            serviceContainer.AddService(typeof(IToolboxService), lstToolbox);
            lstToolbox.designPanel = pnlViewHost;
            PopulateToolbox(lstToolbox);

            // Add menu command service
            menuService = new MenuCommandService();
            serviceContainer.AddService(typeof(IMenuCommandService), menuService);

            // Start the designer host off with a Form to design
            form          = (Form)host.CreateComponent(typeof(Form));
            form.TopLevel = false;
            form.Text     = "Form1";


            // Get the root designer for the form and add its design view to this form
            rootDesigner = (IRootDesigner)host.GetDesigner(form);
            view         = (Control)rootDesigner.GetView(ViewTechnology.Default);//.WindowsForms);
            view.Dock    = DockStyle.Fill;
            pnlViewHost.Controls.Add(view);

            // Subscribe to the selectionchanged event and activate the designer
            ISelectionService s = (ISelectionService)serviceContainer.GetService(typeof(ISelectionService));

            s.SelectionChanged += new EventHandler(OnSelectionChanged);
            host.Activate();
        }
예제 #5
0
        private void GetView()
        {
            IRootDesigner rd = (IRootDesigner)host.GetDesigner(host.RootComponent);

            this.view = (RootDesignerView)rd.GetView(ViewTechnology.Passthrough);

            view.BeginLoad();
            System.Diagnostics.Trace.WriteLine("Document created.");
        }
        public void LoadWorkflow(string xoml, string ruleSetXml)
        {
            SuspendLayout();

            DesignSurface  designSurface = new DesignSurface();
            WorkflowLoader loader        = new WorkflowLoader();

            loader.RuleSetXml = ruleSetXml;
            loader.Xoml       = xoml;
            designSurface.BeginLoad(loader);

            IDesignerHost designerHost = designSurface.GetService(typeof(IDesignerHost)) as IDesignerHost;

            if (designerHost != null && designerHost.RootComponent != null)
            {
                IRootDesigner rootDesigner = designerHost.GetDesigner(designerHost.RootComponent) as IRootDesigner;
                if (rootDesigner != null)
                {
                    UnloadWorkflow();

                    this.designSurface = designSurface;
                    this.loader        = loader;
                    this.workflowView  = rootDesigner.GetView(ViewTechnology.Default) as WorkflowView;
                    this.workflowViewSplitter.Panel2.Controls.Add(this.workflowView);
                    this.workflowView.Dock               = DockStyle.Fill;
                    this.workflowView.TabIndex           = 1;
                    this.workflowView.TabStop            = true;
                    this.workflowView.HScrollBar.TabStop = false;
                    this.workflowView.VScrollBar.TabStop = false;
                    this.workflowView.Focus();
                    this.propertyGrid.Site = designerHost.RootComponent.Site;

                    ISelectionService selectionService = GetService(typeof(ISelectionService)) as ISelectionService;
                    if (selectionService != null)
                    {
                        selectionService.SelectionChanged += new EventHandler(OnSelectionChanged);
                    }
                }
            }

            ResumeLayout(true);

            //Add the code compile unit for the xaml file
            TypeProvider typeProvider = (TypeProvider)GetService(typeof(ITypeProvider));

            this.loader.XamlCodeCompileUnit = new CodeCompileUnit();
            this.loader.XamlCodeCompileUnit.Namespaces.Add(Helpers.GenerateCodeFromXomlDocument(Helpers.GetRootActivity(xoml), this, ref this.nameSpace, ref this.typeName));
            typeProvider.AddCodeCompileUnit(this.loader.XamlCodeCompileUnit);

            this.loader.CodeBesideCCU = new CodeCompileUnit();
            this.loader.CodeBesideCCU.Namespaces.Add(Helpers.GenerateCodeBeside(Helpers.GetRootActivity(xoml), this));
            typeProvider.AddCodeCompileUnit(this.loader.CodeBesideCCU);
        }
        ///     Establishes the given designer as the main top level designer for the document.
        public void SetDesigner(IRootDesigner document)
        {
            if (designerView != null)
            {
                Controls.Clear();
                designerView.Dispose();
                designerView = null;
            }

            if (document != null)
            {
                // Demand create the designer holder, if it doesn't already exist.
                ViewTechnology[] technologies        = document.SupportedTechnologies;
                bool             supportedTechnology = false;

                // Search for supported technologies that we know how to design.
                // In our case, we only know how to design WindowsForms.
                //
                foreach (ViewTechnology tech in technologies)
                {
                    switch (tech)
                    {
                    case ViewTechnology.WindowsForms:
                    {
                        designerView      = (Control)document.GetView(ViewTechnology.WindowsForms);
                        designerView.Dock = DockStyle.Fill;
                        Controls.Add(designerView);
                        supportedTechnology = true;
                        break;
                    }
                    }

                    // Stop looping if we found one
                    //
                    if (supportedTechnology)
                    {
                        break;
                    }
                }

                // If we didn't find a supported technology, report it.
                //
                if (!supportedTechnology)
                {
                    throw new Exception("Unsupported Technology " + designerHost.RootComponent.GetType().FullName);
                }
            }
        }
예제 #8
0
파일: Viewer.cs 프로젝트: penzhaohui/Crab
        //Expand or collapse all composite activities

        static public byte[] GetWorkflowImageBinary(Activity workflowDefinition, Dictionary <string, ActivityStatusInfo> activityStatusList)
        {
            AutoResetEvent waitHandle = new AutoResetEvent(false);

            byte[] results = null;
            Thread thread  = new Thread(delegate()
            {
                Loader loader = new Loader();
                WorkflowDesignSurface surface = new WorkflowDesignSurface(new MemberCreationService());
                IDesignerHost host            = (IDesignerHost)surface.GetService(typeof(IDesignerHost));
                if (host == null)
                {
                    waitHandle.Set();
                    return;
                }
                loader.WorkflowDefinition = workflowDefinition;
                surface.BeginLoad(loader);
                if (activityStatusList != null)
                {
                    IDesignerGlyphProviderService glyphService         = surface.GetService(typeof(IDesignerGlyphProviderService)) as IDesignerGlyphProviderService;
                    WorkflowMonitorDesignerGlyphProvider glyphProvider = new WorkflowMonitorDesignerGlyphProvider(activityStatusList);
                    glyphService.AddGlyphProvider(glyphProvider);
                }
                ((IDesignerLoaderHost)host).EndLoad(host.RootComponent.Site.Name, true, null);
                IDesignerHost designerHost = surface.GetService(typeof(IDesignerHost)) as IDesignerHost;
                if (designerHost != null && designerHost.RootComponent != null)
                {
                    IRootDesigner rootDesigner = designerHost.GetDesigner(designerHost.RootComponent) as IRootDesigner;
                    if (rootDesigner != null)
                    {
                        MemoryStream ms           = new MemoryStream();
                        WorkflowView workflowView = rootDesigner.GetView(ViewTechnology.Default) as WorkflowView;
                        workflowView.SaveWorkflowImage(ms, ImageFormat.Png);
                        results = ms.GetBuffer();
                    }
                }
                waitHandle.Set();
            });

            thread.IsBackground = true;
            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            waitHandle.WaitOne();
            return(results);
        }
예제 #9
0
        public void Initialise()
        {
            DispatchService.AssertGuiThread();
            System.Diagnostics.Trace.WriteLine("Loading document into DesignerHost");
            designerHost.LoadDocument();
            System.Diagnostics.Trace.WriteLine("Loaded document into DesignerHost");

            designerHost.Activate();
            System.Diagnostics.Trace.WriteLine("DesignerHost activated; getting designer view");

            IRootDesigner rootDesigner = (IRootDesigner)designerHost.GetDesigner(designerHost.RootComponent);

            designerView = (RootDesignerView)rootDesigner.GetView(ViewTechnology.Default);
//			designerView.Realized += delegate {
//				System.Diagnostics.Trace.WriteLine ("Designer view realized");
//			};
            designerView.Realized += new EventHandler(designerHost.RootDesignerView_Realized);
        }
        private bool SendKeyDownCommand(Keys key)
        {
            IDesignerHost service = this.serviceProvider.GetService(typeof(IDesignerHost)) as IDesignerHost;

            if (service != null)
            {
                IRootDesigner designer = ActivityDesigner.GetDesigner(service.RootComponent as Activity);
                if (designer != null)
                {
                    WorkflowView view = designer.GetView(ViewTechnology.Default) as WorkflowView;
                    if (view != null)
                    {
                        KeyEventArgs e = new KeyEventArgs(key);
                        view.OnCommandKey(e);
                        return(e.Handled);
                    }
                }
            }
            return(false);
        }
예제 #11
0
        public void Initialise(string document, string fileName)
        {
            DispatchService.AssertGuiThread();

            System.Diagnostics.Trace.WriteLine("Loading document into DesignerHost");
            if (document != null)
            {
                host.Load(document, fileName);
            }
            else
            {
                host.NewFile();
            }
            System.Diagnostics.Trace.WriteLine("Loaded document into DesignerHost");

            host.Activate();
            System.Diagnostics.Trace.WriteLine("DesignerHost activated; getting designer view");

            IRootDesigner rootDesigner = (IRootDesigner)host.GetDesigner(host.RootComponent);

            designerView           = (RootDesignerView)rootDesigner.GetView(ViewTechnology.Passthrough);
            designerView.Realized += delegate { System.Diagnostics.Trace.WriteLine("Designer view realized"); };
        }
예제 #12
0
        private void LoadWorkflow()
        {
            SuspendLayout();

            DesignSurface  designSurface = new DesignSurface();
            WorkflowLoader loader        = new WorkflowLoader();

            loader.WorkflowType = workflowTypeValue;
            loader.Xaml         = xamlValue;
            designSurface.BeginLoad(loader);

            IDesignerHost designerHost = designSurface.GetService(typeof(IDesignerHost)) as IDesignerHost;

            if (designerHost != null && designerHost.RootComponent != null)
            {
                IRootDesigner rootDesigner = designerHost.GetDesigner(designerHost.RootComponent) as IRootDesigner;
                if (rootDesigner != null)
                {
                    UnloadWorkflow();

                    this.designSurface = designSurface;
                    this.loader        = loader;
                    this.workflowView  = rootDesigner.GetView(ViewTechnology.Default) as WorkflowView;
                    this.panel1.Controls.Add(this.workflowView);
                    this.workflowView.Dock               = DockStyle.Fill;
                    this.workflowView.TabIndex           = 1;
                    this.workflowView.TabStop            = true;
                    this.workflowView.HScrollBar.TabStop = false;
                    this.workflowView.VScrollBar.TabStop = false;
                    this.workflowView.Focus();
                    this.workflowView.FitToScreenSize();
                }
            }

            ResumeLayout(true);
        }
예제 #13
0
        // This is called during Dispose and Reload methods to unload the current designer.
        private void UnloadDocument() {

            if (helpService != null && rootDesigner != null) {
                helpService.RemoveContextAttribute("Keyword", "Designer_" + rootDesigner.GetType().FullName);
            }
            
            // Note: Because this can be called during Dispose, we are very anal here
            // about checking for null references.

            // If we can get a selection service, clear the selection...
            // we don't want the property browser browsing disposed components...
            // or components who's designer has been destroyed.
            IServiceProvider sp = (IServiceProvider)this;
            ISelectionService selectionService = (ISelectionService)sp.GetService(typeof(ISelectionService));
            Debug.Assert(selectionService != null, "ISelectionService not found");
            if (selectionService != null) {
                selectionService.SetSelectedComponents(null);
            }

            // Stash off the base designer and component.  We are
            // going to be destroying these and we don't want them
            // to be accidently referenced after they're dead.
            //
            IDesigner rootDesignerHolder = rootDesigner;
            IComponent rootComponentHolder = rootComponent;

            rootDesigner = null;
            rootComponent = null;
            rootComponentClassName = null;

            SampleDesignSite[] siteArray = new SampleDesignSite[sites.Values.Count];
            sites.Values.CopyTo(siteArray, 0);

            // Destroy all designers.  We save the base designer for last.
            //
            IDesigner[] designers = new IDesigner[designerTable.Values.Count];
            designerTable.Values.CopyTo(designers, 0);
            designerTable.Clear();

            // Loading, unloading, it's all the same.  It indicates that you
            // shouldn't dirty or otherwise mess with the buffer.  We also
            // create a transaction here to limit the effects of making
            // so many changes.
            loadingDesigner = true;
            DesignerTransaction trans = CreateTransaction();
            
            try {
                for (int i = 0; i < designers.Length; i++) {
                    if (designers[i] != rootDesignerHolder) {
                        try {
                            designers[i].Dispose();
                        }
                        catch {
                            Debug.Fail("Designer " + designers[i].GetType().Name + " threw an exception during Dispose.");
                        }
                    }
                }
    
                // Now destroy all components.
                for (int i = 0; i < siteArray.Length; i++) {
                    SampleDesignSite site = siteArray[i];
                    IComponent comp = site.Component;
                    if (comp != null && comp != rootComponentHolder) {
                        try {
                            comp.Dispose();
                        }
                        catch {
                            Debug.Fail("Component " + site.Name + " threw during dispose.  Bad component!!");
                        }
                        if (comp.Site != null) {
                            Debug.Fail("Component " + site.Name + " did not remove itself from its container");
                            Remove(comp);
                        }
                    }
                }
    
                // Finally, do the base designer and component.
                //
                if (rootDesignerHolder != null) {
                    try {
                        rootDesignerHolder.Dispose();
                    }
                    catch {
                        Debug.Fail("Designer " + rootDesignerHolder.GetType().Name + " threw an exception during Dispose.");
                    }
                }
    
                if (rootComponentHolder != null) {
                    try {
                        rootComponentHolder.Dispose();
                    }
                    catch {
                        Debug.Fail("Component " + rootComponentHolder.GetType().Name + " threw during dispose.  Bad component!!");
                    }
                    
                    if (rootComponentHolder.Site != null) {
                        Debug.Fail("Component " + rootComponentHolder.Site.Name + " did not remove itself from its container");
                        Remove(rootComponentHolder);
                    }
                }
            
                sites.Clear();
                if (components != null) {
                    components.Clear();
                }
            }
            finally {
                loadingDesigner = false;
                trans.Commit();
            }
            
            // And clear the document window
            //
            if (documentWindow != null) {
                documentWindow.SetDesigner(null);
            }
        }
예제 #14
0
        private void CreateComponentDesigner(IComponent component) {
            
            // Is this the first component the loader has created?  If so, then it must
            // be the base component (by definition) so we will expect there to be a document
            // designer associated with the component.  Otherwise, we search for a
            // normal designer, which can be optionally provided.
            
            IDesigner designer = null;

            if (rootComponent == null) {
                rootComponent = component;

                // Get the root designer.  We check right here to see if the document window supports
                // hosting this type of designer.  If not, we bail early.
                rootDesigner = (IRootDesigner)TypeDescriptor.CreateDesigner(component, typeof(IRootDesigner));

                if (rootDesigner == null) {
                    rootComponent = null;
                    Exception ex = new Exception("No Top Level Designer for " + component.GetType().FullName);
                    throw ex;
                }

                ViewTechnology[] technologies = rootDesigner.SupportedTechnologies;
                bool supported = false;
                foreach(ViewTechnology tech in technologies) {
                    if (tech == ViewTechnology.WindowsForms) {
                        supported = true;
                        break;
                    }
                }

                if (!supported) {
                    Exception ex = new Exception("This designer host does not support the designer for " + component.GetType().FullName);
                    throw ex;
                }                    

                designer = rootDesigner;

                // Check and see if anyone has set the class name of the base component.
                // We default to the component name.
                if (rootComponentClassName == null) {
                    rootComponentClassName = component.Site.Name;
                }
            }
            else {
                designer = TypeDescriptor.CreateDesigner(component, typeof(IDesigner));
            }

            if (designer != null) {
                designerTable[component] = designer;
                try {
                    designer.Initialize(component);
                }
                catch {
                    designerTable.Remove(component);

                    if (designer == rootDesigner) {
                        rootDesigner = null;
                    }

                    throw;
                }

                if (designer is IExtenderProvider &&
                    !TypeDescriptor.GetAttributes(designer).Contains(InheritanceAttribute.InheritedReadOnly)) {
                    ((IExtenderProviderService)this).AddExtenderProvider((IExtenderProvider)designer);
                }

                // Now, if this is the root designer, initialize the designer window with it.
                if (designer == rootDesigner) {
                    documentWindow.SetDesigner(rootDesigner);
                }
            }
        }
 private void CreateComponentDesigner(IComponent component)
 {
     IDesigner designer = null;
     if (this.rootComponent != null)
     {
         designer = TypeDescriptor.CreateDesigner(component, typeof(IDesigner));
     }
     else
     {
         Exception ex;
         this.rootComponent = component;
         this.rootDesigner = (IRootDesigner) TypeDescriptor.CreateDesigner(component, typeof(IRootDesigner));
         if (this.rootDesigner == null)
         {
             this.rootComponent = null;
             ex = new Exception("No Top Level Designer for " + component.GetType().FullName);
             throw ex;
         }
         ViewTechnology[] technologies = this.rootDesigner.SupportedTechnologies;
         bool supported = false;
         foreach (ViewTechnology tech in technologies)
         {
             if (tech == ViewTechnology.Default)
             {
                 supported = true;
                 break;
             }
         }
         if (!supported)
         {
             ex = new Exception("This designer host does not support the designer for " + component.GetType().FullName);
             throw ex;
         }
         designer = this.rootDesigner;
         if (this.rootComponentClassName == null)
         {
             this.rootComponentClassName = component.Site.Name;
         }
     }
     if (designer != null)
     {
         this.designerTable[component] = designer;
         try
         {
             designer.Initialize(component);
         }
         catch
         {
             this.designerTable.Remove(component);
             if (designer == this.rootDesigner)
             {
                 this.rootDesigner = null;
             }
             throw;
         }
         if (!(!(designer is IExtenderProvider) || TypeDescriptor.GetAttributes(designer).Contains(InheritanceAttribute.InheritedReadOnly)))
         {
             ((IExtenderProviderService) this).AddExtenderProvider((IExtenderProvider) designer);
         }
         if (designer == this.rootDesigner)
         {
             this.documentWindow.SetDesigner(this.rootDesigner);
         }
     }
 }
        private void CreateComponentDesigner(IComponent component)
        {
            IDesigner designer = null;

            if (this.rootComponent != null)
            {
                designer = TypeDescriptor.CreateDesigner(component, typeof(IDesigner));
            }
            else
            {
                Exception ex;
                this.rootComponent = component;
                this.rootDesigner  = (IRootDesigner)TypeDescriptor.CreateDesigner(component, typeof(IRootDesigner));
                if (this.rootDesigner == null)
                {
                    this.rootComponent = null;
                    ex = new Exception("No Top Level Designer for " + component.GetType().FullName);
                    throw ex;
                }
                ViewTechnology[] technologies = this.rootDesigner.SupportedTechnologies;
                bool             supported    = false;
                foreach (ViewTechnology tech in technologies)
                {
                    if (tech == ViewTechnology.Default)
                    {
                        supported = true;
                        break;
                    }
                }
                if (!supported)
                {
                    ex = new Exception("This designer host does not support the designer for " + component.GetType().FullName);
                    throw ex;
                }
                designer = this.rootDesigner;
                if (this.rootComponentClassName == null)
                {
                    this.rootComponentClassName = component.Site.Name;
                }
            }
            if (designer != null)
            {
                this.designerTable[component] = designer;
                try
                {
                    designer.Initialize(component);
                }
                catch
                {
                    this.designerTable.Remove(component);
                    if (designer == this.rootDesigner)
                    {
                        this.rootDesigner = null;
                    }
                    throw;
                }
                if (!(!(designer is IExtenderProvider) || TypeDescriptor.GetAttributes(designer).Contains(InheritanceAttribute.InheritedReadOnly)))
                {
                    ((IExtenderProviderService)this).AddExtenderProvider((IExtenderProvider)designer);
                }
                if (designer == this.rootDesigner)
                {
                    this.documentWindow.SetDesigner(this.rootDesigner);
                }
            }
        }
예제 #17
0
        /// <summary>
        /// Finish the process of loading an existing
        /// or new workflow
        /// </summary>
        /// <returns></returns>
        private Boolean CommonWorkflowLoading()
        {
            Boolean result = false;

            //tell the designer to begin loading
            _designSurface.BeginLoad(_wfLoader);

            //retrieve the designer host
            IDesignerHost designer
                = _designSurface.GetService(typeof(IDesignerHost))
                  as IDesignerHost;

            if (designer == null || designer.RootComponent == null)
            {
                return(false);
            }

            IRootDesigner rootDesigner
                = designer.GetDesigner(designer.RootComponent)
                  as IRootDesigner;

            if (rootDesigner != null)
            {
                SuspendLayout();
                //get the default workflow view from the designer
                _workflowView = rootDesigner.GetView(
                    ViewTechnology.Default)
                                as WorkflowView;
                //add the workflow view to a panel for display
                splitContainer1.Panel2.Controls.Add(_workflowView);
                _workflowView.Dock = DockStyle.Fill;
                _workflowView.Focus();

                //link the propertyGrid with the designer
                propertyGrid1.Site = designer.RootComponent.Site;

                //setup the toolbar for the workflow using the one
                //constructed by the workflow loader
                IToolboxService toolboxService = designer.GetService(
                    typeof(IToolboxService)) as IToolboxService;
                if (toolboxService != null)
                {
                    if (toolboxService is Control)
                    {
                        //add the toolbox control to a panel
                        _toolboxControl = (Control)toolboxService;
                        splitContainer2.Panel1.Controls.Add(
                            _toolboxControl);
                    }
                }

                //get the ISelectionService from the workflow view
                //and add a handler for the SelectionChanged event
                ISelectionService selectionService
                    = ((IServiceProvider)_workflowView).GetService(
                          typeof(ISelectionService)) as ISelectionService;
                if (selectionService != null)
                {
                    selectionService.SelectionChanged += new EventHandler(
                        selectionService_SelectionChanged);
                }

                ResumeLayout();
                result = true;
            }
            return(result);
        }
예제 #18
0
        public override void DoDefaultAction()
        {
            try
            {
                if (DesignerHost == null)
                {
                    DesignerHost = this.GetService(typeof(IDesignerHost)) as IDesignerHost;
                }
                if (DesignedDataSet == null)
                {
                    DesignedDataSet = this.Component as InfoDataSet;
                }
                if (RootComponent == null)
                {
                    RootComponent = DesignerHost.RootComponent as Control;
                }
                if (RootDesigner == null)
                {
                    RootDesigner = DesignerHost.GetDesigner(RootComponent) as IRootDesigner;
                }
                if (View == null)
                {
                    View = RootDesigner.GetView(ViewTechnology.Default) as Control;
                }
                if (ColumnsToCreate == null)
                {
                    ColumnsToCreate = new ColumnsToCreate();
                }

                // if the RootComponent is not a Form
                if (RootComponent == null)
                {
                    return;
                }
                editorDialog = new InfoDataSetEditorDialog();
                editorDialog.ColumnsToCreate = ColumnsToCreate;
                editorDialog.DesignedDataSet = DesignedDataSet;
                editorDialog.DesignerHost = DesignerHost;
                editorDialog.RootDesigner = RootDesigner;
                editorDialog.RootComponent = RootComponent;
                editorDialog.View = View;

                editorDialog.InitialTreeView();
                editorDialog.Show();
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message);
            }
        }
 private void UnloadDocument()
 {
     if ((this.helpService != null) && (this.rootDesigner != null))
     {
         this.helpService.RemoveContextAttribute("Keyword", "Designer_" + this.rootDesigner.GetType().FullName);
     }
     IServiceProvider sp = this;
     ISelectionService selectionService = (ISelectionService) sp.GetService(typeof(ISelectionService));
     Debug.Assert(selectionService != null, "ISelectionService not found");
     if (selectionService != null)
     {
         selectionService.SetSelectedComponents(null);
     }
     IDesigner rootDesignerHolder = this.rootDesigner;
     IComponent rootComponentHolder = this.rootComponent;
     this.rootDesigner = null;
     this.rootComponent = null;
     this.rootComponentClassName = null;
     SampleDesignSite[] siteArray = new SampleDesignSite[this.sites.Values.Count];
     this.sites.Values.CopyTo(siteArray, 0);
     IDesigner[] designers = new IDesigner[this.designerTable.Values.Count];
     this.designerTable.Values.CopyTo(designers, 0);
     this.designerTable.Clear();
     this.loadingDesigner = true;
     DesignerTransaction trans = this.CreateTransaction();
     try
     {
         int i;
         for (i = 0; i < designers.Length; i++)
         {
             if (designers[i] != rootDesignerHolder)
             {
                 try
                 {
                     designers[i].Dispose();
                 }
                 catch
                 {
                     Debug.Fail("Designer " + designers[i].GetType().Name + " threw an exception during Dispose.");
                 }
             }
         }
         for (i = 0; i < siteArray.Length; i++)
         {
             SampleDesignSite site = siteArray[i];
             IComponent comp = site.Component;
             if ((comp != null) && (comp != rootComponentHolder))
             {
                 try
                 {
                     comp.Dispose();
                 }
                 catch
                 {
                     Debug.Fail("Component " + site.Name + " threw during dispose.  Bad component!!");
                 }
                 if (comp.Site != null)
                 {
                     Debug.Fail("Component " + site.Name + " did not remove itself from its container");
                     this.Remove(comp);
                 }
             }
         }
         if (rootDesignerHolder != null)
         {
             try
             {
                 rootDesignerHolder.Dispose();
             }
             catch
             {
                 Debug.Fail("Designer " + rootDesignerHolder.GetType().Name + " threw an exception during Dispose.");
             }
         }
         if (rootComponentHolder != null)
         {
             try
             {
                 rootComponentHolder.Dispose();
             }
             catch
             {
                 Debug.Fail("Component " + rootComponentHolder.GetType().Name + " threw during dispose.  Bad component!!");
             }
             if (rootComponentHolder.Site != null)
             {
                 Debug.Fail("Component " + rootComponentHolder.Site.Name + " did not remove itself from its container");
                 this.Remove(rootComponentHolder);
             }
         }
         this.sites.Clear();
         if (this.components != null)
         {
             this.components.Clear();
         }
     }
     finally
     {
         this.loadingDesigner = false;
         trans.Commit();
     }
     if (this.documentWindow != null)
     {
         this.documentWindow.SetDesigner(null);
     }
 }
예제 #20
0
        static void Main()
        {
                        #if TRACE
            System.Diagnostics.TextWriterTraceListener listener
                = new System.Diagnostics.TextWriterTraceListener(System.Console.Out);
            System.Diagnostics.Trace.Listeners.Add(listener);
                        #endif

            Application.Init();

            #region Packing and layout

            Window window = new Window("AspNetEdit Host Sample");
            window.SetDefaultSize(1000, 700);
            window.DeleteEvent += new DeleteEventHandler(window_DeleteEvent);

            VBox outerBox = new VBox();
            window.Add(outerBox);

            HPaned leftBox = new HPaned();
            outerBox.PackEnd(leftBox, true, true, 0);
            HPaned rightBox = new HPaned();
            leftBox.Add2(rightBox);

            geckoFrame        = new Frame();
            geckoFrame.Shadow = ShadowType.In;
            rightBox.Pack1(geckoFrame, true, false);

            #endregion

            #region Toolbar

            // * Save/Open

            Toolbar buttons = new Toolbar();
            outerBox.PackStart(buttons, false, false, 0);

            ToolButton saveButton = new ToolButton(Stock.Save);
            buttons.Add(saveButton);
            saveButton.Clicked += new EventHandler(saveButton_Clicked);

            ToolButton openButton = new ToolButton(Stock.Open);
            buttons.Add(openButton);
            openButton.Clicked += new EventHandler(openButton_Clicked);

            buttons.Add(new SeparatorToolItem());

            // * Clipboard

            ToolButton undoButton = new ToolButton(Stock.Undo);
            buttons.Add(undoButton);
            undoButton.Clicked += new EventHandler(undoButton_Clicked);

            ToolButton redoButton = new ToolButton(Stock.Redo);
            buttons.Add(redoButton);
            redoButton.Clicked += new EventHandler(redoButton_Clicked);

            ToolButton cutButton = new ToolButton(Stock.Cut);
            buttons.Add(cutButton);
            cutButton.Clicked += new EventHandler(cutButton_Clicked);

            ToolButton copyButton = new ToolButton(Stock.Copy);
            buttons.Add(copyButton);
            copyButton.Clicked += new EventHandler(copyButton_Clicked);

            ToolButton pasteButton = new ToolButton(Stock.Paste);
            buttons.Add(pasteButton);
            pasteButton.Clicked += new EventHandler(pasteButton_Clicked);

            buttons.Add(new SeparatorToolItem());

            // * Text style

            ToolButton boldButton = new ToolButton(Stock.Bold);
            buttons.Add(boldButton);
            boldButton.Clicked += new EventHandler(boldButton_Clicked);

            ToolButton italicButton = new ToolButton(Stock.Italic);
            buttons.Add(italicButton);
            italicButton.Clicked += new EventHandler(italicButton_Clicked);

            ToolButton underlineButton = new ToolButton(Stock.Underline);
            buttons.Add(underlineButton);
            underlineButton.Clicked += new EventHandler(underlineButton_Clicked);

            ToolButton indentButton = new ToolButton(Stock.Indent);
            buttons.Add(indentButton);
            indentButton.Clicked += new EventHandler(indentButton_Clicked);

            ToolButton unindentButton = new ToolButton(Stock.Unindent);
            buttons.Add(unindentButton);
            unindentButton.Clicked += new EventHandler(unindentButton_Clicked);

            buttons.Add(new SeparatorToolItem());

            // * Toolbox

            ToolButton toolboxAddButton = new ToolButton(Stock.Add);
            buttons.Add(toolboxAddButton);
            toolboxAddButton.Clicked += new EventHandler(toolboxAddButton_Clicked);

            #endregion

            #region Designer services and host

            //set up the services
            ServiceContainer services = new ServiceContainer();
            services.AddService(typeof(INameCreationService), new NameCreationService());
            services.AddService(typeof(ISelectionService), new SelectionService());
            services.AddService(typeof(IEventBindingService), new EventBindingService(window));
            services.AddService(typeof(ITypeResolutionService), new TypeResolutionService());
            ExtenderListService extListServ = new AspNetEdit.Editor.ComponentModel.ExtenderListService();
            services.AddService(typeof(IExtenderListService), extListServ);
            services.AddService(typeof(IExtenderProviderService), extListServ);
            services.AddService(typeof(ITypeDescriptorFilterService), new TypeDescriptorFilterService());
            toolboxService = new ToolboxService();
            services.AddService(typeof(IToolboxService), toolboxService);

            //create our host
            host = new DesignerHost(services);
            host.NewFile();
            host.Activate();

            #endregion

            #region Designer UI and panels

            IRootDesigner    rootDesigner = (IRootDesigner)host.GetDesigner(host.RootComponent);
            RootDesignerView designerView = (RootDesignerView)rootDesigner.GetView(ViewTechnology.Passthrough);
            geckoFrame.Add(designerView);

            PropertyGrid p = new PropertyGrid(services);
            p.WidthRequest = 200;
            rightBox.Pack2(p, false, false);

            Toolbox toolbox = new Toolbox(services);
            leftBox.Pack1(toolbox, false, false);
            toolboxService.PopulateFromAssembly(System.Reflection.Assembly.GetAssembly(typeof(System.Web.UI.Control)));
            toolboxService.AddToolboxItem(new TextToolboxItem("<table><tr><td></td><td></td></tr><tr><td></td><td></td></tr></table>", "Table"), "Html");
            toolboxService.AddToolboxItem(new TextToolboxItem("<div style=\"width: 100px; height: 100px;\"></div>", "Div"), "Html");
            toolboxService.AddToolboxItem(new TextToolboxItem("<hr />", "Horizontal Rule"), "Html");
            toolboxService.AddToolboxItem(new TextToolboxItem("<select><option></option></select>", "Select"), "Html");
            toolboxService.AddToolboxItem(new TextToolboxItem("<img src=\"\" />", "Image"), "Html");
            toolboxService.AddToolboxItem(new TextToolboxItem("<textarea cols=\"20\" rows=\"2\"></textarea>", "Textarea"), "Html");
            toolboxService.AddToolboxItem(new TextToolboxItem("<input type=\"hidden\" />", "Input [Hidden]"), "Html");
            toolboxService.AddToolboxItem(new TextToolboxItem("<input type=\"radio\" />", "Input [Radio]"), "Html");
            toolboxService.AddToolboxItem(new TextToolboxItem("<input type=\"checkbox\" />", "Input [Checkbox]"), "Html");
            toolboxService.AddToolboxItem(new TextToolboxItem("<input type=\"password\" />", "Input [Password]"), "Html");
            toolboxService.AddToolboxItem(new TextToolboxItem("<input type=\"file\" />", "Input [File]"), "Html");
            toolboxService.AddToolboxItem(new TextToolboxItem("<input type=\"text\" />", "Input [Text]"), "Html");
            toolboxService.AddToolboxItem(new TextToolboxItem("<input type=\"submit\" value=\"submit\" />", "Input [Submit]"), "Html");
            toolboxService.AddToolboxItem(new TextToolboxItem("<input type=\"reset\" value=\"reset\" />", "Input [Reset]"), "Html");
            toolboxService.AddToolboxItem(new TextToolboxItem("<input type=\"button\" value=\"button\" />", "Input [Button]"), "Html");
            toolbox.Refresh();

            #endregion

            window.ShowAll();
            Application.Run();
        }
예제 #21
0
        /// <summary>
        ///     Establishes the given designer as the main top level designer for the document.
        /// </summary>
        /// <param name='document'>
        ///     The designer to make top-level.
        /// </param>
        public void SetDesigner(IRootDesigner document)
        {
            ISelectionService ss = SelectionService;

            if (designerView != null)
            {
                if (ss != null)
                {
                    ss.SelectionChanged -= new EventHandler(this.OnSelectionChanged);
                }
                Controls.Remove(designerView);
                designerView = null;
            }

            docObject = null;

            if (document != null)
            {
                if (ss != null)
                {
                    ss.SelectionChanged += new EventHandler(this.OnSelectionChanged);
                }

                // If we got a designer, then clear our error list.
                if (errorList != null)
                {
                    errorList.Clear();
                }

                // Demand create the designer holder, if it doesn't already exist.
                ViewTechnology[] technologies        = document.SupportedTechnologies;
                bool             supportedTechnology = false;

                foreach (ViewTechnology tech in technologies)
                {
                    switch (tech)
                    {
                    case ViewTechnology.WindowsForms: {
                        designerView      = (Control)document.GetView(ViewTechnology.WindowsForms);
                        designerView.Dock = DockStyle.Fill;
                        Controls.Add(designerView);
                        supportedTechnology = true;
                        break;
                    }

                    case ViewTechnology.Passthrough: {
                        docObject           = document.GetView(ViewTechnology.Passthrough);
                        supportedTechnology = true;
                        break;
                    }
                    }

                    // Stop looping if we found one
                    //
                    if (supportedTechnology)
                    {
                        break;
                    }
                }

                // If we didn't find a supported technology, report it.
                //
                if (!supportedTechnology)
                {
                    throw new Exception(SR.GetString(SR.CODEMANUnsupportedTechnology, designerHost.RootComponent.GetType().FullName));
                }
            }
        }
예제 #22
0
        ///     Establishes the given designer as the main top level designer for the document.
        public void SetDesigner(IRootDesigner document) {

            if (designerView != null) {
				Controls.Clear();
                designerView.Dispose();
				designerView = null;
            }
            
            if (document != null) {
                // Demand create the designer holder, if it doesn't already exist.
                ViewTechnology[] technologies = document.SupportedTechnologies;
                bool supportedTechnology = false;
                
				// Search for supported technologies that we know how to design.
				// In our case, we only know how to design WindowsForms.
				//
                foreach(ViewTechnology tech in technologies) {
                    switch(tech) {
                        case ViewTechnology.WindowsForms: {
                            designerView = (Control)document.GetView(ViewTechnology.WindowsForms);
                            designerView.Dock = DockStyle.Fill;
							Controls.Add(designerView);
                            supportedTechnology = true;
                            break;
                        }
                    }
                    
                    // Stop looping if we found one
                    //
                    if (supportedTechnology) {
                        break;
                    }
                }
                
                // If we didn't find a supported technology, report it.
                //
                if (!supportedTechnology) {
                    throw new Exception("Unsupported Technology " + designerHost.RootComponent.GetType().FullName);
                }

            }
        }
예제 #23
0
 private void GenerateControls()
 {
     try
     {
         form = (Form)host.CreateComponent(typeof(Form), null);
         form.Controls.Clear();
         form.TopLevel = false;
         form.Text     = "Design view";
         DataTable dtControlsList = DBEngine.execReturnDataTable("FormLayout_ControlList", "@FormName", this.Name);
         if (dtControlsList != null && dtControlsList.Rows.Count > 0)
         {
             foreach (DataRow dr in dtControlsList.Rows)
             {
                 if (dr["ControlName"] != DBNull.Value && !dr["ControlName"].ToString().Trim().Equals(string.Empty) && !dr["ControlName"].ToString().Equals(this.Name))
                 {
                     Control ctr = (Control)host.CreateComponent(dr["SystemType"].ToString(), dr["ControlName"].ToString());
                     ctr.Location = new Point((int)dr["LocationX"], (int)dr["LocationY"]);
                     ctr.Text     = HPA.Common.UIMessage.Get_Message(ctr.Name);
                     ctr.Size     = new Size((int)dr["Width"], (int)dr["Height"]);
                     ctr.Visible  = Convert.ToBoolean(dr["Visible"]);
                     ctr.Enabled  = Convert.ToBoolean(dr["Enabled"]);
                     if (dr[CommonConst.TabIndex] != DBNull.Value)
                     {
                         ctr.TabIndex = Convert.ToInt32(dr[CommonConst.TabIndex]);
                     }
                     // set font style
                     if (dr["FontName"] != DBNull.Value)
                     {
                         HPA.Common.LayOutControlHelper.SetFontStyle(ref ctr, dr);
                     }
                     if (dr[CommonConst.ForeColor] != DBNull.Value)
                     {
                         HPA.Common.LayOutControlHelper.SetForeColor(ref ctr, dr);
                     }
                     if (ctr is PictureBox)
                     {
                         ((PictureBox)ctr).Image = CImageUtility.byteArrayToImage((byte[])dr["Image"]);
                     }
                     form.Controls.Add(ctr);
                 }
                 else if (dr["ControlName"].ToString().Equals(this.Name) || (dr["SystemType"].ToString().Equals("System.Windows.Forms.SplitterPanel,System.Windows.Forms") && dr["ControlName"].ToString().Trim().Equals(string.Empty)))
                 {
                     form.Size = new Size((int)dr["Width"], (int)dr["Height"]);
                     form.Name = dr["FormName"].ToString();
                 }
             }
             foreach (DataRow dr in dtControlsList.Rows)
             {
                 if (dr["ParentControl"] == DBNull.Value)
                 {
                     continue;
                 }
                 string PrentCtrName = dr["ParentControl"].ToString();
                 if (PrentCtrName.Trim().Equals(string.Empty))
                 {
                     PrentCtrName = form.Name;
                 }
                 if (!PrentCtrName.Equals(form.Name) && !dr["ControlName"].ToString().Trim().Equals(string.Empty))
                 {
                     if (form.Controls.Find(PrentCtrName, true).Length > 0 && form.Controls.Find(dr["ControlName"].ToString(), true).Length > 0)
                     {
                         form.Controls.Find(PrentCtrName, true)[0].Controls.Add(form.Controls.Find(dr["ControlName"].ToString(), true)[0]);
                     }
                 }
             }
         }
         IRootDesigner rootDesigner = (IRootDesigner)host.GetDesigner(form);
         Control       designView   = (Control)rootDesigner.GetView(ViewTechnology.Default);
         designView.Dock = DockStyle.Fill;
         designSurfacePanel.Controls.Add(designView);
     }
     catch (Exception ex)
     {
         HPA.Common.Helper.LogError(ex, this.Text, "GenerateControls");
     }
 }
        private void UnloadDocument()
        {
            if ((this.helpService != null) && (this.rootDesigner != null))
            {
                this.helpService.RemoveContextAttribute("Keyword", "Designer_" + this.rootDesigner.GetType().FullName);
            }
            IServiceProvider  sp = this;
            ISelectionService selectionService = (ISelectionService)sp.GetService(typeof(ISelectionService));

            Debug.Assert(selectionService != null, "ISelectionService not found");
            if (selectionService != null)
            {
                selectionService.SetSelectedComponents(null);
            }
            IDesigner  rootDesignerHolder  = this.rootDesigner;
            IComponent rootComponentHolder = this.rootComponent;

            this.rootDesigner           = null;
            this.rootComponent          = null;
            this.rootComponentClassName = null;
            SampleDesignSite[] siteArray = new SampleDesignSite[this.sites.Values.Count];
            this.sites.Values.CopyTo(siteArray, 0);
            IDesigner[] designers = new IDesigner[this.designerTable.Values.Count];
            this.designerTable.Values.CopyTo(designers, 0);
            this.designerTable.Clear();
            this.loadingDesigner = true;
            DesignerTransaction trans = this.CreateTransaction();

            try
            {
                int i;
                for (i = 0; i < designers.Length; i++)
                {
                    if (designers[i] != rootDesignerHolder)
                    {
                        try
                        {
                            designers[i].Dispose();
                        }
                        catch
                        {
                            Debug.Fail("Designer " + designers[i].GetType().Name + " threw an exception during Dispose.");
                        }
                    }
                }
                for (i = 0; i < siteArray.Length; i++)
                {
                    SampleDesignSite site = siteArray[i];
                    IComponent       comp = site.Component;
                    if ((comp != null) && (comp != rootComponentHolder))
                    {
                        try
                        {
                            comp.Dispose();
                        }
                        catch
                        {
                            Debug.Fail("Component " + site.Name + " threw during dispose.  Bad component!!");
                        }
                        if (comp.Site != null)
                        {
                            Debug.Fail("Component " + site.Name + " did not remove itself from its container");
                            this.Remove(comp);
                        }
                    }
                }
                if (rootDesignerHolder != null)
                {
                    try
                    {
                        rootDesignerHolder.Dispose();
                    }
                    catch
                    {
                        Debug.Fail("Designer " + rootDesignerHolder.GetType().Name + " threw an exception during Dispose.");
                    }
                }
                if (rootComponentHolder != null)
                {
                    try
                    {
                        rootComponentHolder.Dispose();
                    }
                    catch
                    {
                        Debug.Fail("Component " + rootComponentHolder.GetType().Name + " threw during dispose.  Bad component!!");
                    }
                    if (rootComponentHolder.Site != null)
                    {
                        Debug.Fail("Component " + rootComponentHolder.Site.Name + " did not remove itself from its container");
                        this.Remove(rootComponentHolder);
                    }
                }
                this.sites.Clear();
                if (this.components != null)
                {
                    this.components.Clear();
                }
            }
            finally
            {
                this.loadingDesigner = false;
                trans.Commit();
            }
            if (this.documentWindow != null)
            {
                this.documentWindow.SetDesigner(null);
            }
        }