public WorkflowView(IServiceProvider serviceProvider)
 {
     this.zoomLevel = 1f;
     this.shadowDepth = WorkflowTheme.CurrentTheme.AmbientTheme.ShadowDepth;
     this.stockMessageFilters = new List<WorkflowDesignerMessageFilter>();
     this.customMessageFilters = new List<WorkflowDesignerMessageFilter>();
     this.prePreviewZoom = 100;
     this.prePreviewScroll = Point.Empty;
     this.messageHitTestContexts = new Stack<System.Workflow.ComponentModel.Design.HitTestInfo>();
     if (serviceProvider == null)
     {
         throw new ArgumentNullException("serviceProvider");
     }
     base.SuspendLayout();
     this.AllowDrop = true;
     this.AutoScroll = false;
     base.HScroll = false;
     base.VScroll = false;
     base.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.EnableNotifyMessage | ControlStyles.AllPaintingInWmPaint | ControlStyles.Selectable | ControlStyles.Opaque | ControlStyles.UserPaint, true);
     this.serviceProvider = serviceProvider;
     IServiceContainer container = this.GetService(typeof(IServiceContainer)) as IServiceContainer;
     if (container != null)
     {
         container.RemoveService(typeof(WorkflowView));
         container.AddService(typeof(WorkflowView), this);
     }
     IUIService service = this.serviceProvider.GetService(typeof(IUIService)) as IUIService;
     if (service != null)
     {
         WorkflowTheme.UIService = service;
     }
     this.EnsureScrollBars(new System.Windows.Forms.HScrollBar(), new System.Windows.Forms.VScrollBar());
     this.workflowToolTip = new WorkflowToolTip(this);
     WorkflowTheme.ThemeChanged += new EventHandler(this.OnThemeChange);
     this.PopulateMessageFilters(true);
     this.RootDesigner = ActivityDesigner.GetSafeRootDesigner(this);
     this.fitAllAction = this.CreateDynamicAction();
     if ((this.activeLayout == null) || (this.defaultLayout == null))
     {
         this.ActiveLayout = this.DefaultLayout = new WorkflowRootLayout(this.serviceProvider);
     }
     if (this.GetService(typeof(IMenuCommandService)) is IMenuCommandService)
     {
         this.commandSet = new System.Workflow.ComponentModel.Design.CommandSet(this);
         this.commandSet.UpdatePanCommands(true);
     }
     ISelectionService service3 = this.GetService(typeof(ISelectionService)) as ISelectionService;
     if (service3 != null)
     {
         service3.SelectionChanged += new EventHandler(this.OnSelectionChanged);
     }
     Application.AddMessageFilter(this);
     base.ResumeLayout(true);
 }
        protected override void Dispose(bool disposing)
        {
            //Remove the proffered services
            if (disposing)
            {
                try
                {
                    SuspendLayout();

                    Application.RemoveMessageFilter(this);

                    if (this.layoutEventHandler != null)
                    {
                        Idle -= this.layoutEventHandler;
                        this.layoutEventHandler = null;
                    }

                    if (this.ensureVisibleEventHandler != null)
                    {
                        Idle -= this.ensureVisibleEventHandler;
                        this.ensureVisibleEventHandler = null;
                    }

                    if (this.idleEventHandler != null)
                    {
                        this.idleEventListeners = null;

                        Form host = TopLevelControl as Form;
                        if (!Application.MessageLoop || (host != null && host.Modal))
                            WorkflowTimer.Default.Unsubscribe(this.idleEventHandler);
                        else
                            Application.Idle -= this.idleEventHandler;
                        this.idleEventHandler = null;
                    }

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

                    //Unsubscribe the theme change
                    WorkflowTheme.ThemeChanged -= new EventHandler(OnThemeChange);

                    //Remove the dynamic action
                    if (this.fitAllAction != null)
                    {
                        this.fitAllAction.Dispose();
                        this.fitAllAction = null;
                    }

                    if (this.workflowToolTip != null)
                    {
                        ((IDisposable)this.workflowToolTip).Dispose();
                        this.workflowToolTip = null;
                    }

                    DisposeMessageFilters(false);
                    DisposeMessageFilters(true);

                    //Dispose the layouts
                    this.activeLayout = null;
                    if (this.defaultLayout != null)
                    {
                        this.defaultLayout.Dispose();
                        this.defaultLayout = null;
                    }

                    //Destroy other resources
                    if (this.viewPortBitmap != null)
                    {
                        this.viewPortBitmap.Dispose();
                        this.viewPortBitmap = null;
                    }

                    if (this.commandSet != null)
                    {
                        this.commandSet.Dispose();
                        this.commandSet = null;
                    }

                    HScrollBar.ValueChanged -= new EventHandler(OnScroll);
                    VScrollBar.ValueChanged -= new EventHandler(OnScroll);

                    if (this.toolContainer != null)
                    {
                        Controls.Remove(this.toolContainer);
                        this.toolContainer.TabStrip.Tabs.Clear();
                        this.toolContainer.Dispose();
                        this.toolContainer = null;
                    }

                    IServiceContainer serviceContainer = GetService(typeof(IServiceContainer)) as IServiceContainer;
                    if (serviceContainer != null)
                    {
                        serviceContainer.RemoveService(typeof(WorkflowView));
                    }
                }
                finally
                {
                    ResumeLayout(false);
                }
            }

            base.Dispose(disposing);
        }
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         try
         {
             base.SuspendLayout();
             Application.RemoveMessageFilter(this);
             if (this.layoutEventHandler != null)
             {
                 this.Idle -= this.layoutEventHandler;
                 this.layoutEventHandler = null;
             }
             if (this.ensureVisibleEventHandler != null)
             {
                 this.Idle -= this.ensureVisibleEventHandler;
                 this.ensureVisibleEventHandler = null;
             }
             if (this.idleEventHandler != null)
             {
                 this.idleEventListeners = null;
                 Form topLevelControl = base.TopLevelControl as Form;
                 if (!Application.MessageLoop || ((topLevelControl != null) && topLevelControl.Modal))
                 {
                     WorkflowTimer.Default.Unsubscribe(this.idleEventHandler);
                 }
                 else
                 {
                     Application.Idle -= this.idleEventHandler;
                 }
                 this.idleEventHandler = null;
             }
             ISelectionService service = this.GetService(typeof(ISelectionService)) as ISelectionService;
             if (service != null)
             {
                 service.SelectionChanged -= new EventHandler(this.OnSelectionChanged);
             }
             WorkflowTheme.ThemeChanged -= new EventHandler(this.OnThemeChange);
             if (this.fitAllAction != null)
             {
                 this.fitAllAction.Dispose();
                 this.fitAllAction = null;
             }
             if (this.workflowToolTip != null)
             {
                 ((IDisposable) this.workflowToolTip).Dispose();
                 this.workflowToolTip = null;
             }
             this.DisposeMessageFilters(false);
             this.DisposeMessageFilters(true);
             this.activeLayout = null;
             if (this.defaultLayout != null)
             {
                 this.defaultLayout.Dispose();
                 this.defaultLayout = null;
             }
             if (this.viewPortBitmap != null)
             {
                 this.viewPortBitmap.Dispose();
                 this.viewPortBitmap = null;
             }
             if (this.commandSet != null)
             {
                 this.commandSet.Dispose();
                 this.commandSet = null;
             }
             this.HScrollBar.ValueChanged -= new EventHandler(this.OnScroll);
             this.VScrollBar.ValueChanged -= new EventHandler(this.OnScroll);
             if (this.toolContainer != null)
             {
                 base.Controls.Remove(this.toolContainer);
                 this.toolContainer.TabStrip.Tabs.Clear();
                 this.toolContainer.Dispose();
                 this.toolContainer = null;
             }
             IServiceContainer container = this.GetService(typeof(IServiceContainer)) as IServiceContainer;
             if (container != null)
             {
                 container.RemoveService(typeof(WorkflowView));
             }
         }
         finally
         {
             base.ResumeLayout(false);
         }
     }
     base.Dispose(disposing);
 }
        public WorkflowView(IServiceProvider serviceProvider)
        {
            Debug.Assert(serviceProvider != null);
            if (serviceProvider == null)
                throw new ArgumentNullException("serviceProvider");

            SuspendLayout();
            AllowDrop = true;
            AutoScroll = false;
            HScroll = false;
            VScroll = false;
            SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.Opaque | ControlStyles.AllPaintingInWmPaint | ControlStyles.Selectable | ControlStyles.EnableNotifyMessage, true);

            this.serviceProvider = serviceProvider;

            //*****Promote the services which are accessed from other components
            IServiceContainer serviceContainer = GetService(typeof(IServiceContainer)) as IServiceContainer;
            if (serviceContainer != null)
            {
                //Remove any existing designer service if there is any
                serviceContainer.RemoveService(typeof(WorkflowView));
                serviceContainer.AddService(typeof(WorkflowView), this);
            }

            //set the UI Service to be used by themes
            IUIService uiService = this.serviceProvider.GetService(typeof(IUIService)) as IUIService;
            if (uiService != null)
                WorkflowTheme.UIService = uiService;

            //Make sure that we add scrollbars
            EnsureScrollBars(new HScrollBar(), new VScrollBar());

            //Initialize the tooltip shown
            this.workflowToolTip = new WorkflowToolTip(this);

            //[....] the global theme change event, which is fired by the theme infrastructure for theme change
            WorkflowTheme.ThemeChanged += new EventHandler(OnThemeChange);

            //Create the core message filters
            PopulateMessageFilters(true);

            //Set the root designer, note that the dynamic action is dependent on the DynamicActionMessageFilter pushed
            //when the root is set.
            RootDesigner = ActivityDesigner.GetSafeRootDesigner(this);
            this.fitAllAction = CreateDynamicAction();

            //If the active layout is still null then we will set the default layout as active layout
            if (this.activeLayout == null || this.defaultLayout == null)
                ActiveLayout = DefaultLayout = new WorkflowRootLayout(this.serviceProvider);

            //Create the local command set and update all the commands once
            IMenuCommandService menuCommandService = GetService(typeof(IMenuCommandService)) as IMenuCommandService;
            if (menuCommandService != null)
            {
                this.commandSet = new CommandSet(this);
                this.commandSet.UpdatePanCommands(true);
            }

            //Subscribe to selection change
            ISelectionService selectionService = GetService(typeof(ISelectionService)) as ISelectionService;
            if (selectionService != null)
                selectionService.SelectionChanged += new EventHandler(OnSelectionChanged);

            //In case of non VS case we need to pumpin the Keyboard messages, the user control sets
            //focus to the child controls by default which is a problem so we need to trap the 
            //messages by adding application level message filter, in case of VS this is not required and
            //the message filter is never called.
            Application.AddMessageFilter(this);

            //We make sure that during the construction we dont do perform layouts on idle event
            ResumeLayout(true);
        }