From 45f74150dd79db5a162034ab0c43e6abdb83beea Mon Sep 17 00:00:00 2001 From: jpbruyere Date: Wed, 15 Mar 2017 05:59:51 +0100 Subject: split graphic objects dir --- src/GraphicObjects/Base/TextBox.cs | 228 +++++++++++++++++++++++++++++++++++++ 1 file changed, 228 insertions(+) create mode 100644 src/GraphicObjects/Base/TextBox.cs (limited to 'src/GraphicObjects/Base/TextBox.cs') diff --git a/src/GraphicObjects/Base/TextBox.cs b/src/GraphicObjects/Base/TextBox.cs new file mode 100644 index 00000000..0cbee9f8 --- /dev/null +++ b/src/GraphicObjects/Base/TextBox.cs @@ -0,0 +1,228 @@ +// +// TextBox.cs +// +// Author: +// Jean-Philippe Bruyère +// +// Copyright (c) 2013-2017 Jean-Philippe Bruyère +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System; +using Cairo; +using System.Diagnostics; +using System.Xml.Serialization; + +namespace Crow +{ + public class TextBox : Label + { + #region CTOR + public TextBox() + { } + public TextBox(string _initialValue) + : base(_initialValue) + { + + } + #endregion + + #region GraphicObject overrides + [XmlIgnore]public override bool HasFocus //trigger update when lost focus to errase text beam + { + get + { + return base.HasFocus; + } + set + { + base.HasFocus = value; + RegisterForRedraw(); + } + } + + protected override void onDraw (Context gr) + { + base.onDraw (gr); + FontExtents fe = gr.FontExtents; + } + #endregion + + #region Keyboard handling + public override void onKeyDown (object sender, KeyboardKeyEventArgs e) + { + base.onKeyDown (sender, e); + + Key key = e.Key; + + switch (key) + { + case Key.Back: + if (CurrentPosition == 0) + return; + this.DeleteChar(); + break; + case Key.Clear: + break; + case Key.Delete: + if (selectionIsEmpty) { + if (!MoveRight ()) + return; + }else if (e.Shift) + CurrentInterface.Clipboard = this.SelectedText; + this.DeleteChar (); + break; + case Key.Enter: + case Key.KeypadEnter: + if (!selectionIsEmpty) + this.DeleteChar (); + if (Multiline) + this.InsertLineBreak (); + else + OnTextChanged(this,new TextChangeEventArgs(Text)); + break; + case Key.Escape: + Text = ""; + CurrentColumn = 0; + SelRelease = -1; + break; + case Key.Home: + if (e.Shift) { + if (selectionIsEmpty) + SelBegin = new Point (CurrentColumn, CurrentLine); + if (e.Control) + CurrentLine = 0; + CurrentColumn = 0; + SelRelease = new Point (CurrentColumn, CurrentLine); + break; + } + SelRelease = -1; + if (e.Control) + CurrentLine = 0; + CurrentColumn = 0; + break; + case Key.End: + if (e.Shift) { + if (selectionIsEmpty) + SelBegin = CurrentPosition; + if (e.Control) + CurrentLine = int.MaxValue; + CurrentColumn = int.MaxValue; + SelRelease = CurrentPosition; + break; + } + SelRelease = -1; + if (e.Control) + CurrentLine = int.MaxValue; + CurrentColumn = int.MaxValue; + break; + case Key.Insert: + if (e.Shift) + this.Insert (CurrentInterface.Clipboard); + else if (e.Control && !selectionIsEmpty) + CurrentInterface.Clipboard = this.SelectedText; + break; + case Key.Left: + if (e.Shift) { + if (selectionIsEmpty) + SelBegin = new Point(CurrentColumn, CurrentLine); + if (e.Control) + GotoWordStart (); + else if (!MoveLeft ()) + return; + SelRelease = CurrentPosition; + break; + } + SelRelease = -1; + if (e.Control) + GotoWordStart (); + else + MoveLeft(); + break; + case Key.Right: + if (e.Shift) { + if (selectionIsEmpty) + SelBegin = CurrentPosition; + if (e.Control) + GotoWordEnd (); + else if (!MoveRight ()) + return; + SelRelease = CurrentPosition; + break; + } + SelRelease = -1; + if (e.Control) + GotoWordEnd (); + else + MoveRight (); + break; + case Key.Up: + if (e.Shift) { + if (selectionIsEmpty) + SelBegin = CurrentPosition; + CurrentLine--; + SelRelease = CurrentPosition; + break; + } + SelRelease = -1; + CurrentLine--; + break; + case Key.Down: + if (e.Shift) { + if (selectionIsEmpty) + SelBegin = CurrentPosition; + CurrentLine++; + SelRelease = CurrentPosition; + break; + } + SelRelease = -1; + CurrentLine++; + break; + case Key.Menu: + break; + case Key.NumLock: + break; + case Key.PageDown: + break; + case Key.PageUp: + break; + case Key.RWin: + break; + case Key.Tab: + this.Insert ("\t"); + break; + default: + break; + } + RegisterForGraphicUpdate(); + } + public override void onKeyPress (object sender, KeyPressEventArgs e) + { + base.onKeyPress (sender, e); + + this.Insert (e.KeyChar.ToString()); + + SelRelease = -1; + SelBegin = new Point(CurrentColumn, SelBegin.Y); + + RegisterForGraphicUpdate(); + } + #endregion + } +} -- cgit v1.3.1-4-g156e