/// ------------------------------------------------------------------------------------
        /// <summary>
        /// Shows the Format Apply Style dialog. Apply the results to the selection of the active
        /// view if the user clicks OK.
        /// </summary>
        /// <param name="paraStyleName">Name of the para style.</param>
        /// <param name="charStyleName">Name of the char style.</param>
        /// <param name="maxStyleLevel">The maximum style level that will be shown in this
        /// dialog. (apps that do not use style levels in their stylesheets can pass 0)</param>
        /// ------------------------------------------------------------------------------------
        public void ShowApplyStyleDialog(string paraStyleName, string charStyleName, int maxStyleLevel)
        {
            SimpleRootSite rootsite = (ActiveView as SimpleRootSite);

            try
            {
                if (rootsite != null)
                {
                    rootsite.ShowRangeSelAfterLostFocus = true;
                }

                int hvoRoot, frag;
                IVwViewConstructor vc;
                IVwStylesheet      ss;
                ActiveView.CastAsIVwRootSite().RootBox.GetRootObject(out hvoRoot, out vc, out frag, out ss);
                using (FwApplyStyleDlg applyStyleDlg = new FwApplyStyleDlg(ActiveView.CastAsIVwRootSite(),
                                                                           Cache, StyleSheet.RootObjectHvo, StyleSheetOwningFlid,
                                                                           StyleSheet.GetDefaultBasedOnStyleName(), maxStyleLevel,
                                                                           paraStyleName, charStyleName, hvoRoot, FwApp.App, FwApp.App))
                {
                    if (FwEditingHelper != null)
                    {
                        if (FwEditingHelper.ApplicableStyleContexts != null)
                        {
                            applyStyleDlg.ApplicableStyleContexts = FwEditingHelper.ApplicableStyleContexts;
                        }
                    }
                    else if (FwApp.App != null)
                    {
                        // Window doesn't have an editing helper, go with whole-app default
                        if (FwApp.App.DefaultStyleContexts != null)
                        {
                            applyStyleDlg.ApplicableStyleContexts = FwApp.App.DefaultStyleContexts;
                        }
                    }
                    applyStyleDlg.AllowSelectStyleTypes = m_callbacks.ShowSelectStylesComboInStylesDialog;
                    IVwSelection sel = EditingHelper.CurrentSelection.Selection;
                    applyStyleDlg.CanApplyCharacterStyle = sel.CanFormatChar;
                    applyStyleDlg.CanApplyParagraphStyle = sel.CanFormatPara;

                    if (applyStyleDlg.ShowDialog(m_callbacks) == DialogResult.OK)
                    {
                        EditingHelper.ApplyStyle(applyStyleDlg.StyleChosen);
                    }
                }
            }
            finally
            {
                if (rootsite != null)
                {
                    rootsite.ShowRangeSelAfterLostFocus = false;
                }
            }
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Shows the Format Styles dialog.
        /// </summary>
        /// <param name="paraStyleName">Name of the initially selected paragraph style.</param>
        /// <param name="charStyleName">Name of the initially selected character style.</param>
        /// <returns>
        /// true if a refresh is needed to reload the cache
        /// </returns>
        /// ------------------------------------------------------------------------------------
        public bool ShowStylesDialog(string paraStyleName, string charStyleName)
        {
            StVc        vc             = null;
            IVwRootSite activeViewSite = null;

            if (ActiveView != null)
            {
                vc             = ActiveView.EditingHelper.ViewConstructor as StVc;
                activeViewSite = ActiveView.CastAsIVwRootSite();
            }
            using (FwStylesDlg stylesDlg = new FwStylesDlg(activeViewSite,
                                                           Cache, StyleSheet, (vc == null) ? false : vc.RightToLeft,
                                                           Cache.ProjectIncludesRightToLeftWs, StyleSheet.GetDefaultBasedOnStyleName(),
                                                           MaxStyleLevelToShow, FwApp.MeasurementSystem, paraStyleName, charStyleName,
                                                           HvoAppRootObject, FwApp.App, FwApp.App))
            {
                stylesDlg.StylesRenamedOrDeleted +=
                    new FwStylesDlg.StylesRenOrDelDelegate(m_callbacks.OnStylesRenamedOrDeleted);
                stylesDlg.AllowSelectStyleTypes             = m_callbacks.ShowSelectStylesComboInStylesDialog;
                stylesDlg.CanSelectParagraphBackgroundColor = m_callbacks.CanSelectParagraphBackgroundColor;
                return(stylesDlg.ShowDialog(m_callbacks) == DialogResult.OK &&
                       ((stylesDlg.ChangeType & StyleChangeType.DefChanged) > 0 ||
                        (stylesDlg.ChangeType & StyleChangeType.Added) > 0));
            }
        }