/// ------------------------------------------------------------------------------------ /// <summary> /// Activate the view /// </summary> /// ------------------------------------------------------------------------------------ void ISelectableView.ActivateView() { ActivateView(); ISelectableView grid = m_gridControl as ISelectableView; if (grid != null) { grid.ActivateView(); } }
/// ----------------------------------------------------------------------------------- /// <summary> /// Make it inactive by hiding it. /// </summary> /// ----------------------------------------------------------------------------------- void ISelectableView.DeactivateView() { CheckDisposed(); Enabled = false; Visible = false; Enabled = true; ISelectableView grid = m_gridControl as ISelectableView; if (grid != null) { grid.DeactivateView(); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Hide the previously active client window and activate the new one /// </summary> /// <param name="selectedView">client window to switch to</param> /// ------------------------------------------------------------------------------------ public virtual bool SwitchActiveView(ISelectableView selectedView) { CheckDisposed(); using (new WaitCursor(this)) { // If the user minimizes the app during startup, we need to restore it before // activating the view so it gets laid out correctly. if (WindowState == FormWindowState.Minimized) WindowState = FormWindowState.Normal; if (selectedView == null || selectedView == m_selectedView) return true; if (selectedView is Control && ((Control)selectedView).FindForm() != this) { // we don't want to deactivate a view of another main window! Fix for TE-3305 return false; } // deactivate the old view if it is not the same as the new one if (m_selectedView != null && selectedView != m_selectedView) m_selectedView.DeactivateView(); InformationBarText = selectedView.BaseInfoBarCaption; // There is a strange quirk (perhaps bug) where a view's window first appears // at 0,0 relative to the FwMainWnd's client area before it pops into its // container control. Therefore, we set the default location of the view's // window to somewhere outside the viewable area so the user won't see the // strange behavior. Control view = selectedView as Control; if (view != null && view.Location == new Point(0, 0)) view.Location = new Point(this.Width + 10, 10); Logger.WriteEvent("Switching view to " + view.Name + " (" + Text + ")"); // activate the new view, even if it is the same view so that the focus will come back selectedView.ActivateView(); m_selectedView = selectedView; return true; } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Clean up any resources being used. /// </summary> /// ------------------------------------------------------------------------------------ protected override void Dispose(bool disposing) { Debug.WriteLineIf(!disposing, "****************** Missing Dispose() call for " + GetType().Name + ". ******************"); // Must not be run more than once. if (IsDisposed || m_beingDisposed || Disposing) return; m_beingDisposed = true; if (disposing) { foreach (Control ctrl in m_rgClientViews.Values) { // Dispose of any views that aren't in the form currently. if (ctrl.Parent == null) ctrl.Dispose(); } if (m_mediator != null) { m_mediator.ProcessMessages = false; m_mediator.RemoveColleague(this); } if (m_cboZoomPercent != null) m_cboZoomPercent.Dispose(); if (m_paraStylesComboBox != null) m_paraStylesComboBox.Dispose(); if (m_charStylesComboBox != null) m_charStylesComboBox.Dispose(); if (m_writingSystemSelector != null) m_writingSystemSelector.Dispose(); if (m_progressHandler != null) m_progressHandler.Dispose(); if (m_writingSystemSelector != null) m_writingSystemSelector.Dispose(); if (m_UndoRedoDropDown != null) m_UndoRedoDropDown.Dispose(); if (components != null) components.Dispose(); // no need to explicitly call Dispose on m_persistence - it's part of // components collection and gets disposed there. if (m_rgClientViews != null) m_rgClientViews.Clear(); if (m_tmAdapter != null) { m_tmAdapter.LoadControlContainerItem -= LoadCustomToolBarControls; m_tmAdapter.InitializeComboItem -= InitializeToolBarCombos; m_tmAdapter.Dispose(); } if (m_cache != null) m_cache.ProjectNameChanged -= ProjectNameChanged; if (m_app != null) { // The removing of the window from the app's collection needs to happen later, after // this main window is already disposed of. This is needed for side-effects // that require a running message loop (such as closing the TE notes view // which would normally happen at this call without a running message loop) m_app.FwManager.ExecuteAsync(m_app.RemoveWindow, this); } } m_cboZoomPercent = null; m_paraStylesComboBox = null; m_charStylesComboBox = null; m_writingSystemSelector = null; m_delegate = null; m_tmAdapter = null; m_UndoRedoDropDown = null; m_writingSystemSelector = null; m_StyleSheet = null; m_selectedView = null; m_rgClientViews = null; #if !__MonoCS__ base.Dispose(disposing); #else try { base.Dispose(disposing); } catch (System.ArgumentOutOfRangeException) { // TODO-Linux: examine ToolStrip disposal in UIAdapter // is ToolStrip (from UIAdapter?) being Disposed multiple times? } #endif if (disposing) { if (m_viewHelper != null) m_viewHelper.Dispose(); if (m_mediator != null) m_mediator.Dispose(); } m_cache = null; m_viewHelper = null; m_mediator = null; m_app = null; m_beingDisposed = false; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Clean up any resources being used. /// </summary> /// ------------------------------------------------------------------------------------ protected override void Dispose(bool disposing) { //Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************"); // Must not be run more than once. if (IsDisposed || m_beingDisposed || Disposing) return; m_beingDisposed = true; FdoCache wndCache = null; if (disposing) { foreach (Control ctrl in m_rgClientWindows.Values) { // Dispose of any views that aren't in the form currently. if (ctrl.Parent == null) ctrl.Dispose(); } if (m_mediator != null) { m_mediator.ProcessMessages = false; m_mediator.RemoveColleague(this); } if (m_writingSystemSelector != null) m_writingSystemSelector.Dispose(); if (m_UndoRedoDropDown != null) m_UndoRedoDropDown.Dispose(); if (components != null) components.Dispose(); // no need to explicitly call Dispose on m_persistence - it's part of // components collection and gets disposed there. if (m_delegate != null) m_delegate.Dispose(); if (m_rgClientWindows != null) m_rgClientWindows.Clear(); if (m_cache != null && m_cache.ProgressBar == m_progressHandler) m_cache.ProgressBar = null; if (FwApp.App != null) { FwApp.App.OkToCloseApp = false; // Make sure we don't shutdown too soon FwApp.App.RemoveWindow(this, out wndCache); } } m_delegate = null; m_UndoRedoDropDown = null; m_writingSystemSelector = null; m_StyleSheet = null; m_selectedView = null; m_rgClientWindows = null; base.Dispose(disposing); if (disposing) { if (m_viewHelper != null) m_viewHelper.Dispose(); if (m_mediator != null) m_mediator.Dispose(); if (FwApp.App != null) { // Remove the cache as the last step. Hopefully this will fix some // ObjectDisposed exceptions we get but can't reproduce. (TE-8340) FwApp.App.OkToCloseApp = true; if (wndCache != null) FwApp.App.RemoveFdoCache(wndCache); } } m_cache = null; m_viewHelper = null; m_mediator = null; m_beingDisposed = false; }
/// <summary> /// Executes in two distinct scenarios. /// /// 1. If disposing is true, the method has been called directly /// or indirectly by a user's code via the Dispose method. /// Both managed and unmanaged resources can be disposed. /// /// 2. If disposing is false, the method has been called by the /// runtime from inside the finalizer and you should not reference (access) /// other managed objects, as they already have been garbage collected. /// Only unmanaged resources can be disposed. /// </summary> /// <param name="disposing"></param> /// <remarks> /// If any exceptions are thrown, that is fine. /// If the method is being done in a finalizer, it will be ignored. /// If it is thrown by client code calling Dispose, /// it needs to be handled by fixing the bug. /// /// If subclasses override this method, they should call the base implementation. /// </remarks> protected override void Dispose(bool disposing) { //Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************"); // Must not be run more than once. if (IsDisposed || Disposing) return; if (disposing) { // Dispose managed resources here. Application.RemoveMessageFilter(this); // KeyTermsViewWrapper gets disposed when base class disposes ClientWindows if (m_gotoRefCtrl != null && m_gotoRefCtrl.Parent == null) m_gotoRefCtrl.Dispose(); if (m_changeWatcher != null) m_changeWatcher.Dispose(); if (m_scrDraftView != null && (m_scrDraftView as Control).Parent == null && m_scrDraftView is IDisposable) (m_scrDraftView as IDisposable).Dispose(); } // Dispose unmanaged resources here, whether disposing is true or false. m_gotoRefCtrl = null; m_changeWatcher = null; m_scrDraftView = null; base.Dispose(disposing); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Creates the Scripture/Draft View /// </summary> /// <param name="userView">The user view.</param> /// <param name="viewType">Type of the view.</param> /// <param name="tabItem">The tab item.</param> /// <returns></returns> /// ------------------------------------------------------------------------------------ protected ISelectableView CreateDraftView(UserView userView, TeViewType viewType, SBTabItemProperties tabItem) { DraftViewCreateInfo topDraftView = new DraftViewCreateInfo("TopDraftView", false, false, false, true, true, TeViewType.DraftView); StylebarCreateInfo topStylebar = new StylebarCreateInfo("Top", false); DraftViewCreateInfo bottomDraftView = new DraftViewCreateInfo("BottomDraftView", false, false, false, true, true, TeViewType.DraftView); StylebarCreateInfo bottomStylebar = new StylebarCreateInfo("Bottom", false); FootnoteCreateInfo footnoteDraftView = new FootnoteCreateInfo("DraftFootnoteView", false, true); StylebarCreateInfo footnoteStylebar = new StylebarCreateInfo("Footnote", true); // Construct the one draft view wrapper (client window) DraftViewWrapper draftViewWrap = new DraftViewWrapper(kDraftViewWrapperName, this, m_cache, StyleSheet, SettingsKey, topDraftView, topStylebar, bottomDraftView, bottomStylebar, footnoteDraftView, footnoteStylebar); ((ISelectableView)draftViewWrap).BaseInfoBarCaption = userView.ViewNameShort; draftViewWrap.ResumeLayout(); if (tabItem != null) { tabItem.Tag = draftViewWrap; tabItem.Update = true; } Debug.Assert(m_scrDraftView == null, "Shouldn't try to create a draft view if one already exists"); m_scrDraftView = draftViewWrap; ClientControls.Add(draftViewWrap); // Bring the draftView to the top of the z-order, so that // (if it is the active view) it fills only the remaining space draftViewWrap.BringToFront(); ClientWindows.Add(TeEditingHelper.ViewTypeString(viewType), draftViewWrap); m_uncreatedViews.Remove(viewType); return draftViewWrap; }