From 357f885b5e052cc60342710b25b00c083b881071 Mon Sep 17 00:00:00 2001 From: David Gardiner Date: Sat, 20 Feb 2016 17:37:19 +1030 Subject: [PATCH] Table percent widths and no widths Radio buttons for pixels and percent --- .../OpenLiveWriter.PostEditor.csproj | 1 + .../Tables/CellPropertiesControl.cs | 41 ++--- .../Tables/CellPropertiesControl.resx | 108 ++++--------- .../Tables/CellPropertiesForm.cs | 36 +++-- .../Tables/CellPropertiesForm.resx | 99 ++++-------- .../Tables/ColumnPropertiesForm.cs | 58 +++---- .../Tables/ColumnPropertiesForm.resx | 135 ++++------------- .../Tables/ColumnWidthControl.cs | 114 +++++++++----- .../Tables/ColumnWidthControl.resx | 99 ++++-------- .../Tables/HTMLTableColumn.cs | 11 +- .../Tables/PixelPercent.cs | 143 ++++++++++++++++++ .../Tables/TableEditor.cs | 61 ++++---- .../Tables/TableHelper.cs | 22 ++- .../Tables/TablePropertiesForm.cs | 8 +- 14 files changed, 475 insertions(+), 461 deletions(-) create mode 100644 src/managed/OpenLiveWriter.PostEditor/Tables/PixelPercent.cs diff --git a/src/managed/OpenLiveWriter.PostEditor/OpenLiveWriter.PostEditor.csproj b/src/managed/OpenLiveWriter.PostEditor/OpenLiveWriter.PostEditor.csproj index 3afb39f9..3a2dfe00 100644 --- a/src/managed/OpenLiveWriter.PostEditor/OpenLiveWriter.PostEditor.csproj +++ b/src/managed/OpenLiveWriter.PostEditor/OpenLiveWriter.PostEditor.csproj @@ -807,6 +807,7 @@ UserControl + Form diff --git a/src/managed/OpenLiveWriter.PostEditor/Tables/CellPropertiesControl.cs b/src/managed/OpenLiveWriter.PostEditor/Tables/CellPropertiesControl.cs index 42f346ba..90789bfe 100644 --- a/src/managed/OpenLiveWriter.PostEditor/Tables/CellPropertiesControl.cs +++ b/src/managed/OpenLiveWriter.PostEditor/Tables/CellPropertiesControl.cs @@ -113,47 +113,48 @@ namespace OpenLiveWriter.PostEditor.Tables this.horizontalAlignmentControl = new OpenLiveWriter.PostEditor.Tables.HorizontalAlignmentControl(); this.groupBoxCells.SuspendLayout(); this.SuspendLayout(); - // + // // groupBoxCells - // - this.groupBoxCells.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); + // + this.groupBoxCells.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.groupBoxCells.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; this.groupBoxCells.Controls.Add(this.verticalAlignmentControl); this.groupBoxCells.Controls.Add(this.horizontalAlignmentControl); this.groupBoxCells.FlatStyle = System.Windows.Forms.FlatStyle.System; this.groupBoxCells.Location = new System.Drawing.Point(0, 0); this.groupBoxCells.Name = "groupBoxCells"; - this.groupBoxCells.Size = new System.Drawing.Size(304, 136); + this.groupBoxCells.Size = new System.Drawing.Size(233, 108); this.groupBoxCells.TabIndex = 2; this.groupBoxCells.TabStop = false; this.groupBoxCells.Text = "Cells"; - // + // // verticalAlignmentControl - // - this.verticalAlignmentControl.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.verticalAlignmentControl.Location = new System.Drawing.Point(15, 56); + // + this.verticalAlignmentControl.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.verticalAlignmentControl.Location = new System.Drawing.Point(15, 60); this.verticalAlignmentControl.Name = "verticalAlignmentControl"; - this.verticalAlignmentControl.Size = new System.Drawing.Size(283, 21); + this.verticalAlignmentControl.Size = new System.Drawing.Size(212, 28); this.verticalAlignmentControl.TabIndex = 1; this.verticalAlignmentControl.VerticalAlignment = OpenLiveWriter.PostEditor.Tables.VerticalAlignment.Middle; - // + // // horizontalAlignmentControl - // - this.horizontalAlignmentControl.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); + // + this.horizontalAlignmentControl.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); this.horizontalAlignmentControl.HorizontalAlignment = OpenLiveWriter.PostEditor.Tables.HorizontalAlignment.Left; this.horizontalAlignmentControl.Location = new System.Drawing.Point(15, 25); this.horizontalAlignmentControl.Name = "horizontalAlignmentControl"; - this.horizontalAlignmentControl.Size = new System.Drawing.Size(283, 21); + this.horizontalAlignmentControl.Size = new System.Drawing.Size(212, 31); this.horizontalAlignmentControl.TabIndex = 0; - // + // // CellPropertiesControl - // + // this.Controls.Add(this.groupBoxCells); this.Name = "CellPropertiesControl"; - this.Size = new System.Drawing.Size(304, 136); + this.Size = new System.Drawing.Size(239, 108); this.groupBoxCells.ResumeLayout(false); this.ResumeLayout(false); diff --git a/src/managed/OpenLiveWriter.PostEditor/Tables/CellPropertiesControl.resx b/src/managed/OpenLiveWriter.PostEditor/Tables/CellPropertiesControl.resx index ee4f9355..d58980a3 100644 --- a/src/managed/OpenLiveWriter.PostEditor/Tables/CellPropertiesControl.resx +++ b/src/managed/OpenLiveWriter.PostEditor/Tables/CellPropertiesControl.resx @@ -3,7 +3,7 @@ + + + + + + + + + + + + + + + + + + - + + @@ -89,78 +109,12 @@ text/microsoft-resx - 1.3 + 2.0 - System.Resources.ResXResourceReader, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - Private - - - 8, 8 - - - True - - - False - - - True - - - Private - - - False - - - Private - - - Private - - - Private - - - False - - - Private - - - False - - - False - - - True - - - True - - - 80 - - - (Default) - - - False - - - CellPropertiesControl - - - Private - - - 8, 8 - \ No newline at end of file diff --git a/src/managed/OpenLiveWriter.PostEditor/Tables/CellPropertiesForm.cs b/src/managed/OpenLiveWriter.PostEditor/Tables/CellPropertiesForm.cs index 8946bd97..17d22203 100644 --- a/src/managed/OpenLiveWriter.PostEditor/Tables/CellPropertiesForm.cs +++ b/src/managed/OpenLiveWriter.PostEditor/Tables/CellPropertiesForm.cs @@ -94,48 +94,54 @@ namespace OpenLiveWriter.PostEditor.Tables /// private void InitializeComponent() { + OpenLiveWriter.PostEditor.Tables.CellProperties cellProperties1 = new OpenLiveWriter.PostEditor.Tables.CellProperties(); this.buttonOK = new System.Windows.Forms.Button(); this.buttonCancel = new System.Windows.Forms.Button(); this.cellPropertiesControl = new OpenLiveWriter.PostEditor.Tables.CellPropertiesControl(); this.SuspendLayout(); - // + // // buttonOK - // + // this.buttonOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonOK.FlatStyle = System.Windows.Forms.FlatStyle.System; - this.buttonOK.Location = new System.Drawing.Point(85, 112); + this.buttonOK.Location = new System.Drawing.Point(114, 158); this.buttonOK.Name = "buttonOK"; + this.buttonOK.Size = new System.Drawing.Size(105, 33); this.buttonOK.TabIndex = 2; this.buttonOK.Text = "OK"; this.buttonOK.Click += new System.EventHandler(this.buttonOK_Click); - // + // // buttonCancel - // + // this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; this.buttonCancel.FlatStyle = System.Windows.Forms.FlatStyle.System; - this.buttonCancel.Location = new System.Drawing.Point(166, 112); + this.buttonCancel.Location = new System.Drawing.Point(227, 158); this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(105, 33); this.buttonCancel.TabIndex = 3; this.buttonCancel.Text = "Cancel"; - // + // // cellPropertiesControl - // - this.cellPropertiesControl.Location = new System.Drawing.Point(9, 8); + // + cellProperties1.BackgroundColor = null; + cellProperties1.HorizontalAlignment = OpenLiveWriter.PostEditor.Tables.HorizontalAlignment.Left; + cellProperties1.VerticalAlignment = OpenLiveWriter.PostEditor.Tables.VerticalAlignment.Middle; + this.cellPropertiesControl.CellProperties = cellProperties1; + this.cellPropertiesControl.Location = new System.Drawing.Point(13, 11); this.cellPropertiesControl.Name = "cellPropertiesControl"; - this.cellPropertiesControl.Size = new System.Drawing.Size(231, 97); + this.cellPropertiesControl.Size = new System.Drawing.Size(323, 139); this.cellPropertiesControl.TabIndex = 4; - // + // // CellPropertiesForm - // + // this.AcceptButton = this.buttonOK; - this.AutoScaleBaseSize = new System.Drawing.Size(5, 14); this.CancelButton = this.buttonCancel; - this.ClientSize = new System.Drawing.Size(250, 143); + this.ClientSize = new System.Drawing.Size(345, 202); this.Controls.Add(this.cellPropertiesControl); this.Controls.Add(this.buttonCancel); this.Controls.Add(this.buttonOK); - this.Location = new System.Drawing.Point(0, 0); + this.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "CellPropertiesForm"; diff --git a/src/managed/OpenLiveWriter.PostEditor/Tables/CellPropertiesForm.resx b/src/managed/OpenLiveWriter.PostEditor/Tables/CellPropertiesForm.resx index 04dc40b1..d58980a3 100644 --- a/src/managed/OpenLiveWriter.PostEditor/Tables/CellPropertiesForm.resx +++ b/src/managed/OpenLiveWriter.PostEditor/Tables/CellPropertiesForm.resx @@ -3,7 +3,7 @@ + + + + + + + + + + + + + + + + + + - + + @@ -89,69 +109,12 @@ text/microsoft-resx - 1.3 + 2.0 - System.Resources.ResXResourceReader, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - False - - - Private - - - Private - - - False - - - Private - - - Private - - - Private - - - False - - - Private - - - False - - - (Default) - - - False - - - False - - - 8, 8 - - - CellPropertiesForm - - - True - - - 80 - - - False - - - Private - \ No newline at end of file diff --git a/src/managed/OpenLiveWriter.PostEditor/Tables/ColumnPropertiesForm.cs b/src/managed/OpenLiveWriter.PostEditor/Tables/ColumnPropertiesForm.cs index 0134e03e..25b4e8a7 100644 --- a/src/managed/OpenLiveWriter.PostEditor/Tables/ColumnPropertiesForm.cs +++ b/src/managed/OpenLiveWriter.PostEditor/Tables/ColumnPropertiesForm.cs @@ -98,6 +98,7 @@ namespace OpenLiveWriter.PostEditor.Tables /// private void InitializeComponent() { + OpenLiveWriter.PostEditor.Tables.CellProperties cellProperties1 = new OpenLiveWriter.PostEditor.Tables.CellProperties(); this.buttonCancel = new System.Windows.Forms.Button(); this.groupBoxSize = new System.Windows.Forms.GroupBox(); this.columnWidthControl = new OpenLiveWriter.PostEditor.Tables.ColumnWidthControl(); @@ -106,70 +107,75 @@ namespace OpenLiveWriter.PostEditor.Tables this.cellPropertiesControl = new OpenLiveWriter.PostEditor.Tables.CellPropertiesControl(); this.groupBoxSize.SuspendLayout(); this.SuspendLayout(); - // + // // buttonCancel - // + // this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; this.buttonCancel.FlatStyle = System.Windows.Forms.FlatStyle.System; - this.buttonCancel.Location = new System.Drawing.Point(169, 184); + this.buttonCancel.Location = new System.Drawing.Point(379, 201); this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(105, 33); this.buttonCancel.TabIndex = 3; this.buttonCancel.Text = "Cancel"; - // + // // groupBoxSize - // + // this.groupBoxSize.Controls.Add(this.columnWidthControl); this.groupBoxSize.FlatStyle = System.Windows.Forms.FlatStyle.System; - this.groupBoxSize.Location = new System.Drawing.Point(9, 8); + this.groupBoxSize.Location = new System.Drawing.Point(13, 11); this.groupBoxSize.Name = "groupBoxSize"; - this.groupBoxSize.Size = new System.Drawing.Size(234, 66); + this.groupBoxSize.Size = new System.Drawing.Size(341, 79); this.groupBoxSize.TabIndex = 0; this.groupBoxSize.TabStop = false; this.groupBoxSize.Text = "Size"; - // + // // columnWidthControl - // - this.columnWidthControl.ColumnWidth = 0; - this.columnWidthControl.Location = new System.Drawing.Point(15, 24); + // + this.columnWidthControl.Location = new System.Drawing.Point(21, 25); this.columnWidthControl.Name = "columnWidthControl"; - this.columnWidthControl.Size = new System.Drawing.Size(209, 23); + this.columnWidthControl.Size = new System.Drawing.Size(308, 36); this.columnWidthControl.TabIndex = 0; - // + // // label11 - // + // this.label11.Location = new System.Drawing.Point(1, 1); this.label11.Name = "label11"; + this.label11.Size = new System.Drawing.Size(100, 23); this.label11.TabIndex = 0; - // + // // buttonOK - // + // this.buttonOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonOK.FlatStyle = System.Windows.Forms.FlatStyle.System; - this.buttonOK.Location = new System.Drawing.Point(86, 184); + this.buttonOK.Location = new System.Drawing.Point(262, 201); this.buttonOK.Name = "buttonOK"; + this.buttonOK.Size = new System.Drawing.Size(105, 33); this.buttonOK.TabIndex = 2; this.buttonOK.Text = "OK"; this.buttonOK.Click += new System.EventHandler(this.buttonOK_Click); - // + // // cellPropertiesControl - // - this.cellPropertiesControl.Location = new System.Drawing.Point(9, 79); + // + cellProperties1.BackgroundColor = null; + cellProperties1.HorizontalAlignment = OpenLiveWriter.PostEditor.Tables.HorizontalAlignment.Left; + cellProperties1.VerticalAlignment = OpenLiveWriter.PostEditor.Tables.VerticalAlignment.Middle; + this.cellPropertiesControl.CellProperties = cellProperties1; + this.cellPropertiesControl.Location = new System.Drawing.Point(13, 113); this.cellPropertiesControl.Name = "cellPropertiesControl"; - this.cellPropertiesControl.Size = new System.Drawing.Size(234, 98); + this.cellPropertiesControl.Size = new System.Drawing.Size(243, 120); this.cellPropertiesControl.TabIndex = 1; - // + // // ColumnPropertiesForm - // + // this.AcceptButton = this.buttonOK; - this.AutoScaleBaseSize = new System.Drawing.Size(5, 14); this.CancelButton = this.buttonCancel; - this.ClientSize = new System.Drawing.Size(253, 215); + this.ClientSize = new System.Drawing.Size(496, 245); this.Controls.Add(this.cellPropertiesControl); this.Controls.Add(this.buttonOK); this.Controls.Add(this.groupBoxSize); this.Controls.Add(this.buttonCancel); - this.Location = new System.Drawing.Point(0, 0); + this.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "ColumnPropertiesForm"; diff --git a/src/managed/OpenLiveWriter.PostEditor/Tables/ColumnPropertiesForm.resx b/src/managed/OpenLiveWriter.PostEditor/Tables/ColumnPropertiesForm.resx index 5023b541..d58980a3 100644 --- a/src/managed/OpenLiveWriter.PostEditor/Tables/ColumnPropertiesForm.resx +++ b/src/managed/OpenLiveWriter.PostEditor/Tables/ColumnPropertiesForm.resx @@ -3,7 +3,7 @@ + + + + + + + + + + + + + + + + + + - + + @@ -89,105 +109,12 @@ text/microsoft-resx - 1.3 + 2.0 - System.Resources.ResXResourceReader, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - False - - - Private - - - Private - - - Private - - - 8, 8 - - - True - - - False - - - True - - - Private - - - False - - - Private - - - Private - - - False - - - Private - - - Private - - - False - - - Private - - - Private - - - False - - - Private - - - Private - - - False - - - (Default) - - - False - - - False - - - 8, 8 - - - ColumnPropertiesForm - - - True - - - 80 - - - False - - - Private - \ No newline at end of file diff --git a/src/managed/OpenLiveWriter.PostEditor/Tables/ColumnWidthControl.cs b/src/managed/OpenLiveWriter.PostEditor/Tables/ColumnWidthControl.cs index d90ea1d8..2d01d411 100644 --- a/src/managed/OpenLiveWriter.PostEditor/Tables/ColumnWidthControl.cs +++ b/src/managed/OpenLiveWriter.PostEditor/Tables/ColumnWidthControl.cs @@ -32,7 +32,9 @@ namespace OpenLiveWriter.PostEditor.Tables { private OpenLiveWriter.Controls.NumericTextBox textBoxWidth; private System.Windows.Forms.Label labelWidth; - private System.Windows.Forms.Label labelPixels; + private RadioButton rbPixels; + private RadioButton rbPercent; + /// /// Required designer variable. /// @@ -43,7 +45,7 @@ namespace OpenLiveWriter.PostEditor.Tables // This call is required by the Windows.Forms Form Designer. InitializeComponent(); this.labelWidth.Text = Res.Get(StringId.WidthLabel); - this.labelPixels.Text = Res.Get(StringId.pixels); + this.rbPixels.Text = Res.Get(StringId.pixels); } protected override void OnLoad(EventArgs e) @@ -53,12 +55,13 @@ namespace OpenLiveWriter.PostEditor.Tables using (new AutoGrow(this, AnchorStyles.Right, false)) { DisplayHelper.AutoFitSystemLabel(labelWidth, 0, int.MaxValue); - DisplayHelper.AutoFitSystemLabel(labelPixels, 0, int.MaxValue); - LayoutHelper.DistributeHorizontally(8, labelWidth, textBoxWidth, labelPixels); + DisplayHelper.AutoFitSystemRadioButton(rbPixels, 0, int.MaxValue); + DisplayHelper.AutoFitSystemRadioButton(rbPercent, 0, int.MaxValue); + LayoutHelper.DistributeHorizontally(8, labelWidth, textBoxWidth, rbPixels, rbPercent); } } - public int ColumnWidth + public PixelPercent ColumnWidth { get { @@ -66,22 +69,36 @@ namespace OpenLiveWriter.PostEditor.Tables { try { - return int.Parse(textBoxWidth.Text, CultureInfo.CurrentCulture); + var units = rbPercent.Checked ? PixelPercentUnits.Percentage : PixelPercentUnits.Pixels; + return new PixelPercent(textBoxWidth.Text, CultureInfo.CurrentCulture, units); } catch { - return 0; + return new PixelPercent(); } } else - return 0; + return new PixelPercent(); } set { - if (value != 0) - textBoxWidth.Text = value.ToString(CultureInfo.CurrentCulture); + if (value.Units != PixelPercentUnits.Undefined) + { + textBoxWidth.Text = value.Value.ToString(CultureInfo.CurrentCulture); + } else + { textBoxWidth.Text = String.Empty; + } + + if (value.Units == PixelPercentUnits.Percentage) + { + rbPercent.Checked = true; + } + else + { + rbPixels.Checked = true; + } } } @@ -92,20 +109,19 @@ namespace OpenLiveWriter.PostEditor.Tables public bool ValidateInput(int maxValue) { - int result; - if (textBoxWidth.Text == String.Empty || !Int32.TryParse(textBoxWidth.Text, out result)) + if (!PixelPercent.CanParse(textBoxWidth.Text)) { DisplayMessage.Show(MessageId.UnspecifiedValue, this, Res.Get(StringId.Width)); textBoxWidth.Focus(); return false; } - else if (ColumnWidth <= 0) + else if (ColumnWidth.Units != PixelPercentUnits.Undefined && ColumnWidth.Value <= 0) { DisplayMessage.Show(MessageId.InvalidNumberPositiveOnly, FindForm(), Res.Get(StringId.Width)); textBoxWidth.Focus(); return false; } - else if (maxValue > 0 && ColumnWidth >= maxValue) + else if (maxValue > 0 && ColumnWidth.Units != PixelPercentUnits.Undefined && ColumnWidth.Value >= maxValue) { DisplayMessage.Show(MessageId.ValueExceedsMaximum, FindForm(), maxValue, Res.Get(StringId.Width)); textBoxWidth.Focus(); @@ -139,50 +155,66 @@ namespace OpenLiveWriter.PostEditor.Tables /// private void InitializeComponent() { - this.textBoxWidth = new OpenLiveWriter.Controls.NumericTextBox(); this.labelWidth = new System.Windows.Forms.Label(); - this.labelPixels = new System.Windows.Forms.Label(); + this.rbPixels = new System.Windows.Forms.RadioButton(); + this.rbPercent = new System.Windows.Forms.RadioButton(); + this.textBoxWidth = new OpenLiveWriter.Controls.NumericTextBox(); this.SuspendLayout(); - // - // textBoxWidth - // - this.textBoxWidth.Location = new System.Drawing.Point(72, 0); - this.textBoxWidth.MaxLength = 9; - this.textBoxWidth.Name = "textBoxWidth"; - this.textBoxWidth.Size = new System.Drawing.Size(46, 20); - this.textBoxWidth.TabIndex = 2; - this.textBoxWidth.Text = ""; - // + // // labelWidth - // + // this.labelWidth.FlatStyle = System.Windows.Forms.FlatStyle.System; this.labelWidth.Location = new System.Drawing.Point(0, 3); this.labelWidth.Name = "labelWidth"; this.labelWidth.Size = new System.Drawing.Size(64, 15); this.labelWidth.TabIndex = 0; this.labelWidth.Text = "&Width:"; - // - // labelPixels - // - this.labelPixels.FlatStyle = System.Windows.Forms.FlatStyle.System; - this.labelPixels.Location = new System.Drawing.Point(120, 3); - this.labelPixels.Name = "labelPixels"; - this.labelPixels.Size = new System.Drawing.Size(63, 15); - this.labelPixels.TabIndex = 3; - this.labelPixels.Text = "pixels"; - // + // + // rbPixels + // + this.rbPixels.AutoSize = true; + this.rbPixels.Checked = true; + this.rbPixels.FlatStyle = System.Windows.Forms.FlatStyle.System; + this.rbPixels.Location = new System.Drawing.Point(124, 3); + this.rbPixels.Name = "rbPixels"; + this.rbPixels.Size = new System.Drawing.Size(67, 22); + this.rbPixels.TabIndex = 4; + this.rbPixels.TabStop = true; + this.rbPixels.Text = "pixels"; + this.rbPixels.UseVisualStyleBackColor = true; + // + // rbPercent + // + this.rbPercent.AutoSize = true; + this.rbPercent.FlatStyle = System.Windows.Forms.FlatStyle.System; + this.rbPercent.Location = new System.Drawing.Point(194, 3); + this.rbPercent.Name = "rbPercent"; + this.rbPercent.Size = new System.Drawing.Size(80, 22); + this.rbPercent.TabIndex = 5; + this.rbPercent.Text = "percent"; + this.rbPercent.UseVisualStyleBackColor = true; + // + // textBoxWidth + // + this.textBoxWidth.Location = new System.Drawing.Point(72, 0); + this.textBoxWidth.MaxLength = 9; + this.textBoxWidth.Name = "textBoxWidth"; + this.textBoxWidth.Size = new System.Drawing.Size(46, 22); + this.textBoxWidth.TabIndex = 2; + // // ColumnWidthControl - // - this.Controls.Add(this.labelPixels); + // + this.Controls.Add(this.rbPercent); + this.Controls.Add(this.rbPixels); this.Controls.Add(this.textBoxWidth); this.Controls.Add(this.labelWidth); this.Name = "ColumnWidthControl"; - this.Size = new System.Drawing.Size(348, 23); + this.Size = new System.Drawing.Size(284, 23); this.ResumeLayout(false); + this.PerformLayout(); } #endregion - } diff --git a/src/managed/OpenLiveWriter.PostEditor/Tables/ColumnWidthControl.resx b/src/managed/OpenLiveWriter.PostEditor/Tables/ColumnWidthControl.resx index 7b85c514..d58980a3 100644 --- a/src/managed/OpenLiveWriter.PostEditor/Tables/ColumnWidthControl.resx +++ b/src/managed/OpenLiveWriter.PostEditor/Tables/ColumnWidthControl.resx @@ -3,7 +3,7 @@ + + + + + + + + + + + + + + + + + + - + + @@ -89,69 +109,12 @@ text/microsoft-resx - 1.3 + 2.0 - System.Resources.ResXResourceReader, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - Private - - - False - - - Private - - - False - - - Private - - - Private - - - False - - - Private - - - Private - - - False - - - False - - - False - - - (Default) - - - True - - - 80 - - - False - - - Private - - - ColumnWidthControl - - - 8, 8 - \ No newline at end of file diff --git a/src/managed/OpenLiveWriter.PostEditor/Tables/HTMLTableColumn.cs b/src/managed/OpenLiveWriter.PostEditor/Tables/HTMLTableColumn.cs index 1fd9c5f7..93fabd1b 100644 --- a/src/managed/OpenLiveWriter.PostEditor/Tables/HTMLTableColumn.cs +++ b/src/managed/OpenLiveWriter.PostEditor/Tables/HTMLTableColumn.cs @@ -36,11 +36,11 @@ namespace OpenLiveWriter.PostEditor.Tables } } - public int Width + public PixelPercent Width { get { - return TableHelper.GetCellWidth(_baseCell); + return new PixelPercent((string) _baseCell.width); //TableHelper.GetCellWidth(_baseCell); } set { @@ -245,13 +245,14 @@ namespace OpenLiveWriter.PostEditor.Tables private class CellWidthProcessor : IColumnCellProcessor { - private int _width; - public CellWidthProcessor(int width) { _width = width; } + private PixelPercent _width; + public CellWidthProcessor(PixelPercent width) { _width = width; } public void ProcessCell(IHTMLTableCell cell) { - if (_width > 0) + if (_width > 0 && _width.Units != PixelPercentUnits.Undefined) { + cell.width = _width.ToString(CultureInfo.InvariantCulture); } else diff --git a/src/managed/OpenLiveWriter.PostEditor/Tables/PixelPercent.cs b/src/managed/OpenLiveWriter.PostEditor/Tables/PixelPercent.cs new file mode 100644 index 00000000..54a99427 --- /dev/null +++ b/src/managed/OpenLiveWriter.PostEditor/Tables/PixelPercent.cs @@ -0,0 +1,143 @@ +using System; +using System.Diagnostics; +using System.Globalization; + +namespace OpenLiveWriter.PostEditor.Tables +{ + public enum PixelPercentUnits + { + Undefined, + Pixels, + Percentage + } + + /// + /// Represents a value that can be a number of pixels or a percentage + /// + [DebuggerDisplay("{Value} {Units}")] + public struct PixelPercent + { + public PixelPercent(int value, PixelPercentUnits units) : this() + { + Units = units; + + if (value < 0) + throw new ArgumentOutOfRangeException("value", value, "value must be greater than zero"); + + if (value > 100 && units == PixelPercentUnits.Percentage) + throw new ArgumentOutOfRangeException("value", value, + "value when percent must be less or equal to 100"); + + Value = value; + } + + public PixelPercent(string text, IFormatProvider provider, PixelPercentUnits units) + { + if (string.IsNullOrEmpty(text)) + { + Value = 0; + Units = PixelPercentUnits.Undefined; + } + else + { + var s = text.Trim(); + Units = units; + + var value = int.Parse(s, provider); + + Value = value; + } + } + + public PixelPercent(string text, IFormatProvider provider) : this() + { + if (string.IsNullOrEmpty(text)) + { + Value = 0; + Units = PixelPercentUnits.Undefined; + } + else + { + var s = text.Trim(); + var units = PixelPercentUnits.Pixels; + + if (s.EndsWith("%")) + { + units = PixelPercentUnits.Percentage; + s = s.TrimEnd('%'); + } + + var value = int.Parse(s, provider); + Value = value; + Units = units; + } + } + + public static bool CanParse(string text) + { + try + { + var p = new PixelPercent(text, CultureInfo.InvariantCulture); + return true; + } + catch (Exception) + { + return false; + } + + } + + public PixelPercent(string text) : this(text, CultureInfo.CurrentCulture) + { + } + + public int Value { get; private set; } + + public PixelPercentUnits Units { get; private set; } + + public static PixelPercent operator / (PixelPercent left, int right) + { + if (right <= 0) + throw new InvalidOperationException("Can't divide PixelPercent by zero or negative numbers"); + + if (left.Units == PixelPercentUnits.Undefined) + throw new InvalidOperationException("Can't divide PixelPercent as it doesn't have an assigned value"); + + return new PixelPercent(left.Value / right, left.Units); + } + + public static PixelPercent operator * (PixelPercent left, int right) + { + throw new NotImplementedException(); + } + + public static implicit operator int(PixelPercent value) + { + return value.Value; + } + + public static implicit operator PixelPercent(int value) + { + return new PixelPercent(value, PixelPercentUnits.Pixels); + } + + public override string ToString() + { + return ToString(CultureInfo.CurrentCulture); + } + + public string ToString(IFormatProvider provider) + { + switch (Units) + { + case PixelPercentUnits.Percentage: + return String.Format(provider, "{0}%", Value); + case PixelPercentUnits.Pixels: + return String.Format(provider, "{0}", Value); + default: + return String.Empty; + } + + } + } +} \ No newline at end of file diff --git a/src/managed/OpenLiveWriter.PostEditor/Tables/TableEditor.cs b/src/managed/OpenLiveWriter.PostEditor/Tables/TableEditor.cs index 09cc8db3..64bb1ce2 100644 --- a/src/managed/OpenLiveWriter.PostEditor/Tables/TableEditor.cs +++ b/src/managed/OpenLiveWriter.PostEditor/Tables/TableEditor.cs @@ -38,7 +38,7 @@ namespace OpenLiveWriter.PostEditor.Tables if (parentCellBlock is IHTMLTableCell) { int parentCellWidth = parentCellBlock.clientWidth != 0 ? parentCellBlock.clientWidth : parentCellBlock.scrollWidth; - parameters.Properties.Width = Math.Min(parameters.Properties.Width, parentCellWidth); + parameters.Properties.Width = Math.Min(parentCellWidth, parameters.Properties.Width); } } @@ -58,7 +58,19 @@ namespace OpenLiveWriter.PostEditor.Tables tableHtml.Append("\r\n"); // write cells - int columnWidth = parameters.Properties.Width / parameters.Columns; + string columnWidth = String.Empty; + + switch (parameters.Properties.Width.Units) + { + case PixelPercentUnits.Pixels: + int width = parameters.Properties.Width / parameters.Columns; + columnWidth = string.Format(" width=\"{0}\"", width); + break; + case PixelPercentUnits.Percentage: + columnWidth = string.Format(" width=\"{0}%\"", 100 / parameters.Columns); + break; + } + for (int r = 0; r < parameters.Rows; r++) { tableHtml.Append("\r\n"); @@ -67,11 +79,12 @@ namespace OpenLiveWriter.PostEditor.Tables { // add default alignment and width to each cell string valign = " valign=\"top\""; // (more natural/expected behavior than middle) - tableHtml.AppendFormat("\r\n", valign, columnWidth); + tableHtml.AppendFormat("\r\n", valign, columnWidth); } tableHtml.Append("\r\n"); } + // end table tableHtml.Append("\r\n"); @@ -447,22 +460,27 @@ namespace OpenLiveWriter.PostEditor.Tables // get the existing width, calculate the delta, then spread // the delta across all of the columns - int existingWidth = TableHelper.GetTableWidth(TableSelection.Table); - int changeInWidth = value.Width - existingWidth; - IHTMLTableRow firstRow = TableSelection.Table.rows.item(0, 0) as IHTMLTableRow; - if (firstRow.cells.length > 0) + var existingWidth = TableHelper.GetTableWidth(TableSelection.Table); + + if (existingWidth.Units == PixelPercentUnits.Pixels) { - int changePerColumn = changeInWidth / firstRow.cells.length; - int leftoverChange = changeInWidth % firstRow.cells.length; - foreach (IHTMLTableCell cell in firstRow.cells) + int changeInWidth = value.Width - existingWidth; + IHTMLTableRow firstRow = TableSelection.Table.rows.item(0, 0) as IHTMLTableRow; + if (firstRow.cells.length > 0) { - HTMLTableColumn column = new HTMLTableColumn(TableSelection.Table, cell); - column.Width = column.Width + changePerColumn + leftoverChange; - leftoverChange = 0; // allocate only once + int changePerColumn = changeInWidth / firstRow.cells.length; + int leftoverChange = changeInWidth % firstRow.cells.length; + foreach (IHTMLTableCell cell in firstRow.cells) + { + HTMLTableColumn column = new HTMLTableColumn(TableSelection.Table, cell); + column.Width = column.Width + changePerColumn + leftoverChange; + leftoverChange = 0; // allocate only once + } } } + // also set the width of the whole table to match the columns - TableSelection.Table.width = value.Width; + TableSelection.Table.width = value.Width.ToString(); // update borders TableHelper.UpdateDesignTimeBorders(TableSelection.Table); @@ -1326,12 +1344,7 @@ namespace OpenLiveWriter.PostEditor.Tables } private string _borderSize = String.Empty; - public int Width - { - get { return _width; } - set { _width = value; } - } - private int _width = 0; + public PixelPercent Width { get; set; } } public class CellProperties @@ -1377,12 +1390,8 @@ namespace OpenLiveWriter.PostEditor.Tables public class ColumnProperties { - public int Width - { - get { return _width; } - set { _width = value; } - } - private int _width = 0; + public PixelPercent Width { get; set; } + public CellProperties CellProperties { diff --git a/src/managed/OpenLiveWriter.PostEditor/Tables/TableHelper.cs b/src/managed/OpenLiveWriter.PostEditor/Tables/TableHelper.cs index ba9dfc43..7b9e6555 100644 --- a/src/managed/OpenLiveWriter.PostEditor/Tables/TableHelper.cs +++ b/src/managed/OpenLiveWriter.PostEditor/Tables/TableHelper.cs @@ -93,22 +93,22 @@ namespace OpenLiveWriter.PostEditor.Tables } } - public static int GetTableWidth(IHTMLTable table) + public static PixelPercent GetTableWidth(IHTMLTable table) { if (table.width != null) { try { - return int.Parse(table.width.ToString(), CultureInfo.InvariantCulture); + return new PixelPercent(table.width.ToString(), CultureInfo.InvariantCulture); } catch { - return 0; + return new PixelPercent(); } } else { - return 0; + return new PixelPercent(); } } @@ -132,8 +132,14 @@ namespace OpenLiveWriter.PostEditor.Tables } } - public static int GetTableLogicalEditingWidth(IHTMLTable table) + public static PixelPercent GetTableLogicalEditingWidth(IHTMLTable table) { + // If percentage, then just keep that + var width = GetTableWidth(table); + + if (width.Units == PixelPercentUnits.Percentage || width.Units == PixelPercentUnits.Undefined) + return width; + // value to return (default to zero) int logicalWidth = 0; @@ -173,9 +179,9 @@ namespace OpenLiveWriter.PostEditor.Tables public static void SynchronizeTableWidthForEditing(IHTMLTable table) { - int logicalWidth = TableHelper.GetTableLogicalEditingWidth(table); - if (logicalWidth > 0) - table.width = logicalWidth; + var logicalWidth = TableHelper.GetTableLogicalEditingWidth(table); + if (logicalWidth > 0 && logicalWidth.Units != PixelPercentUnits.Undefined) + table.width = logicalWidth.ToString(); else (table as IHTMLElement).removeAttribute("width", 0); } diff --git a/src/managed/OpenLiveWriter.PostEditor/Tables/TablePropertiesForm.cs b/src/managed/OpenLiveWriter.PostEditor/Tables/TablePropertiesForm.cs index 1a9400a4..f8d61bb7 100644 --- a/src/managed/OpenLiveWriter.PostEditor/Tables/TablePropertiesForm.cs +++ b/src/managed/OpenLiveWriter.PostEditor/Tables/TablePropertiesForm.cs @@ -119,7 +119,9 @@ namespace OpenLiveWriter.PostEditor.Tables TableCreationParameters creationParameters = CreateDefaultParameters(); numericTextBoxRows.Text = creationParameters.Rows.ToString(CultureInfo.CurrentCulture); numericTextBoxColumns.Text = creationParameters.Columns.ToString(CultureInfo.CurrentCulture); - columnWidthControl.Text = creationParameters.Properties.Width.ToString(CultureInfo.CurrentCulture); + + var width = creationParameters.Properties.Width; + columnWidthControl.Text = width.ToString(CultureInfo.CurrentCulture); InitializeFormProperties(creationParameters.Properties); // show the dialog @@ -376,7 +378,7 @@ namespace OpenLiveWriter.PostEditor.Tables tableProperties.CellPadding = TableEditingSettings.DefaultCellPadding; tableProperties.CellSpacing = TableEditingSettings.DefaultCellSpacing; tableProperties.BorderSize = TableEditingSettings.DefaultBorderSize; - tableProperties.Width = TableEditingSettings.DefaultWidth; + tableProperties.Width = new PixelPercent(); // return default parameters return new TableCreationParameters( @@ -479,7 +481,7 @@ namespace OpenLiveWriter.PostEditor.Tables // this.columnWidthControl.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.columnWidthControl.ColumnWidth = 0; + this.columnWidthControl.ColumnWidth = new PixelPercent(); this.columnWidthControl.ImeMode = System.Windows.Forms.ImeMode.Off; this.columnWidthControl.Location = new System.Drawing.Point(16, 55); this.columnWidthControl.Name = "columnWidthControl";