diff --git a/Greenshot/Drawing/TextContainer.cs b/Greenshot/Drawing/TextContainer.cs
index 0c72b464b..80f9a66f5 100644
--- a/Greenshot/Drawing/TextContainer.cs
+++ b/Greenshot/Drawing/TextContainer.cs
@@ -35,572 +35,590 @@ using System.Windows.Forms;
namespace Greenshot.Drawing
{
- ///
- /// Represents a textbox (extends RectangleContainer for border/background support
- ///
- [Serializable]
- public class TextContainer : RectangleContainer, ITextContainer
- {
- // If makeUndoable is true the next text-change will make the change undoable.
- // This is set to true AFTER the first change is made, as there is already a "add element" on the undo stack
- // Although the name is wrong, we can't change it due to file serialization
- // ReSharper disable once InconsistentNaming
- private bool makeUndoable;
- [NonSerialized]
- private Font _font;
- public Font Font => _font;
+ ///
+ /// Represents a textbox (extends RectangleContainer for border/background support
+ ///
+ [Serializable]
+ public class TextContainer : RectangleContainer, ITextContainer
+ {
+ // If makeUndoable is true the next text-change will make the change undoable.
+ // This is set to true AFTER the first change is made, as there is already a "add element" on the undo stack
+ // Although the name is wrong, we can't change it due to file serialization
+ // ReSharper disable once InconsistentNaming
+ private bool makeUndoable;
+ [NonSerialized]
+ private Font _font;
+ public Font Font => _font;
- [NonSerialized]
- private TextBox _textBox;
+ [NonSerialized]
+ private TextBox _textBox;
- ///
- /// The StringFormat object is not serializable!!
- ///
- [NonSerialized]
- private StringFormat _stringFormat = new StringFormat();
+ ///
+ /// The StringFormat object is not serializable!!
+ ///
+ [NonSerialized]
+ private StringFormat _stringFormat = new StringFormat();
- public StringFormat StringFormat => _stringFormat;
+ public StringFormat StringFormat => _stringFormat;
- // Although the name is wrong, we can't change it due to file serialization
- // ReSharper disable once InconsistentNaming
- private string text;
- // there is a binding on the following property!
- public string Text
- {
- get { return text; }
- set
- {
- ChangeText(value, true);
- }
- }
+ // Although the name is wrong, we can't change it due to file serialization
+ // ReSharper disable once InconsistentNaming
+ private string text;
+ // there is a binding on the following property!
+ public string Text
+ {
+ get { return text; }
+ set
+ {
+ ChangeText(value, true);
+ }
+ }
- internal void ChangeText(string newText, bool allowUndoable)
- {
- if ((text == null && newText != null) || !string.Equals(text, newText))
- {
- if (makeUndoable && allowUndoable)
- {
- makeUndoable = false;
- _parent.MakeUndoable(new TextChangeMemento(this), false);
- }
- text = newText;
- OnPropertyChanged("Text");
- }
- }
+ internal void ChangeText(string newText, bool allowUndoable)
+ {
+ if ((text == null && newText != null) || !string.Equals(text, newText))
+ {
+ if (makeUndoable && allowUndoable)
+ {
+ makeUndoable = false;
+ _parent.MakeUndoable(new TextChangeMemento(this), false);
+ }
+ text = newText;
+ OnPropertyChanged("Text");
+ }
+ }
- public TextContainer(Surface parent) : base(parent)
- {
- Init();
- }
+ public TextContainer(Surface parent) : base(parent)
+ {
+ Init();
+ }
- protected override void InitializeFields()
- {
- AddField(GetType(), FieldType.LINE_THICKNESS, 2);
- AddField(GetType(), FieldType.LINE_COLOR, Color.Red);
- AddField(GetType(), FieldType.SHADOW, true);
- AddField(GetType(), FieldType.FONT_ITALIC, false);
- AddField(GetType(), FieldType.FONT_BOLD, false);
- AddField(GetType(), FieldType.FILL_COLOR, Color.Transparent);
- AddField(GetType(), FieldType.FONT_FAMILY, FontFamily.GenericSansSerif.Name);
- AddField(GetType(), FieldType.FONT_SIZE, 11f);
- AddField(GetType(), FieldType.TEXT_HORIZONTAL_ALIGNMENT, StringAlignment.Center);
- AddField(GetType(), FieldType.TEXT_VERTICAL_ALIGNMENT, StringAlignment.Center);
- }
+ protected override void InitializeFields()
+ {
+ AddField(GetType(), FieldType.LINE_THICKNESS, 2);
+ AddField(GetType(), FieldType.LINE_COLOR, Color.Red);
+ AddField(GetType(), FieldType.SHADOW, true);
+ AddField(GetType(), FieldType.FONT_ITALIC, false);
+ AddField(GetType(), FieldType.FONT_BOLD, false);
+ AddField(GetType(), FieldType.FILL_COLOR, Color.Transparent);
+ AddField(GetType(), FieldType.FONT_FAMILY, FontFamily.GenericSansSerif.Name);
+ AddField(GetType(), FieldType.FONT_SIZE, 11f);
+ AddField(GetType(), FieldType.TEXT_HORIZONTAL_ALIGNMENT, StringAlignment.Center);
+ AddField(GetType(), FieldType.TEXT_VERTICAL_ALIGNMENT, StringAlignment.Center);
+ }
- ///
- /// Do some logic to make sure all field are initiated correctly
- ///
- /// StreamingContext
- protected override void OnDeserialized(StreamingContext streamingContext)
- {
- base.OnDeserialized(streamingContext);
- Init();
- }
+ ///
+ /// Do some logic to make sure all field are initiated correctly
+ ///
+ /// StreamingContext
+ protected override void OnDeserialized(StreamingContext streamingContext)
+ {
+ base.OnDeserialized(streamingContext);
+ Init();
+ }
- protected override void Dispose(bool disposing)
- {
- if (disposing)
- {
- if (_font != null)
- {
- _font.Dispose();
- _font = null;
- }
- if (_stringFormat != null)
- {
- _stringFormat.Dispose();
- _stringFormat = null;
- }
- if (_textBox != null)
- {
- _textBox.Dispose();
- _textBox = null;
- }
- }
- base.Dispose(disposing);
- }
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing)
+ {
+ if (_font != null)
+ {
+ _font.Dispose();
+ _font = null;
+ }
+ if (_stringFormat != null)
+ {
+ _stringFormat.Dispose();
+ _stringFormat = null;
+ }
+ if (_textBox != null)
+ {
+ _textBox.Dispose();
+ _textBox = null;
+ }
+ }
+ base.Dispose(disposing);
+ }
- private void Init()
- {
- _stringFormat = new StringFormat
- {
- Trimming = StringTrimming.EllipsisWord
- };
+ private void Init()
+ {
+ _stringFormat = new StringFormat
+ {
+ Trimming = StringTrimming.EllipsisWord
+ };
- CreateTextBox();
+ CreateTextBox();
- UpdateFormat();
- UpdateTextBoxFormat();
+ UpdateFormat();
+ UpdateTextBoxFormat();
- PropertyChanged += TextContainer_PropertyChanged;
- FieldChanged += TextContainer_FieldChanged;
- }
+ PropertyChanged += TextContainer_PropertyChanged;
+ FieldChanged += TextContainer_FieldChanged;
+ }
- public override void Invalidate()
- {
- base.Invalidate();
- if (_textBox != null && _textBox.Visible)
- {
- _textBox.Invalidate();
- }
- }
+ public override void Invalidate()
+ {
+ base.Invalidate();
+ if (_textBox != null && _textBox.Visible)
+ {
+ _textBox.Invalidate();
+ }
+ }
- public void FitToText()
- {
- Size textSize = TextRenderer.MeasureText(text, _font);
- int lineThickness = GetFieldValueAsInt(FieldType.LINE_THICKNESS);
- Width = textSize.Width + lineThickness;
- Height = textSize.Height + lineThickness;
- }
+ public void FitToText()
+ {
+ Size textSize = TextRenderer.MeasureText(text, _font);
+ int lineThickness = GetFieldValueAsInt(FieldType.LINE_THICKNESS);
+ Width = textSize.Width + lineThickness;
+ Height = textSize.Height + lineThickness;
+ }
- private void TextContainer_PropertyChanged(object sender, PropertyChangedEventArgs e)
- {
- if (_textBox == null)
- {
- return;
- }
+ private void TextContainer_PropertyChanged(object sender, PropertyChangedEventArgs e)
+ {
+ if (_textBox == null)
+ {
+ return;
+ }
- if (_textBox.Visible)
- {
- _textBox.Invalidate();
- }
+ if (_textBox.Visible)
+ {
+ _textBox.Invalidate();
+ }
- UpdateTextBoxPosition();
- UpdateTextBoxFormat();
- if (e.PropertyName.Equals("Selected"))
- {
- if (!Selected && _textBox.Visible)
- {
- HideTextBox();
- }
- else if (Selected && Status == EditStatus.DRAWING)
- {
- ShowTextBox();
- }
- else if (_parent != null && Selected && Status == EditStatus.IDLE && _textBox.Visible)
- {
- // Fix (workaround) for BUG-1698
- _parent.KeysLocked = true;
- }
- }
- if (_textBox.Visible)
- {
- _textBox.Invalidate();
- }
- }
+ UpdateTextBoxPosition();
+ UpdateTextBoxFormat();
+ if (e.PropertyName.Equals("Selected"))
+ {
+ if (!Selected && _textBox.Visible)
+ {
+ HideTextBox();
+ }
+ else if (Selected && Status == EditStatus.DRAWING)
+ {
+ ShowTextBox();
+ }
+ else if (_parent != null && Selected && Status == EditStatus.IDLE && _textBox.Visible)
+ {
+ // Fix (workaround) for BUG-1698
+ _parent.KeysLocked = true;
+ }
+ }
+ if (_textBox.Visible)
+ {
+ _textBox.Invalidate();
+ }
+ }
- private void TextContainer_FieldChanged(object sender, FieldChangedEventArgs e)
- {
- if (_textBox == null)
- {
- return;
- }
- if (_textBox.Visible)
- {
- _textBox.Invalidate();
- }
- // Only dispose the font, and re-create it, when a font field has changed.
- if (e.Field.FieldType.Name.StartsWith("FONT"))
- {
- if (_font != null)
- {
- _font.Dispose();
- _font = null;
- }
- UpdateFormat();
- }
- else
- {
- UpdateAlignment();
- }
- UpdateTextBoxFormat();
+ private void TextContainer_FieldChanged(object sender, FieldChangedEventArgs e)
+ {
+ if (_textBox == null)
+ {
+ return;
+ }
+ if (_textBox.Visible)
+ {
+ _textBox.Invalidate();
+ }
+ // Only dispose the font, and re-create it, when a font field has changed.
+ if (e.Field.FieldType.Name.StartsWith("FONT"))
+ {
+ if (_font != null)
+ {
+ _font.Dispose();
+ _font = null;
+ }
+ UpdateFormat();
+ }
+ else
+ {
+ UpdateAlignment();
+ }
+ UpdateTextBoxFormat();
- if (_textBox.Visible)
- {
- _textBox.Invalidate();
- }
- }
+ if (_textBox.Visible)
+ {
+ _textBox.Invalidate();
+ }
+ }
- public override void OnDoubleClick()
- {
- ShowTextBox();
- }
+ public override void OnDoubleClick()
+ {
+ ShowTextBox();
+ }
- private void CreateTextBox()
- {
- _textBox = new TextBox
- {
- ImeMode = ImeMode.On,
- Multiline = true,
- AcceptsTab = true,
- AcceptsReturn = true,
- BorderStyle = BorderStyle.None,
- Visible = false
- };
+ private void CreateTextBox()
+ {
+ _textBox = new TextBox
+ {
+ ImeMode = ImeMode.On,
+ Multiline = true,
+ AcceptsTab = true,
+ AcceptsReturn = true,
+ BorderStyle = BorderStyle.None,
+ Visible = false
+ };
- _textBox.DataBindings.Add("Text", this, "Text", false, DataSourceUpdateMode.OnPropertyChanged);
- _textBox.LostFocus += textBox_LostFocus;
- _textBox.KeyDown += textBox_KeyDown;
- }
+ _textBox.DataBindings.Add("Text", this, "Text", false, DataSourceUpdateMode.OnPropertyChanged);
+ _textBox.LostFocus += textBox_LostFocus;
+ _textBox.KeyDown += textBox_KeyDown;
+ }
- private void ShowTextBox()
- {
- if (_parent != null)
- {
- _parent.KeysLocked = true;
- _parent.Controls.Add(_textBox);
- }
- EnsureTextBoxContrast();
- if (_textBox != null)
- {
- _textBox.Show();
- _textBox.Focus();
- }
- }
+ private void ShowTextBox()
+ {
+ if (_parent != null)
+ {
+ _parent.KeysLocked = true;
+ _parent.Controls.Add(_textBox);
+ }
+ EnsureTextBoxContrast();
+ if (_textBox != null)
+ {
+ _textBox.Show();
+ _textBox.Focus();
+ }
+ }
- ///
- /// Makes textbox background dark if text color is very bright
- ///
- private void EnsureTextBoxContrast()
- {
- if (_textBox == null)
- {
- return;
- }
- Color lc = GetFieldValueAsColor(FieldType.LINE_COLOR);
- if (lc.R > 203 && lc.G > 203 && lc.B > 203)
- {
- _textBox.BackColor = Color.FromArgb(51, 51, 51);
- }
- else
- {
- _textBox.BackColor = Color.White;
- }
- }
+ ///
+ /// Makes textbox background dark if text color is very bright
+ ///
+ private void EnsureTextBoxContrast()
+ {
+ if (_textBox == null)
+ {
+ return;
+ }
+ Color lc = GetFieldValueAsColor(FieldType.LINE_COLOR);
+ if (lc.R > 203 && lc.G > 203 && lc.B > 203)
+ {
+ _textBox.BackColor = Color.FromArgb(51, 51, 51);
+ }
+ else
+ {
+ _textBox.BackColor = Color.White;
+ }
+ }
- private void HideTextBox()
- {
- _parent.Focus();
- _textBox?.Hide();
- _parent.KeysLocked = false;
- _parent.Controls.Remove(_textBox);
- }
+ private void HideTextBox()
+ {
+ _parent.Focus();
+ _textBox?.Hide();
+ _parent.KeysLocked = false;
+ _parent.Controls.Remove(_textBox);
+ }
- ///
- /// Make sure the size of the font is scaled
- ///
- ///
- public override void Transform(Matrix matrix)
- {
- Rectangle rect = GuiRectangle.GetGuiRectangle(Left, Top, Width, Height);
- int pixelsBefore = rect.Width * rect.Height;
+ ///
+ /// Make sure the size of the font is scaled
+ ///
+ ///
+ public override void Transform(Matrix matrix)
+ {
+ Rectangle rect = GuiRectangle.GetGuiRectangle(Left, Top, Width, Height);
+ int pixelsBefore = rect.Width * rect.Height;
- // Transform this container
- base.Transform(matrix);
- rect = GuiRectangle.GetGuiRectangle(Left, Top, Width, Height);
+ // Transform this container
+ base.Transform(matrix);
+ rect = GuiRectangle.GetGuiRectangle(Left, Top, Width, Height);
- int pixelsAfter = rect.Width * rect.Height;
- float factor = pixelsAfter / (float)pixelsBefore;
+ int pixelsAfter = rect.Width * rect.Height;
+ float factor = pixelsAfter / (float)pixelsBefore;
- float fontSize = GetFieldValueAsFloat(FieldType.FONT_SIZE);
- fontSize *= factor;
- SetFieldValue(FieldType.FONT_SIZE, fontSize);
- UpdateFormat();
- }
+ float fontSize = GetFieldValueAsFloat(FieldType.FONT_SIZE);
+ fontSize *= factor;
+ SetFieldValue(FieldType.FONT_SIZE, fontSize);
+ UpdateFormat();
+ }
- private Font CreateFont(string fontFamilyName, bool fontBold, bool fontItalic, float fontSize)
- {
- FontStyle fontStyle = FontStyle.Regular;
+ private Font CreateFont(string fontFamilyName, bool fontBold, bool fontItalic, float fontSize)
+ {
+ FontStyle fontStyle = FontStyle.Regular;
- bool hasStyle = false;
- using (var fontFamily = new FontFamily(fontFamilyName))
- {
- bool boldAvailable = fontFamily.IsStyleAvailable(FontStyle.Bold);
- if (fontBold && boldAvailable)
- {
- fontStyle |= FontStyle.Bold;
- hasStyle = true;
- }
+ bool hasStyle = false;
+ using (var fontFamily = new FontFamily(fontFamilyName))
+ {
+ bool boldAvailable = fontFamily.IsStyleAvailable(FontStyle.Bold);
+ if (fontBold && boldAvailable)
+ {
+ fontStyle |= FontStyle.Bold;
+ hasStyle = true;
+ }
- bool italicAvailable = fontFamily.IsStyleAvailable(FontStyle.Italic);
- if (fontItalic && italicAvailable)
- {
- fontStyle |= FontStyle.Italic;
- hasStyle = true;
- }
+ bool italicAvailable = fontFamily.IsStyleAvailable(FontStyle.Italic);
+ if (fontItalic && italicAvailable)
+ {
+ fontStyle |= FontStyle.Italic;
+ hasStyle = true;
+ }
- if (!hasStyle)
- {
- bool regularAvailable = fontFamily.IsStyleAvailable(FontStyle.Regular);
- if (regularAvailable)
- {
- fontStyle = FontStyle.Regular;
- }
- else
- {
- if (boldAvailable)
- {
- fontStyle = FontStyle.Bold;
- }
- else if (italicAvailable)
- {
- fontStyle = FontStyle.Italic;
- }
- }
- }
- return new Font(fontFamily, fontSize, fontStyle, GraphicsUnit.Pixel);
- }
- }
+ if (!hasStyle)
+ {
+ bool regularAvailable = fontFamily.IsStyleAvailable(FontStyle.Regular);
+ if (regularAvailable)
+ {
+ fontStyle = FontStyle.Regular;
+ }
+ else
+ {
+ if (boldAvailable)
+ {
+ fontStyle = FontStyle.Bold;
+ }
+ else if (italicAvailable)
+ {
+ fontStyle = FontStyle.Italic;
+ }
+ }
+ }
+ return new Font(fontFamily, fontSize, fontStyle, GraphicsUnit.Pixel);
+ }
+ }
- ///
- /// Generate the Font-Formal so we can draw correctly
- ///
- protected void UpdateFormat()
- {
- if (_textBox == null)
- {
- return;
- }
- string fontFamily = GetFieldValueAsString(FieldType.FONT_FAMILY);
- bool fontBold = GetFieldValueAsBool(FieldType.FONT_BOLD);
- bool fontItalic = GetFieldValueAsBool(FieldType.FONT_ITALIC);
- float fontSize = GetFieldValueAsFloat(FieldType.FONT_SIZE);
- try
- {
- var newFont = CreateFont(fontFamily, fontBold, fontItalic, fontSize);
- _font?.Dispose();
- _font = newFont;
- _textBox.Font = _font;
- }
- catch (Exception ex)
- {
- // Problem, try again with the default
- try
- {
- fontFamily = FontFamily.GenericSansSerif.Name;
- SetFieldValue(FieldType.FONT_FAMILY, fontFamily);
- var newFont = CreateFont(fontFamily, fontBold, fontItalic, fontSize);
- _font?.Dispose();
- _font = newFont;
- _textBox.Font = _font;
- }
- catch (Exception)
- {
- // When this happens... the PC is broken
- ex.Data.Add("fontFamilyName", fontFamily);
- ex.Data.Add("fontBold", fontBold);
- ex.Data.Add("fontItalic", fontItalic);
- ex.Data.Add("fontSize", fontSize);
- throw ex;
- }
- }
+ ///
+ /// Generate the Font-Formal so we can draw correctly
+ ///
+ protected void UpdateFormat()
+ {
+ if (_textBox == null)
+ {
+ return;
+ }
+ string fontFamily = GetFieldValueAsString(FieldType.FONT_FAMILY);
+ bool fontBold = GetFieldValueAsBool(FieldType.FONT_BOLD);
+ bool fontItalic = GetFieldValueAsBool(FieldType.FONT_ITALIC);
+ float fontSize = GetFieldValueAsFloat(FieldType.FONT_SIZE);
+ try
+ {
+ var newFont = CreateFont(fontFamily, fontBold, fontItalic, fontSize);
+ _font?.Dispose();
+ _font = newFont;
+ _textBox.Font = _font;
+ }
+ catch (Exception ex)
+ {
+ // Problem, try again with the default
+ try
+ {
+ fontFamily = FontFamily.GenericSansSerif.Name;
+ SetFieldValue(FieldType.FONT_FAMILY, fontFamily);
+ var newFont = CreateFont(fontFamily, fontBold, fontItalic, fontSize);
+ _font?.Dispose();
+ _font = newFont;
+ _textBox.Font = _font;
+ }
+ catch (Exception)
+ {
+ // When this happens... the PC is broken
+ ex.Data.Add("fontFamilyName", fontFamily);
+ ex.Data.Add("fontBold", fontBold);
+ ex.Data.Add("fontItalic", fontItalic);
+ ex.Data.Add("fontSize", fontSize);
+ throw ex;
+ }
+ }
- UpdateAlignment();
- }
+ UpdateAlignment();
+ }
- private void UpdateAlignment()
- {
- _stringFormat.Alignment = (StringAlignment)GetFieldValue(FieldType.TEXT_HORIZONTAL_ALIGNMENT);
- _stringFormat.LineAlignment = (StringAlignment)GetFieldValue(FieldType.TEXT_VERTICAL_ALIGNMENT);
- }
+ private void UpdateAlignment()
+ {
+ _stringFormat.Alignment = (StringAlignment)GetFieldValue(FieldType.TEXT_HORIZONTAL_ALIGNMENT);
+ _stringFormat.LineAlignment = (StringAlignment)GetFieldValue(FieldType.TEXT_VERTICAL_ALIGNMENT);
+ }
- ///
- /// This will create the textbox exactly to the inner size of the element
- /// is a bit of a hack, but for now it seems to work...
- ///
- private void UpdateTextBoxPosition()
- {
- if (_textBox == null)
- {
- return;
- }
- int lineThickness = GetFieldValueAsInt(FieldType.LINE_THICKNESS);
+ ///
+ /// This will create the textbox exactly to the inner size of the element
+ /// is a bit of a hack, but for now it seems to work...
+ ///
+ private void UpdateTextBoxPosition()
+ {
+ if (_textBox == null)
+ {
+ return;
+ }
+ int lineThickness = GetFieldValueAsInt(FieldType.LINE_THICKNESS);
- int lineWidth = (int)Math.Floor(lineThickness / 2d);
- int correction = (lineThickness + 1) % 2;
- if (lineThickness <= 1)
- {
- lineWidth = 1;
- correction = -1;
- }
- Rectangle absRectangle = GuiRectangle.GetGuiRectangle(Left, Top, Width, Height);
- _textBox.Left = absRectangle.Left + lineWidth;
- _textBox.Top = absRectangle.Top + lineWidth;
- if (lineThickness <= 1)
- {
- lineWidth = 0;
- }
- _textBox.Width = absRectangle.Width - 2 * lineWidth + correction;
- _textBox.Height = absRectangle.Height - 2 * lineWidth + correction;
- }
+ int lineWidth = (int)Math.Floor(lineThickness / 2d);
+ int correction = (lineThickness + 1) % 2;
+ if (lineThickness <= 1)
+ {
+ lineWidth = 1;
+ correction = -1;
+ }
+ Rectangle absRectangle = GuiRectangle.GetGuiRectangle(Left, Top, Width, Height);
+ _textBox.Left = absRectangle.Left + lineWidth;
+ _textBox.Top = absRectangle.Top + lineWidth;
+ if (lineThickness <= 1)
+ {
+ lineWidth = 0;
+ }
+ _textBox.Width = absRectangle.Width - 2 * lineWidth + correction;
+ _textBox.Height = absRectangle.Height - 2 * lineWidth + correction;
+ }
- public override void ApplyBounds(RectangleF newBounds)
- {
- base.ApplyBounds(newBounds);
- UpdateTextBoxPosition();
- }
+ public override void ApplyBounds(RectangleF newBounds)
+ {
+ base.ApplyBounds(newBounds);
+ UpdateTextBoxPosition();
+ }
- private void UpdateTextBoxFormat()
- {
- if (_textBox == null)
- {
- return;
- }
- var alignment = (StringAlignment)GetFieldValue(FieldType.TEXT_HORIZONTAL_ALIGNMENT);
- switch (alignment)
- {
- case StringAlignment.Near:
- _textBox.TextAlign = HorizontalAlignment.Left;
- break;
- case StringAlignment.Far:
- _textBox.TextAlign = HorizontalAlignment.Right;
- break;
- case StringAlignment.Center:
- _textBox.TextAlign = HorizontalAlignment.Center;
- break;
- }
+ private void UpdateTextBoxFormat()
+ {
+ if (_textBox == null)
+ {
+ return;
+ }
+ var alignment = (StringAlignment)GetFieldValue(FieldType.TEXT_HORIZONTAL_ALIGNMENT);
+ switch (alignment)
+ {
+ case StringAlignment.Near:
+ _textBox.TextAlign = HorizontalAlignment.Left;
+ break;
+ case StringAlignment.Far:
+ _textBox.TextAlign = HorizontalAlignment.Right;
+ break;
+ case StringAlignment.Center:
+ _textBox.TextAlign = HorizontalAlignment.Center;
+ break;
+ }
- var lineColor = GetFieldValueAsColor(FieldType.LINE_COLOR);
- _textBox.ForeColor = lineColor;
- }
+ var lineColor = GetFieldValueAsColor(FieldType.LINE_COLOR);
+ _textBox.ForeColor = lineColor;
+ }
- private void textBox_KeyDown(object sender, KeyEventArgs e)
- {
- // ESC and Enter/Return (w/o Shift) hide text editor
- if (e.KeyCode == Keys.Escape || ((e.KeyCode == Keys.Return || e.KeyCode == Keys.Enter) && e.Modifiers == Keys.None))
- {
- HideTextBox();
- e.SuppressKeyPress = true;
- }
- }
+ private void textBox_KeyDown(object sender, KeyEventArgs e)
+ {
+ // ESC and Enter/Return (w/o Shift) hide text editor
+ if (e.KeyCode == Keys.Escape || ((e.KeyCode == Keys.Return || e.KeyCode == Keys.Enter) && e.Modifiers == Keys.None))
+ {
+ HideTextBox();
+ e.SuppressKeyPress = true;
+ }
- private void textBox_LostFocus(object sender, EventArgs e)
- {
- // next change will be made undoable
- makeUndoable = true;
- HideTextBox();
- }
+ // Added for FEATURE-1064
+ if (e.KeyCode == Keys.Back && e.Control)
+ {
+ e.SuppressKeyPress = true;
+ int selStart = _textBox.SelectionStart;
+ while (selStart > 0 && _textBox.Text.Substring(selStart - 1, 1) == " ")
+ {
+ selStart--;
+ }
+ int prevSpacePos = -1;
+ if (selStart != 0)
+ {
+ prevSpacePos = _textBox.Text.LastIndexOf(' ', selStart - 1);
+ }
+ _textBox.Select(prevSpacePos + 1, _textBox.SelectionStart - prevSpacePos - 1);
+ _textBox.SelectedText = "";
+ }
+ }
- public override void Draw(Graphics graphics, RenderMode rm)
- {
- base.Draw(graphics, rm);
+ private void textBox_LostFocus(object sender, EventArgs e)
+ {
+ // next change will be made undoable
+ makeUndoable = true;
+ HideTextBox();
+ }
- graphics.SmoothingMode = SmoothingMode.HighQuality;
- graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
- graphics.CompositingQuality = CompositingQuality.HighQuality;
- graphics.PixelOffsetMode = PixelOffsetMode.None;
- graphics.TextRenderingHint = TextRenderingHint.SystemDefault;
+ public override void Draw(Graphics graphics, RenderMode rm)
+ {
+ base.Draw(graphics, rm);
- Rectangle rect = GuiRectangle.GetGuiRectangle(Left, Top, Width, Height);
- if (Selected && rm == RenderMode.EDIT)
- {
- DrawSelectionBorder(graphics, rect);
- }
+ graphics.SmoothingMode = SmoothingMode.HighQuality;
+ graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
+ graphics.CompositingQuality = CompositingQuality.HighQuality;
+ graphics.PixelOffsetMode = PixelOffsetMode.None;
+ graphics.TextRenderingHint = TextRenderingHint.SystemDefault;
- if (string.IsNullOrEmpty(text))
- {
- return;
- }
+ Rectangle rect = GuiRectangle.GetGuiRectangle(Left, Top, Width, Height);
+ if (Selected && rm == RenderMode.EDIT)
+ {
+ DrawSelectionBorder(graphics, rect);
+ }
- // we only draw the shadow if there is no background
- bool shadow = GetFieldValueAsBool(FieldType.SHADOW);
- Color fillColor = GetFieldValueAsColor(FieldType.FILL_COLOR);
- int lineThickness = GetFieldValueAsInt(FieldType.LINE_THICKNESS);
- Color lineColor = GetFieldValueAsColor(FieldType.LINE_COLOR);
- bool drawShadow = shadow && (fillColor == Color.Transparent || fillColor == Color.Empty);
+ if (string.IsNullOrEmpty(text))
+ {
+ return;
+ }
- DrawText(graphics, rect, lineThickness, lineColor, drawShadow, _stringFormat, text, _font);
- }
+ // we only draw the shadow if there is no background
+ bool shadow = GetFieldValueAsBool(FieldType.SHADOW);
+ Color fillColor = GetFieldValueAsColor(FieldType.FILL_COLOR);
+ int lineThickness = GetFieldValueAsInt(FieldType.LINE_THICKNESS);
+ Color lineColor = GetFieldValueAsColor(FieldType.LINE_COLOR);
+ bool drawShadow = shadow && (fillColor == Color.Transparent || fillColor == Color.Empty);
- ///
- /// This method can be used from other containers
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- public static void DrawText(Graphics graphics, Rectangle drawingRectange, int lineThickness, Color fontColor, bool drawShadow, StringFormat stringFormat, string text, Font font)
- {
+ DrawText(graphics, rect, lineThickness, lineColor, drawShadow, _stringFormat, text, _font);
+ }
+
+ ///
+ /// This method can be used from other containers
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static void DrawText(Graphics graphics, Rectangle drawingRectange, int lineThickness, Color fontColor, bool drawShadow, StringFormat stringFormat, string text, Font font)
+ {
#if DEBUG
- Debug.Assert(font != null);
+ Debug.Assert(font != null);
#else
- if (font == null)
- {
- return;
- }
+ if (font == null)
+ {
+ return;
+ }
#endif
- int textOffset = lineThickness > 0 ? (int)Math.Ceiling(lineThickness / 2d) : 0;
- // draw shadow before anything else
- if (drawShadow)
- {
- int basealpha = 100;
- int alpha = basealpha;
- int steps = 5;
- int currentStep = 1;
- while (currentStep <= steps)
- {
- int offset = currentStep;
- Rectangle shadowRect = GuiRectangle.GetGuiRectangle(drawingRectange.Left + offset, drawingRectange.Top + offset, drawingRectange.Width, drawingRectange.Height);
- if (lineThickness > 0)
- {
- shadowRect.Inflate(-textOffset, -textOffset);
- }
- using (Brush fontBrush = new SolidBrush(Color.FromArgb(alpha, 100, 100, 100)))
- {
- graphics.DrawString(text, font, fontBrush, shadowRect, stringFormat);
- currentStep++;
- alpha = alpha - basealpha / steps;
- }
- }
- }
+ int textOffset = lineThickness > 0 ? (int)Math.Ceiling(lineThickness / 2d) : 0;
+ // draw shadow before anything else
+ if (drawShadow)
+ {
+ int basealpha = 100;
+ int alpha = basealpha;
+ int steps = 5;
+ int currentStep = 1;
+ while (currentStep <= steps)
+ {
+ int offset = currentStep;
+ Rectangle shadowRect = GuiRectangle.GetGuiRectangle(drawingRectange.Left + offset, drawingRectange.Top + offset, drawingRectange.Width, drawingRectange.Height);
+ if (lineThickness > 0)
+ {
+ shadowRect.Inflate(-textOffset, -textOffset);
+ }
+ using (Brush fontBrush = new SolidBrush(Color.FromArgb(alpha, 100, 100, 100)))
+ {
+ graphics.DrawString(text, font, fontBrush, shadowRect, stringFormat);
+ currentStep++;
+ alpha = alpha - basealpha / steps;
+ }
+ }
+ }
- if (lineThickness > 0)
- {
- drawingRectange.Inflate(-textOffset, -textOffset);
- }
- using (Brush fontBrush = new SolidBrush(fontColor))
- {
- if (stringFormat != null)
- {
- graphics.DrawString(text, font, fontBrush, drawingRectange, stringFormat);
- }
- else
- {
- graphics.DrawString(text, font, fontBrush, drawingRectange);
- }
- }
- }
+ if (lineThickness > 0)
+ {
+ drawingRectange.Inflate(-textOffset, -textOffset);
+ }
+ using (Brush fontBrush = new SolidBrush(fontColor))
+ {
+ if (stringFormat != null)
+ {
+ graphics.DrawString(text, font, fontBrush, drawingRectange, stringFormat);
+ }
+ else
+ {
+ graphics.DrawString(text, font, fontBrush, drawingRectange);
+ }
+ }
+ }
- public override bool ClickableAt(int x, int y)
- {
- Rectangle r = GuiRectangle.GetGuiRectangle(Left, Top, Width, Height);
- r.Inflate(5, 5);
- return r.Contains(x, y);
- }
- }
+ public override bool ClickableAt(int x, int y)
+ {
+ Rectangle r = GuiRectangle.GetGuiRectangle(Left, Top, Width, Height);
+ r.Inflate(5, 5);
+ return r.Contains(x, y);
+ }
+ }
}