private void SetBottomMessage() { int userWs = m_cache.LangProject.DefaultUserWritingSystem; int vernWs = m_cache.LangProject.DefaultVernacularWritingSystem; string sBase; if (m_obj != null && m_obj.Hvo > 0) { sBase = FdoUiStrings.ksMergeXIntoY; } else { sBase = FdoUiStrings.ksMergeXIntoSelection; } ITsStrBldr tsb = TsStrBldrClass.Create(); tsb.ReplaceTsString(0, tsb.Length, m_tsf.MakeString(sBase, userWs)); // Replace every "{0}" with the headword we'll be merging, and make it bold. ITsString tssFrom = m_tsf.MakeString(m_mainObj.ToString(), m_mainObj.WS); string sTmp = tsb.Text; int ich = sTmp.IndexOf("{0}"); int cch = tssFrom.Length; while (ich >= 0 && cch > 0) { tsb.ReplaceTsString(ich, ich + 3, tssFrom); tsb.SetIntPropValues(ich, ich + cch, (int)FwTextPropType.ktptBold, (int)FwTextPropVar.ktpvEnum, (int)FwTextToggleVal.kttvForceOn); sTmp = tsb.Text; ich = sTmp.IndexOf("{0}"); // in case localization needs more than one. } if (m_obj != null && m_obj.Hvo > 0) { // Replace every "{1}" with the headword we'll be merging into. ITsString tssTo = m_tsf.MakeString(m_obj.ToString(), m_obj.WS); ich = sTmp.IndexOf("{1}"); cch = tssTo.Length; while (ich >= 0 && cch > 0) { tsb.ReplaceTsString(ich, ich + 3, tssTo); tsb.SetIntPropValues(ich, ich + cch, (int)FwTextPropType.ktptBold, (int)FwTextPropVar.ktpvEnum, (int)FwTextToggleVal.kttvForceOn); sTmp = tsb.Text; ich = sTmp.IndexOf("{0}"); } // Replace every "{2}" with a newline character. ich = sTmp.IndexOf("{2}"); while (ich >= 0) { tsb.ReplaceTsString(ich, ich + 3, m_tsf.MakeString("\x2028", userWs)); sTmp = tsb.Text; ich = sTmp.IndexOf("{2}"); } } else { // Replace every "{1}" with a newline character. ich = sTmp.IndexOf("{1}"); while (ich >= 0) { tsb.ReplaceTsString(ich, ich + 3, m_tsf.MakeString("\x2028", userWs)); sTmp = tsb.Text; ich = sTmp.IndexOf("{1}"); } } m_fwTextBoxBottomMsg.Tss = tsb.GetString(); int oldHeight = m_fwTextBoxBottomMsg.Height; int newHeight = m_fwTextBoxBottomMsg.PreferredHeight; if (newHeight != m_fwTextBoxBottomMsg.Height) { int delta = newHeight - oldHeight; Size = MinimumSize; SIL.FieldWorks.Common.Widgets.FontHeightAdjuster.GrowDialogAndAdjustControls(this, delta, m_fwTextBoxBottomMsg); m_fwTextBoxBottomMsg.Height = newHeight; } }
private void SetBottomMessage() { int userWs = m_cache.ServiceLocator.WritingSystemManager.UserWs; int vernWs = m_cache.ServiceLocator.WritingSystems.DefaultVernacularWritingSystem.Handle; string sBase; if (m_obj != null && m_obj.Hvo > 0) { sBase = FdoUiStrings.ksMergeXIntoY; } else { sBase = FdoUiStrings.ksMergeXIntoSelection; } ITsStrBldr tsb = TsStrBldrClass.Create(); tsb.ReplaceTsString(0, tsb.Length, m_tsf.MakeString(sBase, userWs)); // Replace every "{0}" with the headword we'll be merging, and make it bold. ITsString tssFrom = m_tsf.MakeString(m_mainObj.ToString(), m_mainObj.WS); string sTmp = tsb.Text; int ich = sTmp.IndexOf("{0}"); int cch = tssFrom.Length; while (ich >= 0 && cch > 0) { tsb.ReplaceTsString(ich, ich + 3, tssFrom); tsb.SetIntPropValues(ich, ich + cch, (int)FwTextPropType.ktptBold, (int)FwTextPropVar.ktpvEnum, (int)FwTextToggleVal.kttvForceOn); sTmp = tsb.Text; ich = sTmp.IndexOf("{0}"); // in case localization needs more than one. } int cLines = 1; if (m_obj != null && m_obj.Hvo > 0) { // Replace every "{1}" with the headword we'll be merging into. ITsString tssTo = m_tsf.MakeString(m_obj.ToString(), m_obj.WS); ich = sTmp.IndexOf("{1}"); cch = tssTo.Length; while (ich >= 0 && cch > 0) { tsb.ReplaceTsString(ich, ich + 3, tssTo); tsb.SetIntPropValues(ich, ich + cch, (int)FwTextPropType.ktptBold, (int)FwTextPropVar.ktpvEnum, (int)FwTextToggleVal.kttvForceOn); sTmp = tsb.Text; ich = sTmp.IndexOf("{1}"); } // Replace every "{2}" with a newline character. ich = sTmp.IndexOf("{2}"); while (ich >= 0) { tsb.ReplaceTsString(ich, ich + 3, m_tsf.MakeString(StringUtils.kChHardLB.ToString(), userWs)); sTmp = tsb.Text; ich = sTmp.IndexOf("{2}"); ++cLines; } } else { // Replace every "{1}" with a newline character. ich = sTmp.IndexOf("{1}"); while (ich >= 0) { tsb.ReplaceTsString(ich, ich + 3, m_tsf.MakeString(StringUtils.kChHardLB.ToString(), userWs)); sTmp = tsb.Text; ich = sTmp.IndexOf("{1}"); ++cLines; } } m_fwTextBoxBottomMsg.Tss = tsb.GetString(); int oldHeight = m_fwTextBoxBottomMsg.Height; int newHeight = m_fwTextBoxBottomMsg.PreferredHeight; // Having newlines in the middle of the string messes up the height calculation. // See FWR-2308. The adjustment may not be perfect, but is better than just showing // the text before the first newline. if (newHeight < 30) { newHeight *= cLines; } if (newHeight != m_fwTextBoxBottomMsg.Height) { int delta = newHeight - oldHeight; Size = MinimumSize; SIL.FieldWorks.Common.Widgets.FontHeightAdjuster.GrowDialogAndAdjustControls(this, delta, m_fwTextBoxBottomMsg); m_fwTextBoxBottomMsg.Height = newHeight; } }