private void GetStyleNames(SimpleRootSite rootsite, IVwSelection sel, ref string paraStyleName, ref string charStyleName) { ITsTextProps[] vttp; IVwPropertyStore[] vvps; int cttp; SelectionHelper.GetSelectionProps(sel, out vttp, out vvps, out cttp); bool fSingleStyle = true; string sStyle = null; for (int ittp = 0; ittp < cttp; ++ittp) { string style = vttp[ittp].Style(); if (ittp == 0) { sStyle = style; } else if (sStyle != style) { fSingleStyle = false; } } if (fSingleStyle && !String.IsNullOrEmpty(sStyle)) { if (ActiveStyleSheet.GetType(sStyle) == (int)StyleType.kstCharacter) { if (sel.CanFormatChar) { charStyleName = sStyle; } } else { if (sel.CanFormatPara) { paraStyleName = sStyle; } } } if (paraStyleName == null) { // Look at the paragraph (if there is one) to get the paragraph style. var helper = SelectionHelper.GetSelectionInfo(sel, rootsite); var info = helper.GetLevelInfo(SelectionHelper.SelLimitType.End); if (info.Length > 0) { var hvo = info[0].hvo; if (hvo != 0) { var cmObjectRepository = m_callbacks.Cache.ServiceLocator.GetInstance <ICmObjectRepository>(); if (cmObjectRepository.IsValidObjectId(hvo)) // perhaps some sort of dummy; we can't get paragraph style. { var cmo = cmObjectRepository.GetObject(hvo); if (cmo is IStPara) { paraStyleName = (cmo as IStPara).StyleName; } } } } } }