From 6c5120d8108af9ed53e7205d221cf96a281a28a4 Mon Sep 17 00:00:00 2001 From: jpbruyere Date: Mon, 15 Aug 2016 01:49:35 +0200 Subject: [PATCH] CurrentInterface in GraphicObject base --- Crow.csproj | 1 + Templates/DirectoryView.template | 2 +- Templates/Window.template | 4 +- Templates/treeList.crow | 3 ++ Tests/BasicTests.cs | 4 +- Tests/Interfaces/basicTests/0.crow | 7 +-- src/CompilerServices/CompilerServices.cs | 8 ++- src/GraphicObjects/Border.cs | 2 +- src/GraphicObjects/FileDialog.cs | 2 +- src/GraphicObjects/GenericStack.cs | 2 +- src/GraphicObjects/GraphicObject.cs | 62 ++++++++++-------------- src/GraphicObjects/Grid.cs | 2 +- src/GraphicObjects/Group.cs | 4 +- src/GraphicObjects/Label.cs | 4 +- src/GraphicObjects/ListBox.cs | 8 +-- src/GraphicObjects/Popper.cs | 10 ++-- src/GraphicObjects/Splitter.cs | 6 +-- src/GraphicObjects/TabView.cs | 6 +-- src/GraphicObjects/TemplatedControl.cs | 12 ++--- src/GraphicObjects/TextBox.cs | 6 +-- src/GraphicObjects/Window.cs | 10 ++-- src/GraphicObjects/Wrapper.cs | 2 +- src/IMLReader.cs | 13 +++-- src/Instantiator.cs | 10 ++-- src/Interface.cs | 19 +++----- src/ItemTemplate.cs | 2 +- src/LayoutingQueueItem.cs | 4 +- 27 files changed, 105 insertions(+), 110 deletions(-) create mode 100755 Templates/treeList.crow diff --git a/Crow.csproj b/Crow.csproj index cf48acaa..05d5dbd9 100644 --- a/Crow.csproj +++ b/Crow.csproj @@ -264,6 +264,7 @@ Crow.Window.template + diff --git a/Templates/DirectoryView.template b/Templates/DirectoryView.template index e861ef8e..13f10f11 100755 --- a/Templates/DirectoryView.template +++ b/Templates/DirectoryView.template @@ -32,7 +32,7 @@ + Template="#Crow.Templates.treeList.crow" /> diff --git a/Templates/Window.template b/Templates/Window.template index 1ca344d6..481c030b 100755 --- a/Templates/Window.template +++ b/Templates/Window.template @@ -1,8 +1,8 @@ - - + + \ No newline at end of file diff --git a/Tests/BasicTests.cs b/Tests/BasicTests.cs index 970480f2..1114cdf3 100644 --- a/Tests/BasicTests.cs +++ b/Tests/BasicTests.cs @@ -157,7 +157,7 @@ namespace Tests Instantiator i = new Instantiator(fi.FullName); lock (CrowInterface.UpdateMutex) { (CrowInterface.FindByName ("crowContainer") as Container).SetChild - (i.CreateInstance()); + (i.CreateInstance(CrowInterface)); CurSources = i.GetImlSourcesCode(); } } @@ -172,7 +172,7 @@ namespace Tests } lock (CrowInterface.UpdateMutex) { (CrowInterface.FindByName ("crowContainer") as Container).SetChild - (i.CreateInstance()); + (i.CreateInstance(CrowInterface)); } } void onButClick(object send, MouseButtonEventArgs e) diff --git a/Tests/Interfaces/basicTests/0.crow b/Tests/Interfaces/basicTests/0.crow index c41c1317..42930b0a 100755 --- a/Tests/Interfaces/basicTests/0.crow +++ b/Tests/Interfaces/basicTests/0.crow @@ -1,7 +1,8 @@ - - + + \ No newline at end of file diff --git a/src/CompilerServices/CompilerServices.cs b/src/CompilerServices/CompilerServices.cs index d06cd29b..79d3745d 100644 --- a/src/CompilerServices/CompilerServices.cs +++ b/src/CompilerServices/CompilerServices.cs @@ -13,8 +13,14 @@ namespace Crow public static class CompilerServices { static MethodInfo miAddBinding = typeof(GraphicObject).GetMethod ("BindMember"); + static FieldInfo miSetCurIface = typeof(GraphicObject). + GetField ("CurrentInterface", BindingFlags.NonPublic | BindingFlags.Instance); - + public static void emitSetCurInterface(ILGenerator il){ + il.Emit (OpCodes.Ldloc_0); + il.Emit (OpCodes.Ldarg_1); + il.Emit (OpCodes.Stfld, miSetCurIface); + } public static void emitBindingCreation(ILGenerator il, string memberName, string expression){ il.Emit (OpCodes.Ldloc_0); il.Emit (OpCodes.Ldstr, memberName); diff --git a/src/GraphicObjects/Border.cs b/src/GraphicObjects/Border.cs index a6e5432b..c91001b7 100644 --- a/src/GraphicObjects/Border.cs +++ b/src/GraphicObjects/Border.cs @@ -60,7 +60,7 @@ namespace Crow gr.Save (); if (ClipToClientRect) { //clip to client zone - CairoHelpers.CairoRectangle (gr, ClientRectangle, CornerRadius); + CairoHelpers.CairoRectangle (gr, ClientRectangle,Math.Max(0.0, CornerRadius-Margin)); gr.Clip (); } diff --git a/src/GraphicObjects/FileDialog.cs b/src/GraphicObjects/FileDialog.cs index da85580a..16a60a4f 100644 --- a/src/GraphicObjects/FileDialog.cs +++ b/src/GraphicObjects/FileDialog.cs @@ -48,7 +48,7 @@ namespace Crow public FileDialog () { currentDir = new DirectoryInfo (Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)); - window = Interface.Load("#Crow.Templates.FileDialog.goml") as Window; + //window = Interface..Load("#Crow.Templates.FileDialog.goml") as Window; window.DataSource = this; } #endregion diff --git a/src/GraphicObjects/GenericStack.cs b/src/GraphicObjects/GenericStack.cs index fcc90e98..840e883f 100644 --- a/src/GraphicObjects/GenericStack.cs +++ b/src/GraphicObjects/GenericStack.cs @@ -100,7 +100,7 @@ namespace Crow //if no layouting remains in queue for item, registre for redraw if (RegisteredLayoutings == LayoutingType.None && bmp == null) - Interface.CurrentInterface.EnqueueForRepaint (this); + CurrentInterface.EnqueueForRepaint (this); return true; } diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index d5c92011..bd96b76c 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -42,14 +42,14 @@ namespace Crow uid = currentUid; currentUid++; - if (Interface.CurrentInterface.XmlLoading) - return; - loadDefaultValues (); +// if (CurrentInterface.XmlLoading) +// return; +// loadDefaultValues (); } public GraphicObject (Rectangle _bounds) { - if (!Interface.CurrentInterface.XmlLoading) - loadDefaultValues (); +// if (!CurrentInterface.XmlLoading) +// loadDefaultValues (); Left = _bounds.Left; Top = _bounds.Top; @@ -443,12 +443,9 @@ namespace Crow isVisible = value; - if (Interface.CurrentInterface == null) - return; - //ensure main win doesn't keep hidden childrens ref - if (!isVisible && this.Contains (Interface.CurrentInterface.HoverWidget)) - Interface.CurrentInterface.HoverWidget = null; + if (!isVisible && this.Contains (CurrentInterface.HoverWidget)) + CurrentInterface.HoverWidget = null; if (Parent is GraphicObject) (Parent as GraphicObject).RegisterForLayouting (LayoutingType.Sizing); @@ -457,7 +454,7 @@ namespace Crow if (isVisible) RegisterForLayouting (LayoutingType.Sizing); - Interface.CurrentInterface.EnqueueForRepaint (this); + CurrentInterface.EnqueueForRepaint (this); NotifyValueChanged ("Visible", isVisible); } @@ -722,7 +719,7 @@ namespace Crow if (Width == Measure.Fit || Height == Measure.Fit) RegisterForLayouting (LayoutingType.Sizing); else if (RegisteredLayoutings == LayoutingType.None) - Interface.CurrentInterface.EnqueueForRepaint (this); + CurrentInterface.EnqueueForRepaint (this); } /// query an update of the content, a redraw [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -730,19 +727,9 @@ namespace Crow { bmp = null; if (RegisteredLayoutings == LayoutingType.None) - Interface.CurrentInterface.EnqueueForRepaint (this); - } - // public Interface CurrentInterface { - // get { - // ILayoutable tmp = this.Parent; - // while (tmp != null) { - // if (tmp is Interface) - // return tmp as Interface; - // tmp = tmp.Parent; - // } - // return null; - // } - // } + CurrentInterface.EnqueueForRepaint (this); + } + internal Interface CurrentInterface = null; #endregion #region Layouting @@ -763,7 +750,7 @@ namespace Crow public virtual void RegisterForLayouting(LayoutingType layoutType){ if (Parent == null) return; - lock (Interface.CurrentInterface.LayoutMutex) { + lock (CurrentInterface.LayoutMutex) { //dont set position for stretched item if (Width == Measure.Stretched) layoutType &= (~LayoutingType.X); @@ -785,15 +772,15 @@ namespace Crow //enqueue LQI LayoutingTypes separately if (layoutType.HasFlag (LayoutingType.Width)) - Interface.CurrentInterface.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.Width, this)); + CurrentInterface.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.Width, this)); if (layoutType.HasFlag (LayoutingType.Height)) - Interface.CurrentInterface.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.Height, this)); + CurrentInterface.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.Height, this)); if (layoutType.HasFlag (LayoutingType.X)) - Interface.CurrentInterface.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.X, this)); + CurrentInterface.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.X, this)); if (layoutType.HasFlag (LayoutingType.Y)) - Interface.CurrentInterface.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.Y, this)); + CurrentInterface.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.Y, this)); if (layoutType.HasFlag (LayoutingType.ArrangeChildren)) - Interface.CurrentInterface.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.ArrangeChildren, this)); + CurrentInterface.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.ArrangeChildren, this)); } } @@ -963,7 +950,7 @@ namespace Crow //if no layouting remains in queue for item, registre for redraw if (this.registeredLayoutings == LayoutingType.None && bmp == null) - Interface.CurrentInterface.EnqueueForRepaint (this); + CurrentInterface.EnqueueForRepaint (this); return true; } @@ -1090,8 +1077,8 @@ namespace Crow } public virtual void checkHoverWidget(MouseMoveEventArgs e) { - if (Interface.CurrentInterface.HoverWidget != this) { - Interface.CurrentInterface.HoverWidget = this; + if (CurrentInterface.HoverWidget != this) { + CurrentInterface.HoverWidget = this; onMouseEnter (this, e); } @@ -1107,13 +1094,13 @@ namespace Crow MouseMove.Raise (sender, e); } public virtual void onMouseDown(object sender, MouseButtonEventArgs e){ - if (Interface.CurrentInterface.activeWidget == null) - Interface.CurrentInterface.activeWidget = this; + if (CurrentInterface.activeWidget == null) + CurrentInterface.activeWidget = this; if (this.Focusable && !Interface.FocusOnHover) { BubblingMouseButtonEventArg be = e as BubblingMouseButtonEventArg; if (be.Focused == null) { be.Focused = this; - Interface.CurrentInterface.FocusedWidget = this; + CurrentInterface.FocusedWidget = this; } } //bubble event to the top @@ -1464,6 +1451,7 @@ namespace Crow { Type type = this.GetType (); GraphicObject result = (GraphicObject)Activator.CreateInstance (type); + result.CurrentInterface = CurrentInterface; foreach (PropertyInfo pi in type.GetProperties(BindingFlags.Public | BindingFlags.Instance)) { if (pi.GetSetMethod () == null) diff --git a/src/GraphicObjects/Grid.cs b/src/GraphicObjects/Grid.cs index ed0cd986..a0f0cb69 100644 --- a/src/GraphicObjects/Grid.cs +++ b/src/GraphicObjects/Grid.cs @@ -135,7 +135,7 @@ namespace Crow //if no layouting remains in queue for item, registre for redraw if (RegisteredLayoutings == LayoutingType.None && bmp == null) - Interface.CurrentInterface.EnqueueForRepaint (this); + CurrentInterface.EnqueueForRepaint (this); return true; } diff --git a/src/GraphicObjects/Group.cs b/src/GraphicObjects/Group.cs index 66f2f57e..950992e2 100644 --- a/src/GraphicObjects/Group.cs +++ b/src/GraphicObjects/Group.cs @@ -292,8 +292,8 @@ namespace Crow #region Mouse handling public override void checkHoverWidget (MouseMoveEventArgs e) { - if (Interface.CurrentInterface.HoverWidget != this) { - Interface.CurrentInterface.HoverWidget = this; + if (CurrentInterface.HoverWidget != this) { + CurrentInterface.HoverWidget = this; onMouseEnter (this, e); } for (int i = Children.Count - 1; i >= 0; i--) { diff --git a/src/GraphicObjects/Label.cs b/src/GraphicObjects/Label.cs index 37a32a2f..666f00a2 100644 --- a/src/GraphicObjects/Label.cs +++ b/src/GraphicObjects/Label.cs @@ -663,12 +663,12 @@ namespace Crow { base.onMouseEnter (sender, e); if (Selectable) - Interface.CurrentInterface.MouseCursor = XCursor.Text; + CurrentInterface.MouseCursor = XCursor.Text; } public override void onMouseLeave (object sender, MouseMoveEventArgs e) { base.onMouseLeave (sender, e); - Interface.CurrentInterface.MouseCursor = XCursor.Default; + CurrentInterface.MouseCursor = XCursor.Default; } public override void onFocused (object sender, EventArgs e) { diff --git a/src/GraphicObjects/ListBox.cs b/src/GraphicObjects/ListBox.cs index 315bad87..ffbaf3e8 100644 --- a/src/GraphicObjects/ListBox.cs +++ b/src/GraphicObjects/ListBox.cs @@ -62,7 +62,7 @@ namespace Crow NotifyValueChanged ("Data", data); - lock (Interface.CurrentInterface.UpdateMutex) + lock (CurrentInterface.UpdateMutex) _list.ClearChildren (); if (_gsList.Orientation == Orientation.Horizontal) _gsList.Width = -1; @@ -167,7 +167,7 @@ namespace Crow //g.LogicalParent = this; } - lock (Interface.CurrentInterface.LayoutMutex) + lock (CurrentInterface.LayoutMutex) _list.AddChild (page); #if DEBUG_LOAD @@ -187,8 +187,8 @@ namespace Crow else iTemp = ItemTemplates ["default"]; - lock (Interface.CurrentInterface.LayoutMutex) { - g = iTemp.CreateInstance(); + lock (CurrentInterface.LayoutMutex) { + g = iTemp.CreateInstance(CurrentInterface); page.AddChild (g); g.DataSource = data [i]; } diff --git a/src/GraphicObjects/Popper.cs b/src/GraphicObjects/Popper.cs index 029a9837..8d62f002 100644 --- a/src/GraphicObjects/Popper.cs +++ b/src/GraphicObjects/Popper.cs @@ -169,7 +169,7 @@ namespace Crow //ensure popped window is cleared if (Content != null) { if (Content.Parent != null) - Interface.CurrentInterface.DeleteWidget (Content); + CurrentInterface.DeleteWidget (Content); } base.ClearBinding (); } @@ -194,21 +194,17 @@ namespace Crow public virtual void onPop(object sender, EventArgs e) { - if (Interface.CurrentInterface == null) - return; if (Content != null) { Content.Visible = true; if (Content.Parent == null) - Interface.CurrentInterface.AddWidget (Content); - Interface.CurrentInterface.PutOnTop (Content); + CurrentInterface.AddWidget (Content); + CurrentInterface.PutOnTop (Content); _content_LayoutChanged (this, new LayoutingEventArgs (LayoutingType.Sizing)); } Pop.Raise (this, e); } public virtual void onUnpop(object sender, EventArgs e) { - if (Interface.CurrentInterface == null) - return; if (Content != null) Content.Visible = false; Unpop.Raise (this, e); diff --git a/src/GraphicObjects/Splitter.cs b/src/GraphicObjects/Splitter.cs index 1a1558af..43c1ab08 100644 --- a/src/GraphicObjects/Splitter.cs +++ b/src/GraphicObjects/Splitter.cs @@ -61,14 +61,14 @@ namespace Crow { base.onMouseEnter (sender, e); if ((Parent as GenericStack).Orientation == Orientation.Horizontal) - Interface.CurrentInterface.MouseCursor = XCursor.H; + CurrentInterface.MouseCursor = XCursor.H; else - Interface.CurrentInterface.MouseCursor = XCursor.V; + CurrentInterface.MouseCursor = XCursor.V; } public override void onMouseLeave (object sender, MouseMoveEventArgs e) { base.onMouseLeave (sender, e); - Interface.CurrentInterface.MouseCursor = XCursor.Default; + CurrentInterface.MouseCursor = XCursor.Default; } public override void onMouseMove (object sender, MouseMoveEventArgs e) { diff --git a/src/GraphicObjects/TabView.cs b/src/GraphicObjects/TabView.cs index 7f87fa11..a1d1a093 100644 --- a/src/GraphicObjects/TabView.cs +++ b/src/GraphicObjects/TabView.cs @@ -143,7 +143,7 @@ namespace Crow //if no layouting remains in queue for item, registre for redraw if (RegisteredLayoutings == LayoutingType.None && bmp == null) - Interface.CurrentInterface.EnqueueForRepaint (this); + CurrentInterface.EnqueueForRepaint (this); return true; } @@ -181,8 +181,8 @@ namespace Crow #region Mouse handling public override void checkHoverWidget (MouseMoveEventArgs e) { - if (Interface.CurrentInterface.HoverWidget != this) { - Interface.CurrentInterface.HoverWidget = this; + if (CurrentInterface.HoverWidget != this) { + CurrentInterface.HoverWidget = this; onMouseEnter (this, e); } diff --git a/src/GraphicObjects/TemplatedControl.cs b/src/GraphicObjects/TemplatedControl.cs index b10d89eb..b77c89e3 100644 --- a/src/GraphicObjects/TemplatedControl.cs +++ b/src/GraphicObjects/TemplatedControl.cs @@ -36,9 +36,9 @@ namespace Crow #region CTOR public TemplatedControl () : base() { - if (Interface.CurrentInterface.XmlLoading) - return; - loadTemplate (); +// if (CurrentInterface.XmlLoading) +// return; + //loadTemplate (); } #endregion @@ -57,7 +57,7 @@ namespace Crow if (string.IsNullOrEmpty(_template)) loadTemplate (); else - loadTemplate (Interface.Load (_template)); + loadTemplate (CurrentInterface.Load (_template)); } } [XmlAttributeAttribute][DefaultValue("#Crow.Templates.ItemTemplate.goml")] @@ -100,7 +100,7 @@ namespace Crow if (template == null) { if (!Interface.DefaultTemplates.ContainsKey (this.GetType ().FullName)) throw new Exception (string.Format ("No default template found for '{0}'", this.GetType ().FullName)); - this.SetChild (Interface.Load (Interface.DefaultTemplates[this.GetType ().FullName])); + this.SetChild (CurrentInterface.Load (Interface.DefaultTemplates[this.GetType ().FullName])); }else this.SetChild (template); @@ -178,7 +178,7 @@ namespace Crow } } } else - loadTemplate (Interface.Load (template)); + loadTemplate (CurrentInterface.Load (template)); //if no template found, load default one if (this.child == null) diff --git a/src/GraphicObjects/TextBox.cs b/src/GraphicObjects/TextBox.cs index 2be9585a..44690342 100644 --- a/src/GraphicObjects/TextBox.cs +++ b/src/GraphicObjects/TextBox.cs @@ -87,7 +87,7 @@ namespace Crow if (!MoveRight ()) return; }else if (e.Shift) - Interface.CurrentInterface.Clipboard = this.SelectedText; + CurrentInterface.Clipboard = this.SelectedText; this.DeleteChar (); break; case Key.Enter: @@ -136,9 +136,9 @@ namespace Crow break; case Key.Insert: if (e.Shift) - this.Insert (Interface.CurrentInterface.Clipboard); + this.Insert (CurrentInterface.Clipboard); else if (e.Control && !selectionIsEmpty) - Interface.CurrentInterface.Clipboard = this.SelectedText; + CurrentInterface.Clipboard = this.SelectedText; break; case Key.Left: if (e.Shift) { diff --git a/src/GraphicObjects/Window.cs b/src/GraphicObjects/Window.cs index bf6bd5cf..9ef9e642 100644 --- a/src/GraphicObjects/Window.cs +++ b/src/GraphicObjects/Window.cs @@ -144,11 +144,11 @@ namespace Crow { base.onMouseMove (sender, e); - Interface otkgw = Interface.CurrentInterface; + Interface otkgw = CurrentInterface; if (!hoverBorder) { currentDirection = Direction.None; - Interface.CurrentInterface.MouseCursor = XCursor.Default; + CurrentInterface.MouseCursor = XCursor.Default; return; } @@ -314,7 +314,7 @@ namespace Crow { hoverBorder = false; currentDirection = Direction.None; - Interface.CurrentInterface.MouseCursor = XCursor.Default; + CurrentInterface.MouseCursor = XCursor.Default; } protected void onBorderMouseEnter (object sender, MouseMoveEventArgs e) { @@ -327,13 +327,13 @@ namespace Crow } protected void butQuitPress (object sender, MouseButtonEventArgs e) { - Interface.CurrentInterface.MouseCursor = XCursor.Default; + CurrentInterface.MouseCursor = XCursor.Default; close (); } void close(){ Closing.Raise (this, null); - Interface.CurrentInterface.DeleteWidget (this); + CurrentInterface.DeleteWidget (this); } } } diff --git a/src/GraphicObjects/Wrapper.cs b/src/GraphicObjects/Wrapper.cs index 68e8cab6..03251af9 100644 --- a/src/GraphicObjects/Wrapper.cs +++ b/src/GraphicObjects/Wrapper.cs @@ -181,7 +181,7 @@ namespace Crow //if no layouting remains in queue for item, registre for redraw if (RegisteredLayoutings == LayoutingType.None && bmp == null) - Interface.CurrentInterface.EnqueueForRepaint (this); + CurrentInterface.EnqueueForRepaint (this); return true; } diff --git a/src/IMLReader.cs b/src/IMLReader.cs index 78f1880a..e4f98ecb 100644 --- a/src/IMLReader.cs +++ b/src/IMLReader.cs @@ -30,7 +30,7 @@ namespace Crow { public class IMLReader : XmlTextReader { - Interface.LoaderInvoker loader = null; + InstanciatorInvoker loader = null; string ImlPath; Stream ImlStream; @@ -43,12 +43,12 @@ namespace Crow /// /// Finalize instatiator MSIL and return LoaderInvoker delegate /// - public Interface.LoaderInvoker GetLoader(){ + public InstanciatorInvoker GetLoader(){ if (loader != null) return loader; il.Emit(OpCodes.Ret); - loader = (Interface.LoaderInvoker)dm.CreateDelegate (typeof(Interface.LoaderInvoker)); + loader = (InstanciatorInvoker)dm.CreateDelegate (typeof(InstanciatorInvoker)); return loader; } @@ -92,7 +92,7 @@ namespace Crow dm = new DynamicMethod("dyn_instantiator", MethodAttributes.Family | MethodAttributes.FamANDAssem | MethodAttributes.NewSlot, CallingConventions.Standard, - typeof(void),new Type[] {typeof(object)}, RootType, true); + typeof(void),new Type[] {typeof(object), typeof(Interface)}, RootType, true); il = dm.GetILGenerator(256); il.DeclareLocal(typeof(GraphicObject)); @@ -100,6 +100,7 @@ namespace Crow //set local GraphicObject to root object passed as 1st argument il.Emit (OpCodes.Ldarg_0); il.Emit (OpCodes.Stloc_0); + CompilerServices.emitSetCurInterface (il); } void emitLoader(Type crowType){ string tmpXml = ReadOuterXml (); @@ -151,9 +152,10 @@ namespace Crow if (string.IsNullOrEmpty (templatePath)) { reader.il.Emit (OpCodes.Ldnull);//default template loading }else{ + reader.il.Emit (OpCodes.Ldarg_1);//load currentInterface reader.il.Emit (OpCodes.Ldstr, templatePath); //Load template path string reader.il.Emit (OpCodes.Callvirt,//call Interface.Load(path) - typeof(Interface).GetMethod ("Load", BindingFlags.Static | BindingFlags.Public)); + typeof(Interface).GetMethod ("Load", BindingFlags.Instance | BindingFlags.Public)); } reader.il.Emit (OpCodes.Callvirt,//load template crowType.GetMethod ("loadTemplate", BindingFlags.Instance | BindingFlags.NonPublic)); @@ -288,6 +290,7 @@ namespace Crow reader.il.Emit(OpCodes.Newobj, t.GetConstructors () [0]);//TODO:search parameterless ctor reader.il.Emit (OpCodes.Stloc_0);//child is now loc_0 + CompilerServices.emitSetCurInterface (il); reader.emitLoader(t); diff --git a/src/Instantiator.cs b/src/Instantiator.cs index fc3595f4..1a8cdb75 100644 --- a/src/Instantiator.cs +++ b/src/Instantiator.cs @@ -26,10 +26,12 @@ using System.Diagnostics; namespace Crow { + public delegate void InstanciatorInvoker(object instance, Interface iface); + public class Instantiator { public Type RootType; - Interface.LoaderInvoker loader; + InstanciatorInvoker loader; string imlPath; @@ -80,16 +82,16 @@ namespace Crow loadingTime.ElapsedTicks, loadingTime.ElapsedMilliseconds, imlPath); #endif } - public Instantiator (Type _root, Interface.LoaderInvoker _loader) + public Instantiator (Type _root, InstanciatorInvoker _loader) { RootType = _root; loader = _loader; } #endregion - public GraphicObject CreateInstance(){ + public GraphicObject CreateInstance(Interface iface){ GraphicObject tmp = (GraphicObject)Activator.CreateInstance(RootType); - loader (tmp); + loader (tmp, iface); return tmp; } public string GetImlSourcesCode(){ diff --git a/src/Interface.cs b/src/Interface.cs index 052a5a19..bc0d1f98 100644 --- a/src/Interface.cs +++ b/src/Interface.cs @@ -56,7 +56,6 @@ namespace Crow FontRenderingOptions.SubpixelOrder = SubpixelOrder.Rgb; } public Interface(){ - Interface.CurrentInterface = this; CultureInfo.DefaultThreadCurrentCulture = System.Globalization.CultureInfo.InvariantCulture; } #endregion @@ -208,10 +207,10 @@ namespace Crow xs.Serialize (s, graphicObject, xn); } } - public static GraphicObject Load (string path) + public GraphicObject Load (string path) { try { - return GetInstantiator (path).CreateInstance (); + return GetInstantiator (path).CreateInstance (this); } catch (Exception ex) { throw new Exception ("Error loading <" + path + ">:", ex); } @@ -232,7 +231,7 @@ namespace Crow public GraphicObject LoadInterface (string path) { lock (UpdateMutex) { - GraphicObject tmp = Interface.Load (path); + GraphicObject tmp = Load (path); AddWidget (tmp); return tmp; @@ -249,8 +248,6 @@ namespace Crow public List GraphicTree = new List(); - public static Interface CurrentInterface; - Rectangles _redrawClip = new Rectangles(); Context ctx; @@ -324,8 +321,6 @@ namespace Crow public void Update(){ - CurrentInterface = this; - if (mouseRepeatCount > 0) { int mc = mouseRepeatCount; mouseRepeatCount -= mc; @@ -384,9 +379,9 @@ namespace Crow #if MEASURE_TIME clippingTime.Restart (); #endif - lock (CurrentInterface.DrawingQueue) { - while (CurrentInterface.DrawingQueue.Count > 0) { - GraphicObject g = CurrentInterface.DrawingQueue.Dequeue (); + lock (DrawingQueue) { + while (DrawingQueue.Count > 0) { + GraphicObject g = DrawingQueue.Dequeue (); g.IsQueueForRedraw = false; try { if (g.Parent == null) @@ -431,7 +426,7 @@ namespace Crow #if DEBUG_CLIP_RECTANGLE clipping.stroke (ctx, Color.Red.AdjustAlpha(0.5)); #endif - lock (Interface.CurrentInterface.RenderMutex) { + lock (RenderMutex) { if (IsDirty) DirtyRect += clipping.Bounds; else diff --git a/src/ItemTemplate.cs b/src/ItemTemplate.cs index 1afefe2b..cc5d5075 100644 --- a/src/ItemTemplate.cs +++ b/src/ItemTemplate.cs @@ -39,7 +39,7 @@ namespace Crow public ItemTemplate(string path) : base(path) { } - public ItemTemplate (Type _root, Interface.LoaderInvoker _loader,string _dataType, string _fetchDataMethod) + public ItemTemplate (Type _root, InstanciatorInvoker _loader,string _dataType, string _fetchDataMethod) :base(_root, _loader) { strDataType = _dataType; diff --git a/src/LayoutingQueueItem.cs b/src/LayoutingQueueItem.cs index e33d209c..6de5be7b 100644 --- a/src/LayoutingQueueItem.cs +++ b/src/LayoutingQueueItem.cs @@ -101,12 +101,12 @@ namespace Crow if (LayoutingTries < Interface.MaxLayoutingTries) { LayoutingTries++; Layoutable.RegisteredLayoutings |= LayoutType; - Interface.CurrentInterface.LayoutingQueue.Enqueue (this); + (Layoutable as GraphicObject).CurrentInterface.LayoutingQueue.Enqueue (this); } else if (DiscardCount < Interface.MaxDiscardCount) { LayoutingTries = 0; DiscardCount++; Layoutable.RegisteredLayoutings |= LayoutType; - Interface.CurrentInterface.DiscardQueue.Enqueue (this); + (Layoutable as GraphicObject).CurrentInterface.DiscardQueue.Enqueue (this); } #if DEBUG_LAYOUTING else -- 2.47.3