From: Jean-Philippe Bruyère Date: Fri, 21 Dec 2018 04:24:46 +0000 (+0100) Subject: rename GraphicObject to Widget X-Git-Tag: v0.8.7~20 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=478959aad0df1b870304e1d64f6b284994c2feeb;p=jp%2Fcrow.git rename GraphicObject to Widget --- diff --git a/Crow/Templates/ColorPicker.template b/Crow/Templates/ColorPicker.template index 71965850..cf9dd760 100755 --- a/Crow/Templates/ColorPicker.template +++ b/Crow/Templates/ColorPicker.template @@ -1,4 +1,4 @@ - + @@ -9,7 +9,7 @@ - + - + diff --git a/Crow/Templates/DockWindow.template b/Crow/Templates/DockWindow.template index 1763b08f..e62672bc 100755 --- a/Crow/Templates/DockWindow.template +++ b/Crow/Templates/DockWindow.template @@ -1,5 +1,5 @@ - - + + - + diff --git a/Crow/Templates/FileDialog.template b/Crow/Templates/FileDialog.template index 50be2198..419e093a 100644 --- a/Crow/Templates/FileDialog.template +++ b/Crow/Templates/FileDialog.template @@ -1,4 +1,4 @@ - + - + diff --git a/Crow/Templates/FileItems.template b/Crow/Templates/FileItems.template index 452a402a..fb95e29b 100644 --- a/Crow/Templates/FileItems.template +++ b/Crow/Templates/FileItems.template @@ -1,5 +1,5 @@  - + diff --git a/Crow/Templates/GroupBox.template b/Crow/Templates/GroupBox.template index 199cfe9b..0540b552 100755 --- a/Crow/Templates/GroupBox.template +++ b/Crow/Templates/GroupBox.template @@ -1,8 +1,8 @@ - + - + diff --git a/Crow/Templates/MenuItem.template b/Crow/Templates/MenuItem.template index 4f77fb46..d3321661 100644 --- a/Crow/Templates/MenuItem.template +++ b/Crow/Templates/MenuItem.template @@ -22,5 +22,5 @@ - + diff --git a/Crow/Templates/MessageBox.template b/Crow/Templates/MessageBox.template index c68bdd71..385bf824 100644 --- a/Crow/Templates/MessageBox.template +++ b/Crow/Templates/MessageBox.template @@ -1,4 +1,4 @@ - + @@ -6,7 +6,7 @@ - + diff --git a/Crow/Templates/ToolWindow.template b/Crow/Templates/ToolWindow.template index 16f0c71a..e5c9fe74 100755 --- a/Crow/Templates/ToolWindow.template +++ b/Crow/Templates/ToolWindow.template @@ -1,4 +1,4 @@ - + --> - + diff --git a/Crow/Templates/Window.template b/Crow/Templates/Window.template index 1e66a6da..ce3cfaea 100755 --- a/Crow/Templates/Window.template +++ b/Crow/Templates/Window.template @@ -1,4 +1,4 @@ - + --> - + diff --git a/Crow/src/BubblingMouseButtonEventArgs.cs b/Crow/src/BubblingMouseButtonEventArgs.cs index e81a6f74..21f0ded6 100644 --- a/Crow/src/BubblingMouseButtonEventArgs.cs +++ b/Crow/src/BubblingMouseButtonEventArgs.cs @@ -33,7 +33,7 @@ namespace Crow /// public class BubblingMouseButtonEventArg: MouseButtonEventArgs { - public GraphicObject Focused; + public Widget Focused; public BubblingMouseButtonEventArg(MouseButtonEventArgs mbe) : base(mbe){} public BubblingMouseButtonEventArg(int x, int y, MouseButton button, bool pressed) : base (x,y,button,pressed){} diff --git a/Crow/src/CompilerServices/CompilerServices.cs b/Crow/src/CompilerServices/CompilerServices.cs index 7b95c9d7..d57cb7b5 100644 --- a/Crow/src/CompilerServices/CompilerServices.cs +++ b/Crow/src/CompilerServices/CompilerServices.cs @@ -87,14 +87,14 @@ namespace Crow.IML internal static MethodInfo miDSChangeEmitHelper = typeof(Instantiator).GetMethod("dataSourceChangedEmitHelper", BindingFlags.Instance | BindingFlags.NonPublic); internal static MethodInfo miDSReverseBinding = typeof(Instantiator).GetMethod("dataSourceReverseBinding", BindingFlags.Static | BindingFlags.NonPublic); - internal static FieldInfo miSetCurIface = typeof(GraphicObject).GetField ("IFace", BindingFlags.Public | BindingFlags.Instance); - internal static MethodInfo miFindByName = typeof (GraphicObject).GetMethod ("FindByName"); - internal static MethodInfo miGetGObjItem = typeof(List).GetMethod("get_Item", new Type[] { typeof(Int32) }); - internal static MethodInfo miLoadDefaultVals = typeof (GraphicObject).GetMethod ("loadDefaultValues"); - internal static PropertyInfo piStyle = typeof (GraphicObject).GetProperty ("Style"); - internal static MethodInfo miGetLogicalParent = typeof(GraphicObject).GetProperty("LogicalParent").GetGetMethod(); - internal static MethodInfo miGetDataSource = typeof(GraphicObject).GetProperty("DataSource").GetGetMethod (); - internal static EventInfo eiLogicalParentChanged = typeof(GraphicObject).GetEvent("LogicalParentChanged"); + internal static FieldInfo miSetCurIface = typeof(Widget).GetField ("IFace", BindingFlags.Public | BindingFlags.Instance); + internal static MethodInfo miFindByName = typeof (Widget).GetMethod ("FindByName"); + internal static MethodInfo miGetGObjItem = typeof(List).GetMethod("get_Item", new Type[] { typeof(Int32) }); + internal static MethodInfo miLoadDefaultVals = typeof (Widget).GetMethod ("loadDefaultValues"); + internal static PropertyInfo piStyle = typeof (Widget).GetProperty ("Style"); + internal static MethodInfo miGetLogicalParent = typeof(Widget).GetProperty("LogicalParent").GetGetMethod(); + internal static MethodInfo miGetDataSource = typeof(Widget).GetProperty("DataSource").GetGetMethod (); + internal static EventInfo eiLogicalParentChanged = typeof(Widget).GetEvent("LogicalParentChanged"); internal static MethodInfo miIFaceLoad = typeof(Interface).GetMethod ("CreateInstance", BindingFlags.Instance | BindingFlags.Public); internal static MethodInfo miIFaceCreateTemplateInst = typeof (Interface).GetMethod ("CreateTemplateInstance", BindingFlags.Instance | BindingFlags.Public); @@ -133,7 +133,7 @@ namespace Crow.IML internal static FieldInfo fiVCMbName = typeof (ValueChangeEventArgs).GetField ("MemberName"); internal static MethodInfo miValueChangeAdd = eiValueChange.GetAddMethod (); - internal static EventInfo eiDSChange = typeof (GraphicObject).GetEvent ("DataSourceChanged"); + internal static EventInfo eiDSChange = typeof (Widget).GetEvent ("DataSourceChanged"); internal static MethodInfo miInvokeDSChange = eiDSChange.EventHandlerType.GetMethod ("Invoke"); internal static Type [] argsBoundDSChange = {typeof (object), typeof (object), miInvokeDSChange.GetParameters () [1].ParameterType }; internal static FieldInfo fiDSCNewDS = typeof (DataSourceChangeEventArgs).GetField ("NewDataSource"); @@ -806,7 +806,7 @@ namespace Crow.IML //if left operand is member of current node, it's easy to fetch type, else we should use reflexion in msil if (lopPI == null){//accept GraphicObj members, but it's restricive //TODO: we should get the parse method by reflexion, or something else - lopPI = typeof(GraphicObject).GetProperty (lop.Tokens [lop.Tokens.Length-1]); + lopPI = typeof(Widget).GetProperty (lop.Tokens [lop.Tokens.Length-1]); if (lopPI == null) throw new NotSupportedException (); } diff --git a/Crow/src/CrowThread.cs b/Crow/src/CrowThread.cs index a1b4c38e..5c5ceef0 100644 --- a/Crow/src/CrowThread.cs +++ b/Crow/src/CrowThread.cs @@ -36,8 +36,8 @@ namespace Crow public bool cancelRequested = false; Thread thread; public event EventHandler Finished; - public GraphicObject Host; - public CrowThread (GraphicObject host, ThreadStart start){ + public Widget Host; + public CrowThread (Widget host, ThreadStart start){ thread = new Thread (start); thread.IsBackground = true; Host = host; diff --git a/Crow/src/DragDropEventArgs.cs b/Crow/src/DragDropEventArgs.cs index 428a7363..b79c3669 100644 --- a/Crow/src/DragDropEventArgs.cs +++ b/Crow/src/DragDropEventArgs.cs @@ -33,14 +33,14 @@ namespace Crow /// /// Source of the drag and drop operation /// - public GraphicObject DragSource; + public Widget DragSource; /// /// Target of the drag and drop operation /// - public GraphicObject DropTarget; + public Widget DropTarget; //public DragDropEventArgs (GraphicObject source, GraphicObject target = null) : base() - public DragDropEventArgs (GraphicObject source = null, GraphicObject target = null) : base() + public DragDropEventArgs (Widget source = null, Widget target = null) : base() { DragSource = source; DropTarget = target; diff --git a/Crow/src/DynAttribute.cs b/Crow/src/DynAttribute.cs index 174eec2e..aa9b5ce2 100644 --- a/Crow/src/DynAttribute.cs +++ b/Crow/src/DynAttribute.cs @@ -33,7 +33,7 @@ namespace Crow { public class DynAttribute { - public GraphicObject Source; + public Widget Source; public string MemberName; public String Value; } diff --git a/Crow/src/Font.cs b/Crow/src/Font.cs index 4314222b..16353d70 100644 --- a/Crow/src/Font.cs +++ b/Crow/src/Font.cs @@ -64,12 +64,11 @@ namespace Crow public FontSlant Slant { get{ switch (Style) { - case FontStyle.Normal: - default: - return FontSlant.Normal; case FontStyle.Italic: return FontSlant.Italic; - } + default: + return FontSlant.Normal; + } } } public FontWeight Wheight { @@ -77,8 +76,6 @@ namespace Crow switch (Style) { case FontStyle.Bold: return FontWeight.Bold; - case FontStyle.Italic: - case FontStyle.Normal: default: return FontWeight.Normal; } @@ -114,10 +111,8 @@ namespace Crow public override string ToString() { - if (_style == FontStyle.Normal) - return string.Format("{0},{1}", _name, _size); - else - return string.Format("{0} {1},{2}", _name, _style, _size); + + return (_style == FontStyle.Normal) ? $"{_name},{_size}" : $"{_name} {_style},{_size}"; } diff --git a/Crow/src/GraphicObjects/ColorSelector.cs b/Crow/src/GraphicObjects/ColorSelector.cs index ee57a262..7ef037e9 100644 --- a/Crow/src/GraphicObjects/ColorSelector.cs +++ b/Crow/src/GraphicObjects/ColorSelector.cs @@ -34,7 +34,7 @@ namespace Crow /// simple squarred rgb color selector /// [DesignIgnore] - public class ColorSelector : GraphicObject + public class ColorSelector : Widget { #region CTOR protected ColorSelector() : base(){} diff --git a/Crow/src/GraphicObjects/Container.cs b/Crow/src/GraphicObjects/Container.cs index 364bad83..8bff8100 100644 --- a/Crow/src/GraphicObjects/Container.cs +++ b/Crow/src/GraphicObjects/Container.cs @@ -55,7 +55,7 @@ namespace Crow public Container (Interface iface) : base(iface){} #endregion - [XmlIgnore]public GraphicObject Child { + [XmlIgnore]public Widget Child { get { return child; } set { base.SetChild(value); } } @@ -63,7 +63,7 @@ namespace Crow /// override this to handle specific steps in child addition in derived class, /// and don't forget to call the base.SetChild /// - public virtual void SetChild(GraphicObject _child) + public virtual void SetChild(Widget _child) { base.SetChild (_child); } diff --git a/Crow/src/GraphicObjects/DockStack.cs b/Crow/src/GraphicObjects/DockStack.cs index c91b9901..a52c7f6e 100644 --- a/Crow/src/GraphicObjects/DockStack.cs +++ b/Crow/src/GraphicObjects/DockStack.cs @@ -46,7 +46,7 @@ namespace Crow base.onInitialized (sender, e); Background = Color.ColorDic.Values.ToList()[color++]; }*/ - public override void AddChild (GraphicObject g) + public override void AddChild (Widget g) { base.AddChild (g); if (localLogicalParentIsNull) @@ -54,7 +54,7 @@ namespace Crow else g.LogicalParent = this.LogicalParent; } - public override void InsertChild (int idx, GraphicObject g) + public override void InsertChild (int idx, Widget g) { base.InsertChild (idx, g); g.LogicalParent = this.LogicalParent; @@ -94,14 +94,14 @@ namespace Crow Rectangle rIn = default(Rectangle); double dockThresh = 0.2; - GraphicObject focusedChild; - internal GraphicObject stretchedChild; + Widget focusedChild; + internal Widget stretchedChild; void getFocusedChild (Point lm) { Rectangle cb = ClientRectangle; childrenRWLock.EnterReadLock (); - foreach (GraphicObject c in Children) { + foreach (Widget c in Children) { Rectangle bounds = c.Slot + cb.Position; if (!bounds.ContainsOrIsEqual (lm)) continue; @@ -207,7 +207,7 @@ namespace Crow childrenRWLock.EnterReadLock (); - foreach (GraphicObject g in Children) + foreach (Widget g in Children) g.Paint (ref gr); childrenRWLock.ExitReadLock (); @@ -349,7 +349,7 @@ namespace Crow return; } //remove level and move remaining obj to level above - GraphicObject g = Children [0]; + Widget g = Children [0]; RemoveChild (g); idx = dsp.Children.IndexOf (this); dsp.RemoveChild (this); diff --git a/Crow/src/GraphicObjects/GenericStack.cs b/Crow/src/GraphicObjects/GenericStack.cs index 50c66c3e..51897487 100644 --- a/Crow/src/GraphicObjects/GenericStack.cs +++ b/Crow/src/GraphicObjects/GenericStack.cs @@ -93,14 +93,14 @@ namespace Crow { int d = 0; if (Orientation == Orientation.Horizontal) { - foreach (GraphicObject c in Children) { + foreach (Widget c in Children) { if (!c.Visible) continue; c.Slot.X = d; d += c.Slot.Width + Spacing; } } else { - foreach (GraphicObject c in Children) { + foreach (Widget c in Children) { if (!c.Visible) continue; c.Slot.Y = d; @@ -109,7 +109,7 @@ namespace Crow } IsDirty = true; } - GraphicObject stretchedGO = null; + Widget stretchedGO = null; public override bool UpdateLayout (LayoutingType layoutType) { RegisteredLayoutings &= (~layoutType); @@ -173,7 +173,7 @@ namespace Crow public override void OnChildLayoutChanges (object sender, LayoutingEventArgs arg) { - GraphicObject go = sender as GraphicObject; + Widget go = sender as Widget; //Debug.WriteLine ("child layout change: " + go.LastSlots.ToString() + " => " + go.Slot.ToString()); switch (arg.LayoutType) { case LayoutingType.Width: @@ -225,7 +225,7 @@ namespace Crow } #endregion - public override void RemoveChild (GraphicObject child) + public override void RemoveChild (Widget child) { if (child != stretchedGO) { if (Orientation == Orientation.Horizontal) diff --git a/Crow/src/GraphicObjects/GraphicObject.cs b/Crow/src/GraphicObjects/GraphicObject.cs deleted file mode 100644 index aa200802..00000000 --- a/Crow/src/GraphicObjects/GraphicObject.cs +++ /dev/null @@ -1,2010 +0,0 @@ -// -// GraphicObject.cs -// -// Author: -// Jean-Philippe Bruyère -// -// Copyright (c) 2013-2017 Jean-Philippe Bruyère -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Xml.Serialization; -using System.Reflection; -using System.Reflection.Emit; -using System.Runtime.CompilerServices; -using Cairo; -using System.Diagnostics; -using Crow.IML; -using System.Threading; - - -#if DESIGN_MODE -using System.Xml; -using System.IO; -#endif - -namespace Crow -{ - /// - /// The base class for all the graphic tree elements. - /// - public class GraphicObject : ILayoutable, IValueChange, IDisposable - { - internal ReaderWriterLockSlim parentRWLock = new ReaderWriterLockSlim(); - #if DEBUG_LOG - //0 is the main graphic tree, for other obj tree not added to main tree, it range from 1->n - //useful to track events for obj shown later, not on start, or never added to main tree - public int treeIndex; - public int yIndex;//absolute index in the graphic tree for debug draw - public int xLevel;//x increment for debug draw - #endif - #if DESIGN_MODE - static MethodInfo miDesignAddDefLoc = typeof(GraphicObject).GetMethod("design_add_style_location", - BindingFlags.Instance | BindingFlags.NonPublic); - static MethodInfo miDesignAddValLoc = typeof(GraphicObject).GetMethod("design_add_iml_location", - BindingFlags.Instance | BindingFlags.NonPublic); - - public volatile bool design_HasChanged = false; - public string design_id; - public int design_line; - public int design_column; - public string design_imlPath; - public bool design_isTGItem = false;//true if this is a templated item's root - public Dictionary design_iml_values = new Dictionary(); - public Dictionary design_style_values = new Dictionary(); - //public Dictionary design_iml_locations = new Dictionary(); - public Dictionary design_style_locations = new Dictionary(); - - internal void design_add_style_location (string memberName, string path, int line, int col) { - if (design_style_locations.ContainsKey(memberName)){ - Console.WriteLine ("default value localtion already set for {0}{1}.{2}", this.GetType().Name, this.design_id, memberName); - return; - } - design_style_locations.Add(memberName, new FileLocation(path,line,col)); - } -// internal void design_add_iml_location (string memberName, string path, int line, int col) { -// if (design_iml_locations.ContainsKey(memberName)){ -// Console.WriteLine ("IML value localtion already set for {0}{1}.{2}", this.GetType().Name, this.design_id, memberName); -// return; -// } -// design_iml_locations.Add(memberName, new FileLocation(path,line,col)); -// } - - public virtual bool FindByDesignID(string designID, out GraphicObject go){ - go = null; - if (this.design_id == designID){ - go = this; - return true; - } - return false; - } - - public string GetIML(){ - XmlDocument doc = new XmlDocument( ); - - using (StringWriter sw = new StringWriter ()) { - XmlWriterSettings settings = new XmlWriterSettings { - Indent = true, - IndentChars = "\t", - }; - using (XmlWriter xtw = XmlWriter.Create (sw, settings)) { - //(1) the xml declaration is recommended, but not mandatory - XmlDeclaration xmlDeclaration = doc.CreateXmlDeclaration ("1.0", "UTF-8", null); - doc.InsertBefore (xmlDeclaration, null); - getIML (doc, (XmlNode)doc); - doc.WriteTo (xtw); - } - this.design_HasChanged = false; - return sw.ToString (); - } - } - - public virtual void getIML(XmlDocument doc, XmlNode parentElem) { - if (this.design_isTGItem) - return; - - XmlElement xe = doc.CreateElement(this.GetType().Name); - - foreach (KeyValuePair kv in design_iml_values) { - XmlAttribute xa = doc.CreateAttribute (kv.Key); - xa.Value = kv.Value; - xe.Attributes.Append (xa); - } - - parentElem.AppendChild (xe); - } - public Surface CreateIcon (int dragIconSize = 32) { - ImageSurface di = new ImageSurface (Format.Argb32, dragIconSize, dragIconSize); - using (Context ctx = new Context (di)) { - double div = Math.Max (LastPaintedSlot.Width, LastPaintedSlot.Height); - double s = (double)dragIconSize / div; - ctx.Scale (s, s); - if (bmp == null) - this.onDraw (ctx); - else { - if (LastPaintedSlot.Width>LastPaintedSlot.Height) - ctx.SetSourceSurface (bmp, 0, (LastPaintedSlot.Width-LastPaintedSlot.Height)/2); - else - ctx.SetSourceSurface (bmp, (LastPaintedSlot.Height-LastPaintedSlot.Width)/2, 0); - ctx.Paint (); - } - } - return di; - } - public string DesignName { - get { return GetType ().Name + design_id; } - } - #endif - - #region IDisposable implementation - protected bool disposed = false; - - public void Dispose(){ - Dispose(true); - GC.SuppressFinalize(this); - } - ~GraphicObject(){ - Debug.WriteLine(this.ToString() + " not disposed by user"); - Dispose(false); - } - protected virtual void Dispose(bool disposing){ - if (disposed){ - #if DEBUG_DISPOSE - Debug.WriteLine ("Trying to dispose already disposed obj: {0}", this.ToString()); - #endif - return; - } - - if (disposing) { - #if DEBUG_DISPOSE - Debug.WriteLine ("Disposing: {0}", this.ToString()); - if (IsQueueForRedraw) - throw new Exception("Trying to dispose an object queued for Redraw: " + this.ToString()); - #endif - - unshownPostActions (); - - if (!localDataSourceIsNull) - DataSource = null; - - parentRWLock.EnterWriteLock(); - parent = null; - parentRWLock.ExitWriteLock(); - } else - Debug.WriteLine ("!!! Finalized by GC: {0}", this.ToString ()); - Clipping?.Dispose (); - bmp?.Dispose (); - disposed = true; - } - #endregion - - #if DEBUG_LOG - internal static List GraphicObjects = new List(); - #endif - - internal bool isPopup = false; - public GraphicObject focusParent { - get { return (isPopup ? LogicalParent : parent) as GraphicObject; } - } - - /// - /// interface this widget is bound to, this should not be changed once the instance is created - /// - public Interface IFace = null; - - /// - /// contains the dirty rectangles in the coordinate system of the cache. those dirty zones - /// are repeated at each cached levels of the tree with correspondig coordinate system. This is done - /// in a dedicated step of the update between layouting and drawing. - /// - public Region Clipping; - - #region IValueChange implementation - /// - /// Raise to notify that the value of a property has changed, the binding system - /// rely mainly on this event. the member name may not be present in the class, this is - /// used in **propertyless** bindings, this allow to raise custom named events without needing - /// to create an new one in the class or a new property. - /// - public event EventHandler ValueChanged; - /// - /// Helper function to raise the value changed event - /// - public virtual void NotifyValueChanged(string MemberName, object _value) - { - //Debug.WriteLine ("Value changed: {0}->{1} = {2}", this, MemberName, _value); - ValueChanged.Raise(this, new ValueChangeEventArgs(MemberName, _value)); - } - #endregion - - #region CTOR - /// - /// default private parameter less constructor use in instantiators, it should not be used - /// when creating widget from code because widgets has to be bound to an interface before any other - /// action. - /// - protected GraphicObject () { - Clipping = new Region (); - #if DEBUG_LOG - GraphicObjects.Add (this); - DebugLog.AddEvent(DbgEvtType.GOClassCreation, this); - #endif - } - /// - /// This constructor **must** be used when creating widget from code. - /// - /// When creating new widgets derived from GraphicObject, both parameterless and this constructors are - /// facultatives, the compiler will create the parameterless one automaticaly if no other one exists. - /// But if you intend to be able to create instances of the new widget in code and override the constructor - /// with the Interface parameter, you **must** also provide the override of the parameterless constructor because - /// compiler will not create it automatically because of the presence of the other one. - /// - /// Iface. - public GraphicObject (Interface iface) : this() - { - IFace = iface; - Initialize (); - } - #endregion - //internal bool initialized = false; - /// - /// Initialize this Graphic object instance by setting style and default values and loading template if required - /// - public virtual void Initialize(){ - loadDefaultValues (); - } - #region private fields - LayoutingType registeredLayoutings = LayoutingType.All; - ILayoutable logicalParent; - ILayoutable parent; - string name; - Fill background = Color.Transparent; - Fill foreground = Color.White; - Font font = "sans, 10"; - protected Measure width, height; - int left, top; - double cornerRadius = 0; - int margin = 0; - bool focusable = false; - bool hasFocus = false; - bool isActive = false; - //bool isHover = false; - bool mouseRepeat; - protected bool isVisible = true; - bool isEnabled = true; - VerticalAlignment verticalAlignment = VerticalAlignment.Center; - HorizontalAlignment horizontalAlignment = HorizontalAlignment.Center; - Size maximumSize = "0,0"; - Size minimumSize = "0,0"; - bool cacheEnabled = false; - bool clipToClientRect = true; - Type dataSourceType; - protected object dataSource; - bool rootDataLevel; - string style; - object tag; - bool isDragged; - bool allowDrag; - bool allowDrop; - string tooltip; - IList contextCommands; - #endregion - - #region public fields - /// - /// Current size and position computed during layouting pass - /// - public Rectangle Slot = new Rectangle (); - /// - /// keep last slot components for each layouting pass to track - /// changes and trigger update of other component accordingly - /// - public Rectangle LastSlots; - /// - /// keep last slot painted on screen to clear traces if moved or resized - /// version to clear effective oldslot if parents have been moved or resized. - /// IDEA is to add a ScreenCoordinates function that use only lastPaintedSlots - /// - //TODO: we should ensure the whole parsed widget tree is the last painted - public Rectangle LastPaintedSlot; - /// Prevent requeuing multiple times the same widget - public bool IsQueueForClipping = false; - /// drawing Cache, if null, a redraw is done, cached or not - public Surface bmp; - public bool IsDirty = true; - /// - /// This size is computed on each child' layout changes. - /// In stacking widget, it is used to compute the remaining space for the stretched - /// widget inside the stack, which is never added to the contentSize, instead, its size - /// is deducted from (parent.ClientRectangle - contentSize) - /// - internal Size contentSize; - #endregion - - #region ILayoutable - [XmlIgnore]public LayoutingType RegisteredLayoutings { get { return registeredLayoutings; } set { registeredLayoutings = value; } } - //TODO: it would save the recurent cost of a cast in event bubbling if parent type was GraphicObject - // or we could add to the interface the mouse events - /// - /// Parent in the graphic tree, used for rendering and layouting - /// - [XmlIgnore]public virtual ILayoutable Parent { - get { return parent; } - set { - if (parent == value) - return; - DataSourceChangeEventArgs e = new DataSourceChangeEventArgs (parent, value); - - parentRWLock.EnterWriteLock(); - parent = value; - Slot = LastSlots = default(Rectangle); - parentRWLock.ExitWriteLock(); - - onParentChanged (this, e); - } - } - [XmlIgnore]public ILayoutable LogicalParent { - get { return logicalParent == null ? Parent : logicalParent; } - set { - if (logicalParent == value) - return; - if (logicalParent != null) - (logicalParent as GraphicObject).DataSourceChanged -= onLogicalParentDataSourceChanged; - DataSourceChangeEventArgs dsce = new DataSourceChangeEventArgs (LogicalParent, null); - logicalParent = value; - dsce.NewDataSource = LogicalParent; - if (logicalParent != null) - (logicalParent as GraphicObject).DataSourceChanged += onLogicalParentDataSourceChanged; - onLogicalParentChanged (this, dsce); - } - } - [XmlIgnore]public virtual Rectangle ClientRectangle { - get { - Rectangle cb = Slot.Size; - cb.Inflate ( - margin); - return cb; - } - } - public virtual Rectangle ContextCoordinates(Rectangle r){ - GraphicObject go = Parent as GraphicObject; - if (go == null) - return r + Parent.ClientRectangle.Position; - return go.CacheEnabled ? - r + Parent.ClientRectangle.Position : - Parent.ContextCoordinates (r); - } - public virtual Rectangle ScreenCoordinates (Rectangle r){ - try { - return - Parent.ScreenCoordinates(r) + Parent.getSlot().Position + Parent.ClientRectangle.Position; - } catch (Exception ex) { - Debug.WriteLine (ex); - return default(Rectangle); - } - } - public virtual Rectangle getSlot () { return Slot;} - #endregion - public Point ScreenPointToLocal(Point p){ - Point pt = p - ScreenCoordinates(Slot).TopLeft - ClientRectangle.TopLeft; - if (pt.X < 0) - pt.X = 0; - if (pt.Y < 0) - pt.Y = 0; - return pt; - } - - #region EVENT HANDLERS - /// Occurs when mouse wheel is rolled in this object. It bubbles to the root - public event EventHandler MouseWheelChanged; - /// Occurs when mouse button is released in this object. It bubbles to the root - public event EventHandler MouseUp; - /// Occurs when mouse button is pressed in this object. It bubbles to the root - public event EventHandler MouseDown; - /// Occurs when mouse button has been pressed then relesed in this object. It bubbles to the root - public event EventHandler MouseClick; - /// Occurs when mouse button has been pressed then relesed 2 times in this object. It bubbles to the root - public event EventHandler MouseDoubleClick; - /// Occurs when mouse mouve in this object. It bubbles to the root - public event EventHandler MouseMove; - /// Occurs when mouse enter this object - public event EventHandler MouseEnter; - /// Occurs when mouse leave this object - public event EventHandler MouseLeave; - /// Occurs when key is pressed when this object is active - public event EventHandler KeyDown; - /// Occurs when key is released when this object is active - public event EventHandler KeyUp; - /// Occurs when translated key event occurs in the host when this object is active - public event EventHandler KeyPress; - /// Occurs when this object received focus - public event EventHandler Focused; - /// Occurs when this object loose focus - public event EventHandler Unfocused; - /// Occurs when mouse is over - //public event EventHandler Hover; - /// Occurs when this control is no longer the Hover one - //public event EventHandler UnHover; - /// Occurs when this object loose focus - public event EventHandler Enabled; - /// Occurs when the enabled state this object is set to false - public event EventHandler Disabled; - - #region DragAndDrop Events - public event EventHandler StartDrag; - public event EventHandler DragEnter; - public event EventHandler DragLeave; - public event EventHandler EndDrag; - public event EventHandler Drop; - #endregion - - /// - /// Occurs when default value and styling are loaded, and for templated control, - /// template is also loaded. Bindings should be functionnal as well. - /// - public event EventHandler Initialized; - - /// Occurs when one part of the rendering slot changed - public event EventHandler LayoutChanged; - /// Occurs when DataSource changed - public event EventHandler DataSourceChanged; - /// Occurs when the parent has changed - public event EventHandler ParentChanged; - /// Occurs when the logical parent has changed - public event EventHandler LogicalParentChanged; - #endregion - - #region public properties - /// Random value placeholder - [DesignCategory ("Divers")] - public object Tag { - get { return tag; } - set { - if (tag == value) - return; - tag = value; - NotifyValueChanged ("Tag", tag); - } - } - /// - /// If enabled, resulting bitmap of graphic object is cached - /// speeding up rendering of complex object. Default is enabled. - /// - [DesignCategory ("Behavior")][DefaultValue(true)] - public virtual bool CacheEnabled { - get { return cacheEnabled; } - set { - if (cacheEnabled == value) - return; - cacheEnabled = value; - NotifyValueChanged ("CacheEnabled", cacheEnabled); - } - } - /// - /// If true, rendering of GraphicObject is clipped inside client rectangle - /// - [DesignCategory ("Appearance")][DefaultValue(true)] - public virtual bool ClipToClientRect { - get { return clipToClientRect; } - set { - if (clipToClientRect == value) - return; - clipToClientRect = value; - NotifyValueChanged ("ClipToClientRect", clipToClientRect); - this.RegisterForRedraw (); - } - } - #if DEBUG_LOG - [XmlIgnore]public string TreePath { - get { return this.GetType().Name + GraphicObjects.IndexOf(this).ToString (); } - } - #endif - /// - /// Name is used in binding to reference other GraphicObjects inside the graphic tree - /// and by template controls to find special element in their template implementation such - /// as a container or a group to put children in. - /// - [DesignCategory ("Divers")][DefaultValue(null)] - public virtual string Name { - get { - #if DEBUG_LOG - return string.IsNullOrEmpty(name) ? this.GetType().Name + GraphicObjects.IndexOf(this).ToString () : name; - #else - return name; - #endif - } - set { - if (name == value) - return; - name = value; - NotifyValueChanged("Name", name); - } - } - /// - /// Vertical alignment inside parent, disabled if height is stretched - /// or top coordinate is not null - /// - [DesignCategory ("Layout")][DefaultValue(VerticalAlignment.Center)] - public virtual VerticalAlignment VerticalAlignment { - get { return verticalAlignment; } - set { - if (verticalAlignment == value) - return; - - verticalAlignment = value; - NotifyValueChanged("VerticalAlignment", verticalAlignment); - RegisterForLayouting (LayoutingType.Y); - } - } - /// - /// Horizontal alignment inside parent, disabled if width is stretched - /// or left coordinate is not null - /// - [DesignCategory ("Layout")][DefaultValue(HorizontalAlignment.Center)] - public virtual HorizontalAlignment HorizontalAlignment { - get { return horizontalAlignment; } - set { - if (horizontalAlignment == value) - return; - horizontalAlignment = value; - NotifyValueChanged("HorizontalAlignment", horizontalAlignment); - RegisterForLayouting (LayoutingType.X); - } - } - /// - /// x position inside parent - /// - [DesignCategory ("Layout")][DefaultValue(0)] - public virtual int Left { - get { return left; } - set { - if (left == value) - return; - left = value; - NotifyValueChanged ("Left", left); - this.RegisterForLayouting (LayoutingType.X); - } - } - /// - /// y position inside parent - /// - [DesignCategory ("Layout")][DefaultValue(0)] - public virtual int Top { - get { return top; } - set { - if (top == value) - return; - top = value; - NotifyValueChanged ("Top", top); - this.RegisterForLayouting (LayoutingType.Y); - } - } - /// - /// Helper property used to set width and height to fit in one call - /// - [DesignCategory ("Layout")][DefaultValue(false)] - public virtual bool Fit { - get { return Width == Measure.Fit && Height == Measure.Fit ? true : false; } - set { - if (value == Fit) - return; - - Width = Height = Measure.Fit; - } - } - /// - /// Width of this control, by default inherited from parent. May have special values - /// such as Stretched or Fit. It may be proportionnal or absolute. - /// - [DesignCategory ("Layout")][DefaultValue("Inherit")] - public virtual Measure Width { - get { - return width.Units == Unit.Inherit ? - Parent is GraphicObject ? (Parent as GraphicObject).WidthPolicy : - Measure.Stretched : width; - } - set { - if (width == value) - return; - if (value.IsFixed) { - if (value < minimumSize.Width || (value > maximumSize.Width && maximumSize.Width > 0)) - return; - } - Measure old = width; - width = value; - NotifyValueChanged ("Width", width); - if (width == Measure.Stretched || old == Measure.Stretched) { - //NotifyValueChanged ("WidthPolicy", width.Policy); - //contentSize in Stacks are only update on childLayoutChange, and the single stretched - //child of the stack is not counted in contentSize, so when changing size policy of a child - //we should adapt contentSize - //TODO:check case when child become stretched, and another stretched item already exists. - GenericStack gs = Parent as GenericStack; - if (gs != null){ //TODO:check if I should test Group instead - if (gs.Orientation == Orientation.Horizontal) { - if (width == Measure.Stretched) - gs.contentSize.Width -= this.LastSlots.Width; - else - gs.contentSize.Width += this.LastSlots.Width; - } - } - } - - this.RegisterForLayouting (LayoutingType.Width); - } - } - /// - /// Height of this control, by default inherited from parent. May have special values - /// such as Stretched or Fit. It may be proportionnal or absolute. - /// - [DesignCategory ("Layout")][DefaultValue("Inherit")] - public virtual Measure Height { - get { - return height.Units == Unit.Inherit ? - Parent is GraphicObject ? (Parent as GraphicObject).HeightPolicy : - Measure.Stretched : height; - } - set { - if (height == value) - return; - if (value.IsFixed) { - if (value < minimumSize.Height || (value > maximumSize.Height && maximumSize.Height > 0)) - return; - } - Measure old = height; - height = value; - NotifyValueChanged ("Height", height); - if (height == Measure.Stretched || old == Measure.Stretched) { - //NotifyValueChanged ("HeightPolicy", HeightPolicy); - GenericStack gs = Parent as GenericStack; - if (gs != null){ //TODO:check if I should test Group instead - if (gs.Orientation == Orientation.Vertical) { - if (height == Measure.Stretched) - gs.contentSize.Height -= this.LastSlots.Height; - else - gs.contentSize.Height += this.LastSlots.Height; - } - } - } - - this.RegisterForLayouting (LayoutingType.Height); - } - } - /// - /// Was Used for binding on dimensions, this property will never hold fixed size, but instead only - /// Fit or Stretched, **with inherited state implementation, it is not longer used in binding** - /// - [XmlIgnore]public virtual Measure WidthPolicy { get { - return Width.IsFit ? Measure.Fit : Measure.Stretched; } } - /// - /// Was Used for binding on dimensions, this property will never hold fixed size, but instead only - /// Fit or Stretched, **with inherited state implementation, it is not longer used in binding** - /// - [XmlIgnore]public virtual Measure HeightPolicy { get { - return Height.IsFit ? Measure.Fit : Measure.Stretched; } } - /// - /// Indicate that this object may received focus or not, if not focusable all the descendants are - /// affected. - /// - [DesignCategory ("Behaviour")][DefaultValue(false)] - public virtual bool Focusable { - get { return focusable; } - set { - if (focusable == value) - return; - focusable = value; - NotifyValueChanged ("Focusable", focusable); - } - } - /// - /// True when this control has the focus, only one control per interface may have it. - /// - [XmlIgnore]public virtual bool HasFocus { - get { return hasFocus; } - set { - if (value == hasFocus) - return; - - hasFocus = value; - if (hasFocus) - onFocused (this, null); - else - onUnfocused (this, null); - NotifyValueChanged ("HasFocus", hasFocus); - } - } - /// - /// true if this control is active, this means that mouse has been pressed in it and not yet released. It could - /// be used for other two states periferic action. - /// - [XmlIgnore]public virtual bool IsActive { - get { return isActive; } - set { - if (value == isActive) - return; - - isActive = value; - NotifyValueChanged ("IsActive", isActive); - } - } - /// - /// true if this control has the pointer hover - /// - /*[XmlIgnore]public virtual bool IsHover { - get { return isHover; } - set { - if (value == isHover) - return; - - isHover = value; - - if (isHover) - onHover (this, null); - else - onUnHover (this, null); - - NotifyValueChanged ("IsHover", isHover); - } - }*/ - /// - /// true if holding mouse button down should trigger multiple click events - /// - [DesignCategory ("Behaviour")][DefaultValue(false)] - public virtual bool MouseRepeat { - get { return mouseRepeat; } - set { - if (mouseRepeat == value) - return; - mouseRepeat = value; - NotifyValueChanged ("MouseRepeat", mouseRepeat); - } - } - bool clearBackground = false; - /// - /// background fill of the control, maybe solid color, gradient, image, or svg - /// - [DesignCategory ("Appearance")][DefaultValue("Transparent")] - public virtual Fill Background { - get { return background; } - set { - if (background == value) - return; - clearBackground = false; - if (value == null) - return; - background = value; - NotifyValueChanged ("Background", background); - RegisterForRedraw (); - if (background is SolidColor) { - if ((background as SolidColor).Equals (Color.Clear)) - clearBackground = true; - } - } - } - /// - /// Foreground fill of the control, usage may be different among derived controls - /// - [DesignCategory ("Appearance")][DefaultValue("White")] - public virtual Fill Foreground { - get { return foreground; } - set { - if (foreground == value) - return; - foreground = value; - NotifyValueChanged ("Foreground", foreground); - RegisterForRedraw (); - } - } - /// - /// Font being used in many controls, it is defined in the base GraphicObject class. - /// - [DesignCategory ("Appearance")][DefaultValue("sans, 10")] - public virtual Font Font { - get { return font; } - set { - if (value == font) - return; - font = value; - NotifyValueChanged ("Font", font); - RegisterForGraphicUpdate (); - } - } - /// - /// to get rounded corners - /// - [DesignCategory ("Appearance")][DefaultValue(0.0)] - public virtual double CornerRadius { - get { return cornerRadius; } - set { - if (value == cornerRadius) - return; - cornerRadius = value; - NotifyValueChanged ("CornerRadius", cornerRadius); - RegisterForRedraw (); - } - } - /// - /// This is a single integer for the 4 direction, a gap between the control and it's container, - /// by default it is filled with the background. - /// - [DesignCategory ("Layout")][DefaultValue(0)] - public virtual int Margin { - get { return margin; } - set { - if (value == margin) - return; - margin = value; - NotifyValueChanged ("Margin", margin); - RegisterForGraphicUpdate (); - } - } - /// - /// set the visible state of the control, invisible controls does reserve space in the layouting system. - /// - [DesignCategory ("Appearance")][DefaultValue(true)] - public virtual bool Visible { - get { return isVisible; } - set { - if (value == isVisible) - return; - - isVisible = value; - - RegisterForLayouting (LayoutingType.Sizing); - - if (!isVisible && IFace.HoverWidget != null) { - if (IFace.HoverWidget.IsOrIsInside (this)) { - //IFace.HoverWidget = null; - IFace.ProcessMouseMove (IFace.Mouse.X, IFace.Mouse.Y); - } - } - - NotifyValueChanged ("Visible", isVisible); - } - } - /// - /// get or set the enabled state, disabling a control will affect focuability and - /// also it's rendering which will be grayed - /// - [DesignCategory ("Behaviour")][DefaultValue(true)] - public virtual bool IsEnabled { - get { return isEnabled; } - set { - if (value == isEnabled) - return; - - isEnabled = value; - - if (isEnabled) - onEnable (this, null); - else - onDisable (this, null); - - NotifyValueChanged ("IsEnabled", isEnabled); - RegisterForRedraw (); - } - } - /// - /// Minimal width and height for this control - /// - [DesignCategory ("Layout")][DefaultValue("1,1")] - public virtual Size MinimumSize { - get { return minimumSize; } - set { - if (value == minimumSize) - return; - - minimumSize = value; - - NotifyValueChanged ("MinimumSize", minimumSize); - RegisterForLayouting (LayoutingType.Sizing); - } - } - /// - /// Maximum width and height for this control, unlimited if null. - /// - [DesignCategory ("Layout")][DefaultValue("0,0")] - public virtual Size MaximumSize { - get { return maximumSize; } - set { - if (value == maximumSize) - return; - - maximumSize = value; - - NotifyValueChanged (nameof(MaximumSize), maximumSize); - RegisterForLayouting (LayoutingType.Sizing); - } - } - /// - /// Fully qualify type name of expected data source. - /// If set, datasource bindings will be speedup by avoiding reflexion in generated dyn methods. - /// If an object of a different type is set as datasource, bindings will be canceled. - /// It accepts all derived type. - /// - [DesignCategory ("Data")] - public Type DataSourceType { - get { return dataSourceType; } - set { dataSourceType = value; } - } - /// - /// Seek first logical tree upward if logicalParent is set, or seek graphic tree for - /// a not null dataSource that will be active for all descendants having dataSource=null - /// - [DesignCategory ("Data")] - public virtual object DataSource { - set { - if (DataSource == value) - return; - - DataSourceChangeEventArgs dse = new DataSourceChangeEventArgs (DataSource, null); - dataSource = value; - dse.NewDataSource = DataSource; - - if (dse.NewDataSource == dse.OldDataSource) - return; - - if (value != null) - rootDataLevel = true; - - #if DEBUG_LOG - DbgEvent dbgEvt = DebugLog.AddEvent(DbgEvtType.GOLockLayouting, this); - #endif - lock (IFace.LayoutMutex) { - OnDataSourceChanged (this, dse); - NotifyValueChanged ("DataSource", DataSource); - } - #if DEBUG_LOG - dbgEvt.end = DebugLog.chrono.ElapsedTicks; - #endif - } - get { - return rootDataLevel ? dataSource : dataSource == null ? - LogicalParent == null ? null : - LogicalParent is GraphicObject ? (LogicalParent as GraphicObject).DataSource : null : - dataSource; - } - } - /// - /// If true, rendering of GraphicObject is clipped inside client rectangle - /// - [DesignCategory ("Data")][DefaultValue(false)] - public virtual bool RootDataLevel { - get { return rootDataLevel; } - set { - if (rootDataLevel == value) - return; - rootDataLevel = value; - NotifyValueChanged ("RootDataLevel", rootDataLevel); - this.RegisterForRedraw (); - } - } - protected virtual void onLogicalParentDataSourceChanged(object sender, DataSourceChangeEventArgs e){ - if (localDataSourceIsNull) - OnDataSourceChanged (this, e); - } - internal bool localDataSourceIsNull { get { return dataSource == null; } } - public bool localLogicalParentIsNull { get { return logicalParent == null; } } - - public virtual void OnDataSourceChanged(object sender, DataSourceChangeEventArgs e){ - DataSourceChanged.Raise (this, e); - #if DEBUG_LOG - DebugLog.AddEvent(DbgEvtType.GONewDataSource, this); - #endif - - #if DEBUG_BINDING - Debug.WriteLine("New DataSource for => {0} \n\t{1}=>{2}", this.ToString(),e.OldDataSource,e.NewDataSource); - #endif - } - /// - /// Style key to use for this control - /// - [DesignCategory ("Appearance")] - public virtual string Style { - get { return style; } - set { - if (value == style) - return; - - style = value; - - NotifyValueChanged ("Style", style); - } - } - [DesignCategory ("Divers")] - public virtual string Tooltip { - get { return tooltip; } - set { - if (tooltip == value) - return; - tooltip = value; - NotifyValueChanged("Tooltip", tooltip); - } - } - [DesignCategory ("Divers")] - public IList ContextCommands { - get { return contextCommands; } - set { - if (contextCommands == value) - return; - contextCommands = value; - NotifyValueChanged("ContextCommands", contextCommands); - } - } - #endregion - - #region Default and Style Values loading - /// Loads the default values from XML attributes default - public void loadDefaultValues() - { - #if DEBUG_LOG - DbgEvent dbgEvt = DebugLog.AddEvent(DbgEvtType.GOInitialization, this); - #endif - - Type thisType = this.GetType (); - - if (!string.IsNullOrEmpty (style)) { - if (IFace.DefaultValuesLoader.ContainsKey (style)) { - IFace.DefaultValuesLoader [style] (this); - onInitialized (this, null); - return; - } - } else if (IFace.DefaultValuesLoader.ContainsKey (thisType.FullName)) { - IFace.DefaultValuesLoader [thisType.FullName] (this); - onInitialized (this, null); - return; - } else if (IFace.DefaultValuesLoader.ContainsKey (thisType.Name)) { - IFace.DefaultValuesLoader [thisType.Name] (this); - onInitialized (this, null); - return; - } - - List