diff options
| author | jpbruyere <jp.bruyere@hotmail.com> | 2015-09-03 12:48:04 +0200 |
|---|---|---|
| committer | jpbruyere <jp.bruyere@hotmail.com> | 2015-09-03 12:48:04 +0200 |
| commit | 6fd66d56dd5789eae345a517dc42f3488cf7aca6 (patch) | |
| tree | d8668c1870fa1cb91edac7d3d788aeed174a4c1f /src | |
| parent | fcfe9c2189fbbb00b0901b246e401b0f05413c7f (diff) | |
* GOLib.sln:
* GOLib.csproj:
* GOLIBTest_0.cs:
* GOLIBTest_fps.cs:
* ReflexionExtensions.cs:
* Label.cs:
* test4.goml:
* GenericStack.cs:
* PrivateContainer.cs:
* CompilerServices.cs:
* Tests.csproj:
* member.svg:
* GOLIBTest_TypeViewer.cs:
* tmpMembers.goml:
* testTypeViewer.goml: Type viewer
* Group.cs:
* Window.cs:
* GraphicObject.cs: set OnLayoutChanges to public
* Point.cs: Implement length
Diffstat (limited to 'src')
| -rw-r--r-- | src/CompilerServices/CompilerServices.cs | 65 | ||||
| -rw-r--r-- | src/GraphicObjects/GenericStack.cs | 4 | ||||
| -rw-r--r-- | src/GraphicObjects/GraphicObject.cs | 2 | ||||
| -rw-r--r-- | src/GraphicObjects/Group.cs | 2 | ||||
| -rwxr-xr-x | src/GraphicObjects/Label.cs | 4 | ||||
| -rw-r--r-- | src/GraphicObjects/PrivateContainer.cs | 2 | ||||
| -rw-r--r-- | src/GraphicObjects/Window.cs | 11 | ||||
| -rwxr-xr-x | src/Point.cs | 3 | ||||
| -rw-r--r-- | src/ReflexionExtensions.cs | 56 |
9 files changed, 141 insertions, 8 deletions
diff --git a/src/CompilerServices/CompilerServices.cs b/src/CompilerServices/CompilerServices.cs index b1b08d5e..1aaeac99 100644 --- a/src/CompilerServices/CompilerServices.cs +++ b/src/CompilerServices/CompilerServices.cs @@ -4,6 +4,8 @@ using System.Reflection; using System.Collections; using System.Diagnostics; using System.Linq; +using System.Collections.Generic; +using System.Runtime.CompilerServices; namespace go @@ -37,6 +39,10 @@ namespace go } static int dynHandleCpt = 0; + /// <summary> + /// Compile events expression in GOML attributes + /// </summary> + /// <param name="es">Event binding details</param> public static void CompileEventSource(DynAttribute es) { Type srcType = es.Source.GetType (); @@ -154,6 +160,11 @@ namespace go evtFi.SetValue(es.Source, del); } + /// <summary> + /// Resolves GOML property bindings afler loading + /// </summary> + /// <param name="binding">Binding details</param> + /// <param name="_source">Data source for binding</param> public static void ResolveBinding(DynAttribute binding, object _source) { object srcGO = null; @@ -185,14 +196,28 @@ namespace go throw new Exception ("Syntax error in binding, expected 'go dot member'"); } + if (srcGO == null) { + Debug.WriteLine ("Invalid Binding Source: " + binding.Value); + return; + } Type srcType = srcGO.GetType (); Type dstType = binding.Source.GetType (); MemberInfo miSrc = srcType.GetMember (statement).FirstOrDefault (); MemberInfo miDst = dstType.GetMember (binding.MemberName).FirstOrDefault (); + object srcVal = null; //value in source member + + #region search for extensions methods if member not found in type + if (miSrc == null && !string.IsNullOrEmpty(statement)) + { + Assembly a = Assembly.GetExecutingAssembly(); + miSrc = CompilerServices.GetExtensionMethods(a, srcType).FirstOrDefault(); + } + #endregion + #region initialize target with actual value - object srcVal = null; + if (miSrc == null) srcVal = srcGO;//if no member is provided for binding, source raw value is taken else { @@ -200,7 +225,13 @@ namespace go srcVal = (miSrc as PropertyInfo).GetGetMethod ().Invoke (srcGO, null); else if (miSrc.MemberType == MemberTypes.Field) srcVal = (miSrc as FieldInfo).GetValue (srcGO); - else + else if (miSrc.MemberType == MemberTypes.Method){ + MethodInfo mthSrc = miSrc as MethodInfo; + if (mthSrc.IsDefined(typeof(ExtensionAttribute), false)) + srcVal = mthSrc.Invoke(null, new object[] {srcGO}); + else + srcVal = mthSrc.Invoke(srcGO, null); + }else throw new Exception ("unandled source member type for binding"); } if (miDst.MemberType == MemberTypes.Property) { @@ -363,6 +394,36 @@ namespace go } while(fi == null); return fi; } + + /// <summary> + /// Gets extension methods defined in assembley for extendedType + /// </summary> + /// <returns>Extension methods enumerable</returns> + /// <param name="assembly">Assembly</param> + /// <param name="extendedType">Extended type to search for</param> + public static IEnumerable<MethodInfo> GetExtensionMethods(Assembly assembly, + Type extendedType) + { + IEnumerable<MethodInfo> query = null; + Type curType = extendedType; + + do { + query = from type in assembly.GetTypes () + where type.IsSealed && !type.IsGenericType && !type.IsNested + from method in type.GetMethods (BindingFlags.Static + | BindingFlags.Public | BindingFlags.NonPublic) + where method.IsDefined (typeof(ExtensionAttribute), false) + where method.GetParameters () [0].ParameterType == curType + select method; + + if (query.Count() > 0) + break; + + curType = curType.BaseType; + } while (curType != null); + + return query; + } } } diff --git a/src/GraphicObjects/GenericStack.cs b/src/GraphicObjects/GenericStack.cs index 3b96d548..20130576 100644 --- a/src/GraphicObjects/GenericStack.cs +++ b/src/GraphicObjects/GenericStack.cs @@ -125,13 +125,13 @@ namespace go else if (gobjs.Length == 1) {
int sz = Children.Where(ch=>ch.Visible).Except (gobjs).Sum (g => g.Slot.Width);
if (sz < Slot.Width) {
- gobjs [0].Slot.Width = Slot.Width - sz - Spacing;
+ gobjs [0].Slot.Width = Slot.Width - sz - (Children.Count+1) * Spacing;
int idx = Children.IndexOf (gobjs [0]);
if (idx > 0 && idx < Children.Count - 1)
gobjs [0].Slot.Width -= Spacing;
-
if (gobjs [0].LastSlots.Width != gobjs [0].Slot.Width) {
gobjs [0].bmp = null;
+ //gobjs [0].OnLayoutChanges (LayoutingType.Width);
gobjs [0].LastSlots.Width = gobjs [0].Slot.Width;
}
}
diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index 457a6016..e1e2963b 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -456,7 +456,7 @@ namespace go }
/// <summary> trigger dependant sizing component update </summary>
- protected virtual void OnLayoutChanges(LayoutingType layoutType)
+ public virtual void OnLayoutChanges(LayoutingType layoutType)
{
if (Parent==null)
return;
diff --git a/src/GraphicObjects/Group.cs b/src/GraphicObjects/Group.cs index aac566db..e7a4b2b6 100644 --- a/src/GraphicObjects/Group.cs +++ b/src/GraphicObjects/Group.cs @@ -120,7 +120,7 @@ namespace go return tmp;
}
- protected override void OnLayoutChanges (LayoutingType layoutType)
+ public override void OnLayoutChanges (LayoutingType layoutType)
{
base.OnLayoutChanges (layoutType);
diff --git a/src/GraphicObjects/Label.cs b/src/GraphicObjects/Label.cs index e9951862..c0bfe47e 100755 --- a/src/GraphicObjects/Label.cs +++ b/src/GraphicObjects/Label.cs @@ -202,7 +202,9 @@ namespace go lines [selectionEnd.Y].Substring (selectionEnd.X, lines [selectionEnd.Y].Length - selectionEnd.X);
l++;
for (int c = 0; c < linesToRemove-1; c++)
- lines.RemoveAt (l);
+ lines.RemoveAt (l);
+ currentCol = selectionStart.X;
+ currentLine = selectionStart.Y;
} else
lines [l] = lines [l].Remove (selectionStart.X, selectionEnd.X - selectionStart.X);
currentCol = selectionStart.X;
diff --git a/src/GraphicObjects/PrivateContainer.cs b/src/GraphicObjects/PrivateContainer.cs index cd234d62..025934f9 100644 --- a/src/GraphicObjects/PrivateContainer.cs +++ b/src/GraphicObjects/PrivateContainer.cs @@ -92,7 +92,7 @@ namespace go return child == null ? Bounds.Size : new Size(child.Slot.Width + 2 * Margin, child.Slot.Height + 2 * (Margin)); } - protected override void OnLayoutChanges (LayoutingType layoutType) + public override void OnLayoutChanges (LayoutingType layoutType) { switch (layoutType) { case LayoutingType.Width: diff --git a/src/GraphicObjects/Window.cs b/src/GraphicObjects/Window.cs index 7eb910cc..0fd2b780 100644 --- a/src/GraphicObjects/Window.cs +++ b/src/GraphicObjects/Window.cs @@ -36,8 +36,19 @@ namespace go void Window_MouseMove (object sender, OpenTK.Input.MouseMoveEventArgs e) { + +// if ((e.Position - this.Slot.TopLeft).Length < 3) +// System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.SizeNWSE; +// else +// System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default; + if (!e.Mouse.IsButtonDown (MouseButton.Left)) return; + + // + + System.Windows.Forms.Cursor.Show();// = System.Windows.Forms.Cursors.SizeAll; + this.TopContainer.redrawClip.AddRectangle (this.ScreenCoordinates(this.Slot)); this.Left += e.XDelta; this.Top += e.YDelta; diff --git a/src/Point.cs b/src/Point.cs index db06a05b..58305f00 100755 --- a/src/Point.cs +++ b/src/Point.cs @@ -26,6 +26,9 @@ namespace go _y = y;
}
+ public int Length {
+ get { return (int)Math.Sqrt (Math.Pow (_x, 2) + Math.Pow (_y, 2)); }
+ }
public static implicit operator Cairo.Point(Point p)
{
return new Cairo.Point(p.X, p.Y);
diff --git a/src/ReflexionExtensions.cs b/src/ReflexionExtensions.cs new file mode 100644 index 00000000..fc16c9d4 --- /dev/null +++ b/src/ReflexionExtensions.cs @@ -0,0 +1,56 @@ +// +// ReflexionExtensions.cs +// +// Author: +// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> +// +// Copyright (c) 2015 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.Reflection; + +namespace go +{ + public static class ReflexionExtensions + { + public static string GetIcon(this MemberInfo mi) + { + switch (mi.MemberType) { + case MemberTypes.Constructor: + return "ctor"; + case MemberTypes.Event: + return "event"; + case MemberTypes.Field: + return "field"; + case MemberTypes.Method: + return "method"; + case MemberTypes.Property: + return "property"; + case MemberTypes.TypeInfo: + break; + case MemberTypes.Custom: + break; + case MemberTypes.NestedType: + break; + case MemberTypes.All: + break; + default: + return "pubfld"; + } + return "notset"; + } + } +} + |