]> O.S.I.I.S - jp/crow.git/commitdiff
Menu and MenuItem classes, templates, styles and tests
authorjpbruyere <jp.bruyere@hotmail.com>
Fri, 19 Aug 2016 20:44:48 +0000 (22:44 +0200)
committerjpbruyere <jp.bruyere@hotmail.com>
Thu, 1 Sep 2016 10:44:38 +0000 (12:44 +0200)
modifié :         Crow.csproj
modifié :         Default.style
modifié :         Style.cs
nouveau fichier : Templates/Menu.template
nouveau fichier : Templates/MenuItem.template
modifié :         Tests/Interfaces/TemplatedGroup/0.crow
nouveau fichier : Tests/Interfaces/TemplatedGroup/1.crow
nouveau fichier : Tests/Interfaces/TemplatedGroup/2.crow
modifié :         Tests/Tests.csproj
nouveau fichier : src/GraphicObjects/Menu.cs
nouveau fichier : src/GraphicObjects/MenuItem.cs
modifié :         src/GraphicObjects/TemplatedGroup.cs

12 files changed:
Crow.csproj
Default.style
Templates/Menu.template [new file with mode: 0644]
Templates/MenuItem.template [new file with mode: 0644]
Tests/Interfaces/TemplatedGroup/0.crow
Tests/Interfaces/TemplatedGroup/1.crow [new file with mode: 0755]
Tests/Interfaces/TemplatedGroup/2.crow [new file with mode: 0755]
Tests/Tests.csproj
src/GraphicObjects/Menu.cs [new file with mode: 0644]
src/GraphicObjects/MenuItem.cs [new file with mode: 0644]
src/GraphicObjects/TemplatedGroup.cs
src/Style.cs

index 570a8941fd67a5fe9d50d25c001a16c5446f4470..5c6cb9e3c96dc43ff33fe72837687c7930e1322c 100644 (file)
     <Compile Include="src\Style.cs" />
     <Compile Include="src\GraphicObjects\Wrapper.cs" />
     <Compile Include="src\GraphicObjects\TemplatedGroup.cs" />
+    <Compile Include="src\GraphicObjects\MenuItem.cs" />
+    <Compile Include="src\GraphicObjects\Menu.cs" />
   </ItemGroup>
   <ItemGroup>
     <Reference Include="System" />
     </EmbeddedResource>
     <EmbeddedResource Include="Images\Icons\Cursors\ibeam" />
     <EmbeddedResource Include="Templates\treeList.crow" />
+    <EmbeddedResource Include="Templates\MenuItem.template">
+      <LogicalName>Crow.MenuItem.template</LogicalName>
+    </EmbeddedResource>
+    <EmbeddedResource Include="Templates\Menu.template">
+      <LogicalName>Crow.Menu.template</LogicalName>
+    </EmbeddedResource>
   </ItemGroup>
   <ItemGroup>
     <None Include="README.md" />
index 8a63a27674d00b661dcd5e35ca48a2541163a8a6..9ddac6a9ecaafe013b3acbbb8f5c3ce59650cb69 100644 (file)
@@ -14,6 +14,20 @@ Label {
        Width = Fit;
        Margin = 0;
 }
+Menu {
+       Margin = 1;
+       Background = vgradient|0:DimGray|1:Onyx;
+       Height = Fit;
+       Width = Stretched;
+       VerticalAlignment = Top;
+}
+MenuItem {
+       Height = Fit;
+       Width = Fit;
+       Background = Transparent;
+       MouseEnter = {Background = Mantis;Foreground=Jet;}
+       MouseLeave = {Background=Transparent;Foreground=LightGray;};
+}
 MessageBox {
        Width=200;
        Title=MessageBox;
diff --git a/Templates/Menu.template b/Templates/Menu.template
new file mode 100644 (file)
index 0000000..facc189
--- /dev/null
@@ -0,0 +1,3 @@
+<?xml version="1.0"?>
+<HorizontalStack Name="ItemsContainer" Margin="2" Background="{./Background}"
+       Width="{./WidthPolicy}" Height="{./HeightPolicy}"/>
diff --git a/Templates/MenuItem.template b/Templates/MenuItem.template
new file mode 100644 (file)
index 0000000..86b05be
--- /dev/null
@@ -0,0 +1,17 @@
+<?xml version="1.0"?>
+<Popper Caption="{./Caption}"  Background="{./Background}" PopDirection="{./Orientation}"
+       Foreground = "{./Foreground}"
+       Unpop = "{Foreground=LightGray;Background=Transparent}">
+       <Template>
+               <Label Text="{./Caption}"
+                       MinimumSize = "120,0"
+                       Margin="3" TextAlignment="Left"
+                       Height="{./HeightPolicy}" Width="{./WidthPolicy}"
+                       Font="{./Font}"
+                       Background="{./Background}"
+                       Foreground="{./Foreground}"/>
+       </Template>
+       <Border Foreground="LightGray" Fit="true">
+               <VerticalStack Name="ItemsContainer" Margin="2" Fit="true" Background="Onyx"/>
+       </Border>
+</Popper>
index 9c7bb705e1543f7fedbe888072d6b077f7dbacce..09b4bd49decbf5bfecf77d979c9f8999e06c5c9e 100755 (executable)
@@ -1 +1,23 @@
 <?xml version="1.0"?>
+<Menu>
+       <MenuItem Caption="File">
+               <MenuItem Caption="New"/>
+               <MenuItem Caption="Open"/>
+               <MenuItem Caption="Save"/>
+               <MenuItem Caption="Quit"/>
+       </MenuItem>
+       <MenuItem Caption="Edit">
+               <MenuItem Caption="Cut"/>
+               <MenuItem Caption="Copy"/>
+               <MenuItem Caption="Paste"/>
+               <MenuItem Caption="Special">
+                       <MenuItem Caption="Cut"/>
+                       <MenuItem Caption="Copy"/>
+                       <MenuItem Caption="Paste"/>
+               </MenuItem>
+       </MenuItem>
+       <MenuItem Caption="Help">
+               <MenuItem Caption="About"/>
+               <MenuItem Caption="Help"/>
+       </MenuItem>
+</Menu>
\ No newline at end of file
diff --git a/Tests/Interfaces/TemplatedGroup/1.crow b/Tests/Interfaces/TemplatedGroup/1.crow
new file mode 100755 (executable)
index 0000000..eb857f9
--- /dev/null
@@ -0,0 +1,7 @@
+<?xml version="1.0"?>
+<MenuItem Caption="File">
+       <MenuItem Caption="New"/>
+       <MenuItem Caption="Open"/>
+       <MenuItem Caption="Save"/>
+       <MenuItem Caption="Quit"/>
+</MenuItem>
diff --git a/Tests/Interfaces/TemplatedGroup/2.crow b/Tests/Interfaces/TemplatedGroup/2.crow
new file mode 100755 (executable)
index 0000000..5e5d894
--- /dev/null
@@ -0,0 +1,25 @@
+<?xml version="1.0"?>
+<Container>
+<MenuItem Caption="Menu">
+       <MenuItem Caption="File">
+               <MenuItem Caption="New"></MenuItem>
+               <MenuItem Caption="Open"></MenuItem>
+               <MenuItem Caption="Save"></MenuItem>
+               <MenuItem Caption="Quit"></MenuItem>
+       </MenuItem>
+       <MenuItem Caption="Edit">
+               <MenuItem Caption="Cut"/>
+               <MenuItem Caption="Copy"/>
+               <MenuItem Caption="Paste"/>
+               <MenuItem Caption="Special">
+                       <MenuItem Caption="Cut"/>
+                       <MenuItem Caption="Copy"/>
+                       <MenuItem Caption="Paste"/>
+               </MenuItem>
+       </MenuItem>
+       <MenuItem Caption="Help">
+               <MenuItem Caption="About"/>
+               <MenuItem Caption="Help"/>
+       </MenuItem>
+</MenuItem>
+</Container>
\ No newline at end of file
index 566abf23a201b201c1617ca0e0f3ebbda510929b..1095bd6a233f2f52f94bd1e96182810f47358e71 100644 (file)
     <None Include="Interfaces\TemplatedGroup\0.crow">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </None>
+    <None Include="Interfaces\TemplatedGroup\1.crow">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
+    <None Include="Interfaces\TemplatedGroup\2.crow">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
   </ItemGroup>
   <ItemGroup>
     <Folder Include="Interfaces\" />
diff --git a/src/GraphicObjects/Menu.cs b/src/GraphicObjects/Menu.cs
new file mode 100644 (file)
index 0000000..561db65
--- /dev/null
@@ -0,0 +1,56 @@
+//
+//  Menu.cs
+//
+//  Author:
+//       Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
+//
+//  Copyright (c) 2016 jp
+//
+//  This program is free software: you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation, either version 3 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+using System;
+using System.Xml.Serialization;
+using System.ComponentModel;
+
+namespace Crow
+{
+       public class Menu : TemplatedGroup
+       {
+               Orientation orientation;
+
+               [XmlAttributeAttribute()][DefaultValue(Orientation.Horizontal)]
+               public virtual Orientation Orientation {
+                       get { return orientation; }
+                       set {
+                               if (orientation == value)
+                                       return;
+                               orientation = value;
+                               NotifyValueChanged ("Orientation", orientation);
+                       }
+               }
+
+               public Menu () : base()
+               {
+               }
+
+               public override void AddItem (GraphicObject g)
+               {
+                       base.AddItem (g);
+
+                       if (orientation == Orientation.Horizontal)
+                               g.NotifyValueChanged ("Orientation", Alignment.Bottom);
+                       else
+                               g.NotifyValueChanged ("Orientation", Alignment.Right);
+               }
+       }
+}
diff --git a/src/GraphicObjects/MenuItem.cs b/src/GraphicObjects/MenuItem.cs
new file mode 100644 (file)
index 0000000..591be2b
--- /dev/null
@@ -0,0 +1,71 @@
+//
+//  MenuItem.cs
+//
+//  Author:
+//       Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
+//
+//  Copyright (c) 2016 jp
+//
+//  This program is free software: you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation, either version 3 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+using System;
+using System.Xml.Serialization;
+using System.ComponentModel;
+
+namespace Crow
+{
+       public class MenuItem : TemplatedGroup
+       {
+               #region CTOR
+               public MenuItem () : base() {}
+               #endregion
+
+//             public event EventHandler Pop;
+//             public event EventHandler Unpop;
+
+               string caption;
+
+               [XmlAttributeAttribute][DefaultValue("MenuItem")]
+               public string Caption {
+                       get { return caption; }
+                       set {
+                               if (caption == value)
+                                       return;
+                               caption = value;
+                               NotifyValueChanged ("Caption", caption);
+                       }
+               }
+//             [XmlIgnore]
+//             public virtual Alignment Orientation {
+//                     get { return Parent is Menu ? (Parent as Menu).Orientation : (Parent as MenuItem); }
+//             }
+
+               Menu MenuRoot {
+                       get {
+                               ILayoutable tmp = Parent;
+                               while (tmp != null) {
+                                       if (tmp is Menu)
+                                               return tmp as Menu;
+                                       tmp = tmp.Parent;
+                               }
+                               return null;
+                       }
+               }
+
+               public override void AddItem (GraphicObject g)
+               {
+                       base.AddItem (g);
+                       g.NotifyValueChanged ("Orientation", Alignment.Right);
+               }
+       }
+}
index 12448b82a28417d3193ef59cf15b041b123e9e35..cee4adea8ea048960845aee1fc9d1dc1e2abe79a 100644 (file)
@@ -38,7 +38,7 @@ namespace Crow
 
                public virtual void AddItem(GraphicObject g){
                        items.AddChild (g);
-                       g.LogicalParent = this;
+                       //g.LogicalParent = this;
                }
                public virtual void RemoveItem(GraphicObject g)
                {
@@ -82,6 +82,19 @@ namespace Crow
                        }
                        return false;
                }
+//             public override void ClearBinding ()
+//             {
+//                     if (items != null)
+//                             items.ClearBinding ();
+//
+//                     base.ClearBinding ();
+//             }
+//             public override void ResolveBindings ()
+//             {
+//                     base.ResolveBindings ();
+//                     if (items != null)
+//                             items.ResolveBindings ();
+//             }
                #endregion
 
                #region IXmlSerialisation Overrides
index 5824e73566880644c5265902a2200dee16f4bfb8..0ca564999ee305e175c66797fe46b9459696eb7d 100644 (file)
@@ -25,7 +25,7 @@ namespace Crow
 {
        public class Style : Dictionary<string, object>
        {
-               public Dictionary<string, Style> SubStyles;
+               public Dictionary<string, Style> SubStyles;//TODO:implement substyles for all tags inside a style
                public Style () : base()
                {
                }