/// ------------------------------------------------------------------------------------ /// <summary> /// Saves the paragraph information to the styleInfo /// </summary> /// <param name="styleInfo">The style info.</param> /// ------------------------------------------------------------------------------------ public void SaveToInfo(StyleInfo styleInfo) { CheckDisposed(); if (styleInfo.IsCharacterStyle) { Debug.Assert(false, "Somehow, the Paragraph tab has been asked to write its data to a character-based style [" + styleInfo.Name + "]."); return; } // direction bool newInherit = IsInherited(m_cboDirection); if (styleInfo.IRightToLeftStyle.Save(newInherit, (TriStateBool)m_cboDirection.SelectedIndex)) { styleInfo.Dirty = true; } // alignment newInherit = m_cboAlignment.IsInherited; FwTextAlign newAlignment = FwTextAlign.ktalLeading; switch (m_cboAlignment.AdjustedSelectedIndex) { case 1: newAlignment = FwTextAlign.ktalLeading; break; case 2: newAlignment = FwTextAlign.ktalLeft; break; case 3: newAlignment = FwTextAlign.ktalCenter; break; case 4: newAlignment = FwTextAlign.ktalRight; break; case 5: newAlignment = FwTextAlign.ktalTrailing; break; case 6: newAlignment = FwTextAlign.ktalJustify; break; } if (styleInfo.IAlignment.Save(newInherit, newAlignment)) { styleInfo.Dirty = true; } // background color - only save it if the control is visible if (m_cboBackground.Visible) { newInherit = IsInherited(m_cboBackground); FontInfo fontInfo = styleInfo.FontInfoForWs(-1); // get default FontInfo if (fontInfo.m_backColor.Save(newInherit, m_cboBackground.ColorValue)) { styleInfo.Dirty = true; } } // left indent newInherit = IsInherited(m_nudLeftIndentation); if (styleInfo.ILeadingIndent.Save(newInherit, m_nudLeftIndentation.MeasureValue)) { styleInfo.Dirty = true; } // right indent newInherit = IsInherited(m_nudRightIndentation); if (styleInfo.ITrailingIndent.Save(newInherit, m_nudRightIndentation.MeasureValue)) { styleInfo.Dirty = true; } // special indent newInherit = m_cboSpecialIndentation.IsInherited; int newValue = 0; switch (m_cboSpecialIndentation.AdjustedSelectedIndex) { case 2: newValue = m_nudIndentBy.MeasureValue; break; case 3: newValue = -m_nudIndentBy.MeasureValue; break; } if (styleInfo.IFirstLineIndent.Save(newInherit, newValue)) { styleInfo.Dirty = true; } // spacing before newInherit = IsInherited(m_nudBefore); if (styleInfo.ISpaceBefore.Save(newInherit, m_nudBefore.MeasureValue)) { styleInfo.Dirty = true; } // spacing after newInherit = IsInherited(m_nudAfter); if (styleInfo.ISpaceAfter.Save(newInherit, m_nudAfter.MeasureValue)) { styleInfo.Dirty = true; } // line spacing int index = m_cboLineSpacing.AdjustedSelectedIndex; newInherit = m_cboLineSpacing.IsInherited; LineHeightInfo newLineHeight = new LineHeightInfo(); newLineHeight.m_relative = (index <= 3); switch (index) { case 1: // single spacing newLineHeight.m_lineHeight = 10000; break; case 2: // 1.5 spacing newLineHeight.m_lineHeight = 15000; break; case 3: // double spacing newLineHeight.m_lineHeight = 20000; break; case kAtLeastIndex: // at least newLineHeight.m_lineHeight = m_nudSpacingAt.MeasureValue; break; case kExactlyIndex: // exactly newLineHeight.m_lineHeight = -m_nudSpacingAt.MeasureValue; break; } if (styleInfo.ILineSpacing.Save(newInherit, newLineHeight)) { styleInfo.Dirty = true; } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Adds the paragraph info to the style description /// </summary> /// <param name="text">The text description to append to</param> /// <param name="useBiDiLabels">if set to <c>true</c> use labels suitable for describing /// the style's behavior when applied to bi-directional text.</param> /// <param name="userMeasurementType">User's preferred measurement units for /// indentation.</param> /// ------------------------------------------------------------------------------------ private void AppendParagraphInfo(StringBuilder text, bool useBiDiLabels, MsrSysType userMeasurementType) { if (m_rtl.IsExplicit) { AppendRtl(text); } if (m_alignment.IsExplicit) { AppendAlignment(text); } if (m_leadingIndent.IsExplicit) { AppendMeasure(text, (useBiDiLabels) ? FwCoreDlgControls.ksLeading : FwCoreDlgControls.ksLeft, userMeasurementType, m_leadingIndent.Value); } if (m_trailingIndent.IsExplicit) { AppendMeasure(text, (useBiDiLabels) ? FwCoreDlgControls.ksTrailing : FwCoreDlgControls.ksRight, userMeasurementType, m_trailingIndent.Value); } if (m_firstLineIndent.IsExplicit) { if (m_firstLineIndent.Value < 0) { AppendMeasure(text, FwCoreDlgControls.ksFirstLineHanging, -m_firstLineIndent.Value); } else if (m_firstLineIndent.Value > 0) { AppendMeasure(text, FwCoreDlgControls.ksFirstLineIndent, m_firstLineIndent.Value); } else { AppendItem(text, FwCoreDlgControls.ksSpecialIndent, FwCoreDlgControls.ksNone); } } if (m_spaceBefore.IsExplicit) { AppendMeasure(text, FwCoreDlgControls.ksSpacingBefore, m_spaceBefore.Value); } if (m_spaceAfter.IsExplicit) { AppendMeasure(text, FwCoreDlgControls.ksSpacingAfter, m_spaceAfter.Value); } if (m_lineSpacing.IsExplicit) { LineHeightInfo info = m_lineSpacing.Value; if (info.m_relative) { switch (info.m_lineHeight) { case 10000: AppendItem(text, FwCoreDlgControls.ksSingleSpacing); break; case 15000: AppendItem(text, FwCoreDlgControls.ksPlusSpacing); break; case 20000: AppendItem(text, FwCoreDlgControls.ksDoubleSpacing); break; } } else { if (info.m_lineHeight < 0) { AppendMeasure(text, FwCoreDlgControls.ksExactSpacing, -info.m_lineHeight); } else { AppendMeasure(text, FwCoreDlgControls.ksAtLeastSpacing, info.m_lineHeight); } } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Updates the form based on a style being selected. /// </summary> /// <param name="styleInfo">The style info.</param> /// ------------------------------------------------------------------------------------ public void UpdateForStyle(StyleInfo styleInfo) { CheckDisposed(); #if __MonoCS__ // On Mono, the sequence of events when changing styles can cause this to be // called even when switching to a character style. See FWNX-870. if (!styleInfo.IsParagraphStyle) { return; } #endif // Don't allow controls to undo their inherited state while filling in m_dontUpdateInheritance = true; m_currentStyleInfo = styleInfo; // Initialize controls based on whether or not this style inherits from another style. InitControlBehavior(styleInfo.Inherits); // LTR or RTL m_cboDirection.SetInheritableProp(styleInfo.IRightToLeftStyle); m_cboDirection.AdjustedSelectedIndex = (int)styleInfo.IRightToLeftStyle.Value; ChangeDirectionLabels(styleInfo.IRightToLeftStyle.Value == TriStateBool.triNotSet || m_fShowBiDiLabels ? m_fShowBiDiLabels : styleInfo.IRightToLeftStyle.Value == TriStateBool.triTrue); // Paragraph Alignment m_cboAlignment.SetInheritableProp(styleInfo.IAlignment); switch (styleInfo.IAlignment.Value) { case FwTextAlign.ktalLeading: m_cboAlignment.AdjustedSelectedIndex = 1; break; case FwTextAlign.ktalLeft: m_cboAlignment.AdjustedSelectedIndex = 2; break; case FwTextAlign.ktalCenter: m_cboAlignment.AdjustedSelectedIndex = 3; break; case FwTextAlign.ktalRight: m_cboAlignment.AdjustedSelectedIndex = 4; break; case FwTextAlign.ktalTrailing: m_cboAlignment.AdjustedSelectedIndex = 5; break; case FwTextAlign.ktalJustify: m_cboAlignment.AdjustedSelectedIndex = 6; break; } // Special indent m_cboSpecialIndentation.SetInheritableProp(styleInfo.IFirstLineIndent); if (styleInfo.IFirstLineIndent.Value == 0) { m_cboSpecialIndentation.AdjustedSelectedIndex = 1; // none } else if (styleInfo.IFirstLineIndent.Value > 0) { m_cboSpecialIndentation.AdjustedSelectedIndex = 2; // first line } else { m_cboSpecialIndentation.AdjustedSelectedIndex = 3; // hanging } m_nudIndentBy.ForeColor = GetCtrlForeColorForProp(styleInfo.IFirstLineIndent); m_nudIndentBy.MeasureValue = Math.Abs(styleInfo.IFirstLineIndent.Value); // update the up/down measure controls m_nudLeftIndentation.ForeColor = GetCtrlForeColorForProp(styleInfo.ILeadingIndent); m_nudLeftIndentation.MeasureValue = styleInfo.ILeadingIndent.Value; m_nudRightIndentation.ForeColor = GetCtrlForeColorForProp(styleInfo.ITrailingIndent); m_nudRightIndentation.MeasureValue = styleInfo.ITrailingIndent.Value; m_nudBefore.ForeColor = GetCtrlForeColorForProp(styleInfo.ISpaceBefore); m_nudBefore.MeasureValue = styleInfo.ISpaceBefore.Value; m_nudAfter.ForeColor = GetCtrlForeColorForProp(styleInfo.ISpaceAfter); m_nudAfter.MeasureValue = styleInfo.ISpaceAfter.Value; LineHeightInfo info = styleInfo.ILineSpacing.Value; m_cboLineSpacing.SetInheritableProp(styleInfo.ILineSpacing); m_nudSpacingAt.ForeColor = GetCtrlForeColorForProp(styleInfo.ILineSpacing); if (!info.m_relative) { if (info.m_lineHeight < 0) { // Exact line spacing m_cboLineSpacing.AdjustedSelectedIndex = kExactlyIndex; m_nudSpacingAt.MeasureMin = 1000; } else { // at least line spacing m_cboLineSpacing.AdjustedSelectedIndex = kAtLeastIndex; m_nudSpacingAt.MeasureMin = 0; } m_nudSpacingAt.MeasureValue = Math.Abs(info.m_lineHeight); } else { switch (info.m_lineHeight) { case 10000: // single spacing m_cboLineSpacing.AdjustedSelectedIndex = 1; break; case 15000: // 1.5 line spacing m_cboLineSpacing.AdjustedSelectedIndex = 2; break; case 20000: // double spacing m_cboLineSpacing.AdjustedSelectedIndex = 3; break; } } FontInfo fontInfo = styleInfo.FontInfoForWs(-1); // get default fontInfo m_cboBackground.ForeColor = GetCtrlForeColorForProp(fontInfo.m_backColor); m_cboBackground.ColorValue = fontInfo.m_backColor.Value; m_dontUpdateInheritance = false; }