]> O.S.I.I.S - jp/crow.git/commitdiff
label size adjust, modal window, crowIDE wip
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Thu, 1 Mar 2018 09:32:53 +0000 (10:32 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Thu, 1 Mar 2018 09:32:53 +0000 (10:32 +0100)
23 files changed:
CrowIDE/CrowIDE.csproj
CrowIDE/src/CrowIDE.cs
CrowIDE/src/ProjectNodes.cs
CrowIDE/src/PropertyContainer.cs
CrowIDE/src/Solution.cs
CrowIDE/src/SourceEditor/BufferParser.cs
CrowIDE/src/SourceEditor/CSharpParser.cs
CrowIDE/src/SourceEditor/CodeBuffer.cs
CrowIDE/src/SourceEditor/CodeLine.cs
CrowIDE/src/SourceEditor/SourceEditor.cs
CrowIDE/src/SourceEditor/StyleParser.cs
CrowIDE/src/SourceEditor/XMLParser.cs
CrowIDE/ui/ItemTemplates/Enum.template [new file with mode: 0755]
CrowIDE/ui/ItemTemplates/Fill.template [new file with mode: 0755]
CrowIDE/ui/MembersItem.template
Default.style
Templates/MessageBox.template
Tests/test.style
Tests/ui/LabelButton.style
Tests/ui/MenuItem.style
src/GraphicObjects/Label.cs
src/GraphicObjects/MessageBox.cs
src/GraphicObjects/Window.cs

index 38adac8518a15455fecfd50d5df6be3277fec590..9a9a222f60ca60491c7a0bf7cd4d39375e0e703f 100644 (file)
     <Folder Include="src\" />
     <Folder Include="images\" />
     <Folder Include="src\SourceEditor\" />
+    <Folder Include="ui\ItemTemplates\" />
   </ItemGroup>
   <ItemGroup>
     <EmbeddedResource Include="images\save.svg" />
     <EmbeddedResource Include="ui\SrcEdit.itemp" />
     <EmbeddedResource Include="ui\IcoBut.template" />
     <EmbeddedResource Include="ui\MembersItem.template" />
+    <EmbeddedResource Include="ui\ItemTemplates\Enum.template" />
+    <EmbeddedResource Include="ui\ItemTemplates\Fill.template" />
   </ItemGroup>
   <ItemGroup>
     <None Include="ui\test.crow">
index eeedeb639c870c3652fd0fdc888943357033c9a1..c08dd663ebc6ff94d9d39b00f802a679bb58a1df 100644 (file)
@@ -90,13 +90,12 @@ namespace Crow.Coding
                Instantiator instFileDlg;
                Solution currentSolution;
 
+               public static Interface MainIFace;
+
                protected override void OnLoad (EventArgs e)
                {
                        base.OnLoad (e);
 
-                       instFileDlg = Instantiator.CreateFromImlFragment
-                               (CurrentInterface, "<FileDialog Caption='Open File' CurrentDirectory='{²CurrentDirectory}' SearchPattern='*.sln' OkClicked='onFileOpen'/>");
-
                        initCommands ();
 
                        this.KeyDown += CrowIDE_KeyDown;
@@ -104,11 +103,16 @@ namespace Crow.Coding
                        //this.CrowInterface.LoadInterface ("#Crow.Coding.ui.imlEditor.crow").DataSource = this;
                        //GraphicObject go = this.CrowInterface.LoadInterface (@"ui/test.crow");
                        GraphicObject go = AddWidget (@"#Crow.Coding.ui.CrowIDE.crow");
+
+                       MainIFace = ifaceControl[0].CrowInterface;
+
                        if (ReopenLastSolution && !string.IsNullOrEmpty(LastOpenSolution))
                                CurrentSolution = Solution.LoadSolution (LastOpenSolution);
 
                        go.DataSource = this;
 
+                       instFileDlg = Instantiator.CreateFromImlFragment
+                               (MainIFace, "<FileDialog Caption='Open File' CurrentDirectory='{²CurrentDirectory}' SearchPattern='*.sln' OkClicked='onFileOpen'/>");
                }
 
                void loadProjProps () {
@@ -195,10 +199,10 @@ namespace Crow.Coding
                }
                void loadWindow(string path, object dataSource = null){
                        try {
-                               GraphicObject g = CurrentInterface.FindByName (path);
+                               GraphicObject g = MainIFace.FindByName (path);
                                if (g != null)
                                        return;
-                               g = CurrentInterface.AddWidget (path);
+                               g = MainIFace.AddWidget (path);
                                g.Name = path;
                                g.DataSource = dataSource;
                        } catch (Exception ex) {
@@ -206,9 +210,9 @@ namespace Crow.Coding
                        }
                }
                void closeWindow (string path){
-                       GraphicObject g = CurrentInterface.FindByName (path);
+                       GraphicObject g = MainIFace.FindByName (path);
                        if (g != null)
-                               CurrentInterface.DeleteWidget (g);
+                               MainIFace.DeleteWidget (g);
                }
 
                protected void onCommandSave(object sender, MouseButtonEventArgs e){
index eb7d6506ea6c837e68fca753c33b96aa63b18fa4..4f24060f1c9b7abef9d7d8f2bf516a144df7eeac 100644 (file)
@@ -168,7 +168,7 @@ namespace Crow.Coding
                        : base (pi.Project, pi.node) {
 
                        cmdSave = new Crow.Command (new Action (() => Save ()))
-                               { Caption = "Save", Icon = new SvgPicture ("#Crow.Coding.ui.icons.inbox.svg"), CanExecute = false };
+                               { Caption = "Save", Icon = new SvgPicture ("#Crow.Coding.ui.icons.inbox.svg"), CanExecute = true };
                        cmdOpen = new Crow.Command (new Action (() => Open ())) 
                                { Caption = "Open", Icon = new SvgPicture ("#Crow.Coding.ui.icons.outbox.svg"), CanExecute = false };
 
@@ -293,11 +293,31 @@ namespace Crow.Coding
                        origSource = source;
                        NotifyValueChanged ("IsDirty", false);
                }
+               public void Close () {
+                       origSource = null;
+                       isOpened = false;
+                       Project.solution.CloseItem (this);
+               }
 
                public void OnQueryClose (object sender, EventArgs e){
-                       if (IsDirty)
-                               Console.WriteLine ("closing unsaved file");
-                       Project.solution.CloseItem (this);
+                       if (IsDirty) {
+                               MessageBox mb = MessageBox.ShowModal (CrowIDE.MainIFace,
+                                                       MessageBox.Type.YesNoCancel, $"{DisplayName} has unsaved changes.\nSave it now?");
+                               mb.Yes += onClickSaveAndCloseNow;
+                               mb.No += onClickCloseNow;
+                       } else
+                               Close ();
+               }
+
+               void onClickCloseNow (object sender, EventArgs e)
+               {
+                       Close ();
+               }
+
+               void onClickSaveAndCloseNow (object sender, EventArgs e)
+               {
+                       Save ();
+                       Close ();
                }
        }
        public class ImlProjectItem : ProjectFile
index 6caec9d49290d9f55f0f3428f50ae4e5a0cb2207..298dcd157e1b2c9fb1c578eae4568fdb6d6fd30f 100644 (file)
@@ -121,7 +121,9 @@ namespace Crow.Coding
                
                public object[] Choices {
                        get {
-                               return Enum.GetValues (pi.PropertyType).Cast<object>().ToArray();
+                               return pi.PropertyType.IsEnum ?
+                                       Enum.GetValues (pi.PropertyType).Cast<object>().ToArray() :
+                                       mview.ProjectNode.Project.solution.AvailaibleStyles;
                        }
                }
 
index 6746f5d382107af0a47c6ded671e2f59a9bbb7c1..9874fd4a8aad21407b48f7b067667d319069da1e 100644 (file)
@@ -55,7 +55,9 @@ namespace Crow.Coding{
                        if (StartupProject != null)
                                StartupProject.GetStyling ();
                }
-
+               public string[] AvailaibleStyles {
+                       get { return Styling == null ? new string[] {} : Styling.Keys.ToArray();}
+               }
                public void ReloadDefaultTemplates () {
                        DefaultTemplates = new Dictionary<string, string>();
                        if (StartupProject != null)
index 87dd779edb7a569d9d139de141f164baeb019973..0d1d0667f2031b486bd5515d9f53cf46c080fe90 100644 (file)
@@ -24,21 +24,24 @@ namespace Crow.Coding
                        BlockCommentStart = 4,
                        BlockComment = 5,
                        BlockCommentEnd = 6,
-                       Type = 7,
+                       Preprocessor = 7,
                        Identifier = 8,
-                       Indexer = 9,
+                       Keyword = 9,
                        OpenBlock = 10,
                        CloseBlock = 11,
                        StatementEnding = 12,
-                       UnaryOp = 13,
-                       BinaryOp = 14,
-                       Affectation = 15,
+                       OperatorOrPunctuation = 13,
+                       IntegerLitteral = 14,
+                       RealLitteral = 15,
                        StringLitteralOpening = 16,
                        StringLitteralClosing = 17,
                        StringLitteral = 18,
-                       NumericLitteral = 19,
-                       Preprocessor = 20,
-                       Keyword = 21,
+                       CharLitteralOpening = 19,
+                       CharLitteralClosing = 20,
+                       CharLitteral = 21,
+                       BoolLitteral = 22,
+                       NullLitteral = 23,                       
+                       Type = 24,
                }
 
                #region CTOR
@@ -70,11 +73,69 @@ namespace Crow.Coding
                void Buffer_LineUpadateEvent (object sender, CodeBufferEventArgs e)
                {
                        for (int i = 0; i < e.LineCount; i++)
-                               tryParseBufferLine (e.LineStart + i);
+                               TryParseBufferLine (e.LineStart + i);
                        reparseSource ();
                }
                #endregion
 
+               internal int currentLine = 0;
+               internal int currentColumn = 0;
+
+               protected CodeBuffer buffer;
+               protected Token currentTok;
+               protected bool eol = true;
+               protected Point CurrentPosition {
+                       get { return new Point (currentLine, currentColumn); }
+                       set {
+                               currentLine = value.Y;
+                               currentColumn = value.X;
+                       }
+               }
+
+               public Node RootNode;
+
+               public abstract void ParseCurrentLine();
+               public abstract void SyntaxAnalysis ();
+               public void reparseSource () {
+                       for (int i = 0; i < buffer.LineCount; i++) {
+                               if (!buffer[i].IsParsed)
+                                       TryParseBufferLine (i);
+                       }
+                       try {
+                               SyntaxAnalysis ();
+                       } catch (Exception ex) {
+                               Debug.WriteLine ("Syntax Error: " + ex.ToString ());
+                               if (ex is ParserException)
+                                       SetLineInError (ex as ParserException);
+                       }
+               }
+               public void TryParseBufferLine(int lPtr) {
+                       buffer [lPtr].exception = null;
+                       currentLine = lPtr;
+                       currentColumn = 0;
+                       eol = false;
+
+                       try {
+                               ParseCurrentLine ();
+                       } catch (Exception ex) {
+                               Debug.WriteLine (ex.ToString ());
+                               if (ex is ParserException)
+                                       SetLineInError (ex as ParserException);
+                       }
+
+               }
+
+               public virtual void SetLineInError(ParserException ex) {
+                       currentTok = default(Token);
+                       if (ex.Line >= buffer.LineCount)
+                               ex.Line = buffer.LineCount - 1;
+                       if (buffer [ex.Line].IsFolded)
+                               buffer.ToogleFolding (ex.Line);
+                       buffer [ex.Line].SetLineInError (ex);
+               }
+               public virtual string LineBrkRegex {
+                       get { return @"\r\n|\r|\n|\\\\n"; }
+               }
                void updateFolding () {
                        //                      Stack<TokenList> foldings = new Stack<TokenList>();
                        //                      bool inStartTag = false;
@@ -114,63 +175,6 @@ namespace Crow.Coding
                        //                              }
                        //                      }
                }
-               public void reparseSource () {
-                       for (int i = 0; i < buffer.LineCount; i++) {
-                               if (!buffer[i].IsParsed)
-                                       tryParseBufferLine (i);
-                       }
-                       try {
-                               SyntaxAnalysis ();
-                       } catch (Exception ex) {
-                               Debug.WriteLine ("Syntax Error: " + ex.ToString ());
-                               if (ex is ParserException)
-                                       SetLineInError (ex as ParserException);
-                       }
-               }
-               public void tryParseBufferLine(int lPtr) {
-                       buffer [lPtr].exception = null;
-                       currentLine = lPtr;
-                       currentColumn = 0;
-                       eol = false;
-
-                       try {
-                               ParseCurrentLine ();
-                       } catch (Exception ex) {
-                               Debug.WriteLine (ex.ToString ());
-                               if (ex is ParserException)
-                                       SetLineInError (ex as ParserException);
-                       }
-
-               }
-
-               protected CodeBuffer buffer;
-
-               internal int currentLine = 0;
-               internal int currentColumn = 0;
-               protected Token currentTok;
-               protected bool eol = true;
-
-               public Node RootNode;
-
-               protected Point CurrentPosition {
-                       get { return new Point (currentLine, currentColumn); }
-                       set {
-                               currentLine = value.Y;
-                               currentColumn = value.X;
-                       }
-               }
-
-               public abstract void ParseCurrentLine();
-               public abstract void SyntaxAnalysis ();
-
-               public virtual void SetLineInError(ParserException ex) {
-                       currentTok = default(Token);
-                       if (ex.Line >= buffer.LineCount)
-                               ex.Line = buffer.LineCount - 1;
-                       if (buffer [ex.Line].IsFolded)
-                               buffer.ToogleFolding (ex.Line);
-                       buffer [ex.Line].SetLineInError (ex);
-               }
 
                #region low level parsing
                /// <summary>
@@ -214,6 +218,20 @@ namespace Crow.Coding
                        currentTok.Type = (TokenType)type;
                        saveAndResetCurrentTok ();
                }
+               protected void setPreviousTokOfTypeTo (TokenType inType, TokenType newType) {
+                       for (int i = currentLine; i >= 0; i--) {
+                               int j = buffer [i].Tokens.Count - 1;
+                               while (j >= 0) {
+                                       if (buffer [i].Tokens [j].Type == inType) {
+                                               Token t = buffer [i].Tokens [j];
+                                               t.Type = newType;
+                                               buffer [i].Tokens [j] = t;
+                                               return;
+                                       }
+                                       j--;
+                               }                               
+                       }
+               }
                /// <summary>
                /// Peek next char, emit '\n' if current column > buffer's line length
                /// Throw error if eof is true
index 8c445824c1d3752560a68983055e7fe6cbaf8d83..23aef43e362a00b52264da9aa03a99c37891a526 100644 (file)
@@ -127,14 +127,14 @@ namespace Crow.Coding
                }
 
                #region Regular Expression for validity checks
-               private static Regex rxValidChar = new Regex(@"\p{Lu}|\p{Ll}|\p{Lt}|\p{Lm}|\p{Lo}|\p{Nl}|\p{Mn}|\p{Mc}|\p{Nd}|\p{Pc}|\p{Cf}");
-               private static Regex rxNameStartChar = new Regex(@"_|\p{Lu}|\p{Ll}|\p{Lt}|\p{Lm}|\p{Lo}");                                                                                                                      
-               private static Regex rxNameChar = new Regex(@"\p{Lu}|\p{Ll}|\p{Lt}|\p{Lm}|\p{Lo}|\p{Nl}|\p{Mn}|\p{Mc}|\p{Nd}|\p{Pc}|\p{Cf}");
-               private static Regex rxDecimal = new Regex(@"[0-9]+");
-               private static Regex rxHexadecimal = new Regex(@"[0-9a-fA-F]+");
-               #endregion
+               static Regex rxValidChar = new Regex(@"\p{Lu}|\p{Ll}|\p{Lt}|\p{Lm}|\p{Lo}|\p{Nl}|\p{Mn}|\p{Mc}|\p{Nd}|\p{Pc}|\p{Cf}");
+               static Regex rxNameStartChar = new Regex(@"_|\p{Lu}|\p{Ll}|\p{Lt}|\p{Lm}|\p{Lo}|\p{Nl}");
+               static Regex rxNameChar = new Regex(@"\p{Lu}|\p{Ll}|\p{Lt}|\p{Lm}|\p{Lo}|\p{Nl}|\p{Mn}|\p{Mc}|\p{Nd}|\p{Pc}|\p{Cf}");
+               static Regex rxNewLineChar = new Regex(@"\u000D|\u000A|\u0085|\u2028|\u2029");
+               static Regex rxWhiteSpaceChar = new Regex(@"\p{Zs}|\u0009|\u000B|\u000C");
+               static Regex rxDecimal = new Regex(@"[0-9]+");
+               static Regex rxHexadecimal = new Regex(@"[0-9a-fA-F]+");
 
-               #region Character ValidityCheck
                public bool nextCharIsValidCharStartName
                {
                        get { return rxNameStartChar.IsMatch(new string(new char[]{Peek()})); }
@@ -245,9 +245,75 @@ namespace Crow.Coding
 
                        cl.EndingState = (int)curState;
                }
+
+               Node addChildNode (Node curNode, CodeLine cl, int tokPtr) {
+                       Node n = new Node () { Name = cl.Tokens [tokPtr].Content, StartLine = cl };
+                       curNode.AddChild (n);
+                       if (cl.SyntacticNode == null)
+                               cl.SyntacticNode = n;
+                       return n;
+               }
+               void closeNodeAndGoUp (ref Node n, CodeLine cl){
+                       if (n.StartLine == cl){//prevent single line node
+                               n.Parent.Children.Remove (n);
+                               if (cl.SyntacticNode == n)
+                                       cl.SyntacticNode = null;
+                       }else                           
+                               n.EndLine = cl;
+                       n = n.Parent;
+               }
+
                public override void SyntaxAnalysis ()
                {
                        RootNode = new Node () { Name = "RootNode", Type="Root" };
+
+                       Node currentNode = RootNode;
+
+                       int ptrLine = 0;
+                       while (ptrLine < buffer.LineCount) {
+                               CodeLine cl = buffer [ptrLine];
+                               if (cl.Tokens == null){
+                                       ptrLine++;
+                                       continue;
+                               }
+                               cl.SyntacticNode = null;
+
+                               int tokPtr = 0;
+                               bool onlyWhiteSpace = true;
+                               while (tokPtr < cl.Tokens.Count) {
+                                       if (cl.Tokens [tokPtr].Type == TokenType.WhiteSpace) {
+                                               tokPtr++;
+                                               continue;
+                                       }
+
+                                       if (cl.Tokens [tokPtr].Type == TokenType.LineComment && onlyWhiteSpace) {
+                                               currentNode = addChildNode (currentNode, cl, tokPtr);
+                                               ptrLine++;
+                                               while (ptrLine < buffer.LineCount) {
+                                                       int idx = buffer [ptrLine].FirstNonBlankTokIndex;
+                                                       if (idx < 0) 
+                                                               break;
+                                                       if (buffer [ptrLine].Tokens [idx].Type != TokenType.LineComment)
+                                                               break;
+                                                       ptrLine++;
+                                               }
+                                               closeNodeAndGoUp (ref currentNode, buffer [ptrLine]);
+                                               break;
+                                       }
+
+                                       switch (cl.Tokens [tokPtr].Type) {
+                                       case TokenType.OpenBlock:
+                                               currentNode = addChildNode (currentNode, cl, tokPtr);
+                                               break;
+                                       case TokenType.CloseBlock:                                              
+                                               closeNodeAndGoUp (ref currentNode, cl);
+                                               break;
+                                       }
+                                       onlyWhiteSpace = false;
+                                       tokPtr++;
+                               }
+                               ptrLine++;
+                       }
                }
        }
 }
index 31739bdc4a09fff716e6ffb728eb00c12aa352ae..55d8897856d5e74049c7b52c5251724e429aef15 100644 (file)
@@ -44,12 +44,6 @@ namespace Crow.Coding
                public event EventHandler PositionChanged;
                #endregion
 
-               #region CTOR
-               public CodeBuffer () {
-
-               }
-               #endregion
-
                string lineBreak = Interface.LineBreak;
                List<CodeLine> lines = new List<CodeLine>();
                public int longestLineIdx = 0;
@@ -138,13 +132,13 @@ namespace Crow.Coding
                                FoldingEvent.Raise (this, new CodeBufferEventArgs (line));
                        }
                }
-               public void Load(string rawSource) {
+               public void Load(string rawSource, string lineBrkRegex = @"\r\n|\r|\n|\\\n") {
                        this.Clear();
 
                        if (string.IsNullOrEmpty (rawSource))
                                return;
 
-                       AddRange (Regex.Split (rawSource, "\r\n|\r|\n|\\\\n"));
+                       AddRange (Regex.Split (rawSource, lineBrkRegex));
 
                        lineBreak = detectLineBreakKind (rawSource);
                }
@@ -237,6 +231,28 @@ namespace Crow.Coding
                public int GetEndNodeIndex (int line) {
                        return IndexOf (this [line].SyntacticNode.EndLine);
                }
+
+               int ConverteTabulatedPosOfCurLine (int column) {
+                       int tmp = 0;
+                       int i = 0;
+                       while (i < lines [_currentLine].Content.Length){
+                               if (lines [_currentLine].Content [i] == '\t')
+                                       tmp += 4;
+                               else
+                                       tmp++;
+                               if (tmp > column)
+                                       break;
+                               i++;
+                       }
+                       return i;
+               }
+
+               int CurrentTabulatedColumn {
+                       get {
+                               return lines [_currentLine].Content.Substring (0, _currentCol).
+                                       Replace ("\t", new String (' ', Interface.TabSize)).Length;
+                       }
+               }
                /// <summary>
                /// Gets visual position computed from actual buffer position
                /// </summary>
@@ -303,6 +319,7 @@ namespace Crow.Coding
                }
                public bool SelectionIsEmpty
                { get { return selEndPos == selStartPos; } }
+               int requestedColumn = -1;
                /// <summary>
                /// Current column in buffer coordinate, tabulation = 1 char
                /// </summary>
@@ -313,11 +330,14 @@ namespace Crow.Coding
                                        return;
                                if (value < 0)
                                        _currentCol = 0;
-                               else if (value >  lines [_currentLine].Length)
+                               else if (value > lines [_currentLine].Length)
                                        _currentCol = lines [_currentLine].Length;
                                else
                                        _currentCol = value;
 
+                               requestedColumn = CurrentTabulatedColumn;
+                               //requestedColumn = _currentCol;
+
                                PositionChanged.Raise (this, null);
                        }
                }
@@ -335,9 +355,14 @@ namespace Crow.Coding
                                        _currentLine = 0;
                                else
                                        _currentLine = value;
-
-                               if (_currentCol >  lines [_currentLine].Length)
+//                             if (_currentCol < 0)
+//                                     requestedColumn = tabu _currentCol;
+                               int tabulatedRequestedCol = ConverteTabulatedPosOfCurLine(requestedColumn);
+                               if (requestedColumn > lines [_currentLine].PrintableLength)
                                        _currentCol = lines [_currentLine].Length;
+                               else
+                                       //_currentCol = requestedColumn;
+                                       _currentCol = tabulatedRequestedCol;
                                //Debug.WriteLine ("buff cur line: " + _currentLine);
                                PositionChanged.Raise (this, null);
                        }
index 612cac7388d11e4415392b66603b8188b3725cb5..ca8c830755c04ef38ee60cc65fc4fa8bde48a260 100644 (file)
@@ -1,6 +1,7 @@
 using System;
 using System.Text;
 using System.Collections.Generic;
+using System.Linq;
 
 namespace Crow.Coding
 {
@@ -51,6 +52,9 @@ namespace Crow.Coding
                                return string.IsNullOrEmpty (Content) ? 0 : Content.Length;
                        }
                }
+               public int FirstNonBlankTokIndex {
+                       get { return Tokens == null ? -1 : Tokens.FindIndex (tk=>tk.Type != BufferParser.TokenType.WhiteSpace); }
+               }
 
                public void SetLineInError (ParserException ex) {
                        Tokens = null; 
index 8d8a5d688e2e1ae9db3f59a606a708c0d1909c68..d1f7eb1f0f73a3a84f83d7a6c1b913fb464611d1 100644 (file)
@@ -60,7 +60,7 @@ namespace Crow.Coding
 
                        formatting.Add ((int)BufferParser.TokenType.BlockComment, new TextFormatting (Color.Gray, Color.Transparent, false, true));
                        formatting.Add ((int)BufferParser.TokenType.LineComment, new TextFormatting (Color.Gray, Color.Transparent, false, true));
-                       formatting.Add ((int)BufferParser.TokenType.Affectation, new TextFormatting (Color.Black, Color.Transparent));
+                       formatting.Add ((int)BufferParser.TokenType.OperatorOrPunctuation, new TextFormatting (Color.Black, Color.Transparent));
                        formatting.Add ((int)BufferParser.TokenType.Keyword, new TextFormatting (Color.DarkCyan, Color.Transparent));
 
                        parsing.Add (".crow", "Crow.Coding.XMLParser");
@@ -164,6 +164,7 @@ namespace Crow.Coding
                        NotifyValueChanged ("VisibleLines", visibleLines);
                        updateMaxScrollY ();
                        updatePrintedLines ();
+                       RegisterForGraphicUpdate ();
 //                     System.Diagnostics.Debug.WriteLine ("update visible lines: " + visibleLines);
 //                     System.Diagnostics.Debug.WriteLine ("update MaxScrollY: " + MaxScrollY);
                }
@@ -210,7 +211,6 @@ namespace Crow.Coding
                                        i++;
                                }
                        }
-                       RegisterForGraphicUpdate ();
                }
                void toogleFolding (int line) {
                        if (parser == null || !foldingEnabled)
@@ -244,7 +244,7 @@ namespace Crow.Coding
                                        buffer.longestLineIdx++;
                                if (parser == null)
                                        continue;
-                               parser.tryParseBufferLine (e.LineStart + i);
+                               parser.TryParseBufferLine (e.LineStart + i);
                        }
                        measureLeftMargin ();
 
@@ -309,6 +309,7 @@ namespace Crow.Coding
                void Buffer_FoldingEvent (object sender, CodeBufferEventArgs e)
                {
                        updatePrintedLines ();
+                       updateOnScreenCurLineFromBuffCurLine ();
                        updateMaxScrollY ();
                        RegisterForGraphicUpdate ();
                }
@@ -402,7 +403,12 @@ namespace Crow.Coding
                void loadSource () {
                        
                        try {
-                               buffer.Load (projFile.Source);
+                               
+                               if (parser == null)
+                                       buffer.Load (projFile.Source);
+                               else//parser may have special linebrk rules
+                                       buffer.Load (projFile.Source, parser.LineBrkRegex);
+                               
                        } catch (Exception ex) {
                                Debug.WriteLine (ex.ToString ());
                        }
@@ -464,6 +470,8 @@ namespace Crow.Coding
                                        return;
                                base.ScrollY = value;
                                updatePrintedLines ();
+                               updateOnScreenCurLineFromBuffCurLine ();
+                               RegisterForGraphicUpdate ();
                        }
                }
 
@@ -783,7 +791,7 @@ namespace Crow.Coding
                                if (buffer.SelectionInProgress){
                                        selStartCol = getTabulatedColumn (buffer.SelectionStart);
                                        selEndCol = getTabulatedColumn (buffer.SelectionEnd);
-                               }else if (HasFocus){
+                               }else if (HasFocus && printedCurrentLine >= 0){
                                        gr.LineWidth = 1.0;
                                        double cursorX = cb.X + (getTabulatedColumn(buffer.CurrentPosition) - ScrollX) * fe.MaxXAdvance + leftMargin;
                                        gr.MoveTo (0.5 + cursorX, cb.Y + (printedCurrentLine) * fe.Height);
@@ -806,7 +814,7 @@ namespace Crow.Coding
 
                #region Mouse handling
 
-               void updateCurrentPos(){
+               void updateCurrentPosFromMouseLocalPos(){
                        PrintedCurrentLine = (int)Math.Max (0, Math.Floor (mouseLocalPos.Y / fe.Height));
                        int curVisualCol = ScrollX +  (int)Math.Round ((mouseLocalPos.X - leftMargin) / fe.MaxXAdvance);
 
@@ -855,7 +863,7 @@ namespace Crow.Coding
                                return;
 
                        //mouse is down
-                       updateCurrentPos();
+                       updateCurrentPosFromMouseLocalPos();
                        buffer.SetSelEndPos ();
                }
                public override void onMouseDown (object sender, MouseButtonEventArgs e)
@@ -876,7 +884,7 @@ namespace Crow.Coding
                                return;
                        }
 
-                       updateCurrentPos ();
+                       updateCurrentPosFromMouseLocalPos ();
                        buffer.SetSelStartPos ();
                }
                public override void onMouseUp (object sender, MouseButtonEventArgs e)
index a4273ede22b138e52be11b8d818682f0822f4242..13c94d90d0adaf39201d9edeb5390bd975a91ff9 100644 (file)
@@ -79,7 +79,7 @@ namespace Crow.Coding
                                case ',':
                                        if (curState != States.init || curState != States.classNames )
                                                throw new ParserException (currentLine, currentColumn, "Unexpected char ','");
-                                       readAndResetCurrentTok (TokenType.UnaryOp, true);
+                                       readAndResetCurrentTok (TokenType.OperatorOrPunctuation, true);
                                        curState = States.classNames;
                                        break;
                                case '{':
@@ -97,7 +97,8 @@ namespace Crow.Coding
                                case '=':
                                        if (curState == States.classNames)
                                                throw new ParserException (currentLine, currentColumn, "Unexpected char '='");
-                                       readAndResetCurrentTok (TokenType.Affectation, true);
+                                       setPreviousTokOfTypeTo (TokenType.Type, TokenType.Identifier);
+                                       readAndResetCurrentTok (TokenType.OperatorOrPunctuation, true);
                                        curState = States.value;
                                        break;
                                case '"':
@@ -138,7 +139,7 @@ namespace Crow.Coding
                                                while (nextCharIsValidCharName)
                                                        readToCurrTok ();
                                        }
-                                       saveAndResetCurrentTok (TokenType.Identifier);
+                                       saveAndResetCurrentTok (TokenType.Type);
                                        break;
                                }
                        }
@@ -151,6 +152,33 @@ namespace Crow.Coding
                public override void SyntaxAnalysis ()
                {
                        RootNode = new Node () { Name = "RootNode", Type="Root" };
+
+                       Node currentNode = RootNode;
+
+                       for (int i = 0; i < buffer.LineCount; i++) {
+                               CodeLine cl = buffer[i];
+                               if (cl.Tokens == null)
+                                       continue;
+                               cl.SyntacticNode = null;
+
+                               int tokPtr = 0;
+                               while (tokPtr < cl.Tokens.Count) {
+                                       switch (cl.Tokens [tokPtr].Type) {
+                                       case TokenType.OpenBlock:                                               
+                                               Node newElt = new Node () { Name = cl.Tokens [tokPtr].Content, StartLine = cl };
+                                               currentNode.AddChild (newElt);
+                                               currentNode = newElt;
+                                               if (cl.SyntacticNode == null)
+                                                       cl.SyntacticNode = newElt;
+                                               break;
+                                       case TokenType.CloseBlock:                                              
+                                               currentNode.EndLine = cl;
+                                               currentNode = currentNode.Parent;
+                                               break;
+                                       }
+                                       tokPtr++;
+                               }
+                       }
                }
        }
 }
index 59601a75cfff25df296bd9aae5e87294ef392ca7..ada055124a34ade5e03f80419dca4520388e3bbb 100644 (file)
@@ -20,7 +20,7 @@ namespace Crow.Coding
                        ElementName = BufferParser.TokenType.Type,
                        AttributeName = BufferParser.TokenType.Identifier,
                        ElementClosing = BufferParser.TokenType.StatementEnding,
-                       Affectation = BufferParser.TokenType.Affectation,
+                       Affectation = BufferParser.TokenType.OperatorOrPunctuation,
                        AttributeValueOpening = BufferParser.TokenType.StringLitteralOpening,
                        AttributeValueClosing = BufferParser.TokenType.StringLitteralClosing,
                        AttributeValue = BufferParser.TokenType.StringLitteral,
diff --git a/CrowIDE/ui/ItemTemplates/Enum.template b/CrowIDE/ui/ItemTemplates/Enum.template
new file mode 100755 (executable)
index 0000000..768b80d
--- /dev/null
@@ -0,0 +1,48 @@
+<?xml version="1.0"?>
+<HorizontalStack Style="MemberViewHStack" ContextCommands="{Commands}">
+       <Label Style="MemberViewLabel" Text="{Name}" Foreground = "{LabForeground}"/>
+       <ComboBox Margin="0"  Height="Stretched" Width="50%" Data="{Choices}"
+                       SelectedItem="{²Value}">
+               <Template>
+                       <Popper Name="popper" PopDirection="Bottom">
+                               <Template>
+                                       <CheckBox Caption="{./Caption}" IsChecked="{²./IsPopped}" Foreground="{./Foreground}" Background="{./Background}">
+                                               <Template>
+                                                       <Border CornerRadius="0" Foreground="LightGray" Background="White">
+                                                               <HorizontalStack Margin="0" Spacing="1">
+                                                                       <Label Width="Stretched" MinimumSize="80,10" Margin="1" Foreground = "{LabForeground}" Background="White"
+                                                                               Text="{../../../../../SelectedItem}"/>
+                                                                       <Button Width="12" Height="12" Focusable="false"
+                                                                               Template="#Crow.Templates.ArrowBut.template">
+                                                                               <Image Margin="1" Path="#Crow.Images.Icons.updown.svg" SvgSub="down"/>
+                                                                       </Button>
+                                                               </HorizontalStack>
+                                                       </Border>
+                                               </Template>
+                                       </CheckBox>
+                               </Template>
+                               <Border Background="White" BorderWidth="1" Margin="1" Foreground="Black"
+                                       MinimumSize="{../../MinimumPopupSize}" Fit="true">
+                                       <Scroller Name="scroller1" Margin="2" VerticalScrolling="true"
+                                               MaximumSize="0,200"
+                                               HorizontalAlignment="Left"
+                                               ValueChanged="../../../_scroller_ValueChanged">
+                                               <VerticalStack LayoutChanged="../../../../_list_LayoutChanged"
+                                                       MouseClick="../../../onMouseClick" Focusable="True"
+                                                       Height="Fit" Name="ItemsContainer" Margin="0"
+                                                       HorizontalAlignment="Left"
+                                                       VerticalAlignment="Top"/>
+                                       </Scroller>
+                               </Border>
+                       </Popper>
+               </Template>
+               <ItemTemplate>
+                       <Container Fit="true" Margin="0" Focusable="true"
+                                       HorizontalAlignment="Left"
+                                       MouseEnter="{Background=SteelBlue}"
+                                       MouseLeave="{Background=Transparent}">
+                               <Label Text="{}" Foreground="Black"/>
+                       </Container>
+               </ItemTemplate>
+       </ComboBox>
+</HorizontalStack>
diff --git a/CrowIDE/ui/ItemTemplates/Fill.template b/CrowIDE/ui/ItemTemplates/Fill.template
new file mode 100755 (executable)
index 0000000..b3b1e89
--- /dev/null
@@ -0,0 +1,19 @@
+<?xml version="1.0"?>
+<HorizontalStack Style="MemberViewHStack" ContextCommands="{Commands}">
+       <Label Style="MemberViewLabel" Text="{Name}" Foreground = "{LabForeground}"/>
+       <Popper Height="Stretched" Caption="{Value}">
+               <Template>
+                       <CheckBox Caption="{./Caption}" IsChecked="{²./IsPopped}">
+                               <Template>
+                                       <HorizontalStack Margin="1" Height="Stretched" Spacing="3" Background="White">
+                                               <Border Foreground="{LabForeground}" Width="18" Height="12" CornerRadius="3"
+                                                       Background="{Value}">
+                                               </Border>
+                                               <Label Width="Stretched" Text="{./Caption}" Foreground="{LabForeground}"/>
+                                       </HorizontalStack>
+                               </Template>
+                       </CheckBox>
+               </Template>
+               <ColorPicker SelectedColor="{²Value}" Background="Onyx" Margin="5" Fit="True" />
+       </Popper>
+</HorizontalStack>
\ No newline at end of file
index cc653ef881c6ad5708a52f6e2d419a92dfc37be0..812d7884acf00873b71e25762fb8961f98aec81e 100755 (executable)
                <CheckBox Background="White" Foreground = "{LabForeground}" Height="Stretched" Caption="" IsChecked="{²Value}"/>
        </HorizontalStack>
 </ItemTemplate>
-<ItemTemplate DataType="System.Enum">
-       <HorizontalStack Style="MemberViewHStack" ContextCommands="{Commands}">
-               <Label Style="MemberViewLabel" Text="{Name}" Foreground = "{LabForeground}"/>
-               <ComboBox Margin="0"  Height="Stretched" Width="50%" Data="{Choices}"
-                               SelectedItem="{²Value}">
-                       <Template>
-                               <Popper Name="popper" PopDirection="Bottom">
-                                       <Template>
-                                               <CheckBox Caption="{./Caption}" IsChecked="{²./IsPopped}" Foreground="{./Foreground}" Background="{./Background}">
-                                                       <Template>
-                                                               <Border CornerRadius="0" Foreground="LightGray" Background="White">
-                                                                       <HorizontalStack Margin="0" Spacing="1">
-                                                                               <Label Width="Stretched" MinimumSize="80,10" Margin="1" Foreground = "{LabForeground}" Background="White"
-                                                                                       Text="{../../../../../SelectedItem}"/>
-                                                                               <Button Width="12" Height="12" Focusable="false"
-                                                                                       Template="#Crow.Templates.ArrowBut.template">
-                                                                                       <Image Margin="1" Path="#Crow.Images.Icons.updown.svg" SvgSub="down"/>
-                                                                               </Button>
-                                                                       </HorizontalStack>
-                                                               </Border>
-                                                       </Template>
-                                               </CheckBox>
-                                       </Template>
-                                       <Border Background="White" BorderWidth="1" Margin="1" Foreground="Black"
-                                               MinimumSize="{../../MinimumPopupSize}" Fit="true">
-                                               <Scroller Name="scroller1" Margin="2" VerticalScrolling="true"
-                                                       MaximumSize="0,200"
-                                                       HorizontalAlignment="Left"
-                                                       ValueChanged="../../../_scroller_ValueChanged">
-                                                       <VerticalStack LayoutChanged="../../../../_list_LayoutChanged"
-                                                               MouseClick="../../../onMouseClick" Focusable="True"
-                                                               Height="Fit" Name="ItemsContainer" Margin="0"
-                                                               HorizontalAlignment="Left"
-                                                               VerticalAlignment="Top"/>
-                                               </Scroller>
-                                       </Border>
-                               </Popper>
-                       </Template>
-                       <ItemTemplate>
-                               <Container Fit="true" Margin="0" Focusable="true"
-                                               HorizontalAlignment="Left"
-                                               MouseEnter="{Background=SteelBlue}"
-                                               MouseLeave="{Background=Transparent}">
-                                       <Label Text="{}" Foreground="Black"/>
-                               </Container>
-                       </ItemTemplate>
-               </ComboBox>
-       </HorizontalStack>
-</ItemTemplate>
-<ItemTemplate DataType="Crow.Fill">
-       <HorizontalStack Style="MemberViewHStack" ContextCommands="{Commands}">
-               <Label Style="MemberViewLabel" Text="{Name}" Foreground = "{LabForeground}"/>
-               <Popper Height="Stretched" Caption="{Value}">
-                       <Template>
-                               <CheckBox Caption="{./Caption}" IsChecked="{²./IsPopped}">
-                                       <Template>
-                                               <HorizontalStack Margin="1" Height="Stretched" Spacing="3" Background="White">
-                                                       <Border Foreground="{LabForeground}" Width="18" Height="12" CornerRadius="3"
-                                                               Background="{Value}">
-                                                       </Border>
-                                                       <Label Width="Stretched" Text="{./Caption}" Foreground="{LabForeground}"/>
-                                               </HorizontalStack>
-                                       </Template>
-                               </CheckBox>
-                       </Template>
-                       <ColorPicker SelectedColor="{²Value}" Background="Onyx" Margin="5" Fit="True" />
-               </Popper>
-       </HorizontalStack>
-</ItemTemplate>
\ No newline at end of file
+<ItemTemplate Path="#Crow.Coding.ui.ItemTemplates.Enum.template" DataType="System.Enum" />
+<ItemTemplate Path="#Crow.Coding.ui.ItemTemplates.Enum.template" DataType="Style" />
+<ItemTemplate Path="#Crow.Coding.ui.ItemTemplates.Fill.template" DataType="Crow.Fill"/>
+       
\ No newline at end of file
index 2e9e72a1af06333fbc6ea7f118e12e4f9dfc1ec8..c5e42347c95ddb33da07867a8aac3bdf2912bb2f 100644 (file)
@@ -65,7 +65,7 @@ DockWindow {
        AllowDrag = "true";
 }
 MessageBox {
-       Background = "0.3,0.3,0.3,0.3";
+       Background = "0.1,0.1,0.2,0.7";
        Width = "Fit";
        Caption="MessageBox";
        Font = "serif, 12";
index 129e24ca244efcaec17af5d3aad5c63c972a8079..e8b58ad147c47c87fd5559478f1b437d8661fec9 100644 (file)
                                <GraphicObject Width="5" Height="5"/>
                        </HorizontalStack>
                </Border>
-               <HorizontalStack Margin="5">
+               <HorizontalStack Margin="5" >
                        <Image Name="Image" Width="50" Height="30" Path="{./MsgIcon}" />
-                       <Label Margin="5" Font="{./Font}" Width="Fit" Text="{./Message}"
-                               TextAlignment="Left"
+                       <Label Margin="5" Font="{./Font}" Width="Fit" Text="{./Message}"                                
+                               TextAlignment="Center"
                                Multiline="true" />             
                </HorizontalStack>
-               <HorizontalStack Margin="1" Spacing="0" Width="Fit" Height="Fit" HorizontalAlignment="Right">
+               <HorizontalStack Margin="4" Spacing="0" Width="Fit" Height="Fit" HorizontalAlignment="Right">
                        <Button Width="Fit" Caption="{./OkMessage}" MouseClick="./onOkButtonClick" />
-                       <Button Width="Fit" Caption="{./CancelMessage}" MouseClick="./onCancelButtonClick" />
+                       <Button Width="Fit" Visible="{./NoButIsVisible}"
+                               Caption="{./NoMessage}" MouseClick="./onNoButtonClick" />
+                       <Button Width="Fit" Visible="{./CancelButIsVisible}"
+                               Caption="{./CancelMessage}" MouseClick="./onCancelButtonClick" />
                </HorizontalStack>
        </VerticalStack>
 </Border>
index fc327ab142284da222906b97fb0a98290af5f132..e9709b2c28bcdba5235c4fd86474a962b372880f 100644 (file)
@@ -1,34 +1,34 @@
 FpsLabel {
-       Width = 50%;
-       Font = droid, 10;
-       Margin = 0;
-       TextAlignment = Center;
-       Background = Onyx;
+       Width = "50%";
+       Font = "droid, 10";
+       Margin = "0";
+       TextAlignment = "Center";
+       Background = "Onyx";
 }
 FpsDisp {
-       Font = droid bold, 10;
-       Width = 50%;
-       Margin = 0;
-       TextAlignment = Center;
-       Background = Teal;
+       Font = "droid bold, 10";
+       Width = "50%";
+       Margin = "0";
+       TextAlignment = "Center";
+       Background = "Teal";
 }
 CheckBox2 {
-       Template= #Tests.Interfaces.CheckBox2.imlt;
-       Background = Onyx;
-       Checked={Background=Mantis;Font=droid bold, 10};
-       Unchecked = {Background=Onyx;Font=droid,10};
+       Template= "#Tests.Interfaces.CheckBox2.imlt";
+       Background = "Onyx";
+       Checked="{Background=Mantis;Font=droid bold, 10}";
+       Unchecked = "{Background=Onyx;Font=droid,10}";
 }
 RadioButton2 {
-       Template=#Tests.Interfaces.CheckBox2.imlt;
-       Background = Onyx;
-       Checked = {Background=Mantis;Font=droid bold, 10};
-       Unchecked = {Background=Onyx;Font=droid,10};
+       Template="#Tests.Interfaces.CheckBox2.imlt";
+       Background = "Onyx";
+       Checked = "{Background=Mantis;Font=droid bold, 10}";
+       Unchecked = "{Background=Onyx;Font=droid,10}";
 }
 labPerf {
-       Font = droid, 8;
-       Width = 50%;
+       Font = "droid, 8";
+       Width = "50%";
 }
 labPerfVal{
-       Font = droid, 8;
-       Width = 50%;
+       Font = "droid, 8";
+       Width = "50%";
 }
index 617cfb8e877f9d2d77d5cc1e221bcb83f752e0ed..7182d8682b0a1bb49e69774e386a2ced2600c22d 100644 (file)
@@ -1,8 +1,8 @@
-MouseEnter = {Background = Gray;Foreground = White;}
-Fit = true;
-MouseLeave = {Background=Transparent;Foreground=Gray;}
-MouseDown = {Background=Red;Foreground=White;}
-MouseUp = {Background=Gray;Foreground=White;}
-Foreground=Gray;
-Margin=5;
-CornerRadius=5;
+MouseEnter = "{Background = Gray;Foreground = White;}";
+Fit = "true";
+MouseLeave = "{Background=Transparent;Foreground=Gray;}";
+MouseDown = "{Background=Red;Foreground=White;}";
+MouseUp = "{Background=Gray;Foreground=White;}";
+Foreground="Gray";
+Margin="5";
+CornerRadius="5";
index bce8e730104778121cf21e906a077d5f5011bd3f..969a4abc27d5b830c836acf09ee804f69c802fd0 100644 (file)
@@ -1,11 +1,11 @@
-Height = Fit;
-Width = Stretched;
-MinimumSize=60;10;
-Margin=2;
-CornerRadius=0;
-TextAlignment=Left;
-Foreground=Gray;
-MouseEnter = {Background=SeaGreen;Foreground=White;}
-MouseLeave = {Background=Transparent;Foreground=Gray;}
-MouseDown = {Background=White;Foreground=DimGray;}
-MouseUp = {Background=SeaGreen;Foreground=White;}
+Height = "Fit";
+Width = "Stretched";
+MinimumSize="60;10";
+Margin="2";
+CornerRadius="0";
+TextAlignment="Left";
+Foreground="Gray";
+MouseEnter = "{Background=SeaGreen;Foreground=White;}";
+MouseLeave = "{Background=Transparent;Foreground=Gray;}";
+MouseDown = "{Background=White;Foreground=DimGray;}";
+MouseUp = "{Background=SeaGreen;Foreground=White;}";
index 56508d2308c9ec87f21dbd6d0bf11b2dd844920d..1189b0e0642fef8b65f66a212ea058d4fbf32dd5 100644 (file)
@@ -55,6 +55,7 @@ namespace Crow
 
                public virtual void OnTextChanged(Object sender, TextChangeEventArgs e)
                {
+                       textMeasureIsUpToDate = false;
                        NotifyValueChanged ("Text", Text);
                        TextChanged.Raise (this, e);
                }
@@ -437,48 +438,49 @@ namespace Crow
                        CurrentColumn = 0;
                        OnTextChanged (this, new TextChangeEventArgs (Text));
                }
+               bool textMeasureIsUpToDate = false;
+               Size cachedTextSize = default(Size);
 
                #region GraphicObject overrides
                protected override int measureRawSize(LayoutingType lt)
-        {
+               {
                        if (lines == null)
                                lines = getLines;
-
-                       using (ImageSurface img = new ImageSurface (Format.Argb32, 10, 10)) {
-                               using (Context gr = new Context (img)) {
-                                       //Cairo.FontFace cf = gr.GetContextFontFace ();
-
-                                       gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight);
-                                       gr.SetFontSize (Font.Size);
-
-
-                                       fe = gr.FontExtents;
-                                       te = new TextExtents();
-
-                                       if (lt == LayoutingType.Height){
-                                               int lc = lines.Count;
-                                               //ensure minimal height = text line height
-                                               if (lc == 0)
-                                                       lc = 1;
-
-                                               return (int)Math.Ceiling(fe.Height * lc) + Margin * 2;
+                       if (!textMeasureIsUpToDate) {
+                               using (ImageSurface img = new ImageSurface (Format.Argb32, 10, 10)) {
+                                       using (Context gr = new Context (img)) {
+                                               //Cairo.FontFace cf = gr.GetContextFontFace ();
+
+                                               gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight);
+                                               gr.SetFontSize (Font.Size);
+                                               gr.FontOptions = Interface.FontRenderingOptions;
+                                               gr.Antialias = Interface.Antialias;
+
+                                               fe = gr.FontExtents;
+                                               te = new TextExtents ();
+
+                                               cachedTextSize.Height = (int)Math.Ceiling ((fe.Ascent+fe.Descent) * Math.Max (1, lines.Count)) + Margin * 2;
+
+                                               try {
+                                                       foreach (string s in lines) {
+                                                               string l = s.Replace ("\t", new String (' ', Interface.TabSize));
+
+                                                               TextExtents tmp = gr.TextExtents (l);
+
+                                                               if (tmp.XAdvance > te.XAdvance)
+                                                                       te = tmp;
+                                                       }
+                                                       cachedTextSize.Width = (int)Math.Ceiling (te.XAdvance) + Margin * 2;
+                                                       textMeasureIsUpToDate = true;
+                                               } catch {                                                       
+                                                       return -1;
+                                               }                                       
                                        }
-                                       try {
-                                               foreach (string s in lines) {
-                                                       string l = s.Replace("\t", new String (' ', Interface.TabSize));
-
-                                                       TextExtents tmp = gr.TextExtents (l);
-
-                                                       if (tmp.XAdvance > te.XAdvance)
-                                                               te = tmp;
-                                               }
-                                       } catch (Exception ex) {
-                                               return -1;
-                                       }
-                                       return (int)Math.Ceiling (te.XAdvance) + Margin * 2;
                                }
+
                        }
-        }
+                       return lt == LayoutingType.Height ? cachedTextSize.Height : cachedTextSize.Width;
+               }
                protected override void onDraw (Context gr)
                {
                        base.onDraw (gr);
@@ -552,11 +554,12 @@ namespace Crow
                                break;
                        case Alignment.Center://ok
                                rText.X = cb.X + cb.Width / 2 - rText.Width / 2;
-                               rText.Y = cb.Y + cb.Height / 2 - rText.Height / 2;
+                               //rText.Y = cb.Y + cb.Height / 2 - rText.Height / 2;
+                               rText.Y = cb.Y + (int)Math.Floor((double)cb.Height / 2.0 - (double)rText.Height / 2.0);
                                break;
                        }
 
-                       gr.FontMatrix = new Matrix(widthRatio * (float)Font.Size, 0, 0, heightRatio * (float)Font.Size, 0, 0);
+                       //gr.FontMatrix = new Matrix(widthRatio * (float)Font.Size, 0, 0, heightRatio * (float)Font.Size, 0, 0);
                        fe = gr.FontExtents;
 
                        #region draw text cursor
@@ -586,8 +589,8 @@ namespace Crow
 
                                Foreground.SetAsSource (gr);
                                gr.LineWidth = 1.0;
-                               gr.MoveTo (0.5 + textCursorPos + rText.X, rText.Y + CurrentLine * fe.Height);
-                               gr.LineTo (0.5 + textCursorPos + rText.X, rText.Y + (CurrentLine + 1) * fe.Height);
+                               gr.MoveTo (0.5 + textCursorPos + rText.X, rText.Y + CurrentLine * (fe.Ascent+fe.Descent));
+                               gr.LineTo (0.5 + textCursorPos + rText.X, rText.Y + (CurrentLine + 1) * (fe.Ascent+fe.Descent));
                                gr.Stroke();
                        }
                        #endregion
@@ -597,9 +600,9 @@ namespace Crow
 //                             new SolidColor(Color.DarkGreen).SetAsSource(gr);
 //                             Rectangle R = new Rectangle (
 //                                                  rText.X + (int)SelEndCursorPos - 3,
-//                                                  rText.Y + (int)(SelRelease.Y * fe.Height),
+//                                                  rText.Y + (int)(SelRelease.Y * (fe.Ascent+fe.Descent)),
 //                                                  6,
-//                                                  (int)fe.Height);
+//                                                  (int)(fe.Ascent+fe.Descent));
 //                             gr.Rectangle (R);
 //                             gr.Fill ();
 //                     }
@@ -607,9 +610,9 @@ namespace Crow
 //                             new SolidColor(Color.DarkRed).SetAsSource(gr);
 //                             Rectangle R = new Rectangle (
 //                                     rText.X + (int)SelStartCursorPos - 3,
-//                                     rText.Y + (int)(SelBegin.Y * fe.Height),
+//                                     rText.Y + (int)(SelBegin.Y * (fe.Ascent+fe.Descent)),
 //                                     6,
-//                                     (int)fe.Height);
+//                                     (int)(fe.Ascent+fe.Descent));
 //                             gr.Rectangle (R);
 //                             gr.Fill ();
 //                     }
@@ -620,9 +623,9 @@ namespace Crow
                                int lineLength = (int)gr.TextExtents (l).XAdvance;
                                Rectangle lineRect = new Rectangle (
                                        rText.X,
-                                       rText.Y + (int)Math.Ceiling(i * fe.Height),
+                                       rText.Y + (int)Math.Floor((double)i * (fe.Ascent+fe.Descent)),
                                        lineLength,
-                                       (int)Math.Ceiling(fe.Height));
+                                       (int)Math.Ceiling((fe.Ascent+fe.Descent)));
 
 //                             if (TextAlignment == Alignment.Center ||
 //                                     TextAlignment == Alignment.Top ||
@@ -636,7 +639,7 @@ namespace Crow
                                        continue;
 
                                Foreground.SetAsSource (gr);
-                               gr.MoveTo (lineRect.X, rText.Y + fe.Ascent + fe.Height * i);
+                               gr.MoveTo (lineRect.X,(double)rText.Y + fe.Ascent + (fe.Ascent+fe.Descent) * i) ;
                                gr.ShowText (l);
                                gr.Fill ();
 
@@ -666,7 +669,7 @@ namespace Crow
                                                gr.Save ();
                                                gr.Clip ();
                                                gr.SetSourceColor (SelectionForeground);
-                                               gr.MoveTo (lineRect.X, rText.Y + fe.Ascent + fe.Height * i);
+                                               gr.MoveTo (lineRect.X, (double)rText.Y + fe.Ascent + (fe.Ascent+fe.Descent) * i);
                                                gr.ShowText (l);
                                                gr.Fill ();
                                                gr.Restore ();
@@ -774,7 +777,7 @@ namespace Crow
 
                        double cPos = 0f;
 
-                       CurrentLine = (int)(mouseLocalPos.Y / fe.Height);
+                       CurrentLine = (int)(mouseLocalPos.Y / (fe.Ascent+fe.Descent));
 
                        //fix cu
                        if (CurrentLine >= lines.Count)
index e59e0e63d77b5b9e3f83e446a1b79bde6a36bff3..45ef1e009ce3bf85824663018e2471d6d1db07ca 100644 (file)
@@ -38,10 +38,13 @@ namespace Crow
                #endregion
 
                public enum Type {
+                       None,
                        Information,
-                       YesNo,
                        Alert,
-                       Error
+                       Error,
+                       YesNo,
+                       YesNoCancel,
+
                }
 
                protected override void loadTemplate (GraphicObject template)
@@ -49,13 +52,14 @@ namespace Crow
                        base.loadTemplate (template);
                        NotifyValueChanged ("MsgIcon", "#Crow.Images.Icons.Informations.svg");
                }
-               string message, okMessage, cancelMessage;
-               Type msgType = Type.Information;
+               string message, okMessage, cancelMessage, noMessage;
+               Type msgType = Type.None;
 
-               public event EventHandler Ok;
+               public event EventHandler Yes;
+               public event EventHandler No;
                public event EventHandler Cancel;
 
-               [XmlAttributeAttribute][DefaultValue("Informations")]
+               [DefaultValue("Informations")]
                public virtual string Message
                {
                        get { return message; }
@@ -66,7 +70,7 @@ namespace Crow
                                NotifyValueChanged ("Message", message);
                        }
                }
-               [XmlAttributeAttribute][DefaultValue("Ok")]
+               [DefaultValue("Ok")]
                public virtual string OkMessage
                {
                        get { return okMessage; }
@@ -77,7 +81,7 @@ namespace Crow
                                NotifyValueChanged ("OkMessage", okMessage);
                        }
                }
-               [XmlAttributeAttribute][DefaultValue("Cancel")]
+               [DefaultValue("Cancel")]
                public virtual string CancelMessage
                {
                        get { return cancelMessage; }
@@ -88,7 +92,18 @@ namespace Crow
                                NotifyValueChanged ("CancelMessage", cancelMessage);
                        }
                }
-               [XmlAttributeAttribute][DefaultValue("Information")]
+               [DefaultValue("No")]
+               public virtual string NoMessage
+               {
+                       get { return cancelMessage; }
+                       set {
+                               if (cancelMessage == value)
+                                       return;
+                               cancelMessage = value;
+                               NotifyValueChanged ("NoMessage", cancelMessage);
+                       }
+               }
+               [DefaultValue("Information")]
                public virtual Type MsgType
                {
                        get { return msgType; }
@@ -99,34 +114,58 @@ namespace Crow
                                NotifyValueChanged ("MsgType", msgType);
                                switch (msgType) {
                                case Type.Information:
-                                       NotifyValueChanged ("MsgIcon", "#Crow.Images.Icons.Informations.svg");
+                                       MsgIcon = "#Crow.Images.Icons.Informations.svg";
                                        Caption = "Informations";
                                        OkMessage = "Ok";
-                                       CancelMessage = "Cancel";
+                                       NotifyValueChanged ("CancelButIsVisible", false);
+                                       NotifyValueChanged ("NoButIsVisible", false);
                                        break;
                                case Type.YesNo:
-                                       NotifyValueChanged ("MsgIcon", "#Crow.Icons.question.svg");
+                               case Type.YesNoCancel:
+                                       MsgIcon = "#Crow.Icons.question.svg";
                                        Caption = "Choice";
                                        OkMessage = "Yes";
-                                       CancelMessage = "No";
+                                       NoMessage = "No";
+                                       NotifyValueChanged ("CancelButIsVisible", msgType == Type.YesNoCancel);
+                                       NotifyValueChanged ("NoButIsVisible", true);
                                        break;
                                case Type.Alert:
-                                       NotifyValueChanged ("MsgIcon", "#Crow.Images.Icons.IconAlerte.svg");
+                                       MsgIcon = "#Crow.Images.Icons.IconAlerte.svg";
                                        Caption = "Alert";
                                        OkMessage = "Ok";
                                        CancelMessage = "Cancel";
+                                       NotifyValueChanged ("CancelButIsVisible", true);
+                                       NotifyValueChanged ("NoButIsVisible", false);
                                        break;
                                case Type.Error:
-                                       NotifyValueChanged ("MsgIcon", "#Crow.Images.Icons.exit.svg");
+                                       MsgIcon = "#Crow.Images.Icons.exit.svg";
                                        Caption = "Error";
                                        OkMessage = "Ok";
+                                       NotifyValueChanged ("CancelButIsVisible", false);
+                                       NotifyValueChanged ("NoButIsVisible", false);
                                        break;
                                }
                        }
                }
+
+               string msgIcon = null;
+               public string MsgIcon {
+                       get { return msgIcon; }
+                       set {
+                               if (value == MsgIcon)
+                                       return;
+                               msgIcon = value;
+                               NotifyValueChanged ("MsgIcon", MsgIcon);
+                       }
+               }
                void onOkButtonClick (object sender, EventArgs e)
                {
-                       Ok.Raise (this, null);
+                       Yes.Raise (this, null);
+                       close ();
+               }
+               void onNoButtonClick (object sender, EventArgs e)
+               {
+                       No.Raise (this, null);
                        close ();
                }
                void onCancelButtonClick (object sender, EventArgs e)
@@ -147,6 +186,18 @@ namespace Crow
                                return mb;
                        }
                }
+               public static MessageBox ShowModal (Interface iface, Type msgBoxType, string message){
+                       lock (iface.UpdateMutex) {
+                               MessageBox mb = new MessageBox (iface) {
+                                       Modal = true,
+                                       MsgType = msgBoxType,
+                                       Message = message
+                               };
+
+                               iface.AddWidget (mb);
+                               return mb;
+                       }
+               }
        }
 }
 
index cff96a7574d946a2b0cfd87168fc21c86533c4d9..4eef9696fbc3eeb3ce24fa5281804b2f8fc64f6b 100644 (file)
@@ -47,8 +47,9 @@ namespace Crow
                }
 
                string _icon;
-               bool _resizable;
-               bool _movable;
+               bool resizable;
+               bool movable;
+               bool modal;
                protected bool hoverBorder = false;
                bool alwaysOnTop = false;
                Fill titleBarBackground = Color.UnitedNationsBlue;
@@ -124,25 +125,37 @@ namespace Crow
                [XmlAttributeAttribute][DefaultValue(true)]
                public bool Resizable {
                        get {
-                               return _resizable;
+                               return resizable;
                        }
                        set {
-                               if (_resizable == value)
+                               if (resizable == value)
                                        return;
-                               _resizable = value;
-                               NotifyValueChanged ("Resizable", _resizable);
+                               resizable = value;
+                               NotifyValueChanged ("Resizable", resizable);
                        }
                }
                [XmlAttributeAttribute][DefaultValue(true)]
                public bool Movable {
                        get {
-                               return _movable;
+                               return movable;
                        }
                        set {
-                               if (_movable == value)
+                               if (movable == value)
                                        return;
-                               _movable = value;
-                               NotifyValueChanged ("Movable", _movable);
+                               movable = value;
+                               NotifyValueChanged ("Movable", movable);
+                       }
+               }
+               [XmlAttributeAttribute][DefaultValue(false)]
+               public bool Modal {
+                       get {
+                               return modal;
+                       }
+                       set {
+                               if (modal == value)
+                                       return;
+                               modal = value;
+                               NotifyValueChanged ("Modal", modal);
                        }
                }
                [XmlAttributeAttribute][DefaultValue(false)]
@@ -167,17 +180,18 @@ namespace Crow
                [XmlAttributeAttribute][DefaultValue(false)]
                public bool AlwaysOnTop {
                        get {
-                               return alwaysOnTop;
+                               return modal ? true : alwaysOnTop;
                        }
                        set {
                                if (alwaysOnTop == value)
                                        return;
+                               
                                alwaysOnTop = value;
 
-                               if (alwaysOnTop && Parent != null)
+                               if (AlwaysOnTop && Parent != null)
                                        IFace.PutOnTop (this);
 
-                               NotifyValueChanged ("AlwaysOnTop", alwaysOnTop);
+                               NotifyValueChanged ("AlwaysOnTop", AlwaysOnTop);
                        }
                }
 //             [XmlAttributeAttribute()][DefaultValue(WindowState.Normal)]
@@ -286,7 +300,7 @@ namespace Crow
                                return;
                        }
 
-                       if (this.HasFocus && _movable) {
+                       if (this.HasFocus && movable) {
                                if (e.Mouse.IsButtonDown (MouseButton.Left)) {
                                        MoveAndResize (e.XDelta, e.YDelta, currentDirection);
                                        return;
@@ -353,6 +367,10 @@ namespace Crow
                {
                        base.onMouseDown (sender, e);
                }
+               public override bool MouseIsIn (Point m)
+               {
+                       return modal ? true : base.MouseIsIn (m);
+               }
                #endregion
 
                protected void onMaximized (object sender, EventArgs e){