/// <summary> /// Add the application to the TabControl /// </summary> /// <param name="child">The application to add</param> /// <param name="bar">The CcfPanelToolbar to add to the control.</param> /// <param name="closeButton"></param> /// <returns>The tab page</returns> private TabPage addApplicationToTabControl(object child, CcfPanelToolbar bar, bool closeButton) { TabPage tabPage = null; Image icon = null; // Icon for the tab string text; // Text for the tab // Get the application name and icon to be displayed on the tab if (child is IHostedApplication) { IHostedApplication app = child as IHostedApplication; // Get the app's name text = app.ApplicationName; // Get the app's icon ImageList imageList = app.GetIconList(); if (imageList != null && imageList.Images.Count > 0) { icon = imageList.Images[0]; } tabPage = tabControl.ShowApplication(child, text, icon, closeButton); if (app == CCFAppsUI.AppWithFocus) { tabControl.SelectedTab = tabPage; } } else if (child is Control) { text = (child as Control).Text; tabPage = tabControl.ShowApplication(child, text, null, closeButton); } if (bar != null) { // if a toolbar already exists don't add additional ones foreach (Control toolbar in tabPage.Controls) { if (toolbar is CcfPanelToolbar) { tabPage.Controls.Remove(toolbar); break; } } tabPage.Controls.Add(bar); } return(tabPage); }
/// <summary> /// Adds a CCF hosted application or a user WinForms control to the /// CCFPanel. If there are currenlty no app on this panel, then add /// to CcfDeckControl. Else if there are more than one app on this /// panel, then add to CcfTabControl. /// </summary> /// <param name="child">The control or hosted app to add to the panel</param> /// <param name="initializationXml">An XML string for the application being added. /// This is used when determining how the app will appear in the panel, for /// instance, is there a toolbar. /// </param> /// <param name="useToolbar">True if a toolbar is used no mater what, false /// if the xml string should be parsed to see if one is used. /// </param> /// <param name="closeButton">True if a close button is provided for closing /// dynamic hosted application, false otherwise</param> /// <returns>The tabpage from the CcfTabControl if one is used or the CcfDeckControl</returns> virtual public Control Add(object child, string initializationXml, bool useToolbar, bool closeButton) { CcfPanelToolbar bar = null; if (initializationXml != null && initializationXml != String.Empty) { XmlDocument doc = new XmlDocument(); doc.LoadXml(initializationXml); XmlNode node = doc.DocumentElement.SelectSingleNode("descendant::toolbar"); if (node != null) { useToolbar = true; } } IHostedApplication hostapp = child as IHostedApplication; // If you want all web apps to have the toolbar without adding them to // the database, just enable this code. //if ( hostapp != null && hostapp.HostedApp is HostedWebApplication ) //{ // useToolbar = true; //} // Create and add the toolbar to the hosted app's deckControl if (useToolbar && hostapp != null) { foreach (Control toolbar in deckControl.Controls) { if (toolbar is CcfPanelToolbar) { deckControl.Controls.Remove(toolbar); break; } } bar = new CcfPanelToolbar(hostapp); bar.Dock = DockStyle.Top; } // If there are no apps yet, then show app on a deckControl // Else we show the controls in a tabControl if (deckControl.Count == 0 && tabControl.Count == 0) { deckControl.Visible = true; tabControl.Visible = false; // Begin Dynamic if (closeButton) { // Add the close button toolbar to the deckControl CcfButtonToolbar closeButtonToolBar = new CcfButtonToolbar(child); closeButtonToolBar.CloseButtonClick += new CcfButtonToolbar.CloseButtonClickHandler(closeButtonClick); deckControl.Controls.Add(closeButtonToolBar); closeButtonToolBar.Dock = DockStyle.Top; } //deckControl.CloseAppClick += new CcfDeckControl.CloseAppClickHandler(closeAppClick); // End Dynamic if (bar != null) { // Add the CcfPanelToolbar to the deckControl deckControl.Controls.Add(bar); } return(deckControl.ShowApplication(child, closeButton)); } else { // Add the previosly added app from the deckControl to the tabControl if (deckControl.Count > 0) { tabControl.Visible = true; deckControl.Visible = false; tabControl.SelectedIndexChanged += new EventHandler(tabControl_SelectedIndexChanged); // Begin Dynamic tabControl.CloseAppClick += new CcfTabControl.CloseAppClickHandler(closeAppClick); // End Dynamic CcfPanelToolbar tempBar = null; // If there are any CcfPanelToolbar on panel for this control remove from panel and add // to TabPage for this app foreach (Control toolbar in deckControl.Controls) { if (toolbar is CcfPanelToolbar) { tempBar = toolbar as CcfPanelToolbar; deckControl.Controls.Remove(toolbar); break; } else if (toolbar is CcfButtonToolbar) { CcfButtonToolbar tempbar = toolbar as CcfButtonToolbar; tempbar.CloseButtonClick -= new CcfButtonToolbar.CloseButtonClickHandler(closeButtonClick); deckControl.Controls.Remove(tempbar); } } // Only 1 app on the deck control bool closable = deckControl.IsClosableApplication(deckControl.HostedApplications[0] as IHostedApplication); addApplicationToTabControl(deckControl.HostedApplications[0], tempBar, closable); deckControl.RemoveApplication(deckControl.HostedApplications[0]); } return(addApplicationToTabControl(child, bar, closeButton)); } }