private void RemoveSmartPart(Control smartPartControl)
        {
            // get the task pane tool
            TaskPaneTool         taskPane = this.GetTaskPane(smartPartControl);
            UltraTaskPaneToolbar toolbar  = GetOwningToolbar(taskPane);

            // at design time, we won't remove the tool
            // if you remove the control
            //
            if (this.DesignMode == false)
            {
                // remove the root tool so all the instances are removed
                this.Tools.Remove(this.Tools[taskPane.Key]);
            }

            // remove the smart parts
            this.composer.Remove(taskPane, smartPartControl);

            // at design time, don't mess with the toolbar visibility
            if (this.DesignMode == false)
            {
                // get and hide the owning taskpane toolbar if necessary
                this.HideToolbarWithNoVisibleTools(toolbar);
            }

            if (this.MdiParentManager != null)
            {
                this.RefreshMerge();
            }
        }
        private static UltraTaskPaneToolbar GetOwningToolbar(TaskPaneTool tool)
        {
            foreach (ToolBase instance in tool.SharedProps.ToolInstances)
            {
                if (instance.OwnerIsToolbar)
                {
                    return(instance.OwningToolbar as UltraTaskPaneToolbar);
                }
            }

            return(tool.OwningToolbar as UltraTaskPaneToolbar);
        }
        /// <summary>
        /// Hides the smart part.
        /// </summary>
        protected virtual void OnHide(Control smartPart)
        {
            TaskPaneTool tool = this.GetTaskPane(smartPart);

            if (null != tool)
            {
                tool.SharedProps.Visible = false;

                // get and hide the owning taskpane toolbar if necessary
                this.HideToolbarWithNoVisibleTools(GetOwningToolbar(tool));
            }
        }
        private void ApplySmartPartInfoHelper(TaskPaneTool tool, UltraToolbarsSmartPartInfo smartPartInfo)
        {
            tool.SharedProps.Caption     = smartPartInfo.Title;
            tool.SharedProps.ToolTipText = smartPartInfo.Description;

            tool.HeaderCaption = smartPartInfo.HeaderCaption;
            tool.ResizeMode    = smartPartInfo.ResizeMode;

            Image img = smartPartInfo.Image;

            if (img != null)
            {
                tool.SharedProps.AppearancesSmall.Appearance.Image = img;
            }
            else if (tool.SharedProps.HasAppearancesSmall && tool.SharedProps.AppearancesSmall.HasAppearance)
            {
                tool.SharedProps.AppearancesSmall.Appearance.Image = null;
            }
        }
        /// <summary>
        /// Activates the smart part within the workspace.
        /// </summary>
        /// <param name="smartPart">The smart part to activate</param>
        protected virtual void OnActivate(Control smartPart)
        {
            TaskPaneTool taskPane = this.GetTaskPane(smartPart);

            // make sure its visible
            taskPane.SharedProps.Visible = true;

            UltraTaskPaneToolbar taskPaneToolbar = taskPane.OwningToolbar as UltraTaskPaneToolbar;

            // make sure its the selected tool in the owning task pane
            if (taskPaneToolbar != null)
            {
                taskPaneToolbar.SelectedTaskPaneTool = taskPane;
                taskPaneToolbar.Visible = true;
            }

            // assuming the control is visible, give it the input focus
            if (taskPane.Control.Visible)
            {
                taskPane.Control.Focus();
            }
        }
 private Control GetSmartPart(TaskPaneTool taskPane)
 {
     return(this.composer[taskPane]);
 }
        private TaskPaneTool CreateTaskPane(object smartPart, UltraToolbarsSmartPartInfo smartPartInfo)
        {
            // get the control that we will be siting
            Control ctrl = WorkspaceUtilities.GetSmartPartControl(smartPart);

            TaskPaneTool         taskPane = null;
            UltraTaskPaneToolbar toolbar  = null;
            DockedPosition       defaultDockedPosition = smartPartInfo.PreferredDockedPosition;
            string toolbarKey = smartPartInfo.PreferredTaskPane;

            // create the task pane tool and set it up
            taskPane         = new TaskPaneTool(Guid.NewGuid().ToString());
            taskPane.Control = ctrl;

            // add it to the root tools collection
            this.Tools.Add(taskPane);

            this.composer.Add(taskPane, ctrl);

            // initialize its settings
            this.ApplySmartPartInfoHelper(taskPane, smartPartInfo);

            // if a key was specified...
            if (toolbarKey != null && this.Toolbars.Exists(toolbarKey))
            {
                // as long as its an task pane toolbar key, use it
                if (this.Toolbars[toolbarKey] is UltraTaskPaneToolbar)
                {
                    toolbar = this.Toolbars[toolbarKey] as UltraTaskPaneToolbar;
                }
                else                 // otherwise use a default key
                {
                    toolbarKey = null;
                }
            }

            if (toolbar == null)
            {
                // if one wasn't specified use a guid to ensure uniqueness
                if (toolbarKey == null)
                {
                    toolbarKey = Guid.NewGuid().ToString();
                }

                // create a taskpane toolbar and add it to the controls collection
                toolbar = new UltraTaskPaneToolbar(toolbarKey);
                toolbar.DockedPosition = defaultDockedPosition;

                if (smartPartInfo.PreferredExtent != UltraToolbarsSmartPartInfo.DefaultExtent)
                {
                    toolbar.DockedContentExtent = smartPartInfo.PreferredExtent;
                }

                toolbar.ShowHomeButton        = smartPartInfo.PreferredShowHomeButton;
                toolbar.NavigationButtonStyle = smartPartInfo.PreferredNavigationStyle;

                this.Toolbars.Add(toolbar);
            }

            toolbar.Tools.AddTool(taskPane.Key);

            return(taskPane);
        }
        /// <summary>
        /// Shows the smart part in the workspace.
        /// </summary>
        /// <param name="smartPart">The smart part to show</param>
        /// <param name="smartPartInfo">The associated smart part info for the smart part being shown.</param>
        protected virtual void OnShow(Control smartPart, UltraToolbarsSmartPartInfo smartPartInfo)
        {
            TaskPaneTool taskPane = this.CreateTaskPane(smartPart, smartPartInfo);

            taskPane.SharedProps.Visible = true;
        }
        /// <summary>
        /// Applies the smart part info to the smart part within the workspace.
        /// </summary>
        /// <param name="smartPart">The smart part to which the smart part info should be applied.</param>
        /// <param name="smartPartInfo">The smart part info to apply</param>
        protected virtual void OnApplySmartPartInfo(Control smartPart, UltraToolbarsSmartPartInfo smartPartInfo)
        {
            TaskPaneTool tool = this.GetTaskPane(smartPart);

            this.ApplySmartPartInfoHelper(tool, smartPartInfo);
        }