]> O.S.I.I.S - jp/crow.git/commitdiff
add textbox text facilities and clipboard
authorjp <jp_bruyere@hotmail.com>
Sun, 3 Apr 2016 22:24:02 +0000 (00:24 +0200)
committerjp <jp_bruyere@hotmail.com>
Sun, 3 Apr 2016 22:24:02 +0000 (00:24 +0200)
Crow.csproj
Styles/TextBox.style [new file with mode: 0644]
src/GraphicObjects/Label.cs
src/GraphicObjects/TextBox.cs
src/Interface.cs

index 3579f9a1d67a39ce455c1c3b8f5958a423e2fe94..1276874c77385f6a03162612993e5b9b02c65062 100644 (file)
@@ -21,8 +21,9 @@
     <RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
     <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
     <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
-    <ReleaseVersion>0.4</ReleaseVersion>
     <Description>Crow project description</Description>
+    <ProductVersion>8.0.30703</ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
     <DebugSymbols>true</DebugSymbols>
     <EmbeddedResource Include="Styles\Spinner.style" />
     <EmbeddedResource Include="Styles\MessageBox.style" />
     <EmbeddedResource Include="Styles\Window.style" />
+    <EmbeddedResource Include="Styles\TextBox.style" />
   </ItemGroup>
   <ItemGroup>
     <None Include="README.md" />
diff --git a/Styles/TextBox.style b/Styles/TextBox.style
new file mode 100644 (file)
index 0000000..2ad617a
--- /dev/null
@@ -0,0 +1,5 @@
+Fit = true
+Focusable = true
+Background = White
+Foreground = Black
+
index 64c37ff8f3bd9f8f27e9b8ae8a08c4cff88f9b95..6d0bf471f727af31253ae9a8d264e9fbcdc5e79c 100644 (file)
@@ -9,8 +9,7 @@ using System.Xml.Serialization;
 using System.ComponentModel;
 
 namespace Crow
-{
-    [Serializable]
+{    
        [DefaultStyle("#Crow.Styles.Label.style")]
     public class Label : GraphicObject
     {
@@ -155,8 +154,8 @@ namespace Crow
                                        return;
                                if (value < 0)
                                        _currentCol = 0;
-                               else if (value > lines [_currentLine].Count ())
-                                       _currentCol = lines [_currentLine].Count ();
+                               else if (value > lines [_currentLine].Length)
+                                       _currentCol = lines [_currentLine].Length;
                                else
                                        _currentCol = value;
                                NotifyValueChanged ("CurrentColumn", _currentCol);
@@ -173,7 +172,11 @@ namespace Crow
                                else if (value < 0)
                                        _currentLine = 0;
                                else
-                                       _currentLine = value; 
+                                       _currentLine = value;
+                               //force recheck of currentCol for bounding
+                               int cc = _currentCol;
+                               _currentCol = 0;
+                               CurrentColumn = cc;
                                NotifyValueChanged ("CurrentLine", _currentLine);
                        }
                }
@@ -205,6 +208,12 @@ namespace Crow
                        }
                }
 
+               [XmlIgnore]protected Char CurrentChar   //ordered selection start and end positions
+               {
+                       get {
+                               return lines [CurrentLine] [CurrentColumn];
+                       }
+               }
                [XmlIgnore]protected Point selectionStart   //ordered selection start and end positions
                {
                        get { 
@@ -250,6 +259,25 @@ namespace Crow
                        }
                }
 
+               public void GotoWordStart(){
+                       CurrentColumn--;
+                       //skip white spaces
+                       while (char.IsWhiteSpace (this.CurrentChar) && CurrentColumn > 0)
+                               CurrentColumn--;
+                       while (!char.IsWhiteSpace (lines [CurrentLine] [CurrentColumn]) && CurrentColumn > 0)
+                               CurrentColumn--;
+                       if (char.IsWhiteSpace (this.CurrentChar))
+                               CurrentColumn++;
+               }
+               public void GotoWordEnd(){
+                       //skip white spaces
+                       while (char.IsWhiteSpace (this.CurrentChar) && CurrentColumn < lines [CurrentLine].Length-1)
+                               CurrentColumn++;
+                       while (!char.IsWhiteSpace (this.CurrentChar) && CurrentColumn < lines [CurrentLine].Length-1)
+                               CurrentColumn++;
+                       if (!char.IsWhiteSpace (this.CurrentChar))
+                               CurrentColumn++;
+               }
                public void DeleteChar()
                {
                        if (selectionIsEmpty) {                         
@@ -257,7 +285,7 @@ namespace Crow
                                        if (CurrentLine == 0)
                                                return;
                                        CurrentLine--;
-                                       CurrentColumn = lines [CurrentLine].Count ();
+                                       CurrentColumn = lines [CurrentLine].Length;
                                        lines [CurrentLine] += lines [CurrentLine + 1];
                                        lines.RemoveAt (CurrentLine + 1);
                                        NotifyValueChanged ("Text", Text);
@@ -265,8 +293,7 @@ namespace Crow
                                }
                                CurrentColumn--;
                                lines [CurrentLine] = lines [CurrentLine].Remove (CurrentColumn, 1);
-                       } else {
-                               Debug.WriteLine (selectionEnd.ToString());
+                       } else {                                
                                int linesToRemove = selectionEnd.Y - selectionStart.Y;
                                int l = selectionStart.Y;
 
index 08ec1f69ae266091aae05bde04d57598d9d952d8..a042198b18eaf6c097e9ce034362c280b636a843 100644 (file)
@@ -11,6 +11,7 @@ using System.Runtime.InteropServices;
 
 namespace Crow
 {
+       [DefaultStyle("#Crow.Styles.TextBox.style")]
     public class TextBox : Label
     {
                #region CTOR
@@ -37,22 +38,6 @@ namespace Crow
                 RegisterForGraphicUpdate();
             }
         }
-               [XmlAttributeAttribute()][DefaultValue(true)]
-               public override bool Focusable
-               {
-                       get { return base.Focusable; }
-                       set { base.Focusable = value; }
-               }
-               [XmlAttributeAttribute()][DefaultValue("White")]
-               public override Fill Background {
-                       get { return base.Background; }
-                       set { base.Background = value; }
-               }
-               [XmlAttributeAttribute()][DefaultValue("Black")]
-               public override Fill Foreground {
-                       get { return base.Foreground; }
-                       set { base.Foreground = value; }
-               }
 
                protected override void onDraw (Context gr)
                {
@@ -78,24 +63,21 @@ namespace Crow
                        switch (key)
                        {
                        case Key.Back:
-                               if (!selectionIsEmpty)
-                               {
-                                       //                                      Text = Text.Remove(selectionStart, selectionEnd - selectionStart);
-                                       //                                      selReleasePos = -1;
-                                       //                                      currentCol = selBeginPos;
-                               }
-                               else 
-                                       this.DeleteChar();
+                               this.DeleteChar();
                                break;
                        case Key.Clear:
                                break;
                        case Key.Delete:
                                if (selectionIsEmpty)
                                        CurrentColumn++;
+                               else if (e.Shift)
+                                       Interface.CurrentInterface.Clipboard = this.SelectedText;
                                this.DeleteChar ();
                                break;
                        case Key.Enter:
                        case Key.KeypadEnter:
+                               if (!selectionIsEmpty)
+                                       this.DeleteChar ();
                                if (Multiline)
                                        this.InsertLineBreak ();
                                else
@@ -107,35 +89,100 @@ namespace Crow
                                SelRelease = -1;
                                break;
                        case Key.Home:
-                               //TODO
+                               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 = new Point (CurrentColumn, CurrentLine);
+                                       if (e.Control)
+                                               CurrentLine = int.MaxValue;
+                                       CurrentColumn = int.MaxValue;
+                                       SelRelease = new Point (CurrentColumn, CurrentLine);
+                                       break;
+                               }
+                               SelRelease = -1;
                                if (e.Control)
                                        CurrentLine = int.MaxValue;
                                CurrentColumn = int.MaxValue;
                                break;
                        case Key.Insert:
-                               break;
-                       case Key.Left:                          
-                               CurrentColumn--;
-                               break;
-                       case Key.Right:                         
-                               CurrentColumn++;
+                               if (e.Shift)
+                                       this.Insert (Interface.CurrentInterface.Clipboard);
+                               break;
+                       case Key.Left:
+                               if (e.Shift) {
+                                       if (selectionIsEmpty)
+                                               SelBegin = new Point(CurrentColumn, CurrentLine);
+                                       if (e.Control)
+                                               GotoWordStart ();
+                                       else
+                                               CurrentColumn--;
+                                       SelRelease = new Point(CurrentColumn, CurrentLine);
+                                       break;
+                               }
+                               SelRelease = -1;
+                               if (e.Control)
+                                       GotoWordStart ();
+                               else
+                                       CurrentColumn--;
+                               break;
+                       case Key.Right:
+                               if (e.Shift) {
+                                       if (selectionIsEmpty)
+                                               SelBegin = new Point(CurrentColumn, CurrentLine);
+                                       if (e.Control)
+                                               GotoWordEnd ();
+                                       else
+                                               CurrentColumn++;
+                                       SelRelease = new Point(CurrentColumn, CurrentLine);
+                                       break;
+                               }
+                               SelRelease = -1;
+                               if (e.Control)
+                                       GotoWordEnd ();
+                               else
+                                       CurrentColumn++;
                                break;
                        case Key.Up:
+                               if (e.Shift) {
+                                       if (selectionIsEmpty)
+                                               SelBegin = new Point(CurrentColumn, CurrentLine);
+                                       CurrentLine--;
+                                       SelRelease = new Point(CurrentColumn, CurrentLine);
+                                       break;
+                               }
+                               SelRelease = -1;
                                CurrentLine--;
                                break;
                        case Key.Down:
-                               CurrentLine++;
+                               if (e.Shift) {
+                                       if (selectionIsEmpty)
+                                               SelBegin = new Point(CurrentColumn, CurrentLine);
+                                       CurrentLine++;
+                                       SelRelease = new Point(CurrentColumn, CurrentLine);
+                                       break;
+                               }
+                               SelRelease = -1;
+                               CurrentLine++;                          
                                break;
                        case Key.Menu:
                                break;
                        case Key.NumLock:
                                break;
-                       case Key.PageDown:
+                       case Key.PageDown:                              
                                break;
                        case Key.PageUp:
                                break;
index 97ab1c9df6ccb27f4262853513c9ffbd69a6cea8..41199fcc28b42fc49b60952b30e20900927a945e 100644 (file)
@@ -72,7 +72,7 @@ namespace Crow
 
                public Queue<LayoutingQueueItem> LayoutingQueue;
                public Queue<GraphicObject> GraphicUpdateQueue = new Queue<GraphicObject>();
-
+               public string Clipboard;
                public static void RegisterForGraphicUpdate(GraphicObject g)
                {
                        lock (CurrentInterface.GraphicUpdateQueue) {