private void UpdateIndentsUI(ParagraphPropertiesDialogInfo properties)
        {
            if (properties.RightIndent.HasValue)
            {
                this.radNumRightIndent.Value = Unit.DipToPoint(properties.RightIndent.Value);
            }
            else
            {
                this.radNumRightIndent.Value = null;
            }

            double?firstIndentValue = null;

            if (properties.FirstLineIndent.HasValue)
            {
                firstIndentValue = Unit.DipToPoint(properties.FirstLineIndent.Value);

                // < 0 is hanging;
                // > 0 is first line;
                // 0 is none;
                if (firstIndentValue > 0)
                {
                    this.radNumFirstIndent.Value           = firstIndentValue;
                    this.comboFirstIndentType.SelectedItem = this.firstLineIndentTypes[FirstLineIndentDialogTypes.FirstLine];
                }
                else if (firstIndentValue < 0)
                {
                    this.comboFirstIndentType.SelectedItem = this.firstLineIndentTypes[FirstLineIndentDialogTypes.Hanging];
                    this.radNumFirstIndent.Value           = -firstIndentValue;
                }
                else
                {
                    this.comboFirstIndentType.SelectedItem = this.firstLineIndentTypes[FirstLineIndentDialogTypes.None];
                }
            }
            else
            {
                this.comboFirstIndentType.SelectedItem = null;
                this.radNumFirstIndent.Value           = null;
            }

            if (properties.LeftIndent.HasValue)
            {
                double leftIndent = Unit.DipToPoint(properties.LeftIndent.Value);
                if (firstIndentValue.HasValue && firstIndentValue.Value < 0)
                {
                    leftIndent += firstIndentValue.Value;
                }

                this.radNumLeftIndent.Value = leftIndent;
            }
            else
            {
                this.radNumLeftIndent.Value = null;
            }
        }
        private void SetInitialValues()
        {
            StyleUIHelper helper = new StyleUIHelper(this.context.Owner);

            this.initialProperties = new ParagraphPropertiesDialogInfo();
            this.initialProperties.TextAlignment = helper.GetTextAlignmentOfParagraphStyle();

            this.initialProperties.AutomaticSpacingBefore = helper.GetAutomaticSpacingBeforeOfParagraphStyle();
            this.initialProperties.AutomaticSpacingAfter  = helper.GetAutomaticSpacingAfterOfParagraphStyle();

            this.initialProperties.LineSpacing     = helper.GetLineSpacingOfParagraphStyle();
            this.initialProperties.LineSpacingType = helper.GetLineSpacingTypeOfParagraphStyle();
            this.initialLineSpacingDialogType      = this.GetLineSpacingDialogType(initialProperties.LineSpacingType, initialProperties.LineSpacing);
            this.initialProperties.Background      = helper.GetBackgroundOfParagraphStyle();
            this.initialProperties.FlowDirection   = helper.GetFlowDirectionOfParagraphStyle();

            double?spacingBefore = helper.GetSpacingBeforeOfParagraphStyle();

            if (spacingBefore.HasValue)
            {
                this.initialProperties.SpacingBefore = spacingBefore.Value;
            }

            double?spacingAfter = helper.GetSpacingAfterOfParagraphStyle();

            if (spacingAfter.HasValue)
            {
                this.initialProperties.SpacingAfter = spacingAfter.Value;
            }

            double?rightIndent = helper.GetRightIndentOfParagraphStyle();

            if (rightIndent.HasValue)
            {
                this.initialProperties.RightIndent = rightIndent.Value;
            }

            double?firstLineIndent = helper.GetFirstLineIndentOfParagraphStyle();

            if (firstLineIndent.HasValue)
            {
                this.initialProperties.FirstLineIndent = firstLineIndent.Value;
            }

            double?leftIndent = helper.GetLeftIndentOfParagraphStyle();

            if (leftIndent.HasValue)
            {
                this.initialProperties.LeftIndent = leftIndent.Value;
            }
        }
 private void ResetInitialValues()
 {
     this.initialProperties = null;
     this.initialLineSpacingDialogType = null;
 }
        private void DefaultButton_Click(object sender, RoutedEventArgs e)
        {
            ParagraphProperties paragraphProperties = new StyleDefinition(StyleType.Paragraph).ParagraphProperties;

            ParagraphPropertiesDialogInfo propertiesInfo = new ParagraphPropertiesDialogInfo()
            {
                TextAlignment = paragraphProperties.TextAlignment,
                SpacingBefore = paragraphProperties.SpacingBefore,
                SpacingAfter = paragraphProperties.SpacingAfter,
                AutomaticSpacingBefore = paragraphProperties.AutomaticSpacingBefore,
                AutomaticSpacingAfter = paragraphProperties.AutomaticSpacingAfter,
                LineSpacingType = paragraphProperties.LineSpacingType,
                LineSpacing = paragraphProperties.LineSpacing,
                Background = paragraphProperties.Background,
                FlowDirection = paragraphProperties.FlowDirection,
                RightIndent = paragraphProperties.RightIndent,
                FirstLineIndent = paragraphProperties.FirstLineIndent,
                LeftIndent = paragraphProperties.LeftIndent
            };

            this.UpdateUICore(propertiesInfo);
            // When multiple paragraphs with different backgrounds are selected, 
            // the initial value is the default one and this prevents ColorChanged event to be fired. 
            // Thus, we need to set this flag manually.
            this.isBackgroundChanged = true;
        }
        private void UpdateIndentsUI(ParagraphPropertiesDialogInfo properties)
        {
            if (properties.RightIndent.HasValue)
            {
                this.radNumRightIndent.Value = Unit.DipToPoint(properties.RightIndent.Value);
            }
            else
            {
                this.radNumRightIndent.Value = null;
            }

            double? firstIndentValue = null;
            if (properties.FirstLineIndent.HasValue)
            {
                firstIndentValue = Unit.DipToPoint(properties.FirstLineIndent.Value);

                // < 0 is hanging; 
                // > 0 is first line; 
                // 0 is none;
                if (firstIndentValue > 0)
                {
                    this.radNumFirstIndent.Value = firstIndentValue;
                    this.comboFirstIndentType.SelectedItem = this.firstLineIndentTypes[FirstLineIndentDialogTypes.FirstLine];
                }
                else if (firstIndentValue < 0)
                {
                    this.comboFirstIndentType.SelectedItem = this.firstLineIndentTypes[FirstLineIndentDialogTypes.Hanging];
                    this.radNumFirstIndent.Value = -firstIndentValue;
                }
                else
                {
                    this.comboFirstIndentType.SelectedItem = this.firstLineIndentTypes[FirstLineIndentDialogTypes.None];
                }
            }
            else
            {
                this.radNumFirstIndent.Value = null;
            }

            if (properties.LeftIndent.HasValue)
            {
                double leftIndent = Unit.DipToPoint(properties.LeftIndent.Value);
                if (firstIndentValue.HasValue && firstIndentValue.Value < 0)
                {
                    leftIndent += firstIndentValue.Value;
                }

                this.radNumLeftIndent.Value = leftIndent;
            }
            else
            {
                this.radNumLeftIndent.Value = null;
            }
        }
        private void UpdateSpacingsUI(ParagraphPropertiesDialogInfo properties)
        {
            if (properties.SpacingBefore.HasValue)
            {
                this.radNumSpacingBefore.Value = Unit.DipToPoint(properties.SpacingBefore.Value);
            }
            else
            {
                this.radNumSpacingBefore.Value = null;
            }

            if (properties.SpacingAfter.HasValue)
            {
                this.radNumSpacingAfter.Value = Unit.DipToPoint(properties.SpacingAfter.Value);
            }
            else
            {
                this.radNumSpacingAfter.Value = null;
            }

            this.checkBoxAutomaticSpacingBefore.IsChecked = properties.AutomaticSpacingBefore;
            this.checkBoxAutomaticSpacingAfter.IsChecked = properties.AutomaticSpacingAfter;
        }
 private void UpdateBackgroundUI(ParagraphPropertiesDialogInfo properties)
 {
     if (properties.Background.HasValue)
     {
         this.paragraphBackgroundColorSelector.SelectedColor = properties.Background.Value;
     }
     else
     {
         this.paragraphBackgroundColorSelector.ClearValue(DropDownColorPicker.SelectedColorProperty);
     }
 }
        private void UpdateUICore(ParagraphPropertiesDialogInfo properties)
        {
            this.comboAligment.SelectedValue = properties.TextAlignment;

            this.UpdateSpacingsUI(properties);
            this.UpdateLineSpacingUI(properties.LineSpacingType, properties.LineSpacing);
            this.UpdateBackgroundUI(properties);
            this.UpdateFlowDirectionUI(properties.FlowDirection);
            this.UpdateIndentsUI(properties);
        }
        private void UpdateUI(ParagraphPropertiesDialogInfo properties)
        {
            this.BeginUpdateUI();

            this.UpdateUICore(properties);

            this.EndUpdateUI();
        }
        private void SetInitialValues()
        {
            StyleUIHelper helper = new StyleUIHelper(this.context.Owner);

            this.initialProperties = new ParagraphPropertiesDialogInfo();
            this.initialProperties.TextAlignment = helper.GetTextAlignmentOfParagraphStyle();

            this.initialProperties.AutomaticSpacingBefore = helper.GetAutomaticSpacingBeforeOfParagraphStyle();
            this.initialProperties.AutomaticSpacingAfter = helper.GetAutomaticSpacingAfterOfParagraphStyle();

            this.initialProperties.LineSpacing = helper.GetLineSpacingOfParagraphStyle();
            this.initialProperties.LineSpacingType = helper.GetLineSpacingTypeOfParagraphStyle();
            this.initialLineSpacingDialogType = this.GetLineSpacingDialogType(initialProperties.LineSpacingType, initialProperties.LineSpacing);
            this.initialProperties.Background = helper.GetBackgroundOfParagraphStyle();
            this.initialProperties.FlowDirection = helper.GetFlowDirectionOfParagraphStyle();

            double? spacingBefore = helper.GetSpacingBeforeOfParagraphStyle();
            if (spacingBefore.HasValue)
            {
                this.initialProperties.SpacingBefore = spacingBefore.Value;
            }

            double? spacingAfter = helper.GetSpacingAfterOfParagraphStyle();
            if (spacingAfter.HasValue)
            {
                this.initialProperties.SpacingAfter = spacingAfter.Value;
            }

            double? rightIndent = helper.GetRightIndentOfParagraphStyle();
            if (rightIndent.HasValue)
            {
                this.initialProperties.RightIndent = rightIndent.Value;
            }

            double? firstLineIndent = helper.GetFirstLineIndentOfParagraphStyle();
            if (firstLineIndent.HasValue)
            {
                this.initialProperties.FirstLineIndent = firstLineIndent.Value;
            }

            double? leftIndent = helper.GetLeftIndentOfParagraphStyle();
            if (leftIndent.HasValue)
            {
                this.initialProperties.LeftIndent = leftIndent.Value;
            }
        }