private void OnCellSelectedPageChanged(object sender, EventArgs e) { if (ApplyDockingCloseAction || ApplyDockingPinAction) { // Get access to the cached state for this cell KryptonWorkspaceCell cell = (KryptonWorkspaceCell)sender; CachedCellState cellState = _lookupCellState[cell]; // Remove events on the old selected page if (cellState.SelectedPage != null) { cellState.SelectedPage.FlagsChanged -= new KryptonPageFlagsEventHandler(OnCellSelectedPageFlagsChanged); } // Use the new setting cellState.SelectedPage = cell.SelectedPage; UpdateCellActions(cell, cellState); // Add events on the new selected page if (cellState.SelectedPage != null) { cellState.SelectedPage.FlagsChanged += new KryptonPageFlagsEventHandler(OnCellSelectedPageFlagsChanged); } } }
/// <summary> /// Detach an existing cell. /// </summary> /// <param name="cell">Cell being removed from the control.</param> protected override void ExistingCellDetach(KryptonWorkspaceCell cell) { // Grab the per-cell cached state CachedCellState cellState = _lookupCellState[cell]; // Remove all those event hooks used to monitor focus changes FocusMonitorControl(cell, false); // Unhook from events so the cell can be garbage colleced cell.ShowContextMenu -= new EventHandler <ShowContextMenuArgs>(OnCellShowContextMenu); cell.SelectedPageChanged -= new EventHandler(OnCellSelectedPageChanged); cell.PrimaryHeaderLeftClicked -= new EventHandler(OnCellPrimaryHeaderLeftClicked); cell.PrimaryHeaderRightClicked -= new EventHandler(OnCellPrimaryHeaderRightClicked); cell.PrimaryHeaderDoubleClicked -= new EventHandler(OnCellPrimaryHeaderDoubleClicked); cell.TabDoubleClicked -= new EventHandler <KryptonPageEventArgs>(OnCellTabDoubleClicked); cell.TabVisibleCountChanged -= new EventHandler(OnCellTabVisibleCountChanged); cell.Pages.Inserting -= new TypedHandler <KryptonPage>(OnCellPagesInserting); // Remove the per-cell cached state _lookupCellState.Remove(cell); // Let base class unhook from events and reverse other operations base.ExistingCellDetach(cell); }
/// <summary> /// Update the cell settings to reflect the provided page, cell and page flag settings. /// </summary> /// <param name="cell">Reference to workspace cell that needs updating.</param> /// <param name="cellState">Reference to cell specific cached state.</param> protected virtual void UpdateCellActions(KryptonWorkspaceCell cell, CachedCellState cellState) { if (ApplyDockingDropDownAction) { // First time around we need to create the pin button spec if (cellState.DropDownButtonSpec == null) { cellState.DropDownButtonSpec = new ButtonSpecNavigator(); cellState.DropDownButtonSpec.Type = PaletteButtonSpecStyle.DropDown; cellState.DropDownButtonSpec.ToolTipTitle = DropDownTooltip; cellState.DropDownButtonSpec.KryptonContextMenu = new KryptonContextMenu(); cellState.DropDownButtonSpec.KryptonContextMenu.Opening += new CancelEventHandler(OnCellDropDownOpening); cell.Button.ButtonSpecs.Add(cellState.DropDownButtonSpec); } if (cell.SelectedPage == null) { cellState.DropDownButtonSpec.Visible = false; } else { cellState.DropDownButtonSpec.Visible = cell.SelectedPage.AreFlagsSet(KryptonPageFlags.DockingAllowDropDown); } } if (ApplyDockingPinAction) { // First time around we need to create the pin button spec if (cellState.PinButtonSpec == null) { cellState.PinButtonSpec = new ButtonSpecNavigator(); cellState.PinButtonSpec.Type = (AutoHiddenHost ? PaletteButtonSpecStyle.PinHorizontal : PaletteButtonSpecStyle.PinVertical); cellState.PinButtonSpec.ToolTipTitle = PinTooltip; cellState.PinButtonSpec.Click += new EventHandler(OnCellAutoHiddenAction); cell.Button.ButtonSpecs.Add(cellState.PinButtonSpec); } if (cell.SelectedPage == null) { cellState.PinButtonSpec.Visible = false; } else { if (AutoHiddenHost) { cellState.PinButtonSpec.Visible = cell.SelectedPage.AreFlagsSet(KryptonPageFlags.DockingAllowDocked); } else { cellState.PinButtonSpec.Visible = cell.SelectedPage.AreFlagsSet(KryptonPageFlags.DockingAllowAutoHidden); } } } if (ApplyDockingCloseAction) { // First time around we need to create the close button spec if (cellState.CloseButtonSpec == null) { cellState.CloseButtonSpec = new ButtonSpecNavigator(); cellState.CloseButtonSpec.Type = PaletteButtonSpecStyle.Close; cellState.CloseButtonSpec.ToolTipTitle = CloseTooltip; cellState.CloseButtonSpec.Click += new EventHandler(OnCellCloseAction); cell.Button.ButtonSpecs.Add(cellState.CloseButtonSpec); } if (cell.SelectedPage == null) { cellState.CloseButtonSpec.Visible = false; } else { cellState.CloseButtonSpec.Visible = cell.SelectedPage.AreFlagsSet(KryptonPageFlags.DockingAllowClose); } } }
/// <summary> /// Initialize a new cell. /// </summary> /// <param name="cell">Cell being added to the control.</param> protected override void NewCellInitialize(KryptonWorkspaceCell cell) { // Let base class perform event hooking and customizations base.NewCellInitialize(cell); // Should be apply docking specific appearance settings? if (ApplyDockingAppearance) { if (cell.Pages.VisibleCount == 1) { cell.NavigatorMode = NavigatorMode.HeaderGroup; } else { cell.NavigatorMode = NavigatorMode.HeaderGroupTab; } cell.Bar.BarMultiline = BarMultiline.Shrinkline; cell.Bar.BarOrientation = VisualOrientation.Bottom; cell.Bar.TabBorderStyle = TabBorderStyle.DockOutsize; cell.Bar.TabStyle = TabStyle.Dock; cell.Button.ButtonDisplayLogic = ButtonDisplayLogic.None; cell.Button.CloseButtonDisplay = ButtonDisplay.Hide; cell.Header.HeaderStylePrimary = HeaderStyle.DockInactive; cell.Header.HeaderVisibleSecondary = false; cell.Header.HeaderValuesPrimary.MapImage = MapKryptonPageImage.None; cell.ToolTips.AllowButtonSpecToolTips = true; } // Hook into cell specific events cell.ShowContextMenu += new EventHandler <ShowContextMenuArgs>(OnCellShowContextMenu); cell.SelectedPageChanged += new EventHandler(OnCellSelectedPageChanged); cell.PrimaryHeaderLeftClicked += new EventHandler(OnCellPrimaryHeaderLeftClicked); cell.PrimaryHeaderRightClicked += new EventHandler(OnCellPrimaryHeaderRightClicked); cell.PrimaryHeaderDoubleClicked += new EventHandler(OnCellPrimaryHeaderDoubleClicked); cell.TabDoubleClicked += new EventHandler <KryptonPageEventArgs>(OnCellTabDoubleClicked); cell.TabVisibleCountChanged += new EventHandler(OnCellTabVisibleCountChanged); cell.Pages.Inserting += new TypedHandler <KryptonPage>(OnCellPagesInserting); // Create and store per-cell cached state CachedCellState cellState = new CachedCellState(); cellState.Cell = cell; _lookupCellState.Add(cell, cellState); UpdateCellActions(cell, cellState); // We need to know when the focus enters/leaves a cell so styles can be updated FocusMonitorControl(cell, true); // If there is already a selected page then ensure we process its selected state if (cell.SelectedPage != null) { OnCellSelectedPageChanged(cell, EventArgs.Empty); } // If the cell already have pages then raise inserting events for those pages if (cell.Pages.Count > 0) { for (int i = cell.Pages.Count - 1; i >= 0; i--) { OnCellPageInserting(new KryptonPageEventArgs(cell.Pages[i], i)); } } }