diff options
Diffstat (limited to 'src')
184 files changed, 0 insertions, 31300 deletions
diff --git a/src/BmpPicture.cs b/src/BmpPicture.cs deleted file mode 100644 index e3af9c79..00000000 --- a/src/BmpPicture.cs +++ /dev/null @@ -1,169 +0,0 @@ -// -// BmpPicture.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.IO; -using Cairo; - -namespace Crow -{ - - /// <summary> - /// Derived from FILL for loading and drawing bitmaps in the interface - /// </summary> - public class BmpPicture : Picture - { - byte[] image = null; - - #region CTOR - /// <summary> - /// Initializes a new instance of BmpPicture. - /// </summary> - public BmpPicture () - {} - /// <summary> - /// Initializes a new instance of BmpPicture by loading the image pointed by the path argument - /// </summary> - /// <param name="path">image path, may be embedded</param> - public BmpPicture (string path) : base(path) - {} - #endregion - /// <summary> - /// load the image for rendering from the path given as argument - /// </summary> - /// <param name="path">image path, may be embedded</param> - public override void Load (Interface iface, string path) - { - Path = path; - if (sharedResources.ContainsKey (path)) { - sharedPicture sp = sharedResources [path]; - image = (byte[])sp.Data; - Dimensions = sp.Dims; - return; - } - using (Stream stream = iface.GetStreamFromPath (path)) { - loadBitmap (new System.Drawing.Bitmap (stream)); - } - sharedResources [path] = new sharedPicture (image, Dimensions); - } - - //load image via System.Drawing.Bitmap, cairo load png only - void loadBitmap (System.Drawing.Bitmap bitmap) - { - if (bitmap == null) - return; - - System.Drawing.Imaging.BitmapData data = bitmap.LockBits - (new System.Drawing.Rectangle (0, 0, bitmap.Width, bitmap.Height), - System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); - - Dimensions = new Size (bitmap.Width, bitmap.Height); - - int stride = data.Stride; - int bitmapSize = Math.Abs (data.Stride) * bitmap.Height; - - image = new byte[bitmapSize]; - System.Runtime.InteropServices.Marshal.Copy (data.Scan0, image, 0, bitmapSize); - - bitmap.UnlockBits (data); - } - - #region implemented abstract members of Fill - - public override void SetAsSource (Context ctx, Rectangle bounds = default(Rectangle)) - { - float widthRatio = 1f; - float heightRatio = 1f; - - if (Scaled){ - widthRatio = (float)bounds.Width / Dimensions.Width; - heightRatio = (float)bounds.Height / Dimensions.Height; - } - - if (KeepProportions) { - if (widthRatio < heightRatio) - heightRatio = widthRatio; - else - widthRatio = heightRatio; - } - - using (ImageSurface tmp = new ImageSurface (Format.Argb32, bounds.Width, bounds.Height)) { - using (Context gr = new Context (tmp)) { - gr.Translate (bounds.Left, bounds.Top); - gr.Scale (widthRatio, heightRatio); - gr.Translate ((bounds.Width/widthRatio - Dimensions.Width)/2, (bounds.Height/heightRatio - Dimensions.Height)/2); - - using (ImageSurface imgSurf = new ImageSurface (image, Format.Argb32, - Dimensions.Width, Dimensions.Height, 4 * Dimensions.Width)) { - gr.SetSourceSurface (imgSurf, 0,0); - gr.Paint (); - } - } - ctx.SetSource (tmp); - } - } - #endregion - - /// <summary> - /// paint the image in the rectangle given in arguments according - /// to the Scale and keepProportion parameters. - /// </summary> - /// <param name="gr">drawing Backend context</param> - /// <param name="rect">bounds of the target surface to paint</param> - /// <param name="subPart">used for svg only</param> - public override void Paint (Context gr, Rectangle rect, string subPart = "") - { - float widthRatio = 1f; - float heightRatio = 1f; - - if (Scaled){ - widthRatio = (float)rect.Width / Dimensions.Width; - heightRatio = (float)rect.Height / Dimensions.Height; - } - - if (KeepProportions) { - if (widthRatio < heightRatio) - heightRatio = widthRatio; - else - widthRatio = heightRatio; - } - - gr.Save (); - - gr.Translate (rect.Left,rect.Top); - gr.Scale (widthRatio, heightRatio); - gr.Translate ((rect.Width/widthRatio - Dimensions.Width)/2, (rect.Height/heightRatio - Dimensions.Height)/2); - - using (ImageSurface imgSurf = new ImageSurface (image, Format.Argb32, - Dimensions.Width, Dimensions.Height, 4 * Dimensions.Width)) { - gr.SetSourceSurface (imgSurf, 0,0); - gr.Paint (); - } - gr.Restore (); - } - } -} - diff --git a/src/BubblingMouseButtonEventArgs.cs b/src/BubblingMouseButtonEventArgs.cs deleted file mode 100644 index e81a6f74..00000000 --- a/src/BubblingMouseButtonEventArgs.cs +++ /dev/null @@ -1,43 +0,0 @@ -// -// BubblingMouseButtonEventArgs.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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; - -namespace Crow -{ - /// <summary> - /// Store focused widget while bubbling mouse down event to the top - /// </summary> - public class BubblingMouseButtonEventArg: MouseButtonEventArgs - { - public GraphicObject 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/src/Cairo/CairoHelpers.cs b/src/Cairo/CairoHelpers.cs deleted file mode 100644 index 44060259..00000000 --- a/src/Cairo/CairoHelpers.cs +++ /dev/null @@ -1,137 +0,0 @@ -// -// CairoHelpers.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Linq; -using System.Text; - -namespace Crow -{ - public static class CairoHelpers - { - public static T Clamp<T>(this T val, T min, T max) where T : IComparable<T> - { - if (val.CompareTo(min) < 0) return min; - else if(val.CompareTo(max) > 0) return max; - else return val; - } - /// <summary> - /// Convert string to utf8 (extension method) - /// </summary> - /// <returns>byte array with utf8 encoding</returns> - public static byte[] ToUtf8(this String str) - { - return System.Text.UTF8Encoding.UTF8.GetBytes (str); - } - - public static double min(params double[] arr) - { - int minp = 0; - for (int i = 1; i < arr.Length; i++) - if (arr[i] < arr[minp]) - minp = i; - - return arr[minp]; - } - public static void CairoRectangle(Cairo.Context gr, Rectangle r, double radius, double stroke = 0.0) - { - if (radius > 0) - CairoHelpers.DrawRoundedRectangle (gr, r, radius, stroke); - else - gr.Rectangle (r, stroke); - } - public static void CairoCircle(Cairo.Context gr, Rectangle r) - { - gr.Arc(r.X + r.Width/2, r.Y + r.Height/2, Math.Min(r.Width,r.Height)/2, 0, 2*Math.PI); - } - public static void DrawRoundedRectangle(Cairo.Context gr, Rectangle r, double radius, double stroke = 0.0) - { - if (stroke>0.0) { - gr.LineWidth = stroke; - double hsw = stroke / 2.0; - DrawRoundedRectangle (gr, r.X + hsw, r.Y + hsw, r.Width - stroke, r.Height - stroke, radius); - gr.Stroke (); - }else - DrawRoundedRectangle(gr, r.X, r.Y, r.Width, r.Height, radius); - } - public static void DrawRoundedRectangle(Cairo.Context gr, double x, double y, double width, double height, double radius) - { - gr.Save(); - - if ((radius > height / 2) || (radius > width / 2)) - radius = min(height / 2, width / 2); - - gr.MoveTo(x, y + radius); - gr.Arc(x + radius, y + radius, radius, Math.PI, -Math.PI / 2); - gr.LineTo(x + width - radius, y); - gr.Arc(x + width - radius, y + radius, radius, -Math.PI / 2, 0); - gr.LineTo(x + width, y + height - radius); - gr.Arc(x + width - radius, y + height - radius, radius, 0, Math.PI / 2); - gr.LineTo(x + radius, y + height); - gr.Arc(x + radius, y + height - radius, radius, Math.PI / 2, Math.PI); - gr.ClosePath(); - gr.Restore(); - } - public static void StrokeRaisedRectangle(Cairo.Context gr, Rectangle r, double width = 1) - { - gr.Save(); - r.Inflate((int)-width / 2, (int)-width / 2); - gr.LineWidth = width; - gr.SetSourceColor(Color.White); - gr.MoveTo(r.BottomLeft); - gr.LineTo(r.TopLeft); - gr.LineTo(r.TopRight); - gr.Stroke(); - - gr.SetSourceColor(Color.DarkGray); - gr.MoveTo(r.TopRight); - gr.LineTo(r.BottomRight); - gr.LineTo(r.BottomLeft); - gr.Stroke(); - - gr.Restore(); - } - public static void StrokeLoweredRectangle(Cairo.Context gr, Rectangle r, double width = 1) - { - gr.Save(); - r.Inflate((int)-width / 2, (int)-width / 2); - gr.LineWidth = width; - gr.SetSourceColor(Color.DarkGray); - gr.MoveTo(r.BottomLeft); - gr.LineTo(r.TopLeft); - gr.LineTo(r.TopRight); - gr.Stroke(); - gr.SetSourceColor(Color.White); - gr.MoveTo(r.TopRight); - gr.LineTo(r.BottomRight); - gr.LineTo(r.BottomLeft); - gr.Stroke(); - - gr.Restore(); - } - } -} diff --git a/src/Colors.cs b/src/Colors.cs deleted file mode 100644 index 0b1b3ad7..00000000 --- a/src/Colors.cs +++ /dev/null @@ -1,499 +0,0 @@ -// -// Colors.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Linq; -using System.Text; -using System.Xml.Serialization; -using System.Reflection; -using System.Diagnostics; - - - -namespace Crow -{ - /// <summary> - /// Universal Color structure - /// </summary> - public struct Color - { - internal static Type TColor = typeof(Color); - - #region CTOR - public Color(double _R, double _G, double _B, double _A) - { - A = _A.Clamp(0,1); - R = _R.Clamp(0,1); - G = _G.Clamp(0,1); - B = _B.Clamp(0,1); - predefinied = false; - htmlCode = ""; - Name = ""; - } - internal Color(double _R, double _G, double _B, double _A, string _name) - { - A = _A; - R = _R; - G = _G; - B = _B; - predefinied = false; - Name = _name; - htmlCode = ""; - ColorDic.Add(_name,this); - } - internal Color(int _R, int _G, int _B, string _name, string _code) - { - A = 1.0; - R = _R / 255.0; - G = _G / 255.0; - B = _B / 255.0; - Name = _name; - htmlCode = _code; - predefinied = true; - ColorDic.Add(_name,this); - } - #endregion - - /// <summary> - /// color names dictionary - /// </summary> - public static Dictionary<string, Color> ColorDic = new Dictionary<string, Color>(); - - public string Name; - public string htmlCode; - internal bool predefinied; - - #region public fields - public double A; - public double R; - public double G; - public double B; - #endregion - - #region Operators - public static implicit operator string(Color c) - { - return c.ToString(); - } - public static implicit operator Color(string s) - { - if (string.IsNullOrEmpty(s)) - return White; - Color cc = default(Color); - if (s.StartsWith ("#")) { - cc.R = int.Parse (s.Substring (1, 2), System.Globalization.NumberStyles.HexNumber) / 255.0; - cc.G = int.Parse (s.Substring (3, 2), System.Globalization.NumberStyles.HexNumber) / 255.0; - cc.B = int.Parse (s.Substring (5, 2), System.Globalization.NumberStyles.HexNumber) / 255.0; - if (s.Length > 7) - cc.A = int.Parse (s.Substring (7, 2), System.Globalization.NumberStyles.HexNumber) / 255.0; - else - cc.A = 1.0; - return cc; - } - - if (char.IsLetter(s[0])){ - if (ColorDic.ContainsKey (s)) - return ColorDic[s]; - throw new Exception ("Unknown color name: " + s); - } - - string[] c = s.Split(new char[] { ',' }); - - return new Color( - double.Parse(c[0]), - double.Parse(c[1]), - double.Parse(c[2]), - double.Parse(c[3])); - } - -// public static implicit operator OpenTK.Vector4(Color c) -// { -// return new OpenTK.Vector4 ((float)c.R, (float)c.G, (float)c.B, (float)c.A); -// } -// public static implicit operator Color(OpenTK.Vector4 v) -// { -// return new Color (v.X, v.Y, v.Z, v.W); -// } - - - public static bool operator ==(Color left, Color right) - { - if (left.predefinied & right.predefinied) - return left.htmlCode == right.htmlCode; - return left.A != right.A ? false : - left.R != right.R ? false : - left.G != right.G ? false : - left.B != right.B ? false : true; - } - public static bool operator !=(Color left, Color right) - { - if (left.predefinied & right.predefinied) - return left.htmlCode != right.htmlCode; - return left.A == right.A ? false : - left.R == right.R ? false : - left.G == right.G ? false : - left.B == right.B ? false : true; - - } - public static bool operator ==(Color c, string n) - { - return n.StartsWith("#") ? - string.Equals(c.HtmlCode, n, StringComparison.Ordinal) : - string.Equals(c.Name, n, StringComparison.Ordinal); - } - public static bool operator !=(Color c, string n) - { - return n.StartsWith("#") ? - !string.Equals(c.HtmlCode, n, StringComparison.Ordinal) : - !string.Equals(c.Name, n, StringComparison.Ordinal); - } - public static bool operator ==(string n, Color c) - { - return string.Equals (c.Name, n, StringComparison.Ordinal); - } - public static bool operator !=(string n, Color c) - { - return !string.Equals (c.Name, n, StringComparison.Ordinal); - } - public static Color operator *(Color c, Double f) - { - return new Color(c.R,c.G,c.B,c.A * f); - } - public static Color operator +(Color c1, Color c2) - { - return new Color(c1.R + c2.R,c1.G + c2.G,c1.B + c2.B,c1.A + c2.A); - } - public static Color operator -(Color c1, Color c2) - { - return new Color(c1.R - c2.R,c1.G - c2.G,c1.B - c2.B,c1.A - c2.A); - } - #endregion - - /// <summary> - /// compute the hue of the color - /// </summary> - public double Hue { - get { - double min = Math.Min (R, Math.Min (G, B)); //Min. value of RGB - double max = Math.Max (R, Math.Max (G, B)); //Max. value of RGB - double diff = max - min; //Delta RGB value - - if ( diff == 0 )//This is a gray, no chroma... - return 0; - - double h = 0.0, s = diff / max; - - double diffR = (((max - R) / 6.0) + (diff / 2.0)) / diff; - double diffG = (((max - G) / 6.0) + (diff / 2.0)) / diff; - double diffB = (((max - B) / 6.0) + (diff / 2.0)) / diff; - - if (R == max) - h = diffB - diffG; - else if (G == max) - h = (1.0 / 3.0) + diffR - diffB; - else if (B == max) - h = (2.0 / 3.0) + diffG - diffR; - - if (h < 0) - h += 1; - if (h > 1) - h -= 1; - - return h; - } - } - /// <summary> - /// compute the saturation of the color - /// </summary> - public double Saturation { - get { - return Math.Max (R, Math.Max (G, B)); //Max. value of RGB - } - } - /// <summary> - /// compute the RGB intensity of the color - /// </summary> - /// <value>The value.</value> - public double Value { - get { - double min = Math.Min (R, Math.Min (G, B)); //Min. value of RGB - double max = Math.Max (R, Math.Max (G, B)); //Max. value of RGB - double diff = max - min; //Delta RGB value - return diff == 0 ? 0 : diff / max; - } - } - public string HtmlCode { - get { - string tmp = "#" + - ((int)Math.Round (R * 255.0)).ToString ("X2") + - ((int)Math.Round (G * 255.0)).ToString ("X2") + - ((int)Math.Round (B * 255.0)).ToString ("X2"); - if (A < 1.0) - tmp += ((int)Math.Round(A * 255.0)).ToString ("X2"); - return tmp; - } - } - public float[] floatArray - { - get { return new float[]{ (float)R, (float)G, (float)B, (float)A }; } - } - /// <summary> - /// return a copy of the color with the alpha component modified - /// </summary> - /// <returns>new modified color</returns> - /// <param name="_A">normalized alpha component</param> - public Color AdjustAlpha(double _A) - { - return new Color (this.R, this.G, this.B, _A); - } - public void ResetName(){ - Name = ""; - htmlCode = ""; - } - - #region Predefined colors - public static readonly Color Transparent = new Color(0, 0, 0, 0, "Transparent"); - public static readonly Color Clear = new Color(-1, -1, -1, -1, "Clear"); - public static readonly Color AliceBlue = new Color(240,248,255,"AliceBlue","#F0F8FF"); - public static readonly Color AntiqueWhite = new Color(250,235,215,"AntiqueWhite","#FAEBD7"); - public static readonly Color Aqua = new Color(0,255,255,"Aqua","#00FFFF"); - public static readonly Color Aquamarine = new Color(127,255,212,"Aquamarine","#7FFFD4"); - public static readonly Color Azure = new Color(240,255,255,"Azure","#F0FFFF"); - public static readonly Color Beige = new Color(245,245,220,"Beige","#F5F5DC"); - public static readonly Color Bisque = new Color(255,228,196,"Bisque","#FFE4C4"); - public static readonly Color Black = new Color(0,0,0,"Black","#000000"); - public static readonly Color BlanchedAlmond = new Color(255,235,205,"BlanchedAlmond","#FFEBCD"); - public static readonly Color Blue = new Color(0,0,255,"Blue","#0000FF"); - public static readonly Color BlueViolet = new Color(138,43,226,"BlueViolet","#8A2BE2"); - public static readonly Color Brown = new Color(165,42,42,"Brown","#A52A2A"); - public static readonly Color BurlyWood = new Color(222,184,135,"BurlyWood","#DEB887"); - public static readonly Color CadetBlue = new Color(95,158,160,"CadetBlue","#5F9EA0"); - public static readonly Color Chartreuse = new Color(127,255,0,"Chartreuse","#7FFF00"); - public static readonly Color Chocolate = new Color(210,105,30,"Chocolate","#D2691E"); - public static readonly Color Coral = new Color(255,127,80,"Coral","#FF7F50"); - public static readonly Color CornflowerBlue = new Color(100,149,237,"CornflowerBlue","#6495ED"); - public static readonly Color Cornsilk = new Color(255,248,220,"Cornsilk","#FFF8DC"); - public static readonly Color Crimson = new Color(220,20,60,"Crimson","#DC143C"); - public static readonly Color Cyan = new Color(0,255,255,"Cyan","#00FFFF"); - public static readonly Color DarkBlue = new Color(0,0,139,"DarkBlue","#00008B"); - public static readonly Color DarkCyan = new Color(0,139,139,"DarkCyan","#008B8B"); - public static readonly Color DarkGoldenRod = new Color(184,134,11,"DarkGoldenRod","#B8860B"); - public static readonly Color DarkGray = new Color(169,169,169,"DarkGray","#A9A9A9"); - public static readonly Color DarkGrey = new Color(169,169,169,"DarkGrey","#A9A9A9"); - public static readonly Color DarkGreen = new Color(0,100,0,"DarkGreen","#006400"); - public static readonly Color DarkKhaki = new Color(189,183,107,"DarkKhaki","#BDB76B"); - public static readonly Color DarkMagenta = new Color(139,0,139,"DarkMagenta","#8B008B"); - public static readonly Color DarkOliveGreen = new Color(85,107,47,"DarkOliveGreen","#556B2F"); - public static readonly Color DarkOrange = new Color(255,140,0,"DarkOrange","#FF8C00"); - public static readonly Color DarkOrchid = new Color(153,50,204,"DarkOrchid","#9932CC"); - public static readonly Color DarkRed = new Color(139,0,0,"DarkRed","#8B0000"); - public static readonly Color DarkSalmon = new Color(233,150,122,"DarkSalmon","#E9967A"); - public static readonly Color DarkSeaGreen = new Color(143,188,143,"DarkSeaGreen","#8FBC8F"); - public static readonly Color DarkSlateBlue = new Color(72,61,139,"DarkSlateBlue","#483D8B"); - public static readonly Color DarkSlateGray = new Color(47,79,79,"DarkSlateGray","#2F4F4F"); - public static readonly Color DarkSlateGrey = new Color(47,79,79,"DarkSlateGrey","#2F4F4F"); - public static readonly Color DarkTurquoise = new Color(0,206,209,"DarkTurquoise","#00CED1"); - public static readonly Color DarkViolet = new Color(148,0,211,"DarkViolet","#9400D3"); - public static readonly Color DeepPink = new Color(255,20,147,"DeepPink","#FF1493"); - public static readonly Color DeepSkyBlue = new Color(0,191,255,"DeepSkyBlue","#00BFFF"); - public static readonly Color DimGray = new Color(105,105,105,"DimGray","#696969"); - public static readonly Color DimGrey = new Color(105,105,105,"DimGrey","#696969"); - public static readonly Color DodgerBlue = new Color(30,144,255,"DodgerBlue","#1E90FF"); - public static readonly Color FireBrick = new Color(178,34,34,"FireBrick","#B22222"); - public static readonly Color FloralWhite = new Color(255,250,240,"FloralWhite","#FFFAF0"); - public static readonly Color ForestGreen = new Color(34,139,34,"ForestGreen","#228B22"); - public static readonly Color Fuchsia = new Color(255,0,255,"Fuchsia","#FF00FF"); - public static readonly Color Gainsboro = new Color(220,220,220,"Gainsboro","#DCDCDC"); - public static readonly Color GhostWhite = new Color(248,248,255,"GhostWhite","#F8F8FF"); - public static readonly Color Gold = new Color(255,215,0,"Gold","#FFD700"); - public static readonly Color GoldenRod = new Color(218,165,32,"GoldenRod","#DAA520"); - public static readonly Color Gray = new Color(128,128,128,"Gray","#808080"); - public static readonly Color Grey = new Color(128,128,128,"Grey","#808080"); - public static readonly Color Green = new Color(0,128,0,"Green","#008000"); - public static readonly Color GreenYellow = new Color(173,255,47,"GreenYellow","#ADFF2F"); - public static readonly Color HoneyDew = new Color(240,255,240,"HoneyDew","#F0FFF0"); - public static readonly Color HotPink = new Color(255,105,180,"HotPink","#FF69B4"); - public static readonly Color IndianRed = new Color(205,92,92,"IndianRed","#CD5C5C"); - public static readonly Color Indigo = new Color(75,0,130,"Indigo","#4B0082"); - public static readonly Color Ivory = new Color(255,255,240,"Ivory","#FFFFF0"); - public static readonly Color Jet = new Color(52,52,52,"Jet","#343434"); - public static readonly Color Khaki = new Color(240,230,140,"Khaki","#F0E68C"); - public static readonly Color Lavender = new Color(230,230,250,"Lavender","#E6E6FA"); - public static readonly Color LavenderBlush = new Color(255,240,245,"LavenderBlush","#FFF0F5"); - public static readonly Color LawnGreen = new Color(124,252,0,"LawnGreen","#7CFC00"); - public static readonly Color LemonChiffon = new Color(255,250,205,"LemonChiffon","#FFFACD"); - public static readonly Color LightBlue = new Color(173,216,230,"LightBlue","#ADD8E6"); - public static readonly Color LightCoral = new Color(240,128,128,"LightCoral","#F08080"); - public static readonly Color LightCyan = new Color(224,255,255,"LightCyan","#E0FFFF"); - public static readonly Color LightGoldenRodYellow = new Color(250,250,210,"LightGoldenRodYellow","#FAFAD2"); - public static readonly Color LightGray = new Color(211,211,211,"LightGray","#D3D3D3"); - public static readonly Color LightGrey = new Color(211,211,211,"LightGrey","#D3D3D3"); - public static readonly Color LightGreen = new Color(144,238,144,"LightGreen","#90EE90"); - public static readonly Color LightPink = new Color(255,182,193,"LightPink","#FFB6C1"); - public static readonly Color LightSalmon = new Color(255,160,122,"LightSalmon","#FFA07A"); - public static readonly Color LightSeaGreen = new Color(32,178,170,"LightSeaGreen","#20B2AA"); - public static readonly Color LightSkyBlue = new Color(135,206,250,"LightSkyBlue","#87CEFA"); - public static readonly Color LightSlateGray = new Color(119,136,153,"LightSlateGray","#778899"); - public static readonly Color LightSlateGrey = new Color(119,136,153,"LightSlateGrey","#778899"); - public static readonly Color LightSteelBlue = new Color(176,196,222,"LightSteelBlue","#B0C4DE"); - public static readonly Color LightYellow = new Color(255,255,224,"LightYellow","#FFFFE0"); - public static readonly Color Lime = new Color(0,255,0,"Lime","#00FF00"); - public static readonly Color LimeGreen = new Color(50,205,50,"LimeGreen","#32CD32"); - public static readonly Color Linen = new Color(250,240,230,"Linen","#FAF0E6"); - public static readonly Color Magenta = new Color(255,0,255,"Magenta","#FF00FF"); - public static readonly Color Maroon = new Color(128,0,0,"Maroon","#800000"); - public static readonly Color MediumAquaMarine = new Color(102,205,170,"MediumAquaMarine","#66CDAA"); - public static readonly Color MediumBlue = new Color(0,0,205,"MediumBlue","#0000CD"); - public static readonly Color MediumOrchid = new Color(186,85,211,"MediumOrchid","#BA55D3"); - public static readonly Color MediumPurple = new Color(147,112,219,"MediumPurple","#9370DB"); - public static readonly Color MediumSeaGreen = new Color(60,179,113,"MediumSeaGreen","#3CB371"); - public static readonly Color MediumSlateBlue = new Color(123,104,238,"MediumSlateBlue","#7B68EE"); - public static readonly Color MediumSpringGreen = new Color(0,250,154,"MediumSpringGreen","#00FA9A"); - public static readonly Color MediumTurquoise = new Color(72,209,204,"MediumTurquoise","#48D1CC"); - public static readonly Color MediumVioletRed = new Color(199,21,133,"MediumVioletRed","#C71585"); - public static readonly Color MidnightBlue = new Color(25,25,112,"MidnightBlue","#191970"); - public static readonly Color MintCream = new Color(245,255,250,"MintCream","#F5FFFA"); - public static readonly Color MistyRose = new Color(255,228,225,"MistyRose","#FFE4E1"); - public static readonly Color Moccasin = new Color(255,228,181,"Moccasin","#FFE4B5"); - public static readonly Color NavajoWhite = new Color(255,222,173,"NavajoWhite","#FFDEAD"); - public static readonly Color Navy = new Color(0,0,128,"Navy","#000080"); - public static readonly Color OldLace = new Color(253,245,230,"OldLace","#FDF5E6"); - public static readonly Color Olive = new Color(128,128,0,"Olive","#808000"); - public static readonly Color OliveDrab = new Color(107,142,35,"OliveDrab","#6B8E23"); - public static readonly Color Onyx = new Color(53,56,57,"Onyx","#353839"); - public static readonly Color Orange = new Color(255,165,0,"Orange","#FFA500"); - public static readonly Color OrangeRed = new Color(255,69,0,"OrangeRed","#FF4500"); - public static readonly Color Orchid = new Color(218,112,214,"Orchid","#DA70D6"); - public static readonly Color PaleGoldenRod = new Color(238,232,170,"PaleGoldenRod","#EEE8AA"); - public static readonly Color PaleGreen = new Color(152,251,152,"PaleGreen","#98FB98"); - public static readonly Color PaleTurquoise = new Color(175,238,238,"PaleTurquoise","#AFEEEE"); - public static readonly Color PaleVioletRed = new Color(219,112,147,"PaleVioletRed","#DB7093"); - public static readonly Color PapayaWhip = new Color(255,239,213,"PapayaWhip","#FFEFD5"); - public static readonly Color PeachPuff = new Color(255,218,185,"PeachPuff","#FFDAB9"); - public static readonly Color Peru = new Color(205,133,63,"Peru","#CD853F"); - public static readonly Color Pink = new Color(255,192,203,"Pink","#FFC0CB"); - public static readonly Color Plum = new Color(221,160,221,"Plum","#DDA0DD"); - public static readonly Color PowderBlue = new Color(176,224,230,"PowderBlue","#B0E0E6"); - public static readonly Color Purple = new Color(128,0,128,"Purple","#800080"); - public static readonly Color RebeccaPurple = new Color(102,51,153,"RebeccaPurple","#663399"); - public static readonly Color Red = new Color(255,0,0,"Red","#FF0000"); - public static readonly Color RosyBrown = new Color(188,143,143,"RosyBrown","#BC8F8F"); - public static readonly Color RoyalBlue = new Color(65,105,225,"RoyalBlue","#4169E1"); - public static readonly Color SaddleBrown = new Color(139,69,19,"SaddleBrown","#8B4513"); - public static readonly Color Salmon = new Color(250,128,114,"Salmon","#FA8072"); - public static readonly Color SandyBrown = new Color(244,164,96,"SandyBrown","#F4A460"); - public static readonly Color SeaGreen = new Color(46,139,87,"SeaGreen","#2E8B57"); - public static readonly Color SeaShell = new Color(255,245,238,"SeaShell","#FFF5EE"); - public static readonly Color Sienna = new Color(160,82,45,"Sienna","#A0522D"); - public static readonly Color Silver = new Color(192,192,192,"Silver","#C0C0C0"); - public static readonly Color SkyBlue = new Color(135,206,235,"SkyBlue","#87CEEB"); - public static readonly Color SlateBlue = new Color(106,90,205,"SlateBlue","#6A5ACD"); - public static readonly Color SlateGray = new Color(112,128,144,"SlateGray","#708090"); - public static readonly Color SlateGrey = new Color(112,128,144,"SlateGrey","#708090"); - public static readonly Color Snow = new Color(255,250,250,"Snow","#FFFAFA"); - public static readonly Color SpringGreen = new Color(0,255,127,"SpringGreen","#00FF7F"); - public static readonly Color SteelBlue = new Color(70,130,180,"SteelBlue","#4682B4"); - public static readonly Color Tan = new Color(210,180,140,"Tan","#D2B48C"); - public static readonly Color Teal = new Color(0,128,128,"Teal","#008080"); - public static readonly Color Thistle = new Color(216,191,216,"Thistle","#D8BFD8"); - public static readonly Color Tomato = new Color(255,99,71,"Tomato","#FF6347"); - public static readonly Color Turquoise = new Color(64,224,208,"Turquoise","#40E0D0"); - public static readonly Color Violet = new Color(238,130,238,"Violet","#EE82EE"); - public static readonly Color Wheat = new Color(245,222,179,"Wheat","#F5DEB3"); - public static readonly Color White = new Color(255,255,255,"White","#FFFFFF"); - public static readonly Color WhiteSmoke = new Color(245,245,245,"WhiteSmoke","#F5F5F5"); - public static readonly Color Yellow = new Color(255,255,0,"Yellow","#FFFF00"); - public static readonly Color YellowGreen = new Color(154,205,50,"YellowGreen","#9ACD32"); - - #endregion - - public override int GetHashCode () - { - unchecked // Overflow is fine, just wrap - { - int hash = 17; - // Suitable nullity checks etc, of course :) - hash = hash * 23 + A.GetHashCode(); - hash = hash * 23 + R.GetHashCode(); - hash = hash * 23 + G.GetHashCode(); - hash = hash * 23 + B.GetHashCode(); - return hash; - } - } - public override bool Equals (object obj) - { - return (obj == null || obj.GetType() != TColor) ? - false : - this == (Color)obj; - } - public override string ToString() - { - if (!string.IsNullOrEmpty(Name)) - return Name; - if (!string.IsNullOrEmpty (htmlCode)) - return htmlCode; - string hc = HtmlCode; - Color pc = ColorDic.Values.FirstOrDefault (c => c.htmlCode == hc); - return pc.predefinied ? pc.Name : hc; - } - - public static object Parse(string s) - { - return (Color)s; - } - public static Color FromHSV(double _h, double _v = 1.0, double _s = 1.0, double _alpha = 1.0){ - Color c = Color.Black; - c.ResetName (); - c.A = _alpha; - if (_s == 0) {//HSV from 0 to 1 - c.R = _v; - c.G = _v; - c.B = _v; - }else{ - double var_h = _h * 6.0; - - if (var_h == 6.0) - var_h = 0; //H must be < 1 - double var_i = Math.Floor( var_h ); //Or ... var_i = floor( var_h ) - double var_1 = _v * ( 1.0 - _s ); - double var_2 = _v * (1.0 - _s * (var_h - var_i)); - double var_3 = _v * (1.0 - _s * (1.0 - (var_h - var_i))); - - if (var_i == 0.0) { - c.R = _v; - c.G = var_3; - c.B = var_1; - }else if ( var_i == 1.0 ) { c.R = var_2 ; c.G = _v ; c.B = var_1; } - else if ( var_i == 2 ) { c.R = var_1 ; c.G = _v ; c.B = var_3; } - else if ( var_i == 3 ) { c.R = var_1 ; c.G = var_2 ; c.B = _v; } - else if ( var_i == 4 ) { c.R = var_3 ; c.G = var_1 ; c.B = _v; } - else { c.R = _v ; c.G = var_1 ; c.B = var_2; } - } - return c; - } - } -} diff --git a/src/Command.cs b/src/Command.cs deleted file mode 100644 index ba95acc9..00000000 --- a/src/Command.cs +++ /dev/null @@ -1,120 +0,0 @@ -// -// Command.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Xml.Serialization; -using System.ComponentModel; - -namespace Crow -{ - /// <summary> - /// helper class to bind in one step icon, caption, action, and validity tests to a controls - /// </summary> - public class Command : IValueChange - { - #region IValueChange implementation - public event EventHandler<ValueChangeEventArgs> ValueChanged; - public virtual void NotifyValueChanged(string MemberName, object _value) - { - ValueChanged.Raise(this, new ValueChangeEventArgs(MemberName, _value)); - } - #endregion - - #region CTOR - /// <summary> - /// Initializes a new instance of Command with the action pass as argument. - /// </summary> - /// <param name="_executeAction">action to excecute when command is triggered</param> - public Command (Action _executeAction) - { - execute = _executeAction; - } - #endregion - - Action execute; - - string caption; - Picture icon; - bool canExecute = true; - - #region Public properties - /// <summary> - /// if true, action defined in this command may be executed, - /// </summary> - [XmlAttributeAttribute][DefaultValue(true)] - public virtual bool CanExecute { - get { return canExecute; } - set { - if (canExecute == value) - return; - canExecute = value; - NotifyValueChanged ("CanExecute", canExecute); - } - } - /// <summary> - /// label to display in the bound control - /// </summary> - [XmlAttributeAttribute][DefaultValue("Unamed Command")] - public virtual string Caption { - get { return caption; } - set { - if (caption == value) - return; - caption = value; - NotifyValueChanged ("Caption", caption); - - } - } - /// <summary> - /// Icon to display in the bound control - /// </summary> - [XmlAttributeAttribute] - public Picture Icon { - get { return icon; } - set { - if (icon == value) - return; - icon = value; - NotifyValueChanged ("Icon", icon); - } - } - #endregion - - /// <summary> - /// trigger the execution of the command - /// </summary> - public void Execute(){ - if (execute != null && CanExecute) - execute (); - } - internal void raiseAllValuesChanged(){ - NotifyValueChanged ("CanExecute", canExecute); - NotifyValueChanged ("Icon", icon); - NotifyValueChanged ("Caption", caption); - } - - } -} diff --git a/src/CompilerServices/CompilerServices.cs b/src/CompilerServices/CompilerServices.cs deleted file mode 100644 index e315f761..00000000 --- a/src/CompilerServices/CompilerServices.cs +++ /dev/null @@ -1,916 +0,0 @@ -// -// CompilerServices.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Reflection.Emit; -using System.Reflection; -using System.Diagnostics; -using System.Linq; -using System.Collections.Generic; -using System.Runtime.CompilerServices; -using System.Xml; -using Crow.IML; - - -namespace Crow.IML -{ - public static class CompilerServices - { - internal static Type TObject = typeof(object); - internal static MethodInfo stringEquals = typeof (string).GetMethod("Equals", new Type [3] { typeof (string), typeof (string), typeof (StringComparison) }); - internal static MethodInfo miObjToString = typeof(object).GetMethod("ToString"); - internal static MethodInfo miGetType = typeof(object).GetMethod("GetType"); - internal static MethodInfo miParseEnum = typeof(Enum).GetMethod("Parse", BindingFlags.Static | BindingFlags.Public, - Type.DefaultBinder, new Type [] {typeof (Type), typeof (string), typeof (bool)}, null); - - internal static MethodInfo miGetTypeFromHandle = typeof(Type).GetMethod("GetTypeFromHandle"); - internal static MethodInfo miGetEvent = typeof(Type).GetMethod("GetEvent", new Type[] {typeof(string)}); - - internal static MethodInfo miMIInvoke = typeof(MethodInfo).GetMethod ("Invoke", new Type[] { - typeof(object), - typeof(object[]) - }); - - internal static MethodInfo miCreateBoundDel = typeof(Delegate).GetMethod ("CreateDelegate", new Type[] { typeof(Type), typeof(object), typeof(MethodInfo) });//create bound delegate - internal static MethodInfo miGetColCount = typeof(System.Collections.ICollection).GetProperty("Count").GetGetMethod(); - internal static MethodInfo miGetDelegateListItem = typeof(List<Delegate>).GetMethod("get_Item", new Type[] { typeof(Int32) }); - - internal static MethodInfo miCompileDynEventHandler = typeof(CompilerServices).GetMethod ("compileDynEventHandler", BindingFlags.Static | BindingFlags.NonPublic); - internal static MethodInfo miRemEvtHdlByName = typeof(CompilerServices).GetMethod("removeEventHandlerByName", BindingFlags.Static | BindingFlags.NonPublic); - internal static MethodInfo miRemEvtHdlByTarget = typeof(CompilerServices).GetMethod("removeEventHandlerByTarget", BindingFlags.Static | BindingFlags.NonPublic); - internal static MethodInfo miGetMethInfoWithRefx = typeof(CompilerServices).GetMethod ("getMethodInfoWithReflexion", BindingFlags.Static | BindingFlags.NonPublic); - internal static MethodInfo miGetMembIinfoWithRefx = typeof(CompilerServices).GetMethod("getMemberInfoWithReflexion", BindingFlags.Static | BindingFlags.NonPublic); - internal static MethodInfo miSetValWithRefx = typeof(CompilerServices).GetMethod("setValueWithReflexion", BindingFlags.Static | BindingFlags.NonPublic); - internal static MethodInfo miGetValWithRefx = typeof(CompilerServices).GetMethod("getValueWithReflexion", BindingFlags.Static | BindingFlags.NonPublic); - internal static MethodInfo miCreateDel = typeof(CompilerServices).GetMethod ("createDel", BindingFlags.Static | BindingFlags.NonPublic); - internal static MethodInfo miGetImplOp = typeof(CompilerServices).GetMethod ("getImplicitOp", BindingFlags.Static | BindingFlags.NonPublic); - internal static MethodInfo miGetDataTypeAndFetch = typeof(CompilerServices).GetMethod("getDataTypeAndFetch", BindingFlags.Static | BindingFlags.NonPublic); - - - internal static MethodInfo miGoUpLevels = typeof(CompilerServices).GetMethod("goUpNbLevels", BindingFlags.Static | BindingFlags.NonPublic); - - internal static FieldInfo fiCachedDel = typeof(Instantiator).GetField("cachedDelegates", BindingFlags.Instance | BindingFlags.NonPublic); - internal static FieldInfo fiTemplateBinding = typeof(Instantiator).GetField("templateBinding", BindingFlags.Instance | BindingFlags.NonPublic); - 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<GraphicObject>).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 MethodInfo miIFaceLoad = typeof(Interface).GetMethod ("Load", BindingFlags.Instance | BindingFlags.Public); - internal static MethodInfo miGetITemp = typeof(Interface).GetMethod ("GetItemTemplate", BindingFlags.Instance | BindingFlags.Public); - - internal static MethodInfo miAddITemp = typeof(Dictionary<string, ItemTemplate>).GetMethod ("set_Item", new Type[] { typeof(string), typeof(ItemTemplate) }); - internal static MethodInfo miGetITempFromDic = typeof(Dictionary<string, ItemTemplate>).GetMethod ("get_Item", new Type[] { typeof(string) }); - internal static FieldInfo fldItemTemplates = typeof(TemplatedGroup).GetField("ItemTemplates"); - internal static MethodInfo miLoadPage = typeof(TemplatedGroup).GetMethod ("loadPage", BindingFlags.Instance | BindingFlags.NonPublic| BindingFlags.Public); - internal static MethodInfo miIsAlreadyExpanded = typeof(TemplatedGroup).GetMethod("emitHelperIsAlreadyExpanded", BindingFlags.Instance | BindingFlags.NonPublic); - - internal static MethodInfo miCreateExpDel = typeof(ItemTemplate).GetMethod ("CreateExpandDelegate"); - internal static FieldInfo fiFetchMethodName = typeof(ItemTemplate).GetField("fetchMethodName", BindingFlags.Instance | BindingFlags.NonPublic); - - #if DESIGN_MODE - internal static MethodInfo miDicStrStrAdd = typeof(Dictionary<string, string>).GetMethod ("set_Item", new Type[] { typeof(string), typeof(string) }); - #endif - - #region tree handling methods - internal static FieldInfo fiChild = typeof(PrivateContainer).GetField ("child", BindingFlags.Instance | BindingFlags.NonPublic); - internal static MethodInfo miSetChild = typeof (Container).GetMethod ("SetChild"); - internal static MethodInfo miAddChild = typeof (Group).GetMethod ("AddChild"); - internal static FieldInfo fiChildren = typeof(Group).GetField ("children", BindingFlags.Instance | BindingFlags.NonPublic); - internal static MethodInfo miLoadTmp = typeof (TemplatedControl).GetMethod ("loadTemplate", BindingFlags.Instance | BindingFlags.NonPublic); - internal static PropertyInfo piContent = typeof(TemplatedContainer).GetProperty ("Content"); - internal static MethodInfo miAddItem = typeof (TemplatedGroup).GetMethod ("AddItem", BindingFlags.Instance | BindingFlags.Public); - internal static MethodInfo miGetItems = typeof(TemplatedGroup).GetProperty ("Items").GetGetMethod (); - #endregion - - #region ValueChange & DSChange Reflexion member info - internal static EventInfo eiValueChange = typeof (IValueChange).GetEvent ("ValueChanged"); - internal static MethodInfo miInvokeValueChange = eiValueChange.EventHandlerType.GetMethod ("Invoke"); - internal static Type [] argsBoundValueChange = { typeof (object), typeof (object), miInvokeValueChange.GetParameters () [1].ParameterType }; - internal static Type [] argsValueChange = { typeof (object), miInvokeValueChange.GetParameters () [1].ParameterType }; - internal static FieldInfo fiVCNewValue = typeof (ValueChangeEventArgs).GetField ("NewValue"); - internal static FieldInfo fiVCMbName = typeof (ValueChangeEventArgs).GetField ("MemberName"); - internal static MethodInfo miValueChangeAdd = eiValueChange.GetAddMethod (); - - internal static EventInfo eiDSChange = typeof (GraphicObject).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"); - internal static FieldInfo fiDSCOldDS = typeof (DataSourceChangeEventArgs).GetField ("OldDataSource"); - internal static Type ehTypeDSChange = eiDSChange.EventHandlerType; - #endregion - - /// <summary> - /// Loc0 is the current graphic object and arg2 of loader is the current interface - /// </summary> - /// <param name="il">Il.</param> - public static void emitSetCurInterface(ILGenerator il){ - il.Emit (OpCodes.Ldloc_0); - il.Emit (OpCodes.Ldarg_1); - il.Emit (OpCodes.Stfld, miSetCurIface); - } - - public static void EmitSetValue(ILGenerator il, PropertyInfo pi, object val){ - il.Emit (OpCodes.Ldloc_0); - - if (val == null) { - il.Emit (OpCodes.Ldnull); - il.Emit (OpCodes.Callvirt, pi.GetSetMethod ()); - return; - } - Type dvType = val.GetType (); - - if (dvType.IsValueType) { - if (pi.PropertyType.IsValueType) { - if (pi.PropertyType.IsEnum) { - if (pi.PropertyType != dvType) - throw new Exception ("Enum mismatch in default values: " + pi.PropertyType.FullName); - il.Emit (OpCodes.Ldc_I4, Convert.ToInt32 (val)); - } else { - switch (Type.GetTypeCode (dvType)) { - case TypeCode.Boolean: - if ((bool)val == true) - il.Emit (OpCodes.Ldc_I4_1); - else - il.Emit (OpCodes.Ldc_I4_0); - break; -// case TypeCode.Empty: -// break; -// case TypeCode.Object: -// break; -// case TypeCode.DBNull: -// break; -// case TypeCode.SByte: -// break; -// case TypeCode.Decimal: -// break; -// case TypeCode.DateTime: -// break; - case TypeCode.Char: - il.Emit (OpCodes.Ldc_I4, Convert.ToChar (val)); - break; - case TypeCode.Byte: - case TypeCode.Int16: - case TypeCode.Int32: - il.Emit (OpCodes.Ldc_I4, Convert.ToInt32 (val)); - break; - case TypeCode.UInt16: - case TypeCode.UInt32: - il.Emit (OpCodes.Ldc_I4, Convert.ToUInt32 (val)); - break; - case TypeCode.Int64: - il.Emit (OpCodes.Ldc_I8, Convert.ToInt64 (val)); - break; - case TypeCode.UInt64: - il.Emit (OpCodes.Ldc_I8, Convert.ToUInt64 (val)); - break; - case TypeCode.Single: - il.Emit (OpCodes.Ldc_R4, Convert.ToSingle (val)); - break; - case TypeCode.Double: - il.Emit (OpCodes.Ldc_R8, Convert.ToDouble (val)); - break; - case TypeCode.String: - il.Emit (OpCodes.Ldstr, Convert.ToString (val)); - break; - default: - il.Emit (OpCodes.Pop); - return; - } - } - } else - throw new Exception ("Expecting valuetype in default values for: " + pi.Name); - }else{ - //surely a class or struct - if (dvType != typeof(string)) - throw new Exception ("Expecting String in default values for: " + pi.Name); - if (pi.PropertyType == typeof(string)) - il.Emit (OpCodes.Ldstr, Convert.ToString (val)); - else if (pi.PropertyType.IsEnum) { - //load type of enum - il.Emit(OpCodes.Ldtoken, pi.PropertyType); - il.Emit(OpCodes.Call, CompilerServices.miGetTypeFromHandle); - //load enum value name - il.Emit (OpCodes.Ldstr, Convert.ToString (val));//TODO:implement here string format? - //load false - il.Emit (OpCodes.Ldc_I4_0); - il.Emit (OpCodes.Callvirt, CompilerServices.miParseEnum); - - if (CompilerServices.miParseEnum.ReturnType != pi.PropertyType) - il.Emit (OpCodes.Unbox_Any, pi.PropertyType); - } else { - MethodInfo miParse = pi.PropertyType.GetMethod - ("Parse", BindingFlags.Static | BindingFlags.Public, - Type.DefaultBinder, new Type [] {typeof (string)},null); - if (miParse == null) - throw new Exception ("no Parse method found for: " + pi.PropertyType.FullName); - - il.Emit (OpCodes.Ldstr, Convert.ToString (val));//TODO:is this convert required? - il.Emit (OpCodes.Callvirt, miParse); - - if (miParse.ReturnType != pi.PropertyType) - il.Emit (OpCodes.Unbox_Any, pi.PropertyType); - } - } - il.Emit (OpCodes.Callvirt, pi.GetSetMethod ()); - } - - #region conversions - - internal static MethodInfo GetConvertMethod (Type targetType) - { - string name; - - if (targetType == typeof (bool)) - name = "ToBoolean"; - else if (targetType == typeof (byte)) - name = "ToByte"; - else if (targetType == typeof (short)) - name = "ToInt16"; - else if (targetType == typeof (int)) - name = "ToInt32"; - else if (targetType == typeof (long)) - name = "ToInt64"; - else if (targetType == typeof (double)) - name = "ToDouble"; - else if (targetType == typeof (float)) - name = "ToSingle"; - else if (targetType == typeof (string)) - return typeof (object).GetMethod ("ToString", Type.EmptyTypes); - else //try to find implicit convertion - throw new NotImplementedException (string.Format ("Conversion to {0} is not implemented.", targetType.Name)); - - return typeof (Convert).GetMethod (name, BindingFlags.Static | BindingFlags.Public, null, new Type [] { typeof (object) }, null); - } - #endregion - - #region Reflexion helpers - static MemberInfo getMemberInfoWithReflexion(object instance, string member){ - Type t = instance.GetType(); - MemberInfo mi = t.GetMember (member)?.FirstOrDefault(); - if (mi == null) - mi = CompilerServices.SearchExtMethod (t, member); - return mi; - } - static MethodInfo getMethodInfoWithReflexion(object instance, string method){ - return instance.GetType ().GetMethod (method, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); - } - /// <summary> - /// set value, convert if required - /// </summary> - /// <param name="dest">Destination instance</param> - /// <param name="value">Value</param> - /// <param name="destMember">Destination member</param> - static void setValueWithReflexion(object dest, object value, string destMember){ - Type destType = null; - Type origType = null; - object convertedVal = null; - - MemberInfo miDest = getMemberInfoWithReflexion (dest, destMember); - - if (miDest == null) { - Debug.WriteLine ("Reverse template binding error: " + destMember + " not found in " + dest); - return; - } - - if (miDest.MemberType == MemberTypes.Property) - destType =(miDest as PropertyInfo).PropertyType; - else if (miDest.MemberType == MemberTypes.Field) - destType =(miDest as FieldInfo).FieldType; - - try { - if (value != null) { - if (destType == TObject)//TODO: check that test of destType is not causing problems - convertedVal = value; - else { - origType = value.GetType (); - if (destType.IsAssignableFrom (origType)) - convertedVal = Convert.ChangeType (value, destType); - else if (origType == typeof(string) & destType.IsPrimitive) - convertedVal = Convert.ChangeType(value, destType); - else if (origType.IsPrimitive & destType.IsPrimitive) - convertedVal = GetConvertMethod (destType).Invoke (null, new Object[] { value }); - else - convertedVal = getImplicitOp (origType, destType).Invoke (value, null); - } - } - } catch (Exception ex) { - Debug.WriteLine (ex.ToString ()); - return; - } - - if (miDest.MemberType == MemberTypes.Property) - (miDest as PropertyInfo).SetValue (dest, convertedVal); - else if (miDest.MemberType == MemberTypes.Field) - (miDest as FieldInfo).SetValue (dest, convertedVal); - } - /// <summary> - /// Gets value with reflexion, return empty string ("") for string and object and return - /// default value for valueType data. - /// </summary> - static object getValueWithReflexion(object instance, MemberInfo mi){ - object tmp = null; - Type dstType = null; - if (mi == null) - return null; - try { - if (mi.MemberType == MemberTypes.Property) { - PropertyInfo pi = mi as PropertyInfo; - tmp = pi.GetValue (instance); - dstType = pi.PropertyType; - }else if (mi.MemberType == MemberTypes.Field) { - FieldInfo fi = mi as FieldInfo; - tmp = fi.GetValue (instance); - dstType = fi.FieldType; - }else if (mi.MemberType == MemberTypes.Method) { - MethodInfo gi = mi as MethodInfo; - if (gi.IsStatic) - tmp = gi.Invoke(null, new object[] {instance}); - else - tmp = gi.Invoke(instance, null); - dstType = gi.ReturnType; - } - - - if (tmp != null) - return tmp; - if (dstType == typeof(string) || dstType == CompilerServices.TObject)//TODO:object should be allowed to return null and not "" - return ""; - if (dstType.IsValueType) - return Activator.CreateInstance (dstType); - } catch (Exception ex) { - Debug.WriteLine (ex.ToString ()); - return ""; - } - - return null; - } - /// <summary> - /// Gets all extension methods defined in assembly for Type - /// </summary> - /// <returns>Extension methods enumerable</returns> - /// <param name="assembly">Assembly</param> - /// <param name="extendedType">Extended type to search for</param> - internal 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; - } - /// <summary> - /// search for extentions method in entry assembly then in crow assembly - /// </summary> - /// <returns>Extention MethodInfo</returns> - /// <param name="t">Extended type</param> - /// <param name="methodName">Extention method name</param> - internal static MethodInfo SearchExtMethod(Type t, string methodName){ - MethodInfo mi = null; - mi = GetExtensionMethods (Assembly.GetEntryAssembly(), t) - .Where (em => em.Name == methodName).FirstOrDefault (); - if (mi != null) - return mi; - - return GetExtensionMethods (Assembly.GetExecutingAssembly(), t) - .Where (em => em.Name == methodName).FirstOrDefault (); - } - /// <summary> - /// retrieve event handler in class or ancestors - /// </summary> - static FieldInfo getEventHandlerField (Type type, string eventName) - { - FieldInfo fi; - Type ty = type; - do { - fi = ty.GetField (eventName, - BindingFlags.NonPublic | - BindingFlags.Instance | - BindingFlags.GetField); - ty = ty.BaseType; - if (ty == null) - break; - } while (fi == null); - return fi; - } - /// <summary> - /// search for an implicit conversion method in origine or destination classes - /// </summary> - static MethodInfo getImplicitOp(Type origType, Type dstType){ - foreach(MethodInfo mi in origType.GetMethods(BindingFlags.Public|BindingFlags.Static)){ - if (mi.Name == "op_Implicit") { - if (mi.ReturnType == dstType && mi.GetParameters ().FirstOrDefault ().ParameterType == origType) - return mi; - } - } - foreach(MethodInfo mi in dstType.GetMethods(BindingFlags.Public|BindingFlags.Static)){ - if (mi.Name == "op_Implicit") { - if (mi.ReturnType == dstType && mi.GetParameters ().FirstOrDefault ().ParameterType == origType) - return mi; - } - } - return null; - } - #endregion - - /// <summary> - /// Emits tree parsing command to fetch dest instance starting from orig node - /// </summary> - internal static void emitGetInstance (ILGenerator il, NodeAddress orig, NodeAddress dest){ - int ptr = 0; - while (orig [ptr] == dest [ptr]) { - ptr++; - if (ptr == orig.Count || ptr == dest.Count) - break; - } - for (int i = 0; i < orig.Count - ptr; i++) - il.Emit (OpCodes.Callvirt, CompilerServices.miGetLogicalParent); - while (ptr < dest.Count) { - emitGetChild (il, dest [ptr-1].CrowType, dest [ptr].Index); - ptr++; - } - } - /// <summary> - /// Emits tree parsing commands to get child starting at root node - /// </summary> - /// <param name="il">MSIL generator</param> - /// <param name="dest">Absolute Node Address of the instance to get</param> - internal static void emitGetInstance (ILGenerator il, NodeAddress dest){ - if (dest == null) - return; - for (int i = 0; i < dest.Count - 1; i++) - emitGetChild (il, dest [i].CrowType, dest [i + 1].Index); - } - /// <summary> - /// Emits msil to fetch chil instance of current GraphicObject on the stack - /// </summary> - /// <param name="il">Il generator</param> - /// <param name="parentType">Parent type</param> - /// <param name="index">Index of child, -1 for template root</param> - internal static void emitGetChild(ILGenerator il, Type parentType, int index){ - if (typeof (Group).IsAssignableFrom (parentType)) { - il.Emit (OpCodes.Ldfld, fiChildren); - il.Emit(OpCodes.Ldc_I4, index); - il.Emit (OpCodes.Callvirt, miGetGObjItem); - return; - } - if (typeof(Container).IsAssignableFrom (parentType) || index < 0) { - il.Emit (OpCodes.Ldfld, fiChild); - return; - } - if (typeof(TemplatedContainer).IsAssignableFrom (parentType)) { - il.Emit (OpCodes.Callvirt, piContent.GetGetMethod()); - return; - } - if (typeof(TemplatedGroup).IsAssignableFrom (parentType)) { - il.Emit (OpCodes.Callvirt, miGetItems); - il.Emit(OpCodes.Ldc_I4, index); - il.Emit (OpCodes.Callvirt, miGetGObjItem); - return; - } - } - - /// <summary> - /// Emit MSIL for conversion from orig type to dest type - /// </summary> - internal static void emitConvert(ILGenerator il, Type origType, Type destType){ - if (destType == CompilerServices.TObject) - return; - if (destType == typeof(string)) { - System.Reflection.Emit.Label emitNullStr = il.DefineLabel (); - System.Reflection.Emit.Label endConvert = il.DefineLabel (); - il.Emit (OpCodes.Dup); - il.Emit (OpCodes.Brfalse, emitNullStr); - il.Emit (OpCodes.Callvirt, CompilerServices.miObjToString); - il.Emit (OpCodes.Br, endConvert); - il.MarkLabel (emitNullStr); - il.Emit (OpCodes.Pop);//remove null string from stack - il.Emit (OpCodes.Ldstr, "");//replace with empty string - il.MarkLabel (endConvert); - }else if (origType.IsValueType) { - if (destType != origType) { - MethodInfo miIO = getImplicitOp (origType, destType); - if (miIO != null) { - System.Reflection.Emit.Label emitCreateDefault = il.DefineLabel (); - System.Reflection.Emit.Label emitContinue = il.DefineLabel (); - LocalBuilder lbStruct = il.DeclareLocal (origType); - il.Emit (OpCodes.Dup); - il.Emit (OpCodes.Brfalse, emitCreateDefault); - il.Emit (OpCodes.Unbox_Any, origType); - il.Emit (OpCodes.Br, emitContinue); - il.MarkLabel (emitCreateDefault); - il.Emit (OpCodes.Pop);//pop null value - il.Emit (OpCodes.Ldloca, lbStruct); - il.Emit (OpCodes.Initobj, origType); - il.Emit (OpCodes.Ldloc, lbStruct); - il.MarkLabel (emitContinue); - il.Emit (OpCodes.Call, miIO); - }else - il.Emit (OpCodes.Callvirt, CompilerServices.GetConvertMethod (destType)); - }else - il.Emit (OpCodes.Unbox_Any, destType);//TODO:double check this - } else { - if (destType.IsAssignableFrom(origType)) - il.Emit (OpCodes.Castclass, destType); - else { - //implicit conversion can't be defined from or to object base class, - //so we will check if object underlying type is one of the implicit converter of destType - if (origType == TObject) {//test all implicit converter to destType on obj - System.Reflection.Emit.Label emitTestNextImpOp; - System.Reflection.Emit.Label emitImpOpFound = il.DefineLabel (); - foreach (MethodInfo mi in destType.GetMethods(BindingFlags.Public|BindingFlags.Static)) { - if (mi.Name == "op_Implicit") { - if (mi.GetParameters () [0].ParameterType == destType) - continue; - emitTestNextImpOp = il.DefineLabel (); - il.Emit (OpCodes.Dup); - il.Emit (OpCodes.Isinst, mi.GetParameters () [0].ParameterType); - il.Emit (OpCodes.Brfalse, emitTestNextImpOp); - if (mi.GetParameters () [0].ParameterType.IsValueType) - il.Emit (OpCodes.Unbox_Any, mi.GetParameters () [0].ParameterType); - else - il.Emit (OpCodes.Isinst, mi.GetParameters () [0].ParameterType); - - il.Emit (OpCodes.Call, mi); - il.Emit (OpCodes.Br, emitImpOpFound); - - il.MarkLabel (emitTestNextImpOp); - } - } - //il.Emit (OpCodes.Br, emitImpOpNotFound); - il.MarkLabel (emitImpOpFound); - } else {//search both orig and dest types for implicit operators - MethodInfo miIO = getImplicitOp (origType, destType); - if (miIO != null) - il.Emit (OpCodes.Call, miIO); - } - } - } - } - /// <summary> - /// check type of current object on the stack and convert to dest type, - /// use loc_0 so store it as object!!! - /// </summary> - internal static void emitConvert(ILGenerator il, Type dstType){ - System.Reflection.Emit.Label endConvert = il.DefineLabel (); - System.Reflection.Emit.Label convert = il.DefineLabel (); - - il.Emit (OpCodes.Dup); - il.Emit (OpCodes.Isinst, dstType); - il.Emit (OpCodes.Brfalse, convert); - - if (dstType.IsValueType) - il.Emit (OpCodes.Unbox_Any, dstType); - else - il.Emit (OpCodes.Isinst, dstType); - il.Emit (OpCodes.Br, endConvert); - - il.MarkLabel (convert); - - if (dstType == typeof(string)) { - System.Reflection.Emit.Label emitNullStr = il.DefineLabel (); - il.Emit (OpCodes.Dup); - il.Emit (OpCodes.Brfalse, emitNullStr); - il.Emit (OpCodes.Callvirt, CompilerServices.miObjToString); - il.Emit (OpCodes.Br, endConvert); - il.MarkLabel (emitNullStr); - il.Emit (OpCodes.Pop);//remove null string from stack - il.Emit (OpCodes.Ldstr, "");//replace with empty string - } else if (dstType.IsPrimitive) { - //il.Emit (OpCodes.Unbox_Any, dstType); - il.Emit (OpCodes.Callvirt, CompilerServices.GetConvertMethod (dstType)); - } else if (dstType.IsValueType) { - il.Emit (OpCodes.Unbox_Any, dstType); - } else{ - il.Emit (OpCodes.Stloc_0); //save orig value in loc0 - //first check if not null - il.Emit (OpCodes.Ldloc_0); - il.Emit (OpCodes.Dup); - il.Emit (OpCodes.Brfalse, endConvert); - il.Emit (OpCodes.Callvirt, miGetType); - il.Emit (OpCodes.Ldtoken, dstType);//push destination property type for testing - il.Emit (OpCodes.Call, CompilerServices.miGetTypeFromHandle); - il.Emit (OpCodes.Call, miGetImplOp); - il.Emit (OpCodes.Dup); - convert = il.DefineLabel (); - il.Emit (OpCodes.Brtrue, convert); - il.Emit (OpCodes.Pop); - il.Emit (OpCodes.Ldloc_0); - il.Emit (OpCodes.Isinst, dstType); - il.Emit (OpCodes.Br, endConvert); - - il.MarkLabel (convert); - il.Emit (OpCodes.Ldnull);//null instance for invoke - il.Emit (OpCodes.Ldc_I4_1); - il.Emit(OpCodes.Newarr, CompilerServices.TObject); - il.Emit (OpCodes.Dup);//duplicate the array ref - il.Emit (OpCodes.Ldc_I4_0);//push the index 0 - il.Emit (OpCodes.Ldloc_0);//push the orig value to convert - il.Emit (OpCodes.Stelem, CompilerServices.TObject);//set the array element at index 0 - il.Emit (OpCodes.Callvirt, miMIInvoke); - } - - il.MarkLabel (endConvert); - } - - /// <summary> - /// Removes delegate from event handler by name - /// </summary> - static void removeEventHandlerByName(object instance, string eventName, string delegateName){ - Type t = instance.GetType (); - FieldInfo fiEvt = getEventHandlerField (t, eventName); - if (fiEvt == null) { - #if DEBUG_BINDING - Debug.WriteLine ("RemoveHandlerByName: Event '" + eventName + "' not found in " + instance); - #endif - return; - } - EventInfo eiEvt = t.GetEvent (eventName); - MulticastDelegate multiDel = fiEvt.GetValue (instance) as MulticastDelegate; - if (multiDel != null) { - foreach (Delegate d in multiDel.GetInvocationList()) { - if (d.Method.Name == delegateName) { - eiEvt.RemoveEventHandler (instance, d); - #if DEBUG_BINDING - Debug.WriteLine ("\t{0} handler removed in {1} for: {2}", d.Method.Name,instance, eventName); - #endif - } - } - } - } - /// <summary> - /// Removes delegate from event handler by searching for the object they are bond to - /// </summary> - static void removeEventHandlerByTarget(object instance, string eventName, object target){ - Type t = instance.GetType (); - FieldInfo fiEvt = getEventHandlerField (t, eventName); - EventInfo eiEvt = t.GetEvent (eventName); - MulticastDelegate multiDel = fiEvt.GetValue (instance) as MulticastDelegate; - if (multiDel != null) { - foreach (Delegate d in multiDel.GetInvocationList()) { - if (d.Target == target) { - eiEvt.RemoveEventHandler (instance, d); - #if DEBUG_BINDING - Debug.WriteLine ("\t{0} handler removed in {1} for: {2}", d.Method.Name,instance, eventName); - #endif - } - } - } - } - /// <summary> - /// create delegate helper - /// </summary> - static Delegate createDel(object instance, Type eventType, string method){ - Type t = instance.GetType (); - MethodInfo mi = t.GetMethod (method, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); - if (mi == null) { - Debug.WriteLine ("Handler Method '{0}' not found in '{1}'", method, t); - return null; - } - return Delegate.CreateDelegate (eventType, instance, mi); - } - - internal static Delegate compileDynEventHandler(EventInfo sourceEvent, string expression, NodeAddress currentNode = null){ - #if DEBUG_BINDING - Debug.WriteLine ("\tCompile Event {0}: {1}", sourceEvent.Name, expression); - #endif - - Type lopType = null; - - if (currentNode == null) - lopType = sourceEvent.DeclaringType; - else - lopType = currentNode.NodeType; - - #region Retrieve EventHandler parameter type - MethodInfo evtInvoke = sourceEvent.EventHandlerType.GetMethod ("Invoke"); - ParameterInfo [] evtParams = evtInvoke.GetParameters (); - Type handlerArgsType = evtParams [1].ParameterType; - #endregion - - Type [] args = { CompilerServices.TObject, handlerArgsType }; - DynamicMethod dm = new DynamicMethod ("dyn_eventHandler", - typeof(void), - args, true); - ILGenerator il = dm.GetILGenerator (256); - il.Emit (OpCodes.Nop); - - string [] srcLines = expression.Trim ().Split (new char [] { ';' }); - - foreach (string srcLine in srcLines) { - if (string.IsNullOrEmpty (srcLine)) - continue; - string [] operandes = srcLine.Trim ().Split (new char [] { '=' }); - if (operandes.Length != 2) //not an affectation - throw new NotSupportedException (); - - System.Reflection.Emit.Label cancel = il.DefineLabel (); - System.Reflection.Emit.Label cancelFinalSet = il.DefineLabel (); - System.Reflection.Emit.Label success = il.DefineLabel (); - - BindingMember lop = new BindingMember (operandes [0].Trim ()); - BindingMember rop = new BindingMember (operandes [1].Trim ()); - - il.Emit (OpCodes.Ldarg_0); //load sender ref onto the stack, the current node - - #region Left operande - PropertyInfo lopPI = null; - - //in dyn handler, no datasource binding, so single name in expression are also handled as current node property - if (lop.IsSingleName) - lopPI = lopType.GetProperty (lop.Tokens [0]); - else if (lop.IsCurrentNodeProperty) - lopPI = lopType.GetProperty (lop.Tokens [1]); - else - lop.emitGetTarget (il, cancel); - #endregion - - #region RIGHT OPERANDES - if (rop.IsStringConstant){ - il.Emit (OpCodes.Ldstr, rop.Tokens[0]); - lop.emitSetProperty (il); - }else if (rop.IsSingleName && rop.Tokens[0] == "this"){ - il.Emit (OpCodes.Ldarg_0); //load sender ref onto the stack, the current node - lop.emitSetProperty (il); - }else if (rop.LevelsUp ==0 && !string.IsNullOrEmpty(rop.Tokens[0])) {//parsable constant depending on lop type - //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]); - if (lopPI == null) - throw new NotSupportedException (); - } - - MethodInfo lopParseMi = CompilerServices.miParseEnum; - if (lopPI.PropertyType.IsEnum){ - //load type of enum - il.Emit(OpCodes.Ldtoken, lopPI.PropertyType); - il.Emit(OpCodes.Call, CompilerServices.miGetTypeFromHandle); - //load enum value name - il.Emit (OpCodes.Ldstr, operandes [1].Trim ()); - //load false - il.Emit (OpCodes.Ldc_I4_0); - }else{ - lopParseMi = lopPI.PropertyType.GetMethod ("Parse"); - if (lopParseMi == null) - throw new Exception (string.Format - ("IML: no static 'Parse' method found in: {0}", lopPI.PropertyType.Name)); - - il.Emit (OpCodes.Ldstr, operandes [1].Trim ()); - } - il.Emit (OpCodes.Callvirt, lopParseMi); - il.Emit (OpCodes.Unbox_Any, lopPI.PropertyType); - //emit left operand assignment - il.Emit (OpCodes.Callvirt, lopPI.GetSetMethod()); - } else {//tree parsing and propert gets - il.Emit (OpCodes.Ldarg_0); //load sender ref onto the stack, the current node - - rop.emitGetTarget (il, cancelFinalSet); - rop.emitGetProperty (il, cancelFinalSet); - lop.emitSetProperty (il); - } - #endregion - - il.Emit (OpCodes.Br, success); - - il.MarkLabel (cancelFinalSet); - il.Emit (OpCodes.Pop); //pop null MemberInfo on the stack causing cancelation - il.MarkLabel (cancel); - il.Emit (OpCodes.Pop); //pop null instance on the stack causing cancelation - il.MarkLabel (success); - } - - il.Emit (OpCodes.Ret); - - return dm.CreateDelegate (sourceEvent.EventHandlerType); - } - - /// <summary> - /// MSIL helper, go n levels up - /// </summary> - /// <returns><c>true</c>, if logical parents are not null</returns> - /// <param name="instance">Start Instance</param> - /// <param name="levelCount">Levels to go upward</param> - internal static ILayoutable goUpNbLevels(ILayoutable instance, int levelCount){ - ILayoutable tmp = instance; - int i = 0; - while (tmp != null && i < levelCount) { - tmp = tmp.LogicalParent; - i++; - } - return tmp; - } - /// <summary> - /// Splits expression on semicolon but ignore those between accolades - /// </summary> - internal static string[] splitOnSemiColumnOutsideAccolades (string expression){ - List<String> exps = new List<string>(); - int accCount = 0; - int expPtr = 0; - for (int c = 0; c < expression.Length; c++) { - switch (expression[c]){ - case '{': - accCount++; - break; - case '}': - accCount--; - break; - case ';': - if (accCount > 0) - break; - exps.Add(expression.Substring(expPtr, c - expPtr - 1)); - expPtr = c + 1; - break; - } - } - if (exps.Count == 0) - exps.Add(expression); - return exps.ToArray (); - } - /// <summary> - /// Try to get the type named strDataType, search first in crow assembly then in - /// entry assembly. - /// </summary> - /// <returns>the corresponding type object if found</returns> - /// <param name="strDataType">type name</param> - internal static Type tryGetType (string strDataType){ - Type dataType = Type.GetType(strDataType); - if (dataType != null) - return dataType; - Assembly a = Assembly.GetEntryAssembly (); - foreach (Type expT in a.GetExportedTypes ()) { - if (expT.Name == strDataType) - return dataType; - } - return null; - } - - internal static object getDataTypeAndFetch (object data, string fetchMethod){ - Type dataType = data.GetType(); - MethodInfo miGetDatas = dataType.GetMethod (fetchMethod, new Type[] {}); - if (miGetDatas == null) - miGetDatas = CompilerServices.SearchExtMethod (dataType, fetchMethod); - - if (miGetDatas == null) {//in last resort, search among properties - PropertyInfo piDatas = dataType.GetProperty (fetchMethod); - if (piDatas == null) { - FieldInfo fiDatas = dataType.GetField (fetchMethod); - if (fiDatas == null)//and among fields - throw new Exception ("Fetch data member not found in ItemTemplate: " + fetchMethod); - return fiDatas.GetValue (data); - } - miGetDatas = piDatas.GetGetMethod (); - if (miGetDatas == null) - throw new Exception ("Read only property for fetching data in ItemTemplate: " + fetchMethod); - } - object tmp = miGetDatas.Invoke (data, null); - return tmp; - } - } -} - diff --git a/src/Configuration.cs b/src/Configuration.cs deleted file mode 100644 index a6328c0a..00000000 --- a/src/Configuration.cs +++ /dev/null @@ -1,194 +0,0 @@ -// -// Configuration.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Reflection; -using System.IO; -using System.Collections.Generic; -using System.Threading; - -namespace Crow -{ - /// <summary> - /// single element of configuration - /// </summary> - public class ConfigItem { - Type type; - internal object curVal; - bool parsingNeeded = false; - public ConfigItem(object newVal){ - curVal = newVal; - } - public ConfigItem(string newVal){ - curVal = newVal; - parsingNeeded = true; - } - public T GetValue<T>(){ - if (type == null) - type = typeof(T); - if (parsingNeeded) { - MethodInfo miParse = type.GetMethod ("Parse", new Type[] {typeof(string)}); - if (miParse != null) - curVal = miParse.Invoke (null, new object[]{ curVal }); - parsingNeeded = false; - } - return (T)Convert.ChangeType (curVal, type); - } - public void Set(object value){ - curVal = value; - } - } - /// <summary> - /// Application wide Configuration store utility - /// - /// configuration files are automatically stored in **_user/.config/appname/app.config_** on close and every minutes - /// if some items have changed. - /// New items are automaticaly added on first use. Configuration class expose one templated Get and one Templated Set, so - /// creating, storing and retrieving config items is simple as: - /// - /// ```csharp\n - /// //storing\n - /// Configuration.Global.Set ("Option1", 42);\n - /// //loading\n - /// int op1 = Configuration.Global.Get<int> ("Option1");\n - /// ```\n - /// </summary> - /// - /// **.config** file are simple text files with per line, a key/value pair of the form `option=value`. Keys have to be unique - /// in the application scope. - /// - /// When running the application for the first time, some default options may be necessary. Their can be defined - /// in a special embedded resource text file with the key '**appname.default.config**' - public class Configuration - { - volatile bool isDirty = false; - string configPath; - Dictionary<string, ConfigItem> items = new Dictionary<string, ConfigItem> (); - static Configuration globalConfig; - - public static Configuration Global { get { return globalConfig; } } - - public Configuration (string path, Stream defaultConf = null) { - configPath = path; - if (File.Exists (configPath)) { - using (Stream s = new FileStream (configPath, FileMode.Open)) - load (s); - - } else if (defaultConf != null) { - load (defaultConf); - } - startSavingThread (); - } - static Configuration () - { - string configRoot = - Path.Combine( - Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), - ".config"); - - Assembly a = Assembly.GetEntryAssembly (); - string appName = a.GetName().Name; - string globalConfigPath = Path.Combine (configRoot, appName); - - if (!Directory.Exists (globalConfigPath)) - Directory.CreateDirectory (globalConfigPath); - - globalConfigPath = Path.Combine (globalConfigPath, "global.config"); - - string defaultConfigResID = appName + ".default.config"; - foreach (string resIds in a.GetManifestResourceNames()) { - if (string.Equals (defaultConfigResID, resIds, StringComparison.OrdinalIgnoreCase)) { - using (Stream s = a.GetManifestResourceStream (defaultConfigResID)) - globalConfig = new Configuration (globalConfigPath, s); - return; - } - } - globalConfig = new Configuration (globalConfigPath); - } - void startSavingThread(){ - Thread t = new Thread (savingThread); - t.IsBackground = true; - t.Start (); - } - void savingThread(){ - while(true){ - if (isDirty) { - save (); - isDirty = false; - } - Thread.Sleep (1000); - } - } - /// <summary> - /// retrive the value of the configuration key given in parameter - /// </summary> - /// <param name="key">option name</param> - public T Get<T>(string key) - { - return !items.ContainsKey (key) ? default(T) : items [key].GetValue<T> (); - } - /// <summary> - /// store the value of the configuration key given in parameter - /// </summary> - /// <param name="key">option name</param> - /// <param name="value">value for that option</param> - public void Set<T>(string key, T value) - { - if (!items.ContainsKey (key)) { - lock(items) - items[key] = new ConfigItem (value); - }else - items[key].Set (value); - isDirty = true; - } - void save(){ - using (Stream s = new FileStream(configPath,FileMode.Create)){ - using (StreamWriter sw = new StreamWriter (s)) { - lock (items) { - foreach (string key in items.Keys) { - if (items [key].curVal != null) - sw.WriteLine (key + "=" + (string)items [key].curVal.ToString ()); - } - } - } - } - } - void load(Stream s){ - using (StreamReader sr = new StreamReader (s)) { - while (!sr.EndOfStream) { - string l = sr.ReadLine(); - if (string.IsNullOrEmpty (l.Trim ())) - continue; - string[] tmp = l.Trim ().Split ('='); - if (tmp.Length != 2) - continue; - items[tmp [0].Trim ()] = new ConfigItem(tmp [1].Trim ()); - } - } - } - } -} - diff --git a/src/CrowThread.cs b/src/CrowThread.cs deleted file mode 100644 index a1b4c38e..00000000 --- a/src/CrowThread.cs +++ /dev/null @@ -1,65 +0,0 @@ -// -// CrowThread.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Threading; - -namespace Crow -{ - /// <summary> - /// Thread monitored by current interface with Finished event when state==Stopped - /// </summary> - public class CrowThread { - public bool cancelRequested = false; - Thread thread; - public event EventHandler Finished; - public GraphicObject Host; - public CrowThread (GraphicObject host, ThreadStart start){ - thread = new Thread (start); - thread.IsBackground = true; - Host = host; - lock (Host.IFace.CrowThreads) - Host.IFace.CrowThreads.Add (this); - } - public void CheckState(){ - if (thread.ThreadState != ThreadState.Stopped) - return; - Finished.Raise (Host, null); - lock (Host.IFace.CrowThreads) - Host.IFace.CrowThreads.Remove (this); - } - public void Start() { thread.Start();} - public void Cancel(){ - if (thread.IsAlive & !cancelRequested){ - cancelRequested = true; - thread.Join (); - } - lock (Host.IFace.CrowThreads) - Host.IFace.CrowThreads.Remove (this); - } - } -} - diff --git a/src/DragDropEventArgs.cs b/src/DragDropEventArgs.cs deleted file mode 100644 index 428a7363..00000000 --- a/src/DragDropEventArgs.cs +++ /dev/null @@ -1,55 +0,0 @@ -// -// LayoutingEventArgs.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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; - -namespace Crow -{ - public class DragDropEventArgs: EventArgs - { - /// <summary> - /// Source of the drag and drop operation - /// </summary> - public GraphicObject DragSource; - /// <summary> - /// Target of the drag and drop operation - /// </summary> - public GraphicObject DropTarget; - - //public DragDropEventArgs (GraphicObject source, GraphicObject target = null) : base() - public DragDropEventArgs (GraphicObject source = null, GraphicObject target = null) : base() - { - DragSource = source; - DropTarget = target; - } - - public override string ToString () - { - return string.Format ("{0} => {1}", DragSource,DropTarget); - } - } -} - diff --git a/src/DynAttribute.cs b/src/DynAttribute.cs deleted file mode 100644 index 174eec2e..00000000 --- a/src/DynAttribute.cs +++ /dev/null @@ -1,40 +0,0 @@ -// -// DynAttribute.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Linq; -using System.Text; - -namespace Crow -{ - public class DynAttribute - { - public GraphicObject Source; - public string MemberName; - public String Value; - } -} diff --git a/src/Enums.cs b/src/Enums.cs deleted file mode 100644 index 8b90d6ea..00000000 --- a/src/Enums.cs +++ /dev/null @@ -1,65 +0,0 @@ -// -// Enums.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Linq; -using System.Text; - -namespace Crow -{ - public enum Orientation - { - Horizontal, - Vertical - } - - public enum Alignment - { - Top = 0x01, - Left = 0x02, - TopLeft = 0x03, - Right = 0x04, - TopRight = 0x05, - Bottom = 0x08, - BottomLeft = 0x0a, - BottomRight = 0x0c, - Center = 0x10, - Undefined = 0x40 - } - public enum HorizontalAlignment - { - Left, - Right, - Center, - } - public enum VerticalAlignment - { - Top, - Bottom, - Center, - } -} diff --git a/src/ExtensionsMethods.cs b/src/ExtensionsMethods.cs deleted file mode 100644 index 340a8ceb..00000000 --- a/src/ExtensionsMethods.cs +++ /dev/null @@ -1,224 +0,0 @@ -// -// ExtensionsMethods.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Linq.Expressions; - -namespace Crow -{ - public static class ExtensionsMethods - { - #region Cairo extensions - - public static void Rectangle(this Cairo.Context ctx, Rectangle r, double stroke = 0.0) - { - if (stroke > 0.0) { - ctx.LineWidth = stroke; - double shw = stroke / 2.0; - ctx.Rectangle (r.X + shw, r.Y + shw, r.Width - stroke, r.Height - stroke); - ctx.Stroke (); - }else - ctx.Rectangle (r.X, r.Y, r.Width, r.Height); - } - public static double GetLength(this Cairo.PointD p){ - return Math.Sqrt (Math.Pow (p.X, 2) + Math.Pow (p.Y, 2)); - } - public static Cairo.PointD GetPerp(this Cairo.PointD p){ - return new Cairo.PointD(-p.Y, p.X); - } - public static Cairo.PointD GetNormalized(this Cairo.PointD p){ - double length = p.GetLength(); - p.X /= length; - p.Y /= length; - return p; - } - public static Cairo.PointD Substract(this Cairo.PointD p1, Cairo.PointD p2){ - return new Cairo.PointD(p1.X - p2.X, p1.Y - p2.Y); - } - public static Cairo.PointD Divide(this Cairo.PointD p1, double d){ - return new Cairo.PointD(p1.X / d, p1.Y / d); - } - public static Cairo.PointD Add(this Cairo.PointD p1, Cairo.PointD p2){ - return new Cairo.PointD(p1.X + p2.X, p1.Y + p2.Y); - } - public static Cairo.PointD Multiply(this Cairo.PointD p1, double v){ - return new Cairo.PointD(p1.X * v, p1.Y * v); - } - public static void DrawCote(this Cairo.Context ctx, Cairo.PointD p1, Cairo.PointD p2, - double stroke = 1.0, bool fill = false, double arrowWidth = 3.0, double arrowLength = 7.0) - { - Cairo.PointD vDir = p2.Substract(p1); - vDir = vDir.GetNormalized (); - Cairo.PointD vPerp = vDir.GetPerp (); - - Cairo.PointD pA0 = p1.Add(vDir.Multiply(arrowLength)); - Cairo.PointD pA1 = p2.Substract(vDir.Multiply(arrowLength)); - - Cairo.PointD vA = vPerp.Multiply (arrowWidth); - - ctx.MoveTo (p1); - ctx.LineTo (pA0.Add (vA)); - if (fill) - ctx.LineTo (pA0.Substract (vA)); - else - ctx.MoveTo (pA0.Substract (vA)); - - ctx.LineTo (p1); - - ctx.MoveTo (p2); - ctx.LineTo (pA1.Add (vA)); - if (fill) - ctx.LineTo (pA1.Substract (vA)); - else - ctx.MoveTo (pA1.Substract (vA)); - ctx.LineTo (p2); - - if (fill) - ctx.Fill (); - - ctx.MoveTo (p1); - ctx.LineTo (p2); - ctx.LineWidth = stroke; - ctx.Stroke (); - } - public static void DrawCoteInverse(this Cairo.Context ctx, Cairo.PointD p1, Cairo.PointD p2, - double stroke = 1.0, bool fill = false, double arrowWidth = 3.0, double arrowLength = 7.0) - { - Cairo.PointD vDir = p2.Substract(p1); - vDir = vDir.GetNormalized (); - Cairo.PointD vPerp = vDir.GetPerp (); - - Cairo.PointD pA0 = p1.Add(vDir.Multiply(arrowLength)); - Cairo.PointD pA1 = p2.Substract(vDir.Multiply(arrowLength)); - - Cairo.PointD vA = vPerp.Multiply (arrowWidth); - - ctx.MoveTo (p1.Add (vA)); - ctx.LineTo (pA0); - ctx.LineTo (p1.Substract (vA)); - if (fill) - ctx.LineTo (p1.Add (vA)); - - ctx.MoveTo (p2.Add (vA)); - ctx.LineTo (pA1); - ctx.LineTo (p2.Substract (vA)); - - if (fill) { - ctx.LineTo (p2.Add (vA)); - ctx.Fill (); - } - - ctx.MoveTo (pA0); - ctx.LineTo (pA1); - ctx.LineWidth = stroke; - ctx.Stroke (); - } - public static void DrawCoteFixed(this Cairo.Context ctx, Cairo.PointD p1, Cairo.PointD p2, - double stroke = 1.0, double coteWidth = 3.0) - { - Cairo.PointD vDir = p2.Substract(p1); - vDir = vDir.GetNormalized (); - Cairo.PointD vPerp = vDir.GetPerp (); - Cairo.PointD vA = vPerp.Multiply (coteWidth); - - ctx.MoveTo (p1.Add (vA)); - ctx.LineTo (p1.Substract (vA)); - ctx.MoveTo (p2.Add (vA)); - ctx.LineTo (p2.Substract (vA)); - ctx.MoveTo (p1); - ctx.LineTo (p2); - ctx.LineWidth = stroke; - ctx.Stroke (); - } - public static void SetSourceColor(this Cairo.Context ctx, Color c) - { - ctx.SetSourceRGBA(c.R,c.G,c.B,c.A); - } - public static void AddColorStop(this Cairo.Gradient grad, double offset, Color c) - { - grad.AddColorStop (offset, new Cairo.Color (c.R, c.G, c.B, c.A)); - } - #endregion - - public static Orientation GetOrientation(this Alignment a){ - return (a==Alignment.Left) ||(a==Alignment.Right) ? Orientation.Horizontal : Orientation.Vertical; - } - public static Alignment GetOpposite(this Alignment a){ - switch (a) { - case Alignment.Left: - return Alignment.Right; - case Alignment.Right: - return Alignment.Left; - case Alignment.Top: - return Alignment.Bottom; - case Alignment.Bottom: - return Alignment.Top; - case Alignment.TopLeft: - return Alignment.BottomRight; - case Alignment.TopRight: - return Alignment.BottomLeft; - case Alignment.BottomLeft: - return Alignment.TopRight; - case Alignment.BottomRight: - return Alignment.TopLeft; - } - return Alignment.Center; - } - public static void Raise(this EventHandler handler, object sender, EventArgs e) - { - if(handler != null) - { - handler(sender, e); - } - } - public static void Raise<T>(this EventHandler<T> handler, object sender, T e) - { - if(handler != null) - { - handler(sender, e); - } - } - public static byte[] GetBytes(this string str) - { - byte[] bytes = new byte[str.Length * sizeof(char)]; - System.Buffer.BlockCopy(str.ToCharArray(), 0, bytes, 0, bytes.Length); - return bytes; - } - public static bool IsWhiteSpaceOrNewLine (this char c) - { - return c == '\t' || c == '\r' || c == '\n' || char.IsWhiteSpace (c); - } - public static object GetDefaultValue(this object obj) - { - Type t = obj.GetType (); - if (t.IsValueType) - return Activator.CreateInstance (t); - - return null; - } - } -} - diff --git a/src/Fill/Fill.cs b/src/Fill/Fill.cs deleted file mode 100644 index d98e47cf..00000000 --- a/src/Fill/Fill.cs +++ /dev/null @@ -1,70 +0,0 @@ -// -// Fill.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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 Cairo; - -namespace Crow -{ - /// <summary> - /// base class for drawing content to paint on backend - /// </summary> - public abstract class Fill - { - /// <summary> - /// set content of fill as source for drawing operations on the backend context - /// </summary> - /// <param name="ctx">backend context</param> - /// <param name="bounds">paint operation bounding box, unused for SolidColor</param> - public abstract void SetAsSource (Context ctx, Rectangle bounds = default(Rectangle)); - public static object Parse (string s){ - if (string.IsNullOrEmpty (s)) - return null; - if (s.Substring (1).StartsWith ("gradient")) - return (Gradient)Gradient.Parse (s); - if (s.EndsWith (".svg", true, System.Globalization.CultureInfo.InvariantCulture)) - return SvgPicture.Parse (s); - if (s.EndsWith (".png", true, System.Globalization.CultureInfo.InvariantCulture) || - s.EndsWith (".jpg", true, System.Globalization.CultureInfo.InvariantCulture) || - s.EndsWith (".jpeg", true, System.Globalization.CultureInfo.InvariantCulture) || - s.EndsWith (".bmp", true, System.Globalization.CultureInfo.InvariantCulture) || - s.EndsWith (".gif", true, System.Globalization.CultureInfo.InvariantCulture)) - return BmpPicture.Parse (s); - - return (SolidColor)SolidColor.Parse (s); - } - public static implicit operator Color(Fill c){ - SolidColor sc = c as SolidColor; - return sc == null ? default(Color) : sc.color; - } - public static implicit operator Fill(Color c){ - return new SolidColor (c); - } - - } -} - diff --git a/src/Font.cs b/src/Font.cs deleted file mode 100644 index bab2c853..00000000 --- a/src/Font.cs +++ /dev/null @@ -1,130 +0,0 @@ -// -// Font.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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 Cairo; - -namespace Crow -{ - public enum FontStyle - { - Normal, - Bold, - Italic, - Underlined - } - public class Font - { - #region CTOR - public Font () - { - } - #endregion - - string _name = "droid"; - int _size = 12; - FontStyle _style = FontStyle.Normal; - - public string Name { - get { return _name; } - set { _name = value; } - } - public int Size { - get { return _size; } - set { _size = value; } - } - public FontStyle Style { - get { return _style; } - set { _style = value; } - } - - public FontSlant Slant { - get{ - switch (Style) { - case FontStyle.Normal: - default: - return FontSlant.Normal; - case FontStyle.Italic: - return FontSlant.Italic; - } - } - } - public FontWeight Wheight { - get{ - switch (Style) { - case FontStyle.Bold: - return FontWeight.Bold; - case FontStyle.Italic: - case FontStyle.Normal: - default: - return FontWeight.Normal; - } - } - } - - #region Operators - public static implicit operator string(Font c) - { - return c.ToString(); - } - public static implicit operator Font(string s) - { - Font f = new Font (); - - if (!string.IsNullOrEmpty (s)) { - string[] c = s.TrimStart().TrimEnd().Split (new char[] { ',' }); - - if (c.Length == 2) - f.Size = int.Parse (c [1].TrimStart()); - - string[] n = c [0].TrimEnd().Split (new char[] { ' ' }); - - f.Name = n [0]; - - if (n.Length > 1) - f.Style = (FontStyle)Enum.Parse (typeof(FontStyle), n[n.Length-1], true); - } - - return f; - } - #endregion - - 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); - - } - - public static object Parse(string s) - { - return (Font)s; - } - } -} - diff --git a/src/Gradient.cs b/src/Gradient.cs deleted file mode 100644 index 0806e885..00000000 --- a/src/Gradient.cs +++ /dev/null @@ -1,137 +0,0 @@ -// -// Gradient.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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 Cairo; - -namespace Crow -{ - public class Gradient : Fill - { - public enum Type - { - Vertical, - Horizontal, - Oblic, - Radial - } - public class ColorStop - { - public double Offset; - public Color Color; - - public ColorStop(double offset, Color color){ - Offset = offset; - Color = color; - } - public static object Parse(string s) - { - if (string.IsNullOrEmpty (s)) - return null; - - string[] parts = s.Trim ().Split (':'); - - if (parts.Length > 2) - throw new Exception ("too many parameters in color stop: " + s); - - if (parts.Length == 2) - return new ColorStop (double.Parse (parts [0]), (Color)parts [1]); - - return new ColorStop (-1, (Color)parts [0]); - } - } - public Gradient.Type GradientType = Type.Vertical; -// public double x0; -// public double y0; -// public double x1; -// public double y1; -// public double Radius1; -// public double Radius2; - public List<ColorStop> Stops = new List<ColorStop>(); - public Gradient(Gradient.Type _type) - { - GradientType = _type; - } - - #region implemented abstract members of Fill - - public override void SetAsSource (Context ctx, Rectangle bounds = default(Rectangle)) - { - Cairo.Gradient grad = null; - switch (GradientType) { - case Type.Vertical: - grad = new Cairo.LinearGradient (bounds.Left, bounds.Top, bounds.Left, bounds.Bottom); - break; - case Type.Horizontal: - grad = new Cairo.LinearGradient (bounds.Left, bounds.Top, bounds.Right, bounds.Top); - break; - case Type.Oblic: - grad = new Cairo.LinearGradient (bounds.Left, bounds.Top, bounds.Right, bounds.Bottom); - break; - case Type.Radial: - throw new NotImplementedException (); - } - - foreach (ColorStop cs in Stops) - grad.AddColorStop (cs.Offset, cs.Color); - - ctx.SetSource (grad); - grad.Dispose (); - } - #endregion - - public static object Parse(string s) - { - if (string.IsNullOrEmpty (s)) - return Color.White; - - Crow.Gradient tmp; - - string[] stops = s.Trim ().Split ('|'); - - switch (stops[0].Trim()) { - case "vgradient": - tmp = new Gradient (Type.Vertical); - break; - case "hgradient": - tmp = new Gradient (Type.Horizontal); - break; - case "ogradient": - tmp = new Gradient (Type.Oblic); - break; - default: - throw new Exception ("Unknown gradient type: " + stops [0]); - } - - for (int i = 1; i < stops.Length; i++) - tmp.Stops.Add((ColorStop)ColorStop.Parse(stops[i])); - - return tmp; - } - } -} - diff --git a/src/GraphicObjects/Border.cs b/src/GraphicObjects/Border.cs deleted file mode 100644 index adeb32e7..00000000 --- a/src/GraphicObjects/Border.cs +++ /dev/null @@ -1,273 +0,0 @@ -// -// Border.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Xml.Serialization; -using System.ComponentModel; -using System.Diagnostics; -using Cairo; - -namespace Crow -{ - /// <summary> - /// provide an easy way to get 3d border for buttons - /// </summary> - public enum BorderStyle { - Normal, - Raised, - Sunken - }; - - /// <summary> - /// simple container with border - /// </summary> - public class Border : Container - { - #region CTOR - protected Border () : base(){} - public Border (Interface iface) : base(iface){} - #endregion - - #region private fields - int _borderWidth; - BorderStyle _borderStyle; - Fill raisedColor = Color.Gray; - Fill sunkenColor = Color.DimGray; - #endregion - - #region public properties - /// <summary> - /// use to define the colors of the 3d border - /// </summary> - [XmlAttributeAttribute] - public virtual Fill RaisedColor { - get { return raisedColor; } - set { - if (raisedColor == value) - return; - raisedColor = value; - NotifyValueChanged ("RaisedColor", raisedColor); - RegisterForRedraw (); - } - } - /// <summary> - /// use to define the colors of the 3d border - /// </summary> - [XmlAttributeAttribute] - public virtual Fill SunkenColor { - get { return sunkenColor; } - set { - if (sunkenColor == value) - return; - sunkenColor = value; - NotifyValueChanged ("SunkenColor", sunkenColor); - RegisterForRedraw (); - } - } - /// <summary> - /// border width in pixels - /// </summary> - [XmlAttributeAttribute()][DefaultValue(1)] - public virtual int BorderWidth { - get { return _borderWidth; } - set { - _borderWidth = value; - RegisterForGraphicUpdate (); - } - } - /// <summary> - /// allow 3d border effects - /// </summary> - [XmlAttributeAttribute][DefaultValue(BorderStyle.Normal)] - public virtual BorderStyle BorderStyle { - get { return _borderStyle; } - set { - if (_borderStyle == value) - return; - _borderStyle = value; - RegisterForGraphicUpdate (); - } - } - #endregion - - #region GraphicObject override - [XmlIgnore]public override Rectangle ClientRectangle { - get { - Rectangle cb = base.ClientRectangle; - cb.Inflate (- BorderWidth); - return cb; - } - } - - protected override int measureRawSize (LayoutingType lt) - { - int tmp = base.measureRawSize (lt); - return tmp < 0 ? tmp : tmp + 2 * BorderWidth; - } - protected override void onDraw (Context gr) - { - drawborder2 (gr); - - gr.Save (); - if (ClipToClientRect) { - //clip to client zone - CairoHelpers.CairoRectangle (gr, ClientRectangle,Math.Max(0.0, CornerRadius-Margin)); - gr.Clip (); - } - - if (child != null) - child.Paint (ref gr); - gr.Restore (); - } - void drawborder2(Context gr){ - Rectangle rBack = new Rectangle (Slot.Size); - - //rBack.Inflate (-Margin); - // if (BorderWidth > 0) - // rBack.Inflate (-BorderWidth / 2); - - Background.SetAsSource (gr, rBack); - CairoHelpers.CairoRectangle(gr, rBack, CornerRadius); - gr.Fill (); - - - if (BorderStyle == BorderStyle.Normal) { - if (BorderWidth > 0) { - Foreground.SetAsSource (gr, rBack); - CairoHelpers.CairoRectangle (gr, rBack, CornerRadius, BorderWidth); - } - } else { - gr.LineWidth = 1.0; - if (CornerRadius > 0.0) { - double radius = CornerRadius; - if ((radius > rBack.Height / 2.0) || (radius > rBack.Width / 2.0)) - radius = Math.Min (rBack.Height / 2.0, rBack.Width / 2.0); - gr.SetSourceColor (sunkenColor); - gr.MoveTo (0.5 + rBack.Left, -0.5 + rBack.Bottom - radius); - gr.ArcNegative (0.5 + rBack.Left + radius, -0.5 + rBack.Bottom - radius, radius, Math.PI, Math.PI * 0.75); - gr.MoveTo (0.5 + rBack.Left, -0.5 + rBack.Bottom - radius); - gr.LineTo (0.5 + rBack.Left, 0.5 + rBack.Top + radius); - gr.Arc (0.5 + rBack.Left + radius, 0.5 + rBack.Top + radius, radius, Math.PI, Math.PI * 1.5); - gr.LineTo (-0.5 + rBack.Right - radius, 0.5 + rBack.Top); - gr.Arc (-0.5 + rBack.Right - radius, 0.5 + rBack.Top + radius, radius, Math.PI * 1.5, Math.PI * 1.75); - gr.Stroke (); - if (BorderStyle == BorderStyle.Raised) { - gr.MoveTo (-1.5 + rBack.Right, 1.5 + rBack.Top + radius); - gr.ArcNegative (-0.5 + rBack.Right - radius, 0.5 + rBack.Top + radius, radius - 1.0, 0, -Math.PI * 0.25); - gr.MoveTo (-1.5 + rBack.Right, 1.5 + rBack.Top + radius); - gr.LineTo (-1.5 + rBack.Right, -1.5 + rBack.Bottom - radius); - gr.Arc (-0.5 + rBack.Right - radius, -0.5 + rBack.Bottom - radius, radius - 1.0, 0, Math.PI / 2.0); - gr.LineTo (1.5 + rBack.Left + radius, -1.5 + rBack.Bottom); - gr.Arc (0.5 + rBack.Left + radius, -0.5 + rBack.Bottom - radius, radius - 1.0, Math.PI / 2.0, Math.PI * 0.75); - gr.Stroke (); - - gr.SetSourceColor (raisedColor); - gr.MoveTo (1.5 + rBack.Left, -1.5 + rBack.Bottom - radius); - gr.ArcNegative (0.5 + rBack.Left + radius, -0.5 + rBack.Bottom - radius, radius - 1.0, Math.PI, Math.PI * 0.75); - gr.MoveTo (1.5 + rBack.Left, -1.5 + rBack.Bottom - radius); - gr.LineTo (1.5 + rBack.Left, 1.5 + rBack.Top + radius); - gr.Arc (0.5 + rBack.Left + radius, 0.5 + rBack.Top + radius, radius - 1.0, Math.PI, Math.PI * 1.5); - gr.LineTo (-1.5 + rBack.Right - radius, 1.5 + rBack.Top); - gr.Arc (-0.5 + rBack.Right - radius, 0.5 + rBack.Top + radius, radius - 1.0, Math.PI * 1.5, Math.PI * 1.75); - } else { - gr.Stroke (); - gr.SetSourceColor (raisedColor); - } - gr.MoveTo (-0.5 + rBack.Right, 0.5 + rBack.Top + radius); - gr.ArcNegative (-0.5 + rBack.Right - radius, 0.5 + rBack.Top + radius, radius, 0, -Math.PI * 0.25); - gr.MoveTo (-0.5 + rBack.Right, 0.5 + rBack.Top + radius); - gr.LineTo (-0.5 + rBack.Right, -0.5 + rBack.Bottom - radius); - gr.Arc (-0.5 + rBack.Right - radius, -0.5 + rBack.Bottom - radius, radius, 0, Math.PI / 2.0); - gr.LineTo (0.5 + rBack.Left + radius, -0.5 + rBack.Bottom); - gr.Arc (0.5 + rBack.Left + radius, -0.5 + rBack.Bottom - radius, radius, Math.PI / 2.0, Math.PI * 0.75); - gr.Stroke (); - } else { - gr.SetSourceColor (sunkenColor); - gr.MoveTo (0.5 + rBack.Left, rBack.Bottom); - gr.LineTo (0.5 + rBack.Left, 0.5 + rBack.Y); - gr.LineTo (rBack.Right, 0.5 + rBack.Y); - if (BorderStyle == BorderStyle.Raised) { - gr.MoveTo (-1.5 + rBack.Right, 2.0 + rBack.Y); - gr.LineTo (-1.5 + rBack.Right, -1.5 + rBack.Bottom); - gr.LineTo (2.0 + rBack.Left, -1.5 + rBack.Bottom); - gr.Stroke (); - gr.SetSourceColor (raisedColor); - gr.MoveTo (1.5 + rBack.Left, -1.0 + rBack.Bottom); - gr.LineTo (1.5 + rBack.Left, 1.5 + rBack.Y); - gr.LineTo (rBack.Right, 1.5 + rBack.Y); - } else { - gr.Stroke (); - gr.SetSourceColor (raisedColor); - } - gr.MoveTo (-0.5 + rBack.Right, 1.5 + rBack.Y); - gr.LineTo (-0.5 + rBack.Right, -0.5 + rBack.Bottom); - gr.LineTo (1.0 + rBack.Left, -0.5 + rBack.Bottom); - gr.Stroke (); - } - } - } - void drawborder1(Context gr){ - Rectangle rBack = new Rectangle (Slot.Size); - - //rBack.Inflate (-Margin); - // if (BorderWidth > 0) - // rBack.Inflate (-BorderWidth / 2); - - Background.SetAsSource (gr, rBack); - CairoHelpers.CairoRectangle(gr, rBack, CornerRadius); - gr.Fill (); - - double bw = _borderWidth; - double crad = CornerRadius; - - if (bw > 0) { - if (BorderStyle == BorderStyle.Normal) - Foreground.SetAsSource (gr, rBack); - else { - if (BorderStyle == BorderStyle.Sunken) - gr.SetSourceColor (raisedColor); - else - gr.SetSourceColor (sunkenColor); - - CairoHelpers.CairoRectangle (gr, rBack, crad, bw); - - if (BorderStyle == BorderStyle.Sunken) - gr.SetSourceColor (sunkenColor); - else - gr.SetSourceColor (raisedColor); - - bw /= 2.0; - rBack.Width -= (int)Math.Round(bw); - rBack.Height -= (int)Math.Round(bw); - } - - CairoHelpers.CairoRectangle (gr, rBack, crad, bw); - } - } - #endregion - } -} - diff --git a/src/GraphicObjects/Button.cs b/src/GraphicObjects/Button.cs deleted file mode 100644 index 8b60dcb9..00000000 --- a/src/GraphicObjects/Button.cs +++ /dev/null @@ -1,108 +0,0 @@ -// -// Button.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Linq; -using System.Text; -//using OpenTK.Graphics.OpenGL; - -using System.Diagnostics; - -using System.Xml.Serialization; -using Cairo; -using System.ComponentModel; - -namespace Crow -{ - /// <summary> - /// templated button control - /// </summary> - public class Button : TemplatedContainer - { - #region CTOR - protected Button() : base() {} - public Button (Interface iface) : base(iface){} - #endregion - - string image; - bool isPressed; - - public event EventHandler Pressed; - public event EventHandler Released; - - #region GraphicObject Overrides - public override void onMouseDown (object sender, MouseButtonEventArgs e) - { - IsPressed = true; - - base.onMouseDown (sender, e); - - //TODO:remove - NotifyValueChanged ("State", "pressed"); - } - public override void onMouseUp (object sender, MouseButtonEventArgs e) - { - IsPressed = false; - - base.onMouseUp (sender, e); - - //TODO:remove - NotifyValueChanged ("State", "normal"); - } - #endregion - - [XmlAttributeAttribute][DefaultValue("#Crow.Images.button.svg")] - public string Image { - get { return image; } - set { - if (image == value) - return; - image = value; - NotifyValueChanged ("Image", image); - } - } - [XmlAttributeAttribute][DefaultValue(false)] - public bool IsPressed - { - get { return isPressed; } - set - { - if (isPressed == value) - return; - - isPressed = value; - - NotifyValueChanged ("IsPressed", isPressed); - - if (isPressed) - Pressed.Raise (this, null); - else - Released.Raise (this, null); - } - } - } -} diff --git a/src/GraphicObjects/CheckBox.cs b/src/GraphicObjects/CheckBox.cs deleted file mode 100644 index 646a8577..00000000 --- a/src/GraphicObjects/CheckBox.cs +++ /dev/null @@ -1,74 +0,0 @@ -// -// CheckBox.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.ComponentModel; -using System.Xml.Serialization; - -namespace Crow -{ - /// <summary> - /// templated checkbox control - /// </summary> - public class CheckBox : TemplatedControl - { - #region CTOR - protected CheckBox() : base(){} - public CheckBox (Interface iface) : base(iface){} - #endregion - - bool isChecked; - - public event EventHandler Checked; - public event EventHandler Unchecked; - - [XmlAttributeAttribute()][DefaultValue(false)] - public bool IsChecked - { - get { return isChecked; } - set - { - if (isChecked == value) - return; - - isChecked = value; - - NotifyValueChanged ("IsChecked", value); - - if (isChecked) - Checked.Raise (this, null); - else - Unchecked.Raise (this, null); - } - } - - public override void onMouseDown (object sender, MouseButtonEventArgs e) - { - IsChecked = !IsChecked; - base.onMouseDown (sender, e); - } - } -} diff --git a/src/GraphicObjects/ColorPicker.cs b/src/GraphicObjects/ColorPicker.cs deleted file mode 100644 index cc955191..00000000 --- a/src/GraphicObjects/ColorPicker.cs +++ /dev/null @@ -1,228 +0,0 @@ -// -// ColorPicker.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Xml.Serialization; -using System.ComponentModel; - -namespace Crow -{ - /// <summary> - /// templated color selector control - /// </summary> - public class ColorPicker : TemplatedControl - { - #region CTOR - protected ColorPicker() : base(){} - public ColorPicker (Interface iface) : base(iface){} - #endregion - - const double div = 255.0; - const double colDiv = 1.0 / div; - - Color curColor; - double h,s,v; - - [XmlAttributeAttribute()] - public virtual double R { - get { return Math.Round(curColor.R * div); } - set { - if (R == value) - return; - curColor.R = value * colDiv; - NotifyValueChanged ("R", R); - hsvFromRGB (); - notifyCurColorHasChanged (); - } - } - [XmlAttributeAttribute()] - public virtual double G { - get { return Math.Round(curColor.G * div); } - set { - if (G == value) - return; - curColor.G = value * colDiv; - NotifyValueChanged ("G", G); - notifyCurColorHasChanged (); - hsvFromRGB (); - } - } - [XmlAttributeAttribute()] - public virtual double B { - get { return Math.Round(curColor.B * div); } - set { - if (B == value) - return; - curColor.B = value * colDiv; - NotifyValueChanged ("B", B); - notifyCurColorHasChanged (); - hsvFromRGB (); - } - } - [XmlAttributeAttribute()] - public virtual double A { - get { return Math.Round(curColor.A * div); } - set { - if (A == value) - return; - curColor.A = value * colDiv; - NotifyValueChanged ("A", A); - notifyCurColorHasChanged (); - hsvFromRGB (); - } - } - [XmlAttributeAttribute()] - public virtual double H { - get { return Math.Round (h, 3); } - set { - if (H == value) - return; - h = value; - NotifyValueChanged ("H", H); - rgbFromHSV (); - } - } - [XmlAttributeAttribute()] - public virtual double S { - get { return Math.Round (s, 2); } - set { - if (s == value) - return; - s = value; - NotifyValueChanged ("S", S); - rgbFromHSV (); - } - } - [XmlAttributeAttribute()] - public virtual double V { - get { return Math.Round (v, 2); } - set { - if (v == value) - return; - v = value; - NotifyValueChanged ("V", V); - rgbFromHSV (); - } - } - - [XmlAttributeAttribute] - public virtual Fill SelectedColor { - get { return new SolidColor(curColor); } - set { - if (value == null) - curColor = default(Color); - else if (value is SolidColor) { - Color c = (value as SolidColor).color; - if (curColor == c) - return; - curColor = c; - } - notifyCurColorHasChanged (); - notifyRGBAHasChanged (); - hsvFromRGB (); - } - } - [XmlAttributeAttribute] - public virtual Color SelectedRawColor { - get { return curColor; } - set { - if (curColor == value) - return; - curColor = value; - notifyCurColorHasChanged (); - notifyRGBAHasChanged (); - hsvFromRGB (); - } - } - void notifyCurColorHasChanged(){ - NotifyValueChanged ("SelectedColor", SelectedColor); - NotifyValueChanged ("SelectedRawColor", curColor); - string n = curColor.ToString (); - if (char.IsLetter(n[0])) - NotifyValueChanged ("SelectedColorName", n); - else - NotifyValueChanged ("SelectedColorName", "-"); - string tmp = ((int)Math.Round (R)).ToString ("X2") + - ((int)Math.Round (G)).ToString ("X2") + - ((int)Math.Round (B)).ToString ("X2"); - if (curColor.A < 1.0) - tmp += ((int)Math.Round (A)).ToString ("X2"); - NotifyValueChanged ("HexColor", tmp); - } - void notifyRGBAHasChanged(){ - NotifyValueChanged ("R", R); - NotifyValueChanged ("G", G); - NotifyValueChanged ("B", B); - NotifyValueChanged ("A", A); - } - void notifyHSVHasChanged(){ - NotifyValueChanged ("H", H); - NotifyValueChanged ("S", S); - NotifyValueChanged ("V", V); - } - void hsvFromRGB(){ - Color c = curColor; - c.ResetName (); - double min = Math.Min (c.R, Math.Min (c.G, c.B)); //Min. value of RGB - double max = Math.Max (c.R, Math.Max (c.G, c.B)); //Max. value of RGB - double diff = max - min; //Delta RGB value - - v = max; - - if ( diff == 0 )//This is a gray, no chroma... - { - h = 0; - s = 0; - }else{//Chromatic data... - s = diff / max; - - double diffR = (((max - c.R) / 6.0) + (diff / 2.0)) / diff; - double diffG = (((max - c.G) / 6.0) + (diff / 2.0)) / diff; - double diffB = (((max - c.B) / 6.0) + (diff / 2.0)) / diff; - - if (c.R == max) - h = diffB - diffG; - else if (c.G == max) - h = (1.0 / 3.0) + diffR - diffB; - else if (c.B == max) - h = (2.0 / 3.0) + diffG - diffR; - - if (h < 0) - h += 1; - if (h > 1) - h -= 1; - - } - notifyHSVHasChanged (); - } - void rgbFromHSV(){ - curColor = Color.FromHSV (h, v, s, curColor.A); - notifyCurColorHasChanged (); - notifyRGBAHasChanged (); - } - } -} - diff --git a/src/GraphicObjects/ColorSelector.cs b/src/GraphicObjects/ColorSelector.cs deleted file mode 100644 index ee57a262..00000000 --- a/src/GraphicObjects/ColorSelector.cs +++ /dev/null @@ -1,74 +0,0 @@ -// -// ColorSelector.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Xml.Serialization; -using System.ComponentModel; - -namespace Crow -{ - /// <summary> - /// simple squarred rgb color selector - /// </summary> - [DesignIgnore] - public class ColorSelector : GraphicObject - { - #region CTOR - protected ColorSelector() : base(){} - public ColorSelector (Interface iface) : base(iface){} - #endregion - - const double div = 255.0; - const double colDiv = 1.0 / div; - protected Point mousePos; - - public override void onMouseMove (object sender, MouseMoveEventArgs e) - { - base.onMouseMove (sender, e); - if (IFace.Mouse.LeftButton == ButtonState.Released) - return; - updateMouseLocalPos (e.Position); - } - public override void onMouseDown (object sender, MouseButtonEventArgs e) - { - base.onMouseDown (sender, e); - if (e.Button == MouseButton.Left) - updateMouseLocalPos (e.Position); - } - - protected virtual void updateMouseLocalPos(Point mPos){ - Rectangle r = ScreenCoordinates (Slot); - Rectangle cb = ClientRectangle; - mousePos = mPos - r.Position; - - mousePos.X = Math.Max(cb.X, mousePos.X); - mousePos.X = Math.Min(cb.Right, mousePos.X); - mousePos.Y = Math.Max(cb.Y, mousePos.Y); - mousePos.Y = Math.Min(cb.Bottom, mousePos.Y); - } - } -} - diff --git a/src/GraphicObjects/ComboBox.cs b/src/GraphicObjects/ComboBox.cs deleted file mode 100644 index 61227055..00000000 --- a/src/GraphicObjects/ComboBox.cs +++ /dev/null @@ -1,59 +0,0 @@ -// -// ComboBox.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Xml.Serialization; - -namespace Crow -{ - /// <summary> - /// templated control for selecting value in a pop up list - /// </summary> - public class ComboBox : ListBox - { - #region CTOR - protected ComboBox() : base(){} - public ComboBox (Interface iface) : base(iface){} - #endregion - - Size minimumPopupSize = "10,10"; - [XmlIgnore]public Size MinimumPopupSize{ - get { return minimumPopupSize; } - set { - minimumPopupSize = value; - NotifyValueChanged ("MinimumPopupSize", minimumPopupSize); - } - } - - public override void OnLayoutChanges (LayoutingType layoutType) - { - base.OnLayoutChanges (layoutType); - - if (layoutType == LayoutingType.Width) - MinimumPopupSize = new Size (this.Slot.Width, minimumPopupSize.Height); - } - } -} diff --git a/src/GraphicObjects/Container.cs b/src/GraphicObjects/Container.cs deleted file mode 100644 index 364bad83..00000000 --- a/src/GraphicObjects/Container.cs +++ /dev/null @@ -1,72 +0,0 @@ -// -// Container.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Xml.Serialization; -using System.Reflection; -using System.ComponentModel; -using System.Linq; -using System.Threading; - -namespace Crow -{ - /// <summary> - /// simple container accepting one child - /// </summary> - public class Container : PrivateContainer - { - #if DESIGN_MODE - public override void getIML (System.Xml.XmlDocument doc, System.Xml.XmlNode parentElem) - { - if (this.design_isTGItem) - return; - base.getIML (doc, parentElem); - if (child == null) - return; - child.getIML (doc, parentElem.LastChild); - } - #endif - - #region CTOR - protected Container() : base(){} - public Container (Interface iface) : base(iface){} - #endregion - - [XmlIgnore]public GraphicObject Child { - get { return child; } - set { base.SetChild(value); } - } - /// <summary> - /// override this to handle specific steps in child addition in derived class, - /// and don't forget to call the base.SetChild - /// </summary> - public virtual void SetChild(GraphicObject _child) - { - base.SetChild (_child); - } - } -} - diff --git a/src/GraphicObjects/DataSourceChangeEventArgs.cs b/src/GraphicObjects/DataSourceChangeEventArgs.cs deleted file mode 100644 index a2519356..00000000 --- a/src/GraphicObjects/DataSourceChangeEventArgs.cs +++ /dev/null @@ -1,46 +0,0 @@ -// -// DataSourceChangeEventArgs.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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; - -namespace Crow -{ - public class DataSourceChangeEventArgs : EventArgs - { - public object OldDataSource; - public object NewDataSource; - - public DataSourceChangeEventArgs (object oldDataSource, object newDataSource) : base() - { - OldDataSource = oldDataSource; - NewDataSource = newDataSource; - } - public override string ToString () - { - return string.Format ("DSChangeEA: {0} => {1}", OldDataSource, NewDataSource); - } - } -} - diff --git a/src/GraphicObjects/DirectoryView.cs b/src/GraphicObjects/DirectoryView.cs deleted file mode 100644 index d530f0cb..00000000 --- a/src/GraphicObjects/DirectoryView.cs +++ /dev/null @@ -1,136 +0,0 @@ -// -// DirectoryView.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Xml.Serialization; -using System.ComponentModel; -using System.IO; -using System.Collections.Generic; -using System.Linq; - -namespace Crow -{ - /// <summary> - /// templated directory viewer - /// </summary> - public class DirectoryView : TemplatedControl - { - #region CTOR - protected DirectoryView() : base(){} - public DirectoryView (Interface iface) : base(iface){} - #endregion - - #region events - public event EventHandler<SelectionChangeEventArgs> SelectedItemChanged; - #endregion - - string currentDirectory = "/"; - bool showFiles, showHidden; - string fileMask = "*.*"; - - object _selectedItem; - [XmlIgnore]public object SelectedItem { - get { - return _selectedItem; - } - set { - if (value == _selectedItem) - return; - _selectedItem = value; - NotifyValueChanged ("SelectedItem", _selectedItem); - } - } - [XmlAttributeAttribute()][DefaultValue(true)] - public virtual bool ShowFiles { - get { return showFiles; } - set { - if (showFiles == value) - return; - showFiles = value; - NotifyValueChanged ("ShowFiles", showFiles); - NotifyValueChanged ("FileSystemEntries", FileSystemEntries); - } - } - [XmlAttributeAttribute()][DefaultValue(false)] - public virtual bool ShowHidden { - get { return showHidden; } - set { - if (showHidden == value) - return; - showHidden = value; - NotifyValueChanged ("ShowHidden", showHidden); - NotifyValueChanged ("FileSystemEntries", FileSystemEntries); - } - } - [XmlAttributeAttribute][DefaultValue("*.*")] - public virtual string FileMask { - get { return fileMask; } - set { - if (fileMask == value) - return; - fileMask = value; - NotifyValueChanged ("FileMask", fileMask); - NotifyValueChanged ("FileSystemEntries", FileSystemEntries); - } - } - [XmlAttributeAttribute][DefaultValue("/")] - public virtual string CurrentDirectory { - get { return currentDirectory; } - set { - if (currentDirectory == value) - return; - currentDirectory = value; - NotifyValueChanged ("CurrentDirectory", currentDirectory); - NotifyValueChanged ("FileSystemEntries", FileSystemEntries); - } - } - [XmlIgnore]public FileSystemInfo[] FileSystemEntries { - get { - try { - if (string.IsNullOrEmpty(CurrentDirectory)) - return null; - DirectoryInfo di = new DirectoryInfo(CurrentDirectory); - List<FileSystemInfo> fi = new List<FileSystemInfo> (di.GetDirectories()); - if (showFiles && !string.IsNullOrEmpty(fileMask)) - fi.AddRange(di.GetFiles(fileMask)); - return showHidden ? - fi.ToArray() : - fi.Where(f=>!f.Attributes.HasFlag (FileAttributes.Hidden)).ToArray(); - } catch (Exception ex) { - Console.WriteLine (ex.ToString ()); - return null; - } - } - } - public void onSelectedItemChanged (object sender, SelectionChangeEventArgs e){ - if (e.NewValue == SelectedItem) - return; - SelectedItem = e.NewValue; - SelectedItemChanged.Raise (this, e); - } - } -} - diff --git a/src/GraphicObjects/DockStack.cs b/src/GraphicObjects/DockStack.cs deleted file mode 100644 index ae8b9c89..00000000 --- a/src/GraphicObjects/DockStack.cs +++ /dev/null @@ -1,363 +0,0 @@ -// -// DockStack.cs -// -// Author: -// Jean-Philippe Bruyère <jp_bruyere@hotmail.com> -// -// 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 Crow.IML; - -namespace Crow -{ - [DesignIgnore] - public class DockStack : GenericStack - { - #region CTor - public DockStack () {} - public DockStack (Interface iface) : base (iface) {} - #endregion - - public override void AddChild (GraphicObject g) - { - base.AddChild (g); - if (localLogicalParentIsNull) - g.LogicalParent = this; - else - g.LogicalParent = this.LogicalParent; - } - public override void InsertChild (int idx, GraphicObject g) - { - base.InsertChild (idx, g); - g.LogicalParent = this.LogicalParent; - } - - public override bool PointIsIn (ref Point m) - { - if (!base.PointIsIn(ref m)) - return false; - - Group p = Parent as Group; - if (p != null) { - childrenRWLock.EnterReadLock (); - for (int i = p.Children.Count - 1; i >= 0; i--) { - if (p.Children [i] == this) - break; - if (p.Children [i].IsDragged) - continue; - if (p.Children [i].Slot.ContainsOrIsEqual (m)) { - childrenRWLock.ExitReadLock (); - return false; - } - } - } - childrenRWLock.ExitReadLock (); - return Slot.ContainsOrIsEqual(m); - } - -// public override void OnLayoutChanges (LayoutingType layoutType) -// { -// base.OnLayoutChanges (layoutType); -// -// if ((layoutType & LayoutingType.Sizing) > 0) -// computeRects(); -// } - - Rectangle rIn = default(Rectangle); - double dockThresh = 0.2; - GraphicObject focusedChild; - internal GraphicObject stretchedChild; - - void getFocusedChild (Point lm) { - Rectangle cb = ClientRectangle; - - childrenRWLock.EnterReadLock (); - foreach (GraphicObject c in Children) { - Rectangle bounds = c.Slot + cb.Position; - if (!bounds.ContainsOrIsEqual (lm)) - continue; - rIn = bounds; - focusedChild = c; - break; - } - childrenRWLock.ExitReadLock (); - } - - public override void onMouseMove (object sender, MouseMoveEventArgs e) - { - if (IsDropTarget) { - DockWindow dw = IFace.DragAndDropOperation.DragSource as DockWindow; - if (dw.IsDocked) { - base.onMouseMove (sender, e); - return; - } - - Alignment curDockPos = dw.DockingPosition; - dw.DockingPosition = Alignment.Undefined; - - Rectangle cb = ClientRectangle; - Point lm = ScreenPointToLocal (e.Position); - - if (Children.Count == 0) { - Rectangle r = cb; - r.Inflate (r.Width / -5, r.Height / -5); - if (r.ContainsOrIsEqual(lm)) - dw.DockingPosition = Alignment.Center; - } else { - rIn = cb; - - if (Orientation == Orientation.Horizontal || Children.Count == 1) { - if (lm.Y > cb.Top + cb.Height / 3 && lm.Y < cb.Bottom - cb.Height / 3) { - if (lm.X < cb.Left + cb.Width / 3) - dw.DockingPosition = Alignment.Left; - else if (lm.X > cb.Right - cb.Width / 3) - dw.DockingPosition = Alignment.Right; - } else { - getFocusedChild (lm); - if (focusedChild != null) { - if (lm.Y < rIn.Top + rIn.Height / 3) - dw.DockingPosition = Alignment.Top; - else if (lm.Y > rIn.Bottom - rIn.Height / 3) - dw.DockingPosition = Alignment.Bottom; - } - } - } - if (Orientation == Orientation.Vertical || Children.Count == 1) { - if (lm.X > cb.Left + cb.Width / 3 && lm.X < cb.Right - cb.Width / 3) { - if (lm.Y < cb.Top + cb.Height / 3) - dw.DockingPosition = Alignment.Top; - else if (lm.Y > cb.Bottom - cb.Height / 3) - dw.DockingPosition = Alignment.Bottom; - } else { - getFocusedChild (lm); - if (focusedChild != null) { - if (lm.X < rIn.Left + rIn.Width / 3) - dw.DockingPosition = Alignment.Left; - else if (lm.X > rIn.Right - rIn.Width / 3) - dw.DockingPosition = Alignment.Right; - } - } - } - } - - if (curDockPos != dw.DockingPosition) - RegisterForGraphicUpdate (); - } - base.onMouseMove (sender, e); - } - - protected override void onDragEnter (object sender, DragDropEventArgs e) - { - base.onDragEnter (sender, e); - RegisterForGraphicUpdate (); - } - protected override void onDragLeave (object sender, DragDropEventArgs e) - { - DockWindow dw = e.DragSource as DockWindow; - if (dw != null) - dw.DockingPosition = Alignment.Undefined; - base.onDragLeave (sender, e); - RegisterForGraphicUpdate (); - } - - protected override void onDraw (Cairo.Context gr) - { - gr.Save (); - - Rectangle rBack = new Rectangle (Slot.Size); - - Background.SetAsSource (gr, rBack); - CairoHelpers.CairoRectangle (gr, rBack, CornerRadius); - gr.Fill (); - - if (ClipToClientRect) { - //clip to client zone - CairoHelpers.CairoRectangle (gr, ClientRectangle, CornerRadius); - gr.Clip (); - } - - childrenRWLock.EnterReadLock (); - - foreach (GraphicObject g in Children) - g.Paint (ref gr); - - childrenRWLock.ExitReadLock (); - - - if (!IsDropTarget) { - gr.Restore (); - return; - } - - DockWindow dw = IFace.DragAndDropOperation.DragSource as DockWindow; - if (dw == null) - return; - if (!dw.IsDocked) { - Rectangle cb = ClientRectangle; - double minDim = Math.Min (cb.Width, cb.Height); - - Rectangle r = rIn; - if (Children.Count <= 1 || dw.DockingPosition.GetOrientation()==Orientation ) - r = cb; - - switch (dw.DockingPosition) { - case Alignment.Top: - gr.Rectangle (r.Left, r.Top, r.Width, r.Height * dockThresh); - break; - case Alignment.Bottom: - gr.Rectangle (r.Left, r.Bottom - r.Height * dockThresh, r.Width, r.Height * dockThresh); - break; - case Alignment.Left: - gr.Rectangle (r.Left, r.Top, r.Width * dockThresh, r.Height); - break; - case Alignment.Right: - gr.Rectangle (r.Right - r.Width * dockThresh, r.Top, r.Width * dockThresh, r.Height); - break; - case Alignment.Center: - r.Inflate ((int)Math.Ceiling (Math.Min (r.Width, r.Height) * -0.05)); - gr.Rectangle (r); - break; - } - gr.LineWidth = 1; - gr.SetSourceRGBA (0.4, 0.4, 0.9, 0.4); - gr.FillPreserve (); - gr.SetSourceRGBA (0.9, 0.9, 1.0, 0.8); - gr.Stroke (); - } - gr.Restore (); - } - - public void Dock(DockWindow dw){ - DockStack activeStack = this; - - if (Children.Count == 1) { - Orientation = dw.DockingPosition.GetOrientation (); - if (Children [0] is DockWindow) { - (Children [0] as DockWindow).DockingPosition = dw.DockingPosition.GetOpposite (); - } - } else if (Children.Count > 0 && dw.DockingPosition.GetOrientation () != Orientation) { - activeStack = new DockStack (IFace); - activeStack.Orientation = dw.DockingPosition.GetOrientation (); - activeStack.Width = focusedChild.Width; - activeStack.Height = focusedChild.Height; - int idx = Children.IndexOf (focusedChild); - RemoveChild (focusedChild); - focusedChild.Height = Measure.Stretched; - focusedChild.Width = Measure.Stretched; - InsertChild (idx, activeStack); - activeStack.AddChild (focusedChild); - activeStack.stretchedChild = focusedChild; - if (focusedChild is DockWindow) - (focusedChild as DockWindow).DockingPosition = dw.DockingPosition.GetOpposite (); - focusedChild = null; - } - - Rectangle r = ClientRectangle; - int vTreshold = (int)(r.Height * dockThresh); - int hTreshold = (int)(r.Width * dockThresh); - - Console.WriteLine ("Docking {0} as {2} in {1}", dw.Name, activeStack.Name, dw.DockingPosition); - switch (dw.DockingPosition) { - case Alignment.Top: - dw.Height = vTreshold; - dw.Width = Measure.Stretched; - activeStack.InsertChild (0, dw); - activeStack.InsertChild (1, new Splitter(IFace)); - break; - case Alignment.Bottom: - dw.Height = vTreshold; - dw.Width = Measure.Stretched; - activeStack.AddChild (new Splitter(IFace)); - activeStack.AddChild (dw); - break; - case Alignment.Left: - dw.Width = hTreshold; - dw.Height = Measure.Stretched; - activeStack.InsertChild (0, dw); - activeStack.InsertChild (1, new Splitter(IFace)); - break; - case Alignment.Right: - dw.Width = hTreshold; - dw.Height = Measure.Stretched; - activeStack.AddChild (new Splitter(IFace)); - activeStack.AddChild (dw); - break; - case Alignment.Center: - dw.Width = dw.Height = Measure.Stretched; - AddChild (dw); - stretchedChild = dw; - break; - } - } - public void Undock (DockWindow dw){ - int idx = Children.IndexOf(dw); - - RemoveChild(dw); - - if (Children.Count == 0) - return; - - if (dw.DockingPosition == Alignment.Left || dw.DockingPosition == Alignment.Top) { - RemoveChild (idx); - if (stretchedChild == dw) { - stretchedChild = Children [idx]; - stretchedChild.Width = stretchedChild.Height = Measure.Stretched; - } - } else { - RemoveChild (idx - 1); - if (stretchedChild == dw) { - stretchedChild = Children [idx-2]; - stretchedChild.Width = stretchedChild.Height = Measure.Stretched; - } - } - - if (Children.Count == 1) { - DockStack dsp = Parent as DockStack; - if (dsp == null) { - Children [0].Width = Children [0].Height = Measure.Stretched; - return; - } - //remove level and move remaining obj to level above - GraphicObject g = Children [0]; - RemoveChild (g); - idx = dsp.Children.IndexOf (this); - dsp.RemoveChild (this); - dsp.InsertChild (idx, g); - g.Width = this.Width; - g.Height = this.Height; - if (dsp.stretchedChild == this) - dsp.stretchedChild = g; - dsp.checkAlignments (); - } else - checkAlignments (); - } - - internal void checkAlignments () { - DockWindow dw = Children[0] as DockWindow; - if (dw != null) - dw.DockingPosition = (Orientation == Orientation.Horizontal ? Alignment.Left : Alignment.Top); - dw = Children[Children.Count - 1] as DockWindow; - if (dw != null) - dw.DockingPosition = (Orientation == Orientation.Horizontal ? Alignment.Right : Alignment.Bottom); - } - } -} - diff --git a/src/GraphicObjects/DockWindow.cs b/src/GraphicObjects/DockWindow.cs deleted file mode 100644 index ca4b93f4..00000000 --- a/src/GraphicObjects/DockWindow.cs +++ /dev/null @@ -1,179 +0,0 @@ -// -// DockingView.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Xml.Serialization; - -namespace Crow -{ - public class DockWindow : Window - { - #region CTOR - public DockWindow () : base () - { - } - #endregion - - int undockThreshold = 4; - bool isDocked = false; - Alignment docking = Alignment.Undefined; - - Point undockingMousePosOrig; //mouse pos when docking was donne, use for undocking on mouse move - Rectangle savedSlot; //last undocked slot recalled when view is undocked - bool wasResizable; - - public bool IsDocked { - get { return isDocked; } - set { - if (isDocked == value) - return; - isDocked = value; - NotifyValueChanged ("IsDocked", isDocked); - NotifyValueChanged ("IsFloating", !isDocked); - } - } - [XmlIgnore] public bool IsFloating { get { return !isDocked; }} - - public Alignment DockingPosition { - get { return docking; } - set { - if (docking == value) - return; - docking = value; - NotifyValueChanged ("DockingPosition", DockingPosition); - } - } - - public override bool PointIsIn (ref Point m) - { - if (!base.PointIsIn(ref m)) - return false; - - Group p = Parent as Group; - if (p != null) { - lock (p.Children) { - for (int i = p.Children.Count - 1; i >= 0; i--) { - if (p.Children [i] == this) - break; - if (p.Children [i].IsDragged) - continue; - if (p.Children [i].Slot.ContainsOrIsEqual (m)) { - return false; - } - } - } - } - return Slot.ContainsOrIsEqual(m); - } - - public override void onMouseMove (object sender, MouseMoveEventArgs e) - { -// if (this.HasFocus && e.Mouse.IsButtonDown (MouseButton.Left) && IsDocked) { -// if (Math.Abs (e.Position.X - undockingMousePosOrig.X) > 10 || -// Math.Abs (e.Position.X - undockingMousePosOrig.X) > 10) -// Undock (); -// } - - if (this.HasFocus && e.Mouse.IsButtonDown (MouseButton.Left) && IsDocked) - CheckUndock (e.Position); - - base.onMouseMove (sender, e); - } - public override void onMouseDown (object sender, MouseButtonEventArgs e) - { - base.onMouseDown (sender, e); - - if (this.HasFocus && IsDocked && e.Button == MouseButton.Left) - undockingMousePosOrig = e.Position; - } - public bool CheckUndock (Point mousePos) { - if (DockingPosition == Alignment.Center) - return false; - if (Math.Abs (mousePos.X - undockingMousePosOrig.X) < undockThreshold || - Math.Abs (mousePos.X - undockingMousePosOrig.X) < undockThreshold) - return false; - Undock (); - return true; - } - - protected override void onStartDrag (object sender, DragDropEventArgs e) - { - base.onStartDrag (sender, e); - - undockingMousePosOrig = IFace.Mouse.Position; - } - protected override void onDrop (object sender, DragDropEventArgs e) - { - if (!isDocked && DockingPosition != Alignment.Undefined) - Dock (e.DropTarget as DockStack); - base.onDrop (sender, e); - } - public void Undock () { - lock (IFace.UpdateMutex) { - DockStack ds = Parent as DockStack; - ds.Undock (this); - - IFace.AddWidget (this); - - this.Left = savedSlot.Left; - this.Top = savedSlot.Top; - this.Width = savedSlot.Width; - this.Height = savedSlot.Height; - - IsDocked = false; - DockingPosition = Alignment.Undefined; - Resizable = wasResizable; - } - } - - public void Dock (DockStack target){ - lock (IFace.UpdateMutex) { - IsDocked = true; - //undockingMousePosOrig = lastMousePos; - savedSlot = this.LastPaintedSlot; - wasResizable = Resizable; - Resizable = false; - LastSlots = LastPaintedSlot = Slot = default(Rectangle); - Left = Top = 0; - - IFace.RemoveWidget (this); - - target.Dock (this); - } - } - - protected override void close () - { - if (isDocked) - Undock (); - base.close (); - } - - public string ExportWinConfigs () { - return string.Format ("{0};{1};{2}", this.Name, DockingPosition, savedSlot); - } - } -} - diff --git a/src/GraphicObjects/Expandable.cs b/src/GraphicObjects/Expandable.cs deleted file mode 100644 index 1920a8fe..00000000 --- a/src/GraphicObjects/Expandable.cs +++ /dev/null @@ -1,131 +0,0 @@ -// -// Expandable.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.ComponentModel; -using System.Xml.Serialization; - -namespace Crow -{ - /// <summary> - /// templated control whose content can be hidden and shown on demand - /// </summary> - public class Expandable : TemplatedContainer - { - #region CTOR - protected Expandable() : base(){} - public Expandable (Interface iface) : base(iface){} - #endregion - - #region Private fields - bool _isExpanded; - string image; - #endregion - - #region Event Handlers - /// <summary> - /// Occurs when control is expanded. - /// </summary> - public event EventHandler Expand; - /// <summary> - /// Occurs when control is collapsed. - /// </summary> - public event EventHandler Collapse; - #endregion - - public BooleanTestOnInstance GetIsExpandable; - - /// <summary> - /// mouse click event handler for easy expand triggering in IML - /// </summary> - public void onClickForExpand (object sender, MouseButtonEventArgs e) - { - IsExpanded = !IsExpanded; - } - - #region Public properties - [XmlAttributeAttribute][DefaultValue("#Crow.Images.Icons.expandable.svg")] - public string Image { - get { return image; } - set { - if (image == value) - return; - image = value; - NotifyValueChanged ("Image", image); - } - } - [DefaultValue(false)] - public bool IsExpanded - { - get { return _isExpanded; } - set - { - if (value == _isExpanded) - return; - - _isExpanded = value; - - bool isExp = IsExpandable; - NotifyValueChanged ("IsExpandable", isExp); - if (!isExp) - _isExpanded = false; - - NotifyValueChanged ("IsExpanded", _isExpanded); - - if (_isExpanded) - onExpand (this, null); - else - onCollapse (this, null); - } - } - [XmlIgnore]public bool IsExpandable { - get { - try { - return GetIsExpandable == null ? true : GetIsExpandable (this); - } catch (Exception ex) { - System.Diagnostics.Debug.WriteLine ("Not Expandable error: " + ex.ToString ()); - return false; - } - } - } - #endregion - - public virtual void onExpand(object sender, EventArgs e) - { - if (_contentContainer != null) - _contentContainer.Visible = true; - - Expand.Raise (this, e); - } - public virtual void onCollapse(object sender, EventArgs e) - { - if (_contentContainer != null) - _contentContainer.Visible = false; - - Collapse.Raise (this, e); - } - } -} diff --git a/src/GraphicObjects/FileDialog.cs b/src/GraphicObjects/FileDialog.cs deleted file mode 100644 index 8069b8a7..00000000 --- a/src/GraphicObjects/FileDialog.cs +++ /dev/null @@ -1,155 +0,0 @@ -// -// FileDialog.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Xml.Serialization; -using System.ComponentModel; -using System.IO; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Text.RegularExpressions; - -namespace Crow -{ - /// <summary> - /// templated control for selecting files - /// </summary> - public class FileDialog: Window - { - #region CTOR - protected FileDialog() : base(){} - public FileDialog (Interface iface) : base(iface){} - #endregion - - string searchPattern, curDir, _selectedFile, _selectedDir; - bool showHidden, showFiles; - - #region events - public event EventHandler OkClicked; - #endregion - - public string SelectedFileFullPath { - get { return Path.Combine (SelectedDirectory, SelectedFile); } - } - [XmlAttributeAttribute][DefaultValue("/home")] - public virtual string CurrentDirectory { - get { return curDir; } - set { - if (curDir == value) - return; - curDir = value; - NotifyValueChanged ("CurrentDirectory", curDir); - SelectedDirectory = curDir; - } - } - - [XmlAttributeAttribute][DefaultValue("*")] - public virtual string SearchPattern { - get { return searchPattern; } - set { - if (searchPattern == value) - return; - searchPattern = value; - NotifyValueChanged ("SearchPattern", searchPattern); - - } - } - [XmlAttributeAttribute()][DefaultValue(false)] - public virtual bool ShowHidden { - get { return showHidden; } - set { - if (showHidden == value) - return; - showHidden = value; - NotifyValueChanged ("ShowHidden", showHidden); - } - } - [XmlAttributeAttribute()][DefaultValue(true)] - public virtual bool ShowFiles { - get { return showFiles; } - set { - if (showFiles == value) - return; - showFiles = value; - NotifyValueChanged ("ShowFiles", showFiles); - } - } - [XmlAttributeAttribute]public string SelectedFile { - get { return _selectedFile; } - set { - if (value == _selectedFile) - return; - _selectedFile = value; - NotifyValueChanged ("SelectedFile", _selectedFile); - } - } - [XmlAttributeAttribute]public string SelectedDirectory { - get { return _selectedDir; } - set { - if (value == _selectedDir) - return; - _selectedDir = value; - NotifyValueChanged ("SelectedDirectory", _selectedDir); - } - } - - public void onFVSelectedItemChanged (object sender, SelectionChangeEventArgs e){ - if (e.NewValue != null) { - if (File.GetAttributes (e.NewValue.ToString ()).HasFlag (FileAttributes.Directory)) { - SelectedDirectory = e.NewValue.ToString (); - SelectedFile = ""; - } else { - SelectedDirectory = Path.GetDirectoryName (e.NewValue.ToString ()); - SelectedFile = Path.GetFileName (e.NewValue.ToString ()); - } - } - } - public void onDVSelectedItemChanged (object sender, SelectionChangeEventArgs e){ - if (e.NewValue != null) - SelectedDirectory = e.NewValue.ToString(); - } - public void goUpDirClick (object sender, MouseButtonEventArgs e){ - string root = Directory.GetDirectoryRoot(CurrentDirectory); - if (CurrentDirectory == root) - return; - CurrentDirectory = Directory.GetParent(CurrentDirectory).FullName; - } - void onFileSelect(object sender, MouseButtonEventArgs e){ - if (string.IsNullOrEmpty (SelectedFile)) - CurrentDirectory = SelectedDirectory; - else { - OkClicked.Raise (this, null); - IFace.DeleteWidget (this); - } - } - void onCancel(object sender, MouseButtonEventArgs e){ - IFace.DeleteWidget (this); - } - - } -} - diff --git a/src/GraphicObjects/GenericStack.cs b/src/GraphicObjects/GenericStack.cs deleted file mode 100644 index 64841d4b..00000000 --- a/src/GraphicObjects/GenericStack.cs +++ /dev/null @@ -1,246 +0,0 @@ -// -// GenericStack.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.ComponentModel; -using System.Diagnostics; -using System.Xml.Serialization; -using System; -using System.Linq; - -namespace Crow -{ - /// <summary> - /// group container that stacked its children horizontally or vertically - /// </summary> - public class GenericStack : Group - { - #region CTOR - protected GenericStack() : base(){} - public GenericStack(Interface iface) : base(iface){} - #endregion - - #region Private fields - int _spacing; - Orientation _orientation; - #endregion - - #region Public Properties - [XmlAttributeAttribute()][DefaultValue(2)] - public int Spacing - { - get { return _spacing; } - set { - if (_spacing == value) - return; - _spacing = value; - NotifyValueChanged ("Spacing", Spacing); - RegisterForLayouting (LayoutingType.Sizing|LayoutingType.ArrangeChildren); - } - } - [XmlAttributeAttribute()][DefaultValue(Orientation.Horizontal)] - public virtual Orientation Orientation - { - get { return _orientation; } - set { _orientation = value; } - } - #endregion - - #region GraphicObject Overrides - public override bool ArrangeChildren { get { return true; } } - public override void ChildrenLayoutingConstraints (ref LayoutingType layoutType) - { - //Prevent child repositionning in the direction of stacking - if (Orientation == Orientation.Horizontal) - layoutType &= (~LayoutingType.X); - else - layoutType &= (~LayoutingType.Y); - } - protected override int measureRawSize (LayoutingType lt) - { - int totSpace = Math.Max(0, Spacing * (Children.Count (c => c.Visible) - 1)); - if (lt == LayoutingType.Width) { - if (Orientation == Orientation.Horizontal) - return contentSize.Width + totSpace + 2 * Margin; - }else if (Orientation == Orientation.Vertical) - return contentSize.Height + totSpace + 2 * Margin; - - return base.measureRawSize (lt); - } - public virtual void ComputeChildrenPositions() - { - int d = 0; - if (Orientation == Orientation.Horizontal) { - foreach (GraphicObject c in Children) { - if (!c.Visible) - continue; - c.Slot.X = d; - d += c.Slot.Width + Spacing; - } - } else { - foreach (GraphicObject c in Children) { - if (!c.Visible) - continue; - c.Slot.Y = d; - d += c.Slot.Height + Spacing; - } - } - IsDirty = true; - } - GraphicObject stretchedGO = null; - public override bool UpdateLayout (LayoutingType layoutType) - { - RegisteredLayoutings &= (~layoutType); - - if (layoutType == LayoutingType.ArrangeChildren) { - //allow 1 child to have size to 0 if stack has fixed or streched size policy, - //this child will occupy remaining space - //if stack size policy is Fit, no child may have stretch enabled - //in the direction of stacking. - ComputeChildrenPositions (); - - //if no layouting remains in queue for item, registre for redraw - if (RegisteredLayoutings == LayoutingType.None && IsDirty) - IFace.EnqueueForRepaint (this); - - return true; - } - - return base.UpdateLayout(layoutType); - } - - void adjustStretchedGo (LayoutingType lt){ - if (stretchedGO == null) - return; - if (lt == LayoutingType.Width) { - int newW = Math.Max ( - this.ClientRectangle.Width - contentSize.Width - Spacing * (Children.Count - 1), - stretchedGO.MinimumSize.Width); - if (stretchedGO.MaximumSize.Width > 0) - newW = Math.Min (newW, stretchedGO.MaximumSize.Width); - if (newW != stretchedGO.Slot.Width) { - stretchedGO.Slot.Width = newW; - stretchedGO.IsDirty = true; - #if DEBUG_LAYOUTING - Debug.WriteLine ("\tAdjusting Width of " + stretchedGO.ToString()); - #endif - stretchedGO.LayoutChanged -= OnChildLayoutChanges; - stretchedGO.OnLayoutChanges (LayoutingType.Width); - stretchedGO.LayoutChanged += OnChildLayoutChanges; - stretchedGO.LastSlots.Width = stretchedGO.Slot.Width; - } - } else { - int newH = Math.Max ( - this.ClientRectangle.Height - contentSize.Height - Spacing * (Children.Count - 1), - stretchedGO.MinimumSize.Height); - if (stretchedGO.MaximumSize.Height > 0) - newH = Math.Min (newH, stretchedGO.MaximumSize.Height); - if (newH != stretchedGO.Slot.Height) { - stretchedGO.Slot.Height = newH; - stretchedGO.IsDirty = true; - #if DEBUG_LAYOUTING - Debug.WriteLine ("\tAdjusting Height of " + stretchedGO.ToString()); - #endif - stretchedGO.LayoutChanged -= OnChildLayoutChanges; - stretchedGO.OnLayoutChanges (LayoutingType.Height); - stretchedGO.LayoutChanged += OnChildLayoutChanges; - stretchedGO.LastSlots.Height = stretchedGO.Slot.Height; - } - } - } - - public override void OnChildLayoutChanges (object sender, LayoutingEventArgs arg) - { - GraphicObject go = sender as GraphicObject; - //Debug.WriteLine ("child layout change: " + go.LastSlots.ToString() + " => " + go.Slot.ToString()); - switch (arg.LayoutType) { - case LayoutingType.Width: - if (Orientation == Orientation.Horizontal) { - if (go.Width == Measure.Stretched) { - if (stretchedGO == null && Width != Measure.Fit) - stretchedGO = go; - else if (stretchedGO != go) { - go.Slot.Width = 0; - go.Width = Measure.Fit; - return; - } - } else - contentSize.Width += go.Slot.Width - go.LastSlots.Width; - - adjustStretchedGo (LayoutingType.Width); - - if (Width == Measure.Fit) - this.RegisterForLayouting (LayoutingType.Width); - - this.RegisterForLayouting (LayoutingType.ArrangeChildren); - return; - } - break; - case LayoutingType.Height: - if (Orientation == Orientation.Vertical) { - if (go.Height == Measure.Stretched) { - if (stretchedGO == null && Height != Measure.Fit) - stretchedGO = go; - else if (stretchedGO != go){ - go.Slot.Height = 0; - go.Height = Measure.Fit; - return; - } - } else - contentSize.Height += go.Slot.Height - go.LastSlots.Height; - - adjustStretchedGo (LayoutingType.Height); - - if (Height == Measure.Fit) - this.RegisterForLayouting (LayoutingType.Height); - - this.RegisterForLayouting (LayoutingType.ArrangeChildren); - return; - } - break; - } - base.OnChildLayoutChanges (sender, arg); - } - #endregion - - public override void RemoveChild (GraphicObject child) - { - if (child != stretchedGO) { - if (Orientation == Orientation.Horizontal) - contentSize.Width -= child.LastSlots.Width; - else - contentSize.Height -= child.LastSlots.Height; - } - base.RemoveChild (child); - if (child == stretchedGO) { - stretchedGO = null; - RegisterForLayouting (LayoutingType.Sizing); - }else if (Orientation == Orientation.Horizontal) - adjustStretchedGo (LayoutingType.Width); - else - adjustStretchedGo (LayoutingType.Height); - } - } -} diff --git a/src/GraphicObjects/GraduatedSlider.cs b/src/GraphicObjects/GraduatedSlider.cs deleted file mode 100644 index e1d4dd46..00000000 --- a/src/GraphicObjects/GraduatedSlider.cs +++ /dev/null @@ -1,82 +0,0 @@ -// -// GraduatedSlider.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Linq; -using System.Text; -using Cairo; -using System.Xml.Serialization; - -namespace Crow -{ - [DesignIgnore] - public class GraduatedSlider : Slider - { - #region CTOR - protected GraduatedSlider() : base(){} - public GraduatedSlider(Interface iface) : base(iface) - {} -// public GraduatedSlider(double minimum, double maximum, double step) -// : base() -// { -// Minimum = minimum; -// Maximum = maximum; -// SmallIncrement = step; -// LargeIncrement = step * 5; -// } - #endregion - - protected override void DrawGraduations(Context gr, PointD pStart, PointD pEnd) - { - Rectangle r = ClientRectangle; - Foreground.SetAsSource (gr); - - gr.LineWidth = 2; - gr.MoveTo(pStart); - gr.LineTo(pEnd); - - gr.Stroke(); - gr.LineWidth = 1; - - double sst = unity * SmallIncrement; - double bst = unity * LargeIncrement; - - - PointD vBar = new PointD(0, sst); - for (double x = Minimum; x <= Maximum - Minimum; x += SmallIncrement) - { - double lineLength = r.Height / 3; - if (x % LargeIncrement != 0) - lineLength /= 3; - PointD p = new PointD(pStart.X + x * unity, pStart.Y); - gr.MoveTo(p); - gr.LineTo(new PointD(p.X, p.Y + lineLength)); - } - gr.Stroke(); - } - } -} diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs deleted file mode 100644 index bc955368..00000000 --- a/src/GraphicObjects/GraphicObject.cs +++ /dev/null @@ -1,1959 +0,0 @@ -// -// GraphicObject.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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 -{ - /// <summary> - /// The base class for all the graphic tree elements. - /// </summary> - public class GraphicObject : ILayoutable, IValueChange, IDisposable - { - internal ReaderWriterLockSlim parentRWLock = new ReaderWriterLockSlim(); - - #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<string,string> design_iml_values = new Dictionary<string, string>(); - public Dictionary<string,string> design_style_values = new Dictionary<string, string>(); - //public Dictionary<string,FileLocation> design_iml_locations = new Dictionary<string, FileLocation>(); - public Dictionary<string,FileLocation> design_style_locations = new Dictionary<string, FileLocation>(); - - 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<string,string> 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; - } - #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 - - internal static ulong currentUid = 0; - internal ulong uid = 0; - - internal bool isPopup = false; - public GraphicObject focusParent { - get { return (isPopup ? LogicalParent : parent) as GraphicObject; } - } - - /// <summary> - /// interface this widget is bound to, this should not be changed once the instance is created - /// </summary> - public Interface IFace = null; - - /// <summary> - /// 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. - /// </summary> - public Region Clipping; - - #region IValueChange implementation - /// <summary> - /// 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. - /// </summary> - public event EventHandler<ValueChangeEventArgs> ValueChanged; - /// <summary> - /// Helper function to raise the value changed event - /// </summary> - 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 - /// <summary> - /// 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. - /// </summary> - protected GraphicObject () { - Clipping = new Region (); - #if DEBUG - uid = currentUid; - currentUid++; - #endif - } - /// <summary> - /// 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. - /// </summary> - /// <param name="iface">Iface.</param> - public GraphicObject (Interface iface) : this() - { - IFace = iface; - Initialize (); - } - #endregion - //internal bool initialized = false; - /// <summary> - /// Initialize this Graphic object instance by setting style and default values and loading template if required - /// </summary> - public virtual void Initialize(){ - loadDefaultValues (); - //initialized = true; - } - #region private fields - LayoutingType registeredLayoutings = LayoutingType.All; - ILayoutable logicalParent; - ILayoutable parent; - string name; - Fill background = Color.Transparent; - Fill foreground = Color.White; - Font font = "droid, 10"; - 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; - protected object dataSource; - bool rootDataLevel; - string style; - object tag; - bool isDragged; - bool allowDrag; - bool allowDrop; - string tooltip; - IList<Command> contextCommands; - #endregion - - #region public fields - /// <summary> - /// Current size and position computed during layouting pass - /// </summary> - public Rectangle Slot = new Rectangle (); - /// <summary> - /// keep last slot components for each layouting pass to track - /// changes and trigger update of other component accordingly - /// </summary> - public Rectangle LastSlots; - /// <summary> - /// 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 - /// </summary> - //TODO: we should ensure the whole parsed widget tree is the last painted - public Rectangle LastPaintedSlot; - /// <summary>Prevent requeuing multiple times the same widget</summary> - public bool IsQueueForClipping = false; - /// <summary>drawing Cache, if null, a redraw is done, cached or not</summary> - public Surface bmp; - public bool IsDirty = true; - /// <summary> - /// 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) - /// </summary> - 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 - /// <summary> - /// Parent in the graphic tree, used for rendering and layouting - /// </summary> - [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 - /// <summary>Occurs when mouse wheel is rolled in this object. It bubbles to the root</summary> - public event EventHandler<MouseWheelEventArgs> MouseWheelChanged; - /// <summary>Occurs when mouse button is released in this object. It bubbles to the root</summary> - public event EventHandler<MouseButtonEventArgs> MouseUp; - /// <summary>Occurs when mouse button is pressed in this object. It bubbles to the root</summary> - public event EventHandler<MouseButtonEventArgs> MouseDown; - /// <summary>Occurs when mouse button has been pressed then relesed in this object. It bubbles to the root</summary> - public event EventHandler<MouseButtonEventArgs> MouseClick; - /// <summary>Occurs when mouse button has been pressed then relesed 2 times in this object. It bubbles to the root</summary> - public event EventHandler<MouseButtonEventArgs> MouseDoubleClick; - /// <summary>Occurs when mouse mouve in this object. It bubbles to the root</summary> - public event EventHandler<MouseMoveEventArgs> MouseMove; - /// <summary>Occurs when mouse enter this object</summary> - public event EventHandler<MouseMoveEventArgs> MouseEnter; - /// <summary>Occurs when mouse leave this object</summary> - public event EventHandler<MouseMoveEventArgs> MouseLeave; - /// <summary>Occurs when key is pressed when this object is active</summary> - public event EventHandler<KeyboardKeyEventArgs> KeyDown; - /// <summary>Occurs when key is released when this object is active</summary> - public event EventHandler<KeyboardKeyEventArgs> KeyUp; - /// <summary>Occurs when translated key event occurs in the host when this object is active</summary> - public event EventHandler<KeyPressEventArgs> KeyPress; - /// <summary>Occurs when this object received focus</summary> - public event EventHandler Focused; - /// <summary>Occurs when this object loose focus</summary> - public event EventHandler Unfocused; - /// <summary>Occurs when mouse is over</summary> - public event EventHandler Hover; - /// <summary>Occurs when this control is no longer the Hover one</summary> - public event EventHandler UnHover; - /// <summary>Occurs when this object loose focus</summary> - public event EventHandler Enabled; - /// <summary>Occurs when the enabled state this object is set to false</summary> - public event EventHandler Disabled; - - #region DragAndDrop Events - public event EventHandler<DragDropEventArgs> StartDrag; - public event EventHandler<DragDropEventArgs> DragEnter; - public event EventHandler<DragDropEventArgs> DragLeave; - public event EventHandler<DragDropEventArgs> EndDrag; - public event EventHandler<DragDropEventArgs> Drop; - #endregion - - /// <summary> - /// Occurs when default value and styling are loaded, and for templated control, - /// template is also loaded. Bindings should be functionnal as well. - /// </summary> - public event EventHandler Initialized; - - /// <summary>Occurs when one part of the rendering slot changed</summary> - public event EventHandler<LayoutingEventArgs> LayoutChanged; - /// <summary>Occurs when DataSource changed</summary> - public event EventHandler<DataSourceChangeEventArgs> DataSourceChanged; - /// <summary>Occurs when the parent has changed</summary> - public event EventHandler<DataSourceChangeEventArgs> ParentChanged; - /// <summary>Occurs when the logical parent has changed</summary> - public event EventHandler<DataSourceChangeEventArgs> LogicalParentChanged; - #endregion - - #region public properties - /// <summary>Random value placeholder</summary> - [DesignCategory ("Divers")] - public object Tag { - get { return tag; } - set { - if (tag == value) - return; - tag = value; - NotifyValueChanged ("Tag", tag); - } - } - /// <summary> - /// If enabled, resulting bitmap of graphic object is cached - /// speeding up rendering of complex object. Default is enabled. - /// </summary> - [DesignCategory ("Behavior")][DefaultValue(true)] - public virtual bool CacheEnabled { - get { return cacheEnabled; } - set { - if (cacheEnabled == value) - return; - cacheEnabled = value; - NotifyValueChanged ("CacheEnabled", cacheEnabled); - } - } - /// <summary> - /// If true, rendering of GraphicObject is clipped inside client rectangle - /// </summary> - [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 - [XmlIgnore]public string TreePath { - get { return this.GetType().Name + uid.ToString (); } - } - #endif - /// <summary> - /// 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. - /// </summary> - [DesignCategory ("Divers")][DefaultValue(null)] - public virtual string Name { - get { - #if DEBUG - return string.IsNullOrEmpty(name) ? this.GetType().Name + uid.ToString () : name; - #else - return name; - #endif - } - set { - if (name == value) - return; - name = value; - NotifyValueChanged("Name", name); - } - } - /// <summary> - /// Vertical alignment inside parent, disabled if height is stretched - /// or top coordinate is not null - /// </summary> - [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); - } - } - /// <summary> - /// Horizontal alignment inside parent, disabled if width is stretched - /// or left coordinate is not null - /// </summary> - [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); - } - } - /// <summary> - /// x position inside parent - /// </summary> - [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); - } - } - /// <summary> - /// y position inside parent - /// </summary> - [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); - } - } - /// <summary> - /// Helper property used to set width and height to fit in one call - /// </summary> - [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; - } - } - /// <summary> - /// Width of this control, by default inherited from parent. May have special values - /// such as Stretched or Fit. It may be proportionnal or absolute. - /// </summary> - [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); - } - } - /// <summary> - /// Height of this control, by default inherited from parent. May have special values - /// such as Stretched or Fit. It may be proportionnal or absolute. - /// </summary> - [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); - } - } - /// <summary> - /// 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** - /// </summary> - [XmlIgnore]public virtual Measure WidthPolicy { get { - return Width.IsFit ? Measure.Fit : Measure.Stretched; } } - /// <summary> - /// 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** - /// </summary> - [XmlIgnore]public virtual Measure HeightPolicy { get { - return Height.IsFit ? Measure.Fit : Measure.Stretched; } } - /// <summary> - /// Indicate that this object may received focus or not, if not focusable all the descendants are - /// affected. - /// </summary> - [DesignCategory ("Behaviour")][DefaultValue(false)] - public virtual bool Focusable { - get { return focusable; } - set { - if (focusable == value) - return; - focusable = value; - NotifyValueChanged ("Focusable", focusable); - } - } - /// <summary> - /// True when this control has the focus, only one control per interface may have it. - /// </summary> - [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); - } - } - /// <summary> - /// 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. - /// </summary> - [XmlIgnore]public virtual bool IsActive { - get { return isActive; } - set { - if (value == isActive) - return; - - isActive = value; - NotifyValueChanged ("IsActive", isActive); - } - } - /// <summary> - /// true if this control has the pointer hover - /// </summary> - [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); - } - } - /// <summary> - /// true if holding mouse button down should trigger multiple click events - /// </summary> - [DesignCategory ("Behaviour")][DefaultValue(false)] - public virtual bool MouseRepeat { - get { return mouseRepeat; } - set { - if (mouseRepeat == value) - return; - mouseRepeat = value; - NotifyValueChanged ("MouseRepeat", mouseRepeat); - } - } - bool clearBackground = false; - /// <summary> - /// background fill of the control, maybe solid color, gradient, image, or svg - /// </summary> - [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; - } - } - } - /// <summary> - /// Foreground fill of the control, usage may be different among derived controls - /// </summary> - [DesignCategory ("Appearance")][DefaultValue("White")] - public virtual Fill Foreground { - get { return foreground; } - set { - if (foreground == value) - return; - foreground = value; - NotifyValueChanged ("Foreground", foreground); - RegisterForRedraw (); - } - } - /// <summary> - /// Font being used in many controls, it is defined in the base GraphicObject class. - /// </summary> - [DesignCategory ("Appearance")][DefaultValue("sans,10")] - public virtual Font Font { - get { return font; } - set { - if (value == font) - return; - font = value; - NotifyValueChanged ("Font", font); - RegisterForGraphicUpdate (); - } - } - /// <summary> - /// to get rounded corners - /// </summary> - [DesignCategory ("Appearance")][DefaultValue(0.0)] - public virtual double CornerRadius { - get { return cornerRadius; } - set { - if (value == cornerRadius) - return; - cornerRadius = value; - NotifyValueChanged ("CornerRadius", cornerRadius); - RegisterForRedraw (); - } - } - /// <summary> - /// 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. - /// </summary> - [DesignCategory ("Layout")][DefaultValue(0)] - public virtual int Margin { - get { return margin; } - set { - if (value == margin) - return; - margin = value; - NotifyValueChanged ("Margin", margin); - RegisterForGraphicUpdate (); - } - } - /// <summary> - /// set the visible state of the control, invisible controls does reserve space in the layouting system. - /// </summary> - [DesignCategory ("Appearance")][DefaultValue(true)] - public virtual bool Visible { - get { return isVisible; } - set { - if (value == isVisible) - return; - - isVisible = value; - - RegisterForLayouting (LayoutingType.Sizing); - - if (!isVisible) - unshownPostActions (); - - NotifyValueChanged ("Visible", isVisible); - } - } - /// <summary> - /// get or set the enabled state, disabling a control will affect focuability and - /// also it's rendering which will be grayed - /// </summary> - [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 (); - } - } - /// <summary> - /// Minimal width and height for this control - /// </summary> - [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); - } - } - /// <summary> - /// Maximum width and height for this control, unlimited if null. - /// </summary> - [DesignCategory ("Layout")][DefaultValue("0,0")] - public virtual Size MaximumSize { - get { return maximumSize; } - set { - if (value == maximumSize) - return; - - maximumSize = value; - - NotifyValueChanged ("MaximumSize", maximumSize); - RegisterForLayouting (LayoutingType.Sizing); - } - } - /// <summary> - /// 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 - /// </summary> - [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; - - lock (IFace.LayoutMutex) { - OnDataSourceChanged (this, dse); - NotifyValueChanged ("DataSource", DataSource); - } - } - get { - return rootDataLevel ? dataSource : dataSource == null ? - LogicalParent == null ? null : - LogicalParent is GraphicObject ? (LogicalParent as GraphicObject).DataSource : null : - dataSource; - } - } - /// <summary> - /// If true, rendering of GraphicObject is clipped inside client rectangle - /// </summary> - [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_BINDING - Debug.WriteLine("New DataSource for => {0} \n\t{1}=>{2}", this.ToString(),e.OldDataSource,e.NewDataSource); - #endif - } - /// <summary> - /// Style key to use for this control - /// </summary> - [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<Command> ContextCommands { - get { return contextCommands; } - set { - if (contextCommands == value) - return; - contextCommands = value; - NotifyValueChanged("ContextCommands", contextCommands); - } - } - #endregion - - #region Default and Style Values loading - /// <summary> Loads the default values from XML attributes default </summary> - public void loadDefaultValues() - { -// #if DEBUG_LOAD -// Debug.WriteLine ("LoadDefValues for " + this.ToString ()); -// #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<Style> styling = new List<Style>(); - - //Search for a style matching : - //1: Full class name, with full namespace - //2: class name - //3: style may have been registered with their ressource ID minus .style extention - // those files being placed in a Styles folder - string styleKey = Style; - if (!string.IsNullOrEmpty (Style)) { - if (IFace.Styling.ContainsKey (Style)) { - styling.Add (IFace.Styling [Style]); - } - } - if (IFace.Styling.ContainsKey (thisType.FullName)) { - styling.Add (IFace.Styling [thisType.FullName]); - if (string.IsNullOrEmpty (styleKey)) - styleKey = thisType.FullName; - } - if (IFace.Styling.ContainsKey (thisType.Name)) { - styling.Add (IFace.Styling [thisType.Name]); - if (string.IsNullOrEmpty (styleKey)) - styleKey = thisType.Name; - } - - if (string.IsNullOrEmpty (styleKey)) - styleKey = thisType.FullName; - - //Reflexion being very slow compared to dyn method or delegates, - //I compile the initial values coded in the CustomAttribs of the class, - //all other instance of this type would not longer use reflexion to init properly - //but will fetch the dynamic initialisation method compiled for this precise type - //TODO:measure speed gain. - #region Delfault values Loading dynamic compilation - DynamicMethod dm = null; - ILGenerator il = null; - - dm = new DynamicMethod("dyn_loadDefValues", - MethodAttributes.Family | MethodAttributes.FamANDAssem | MethodAttributes.NewSlot, - CallingConventions.Standard, - typeof(void),new Type[] {CompilerServices.TObject},thisType,true); - - il = dm.GetILGenerator(256); - il.DeclareLocal(CompilerServices.TObject); - il.Emit(OpCodes.Nop); - //set local GraphicObject to root object passed as 1st argument - il.Emit (OpCodes.Ldarg_0); - il.Emit (OpCodes.Stloc_0); - - foreach (EventInfo ei in thisType.GetEvents(BindingFlags.Public | BindingFlags.Instance)) { - string expression; - if (!getDefaultEvent(ei, styling, out expression)) - continue; - //TODO:dynEventHandler could be cached somewhere, maybe a style instanciator class holding the styling delegate and bound to it. - foreach (string exp in CompilerServices.splitOnSemiColumnOutsideAccolades(expression)) { - string trimed = exp.Trim(); - if (trimed.StartsWith ("{", StringComparison.OrdinalIgnoreCase)){ - il.Emit (OpCodes.Ldloc_0);//load this as 1st arg of event Add - - //push eventInfo as 1st arg of compile - il.Emit (OpCodes.Ldloc_0); - il.Emit (OpCodes.Call, CompilerServices.miGetType); - il.Emit (OpCodes.Ldstr, ei.Name);//push event name - il.Emit (OpCodes.Call, CompilerServices.miGetEvent); - //push expression as 2nd arg of compile - il.Emit (OpCodes.Ldstr, trimed.Substring (1, trimed.Length - 2)); - //push null as 3rd arg, currentNode, not known when instanciing - il.Emit (OpCodes.Ldnull); - il.Emit (OpCodes.Callvirt, CompilerServices.miCompileDynEventHandler); - il.Emit (OpCodes.Castclass, ei.EventHandlerType); - il.Emit (OpCodes.Callvirt, ei.AddMethod); - }else - Debug.WriteLine("error in styling, event not handled : " + trimed); - } - } - - foreach (PropertyInfo pi in thisType.GetProperties(BindingFlags.Public | BindingFlags.Instance)) { - if (pi.GetSetMethod () == null) - continue; - XmlIgnoreAttribute xia = (XmlIgnoreAttribute)pi.GetCustomAttribute (typeof(XmlIgnoreAttribute)); - if (xia != null) - continue; - - object defaultValue; - string name = ""; - XmlAttributeAttribute xaa = (XmlAttributeAttribute)pi.GetCustomAttribute (typeof(XmlAttributeAttribute)); - if (xaa != null) { - if (string.IsNullOrEmpty (xaa.AttributeName)) - name = pi.Name; - else - name = xaa.AttributeName; - }else - name = pi.Name; - - int styleIndex = -1; - if (styling.Count > 0){ - for (int i = 0; i < styling.Count; i++) { - if (styling[i].ContainsKey (name)){ - styleIndex = i; - break; - } - } - } - if (styleIndex >= 0){ - if (pi.PropertyType.IsEnum)//maybe should be in parser.. - defaultValue = Enum.Parse(pi.PropertyType, (string)styling[styleIndex] [name], true); - else - defaultValue = styling[styleIndex] [name]; - - #if DESIGN_MODE - if (defaultValue != null){ - FileLocation fl = styling[styleIndex].Locations[name]; - il.Emit (OpCodes.Ldloc_0); - il.Emit (OpCodes.Ldstr, name); - il.Emit (OpCodes.Ldstr, fl.FilePath); - il.Emit (OpCodes.Ldc_I4, fl.Line); - il.Emit (OpCodes.Ldc_I4, fl.Column); - il.Emit (OpCodes.Call, miDesignAddDefLoc); - - il.Emit (OpCodes.Ldloc_0); - il.Emit (OpCodes.Ldfld, typeof(GraphicObject).GetField("design_style_values")); - il.Emit (OpCodes.Ldstr, name); - il.Emit (OpCodes.Ldstr, defaultValue.ToString()); - il.Emit (OpCodes.Call, CompilerServices.miDicStrStrAdd); - } - #endif - - }else { - DefaultValueAttribute dv = (DefaultValueAttribute)pi.GetCustomAttribute (typeof (DefaultValueAttribute)); - if (dv == null) - continue; - defaultValue = dv.Value; - } - - CompilerServices.EmitSetValue (il, pi, defaultValue); - } - il.Emit(OpCodes.Ret); - #endregion - - try { - IFace.DefaultValuesLoader[styleKey] = (Interface.LoaderInvoker)dm.CreateDelegate(typeof(Interface.LoaderInvoker)); - IFace.DefaultValuesLoader[styleKey] (this); - } catch (Exception ex) { - throw new Exception ("Error applying style <" + styleKey + ">:", ex); - } - onInitialized (this, null); - } - protected virtual void onInitialized (object sender, EventArgs e){ - Initialized.Raise(sender, e); - } - bool getDefaultEvent(EventInfo ei, List<Style> styling, - out string expression){ - expression = ""; - if (styling.Count > 0){ - for (int i = 0; i < styling.Count; i++) { - if (styling[i].ContainsKey (ei.Name)){ - expression = (string)styling[i] [ei.Name]; - return true; - } - } - } - return false; - } - #endregion - - public virtual GraphicObject FindByName(string nameToFind){ - return string.Equals(nameToFind, name, StringComparison.Ordinal) ? this : null; - } - public virtual bool Contains(GraphicObject goToFind){ - return false; - } - /// <summary> - /// return true if this is contained inside go - /// </summary> - public bool IsOrIsInside(GraphicObject go){ - if (this == go) - return true; - ILayoutable p = this.Parent; - while (p != null) { - if (p == go) - return true; - p = p.Parent; - } - return false; - } - - #region Drag&Drop - [DesignCategory ("DragAndDrop")][DefaultValue(false)] - public virtual bool AllowDrag { - get { return allowDrag; } - set { - if (allowDrag == value) - return; - allowDrag = value; - NotifyValueChanged ("AllowDrag", allowDrag); - } - } - [DesignCategory ("DragAndDrop")][DefaultValue(false)] - public virtual bool AllowDrop { - get { return allowDrop; } - set { - if (allowDrop == value) - return; - allowDrop = value; - NotifyValueChanged ("AllowDrop", allowDrop); - } - } - -// public List<Type> AllowedDroppedTypes; -// public void AddAllowedDroppedType (Type newType){ -// if (AllowedDroppedTypes == null) -// AllowedDroppedTypes = new List<Type> (); -// AllowedDroppedTypes.Add (newType); -// NotifyValueChanged ("AllowDrop", AllowDrop); -// } -// [XmlIgnore]public virtual bool AllowDrop { -// get { return AllowedDroppedTypes?.Count>0; } -// } - [XmlIgnore]public virtual bool IsDragged { - get { return isDragged; } - set { - if (isDragged == value) - return; - isDragged = value; - - NotifyValueChanged ("IsDragged", IsDragged); - } - } - /// <summary> - /// fired when drag and drop operation start - /// </summary> - protected virtual void onStartDrag (object sender, DragDropEventArgs e){ - IFace.HoverWidget = null; - IsDragged = true; - StartDrag.Raise (this, e); - #if DEBUG_DRAGNDROP - Debug.WriteLine(this.ToString() + " : START DRAG => " + e.ToString()); - #endif - } - /// <summary> - /// Occured when dragging ends without dropping - /// </summary> - protected virtual void onEndDrag (object sender, DragDropEventArgs e){ - IsDragged = false; - EndDrag.Raise (this, e); - #if DEBUG_DRAGNDROP - Debug.WriteLine(this.ToString() + " : END DRAG => " + e.ToString()); - #endif - } - protected virtual void onDragEnter (object sender, DragDropEventArgs e){ - e.DropTarget = this; - DragEnter.Raise (this, e); - #if DEBUG_DRAGNDROP - Debug.WriteLine(this.ToString() + " : DRAG Enter => " + e.ToString()); - #endif - } - protected virtual void onDragLeave (object sender, DragDropEventArgs e){ - e.DropTarget = null; - DragLeave.Raise (this, e); - #if DEBUG_DRAGNDROP - Debug.WriteLine(this.ToString() + " : DRAG Leave => " + e.ToString()); - #endif - } - protected virtual void onDrop (object sender, DragDropEventArgs e){ - IsDragged = false; - Drop.Raise (this, e); - //e.DropTarget.onDragLeave (this, e);//raise drag leave in target - #if DEBUG_DRAGNDROP - Debug.WriteLine(this.ToString() + " : DROP => " + e.ToString()); - #endif - } - public bool IsDropTarget { - get { return IFace.DragAndDropOperation?.DropTarget == this; } - } - - #endregion - - #region Queuing - /// <summary> - /// Register old and new slot for clipping - /// </summary> - public virtual void ClippingRegistration(){ - #if DEBUG_UPDATE - Debug.WriteLine (string.Format("ClippingRegistration -> {0}", this.ToString ())); - #endif - parentRWLock.EnterReadLock (); - if (parent != null) { - Parent.RegisterClip (LastPaintedSlot); - Parent.RegisterClip (Slot); - } - parentRWLock.ExitReadLock (); - } - /// <summary> - /// Add clip rectangle to this.clipping and propagate up to root - /// </summary> - /// <param name="clip">Clip rectangle</param> - public virtual void RegisterClip(Rectangle clip){ - #if DEBUG_UPDATE - Debug.WriteLine (string.Format("RegisterClip -> {1}:{0}", clip, this.ToString ())); - #endif - Rectangle r = clip + ClientRectangle.Position; - if (CacheEnabled && !IsDirty) - Clipping.UnionRectangle (r); - if (Parent == null) - return; - GraphicObject p = Parent as GraphicObject; - if (p?.IsDirty == true && p?.CacheEnabled == true) - return; - Parent.RegisterClip (r + Slot.Position); - } - /// <summary> Full update, taking care of sizing policy </summary> - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void RegisterForGraphicUpdate () - { - #if DEBUG_UPDATE - Debug.WriteLine (string.Format("RegisterForGraphicUpdate (IsDirty set)-> {0}", this.ToString ())); - #endif - IsDirty = true; - if (Width.IsFit || Height.IsFit) - RegisterForLayouting (LayoutingType.Sizing); - else if (RegisteredLayoutings == LayoutingType.None) - IFace.EnqueueForRepaint (this); - } - /// <summary> query an update of the content, a redraw </summary> - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void RegisterForRedraw () - { - #if DEBUG_UPDATE - Debug.WriteLine (string.Format("RegisterForRedraw (IsDirty set)-> {0}", this.ToString ())); - #endif - IsDirty = true; - if (RegisteredLayoutings == LayoutingType.None) - IFace.EnqueueForRepaint (this); - } - #endregion - - #region Layouting - - /// <summary> return size of content + margins </summary> - protected virtual int measureRawSize (LayoutingType lt) { - return lt == LayoutingType.Width ? - contentSize.Width + 2 * Margin: contentSize.Height + 2 * Margin; - } - /// <summary> By default in groups, LayoutingType.ArrangeChildren is reset </summary> - public virtual void ChildrenLayoutingConstraints(ref LayoutingType layoutType){ - } - public virtual bool ArrangeChildren { get { return false; } } - public virtual void RegisterForLayouting(LayoutingType layoutType){ - if (Parent == null) - return; - lock (IFace.LayoutMutex) { - //prevent queueing same LayoutingType for this - layoutType &= (~RegisteredLayoutings); - - if (layoutType == LayoutingType.None) - return; - //dont set position for stretched item - if (Width == Measure.Stretched) - layoutType &= (~LayoutingType.X); - if (Height == Measure.Stretched) - layoutType &= (~LayoutingType.Y); - - if (!ArrangeChildren) - layoutType &= (~LayoutingType.ArrangeChildren); - - //apply constraints depending on parent type - if (Parent is GraphicObject) - (Parent as GraphicObject).ChildrenLayoutingConstraints (ref layoutType); - -// //prevent queueing same LayoutingType for this -// layoutType &= (~RegisteredLayoutings); - - if (layoutType == LayoutingType.None) - return; - - //enqueue LQI LayoutingTypes separately - if (layoutType.HasFlag (LayoutingType.Width)) - IFace.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.Width, this)); - if (layoutType.HasFlag (LayoutingType.Height)) - IFace.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.Height, this)); - if (layoutType.HasFlag (LayoutingType.X)) - IFace.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.X, this)); - if (layoutType.HasFlag (LayoutingType.Y)) - IFace.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.Y, this)); - if (layoutType.HasFlag (LayoutingType.ArrangeChildren)) - IFace.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.ArrangeChildren, this)); - } - } - - /// <summary> trigger dependant sizing component update </summary> - public virtual void OnLayoutChanges(LayoutingType layoutType) - { - switch (layoutType) { - case LayoutingType.Width: - RegisterForLayouting (LayoutingType.X); - break; - case LayoutingType.Height: - RegisterForLayouting (LayoutingType.Y); - break; - } - LayoutChanged.Raise (this, new LayoutingEventArgs (layoutType)); - } - internal protected void raiseLayoutChanged(LayoutingEventArgs e){ - LayoutChanged.Raise (this, e); - } - /// <summary> Update layout component only one at a time, this is where the computation of alignement - /// and size take place. - /// The redrawing will only be triggered if final slot size has changed </summary> - /// <returns><c>true</c>, if layouting was possible, <c>false</c> if conditions were not - /// met and LQI has to be re-queued</returns> - public virtual bool UpdateLayout (LayoutingType layoutType) - { - #if DEBUG_UPDATE - Debug.WriteLine (string.Format("UpdateLayout ({1})-> {0}", this.ToString (), layoutType)); - #endif - //unset bit, it would be reset if LQI is re-queued - registeredLayoutings &= (~layoutType); - - switch (layoutType) { - case LayoutingType.X: - if (Left == 0) { - - if (Parent.RegisteredLayoutings.HasFlag (LayoutingType.Width) || - RegisteredLayoutings.HasFlag (LayoutingType.Width)) - return false; - - switch (HorizontalAlignment) { - case HorizontalAlignment.Left: - Slot.X = 0; - break; - case HorizontalAlignment.Right: - Slot.X = Parent.ClientRectangle.Width - Slot.Width; - break; - case HorizontalAlignment.Center: - Slot.X = Parent.ClientRectangle.Width / 2 - Slot.Width / 2; - break; - } - } else - Slot.X = Left; - - if (LastSlots.X == Slot.X) - break; - - IsDirty = true; - - OnLayoutChanges (layoutType); - - LastSlots.X = Slot.X; - break; - case LayoutingType.Y: - if (Top == 0) { - - if (Parent.RegisteredLayoutings.HasFlag (LayoutingType.Height) || - RegisteredLayoutings.HasFlag (LayoutingType.Height)) - return false; - - switch (VerticalAlignment) { - case VerticalAlignment.Top://this could be processed even if parent Height is not known - Slot.Y = 0; - break; - case VerticalAlignment.Bottom: - Slot.Y = Parent.ClientRectangle.Height - Slot.Height; - break; - case VerticalAlignment.Center: - Slot.Y = Parent.ClientRectangle.Height / 2 - Slot.Height / 2; - break; - } - } else - Slot.Y = Top; - - if (LastSlots.Y == Slot.Y) - break; - - IsDirty = true; - - OnLayoutChanges (layoutType); - - LastSlots.Y = Slot.Y; - break; - case LayoutingType.Width: - if (Visible) { - if (Width.IsFixed) - Slot.Width = Width; - else if (Width == Measure.Fit) { - Slot.Width = measureRawSize (LayoutingType.Width); - } else if (Parent.RegisteredLayoutings.HasFlag (LayoutingType.Width)) - return false; - else if (Width == Measure.Stretched) - Slot.Width = Parent.ClientRectangle.Width; - else - Slot.Width = (int)Math.Round ((double)(Parent.ClientRectangle.Width * Width) / 100.0); - - if (Slot.Width < 0) - return false; - - //size constrain - if (Slot.Width < MinimumSize.Width) { - Slot.Width = MinimumSize.Width; - //NotifyValueChanged ("WidthPolicy", Measure.Stretched); - } else if (Slot.Width > MaximumSize.Width && MaximumSize.Width > 0) { - Slot.Width = MaximumSize.Width; - //NotifyValueChanged ("WidthPolicy", Measure.Stretched); - } - } else - Slot.Width = 0; - - if (LastSlots.Width == Slot.Width) - break; - - IsDirty = true; - - OnLayoutChanges (layoutType); - - LastSlots.Width = Slot.Width; - break; - case LayoutingType.Height: - if (Visible) { - if (Height.IsFixed) - Slot.Height = Height; - else if (Height == Measure.Fit) { - Slot.Height = measureRawSize (LayoutingType.Height); - } else if (Parent.RegisteredLayoutings.HasFlag (LayoutingType.Height)) - return false; - else if (Height == Measure.Stretched) - Slot.Height = Parent.ClientRectangle.Height; - else - Slot.Height = (int)Math.Round ((double)(Parent.ClientRectangle.Height * Height) / 100.0); - - if (Slot.Height < 0) - return false; - - //size constrain - if (Slot.Height < MinimumSize.Height) { - Slot.Height = MinimumSize.Height; - //NotifyValueChanged ("HeightPolicy", Measure.Stretched); - } else if (Slot.Height > MaximumSize.Height && MaximumSize.Height > 0) { - Slot.Height = MaximumSize.Height; - //NotifyValueChanged ("HeightPolicy", Measure.Stretched); - } - } else - Slot.Height = 0; - - if (LastSlots.Height == Slot.Height) - break; - - IsDirty = true; - - OnLayoutChanges (layoutType); - - LastSlots.Height = Slot.Height; - break; - } - - //if no layouting remains in queue for item, registre for redraw - if (this.registeredLayoutings == LayoutingType.None && IsDirty) - IFace.EnqueueForRepaint (this); - - return true; - } - #endregion - - #region Rendering - /// <summary> This is the common overridable drawing routine to create new widget </summary> - protected virtual void onDraw(Context gr) - { - #if DEBUG_UPDATE - Debug.WriteLine (string.Format("OnDraw -> {0}", this.ToString ())); - #endif - - Rectangle rBack = new Rectangle (Slot.Size); - - Background.SetAsSource (gr, rBack); - CairoHelpers.CairoRectangle (gr, rBack, cornerRadius); - gr.Fill (); - } - - /// <summary> - /// Internal drawing context creation on a cached surface limited to slot size - /// this trigger the effective drawing routine </summary> - protected virtual void RecreateCache () - { - #if DEBUG_UPDATE - Debug.WriteLine (string.Format("RecreateCache -> {0}", this.ToString ())); - #endif - IsDirty = false; - if (bmp != null) - bmp.Dispose (); - bmp = new ImageSurface (Format.Argb32, Slot.Width, Slot.Height); - using (Context gr = new Context (bmp)) { - gr.Antialias = Interface.Antialias; - onDraw (gr); - } - bmp.Flush (); - } - protected virtual void UpdateCache(Context ctx){ - #if DEBUG_UPDATE - Debug.WriteLine (string.Format("UpdateCache -> {0}", this.ToString ())); - #endif - Rectangle rb = Slot + Parent.ClientRectangle.Position; - if (clearBackground) { - ctx.Save (); - ctx.Operator = Operator.Clear; - ctx.Rectangle (rb); - ctx.Fill (); - ctx.Restore (); - } - ctx.SetSourceSurface (bmp, rb.X, rb.Y); - ctx.Paint (); - Clipping.Dispose (); - Clipping = new Region (); - } - /// <summary> Chained painting routine on the parent context of the actual cached version - /// of the widget </summary> - public virtual void Paint (ref Context ctx) - { - #if DEBUG_UPDATE - Debug.WriteLine (string.Format("Paint -> {0}", this.ToString ())); - #endif - //TODO:this test should not be necessary - if (Slot.Height < 0 || Slot.Width < 0 || parent == null) - return; - lock (this) { - if (cacheEnabled) { - if (Slot.Width > Interface.MaxCacheSize || Slot.Height > Interface.MaxCacheSize) - cacheEnabled = false; - } - - if (cacheEnabled) { - if (IsDirty) - RecreateCache (); - - UpdateCache (ctx); - if (!isEnabled) - paintDisabled (ctx, Slot + Parent.ClientRectangle.Position); - } else { - Rectangle rb = Slot + Parent.ClientRectangle.Position; - ctx.Save (); - - ctx.Translate (rb.X, rb.Y); - - onDraw (ctx); - if (!isEnabled) - paintDisabled (ctx, Slot); - - ctx.Restore (); - } - LastPaintedSlot = Slot; - } - } - void paintDisabled(Context gr, Rectangle rb){ - gr.Operator = Operator.Xor; - gr.SetSourceRGBA (0.6, 0.6, 0.6, 0.3); - gr.Rectangle (rb); - gr.Fill (); - gr.Operator = Operator.Over; - } - #endregion - - #region Keyboard handling - public virtual void onKeyDown(object sender, KeyboardKeyEventArgs e){ - KeyDown.Raise (sender, e); - } - public virtual void onKeyUp(object sender, KeyboardKeyEventArgs e){ - KeyUp.Raise (sender, e); - } - public virtual void onKeyPress(object sender, KeyPressEventArgs e){ - KeyPress.Raise (sender, e); - } - #endregion - - #region Mouse handling - /// <summary> - /// Recursive local coordinate point test. - /// After test on parent, point m is in local coord system. - /// </summary> - /// <returns>return true, if point is in the bounds of this control</returns> - /// <param name="m">by ref point to test, init value is not kept</param> - public virtual bool PointIsIn(ref Point m) - { - if (!(Visible & isEnabled)||IsDragged) - return false; - if (!parent.PointIsIn(ref m)) - return false; - m -= (parent.getSlot().Position + parent.ClientRectangle.Position) ; - return Slot.ContainsOrIsEqual (m); - } - public virtual bool MouseIsIn(Point m) - { - return (!(Visible & isEnabled)||IsDragged) ? false : PointIsIn (ref m); - } - public virtual void checkHoverWidget(MouseMoveEventArgs e) - { - if (IFace.HoverWidget != this) { - IFace.HoverWidget = this; - onMouseEnter (this, e); - } - - //this.onMouseMove (this, e);//without this, window border doesn't work, should be removed - } - public virtual void onMouseMove(object sender, MouseMoveEventArgs e) - { - if (AllowDrag & HasFocus & e.Mouse.LeftButton == ButtonState.Pressed) { - if (IFace.DragAndDropOperation == null) { - IFace.DragAndDropOperation = new DragDropEventArgs (this); - onStartDrag (this, IFace.DragAndDropOperation); - } - } - - //dont bubble event if dragged, mouse move is routed directely from iface - //to let other control behind have mouse entering - if (isDragged) - return; - - //bubble event to the top - GraphicObject p = focusParent; - if (p != null) - p.onMouseMove(sender,e); - - MouseMove.Raise (this, e); - } - public virtual void onMouseDown(object sender, MouseButtonEventArgs e){ - #if DEBUG_FOCUS - Debug.WriteLine("MOUSE DOWN => " + this.ToString()); - #endif - - if (IFace.ActiveWidget == null) - IFace.ActiveWidget = this; - if (this.Focusable && !Interface.FocusOnHover) { - BubblingMouseButtonEventArg be = e as BubblingMouseButtonEventArg; - if (be.Focused == null) { - be.Focused = this; - IFace.FocusedWidget = this; - if (e.Button == MouseButton.Right && this.ContextCommands != null) - IFace.ShowContextMenu (this); - } - } - //bubble event to the top - GraphicObject p = focusParent; - if (p != null) - p.onMouseDown(sender,e); - - MouseDown.Raise (this, e); - } - public virtual void onMouseUp(object sender, MouseButtonEventArgs e){ - #if DEBUG_FOCUS - Debug.WriteLine("MOUSE UP => " + this.ToString()); - #endif - - if (IFace.DragAndDropOperation != null){ - if (IFace.DragAndDropOperation.DragSource == this) { - if (IFace.DragAndDropOperation.DropTarget != null) - onDrop (this, IFace.DragAndDropOperation); - else - onEndDrag (this, IFace.DragAndDropOperation); - IFace.DragAndDropOperation = null; - } - } - - //bubble event to the top - GraphicObject p = focusParent; - if (p != null) - p.onMouseUp(sender,e); - - MouseUp.Raise (this, e); - } - public virtual void onMouseClick(object sender, MouseButtonEventArgs e){ - #if DEBUG_FOCUS - Debug.WriteLine("CLICK => " + this.ToString()); - #endif - GraphicObject p = focusParent; - if (p != null) - p.onMouseClick(sender,e); - MouseClick.Raise (this, e); - } - public virtual void onMouseDoubleClick(object sender, MouseButtonEventArgs e){ - #if DEBUG_FOCUS - Debug.WriteLine("DOUBLE CLICK => " + this.ToString()); - #endif - GraphicObject p = focusParent; - if (p != null) - p.onMouseDoubleClick(sender,e); - MouseDoubleClick.Raise (this, e); - } - public virtual void onMouseWheel(object sender, MouseWheelEventArgs e){ - GraphicObject p = focusParent; - if (p != null) - p.onMouseWheel(sender,e); - - MouseWheelChanged.Raise (this, e); - } - public virtual void onMouseEnter(object sender, MouseMoveEventArgs e) - { - #if DEBUG_FOCUS - Debug.WriteLine("MouseEnter => " + this.ToString()); - #endif - MouseEnter.Raise (this, e); - } - public virtual void onMouseLeave(object sender, MouseMoveEventArgs e) - { - #if DEBUG_FOCUS - Debug.WriteLine("MouseLeave => " + this.ToString()); - #endif - MouseLeave.Raise (this, e); - } - public virtual void onHover(object sender, EventArgs e) - { - #if DEBUG_FOCUS - Debug.WriteLine("MouseHover => " + this.ToString()); - #endif - if (IFace.DragAndDropOperation != null) { - GraphicObject g = this; - while (g != null) { - if (g.AllowDrop) { - if (IFace.DragAndDropOperation.DragSource != this && IFace.DragAndDropOperation.DropTarget != this) { - if (IFace.DragAndDropOperation.DropTarget != null) - IFace.DragAndDropOperation.DropTarget.onDragLeave (this, IFace.DragAndDropOperation); - g.onDragEnter (this, IFace.DragAndDropOperation); - } - break; - } - g = g.focusParent; - } - } - Hover.Raise (this, e); - } - public virtual void onUnHover(object sender, EventArgs e) - { - #if DEBUG_FOCUS - Debug.WriteLine("MouseUnHover => " + this.ToString()); - #endif - UnHover.Raise (this, e); - } - #endregion - - protected virtual void onFocused(object sender, EventArgs e){ - #if DEBUG_FOCUS - Debug.WriteLine("Focused => " + this.ToString()); - #endif - Focused.Raise (this, e); - } - protected virtual void onUnfocused(object sender, EventArgs e){ - #if DEBUG_FOCUS - Debug.WriteLine("UnFocused => " + this.ToString()); - #endif - Unfocused.Raise (this, e); - } - public virtual void onEnable(object sender, EventArgs e){ - Enabled.Raise (this, e); - } - public virtual void onDisable(object sender, EventArgs e){ - Disabled.Raise (this, e); - } - protected virtual void onParentChanged(object sender, DataSourceChangeEventArgs e) { -// if (e.NewDataSource != null) { -// if (width == Measure.Inherit) -// RegisterForLayouting (LayoutingType.Width); -// if (height == Measure.Inherit) -// RegisterForLayouting (LayoutingType.Height); -// } - - ParentChanged.Raise (this, e); - if (logicalParent == null) - LogicalParentChanged.Raise (this, e); - } - protected virtual void onLogicalParentChanged(object sender, DataSourceChangeEventArgs e) { - LogicalParentChanged.Raise (this, e); - } - internal void ClearTemplateBinding(){ - #if DEBUG_UPDATE - Debug.WriteLine (string.Format("ClearTemplateBinding: {0}", this.ToString())); - #endif - if (ValueChanged == null) - return; - EventInfo eiEvt = this.GetType().GetEvent ("ValueChanged"); - foreach (Delegate d in ValueChanged.GetInvocationList()) { - if (d.Method.Name == "dyn_tmpValueChanged") { - eiEvt.RemoveEventHandler (this, d); - #if DEBUG_BINDING - Debug.WriteLine ("\t{0} template binding handler removed in {1} for: {2}", d.Method.Name, this, "ValueChanged"); - #endif - } - } - } - public override string ToString () - { - string tmp =""; - - if (Parent != null) - tmp = Parent.ToString () + tmp; - #if DEBUG_LAYOUTING - return Name == "unamed" ? tmp + "." + this.GetType ().Name + uid.ToString(): tmp + "." + Name; - #else - return Name == "unamed" ? tmp + "." + this.GetType ().Name : tmp + "." + Name; - #endif - } - /// <summary> - /// Checks to handle when widget is removed from the visible graphic tree - /// </summary> - void unshownPostActions () { - if (IFace.ActiveWidget != null) { - if (IFace.ActiveWidget.IsOrIsInside (this)) - IFace.ActiveWidget = null; - } - if (IFace.FocusedWidget != null) { - if (IFace.FocusedWidget.IsOrIsInside (this)) - IFace.FocusedWidget = null; - } - if (IFace.HoverWidget != null) { - if (IFace.HoverWidget.IsOrIsInside (this)) { - IFace.HoverWidget = null; - IFace.ProcessMouseMove (IFace.Mouse.X, IFace.Mouse.Y); - } - } - } - } -} diff --git a/src/GraphicObjects/Grid.cs b/src/GraphicObjects/Grid.cs deleted file mode 100644 index 4ae906a7..00000000 --- a/src/GraphicObjects/Grid.cs +++ /dev/null @@ -1,171 +0,0 @@ -// -// Grid.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Diagnostics; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Xml.Serialization; -using System.ComponentModel; - -namespace Crow -{ - /// <summary> - /// Simple grid container - /// Allow symetric placement of children on a grid, - /// excedental child (above grid sizing) are ignored - /// and invisible child keep their place in the grid - /// </summary> - public class Grid : Group - { - #region CTOR - protected Grid () : base(){} - public Grid(Interface iface) : base(iface) - { - } - #endregion - - #region Private fields - int _spacing; - int _columnCount; - int _rowCount; - #endregion - - #region Public Properties - [XmlAttributeAttribute()][DefaultValue(2)] - public int Spacing - { - get { return _spacing; } - set { _spacing = value; } - } - [XmlAttributeAttribute()][DefaultValue(2)] - public virtual int ColumnCount - { - get { return _columnCount; } - set { - if (_columnCount == value) - return; - - _columnCount = value; - - NotifyValueChanged ("ColumnCount", ColumnCount); - this.RegisterForLayouting (LayoutingType.ArrangeChildren); - } - } - [XmlAttributeAttribute()][DefaultValue(2)] - public virtual int RowCount - { - get { return _rowCount; } - set { - if (_rowCount == value) - return; - - _rowCount = value; - - NotifyValueChanged ("RowCount", RowCount); - this.RegisterForLayouting (LayoutingType.ArrangeChildren); - } - } - public virtual int CaseWidth { - get { return (Slot.Width - (ColumnCount - 1) * Spacing) / ColumnCount; } - } - public virtual int CaseHeight { - get { return (Slot.Height - (RowCount - 1) * Spacing) / RowCount; } - } - - #endregion - - #region GraphicObject Overrides -// protected override Size measureRawSize () -// { -// Size tmp = new Size (); -// -// foreach (GraphicObject c in Children.Where(ch=>ch.Visible)) { -// tmp.Width = Math.Max (tmp.Width, c.Slot.Width); -// tmp.Height = Math.Max (tmp.Height, c.Slot.Height); -// } -// -// tmp.Width *= (ColumnCount - 1) * Spacing / ColumnCount;; -// tmp.Height *= (RowCount - 1) * Spacing / RowCount; -// tmp.Width += 2 * Margin; -// tmp.Height += 2 * Margin; -// -// return tmp; -// } - public override void ChildrenLayoutingConstraints (ref LayoutingType layoutType) - { - //Prevent child repositionning - layoutType &= (~LayoutingType.Positioning); - } - public override bool ArrangeChildren { get { return true; } } - public virtual void ComputeChildrenPositions() - { - int slotWidth = CaseWidth; - int slotHeight = CaseHeight; - for (int curY = 0; curY < RowCount; curY++) { - for (int curX = 0; curX < ColumnCount; curX++) { - int idx = curY * ColumnCount + curX; - if (idx >= Children.Count) - return; - GraphicObject c = Children [idx]; - if (!c.Visible) - continue; - c.Slot.X = curX * (slotWidth + Spacing); - c.Slot.Y = curY * (slotHeight + Spacing); - //c.Slot.Width = slotWidth; - //c.Slot.Height = slotHeight; - } - } - IsDirty = true; - } - public override void OnChildLayoutChanges (object sender, LayoutingEventArgs arg) - { - //base.OnChildLayoutChanges (sender, arg); - } - - public override bool UpdateLayout (LayoutingType layoutType) - { - RegisteredLayoutings &= (~layoutType); - - if (layoutType == LayoutingType.ArrangeChildren) { - - ComputeChildrenPositions (); - - //if no layouting remains in queue for item, registre for redraw - if (RegisteredLayoutings == LayoutingType.None && IsDirty) - IFace.EnqueueForRepaint (this); - - return true; - } - - return base.UpdateLayout(layoutType); - } - #endregion - - - } -} diff --git a/src/GraphicObjects/Group.cs b/src/GraphicObjects/Group.cs deleted file mode 100644 index a90947a5..00000000 --- a/src/GraphicObjects/Group.cs +++ /dev/null @@ -1,469 +0,0 @@ -// -// Group.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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 Cairo; -using System.Diagnostics; -using System.Reflection; -using System.Threading; - - -namespace Crow -{ - public class Group : GraphicObject - { - #if DESIGN_MODE - public override bool FindByDesignID(string designID, out GraphicObject go){ - go = null; - if (base.FindByDesignID (designID, out go)) - return true; - childrenRWLock.EnterReadLock (); - foreach (GraphicObject w in Children) { - if (!w.FindByDesignID (designID, out go)) - continue; - childrenRWLock.ExitReadLock (); - return true; - } - childrenRWLock.ExitReadLock (); - return false; - } - public override void getIML (System.Xml.XmlDocument doc, System.Xml.XmlNode parentElem) - { - if (this.design_isTGItem) - return; - base.getIML (doc, parentElem); - foreach (GraphicObject g in Children) { - g.getIML (doc, parentElem.LastChild); - } - } - #endif - - protected ReaderWriterLockSlim childrenRWLock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); - - #region CTOR - public Group () : base() {} - public Group(Interface iface) : base(iface){} - #endregion - - #region EVENT HANDLERS - public event EventHandler<EventArgs> ChildrenCleared; - #endregion - - internal GraphicObject largestChild = null; - internal GraphicObject tallestChild = null; - - bool _multiSelect = false; - List<GraphicObject> children = new List<GraphicObject>(); - - public virtual List<GraphicObject> Children { - get { return children; } - } - [XmlAttributeAttribute()][DefaultValue(false)] - public bool MultiSelect - { - get { return _multiSelect; } - set { _multiSelect = value; } - } - public virtual void AddChild(GraphicObject g){ - childrenRWLock.EnterWriteLock(); - - g.Parent = this; - Children.Add (g); - - childrenRWLock.ExitWriteLock(); - - g.RegisteredLayoutings = LayoutingType.None; - g.LayoutChanged += OnChildLayoutChanges; - g.RegisterForLayouting (LayoutingType.Sizing | LayoutingType.ArrangeChildren); - } - public virtual void RemoveChild(GraphicObject child) - { - child.LayoutChanged -= OnChildLayoutChanges; - //check if HoverWidget is removed from Tree - if (IFace.HoverWidget != null) { - if (this.Contains (IFace.HoverWidget)) - IFace.HoverWidget = null; - } - - childrenRWLock.EnterWriteLock (); - - Children.Remove(child); - child.Parent = null; - - childrenRWLock.ExitWriteLock (); - - if (child == largestChild && Width == Measure.Fit) - searchLargestChild (); - if (child == tallestChild && Height == Measure.Fit) - searchTallestChild (); - - this.RegisterForLayouting (LayoutingType.Sizing | LayoutingType.ArrangeChildren); - - } - public virtual void DeleteChild(GraphicObject child) - { - RemoveChild (child); - child.Dispose (); - } - public virtual void InsertChild (int idx, GraphicObject g) { - childrenRWLock.EnterWriteLock (); - - g.Parent = this; - Children.Insert (idx, g); - - childrenRWLock.ExitWriteLock (); - - g.RegisteredLayoutings = LayoutingType.None; - g.LayoutChanged += OnChildLayoutChanges; - g.RegisterForLayouting (LayoutingType.Sizing | LayoutingType.ArrangeChildren); - } - public virtual void RemoveChild (int idx) { - RemoveChild (children[idx]); - } - public virtual void DeleteChild (int idx) { - DeleteChild (children[idx]); - } - public virtual void ClearChildren() - { - childrenRWLock.EnterWriteLock (); - - while (Children.Count > 0) { - GraphicObject g = Children [Children.Count - 1]; - g.LayoutChanged -= OnChildLayoutChanges; - Children.RemoveAt (Children.Count - 1); - g.Dispose (); - } - - childrenRWLock.ExitWriteLock (); - - resetChildrenMaxSize (); - - this.RegisterForLayouting (LayoutingType.Sizing); - ChildrenCleared.Raise (this, new EventArgs ()); - } - public override void OnDataSourceChanged (object sender, DataSourceChangeEventArgs e) - { - base.OnDataSourceChanged (this, e); - - childrenRWLock.EnterReadLock (); - foreach (GraphicObject g in Children) { - if (g.localDataSourceIsNull & g.localLogicalParentIsNull) - g.OnDataSourceChanged (g, e); - } - childrenRWLock.ExitReadLock (); - } - - public void putWidgetOnTop(GraphicObject w) - { - if (Children.Contains(w)) - { - childrenRWLock.EnterWriteLock (); - - Children.Remove (w); - Children.Add (w); - - childrenRWLock.ExitWriteLock (); - } - } - public void putWidgetOnBottom(GraphicObject w) - { - if (Children.Contains(w)) - { - childrenRWLock.EnterWriteLock (); - - Children.Remove (w); - Children.Insert (0, w); - - childrenRWLock.ExitWriteLock (); - } - } - - #region GraphicObject overrides - - public override GraphicObject FindByName (string nameToFind) - { - if (Name == nameToFind) - return this; - GraphicObject tmp = null; - - childrenRWLock.EnterReadLock (); - - foreach (GraphicObject w in Children) { - tmp = w.FindByName (nameToFind); - if (tmp != null) - break; - } - - childrenRWLock.ExitReadLock (); - - return tmp; - } - public override bool Contains (GraphicObject goToFind) - { - foreach (GraphicObject w in Children) { - if (w == goToFind) - return true; - if (w.Contains (goToFind)) - return true; - } - return false; - } - protected override int measureRawSize (LayoutingType lt) - { - if (Children.Count > 0) { - if (lt == LayoutingType.Width) { - if (largestChild == null) - searchLargestChild (); - if (largestChild == null) { - //if still null, not possible to determine a width - //because all children are stretched, force first one to fit - Children [0].Width = Measure.Fit; - return -1;//cancel actual sizing to let child computation take place - } - } else { - if (tallestChild == null) - searchTallestChild (); - if (tallestChild == null) { - Children [0].Height = Measure.Fit; - return -1; - } - } - } - return base.measureRawSize (lt); - } - - public override void OnLayoutChanges (LayoutingType layoutType) - { - base.OnLayoutChanges (layoutType); - - childrenRWLock.EnterReadLock (); - //position smaller objects in group when group size is fit - switch (layoutType) { - case LayoutingType.Width: - foreach (GraphicObject c in Children) { - if (c.Width.IsRelativeToParent) - c.RegisterForLayouting (LayoutingType.Width); - else - c.RegisterForLayouting (LayoutingType.X); - } - break; - case LayoutingType.Height: - foreach (GraphicObject c in Children) { - if (c.Height.IsRelativeToParent) - c.RegisterForLayouting (LayoutingType.Height); - else - c.RegisterForLayouting (LayoutingType.Y); - } - break; - } - childrenRWLock.ExitReadLock (); - } - protected override void onDraw (Context gr) - { - base.onDraw (gr); - - gr.Save (); - - if (ClipToClientRect) { - //clip to client zone - CairoHelpers.CairoRectangle (gr, ClientRectangle, CornerRadius); - gr.Clip (); - } - - childrenRWLock.EnterReadLock (); - - foreach (GraphicObject g in Children) { - g.Paint (ref gr); - } - - childrenRWLock.ExitReadLock (); - gr.Restore (); - } - protected override void UpdateCache (Context ctx) - { - Rectangle rb = Slot + Parent.ClientRectangle.Position; - - - Context gr = new Context (bmp); - - if (!Clipping.IsEmpty) { - for (int i = 0; i < Clipping.NumRectangles; i++) - gr.Rectangle(Clipping.GetRectangle(i)); - gr.ClipPreserve(); - gr.Operator = Operator.Clear; - gr.Fill(); - gr.Operator = Operator.Over; - - base.onDraw (gr); - - if (ClipToClientRect) { - CairoHelpers.CairoRectangle (gr, ClientRectangle, CornerRadius); - gr.Clip (); - } - - childrenRWLock.EnterReadLock (); - - foreach (GraphicObject c in Children) { - if (!c.Visible) - continue; - if (Clipping.Contains (c.Slot + ClientRectangle.Position) == RegionOverlap.Out) - continue; - c.Paint (ref gr); - } - - childrenRWLock.ExitReadLock (); - - #if DEBUG_CLIP_RECTANGLE - Clipping.stroke (gr, Color.Amaranth.AdjustAlpha (0.8)); - #endif - } - gr.Dispose (); - - ctx.SetSourceSurface (bmp, rb.X, rb.Y); - ctx.Paint (); - - Clipping.Dispose(); - Clipping = new Region (); - } - #endregion - - public virtual void OnChildLayoutChanges (object sender, LayoutingEventArgs arg) - { - GraphicObject g = sender as GraphicObject; - - switch (arg.LayoutType) { - case LayoutingType.Width: - if (Width != Measure.Fit) - return; - if (g.Slot.Width > contentSize.Width) { - largestChild = g; - contentSize.Width = g.Slot.Width; - } else if (g == largestChild) - searchLargestChild (); - - this.RegisterForLayouting (LayoutingType.Width); - break; - case LayoutingType.Height: - if (Height != Measure.Fit) - return; - if (g.Slot.Height > contentSize.Height) { - tallestChild = g; - contentSize.Height = g.Slot.Height; - } else if (g == tallestChild) - searchTallestChild (); - - this.RegisterForLayouting (LayoutingType.Height); - break; - } - } - //TODO: x,y position should be taken in account for computation of width and height - void resetChildrenMaxSize(){ - largestChild = null; - tallestChild = null; - contentSize = 0; - } - void searchLargestChild(){ - #if DEBUG_LAYOUTING - Debug.WriteLine("\tSearch largest child"); - #endif - largestChild = null; - contentSize.Width = 0; - for (int i = 0; i < Children.Count; i++) { - if (!Children [i].Visible) - continue; - if (children [i].RegisteredLayoutings.HasFlag (LayoutingType.Width)) - continue; - if (Children [i].Slot.Width > contentSize.Width) { - contentSize.Width = Children [i].Slot.Width; - largestChild = Children [i]; - } - } - } - void searchTallestChild(){ - #if DEBUG_LAYOUTING - Debug.WriteLine("\tSearch tallest child"); - #endif - tallestChild = null; - contentSize.Height = 0; - for (int i = 0; i < Children.Count; i++) { - if (!Children [i].Visible) - continue; - if (children [i].RegisteredLayoutings.HasFlag (LayoutingType.Height)) - continue; - if (Children [i].Slot.Height > contentSize.Height) { - contentSize.Height = Children [i].Slot.Height; - tallestChild = Children [i]; - } - } - } - - - #region Mouse handling - public override void checkHoverWidget (MouseMoveEventArgs e) - { - if (IFace.HoverWidget != this) { - IFace.HoverWidget = this; - onMouseEnter (this, e); - } - for (int i = Children.Count - 1; i >= 0; i--) { - if (Children[i].MouseIsIn(e.Position)) - { - Children[i].checkHoverWidget (e); - return; - } - } - base.checkHoverWidget (e); - } -// public override bool PointIsIn (ref Point m) -// { -// if (!base.PointIsIn (ref m)) -// return false; -// if (CurrentInterface.HoverWidget == this) -// return true; -// lock (Children) { -// for (int i = Children.Count - 1; i >= 0; i--) { -// if (Children [i].Slot.ContainsOrIsEqual (m) && !(bool)CurrentInterface.HoverWidget?.IsOrIsInside(Children[i])) { -// return false; -// } -// } -// } -// return true; -// } - #endregion - - protected override void Dispose (bool disposing) - { - if (disposing) { - foreach (GraphicObject c in children) - c.Dispose (); - } - base.Dispose (disposing); - } - } -} diff --git a/src/GraphicObjects/GroupBox.cs b/src/GraphicObjects/GroupBox.cs deleted file mode 100644 index 2e32ddd5..00000000 --- a/src/GraphicObjects/GroupBox.cs +++ /dev/null @@ -1,43 +0,0 @@ -// -// GroupBox.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Xml.Serialization; -using System.ComponentModel; - -namespace Crow -{ - /// <summary> - /// templated container accepting one child - /// </summary> - public class GroupBox : TemplatedContainer - { - #region CTOR - protected GroupBox () : base(){} - public GroupBox(Interface iface) : base(iface){} - #endregion - } -} diff --git a/src/GraphicObjects/HorizontalStack.cs b/src/GraphicObjects/HorizontalStack.cs deleted file mode 100644 index 64d7cae5..00000000 --- a/src/GraphicObjects/HorizontalStack.cs +++ /dev/null @@ -1,53 +0,0 @@ -// -// HorizontalStack.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Linq; -using System.Text; -using System.Xml.Serialization; - -namespace Crow -{ - /// <summary> - /// group control stacking its children horizontally - /// </summary> - public class HorizontalStack : GenericStack - { - #region CTOR - protected HorizontalStack () : base(){} - public HorizontalStack(Interface iface) : base(iface) - { - } - #endregion - - [XmlIgnore] - public override Orientation Orientation - { - get { return Orientation.Horizontal; } - } - } -} diff --git a/src/GraphicObjects/HueSelector.cs b/src/GraphicObjects/HueSelector.cs deleted file mode 100644 index 67f4ec6e..00000000 --- a/src/GraphicObjects/HueSelector.cs +++ /dev/null @@ -1,155 +0,0 @@ -// -// HueSelector.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Xml.Serialization; -using System.ComponentModel; -using Cairo; - -namespace Crow -{ - [DesignIgnore] - public class HueSelector : ColorSelector - { - #region CTOR - protected HueSelector () : base(){} - public HueSelector (Interface iface) : base(iface) - { - } - #endregion - - Orientation _orientation; - double hue; - - [XmlAttributeAttribute][DefaultValue(Orientation.Horizontal)] - public virtual Orientation Orientation - { - get { return _orientation; } - set { - if (_orientation == value) - return; - _orientation = value; - NotifyValueChanged ("Orientation", _orientation); - RegisterForGraphicUpdate (); - } - } - [XmlAttributeAttribute()] - public virtual double Hue { - get { return hue; } - set { - if (hue == value) - return; - hue = value; - notifyHueChanged (); - updateMousePosFromHue (); - RegisterForRedraw (); - } - } - protected override void onDraw (Context gr) - { - base.onDraw (gr); - - Rectangle r = ClientRectangle; - r.Height -= 4; - r.Y += 2; - - Gradient.Type gt = Gradient.Type.Horizontal; - if (Orientation == Orientation.Vertical) - gt = Gradient.Type.Vertical; - - Crow.Gradient grad = new Gradient (gt); - - grad.Stops.Add (new Gradient.ColorStop (0, new Color (1, 0, 0, 1))); - grad.Stops.Add (new Gradient.ColorStop (0.167, new Color (1, 1, 0, 1))); - grad.Stops.Add (new Gradient.ColorStop (0.333, new Color (0, 1, 0, 1))); - grad.Stops.Add (new Gradient.ColorStop (0.5, new Color (0, 1, 1, 1))); - grad.Stops.Add (new Gradient.ColorStop (0.667, new Color (0, 0, 1, 1))); - grad.Stops.Add (new Gradient.ColorStop (0.833, new Color (1, 0, 1, 1))); - grad.Stops.Add (new Gradient.ColorStop (1, new Color (1, 0, 0, 1))); - - grad.SetAsSource (gr, r); - CairoHelpers.CairoRectangle (gr, r, CornerRadius); - gr.Fill(); - } - - public override void Paint (ref Context ctx) - { - base.Paint (ref ctx); - - Rectangle rb = Slot + Parent.ClientRectangle.Position; - ctx.Save (); - - ctx.Translate (rb.X, rb.Y); - - ctx.SetSourceColor (Color.White); - Rectangle r = ClientRectangle; - if (Orientation == Orientation.Horizontal) { - r.Width = 4; - r.X = mousePos.X - 2; - } else { - r.Height = 4; - r.Y = mousePos.Y - 2; - } - - CairoHelpers.CairoRectangle (ctx, r, 1); - ctx.SetSourceColor (Color.White); - ctx.LineWidth = 1.0; - ctx.Stroke(); - ctx.Restore (); - } - public override void OnLayoutChanges (LayoutingType layoutType) - { - base.OnLayoutChanges (layoutType); - - if (Orientation == Orientation.Horizontal) { - if (layoutType == LayoutingType.Width) - updateMousePosFromHue (); - } else if (layoutType == LayoutingType.Height) - updateMousePosFromHue (); - } - protected override void updateMouseLocalPos (Point mPos) - { - base.updateMouseLocalPos (mPos); - if (Orientation == Orientation.Horizontal) - hue = (double)mousePos.X / (double)ClientRectangle.Width; - else - hue = (double)mousePos.Y / (double)ClientRectangle.Height; - notifyHueChanged (); - RegisterForRedraw (); - } - void updateMousePosFromHue(){ - if (Orientation == Orientation.Horizontal) - mousePos.X = (int)Math.Floor(hue * (double)ClientRectangle.Width); - else - mousePos.Y = (int)Math.Floor(hue * (double)ClientRectangle.Height); - } - void notifyHueChanged(){ - NotifyValueChanged ("Hue", hue); - NotifyValueChanged ("HueColor", new SolidColor (Color.FromHSV (hue))); - } - } -} - diff --git a/src/GraphicObjects/ILayoutable.cs b/src/GraphicObjects/ILayoutable.cs deleted file mode 100644 index c8aa38fb..00000000 --- a/src/GraphicObjects/ILayoutable.cs +++ /dev/null @@ -1,55 +0,0 @@ -// -// ILayoutable.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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; - -namespace Crow -{ - public interface ILayoutable - { - /// <summary> Parent in the graphic tree </summary> - ILayoutable Parent { get; set; } - /// <summary> The logical parent (used mainly for bindings) as opposed - /// to the parent in the graphic tree </summary> - ILayoutable LogicalParent { get; set; } - - Rectangle ClientRectangle { get; } - Rectangle getSlot(); - - bool ArrangeChildren { get; } - LayoutingType RegisteredLayoutings { get; set; } - void RegisterForLayouting(LayoutingType layoutType); - void RegisterClip(Rectangle clip); - bool UpdateLayout(LayoutingType layoutType); - bool PointIsIn(ref Point m); - - Rectangle ContextCoordinates(Rectangle r); - Rectangle ScreenCoordinates (Rectangle r); - - } -} - diff --git a/src/GraphicObjects/IMLContainer.cs b/src/GraphicObjects/IMLContainer.cs deleted file mode 100644 index 84692284..00000000 --- a/src/GraphicObjects/IMLContainer.cs +++ /dev/null @@ -1,50 +0,0 @@ -// -// IMLContainer.cs -// -// Author: -// Jean-Philippe Bruyère <jp_bruyere@hotmail.com> -// -// 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; - -namespace Crow -{ - public class IMLContainer : PrivateContainer - { - public IMLContainer () : base() - { - } - - string path; - - public string Path { - get { return path; } - set { - if (path == value) - return; - path = value; - this.SetChild (IFace.Load (path)); - NotifyValueChanged ("Path", path); - } - } - } -} - diff --git a/src/GraphicObjects/IValueChange.cs b/src/GraphicObjects/IValueChange.cs deleted file mode 100644 index 7e18e5e5..00000000 --- a/src/GraphicObjects/IValueChange.cs +++ /dev/null @@ -1,36 +0,0 @@ -// -// IValueChange.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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; - -namespace Crow -{ - public interface IValueChange - { - event EventHandler<ValueChangeEventArgs> ValueChanged; - } -} - diff --git a/src/GraphicObjects/Image.cs b/src/GraphicObjects/Image.cs deleted file mode 100644 index e83183c0..00000000 --- a/src/GraphicObjects/Image.cs +++ /dev/null @@ -1,215 +0,0 @@ -// -// Image.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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 Cairo; -using System.Xml.Serialization; -using System.ComponentModel; -using System.Diagnostics; - - -namespace Crow -{ - /// <summary> - /// Base widget to display an image. Accepts bitmaps and SVGs. - /// </summary> - /// <remarks> - /// </remarks> - public class Image : GraphicObject - { - Picture _pic; - string _svgSub; - bool scaled, keepProps; - double opacity; - - #region Public properties - /// <summary> - /// If false, original size will be kept in any case. - /// </summary> - [XmlAttributeAttribute][DefaultValue(true)] - public virtual bool Scaled { - get { return scaled; } - set { - if (scaled == value) - return; - scaled = value; - NotifyValueChanged ("Scaled", scaled); - if (_pic == null) - return; - _pic.Scaled = scaled; - RegisterForGraphicUpdate (); - } - } - /// <summary> - /// If image is scaled, proportions will be preserved. - /// </summary> - [XmlAttributeAttribute][DefaultValue(true)] - public virtual bool KeepProportions { - get { return keepProps; } - set { - if (keepProps == value) - return; - keepProps = value; - NotifyValueChanged ("KeepProportions", keepProps); - if (_pic == null) - return; - _pic.KeepProportions = keepProps; - RegisterForGraphicUpdate (); - } - } - /// <summary> - /// Image file path, may be on disk or embedded. Accepts bitmaps or SVG drawings. - /// </summary> - [XmlAttributeAttribute] - public string Path { - get { return _pic == null ? "" : _pic.Path; } - set { - if (value == Path) - return; - try { - if (string.IsNullOrEmpty(value)) - Picture = null; - else { - //lock(IFace.LayoutMutex){ - LoadImage (value); - //} - } - } catch (Exception ex) { - Debug.WriteLine (ex.Message); - _pic = null; - } - NotifyValueChanged ("Path", Path); - } - } - /// <summary> - /// Used only for svg images, repaint only node named referenced in SvgSub. - /// If null, all the svg is rendered - /// </summary> - [XmlAttributeAttribute] - public string SvgSub { - get { return _svgSub; } - set { - if (_svgSub == value) - return; - _svgSub = value; - RegisterForGraphicUpdate (); - } - } - /// <summary> - /// Object holding the image data once loaded, may be used directely to pupulate this control without - /// specifying a path. - /// </summary> - [XmlAttributeAttribute] - public Picture Picture { - get { return _pic; } - set { - if (_pic == value) - return; - _pic = value; - NotifyValueChanged ("Picture", _pic); - RegisterForGraphicUpdate (); - } - } - /// <summary> - /// Opacity parameter for the image - /// </summary> - // TODO:could be moved in GraphicObject - [XmlAttributeAttribute()][DefaultValue(1.0)] - public virtual double Opacity { - get { return opacity; } - set { - if (opacity == value) - return; - opacity = value; - NotifyValueChanged ("Faded", opacity); - RegisterForRedraw (); - } - } - #endregion - - #region CTOR - /// <summary> - /// Initializes a new instance of the <see cref="Crow.Image"/> class. - /// </summary> - protected Image () : base(){} - /// <summary> - /// Initializes a new instance of the <see cref="Crow.Image"/> class from code - /// </summary> - /// <param name="iface">interface to bound to</param> - public Image (Interface iface) : base(iface) - { - } - #endregion - - #region Image Loading - public void LoadImage (string path) - { - Picture pic; - if (path.EndsWith (".svg", true, System.Globalization.CultureInfo.InvariantCulture)) - pic = new SvgPicture (path); - else - pic = new BmpPicture (path); - - pic.Load (IFace, path); - pic.Scaled = scaled; - pic.KeepProportions = keepProps; - - Picture = pic; - } - #endregion - - #region GraphicObject overrides - protected override int measureRawSize (LayoutingType lt) - { - if (_pic == null) - return 2 * Margin; - //_pic = "#Crow.Images.Icons.IconAlerte.svg"; - //TODO:take scalling in account - if (lt == LayoutingType.Width) - return _pic.Dimensions.Width + 2 * Margin; - else - return _pic.Dimensions.Height + 2 * Margin; - } - protected override void onDraw (Context gr) - { - base.onDraw (gr); - - if (_pic == null) - return; - - _pic.Paint (gr, ClientRectangle, _svgSub); - - if (Opacity<1.0) { - gr.SetSourceRGBA (0.0, 0.0, 0.0, 1.0-Opacity); - gr.Operator = Operator.DestOut; - gr.Rectangle (ClientRectangle); - gr.Fill (); - gr.Operator = Operator.Over; - } - } - #endregion - } -} diff --git a/src/GraphicObjects/Label.cs b/src/GraphicObjects/Label.cs deleted file mode 100644 index 0e0d9fe1..00000000 --- a/src/GraphicObjects/Label.cs +++ /dev/null @@ -1,846 +0,0 @@ -// -// Label.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Linq; -using System.Diagnostics; -using Cairo; -using System.Text.RegularExpressions; -using System.Xml.Serialization; -using System.ComponentModel; - -namespace Crow -{ - public class Label : GraphicObject - { - #region CTOR - protected Label () : base(){} - - public Label(Interface iface) : base(iface) - { - - } -// public Label(string _text) -// : base() -// { -// Text = _text; -// } - #endregion - - public event EventHandler<TextChangeEventArgs> TextChanged; - - public virtual void OnTextChanged(Object sender, TextChangeEventArgs e) - { - textMeasureIsUpToDate = false; - NotifyValueChanged ("Text", Text); - TextChanged.Raise (this, e); - } - //TODO:change protected to private - - #region private and protected fields - string _text = "label"; - Alignment _textAlignment; - bool horizontalStretch; - bool verticalStretch; - bool _selectable; - bool _multiline; - Color selBackground; - Color selForeground; - Point mouseLocalPos = -1;//mouse coord in widget space, filled only when clicked - int _currentCol; //0 based cursor position in string - int _currentLine; - Point _selBegin = -1; //selection start (row,column) - Point _selRelease = -1; //selection end (row,column) - double textCursorPos; //cursor position in cairo units in widget client coord. - double SelStartCursorPos = -1; - double SelEndCursorPos = -1; - bool SelectionInProgress = false; - - protected Rectangle rText; - protected float widthRatio = 1f; - protected float heightRatio = 1f; - protected FontExtents fe; - protected TextExtents te; - #endregion - - [XmlAttributeAttribute][DefaultValue("SteelBlue")] - public virtual Color SelectionBackground { - get { return selBackground; } - set { - if (value == selBackground) - return; - selBackground = value; - NotifyValueChanged ("SelectionBackground", selBackground); - RegisterForRedraw (); - } - } - [XmlAttributeAttribute][DefaultValue("White")] - public virtual Color SelectionForeground { - get { return selForeground; } - set { - if (value == selForeground) - return; - selForeground = value; - NotifyValueChanged ("SelectionForeground", selForeground); - RegisterForRedraw (); - } - } - [XmlAttributeAttribute][DefaultValue(Alignment.Left)] - public Alignment TextAlignment - { - get { return _textAlignment; } - set { - if (value == _textAlignment) - return; - _textAlignment = value; - RegisterForRedraw (); - NotifyValueChanged ("TextAlignment", _textAlignment); - } - } - [XmlAttributeAttribute][DefaultValue(false)] - public virtual bool HorizontalStretch { - get { return horizontalStretch; } - set { - if (horizontalStretch == value) - return; - horizontalStretch = value; - RegisterForRedraw (); - NotifyValueChanged ("HorizontalStretch", horizontalStretch); - } - } - [XmlAttributeAttribute][DefaultValue(false)] - public virtual bool VerticalStretch { - get { return verticalStretch; } - set { - if (verticalStretch == value) - return; - verticalStretch = value; - RegisterForRedraw (); - NotifyValueChanged ("VerticalStretch", verticalStretch); - } - } - [XmlAttributeAttribute][DefaultValue("label")] - public string Text - { - get { - return lines == null ? - _text : lines.Aggregate((i, j) => i + Interface.LineBreak + j); - } - set - { - if (string.Equals (value, _text, StringComparison.Ordinal)) - return; - - _text = value; - - if (string.IsNullOrEmpty(_text)) - _text = ""; - - lines = getLines; - - OnTextChanged (this, new TextChangeEventArgs (Text)); - RegisterForGraphicUpdate (); - } - } - [XmlAttributeAttribute][DefaultValue(false)] - public bool Selectable - { - get { return _selectable; } - set - { - if (value == _selectable) - return; - _selectable = value; - NotifyValueChanged ("Selectable", _selectable); - SelBegin = -1; - SelRelease = -1; - RegisterForRedraw (); - } - } - [XmlAttributeAttribute][DefaultValue(false)] - public bool Multiline - { - get { return _multiline; } - set - { - if (value == _multiline) - return; - _multiline = value; - NotifyValueChanged ("Multiline", _multiline); - RegisterForGraphicUpdate(); - } - } - [XmlAttributeAttribute][DefaultValue(0)] - public int CurrentColumn{ - get { return _currentCol; } - set { - if (value == _currentCol) - return; - if (value < 0) - _currentCol = 0; - else if (value > lines [_currentLine].Length) - _currentCol = lines [_currentLine].Length; - else - _currentCol = value; - NotifyValueChanged ("CurrentColumn", _currentCol); - } - } - [XmlAttributeAttribute][DefaultValue(0)] - public int CurrentLine{ - get { return _currentLine; } - set { - if (value == _currentLine) - return; - if (value >= lines.Count) - _currentLine = lines.Count-1; - else if (value < 0) - _currentLine = 0; - else - _currentLine = value; - //force recheck of currentCol for bounding - int cc = _currentCol; - _currentCol = 0; - CurrentColumn = cc; - NotifyValueChanged ("CurrentLine", _currentLine); - } - } - [XmlIgnore]public Point CurrentPosition { - get { return new Point(_currentCol, CurrentLine); } - } - //TODO:using HasFocus for drawing selection cause SelBegin and Release binding not to work - /// <summary> - /// Selection begin position in char units - /// </summary> - [XmlAttributeAttribute][DefaultValue("-1")] - public Point SelBegin { - get { - return _selBegin; - } - set { - if (value == _selBegin) - return; - _selBegin = value; - NotifyValueChanged ("SelBegin", _selBegin); - NotifyValueChanged ("SelectedText", SelectedText); - } - } - [XmlAttributeAttribute][DefaultValue("-1")] - public Point SelRelease { - get { - return _selRelease; - } - set { - if (value == _selRelease) - return; - _selRelease = value; - NotifyValueChanged ("SelRelease", _selRelease); - NotifyValueChanged ("SelectedText", SelectedText); - } - } - /// <summary> - /// return char at CurrentLine, CurrentColumn - /// </summary> - [XmlIgnore]protected Char CurrentChar - { - get { - return lines [CurrentLine] [CurrentColumn]; - } - } - /// <summary> - /// ordered selection start and end positions in char units - /// </summary> - [XmlIgnore]protected Point selectionStart - { - get { - return SelRelease < 0 || SelBegin.Y < SelRelease.Y ? SelBegin : - SelBegin.Y > SelRelease.Y ? SelRelease : - SelBegin.X < SelRelease.X ? SelBegin : SelRelease; - } - } - [XmlIgnore]public Point selectionEnd - { - get { - return SelRelease < 0 || SelBegin.Y > SelRelease.Y ? SelBegin : - SelBegin.Y < SelRelease.Y ? SelRelease : - SelBegin.X > SelRelease.X ? SelBegin : SelRelease; - } - } - [XmlIgnore]public string SelectedText - { - get { - - if (SelRelease < 0 || SelBegin < 0) - return ""; - if (selectionStart.Y == selectionEnd.Y) - return lines [selectionStart.Y].Substring (selectionStart.X, selectionEnd.X - selectionStart.X); - string tmp = ""; - tmp = lines [selectionStart.Y].Substring (selectionStart.X); - for (int l = selectionStart.Y + 1; l < selectionEnd.Y; l++) { - tmp += Interface.LineBreak + lines [l]; - } - tmp += Interface.LineBreak + lines [selectionEnd.Y].Substring (0, selectionEnd.X); - return tmp; - } - } - [XmlIgnore]public bool selectionIsEmpty - { get { return SelRelease < 0; } } - - List<string> lines; - List<string> getLines { - get { - return _multiline ? - Regex.Split (_text, "\r\n|\r|\n|\\\\n").ToList() : - new List<string>(new string[] { _text }); - } - } - /// <summary> - /// Moves cursor one char to the left. - /// </summary> - /// <returns><c>true</c> if move succeed</returns> - public bool MoveLeft(){ - int tmp = _currentCol - 1; - if (tmp < 0) { - if (_currentLine == 0) - return false; - CurrentLine--; - CurrentColumn = int.MaxValue; - } else - CurrentColumn = tmp; - return true; - } - /// <summary> - /// Moves cursor one char to the right. - /// </summary> - /// <returns><c>true</c> if move succeed</returns> - public bool MoveRight(){ - int tmp = _currentCol + 1; - if (tmp > lines [_currentLine].Length){ - if (CurrentLine == lines.Count - 1) - return false; - CurrentLine++; - CurrentColumn = 0; - } else - CurrentColumn = tmp; - return true; - } - public void GotoWordStart(){ - CurrentColumn--; - //skip white spaces - while (!char.IsLetterOrDigit (this.CurrentChar) && CurrentColumn > 0) - CurrentColumn--; - while (char.IsLetterOrDigit (lines [CurrentLine] [CurrentColumn]) && CurrentColumn > 0) - CurrentColumn--; - if (!char.IsLetterOrDigit (this.CurrentChar)) - CurrentColumn++; - } - public void GotoWordEnd(){ - //skip white spaces - if (CurrentColumn >= lines [CurrentLine].Length - 1) - return; - while (!char.IsLetterOrDigit (this.CurrentChar) && CurrentColumn < lines [CurrentLine].Length-1) - CurrentColumn++; - while (char.IsLetterOrDigit (this.CurrentChar) && CurrentColumn < lines [CurrentLine].Length-1) - CurrentColumn++; - if (char.IsLetterOrDigit (this.CurrentChar)) - CurrentColumn++; - } - public void DeleteChar() - { - if (selectionIsEmpty) { - if (CurrentColumn == 0) { - if (CurrentLine == 0 && lines.Count == 1) - return; - CurrentLine--; - CurrentColumn = lines [CurrentLine].Length; - lines [CurrentLine] += lines [CurrentLine + 1]; - lines.RemoveAt (CurrentLine + 1); - - OnTextChanged (this, new TextChangeEventArgs (Text)); - return; - } - CurrentColumn--; - lines [CurrentLine] = lines [CurrentLine].Remove (CurrentColumn, 1); - } else { - int linesToRemove = selectionEnd.Y - selectionStart.Y + 1; - int l = selectionStart.Y; - - if (linesToRemove > 0) { - lines [l] = lines [l].Remove (selectionStart.X, lines [l].Length - selectionStart.X) + - lines [selectionEnd.Y].Substring (selectionEnd.X, lines [selectionEnd.Y].Length - selectionEnd.X); - l++; - for (int c = 0; c < linesToRemove-1; c++) - lines.RemoveAt (l); - CurrentLine = selectionStart.Y; - CurrentColumn = selectionStart.X; - } else - lines [l] = lines [l].Remove (selectionStart.X, selectionEnd.X - selectionStart.X); - CurrentColumn = selectionStart.X; - SelBegin = -1; - SelRelease = -1; - } - OnTextChanged (this, new TextChangeEventArgs (Text)); - } - /// <summary> - /// Insert new string at caret position, should be sure no line break is inside. - /// </summary> - /// <param name="str">String.</param> - protected void Insert(string str) - { - if (!selectionIsEmpty) - this.DeleteChar (); - if (_multiline) { - string[] strLines = Regex.Split (str, "\r\n|\r|\n|" + @"\\n").ToArray(); - lines [CurrentLine] = lines [CurrentLine].Insert (CurrentColumn, strLines[0]); - CurrentColumn += strLines[0].Length; - for (int i = 1; i < strLines.Length; i++) { - InsertLineBreak (); - lines [CurrentLine] = lines [CurrentLine].Insert (CurrentColumn, strLines[i]); - CurrentColumn += strLines[i].Length; - } - } else { - lines [CurrentLine] = lines [CurrentLine].Insert (CurrentColumn, str); - CurrentColumn += str.Length; - } - OnTextChanged (this, new TextChangeEventArgs (Text)); - } - /// <summary> - /// Insert a line break. - /// </summary> - protected void InsertLineBreak() - { - lines.Insert(CurrentLine + 1, lines[CurrentLine].Substring(CurrentColumn)); - lines [CurrentLine] = lines [CurrentLine].Substring (0, CurrentColumn); - CurrentLine++; - CurrentColumn = 0; - OnTextChanged (this, new TextChangeEventArgs (Text)); - } - bool textMeasureIsUpToDate = false; - Size cachedTextSize = default(Size); - - #region GraphicObject overrides - protected override int measureRawSize(LayoutingType lt) - { - if (lines == null) - lines = getLines; - if (!textMeasureIsUpToDate) { - using (ImageSurface img = new ImageSurface (Format.Argb32, 10, 10)) { - using (Context gr = new Context (img)) { - //Cairo.FontFace cf = gr.GetContextFontFace (); - - gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight); - gr.SetFontSize (Font.Size); - gr.FontOptions = Interface.FontRenderingOptions; - gr.Antialias = Interface.Antialias; - - fe = gr.FontExtents; - te = new TextExtents (); - - cachedTextSize.Height = (int)Math.Ceiling ((fe.Ascent+fe.Descent) * Math.Max (1, lines.Count)) + Margin * 2; - - try { - foreach (string s in lines) { - string l = s.Replace ("\t", new String (' ', Interface.TabSize)); - - TextExtents tmp = gr.TextExtents (l); - - if (tmp.XAdvance > te.XAdvance) - te = tmp; - } - cachedTextSize.Width = (int)Math.Ceiling (te.XAdvance) + Margin * 2; - textMeasureIsUpToDate = true; - } catch { - return -1; - } - } - } - - } - return lt == LayoutingType.Height ? cachedTextSize.Height : cachedTextSize.Width; - } - protected override void onDraw (Context gr) - { - base.onDraw (gr); - - gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight); - gr.SetFontSize (Font.Size); - gr.FontOptions = Interface.FontRenderingOptions; - gr.Antialias = Interface.Antialias; - - rText = new Rectangle(new Size( - measureRawSize(LayoutingType.Width), measureRawSize(LayoutingType.Height))); - rText.Width -= 2 * Margin; - rText.Height -= 2 * Margin; - - widthRatio = 1f; - heightRatio = 1f; - - Rectangle cb = ClientRectangle; - - rText.X = cb.X; - rText.Y = cb.Y; - - if (horizontalStretch) { - widthRatio = (float)cb.Width / (float)rText.Width; - if (!verticalStretch) - heightRatio = widthRatio; - } - - if (verticalStretch) { - heightRatio = (float)cb.Height / (float)rText.Height; - if (!horizontalStretch) - widthRatio = heightRatio; - } - - rText.Width = (int)(widthRatio * (float)rText.Width); - rText.Height = (int)(heightRatio * (float)rText.Height); - - switch (TextAlignment) - { - case Alignment.TopLeft: //ok - rText.X = cb.X; - rText.Y = cb.Y; - break; - case Alignment.Top: //ok - rText.Y = cb.Y; - rText.X = cb.X + cb.Width / 2 - rText.Width / 2; - break; - case Alignment.TopRight: //ok - rText.Y = cb.Y; - rText.X = cb.Right - rText.Width; - break; - case Alignment.Left://ok - rText.X = cb.X; - rText.Y = cb.Y + cb.Height / 2 - rText.Height / 2; - break; - case Alignment.Right://ok - rText.X = cb.X + cb.Width - rText.Width; - rText.Y = cb.Y + cb.Height / 2 - rText.Height / 2; - break; - case Alignment.Bottom://ok - rText.X = cb.Width / 2 - rText.Width / 2; - rText.Y = cb.Height - rText.Height; - break; - case Alignment.BottomLeft://ok - rText.X = cb.X; - rText.Y = cb.Bottom - rText.Height; - break; - case Alignment.BottomRight://ok - rText.Y = cb.Bottom - rText.Height; - rText.X = cb.Right - rText.Width; - break; - case Alignment.Center://ok - rText.X = cb.X + cb.Width / 2 - rText.Width / 2; - //rText.Y = cb.Y + cb.Height / 2 - rText.Height / 2; - rText.Y = cb.Y + (int)Math.Floor((double)cb.Height / 2.0 - (double)rText.Height / 2.0); - break; - } - - //gr.FontMatrix = new Matrix(widthRatio * (float)Font.Size, 0, 0, heightRatio * (float)Font.Size, 0, 0); - fe = gr.FontExtents; - - #region draw text cursor - if (HasFocus && Selectable) - { - if (mouseLocalPos >= 0) - { - computeTextCursor(gr); - - if (SelectionInProgress) - { - if (SelBegin < 0){ - SelBegin = new Point(CurrentColumn, CurrentLine); - SelStartCursorPos = textCursorPos; - SelRelease = -1; - }else{ - SelRelease = new Point(CurrentColumn, CurrentLine); - if (SelRelease == SelBegin) - SelRelease = -1; - else - SelEndCursorPos = textCursorPos; - } - }else - computeTextCursorPosition(gr); - }else - computeTextCursorPosition(gr); - - Foreground.SetAsSource (gr); - gr.LineWidth = 1.0; - gr.MoveTo (0.5 + textCursorPos + rText.X, rText.Y + CurrentLine * (fe.Ascent+fe.Descent)); - gr.LineTo (0.5 + textCursorPos + rText.X, rText.Y + (CurrentLine + 1) * (fe.Ascent+fe.Descent)); - gr.Stroke(); - } - #endregion - - //****** debug selection ************* -// if (SelRelease >= 0) { -// new SolidColor(Color.DarkGreen).SetAsSource(gr); -// Rectangle R = new Rectangle ( -// rText.X + (int)SelEndCursorPos - 3, -// rText.Y + (int)(SelRelease.Y * (fe.Ascent+fe.Descent)), -// 6, -// (int)(fe.Ascent+fe.Descent)); -// gr.Rectangle (R); -// gr.Fill (); -// } -// if (SelBegin >= 0) { -// new SolidColor(Color.DarkRed).SetAsSource(gr); -// Rectangle R = new Rectangle ( -// rText.X + (int)SelStartCursorPos - 3, -// rText.Y + (int)(SelBegin.Y * (fe.Ascent+fe.Descent)), -// 6, -// (int)(fe.Ascent+fe.Descent)); -// gr.Rectangle (R); -// gr.Fill (); -// } - //******************* - - for (int i = 0; i < lines.Count; i++) { - string l = lines [i].Replace ("\t", new String (' ', Interface.TabSize)); - int lineLength = (int)gr.TextExtents (l).XAdvance; - Rectangle lineRect = new Rectangle ( - rText.X, - rText.Y + i * (int)(fe.Ascent+fe.Descent), - lineLength, - (int)(fe.Ascent+fe.Descent)); - -// if (TextAlignment == Alignment.Center || -// TextAlignment == Alignment.Top || -// TextAlignment == Alignment.Bottom) -// lineRect.X += (rText.Width - lineLength) / 2; -// else if (TextAlignment == Alignment.Right || -// TextAlignment == Alignment.TopRight || -// TextAlignment == Alignment.BottomRight) -// lineRect.X += (rText.Width - lineLength); - if (string.IsNullOrWhiteSpace (l)) - continue; - - Foreground.SetAsSource (gr); - gr.MoveTo (lineRect.X,(double)rText.Y + fe.Ascent + (fe.Ascent+fe.Descent) * i) ; - gr.ShowText (l); - gr.Fill (); - - if (Selectable) { - if (SelRelease >= 0 && i >= selectionStart.Y && i <= selectionEnd.Y) { - gr.SetSourceColor (selBackground); - - Rectangle selRect = lineRect; - - int cpStart = (int)SelStartCursorPos, - cpEnd = (int)SelEndCursorPos; - - if (SelBegin.Y > SelRelease.Y) { - cpStart = cpEnd; - cpEnd = (int)SelStartCursorPos; - } - - if (i == selectionStart.Y) { - selRect.Width -= cpStart; - selRect.Left += cpStart; - } - if (i == selectionEnd.Y) - selRect.Width -= (lineLength - cpEnd); - - gr.Rectangle (selRect); - gr.FillPreserve (); - gr.Save (); - gr.Clip (); - gr.SetSourceColor (SelectionForeground); - gr.MoveTo (lineRect.X, rText.Y + fe.Ascent + (fe.Ascent+fe.Descent) * i); - gr.ShowText (l); - gr.Fill (); - gr.Restore (); - } - } - } - } - #endregion - - #region Mouse handling - void updatemouseLocalPos(Point mpos){ - mouseLocalPos = mpos - ScreenCoordinates(Slot).TopLeft - ClientRectangle.TopLeft; - if (mouseLocalPos.X < 0) - mouseLocalPos.X = 0; - if (mouseLocalPos.Y < 0) - mouseLocalPos.Y = 0; - } - public override void onMouseEnter (object sender, MouseMoveEventArgs e) - { - base.onMouseEnter (sender, e); - if (Selectable) - IFace.MouseCursor = XCursor.Text; - } - public override void onMouseLeave (object sender, MouseMoveEventArgs e) - { - base.onMouseLeave (sender, e); - IFace.MouseCursor = XCursor.Default; - } - protected override void onFocused (object sender, EventArgs e) - { - base.onFocused (sender, e); - - if (!_selectable) - return; - SelBegin = new Point(0,0); - SelRelease = new Point (lines.LastOrDefault ().Length, lines.Count-1); - RegisterForRedraw (); - } - protected override void onUnfocused (object sender, EventArgs e) - { - base.onUnfocused (sender, e); - - SelBegin = -1; - SelRelease = -1; - RegisterForRedraw (); - } - public override void onMouseMove (object sender, MouseMoveEventArgs e) - { - base.onMouseMove (sender, e); - - if (!(SelectionInProgress && HasFocus && _selectable)) - return; - - updatemouseLocalPos (e.Position); - - RegisterForRedraw(); - } - public override void onMouseDown (object sender, MouseButtonEventArgs e) - { - if (this.HasFocus && _selectable){ - updatemouseLocalPos (e.Position); - SelBegin = -1; - SelRelease = -1; - SelectionInProgress = true; - RegisterForRedraw();//TODO:should put it in properties - } - - //done at the end to set 'hasFocus' value after testing it - base.onMouseDown (sender, e); - } - public override void onMouseUp (object sender, MouseButtonEventArgs e) - { - base.onMouseUp (sender, e); - if (!(this.HasFocus || _selectable)) - return; - if (!SelectionInProgress) - return; - - updatemouseLocalPos (e.Position); - SelectionInProgress = false; - RegisterForRedraw (); - } - public override void onMouseDoubleClick (object sender, MouseButtonEventArgs e) - { - base.onMouseDoubleClick (sender, e); - if (!(this.HasFocus || _selectable)) - return; - - GotoWordStart (); - SelBegin = CurrentPosition; - GotoWordEnd (); - SelRelease = CurrentPosition; - SelectionInProgress = false; - RegisterForRedraw (); - } - #endregion - - /// <summary> - /// Update Current Column, line and TextCursorPos - /// from mouseLocalPos - /// </summary> - void computeTextCursor(Context gr) - { - TextExtents te; - - double cPos = 0f; - - CurrentLine = (int)(mouseLocalPos.Y / (fe.Ascent+fe.Descent)); - - //fix cu - if (CurrentLine >= lines.Count) - CurrentLine = lines.Count - 1; - - switch (TextAlignment) { - case Alignment.Center: - case Alignment.Top: - case Alignment.Bottom: - cPos+= ClientRectangle.Width - gr.TextExtents(lines [CurrentLine]).Width/2.0; - break; - case Alignment.Right: - case Alignment.TopRight: - case Alignment.BottomRight: - cPos += ClientRectangle.Width - gr.TextExtents(lines [CurrentLine]).Width; - break; - } - - for (int i = 0; i < lines[CurrentLine].Length; i++) - { - string c = lines [CurrentLine].Substring (i, 1); - if (c == "\t") - c = new string (' ', Interface.TabSize); - - te = gr.TextExtents(c); - - double halfWidth = te.XAdvance / 2; - - if (mouseLocalPos.X <= cPos + halfWidth) - { - CurrentColumn = i; - textCursorPos = cPos; - mouseLocalPos = -1; - return; - } - - cPos += te.XAdvance; - } - CurrentColumn = lines[CurrentLine].Length; - textCursorPos = cPos; - - //reset mouseLocalPos - mouseLocalPos = -1; - } - /// <summary> Computes offsets in cairo units </summary> - void computeTextCursorPosition(Context gr) - { - if (SelBegin >= 0) - SelStartCursorPos = GetXFromTextPointer (gr, SelBegin); - if (SelRelease >= 0) - SelEndCursorPos = GetXFromTextPointer (gr, SelRelease); - textCursorPos = GetXFromTextPointer (gr, new Point(CurrentColumn, CurrentLine)); - } - /// <summary> Compute x offset in cairo unit from text position </summary> - double GetXFromTextPointer(Context gr, Point pos) - { - try { - string l = lines [pos.Y].Substring (0, pos.X). - Replace ("\t", new String (' ', Interface.TabSize)); - return gr.TextExtents (l).XAdvance; - } catch{ - return -1; - } - } - } -} diff --git a/src/GraphicObjects/ListBox.cs b/src/GraphicObjects/ListBox.cs deleted file mode 100644 index 438e8d60..00000000 --- a/src/GraphicObjects/ListBox.cs +++ /dev/null @@ -1,48 +0,0 @@ -// -// ListBox.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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; -using System.Xml.Serialization; -using System.ComponentModel; -using System.IO; -using System.Diagnostics; -using System.Xml; -using System.Collections.Generic; -using System.Threading; - -namespace Crow -{ - public class ListBox : TemplatedGroup - { - #region CTOR - protected ListBox () : base(){} - public ListBox (Interface iface) : base(iface) {} - #endregion - - } -} - diff --git a/src/GraphicObjects/Menu.cs b/src/GraphicObjects/Menu.cs deleted file mode 100644 index dbc1d636..00000000 --- a/src/GraphicObjects/Menu.cs +++ /dev/null @@ -1,77 +0,0 @@ -// -// Menu.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Xml.Serialization; -using System.ComponentModel; - -namespace Crow -{ - public class Menu : TemplatedGroup - { - #region CTOR - protected Menu () : base(){} - public Menu (Interface iface) : base(iface) {} - #endregion - - Orientation orientation; - bool autoOpen = false; - - #region Public properties - [XmlAttributeAttribute][DefaultValue(Orientation.Horizontal)] - public Orientation Orientation { - get { return orientation; } - set { - if (orientation == value) - return; - orientation = value; - NotifyValueChanged ("Orientation", orientation); - } - } - [XmlIgnore]public bool AutomaticOpenning - { - get { return autoOpen; } - set { autoOpen = value; } - } - #endregion - - public override void AddItem (GraphicObject g) - { - base.AddItem (g); - - if (orientation == Orientation.Horizontal) - g.NotifyValueChanged ("PopDirection", Alignment.Bottom); - else - g.NotifyValueChanged ("PopDirection", Alignment.Right); - } - public override void onMouseLeave (object sender, MouseMoveEventArgs e) - { - base.onMouseLeave (sender, e); - AutomaticOpenning = false; - } - } -} - diff --git a/src/GraphicObjects/MenuItem.cs b/src/GraphicObjects/MenuItem.cs deleted file mode 100644 index 5c9665fb..00000000 --- a/src/GraphicObjects/MenuItem.cs +++ /dev/null @@ -1,186 +0,0 @@ -// -// MenuItem.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Xml.Serialization; -using System.ComponentModel; - -namespace Crow -{ - public class MenuItem : Menu - { - #region CTOR - protected MenuItem () : base(){} - public MenuItem (Interface iface) : base(iface) {} - #endregion - - public event EventHandler Open; - public event EventHandler Close; - - Command command; - Picture icon; - bool isOpened; - Measure popWidth, popHeight; - - #region Public properties - [XmlAttributeAttribute][DefaultValue(false)] - public bool IsOpened { - get { return isOpened; } - set { - if (isOpened == value) - return; - isOpened = value; - NotifyValueChanged ("IsOpened", isOpened); - - if (isOpened) { - onOpen (this, null); - if (LogicalParent is Menu) - (LogicalParent as Menu).AutomaticOpenning = true; - }else - onClose (this, null); - } - } - [XmlAttributeAttribute][DefaultValue(null)] - public virtual Command Command { - get { return command; } - set { - if (command == value) - return; - - if (command != null) { - command.raiseAllValuesChanged (); - command.ValueChanged -= Command_ValueChanged; - } - - command = value; - - if (command != null) { - command.ValueChanged += Command_ValueChanged; - command.raiseAllValuesChanged (); - } - - NotifyValueChanged ("Command", command); - } - } - [XmlAttributeAttribute] - public override bool IsEnabled { - get { return Command == null ? base.IsEnabled : Command.CanExecute; } - set { base.IsEnabled = value; } - } - [XmlAttributeAttribute] - public override string Caption { - get { return Command == null ? base.Caption : Command.Caption; } - set { base.Caption = value; } - } - [XmlAttributeAttribute] - public Picture Icon { - get { return Command == null ? icon : Command.Icon;; } - set { - if (icon == value) - return; - icon = value; - if (command == null) - NotifyValueChanged ("Icon", icon); - } - } - [XmlAttributeAttribute()][DefaultValue("Fit")] - public virtual Measure PopWidth { - get { return popWidth; } - set { - if (popWidth == value) - return; - popWidth = value; - NotifyValueChanged ("PopWidth", popWidth); - } - } - [XmlAttributeAttribute()][DefaultValue("Fit")] - public virtual Measure PopHeight { - get { return popHeight; } - set { - if (popHeight == value) - return; - popHeight = value; - NotifyValueChanged ("PopHeight", popHeight); - } - } - #endregion - - public override void AddItem (GraphicObject g) - { - base.AddItem (g); - g.NotifyValueChanged ("PopDirection", Alignment.Right); - } - - void Command_ValueChanged (object sender, ValueChangeEventArgs e) - { - string mName = e.MemberName; - if (mName == "CanExecute") - mName = "IsEnabled"; - NotifyValueChanged (mName, e.NewValue); - } - void onMI_Click (object sender, MouseButtonEventArgs e) - { - if (command != null) { - command.Execute (); - closeMenu (); - } - if(!IsOpened) - (LogicalParent as Menu).AutomaticOpenning = false; - } - protected virtual void onOpen (object sender, EventArgs e){ - Open.Raise (this, null); - } - protected virtual void onClose (object sender, EventArgs e){ - System.Diagnostics.Debug.WriteLine ("close: " + this.ToString()); - Close.Raise (this, null); - } - public override bool MouseIsIn (Point m) - { - return IsEnabled && !IsDragged ? base.MouseIsIn (m) || child.MouseIsIn (m) : false; - } - public override void onMouseEnter (object sender, MouseMoveEventArgs e) - { - base.onMouseEnter (sender, e); - if ((LogicalParent as Menu).AutomaticOpenning && items.Children.Count>0) - IsOpened = true; - } - public override void onMouseLeave (object sender, MouseMoveEventArgs e) - { - if (IsOpened) - IsOpened = false; - base.onMouseLeave (this, e); - } - - void closeMenu () { - MenuItem tmp = LogicalParent as MenuItem; - while (tmp != null) { - tmp.IsOpened = false; - tmp = tmp.LogicalParent as MenuItem; - } - } - } -} - diff --git a/src/GraphicObjects/MessageBox.cs b/src/GraphicObjects/MessageBox.cs deleted file mode 100644 index 45ef1e00..00000000 --- a/src/GraphicObjects/MessageBox.cs +++ /dev/null @@ -1,203 +0,0 @@ -// -// MessageBox.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Xml.Serialization; -using System.ComponentModel; - -namespace Crow -{ - public class MessageBox : Window - { - #region CTOR - protected MessageBox () : base(){} - public MessageBox (Interface iface) : base(iface){} - #endregion - - public enum Type { - None, - Information, - Alert, - Error, - YesNo, - YesNoCancel, - - } - - protected override void loadTemplate (GraphicObject template) - { - base.loadTemplate (template); - NotifyValueChanged ("MsgIcon", "#Crow.Images.Icons.Informations.svg"); - } - string message, okMessage, cancelMessage, noMessage; - Type msgType = Type.None; - - public event EventHandler Yes; - public event EventHandler No; - public event EventHandler Cancel; - - [DefaultValue("Informations")] - public virtual string Message - { - get { return message; } - set { - if (message == value) - return; - message = value; - NotifyValueChanged ("Message", message); - } - } - [DefaultValue("Ok")] - public virtual string OkMessage - { - get { return okMessage; } - set { - if (okMessage == value) - return; - okMessage = value; - NotifyValueChanged ("OkMessage", okMessage); - } - } - [DefaultValue("Cancel")] - public virtual string CancelMessage - { - get { return cancelMessage; } - set { - if (cancelMessage == value) - return; - cancelMessage = value; - NotifyValueChanged ("CancelMessage", cancelMessage); - } - } - [DefaultValue("No")] - public virtual string NoMessage - { - get { return cancelMessage; } - set { - if (cancelMessage == value) - return; - cancelMessage = value; - NotifyValueChanged ("NoMessage", cancelMessage); - } - } - [DefaultValue("Information")] - public virtual Type MsgType - { - get { return msgType; } - set { - if (msgType == value) - return; - msgType = value; - NotifyValueChanged ("MsgType", msgType); - switch (msgType) { - case Type.Information: - MsgIcon = "#Crow.Images.Icons.Informations.svg"; - Caption = "Informations"; - OkMessage = "Ok"; - NotifyValueChanged ("CancelButIsVisible", false); - NotifyValueChanged ("NoButIsVisible", false); - break; - case Type.YesNo: - case Type.YesNoCancel: - MsgIcon = "#Crow.Icons.question.svg"; - Caption = "Choice"; - OkMessage = "Yes"; - NoMessage = "No"; - NotifyValueChanged ("CancelButIsVisible", msgType == Type.YesNoCancel); - NotifyValueChanged ("NoButIsVisible", true); - break; - case Type.Alert: - MsgIcon = "#Crow.Images.Icons.IconAlerte.svg"; - Caption = "Alert"; - OkMessage = "Ok"; - CancelMessage = "Cancel"; - NotifyValueChanged ("CancelButIsVisible", true); - NotifyValueChanged ("NoButIsVisible", false); - break; - case Type.Error: - MsgIcon = "#Crow.Images.Icons.exit.svg"; - Caption = "Error"; - OkMessage = "Ok"; - NotifyValueChanged ("CancelButIsVisible", false); - NotifyValueChanged ("NoButIsVisible", false); - break; - } - } - } - - string msgIcon = null; - public string MsgIcon { - get { return msgIcon; } - set { - if (value == MsgIcon) - return; - msgIcon = value; - NotifyValueChanged ("MsgIcon", MsgIcon); - } - } - void onOkButtonClick (object sender, EventArgs e) - { - Yes.Raise (this, null); - close (); - } - void onNoButtonClick (object sender, EventArgs e) - { - No.Raise (this, null); - close (); - } - void onCancelButtonClick (object sender, EventArgs e) - { - Cancel.Raise (this, null); - close (); - } - public static MessageBox Show (Interface iface, Type msgBoxType, string message, string okMsg = "", string cancelMsg = ""){ - lock (iface.UpdateMutex) { - MessageBox mb = new MessageBox (iface); - mb.IFace.AddWidget (mb); - mb.MsgType = msgBoxType; - mb.Message = message; - if (!string.IsNullOrEmpty(okMsg)) - mb.OkMessage = okMsg; - if (!string.IsNullOrEmpty(cancelMsg)) - mb.CancelMessage = cancelMsg; - return mb; - } - } - public static MessageBox ShowModal (Interface iface, Type msgBoxType, string message){ - lock (iface.UpdateMutex) { - MessageBox mb = new MessageBox (iface) { - Modal = true, - MsgType = msgBoxType, - Message = message - }; - - iface.AddWidget (mb); - return mb; - } - } - } -} - diff --git a/src/GraphicObjects/NumericControl.cs b/src/GraphicObjects/NumericControl.cs deleted file mode 100644 index f0eda90f..00000000 --- a/src/GraphicObjects/NumericControl.cs +++ /dev/null @@ -1,142 +0,0 @@ -// -// NumericControl.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Xml.Serialization; -using System.ComponentModel; - -namespace Crow -{ - public abstract class NumericControl : TemplatedControl - { - #region CTOR - protected NumericControl () : base(){} - public NumericControl (Interface iface) : base(iface) - { - } -// public NumericControl(double minimum, double maximum, double step) -// : base() -// { -// } - #endregion - - #region private fields - double _actualValue, minValue, maxValue, smallStep, bigStep; - int _decimals; - #endregion - - #region public properties - [XmlAttributeAttribute][DefaultValue(2)] - public int Decimals - { - get { return _decimals; } - set - { - if (value == _decimals) - return; - _decimals = value; - NotifyValueChanged("Decimals", _decimals); - RegisterForGraphicUpdate(); - } - } - [XmlAttributeAttribute][DefaultValue(0.0)] - public virtual double Minimum { - get { return minValue; } - set { - if (minValue == value) - return; - - minValue = value; - NotifyValueChanged ("Minimum", minValue); - RegisterForRedraw (); - } - } - [XmlAttributeAttribute][DefaultValue(100.0)] - public virtual double Maximum - { - get { return maxValue; } - set { - if (maxValue == value) - return; - - maxValue = value; - NotifyValueChanged ("Maximum", maxValue); - RegisterForRedraw (); - } - } - [XmlAttributeAttribute][DefaultValue(1.0)] - public virtual double SmallIncrement - { - get { return smallStep; } - set { - if (smallStep == value) - return; - - smallStep = value; - NotifyValueChanged ("SmallIncrement", smallStep); - RegisterForRedraw (); - } - } - [XmlAttributeAttribute][DefaultValue(5.0)] - public virtual double LargeIncrement - { - get { return bigStep; } - set { - if (bigStep == value) - return; - - bigStep = value; - NotifyValueChanged ("LargeIncrement", bigStep); - RegisterForRedraw (); - } - } - [DefaultValue(0.0)] - public double Value - { - get { return _actualValue; } - set - { - if (value == _actualValue) - return; - - if (value < minValue) - _actualValue = minValue; - else if (value > maxValue) - _actualValue = maxValue; - else - _actualValue = value; - - _actualValue = Math.Round (_actualValue, _decimals); - - NotifyValueChanged("Value", _actualValue); - RegisterForGraphicUpdate(); - } - } - #endregion - - } -} - diff --git a/src/GraphicObjects/Popper.cs b/src/GraphicObjects/Popper.cs deleted file mode 100644 index 1186e8e7..00000000 --- a/src/GraphicObjects/Popper.cs +++ /dev/null @@ -1,250 +0,0 @@ -// -// Popper.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Xml.Serialization; -using System.ComponentModel; - -namespace Crow -{ - public class Popper : TemplatedContainer - { - #region CTOR - protected Popper () : base(){} - public Popper (Interface iface) : base(iface){} - #endregion - - bool _isPopped, _canPop; - Alignment popDirection; - GraphicObject _content; - Measure popWidth, popHeight; - - public event EventHandler Popped; - public event EventHandler Unpoped; - - #region Public Properties - [XmlAttributeAttribute()][DefaultValue("Fit")] - public virtual Measure PopWidth { - get { return popWidth; } - set { - if (popWidth == value) - return; - popWidth = value; - NotifyValueChanged ("PopWidth", popWidth); - } - } - [XmlAttributeAttribute()][DefaultValue("Fit")] - public virtual Measure PopHeight { - get { return popHeight; } - set { - if (popHeight == value) - return; - popHeight = value; - NotifyValueChanged ("PopHeight", popHeight); - } - } - [XmlAttributeAttribute()][DefaultValue(false)] - public bool IsPopped - { - get { return _isPopped; } - set - { - if (!_canPop & value) - return; - - if (value == _isPopped) - return; - - _isPopped = value; - - NotifyValueChanged ("IsPopped", _isPopped); - - if (_isPopped) - onPop (this, null); - else - onUnpop (this, null); - - } - } - [XmlAttributeAttribute()][DefaultValue(true)] - public bool CanPop - { - get { return _canPop; } - set - { - if (value == _canPop) - return; - - _canPop = value; - NotifyValueChanged ("CanPop", _canPop); - } - } - [XmlAttributeAttribute()][DefaultValue(Alignment.Bottom)] - public virtual Alignment PopDirection { - get { return popDirection; } - set { - if (popDirection == value) - return; - popDirection = value; - NotifyValueChanged ("PopDirection", popDirection); - } - } - #endregion - - public override GraphicObject Content { - get { return _content; } - set { - if (_content != null) { - _content.LogicalParent = null; - _content.isPopup = false; - _content.LayoutChanged -= _content_LayoutChanged; - } - - _content = value; - - if (_content == null) - return; - - _content.LogicalParent = this; - _content.isPopup = true; - _content.HorizontalAlignment = HorizontalAlignment.Left; - _content.VerticalAlignment = VerticalAlignment.Top; - _content.LayoutChanged += _content_LayoutChanged; - } - } - void positionContent(LayoutingType lt){ - ILayoutable tc = Content.Parent; - if (tc == null) - return; - Rectangle r = this.ScreenCoordinates (this.Slot); - if (lt == LayoutingType.X) { - if (popDirection.HasFlag (Alignment.Right)) { - if (r.Right + Content.Slot.Width > tc.ClientRectangle.Right) - Content.Left = r.Left - Content.Slot.Width; - else - Content.Left = r.Right; - } else if (popDirection.HasFlag (Alignment.Left)) { - if (r.Left - Content.Slot.Width < tc.ClientRectangle.Left) - Content.Left = r.Right; - else - Content.Left = r.Left - Content.Slot.Width; - } else { - if (Content.Slot.Width < tc.ClientRectangle.Width) { - if (r.Left + Content.Slot.Width > tc.ClientRectangle.Right) - Content.Left = tc.ClientRectangle.Right - Content.Slot.Width; - else - Content.Left = r.Left; - } else - Content.Left = 0; - } - }else if (lt == LayoutingType.Y) { - if (Content.Slot.Height < tc.ClientRectangle.Height) { - if (PopDirection.HasFlag (Alignment.Bottom)) { - if (r.Bottom + Content.Slot.Height > tc.ClientRectangle.Bottom) - Content.Top = r.Top - Content.Slot.Height; - else - Content.Top = r.Bottom; - } else if (PopDirection.HasFlag (Alignment.Top)) { - if (r.Top - Content.Slot.Height < tc.ClientRectangle.Top) - Content.Top = r.Bottom; - else - Content.Top = r.Top - Content.Slot.Height; - } else - Content.Top = r.Top; - }else - Content.Top = 0; - } - } - protected void _content_LayoutChanged (object sender, LayoutingEventArgs e) - { - if (e.LayoutType.HasFlag (LayoutingType.Width)) - positionContent (LayoutingType.X); - if (e.LayoutType.HasFlag(LayoutingType.Height)) - positionContent (LayoutingType.Y); - } - - #region GraphicObject overrides - public override void onMouseLeave (object sender, MouseMoveEventArgs e) - { - base.onMouseLeave (this, e); - IsPopped = false; - } - public override bool MouseIsIn (Point m) - { - if (Content?.Parent != null) - if (Content.MouseIsIn (m)) - return true; - return base.MouseIsIn (m); - } - public override void checkHoverWidget (MouseMoveEventArgs e) - { - if (IFace.HoverWidget != this) { - IFace.HoverWidget = this; - onMouseEnter (this, e); - } - if (Content != null){ - if (Content.Parent != null) { - if (Content.MouseIsIn (e.Position)) { - Content.checkHoverWidget (e); - return; - } - } - } - base.checkHoverWidget (e); - } - #endregion - - public virtual void onPop(object sender, EventArgs e) - { - if (Content != null) { - Content.Visible = true; - if (Content.Parent == null) - IFace.AddWidget (Content); - if (Content.LogicalParent != this) - Content.LogicalParent = this; - IFace.PutOnTop (Content, true); - _content_LayoutChanged (this, new LayoutingEventArgs (LayoutingType.Sizing)); - } - Popped.Raise (this, e); - } - public virtual void onUnpop(object sender, EventArgs e) - { - if (Content != null) { - Content.Visible = false; - } - Unpoped.Raise (this, e); - } - - protected override void Dispose (bool disposing) - { - if (_content != null && disposing) { - if (_content.Parent == null) - _content.Dispose (); - } - base.Dispose (disposing); - } - } -} diff --git a/src/GraphicObjects/PrivateContainer.cs b/src/GraphicObjects/PrivateContainer.cs deleted file mode 100644 index d6637247..00000000 --- a/src/GraphicObjects/PrivateContainer.cs +++ /dev/null @@ -1,237 +0,0 @@ -// -// PrivateContainer.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Xml.Serialization; -using System.ComponentModel; -using Cairo; - -namespace Crow -{ - /// <summary> - /// Implement drawing and layouting for a single child, but - /// does not expose child to allow reuse of container - /// behaviour for widgets that have other xml hierarchy: example - /// TemplatedControl may have 3 children (template,templateItem,content) but - /// behave exactely as a container for layouting and drawing - /// </summary> - [DesignIgnore] - public class PrivateContainer : GraphicObject - { - #region CTOR - protected PrivateContainer () : base(){} - public PrivateContainer (Interface iface) : base(iface){} - #endregion - - #if DESIGN_MODE - public override bool FindByDesignID(string designID, out GraphicObject go){ - go = null; - if (base.FindByDesignID (designID, out go)) - return true; - return (bool)child?.FindByDesignID (designID, out go); - } - #endif - protected GraphicObject child; - - protected virtual void SetChild(GraphicObject _child) - { - - if (child != null) { - //check if HoverWidget is removed from Tree - if (IFace.HoverWidget != null) { - if (this.Contains (IFace.HoverWidget)) - IFace.HoverWidget = null; - } - contentSize = default(Size); - child.LayoutChanged -= OnChildLayoutChanges; - this.RegisterForGraphicUpdate (); - } - - child = _child as GraphicObject; - - if (child != null) { - child.Parent = this; - child.LayoutChanged += OnChildLayoutChanges; - contentSize = child.Slot.Size; - child.RegisteredLayoutings = LayoutingType.None; - child.RegisterForLayouting (LayoutingType.Sizing); - } - } - //dispose child if not null - protected virtual void deleteChild () { - GraphicObject g = child; - SetChild (null); - if (g != null) - g.Dispose (); - } - - #region GraphicObject Overrides - - public override GraphicObject FindByName (string nameToFind) - { - if (Name == nameToFind) - return this; - - return child == null ? null : child.FindByName (nameToFind); - } - public override bool Contains (GraphicObject goToFind) - { - return child == goToFind ? true : - child == null ? false : child.Contains(goToFind); - } - public override void OnDataSourceChanged (object sender, DataSourceChangeEventArgs e) - { - base.OnDataSourceChanged (this, e); - if (child != null) - if (child.localDataSourceIsNull & child.localLogicalParentIsNull) - child.OnDataSourceChanged (child, e); - } - public override bool UpdateLayout (LayoutingType layoutType) - { - if (child != null) { - //force sizing to fit if sizing on children and child has stretched size - switch (layoutType) { - case LayoutingType.Width: - if (Width == Measure.Fit && child.Width.IsRelativeToParent) - child.Width = Measure.Fit; - break; - case LayoutingType.Height: - if (Height == Measure.Fit && child.Height.IsRelativeToParent) - child.Height = Measure.Fit; - break; - } - } - return base.UpdateLayout (layoutType); - } - public override void OnLayoutChanges (LayoutingType layoutType) - { - base.OnLayoutChanges (layoutType); - - if (child == null) - return; - - LayoutingType ltChild = LayoutingType.None; - - if (layoutType == LayoutingType.Width) { - if (child.Width.IsRelativeToParent) { - ltChild |= LayoutingType.Width; - if (child.Width.Value < 100 && child.Left == 0) - ltChild |= LayoutingType.X; - } else if (child.Left == 0) - ltChild |= LayoutingType.X; - } else if (layoutType == LayoutingType.Height) { - if (child.Height.IsRelativeToParent) { - ltChild |= LayoutingType.Height; - if (child.Height.Value < 100 && child.Top == 0) - ltChild |= LayoutingType.Y; - } else if (child.Top == 0) - ltChild |= LayoutingType.Y; - } - if (ltChild == LayoutingType.None) - return; - child.RegisterForLayouting (ltChild); - } - public virtual void OnChildLayoutChanges (object sender, LayoutingEventArgs arg) - { - GraphicObject g = sender as GraphicObject; - - if (arg.LayoutType == LayoutingType.Width) { - if (Width != Measure.Fit) - return; - contentSize.Width = g.Slot.Width; - this.RegisterForLayouting (LayoutingType.Width); - }else if (arg.LayoutType == LayoutingType.Height){ - if (Height != Measure.Fit) - return; - contentSize.Height = g.Slot.Height; - this.RegisterForLayouting (LayoutingType.Height); - } - } - protected override void onDraw (Context gr) - { - base.onDraw (gr); - - gr.Save (); - - if (ClipToClientRect) { - //clip to client zone - CairoHelpers.CairoRectangle (gr, ClientRectangle, CornerRadius); - gr.Clip (); - } - - if (child != null) { - if (child.Visible) - child.Paint (ref gr); - } - gr.Restore (); - } - protected override void UpdateCache (Context ctx) - { - Rectangle rb = Slot + Parent.ClientRectangle.Position; - - - Context gr = new Context (bmp); - - if (!Clipping.IsEmpty) { - for (int i = 0; i < Clipping.NumRectangles; i++) - gr.Rectangle(Clipping.GetRectangle(i)); - gr.ClipPreserve(); - gr.Operator = Operator.Clear; - gr.Fill(); - gr.Operator = Operator.Over; - - onDraw (gr); - } - - gr.Dispose (); - - ctx.SetSourceSurface (bmp, rb.X, rb.Y); - ctx.Paint (); - Clipping.Dispose(); - Clipping = new Region (); - } - #endregion - - #region Mouse handling - public override void checkHoverWidget (MouseMoveEventArgs e) - { - base.checkHoverWidget (e); - - if (child != null) - if (child.MouseIsIn (e.Position)) - child.checkHoverWidget (e); - } - #endregion - - protected override void Dispose (bool disposing) - { - if (disposing && child != null) - child.Dispose (); - base.Dispose (disposing); - } - } -} - diff --git a/src/GraphicObjects/ProgressBar.cs b/src/GraphicObjects/ProgressBar.cs deleted file mode 100644 index e8165fd2..00000000 --- a/src/GraphicObjects/ProgressBar.cs +++ /dev/null @@ -1,68 +0,0 @@ -// -// ProgressBar.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Linq; -using System.Text; -using Cairo; -using System.Diagnostics; -using System.Xml.Serialization; -using System.ComponentModel; - -namespace Crow -{ - - public class ProgressBar : NumericControl - { - #region CTOR - protected ProgressBar () : base(){} - public ProgressBar(Interface iface) : base(iface){} - #endregion - - protected override void loadTemplate (GraphicObject template) - { - - } - - #region GraphicObject overrides - protected override void onDraw (Context gr) - { - base.onDraw (gr); - - if (Maximum == 0) - return; - - Rectangle rBack = ClientRectangle; - rBack.Width = (int)((double)rBack.Width / Maximum * Value); - Foreground.SetAsSource (gr, rBack); - - CairoHelpers.CairoRectangle(gr,rBack,CornerRadius); - gr.Fill(); - } - #endregion - } -} diff --git a/src/GraphicObjects/RadioButton.cs b/src/GraphicObjects/RadioButton.cs deleted file mode 100644 index 4c553481..00000000 --- a/src/GraphicObjects/RadioButton.cs +++ /dev/null @@ -1,83 +0,0 @@ -// -// RadioButton.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.ComponentModel; -using System.Xml.Serialization; - -namespace Crow -{ - public class RadioButton : TemplatedControl - { - bool isChecked; - - #region CTOR - protected RadioButton () : base(){} - public RadioButton(Interface iface) : base(iface){} - #endregion - - public event EventHandler Checked; - public event EventHandler Unchecked; - - #region GraphicObject overrides - public override void onMouseDown (object sender, MouseButtonEventArgs e) - { - Group pg = Parent as Group; - if (pg != null) { - for (int i = 0; i < pg.Children.Count; i++) { - RadioButton c = pg.Children [i] as RadioButton; - if (c == null) - continue; - c.IsChecked = (c == this); - } - } else - IsChecked = !IsChecked; - - base.onMouseDown (sender, e); - } - #endregion - - [XmlAttributeAttribute()][DefaultValue(false)] - public bool IsChecked - { - get { return isChecked; } - set - { - if (isChecked == value) - return; - - isChecked = value; - - NotifyValueChanged ("IsChecked", value); - - if (isChecked) - Checked.Raise (this, null); - else - Unchecked.Raise (this, null); - } - } - } -} diff --git a/src/GraphicObjects/SaturationValueSelector.cs b/src/GraphicObjects/SaturationValueSelector.cs deleted file mode 100644 index 485a33d2..00000000 --- a/src/GraphicObjects/SaturationValueSelector.cs +++ /dev/null @@ -1,143 +0,0 @@ -// -// SaturationValueSelector.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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 Cairo; -using System.Xml.Serialization; - -namespace Crow -{ - [DesignIgnore] - public class SaturationValueSelector : ColorSelector - { - public SaturationValueSelector () : base(){} - public SaturationValueSelector (Interface iface) : base(iface) - { - } - - double v, s; - - [XmlAttributeAttribute()] - public virtual double V { - get { return v; } - set { - if (v == value) - return; - v = value; - NotifyValueChanged ("V", v); - mousePos.Y = (int)Math.Floor((1.0-v) * (double)ClientRectangle.Height); - - RegisterForRedraw (); - } - } - [XmlAttributeAttribute()] - public virtual double S { - get { return s; } - set { - if (s == value) - return; - s = value; - NotifyValueChanged ("S", s); - mousePos.X = (int)Math.Floor(s * (double)ClientRectangle.Width); - - RegisterForRedraw (); - } - } - protected override void onDraw (Context gr) - { - base.onDraw (gr); - - Rectangle r = ClientRectangle; - - if (Foreground != null) {//TODO:test if null should be removed - Foreground.SetAsSource (gr, r); - CairoHelpers.CairoRectangle (gr, r, CornerRadius); - gr.Fill (); - } - - Crow.Gradient grad = new Gradient (Gradient.Type.Horizontal); - grad.Stops.Add (new Gradient.ColorStop (0, new Color (1, 1, 1, 1))); - grad.Stops.Add (new Gradient.ColorStop (1, new Color (1, 1, 1, 0))); - grad.SetAsSource (gr, r); - CairoHelpers.CairoRectangle (gr, r, CornerRadius); - gr.Fill(); - grad = new Gradient (Gradient.Type.Vertical); - grad.Stops.Add (new Gradient.ColorStop (0, new Color (0, 0, 0, 0))); - grad.Stops.Add (new Gradient.ColorStop (1, new Color (0, 0, 0, 1))); - grad.SetAsSource (gr, r); - CairoHelpers.CairoRectangle (gr, r, CornerRadius); - gr.Fill(); - - } - - public override void Paint (ref Context ctx) - { - base.Paint (ref ctx); - - Rectangle rb = Slot + Parent.ClientRectangle.Position; - ctx.Save (); - - ctx.Translate (rb.X, rb.Y); - - ctx.SetSourceColor (Color.DimGrey); - ctx.Arc (mousePos.X, mousePos.Y, 3.5, 0, Math.PI * 2.0); - ctx.LineWidth = 0.5; - ctx.Stroke (); - ctx.Translate (-0.5, -0.5); - ctx.Arc (mousePos.X, mousePos.Y, 3.5, 0, Math.PI * 2.0); - ctx.SetSourceColor (Color.White); - ctx.Stroke (); - - ctx.Restore (); - } - - protected override void updateMouseLocalPos (Point mPos) - { - base.updateMouseLocalPos (mPos); - - Rectangle cb = ClientRectangle; - s = (double)mousePos.X / (double)cb.Width; - v = 1.0 - (double)mousePos.Y / (double)cb.Height; - NotifyValueChanged ("S", s); - NotifyValueChanged ("V", v); - - RegisterForRedraw (); - } - public override void OnLayoutChanges (LayoutingType layoutType) - { - base.OnLayoutChanges (layoutType); - switch (layoutType) { - case LayoutingType.Width: - mousePos.X = (int)Math.Floor(s * (double)ClientRectangle.Width); - break; - case LayoutingType.Height: - mousePos.Y = (int)Math.Floor((1.0-v) * (double)ClientRectangle.Height); - break; - } - } - } -} - diff --git a/src/GraphicObjects/ScrollBar.cs b/src/GraphicObjects/ScrollBar.cs deleted file mode 100644 index 5dac20e1..00000000 --- a/src/GraphicObjects/ScrollBar.cs +++ /dev/null @@ -1,85 +0,0 @@ -// -// ScrollBar.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Xml.Serialization; -using System.ComponentModel; - -namespace Crow -{ - /// <summary> - /// templeted numeric control - /// </summary> - public class ScrollBar : NumericControl - { - //TODO:could be replaced by a template for a Slider - - Orientation _orientation; - int _cursorSize; - - #region CTOR - protected ScrollBar () : base(){} - public ScrollBar(Interface iface) : base(iface) {} - #endregion - - [XmlAttributeAttribute()][DefaultValue(Orientation.Vertical)] - public virtual Orientation Orientation - { - get { return _orientation; } - set { - if (_orientation == value) - return; - _orientation = value; - NotifyValueChanged ("Orientation", _orientation); - RegisterForGraphicUpdate (); - } - } - [XmlAttributeAttribute()][DefaultValue(20)] - public virtual int CursorSize { - get { return _cursorSize; } - set { - if (_cursorSize == value) - return; - _cursorSize = value; - RegisterForGraphicUpdate (); - NotifyValueChanged ("CursorSize", _cursorSize); - } - } - public void onScrollBack (object sender, MouseButtonEventArgs e) - { - Value -= SmallIncrement; - } - public void onScrollForth (object sender, MouseButtonEventArgs e) - { - Value += SmallIncrement; - } - - public void onSliderValueChange(object sender, ValueChangeEventArgs e){ - if (e.MemberName == "Value") - Value = Convert.ToDouble(e.NewValue); - } - } -} diff --git a/src/GraphicObjects/Scroller.cs b/src/GraphicObjects/Scroller.cs deleted file mode 100644 index 30dd1480..00000000 --- a/src/GraphicObjects/Scroller.cs +++ /dev/null @@ -1,291 +0,0 @@ -// -// Scroller.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Xml.Serialization; -using System.ComponentModel; -using System.Diagnostics; -using Cairo; - -namespace Crow -{ - /// <summary> - /// scrolling surface, to be contained in a smaller container in which it will be scrolled - /// </summary> - public class Scroller : Container - { - #region CTOR - protected Scroller () : base(){} - public Scroller (Interface iface) : base(iface){} - #endregion - - public event EventHandler<ScrollingEventArgs> Scrolled; - - int scrollX, scrollY, maxScrollX, maxScrollY, scrollSpeed; - - /// <summary> - /// if true, key stroke are handled in derrived class - /// </summary> - protected bool KeyEventsOverrides = false; - - #region public properties - /// <summary> Horizontal Scrolling Position </summary> - [XmlAttributeAttribute][DefaultValue(0)] - public virtual int ScrollX { - get { return scrollX; } - set { - if (scrollX == value) - return; - - int newS = value; - if (newS < 0) - newS = 0; - else if (newS > maxScrollX) - newS = maxScrollX; - - if (newS == scrollX) - return; - - scrollX = value; - - NotifyValueChanged ("ScrollX", scrollX); - RegisterForGraphicUpdate (); - } - } - /// <summary> Vertical Scrolling Position </summary> - [XmlAttributeAttribute][DefaultValue(0)] - public virtual int ScrollY { - get { return scrollY; } - set { - if (scrollY == value) - return; - - int newS = value; - if (newS < 0) - newS = 0; - else if (newS > maxScrollY) - newS = maxScrollY; - - if (newS == scrollY) - return; - - scrollY = value; - - NotifyValueChanged ("ScrollY", scrollY); - RegisterForGraphicUpdate (); - } - } - /// <summary> Horizontal Scrolling maximum value </summary> - [XmlAttributeAttribute][DefaultValue(0)] - public virtual int MaxScrollX { - get { return maxScrollX; } - set { - if (maxScrollX == value) - return; - - maxScrollX = value; - - if (scrollX > maxScrollX) - ScrollX = maxScrollX; - - NotifyValueChanged ("MaxScrollX", maxScrollX); - RegisterForGraphicUpdate (); - } - } - /// <summary> Vertical Scrolling maximum value </summary> - [XmlAttributeAttribute][DefaultValue(0)] - public virtual int MaxScrollY { - get { return maxScrollY; } - set { - if (maxScrollY == value) - return; - - maxScrollY = value; - - if (scrollY > maxScrollY) - ScrollY = maxScrollY; - - NotifyValueChanged ("MaxScrollY", maxScrollY); - RegisterForGraphicUpdate (); - } - } - /// <summary> Mouse Wheel Scrolling multiplier </summary> - [XmlAttributeAttribute][DefaultValue(50)] - public virtual int ScrollSpeed { - get { return scrollSpeed; } - set { - if (scrollSpeed == value) - return; - - scrollSpeed = value; - - NotifyValueChanged ("ScrollSpeed", scrollSpeed); - } - } - #endregion - - public override void SetChild (GraphicObject _child) - { - Group g = child as Group; - if (g != null) - g.ChildrenCleared -= onChildListCleared; - - base.SetChild (_child); - - g = _child as Group; - if (g != null) - g.ChildrenCleared += onChildListCleared; - } - public override void OnChildLayoutChanges (object sender, LayoutingEventArgs arg) - { - base.OnChildLayoutChanges (sender, arg); - updateMaxScroll (arg.LayoutType); - } - - - #region GraphicObject Overrides - public override Rectangle ScreenCoordinates (Rectangle r) - { - return base.ScreenCoordinates (r) - new Point((int)ScrollX,(int)ScrollY); - } - public override bool PointIsIn (ref Point m) - { - if (!base.PointIsIn(ref m)) - return false; - if (!Slot.ContainsOrIsEqual (m) || child==null) - return false; - m += new Point (ScrollX, ScrollY); - return true; - } - public override void RegisterClip (Rectangle clip) - { - base.RegisterClip (clip - new Point(ScrollX,ScrollY)); - } - public override void OnLayoutChanges (LayoutingType layoutType) - { - base.OnLayoutChanges (layoutType); - - if (layoutType == LayoutingType.Height) - NotifyValueChanged ("PageHeight", Slot.Height); - else if (layoutType == LayoutingType.Width) - NotifyValueChanged ("PageWidth", Slot.Width); - else - return; - updateMaxScroll(layoutType); - } - protected override void onDraw (Context gr) - { - Rectangle rBack = new Rectangle (Slot.Size); - - Background.SetAsSource (gr, rBack); - CairoHelpers.CairoRectangle(gr,rBack, CornerRadius); - gr.Fill (); - - gr.Save (); - if (ClipToClientRect) { - //clip to scrolled client zone - CairoHelpers.CairoRectangle (gr, ClientRectangle, CornerRadius); - gr.Clip (); - } - - gr.Translate (-ScrollX, -ScrollY); - if (child != null) - child.Paint (ref gr); - gr.Restore (); - } - - #region Mouse & Keyboard - /// <summary> Process scrolling vertically, or if shift is down, vertically </summary> - public override void onMouseWheel (object sender, MouseWheelEventArgs e) - { - base.onMouseWheel (sender, e); - if (IFace.Keyboard.IsKeyDown (Key.ShiftLeft)) - ScrollX += e.Delta * ScrollSpeed; - else - ScrollY -= e.Delta * ScrollSpeed; - } - /// <summary> Process scrolling with arrow keys, home and end keys. </summary> - public override void onKeyDown (object sender, KeyboardKeyEventArgs e) - { - base.onKeyDown (sender, e); - - if (KeyEventsOverrides) - return; - - switch (e.Key) { - case Key.Up: - ScrollY--; - break; - case Key.Down: - ScrollY++; - break; - case Key.Left: - ScrollX--; - break; - case Key.Right: - ScrollX++; - break; - case Key.Home: - ScrollX = 0; - ScrollY = 0; - break; - case Key.End: - ScrollX = MaxScrollX; - ScrollY = MaxScrollY; - break; - } - } - #endregion - - #endregion - - void updateMaxScroll (LayoutingType lt){ - if (Child == null) { - MaxScrollX = 0; - MaxScrollY = 0; - return; - } - - Rectangle cb = ClientRectangle; - - if (lt == LayoutingType.Height) { - MaxScrollY = child.Slot.Height - cb.Height; - if (child.Slot.Height > 0) - NotifyValueChanged ("ChildHeightRatio", Slot.Height * Slot.Height / child.Slot.Height); - } else if (lt == LayoutingType.Width) { - MaxScrollX = child.Slot.Width - cb.Width; - if (child.Slot.Width > 0) - NotifyValueChanged ("ChildWidthRatio", Slot.Width * Slot.Width / child.Slot.Width); - } - } - void onChildListCleared(object sender, EventArgs e){ - ScrollY = 0; - ScrollX = 0; - } - - - } -} diff --git a/src/GraphicObjects/ScrollingObject.cs b/src/GraphicObjects/ScrollingObject.cs deleted file mode 100644 index de4b2113..00000000 --- a/src/GraphicObjects/ScrollingObject.cs +++ /dev/null @@ -1,190 +0,0 @@ -// -// ScrollingObject.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Xml.Serialization; -using System.ComponentModel; -using System.Collections; -using Cairo; - - -namespace Crow -{ - /// <summary> - /// generic class to build scrolling control in both directions - /// </summary> - [DesignIgnore] - public class ScrollingObject : GraphicObject - { - #region CTOR - protected ScrollingObject ():base(){} - public ScrollingObject (Interface iface):base(iface){} - #endregion - - int scrollX, scrollY, maxScrollX, maxScrollY, mouseWheelSpeed; - - /// <summary> - /// if true, key stroke are handled in derrived class - /// </summary> - protected bool KeyEventsOverrides = false; - - /// <summary> Horizontal Scrolling Position </summary> - [XmlAttributeAttribute][DefaultValue(0)] - public virtual int ScrollX { - get { return scrollX; } - set { - if (scrollX == value) - return; - - int newS = value; - if (newS < 0) - newS = 0; - else if (newS > maxScrollX) - newS = maxScrollX; - - if (newS == scrollX) - return; - - scrollX = value; - - NotifyValueChanged ("ScrollX", scrollX); - RegisterForGraphicUpdate (); - } - } - /// <summary> Vertical Scrolling Position </summary> - [XmlAttributeAttribute][DefaultValue(0)] - public virtual int ScrollY { - get { return scrollY; } - set { - if (scrollY == value) - return; - - int newS = value; - if (newS < 0) - newS = 0; - else if (newS > maxScrollY) - newS = maxScrollY; - - if (newS == scrollY) - return; - - scrollY = value; - - NotifyValueChanged ("ScrollY", scrollY); - RegisterForGraphicUpdate (); - } - } - /// <summary> Horizontal Scrolling maximum value </summary> - [XmlAttributeAttribute][DefaultValue(0)] - public virtual int MaxScrollX { - get { return maxScrollX; } - set { - if (maxScrollX == value) - return; - - maxScrollX = value; - - if (scrollX > maxScrollX) - ScrollX = maxScrollX; - - NotifyValueChanged ("MaxScrollX", maxScrollX); - RegisterForGraphicUpdate (); - } - } - /// <summary> Vertical Scrolling maximum value </summary> - [XmlAttributeAttribute][DefaultValue(0)] - public virtual int MaxScrollY { - get { return maxScrollY; } - set { - if (maxScrollY == value) - return; - - maxScrollY = value; - - if (scrollY > maxScrollY) - ScrollY = maxScrollY; - - NotifyValueChanged ("MaxScrollY", maxScrollY); - RegisterForGraphicUpdate (); - } - } - /// <summary> Mouse Wheel Scrolling multiplier </summary> - [XmlAttributeAttribute][DefaultValue(1)] - public virtual int MouseWheelSpeed { - get { return mouseWheelSpeed; } - set { - if (mouseWheelSpeed == value) - return; - - mouseWheelSpeed = value; - - NotifyValueChanged ("MouseWheelSpeed", mouseWheelSpeed); - } - } - - /// <summary> Process scrolling vertically, or if shift is down, vertically </summary> - public override void onMouseWheel (object sender, MouseWheelEventArgs e) - { - base.onMouseWheel (sender, e); - if (IFace.Keyboard.IsKeyDown (Key.ShiftLeft)) - ScrollX += e.Delta * MouseWheelSpeed; - else - ScrollY -= e.Delta * MouseWheelSpeed; - } - /// <summary> Process scrolling with arrow keys, home and end keys. </summary> - public override void onKeyDown (object sender, KeyboardKeyEventArgs e) - { - base.onKeyDown (sender, e); - - if (KeyEventsOverrides) - return; - - switch (e.Key) { - case Key.Up: - ScrollY--; - break; - case Key.Down: - ScrollY++; - break; - case Key.Left: - ScrollX--; - break; - case Key.Right: - ScrollX++; - break; - case Key.Home: - ScrollX = 0; - ScrollY = 0; - break; - case Key.End: - ScrollX = MaxScrollX; - ScrollY = MaxScrollY; - break; - } - } - } -} - diff --git a/src/GraphicObjects/Shape.cs b/src/GraphicObjects/Shape.cs deleted file mode 100644 index a4b3193e..00000000 --- a/src/GraphicObjects/Shape.cs +++ /dev/null @@ -1,164 +0,0 @@ -// -// Shape.cs -// -// Author: -// jp <> -// -// 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.Xml.Serialization; -using System.ComponentModel; -using System.IO; -using System.Text; -using Cairo; - -namespace Crow -{ - public class PathParser : StringReader - { - public PathParser (string str) : base (str) {} - - public double ReadDouble () { - StringBuilder tmp = new StringBuilder(); - - while (Peek () >= 0) { - char c = (char)Read(); - if (c.IsWhiteSpaceOrNewLine()) { - if (tmp.Length == 0) - continue; - else - break; - } else if (c == ',') - break; - tmp.Append (c); - } - return double.Parse (tmp.ToString ()); - } - - } - public class Shape : GraphicObject - { - #region CTOR - protected Shape () : base() {} - public Shape (Interface iface) : base (iface) {} - #endregion - - string path; - double strokeWidth; - - public string Path { - get { return path; } - set { - if (path == value) - return; - path = value; - contentSize = default (Size); - NotifyValueChanged ("Path", path); - RegisterForGraphicUpdate (); - } - } - [XmlAttributeAttribute][DefaultValue(1.0)] - public double StokeWidth { - get { return strokeWidth; } - set { - if (strokeWidth == value) - return; - strokeWidth = value; - contentSize = default (Size); - NotifyValueChanged ("StrokeWidth", strokeWidth); - RegisterForGraphicUpdate (); - } - } - - protected override void onDraw (Context gr) - { - - if (string.IsNullOrEmpty (path)) - return; - - Rectangle r = ClientRectangle; - - executePath (gr); - - Background.SetAsSource (gr, r); - gr.FillPreserve (); - gr.LineWidth = strokeWidth; - Foreground.SetAsSource (gr, r); - gr.Stroke (); - } - - void executePath (Context gr){ - using (PathParser sr = new PathParser (path)) { - while (sr.Peek () >= 0) { - char c = (char)sr.Read (); - if (c.IsWhiteSpaceOrNewLine ()) - continue; - switch (c) { - case 'M': - gr.MoveTo (sr.ReadDouble (), sr.ReadDouble ()); - break; - case 'm': - gr.RelMoveTo (sr.ReadDouble (), sr.ReadDouble ()); - break; - case 'L': - gr.LineTo (sr.ReadDouble (), sr.ReadDouble ()); - break; - case 'l': - gr.RelLineTo (sr.ReadDouble (), sr.ReadDouble ()); - break; - case 'C': - gr.CurveTo (sr.ReadDouble (), sr.ReadDouble (), sr.ReadDouble (), sr.ReadDouble (), sr.ReadDouble (), sr.ReadDouble ()); - break; - case 'c': - gr.RelCurveTo (sr.ReadDouble (), sr.ReadDouble (), sr.ReadDouble (), sr.ReadDouble (), sr.ReadDouble (), sr.ReadDouble ()); - break; - case 'Z': - gr.ClosePath (); - break; - case 'F': - gr.Fill (); - break; - case 'G': - gr.Stroke (); - break; - default: - throw new Exception ("Invalid character in path string of Shape control"); - } - } - } - } - protected override int measureRawSize (LayoutingType lt) - { - if ((lt == LayoutingType.Width && contentSize.Width == 0) || (lt == LayoutingType.Height && contentSize.Height == 0)) { - using (Surface drawing = new ImageSurface (Format.A1, 1,1)) { - using (Context ctx = new Context (drawing)) { - executePath (ctx); - Rectangle r = ctx.StrokeExtents (); - contentSize = new Size (r.Right, r.Bottom); - } - } - } - return lt == LayoutingType.Width ? - contentSize.Width + 2 * Margin: contentSize.Height + 2 * Margin; - } - } -} - diff --git a/src/GraphicObjects/Slider.cs b/src/GraphicObjects/Slider.cs deleted file mode 100644 index 2bdd5b8a..00000000 --- a/src/GraphicObjects/Slider.cs +++ /dev/null @@ -1,251 +0,0 @@ -// -// Slider.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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 Cairo; -using System.Xml.Serialization; -using System.ComponentModel; -using System.Diagnostics; - -namespace Crow -{ - /// <summary> - /// templated numeric control to select a value - /// by slidding a cursor - /// </summary> - public class Slider : NumericControl - { - #region CTOR - protected Slider() : base(){} - public Slider(Interface iface) : base(iface) - {} -// public Slider(double minimum, double maximum, double step) -// : base(minimum,maximum,step) -// { -// } - #endregion - - #region implemented abstract members of TemplatedControl - - protected override void loadTemplate (GraphicObject template = null) - { - - } - - #endregion - - #region private fields - Rectangle cursor; - int _cursorSize; - Fill _cursorColor; - Orientation _orientation; - bool holdCursor = false; - #endregion - - protected double unity; - - #region Public properties - [DefaultValue("vgradient|0:White|0,1:LightGray|0,9:LightGray|1:DimGray")] - public virtual Fill CursorColor { - get { return _cursorColor; } - set { - if (_cursorColor == value) - return; - _cursorColor = value; - RegisterForRedraw (); - NotifyValueChanged ("CursorColor", _cursorColor); - } - } - [DefaultValue(20)] - public virtual int CursorSize { - get { return _cursorSize; } - set { - if (_cursorSize == value || value < 8) - return; - _cursorSize = value; - RegisterForGraphicUpdate (); - NotifyValueChanged ("CursorSize", _cursorSize); - } - } - [DefaultValue(Orientation.Horizontal)] - public virtual Orientation Orientation - { - get { return _orientation; } - set { - if (_orientation == value) - return; - _orientation = value; - - RegisterForLayouting (LayoutingType.All); - NotifyValueChanged ("Orientation", _orientation); - } - } - #endregion - - [DefaultValue(10.0)] - public override double Maximum { - get { return base.Maximum; } - set { - if (value == base.Maximum) - return; - base.Maximum = value; - LargeIncrement = base.Maximum / 10.0; - SmallIncrement = LargeIncrement / 5.0; - } - } - - #region GraphicObject Overrides - protected override void onDraw (Context gr) - { - base.onDraw (gr); - if (Maximum <= 0) - return; - - computeCursorPosition (); - - Rectangle r = ClientRectangle; - PointD pStart; - PointD pEnd; - if (_orientation == Orientation.Horizontal) { - pStart = r.TopLeft + new Point (_cursorSize / 2, r.Height / 2); - pEnd = r.TopRight + new Point (-_cursorSize / 2, r.Height / 2); - pStart.Y += 0.5; - pEnd.Y += 0.5; - } else { - pStart = r.TopLeft + new Point (r.Width / 2, _cursorSize / 2); - pEnd = r.BottomLeft + new Point (r.Width / 2,- _cursorSize / 2); - pStart.X += 0.5; - pEnd.X += 0.5; - - } - - DrawGraduations (gr, pStart,pEnd); - - DrawCursor (gr, cursor); - } - #endregion - - protected virtual void DrawGraduations(Context gr, PointD pStart, PointD pEnd) - { - Foreground.SetAsSource (gr); - - gr.LineWidth = 1; - gr.MoveTo(pStart); - gr.LineTo(pEnd); - - gr.Stroke(); - - } - protected virtual void DrawCursor(Context gr, Rectangle _cursor) - { - CursorColor.SetAsSource (gr, _cursor); - CairoHelpers.CairoRectangle (gr, _cursor, CornerRadius); - gr.Fill(); - } - - void computeCursorPosition() - { - Rectangle r = ClientRectangle; - PointD p1; - - if (_orientation == Orientation.Horizontal) { - cursor = new Rectangle (new Size (_cursorSize, (int)(r.Height))); - p1 = r.TopLeft + new Point (_cursorSize / 2, r.Height / 2); - unity = (double)(r.Width - _cursorSize) / (Maximum - Minimum); - cursor.TopLeft = new Point (r.Left + (int)((Value - Minimum) * unity), - (int)(p1.Y - cursor.Height / 2)); - } else { - cursor = new Rectangle (new Size ((int)(r.Width), _cursorSize)); - p1 = r.TopLeft + new Point (r.Width / 2, _cursorSize / 2); - unity = (double)(r.Height - _cursorSize) / (Maximum - Minimum); - cursor.TopLeft = new Point ((int)(p1.X - r.Width / 2), - r.Top + (int)((Value - Minimum) * unity)); - } - cursor.Inflate (-1); - } - Point mouseDownInit; - double mouseDownInitValue; - - #region mouse handling - public override void onMouseDown (object sender, MouseButtonEventArgs e) - { - base.onMouseDown (sender, e); - mouseDownInit = ScreenPointToLocal (e.Position); - mouseDownInitValue = Value; - Rectangle cursInScreenCoord = ScreenCoordinates (cursor + Slot.Position); - if (cursInScreenCoord.ContainsOrIsEqual (e.Position)){ -// Rectangle r = ClientRectangle; -// if (r.Width - _cursorSize > 0) { -// double unit = (Maximum - Minimum) / (double)(r.Width - _cursorSize); -// mouseDownInit += new Point ((int)(Value / unit), (int)(Value / unit)); -// } - holdCursor = true; - }else if (_orientation == Orientation.Horizontal) { - if (e.Position.X < cursInScreenCoord.Left) - Value -= LargeIncrement; - else - Value += LargeIncrement; - } else { - if (e.Position.Y < cursInScreenCoord.Top) - Value -= LargeIncrement; - else - Value += LargeIncrement; - } - } - public override void onMouseUp (object sender,MouseButtonEventArgs e) - { - base.onMouseUp (sender, e); - - holdCursor = false; - } - public override void onMouseMove (object sender, MouseMoveEventArgs e) - { - if (holdCursor) { - Point m = ScreenPointToLocal (e.Position) - mouseDownInit; - Rectangle r = ClientRectangle; - - if (_orientation == Orientation.Horizontal) { - if (r.Width - _cursorSize == 0) - return; - double unit = (Maximum - Minimum) / (double)(r.Width - _cursorSize); - double tmp = mouseDownInitValue + (double)m.X * unit; - tmp -= tmp % SmallIncrement; - Value = tmp; - } else { - if (r.Height - _cursorSize == 0) - return; - double unit = (Maximum - Minimum) / (double)(r.Height - _cursorSize); - double tmp = mouseDownInitValue + (double)m.Y * unit; - tmp -= tmp % SmallIncrement; - Value = tmp; - } - } - - base.onMouseMove (sender, e); - } - #endregion - } -} diff --git a/src/GraphicObjects/Spinner.cs b/src/GraphicObjects/Spinner.cs deleted file mode 100644 index 7c5fdb26..00000000 --- a/src/GraphicObjects/Spinner.cs +++ /dev/null @@ -1,55 +0,0 @@ -// -// Spinner.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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; - -namespace Crow -{ - /// <summary> - /// templated control for selecting a numeric value by clicking on - /// up and down buttons - /// </summary> - public class Spinner : NumericControl - { - #region CTOR - protected Spinner() : base(){} - public Spinner (Interface iface) : base(iface) - { - } - #endregion - - void onUp (object sender, MouseButtonEventArgs e) - { - Value += this.SmallIncrement; - } - void onDown (object sender, MouseButtonEventArgs e) - { - Value -= this.SmallIncrement; - } - - } -} - diff --git a/src/GraphicObjects/Splitter.cs b/src/GraphicObjects/Splitter.cs deleted file mode 100644 index 84e1ade0..00000000 --- a/src/GraphicObjects/Splitter.cs +++ /dev/null @@ -1,237 +0,0 @@ -// -// Splitter.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Xml.Serialization; -using System.ComponentModel; - -namespace Crow -{ - /// <summary> - /// control to add between children of a Stack to allow them to be resized - /// with the pointer - /// </summary> - public class Splitter : GraphicObject - { - #region CTOR - protected Splitter() : base(){} - public Splitter (Interface iface) : base(iface){} - #endregion - - int thickness; - - [XmlAttributeAttribute][DefaultValue(1)] - public virtual int Thickness { - get { return thickness; } - set { - if (thickness == value) - return; - thickness = value; - NotifyValueChanged ("Thickness", thickness); - RegisterForLayouting (LayoutingType.Sizing); - RegisterForGraphicUpdate (); - } - } - - Unit u1, u2; - int init1 = -1, init2 = -1, delta = 0, min1, min2, max1 , max2; - GraphicObject go1 = null, go2 = null; - - void initSplit(Measure m1, int size1, Measure m2, int size2){ - if (m1 != Measure.Stretched) { - init1 = size1; - u1 = m1.Units; - } - if (m2 != Measure.Stretched) { - init2 = size2; - u2 = m2.Units; - } - } - void convertSizeInPix(GraphicObject g1){ - - } - - #region GraphicObject override - public override ILayoutable Parent { - get { return base.Parent; } - set { - if (value != null) { - GenericStack gs = value as GenericStack; - if (gs == null) - throw new Exception ("Splitter may only be chil of stack"); - - } - base.Parent = value; - } - } - public override void onMouseEnter (object sender, MouseMoveEventArgs e) - { - base.onMouseEnter (sender, e); - if ((Parent as GenericStack).Orientation == Orientation.Horizontal) - IFace.MouseCursor = XCursor.H; - else - IFace.MouseCursor = XCursor.V; - } - public override void onMouseLeave (object sender, MouseMoveEventArgs e) - { - base.onMouseLeave (sender, e); - IFace.MouseCursor = XCursor.Default; - } - public override void onMouseDown (object sender, MouseButtonEventArgs e) - { - base.onMouseDown (sender, e); - go1 = go2 = null; - init1 = init2 = -1; - delta = 0; - - GenericStack gs = Parent as GenericStack; - int ptrSplit = gs.Children.IndexOf (this); - if (ptrSplit == 0 || ptrSplit == gs.Children.Count - 1) - return; - - go1 = gs.Children [ptrSplit - 1]; - go2 = gs.Children [ptrSplit + 1]; - - if (gs.Orientation == Orientation.Horizontal) { - initSplit (go1.Width, go1.Slot.Width, go2.Width, go2.Slot.Width); - min1 = go1.MinimumSize.Width; - min2 = go2.MinimumSize.Width; - max1 = go1.MaximumSize.Width; - max2 = go2.MaximumSize.Width; - if (init1 >= 0) - go1.Width = init1; - if (init2 >= 0) - go2.Width = init2; - } else { - initSplit (go1.Height, go1.Slot.Height, go2.Height, go2.Slot.Height); - min1 = go1.MinimumSize.Height; - min2 = go2.MinimumSize.Height; - max1 = go1.MaximumSize.Height; - max2 = go2.MaximumSize.Height; - if (init1 >= 0) - go1.Height = init1; - if (init2 >= 0) - go2.Height = init2; - } - } - public override void onMouseMove (object sender, MouseMoveEventArgs e) - { - base.onMouseMove (sender, e); - - if (!IsActive) - return; - - GenericStack gs = Parent as GenericStack; - int newDelta = delta, size1 = init1 , size2 = init2; - if (gs.Orientation == Orientation.Horizontal) { - newDelta -= e.XDelta; - if (size1 < 0) - size1 = go1.Slot.Width + delta; - if (size2 < 0) - size2 = go2.Slot.Width - delta; - } else { - newDelta -= e.YDelta; - if (size1 < 0) - size1 = go1.Slot.Height + delta; - if (size2 < 0) - size2 = go2.Slot.Height - delta; - } - - if (size1 - newDelta < min1 || (max1 > 0 && size1 - newDelta > max1) || - size2 + newDelta < min2 || (max2 > 0 && size2 + newDelta > max2)) - return; - - delta = newDelta; - - if (gs.Orientation == Orientation.Horizontal) { - if (init1 >= 0) - go1.Width = init1 - delta; - if (init2 >= 0) - go2.Width = init2 + delta; - } else { - if (init1 >= 0) - go1.Height = init1 - delta; - if (init2 >= 0) - go2.Height = init2 + delta; - } - } - public override void onMouseUp (object sender, MouseButtonEventArgs e) - { - base.onMouseUp (sender, e); - - GenericStack gs = Parent as GenericStack; - - if (init1 >= 0 && u1 == Unit.Percent) { - if (gs.Orientation == Orientation.Horizontal) - go1.Width = new Measure ((int)Math.Ceiling ( - go1.Width.Value * 100.0 / (double)gs.Slot.Width), Unit.Percent); - else - go1.Height = new Measure ((int)Math.Ceiling ( - go1.Height.Value * 100.0 / (double)gs.Slot.Height), Unit.Percent); - } - if (init2 >= 0 && u2 == Unit.Percent) { - if (gs.Orientation == Orientation.Horizontal) - go2.Width = new Measure ((int)Math.Floor ( - go2.Width.Value * 100.0 / (double)gs.Slot.Width), Unit.Percent); - else - go2.Height = new Measure ((int)Math.Floor ( - go2.Height.Value * 100.0 / (double)gs.Slot.Height), Unit.Percent); - } - } - public override bool UpdateLayout (LayoutingType layoutType) - { - GenericStack gs = Parent as GenericStack; - if (layoutType == LayoutingType.Width){ - if (gs.Orientation == Orientation.Horizontal) - Width = thickness; - else - Width = Measure.Stretched; - } else if (layoutType == LayoutingType.Height){ - if (gs.Orientation == Orientation.Vertical) - Height = thickness; - else - Height = Measure.Stretched; - } - return base.UpdateLayout (layoutType); - } - public override bool PointIsIn (ref Point m) - { - if (!(Visible & IsEnabled)||IsDragged) - return false; - if (!Parent.PointIsIn(ref m)) - return false; - m -= (Parent.getSlot().Position + Parent.ClientRectangle.Position) ; - Rectangle r = Slot; - if (Width == Measure.Stretched) - r.Inflate (0, 5); - else - r.Inflate (5, 0); - return r.ContainsOrIsEqual (m); - } - #endregion - } -} - diff --git a/src/GraphicObjects/TabItem.cs b/src/GraphicObjects/TabItem.cs deleted file mode 100644 index 473fc313..00000000 --- a/src/GraphicObjects/TabItem.cs +++ /dev/null @@ -1,302 +0,0 @@ -// -// TabItem.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Xml.Serialization; -using System.ComponentModel; -using System.Diagnostics; -using Cairo; -using System.Linq; - -namespace Crow -{ - public class TabItem : TemplatedContainer - { - #region CTOR - protected TabItem() : base(){} - public TabItem (Interface iface) : base(iface){} - #endregion - - public event EventHandler QueryClose; - - internal TabView tview = null; - - #region Private fields - GraphicObject titleWidget; - int tabOffset; - bool isSelected; - Measure tabThickness; - #endregion - - #region TemplatedControl overrides - public override GraphicObject Content { - get { - return _contentContainer == null ? null : _contentContainer.Child; - } - set { - if (Content != null) { - Content.LogicalParent = null; - _contentContainer.SetChild (null); - } - _contentContainer.SetChild(value); - if (value != null) - value.LogicalParent = this; - } - } - protected override void loadTemplate(GraphicObject template = null) - { - base.loadTemplate (template); - - titleWidget = this.child.FindByName ("TabTitle"); - } - internal GraphicObject TabTitle { get { return titleWidget; }} - #endregion - - /// <summary> - /// order of redrawing, items can't be reordered in TemplatedGroup due to data linked, so we need another index - /// instead of children list order - /// </summary> - public int viewIndex = 0; - public virtual int ViewIndex { - get { return viewIndex; } - set { - if (viewIndex == value) - return; - viewIndex = value; - NotifyValueChanged ("ViewIndex", viewIndex); - } - } - - [DefaultValue(0)] - public int TabOffset { - get { return tabOffset; } - set { - if (tabOffset == value) - return; - tabOffset = value; - NotifyValueChanged ("TabOffset", tabOffset); - - RegisterForLayouting (LayoutingType.X); - RegisterForGraphicUpdate (); - } - } - public Measure TabHeight { - get { return tview == null ? Measure.Fit : tview.TabHeight; } - } - public Measure TabWidth { - get { return tview == null ? Measure.Fit : tview.TabWidth; } - } - [DefaultValue(false)] - public virtual bool IsSelected { - get { return isSelected; } - set { - if (isSelected == value) - return; - isSelected = value; - NotifyValueChanged ("IsSelected", isSelected); - } - } - protected override void onDraw (Context gr) - { - gr.Save (); - - TabView tv = Parent as TabView; - - Rectangle r = TabTitle.Slot; - r.Width = TabWidth; - - gr.MoveTo (0.5, r.Bottom-0.5); - gr.LineTo (r.Left - tv.LeftSlope, r.Bottom-0.5); - gr.CurveTo ( - r.Left - tv.LeftSlope / 2, r.Bottom-0.5, - r.Left - tv.LeftSlope / 2, 0.5, - r.Left, 0.5); - gr.LineTo (r.Right, 0.5); - gr.CurveTo ( - r.Right + tv.RightSlope / 2, 0.5, - r.Right + tv.RightSlope / 2, r.Bottom-0.5, - r.Right + tv.RightSlope, r.Bottom-0.5); - gr.LineTo (Slot.Width-0.5, r.Bottom-0.5); - - - gr.LineTo (Slot.Width-0.5, Slot.Height-0.5); - gr.LineTo (0.5, Slot.Height-0.5); - gr.ClosePath (); - gr.LineWidth = 1; - Foreground.SetAsSource (gr); - gr.StrokePreserve (); - gr.Clip (); - base.onDraw (gr); - gr.Restore (); - } - - Point dragStartPoint; - int dragThreshold = 16; - int dis = 128; - internal TabView savedParent = null; - - void makeFloating (TabView tv) { - lock (IFace.UpdateMutex) { - ImageSurface di = new ImageSurface (Format.Argb32, dis, dis); - IFace.DragImageHeight = dis; - IFace.DragImageWidth = dis; - using (Context ctx = new Context (di)) { - double div = Math.Max (LastPaintedSlot.Width, LastPaintedSlot.Height); - double s = (double)dis / 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 (); - } - } - IFace.DragImage = di; - } - tv.RemoveChild (this); - savedParent = tv; - } - - public override ILayoutable Parent { - get { - return base.Parent; - } - set { - base.Parent = value; - if (value != null) { - dragStartPoint = IFace.Mouse.Position; - savedParent = value as TabView; - } - } - } - protected override void onStartDrag (object sender, DragDropEventArgs e) - { - base.onStartDrag (sender, e); - - dragStartPoint = IFace.Mouse.Position; - } - protected override void onEndDrag (object sender, DragDropEventArgs e) - { - base.onEndDrag (sender, e); - - if (Parent != null) - return; - - savedParent.AddChild (this); - - IFace.ClearDragImage (); - } - protected override void onDrop (object sender, DragDropEventArgs e) - { - base.onDrop (sender, e); - if (Parent != null) - return; - TabView tv = e.DropTarget as TabView; - if (tv == null) - return; - - IFace.ClearDragImage (); - - tv.AddChild (this); - } - #region Mouse Handling - public override bool PointIsIn (ref Point m) - { - if (!base.PointIsIn (ref m)) - return false; - - if (m.Y < tview.TabHeight) - return TabTitle.Slot.ContainsOrIsEqual (m); - else - return this.isSelected; - } - public override void onMouseUp (object sender, MouseButtonEventArgs e) - { - base.onMouseUp (sender, e); - tview.UpdateLayout (LayoutingType.ArrangeChildren); - } - public override void onMouseMove (object sender, MouseMoveEventArgs e) - { - base.onMouseMove (sender, e); - - if (Parent == null) - return; - - if (!IsDragged) - return; - - TabView tv = Parent as TabView; - if (Math.Abs (e.Position.Y - dragStartPoint.Y) > dragThreshold || - Math.Abs (e.Position.X - dragStartPoint.X) > dragThreshold) { - makeFloating (tv); - return; - } - - Rectangle cb = ClientRectangle; - - int tmp = TabOffset + e.XDelta; - if (tmp < tview.LeftSlope) { - TabOffset = tview.LeftSlope; - } else if (tmp > cb.Width - tv.RightSlope - tv.TabWidth) { - TabOffset = cb.Width - tv.RightSlope - tv.TabWidth; - }else{ - dragStartPoint.X = e.Position.X; - TabItem[] tabItms = tv.Children.Cast<TabItem>().OrderBy (t=>t.ViewIndex).ToArray(); - if (ViewIndex > 0 && e.XDelta < 0) { - TabItem previous = tabItms [ViewIndex - 1]; - if (tmp < previous.TabOffset + tview.TabWidth / 2) { - previous.ViewIndex = ViewIndex; - ViewIndex--; - tv.UpdateLayout (LayoutingType.ArrangeChildren); - } - - }else if (ViewIndex < tabItms.Length - 1 && e.XDelta > 0) { - TabItem next = tabItms [ViewIndex + 1]; - if (tmp > next.TabOffset - tview.TabWidth / 2){ - next.ViewIndex = ViewIndex; - ViewIndex++; - tv.UpdateLayout (LayoutingType.ArrangeChildren); - } - } - TabOffset = tmp; - } - } - public void butCloseTabClick (object sender, MouseButtonEventArgs e){ - QueryClose.Raise (this, null); - //if tab is used as a templated item root in a templatedGroup, local datasource - //is not null, in this case, removing the data entries will delete automatically the item - if (localDataSourceIsNull) - (Parent as TabView)?.DeleteChild (this); - } - #endregion - - } -} - diff --git a/src/GraphicObjects/TabView.cs b/src/GraphicObjects/TabView.cs deleted file mode 100644 index 304e820d..00000000 --- a/src/GraphicObjects/TabView.cs +++ /dev/null @@ -1,337 +0,0 @@ -// -// TabView.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Xml.Serialization; -using System.ComponentModel; -using Cairo; -using System.Diagnostics; -using System.Linq; - -namespace Crow -{ - public class TabView : Group - { - #region CTOR - public TabView() : base(){} - public TabView (Interface iface) : base(iface){} - #endregion - - #region Private fields - int adjustedTab = -1; - int leftSlope; - int rightSlope; - Measure tabHeight, tabWidth; - Orientation _orientation; - int selectedTab; - #endregion - - #region public properties - [DefaultValue(Orientation.Horizontal)] - public virtual Orientation Orientation - { - get { return _orientation; } - set { - if (_orientation == value) - return; - _orientation = value; - NotifyValueChanged ("Orientation", _orientation); - if (_orientation == Orientation.Horizontal) - NotifyValueChanged ("TabOrientation", Orientation.Vertical); - else - NotifyValueChanged ("TabOrientation", Orientation.Horizontal); - this.RegisterForLayouting (LayoutingType.ArrangeChildren); - } - } - [DefaultValue(16)] - public int LeftSlope - { - get { return leftSlope; } - set { - if (leftSlope == value) - return; - leftSlope = value; - NotifyValueChanged ("leftSlope", leftSlope); - tabSizeHasChanged = true; - //RegisterForLayouting (LayoutingType.ArrangeChildren); - } - } - bool tabSizeHasChanged = false; - [DefaultValue(16)] - public int RightSlope - { - get { return rightSlope; } - set { - if (rightSlope == value) - return; - rightSlope = value; - NotifyValueChanged ("RightSlope", rightSlope); - tabSizeHasChanged = true; - //RegisterForLayouting (LayoutingType.ArrangeChildren); - } - } - [DefaultValue("18")] - public Measure TabHeight { - get { return tabHeight; } - set { - if (tabHeight == value) - return; - tabHeight = value; - NotifyValueChanged ("TabHeight", tabHeight); -// childrenRWLock.EnterReadLock (); -// foreach (GraphicObject ti in Children) { -// ti.NotifyValueChanged ("TabHeight", tabHeight); -// } -// childrenRWLock.ExitReadLock (); - RegisterForLayouting (LayoutingType.ArrangeChildren); - } - } - [DefaultValue("120")] - public Measure TabWidth { - get { return adjustedTab > 0 ? (Measure)adjustedTab : tabWidth; } - set { - if (tabWidth == value) - return; - tabWidth = value; - NotifyValueChanged ("TabWidth", TabWidth); -// -// childrenRWLock.EnterReadLock (); -// foreach (GraphicObject ti in Children) { -// ti.NotifyValueChanged ("TabWidth", tabWidth); -// } -// childrenRWLock.ExitReadLock (); - RegisterForLayouting (LayoutingType.ArrangeChildren); - } - } - - public virtual int SelectedTab { - get { return selectedTab; } - set { - if (value == selectedTab) - return; - - if (selectedTab < Children.Count && selectedTab >= 0) - (Children [selectedTab] as TabItem).IsSelected = false; - - selectedTab = value; - - if (selectedTab < Children.Count && selectedTab >= 0) - (Children [selectedTab] as TabItem).IsSelected = true; - - NotifyValueChanged ("SelectedTab", selectedTab); - RegisterForRedraw (); - } - } - #endregion - - public override void AddChild (GraphicObject child) - { - TabItem ti = child as TabItem; - if (ti == null) - throw new Exception ("TabView control accept only TabItem as child."); - - ti.MouseDown += Ti_MouseDown; - ti.TabTitle.LayoutChanged += Ti_TabTitle_LayoutChanged; - ti.tview = this; - - base.AddChild (child); - - SelectedTab = ti.ViewIndex = Children.Count - 1; - this.RegisterForLayouting (LayoutingType.ArrangeChildren); - } - public override void RemoveChild (GraphicObject child) - { - TabItem ti = child as TabItem; - if (ti == null) - throw new Exception ("TabView control accept only TabItem as child."); - - ti.MouseDown -= Ti_MouseDown; - ti.TabTitle.LayoutChanged -= Ti_TabTitle_LayoutChanged; - ti.tview = null; - - childrenRWLock.EnterReadLock (); - - TabItem[] tabItms = Children.Cast<TabItem>().OrderBy (t=>t.ViewIndex).ToArray(); - int selTabViewIdx = -1; - - if (SelectedTab < tabItms.Length && SelectedTab >= 0) - selTabViewIdx = (Children [SelectedTab] as TabItem).ViewIndex; - - for (int i = selTabViewIdx+1; i < tabItms.Length; i++) - tabItms [i].ViewIndex--; - - if (selTabViewIdx > tabItms.Length - 2) - selTabViewIdx = tabItms.Length - 2; - - if (selTabViewIdx < 0) - SelectedTab = -1; - else - SelectedTab = Children.IndexOf (tabItms [selTabViewIdx]); - - childrenRWLock.ExitReadLock (); - - base.RemoveChild (child); - } - - public override bool ArrangeChildren { get { return true; } } - public override bool UpdateLayout (LayoutingType layoutType) - { - RegisteredLayoutings &= (~layoutType); - - if (layoutType == LayoutingType.ArrangeChildren && Children.Count > 0) { - Rectangle cb = ClientRectangle; - - int tabSpace = tabWidth + leftSlope; - int tc = Children.Count (c => c.Visible == true); - - if (tc > 0) - tabSpace = Math.Min(tabSpace, (cb.Width-rightSlope) / tc); - - if (tabSpace < tabWidth + leftSlope) - adjustedTab = tabSpace - leftSlope; - else - adjustedTab = -1; - - //Console.WriteLine ("tabspace: {0} tw:{1}", tabSpace, tabWidth); - - childrenRWLock.EnterReadLock(); - TabItem[] tabItms = Children.Cast<TabItem>().OrderBy (t=>t.ViewIndex).ToArray(); - childrenRWLock.ExitReadLock(); - int curOffset = leftSlope; - - for (int i = 0; i < tabItms.Length; i++) { - if (!tabItms [i].Visible) - continue; - tabItms [i].NotifyValueChanged ("TabHeight", tabHeight); - tabItms [i].NotifyValueChanged ("TabWidth", TabWidth); - if (!tabItms [i].IsDragged) { - tabItms [i].TabOffset = curOffset; - //Console.WriteLine ("offset: {0}=>{1}", tabItms [i].Name, tabItms [i].TabOffset); - } - if (Orientation == Orientation.Horizontal) { - curOffset += tabSpace; - } else - curOffset += tabSpace; - } - - //if no layouting remains in queue for item, registre for redraw - if (RegisteredLayoutings == LayoutingType.None && IsDirty) - IFace.EnqueueForRepaint (this); - - return true; - } - - return base.UpdateLayout(layoutType); - } - public override void OnLayoutChanges (LayoutingType layoutType) - { - if (_orientation == Orientation.Horizontal) { - if (layoutType == LayoutingType.Width) - RegisterForLayouting (LayoutingType.ArrangeChildren); - } else if (layoutType == LayoutingType.Height) - RegisterForLayouting (LayoutingType.ArrangeChildren); - - base.OnLayoutChanges (layoutType); - } - - protected override void onDraw (Context gr) - { - Rectangle rBack = new Rectangle (Slot.Size); - - Background.SetAsSource (gr, rBack); - CairoHelpers.CairoRectangle(gr,rBack, CornerRadius); - gr.Fill (); - - gr.Save (); - - if (ClipToClientRect) { - //clip to client zone - CairoHelpers.CairoRectangle (gr, ClientRectangle, CornerRadius); - gr.Clip (); - } - - childrenRWLock.EnterReadLock (); - - TabItem[] tabItms = Children.Where(tt=>tt.Visible).Cast<TabItem> (). - OrderBy (t => t.ViewIndex).ToArray (); - - int selTabViewIdx = -1; - if (SelectedTab < tabItms.Length && SelectedTab >= 0) - selTabViewIdx = (Children [SelectedTab] as TabItem).ViewIndex; - - childrenRWLock.ExitReadLock (); - - int i = 0; - while (i < selTabViewIdx) { - tabItms [i].Paint (ref gr); - i++; - } - i = tabItms.Length - 1; - while (i > selTabViewIdx) { - tabItms [i].Paint (ref gr); - i--; - } - - if (selTabViewIdx >= 0) - tabItms [selTabViewIdx].Paint (ref gr); - - gr.Restore (); - } - - protected override void onDragEnter (object sender, DragDropEventArgs e) - { - base.onDragEnter (sender, e); - - TabItem ti = e.DragSource as TabItem; - if (ti == null) - return; - if (ti.Parent != null || ti.savedParent == this) - return; - - this.AddChild (ti); - - Point p = ScreenPointToLocal (IFace.Mouse.Position) - Margin; - - p.X = Math.Max (leftSlope, p.X); - p.X = Math.Min (ClientRectangle.Width - rightSlope - TabWidth, p.X); - ti.TabOffset = p.X; - - IFace.ClearDragImage (); - - } - - void Ti_TabTitle_LayoutChanged (object sender, LayoutingEventArgs e) - { - if (e.LayoutType == LayoutingType.X) - RegisterForLayouting (LayoutingType.ArrangeChildren); - } - void Ti_MouseDown (object sender, MouseButtonEventArgs e) - { - SelectedTab = Children.IndexOf (sender as GraphicObject); - } - } -} - diff --git a/src/GraphicObjects/TemplatedContainer.cs b/src/GraphicObjects/TemplatedContainer.cs deleted file mode 100644 index a779595d..00000000 --- a/src/GraphicObjects/TemplatedContainer.cs +++ /dev/null @@ -1,101 +0,0 @@ -// -// TemplatedContainer.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Xml.Serialization; -using System.Xml; -using System.Reflection; - -namespace Crow -{ - /// <summary> - /// base class for new containers that will use templates. - /// - /// TemplatedControl's **must** provide a widget of the [`Container`](Container) class named **_'Content'_** inside their template tree - /// </summary> - public class TemplatedContainer : TemplatedControl - { - #if DESIGN_MODE - public override void getIML (System.Xml.XmlDocument doc, System.Xml.XmlNode parentElem) - { - if (this.design_isTGItem) - return; - base.getIML (doc, parentElem); - if (!HasContent) - return; - Content.getIML (doc, parentElem.LastChild); - } - #endif - - #region CTOR - protected TemplatedContainer() : base(){} - public TemplatedContainer (Interface iface) : base(iface){} - #endregion - - protected Container _contentContainer; - - /// <summary> - /// Single child of this templated container. - /// </summary> - public virtual GraphicObject Content { - get { - return _contentContainer == null ? null : _contentContainer.Child; - } - set { - _contentContainer.SetChild(value); - NotifyValueChanged ("HasContent", HasContent); - } - } - [XmlIgnore]public bool HasContent { - get { return _contentContainer?.Child != null; } - } - //TODO: move loadTemplate and ResolveBinding in TemplatedContainer - protected override void loadTemplate(GraphicObject template = null) - { - base.loadTemplate (template); - _contentContainer = this.child.FindByName ("Content") as Container; - } - - #region GraphicObject overrides - public override GraphicObject FindByName (string nameToFind) - { - if (Name == nameToFind) - return this; - - return Content == null ? null : Content.FindByName (nameToFind); - } - public override bool Contains (GraphicObject goToFind) - { - if (Content == goToFind) - return true; - if (Content?.Contains (goToFind) == true) - return true; - return base.Contains (goToFind); - } - #endregion - } -} - diff --git a/src/GraphicObjects/TemplatedControl.cs b/src/GraphicObjects/TemplatedControl.cs deleted file mode 100644 index 54991a41..00000000 --- a/src/GraphicObjects/TemplatedControl.cs +++ /dev/null @@ -1,158 +0,0 @@ -// -// TemplatedControl.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Xml.Serialization; -using System.ComponentModel; -using System.IO; -using System.Xml; -using System.Diagnostics; -using System.Linq; -using System.Collections.Generic; -using System.Text; -using System.Reflection; -using Cairo; - -namespace Crow -{ - /// <summary> - /// Base class for all templated widget - /// </summary> - public abstract class TemplatedControl : PrivateContainer - { - #if DESIGN_MODE - public bool design_inlineTemplate = false; - public override void getIML (System.Xml.XmlDocument doc, System.Xml.XmlNode parentElem) - { - if (this.design_isTGItem) - return; - base.getIML (doc, parentElem); - if (child == null || !design_inlineTemplate) - return; - XmlElement xe = doc.CreateElement("Template"); - child.getIML (doc, xe); - parentElem.LastChild.AppendChild (xe); - } - #endif - #region CTOR - protected TemplatedControl() : base(){} - public TemplatedControl (Interface iface) : base(iface){} - #endregion - - string _template; - string caption; - - /// <summary> - /// Template path - /// </summary> - //TODO: this property should be renamed 'TemplatePath' - [XmlAttributeAttribute][DefaultValue(null)] - public string Template { - get { return _template; } - set { - if (Template == value) - return; - _template = value; - - if (string.IsNullOrEmpty(_template)) - loadTemplate (); - else - loadTemplate (IFace.Load (_template)); - } - } - /// <summary> - /// a caption being recurrent need in templated widget, it is declared here. - /// </summary> - [XmlAttributeAttribute()][DefaultValue("Templated Control")] - public virtual string Caption { - get { return caption; } - set { - if (caption == value) - return; - caption = value; - NotifyValueChanged ("Caption", caption); - } - } - - #region GraphicObject overrides - - public override void Initialize () - { - loadTemplate (); - base.Initialize (); - } - /// <summary> - /// override search method from GraphicObject to prevent - /// searching inside template - /// </summary> - /// <returns>widget identified by name, or null if not found</returns> - /// <param name="nameToFind">widget's name to find</param> - public override GraphicObject FindByName (string nameToFind) - { - //prevent name searching in template - return nameToFind == this.Name ? this : null; - } - /// <summary> - ///onDraw is overrided to prevent default drawing of background, template top container - ///may have a binding to root background or a fixed one. - ///this allow applying root background to random template's component - /// </summary> - /// <param name="gr">Backend context</param> - protected override void onDraw (Context gr) - { - gr.Save (); - - if (ClipToClientRect) { - //clip to client zone - CairoHelpers.CairoRectangle (gr, ClientRectangle, CornerRadius); - gr.Clip (); - } - - if (child != null) - child.Paint (ref gr); - gr.Restore (); - } - #endregion - - /// <summary> - /// Loads the template. - /// </summary> - /// <param name="template">Optional template instance</param> - protected virtual void loadTemplate(GraphicObject template = null) - { - if (this.child != null)//template change, bindings has to be reset - this.ClearTemplateBinding(); - - if (template == null) { - if (!IFace.DefaultTemplates.ContainsKey (this.GetType ().FullName)) - throw new Exception (string.Format ("No default template found for '{0}'", this.GetType ().FullName)); - this.SetChild (IFace.Load (IFace.DefaultTemplates[this.GetType ().FullName])); - }else - this.SetChild (template); - } - } -} - diff --git a/src/GraphicObjects/TemplatedGroup.cs b/src/GraphicObjects/TemplatedGroup.cs deleted file mode 100644 index f7c93763..00000000 --- a/src/GraphicObjects/TemplatedGroup.cs +++ /dev/null @@ -1,514 +0,0 @@ -// -// TemplatedGroup.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Xml.Serialization; -using System.Xml; -using System.Reflection; -using System.Collections.Generic; -using System.ComponentModel; -using System.Collections; -using System.Threading; -using System.Linq; -using Crow.IML; -using System.Diagnostics; - -namespace Crow -{ - public abstract class TemplatedGroup : TemplatedControl - { - #if DESIGN_MODE - public override void getIML (System.Xml.XmlDocument doc, System.Xml.XmlNode parentElem) - { - if (this.design_isTGItem) - return; - base.getIML (doc, parentElem); - - if (string.IsNullOrEmpty(_itemTemplate)) { - foreach (ItemTemplate it in ItemTemplates.Values) - it.getIML (doc, parentElem.LastChild); - } - - foreach (GraphicObject g in Items) { - g.getIML (doc, parentElem.LastChild); - } - } - #endif - - #region CTOR - protected TemplatedGroup() : base(){} - public TemplatedGroup (Interface iface) : base(iface){} - #endregion - - protected Group items; - string _itemTemplate, dataTest; - - #region events - public event EventHandler<SelectionChangeEventArgs> SelectedItemChanged; - public event EventHandler Loaded; - #endregion - - IList data; - int _selectedIndex = -1; - Color selBackground, selForeground; - - int itemPerPage = 50; - CrowThread loadingThread = null; - - bool isPaged = false; - - #region Templating - //TODO: dont instantiate ItemTemplates if not used - //but then i should test if null in msil gen - public Dictionary<string, ItemTemplate> ItemTemplates = new Dictionary<string, Crow.ItemTemplate>(); - - /// <summary> - /// Keep track of expanded subnodes and closed time to unload - /// </summary> - //Dictionary<GraphicObject, Stopwatch> nodes = new Dictionary<GraphicObject, Stopwatch>(); - internal List<GraphicObject> nodes = new List<GraphicObject>(); - /// <summary> - /// Item templates file path, on disk or embedded. - /// - /// ItemTemplate file may contains either a single template without the - /// ItemTemplate enclosing tag, or several item templates each enclosed - /// in a separate tag. - /// </summary> - [XmlAttributeAttribute] - public string ItemTemplate { - get { return _itemTemplate; } - set { - if (value == _itemTemplate) - return; - - _itemTemplate = value; - - //TODO:reload list with new template? - NotifyValueChanged("ItemTemplate", _itemTemplate); - } - } - protected override void loadTemplate(GraphicObject template = null) - { - base.loadTemplate (template); - - items = this.child.FindByName ("ItemsContainer") as Group; - if (items == null) - throw new Exception ("TemplatedGroup template Must contain a Group named 'ItemsContainer'"); - if (items.Children.Count == 0) - NotifyValueChanged ("HasChildren", false); - else - NotifyValueChanged ("HasChildren", true); - } - /// <summary> - /// Use to define condition on Data item for selecting among ItemTemplates. - /// Default value is 'TypeOf' for selecting Template depending on Type of Data. - /// Other possible values are properties of Data - /// </summary> - /// <value>The data property test.</value> - [XmlAttributeAttribute][DefaultValue("TypeOf")] - public string DataTest { - get { return dataTest; } - set { - if (value == dataTest) - return; - - dataTest = value; - - NotifyValueChanged("DataTest", dataTest); - } - } - #endregion - - public virtual List<GraphicObject> Items{ - get { - return isPaged ? items.Children.SelectMany(x => (x as Group).Children).ToList() - : items.Children; - } - } - [XmlAttributeAttribute][DefaultValue(-1)]public virtual int SelectedIndex{ - get { return _selectedIndex; } - set { - if (value == _selectedIndex) - return; - - if (_selectedIndex >= 0 && Items.Count > _selectedIndex) { - Items[_selectedIndex].Foreground = Color.Transparent; - Items[_selectedIndex].Background = Color.Transparent; - } - - _selectedIndex = value; - - if (_selectedIndex >= 0 && Items.Count > _selectedIndex) { - Items[_selectedIndex].Foreground = SelectionForeground; - Items[_selectedIndex].Background = SelectionBackground; - } - - NotifyValueChanged ("SelectedIndex", _selectedIndex); - NotifyValueChanged ("SelectedItem", SelectedItem); - SelectedItemChanged.Raise (this, new SelectionChangeEventArgs (SelectedItem)); - } - } - [XmlIgnore]public virtual object SelectedItem{ - get { return data == null ? null : _selectedIndex < 0 ? data.GetDefaultValue() : data[_selectedIndex]; } - set { - if (data == null) { - SelectedIndex = -1; - return; - } - //TODO:double check if value type will be notified to binding sys - if (value == SelectedItem) - return; - - SelectedIndex = data.IndexOf (value); - } - } - [XmlIgnore]public bool HasItems { - get { return Items.Count > 0; } - } - [XmlAttributeAttribute]public IList Data { - get { return data; } - set { - if (value == data) - return; - - cancelLoadingThread (); - - if (data is IObservableList) { - IObservableList ol = data as IObservableList; - ol.ListAdd -= Ol_ListAdd; - ol.ListRemove -= Ol_ListRemove; - } - - data = value; - - if (data is IObservableList) { - IObservableList ol = data as IObservableList; - ol.ListAdd += Ol_ListAdd; - ol.ListRemove += Ol_ListRemove; - } - - NotifyValueChanged ("Data", data); - - //lock (CurrentInterface.LayoutMutex) - ClearItems (); - - if (data == null) - return; - - loadingThread = new CrowThread (this, loading); - loadingThread.Finished += (object sender, EventArgs e) => (sender as TemplatedGroup).Loaded.Raise (sender, e); - loadingThread.Start (); - - NotifyValueChanged ("SelectedIndex", _selectedIndex); - NotifyValueChanged ("SelectedItem", SelectedItem); - SelectedItemChanged.Raise (this, new SelectionChangeEventArgs (SelectedItem)); - NotifyValueChanged ("HasItems", HasItems); - } - } - - void Ol_ListRemove (object sender, ListChangedEventArg e) - { - if (this.isPaged) { - int p = e.Index / itemPerPage; - int i = e.Index % itemPerPage; - (items.Children [p] as Group).DeleteChild (i); - } else - items.DeleteChild (e.Index); - } - - void Ol_ListAdd (object sender, ListChangedEventArg e) - { - if (this.isPaged) { - throw new NotImplementedException(); -// int p = e.Index / itemPerPage; -// int i = e.Index % itemPerPage; -// (items.Children [p] as Group).InsertChild (i, e.Element); - } else - loadItem (e.Element, items, dataTest); - } - - [XmlAttributeAttribute][DefaultValue("SteelBlue")] - public virtual Color SelectionBackground { - get { return selBackground; } - set { - if (value == selBackground) - return; - selBackground = value; - NotifyValueChanged ("SelectionBackground", selBackground); - RegisterForRedraw (); - } - } - [XmlAttributeAttribute][DefaultValue("White")] - public virtual Color SelectionForeground { - get { return selForeground; } - set { - if (value == selForeground) - return; - selForeground = value; - NotifyValueChanged ("SelectionForeground", selForeground); - RegisterForRedraw (); - } - } - - protected void raiseSelectedItemChanged(){ - SelectedItemChanged.Raise (this, new SelectionChangeEventArgs (SelectedItem)); - } - - - public virtual void AddItem(GraphicObject g){ - items.AddChild (g); - g.LogicalParent = this; - NotifyValueChanged ("HasChildren", true); - } - public virtual void RemoveItem(GraphicObject g) - { - g.LogicalParent = null; - items.DeleteChild (g); - if (items.Children.Count == 0) - NotifyValueChanged ("HasChildren", false); - } - - public virtual void ClearItems() - { - _selectedIndex = -1; - NotifyValueChanged ("SelectedIndex", _selectedIndex); - NotifyValueChanged ("SelectedItem", null); - - items.ClearChildren (); - NotifyValueChanged ("HasChildren", false); - } - - - #region GraphicObject overrides - public override GraphicObject FindByName (string nameToFind) - { - if (Name == nameToFind) - return this; - - foreach (GraphicObject w in Items) { - GraphicObject r = w.FindByName (nameToFind); - if (r != null) - return r; - } - return null; - } - public override bool Contains (GraphicObject goToFind) - { - foreach (GraphicObject w in Items) { - if (w == goToFind) - return true; - if (w.Contains (goToFind)) - return true; - } - return base.Contains(goToFind); - } -// public override void ClearBinding () -// { -// if (items != null) -// items.ClearBinding (); -// -// base.ClearBinding (); -// } -// public override void ResolveBindings () -// { -// base.ResolveBindings (); -// if (items != null) -// items.ResolveBindings (); -// } - #endregion - - /// <summary> - /// Items loading thread - /// </summary> - void loading(){ - loadPage (data, items, dataTest); - } -// //if (!ItemTemplates.ContainsKey ("default")) -// // ItemTemplates ["default"] = Interface.GetItemTemplate (ItemTemplate); -// -// for (int i = 1; i <= (data.Count / itemPerPage) + 1; i++) { -// if ((bool)loadingThread?.cancelRequested) { -// this.Dispose (); -// return; -// } -// loadPage (i); -// Thread.Sleep (1); -// } -// } - void cancelLoadingThread(){ - if (loadingThread != null) - loadingThread.Cancel (); - } - void loadPage(IList _data, Group page, string _dataTest) - { - #if DEBUG_LOAD - Stopwatch loadingTime = new Stopwatch (); - loadingTime.Start (); - #endif - - -// if (typeof(TabView).IsAssignableFrom (items.GetType ())|| -// typeof(Menu).IsAssignableFrom (this.GetType())|| -// typeof(Wrapper).IsAssignableFrom (items.GetType ())) { - //page = items; - itemPerPage = int.MaxValue; -// } else if (typeof(GenericStack).IsAssignableFrom (items.GetType ())) { -// GenericStack gs = new GenericStack (items.CurrentInterface); -// gs.Orientation = (items as GenericStack).Orientation; -// gs.Width = items.Width; -// gs.Height = items.Height; -// gs.VerticalAlignment = items.VerticalAlignment; -// gs.HorizontalAlignment = items.HorizontalAlignment; -// page = gs; -// page.Name = "page" + pageNum; -// isPaged = true; -// } else { -// page = Activator.CreateInstance (items.GetType ()) as Group; -// page.CurrentInterface = items.CurrentInterface; -// page.Initialize (); -// page.Name = "page" + pageNum; -// isPaged = true; -// } - - for (int i = 0; i < _data.Count; i++) { - loadItem (_data[i], page, _dataTest); - if (loadingThread.cancelRequested) - break; - } - -// if (page == items) -// return; -// lock (CurrentInterface.LayoutMutex) -// items.AddChild (page); - - #if DEBUG_LOAD - loadingTime.Stop (); - Debug.WriteLine("Listbox {2} Loading: {0} ticks \t, {1} ms", - loadingTime.ElapsedTicks, - loadingTime.ElapsedMilliseconds, this.ToString()); - #endif - } - string getItempKey(Type dataType, object o, string propertyName){ - try { - return dataType.GetProperty (propertyName).GetGetMethod ().Invoke (o, null)?.ToString(); - } catch { - return dataType.FullName; - } - } - protected void loadItem(object o, Group page, string _dataTest){ - if (o == null)//TODO:surely a threading sync problem - return; - GraphicObject g = null; - ItemTemplate iTemp = null; - Type dataType = o.GetType (); - string itempKey = dataType.FullName; - - if (_dataTest != "TypeOf") - itempKey = getItempKey (dataType, o, _dataTest); - - if (ItemTemplates.ContainsKey (itempKey)) - iTemp = ItemTemplates [itempKey]; - else { - foreach (string it in ItemTemplates.Keys) { - Type t = CompilerServices.tryGetType (it); - if (t == null) - continue; - if (t.IsAssignableFrom (dataType)) {//TODO:types could be cached - iTemp = ItemTemplates [it]; - break; - } - } - if (iTemp == null) - iTemp = ItemTemplates ["default"]; - } - - lock (IFace.LayoutMutex) { - g = iTemp.CreateInstance(); - #if DESIGN_MODE - g.design_isTGItem = true; - #endif - page.AddChild (g); -// if (isPaged) - g.LogicalParent = this; - g.MouseDown += itemClick; - } - - if (iTemp.Expand != null && g is Expandable) { - Expandable e = g as Expandable; - e.Expand += iTemp.Expand; - e.GetIsExpandable = iTemp.HasSubItems; - } - - g.DataSource = o; - } -// protected void _list_LayoutChanged (object sender, LayoutingEventArgs e) -// { -// #if DEBUG_LAYOUTING -// Debug.WriteLine("list_LayoutChanged"); -// #endif -// if (_gsList.Orientation == Orientation.Horizontal) { -// if (e.LayoutType == LayoutingType.Width) -// _gsList.Width = approxSize; -// } else if (e.LayoutType == LayoutingType.Height) -// _gsList.Height = approxSize; -// } - int approxSize - { - get { - if (data == null) - return -1; - GenericStack page1 = items.FindByName ("page1") as GenericStack; - if (page1 == null) - return -1; - - return page1.Orientation == Orientation.Horizontal ? - data.Count < itemPerPage ? - -1: - (int)Math.Ceiling ((double)page1.Slot.Width / (double)itemPerPage * (double)(data.Count+1)): - data.Count < itemPerPage ? - -1: - (int)Math.Ceiling ((double)page1.Slot.Height / (double)itemPerPage * (double)(data.Count+1)); - } - } - internal virtual void itemClick(object sender, MouseButtonEventArgs e){ - SelectedIndex = data.IndexOf((sender as GraphicObject).DataSource); - } - - bool emitHelperIsAlreadyExpanded (GraphicObject go){ - if (nodes.Contains (go)) - return true; - nodes.Add (go); - return false; - } - - protected override void Dispose (bool disposing) - { - if (disposing && loadingThread != null) - loadingThread.Cancel (); - base.Dispose (disposing); - } - } -} diff --git a/src/GraphicObjects/TestCairoPatch.cs b/src/GraphicObjects/TestCairoPatch.cs deleted file mode 100644 index f155d3c0..00000000 --- a/src/GraphicObjects/TestCairoPatch.cs +++ /dev/null @@ -1,148 +0,0 @@ -// -// TestCairoPatch.cs -// -// Author: -// jp <> -// -// 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 Cairo; - -namespace Crow -{ - public class TestCairoPatch : GraphicObject - { - void computeControlPoints ( - double xc, double yc, - double x1, double y1, - out double x2, out double y2, - out double x3, out double y3, - double x4, double y4){ - double ax = x1 - xc; - double ay = y1 - yc; - double bx = x4 - xc; - double byy = y4 - yc; - double q1 = ax * ax + ay * ay; - double q2 = q1 + ax * bx + ay * byy; - double k2 = 4.0/3.0 * (Math.Sqrt(2.0 * q1 * q2) - q2) / (ax * byy - ay * bx); - - - x2 = xc + ax - k2 * ay; - y2 = yc + ay + k2 * ax; - x3 = xc + bx + k2 * byy; - y3 = yc + byy - k2 * bx; - } - protected override void onDraw (Context gr) - { - base.onDraw (gr); - - double radius = 100; - - double pi3 = Math.PI / 3.0; - - MeshPattern mp = new MeshPattern (); - - double x1 = radius,y1 = 0, - x2 = 0, y2 = 0, x3 = 0, y3 = 0, x4 = 0, y4 = 0, - xc = radius,yc = radius; - - double dx = Math.Sin (pi3) * radius; - double dy = Math.Cos (pi3) * radius; - - mp.BeginPatch (); - mp.MoveTo (xc, yc); - mp.LineTo (x1, y1); - x4 = xc + dx; - y4 = yc - dy; - computeControlPoints (xc, yc, x1, y1, out x2, out y2, out x3, out y3, x4, y4); - mp.CurveTo (x2, y2, x3, y3, x4, y4); - - mp.SetCornerColorRGB (0, 1, 1, 1); - mp.SetCornerColorRGB (1, 1, 0, 0); - mp.SetCornerColorRGB (2, 1, 1, 0); - - x1 = x4; - y1 = y4; - y4 = yc + dy; - - computeControlPoints (xc, yc, x1, y1, out x2, out y2, out x3, out y3, x4, y4); - mp.CurveTo (x2, y2, x3, y3, x4, y4); - - mp.SetCornerColorRGB (3, 0, 1, 0); - mp.EndPatch (); - - x1 = x4; - y1 = y4; - x4 = xc; - y4 = yc * 2.0; - - mp.BeginPatch (); - mp.MoveTo (xc, yc); - mp.LineTo (x1, y1); - computeControlPoints (xc, yc, x1, y1, out x2, out y2, out x3, out y3, x4, y4); - mp.CurveTo (x2, y2, x3, y3, x4, y4); - - mp.SetCornerColorRGB (0, 1, 1, 1); - mp.SetCornerColorRGB (1, 0, 1, 0); - mp.SetCornerColorRGB (2, 0, 1, 1); - - x1 = x4; - y1 = y4; - x4 = xc-dx; - y4 = yc+dy; - - computeControlPoints (xc, yc, x1, y1, out x2, out y2, out x3, out y3, x4, y4); - mp.CurveTo (x2, y2, x3, y3, x4, y4); - - mp.SetCornerColorRGB (3, 0, 0, 1); - mp.EndPatch (); - - x1 = x4; - y1 = y4; - y4 = yc - dy; - - mp.BeginPatch (); - mp.MoveTo (xc, yc); - mp.LineTo (x1, y1); - computeControlPoints (xc, yc, x1, y1, out x2, out y2, out x3, out y3, x4, y4); - mp.CurveTo (x2, y2, x3, y3, x4, y4); - - mp.SetCornerColorRGB (0, 1, 1, 1); - mp.SetCornerColorRGB (1, 0, 0, 1); - mp.SetCornerColorRGB (2, 1, 0, 1); - - x1 = x4; - y1 = y4; - x4 = radius; - y4 = 0; - - computeControlPoints (xc, yc, x1, y1, out x2, out y2, out x3, out y3, x4, y4); - mp.CurveTo (x2, y2, x3, y3, x4, y4); - - mp.SetCornerColorRGB (3, 1, 0, 0); - mp.EndPatch (); - - gr.SetSource (mp); - gr.Paint (); - } - } -} - diff --git a/src/GraphicObjects/TextBox.cs b/src/GraphicObjects/TextBox.cs deleted file mode 100644 index e29ff9bf..00000000 --- a/src/GraphicObjects/TextBox.cs +++ /dev/null @@ -1,229 +0,0 @@ -// -// TextBox.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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 Cairo; -using System.Diagnostics; -using System.Xml.Serialization; - -namespace Crow -{ - public class TextBox : Label - { - #region CTOR - protected TextBox() : base(){} - public TextBox(Interface iface) : base(iface) - { } -// public TextBox(string _initialValue) -// : base(_initialValue) -// { -// -// } - #endregion - - #region GraphicObject overrides - [XmlIgnore]public override bool HasFocus //trigger update when lost focus to errase text beam - { - get - { - return base.HasFocus; - } - set - { - base.HasFocus = value; - RegisterForRedraw(); - } - } - - protected override void onDraw (Context gr) - { - base.onDraw (gr); - FontExtents fe = gr.FontExtents; - } - #endregion - - #region Keyboard handling - public override void onKeyDown (object sender, KeyboardKeyEventArgs e) - { - base.onKeyDown (sender, e); - - Key key = e.Key; - - switch (key) - { - case Key.Back: - if (CurrentPosition == 0) - return; - this.DeleteChar(); - break; - case Key.Clear: - break; - case Key.Delete: - if (selectionIsEmpty) { - if (!MoveRight ()) - return; - }else if (e.Shift) - IFace.Clipboard = this.SelectedText; - this.DeleteChar (); - break; - case Key.Enter: - case Key.KeypadEnter: - if (!selectionIsEmpty) - this.DeleteChar (); - if (Multiline) - this.InsertLineBreak (); - else - OnTextChanged(this,new TextChangeEventArgs(Text)); - break; - case Key.Escape: - Text = ""; - CurrentColumn = 0; - SelRelease = -1; - break; - case Key.Home: - if (e.Shift) { - if (selectionIsEmpty) - SelBegin = new Point (CurrentColumn, CurrentLine); - if (e.Control) - CurrentLine = 0; - CurrentColumn = 0; - SelRelease = new Point (CurrentColumn, CurrentLine); - break; - } - SelRelease = -1; - if (e.Control) - CurrentLine = 0; - CurrentColumn = 0; - break; - case Key.End: - if (e.Shift) { - if (selectionIsEmpty) - SelBegin = CurrentPosition; - if (e.Control) - CurrentLine = int.MaxValue; - CurrentColumn = int.MaxValue; - SelRelease = CurrentPosition; - break; - } - SelRelease = -1; - if (e.Control) - CurrentLine = int.MaxValue; - CurrentColumn = int.MaxValue; - break; - case Key.Insert: - if (e.Shift) - this.Insert (IFace.Clipboard); - else if (e.Control && !selectionIsEmpty) - IFace.Clipboard = this.SelectedText; - break; - case Key.Left: - if (e.Shift) { - if (selectionIsEmpty) - SelBegin = new Point(CurrentColumn, CurrentLine); - if (e.Control) - GotoWordStart (); - else if (!MoveLeft ()) - return; - SelRelease = CurrentPosition; - break; - } - SelRelease = -1; - if (e.Control) - GotoWordStart (); - else - MoveLeft(); - break; - case Key.Right: - if (e.Shift) { - if (selectionIsEmpty) - SelBegin = CurrentPosition; - if (e.Control) - GotoWordEnd (); - else if (!MoveRight ()) - return; - SelRelease = CurrentPosition; - break; - } - SelRelease = -1; - if (e.Control) - GotoWordEnd (); - else - MoveRight (); - break; - case Key.Up: - if (e.Shift) { - if (selectionIsEmpty) - SelBegin = CurrentPosition; - CurrentLine--; - SelRelease = CurrentPosition; - break; - } - SelRelease = -1; - CurrentLine--; - break; - case Key.Down: - if (e.Shift) { - if (selectionIsEmpty) - SelBegin = CurrentPosition; - CurrentLine++; - SelRelease = CurrentPosition; - break; - } - SelRelease = -1; - CurrentLine++; - break; - case Key.Menu: - break; - case Key.NumLock: - break; - case Key.PageDown: - break; - case Key.PageUp: - break; - case Key.RWin: - break; - case Key.Tab: - this.Insert ("\t"); - break; - default: - break; - } - RegisterForGraphicUpdate(); - } - public override void onKeyPress (object sender, KeyPressEventArgs e) - { - base.onKeyPress (sender, e); - - this.Insert (e.KeyChar.ToString()); - - SelRelease = -1; - SelBegin = new Point(CurrentColumn, SelBegin.Y); - - RegisterForGraphicUpdate(); - } - #endregion - } -} diff --git a/src/GraphicObjects/TextRun.cs b/src/GraphicObjects/TextRun.cs deleted file mode 100644 index 17e3b770..00000000 --- a/src/GraphicObjects/TextRun.cs +++ /dev/null @@ -1,309 +0,0 @@ -// -// TextRun.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Linq; -using System.Text; -using System.Diagnostics; -using Cairo; -using System.Text.RegularExpressions; -using System.Xml.Serialization; -using System.ComponentModel; - -namespace Crow -{ - [DesignIgnore] - public class TextRun : GraphicObject - { - #region CTOR - protected TextRun () : base(){} - public TextRun (Interface iface) : base (iface){} - #endregion - - //TODO:change protected to private - - #region private and protected fields - protected string _text = "label"; - Alignment _textAlignment = Alignment.Left; - bool horizontalStretch = false; - bool verticalStretch = false; - bool _multiline; - bool wordWrap; - protected Rectangle rText; - protected float widthRatio = 1f; - protected float heightRatio = 1f; - protected FontExtents fe; - protected TextExtents te; - #endregion - - - [XmlAttributeAttribute ()] - [DefaultValue (Alignment.Left)] - public Alignment TextAlignment { - get { return _textAlignment; } - set { _textAlignment = value; } - } - [XmlAttributeAttribute ()] - [DefaultValue (false)] - public virtual bool HorizontalStretch { - get { return horizontalStretch; } - set { - if (horizontalStretch == value) - return; - horizontalStretch = value; - RegisterForRedraw (); - NotifyValueChanged ("HorizontalStretch", horizontalStretch); - } - } - [XmlAttributeAttribute ()] - [DefaultValue (false)] - public virtual bool VerticalStretch { - get { return verticalStretch; } - set { - if (verticalStretch == value) - return; - verticalStretch = value; - RegisterForRedraw (); - NotifyValueChanged ("VerticalStretch", verticalStretch); - } - } - [XmlAttributeAttribute ()] - [DefaultValue ("label")] - public string Text { - get { - return lines == null ? - _text : lines.Aggregate ((i, j) => i + Interface.LineBreak + j); - } - set { - if (_text == value) - return; - - RegisterForGraphicUpdate (); - - _text = value; - - if (string.IsNullOrEmpty (_text)) - _text = ""; - - lines = getLines; - } - } - [XmlAttributeAttribute ()] - [DefaultValue (false)] - public bool Multiline { - get { return _multiline; } - set { - _multiline = value; - RegisterForGraphicUpdate (); - } - } - [XmlAttributeAttribute ()] - [DefaultValue (false)] - public bool WordWrap { - get { - return wordWrap; - } - set { - if (wordWrap == value) - return; - wordWrap = value; - RegisterForGraphicUpdate (); - } - } - - List<string> lines; - List<string> getLines { - get { - return _multiline ? - Regex.Split (_text, "\r\n|\r|\n").ToList () : - new List<string> (new string [] { _text }); - } - } - - #region GraphicObject overrides - protected override int measureRawSize (LayoutingType lt) - { - if (lines == null) - lines = getLines; - - using (ImageSurface img = new ImageSurface (Format.Argb32, 10, 10)) { - using (Context gr = new Context (img)) { - //Cairo.FontFace cf = gr.GetContextFontFace (); - - gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight); - gr.SetFontSize (Font.Size); - - - fe = gr.FontExtents; - te = new TextExtents (); - - if (lt == LayoutingType.Height) { - int lc = lines.Count; - //ensure minimal height = text line height - if (lc == 0) - lc = 1; - - return (int)(fe.Height * lc) + Margin * 2; - } - - foreach (string s in lines) { - string l = s.Replace("\t", new String (' ', Interface.TabSize)); - TextExtents tmp = gr.TextExtents (l); - if (tmp.XAdvance > te.XAdvance) - te = tmp; - } - return (int)Math.Ceiling (te.XAdvance) + Margin * 2; - } - } - } - protected override void onDraw (Context gr) - { - base.onDraw (gr); - - gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight); - gr.SetFontSize (Font.Size); - gr.FontOptions = Interface.FontRenderingOptions; - gr.Antialias = Interface.Antialias; - - rText = new Rectangle (new Size ( - measureRawSize (LayoutingType.Width), measureRawSize (LayoutingType.Height))); - rText.Width -= 2 * Margin; - rText.Height -= 2 * Margin; - - widthRatio = 1f; - heightRatio = 1f; - - Rectangle cb = ClientRectangle; - - //ignore text alignment if size to content = true - //or if text size is larger than client bounds - if (Width < 0 || Height < 0 || rText.Width > cb.Width) { - rText.X = cb.X; - rText.Y = cb.Y; - } else { - if (horizontalStretch) { - widthRatio = (float)cb.Width / rText.Width; - if (!verticalStretch) - heightRatio = widthRatio; - } - if (verticalStretch) { - heightRatio = (float)cb.Height / rText.Height; - if (!horizontalStretch) - widthRatio = heightRatio; - } - - rText.Width = (int)(widthRatio * cb.Width); - rText.Height = (int)(heightRatio * cb.Height); - - switch (TextAlignment) { - case Alignment.TopLeft: //ok - rText.X = cb.X; - rText.Y = cb.Y; - break; - case Alignment.Top: //ok - rText.Y = cb.Y; - rText.X = cb.X + cb.Width / 2 - rText.Width / 2; - break; - case Alignment.TopRight: //ok - rText.Y = cb.Y; - rText.X = cb.Right - rText.Width; - break; - case Alignment.Left://ok - rText.X = cb.X; - rText.Y = cb.Y + cb.Height / 2 - rText.Height / 2; - break; - case Alignment.Right://ok - rText.X = cb.X + cb.Width - rText.Width; - rText.Y = cb.Y + cb.Height / 2 - rText.Height / 2; - break; - case Alignment.Bottom://ok - rText.X = cb.Width / 2 - rText.Width / 2; - rText.Y = cb.Height - rText.Height; - break; - case Alignment.BottomLeft://ok - rText.X = cb.X; - rText.Y = cb.Bottom - rText.Height; - break; - case Alignment.BottomRight://ok - rText.Y = cb.Bottom - rText.Height; - rText.X = cb.Right - rText.Width; - break; - case Alignment.Center://ok - rText.X = cb.X + cb.Width / 2 - rText.Width / 2; - rText.Y = cb.Y + cb.Height / 2 - rText.Height / 2; - break; - } - } - - gr.FontMatrix = new Matrix (widthRatio * Font.Size, 0, 0, heightRatio * Font.Size, 0, 0); - - - int curLineCount = 0; - for (int i = 0; i < lines.Count; i++) { - string l = lines [i].Replace ("\t", new String (' ', Interface.TabSize)); - List<string> wl = new List<string> (); - int lineLength = (int)gr.TextExtents (l).XAdvance; - - if (wordWrap && lineLength > cb.Width) { - string tmpLine = ""; - int curChar = 0; - while (curChar < l.Length) { - tmpLine += l [curChar]; - if ((int)gr.TextExtents (tmpLine).XAdvance > cb.Width) { - tmpLine = tmpLine.Remove (tmpLine.Length - 1); - wl.Add (tmpLine); - tmpLine = ""; - continue; - } - curChar++; - } - wl.Add (tmpLine); - } else - wl.Add (l); - - foreach (string ll in wl) { - lineLength = (int)gr.TextExtents (ll).XAdvance; - - - if (string.IsNullOrWhiteSpace (ll)) { - curLineCount++; - continue; - } - - Foreground.SetAsSource (gr); - gr.MoveTo (rText.X, rText.Y + fe.Ascent + fe.Height * curLineCount); - - gr.ShowText (ll); - gr.Fill (); - - curLineCount++; - } - } - } - #endregion - } -} diff --git a/src/GraphicObjects/TreeView.cs b/src/GraphicObjects/TreeView.cs deleted file mode 100644 index 2c3f817f..00000000 --- a/src/GraphicObjects/TreeView.cs +++ /dev/null @@ -1,108 +0,0 @@ -// -// TreeView.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Xml.Serialization; -using System.Diagnostics; -using System.ComponentModel; - -namespace Crow -{ - //treeview expect expandable child (or not) - //if their are expandable, some functions and events are added - public class TreeView : TemplatedGroup - { - GraphicObject selectedItemContainer = null; - bool isRoot; - - #region CTOR - protected TreeView() : base(){} - public TreeView (Interface iface) : base(iface) - { - } - #endregion - - [XmlAttributeAttribute()][DefaultValue(false)] - public virtual bool IsRoot { - get { return isRoot; } - set { - if (isRoot == value) - return; - isRoot = value; - NotifyValueChanged ("IsRoot", isRoot); - } - } - [XmlIgnore]public override object SelectedItem { - get { - return selectedItemContainer == null ? - "" : selectedItemContainer.DataSource; - } - } - - internal override void itemClick (object sender, MouseButtonEventArgs e) - { - GraphicObject tmp = sender as GraphicObject; - if (!tmp.HasFocus) - return; - if (selectedItemContainer != null) { - selectedItemContainer.Foreground = Color.Transparent; - selectedItemContainer.Background = Color.Transparent; - } - selectedItemContainer = tmp; - selectedItemContainer.Foreground = SelectionForeground; - selectedItemContainer.Background = SelectionBackground; - NotifyValueChanged ("SelectedItem", SelectedItem); - raiseSelectedItemChanged (); - } - - void onExpandAll_MouseClick (object sender, MouseButtonEventArgs e) - { - ExpandAll (); - } - - public void ExpandAll(){ - foreach (Group grp in items.Children) { - foreach (GraphicObject go in grp.Children) { - Expandable exp = go as Expandable; - if (exp == null) - continue; - TreeView subTV = exp.FindByName ("List") as TreeView; - if (subTV == null) - continue; - EventHandler handler = null; - handler = delegate(object sender, EventArgs e) { - TreeView tv = sender as TreeView; - tv.Loaded -= handler; - tv.ExpandAll (); - }; - subTV.Loaded += handler; - exp.IsExpanded = true; - } - } - } - } -} - diff --git a/src/GraphicObjects/Trend.cs b/src/GraphicObjects/Trend.cs deleted file mode 100644 index e9d3c2d3..00000000 --- a/src/GraphicObjects/Trend.cs +++ /dev/null @@ -1,189 +0,0 @@ -// -// Trend.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Xml.Serialization; -using System.ComponentModel; -using Cairo; - -namespace Crow -{ - public class Trend : GraphicObject - { - #region private fields - double minValue, maxValue, lowThreshold, highThreshold; - Fill lowThresholdFill, highThresholdFill; - int nbValues; - List<double> values = new List<double>(); - #endregion - - - - public virtual void AddValue(double _value) - { - values.Add (_value); - while (values.Count > nbValues) - values.RemoveAt (0); - RegisterForRedraw (); - } - #region CTOR - protected Trend () : base() - { - } - #endregion - [XmlIgnore]public virtual int NewValue { - set { - AddValue (value); - } - } - [XmlAttributeAttribute()][DefaultValue(100)] - public virtual int NbValues { - get { return nbValues; } - set { - if (nbValues == value) - return; - - nbValues = value; - NotifyValueChanged ("NbValues", minValue); - RegisterForRedraw (); - } - } - [XmlAttributeAttribute()][DefaultValue(0.0)] - public virtual double Minimum { - get { return minValue; } - set { - if (minValue == value) - return; - - minValue = value; - NotifyValueChanged ("Minimum", minValue); - RegisterForRedraw (); - } - } - [XmlAttributeAttribute()][DefaultValue(100.0)] - public virtual double Maximum - { - get { return maxValue; } - set { - if (maxValue == value) - return; - - maxValue = value; - NotifyValueChanged ("Maximum", maxValue); - RegisterForRedraw (); - } - } - [XmlAttributeAttribute()][DefaultValue(20.0)] - public virtual double LowThreshold { - get { return lowThreshold; } - set { - if (lowThreshold == value) - return; - lowThreshold = value; - NotifyValueChanged ("LowThreshold", lowThreshold); - RegisterForGraphicUpdate (); - } - } - [XmlAttributeAttribute()][DefaultValue(80.0)] - public virtual double HighThreshold { - get { return highThreshold; } - set { - if (highThreshold == value) - return; - highThreshold = value; - NotifyValueChanged ("HighThreshold", highThreshold); - RegisterForGraphicUpdate (); - } - } - [XmlAttributeAttribute()][DefaultValue("DarkRed")] - public virtual Fill LowThresholdFill { - get { return lowThresholdFill; } - set { - if (lowThresholdFill == value) - return; - lowThresholdFill = value; - NotifyValueChanged ("LowThresholdFill", lowThresholdFill); - RegisterForRedraw (); - } - } - [XmlAttributeAttribute()][DefaultValue("DarkGreen")] - public virtual Fill HighThresholdFill { - get { return highThresholdFill; } - set { - if (highThresholdFill == value) - return; - highThresholdFill = value; - NotifyValueChanged ("HighThresholdFill", highThresholdFill); - RegisterForRedraw (); - } - } - protected override void onDraw (Context gr) - { - base.onDraw (gr); - - if (values.Count == 0) - return; - Rectangle r = ClientRectangle; - - int i = values.Count -1; - - double ptrX = (double)r.Right; - double scaleY = (double)r.Height / (Maximum - Minimum); - double stepX = (double)r.Width / (double)(nbValues-1); - - gr.LineWidth = 1.0; - gr.SetDash (new double[]{ 1.0 },0.0); - - - - LowThresholdFill.SetAsSource (gr); - gr.MoveTo (r.Left, r.Bottom - LowThreshold * scaleY); - gr.LineTo (r.Right, r.Bottom - LowThreshold * scaleY); -// gr.Rectangle (r.Left, r.Bottom - LowThreshold * scaleY, r.Width, LowThreshold * scaleY); - gr.Stroke(); - - HighThresholdFill.SetAsSource (gr); - gr.MoveTo (r.Left, (Maximum - HighThreshold) * scaleY); - gr.LineTo (r.Right, (Maximum - HighThreshold) * scaleY); -// gr.Rectangle (r.Left, r.Top, r.Width, (Maximum - HighThreshold) * scaleY); - gr.Stroke(); - - gr.MoveTo (ptrX, values [i] * scaleY); - - Foreground.SetAsSource (gr); - gr.SetDash (new double[]{ }, 0.0); - - while (i >= 0) { - gr.LineTo (ptrX, r.Bottom - values [i] * scaleY); - ptrX -= stepX; - i--; - } - gr.Stroke (); - } - } -} - diff --git a/src/GraphicObjects/VerticalStack.cs b/src/GraphicObjects/VerticalStack.cs deleted file mode 100644 index 9650e685..00000000 --- a/src/GraphicObjects/VerticalStack.cs +++ /dev/null @@ -1,54 +0,0 @@ -// -// VerticalStack.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Linq; -using System.Text; - -namespace Crow -{ - /// <summary> - /// group control stacking its children vertically - /// </summary> - public class VerticalStack : GenericStack - { - #region CTOR - protected VerticalStack() : base(){} - public VerticalStack(Interface iface) : base(iface) - { - } - #endregion - - [System.Xml.Serialization.XmlIgnore] - public override Orientation Orientation - { - get { return Orientation.Vertical; } - } - - - } -} diff --git a/src/GraphicObjects/Window.cs b/src/GraphicObjects/Window.cs deleted file mode 100644 index 56632ff3..00000000 --- a/src/GraphicObjects/Window.cs +++ /dev/null @@ -1,466 +0,0 @@ -// -// Window.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Xml.Serialization; -using System.ComponentModel; -using System.Diagnostics; - -namespace Crow -{ - public class Window : TemplatedContainer - { - public enum Direction - { - None, - N, - S, - E, - W, - NW, - NE, - SW, - SE, - } - - string _icon; - bool resizable; - bool movable; - bool modal; - protected bool hoverBorder = false; - bool alwaysOnTop = false; - Fill titleBarBackground = Color.SteelBlue; - Fill titleBarForeground = Color.White; - - Rectangle savedBounds; - bool _minimized = false; - - Direction currentDirection = Direction.None; - - #region Events - public event EventHandler Closing; - public event EventHandler Maximized; - public event EventHandler Unmaximized; - public event EventHandler Minimize; - #endregion - - #region CTOR - protected Window() : base(){} - public Window (Interface iface) : base(iface){} - #endregion - - #region TemplatedContainer overrides - protected override void loadTemplate(GraphicObject template = null) - { - base.loadTemplate (template); - - NotifyValueChanged ("ShowNormal", false); - NotifyValueChanged ("ShowMinimize", true); - NotifyValueChanged ("ShowMaximize", true); - } - #endregion - - #region public properties - [XmlAttributeAttribute][DefaultValue("#Crow.Images.Icons.crow.png")] - public string Icon { - get { return _icon; } - set { - if (_icon == value) - return; - _icon = value; - NotifyValueChanged ("Icon", _icon); - } - } - /// <summary> - /// Background of the title bar if any. - /// </summary> - [XmlAttributeAttribute][DefaultValue("vgradient|0:Onyx|1:SteelBlue")] - public virtual Fill TitleBarBackground { - get { return titleBarBackground; } - set { - if (titleBarBackground == value) - return; - titleBarBackground = value; - NotifyValueChanged ("TitleBarBackground", titleBarBackground); - RegisterForRedraw (); - } - } - /// <summary> - /// Foreground of the title bar, usualy used for the window caption color. - /// </summary> - [XmlAttributeAttribute][DefaultValue("White")] - public virtual Fill TitleBarForeground { - get { return titleBarForeground; } - set { - if (titleBarForeground == value) - return; - titleBarForeground = value; - NotifyValueChanged ("TitleBarForeground", titleBarForeground); - RegisterForRedraw (); - } - } - [XmlAttributeAttribute][DefaultValue(true)] - public bool Resizable { - get { - return resizable; - } - set { - if (resizable == value) - return; - resizable = value; - NotifyValueChanged ("Resizable", resizable); - } - } - [XmlAttributeAttribute][DefaultValue(true)] - public bool Movable { - get { - return movable; - } - set { - if (movable == value) - return; - movable = value; - NotifyValueChanged ("Movable", movable); - } - } - [XmlAttributeAttribute][DefaultValue(false)] - public bool Modal { - get { - return modal; - } - set { - if (modal == value) - return; - modal = value; - NotifyValueChanged ("Modal", modal); - } - } - [XmlAttributeAttribute][DefaultValue(false)] - public bool IsMinimized { - get { return _minimized; } - set{ - if (value == IsMinimized) - return; - - _minimized = value; - _contentContainer.Visible = !_minimized; - - NotifyValueChanged ("IsMinimized", _minimized); - } - } - [XmlIgnore]public bool IsMaximized { - get { return Width == Measure.Stretched & Height == Measure.Stretched & !_minimized; } - } - [XmlIgnore]public bool IsNormal { - get { return !(IsMaximized|_minimized); } - } - [XmlAttributeAttribute][DefaultValue(false)] - public bool AlwaysOnTop { - get { - return modal ? true : alwaysOnTop; - } - set { - if (alwaysOnTop == value) - return; - - alwaysOnTop = value; - - if (AlwaysOnTop && Parent != null) - IFace.PutOnTop (this); - - NotifyValueChanged ("AlwaysOnTop", AlwaysOnTop); - } - } -// [XmlAttributeAttribute()][DefaultValue(WindowState.Normal)] -// public virtual WindowState State { -// get { return _state; } -// set { -// if (_state == value) -// return; -// _state = value; -// NotifyValueChanged ("State", _state); -// NotifyValueChanged ("IsNormal", IsNormal); -// NotifyValueChanged ("IsMaximized", IsMaximized); -// NotifyValueChanged ("IsMinimized", IsMinimized); -// NotifyValueChanged ("IsNotMinimized", IsNotMinimized); -// } -// } - #endregion - - /// <summary> - /// Moves the and resize with the same function entry point, the direction give the kind of move or resize - /// </summary> - /// <param name="XDelta">mouse delta on the X axis</param> - /// <param name="YDelta">mouse delta on the Y axis</param> - /// <param name="currentDirection">Current Direction of the operation, none for moving, other value for resizing in the given direction</param> - public void MoveAndResize (int XDelta, int YDelta, Direction currentDirection = (Direction)0) { - int currentLeft = this.Left; - int currentTop = this.Top; - int currentWidth, currentHeight; - - if (currentLeft == 0) { - currentLeft = this.Slot.Left; - this.Left = currentLeft; - } - if (currentTop == 0) { - currentTop = this.Slot.Top; - this.Top = currentTop; - } - if (this.Width.IsFixed) - currentWidth = this.Width; - else - currentWidth = this.Slot.Width; - - if (this.Height.IsFixed) - currentHeight = this.Height; - else - currentHeight = this.Slot.Height; - - switch (currentDirection) { - case Direction.None: - this.Left = currentLeft + XDelta; - this.Top = currentTop + YDelta; - break; - case Direction.N: - this.Height = currentHeight - YDelta; - if (this.Height == currentHeight - YDelta) - this.Top = currentTop + YDelta; - break; - case Direction.S: - this.Height = currentHeight + YDelta; - break; - case Direction.W: - this.Width = currentWidth - XDelta; - if (this.Width == currentWidth - XDelta) - this.Left = currentLeft + XDelta; - break; - case Direction.E: - this.Width = currentWidth + XDelta; - break; - case Direction.NW: - this.Height = currentHeight - YDelta; - if (this.Height == currentHeight - YDelta) - this.Top = currentTop + YDelta; - this.Width = currentWidth - XDelta; - if (this.Width == currentWidth - XDelta) - this.Left = currentLeft + XDelta; - break; - case Direction.NE: - this.Height = currentHeight - YDelta; - if (this.Height == currentHeight - YDelta) - this.Top = currentTop + YDelta; - this.Width = currentWidth + XDelta; - break; - case Direction.SW: - this.Width = currentWidth - XDelta; - if (this.Width == currentWidth - XDelta) - this.Left = currentLeft + XDelta; - this.Height = currentHeight + YDelta; - break; - case Direction.SE: - this.Height = currentHeight + YDelta; - this.Width = currentWidth + XDelta; - break; - } - } - - #region GraphicObject Overrides - public override void onMouseMove (object sender, MouseMoveEventArgs e) - { - base.onMouseMove (sender, e); - - Interface otkgw = IFace; - - if (!hoverBorder) { - currentDirection = Direction.None; - IFace.MouseCursor = XCursor.Default; - return; - } - - if (this.HasFocus && movable) { - if (e.Mouse.IsButtonDown (MouseButton.Left)) { - MoveAndResize (e.XDelta, e.YDelta, currentDirection); - return; - } - } - if (Resizable) { - Direction lastDir = currentDirection; - - if (Math.Abs (e.Position.Y - this.Slot.Y) < Interface.BorderThreshold) { - if (Math.Abs (e.Position.X - this.Slot.X) < Interface.BorderThreshold) - currentDirection = Direction.NW; - else if (Math.Abs (e.Position.X - this.Slot.Right) < Interface.BorderThreshold) - currentDirection = Direction.NE; - else - currentDirection = Direction.N; - } else if (Math.Abs (e.Position.Y - this.Slot.Bottom) < Interface.BorderThreshold) { - if (Math.Abs (e.Position.X - this.Slot.X) < Interface.BorderThreshold) - currentDirection = Direction.SW; - else if (Math.Abs (e.Position.X - this.Slot.Right) < Interface.BorderThreshold) - currentDirection = Direction.SE; - else - currentDirection = Direction.S; - } else if (Math.Abs (e.Position.X - this.Slot.X) < Interface.BorderThreshold) - currentDirection = Direction.W; - else if (Math.Abs (e.Position.X - this.Slot.Right) < Interface.BorderThreshold) - currentDirection = Direction.E; - else - currentDirection = Direction.None; - - if (currentDirection != lastDir) { - switch (currentDirection) { - case Direction.None: - otkgw.MouseCursor = XCursor.Default; - break; - case Direction.N: - otkgw.MouseCursor = XCursor.V; - break; - case Direction.S: - otkgw.MouseCursor = XCursor.V; - break; - case Direction.E: - otkgw.MouseCursor = XCursor.H; - break; - case Direction.W: - otkgw.MouseCursor = XCursor.H; - break; - case Direction.NW: - otkgw.MouseCursor = XCursor.NW; - break; - case Direction.NE: - otkgw.MouseCursor = XCursor.NE; - break; - case Direction.SW: - otkgw.MouseCursor = XCursor.SW; - break; - case Direction.SE: - otkgw.MouseCursor = XCursor.SE; - break; - } - } - } - } - public override void onMouseDown (object sender, MouseButtonEventArgs e) - { - base.onMouseDown (sender, e); - } - public override bool MouseIsIn (Point m) - { - return modal ? true : base.MouseIsIn (m); - } - #endregion - - protected void onMaximized (object sender, EventArgs e){ - lock (IFace.LayoutMutex) { - if (!IsMinimized) - savedBounds = this.LastPaintedSlot; - this.Left = this.Top = 0; - this.RegisterForLayouting (LayoutingType.Positioning); - this.Width = this.Height = Measure.Stretched; - IsMinimized = false; - Resizable = false; - NotifyValueChanged ("ShowNormal", true); - NotifyValueChanged ("ShowMinimize", true); - NotifyValueChanged ("ShowMaximize", false); - } - - Maximized.Raise (sender, e); - } - protected void onUnmaximized (object sender, EventArgs e){ - lock (IFace.LayoutMutex) { - this.Left = savedBounds.Left; - this.Top = savedBounds.Top; - this.Width = savedBounds.Width; - this.Height = savedBounds.Height; - IsMinimized = false; - Resizable = true; - NotifyValueChanged ("ShowNormal", false); - NotifyValueChanged ("ShowMinimize", true); - NotifyValueChanged ("ShowMaximize", true); - } - - Unmaximized.Raise (sender, e); - } - protected void onMinimized (object sender, EventArgs e){ - lock (IFace.LayoutMutex) { - if (IsNormal) - savedBounds = this.LastPaintedSlot; - Width = 200; - Height = 20; - Resizable = false; - IsMinimized = true; - NotifyValueChanged ("ShowNormal", true); - NotifyValueChanged ("ShowMinimize", false); - NotifyValueChanged ("ShowMaximize", true); - } - - Minimize.Raise (sender, e); - } - protected virtual void onBorderMouseLeave (object sender, MouseMoveEventArgs e) - { - hoverBorder = false; - currentDirection = Direction.None; - IFace.MouseCursor = XCursor.Default; - } - protected virtual void onBorderMouseEnter (object sender, MouseMoveEventArgs e) - { - hoverBorder = true; - } - - - protected void butQuitPress (object sender, MouseButtonEventArgs e) - { - IFace.MouseCursor = XCursor.Default; - close (); - } - - protected virtual void close(){ - Closing.Raise (this, null); - if (Parent is Interface) - (Parent as Interface).DeleteWidget (this); - else { - GraphicObject p = Parent as GraphicObject; - if (p is Group) { - lock (IFace.UpdateMutex) { - RegisterClip (p.ScreenCoordinates (p.LastPaintedSlot)); - (p as Group).DeleteChild (this); - } - //(Parent as Group).RegisterForRedraw (); - } else if (Parent is PrivateContainer) - (Parent as Container).Child = null; - } - } - - public static Window Show (Interface iface, string imlPath, bool modal = false){ - lock (iface.UpdateMutex) { - Window w = iface.AddWidget (imlPath) as Window; - w.Modal = modal; - return w; - } - } - } -} - diff --git a/src/GraphicObjects/Wrapper.cs b/src/GraphicObjects/Wrapper.cs deleted file mode 100644 index a7f5f73b..00000000 --- a/src/GraphicObjects/Wrapper.cs +++ /dev/null @@ -1,251 +0,0 @@ -// -// Wrapper.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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; - -namespace Crow -{ - /// <summary> - /// group control that arrange its children in a direction and jump to - /// the next line or row when no room is left - /// </summary> - public class Wrapper : GenericStack - { - #region CTOR - protected Wrapper() : base(){} - public Wrapper (Interface iface) : base(iface){} - #endregion - - #region Group Overrides - public override void ChildrenLayoutingConstraints (ref LayoutingType layoutType) - { - layoutType &= (~LayoutingType.Positioning); - } - public override void ComputeChildrenPositions() - { - int dx = 0; - int dy = 0; - - if (Orientation == Orientation.Vertical) { - int tallestChild = 0; - foreach (GraphicObject c in Children) { - if (!c.Visible) - continue; - if (dx + c.Slot.Width > ClientRectangle.Width) { - dx = 0; - dy += tallestChild + Spacing; - c.Slot.X = dx; - c.Slot.Y = dy; - tallestChild = c.Slot.Height; - } else { - if (tallestChild < c.Slot.Height) - tallestChild = c.Slot.Height; - c.Slot.X = dx; - c.Slot.Y = dy; - } - dx += c.Slot.Width + Spacing; - } - } else { - int largestChild = 0; - foreach (GraphicObject c in Children) { - if (!c.Visible) - continue; - if (dy + c.Slot.Height > ClientRectangle.Height) { - dy = 0; - dx += largestChild + Spacing; - c.Slot.X = dx; - c.Slot.Y = dy; - largestChild = c.Slot.Width; - } else { - if (largestChild < c.Slot.Width) - largestChild = c.Slot.Width; - c.Slot.X = dx; - c.Slot.Y = dy; - } - dy += c.Slot.Height + Spacing; - } - } - IsDirty = true; - } - public override void OnChildLayoutChanges (object sender, LayoutingEventArgs arg) - { - //children can't stretch in a wrapper - GraphicObject go = sender as GraphicObject; - //System.Diagnostics.Debug.WriteLine ("wrapper child layout change: " + go.LastSlots.ToString() + " => " + go.Slot.ToString()); - switch (arg.LayoutType) { - case LayoutingType.Width: - if (Orientation == Orientation.Horizontal && go.Width.Units == Unit.Percent){ - go.Width = Measure.Fit; - return; - } - this.RegisterForLayouting (LayoutingType.Width); - break; - case LayoutingType.Height: - if (Orientation == Orientation.Vertical && go.Height.IsRelativeToParent) { - go.Height = Measure.Fit; - return; - } - this.RegisterForLayouting (LayoutingType.Height); - break; - default: - return; - } - this.RegisterForLayouting (LayoutingType.ArrangeChildren); - } - #endregion - - #region GraphicObject Overrides - protected override int measureRawSize (LayoutingType lt) - { - int tmp = 0; - //Wrapper can't fit in the opposite direction of the wrapper, this func is called only if Fit - if (lt == LayoutingType.Width) { - if (Orientation == Orientation.Vertical) { - Width = Measure.Stretched; - return -1; - } else if (RegisteredLayoutings.HasFlag (LayoutingType.Height)) - return -1; - else { - int dy = 0; - int largestChild = 0; - - childrenRWLock.EnterReadLock(); - - foreach (GraphicObject c in Children) { - if (!c.Visible) - continue; - if (c.Height.IsRelativeToParent && - c.RegisteredLayoutings.HasFlag (LayoutingType.Height)) { - childrenRWLock.ExitReadLock(); - return -1; - } - if (dy + c.Slot.Height > ClientRectangle.Height) { - dy = 0; - tmp += largestChild + Spacing; - largestChild = c.Slot.Width; - } else if (largestChild < c.Slot.Width) - largestChild = c.Slot.Width; - - dy += c.Slot.Height + Spacing; - } - - childrenRWLock.ExitReadLock (); - - if (dy == 0) - tmp -= Spacing; - return tmp + largestChild + 2 * Margin; - } - } else if (Orientation == Orientation.Horizontal) { - Height = Measure.Stretched; - return -1; - } else if (RegisteredLayoutings.HasFlag (LayoutingType.Width)) - return -1; - else { - int dx = 0; - int tallestChild = 0; - - childrenRWLock.EnterReadLock(); - - foreach (GraphicObject c in Children) { - if (!c.Visible) - continue; - if (c.Width.IsRelativeToParent && - c.RegisteredLayoutings.HasFlag (LayoutingType.Width)) { - childrenRWLock.ExitReadLock(); - return -1; - } - if (dx + c.Slot.Width > ClientRectangle.Width) { - dx = 0; - tmp += tallestChild + Spacing; - tallestChild = c.Slot.Height; - } else if (tallestChild < c.Slot.Height) - tallestChild = c.Slot.Height; - - dx += c.Slot.Width + Spacing; - } - - childrenRWLock.ExitReadLock(); - - if (dx == 0) - tmp -= Spacing; - return tmp + tallestChild + 2 * Margin; - } - } - - public override bool UpdateLayout (LayoutingType layoutType) - { - RegisteredLayoutings &= (~layoutType); - - if (layoutType == LayoutingType.ArrangeChildren) { - if ((RegisteredLayoutings & LayoutingType.Sizing) != 0) - return false; - - ComputeChildrenPositions (); - - //if no layouting remains in queue for item, registre for redraw - if (RegisteredLayoutings == LayoutingType.None && IsDirty) - IFace.EnqueueForRepaint (this); - - return true; - } - - return base.UpdateLayout(layoutType); - } - public override void OnLayoutChanges (LayoutingType layoutType) - { - #if DEBUG_LAYOUTING - IFace.currentLQI.Slot = LastSlots; - IFace.currentLQI.Slot = Slot; - #endif - switch (layoutType) { - case LayoutingType.Width: - foreach (GraphicObject c in Children) { - if (c.Width.IsRelativeToParent) - c.RegisterForLayouting (LayoutingType.Width); - } - if (Height == Measure.Fit) - RegisterForLayouting (LayoutingType.Height); - RegisterForLayouting (LayoutingType.X); - break; - case LayoutingType.Height: - foreach (GraphicObject c in Children) { - if (c.Height.IsRelativeToParent) - c.RegisterForLayouting (LayoutingType.Height); - } - if (Width == Measure.Fit) - RegisterForLayouting (LayoutingType.Width); - RegisterForLayouting (LayoutingType.Y); - break; - default: - return; - } - RegisterForLayouting (LayoutingType.ArrangeChildren); - raiseLayoutChanged (new LayoutingEventArgs (layoutType)); - } - #endregion - } -} - diff --git a/src/IListChanged.cs b/src/IListChanged.cs deleted file mode 100644 index b2b23375..00000000 --- a/src/IListChanged.cs +++ /dev/null @@ -1,43 +0,0 @@ -// -// IListChanged.cs -// -// Author: -// Jean-Philippe Bruyère <jp_bruyere@hotmail.com> -// -// 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; - -namespace Crow -{ - public class ListChangedEventArg : EventArgs { - public int Index; - public object Element; - public ListChangedEventArg (int index, object element) { - Index = index; - Element = element; - } - } - public interface IObservableList { - event EventHandler<ListChangedEventArg> ListAdd; - event EventHandler<ListChangedEventArg> ListRemove; - } -} - diff --git a/src/IML/BindingDefinition.cs b/src/IML/BindingDefinition.cs deleted file mode 100644 index 075b80b3..00000000 --- a/src/IML/BindingDefinition.cs +++ /dev/null @@ -1,90 +0,0 @@ -// -// BindingDefinition.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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; - -namespace Crow.IML -{ - /// <summary> - /// store binding source and target addresses and member names - /// </summary> - public class BindingDefinition - { - public NodeAddress SourceNA = null; - public string SourceMember = ""; - public NodeAddress TargetNA = null; - public string TargetMember = ""; - public string TargetName = ""; - public bool TwoWay = false; - - #region CTOR - public BindingDefinition (NodeAddress _sourceNA, string _sourceMember){ - SourceNA = _sourceNA; - SourceMember = _sourceMember; - } - public BindingDefinition (NodeAddress _sourceNA, string _sourceMember, NodeAddress _targetNA, string _targetMember, string _targetName = "", bool _twoWay = false) - { - SourceNA = _sourceNA; - SourceMember = _sourceMember; - TargetNA = _targetNA; - TargetMember = _targetMember; - TargetName = _targetName; - TwoWay = _twoWay; - } - #endregion - - public bool IsDataSourceBinding { get { return TargetNA == null; }} - public bool IsTemplateBinding { get { return IsDataSourceBinding ? false : TargetNA.Count == 0; }} - public bool HasUnresolvedTargetName { get { return !string.IsNullOrEmpty(TargetName); }} - public MemberAddress SourceMemberAddress { get { return new MemberAddress (SourceNA, SourceMember);}} - public MemberAddress TargetMemberAddress { get { return new MemberAddress (TargetNA, TargetMember);}} - - /// <summary> - /// replace the target node address with corresponding named node address, and clear the target name once resolved - /// </summary> - /// <param name="newTargetNA">Named Node</param> - public void ResolveTargetName(NodeAddress newTargetNA){ - TargetNA = newTargetNA; - TargetName = ""; - } - - public override string ToString () - { - string tmp = string.Format ("Source:{0}.{1}", SourceNA, SourceMember); - if (TwoWay) - tmp += " <=> "; - else - tmp += " <= "; - - if (string.IsNullOrEmpty (TargetName)) - tmp += string.Format ("Target:{0}.{1}]", TargetNA, TargetMember); - else - tmp += string.Format ("Target:{0}.{1}.{2}]", TargetNA, TargetName, TargetMember); - return tmp; - } - } -} - diff --git a/src/IML/BindingMember.cs b/src/IML/BindingMember.cs deleted file mode 100644 index 4a2b2c61..00000000 --- a/src/IML/BindingMember.cs +++ /dev/null @@ -1,191 +0,0 @@ -// -// BindingMember.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Reflection.Emit; - -namespace Crow.IML -{ - /// <summary> - /// Binding expression parser. - /// - /// Valid tokens in binding expression: - /// - '../' => 1 level up in graphic tree - /// - './' or '/' => template root level - /// - '.Name1.Name2' current level properties - /// - 'name.prop' named descendant in graphic tree, search with 'FindByName' method of GraphicObject - /// </summary> - public class BindingMember - { - /// <summary> - /// true if expression was enclosed in ' - /// </summary> - public bool IsStringConstant = false; - /// <summary> - /// Nb level to go up, '-1' for template root - /// </summary> - public int LevelsUp; - /// <summary> - /// Remaining string after '/' split, splitted on '.' - /// </summary> - public string[] Tokens; - - /// <summary> - /// Target the template's root node, expression was in the form './name[.name[...]]' or '/name[.name[...]]' - /// </summary> - public bool IsTemplateBinding { get { return LevelsUp < 0; }} - - /// <summary> - /// No level change and expression was '.name' - /// </summary> - /// <value><c>true</c> if this instance is current node property; otherwise, <c>false</c>.</value> - public bool IsCurrentNodeProperty { - get { - return LevelsUp == 0 && ( Tokens.Length == 2 && string.IsNullOrEmpty(Tokens[0])); - } - } - /// <summary> - /// no level change, and only a single name in Tokens[], that's dataSource member if property binding - /// </summary> - public bool IsSingleName { get { return LevelsUp == 0 && Tokens.Length == 1; }} - - #region CTOR - /// <summary> - /// Initializes a new instance of BindingMember. - /// </summary> - public BindingMember (){} - /// <summary> - /// Initializes a new instance of BindingMember by parsing the string passed as argument - /// </summary> - /// <param name="expression">binding expression</param> - public BindingMember (string expression){ - if (string.IsNullOrEmpty (expression)) - return; - - string[] splitedExp = expression.Trim().Split ('/'); - - int ptr = 0; - if (splitedExp.Length == 1) { - if (splitedExp [0].StartsWith ("\'")) { - if (!splitedExp [0].EndsWith ("\'")) - throw new Exception (string.Format - ("IML:malformed string constant in binding expression: {0}", splitedExp [0])); - Tokens = new string[] { splitedExp [0].Substring (1, splitedExp [0].Length - 2) }; - IsStringConstant = true; - return; - } - } else if (string.IsNullOrEmpty (splitedExp [0])) { - ptr++; - } else { - if (splitedExp [0] == ".") {//template root - LevelsUp = -1; - ptr++; - } else { - while (splitedExp [ptr] == "..") - ptr++; - LevelsUp = ptr; - } - } - if (ptr != splitedExp.Length - 1) - throw new Exception ("invalid expresion: " + expression); - Tokens = splitedExp [ptr].Split ('.'); - } - #endregion - - /// <summary> - /// Emits the MSIL instructions to get the target of the binding expression - /// </summary> - /// <param name="il">current MSIL generator</param> - /// <param name="cancel">cancel branching in MSIL if something go wrong</param> - public void emitGetTarget(ILGenerator il, System.Reflection.Emit.Label cancel){ - - if (IsTemplateBinding) { - System.Reflection.Emit.Label nextLogicParent = il.DefineLabel (); - il.MarkLabel (nextLogicParent); - il.Emit (OpCodes.Callvirt, CompilerServices.miGetLogicalParent); - il.Emit (OpCodes.Dup); - il.Emit (OpCodes.Brfalse, cancel); - il.Emit (OpCodes.Isinst, typeof(TemplatedControl)); - il.Emit (OpCodes.Dup); - il.Emit (OpCodes.Brfalse, nextLogicParent); - } else if (LevelsUp > 0) {//go upward in logical tree - il.Emit (OpCodes.Ldc_I4, LevelsUp);//push arg 2 of goUpLevels - il.Emit (OpCodes.Callvirt, CompilerServices.miGoUpLevels); - //test if null - il.Emit (OpCodes.Dup); - il.Emit (OpCodes.Brfalse, cancel); - } - - if (!string.IsNullOrEmpty (Tokens [0])) {//find by name - il.Emit (OpCodes.Ldstr, Tokens [0]); - il.Emit (OpCodes.Callvirt, CompilerServices.miFindByName); - il.Emit (OpCodes.Dup); - il.Emit (OpCodes.Brfalse, cancel); - } - - for (int i = 1; i < Tokens.Length -1; i++) { - System.Reflection.Emit.Label miOK = il.DefineLabel (); - il.Emit (OpCodes.Dup);//duplicate instance - il.Emit (OpCodes.Ldstr, Tokens [i]);//load member name - il.Emit (OpCodes.Call, CompilerServices.miGetMembIinfoWithRefx); - il.Emit (OpCodes.Dup); - il.Emit (OpCodes.Brtrue, miOK); - il.Emit (OpCodes.Pop);//pop dup instance - il.Emit (OpCodes.Br, cancel); - il.MarkLabel (miOK); - il.Emit (OpCodes.Call, CompilerServices.miGetValWithRefx); - il.Emit (OpCodes.Dup); - il.Emit (OpCodes.Brfalse, cancel); - } - } - /// <summary> - /// Emit the MSIL instructions to get the target property of the binding expression - /// </summary> - /// <param name="il">current MSIL generator</param> - /// <param name="cancel">cancel branching in MSIL if something go wrong</param> - public void emitGetProperty(ILGenerator il, System.Reflection.Emit.Label cancel) { - System.Reflection.Emit.Label miOK = il.DefineLabel (); - il.Emit (OpCodes.Dup);//duplicate instance - il.Emit (OpCodes.Ldstr, Tokens [Tokens.Length -1]);//load member name - il.Emit (OpCodes.Call, CompilerServices.miGetMembIinfoWithRefx); - il.Emit (OpCodes.Dup); - il.Emit (OpCodes.Brtrue, miOK); - il.Emit (OpCodes.Pop);//pop dup instance - il.Emit (OpCodes.Br, cancel); - il.MarkLabel (miOK); - il.Emit (OpCodes.Call, CompilerServices.miGetValWithRefx); - } - /// <summary> - /// Emit the MSIL instructions to set the target property of the binding expression - /// </summary> - /// <param name="il">current MSIL generator</param> - public void emitSetProperty(ILGenerator il) { - il.Emit (OpCodes.Ldstr, Tokens [Tokens.Length -1]);//load member name - il.Emit (OpCodes.Call, CompilerServices.miSetValWithRefx); - } - } -} - diff --git a/src/IML/EventBinding.cs b/src/IML/EventBinding.cs deleted file mode 100644 index 41e0c96a..00000000 --- a/src/IML/EventBinding.cs +++ /dev/null @@ -1,45 +0,0 @@ -// -// EventBinding.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Reflection; - -namespace Crow.IML -{ - public class EventBinding : BindingDefinition - { - public EventInfo SourceEvent; - - #region CTOR - public EventBinding (NodeAddress _sourceNA, EventInfo _sourceEvt, NodeAddress _targetNA, string _targetMember, string _targetName = "") - : base (_sourceNA, _sourceEvt.Name, _targetNA, _targetMember, _targetName) - { - SourceEvent = _sourceEvt; - } - #endregion - } -} - diff --git a/src/IML/IMLContext.cs b/src/IML/IMLContext.cs deleted file mode 100644 index aa4dee2f..00000000 --- a/src/IML/IMLContext.cs +++ /dev/null @@ -1,230 +0,0 @@ -// -// Context.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Reflection; -using System.Reflection.Emit; -using System.Xml; - -namespace Crow.IML -{ - public class DataSourceBinding { - public bool TwoWay; - public MemberAddress Source; - public string DataSourceMember; - } - /// <summary> - /// Context while parsing IML, this will store what's needed only while parsing and not during instancing - /// </summary> - public class IMLContext - { - public XmlReader reader = null; - public int curLine = 0; - public Type RootType = null; - - public DynamicMethod dm = null; - public ILGenerator il = null; - //public SubNodeType curSubNodeType; - public NodeStack nodesStack = new NodeStack (); - - /// <summary> store addresses of named node for name resolution at end of parsing </summary> - public Dictionary<string, List<NodeAddress>> Names = new Dictionary<string, List<NodeAddress>>(); - /// <summary> Store non datasource binding (in tree and template) by origine and orig member </summary> - public Dictionary<NodeAddress, Dictionary<string, List<MemberAddress>>> Bindings = - new Dictionary<NodeAddress, Dictionary<string, List<MemberAddress>>>(); - /// <summary> Store binding with name in target, will be resolved at end of parsing </summary> - public List<BindingDefinition> UnresolvedTargets = new List<BindingDefinition>(); - - - public IMLContext (Type rootType) - { - RootType = rootType; - dm = new DynamicMethod ("dyn_instantiator", - CompilerServices.TObject, new Type [] { typeof (Instantiator), typeof (Interface) }, true); - il = dm.GetILGenerator (256); - - il.DeclareLocal (typeof (GraphicObject)); - il.Emit (OpCodes.Nop); - //set local GraphicObject to root object - ConstructorInfo ci = rootType.GetConstructor ( - BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, - null, Type.EmptyTypes, null); - if (ci == null) - throw new Exception ("No default parameterless constructor found in " + rootType.Name); - il.Emit (OpCodes.Newobj, ci); - il.Emit (OpCodes.Stloc_0); - CompilerServices.emitSetCurInterface (il); - } - - public NodeAddress CurrentNodeAddress { - get { - Node[] n = nodesStack.ToArray (); - Array.Reverse (n); - return new NodeAddress(n); - } - } - public Type CurrentNodeType { - get { return nodesStack.Peek().CrowType; } - } - public void StorePropertyBinding(NodeAddress origNA, string origMember, NodeAddress destNA, string destMember){ - Dictionary<string, List<MemberAddress>> nodeBindings = null; - if (Bindings.ContainsKey (origNA)) - nodeBindings = Bindings [origNA]; - else { - nodeBindings = new Dictionary<string, List<MemberAddress>> (); - Bindings [origNA] = nodeBindings; - } - - if (!nodeBindings.ContainsKey (origMember)) - nodeBindings [origMember] = new List<MemberAddress> (); - nodeBindings [origMember].Add (new MemberAddress (destNA, destMember)); - } - public void StorePropertyBinding(BindingDefinition bindDef){ - if (bindDef.HasUnresolvedTargetName) { - UnresolvedTargets.Add (bindDef); - return; - } - StorePropertyBinding (bindDef.TargetNA, bindDef.TargetMember, bindDef.SourceNA, bindDef.SourceMember); - if (bindDef.TwoWay) - StorePropertyBinding (bindDef.SourceNA, bindDef.SourceMember, bindDef.TargetNA, bindDef.TargetMember); - } - public void StoreCurrentName(string name){ - if (!Names.ContainsKey(name)) - Names[name] = new List<NodeAddress>(); - Names[name].Add(CurrentNodeAddress); - } - public void ResolveNamedTargets(){//TODO:methodinfo fetching is redundant with early parsing - foreach (BindingDefinition bd in UnresolvedTargets) { - if (bd.HasUnresolvedTargetName) { - try { - ResolveName (bd); - } catch (Exception ex) { - System.Diagnostics.Debug.WriteLine (ex.ToString ()); - continue; - } - } - - if (bd is EventBinding) { - emitHandlerMethodAddition (bd as EventBinding); - continue; - } - - MemberInfo miSource = bd.SourceMemberAddress.member; - if (miSource == null) - throw new Exception ("Source member '" + bd.SourceMember + "' not found"); - StorePropertyBinding (bd); - } - } - public void ResolveName (BindingDefinition bd){ - - if (!Names.ContainsKey (bd.TargetName)) - throw new Exception ("Target Name '" + bd.TargetName + "' not found"); - - NodeAddress resolvedNA = null; - foreach (NodeAddress na in Names[bd.TargetName]) { - bool naMatch = true; - for (int i = 0; i < bd.TargetNA.Count; i++) { - if (bd.TargetNA [i] != na [i]) { - naMatch = false; - break; - } - } - if (naMatch) { - resolvedNA = na; - break; - } - } - - if (resolvedNA == null) - throw new Exception ("Target Name '" + bd.TargetName + "' not found"); - - bd.ResolveTargetName (resolvedNA); - } - - /// <summary> - /// Emits cached delegate handler addition in the context of instantiator (ctx) - /// </summary> - public void emitCachedDelegateHandlerAddition(int index, EventInfo evt, NodeAddress address = null){ - il.Emit(OpCodes.Ldloc_0);//load ref to current graphic object - CompilerServices.emitGetInstance (il, address); - il.Emit(OpCodes.Ldarg_0);//load ref to this instanciator onto the stack - il.Emit(OpCodes.Ldfld, CompilerServices.fiCachedDel); - il.Emit(OpCodes.Ldc_I4, index);//load delegate index - il.Emit(OpCodes.Callvirt, CompilerServices.miGetDelegateListItem); - il.Emit(OpCodes.Callvirt, evt.AddMethod);//call add event - } - /// <summary> - /// Emits the handler method addition, done at end of parsing, Loc_0 is root node instance - /// </summary> - /// <param name="bd">Bd.</param> - /// <param name="evt">passed as arg to prevent refetching it for the 3rd time</param> - public void emitHandlerMethodAddition(EventBinding bd){ - - //fetch source instance with address for handler addition (as 1st arg of handler.add) - il.Emit (OpCodes.Ldloc_0);//push root - CompilerServices.emitGetInstance (il, bd.SourceNA); - - il.Emit (OpCodes.Ldloc_0); - CompilerServices.emitGetInstance (il, bd.TargetNA); - - string[] membs = bd.TargetMember.Split ('.'); - for (int i = 0; i < membs.Length - 1; i++) { - il.Emit (OpCodes.Dup); - il.Emit (OpCodes.Ldstr, membs[i]); - il.Emit (OpCodes.Call, CompilerServices.miGetMembIinfoWithRefx); - il.Emit (OpCodes.Call, CompilerServices.miGetValWithRefx); - } - - //load handlerType of sourceEvent to create handler delegate (1st arg) - il.Emit (OpCodes.Ldtoken, bd.SourceEvent.EventHandlerType); - il.Emit (OpCodes.Call, CompilerServices.miGetTypeFromHandle); - //load methodInfo (3rd arg) - il.Emit (OpCodes.Ldstr, membs[membs.Length-1]); - il.Emit (OpCodes.Callvirt, CompilerServices.miCreateDel); - il.Emit (OpCodes.Callvirt, bd.SourceEvent.AddMethod);//call add event - } -// public void emitHandlerMethodAddition(EventBinding bd){ -// //fetch source instance with address for handler addition (as 1st arg of handler.add) -// il.Emit (OpCodes.Ldloc_0);//push root -// CompilerServices.emitGetInstance (il, bd.SourceNA); -// -// //load handlerType of sourceEvent to create handler delegate (1st arg) -// il.Emit (OpCodes.Ldtoken, bd.SourceEvent.EventHandlerType); -// il.Emit (OpCodes.Call, CompilerServices.miGetTypeFromHandle); -// //load target the where the method is defined (2nd arg) -// il.Emit (OpCodes.Ldloc_0); -// CompilerServices.emitGetInstance (il, bd.TargetNA); -// //load methodInfo (3rd arg) -// il.Emit (OpCodes.Ldstr, bd.TargetMember); -// -// il.Emit (OpCodes.Callvirt, CompilerServices.miCreateDel); -// -// il.Emit (OpCodes.Callvirt, bd.SourceEvent.AddMethod);//call add event -// } -// - } -}
\ No newline at end of file diff --git a/src/IML/MemberAddress.cs b/src/IML/MemberAddress.cs deleted file mode 100644 index f27a8b87..00000000 --- a/src/IML/MemberAddress.cs +++ /dev/null @@ -1,116 +0,0 @@ -// -// MemberAddress.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Linq; -using System.Reflection; - -namespace Crow.IML -{ - /// <summary> - /// Address member of a node - /// </summary> - public struct MemberAddress - { - public string memberName; - public MemberInfo member; - public NodeAddress Address; - - public PropertyInfo Property { get { return member as PropertyInfo; }} - public bool IsTemplateBinding { get { return Address == null ? false : Address.Count == 0; }} -// public string Name { -// get { return memberName; } -// set { memberName = value; } -// } - - public MemberAddress (NodeAddress _address, string _member, bool findMember = true) - { - Address = _address; - memberName = _member; - member = null; - - if (Address == null) - return; - if (Address.Count == 0) - return; - - if (!findMember) - return; - if (!tryFindMember ()) - throw new Exception ("Member Not Found: " + memberName); - } - public MemberAddress (NodeAddress _address, MemberInfo _member) - { - Address = _address; - member = _member; - memberName = ""; - - if (member != null) - memberName = member.Name; - } - - #region Equality Compare - public override bool Equals (object obj) - { - return obj is MemberAddress && this == (MemberAddress)obj; - } - public override int GetHashCode () - { - return Address.GetHashCode () ^ member.GetHashCode (); - } - public static bool operator == (MemberAddress x, MemberAddress y) - { - return x.Address == y.Address && x.memberName == y.memberName; - } - public static bool operator != (MemberAddress x, MemberAddress y) - { - return !(x == y); - } - #endregion - - bool tryFindMember () - { - if (member != null) - throw new Exception ("member already found"); - if (Address == null) - return false; - if (Address.Count == 0) - return false; - Type t = Address.LastOrDefault ().CrowType; - member = t.GetMember (memberName, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance).FirstOrDefault (); - - #region search for extensions methods if member not found in type - if (member == null && !string.IsNullOrEmpty (memberName)) { - Assembly a = Assembly.GetExecutingAssembly (); - string mn = memberName; - member = CompilerServices.GetExtensionMethods (a, t).Where (em => em.Name == mn).FirstOrDefault (); - } - #endregion - - return member != null; - } - } -} diff --git a/src/IML/Node.cs b/src/IML/Node.cs deleted file mode 100644 index 2ca90e8c..00000000 --- a/src/IML/Node.cs +++ /dev/null @@ -1,101 +0,0 @@ -// -// Node.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Reflection; -using System.Reflection.Emit; -using System.Collections.Generic; - -namespace Crow.IML -{ - /// <summary> - /// IML Node are defined with a type and the index in the parent, - /// </summary> - public struct Node - { - #region CTOR - public Node (Type crowType, int _index = 0) - { - CrowType = crowType; - Index = _index; - } - #endregion - - /// <summary> Current node type</summary> - public Type CrowType; - /// <summary> Index in parent, -1 for template</summary> - public int Index; - - /// <summary> - /// retrieve the child addition method depending on the type of this node - /// </summary> - /// <returns>The child addition method</returns> - /// <param name="childIdx">child index or, template root node has index == -1</param> - public MethodInfo GetAddMethod(int childIdx){ - if (typeof (Group).IsAssignableFrom (CrowType)) - return CompilerServices.miAddChild; - if (typeof (Container).IsAssignableFrom (CrowType)) - return CompilerServices.miSetChild; - if (typeof (TemplatedContainer).IsAssignableFrom (CrowType)) - return childIdx < 0 ? CompilerServices.miLoadTmp : CompilerServices.piContent.GetSetMethod(); - if (typeof (TemplatedGroup).IsAssignableFrom (CrowType)) - return childIdx < 0 ? CompilerServices.miLoadTmp : CompilerServices.miAddItem; - if (typeof (TemplatedControl).IsAssignableFrom (CrowType)) - return CompilerServices.miLoadTmp; - return null; - } - - #region Equality Compare - public override bool Equals (object obj) - { - if (obj == null) - return false; - Node n = (Node)obj; - return CrowType == n.CrowType && Index == n.Index; - } - public override int GetHashCode () - { - return CrowType.GetHashCode () ^ Index.GetHashCode (); - } - #endregion - - public bool HasTemplate { - get { return typeof (TemplatedControl).IsAssignableFrom (CrowType);} - } - public bool IsTemplatedGroup { - get { return typeof (TemplatedGroup).IsAssignableFrom (CrowType);} - } - - public static implicit operator string (Node sn) - { - return sn.ToString (); - } - public override string ToString () - { - return string.Format ("{0}.{1}", CrowType.FullName, Index); - } - } -} diff --git a/src/IML/NodeAddress.cs b/src/IML/NodeAddress.cs deleted file mode 100644 index 450a9d2d..00000000 --- a/src/IML/NodeAddress.cs +++ /dev/null @@ -1,148 +0,0 @@ -// -// NodeAddress.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Linq; -using System.Reflection; -using System.Reflection.Emit; - -namespace Crow.IML -{ - /// <summary> - /// Node address is a list of nodes from root to leaf defining a unique node - /// </summary> - public class NodeAddress : List<Node> - { - #region CTOR - public NodeAddress (Node[] nodes) : base(nodes) {} - #endregion - - public Type NodeType { get { return Count == 0 ? null : this[this.Count -1].CrowType; }} - - /// <summary> - /// Gets the node adress from binding expression starting from this node - /// and return in expression remaining part - /// </summary> - public NodeAddress ResolveExpression (ref string expression){ - int ptr = this.Count - 1; - string[] splitedExp = expression.Split ('/'); - - if (splitedExp.Length < 2)//dataSource binding - return null; - - if (!string.IsNullOrEmpty (splitedExp [0])) {//else bind on current node - //return new NodeAddress (this.Take(ptr+1).ToArray()); - if (splitedExp [0] == ".") {//search template root - ptr--; - while (ptr >= 0) { - if (typeof(TemplatedControl).IsAssignableFrom (this [ptr].CrowType)) - break; - ptr--; - } - } else if (splitedExp [0] == "..") { //search starting at current node - int levelUp = splitedExp.Length - 1; - if (levelUp > ptr + 1) - throw new Exception ("Binding error: try to bind outside IML source"); - ptr -= levelUp; - } - } - expression = splitedExp [splitedExp.Length - 1]; - //TODO:change Template special address identified with Nodecount = 0 to something not using array count to 0, - //here linq is working without limits checking in compile option - //but defining a 0 capacity array with limits cheking enabled, cause 'out of memory' error - return new NodeAddress (this.Take(ptr+1).ToArray());//[ptr+1]; - //Array.Copy (sourceAddr.ToArray (), targetNode, ptr + 1); - //return new NodeAddress (targetNode); - } - /// <summary> - /// get BindingDefinition from binding expression - /// </summary> - public BindingDefinition GetBindingDef(string sourceMember, string expression){ - BindingDefinition bindingDef = new BindingDefinition(this, sourceMember); - if (string.IsNullOrEmpty (expression)) { - return bindingDef; - } else { - if (expression.StartsWith ("²")) { - bindingDef.TwoWay = true; - expression = expression.Substring (1); - } - - string exp = expression; - bindingDef.TargetNA = this.ResolveExpression (ref exp); - - string [] bindTrg = exp.Split ('.'); - - if (bindTrg.Length == 0) - throw new Exception ("invalid binding expression: " + expression); - if (bindTrg.Length == 1) - bindingDef.TargetMember = bindTrg [0]; - else { - if (!string.IsNullOrEmpty(bindTrg[0]))//searchByName - bindingDef.TargetName = bindTrg[0]; - - bindingDef.TargetMember = exp.Substring (bindTrg[0].Length + 1); - } - } - - return bindingDef; - } - - #region Object overrides - public override bool Equals (object obj) - { - if (obj == null) - return false; - - NodeAddress na = (NodeAddress)obj; - return this.SequenceEqual (na); - } - public override int GetHashCode () - { - unchecked { - int hash = 19; - foreach (Node n in this) - hash = hash * 31 + (n == null ? 0 : n.GetHashCode ()); - return hash; - } - } - public override string ToString () - { - string tmp = ""; - foreach (Node n in this) - tmp += string.Format ("{0};", n.Index); - return tmp; - } - #endregion - } - - public class NamedNodeAddress : NodeAddress { - public string Name; - public NamedNodeAddress(string name, Node[] nodes) : base(nodes){ - Name = name; - } - } -} diff --git a/src/IML/NodeStack.cs b/src/IML/NodeStack.cs deleted file mode 100644 index 80e9156f..00000000 --- a/src/IML/NodeStack.cs +++ /dev/null @@ -1,50 +0,0 @@ -// -// NodeStack.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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; - -namespace Crow.IML -{ - public class NodeStack : Stack<Node> - { - public NodeStack () : base() - { - } - public void IncrementCurrentNodeIndex(){ - Node n = this.Pop(); - this.Push (new Node (n.CrowType, n.Index + 1)); - } - public void DecrementCurrentNodeIndex(){ - Node n = this.Pop(); - this.Push (new Node (n.CrowType, n.Index - 1)); - } - public void ResetCurrentNodeIndex(){ - this.Push (new Node (this.Pop().CrowType)); - } - } -} - diff --git a/src/IML/Reader.cs b/src/IML/Reader.cs deleted file mode 100644 index 7a0c8405..00000000 --- a/src/IML/Reader.cs +++ /dev/null @@ -1,223 +0,0 @@ -// -// IMLReader.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; -using System.IO; -using System.Reflection; -using System.Reflection.Emit; -using System.Linq; -using System.Collections.Generic; - -namespace Crow.IML2 -{ - public class Reader : XmlTextReader - { - static List<Type> CrowTypes = new List<Type> (); - - public enum SubNodeType{ - None, - Child, - Children, - Template, - Content, - Items, - ItemTemplate - } - - //public static Node Parse(string str){ - // string[] tmp = str.Trim ().Split ('.'); - // switch (tmp.Length) { - // case 1: - // return new Node ((SubNodeType)int.Parse (tmp [0])); - // case 2: - // return new Node ((SubNodeType)int.Parse (tmp [0]), int.Parse (tmp[1])); - // case 0: - // default: - // return new Node (); - // } - //} - //public static string AddressToString(Node[] address){ - // string tmp = ""; - // foreach (Node n in address) { - // tmp += n.ToString () + ";"; - // } - // return string.IsNullOrEmpty(tmp) ? tmp : tmp.Substring (0, tmp.Length - 1); - //} - //public static Node[] AddressFromString(string address) { - // List<Node> nodes = new List<Node> (); - // string[] tmp = address.Split (';'); - // for (int i = 0; i < tmp.Length; i++) - // nodes.Add (Node.Parse (tmp [i])); - // return nodes.ToArray(); - //} - - - // public class PropertyBinding { - // public string OriginePropertyName = ""; - // public MemberAddress Destination; - // } - - public Type RootType = null; - public Context context; - - InstanciatorInvoker loader = null; - DynamicMethod dm = null; - - ILGenerator il { get { return context.il; }} - - /// <summary> - /// Finalize instatiator MSIL and return LoaderInvoker delegate - /// </summary> - public InstanciatorInvoker GetLoader(){ - if (loader != null) - return loader; - - il.Emit(OpCodes.Ret); - loader = (InstanciatorInvoker)dm.CreateDelegate (typeof(InstanciatorInvoker)); - return loader; - } - - protected int curDepth { - get { return context.nodesStack.Count - 1;} - } - protected Node curNode { - get { return context.nodesStack.Peek(); } - } - //protected Stack<int> curTemplateDepth = new Stack<int>(new int[] {0}); //current template root depth - - #region CTOR - public Reader (string path) - : this(Interface.GetStreamFromPath (path)){ - } - public Reader (Stream stream) - : base(stream) - { - createInstantiator (); - } - /// <summary> - /// Used to parse xmlFrament with same code generator linked - /// If ilGen=null, a new Code Generator will be created. - /// </summary> - public Reader (Context ctx, string xmlFragment) - : base(xmlFragment, XmlNodeType.Element,null){ - - context = ctx; -// -// if (IMLCtx != null) -// return; -// -// createInstantiator(); - } - #endregion - - - void createBindingDelegates(){ -// foreach (Dictionary<string, MemberAddress> pb in IMLCtx.PropertyBindings) { -// -// } - } - - - void registerPropertyBinding(string origNode, string origProp, MemberAddress ma){ - if (!context.PropertyBindings.ContainsKey(origNode)) - context.PropertyBindings [origNode] = new Dictionary<string, MemberAddress> (); - context.PropertyBindings [origNode] [origProp] = ma; - } - void readPropertyBinding(string srcProperty, string expression){ - //if binding exp = '{}' => binding is done on datasource - if (string.IsNullOrEmpty (expression)) { - registerPropertyBinding ("DS", "", new MemberAddress (context.nodesStack.ToArray (), srcProperty)); - return; - } - -// if (expression.StartsWith ("²")) { -// expression = expression.Substring (1); -// TwoWayBinding = true; -// } -// - string [] bindingExp = expression.Split ('/'); - - - if (bindingExp.Length == 1) { - registerPropertyBinding ("DS", bindingExp [0], - new MemberAddress (context.nodesStack.ToArray (), srcProperty)); - return; - } - - string targetName = ""; - string nodeId = ""; - Node[] target = context.nodesStack.ToArray (); - - int nodeIdx = target.Length - 1;//index of target in nodeStack - int ptr = 0;//pointer in bindingExp splitted on '/' - -// //if exp start with '/' => WidgetName.property - if (string.IsNullOrEmpty (bindingExp [0])) { - string[] bindTrg = bindingExp [1].Split ('.'); - if (bindTrg.Length == 1) { - nodeId = Node.AddressToString (target); - targetName = bindTrg [0]; - }else if (bindTrg.Length == 2) { - nodeId = context.Names [bindTrg [0]]; - targetName = bindTrg [1]; - } else - throw new Exception ("Syntax error in binding, expected 'go dot member'"); - } else { - if (bindingExp [0] == ".") { //template binding - //parse nodes up until template node - while (nodeIdx > 0) { - if (target [nodeIdx].Type == SubNodeType.Template) - break; - nodeIdx--; - } - ptr++; - } else { - while (ptr < bindingExp.Length - 1) { - if (bindingExp [ptr] == "..") - nodeIdx--; - else - break; - ptr++; - } - } - Node[] origine = new Node[nodeIdx + 1]; - try { - Array.Copy (target, origine, nodeIdx + 1); - - int destLength = target.Length - nodeIdx; - Node[] dest = new Node[destLength]; - Array.Copy (target, nodeIdx, dest, 0, destLength); - - } catch (Exception ex) { - System.Diagnostics.Debug.WriteLine (ex.ToString ()); - } - - - nodeId = Node.AddressToString (origine); - targetName = bindingExp [ptr]; - } - - registerPropertyBinding (nodeId, targetName, new MemberAddress (context.nodesStack.ToArray (), srcProperty)); - } - - } -} - diff --git a/src/IMLAttributes.cs b/src/IMLAttributes.cs deleted file mode 100644 index 929fd4f8..00000000 --- a/src/IMLAttributes.cs +++ /dev/null @@ -1,44 +0,0 @@ -// -// IMLAttributes.cs -// -// Author: -// Jean-Philippe Bruyère <jp_bruyere@hotmail.com> -// -// 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; - -namespace Crow -{ - public class DesignIgnore : Attribute - { - } - - public class DesignCategory : Attribute - { - public string Name { get; set; } - - public DesignCategory (string name) - { - Name = name; - } - } -} - diff --git a/src/Input/ButtonState.cs b/src/Input/ButtonState.cs deleted file mode 100644 index 17849ca8..00000000 --- a/src/Input/ButtonState.cs +++ /dev/null @@ -1,45 +0,0 @@ - #region License - // - // The Open Toolkit Library License - // - // Copyright (c) 2006 - 2010 the Open Toolkit library. - // - // 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. - // - #endregion - -namespace Crow -{ - /// <summary> - /// Enumerates possible mouse button states. - /// </summary> - public enum ButtonState - { - /// <summary> - /// Indicates that a mouse button is released. - /// </summary> - Released = 0, - - /// <summary> - /// Indicates that a mouse button is pressed. - /// </summary> - Pressed = 1 - } -} diff --git a/src/Input/Buttons.cs b/src/Input/Buttons.cs deleted file mode 100644 index ebf3bc42..00000000 --- a/src/Input/Buttons.cs +++ /dev/null @@ -1,166 +0,0 @@ -// -// GamePadButton.cs -// -// Author: -// robert <${AuthorEmail}> -// -// Copyright (c) 2012 robert -// -// 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; - -namespace Crow -{ - /// <summary> - /// Enumerates available buttons for a <c>GamePad</c> device. - /// </summary> - [Flags] - public enum Buttons - { - /// <summary> - /// DPad up direction button - /// </summary> - DPadUp = 1 << 0, - - /// <summary> - /// DPad down direction button - /// </summary> - DPadDown = 1 << 1, - - /// <summary> - /// DPad left direction button - /// </summary> - DPadLeft = 1 << 2, - - /// <summary> - /// DPad right direction button - /// </summary> - DPadRight = 1 << 3, - - /// <summary> - /// Start button - /// </summary> - Start = 1 << 4, - - /// <summary> - /// Back button - /// </summary> - Back = 1 << 5, - - /// <summary> - /// Left stick button - /// </summary> - LeftStick = 1 << 6, - - /// <summary> - /// Right stick button - /// </summary> - RightStick = 1 << 7, - - /// <summary> - /// Left shoulder button - /// </summary> - LeftShoulder = 1 << 8, - - /// <summary> - /// Right shoulder button - /// </summary> - RightShoulder = 1 << 9, - - /// <summary> - /// Home button - /// </summary> - Home = 1 << 11, - - /// <summary> - /// Home button - /// </summary> - BigButton = Home, - - /// <summary> - /// A button - /// </summary> - A = 1 << 12, - - /// <summary> - /// B button - /// </summary> - B = 1 << 13, - - /// <summary> - /// X button - /// </summary> - X = 1 << 14, - - /// <summary> - /// Y button - /// </summary> - Y = 1 << 15, - - /// <summary> - /// Left thumbstick left direction button - /// </summary> - LeftThumbstickLeft = 1 << 21, - - /// <summary> - /// Right trigger button - /// </summary> - RightTrigger = 1 << 22, - - /// <summary> - /// Left trigger button - /// </summary> - LeftTrigger = 1 << 23, - - /// <summary> - /// Right thumbstick up direction button - /// </summary> - RightThumbstickUp = 1 << 24, - - /// <summary> - /// Right thumbstick down direction button - /// </summary> - RightThumbstickDown = 1 << 25, - - /// <summary> - /// Right stick right direction button - /// </summary> - RightThumbstickRight = 1 << 26, - - /// <summary> - /// Right stick left direction button - /// </summary> - RightThumbstickLeft = 1 << 27, - - /// <summary> - /// Left stick up direction button - /// </summary> - LeftThumbstickUp = 1 << 28, - - /// <summary> - /// Left stick down direction button - /// </summary> - LeftThumbstickDown = 1 << 29, - - /// <summary> - /// Left stick right direction button - /// </summary> - LeftThumbstickRight = 1 << 30, - } -} diff --git a/src/Input/Key.cs b/src/Input/Key.cs deleted file mode 100644 index 71f9d85a..00000000 --- a/src/Input/Key.cs +++ /dev/null @@ -1,380 +0,0 @@ - #region License - // - // The Open Toolkit Library License - // - // Copyright (c) 2006 - 2009 the Open Toolkit library. - // - // 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. - // - #endregion - -namespace Crow -{ - /// <summary> - /// The available keyboard keys. - /// </summary> - public enum Key : int - { - /// <summary>A key outside the known keys.</summary> - Unknown = 0, - - // Modifiers - /// <summary>The left shift key.</summary> - ShiftLeft, - /// <summary>The left shift key (equivalent to ShiftLeft).</summary> - LShift = ShiftLeft, - /// <summary>The right shift key.</summary> - ShiftRight, - /// <summary>The right shift key (equivalent to ShiftRight).</summary> - RShift = ShiftRight, - /// <summary>The left control key.</summary> - ControlLeft, - /// <summary>The left control key (equivalent to ControlLeft).</summary> - LControl = ControlLeft, - /// <summary>The right control key.</summary> - ControlRight, - /// <summary>The right control key (equivalent to ControlRight).</summary> - RControl = ControlRight, - /// <summary>The left alt key.</summary> - AltLeft, - /// <summary>The left alt key (equivalent to AltLeft.</summary> - LAlt = AltLeft, - /// <summary>The right alt key.</summary> - AltRight, - /// <summary>The right alt key (equivalent to AltRight).</summary> - RAlt = AltRight, - /// <summary>The left win key.</summary> - WinLeft, - /// <summary>The left win key (equivalent to WinLeft).</summary> - LWin = WinLeft, - /// <summary>The right win key.</summary> - WinRight, - /// <summary>The right win key (equivalent to WinRight).</summary> - RWin = WinRight, - /// <summary>The menu key.</summary> - Menu, - - // Function keys (hopefully enough for most keyboards - mine has 26) - // <keysymdef.h> on X11 reports up to 35 function keys. - /// <summary>The F1 key.</summary> - F1, - /// <summary>The F2 key.</summary> - F2, - /// <summary>The F3 key.</summary> - F3, - /// <summary>The F4 key.</summary> - F4, - /// <summary>The F5 key.</summary> - F5, - /// <summary>The F6 key.</summary> - F6, - /// <summary>The F7 key.</summary> - F7, - /// <summary>The F8 key.</summary> - F8, - /// <summary>The F9 key.</summary> - F9, - /// <summary>The F10 key.</summary> - F10, - /// <summary>The F11 key.</summary> - F11, - /// <summary>The F12 key.</summary> - F12, - /// <summary>The F13 key.</summary> - F13, - /// <summary>The F14 key.</summary> - F14, - /// <summary>The F15 key.</summary> - F15, - /// <summary>The F16 key.</summary> - F16, - /// <summary>The F17 key.</summary> - F17, - /// <summary>The F18 key.</summary> - F18, - /// <summary>The F19 key.</summary> - F19, - /// <summary>The F20 key.</summary> - F20, - /// <summary>The F21 key.</summary> - F21, - /// <summary>The F22 key.</summary> - F22, - /// <summary>The F23 key.</summary> - F23, - /// <summary>The F24 key.</summary> - F24, - /// <summary>The F25 key.</summary> - F25, - /// <summary>The F26 key.</summary> - F26, - /// <summary>The F27 key.</summary> - F27, - /// <summary>The F28 key.</summary> - F28, - /// <summary>The F29 key.</summary> - F29, - /// <summary>The F30 key.</summary> - F30, - /// <summary>The F31 key.</summary> - F31, - /// <summary>The F32 key.</summary> - F32, - /// <summary>The F33 key.</summary> - F33, - /// <summary>The F34 key.</summary> - F34, - /// <summary>The F35 key.</summary> - F35, - - // Direction arrows - /// <summary>The up arrow key.</summary> - Up, - /// <summary>The down arrow key.</summary> - Down, - /// <summary>The left arrow key.</summary> - Left, - /// <summary>The right arrow key.</summary> - Right, - - /// <summary>The enter key.</summary> - Enter, - /// <summary>The escape key.</summary> - Escape, - /// <summary>The space key.</summary> - Space, - /// <summary>The tab key.</summary> - Tab, - /// <summary>The backspace key.</summary> - BackSpace, - /// <summary>The backspace key (equivalent to BackSpace).</summary> - Back = BackSpace, - /// <summary>The insert key.</summary> - Insert, - /// <summary>The delete key.</summary> - Delete, - /// <summary>The page up key.</summary> - PageUp, - /// <summary>The page down key.</summary> - PageDown, - /// <summary>The home key.</summary> - Home, - /// <summary>The end key.</summary> - End, - /// <summary>The caps lock key.</summary> - CapsLock, - /// <summary>The scroll lock key.</summary> - ScrollLock, - /// <summary>The print screen key.</summary> - PrintScreen, - /// <summary>The pause key.</summary> - Pause, - /// <summary>The num lock key.</summary> - NumLock, - - // Special keys - /// <summary>The clear key (Keypad5 with NumLock disabled, on typical keyboards).</summary> - Clear, - /// <summary>The sleep key.</summary> - Sleep, - /*LogOff, - Help, - Undo, - Redo, - New, - Open, - Close, - Reply, - Forward, - Send, - Spell, - Save, - Calculator, - - // Folders and applications - Documents, - Pictures, - Music, - MediaPlayer, - Mail, - Browser, - Messenger, - - // Multimedia keys - Mute, - PlayPause, - Stop, - VolumeUp, - VolumeDown, - TrackPrevious, - TrackNext,*/ - - // Keypad keys - /// <summary>The keypad 0 key.</summary> - Keypad0, - /// <summary>The keypad 1 key.</summary> - Keypad1, - /// <summary>The keypad 2 key.</summary> - Keypad2, - /// <summary>The keypad 3 key.</summary> - Keypad3, - /// <summary>The keypad 4 key.</summary> - Keypad4, - /// <summary>The keypad 5 key.</summary> - Keypad5, - /// <summary>The keypad 6 key.</summary> - Keypad6, - /// <summary>The keypad 7 key.</summary> - Keypad7, - /// <summary>The keypad 8 key.</summary> - Keypad8, - /// <summary>The keypad 9 key.</summary> - Keypad9, - /// <summary>The keypad divide key.</summary> - KeypadDivide, - /// <summary>The keypad multiply key.</summary> - KeypadMultiply, - /// <summary>The keypad subtract key.</summary> - KeypadSubtract, - /// <summary>The keypad minus key (equivalent to KeypadSubtract).</summary> - KeypadMinus = KeypadSubtract, - /// <summary>The keypad add key.</summary> - KeypadAdd, - /// <summary>The keypad plus key (equivalent to KeypadAdd).</summary> - KeypadPlus = KeypadAdd, - /// <summary>The keypad decimal key.</summary> - KeypadDecimal, - /// <summary>The keypad period key (equivalent to KeypadDecimal).</summary> - KeypadPeriod = KeypadDecimal, - /// <summary>The keypad enter key.</summary> - KeypadEnter, - - // Letters - /// <summary>The A key.</summary> - A, - /// <summary>The B key.</summary> - B, - /// <summary>The C key.</summary> - C, - /// <summary>The D key.</summary> - D, - /// <summary>The E key.</summary> - E, - /// <summary>The F key.</summary> - F, - /// <summary>The G key.</summary> - G, - /// <summary>The H key.</summary> - H, - /// <summary>The I key.</summary> - I, - /// <summary>The J key.</summary> - J, - /// <summary>The K key.</summary> - K, - /// <summary>The L key.</summary> - L, - /// <summary>The M key.</summary> - M, - /// <summary>The N key.</summary> - N, - /// <summary>The O key.</summary> - O, - /// <summary>The P key.</summary> - P, - /// <summary>The Q key.</summary> - Q, - /// <summary>The R key.</summary> - R, - /// <summary>The S key.</summary> - S, - /// <summary>The T key.</summary> - T, - /// <summary>The U key.</summary> - U, - /// <summary>The V key.</summary> - V, - /// <summary>The W key.</summary> - W, - /// <summary>The X key.</summary> - X, - /// <summary>The Y key.</summary> - Y, - /// <summary>The Z key.</summary> - Z, - - // Numbers - /// <summary>The number 0 key.</summary> - Number0, - /// <summary>The number 1 key.</summary> - Number1, - /// <summary>The number 2 key.</summary> - Number2, - /// <summary>The number 3 key.</summary> - Number3, - /// <summary>The number 4 key.</summary> - Number4, - /// <summary>The number 5 key.</summary> - Number5, - /// <summary>The number 6 key.</summary> - Number6, - /// <summary>The number 7 key.</summary> - Number7, - /// <summary>The number 8 key.</summary> - Number8, - /// <summary>The number 9 key.</summary> - Number9, - - // Symbols - /// <summary>The tilde key.</summary> - Tilde, - /// <summary>The grave key (equivaent to Tilde).</summary> - Grave = Tilde, - /// <summary>The minus key.</summary> - Minus, - //Equal, - /// <summary>The plus key.</summary> - Plus, - /// <summary>The left bracket key.</summary> - BracketLeft, - /// <summary>The left bracket key (equivalent to BracketLeft).</summary> - LBracket = BracketLeft, - /// <summary>The right bracket key.</summary> - BracketRight, - /// <summary>The right bracket key (equivalent to BracketRight).</summary> - RBracket = BracketRight, - /// <summary>The semicolon key.</summary> - Semicolon, - /// <summary>The quote key.</summary> - Quote, - /// <summary>The comma key.</summary> - Comma, - /// <summary>The period key.</summary> - Period, - /// <summary>The slash key.</summary> - Slash, - /// <summary>The backslash key.</summary> - BackSlash, - /// <summary>The secondary backslash key.</summary> - NonUSBackSlash, - /// <summary>Indicates the last available keyboard key.</summary> - LastKey - } -}
\ No newline at end of file diff --git a/src/Input/KeyModifiers.cs b/src/Input/KeyModifiers.cs deleted file mode 100644 index 885365ca..00000000 --- a/src/Input/KeyModifiers.cs +++ /dev/null @@ -1,63 +0,0 @@ -#region License -// -// HatPosition.cs -// -// Author: -// Stefanos A. <stapostol@gmail.com> -// -// Copyright (c) 2006-2014 Stefanos Apostolopoulos -// -// 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. -// -#endregion - -using System; -using System.Collections.Generic; -using System.Text; - -namespace Crow -{ - /// <summary> - /// Enumerates modifier keys. - /// </summary> - [Flags] - public enum KeyModifiers : byte - { - None = 0, - /// <summary> - /// The alt key modifier (option on Mac). - /// </summary> - Alt = 1 << 0, - - /// <summary> - /// The control key modifier. - /// </summary> - Control = 1 << 1, - - /// <summary> - /// The shift key modifier. - /// </summary> - Shift = 1 << 2, - - /// <summary> - /// The shift key modifier. - /// </summary> - AltGr = 1 << 3 - } -} diff --git a/src/Input/KeyPressEventArgs.cs b/src/Input/KeyPressEventArgs.cs deleted file mode 100644 index 73990613..00000000 --- a/src/Input/KeyPressEventArgs.cs +++ /dev/null @@ -1,58 +0,0 @@ -// #region License -// // -// // The Open Toolkit Library License -// // -// // Copyright (c) 2006 - 2009 the Open Toolkit library. -// // -// // 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. -// // -// #endregion - -using System; - -namespace Crow -{ - /// <summary> - /// Defines the event arguments for KeyPress events. Instances of this class are cached: - /// KeyPressEventArgs should only be used inside the relevant event, unless manually cloned. - /// </summary> - public class KeyPressEventArgs : EventArgs - { - char key_char; - - /// <summary> - /// Constructs a new instance. - /// </summary> - /// <param name="keyChar">The ASCII character that was typed.</param> - public KeyPressEventArgs(char keyChar) - { - KeyChar = keyChar; - } - - /// <summary> - /// Gets a <see cref="System.Char"/> that defines the ASCII character that was typed. - /// </summary> - public char KeyChar - { - get { return key_char; } - internal set { key_char = value; } - } - } -} diff --git a/src/Input/KeyboardKeyEventArgs.cs b/src/Input/KeyboardKeyEventArgs.cs deleted file mode 100644 index f9307ffc..00000000 --- a/src/Input/KeyboardKeyEventArgs.cs +++ /dev/null @@ -1,167 +0,0 @@ -#region License -// -// The Open Toolkit Library License -// -// Copyright (c) 2006 - 2009 the Open Toolkit library. -// -// 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. -// -#endregion - -using System; -using System.Collections.Generic; -using System.Text; - -namespace Crow -{ - /// <summary> - /// Defines the event data for <see cref="KeyboardDevice"/> events. - /// </summary> - /// <remarks> - /// <para> - /// Do not cache instances of this type outside their event handler. - /// If necessary, you can clone a KeyboardEventArgs instance using the - /// <see cref="KeyboardKeyEventArgs(KeyboardKeyEventArgs)"/> constructor. - /// </para> - /// </remarks> - public class KeyboardKeyEventArgs : EventArgs - { - #region Fields - - Key key; - bool repeat; - KeyboardState state; - - #endregion - - #region Constructors - - /// <summary> - /// Constructs a new KeyboardEventArgs instance. - /// </summary> - public KeyboardKeyEventArgs(Key _key, bool _repeat, KeyboardState _state) - { - key = _key; - repeat = _repeat; - state = _state; - } - - /// <summary> - /// Constructs a new KeyboardEventArgs instance. - /// </summary> - /// <param name="args">An existing KeyboardEventArgs instance to clone.</param> - public KeyboardKeyEventArgs(KeyboardKeyEventArgs args) - { - Key = args.Key; - } - - #endregion - - #region Public Members - - /// <summary> - /// Gets the <see cref="Key"/> that generated this event. - /// </summary> - public Key Key - { - get { return key; } - internal set { key = value; } - } - - /// <summary> - /// Gets the scancode which generated this event. - /// </summary> - public uint ScanCode - { - get { return (uint)Key; } - } - - /// <summary> - /// Gets a value indicating whether <see cref="OpenTK.Input.KeyModifiers.Alt"/> is pressed. - /// </summary> - /// <value><c>true</c> if pressed; otherwise, <c>false</c>.</value> - public bool Alt - { - get { return state[Key.AltLeft] || state[Key.AltRight]; } - } - - /// <summary> - /// Gets a value indicating whether <see cref="OpenTK.Input.KeyModifiers.Control"/> is pressed. - /// </summary> - /// <value><c>true</c> if pressed; otherwise, <c>false</c>.</value> - public bool Control - { - get { return state[Key.ControlLeft] || state[Key.ControlRight]; } - } - - /// <summary> - /// Gets a value indicating whether <see cref="OpenTK.Input.KeyModifiers.Shift"/> is pressed. - /// </summary> - /// <value><c>true</c> if pressed; otherwise, <c>false</c>.</value> - public bool Shift - { - get { return state[Key.ShiftLeft] || state[Key.ShiftRight]; } - } - - /// <summary> - /// Gets a bitwise combination representing the <see cref="OpenTK.Input.KeyModifiers"/> - /// that are currently pressed. - /// </summary> - /// <value>The modifiers.</value> - public KeyModifiers Modifiers - { - get - { - KeyModifiers mods = 0; - mods |= Alt ? KeyModifiers.Alt : 0; - mods |= Control ? KeyModifiers.Control : 0; - mods |= Shift ? KeyModifiers.Shift : 0; - return mods; - } - } - - /// <summary> - /// Gets the current <see cref="OpenTK.Input.KeyboardState"/>. - /// </summary> - /// <value>The keyboard.</value> - public KeyboardState Keyboard - { - get { return state; } - internal set { state = value; } - } - - /// <summary> - /// Gets a <see cref="System.Boolean"/> indicating whether - /// this key event is a repeat. - /// </summary> - /// <value> - /// true, if this event was caused by the user holding down - /// a key; false, if this was caused by the user pressing a - /// key for the first time. - /// </value> - public bool IsRepeat - { - get { return repeat; } - internal set { repeat = value; } - } - - #endregion - } -} diff --git a/src/Input/KeyboardState.cs b/src/Input/KeyboardState.cs deleted file mode 100644 index e3784bc3..00000000 --- a/src/Input/KeyboardState.cs +++ /dev/null @@ -1,316 +0,0 @@ - #region License - // - // The Open Toolkit Library License - // - // Copyright (c) 2006 - 2009 the Open Toolkit library. - // - // 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. - // - #endregion - -using System; -using System.Collections.Specialized; -using System.Text; - -namespace Crow -{ - /// <summary> - /// Encapsulates the state of a Keyboard device. - /// </summary> - public struct KeyboardState : IEquatable<KeyboardState> - { - #region Fields - - // Allocate enough ints to store all keyboard keys - const int IntSize = sizeof(int); - const int NumInts = ((int)Key.LastKey + IntSize - 1) / IntSize; - // The following line triggers bogus CS0214 in gmcs 2.0.1, sigh... - unsafe fixed int Keys[NumInts]; - bool is_connected; - - #endregion - - #region Public Members - - /// <summary> - /// Gets a <see cref="System.Boolean"/> indicating whether the specified - /// <see cref="OpenTK.Input.Key"/> is pressed. - /// </summary> - /// <param name="key">The <see cref="OpenTK.Input.Key"/> to check.</param> - /// <returns>True if key is pressed; false otherwise.</returns> - public bool this[Key key] - { - get { return IsKeyDown(key); } - internal set { SetKeyState(key, value); } - } - - /// <summary> - /// Gets a <see cref="System.Boolean"/> indicating whether the specified - /// <see cref="OpenTK.Input.Key"/> is pressed. - /// </summary> - /// <param name="code">The scancode to check.</param> - /// <returns>True if code is pressed; false otherwise.</returns> - public bool this[short code] - { - get { return IsKeyDown((Key)code); } - } - - /// <summary> - /// Gets a <see cref="System.Boolean"/> indicating whether this key is down. - /// </summary> - /// <param name="key">The <see cref="OpenTK.Input.Key"/> to check.</param> - public bool IsKeyDown(Key key) - { - return ReadBit((int)key); - } - - /// <summary> - /// Gets a <see cref="System.Boolean"/> indicating whether this scan code is down. - /// </summary> - /// <param name="code">The scan code to check.</param> - public bool IsKeyDown(short code) - { - return code >= 0 && code < (short)Key.LastKey && ReadBit(code); - } - - /// <summary> - /// Gets a <see cref="System.Boolean"/> indicating whether this key is up. - /// </summary> - /// <param name="key">The <see cref="OpenTK.Input.Key"/> to check.</param> - public bool IsKeyUp(Key key) - { - return !ReadBit((int)key); - } - - /// <summary> - /// Gets a <see cref="System.Boolean"/> indicating whether this scan code is down. - /// </summary> - /// <param name="code">The scan code to check.</param> - public bool IsKeyUp(short code) - { - return !IsKeyDown(code); - } - - /// <summary> - /// Gets a <see cref="System.Boolean"/> indicating whether this keyboard - /// is connected. - /// </summary> - public bool IsConnected - { - get { return is_connected; } - internal set { is_connected = value; } - } - -#if false - // Disabled until the correct cross-platform API can be determined. - public bool IsLedOn(KeyboardLeds led) - { - return false; - } - - public bool IsLedOff(KeyboardLeds led) - { - return false; - } -#endif - - /// <summary> - /// Checks whether two <see cref="KeyboardState" /> instances are equal. - /// </summary> - /// <param name="left"> - /// A <see cref="KeyboardState"/> instance. - /// </param> - /// <param name="right"> - /// A <see cref="KeyboardState"/> instance. - /// </param> - /// <returns> - /// True if both left is equal to right; false otherwise. - /// </returns> - public static bool operator ==(KeyboardState left, KeyboardState right) - { - return left.Equals(right); - } - - /// <summary> - /// Checks whether two <see cref="KeyboardState" /> instances are not equal. - /// </summary> - /// <param name="left"> - /// A <see cref="KeyboardState"/> instance. - /// </param> - /// <param name="right"> - /// A <see cref="KeyboardState"/> instance. - /// </param> - /// <returns> - /// True if both left is not equal to right; false otherwise. - /// </returns> - public static bool operator !=(KeyboardState left, KeyboardState right) - { - return !left.Equals(right); - } - - /// <summary> - /// Compares to an object instance for equality. - /// </summary> - /// <param name="obj"> - /// The <see cref="System.Object"/> to compare to. - /// </param> - /// <returns> - /// True if this instance is equal to obj; false otherwise. - /// </returns> - public override bool Equals(object obj) - { - if (obj is KeyboardState) - { - return this == (KeyboardState)obj; - } - else - { - return false; - } - } - - /// <summary> - /// Generates a hashcode for the current instance. - /// </summary> - /// <returns> - /// A <see cref="System.Int32"/> represting the hashcode for this instance. - /// </returns> - public override int GetHashCode() - { - unsafe - { - fixed (int* k = Keys) - { - int hashcode = 0; - for (int i = 0; i < NumInts; i++) - hashcode ^= (k + i)->GetHashCode(); - return hashcode; - } - } - } - - #endregion - - #region Internal Members - - public void SetKeyState(Key key, bool down) - { - if (down) - { - EnableBit((int)key); - } - else - { - DisableBit((int)key); - } - } - - internal bool ReadBit(int offset) - { - ValidateOffset(offset); - - int int_offset = offset / 32; - int bit_offset = offset % 32; - unsafe - { - fixed (int* k = Keys) { return (*(k + int_offset) & (1 << bit_offset)) != 0u; } - } - } - - internal void EnableBit(int offset) - { - //ValidateOffset(offset); - - int int_offset = offset / 32; - int bit_offset = offset % 32; - unsafe - { - fixed (int* k = Keys) { *(k + int_offset) |= 1 << bit_offset; } - } - } - - internal void DisableBit(int offset) - { - ValidateOffset(offset); - - int int_offset = offset / 32; - int bit_offset = offset % 32; - unsafe - { - fixed (int* k = Keys) { *(k + int_offset) &= ~(1 << bit_offset); } - } - } - - internal void MergeBits(KeyboardState other) - { - unsafe - { - int* k2 = other.Keys; - fixed (int* k1 = Keys) - { - for (int i = 0; i < NumInts; i++) - *(k1 + i) |= *(k2 + i); - } - } - IsConnected |= other.IsConnected; - } - - internal void SetIsConnected(bool value) - { - IsConnected = value; - } - - #endregion - - #region Private Members - - static void ValidateOffset(int offset) - { - if (offset < 0 || offset >= NumInts * IntSize) - throw new ArgumentOutOfRangeException(); - } - - #endregion - - #region IEquatable<KeyboardState> Members - - /// <summary> - /// Compares two KeyboardState instances. - /// </summary> - /// <param name="other">The instance to compare two.</param> - /// <returns>True, if both instances are equal; false otherwise.</returns> - public bool Equals(KeyboardState other) - { - bool equal = true; - unsafe - { - int* k2 = other.Keys; - fixed (int* k1 = Keys) - { - for (int i = 0; equal && i < NumInts; i++) - equal &= *(k1 + i) == *(k2 + i); - } - } - return equal; - } - - #endregion - } -} diff --git a/src/Input/MouseButton.cs b/src/Input/MouseButton.cs deleted file mode 100644 index 92be4774..00000000 --- a/src/Input/MouseButton.cs +++ /dev/null @@ -1,92 +0,0 @@ - #region License - // - // The Open Toolkit Library License - // - // Copyright (c) 2006 - 2009 the Open Toolkit library. - // - // 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. - // - #endregion - -using System; -using System.Collections.Generic; -using System.Text; - -namespace Crow -{ - /// <summary> - /// Enumerates all possible mouse buttons. - /// </summary> - public enum MouseButton - { - /// <summary> - /// The left mouse button. - /// </summary> - Left = 0, - /// <summary> - /// The middle mouse button. - /// </summary> - Middle, - /// <summary> - /// The right mouse button. - /// </summary> - Right, - /// <summary> - /// The first extra mouse button. - /// </summary> - Button1, - /// <summary> - /// The second extra mouse button. - /// </summary> - Button2, - /// <summary> - /// The third extra mouse button. - /// </summary> - Button3, - /// <summary> - /// The fourth extra mouse button. - /// </summary> - Button4, - /// <summary> - /// The fifth extra mouse button. - /// </summary> - Button5, - /// <summary> - /// The sixth extra mouse button. - /// </summary> - Button6, - /// <summary> - /// The seventh extra mouse button. - /// </summary> - Button7, - /// <summary> - /// The eigth extra mouse button. - /// </summary> - Button8, - /// <summary> - /// The ninth extra mouse button. - /// </summary> - Button9, - /// <summary> - /// Indicates the last available mouse button. - /// </summary> - LastButton - } -} diff --git a/src/Input/MouseEventArgs.cs b/src/Input/MouseEventArgs.cs deleted file mode 100644 index cf883f13..00000000 --- a/src/Input/MouseEventArgs.cs +++ /dev/null @@ -1,375 +0,0 @@ -#region License -// -// MouseEventArgs.cs -// -// Author: -// Stefanos A. <stapostol@gmail.com> -// -// Copyright (c) 2006-2014 Stefanos Apostolopoulos -// -// 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. -// -#endregion - -using System; -#if !MINIMAL -using System.Drawing; -#endif - -namespace Crow -{ - /// <summary> - /// Defines the event data for <see cref="MouseDevice"/> events. - /// </summary> - /// <remarks> - /// <para> - /// Do not cache instances of this type outside their event handler. - /// If necessary, you can clone an instance using the - /// <see cref="MouseEventArgs(MouseEventArgs)"/> constructor. - /// </para> - /// </remarks> - public class MouseEventArgs : EventArgs - { - #region Fields - - MouseState state; - - #endregion - - #region Constructors - - /// <summary> - /// Constructs a new instance. - /// </summary> - public MouseEventArgs() - { - state.SetIsConnected(true); - } - - /// <summary> - /// Constructs a new instance. - /// </summary> - /// <param name="x">The X position.</param> - /// <param name="y">The Y position.</param> - public MouseEventArgs(int x, int y) - : this() - { - state.X = x; - state.Y = y; - } - - /// <summary> - /// Constructs a new instance. - /// </summary> - /// <param name="args">The <see cref="MouseEventArgs"/> instance to clone.</param> - public MouseEventArgs(MouseEventArgs args) - : this(args.X, args.Y) - { - } - - #endregion - - #region Protected Members - - internal void SetButton(MouseButton button, ButtonState state) - { - if (button < 0 || button > MouseButton.LastButton) - throw new ArgumentOutOfRangeException(); - - switch (state) - { - case ButtonState.Pressed: - this.state.EnableBit((int)button); - break; - - case ButtonState.Released: - this.state.DisableBit((int)button); - break; - } - } - - internal ButtonState GetButton(MouseButton button) - { - if (button < 0 || button > MouseButton.LastButton) - throw new ArgumentOutOfRangeException(); - - return - state.ReadBit((int)button) ? - ButtonState.Pressed : ButtonState.Released; - } - - #endregion - - #region Public Members - - /// <summary> - /// Gets the X position of the mouse for the event. - /// </summary> - public int X { get { return state.X; } internal set { state.X = value; } } - - /// <summary> - /// Gets the Y position of the mouse for the event. - /// </summary> - public int Y { get { return state.Y; } internal set { state.Y = value; } } - - /// <summary> - /// Gets a <see cref="System.Drawing.Point"/> representing the location of the mouse for the event. - /// </summary> - public Point Position - { - get { return new Point(state.X, state.Y); } - set - { - X = value.X; - Y = value.Y; - } - } - - /// <summary> - /// Gets the current <see cref="OpenTK.Input.MouseState"/>. - /// </summary> - public MouseState Mouse - { - get { return state; } - set { state = value; } - } - - #endregion - } - - /// <summary> - /// Defines the event data for <see cref="MouseDevice.Move"/> events. - /// </summary> - /// <remarks> - /// <para> - /// Do not cache instances of this type outside their event handler. - /// If necessary, you can clone an instance using the - /// <see cref="MouseMoveEventArgs(MouseMoveEventArgs)"/> constructor. - /// </para> - /// </remarks> - public class MouseMoveEventArgs : MouseEventArgs - { - #region Fields - - int x_delta, y_delta; - - #endregion - - #region Constructors - - /// <summary> - /// Constructs a new <see cref="MouseMoveEventArgs"/> instance. - /// </summary> - public MouseMoveEventArgs() { } - - /// <summary> - /// Constructs a new <see cref="MouseMoveEventArgs"/> instance. - /// </summary> - /// <param name="x">The X position.</param> - /// <param name="y">The Y position.</param> - /// <param name="xDelta">The change in X position produced by this event.</param> - /// <param name="yDelta">The change in Y position produced by this event.</param> - public MouseMoveEventArgs(int x, int y, int xDelta, int yDelta) - : base(x, y) - { - XDelta = xDelta; - YDelta = yDelta; - } - - /// <summary> - /// Constructs a new <see cref="MouseMoveEventArgs"/> instance. - /// </summary> - /// <param name="args">The <see cref="MouseMoveEventArgs"/> instance to clone.</param> - public MouseMoveEventArgs(MouseMoveEventArgs args) - : this(args.X, args.Y, args.XDelta, args.YDelta) - { - } - - #endregion - - #region Public Members - - /// <summary> - /// Gets the change in X position produced by this event. - /// </summary> - public int XDelta { get { return x_delta; } internal set { x_delta = value; } } - - /// <summary> - /// Gets the change in Y position produced by this event. - /// </summary> - public int YDelta { get { return y_delta; } internal set { y_delta = value; } } - - #endregion - } - - /// <summary> - /// Defines the event data for <see cref="MouseDevice.ButtonDown"/> and <see cref="MouseDevice.ButtonUp"/> events. - /// </summary> - /// <remarks> - /// <para> - /// Do not cache instances of this type outside their event handler. - /// If necessary, you can clone an instance using the - /// <see cref="MouseButtonEventArgs(MouseButtonEventArgs)"/> constructor. - /// </para> - /// </remarks> - public class MouseButtonEventArgs : MouseEventArgs - { - #region Fields - - MouseButton button; - - #endregion - - #region Constructors - - /// <summary> - /// Constructs a new <see cref="MouseButtonEventArgs"/> instance. - /// </summary> - public MouseButtonEventArgs() { } - - /// <summary> - /// Constructs a new <see cref="MouseButtonEventArgs"/> instance. - /// </summary> - /// <param name="x">The X position.</param> - /// <param name="y">The Y position.</param> - /// <param name="button">The mouse button for the event.</param> - /// <param name="pressed">The current state of the button.</param> - public MouseButtonEventArgs(int x, int y, MouseButton button, bool pressed) - : base(x, y) - { - this.button = button; - this.IsPressed = pressed; - } - - public MouseButtonEventArgs(MouseButton button) - : base() - { - this.button = button; - } - - /// <summary> - /// Constructs a new <see cref="MouseButtonEventArgs"/> instance. - /// </summary> - /// <param name="args">The <see cref="MouseButtonEventArgs"/> instance to clone.</param> - public MouseButtonEventArgs(MouseButtonEventArgs args) - : this(args.X, args.Y, args.Button, args.IsPressed) - { - } - - #endregion - - #region Public Members - - /// <summary> - /// Gets the <see cref="MouseButton"/> that triggered this event. - /// </summary> - public MouseButton Button { get { return button; } internal set { button = value; } } - - /// <summary> - /// Gets a System.Boolean representing the state of the mouse button for the event. - /// </summary> - public bool IsPressed - { - get { return GetButton(Button) == ButtonState.Pressed; } - internal set { SetButton(Button, value ? ButtonState.Pressed : ButtonState.Released); } - } - - #endregion - } - - /// <summary> - /// Defines the event data for <see cref="MouseDevice.WheelChanged"/> events. - /// </summary> - /// <remarks> - /// <para> - /// Do not cache instances of this type outside their event handler. - /// If necessary, you can clone an instance using the - /// <see cref="MouseWheelEventArgs(MouseWheelEventArgs)"/> constructor. - /// </para> - /// </remarks> - public class MouseWheelEventArgs : MouseEventArgs - { - #region Fields - - float delta; - - #endregion - - #region Constructors - - /// <summary> - /// Constructs a new <see cref="MouseWheelEventArgs"/> instance. - /// </summary> - public MouseWheelEventArgs() { } - - /// <summary> - /// Constructs a new <see cref="MouseWheelEventArgs"/> instance. - /// </summary> - /// <param name="x">The X position.</param> - /// <param name="y">The Y position.</param> - /// <param name="value">The value of the wheel.</param> - /// <param name="delta">The change in value of the wheel for this event.</param> - public MouseWheelEventArgs(int x, int y, int value, int delta) - : base(x, y) - { - Mouse.SetScrollAbsolute(Mouse.Scroll.X, value); - this.delta = delta; - } - - /// <summary> - /// Constructs a new <see cref="MouseWheelEventArgs"/> instance. - /// </summary> - /// <param name="args">The <see cref="MouseWheelEventArgs"/> instance to clone.</param> - public MouseWheelEventArgs(MouseWheelEventArgs args) - : this(args.X, args.Y, args.Value, args.Delta) - { - } - - #endregion - - #region Public Members - - /// <summary> - /// Gets the value of the wheel in integer units. - /// To support high-precision mice, it is recommended to use <see cref="ValuePrecise"/> instead. - /// </summary> - public int Value { get { return (int)Math.Round(Mouse.Scroll.Y, MidpointRounding.AwayFromZero); } } - - /// <summary> - /// Gets the change in value of the wheel for this event in integer units. - /// To support high-precision mice, it is recommended to use <see cref="DeltaPrecise"/> instead. - /// </summary> - public int Delta { get { return (int)Math.Round(delta, MidpointRounding.AwayFromZero); } } - - /// <summary> - /// Gets the precise value of the wheel in floating-point units. - /// </summary> - public float ValuePrecise - { - get { return Mouse.Scroll.Y; } - } - - /// <summary> - /// Gets the precise change in value of the wheel for this event in floating-point units. - /// </summary> - public float DeltaPrecise { get { return delta; } internal set { delta = value; } } - - #endregion - } -} diff --git a/src/Input/MouseScroll.cs b/src/Input/MouseScroll.cs deleted file mode 100644 index a04e9d69..00000000 --- a/src/Input/MouseScroll.cs +++ /dev/null @@ -1,118 +0,0 @@ -#region License -// -// MouseWheel.cs -// -// Author: -// Stefanos A. <stapostol@gmail.com> -// -// Copyright (c) 2006-2014 Stefanos Apostolopoulos -// -// 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. -// -#endregion - -using System; - -namespace Crow -{ - /// <summary> - /// Represents the state of a mouse wheel. - /// </summary> - public struct MouseScroll : IEquatable<MouseScroll> - { - #region Public Members - - /// <summary> - /// Gets the absolute horizontal offset of the wheel, - /// or 0 if no horizontal scroll wheel exists. - /// </summary> - /// <value>The x.</value> - public float X { get; internal set; } - - /// <summary> - /// Gets the absolute vertical offset of the wheel, - /// or 0 if no vertical scroll wheel exists. - /// </summary> - /// <value>The y.</value> - public float Y { get; internal set; } - - /// <param name="left">A <see cref="MouseScroll"/> instance to test for equality.</param> - /// <param name="right">A <see cref="MouseScroll"/> instance to test for equality.</param> - public static bool operator ==(MouseScroll left, MouseScroll right) - { - return left.Equals(right); - } - - /// <param name="left">A <see cref="MouseScroll"/> instance to test for inequality.</param> - /// <param name="right">A <see cref="MouseScroll"/> instance to test for inequality.</param> - public static bool operator !=(MouseScroll left, MouseScroll right) - { - return !left.Equals(right); - } - - /// <summary> - /// Returns a <see cref="System.String"/> that represents the current <see cref="OpenTK.Input.MouseScroll"/>. - /// </summary> - /// <returns>A <see cref="System.String"/> that represents the current <see cref="OpenTK.Input.MouseScroll"/>.</returns> - public override string ToString() - { - return string.Format("[X={0:0.00}, Y={1:0.00}]", X, Y); - } - - /// <summary> - /// Serves as a hash function for a <see cref="OpenTK.Input.MouseScroll"/> object. - /// </summary> - /// <returns>A hash code for this instance that is suitable for use in hashing algorithms and data structures such as a - /// hash table.</returns> - public override int GetHashCode() - { - return X.GetHashCode() ^ Y.GetHashCode(); - } - - /// <summary> - /// Determines whether the specified <see cref="System.Object"/> is equal to the current <see cref="OpenTK.Input.MouseScroll"/>. - /// </summary> - /// <param name="obj">The <see cref="System.Object"/> to compare with the current <see cref="OpenTK.Input.MouseScroll"/>.</param> - /// <returns><c>true</c> if the specified <see cref="System.Object"/> is equal to the current - /// <see cref="OpenTK.Input.MouseScroll"/>; otherwise, <c>false</c>.</returns> - public override bool Equals(object obj) - { - return - obj is MouseScroll && - Equals((MouseScroll)obj); - } - - #endregion - - #region IEquatable Members - - /// <summary> - /// Determines whether the specified <see cref="OpenTK.Input.MouseScroll"/> is equal to the current <see cref="OpenTK.Input.MouseScroll"/>. - /// </summary> - /// <param name="other">The <see cref="OpenTK.Input.MouseScroll"/> to compare with the current <see cref="OpenTK.Input.MouseScroll"/>.</param> - /// <returns><c>true</c> if the specified <see cref="OpenTK.Input.MouseScroll"/> is equal to the current - /// <see cref="OpenTK.Input.MouseScroll"/>; otherwise, <c>false</c>.</returns> - public bool Equals(MouseScroll other) - { - return X == other.X && Y == other.Y; - } - - #endregion - } -} diff --git a/src/Input/MouseState.cs b/src/Input/MouseState.cs deleted file mode 100644 index f6db21ea..00000000 --- a/src/Input/MouseState.cs +++ /dev/null @@ -1,362 +0,0 @@ - #region License - // - // The Open Toolkit Library License - // - // Copyright (c) 2006 - 2009 the Open Toolkit library. - // - // 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. - // - #endregion - -using System; -using System.Collections.Generic; -using System.Text; - -namespace Crow -{ - /// <summary> - /// Encapsulates the state of a mouse device. - /// </summary> - public struct MouseState : IEquatable<MouseState> - { - #region Fields - - public const int MaxButtons = 16; // we are storing in an ushort - Point position; - MouseScroll scroll; - ushort buttons; - bool is_connected; - - #endregion - - - - #region Public Members - - /// <summary> - /// Gets a <see cref="System.Boolean"/> indicating whether the specified - /// <see cref="OpenTK.Input.MouseButton"/> is pressed. - /// </summary> - /// <param name="button">The <see cref="OpenTK.Input.MouseButton"/> to check.</param> - /// <returns>True if key is pressed; false otherwise.</returns> - public bool this[MouseButton button] - { - get { return IsButtonDown(button); } - internal set - { - if (value) - EnableBit((int)button); - else - DisableBit((int)button); - } - } - - /// <summary> - /// Gets a <see cref="System.Boolean"/> indicating whether this button is down. - /// </summary> - /// <param name="button">The <see cref="OpenTK.Input.MouseButton"/> to check.</param> - public bool IsButtonDown(MouseButton button) - { - return ReadBit((int)button); - } - - /// <summary> - /// Gets a <see cref="System.Boolean"/> indicating whether this button is up. - /// </summary> - /// <param name="button">The <see cref="OpenTK.Input.MouseButton"/> to check.</param> - public bool IsButtonUp(MouseButton button) - { - return !ReadBit((int)button); - } - - /// <summary> - /// Gets the absolute wheel position in integer units. - /// To support high-precision mice, it is recommended to use <see cref="WheelPrecise"/> instead. - /// </summary> - public int Wheel - { - get { return (int)Math.Round(scroll.Y, MidpointRounding.AwayFromZero); } - } - - /// <summary> - /// Gets the absolute wheel position in floating-point units. - /// </summary> - public float WheelPrecise - { - get { return scroll.Y; } - } - - /// <summary> - /// Gets a <see cref="OpenTK.Input.MouseScroll"/> instance, - /// representing the current state of the mouse scroll wheel. - /// </summary> - public MouseScroll Scroll - { - get { return scroll; } - } - - /// <summary> - /// Gets an integer representing the absolute x position of the pointer, in window pixel coordinates. - /// </summary> - public int X - { - get { return position.X; } - set { position.X = value; } - } - - /// <summary> - /// Gets an integer representing the absolute y position of the pointer, in window pixel coordinates. - /// </summary> - public int Y - { - get { return position.Y; } - set { position.Y = value; } - } - - /// <summary> - /// Gets a <see cref="System.Boolean"/> indicating whether the left mouse button is pressed. - /// This property is intended for XNA compatibility. - /// </summary> - public ButtonState LeftButton - { - get { return IsButtonDown(MouseButton.Left) ? ButtonState.Pressed : ButtonState.Released; } - } - - /// <summary> - /// Gets a <see cref="System.Boolean"/> indicating whether the middle mouse button is pressed. - /// This property is intended for XNA compatibility. - /// </summary> - public ButtonState MiddleButton - { - get { return IsButtonDown(MouseButton.Middle) ? ButtonState.Pressed : ButtonState.Released; } - } - - /// <summary> - /// Gets a <see cref="System.Boolean"/> indicating whether the right mouse button is pressed. - /// This property is intended for XNA compatibility. - /// </summary> - public ButtonState RightButton - { - get { return IsButtonDown(MouseButton.Right) ? ButtonState.Pressed : ButtonState.Released; } - } - - /// <summary> - /// Gets a <see cref="System.Boolean"/> indicating whether the first extra mouse button is pressed. - /// This property is intended for XNA compatibility. - /// </summary> - public ButtonState XButton1 - { - get { return IsButtonDown(MouseButton.Button1) ? ButtonState.Pressed : ButtonState.Released; } - } - - /// <summary> - /// Gets a <see cref="System.Boolean"/> indicating whether the second extra mouse button is pressed. - /// This property is intended for XNA compatibility. - /// </summary> - public ButtonState XButton2 - { - get { return IsButtonDown(MouseButton.Button2) ? ButtonState.Pressed : ButtonState.Released; } - } - - /// <summary> - /// Gets the absolute wheel position in integer units. This property is intended for XNA compatibility. - /// To support high-precision mice, it is recommended to use <see cref="WheelPrecise"/> instead. - /// </summary> - public int ScrollWheelValue - { - get { return Wheel; } - } - - /// <summary> - /// Gets a value indicating whether this instance is connected. - /// </summary> - /// <value><c>true</c> if this instance is connected; otherwise, <c>false</c>.</value> - public bool IsConnected - { - get { return is_connected; } - internal set { is_connected = value; } - } - - /// <summary> - /// Checks whether two <see cref="MouseState" /> instances are equal. - /// </summary> - /// <param name="left"> - /// A <see cref="MouseState"/> instance. - /// </param> - /// <param name="right"> - /// A <see cref="MouseState"/> instance. - /// </param> - /// <returns> - /// True if both left is equal to right; false otherwise. - /// </returns> - public static bool operator ==(MouseState left, MouseState right) - { - return left.Equals(right); - } - - /// <summary> - /// Checks whether two <see cref="MouseState" /> instances are not equal. - /// </summary> - /// <param name="left"> - /// A <see cref="MouseState"/> instance. - /// </param> - /// <param name="right"> - /// A <see cref="MouseState"/> instance. - /// </param> - /// <returns> - /// True if both left is not equal to right; false otherwise. - /// </returns> - public static bool operator !=(MouseState left, MouseState right) - { - return !left.Equals(right); - } - - /// <summary> - /// Compares to an object instance for equality. - /// </summary> - /// <param name="obj"> - /// The <see cref="System.Object"/> to compare to. - /// </param> - /// <returns> - /// True if this instance is equal to obj; false otherwise. - /// </returns> - public override bool Equals(object obj) - { - if (obj is MouseState) - { - return this == (MouseState)obj; - } - else - { - return false; - } - } - - /// <summary> - /// Generates a hashcode for the current instance. - /// </summary> - /// <returns> - /// A <see cref="System.Int32"/> represting the hashcode for this instance. - /// </returns> - public override int GetHashCode() - { - return buttons.GetHashCode() ^ X.GetHashCode() ^ Y.GetHashCode() ^ scroll.GetHashCode(); - } - - /// <summary> - /// Returns a <see cref="System.String"/> that represents the current <see cref="OpenTK.Input.MouseState"/>. - /// </summary> - /// <returns>A <see cref="System.String"/> that represents the current <see cref="OpenTK.Input.MouseState"/>.</returns> - public override string ToString() - { - string b = Convert.ToString(buttons, 2).PadLeft(10, '0'); - return String.Format("[X={0}, Y={1}, Scroll={2}, Buttons={3}, IsConnected={4}]", - X, Y, Scroll, b, IsConnected); - } - - #endregion - - #region Internal Members - - internal Point Position - { - get { return position; } - set { position = value; } - } - - internal bool ReadBit(int offset) - { - ValidateOffset(offset); - return (buttons & (1 << offset)) != 0; - } - - public void EnableBit(int offset) - { - ValidateOffset(offset); - buttons |= unchecked((ushort)(1 << offset)); - } - - public void DisableBit(int offset) - { - ValidateOffset(offset); - buttons &= unchecked((ushort)(~(1 << offset))); - } - - internal void MergeBits(MouseState other) - { - buttons |= other.buttons; - SetScrollRelative(other.scroll.X, other.scroll.Y); - X += other.X; - Y += other.Y; - IsConnected |= other.IsConnected; - } - - internal void SetIsConnected(bool value) - { - IsConnected = value; - } - - #region Internal Members - - internal void SetScrollAbsolute(float x, float y) - { - scroll.X = x; - scroll.Y = y; - } - - internal void SetScrollRelative(float x, float y) - { - scroll.X += x; - scroll.Y += y; - } - - #endregion - - #endregion - - #region Private Members - - static void ValidateOffset(int offset) - { - if (offset < 0 || offset >= 16) - throw new ArgumentOutOfRangeException("offset"); - } - - #endregion - - #region IEquatable<MouseState> Members - - /// <summary> - /// Compares two MouseState instances. - /// </summary> - /// <param name="other">The instance to compare two.</param> - /// <returns>True, if both instances are equal; false otherwise.</returns> - public bool Equals(MouseState other) - { - return - buttons == other.buttons && - X == other.X && - Y == other.Y && - Scroll == other.Scroll; - } - - #endregion - } -} diff --git a/src/Instantiator.cs b/src/Instantiator.cs deleted file mode 100644 index 001832b1..00000000 --- a/src/Instantiator.cs +++ /dev/null @@ -1,1197 +0,0 @@ -// -// Instantiator.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Threading; -using System.IO; -using System.Text; -using System.Diagnostics; -using System.Xml; -using System.Reflection.Emit; -using System.Reflection; -using System.Collections.Generic; -using System.Linq; -using Crow.IML; - -namespace Crow.IML -{ - public class InstantiatorException : Exception { - public string Path; - public InstantiatorException (string path, Exception innerException) - : base ("ITor error:" + path, innerException){ - Path = path; - } - } - public delegate object InstanciatorInvoker(Interface iface); - - /// <summary> - /// Reflexion being very slow, the settings of the starting values for widgets are set by a dynamic method. - /// This method is created on the first instacing and is recalled for further widget instancing. - /// - /// It includes: - /// - XML values setting - /// - Default values (appearing as attribute in C#) loading - /// - Styling - /// - /// Instantiators are shared amongs interfaces. Their are stored with their path as key, and inlined template - /// and itemtemplate are stored with a generated uuid - /// </summary> - public class Instantiator - { - #region Dynamic Method ID generation - static long curId = 0; - internal static long NewId { - get { return curId++; } - } - #endregion - - public Type RootType; - InstanciatorInvoker loader; - protected Interface iface; - - internal string sourcePath; - - #if DESIGN_MODE - public static int NextInstantiatorID = 0; - public int currentInstantiatorID = 0; - int currentDesignID = 0; - internal string NextDesignID { get { return string.Format ("{0}_{1}",currentInstantiatorID, currentDesignID++); }} - #endif - - #region CTOR - /// <summary> - /// Initializes a new instance of the Instantiator class. - /// </summary> - public Instantiator (Interface _iface, string path) : this (_iface, _iface.GetStreamFromPath(path), path) { - - } - /// <summary> - /// Initializes a new instance of the Instantiator class. - /// </summary> - public Instantiator (Interface _iface, Stream stream, string srcPath = null) - { - #if DESIGN_MODE - currentInstantiatorID = NextInstantiatorID++; - #endif - iface = _iface; - sourcePath = srcPath; - #if DEBUG_LOAD - Stopwatch loadingTime = new Stopwatch (); - loadingTime.Start (); - #endif - try { - using (XmlReader itr = XmlReader.Create (stream)) { - parseIML (itr); - } - stream.Dispose (); - } catch (Exception ex) { - throw new InstantiatorException(sourcePath, ex); - } finally { - #if DEBUG_LOAD - loadingTime.Stop (); - Debug.WriteLine ("IML Instantiator creation '{2}' : {0} ticks, {1} ms", - loadingTime.ElapsedTicks, loadingTime.ElapsedMilliseconds, sourcePath); - #endif - } - } - /// <summary> - /// Initializes a new instance of the Instantiator class with an already openned xml reader - /// positionned on the start tag inside the itemTemplate - /// </summary> - public Instantiator (Interface _iface, XmlReader itr){ - #if DESIGN_MODE - currentInstantiatorID = NextInstantiatorID++; - #endif - iface = _iface; - parseIML (itr); - } - //TODO:check if still used - public Instantiator (Interface _iface, Type _root, InstanciatorInvoker _loader) - { - #if DESIGN_MODE - currentInstantiatorID = NextInstantiatorID++; - #endif - iface = _iface; - RootType = _root; - loader = _loader; - } - /// <summary> - /// Create a new instantiator from IML fragment provided directely as a string - /// </summary> - /// <returns>A new instantiator</returns> - /// <param name="fragment">IML string</param> - public static Instantiator CreateFromImlFragment (Interface _iface, string fragment) - { - using (Stream s = new MemoryStream (Encoding.UTF8.GetBytes (fragment))) { - return new Instantiator (_iface, s); - } - } - #endregion - - /// <summary> - /// Creates a new instance of the GraphicObject compiled in the instantiator - /// and bind it the an interface - /// </summary> - /// <returns>The new graphic object instance</returns> - /// <param name="iface">The interface to bind to</param> - public GraphicObject CreateInstance(){ - return loader (iface) as GraphicObject; - } - /// <summary> - /// Creates a new instance of T compiled in the instantiator - /// and bind it the an interface - /// </summary> - /// <returns>The new T instance</returns> - /// <param name="iface">The interface to bind to</param> - public T CreateInstance<T>(){ - return (T)loader (iface); - } - List<DynamicMethod> dsValueChangedDynMeths = new List<DynamicMethod>(); - List<Delegate> cachedDelegates = new List<Delegate>(); - /// <summary> - /// store indices of template delegate to be handled by root parentChanged event - /// </summary> - List<int> templateCachedDelegateIndices = new List<int>(); - /// <summary> - /// Store template bindings in the instantiator - /// </summary> - Delegate templateBinding; - - #region IML parsing - /// <summary> - /// Parses IML and build a dynamic method that will be used to instantiate one or multiple occurences of the IML file or fragment - /// </summary> - void parseIML (XmlReader reader) { - IMLContext ctx = new IMLContext (findRootType (reader)); - - ctx.nodesStack.Push (new Node (ctx.RootType)); - emitLoader (reader, ctx); - ctx.nodesStack.Pop (); - - foreach (int idx in templateCachedDelegateIndices) - ctx.emitCachedDelegateHandlerAddition(idx, CompilerServices.eiLogicalParentChanged); - - ctx.ResolveNamedTargets (); - - emitBindingDelegates (ctx); - - ctx.il.Emit (OpCodes.Ldloc_0);//load root obj to return - ctx.il.Emit(OpCodes.Ret); - - reader.Read ();//close tag - RootType = ctx.RootType; - loader = (InstanciatorInvoker)ctx.dm.CreateDelegate (typeof (InstanciatorInvoker), this); - } - /// <summary> - /// read first node to set GraphicObject class for loading - /// and let reader position on that node - /// </summary> - Type findRootType (XmlReader reader) - { - string root = "Object"; - while (reader.NodeType != XmlNodeType.Element) - reader.Read (); - root = reader.Name; - Type t = tryGetGOType (root); - if (t == null) - throw new Exception ("IML parsing error: undefined root type (" + root + ")"); - return t; - } - /// <summary> - /// main parsing entry point - /// </summary> - void emitLoader (XmlReader reader, IMLContext ctx) - { - int curLine = ctx.curLine; - - #if DESIGN_MODE - IXmlLineInfo li = (IXmlLineInfo)reader; - ctx.curLine += li.LineNumber - 1; - #endif - - string tmpXml = reader.ReadOuterXml (); - - if (ctx.nodesStack.Peek().HasTemplate) - emitTemplateLoad (ctx, tmpXml); - - emitGOLoad (ctx, tmpXml); - - ctx.curLine = curLine; - //emitCheckAndBindValueChanged (ctx); - } - /// <summary> - /// Parses the item template tag. - /// </summary> - /// <returns>the string triplet dataType, itemTmpID read as attribute of this tag</returns> - /// <param name="reader">current xml text reader</param> - /// <param name="itemTemplatePath">file containing the templates if its a dedicated one</param> - string[] parseItemTemplateTag (XmlReader reader, string itemTemplatePath = "") { - string dataType = "default", datas = "", path = "", dataTest = "TypeOf"; - while (reader.MoveToNextAttribute ()) { - if (reader.Name == "DataType") - dataType = reader.Value; - else if (reader.Name == "Data") - datas = reader.Value; - else if (reader.Name == "Path") - path = reader.Value; - else if (reader.Name == "DataTest") - dataTest = reader.Value; - } - reader.MoveToElement (); - - string itemTmpID = itemTemplatePath; - - if (string.IsNullOrEmpty (path)) { - itemTmpID += Guid.NewGuid ().ToString (); - iface.Instantiators [itemTmpID] = - new ItemTemplate (iface, new MemoryStream (Encoding.UTF8.GetBytes (reader.ReadInnerXml ())), dataTest, dataType, datas); - - } else { - if (!reader.IsEmptyElement) - throw new Exception ("ItemTemplate with Path attribute set may not include sub nodes"); - itemTmpID += path+dataType+datas; - if (!iface.Instantiators.ContainsKey (itemTmpID)) - iface.Instantiators [itemTmpID] = - new ItemTemplate (iface, path, dataTest, dataType, datas); - } - return new string [] { dataType, itemTmpID, datas, dataTest }; - } - /// <summary> - /// process template and item template definition prior to - /// other attributes or childs processing - /// </summary> - /// <param name="ctx">Loading Context</param> - /// <param name="tmpXml">xml fragment</param> - void emitTemplateLoad (IMLContext ctx, string tmpXml) { - //if its a template, first read template elements - using (XmlTextReader reader = new XmlTextReader (tmpXml, XmlNodeType.Element, null)) { - List<string[]> itemTemplateIds = new List<string[]> (); - bool inlineTemplate = false; - - reader.Read (); - string templatePath = reader.GetAttribute ("Template"); - string itemTemplatePath = reader.GetAttribute ("ItemTemplate"); - - int depth = reader.Depth + 1; - while (reader.Read ()) { - if (!reader.IsStartElement () || reader.Depth > depth) - continue; - if (reader.Name == "Template") { - inlineTemplate = true; - #if DESIGN_MODE - ctx.il.Emit (OpCodes.Ldloc_0); - ctx.il.Emit (OpCodes.Ldc_I4_1); - ctx.il.Emit (OpCodes.Stfld, typeof(TemplatedControl).GetField("design_inlineTemplate")); - #endif - reader.Read (); - readChildren (reader, ctx, -1); - } else if (reader.Name == "ItemTemplate") - itemTemplateIds.Add (parseItemTemplateTag (reader)); - } - - if (!inlineTemplate) {//load from path or default template - ctx.il.Emit (OpCodes.Ldloc_0);//Load current templatedControl ref - if (string.IsNullOrEmpty (templatePath)) { - ctx.il.Emit (OpCodes.Ldnull);//default template loading - } else { - ctx.il.Emit (OpCodes.Ldarg_1);//load currentInterface - ctx.il.Emit (OpCodes.Ldstr, templatePath); //Load template path string - ctx.il.Emit (OpCodes.Callvirt,//call Interface.Load(path) - CompilerServices.miIFaceLoad); - } - ctx.il.Emit (OpCodes.Callvirt, CompilerServices.miLoadTmp);//load template - } - if (itemTemplateIds.Count == 0) { - //try to load ItemTemplate(s) from ItemTemplate attribute of TemplatedGroup - if (!string.IsNullOrEmpty (itemTemplatePath)) { - //check if it is already loaded in cache as a single itemTemplate instantiator - if (iface.Instantiators.ContainsKey (itemTemplatePath)) { - itemTemplateIds.Add (new string [] { "default", itemTemplatePath, "" }); - } else { - using (Stream stream = iface.GetStreamFromPath (itemTemplatePath)) { - //itemtemplate files may have multiple root nodes - XmlReaderSettings itrSettings = new XmlReaderSettings { ConformanceLevel = ConformanceLevel.Fragment }; - using (XmlReader itr = XmlReader.Create (stream, itrSettings)) { - while (itr.Read ()) { - if (!itr.IsStartElement ()) - continue; - if (itr.NodeType == XmlNodeType.Element) { - if (itr.Name != "ItemTemplate") { - //the file contains a single template to use as default - iface.Instantiators [itemTemplatePath] = - new ItemTemplate (iface, itr); - itemTemplateIds.Add (new string [] { "default", itemTemplatePath, "", "TypeOf" }); - break;//we should be at the end of the file - } - itemTemplateIds.Add (parseItemTemplateTag (itr, itemTemplatePath)); - } - } - } - } - } - } - } - if (!ctx.nodesStack.Peek ().IsTemplatedGroup) - return; - //add the default item template if no default is defined - if (!itemTemplateIds.Any(ids=>ids[0] == "default")) - itemTemplateIds.Add (new string [] { "default", "#Crow.DefaultItem.template", "", "TypeOf"}); - //get item templates - foreach (string [] iTempId in itemTemplateIds) { - ctx.il.Emit (OpCodes.Ldloc_0);//load TempControl ref - ctx.il.Emit (OpCodes.Ldfld, CompilerServices.fldItemTemplates);//load ItemTemplates dic field - - //prepare argument to add itemTemplate to templated group dic of ItemTemplates - ctx.il.Emit (OpCodes.Ldstr, iTempId [0]);//load key - //load itemTemplate - ctx.il.Emit (OpCodes.Ldarg_1);//load currentInterface - ctx.il.Emit (OpCodes.Ldstr, iTempId [1]);//load path - ctx.il.Emit (OpCodes.Callvirt, CompilerServices.miGetITemp); - ctx.il.Emit (OpCodes.Callvirt, CompilerServices.miAddITemp); - - if (!string.IsNullOrEmpty (iTempId [2])) { - //expand delegate creation - ctx.il.Emit (OpCodes.Ldloc_0);//load TempControl ref - ctx.il.Emit (OpCodes.Ldfld, CompilerServices.fldItemTemplates); - ctx.il.Emit (OpCodes.Ldstr, iTempId [0]);//load key - ctx.il.Emit (OpCodes.Callvirt, CompilerServices.miGetITempFromDic); - ctx.il.Emit (OpCodes.Ldloc_0);//load root of treeView - ctx.il.Emit (OpCodes.Callvirt, CompilerServices.miCreateExpDel); - } - } - } - } - - #if DESIGN_MODE - void emitSetDesignAttribute (IMLContext ctx, string name, string value){ - //store member value in iml - ctx.il.Emit (OpCodes.Ldloc_0); - ctx.il.Emit (OpCodes.Ldfld, typeof(GraphicObject).GetField("design_iml_values")); - ctx.il.Emit (OpCodes.Ldstr, name); - if (string.IsNullOrEmpty (value)) - ctx.il.Emit (OpCodes.Ldnull); - else - ctx.il.Emit (OpCodes.Ldstr, value); - ctx.il.Emit (OpCodes.Call, CompilerServices.miDicStrStrAdd); - } - #endif - - /// <summary> - /// process styling, attributes and children loading. - /// </summary> - /// <param name="ctx">parsing context</param> - /// <param name="tmpXml">xml fragment</param> - void emitGOLoad (IMLContext ctx, string tmpXml) { - using (XmlTextReader reader = new XmlTextReader (tmpXml, XmlNodeType.Element, null)) { - reader.Read (); - - #if DESIGN_MODE - IXmlLineInfo li = (IXmlLineInfo)reader; - ctx.il.Emit (OpCodes.Ldloc_0); - ctx.il.Emit (OpCodes.Ldstr, this.NextDesignID); - ctx.il.Emit (OpCodes.Stfld, typeof(GraphicObject).GetField("design_id")); - ctx.il.Emit (OpCodes.Ldloc_0); - ctx.il.Emit (OpCodes.Ldc_I4, ctx.curLine + li.LineNumber); - ctx.il.Emit (OpCodes.Stfld, typeof(GraphicObject).GetField("design_line")); - ctx.il.Emit (OpCodes.Ldloc_0); - ctx.il.Emit (OpCodes.Ldc_I4, li.LinePosition); - ctx.il.Emit (OpCodes.Stfld, typeof(GraphicObject).GetField("design_column")); - if (!string.IsNullOrEmpty (sourcePath)) { - ctx.il.Emit (OpCodes.Ldloc_0); - ctx.il.Emit (OpCodes.Ldstr, sourcePath); - ctx.il.Emit (OpCodes.Stfld, typeof(GraphicObject).GetField("design_imlPath")); - } - #endif - - #region Styling and default values loading - //first check for Style attribute then trigger default value loading - if (reader.HasAttributes) { - string style = reader.GetAttribute ("Style"); - if (!string.IsNullOrEmpty (style)){ - CompilerServices.EmitSetValue (ctx.il, CompilerServices.piStyle, style); - #if DESIGN_MODE - emitSetDesignAttribute (ctx, "Style", style); - #endif - } - } - ctx.il.Emit (OpCodes.Ldloc_0); - ctx.il.Emit (OpCodes.Callvirt, CompilerServices.miLoadDefaultVals); - #endregion - - #region Attributes reading - if (reader.HasAttributes) { - - while (reader.MoveToNextAttribute ()) { - if (reader.Name == "Style") - continue; - - #if DESIGN_MODE - emitSetDesignAttribute (ctx, reader.Name, reader.Value); - #endif - - MemberInfo mi = ctx.CurrentNodeType.GetMember (reader.Name).FirstOrDefault (); - if (mi == null) - throw new Exception ("Member '" + reader.Name + "' not found in " + ctx.CurrentNodeType.Name); - - if (mi.MemberType == MemberTypes.Event) { - foreach (string exp in CompilerServices.splitOnSemiColumnOutsideAccolades(reader.Value)) { - string trimed = exp.Trim(); - if (trimed.StartsWith ("{", StringComparison.OrdinalIgnoreCase)) - compileAndStoreDynHandler (ctx, mi as EventInfo, trimed.Substring (1, trimed.Length - 2)); - else - emitHandlerBinding (ctx, mi as EventInfo, trimed); - } - - continue; - } - PropertyInfo pi = mi as PropertyInfo; - if (pi == null) - throw new Exception ("Member '" + reader.Name + "' is not a property in " + ctx.CurrentNodeType.Name); - - if (pi.Name == "Name") - ctx.StoreCurrentName (reader.Value); - - if (reader.Value.StartsWith ("{", StringComparison.OrdinalIgnoreCase)) - readPropertyBinding (ctx, reader.Name, reader.Value.Substring (1, reader.Value.Length - 2)); - else - CompilerServices.EmitSetValue (ctx.il, pi, reader.Value); - - } - reader.MoveToElement (); - } - #endregion - - readChildren (reader, ctx); - - ctx.nodesStack.ResetCurrentNodeIndex (); - } - } - /// <summary> - /// Parse child node an generate corresponding msil - /// </summary> - void readChildren (XmlTextReader reader, IMLContext ctx, int startingIdx = 0) - { - bool endTagReached = false; - int nodeIdx = startingIdx; - while (reader.Read ()) { - switch (reader.NodeType) { - case XmlNodeType.EndElement: - endTagReached = true; - break; - case XmlNodeType.Element: - //skip Templates - if (reader.Name == "Template" || - reader.Name == "ItemTemplate") { - reader.Skip (); - continue; - } - - //push 2x current instance on stack for parenting and reseting loc0 to parent - //loc_0 will be used for child - ctx.il.Emit (OpCodes.Ldloc_0); - ctx.il.Emit (OpCodes.Ldloc_0); - - Type t = tryGetGOType (reader.Name); - if (t == null) - throw new Exception (reader.Name + " type not found"); - ConstructorInfo ci = t.GetConstructor ( - BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, - null, Type.EmptyTypes, null); - if (ci == null) - throw new Exception ("No default parameterless constructor found in " + t.Name); - ctx.il.Emit (OpCodes.Newobj, ci); - ctx.il.Emit (OpCodes.Stloc_0);//child is now loc_0 - CompilerServices.emitSetCurInterface (ctx.il); - - ctx.nodesStack.Push (new Node (t, nodeIdx)); - emitLoader (reader, ctx); - ctx.nodesStack.Pop (); - - ctx.il.Emit (OpCodes.Ldloc_0);//load child on stack for parenting - ctx.il.Emit (OpCodes.Callvirt, ctx.nodesStack.Peek().GetAddMethod(nodeIdx)); - ctx.il.Emit (OpCodes.Stloc_0); //reset local to current go - - nodeIdx++; - - break; - } - if (endTagReached) - break; - } - } - #endregion - - void readPropertyBinding (IMLContext ctx, string sourceMember, string expression) - { - NodeAddress sourceNA = ctx.CurrentNodeAddress; - BindingDefinition bindingDef = sourceNA.GetBindingDef (sourceMember, expression); - - #if DEBUG_BINDING - Debug.WriteLine("Property Binding: " + bindingDef.ToString()); - #endif - - if (bindingDef.IsDataSourceBinding)//bind on data source - emitDataSourceBindings (ctx, bindingDef); - else - ctx.StorePropertyBinding (bindingDef); - } - - #region Emit Helper - void dataSourceChangedEmitHelper(object dscSource, object dataSource, int dynMethIdx){ - if (dataSource is IValueChange) - (dataSource as IValueChange).ValueChanged += - (EventHandler<ValueChangeEventArgs>)dsValueChangedDynMeths [dynMethIdx].CreateDelegate (typeof(EventHandler<ValueChangeEventArgs>), dscSource); - } - /// <summary> Emits remove old data source event handler./summary> - void emitRemoveOldDataSourceHandler(ILGenerator il, string eventName, string delegateName, bool DSSide = true){ - System.Reflection.Emit.Label cancel = il.DefineLabel (); - - il.Emit (OpCodes.Ldarg_2);//load old parent - il.Emit (OpCodes.Ldfld, CompilerServices.fiDSCOldDS); - il.Emit (OpCodes.Brfalse, cancel);//old parent is null - - //remove handler - if (DSSide){//event is defined in the dataSource instance - il.Emit (OpCodes.Ldarg_2);//1st arg load old datasource - il.Emit (OpCodes.Ldfld, CompilerServices.fiDSCOldDS); - }else//the event is in the source - il.Emit (OpCodes.Ldarg_1);//1st arg load old datasource - il.Emit (OpCodes.Ldstr, eventName);//2nd arg event name - il.Emit (OpCodes.Ldstr, delegateName);//3d arg: delegate name - il.Emit (OpCodes.Call, CompilerServices.miRemEvtHdlByName); - il.MarkLabel(cancel); - } - #endregion - - #region Event Bindings - /// <summary> - /// Compile events expression in IML attributes, and store the result in the instanciator - /// Those handlers will be bound when instatiing - /// </summary> - void compileAndStoreDynHandler (IMLContext ctx, EventInfo sourceEvent, string expression) - { - //store event handler dynamic method in instanciator - int dmIdx = cachedDelegates.Count; - cachedDelegates.Add (CompilerServices.compileDynEventHandler (sourceEvent, expression, ctx.CurrentNodeAddress)); - ctx.emitCachedDelegateHandlerAddition(dmIdx, sourceEvent); - } - /// <summary> Emits handler method bindings </summary> - void emitHandlerBinding (IMLContext ctx, EventInfo sourceEvent, string expression){ - NodeAddress currentNode = ctx.CurrentNodeAddress; - BindingDefinition bindingDef = currentNode.GetBindingDef (sourceEvent.Name, expression); - - #if DEBUG_BINDING - Debug.WriteLine("Event Binding: " + bindingDef.ToString()); - #endif - - if (bindingDef.IsTemplateBinding | bindingDef.IsDataSourceBinding) { - //we need to bind datasource method to source event - DynamicMethod dm = new DynamicMethod ("dyn_dsORtmpChangedForHandler" + NewId, - typeof(void), - CompilerServices.argsBoundDSChange, true); - - ILGenerator il = dm.GetILGenerator (256); - System.Reflection.Emit.Label cancel = il.DefineLabel (); - - il.DeclareLocal (typeof(MethodInfo));//used to cancel binding if method doesn't exist - - il.Emit (OpCodes.Nop); - - emitRemoveOldDataSourceHandler (il, sourceEvent.Name, bindingDef.TargetMember, false); - - //fetch method in datasource and test if it exist - il.Emit (OpCodes.Ldarg_2);//load new datasource - il.Emit (OpCodes.Ldfld, CompilerServices.fiDSCNewDS); - il.Emit (OpCodes.Brfalse, cancel);//cancel if new datasource is null - il.Emit (OpCodes.Ldarg_2);//load new datasource - il.Emit (OpCodes.Ldfld, CompilerServices.fiDSCNewDS); - il.Emit (OpCodes.Ldstr, bindingDef.TargetMember);//load handler method name - il.Emit (OpCodes.Call, CompilerServices.miGetMethInfoWithRefx); - il.Emit (OpCodes.Stloc_0);//save MethodInfo - il.Emit (OpCodes.Ldloc_0);//push mi for test if null - - il.Emit (OpCodes.Brfalse, cancel); - - il.Emit (OpCodes.Ldarg_1);//load datasource change source where the event is as 1st arg of handler.add - if (bindingDef.IsTemplateBinding)//fetch source instance with address - CompilerServices.emitGetInstance (il, bindingDef.SourceNA); - - //load handlerType of sourceEvent to create delegate (1st arg) - il.Emit (OpCodes.Ldtoken, sourceEvent.EventHandlerType); - il.Emit (OpCodes.Call, CompilerServices.miGetTypeFromHandle); - il.Emit (OpCodes.Ldarg_2);//load new datasource where the method is defined - il.Emit (OpCodes.Ldfld, CompilerServices.fiDSCNewDS); - il.Emit (OpCodes.Ldloc_0);//load methodInfo (3rd arg) - - il.Emit (OpCodes.Callvirt, CompilerServices.miCreateBoundDel); - il.Emit (OpCodes.Callvirt, sourceEvent.AddMethod);//call add event - - System.Reflection.Emit.Label finish = il.DefineLabel (); - il.Emit (OpCodes.Br, finish); - il.MarkLabel (cancel); - #if DEBUG_BINDING - il.EmitWriteLine (string.Format ("Handler method '{0}' for '{1}' NOT FOUND in new dataSource", bindingDef.TargetMember, sourceEvent.Name)); - #endif - il.MarkLabel (finish); - #if DEBUG_BINDING - il.EmitWriteLine (string.Format ("Handler method '{0}' for '{1}' FOUND in new dataSource", bindingDef.TargetMember, sourceEvent.Name)); - #endif - il.Emit (OpCodes.Ret); - - //store dschange delegate in instatiator instance for access while instancing graphic object - int delDSIndex = cachedDelegates.Count; - cachedDelegates.Add (dm.CreateDelegate (CompilerServices.ehTypeDSChange, this)); - - if (bindingDef.IsDataSourceBinding) - ctx.emitCachedDelegateHandlerAddition (delDSIndex, CompilerServices.eiDSChange); - else //template handler binding, will be added to root parentChanged - templateCachedDelegateIndices.Add (delDSIndex); - } else {//normal in tree handler binding, store until tree is complete (end of parse) - ctx.UnresolvedTargets.Add (new EventBinding ( - bindingDef.SourceNA, sourceEvent, - bindingDef.TargetNA, bindingDef.TargetMember, bindingDef.TargetName)); - } - } - #endregion - - #region Property Bindings - /// <summary> - /// Create and store in the instanciator the ValueChanged delegates - /// those delegates uses grtree functions to set destination value so they don't - /// need to be bound to destination instance as in the ancient system. - /// </summary> - void emitBindingDelegates(IMLContext ctx){ - foreach (KeyValuePair<NodeAddress,Dictionary<string, List<MemberAddress>>> bindings in ctx.Bindings ) { - if (bindings.Key.Count == 0)//template binding - emitTemplateBindings (ctx, bindings.Value); - else - emitPropertyBindings (ctx, bindings.Key, bindings.Value); - } - } - void emitPropertyBindings(IMLContext ctx, NodeAddress origine, Dictionary<string, List<MemberAddress>> bindings){ - Type origineNodeType = origine.NodeType; - - //value changed dyn method - DynamicMethod dm = new DynamicMethod ("dyn_valueChanged" + NewId, - typeof (void), CompilerServices.argsValueChange, true); - ILGenerator il = dm.GetILGenerator (256); - - System.Reflection.Emit.Label endMethod = il.DefineLabel (); - - il.DeclareLocal (CompilerServices.TObject); - - il.Emit (OpCodes.Nop); - - int i = 0; - foreach (KeyValuePair<string, List<MemberAddress>> bindingCase in bindings ) { - - System.Reflection.Emit.Label nextTest = il.DefineLabel (); - - #region member name test - //load source member name - il.Emit (OpCodes.Ldarg_1); - il.Emit (OpCodes.Ldfld, CompilerServices.fiVCMbName); - - il.Emit (OpCodes.Ldstr, bindingCase.Key);//load name to test - il.Emit (OpCodes.Ldc_I4_4);//StringComparison.Ordinal - il.Emit (OpCodes.Callvirt, CompilerServices.stringEquals); - il.Emit (OpCodes.Brfalse, nextTest);//if not equal, jump to next case - #endregion - - #region destination member affectations - PropertyInfo piOrig = origineNodeType.GetProperty (bindingCase.Key); - Type origineType = null; - if (piOrig != null) - origineType = piOrig.PropertyType; - foreach (MemberAddress ma in bindingCase.Value) { - //first we have to load destination instance onto the stack, it is access - //with graphic tree functions deducted from nodes topology - il.Emit (OpCodes.Ldarg_0);//load source instance of ValueChanged event - - NodeAddress destination = ma.Address; - - if (destination.Count == 0){//template reverse binding - //fetch destination instance (which is the template root) - for (int j = 0; j < origine.Count ; j++) - il.Emit(OpCodes.Callvirt, CompilerServices.miGetLogicalParent); - }else - CompilerServices.emitGetInstance (il, origine, destination); - - if (origineType != null && destination.Count > 0){//else, prop less binding or reverse template bind, no init requiered - //for initialisation dynmeth, push destination instance loc_0 is root node in ctx - ctx.il.Emit(OpCodes.Ldloc_0); - CompilerServices.emitGetInstance (ctx.il, destination); - - //init dynmeth: load actual value from origine - ctx.il.Emit (OpCodes.Ldloc_0); - CompilerServices.emitGetInstance (ctx.il, origine); - ctx.il.Emit (OpCodes.Callvirt, origineNodeType.GetProperty (bindingCase.Key).GetGetMethod()); - } - //load new value - il.Emit (OpCodes.Ldarg_1); - il.Emit (OpCodes.Ldfld, CompilerServices.fiVCNewValue); - - if (origineType == null)//property less binding, no init - CompilerServices.emitConvert (il, ma.Property.PropertyType); - else if (destination.Count > 0) { - if (origineType.IsValueType) - ctx.il.Emit(OpCodes.Box, origineType); - - CompilerServices.emitConvert (ctx.il, origineType, ma.Property.PropertyType); - CompilerServices.emitConvert (il, origineType, ma.Property.PropertyType); - - ctx.il.Emit (OpCodes.Callvirt, ma.Property.GetSetMethod());//set init value - } else {// reverse templateBinding - il.Emit (OpCodes.Ldstr, ma.memberName);//arg 3 of setValueWithReflexion - il.Emit (OpCodes.Call, CompilerServices.miSetValWithRefx); - continue; - } - il.Emit (OpCodes.Callvirt, ma.Property.GetSetMethod());//set value on value changes - } - #endregion - il.Emit (OpCodes.Br, endMethod); - il.MarkLabel (nextTest); - - i++; - } - - il.MarkLabel (endMethod); - il.Emit (OpCodes.Ret); - - //store and emit Add in ctx - int dmIdx = cachedDelegates.Count; - cachedDelegates.Add (dm.CreateDelegate (typeof(EventHandler<ValueChangeEventArgs>))); - ctx.emitCachedDelegateHandlerAddition (dmIdx, CompilerServices.eiValueChange, origine); - - #if DEBUG_BINDING - Debug.WriteLine("\tCrow property binding: " + dm.Name); - #endif - - } - void emitTemplateBindings(IMLContext ctx, Dictionary<string, List<MemberAddress>> bindings){ - //value changed dyn method - DynamicMethod dm = new DynamicMethod ("dyn_tmpValueChanged", - typeof (void), CompilerServices.argsValueChange, true); - ILGenerator il = dm.GetILGenerator (256); - - //create parentchanged dyn meth in parallel to have only one loop over bindings - DynamicMethod dmPC = new DynamicMethod ("dyn_InitAndLogicalParentChanged", - typeof (void), - CompilerServices.argsBoundDSChange, true); - ILGenerator ilPC = dmPC.GetILGenerator (256); - - il.Emit (OpCodes.Nop); - ilPC.Emit (OpCodes.Nop); - - System.Reflection.Emit.Label endMethod = il.DefineLabel (); - - il.DeclareLocal (CompilerServices.TObject); - ilPC.DeclareLocal (CompilerServices.TObject);//used for checking propery less bindings - ilPC.DeclareLocal (typeof(MemberInfo));//used for checking propery less bindings - - System.Reflection.Emit.Label cancel = ilPC.DefineLabel (); - - #region Unregister previous parent event handler - //unregister previous parent handler if not null - ilPC.Emit (OpCodes.Ldarg_2);//load old parent - ilPC.Emit (OpCodes.Ldfld, CompilerServices.fiDSCOldDS); - ilPC.Emit (OpCodes.Brfalse, cancel);//old parent is null - - ilPC.Emit (OpCodes.Ldarg_2);//load old parent - ilPC.Emit (OpCodes.Ldfld, CompilerServices.fiDSCOldDS); - //Load cached delegate - ilPC.Emit(OpCodes.Ldarg_0);//load ref to this instanciator onto the stack - ilPC.Emit(OpCodes.Ldfld, CompilerServices.fiTemplateBinding); - - //add template bindings dynValueChanged delegate to new parent event - ilPC.Emit(OpCodes.Callvirt, CompilerServices.eiValueChange.RemoveMethod);//call remove event - #endregion - - ilPC.MarkLabel(cancel); - - #region check if new parent is null - cancel = ilPC.DefineLabel (); - ilPC.Emit (OpCodes.Ldarg_2);//load datasource change arg - ilPC.Emit (OpCodes.Ldfld, CompilerServices.fiDSCNewDS); - ilPC.Emit (OpCodes.Brfalse, cancel);//new ds is null - #endregion - - int i = 0; - foreach (KeyValuePair<string, List<MemberAddress>> bindingCase in bindings ) { - - System.Reflection.Emit.Label nextTest = il.DefineLabel (); - - #region member name test - //load source member name - il.Emit (OpCodes.Ldarg_1); - il.Emit (OpCodes.Ldfld, CompilerServices.fiVCMbName); - - il.Emit (OpCodes.Ldstr, bindingCase.Key);//load name to test - il.Emit (OpCodes.Ldc_I4_4);//StringComparison.Ordinal - il.Emit (OpCodes.Callvirt, CompilerServices.stringEquals); - il.Emit (OpCodes.Brfalse, nextTest);//if not equal, jump to next case - #endregion - - #region destination member affectations - - foreach (MemberAddress ma in bindingCase.Value) { - if (ma.Address.Count == 0){ - Debug.WriteLine("\t\tBUG: reverse template binding in normal template binding"); - continue;//template binding - } - //first we try to get memberInfo of new parent, if it doesn't exist, it's a propery less binding - ilPC.Emit (OpCodes.Ldarg_2);//load new parent onto the stack for handler addition - ilPC.Emit (OpCodes.Ldfld, CompilerServices.fiDSCNewDS); - ilPC.Emit (OpCodes.Stloc_0);//save new parent - //get parent type - ilPC.Emit (OpCodes.Ldloc_0);//push parent instance - ilPC.Emit (OpCodes.Ldstr, bindingCase.Key);//load member name - ilPC.Emit (OpCodes.Call, CompilerServices.miGetMembIinfoWithRefx); - ilPC.Emit (OpCodes.Stloc_1);//save memberInfo - ilPC.Emit (OpCodes.Ldloc_1);//push mi for test if null - System.Reflection.Emit.Label propLessReturn = ilPC.DefineLabel (); - ilPC.Emit (OpCodes.Brfalse, propLessReturn); - - - //first we have to load destination instance onto the stack, it is access - //with graphic tree functions deducted from nodes topology - il.Emit (OpCodes.Ldarg_0);//load source instance of ValueChanged event - CompilerServices.emitGetChild (il, typeof(TemplatedControl), -1); - CompilerServices.emitGetInstance (il, ma.Address); - - ilPC.Emit (OpCodes.Ldarg_2);//load destination instance to set actual value of member - ilPC.Emit (OpCodes.Ldfld, CompilerServices.fiDSCNewDS); - CompilerServices.emitGetChild (ilPC, typeof(TemplatedControl), -1); - CompilerServices.emitGetInstance (ilPC, ma.Address); - - //load new value - il.Emit (OpCodes.Ldarg_1); - il.Emit (OpCodes.Ldfld, CompilerServices.fiVCNewValue); - - //for the parent changed dyn meth we need to fetch actual value for initialisation thrue reflexion - ilPC.Emit (OpCodes.Ldloc_0);//push root instance of instanciator as parentChanged source - ilPC.Emit (OpCodes.Ldloc_1);//push mi for value fetching - ilPC.Emit (OpCodes.Call, CompilerServices.miGetValWithRefx); - - CompilerServices.emitConvert (il, ma.Property.PropertyType); - CompilerServices.emitConvert (ilPC, ma.Property.PropertyType); - - il.Emit (OpCodes.Callvirt, ma.Property.GetSetMethod()); - ilPC.Emit (OpCodes.Callvirt, ma.Property.GetSetMethod()); - - ilPC.MarkLabel(propLessReturn); - } - #endregion - il.Emit (OpCodes.Br, endMethod); - il.MarkLabel (nextTest); - - i++; - } - //il.Emit (OpCodes.Pop); - il.MarkLabel (endMethod); - il.Emit (OpCodes.Ret); - - //store template bindings in instanciator - templateBinding = dm.CreateDelegate (typeof(EventHandler<ValueChangeEventArgs>)); - - #region emit LogicalParentChanged method - - //load new parent onto the stack for handler addition - ilPC.Emit (OpCodes.Ldarg_2); - ilPC.Emit (OpCodes.Ldfld, CompilerServices.fiDSCNewDS); - - //Load cached delegate - ilPC.Emit(OpCodes.Ldarg_0);//load ref to this instanciator onto the stack - ilPC.Emit(OpCodes.Ldfld, CompilerServices.fiTemplateBinding); - - //add template bindings dynValueChanged delegate to new parent event - ilPC.Emit(OpCodes.Callvirt, CompilerServices.eiValueChange.AddMethod);//call add event - - ilPC.MarkLabel (cancel); - ilPC.Emit (OpCodes.Ret); - - //store dschange delegate in instatiator instance for access while instancing graphic object - int delDSIndex = cachedDelegates.Count; - cachedDelegates.Add(dmPC.CreateDelegate (CompilerServices.ehTypeDSChange, this)); - #endregion - - ctx.emitCachedDelegateHandlerAddition(delDSIndex, CompilerServices.eiLogicalParentChanged); - } - /// <summary> - /// create the valuechanged handler, the datasourcechanged handler and emit event handling - /// </summary> - void emitDataSourceBindings(IMLContext ctx, BindingDefinition bindingDef){ - DynamicMethod dm = null; - ILGenerator il = null; - int dmVC = 0; - PropertyInfo piSource = ctx.CurrentNodeType.GetProperty(bindingDef.SourceMember); - //if no dataSource member name is provided, valuechange is not handle and datasource change - //will be used as origine value - string delName = "dyn_DSvalueChanged" + NewId; - if (!string.IsNullOrEmpty(bindingDef.TargetMember)){ - #region create valuechanged method - dm = new DynamicMethod (delName, - typeof (void), - CompilerServices.argsBoundValueChange, true); - - il = dm.GetILGenerator (256); - - System.Reflection.Emit.Label endMethod = il.DefineLabel (); - - il.DeclareLocal (CompilerServices.TObject); - - il.Emit (OpCodes.Nop); - - //load value changed member name onto the stack - il.Emit (OpCodes.Ldarg_2); - il.Emit (OpCodes.Ldfld, CompilerServices.fiVCMbName); - - //test if it's the expected one - il.Emit (OpCodes.Ldstr, bindingDef.TargetMember); - il.Emit (OpCodes.Ldc_I4_4);//StringComparison.Ordinal - il.Emit (OpCodes.Callvirt, CompilerServices.stringEquals); - il.Emit (OpCodes.Brfalse, endMethod); - //set destination member with valueChanged new value - //load destination ref - il.Emit (OpCodes.Ldarg_0); - //load new value onto the stack - il.Emit (OpCodes.Ldarg_2); - il.Emit (OpCodes.Ldfld, CompilerServices.fiVCNewValue); - - //by default, source value type is deducted from target member type to allow - //memberless binding, if targetMember exists, it will be used to determine target - //value type for conversion - - CompilerServices.emitConvert (il, piSource.PropertyType); - - if (!piSource.CanWrite) - throw new Exception ("Source member of bindind is read only:" + piSource.ToString()); - - il.Emit (OpCodes.Callvirt, piSource.GetSetMethod ()); - - il.MarkLabel (endMethod); - il.Emit (OpCodes.Ret); - - //vc dyn meth is stored in a cached list, it will be bound to datasource only - //when datasource of source graphic object changed - dmVC = dsValueChangedDynMeths.Count; - dsValueChangedDynMeths.Add (dm); - #endregion - } - - #region emit dataSourceChanged event handler - //now we create the datasource changed method that will init the destination member with - //the actual value of the origin member of the datasource and then will bind the value changed - //dyn methode. - //dm is bound to the instanciator instance to have access to cached dyn meth and delegates - dm = new DynamicMethod ("dyn_dschanged" + NewId, - typeof (void), - CompilerServices.argsBoundDSChange, true); - - il = dm.GetILGenerator (256); - - il.DeclareLocal (CompilerServices.TObject);//used for checking propery less bindings - il.DeclareLocal (typeof(MemberInfo));//used for checking propery less bindings - System.Reflection.Emit.Label cancel = il.DefineLabel (); - System.Reflection.Emit.Label newDSIsNull = il.DefineLabel (); - System.Reflection.Emit.Label cancelInit = il.DefineLabel (); - - il.Emit (OpCodes.Nop); - - emitRemoveOldDataSourceHandler(il, "ValueChanged", delName, true); - - if (!string.IsNullOrEmpty(bindingDef.TargetMember)){ - if (bindingDef.TwoWay){ -// System.Reflection.Emit.Label cancelRemove = il.DefineLabel (); -// //remove handler if not null -// il.Emit (OpCodes.Ldarg_2);//load old parent -// il.Emit (OpCodes.Ldfld, CompilerServices.fiDSCOldDS); -// il.Emit (OpCodes.Brfalse, cancelRemove);//old parent is null - - //remove handler - emitRemoveOldDataSourceHandler(il, "ValueChanged", delName, false); - -// il.Emit (OpCodes.Ldarg_1);//3d arg: instance bound to delegate (the source) -// il.Emit (OpCodes.Ldstr, "ValueChanged");//2nd arg event name -// il.Emit (OpCodes.Ldarg_2);//1st arg load old datasource -// il.Emit (OpCodes.Ldfld, CompilerServices.fiDSCOldDS); -// il.Emit (OpCodes.Call, CompilerServices.miRemEvtHdlByTarget); -// il.MarkLabel(cancelRemove); - } - il.Emit (OpCodes.Ldarg_2);//load datasource change arg - il.Emit (OpCodes.Ldfld, CompilerServices.fiDSCNewDS); - il.Emit (OpCodes.Brfalse, newDSIsNull);//new ds is null - } - - #region fetch initial Value - if (!string.IsNullOrEmpty(bindingDef.TargetMember)){ - il.Emit (OpCodes.Ldarg_2);//load new datasource - il.Emit (OpCodes.Ldfld, CompilerServices.fiDSCNewDS); - il.Emit (OpCodes.Ldstr, bindingDef.TargetMember);//load member name - il.Emit (OpCodes.Call, CompilerServices.miGetMembIinfoWithRefx); - il.Emit (OpCodes.Stloc_1);//save memberInfo - il.Emit (OpCodes.Ldloc_1);//push mi for test if null - il.Emit (OpCodes.Brfalse, cancelInit);//propertyLessBinding - } - - il.Emit (OpCodes.Ldarg_1);//load source of dataSourceChanged which is the dest instance - il.Emit (OpCodes.Ldarg_2);//load new datasource - il.Emit (OpCodes.Ldfld, CompilerServices.fiDSCNewDS); - if (!string.IsNullOrEmpty(bindingDef.TargetMember)){ - il.Emit (OpCodes.Ldloc_1);//push mi for value fetching - il.Emit (OpCodes.Call, CompilerServices.miGetValWithRefx); - } - CompilerServices.emitConvert (il, piSource.PropertyType); - il.Emit (OpCodes.Callvirt, piSource.GetSetMethod ()); - #endregion - - if (!string.IsNullOrEmpty(bindingDef.TargetMember)){ - il.MarkLabel(cancelInit); - //check if new dataSource implement IValueChange - il.Emit (OpCodes.Ldarg_2);//load new datasource - il.Emit (OpCodes.Ldfld, CompilerServices.fiDSCNewDS); - il.Emit (OpCodes.Isinst, typeof(IValueChange)); - il.Emit (OpCodes.Brfalse, cancel); - - il.Emit(OpCodes.Ldarg_0);//load ref to this instanciator onto the stack - il.Emit (OpCodes.Ldarg_1);//load datasource change source - il.Emit (OpCodes.Ldarg_2);//load new datasource - il.Emit (OpCodes.Ldfld, CompilerServices.fiDSCNewDS); - il.Emit(OpCodes.Ldc_I4, dmVC);//load index of dynmathod - il.Emit (OpCodes.Call, CompilerServices.miDSChangeEmitHelper); - - il.MarkLabel (cancel); - - if (bindingDef.TwoWay){ - il.Emit (OpCodes.Ldarg_1);//arg1: dataSourceChange source, the origine of the binding - il.Emit (OpCodes.Ldstr, bindingDef.SourceMember);//arg2: orig member - il.Emit (OpCodes.Ldarg_2);//arg3: new datasource - il.Emit (OpCodes.Ldfld, CompilerServices.fiDSCNewDS); - il.Emit (OpCodes.Ldstr, bindingDef.TargetMember);//arg4: dest member - il.Emit (OpCodes.Call, CompilerServices.miDSReverseBinding); - } - - } - il.MarkLabel (newDSIsNull); - il.Emit (OpCodes.Ret); - - //store dschange delegate in instatiator instance for access while instancing graphic object - int delDSIndex = cachedDelegates.Count; - cachedDelegates.Add(dm.CreateDelegate (CompilerServices.ehTypeDSChange, this)); - #endregion - - ctx.emitCachedDelegateHandlerAddition(delDSIndex, CompilerServices.eiDSChange); - - #if DEBUG_BINDING - Debug.WriteLine("\tDataSource ValueChanged: " + delName); - Debug.WriteLine("\tDataSource Changed: " + dm.Name); - #endif - } - /// <summary> - /// Two way binding for datasource, graphicObj=>dataSource link, datasource value has priority - /// and will be set as init for source property (in emitDataSourceBindings func) - /// </summary> - /// <param name="orig">Graphic object instance, source of binding</param> - /// <param name="origMember">Origin member name</param> - /// <param name="dest">datasource instance, target of the binding</param> - /// <param name="destMember">Destination member name</param> - static void dataSourceReverseBinding(IValueChange orig, string origMember, object dest, string destMember){ - Type tOrig = orig.GetType (); - Type tDest = dest.GetType (); - PropertyInfo piOrig = tOrig.GetProperty (origMember); - PropertyInfo piDest = tDest.GetProperty (destMember); - - if (piDest == null) { - Debug.WriteLine ("Member '{0}' not found in new DataSource '{1}' of '{2}'", destMember, dest, orig); - return; - } - #if DEBUG_BINDING - Debug.WriteLine ("DS Reverse binding: Member '{0}' found in new DS '{1}' of '{2}'", destMember, dest, orig); - #endif - - #region ValueChanged emit - DynamicMethod dm = new DynamicMethod ("dyn_valueChanged" + NewId, - typeof (void), CompilerServices.argsBoundValueChange, true); - ILGenerator il = dm.GetILGenerator (256); - - System.Reflection.Emit.Label endMethod = il.DefineLabel (); - - il.DeclareLocal (CompilerServices.TObject); - il.Emit (OpCodes.Nop); - - //load value changed member name onto the stack - il.Emit (OpCodes.Ldarg_2); - il.Emit (OpCodes.Ldfld, CompilerServices.fiVCMbName); - - //test if it's the expected one - il.Emit (OpCodes.Ldstr, origMember); - il.Emit (OpCodes.Ldc_I4_4);//StringComparison.Ordinal - il.Emit (OpCodes.Callvirt, CompilerServices.stringEquals); - il.Emit (OpCodes.Brfalse, endMethod); - //set destination member with valueChanged new value - //load destination ref - il.Emit (OpCodes.Ldarg_0); - //load new value onto the stack - il.Emit (OpCodes.Ldarg_2); - il.Emit (OpCodes.Ldfld, CompilerServices.fiVCNewValue); - - CompilerServices.emitConvert (il, piOrig.PropertyType, piDest.PropertyType); - - il.Emit (OpCodes.Callvirt, piDest.GetSetMethod ()); - - il.MarkLabel (endMethod); - il.Emit (OpCodes.Ret); - #endregion - - orig.ValueChanged += (EventHandler<ValueChangeEventArgs>)dm.CreateDelegate (typeof(EventHandler<ValueChangeEventArgs>), dest); - } - #endregion - - /// <summary> - /// search for graphic object type in crow assembly, if not found, - /// search for type independently of namespace in all the loaded assemblies - /// </summary> - /// <remarks> - /// </remarks> - /// <returns>the corresponding type object</returns> - /// <param name="typeName">graphic object type name without its namespace</param> - Type tryGetGOType (string typeName){ - Type t = Type.GetType ("Crow." + typeName); - if (t != null) - return t; - foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies()) { - if (a.IsDynamic) - continue; - foreach (Type expT in a.GetExportedTypes ()) { - if (expT.Name == typeName) - return expT; - } - } - return null; - } - } -} - diff --git a/src/Interface.cs b/src/Interface.cs deleted file mode 100644 index cc62a1aa..00000000 --- a/src/Interface.cs +++ /dev/null @@ -1,1268 +0,0 @@ -// -// Interface.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Diagnostics; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Threading; -using System.Xml; -using System.Xml.Serialization; -using Cairo; -using System.Globalization; -using Crow.IML; - -namespace Crow -{ - /// <summary> - /// The Interface Class is the root of crow graphic trees. It is thread safe allowing - /// application to run multiple interfaces in different threads. - /// It provides the Dirty bitmap and zone of the interface to be drawn on screen. - /// </summary> - /// <remarks> - /// The Interface contains : - /// - rendering and layouting queues and logic. - /// - helpers to load XML interfaces files directely bound to this interface - /// - global static constants and variables of CROW - /// - Keyboard and Mouse logic - /// - the resulting bitmap of the interface - /// - /// the master branch and the nuget package includes an OpenTK renderer which allows - /// the creation of multiple threaded interfaces. - /// - /// If you intend to create another renderer (GDK, vulkan, etc) the minimal step is to - /// put an interface instance as member of your root object and call (optionally in another thread) the update function - /// at regular interval. Then you have to call - /// mouse, keyboard and resize functions of the interface when those events occurs in the host app. - /// - /// The resulting surface (a byte array in the OpenTK renderer) is made available and protected with the - /// RenderMutex of the interface. - /// </remarks> - public class Interface : ILayoutable - { - #region CTOR - static Interface(){ - if (Type.GetType ("Mono.Runtime") == null) { - throw new Exception (@"C.R.O.W. run only on Mono, download latest version at: http://www.mono-project.com/download/stable/"); - } - - CrowConfigRoot = - System.IO.Path.Combine( - Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), - ".config"); - CrowConfigRoot = System.IO.Path.Combine (CrowConfigRoot, "crow"); - if (!Directory.Exists (CrowConfigRoot)) - Directory.CreateDirectory (CrowConfigRoot); - - //ensure all assemblies are loaded, because IML could contains classes not instanciated in source - foreach (string af in Directory.GetFiles (AppDomain.CurrentDomain.BaseDirectory, "*.dll")){ - try { - Assembly.LoadFrom (af); - } catch (Exception ex) { - Console.WriteLine ("{0} not loaded as assembly.", af); - } - } - - FontRenderingOptions = new FontOptions (); - FontRenderingOptions.Antialias = Antialias.Subpixel; - FontRenderingOptions.HintMetrics = HintMetrics.On; - FontRenderingOptions.HintStyle = HintStyle.Full; - FontRenderingOptions.SubpixelOrder = SubpixelOrder.Rgb; - } - public Interface(){ - CultureInfo.DefaultThreadCurrentCulture = System.Globalization.CultureInfo.InvariantCulture; - } - #endregion - - public void Init () { - CurrentInterface = this; - loadCursors (); - loadStyling (); - findAvailableTemplates (); - initTooltip (); - initContextMenus (); - } - - #region Static and constants - /// <summary> - /// Crow configuration root path - /// </summary> - public static string CrowConfigRoot; - /// <summary>If true, mouse focus is given when mouse is over control</summary> - public static bool FocusOnHover = false; - /// <summary> Threshold to catch borders for sizing </summary> - public static int BorderThreshold = 5; - /// <summary> delay before tooltip appear </summary> - public static int ToolTipDelay = 500; - /// <summary>Double click threshold in milisecond</summary> - public static int DoubleClick = 250;//max duration between two mouse_down evt for a dbl clk in milisec. - /// <summary> Time to wait in millisecond before starting repeat loop</summary> - public static int DeviceRepeatDelay = 700; - /// <summary> Time interval in millisecond between device event repeat</summary> - public static int DeviceRepeatInterval = 40; - /// <summary>Tabulation size in Text controls</summary> - public static int TabSize = 4; - public static string LineBreak = "\n"; - /// <summary> Allow rendering of interface in development environment </summary> - public static bool DesignerMode = false; - /// <summary> Disable caching for a widget if this threshold is reached </summary> - public const int MaxCacheSize = 2048; - /// <summary> Above this count, the layouting is discard from the current - /// update cycle and requeued for the next</summary> - public const int MaxLayoutingTries = 3; - /// <summary> Above this count, the layouting is discard for the widget and it - /// will not be rendered on screen </summary> - public const int MaxDiscardCount = 5; - /// <summary> Global font rendering settings for Cairo </summary> - public static FontOptions FontRenderingOptions; - /// <summary> Global font rendering settings for Cairo </summary> - public static Antialias Antialias = Antialias.Subpixel; - - /// <summary> - /// Each control need a ref to the root interface containing it, if not set in GraphicObject.currentInterface, - /// the ref of this one will be stored in GraphicObject.currentInterface - /// </summary> - protected static Interface CurrentInterface; - internal Stopwatch clickTimer = new Stopwatch(); - GraphicObject armedClickSender = null; - MouseButtonEventArgs armedClickEvtArgs = null; -// internal GraphicObject EligibleForDoubleClick { -// get { return eligibleForDoubleClick; } -// set { -// eligibleForDoubleClick = value; -// clickTimer.Restart (); -// } -// } - internal void armeClick (GraphicObject sender, MouseButtonEventArgs e){ - armedClickSender = sender; - armedClickEvtArgs = e; - clickTimer.Restart (); - } - #endregion - - #region Events - public event EventHandler<MouseCursorChangedEventArgs> MouseCursorChanged; - public event EventHandler Quit; - - public event EventHandler<MouseWheelEventArgs> MouseWheelChanged; - public event EventHandler<MouseButtonEventArgs> MouseButtonUp; - public event EventHandler<MouseButtonEventArgs> MouseButtonDown; - public event EventHandler<MouseButtonEventArgs> MouseClick; - public event EventHandler<MouseMoveEventArgs> MouseMove; - public event EventHandler<KeyboardKeyEventArgs> KeyboardKeyDown; - public event EventHandler<KeyboardKeyEventArgs> KeyboardKeyUp; - #endregion - - #region Public Fields - /// <summary>Graphic Tree of this interface</summary> - public List<GraphicObject> GraphicTree = new List<GraphicObject>(); - /// <summary>Interface's resulting bitmap</summary> - public byte[] bmp; - /// <summary>resulting bitmap limited to last redrawn part</summary> - public byte[] dirtyBmp; - /// <summary>True when host has to repaint Interface</summary> - public bool IsDirty = false; - /// <summary>Coordinate of the dirty bmp on the original bmp</summary> - public Rectangle DirtyRect; - /// <summary>Locked for each layouting operation</summary> - public object LayoutMutex = new object(); - /// <summary>Sync mutex between host and Crow for rendering operations (bmp, dirtyBmp,...)</summary> - public object RenderMutex = new object(); - /// <summary>Global lock of the update cycle</summary> - public object UpdateMutex = new object(); - /// <summary>Global lock of the clipping queue</summary> - public object ClippingMutex = new object(); - //TODO:share resource instances - /// <summary> - /// Store loaded resources instances shared among controls to reduce memory footprint - /// </summary> - public Dictionary<string,object> Ressources = new Dictionary<string, object>(); - /// <summary>The Main layouting queue.</summary> - public Queue<LayoutingQueueItem> LayoutingQueue = new Queue<LayoutingQueueItem> (); - /// <summary>Store discarded lqi between two updates</summary> - public Queue<LayoutingQueueItem> DiscardQueue; - /// <summary>Main drawing queue, holding layouted controls</summary> - public Queue<GraphicObject> ClippingQueue = new Queue<GraphicObject>(); - public string Clipboard;//TODO:use object instead for complex copy paste - /// <summary>each IML and fragments (such as inline Templates) are compiled as a Dynamic Method stored here - /// on the first instance creation of a IML item. - /// </summary> - public Dictionary<String, Instantiator> Instantiators = new Dictionary<string, Instantiator>(); - public List<CrowThread> CrowThreads = new List<CrowThread>();//used to monitor thread finished - - public DragDropEventArgs DragAndDropOperation = null; - public Surface DragImage = null; - public int DragImageWidth, DragImageHeight, DragImageX, DragImageY; - public void ClearDragImage () { - lock (UpdateMutex) { - clipping.UnionRectangle(new Rectangle (DragImageX, DragImageY, DragImageWidth, DragImageHeight)); - DragImage.Dispose(); - DragImage = null; - } - } - #endregion - - #region Private Fields - /// <summary>Client rectangle in the host context</summary> - Rectangle clientRectangle; - /// <summary>Clipping rectangles on the root context</summary> - Region clipping = new Region(); - /// <summary>Main Cairo context</summary> - Context ctx; - /// <summary>Main Cairo surface</summary> - Surface surf; - #endregion - - #region Default values and Style loading - /// Default values of properties from GraphicObjects are retrieve from XML Attributes. - /// The reflexion process used to retrieve those values being very slow, it is compiled in MSIL - /// and injected as a dynamic method referenced in the DefaultValuesLoader Dictionnary. - /// The compilation is done on the first object instancing, and is also done for custom widgets - public delegate void LoaderInvoker(object instance); - /// <summary>Store one loader per StyleKey</summary> - public Dictionary<String, LoaderInvoker> DefaultValuesLoader = new Dictionary<string, LoaderInvoker>(); - /// <summary>Store dictionnary of member/value per StyleKey</summary> - public Dictionary<string, Style> Styling; - /// <summary> parse all styling data's during application startup and build global Styling Dictionary </summary> - protected virtual void loadStyling() { - Styling = new Dictionary<string, Style> (); - - //fetch styling info in this order, if member styling is alreadey referenced in previous - //assembly, it's ignored. - loadStylingFromAssembly (Assembly.GetEntryAssembly ()); - loadStylingFromAssembly (Assembly.GetExecutingAssembly ()); - } - /// <summary> Search for .style resources in assembly </summary> - void loadStylingFromAssembly (Assembly assembly) { - if (assembly == null) - return; - foreach (string s in assembly - .GetManifestResourceNames () - .Where (r => r.EndsWith (".style", StringComparison.OrdinalIgnoreCase))) { - using (Stream stream = assembly.GetManifestResourceStream (s)) { - new StyleReader (this.Styling, stream, s); - } - - } - } - void loadCursors(){ - //Load cursors - XCursor.Cross = XCursorFile.Load(this, "#Crow.Images.Icons.Cursors.cross").Cursors[0]; - XCursor.Default = XCursorFile.Load(this, "#Crow.Images.Icons.Cursors.arrow").Cursors[0]; - XCursor.NW = XCursorFile.Load(this, "#Crow.Images.Icons.Cursors.top_left_corner").Cursors[0]; - XCursor.NE = XCursorFile.Load(this, "#Crow.Images.Icons.Cursors.top_right_corner").Cursors[0]; - XCursor.SW = XCursorFile.Load(this, "#Crow.Images.Icons.Cursors.bottom_left_corner").Cursors[0]; - XCursor.SE = XCursorFile.Load(this, "#Crow.Images.Icons.Cursors.bottom_right_corner").Cursors[0]; - XCursor.H = XCursorFile.Load(this, "#Crow.Images.Icons.Cursors.sb_h_double_arrow").Cursors[0]; - XCursor.V = XCursorFile.Load(this, "#Crow.Images.Icons.Cursors.sb_v_double_arrow").Cursors[0]; - XCursor.Text = XCursorFile.Load(this, "#Crow.Images.Icons.Cursors.ibeam").Cursors[0]; - } - #endregion - - #region Templates - /// <summary>Store one default templates resource ID per class. - /// Resource ID must be 'fullClassName.template' (not case sensitive) - /// Those found in application assembly have priority to the default Crow's one - /// </summary> - public Dictionary<string, string> DefaultTemplates; - /// <summary>Finds available default templates at startup</summary> - void findAvailableTemplates(){ - DefaultTemplates = new Dictionary<string, string>(); - searchTemplatesOnDisk ("./"); - string defTemplatePath = System.IO.Path.Combine (CrowConfigRoot, "defaultTemplates"); - searchTemplatesOnDisk (defTemplatePath); - searchTemplatesIn (Assembly.GetEntryAssembly ()); - searchTemplatesIn (Assembly.GetExecutingAssembly ()); - } - void searchTemplatesOnDisk (string templatePath){ - if (!Directory.Exists (templatePath)) - return; - foreach (string f in Directory.GetFiles(templatePath, "*.template",SearchOption.AllDirectories)) { - string clsName = System.IO.Path.GetFileNameWithoutExtension(f); - if (DefaultTemplates.ContainsKey (clsName)) - continue; - DefaultTemplates [clsName] = f; - } - } - void searchTemplatesIn(Assembly assembly){ - if (assembly == null) - return; - foreach (string resId in assembly - .GetManifestResourceNames () - .Where (r => r.EndsWith (".template", StringComparison.OrdinalIgnoreCase))) { - string clsName = resId.Substring (0, resId.Length - 9); - if (DefaultTemplates.ContainsKey (clsName)) - continue; - DefaultTemplates[clsName] = "#" + resId; - } - } - #endregion - - #region Load/Save - /// <summary>Open file or find a resource from path string</summary> - /// <returns>A file or resource stream</returns> - /// <param name="path">This could be a normal file path, or an embedded ressource ID - /// Resource ID's must be prefixed with '#' character</param> - public virtual Stream GetStreamFromPath (string path) - { - Stream stream = null; - - if (path.StartsWith ("#")) { - string resId = path.Substring (1); - //try/catch added to prevent nunit error - try { - stream = System.Reflection.Assembly.GetEntryAssembly ().GetManifestResourceStream (resId); - } catch{} - if (stream == null)//try to find ressource in Crow assembly - stream = System.Reflection.Assembly.GetExecutingAssembly ().GetManifestResourceStream (resId); - if (stream == null) - throw new Exception ("Resource not found: " + path); - } else { - if (!File.Exists (path)) - throw new FileNotFoundException ("File not found: ", path); - stream = new FileStream (path, FileMode.Open, FileAccess.Read); - } - return stream; - } - public static Stream StaticGetStreamFromPath (string path) - { - Stream stream = null; - - if (path.StartsWith ("#")) { - string resId = path.Substring (1); - //try/catch added to prevent nunit error - try { - stream = System.Reflection.Assembly.GetEntryAssembly ().GetManifestResourceStream (resId); - } catch{} - if (stream == null)//try to find ressource in Crow assembly - stream = System.Reflection.Assembly.GetExecutingAssembly ().GetManifestResourceStream (resId); - if (stream == null) - throw new Exception ("Resource not found: " + path); - } else { - if (!File.Exists (path)) - throw new FileNotFoundException ("File not found: ", path); - stream = new FileStream (path, FileMode.Open, FileAccess.Read); - } - return stream; - } - /// <summary> - /// Add the content of the IML fragment to the graphic tree of this interface - /// </summary> - /// <returns>return the new instance for convenience, may be ignored</returns> - /// <param name="imlFragment">a valid IML string</param> - public GraphicObject LoadIMLFragment (string imlFragment) { - lock (UpdateMutex) { - GraphicObject tmp = CreateITorFromIMLFragment (imlFragment).CreateInstance(); - AddWidget (tmp); - return tmp; - } - } - /// <summary> - /// Add the content of the IML fragment to the graphic tree of this interface - /// </summary> - /// <returns>return the new instance for convenience, may be ignored</returns> - /// <param name="imlFragment">a valid IML string</param> - public Instantiator CreateITorFromIMLFragment (string imlFragment) { - return Instantiator.CreateFromImlFragment (this, imlFragment); - } - /// <summary> - /// Create an instance of a GraphicObject and add it to the GraphicTree of this Interface - /// </summary> - /// <returns>new instance of graphic object created</returns> - /// <param name="path">path of the iml file to load</param> - public GraphicObject AddWidget (string path) - { - lock (UpdateMutex) { - GraphicObject tmp = Load (path); - AddWidget (tmp); - return tmp; - } - } - /// <summary> - /// Create an instance of a GraphicObject linked to this interface but not added to the GraphicTree - /// </summary> - /// <returns>new instance of graphic object created</returns> - /// <param name="path">path of the iml file to load</param> - public virtual GraphicObject Load (string path) - { - try { - return GetInstantiator (path).CreateInstance (); - } catch (Exception ex) { - throw new Exception ("Error loading <" + path + ">:", ex); - } - } - /// <summary> - /// Fetch instantiator from cache or create it. - /// </summary> - /// <returns>new Instantiator</returns> - /// <param name="path">path of the iml file to load</param> - public Instantiator GetInstantiator(string path){ - if (!Instantiators.ContainsKey(path)) - Instantiators [path] = new Instantiator(this, path); - return Instantiators [path]; - } - /// <summary>Item templates are derived from instantiator, this function - /// try to fetch the requested one in the cache or create it. - /// They have additional properties for recursivity and - /// custom display per item type</summary> - public virtual ItemTemplate GetItemTemplate(string path){ - if (!Instantiators.ContainsKey(path)) - Instantiators [path] = new ItemTemplate(this, path); - return Instantiators [path] as ItemTemplate; - } - #endregion - - #region focus - GraphicObject _activeWidget; //button is pressed on widget - GraphicObject _hoverWidget; //mouse is over - GraphicObject _focusedWidget; //has keyboard (or other perif) focus - - /// <summary>Widget is focused and button is down or another perif action is occuring - /// , it can not lose focus while Active</summary> - public GraphicObject ActiveWidget - { - get { return _activeWidget; } - set - { - if (_activeWidget == value) - return; - - if (_activeWidget != null) - _activeWidget.IsActive = false; - - _activeWidget = value; - - if (_activeWidget != null) - { - _activeWidget.IsActive = true; - #if DEBUG_FOCUS - Debug.WriteLine("Active => " + _activeWidget.ToString()); - }else - Debug.WriteLine("Active => null"); - #else - } - #endif - } - } - /// <summary>Pointer is over the widget</summary> - public virtual GraphicObject HoverWidget - { - get { return _hoverWidget; } - set { - if (_hoverWidget == value) - return; - - if (_hoverWidget != null) - _hoverWidget.IsHover = false; - - _hoverWidget = value; - - if (_hoverWidget != null) - { - _hoverWidget.IsHover = true; - #if DEBUG_FOCUS - Debug.WriteLine("Hover => " + _hoverWidget.ToString()); - }else - Debug.WriteLine("Hover => null"); - #else - } - #endif - } - } - /// <summary>Widget has the keyboard or mouse focus</summary> - public GraphicObject FocusedWidget { - get { return _focusedWidget; } - set { - if (_focusedWidget == value) - return; - if (_focusedWidget != null) - _focusedWidget.HasFocus = false; - _focusedWidget = value; - if (_focusedWidget != null) - _focusedWidget.HasFocus = true; - } - } - #endregion - - #region UPDATE Loops - /// <summary>Enqueue Graphic object for Repaint, DrawingQueue is locked because - /// GraphObj's property Set methods could trigger an update from another thread - /// Once in that queue, that means that the layouting of obj and childs have succeed, - /// the next step when dequeued will be clipping registration</summary> - public void EnqueueForRepaint(GraphicObject g) - { - #if DEBUG_UPDATE - Debug.WriteLine (string.Format("\tEnqueueForRepaint -> {0}", g?.ToString ())); - #endif - lock (ClippingMutex) { - if (g.IsQueueForClipping) - return; - ClippingQueue.Enqueue (g); - g.IsQueueForClipping = true; - } - } - /// <summary>Main Update loop, executed in this interface thread, protected by the UpdateMutex - /// Steps: - /// - execute device Repeat events - /// - Layouting - /// - Clipping - /// - Drawing - /// Result: the Interface bitmap is drawn in memory (byte[] bmp) and a dirtyRect and bitmap are available - /// </summary> - public void Update(){ - if (armedClickSender != null && clickTimer.ElapsedMilliseconds >= Interface.DoubleClick) { - armedClickSender.onMouseClick (armedClickSender, armedClickEvtArgs); - armedClickSender = null; - } - - if (mouseRepeatCount > 0) { - int mc = mouseRepeatCount; - mouseRepeatCount -= mc; - if (_focusedWidget != null) { - mouseRepeatTriggeredAtLeastOnce = true; - for (int i = 0; i < mc; i++) { - _focusedWidget.onMouseDown (this, new BubblingMouseButtonEventArg(Mouse.X, Mouse.Y, MouseButton.Left, true)); - } - } - } - - CrowThread[] tmpThreads; - lock (CrowThreads) { - tmpThreads = new CrowThread[CrowThreads.Count]; - Array.Copy (CrowThreads.ToArray (), tmpThreads, CrowThreads.Count); - } - for (int i = 0; i < tmpThreads.Length; i++) - tmpThreads [i].CheckState (); - - if (!Monitor.TryEnter (UpdateMutex)) - return; - - #if MEASURE_TIME - updateMeasure.StartCycle(); - #endif - - processLayouting (); - - #if DEBUG_LAYOUTING - if (curLQIsTries.Count > 0){ - LQIsTries.Add(curLQIsTries); - curLQIsTries = new LQIList(); - LQIs.Add(curLQIs); - curLQIs = new LQIList(); - } - #endif - - clippingRegistration (); - - processDrawing (); - - #if MEASURE_TIME - updateMeasure.StopCycle(); - #endif - - Monitor.Exit (UpdateMutex); - } - /// <summary>Layouting loop, this is the first step of the udpate and process registered - /// Layouting queue items. Failing LQI's are requeued in this cycle until MaxTry is reached which - /// trigger an enqueue for the next Update Cycle</summary> - protected virtual void processLayouting(){ - #if MEASURE_TIME - layoutingMeasure.StartCycle(); - #endif - - if (Monitor.TryEnter (LayoutMutex)) { - DiscardQueue = new Queue<LayoutingQueueItem> (); - //Debug.WriteLine ("======= Layouting queue start ======="); - LayoutingQueueItem lqi; - while (LayoutingQueue.Count > 0) { - lqi = LayoutingQueue.Dequeue (); - #if DEBUG_LAYOUTING - currentLQI = lqi; - curLQIsTries.Add(currentLQI); - #endif - lqi.ProcessLayouting (); - } - LayoutingQueue = DiscardQueue; - Monitor.Exit (LayoutMutex); - DiscardQueue = null; - } - - #if MEASURE_TIME - layoutingMeasure.StopCycle(); - #endif - } - /// <summary>Degueue Widget to clip from DrawingQueue and register the last painted slot and the new one - /// Clipping rectangles are added at each level of the tree from leef to root, that's the way for the painting - /// operation to known if it should go down in the tree for further graphic updates and repaints</summary> - void clippingRegistration(){ - #if MEASURE_TIME - clippingMeasure.StartCycle(); - #endif - GraphicObject g = null; - while (ClippingQueue.Count > 0) { - lock (ClippingMutex) { - g = ClippingQueue.Dequeue (); - g.IsQueueForClipping = false; - } - g.ClippingRegistration (); - } - - #if MEASURE_TIME - clippingMeasure.StopCycle(); - #endif - } - /// <summary>Clipping Rectangles drive the drawing process. For compositing, each object under a clip rectangle should be - /// repainted. If it contains also clip rectangles, its cache will be update, or if not cached a full redraw will take place</summary> - void processDrawing(){ - #if MEASURE_TIME - drawingMeasure.StartCycle(); - #endif - if (DragImage != null) - clipping.UnionRectangle(new Rectangle (DragImageX, DragImageY, DragImageWidth, DragImageHeight)); - using (surf = new ImageSurface (bmp, Format.Argb32, ClientRectangle.Width, ClientRectangle.Height, ClientRectangle.Width * 4)) { - using (ctx = new Context (surf)){ - if (!clipping.IsEmpty) { - - for (int i = 0; i < clipping.NumRectangles; i++) - ctx.Rectangle(clipping.GetRectangle(i)); - - ctx.ClipPreserve(); - ctx.Operator = Operator.Clear; - ctx.Fill(); - ctx.Operator = Operator.Over; - - for (int i = GraphicTree.Count -1; i >= 0 ; i--){ - GraphicObject p = GraphicTree[i]; - if (!p.Visible) - continue; - if (clipping.Contains (p.Slot) == RegionOverlap.Out) - continue; - - ctx.Save (); - p.Paint (ref ctx); - ctx.Restore (); - } - - if (DragAndDropOperation != null) { - if (DragImage != null) { - DirtyRect += new Rectangle (DragImageX, DragImageY, DragImageWidth, DragImageHeight); - DragImageX = Mouse.X - DragImageWidth / 2; - DragImageY = Mouse.Y - DragImageHeight / 2; - ctx.Save (); - ctx.ResetClip (); - ctx.SetSourceSurface (DragImage, DragImageX, DragImageY); - ctx.PaintWithAlpha (0.8); - ctx.Restore (); - DirtyRect += new Rectangle (DragImageX, DragImageY, DragImageWidth, DragImageHeight); - IsDirty = true; - //Console.WriteLine ("dragimage drawn: {0},{1}", DragImageX, DragImageY); - } - } - - #if DEBUG_CLIP_RECTANGLE - clipping.stroke (ctx, Color.Red.AdjustAlpha(0.5)); - #endif - lock (RenderMutex) { -// Array.Copy (bmp, dirtyBmp, bmp.Length); - - if (IsDirty) - DirtyRect += clipping.Extents; - else - DirtyRect = clipping.Extents; - IsDirty = true; - - DirtyRect.Left = Math.Max (0, DirtyRect.Left); - DirtyRect.Top = Math.Max (0, DirtyRect.Top); - DirtyRect.Width = Math.Min (ClientRectangle.Width - DirtyRect.Left, DirtyRect.Width); - DirtyRect.Height = Math.Min (ClientRectangle.Height - DirtyRect.Top, DirtyRect.Height); - DirtyRect.Width = Math.Max (0, DirtyRect.Width); - DirtyRect.Height = Math.Max (0, DirtyRect.Height); - - if (DirtyRect.Width > 0 && DirtyRect.Height >0) { - dirtyBmp = new byte[4 * DirtyRect.Width * DirtyRect.Height]; - for (int y = 0; y < DirtyRect.Height; y++) { - Array.Copy (bmp, - ((DirtyRect.Top + y) * ClientRectangle.Width * 4) + DirtyRect.Left * 4, - dirtyBmp, y * DirtyRect.Width * 4, DirtyRect.Width * 4); - } - - } else - IsDirty = false; - } - clipping.Dispose (); - clipping = new Region (); - } - //surf.WriteToPng (@"/mnt/data/test.png"); - } - } - #if MEASURE_TIME - drawingMeasure.StopCycle(); - #endif - } - #endregion - - #region GraphicTree handling - /// <summary>Add widget to the Graphic tree of this interface and register it for layouting</summary> - public void AddWidget(GraphicObject g) - { - g.Parent = this; - int ptr = 0; - Window newW = g as Window; - if (newW != null) { - while (ptr < GraphicTree.Count) { - Window w = GraphicTree [ptr] as Window; - if (w != null) { - if (newW.AlwaysOnTop || !w.AlwaysOnTop) - break; - } - ptr++; - } - } - - lock (UpdateMutex) - GraphicTree.Insert (ptr, g); - - g.RegisteredLayoutings = LayoutingType.None; - g.RegisterForLayouting (LayoutingType.Sizing | LayoutingType.ArrangeChildren); - } - /// <summary>Set visible state of widget to false and delete if from the graphic tree</summary> - public void DeleteWidget(GraphicObject g) - { - lock (UpdateMutex) { - RegisterClip (g.ScreenCoordinates (g.LastPaintedSlot)); - GraphicTree.Remove (g); - g.Parent = null; - g.Dispose (); - } - } - /// <summary>Set visible state of widget to false and remove if from the graphic tree</summary> - public void RemoveWidget(GraphicObject g) - { -// if (g.Contains(HoverWidget)) { -// while (HoverWidget != g.focusParent) { -// HoverWidget.onMouseLeave (HoverWidget, null); -// HoverWidget = HoverWidget.focusParent; -// } -// } - lock (UpdateMutex) { - RegisterClip (g.ScreenCoordinates (g.LastPaintedSlot)); - GraphicTree.Remove (g); - g.Parent = null; - } - } - /// <summary> Remove all Graphic objects from top container </summary> - public void ClearInterface() - { - lock (UpdateMutex) { - while (GraphicTree.Count > 0) { - //TODO:parent is not reset to null because object will be added - //to ObjectToRedraw list, and without parent, it fails - GraphicObject g = GraphicTree [0]; - RegisterClip (g.ScreenCoordinates (g.LastPaintedSlot)); - GraphicTree.RemoveAt (0); - g.Dispose (); - } - } - #if DEBUG_LAYOUTING - LQIsTries = new List<LQIList>(); - curLQIsTries = new LQIList(); - LQIs = new List<LQIList>(); - curLQIs = new LQIList(); - #endif - } - /// <summary> Put widget on top of other root widgets</summary> - public void PutOnTop(GraphicObject g, bool isOverlay = false) - { - int ptr = 0; - Window newW = g as Window; - if (newW != null) { - while (ptr < GraphicTree.Count) { - Window w = GraphicTree [ptr] as Window; - if (w != null) { - if (newW.AlwaysOnTop || !w.AlwaysOnTop) - break; - } - ptr++; - } - } - if (GraphicTree.IndexOf(g) > ptr) - { - lock (UpdateMutex) { - GraphicTree.Remove (g); - GraphicTree.Insert (ptr, g); - } - EnqueueForRepaint (g); - } - } - - /// <summary>Search a Graphic object in the tree named 'nameToFind'</summary> - public GraphicObject FindByName (string nameToFind) - { - foreach (GraphicObject w in GraphicTree) { - GraphicObject r = w.FindByName (nameToFind); - if (r != null) - return r; - } - return null; - } - #endregion - - /// <summary> - /// Resize the interface. This function should be called by the host - /// when window resize event occurs. - /// </summary> - /// <param name="bounds">bounding box of the interface</param> - public void ProcessResize(Rectangle bounds){ - lock (UpdateMutex) { - clientRectangle = bounds; - int stride = 4 * ClientRectangle.Width; - int bmpSize = Math.Abs (stride) * ClientRectangle.Height; - bmp = new byte[bmpSize]; - dirtyBmp = new byte[bmpSize]; - - foreach (GraphicObject g in GraphicTree) - g.RegisterForLayouting (LayoutingType.All); - - RegisterClip (clientRectangle); - } - } - - #region Mouse and Keyboard Handling - XCursor cursor = XCursor.Default; - - public MouseState Mouse; - public KeyboardState Keyboard; - - public XCursor MouseCursor { - set { - if (value == cursor) - return; - cursor = value; - MouseCursorChanged.Raise (this,new MouseCursorChangedEventArgs(cursor)); - } - } - /// <summary>Processes mouse move events from the root container, this function - /// should be called by the host on mouse move event to forward events to crow interfaces</summary> - /// <returns>true if mouse is in the interface</returns> - public virtual bool ProcessMouseMove(int x, int y) - { - if (armedClickSender != null) { - armedClickSender.onMouseClick (armedClickSender, armedClickEvtArgs); - armedClickSender = null; - } - int deltaX = x - Mouse.X; - int deltaY = y - Mouse.Y; - Mouse.X = x; - Mouse.Y = y; - MouseMoveEventArgs e = new MouseMoveEventArgs (x, y, deltaX, deltaY); - e.Mouse = Mouse; - - if (ActiveWidget != null && DragAndDropOperation == null) { - //TODO, ensure object is still in the graphic tree - //send move evt even if mouse move outside bounds - ActiveWidget.onMouseMove (this, e); - return true; - } - - if (DragAndDropOperation != null)//drag source cant have hover event, so move has to be handle here - DragAndDropOperation.DragSource.onMouseMove (this, e); - - if (HoverWidget != null) { - resetTooltip (); - //check topmost graphicobject first - GraphicObject tmp = HoverWidget; - GraphicObject topc = null; - while (tmp is GraphicObject) { - topc = tmp; - tmp = tmp.focusParent; - } - int idxhw = GraphicTree.IndexOf (topc); - if (idxhw != 0) { - int i = 0; - while (i < idxhw) { - if (!GraphicTree [i].isPopup) { - if (GraphicTree [i].MouseIsIn (e.Position)) { - while (HoverWidget != null) { - HoverWidget.onMouseLeave (HoverWidget, e); - HoverWidget = HoverWidget.focusParent; - } - - GraphicTree [i].checkHoverWidget (e); - HoverWidget.onMouseMove (this, e); - return true; - } - } - i++; - } - } - - if (HoverWidget.MouseIsIn (e.Position)) { - HoverWidget.checkHoverWidget (e); - HoverWidget.onMouseMove (this, e); - return true; - } else { - HoverWidget.onMouseLeave (HoverWidget, e); - //seek upward from last focused graph obj's - while (HoverWidget.focusParent != null) { - HoverWidget = HoverWidget.focusParent; - if (HoverWidget.MouseIsIn (e.Position)) { - HoverWidget.checkHoverWidget (e); - HoverWidget.onMouseMove (this, e); - return true; - } else - HoverWidget.onMouseLeave (HoverWidget, e); - } - } - } - - //top level graphic obj's parsing - lock (GraphicTree) { - for (int i = 0; i < GraphicTree.Count; i++) { - GraphicObject g = GraphicTree [i]; - if (g.MouseIsIn (e.Position)) { - g.checkHoverWidget (e); - if (g is Window) - PutOnTop (g); - HoverWidget.onMouseMove (this, e); - return true; - } - } - } - HoverWidget = null; - return false; - } - /// <summary> - /// Forward the mouse up event from the host to the crow interface - /// </summary> - /// <returns>return true, if interface handled the event, false otherwise.</returns> - /// <param name="button">Button index</param> - public bool ProcessMouseButtonUp(int button) - { - Mouse.DisableBit (button); - MouseButtonEventArgs e = new MouseButtonEventArgs ((Crow.MouseButton)button) { Mouse = Mouse }; - if (_activeWidget == null) - return false; - - if (mouseRepeatThread != null) { - mouseRepeatOn = false; - mouseRepeatThread.Abort(); - mouseRepeatThread.Join (); - } - if (!mouseRepeatTriggeredAtLeastOnce) { - if (_activeWidget.MouseIsIn (e.Position)) - armeClick (_activeWidget, e); - } - mouseRepeatTriggeredAtLeastOnce = false; - _activeWidget.onMouseUp (_activeWidget, e); - -// GraphicObject lastActive = _activeWidget; - ActiveWidget = null; -// if (!lastActive.MouseIsIn (Mouse.Position)) { -// ProcessMouseMove (Mouse.X, Mouse.Y); -// } - return true; - } - /// <summary> - /// Forward the mouse down event from the host to the crow interface - /// </summary> - /// <returns>return true, if interface handled the event, false otherwise.</returns> - /// <param name="button">Button index</param> - public bool ProcessMouseButtonDown(int button) - { - Mouse.EnableBit (button); - MouseButtonEventArgs e = new MouseButtonEventArgs ((Crow.MouseButton)button) { Mouse = Mouse }; - - if (HoverWidget == null) - return false; - - if (HoverWidget == armedClickSender) { - if (clickTimer.ElapsedMilliseconds < Interface.DoubleClick) { - armedClickSender.onMouseDoubleClick (armedClickSender, e); - armedClickSender = null; - return true; - } - - } - if (armedClickSender!=null) - armedClickSender.onMouseClick (armedClickSender, armedClickEvtArgs); - armedClickSender = null; - - HoverWidget.onMouseDown(HoverWidget,new BubblingMouseButtonEventArg(e)); - - if (FocusedWidget == null) - return true; - if (!FocusedWidget.MouseRepeat) - return true; - mouseRepeatThread = new Thread (mouseRepeatThreadFunc); - mouseRepeatThread.IsBackground = true; - mouseRepeatThread.Start (); - return true; - } - /// <summary> - /// Forward the mouse wheel event from the host to the crow interface - /// </summary> - /// <returns>return true, if interface handled the event, false otherwise.</returns> - /// <param name="button">Button index</param> - public bool ProcessMouseWheelChanged(float delta) - { - Mouse.SetScrollRelative (0, delta); - MouseWheelEventArgs e = new MouseWheelEventArgs () { Mouse = Mouse, DeltaPrecise = delta }; - - if (HoverWidget == null) - return false; - HoverWidget.onMouseWheel (this, e); - return true; - } - /// <summary> - /// Forward key down event from the host to the crow interface - /// </summary> - /// <returns>return true, if interface handled the event, false otherwise.</returns> - /// <param name="button">Button index</param> - public bool ProcessKeyDown(int Key){ - Keyboard.SetKeyState((Crow.Key)Key,true); - if (_focusedWidget == null) - return false; - KeyboardKeyEventArgs e = lastKeyDownEvt = new KeyboardKeyEventArgs((Crow.Key)Key, false, Keyboard); - lastKeyDownEvt.IsRepeat = true; - _focusedWidget.onKeyDown (this, e); - -// keyboardRepeatThread = new Thread (keyboardRepeatThreadFunc); -// keyboardRepeatThread.IsBackground = true; -// keyboardRepeatThread.Start (); - - return true; - } - /// <summary> - /// Forward key up event from the host to the crow interface - /// </summary> - /// <returns>return true, if interface handled the event, false otherwise.</returns> - /// <param name="button">Button index</param> - public bool ProcessKeyUp(int Key){ - Keyboard.SetKeyState((Crow.Key)Key,false); - if (_focusedWidget == null) - return false; - KeyboardKeyEventArgs e = new KeyboardKeyEventArgs((Crow.Key)Key, false, Keyboard); - - _focusedWidget.onKeyUp (this, e); - -// if (keyboardRepeatThread != null) { -// keyboardRepeatOn = false; -// keyboardRepeatThread.Abort(); -// keyboardRepeatThread.Join (); -// } - return true; - } - /// <summary> - /// Forward a translated key press event from the host to the crow interface - /// </summary> - /// <returns>return true, if interface handled the event, false otherwise.</returns> - /// <param name="button">Button index</param> - public bool ProcessKeyPress(char Key){ - if (_focusedWidget == null) - return false; - KeyPressEventArgs e = new KeyPressEventArgs(Key); - _focusedWidget.onKeyPress (this, e); - return true; - } - #endregion - - #region Tooltip handling - Stopwatch tooltipTimer = new Stopwatch(); - GraphicObject ToolTipContainer = null; - volatile bool tooltipVisible = false; - - protected void initTooltip () { - ToolTipContainer = Load ("#Crow.Tooltip.template"); - Thread t = new Thread (toolTipThreadFunc); - t.IsBackground = true; - t.Start (); - } - void toolTipThreadFunc () - { - while(true) { - if (tooltipTimer.ElapsedMilliseconds > ToolTipDelay) { - if (!tooltipVisible) { - GraphicObject g = _hoverWidget; - while (g != null) { - if (!string.IsNullOrEmpty (g.Tooltip)) { - AddWidget (ToolTipContainer); - ToolTipContainer.DataSource = g; - ToolTipContainer.Top = Mouse.Y + 10; - ToolTipContainer.Left = Mouse.X + 10; - tooltipVisible = true; - break; - } - g = g.LogicalParent as GraphicObject; - } - } - } - Thread.Sleep (200); - } - - } - void resetTooltip () { - if (tooltipVisible) { - //ToolTipContainer.DataSource = null; - RemoveWidget (ToolTipContainer); - tooltipVisible = false; - } - tooltipTimer.Restart (); - } - #endregion - - #region Contextual menu - MenuItem ctxMenuContainer; - protected void initContextMenus (){ - ctxMenuContainer = Load ("#Crow.ContextMenu.template") as MenuItem; - ctxMenuContainer.LayoutChanged += CtxMenuContainer_LayoutChanged; - } - - void CtxMenuContainer_LayoutChanged (object sender, LayoutingEventArgs e) - { - Rectangle r = ctxMenuContainer.ScreenCoordinates (ctxMenuContainer.Slot); - if (e.LayoutType == LayoutingType.Width || e.LayoutType == LayoutingType.X) { - if (r.Right > this.clientRectangle.Right) - ctxMenuContainer.Left = this.clientRectangle.Right - ctxMenuContainer.Slot.Width; - }else if (e.LayoutType == LayoutingType.Width || e.LayoutType == LayoutingType.Y) { - if (r.Bottom > this.clientRectangle.Bottom) - ctxMenuContainer.Top = this.clientRectangle.Bottom - ctxMenuContainer.Slot.Height; - } - - } - - public void ShowContextMenu (GraphicObject go) { - - lock (UpdateMutex) { - if (ctxMenuContainer.Parent == null) - this.AddWidget (ctxMenuContainer); - else - ctxMenuContainer.IsOpened = true; - - ctxMenuContainer.isPopup = true; - ctxMenuContainer.LogicalParent = go; - ctxMenuContainer.DataSource = go; - - PutOnTop (ctxMenuContainer, true); - } - ctxMenuContainer.Left = Mouse.X - 5; - ctxMenuContainer.Top = Mouse.Y - 5; - - HoverWidget = ctxMenuContainer; - ctxMenuContainer.onMouseEnter (ctxMenuContainer, new MouseMoveEventArgs (Mouse.X, Mouse.Y, 0, 0)); - } - #endregion - - #region Device Repeat Events - volatile bool mouseRepeatOn, keyboardRepeatOn, mouseRepeatTriggeredAtLeastOnce = false; - volatile int mouseRepeatCount, keyboardRepeatCount; - Thread mouseRepeatThread, keyboardRepeatThread; - KeyboardKeyEventArgs lastKeyDownEvt; - void mouseRepeatThreadFunc() - { - mouseRepeatOn = true; - mouseRepeatTriggeredAtLeastOnce = false; - Thread.Sleep (Interface.DeviceRepeatDelay); - while (mouseRepeatOn) { - mouseRepeatCount++; - Thread.Sleep (Interface.DeviceRepeatInterval); - } - mouseRepeatCount = 0; - } - void keyboardRepeatThreadFunc() - { - keyboardRepeatOn = true; - Thread.Sleep (Interface.DeviceRepeatDelay); - while (keyboardRepeatOn) { - keyboardRepeatCount++; - Thread.Sleep (Interface.DeviceRepeatInterval); - } - keyboardRepeatCount = 0; - } - #endregion - - #region ILayoutable implementation - public virtual bool PointIsIn(ref Point m) - { - return true; - } - public void RegisterClip(Rectangle r){ - clipping.UnionRectangle (r); - } - public bool ArrangeChildren { get { return false; }} - public int LayoutingTries { - get { throw new NotImplementedException (); } - set { throw new NotImplementedException (); } - } - public LayoutingType RegisteredLayoutings { - get { return LayoutingType.None; } - set { throw new NotImplementedException (); } - } - public void RegisterForLayouting (LayoutingType layoutType) { throw new NotImplementedException (); } - public bool UpdateLayout (LayoutingType layoutType) { throw new NotImplementedException (); } - public Rectangle ContextCoordinates (Rectangle r) { return r;} - public Rectangle ScreenCoordinates (Rectangle r) { return r; } - - public ILayoutable Parent { - get { return null; } - set { throw new NotImplementedException (); } - } - public ILayoutable LogicalParent { - get { return null; } - set { throw new NotImplementedException (); } - } - - public Rectangle ClientRectangle { - get { return clientRectangle; } - } - public Interface HostContainer { - get { return this; } - } - public Rectangle getSlot () { return ClientRectangle; } - #endregion - - #if MEASURE_TIME - public PerformanceMeasure clippingMeasure = new PerformanceMeasure("Clipping", 100); - public PerformanceMeasure layoutingMeasure = new PerformanceMeasure("Layouting", 100); - public PerformanceMeasure updateMeasure = new PerformanceMeasure("Update", 100); - public PerformanceMeasure drawingMeasure = new PerformanceMeasure("Drawing", 100); - #endif - #if DEBUG_LAYOUTING - public List<LQIList> LQIsTries = new List<LQIList>(); - public LQIList curLQIsTries = new LQIList(); - public List<LQIList> LQIs = new List<LQIList>(); - public LQIList curLQIs = new LQIList(); - // public static LayoutingQueueItem[] MultipleRunsLQIs { - // get { return curUpdateLQIs.Where(l=>l.LayoutingTries>2 || l.DiscardCount > 0).ToArray(); } - // } - public LayoutingQueueItem currentLQI; - #else - public List<LQIList> LQIs = null;//still create the var for CrowIDE - #endif - } -} - diff --git a/src/ItemTemplate.cs b/src/ItemTemplate.cs deleted file mode 100644 index dda9d152..00000000 --- a/src/ItemTemplate.cs +++ /dev/null @@ -1,301 +0,0 @@ -// -// ItemTemplate.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.IO; -using System.Reflection; -using System.Reflection.Emit; -using System.Threading; -using System.Xml.Serialization; -using System.Xml; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using Crow.IML; - -namespace Crow -{ - /// <summary> Test func on data, return yes if there's children </summary> - public delegate bool BooleanTestOnInstance(object instance); - - /// <summary> - /// Derived from Instantiator with sub data fetching facilities for hierarchical data access. - /// - /// ItemTemplate stores the dynamic method for instantiating the control tree defined in a valid IML file. - /// - /// </summary> - public class ItemTemplate : Instantiator { - #if DESIGN_MODE - public void getIML (System.Xml.XmlDocument doc, System.Xml.XmlNode parentElem){ - if (sourcePath == "#Crow.DefaultItem.template") - return; - - XmlElement xe = doc.CreateElement("ItemTemplate"); - XmlAttribute xa = null; - - if (string.IsNullOrEmpty (sourcePath)) { - //inline item template - using (GraphicObject go = this.CreateInstance()) - go.getIML (doc, xe); - } else { - xa = doc.CreateAttribute ("Path"); - xa.Value = sourcePath; - xe.Attributes.Append (xa); - } - - if (strDataType != "default") { - xa = doc.CreateAttribute ("DataType"); - xa.Value = strDataType; - xe.Attributes.Append (xa); - - if (dataTest != "TypeOf"){ - xa = doc.CreateAttribute ("DataTest"); - xa.Value = dataTest; - xe.Attributes.Append (xa); - } - } - - if (!string.IsNullOrEmpty(fetchMethodName)){ - xa = doc.CreateAttribute ("Data"); - xa.Value = fetchMethodName; - xe.Attributes.Append (xa); - } - - parentElem.AppendChild (xe); - - - } - #endif - - public EventHandler Expand; - public BooleanTestOnInstance HasSubItems; - string strDataType; - string fetchMethodName; - string dataTest; - - #region CTOR - /// <summary> - /// Initializes a new instance of the <see cref="Crow.ItemTemplate"/> class by parsing the file passed as argument. - /// </summary> - /// <param name="path">IML file to parse</param> - /// <param name="_dataType">type this item will be choosen for, or member of the data item</param> - /// <param name="_fetchDataMethod">for hierarchical data, method to call for children fetching</param> - public ItemTemplate(Interface _iface, string path, string _dataTest = "TypeOf", string _dataType = "default", string _fetchDataMethod = null) - : base(_iface, path) { - strDataType = _dataType; - fetchMethodName = _fetchDataMethod; - dataTest = _dataTest; - - } - /// <summary> - /// Initializes a new instance of the <see cref="Crow.ItemTemplate"/> class by parsing the IML fragment passed as arg. - /// </summary> - /// <param name="path">IML fragment to parse</param> - /// <param name="_dataType">type this item will be choosen for, or member of the data item</param> - /// <param name="_fetchDataMethod">for hierarchical data, method to call for children fetching</param> - public ItemTemplate (Interface _iface, Stream ImlFragment, string _dataTest, string _dataType, string _fetchDataMethod) - :base(_iface, ImlFragment) - { - strDataType = _dataType; - fetchMethodName = _fetchDataMethod; - dataTest = _dataTest; - } - /// <summary> - /// Initializes a new instance of the <see cref="Crow.ItemTemplate"/> class using the opened XmlReader in args. - /// </summary> - /// <param name="path">XML reader positionned before or at the root node</param> - /// <param name="_dataType">type this item will be choosen for, or member of the data item</param> - /// <param name="_fetchDataMethod">for hierarchical data, method to call for children fetching</param> - public ItemTemplate (Interface _iface, XmlReader reader, string _dataTest = "TypeOf" , string _dataType = null, string _fetchDataMethod = null) - :base(_iface, reader) - { - strDataType = _dataType; - fetchMethodName = _fetchDataMethod; - dataTest = _dataTest; - } - #endregion - - /// <summary> - /// Creates the expand delegate. - /// </summary> - /// <param name="host">Host.</param> - public void CreateExpandDelegate (TemplatedGroup host){ - Type dataType = null; - //if (host.DataTest == "TypeOf"){ - dataType = CompilerServices.tryGetType(strDataType); -// if (dataType == null) { -// Debug.WriteLine ("ItemTemplate error: DataType not found: {0}.", strDataType); -// return; -// } -// } - Type tmpGrpType = typeof(TemplatedGroup); - Type evtType = typeof(EventHandler); - - //PropertyInfo piData = tmpGrpType.GetProperty ("Data"); - - MethodInfo evtInvoke = evtType.GetMethod ("Invoke"); - ParameterInfo [] evtParams = evtInvoke.GetParameters (); - Type handlerArgsType = evtParams [1].ParameterType; - - Type [] args = { CompilerServices.TObject, CompilerServices.TObject, handlerArgsType }; - - #region Expand dyn meth - //DM is bound to templatedGroup root (arg0) - //arg1 is the sender of the expand event - DynamicMethod dm = new DynamicMethod ("dyn_expand_" + fetchMethodName, - typeof (void), args,typeof(TemplatedGroup), true); - - System.Reflection.Emit.Label gotoEnd; - System.Reflection.Emit.Label ifDataIsNull; - System.Reflection.Emit.Label gotoItemsContainerNotFound; - - ILGenerator il = dm.GetILGenerator (256); - il.DeclareLocal(typeof(GraphicObject)); - - gotoEnd = il.DefineLabel (); - ifDataIsNull = il.DefineLabel (); - gotoItemsContainerNotFound = il.DefineLabel (); - - il.Emit (OpCodes.Ldarg_1);//load sender of expand event - il.Emit(OpCodes.Ldstr, "ItemsContainer");//load name to find - il.Emit (OpCodes.Callvirt, CompilerServices.miFindByName); - il.Emit (OpCodes.Stloc_0);//save items container as loc0 - - //ensure ItemsContainer is not null - il.Emit (OpCodes.Ldloc_0); - il.Emit (OpCodes.Brfalse, gotoItemsContainerNotFound); - - //check that node is not already expanded - il.Emit (OpCodes.Ldarg_0);//push root TemplatedGroup into the stack - il.Emit (OpCodes.Ldarg_1); - il.Emit (OpCodes.Call, CompilerServices.miIsAlreadyExpanded); - il.Emit (OpCodes.Brtrue, gotoEnd); -// il.Emit (OpCodes.Ldloc_0); -// il.Emit (OpCodes.Callvirt, piData.GetGetMethod ()); -// il.Emit (OpCodes.Brfalse, ifDataIsNull); -// il.Emit (OpCodes.Br, gotoEnd); - -// il.MarkLabel(ifDataIsNull); - - //copy the ref of ItemTemplates list TODO: maybe find another way to share it among the nodes? -// FieldInfo fiTemplates = tmpGrpType.GetField("ItemTemplates"); -// il.Emit (OpCodes.Ldloc_0); -// il.Emit (OpCodes.Ldarg_0); -// il.Emit (OpCodes.Ldfld, fiTemplates); -// il.Emit (OpCodes.Stfld, fiTemplates); - - //call 'fetchMethodName' from the dataSource to build the sub nodes list - //il.Emit (OpCodes.Ldarg_0);//load root templatedGroop - - il.Emit (OpCodes.Ldarg_0);//push root TemplatedGroup into the stack - il.Emit (OpCodes.Ldarg_1);//load sender node of expand - il.Emit (OpCodes.Callvirt, CompilerServices.miGetDataSource);//get the dataSource of the sender - - - - if (fetchMethodName != "self") {//special keyword self allows the use of recurent list<<< - if (dataType == null) { - //dataTest was not = TypeOF, so we have to get the type of data - //dynamically and fetch - - il.Emit (OpCodes.Ldstr, fetchMethodName); - il.Emit (OpCodes.Callvirt, CompilerServices.miGetDataTypeAndFetch); - }else - emitGetSubData(il, dataType); - } - //set 'return' from the fetch method as 'data' of the list - //il.Emit (OpCodes.Callvirt, piData.GetSetMethod ()); - il.Emit (OpCodes.Ldloc_0);//load second arg of loadPage, the sender node - il.Emit (OpCodes.Ldstr, dataTest);//load 3rd arg, dataTest kind on subitems - il.Emit (OpCodes.Callvirt, CompilerServices.miLoadPage); - il.Emit (OpCodes.Br, gotoEnd); - - il.MarkLabel(gotoItemsContainerNotFound); - il.EmitWriteLine("ItemsContainer not found in ItemTemplate for " + host.ToString()); - - - il.MarkLabel(gotoEnd); - il.Emit (OpCodes.Ret); - - Expand = (EventHandler)dm.CreateDelegate (evtType, host); - #endregion - - #region Items counting dyn method - //dm is unbound, arg0 is instance of Item container to expand - dm = new DynamicMethod ("dyn_count_" + fetchMethodName, - typeof (bool), new Type[] {CompilerServices.TObject}, true); - il = dm.GetILGenerator (256); - - //get the dataSource of the arg0 - il.Emit (OpCodes.Ldarg_0); - il.Emit (OpCodes.Callvirt, CompilerServices.miGetDataSource); - - if (fetchMethodName != "self") {//special keyword self allows the use of recurent list<<< - if (dataType == null) { - //dataTest was not = TypeOF, so we have to get the type of data - //dynamically and fetch - - il.Emit (OpCodes.Ldstr, fetchMethodName); - il.Emit (OpCodes.Callvirt, CompilerServices.miGetDataTypeAndFetch); - }else - emitGetSubData(il, dataType); - } - - il.Emit (OpCodes.Callvirt, CompilerServices.miGetColCount); - il.Emit (OpCodes.Ldc_I4_0); - il.Emit (OpCodes.Cgt); - il.Emit (OpCodes.Ret); - HasSubItems = (BooleanTestOnInstance)dm.CreateDelegate (typeof(BooleanTestOnInstance)); - #endregion - } - //data is on the stack - void emitGetSubData(ILGenerator il, Type dataType){ - MethodInfo miGetDatas = dataType.GetMethod (fetchMethodName, new Type[] {}); - if (miGetDatas == null) - miGetDatas = CompilerServices.SearchExtMethod (dataType, fetchMethodName); - - if (miGetDatas == null) {//in last resort, search among properties - PropertyInfo piDatas = dataType.GetProperty (fetchMethodName); - if (piDatas == null) { - FieldInfo fiDatas = dataType.GetField (fetchMethodName); - if (fiDatas == null)//and among fields - throw new Exception ("Fetch data member not found in ItemTemplate: " + fetchMethodName); - il.Emit (OpCodes.Ldfld, fiDatas); - return; - } - miGetDatas = piDatas.GetGetMethod (); - if (miGetDatas == null) - throw new Exception ("Read only property for fetching data in ItemTemplate: " + fetchMethodName); - } - - il.Emit (OpCodes.Callvirt, miGetDatas); - } - - - - } -} - diff --git a/src/LayoutingEventArgs.cs b/src/LayoutingEventArgs.cs deleted file mode 100644 index 9254aec4..00000000 --- a/src/LayoutingEventArgs.cs +++ /dev/null @@ -1,41 +0,0 @@ -// -// LayoutingEventArgs.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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; - -namespace Crow -{ - public class LayoutingEventArgs: EventArgs - { - public LayoutingType LayoutType; - - public LayoutingEventArgs (LayoutingType _layoutType) : base() - { - LayoutType = _layoutType; - } - } -} - diff --git a/src/LayoutingQueue.cs b/src/LayoutingQueue.cs deleted file mode 100644 index 5f822bf7..00000000 --- a/src/LayoutingQueue.cs +++ /dev/null @@ -1,110 +0,0 @@ -// -// LayoutingQueue.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.Collections.Generic; -using System.Linq; -using System.Diagnostics; - -namespace Crow -{ - public class LayoutingQueue : LinkedList<LayoutingQueueItem> - { - public LayoutingQueue () - { - } - public void Enqueue(LayoutingType _lt, ILayoutable _object) - { - _object.RegisteredLQINodes.Add(this.AddLast (new LayoutingQueueItem (_lt, _object))); - } - LinkedListNode<LayoutingQueueItem> searchLqi(ILayoutable go, LayoutingType lt){ - for (int i = 0; i < go.RegisteredLQINodes.Count; i++) { - if (go.RegisteredLQINodes [i].Value.LayoutType == lt) - return go.RegisteredLQINodes [i]; - } - return null; - } - public void EnqueueAfterParentSizing (LayoutingType _lt, ILayoutable _object) - { - LayoutingQueueItem lqi = new LayoutingQueueItem (_lt, _object); - LinkedListNode<LayoutingQueueItem> parentLqi = searchLqi (_object.Parent, _lt); - - if (parentLqi == null) - _object.RegisteredLQINodes.Add(this.AddLast (lqi)); - else - _object.RegisteredLQINodes.Add(this.AddAfter (parentLqi, lqi)); - } - public void EnqueueBeforeParentSizing (LayoutingType _lt, ILayoutable _object) - { - LayoutingQueueItem lqi = new LayoutingQueueItem (_lt, _object); - LinkedListNode<LayoutingQueueItem> parentLqi = searchLqi (_object.Parent, _lt); - - if (parentLqi == null) - _object.RegisteredLQINodes.Add(this.AddLast (lqi)); - else - _object.RegisteredLQINodes.Add(this.AddBefore (parentLqi, lqi)); - } - public void EnqueueAfterThisAndParentSizing (LayoutingType _lt, ILayoutable _object) - { - LayoutingQueueItem lqi = new LayoutingQueueItem (_lt, _object); - LayoutingType sizing = LayoutingType.Width; - - if (_lt == LayoutingType.Y) - sizing = LayoutingType.Height; - - LinkedListNode<LayoutingQueueItem> parentLqi = searchLqi (_object.Parent, sizing); - LinkedListNode<LayoutingQueueItem> thisLqi = searchLqi (_object, sizing); - - if (parentLqi == null) { - if (thisLqi != null) - _object.RegisteredLQINodes.Add(this.AddAfter (thisLqi, lqi)); - else - _object.RegisteredLQINodes.Add(this.AddLast (lqi)); - } else { - if (thisLqi == null) - _object.RegisteredLQINodes.Add(this.AddAfter (parentLqi, lqi)); - else { - switch (sizing) { - case LayoutingType.Width: - if (_object.Parent.getBounds().Width<0) - _object.RegisteredLQINodes.Add(this.AddAfter (parentLqi, lqi)); - else - _object.RegisteredLQINodes.Add(this.AddAfter (thisLqi, lqi)); - break; - case LayoutingType.Height: - if (_object.Parent.getBounds().Height<0) - _object.RegisteredLQINodes.Add(this.AddAfter (parentLqi, lqi)); - else - _object.RegisteredLQINodes.Add(this.AddAfter (thisLqi, lqi)); - break; - } - } - } - } - public LayoutingQueueItem Dequeue() - { - LayoutingQueueItem tmp = this.First.Value; - tmp.GraphicObject.RegisteredLQINodes.Remove(this.First); - this.RemoveFirst (); - return tmp; - } - } -} - diff --git a/src/LayoutingQueueItem.cs b/src/LayoutingQueueItem.cs deleted file mode 100644 index 7efdf1bc..00000000 --- a/src/LayoutingQueueItem.cs +++ /dev/null @@ -1,180 +0,0 @@ -// -// LayoutingQueueItem.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Diagnostics; -using System.Collections.Generic; -using System.Linq; - -namespace Crow -{ - [Flags] - public enum LayoutingType : byte - { - None = 0x00, - X = 0x01, - Y = 0x02, - Positioning = 0x03, - Width = 0x04, - Height = 0x08, - Sizing = 0x0C, - ArrangeChildren = 0x10, - All = 0xFF - } - - /// <summary> - /// Element class of the LayoutingQueue - /// </summary> - public struct LayoutingQueueItem - { - /// <summary> Instance of widget to be layouted</summary> - public ILayoutable Layoutable; - /// <summary> Bitfield containing the element of the layout to performs (x|y|width|height)</summary> - public LayoutingType LayoutType; - /// <summary> Unsuccessfull UpdateLayout and requeueing count </summary> - public int LayoutingTries, DiscardCount; - - #if DEBUG_LAYOUTING - public Stopwatch LQITime; - public GraphicObject graphicObject { - get { return Layoutable as GraphicObject; } - } - public string Name { - get { return graphicObject.Name; } - } - public string FullName { - get { return graphicObject.ToString(); } - } - public Measure Width { - get { return graphicObject.Width; } - } - public Measure Height { - get { return graphicObject.Height; } - } - public Rectangle Slot, NewSlot; - #endif - - #region CTOR - public LayoutingQueueItem (LayoutingType _layoutType, ILayoutable _graphicObject) - { - LayoutType = _layoutType; - Layoutable = _graphicObject; - Layoutable.RegisteredLayoutings |= LayoutType; - LayoutingTries = 0; - DiscardCount = 0; - #if DEBUG_LAYOUTING - LQITime = new Stopwatch(); - Slot = Rectangle.Empty; - NewSlot = Rectangle.Empty; - Debug.WriteLine ("\tRegister => " + this.ToString ()); - #endif - } - #endregion - - - public void ProcessLayouting() - { - GraphicObject go = Layoutable as GraphicObject; -// if (go == null) { -// Debug.WriteLine ("ERROR: processLayouting on something else than a graphic object: " + this.ToString ()); -// return; -// } - - go.parentRWLock.EnterReadLock (); - - if (go.Parent == null) {//TODO:improve this - //cancel layouting for object without parent, maybe some were in queue when - //removed from a listbox - #if DEBUG_UPDATE || DEBUG_LAYOUTING - Debug.WriteLine ("ERROR: processLayouting, no parent for: " + this.ToString ()); - #endif - go.parentRWLock.ExitReadLock (); - return; - } - #if DEBUG_LAYOUTING - LQITime.Start(); - Debug.WriteLine ("=> " + this.ToString ()); - #endif - LayoutingTries++; - if (!Layoutable.UpdateLayout (LayoutType)) { - #if DEBUG_LAYOUTING - Debug.WriteLine ("\t\tRequeued"); - #endif - if (LayoutingTries < Interface.MaxLayoutingTries) { - Layoutable.RegisteredLayoutings |= LayoutType; - (Layoutable as GraphicObject).IFace.LayoutingQueue.Enqueue (this); - } else if (DiscardCount < Interface.MaxDiscardCount) { - #if DEBUG_LAYOUTING - Debug.WriteLine ("\t\tDiscarded"); - #endif - LayoutingTries = 0; - DiscardCount++; - Layoutable.RegisteredLayoutings |= LayoutType; - (Layoutable as GraphicObject).IFace.DiscardQueue.Enqueue (this); - } -// #if DEBUG_LAYOUTING - else - Debug.WriteLine ("\tDELETED => " + this.ToString ()); -// #endif - } - else{ - if (LayoutingTries > 2 || DiscardCount > 0) - Debug.WriteLine (this.ToString ()); - } - #if DEBUG_LAYOUTING - LQITime.Stop(); - #endif - go.parentRWLock.ExitReadLock (); - } - - public static implicit operator GraphicObject(LayoutingQueueItem queueItem) - { - return queueItem.Layoutable as GraphicObject; - } - public static implicit operator LayoutingType(LayoutingQueueItem lqi) - { - return lqi.LayoutType; - } - public override string ToString () - { - #if DEBUG_LAYOUTING - return string.Format ("{2};{3};{4} {1}->{0}", LayoutType,Layoutable.ToString(), - LayoutingTries,DiscardCount,LQITime.ElapsedTicks); - #else - return string.Format ("{2};{3} {1}->{0}", LayoutType,Layoutable.ToString(), - LayoutingTries, DiscardCount); - #endif - } - } - public class LQIList : List<LayoutingQueueItem>{ -// #if DEBUG_LAYOUTING -// public List<LayoutingQueueItem> GetRootLQIs(){ -// return this.Where (lqi => lqi.wasTriggeredBy == null).ToList (); -// } -// #endif - } -} - diff --git a/src/Measure.cs b/src/Measure.cs deleted file mode 100644 index 0374f5d9..00000000 --- a/src/Measure.cs +++ /dev/null @@ -1,140 +0,0 @@ -// -// Measure.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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; - -namespace Crow -{ - /// <summary> - /// Measurement unit - /// </summary> - public enum Unit { Pixel, Percent, Inherit } - /// <summary> - /// Measure class allow proportional sizes as well as stretched and fit on content. - /// </summary> - public struct Measure - { - /// <summary> - /// Integer value of the measure - /// </summary> - public int Value; - /// <summary> - /// Measurement unit - /// </summary> - public Unit Units; - - /// <summary> - /// Fit on content, this special measure is defined as a fixed integer set to -1 pixel - /// </summary> - public static Measure Fit = new Measure(-1,Unit.Percent); - /// <summary> - /// Stretched into parent client area. This special measure is defined as a proportional cote - /// set to 100 Percents - /// </summary> - public static Measure Stretched = new Measure(100, Unit.Percent); - public static Measure Inherit = new Measure (0, Unit.Inherit); - #region CTOR - public Measure (int _value, Unit _units = Unit.Pixel) - { - Value = _value; - Units = _units; - } - #endregion - - /// <summary> - /// True is size is fixed in pixels, this means not proportional, stretched nor fit. - /// </summary> - public bool IsFixed { get { return Units == Unit.Pixel; }} - public bool IsFit { get { return Value == -1 && Units == Unit.Percent; }} - public bool IsRelativeToParent { get { return Value >= 0 && Units == Unit.Percent; }} - #region Operators - public static implicit operator int(Measure m){ - return m.Value; - } - public static implicit operator Measure(int i){ - return new Measure(i); - } - public static implicit operator string(Measure m){ - return m.ToString(); - } - public static implicit operator Measure(string s){ - return Measure.Parse(s); - } - - public static bool operator ==(Measure m1, Measure m2){ - return m1.Value == m2.Value && m1.Units == m2.Units; - } - public static bool operator !=(Measure m1, Measure m2){ - return !(m1.Value == m2.Value && m1.Units == m2.Units); - } - #endregion - - #region Object overrides - public override int GetHashCode () - { - return Value.GetHashCode (); - } - public override bool Equals (object obj) - { - return (obj == null || obj.GetType() != typeof(Measure)) ? - false : - this == (Measure)obj; - } - public override string ToString () - { - return Units == Unit.Inherit ? "Inherit" : - Value == -1 ? "Fit" : - Units == Unit.Percent ? Value == 100 ? "Stretched" : - Value.ToString () + "%" : Value.ToString (); - } - #endregion - - public static Measure Parse(string s){ - if (string.IsNullOrEmpty (s)) - return Measure.Stretched; - - string st = s.Trim (); - int tmp = 0; - - if (string.Equals ("Inherit", st, StringComparison.Ordinal)) - return Measure.Inherit; - else if (string.Equals ("Fit", st, StringComparison.Ordinal)) - return Measure.Fit; - else if (string.Equals ("Stretched", s, StringComparison.Ordinal)) - return Measure.Stretched; - else { - if (st.EndsWith ("%", StringComparison.Ordinal)) { - if (int.TryParse (s.Substring(0, st.Length - 1), out tmp)) - return new Measure (tmp, Unit.Percent); - }else if (int.TryParse (s, out tmp)) - return new Measure (tmp); - } - - throw new Exception ("Error parsing Measure."); - } - - } -} diff --git a/src/Mono.Cairo/Antialias.cs b/src/Mono.Cairo/Antialias.cs deleted file mode 100644 index 9ea64f75..00000000 --- a/src/Mono.Cairo/Antialias.cs +++ /dev/null @@ -1,43 +0,0 @@ -// -// Mono.Cairo.Antialias.cs -// -// Authors: -// Duncan Mak (duncan@ximian.com) -// Hisham Mardam Bey (hisham.mardambey@gmail.com) -// -// (C) Ximian, Inc. 2003 -// Copyright (C) 2004 Novell, Inc (http://www.novell.com) -// -// 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; - -namespace Cairo -{ - [Serializable] - public enum Antialias - { - Default, - None, - Gray, - Subpixel, - } -} diff --git a/src/Mono.Cairo/Cairo.cs b/src/Mono.Cairo/Cairo.cs deleted file mode 100644 index c0a5f2ab..00000000 --- a/src/Mono.Cairo/Cairo.cs +++ /dev/null @@ -1,53 +0,0 @@ -// -// Cairo.cs - a simplistic binding of the Cairo API to C#. -// -// Authors: Duncan Mak (duncan@ximian.com) -// Hisham Mardam Bey (hisham.mardambey@gmail.com) -// John Luke (john.luke@gmail.com) -// Alp Toker (alp@atoker.com) -// -// (C) Ximian, Inc. 2003 -// Copyright (C) 2004 Novell, Inc (http://www.novell.com) -// Copyright (C) 2005 John Luke -// Copyright (C) 2006 Alp Toker -// -// 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.Runtime.InteropServices; - -namespace Cairo -{ - public static class CairoAPI { - static public int Version { - get { - return Cairo.NativeMethods.cairo_version (); - } - } - - static public string VersionString { - get { - IntPtr x = Cairo.NativeMethods.cairo_version_string (); - return Marshal.PtrToStringAnsi (x); - } - } - } -} diff --git a/src/Mono.Cairo/CairoDebug.cs b/src/Mono.Cairo/CairoDebug.cs deleted file mode 100644 index d694bbb5..00000000 --- a/src/Mono.Cairo/CairoDebug.cs +++ /dev/null @@ -1,82 +0,0 @@ -// -// CairoDebug.cs -// -// Author: -// Michael Hutchinson (mhutch@xamarin.com) -// -// Copyright (C) 2013 Xamarin Inc. (http://www.xamarin.com) -// -// 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; - -namespace Cairo { - - static class CairoDebug - { - static System.Collections.Generic.Dictionary<IntPtr,string> traces; - - public static readonly bool Enabled; - - static CairoDebug () - { - var dbg = Environment.GetEnvironmentVariable ("MONO_CAIRO_DEBUG_DISPOSE"); - if (dbg == null) - return; - Enabled = true; - traces = new System.Collections.Generic.Dictionary<IntPtr,string> (); - } - - public static void OnAllocated (IntPtr obj) - { - if (!Enabled) - throw new InvalidOperationException (); - - traces[obj] = Environment.StackTrace; - } - - public static void OnDisposed<T> (IntPtr obj, bool disposing) - { - if (disposing && !Enabled) - throw new InvalidOperationException (); - - if (Environment.HasShutdownStarted) - return; - - if (!disposing) { - Console.Error.WriteLine ("{0} is leaking, programmer is missing a call to Dispose", typeof(T).FullName); - if (Enabled) { - string val; - if (traces.TryGetValue (obj, out val)) { - Console.Error.WriteLine ("Allocated from:"); - Console.Error.WriteLine (val); - } - } else { - Console.Error.WriteLine ("Set MONO_CAIRO_DEBUG_DISPOSE to track allocation traces"); - } - } - - if (Enabled) - traces.Remove (obj); - } - } - -} diff --git a/src/Mono.Cairo/Color.cs b/src/Mono.Cairo/Color.cs deleted file mode 100644 index 030089e8..00000000 --- a/src/Mono.Cairo/Color.cs +++ /dev/null @@ -1,75 +0,0 @@ -// -// Mono.Cairo.Context.cs -// -// Author: -// Duncan Mak (duncan@ximian.com) -// Miguel de Icaza (miguel@novell.com) -// Hisham Mardam Bey (hisham.mardambey@gmail.com) -// Alp Toker (alp@atoker.com) -// -// (C) Ximian Inc, 2003. -// (C) Novell Inc, 2003. -// -// This is an OO wrapper API for the Cairo API. -// -// Copyright (C) 2004 Novell, Inc (http://www.novell.com) -// -// 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. -// - -namespace Cairo { - - public struct Color - { - public Color(double r, double g, double b) : this (r, g, b, 1.0) - { - } - - public Color(double r, double g, double b, double a) - { - this.r = r; - this.g = g; - this.b = b; - this.a = a; - } - - double r, g, b, a; - - public double R { - get { return r; } - set { r = value; } - } - - public double G { - get { return g; } - set { g = value; } - } - - public double B { - get { return b; } - set { b = value; } - } - - public double A { - get { return a; } - set { a = value; } - } - } -} diff --git a/src/Mono.Cairo/Content.cs b/src/Mono.Cairo/Content.cs deleted file mode 100644 index a88d35a9..00000000 --- a/src/Mono.Cairo/Content.cs +++ /dev/null @@ -1,43 +0,0 @@ -// -// Mono.Cairo.Content.cs -// -// Authors: -// Duncan Mak (duncan@ximian.com) -// Hisham Mardam Bey (hisham.mardambey@gmail.com) -// -// (C) Ximian, Inc. 2003 -// Copyright (C) 2004 Novell, Inc (http://www.novell.com) -// -// 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; - -namespace Cairo -{ - //[Flags] - [Serializable] - public enum Content - { - Color = 0x1000, - Alpha = 0x2000, - ColorAlpha = 0x3000, - } -} diff --git a/src/Mono.Cairo/Context.cs b/src/Mono.Cairo/Context.cs deleted file mode 100644 index 264774dd..00000000 --- a/src/Mono.Cairo/Context.cs +++ /dev/null @@ -1,918 +0,0 @@ -// -// Mono.Cairo.Context.cs -// -// Author: -// Duncan Mak (duncan@ximian.com) -// Miguel de Icaza (miguel@novell.com) -// Hisham Mardam Bey (hisham.mardambey@gmail.com) -// Alp Toker (alp@atoker.com) -// -// (C) Ximian Inc, 2003. -// (C) Novell Inc, 2003. -// -// This is an OO wrapper API for the Cairo API. -// -// Copyright (C) 2004 Novell, Inc (http://www.novell.com) -// -// 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.Runtime.InteropServices; -using System.Text; -using Cairo; - -namespace Cairo { - - [Obsolete ("Renamed Cairo.Context per suggestion from cairo binding guidelines.")] - public class Graphics : Context { - public Graphics (IntPtr state) : base (state) {} - public Graphics (Surface surface) : base (surface) {} - } - - public class Context : IDisposable - { - IntPtr handle = IntPtr.Zero; - - static int native_glyph_size, c_compiler_long_size; - - static Context () - { - // - // This is used to determine what kind of structure - // we should use to marshal Glyphs, as the public - // definition in Cairo uses `long', which can be - // 32 bits or 64 bits depending on the platform. - // - // We assume that sizeof(long) == sizeof(void*) - // except in the case of Win64 where sizeof(long) - // is 32 bits - // - int ptr_size = Marshal.SizeOf (typeof (IntPtr)); - - PlatformID platform = Environment.OSVersion.Platform; - if (platform == PlatformID.Win32NT || - platform == PlatformID.Win32S || - platform == PlatformID.Win32Windows || - platform == PlatformID.WinCE || - ptr_size == 4){ - c_compiler_long_size = 4; - native_glyph_size = Marshal.SizeOf (typeof (NativeGlyph_4byte_longs)); - } else { - c_compiler_long_size = 8; - native_glyph_size = Marshal.SizeOf (typeof (Glyph)); - } - } - - public Context (Surface surface) : this (NativeMethods.cairo_create (surface.Handle), true) - { - } - - - public Context (IntPtr handle, bool owner) - { - this.handle = handle; - if (!owner) - NativeMethods.cairo_reference (handle); - if (CairoDebug.Enabled) - CairoDebug.OnAllocated (handle); - } - - [Obsolete] - public Context (IntPtr state) : this (state, true) - { - } - - ~Context () - { - Dispose (false); - } - - public void Dispose () - { - Dispose (true); - GC.SuppressFinalize (this); - } - - protected virtual void Dispose (bool disposing) - { - if (!disposing || CairoDebug.Enabled) - CairoDebug.OnDisposed<Context> (handle, disposing); - - if (!disposing|| handle == IntPtr.Zero) - return; - - NativeMethods.cairo_destroy (handle); - handle = IntPtr.Zero; - - } - - public void Save () - { - NativeMethods.cairo_save (handle); - } - - public void Restore () - { - NativeMethods.cairo_restore (handle); - } - - public Antialias Antialias { - get { return NativeMethods.cairo_get_antialias (handle); } - set { NativeMethods.cairo_set_antialias (handle, value); } - } - - public Cairo.Status Status { - get { - return NativeMethods.cairo_status (handle); - } - } - - public IntPtr Handle { - get { - return handle; - } - } - - public Operator Operator { - set { - NativeMethods.cairo_set_operator (handle, value); - } - - get { - return NativeMethods.cairo_get_operator (handle); - } - } - - [Obsolete ("Use SetSourceColor method")] - public Color Color { - set { - SetSourceColor (value); - } - } - - [Obsolete ("Use SetSourceRGBA method")] - public Cairo.Color ColorRgb { - set { - Color = new Color (value.R, value.G, value.B); - } - } - - public double Tolerance { - get { - return NativeMethods.cairo_get_tolerance (handle); - } - - set { - NativeMethods.cairo_set_tolerance (handle, value); - } - } - - public Cairo.FillRule FillRule { - set { - NativeMethods.cairo_set_fill_rule (handle, value); - } - - get { - return NativeMethods.cairo_get_fill_rule (handle); - } - } - - public double LineWidth { - set { - NativeMethods.cairo_set_line_width (handle, value); - } - - get { - return NativeMethods.cairo_get_line_width (handle); - } - } - - public Cairo.LineCap LineCap { - set { - NativeMethods.cairo_set_line_cap (handle, value); - } - - get { - return NativeMethods.cairo_get_line_cap (handle); - } - } - - public Cairo.LineJoin LineJoin { - set { - NativeMethods.cairo_set_line_join (handle, value); - } - - get { - return NativeMethods.cairo_get_line_join (handle); - } - } - - public void SetDash (double [] dashes, double offset) - { - NativeMethods.cairo_set_dash (handle, dashes, dashes.Length, offset); - } - - [Obsolete("Use GetSource/SetSource")] - public Pattern Pattern { - set { - SetSource (value); - } - get { - return GetSource (); - } - } - - //This is obsolete because it wasn't obvious it needed to be disposed - [Obsolete("Use GetSource/SetSource")] - public Pattern Source { - set { - SetSource (value); - } - get { - return GetSource (); - } - } - - public void SetSource (Pattern source) - { - NativeMethods.cairo_set_source (handle, source.Handle); - } - - public Pattern GetSource () - { - var ptr = NativeMethods.cairo_get_source (handle); - return Cairo.Pattern.Lookup (ptr, false); - } - - public double MiterLimit { - set { - NativeMethods.cairo_set_miter_limit (handle, value); - } - - get { - return NativeMethods.cairo_get_miter_limit (handle); - } - } - - public PointD CurrentPoint { - get { - double x, y; - NativeMethods.cairo_get_current_point (handle, out x, out y); - return new PointD (x, y); - } - } - - public bool HasCurrentPoint { - get { - return NativeMethods.cairo_has_current_point (handle); - } - } - - [Obsolete ("Use GetTarget/SetTarget")] - public Cairo.Surface Target { - set { - if (handle != IntPtr.Zero) - NativeMethods.cairo_destroy (handle); - - handle = NativeMethods.cairo_create (value.Handle); - } - - get { - return GetTarget (); - } - } - - public Surface GetTarget () - { - return Surface.Lookup (NativeMethods.cairo_get_target (handle), false); - } - - public void SetTarget (Surface target) - { - if (handle != IntPtr.Zero) - NativeMethods.cairo_destroy (handle); - handle = NativeMethods.cairo_create (target.Handle); - } - - [Obsolete("Use GetScaledFont/SetScaledFont")] - public ScaledFont ScaledFont { - set { - SetScaledFont (value); - } - - get { - return GetScaledFont (); - } - } - - public ScaledFont GetScaledFont () - { - return new ScaledFont (NativeMethods.cairo_get_scaled_font (handle), false); - } - - public void SetScaledFont (ScaledFont font) - { - NativeMethods.cairo_set_scaled_font (handle, font.Handle); - } - - public uint ReferenceCount { - get { return NativeMethods.cairo_get_reference_count (handle); } - } - - public void SetSourceColor (Color color) - { - NativeMethods.cairo_set_source_rgba (handle, color.R, color.G, color.B, color.A); - } - - public void SetSourceRGB (double r, double g, double b) - { - NativeMethods.cairo_set_source_rgb (handle, r, g, b); - } - - public void SetSourceRGBA (double r, double g, double b, double a) - { - NativeMethods.cairo_set_source_rgba (handle, r, g, b, a); - } - - //[Obsolete ("Use SetSource method (with double parameters)")] - public void SetSourceSurface (Surface source, int x, int y) - { - NativeMethods.cairo_set_source_surface (handle, source.Handle, x, y); - } - - public void SetSource (Surface source, double x, double y) - { - NativeMethods.cairo_set_source_surface (handle, source.Handle, x, y); - } - - public void SetSource (Surface source) - { - NativeMethods.cairo_set_source_surface (handle, source.Handle, 0, 0); - } - -#region Path methods - - public void NewPath () - { - NativeMethods.cairo_new_path (handle); - } - - public void NewSubPath () - { - NativeMethods.cairo_new_sub_path (handle); - } - - public void MoveTo (PointD p) - { - MoveTo (p.X, p.Y); - } - - public void MoveTo (double x, double y) - { - NativeMethods.cairo_move_to (handle, x, y); - } - - public void LineTo (PointD p) - { - LineTo (p.X, p.Y); - } - - public void LineTo (double x, double y) - { - NativeMethods.cairo_line_to (handle, x, y); - } - - public void CurveTo (PointD p1, PointD p2, PointD p3) - { - CurveTo (p1.X, p1.Y, p2.X, p2.Y, p3.X, p3.Y); - } - - public void CurveTo (double x1, double y1, double x2, double y2, double x3, double y3) - { - NativeMethods.cairo_curve_to (handle, x1, y1, x2, y2, x3, y3); - } - - public void RelMoveTo (Distance d) - { - RelMoveTo (d.Dx, d.Dy); - } - - public void RelMoveTo (double dx, double dy) - { - NativeMethods.cairo_rel_move_to (handle, dx, dy); - } - - public void RelLineTo (Distance d) - { - RelLineTo (d.Dx, d.Dy); - } - - public void RelLineTo (double dx, double dy) - { - NativeMethods.cairo_rel_line_to (handle, dx, dy); - } - - public void RelCurveTo (Distance d1, Distance d2, Distance d3) - { - RelCurveTo (d1.Dx, d1.Dy, d2.Dx, d2.Dy, d3.Dx, d3.Dy); - } - - public void RelCurveTo (double dx1, double dy1, double dx2, double dy2, double dx3, double dy3) - { - NativeMethods.cairo_rel_curve_to (handle, dx1, dy1, dx2, dy2, dx3, dy3); - } - - public void Arc (double xc, double yc, double radius, double angle1, double angle2) - { - NativeMethods.cairo_arc (handle, xc, yc, radius, angle1, angle2); - } - - public void ArcNegative (double xc, double yc, double radius, double angle1, double angle2) - { - NativeMethods.cairo_arc_negative (handle, xc, yc, radius, angle1, angle2); - } - - public void Rectangle (Crow.Rectangle rectangle) - { - Rectangle (rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height); - } - - public void Rectangle (PointD p, double width, double height) - { - Rectangle (p.X, p.Y, width, height); - } - - public void Rectangle (double x, double y, double width, double height) - { - NativeMethods.cairo_rectangle (handle, x, y, width, height); - } - - public void ClosePath () - { - NativeMethods.cairo_close_path (handle); - } - - public Path CopyPath () - { - return new Path (NativeMethods.cairo_copy_path (handle)); - } - - public Path CopyPathFlat () - { - return new Path (NativeMethods.cairo_copy_path_flat (handle)); - } - - public void AppendPath (Path path) - { - NativeMethods.cairo_append_path (handle, path.Handle); - } - -#endregion - -#region Painting Methods - public void Paint () - { - NativeMethods.cairo_paint (handle); - } - - public void PaintWithAlpha (double alpha) - { - NativeMethods.cairo_paint_with_alpha (handle, alpha); - } - - public void Mask (Pattern pattern) - { - NativeMethods.cairo_mask (handle, pattern.Handle); - } - - public void MaskSurface (Surface surface, double surface_x, double surface_y) - { - NativeMethods.cairo_mask_surface (handle, surface.Handle, surface_x, surface_y); - } - - public void Stroke () - { - NativeMethods.cairo_stroke (handle); - } - - public void StrokePreserve () - { - NativeMethods.cairo_stroke_preserve (handle); - } - - public Crow.Rectangle StrokeExtents () - { - double x1, y1, x2, y2; - NativeMethods.cairo_stroke_extents (handle, out x1, out y1, out x2, out y2); - return new Crow.Rectangle ((int)x1, (int)y1, (int)(x2 - x1), (int)(y2 - y1)); - } - - public void Fill () - { - NativeMethods.cairo_fill (handle); - } - - public Crow.Rectangle FillExtents () - { - double x1, y1, x2, y2; - NativeMethods.cairo_fill_extents (handle, out x1, out y1, out x2, out y2); - return new Crow.Rectangle ((int)x1, (int)y1, (int)(x2 - x1), (int)(y2 - y1)); - } - - public void FillPreserve () - { - NativeMethods.cairo_fill_preserve (handle); - } - -#endregion - - public void Clip () - { - NativeMethods.cairo_clip (handle); - } - - public void ClipPreserve () - { - NativeMethods.cairo_clip_preserve (handle); - } - - public void ResetClip () - { - NativeMethods.cairo_reset_clip (handle); - } - - public bool InClip (double x, double y) - { - return NativeMethods.cairo_in_clip (handle, x, y); - } - public RectangleList GetClipRectangles (){ - return (RectangleList)Marshal.PtrToStructure (NativeMethods.cairo_copy_clip_rectangle_list (handle), typeof(RectangleList)); - } - public void ClipExtendRectangle (){ - double x1, y1, x2, y2; - NativeMethods.cairo_clip_extents (handle, out x1, out y1, out x2, out y2); - NativeMethods.cairo_rectangle (handle, x1, y1, x2 - x1, y2 - y1); - } - public bool InStroke (double x, double y) - { - return NativeMethods.cairo_in_stroke (handle, x, y); - } - - public bool InFill (double x, double y) - { - return NativeMethods.cairo_in_fill (handle, x, y); - } - - public Pattern PopGroup () - { - return Pattern.Lookup (NativeMethods.cairo_pop_group (handle), true); - } - - public void PopGroupToSource () - { - NativeMethods.cairo_pop_group_to_source (handle); - } - - public void PushGroup () - { - NativeMethods.cairo_push_group (handle); - } - - public void PushGroup (Content content) - { - NativeMethods.cairo_push_group_with_content (handle, content); - } - - [Obsolete ("Use GetGroupTarget()")] - public Surface GroupTarget { - get { - return GetGroupTarget (); - } - } - - public Surface GetGroupTarget () - { - IntPtr surface = NativeMethods.cairo_get_group_target (handle); - return Surface.Lookup (surface, false); - } - - public void Rotate (double angle) - { - NativeMethods.cairo_rotate (handle, angle); - } - - public void Scale (double sx, double sy) - { - NativeMethods.cairo_scale (handle, sx, sy); - } - - public void Translate (double tx, double ty) - { - NativeMethods.cairo_translate (handle, tx, ty); - } - - public void Transform (Matrix m) - { - NativeMethods.cairo_transform (handle, m); - } - - [Obsolete("Use UserToDevice instead")] - public void TransformPoint (ref double x, ref double y) - { - NativeMethods.cairo_user_to_device (handle, ref x, ref y); - } - - [Obsolete("Use UserToDeviceDistance instead")] - public void TransformDistance (ref double dx, ref double dy) - { - NativeMethods.cairo_user_to_device_distance (handle, ref dx, ref dy); - } - - [Obsolete("Use InverseTransformPoint instead")] - public void InverseTransformPoint (ref double x, ref double y) - { - NativeMethods.cairo_device_to_user (handle, ref x, ref y); - } - - [Obsolete("Use DeviceToUserDistance instead")] - public void InverseTransformDistance (ref double dx, ref double dy) - { - NativeMethods.cairo_device_to_user_distance (handle, ref dx, ref dy); - } - - public void UserToDevice (ref double x, ref double y) - { - NativeMethods.cairo_user_to_device (handle, ref x, ref y); - } - - public void UserToDeviceDistance (ref double dx, ref double dy) - { - NativeMethods.cairo_user_to_device_distance (handle, ref dx, ref dy); - } - - public void DeviceToUser (ref double x, ref double y) - { - NativeMethods.cairo_device_to_user (handle, ref x, ref y); - } - - public void DeviceToUserDistance (ref double dx, ref double dy) - { - NativeMethods.cairo_device_to_user_distance (handle, ref dx, ref dy); - } - - public Matrix Matrix { - set { - NativeMethods.cairo_set_matrix (handle, value); - } - - get { - Matrix m = new Matrix(); - NativeMethods.cairo_get_matrix (handle, m); - return m; - } - } - - public void SetFontSize (double scale) - { - NativeMethods.cairo_set_font_size (handle, scale); - } - - public void IdentityMatrix () - { - NativeMethods.cairo_identity_matrix (handle); - } - - [Obsolete ("Use SetFontSize() instead.")] - public void FontSetSize (double scale) - { - SetFontSize (scale); - } - - [Obsolete ("Use SetFontSize() instead.")] - public double FontSize { - set { SetFontSize (value); } - } - - public Matrix FontMatrix { - get { - Matrix m; - NativeMethods.cairo_get_font_matrix (handle, out m); - return m; - } - set { NativeMethods.cairo_set_font_matrix (handle, value); } - } - - public FontOptions FontOptions { - get { - FontOptions options = new FontOptions (); - NativeMethods.cairo_get_font_options (handle, options.Handle); - return options; - } - set { NativeMethods.cairo_set_font_options (handle, value.Handle); } - } - - [StructLayout(LayoutKind.Sequential)] - internal struct NativeGlyph_4byte_longs { - public int index; - public double x; - public double y; - - public NativeGlyph_4byte_longs (Glyph source) - { - index = (int) source.index; - x = source.x; - y = source.y; - } - } - - static internal IntPtr FromGlyphToUnManagedMemory(Glyph [] glyphs) - { - IntPtr dest = Marshal.AllocHGlobal (native_glyph_size * glyphs.Length); - long pos = dest.ToInt64(); - - if (c_compiler_long_size == 8){ - foreach (Glyph g in glyphs){ - Marshal.StructureToPtr (g, (IntPtr)pos, false); - pos += native_glyph_size; - } - } else { - foreach (Glyph g in glyphs){ - NativeGlyph_4byte_longs n = new NativeGlyph_4byte_longs (g); - - Marshal.StructureToPtr (n, (IntPtr)pos, false); - pos += native_glyph_size; - } - } - - return dest; - } - - public void ShowGlyphs (Glyph[] glyphs) - { - IntPtr ptr; - - ptr = FromGlyphToUnManagedMemory (glyphs); - - NativeMethods.cairo_show_glyphs (handle, ptr, glyphs.Length); - - Marshal.FreeHGlobal (ptr); - } - - [Obsolete("The matrix argument was never used, use ShowGlyphs(Glyphs []) instead")] - public void ShowGlyphs (Matrix matrix, Glyph[] glyphs) - { - ShowGlyphs (glyphs); - } - - [Obsolete("The matrix argument was never used, use GlyphPath(Glyphs []) instead")] - public void GlyphPath (Matrix matrix, Glyph[] glyphs) - { - GlyphPath (glyphs); - } - - public void GlyphPath (Glyph[] glyphs) - { - IntPtr ptr; - - ptr = FromGlyphToUnManagedMemory (glyphs); - - NativeMethods.cairo_glyph_path (handle, ptr, glyphs.Length); - - Marshal.FreeHGlobal (ptr); - - } - - public FontExtents FontExtents { - get { - FontExtents f_extents; - NativeMethods.cairo_font_extents (handle, out f_extents); - return f_extents; - } - } - - public void CopyPage () - { - NativeMethods.cairo_copy_page (handle); - } - - [Obsolete ("Use SelectFontFace() instead.")] - public void FontFace (string family, FontSlant slant, FontWeight weight) - { - SelectFontFace (family, slant, weight); - } - - [Obsolete("Use GetFontFace/SetFontFace")] - public FontFace ContextFontFace { - get { - return GetContextFontFace (); - } - set { - SetContextFontFace (value); - } - } - - public FontFace GetContextFontFace () - { - return Cairo.FontFace.Lookup (NativeMethods.cairo_get_font_face (handle), false); - } - - public void SetContextFontFace (FontFace value) - { - NativeMethods.cairo_set_font_face (handle, value == null ? IntPtr.Zero : value.Handle); - } - - public void SelectFontFace (string family, FontSlant slant, FontWeight weight) - { - NativeMethods.cairo_select_font_face (handle, family, slant, weight); - } - - public void ShowPage () - { - NativeMethods.cairo_show_page (handle); - } - - private static byte[] TerminateUtf8(byte[] utf8) - { - if (utf8.Length > 0 && utf8[utf8.Length - 1] == 0) - return utf8; - var termedArray = new byte[utf8.Length + 1]; - Array.Copy(utf8, termedArray, utf8.Length); - termedArray[utf8.Length] = 0; - return termedArray; - } - - private static byte[] TerminateUtf8(string s) - { - // compute the byte count including the trailing \0 - var byteCount = Encoding.UTF8.GetMaxByteCount(s.Length + 1); - var bytes = new byte[byteCount]; - Encoding.UTF8.GetBytes(s, 0, s.Length, bytes, 0); - return bytes; - } - - public void ShowText(string str) - { - NativeMethods.cairo_show_text (handle, TerminateUtf8(str)); - } - - public void ShowText(byte[] utf8) - { - NativeMethods.cairo_show_text (handle, TerminateUtf8(utf8)); - } - - public void TextPath(string str) - { - NativeMethods.cairo_text_path (handle, TerminateUtf8(str)); - } - - public void TextPath(byte[] utf8) - { - NativeMethods.cairo_text_path (handle, TerminateUtf8(utf8)); - } - - public TextExtents TextExtents(string s) - { - TextExtents extents; - NativeMethods.cairo_text_extents (handle, TerminateUtf8(s), out extents); - return extents; - } - - public TextExtents TextExtents(byte[] utf8) - { - TextExtents extents; - NativeMethods.cairo_text_extents (handle, TerminateUtf8(utf8), out extents); - return extents; - } - - public TextExtents GlyphExtents (Glyph[] glyphs) - { - IntPtr ptr = FromGlyphToUnManagedMemory (glyphs); - - TextExtents extents; - - NativeMethods.cairo_glyph_extents (handle, ptr, glyphs.Length, out extents); - - Marshal.FreeHGlobal (ptr); - - return extents; - } - } -} diff --git a/src/Mono.Cairo/DRMDevice.cs b/src/Mono.Cairo/DRMDevice.cs deleted file mode 100644 index a03195fb..00000000 --- a/src/Mono.Cairo/DRMDevice.cs +++ /dev/null @@ -1,53 +0,0 @@ -// -// Mono.Cairo.Device.cs -// -// Authors: -// JP Bruyère (jp_bruyere@hotmail.com) -// -// This is an OO wrapper API for the Cairo API -// -// Copyright (C) 2016 JP 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; - -namespace Cairo -{ - public class DRMDevice : Device - { - public DRMDevice () : base (NativeMethods.cairo_drm_device_default (), true) - { - } - public DRMDevice (int fd) : base (NativeMethods.cairo_drm_device_get_for_fd (fd), true) - { - } - public DRMDevice (IntPtr udev_device) : base (NativeMethods.cairo_drm_device_get (udev_device), true) - { - } - - public int FileDescriptor { - get { return NativeMethods.cairo_drm_device_get_fd (Handle); } - } - - public void DeviceThrottle () { NativeMethods.cairo_drm_device_throttle (Handle);} - } -} - diff --git a/src/Mono.Cairo/DRMSurface.cs b/src/Mono.Cairo/DRMSurface.cs deleted file mode 100644 index 248541c7..00000000 --- a/src/Mono.Cairo/DRMSurface.cs +++ /dev/null @@ -1,53 +0,0 @@ -// -// Mono.Cairo.GLSurface.cs -// -// Authors: -// JP Bruyère (jp_bruyere@hotmail.com) -// -// This is an OO wrapper API for the Cairo API -// -// Copyright (C) 2016 JP 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; - -namespace Cairo { - - public class DRMSurface : Surface - { - - public DRMSurface (IntPtr ptr, bool own) : base (ptr, own) - {} - - public DRMSurface (DRMDevice device, Format format, int width, int height) - : base (NativeMethods.cairo_drm_surface_create (device.Handle, format, width, height), true) - {} - - public DRMSurface (DRMDevice device, uint name, Format format, int width, int height, int stride) - : base (NativeMethods.cairo_drm_surface_create_for_name (device.Handle, name, format, width, height, stride), true) - {} - - public DRMSurface (DRMDevice device, IntPtr imageSurface) - : base (NativeMethods.cairo_drm_surface_create_from_cacheable_image (device.Handle, imageSurface), true) - {} - } -} diff --git a/src/Mono.Cairo/Device.cs b/src/Mono.Cairo/Device.cs deleted file mode 100644 index 06715bc9..00000000 --- a/src/Mono.Cairo/Device.cs +++ /dev/null @@ -1,101 +0,0 @@ -// -// Mono.Cairo.Device.cs -// -// Authors: -// JP Bruyère (jp_bruyere@hotmail.com) -// -// This is an OO wrapper API for the Cairo API -// -// Copyright (C) 2016 JP 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; - -namespace Cairo -{ - public class Device : IDisposable - { - IntPtr handle = IntPtr.Zero; - - protected Device() - { - } - - protected Device (IntPtr ptr) : this (ptr, true) - { - } - - protected Device (IntPtr handle, bool owner) - { - this.handle = handle; - if (!owner) - NativeMethods.cairo_device_reference (handle); - if (CairoDebug.Enabled) - CairoDebug.OnAllocated (handle); - } - - ~Device () - { - Dispose (false); - } - - public IntPtr Handle { - get { - return handle; - } - } - public string Status { - get { - return System.Runtime.InteropServices.Marshal.PtrToStringAuto(NativeMethods.cairo_status_to_string (NativeMethods.cairo_device_status (handle))); - } - } - public void SetThreadAware (bool value){ - NativeMethods.cairo_gl_device_set_thread_aware (handle, value ? 1 : 0); - } - public Status Acquire() - { - return NativeMethods.cairo_device_acquire (handle); - } - public void Release() - { - NativeMethods.cairo_device_release (handle); - } - - public void Dispose () - { - Dispose (true); - GC.SuppressFinalize (this); - } - - protected virtual void Dispose (bool disposing) - { - if (!disposing || CairoDebug.Enabled) - CairoDebug.OnDisposed<Device> (handle, disposing); - - if (!disposing || handle == IntPtr.Zero) - return; - - NativeMethods.cairo_device_destroy (handle); - handle = IntPtr.Zero; - } - } -} - diff --git a/src/Mono.Cairo/DirectFBSurface.cs b/src/Mono.Cairo/DirectFBSurface.cs deleted file mode 100644 index afa57b7d..00000000 --- a/src/Mono.Cairo/DirectFBSurface.cs +++ /dev/null @@ -1,43 +0,0 @@ -// -// Mono.Cairo.DirectFBSurface.cs -// -// Authors: -// Alp Toker -// -// (C) Alp Toker, 2006. -// -// 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; - -namespace Cairo { - public class DirectFBSurface : Surface - { - internal DirectFBSurface (IntPtr handle, bool owns) : base (handle, owns) - { - } - - public DirectFBSurface (IntPtr dfb, IntPtr dfb_surface) - : base (NativeMethods.cairo_directfb_surface_create (dfb, dfb_surface), true) - { - } - } -} diff --git a/src/Mono.Cairo/Distance.cs b/src/Mono.Cairo/Distance.cs deleted file mode 100644 index 7cba3729..00000000 --- a/src/Mono.Cairo/Distance.cs +++ /dev/null @@ -1,58 +0,0 @@ -// -// Mono.Cairo.Context.cs -// -// Author: -// Duncan Mak (duncan@ximian.com) -// Miguel de Icaza (miguel@novell.com) -// Hisham Mardam Bey (hisham.mardambey@gmail.com) -// Alp Toker (alp@atoker.com) -// -// (C) Ximian Inc, 2003. -// (C) Novell Inc, 2003. -// -// This is an OO wrapper API for the Cairo API. -// -// Copyright (C) 2004 Novell, Inc (http://www.novell.com) -// -// 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. -// - -namespace Cairo { - - public struct Distance - { - public Distance (double dx, double dy) - { - this.dx = dx; - this.dy = dy; - } - - double dx, dy; - public double Dx { - get { return dx; } - set { dx = value; } - } - - public double Dy { - get { return dy; } - set { dy = value; } - } - } -} diff --git a/src/Mono.Cairo/EGLDevice.cs b/src/Mono.Cairo/EGLDevice.cs deleted file mode 100644 index 45c988a3..00000000 --- a/src/Mono.Cairo/EGLDevice.cs +++ /dev/null @@ -1,41 +0,0 @@ -// -// Mono.Cairo.Device.cs -// -// Authors: -// JP Bruyère (jp_bruyere@hotmail.com) -// -// This is an OO wrapper API for the Cairo API -// -// Copyright (C) 2016 JP 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; - -namespace Cairo -{ - public class EGLDevice : Device - { - public EGLDevice (IntPtr dpy, IntPtr gl_ctx) : base (NativeMethods.cairo_egl_device_create (dpy, gl_ctx), true) - { - } - } -} - diff --git a/src/Mono.Cairo/Extend.cs b/src/Mono.Cairo/Extend.cs deleted file mode 100644 index 0ffee3fb..00000000 --- a/src/Mono.Cairo/Extend.cs +++ /dev/null @@ -1,45 +0,0 @@ -// -// Mono.Cairo.Extend.cs -// -// Authors: -// Duncan Mak (duncan@ximian.com) -// Hisham Mardam Bey (hisham.mardambey@gmail.com) -// John Luke (john.luke@gmail.com) -// -// (C) Ximian, Inc. 2003 -// Copyright (C) 2004 Novell, Inc (http://www.novell.com) -// Copyright (C) 2005 John Luke -// -// 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; - -namespace Cairo -{ - [Serializable] - public enum Extend - { - None, - Repeat, - Reflect, - Pad, - } -} diff --git a/src/Mono.Cairo/FillRule.cs b/src/Mono.Cairo/FillRule.cs deleted file mode 100644 index 6d8c0626..00000000 --- a/src/Mono.Cairo/FillRule.cs +++ /dev/null @@ -1,41 +0,0 @@ -// -// Mono.Cairo.FillRule.cs -// -// Authors: -// Duncan Mak (duncan@ximian.com) -// Hisham Mardam Bey (hisham.mardambey@gmail.com) -// -// (C) Ximian, Inc. 2003 -// Copyright (C) 2004 Novell, Inc (http://www.novell.com) -// -// 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; - -namespace Cairo -{ - [Serializable] - public enum FillRule - { - Winding, - EvenOdd - } -} diff --git a/src/Mono.Cairo/Filter.cs b/src/Mono.Cairo/Filter.cs deleted file mode 100644 index d602ed7d..00000000 --- a/src/Mono.Cairo/Filter.cs +++ /dev/null @@ -1,45 +0,0 @@ -// -// Mono.Cairo.Filter.cs -// -// Authors: -// Duncan Mak (duncan@ximian.com) -// Hisham Mardam Bey (hisham.mardambey@gmail.com) -// -// (C) Ximian, Inc. 2003 -// Copyright (C) 2004 Novell, Inc (http://www.novell.com) -// -// 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; - -namespace Cairo -{ - [Serializable] - public enum Filter - { - Fast, - Good, - Best, - Nearest, - Bilinear, - Gaussian, - } -} diff --git a/src/Mono.Cairo/FontExtents.cs b/src/Mono.Cairo/FontExtents.cs deleted file mode 100644 index 76c7e658..00000000 --- a/src/Mono.Cairo/FontExtents.cs +++ /dev/null @@ -1,104 +0,0 @@ -// -// Mono.Cairo.FontExtents.cs -// -// Authors: Duncan Mak (duncan@ximian.com) -// Hisham Mardam Bey (hisham.mardambey@gmail.com) -// -// (C) Ximian, Inc. 2003 -// -// This is a simplistic binding of the Cairo API to C#. All functions -// in cairo.h are transcribed into their C# equivelants -// -// Copyright (C) 2004 Novell, Inc (http://www.novell.com) -// -// 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.Runtime.InteropServices; - -namespace Cairo -{ - [StructLayout (LayoutKind.Sequential)] - public struct FontExtents - { - double ascent; - double descent; - double height; - double maxXAdvance; - double maxYAdvance; - - public double Ascent { - get { return ascent; } - set { ascent = value; } - } - - public double Descent { - get { return descent; } - set { descent = value; } - } - - public double Height { - get { return height; } - set { height = value; } - } - - public double MaxXAdvance { - get { return maxXAdvance; } - set { maxXAdvance = value; } - } - - public double MaxYAdvance { - get { return maxYAdvance; } - set { maxYAdvance = value; } - } - - public FontExtents (double ascent, double descent, double height, double maxXAdvance, double maxYAdvance) - { - this.ascent = ascent; - this.descent = descent; - this.height = height; - this.maxXAdvance = maxXAdvance; - this.maxYAdvance = maxYAdvance; - } - - public override bool Equals (object obj) - { - if (obj is FontExtents) - return this == (FontExtents) obj; - return false; - } - - public override int GetHashCode () - { - return (int) Ascent ^ (int) Descent ^ (int) Height ^ (int) MaxXAdvance ^ (int) MaxYAdvance; - } - - public static bool operator == (FontExtents extents, FontExtents other) - { - return extents.Ascent == other.Ascent && extents.Descent == other.Descent && extents.Height == other.Height && extents.MaxXAdvance == other.MaxXAdvance && extents.MaxYAdvance == other.MaxYAdvance; - } - - public static bool operator != (FontExtents extents, FontExtents other) - { - return !(extents == other); - } - } -} diff --git a/src/Mono.Cairo/FontFace.cs b/src/Mono.Cairo/FontFace.cs deleted file mode 100644 index 19d8163c..00000000 --- a/src/Mono.Cairo/FontFace.cs +++ /dev/null @@ -1,108 +0,0 @@ -// -// Mono.Cairo.FontFace.cs -// -// Author: -// Alp Toker (alp@atoker.com) -// Miguel de Icaza (miguel@novell.com) -// -// (C) Ximian Inc, 2003. -// -// This is an OO wrapper API for the Cairo API. -// -// Copyright (C) 2004, 2007 Novell, Inc (http://www.novell.com) -// -// 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; - -namespace Cairo -{ - public class FontFace : IDisposable - { - IntPtr handle; - - internal static FontFace Lookup (IntPtr handle, bool owner) - { - if (handle == IntPtr.Zero) - return null; - return new FontFace (handle, owner); - } - - ~FontFace () - { - Dispose (false); - } - - public void Dispose () - { - Dispose (true); - GC.SuppressFinalize (this); - } - - protected virtual void Dispose (bool disposing) - { - if (!disposing || CairoDebug.Enabled) - CairoDebug.OnDisposed<FontFace> (handle, disposing); - - if (!disposing|| handle == IntPtr.Zero) - return; - - NativeMethods.cairo_font_face_destroy (handle); - handle = IntPtr.Zero; - } - - [Obsolete] - public FontFace (IntPtr handle) : this (handle, true) - { - } - - public FontFace (IntPtr handle, bool owned) - { - this.handle = handle; - if (!owned) - NativeMethods.cairo_font_face_reference (handle); - if (CairoDebug.Enabled) - CairoDebug.OnAllocated (handle); - } - - public IntPtr Handle { - get { - return handle; - } - } - - public Status Status { - get { - return NativeMethods.cairo_font_face_status (handle); - } - } - - public FontType FontType { - get { - return NativeMethods.cairo_font_face_get_type (handle); - } - } - - public uint ReferenceCount { - get { return NativeMethods.cairo_font_face_get_reference_count (handle); } - } - } -} - diff --git a/src/Mono.Cairo/FontOptions.cs b/src/Mono.Cairo/FontOptions.cs deleted file mode 100644 index 5269d54d..00000000 --- a/src/Mono.Cairo/FontOptions.cs +++ /dev/null @@ -1,143 +0,0 @@ -// -// Mono.Cairo.FontOptions.cs -// -// Author: -// John Luke (john.luke@gmail.com) -// -// (C) John Luke 2005. -// -// 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; - -namespace Cairo -{ - public class FontOptions : IDisposable - { - IntPtr handle; - - public FontOptions () : this (NativeMethods.cairo_font_options_create ()) - { - } - - ~FontOptions () - { - Dispose (false); - } - - internal FontOptions (IntPtr handle) - { - this.handle = handle; - if (CairoDebug.Enabled) - CairoDebug.OnAllocated (handle); - } - - public FontOptions Copy () - { - return new FontOptions (NativeMethods.cairo_font_options_copy (handle)); - } - - [Obsolete ("Use Dispose()")] - public void Destroy () - { - Dispose (); - } - - public void Dispose () - { - Dispose (true); - GC.SuppressFinalize (this); - } - - protected virtual void Dispose (bool disposing) - { - if (!disposing || CairoDebug.Enabled) - CairoDebug.OnDisposed<FontOptions> (handle, disposing); - - if (!disposing|| handle == IntPtr.Zero) - return; - - NativeMethods.cairo_font_options_destroy (handle); - handle = IntPtr.Zero; - } - - public static bool operator == (FontOptions options, FontOptions other) - { - return Equals (options, other); - } - - public static bool operator != (FontOptions options, FontOptions other) - { - return !(options == other); - } - - public override bool Equals (object other) - { - return Equals (other as FontOptions); - } - - bool Equals (FontOptions options) - { - return options != null && NativeMethods.cairo_font_options_equal (Handle, options.Handle); - } - - public IntPtr Handle { - get { return handle; } - } - - public override int GetHashCode () - { - return (int) NativeMethods.cairo_font_options_hash (handle); - } - - public void Merge (FontOptions other) - { - if (other == null) - throw new ArgumentNullException ("other"); - NativeMethods.cairo_font_options_merge (handle, other.Handle); - } - - public Antialias Antialias { - get { return NativeMethods.cairo_font_options_get_antialias (handle); } - set { NativeMethods.cairo_font_options_set_antialias (handle, value); } - } - - public HintMetrics HintMetrics { - get { return NativeMethods.cairo_font_options_get_hint_metrics (handle);} - set { NativeMethods.cairo_font_options_set_hint_metrics (handle, value); } - } - - public HintStyle HintStyle { - get { return NativeMethods.cairo_font_options_get_hint_style (handle);} - set { NativeMethods.cairo_font_options_set_hint_style (handle, value); } - } - - public Status Status { - get { return NativeMethods.cairo_font_options_status (handle); } - } - - public SubpixelOrder SubpixelOrder { - get { return NativeMethods.cairo_font_options_get_subpixel_order (handle);} - set { NativeMethods.cairo_font_options_set_subpixel_order (handle, value); } - } - } -} - diff --git a/src/Mono.Cairo/FontSlant.cs b/src/Mono.Cairo/FontSlant.cs deleted file mode 100644 index c4e1af78..00000000 --- a/src/Mono.Cairo/FontSlant.cs +++ /dev/null @@ -1,42 +0,0 @@ -// -// Mono.Cairo.FontSlant.cs -// -// Authors: -// Duncan Mak (duncan@ximian.com) -// Hisham Mardam Bey (hisham.mardambey@gmail.com) -// -// (C) Ximian, Inc. 2003 -// Copyright (C) 2004 Novell, Inc (http://www.novell.com) -// -// 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; - -namespace Cairo -{ - [Serializable] - public enum FontSlant - { - Normal, - Italic, - Oblique - } -} diff --git a/src/Mono.Cairo/FontType.cs b/src/Mono.Cairo/FontType.cs deleted file mode 100644 index 0c71fcb2..00000000 --- a/src/Mono.Cairo/FontType.cs +++ /dev/null @@ -1,41 +0,0 @@ -// -// Mono.Cairo.FontType.cs -// -// Authors: -// John Luke -// -// (C) John Luke, 2006. -// -// 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; - -namespace Cairo { - - [Serializable] - public enum FontType - { - Toy, - FreeType, - Win32, - Atsui, - } -} diff --git a/src/Mono.Cairo/FontWeight.cs b/src/Mono.Cairo/FontWeight.cs deleted file mode 100644 index 9d1927d8..00000000 --- a/src/Mono.Cairo/FontWeight.cs +++ /dev/null @@ -1,41 +0,0 @@ -// -// Mono.Cairo.FontWeight.cs -// -// Authors: -// Duncan Mak (duncan@ximian.com) -// Hisham Mardam Bey (hisham.mardambey@gmail.com) -// -// (C) Ximian, Inc. 2003 -// Copyright (C) 2004 Novell, Inc (http://www.novell.com) -// -// 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; - -namespace Cairo -{ - [Serializable] - public enum FontWeight - { - Normal, - Bold, - } -} diff --git a/src/Mono.Cairo/Format.cs b/src/Mono.Cairo/Format.cs deleted file mode 100644 index f0bded3c..00000000 --- a/src/Mono.Cairo/Format.cs +++ /dev/null @@ -1,48 +0,0 @@ -// -// Mono.Cairo.Format.cs -// -// Authors: Duncan Mak (duncan@ximian.com) -// Hisham Mardam Bey (hisham.mardambey@gmail.com) -// -// (C) Ximian, Inc. 2003 -// Copyright (C) 2004 Novell, Inc (http://www.novell.com) -// -// 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; - -namespace Cairo -{ - [Serializable] - public enum Format - { - Argb32 = 0, - Rgb24 = 1, - A8 = 2, - A1 = 3, - Rgb16565 = 4, - - //[Obsolete ("Use Argb32")] - ARGB32 = Argb32, - //[Obsolete ("Use Rgb24")] - RGB24 = Rgb24, - } -} diff --git a/src/Mono.Cairo/GLSurface.cs b/src/Mono.Cairo/GLSurface.cs deleted file mode 100644 index 9486c9cd..00000000 --- a/src/Mono.Cairo/GLSurface.cs +++ /dev/null @@ -1,61 +0,0 @@ -// -// Mono.Cairo.GLSurface.cs -// -// Authors: -// JP Bruyère (jp_bruyere@hotmail.com) -// -// This is an OO wrapper API for the Cairo API -// -// Copyright (C) 2016 JP 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; - -namespace Cairo { - - public class GLSurface : Surface - { - - public GLSurface (IntPtr ptr, bool own) : base (ptr, own) - {} - - public GLSurface (Device device, Cairo.Content content, uint tex, int width, int height) - : base (NativeMethods.cairo_gl_surface_create_for_texture (device.Handle, (uint)content, tex, width, height), true) - {} - - public GLSurface (EGLDevice device, IntPtr eglSurf, int width, int height) - : base (NativeMethods.cairo_gl_surface_create_for_egl (device.Handle, eglSurf, width, height), true) - {} - - public GLSurface (GLXDevice device, IntPtr window, int width, int height) - : base (NativeMethods.cairo_gl_surface_create_for_window (device.Handle, window, width, height),true) - {} - - public GLSurface (WGLDevice device, IntPtr hdc, int width, int height) - : base (NativeMethods.cairo_gl_surface_create_for_dc (device.Handle, hdc, width, height), true) - {} - - public void SwapBuffers(){ - NativeMethods.cairo_gl_surface_swapbuffers (this.Handle); - } - } -} diff --git a/src/Mono.Cairo/GLXDevice.cs b/src/Mono.Cairo/GLXDevice.cs deleted file mode 100644 index 189872a2..00000000 --- a/src/Mono.Cairo/GLXDevice.cs +++ /dev/null @@ -1,49 +0,0 @@ -// -// Mono.Cairo.Device.cs -// -// Authors: -// JP Bruyère (jp_bruyere@hotmail.com) -// -// This is an OO wrapper API for the Cairo API -// -// Copyright (C) 2016 JP 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; - -namespace Cairo -{ - public class GLXDevice : Device - { - public GLXDevice (IntPtr dpy, IntPtr gl_ctx) : base (NativeMethods.cairo_glx_device_create (dpy, gl_ctx), true) - { - } - - public IntPtr Display { - get { return NativeMethods.cairo_glx_device_get_display (Handle); } - } - - public IntPtr Context { - get { return NativeMethods.cairo_glx_device_get_context (Handle); } - } - } -} - diff --git a/src/Mono.Cairo/GlitzSurface.cs b/src/Mono.Cairo/GlitzSurface.cs deleted file mode 100644 index 6da1ac6a..00000000 --- a/src/Mono.Cairo/GlitzSurface.cs +++ /dev/null @@ -1,43 +0,0 @@ -// -// Mono.Cairo.GlitzSurface.cs -// -// Authors: -// Alp Toker -// -// (C) Alp Toker, 2006. -// -// 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; - -namespace Cairo { - public class GlitzSurface : Surface - { - internal GlitzSurface (IntPtr handle, bool owns) : base (handle, owns) - { - } - - public GlitzSurface (IntPtr glitz_surface) - : base (NativeMethods.cairo_glitz_surface_create (glitz_surface), true) - { - } - } -} diff --git a/src/Mono.Cairo/Glyph.cs b/src/Mono.Cairo/Glyph.cs deleted file mode 100644 index ec9c2ff3..00000000 --- a/src/Mono.Cairo/Glyph.cs +++ /dev/null @@ -1,96 +0,0 @@ -// -// Mono.Cairo.Glyph.cs -// -// Authors: Duncan Mak (duncan@ximian.com) -// Hisham Mardam Bey (hisham.mardambey@gmail.com) -// -// (C) Ximian, Inc. 2003 -// Copyright (C) 2004 Novell, Inc (http://www.novell.com) -// -// 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.Runtime.InteropServices; - -namespace Cairo -{ - [StructLayout(LayoutKind.Sequential)] - public struct Glyph - { - internal long index; - internal double x; - internal double y; - - public Glyph (long index, double x, double y) - { - this.index = index; - this.x = x; - this.y = y; - } - - public long Index { - get { return index; } - set { index = value; } - } - - public double X { - get { return x; } - set { x = value; } - } - - public double Y { - get { return y; } - set { y = value; } - } - - public override bool Equals (object obj) - { - if (obj is Glyph) - return this == (Glyph)obj; - return false; - } - - public override int GetHashCode () - { - return (int) Index ^ (int) X ^ (int) Y; - } - - internal static IntPtr GlyphsToIntPtr (Glyph[] glyphs) - { - int size = Marshal.SizeOf (glyphs[0]); - IntPtr dest = Marshal.AllocHGlobal (size * glyphs.Length); - long pos = dest.ToInt64 (); - for (int i = 0; i < glyphs.Length; i++, pos += size) - Marshal.StructureToPtr (glyphs[i], (IntPtr) pos, false); - return dest; - } - - public static bool operator == (Glyph glyph, Glyph other) - { - return glyph.Index == other.Index && glyph.X == other.X && glyph.Y == other.Y; - } - - public static bool operator != (Glyph glyph, Glyph other) - { - return !(glyph == other); - } - } -} diff --git a/src/Mono.Cairo/Gradient.cs b/src/Mono.Cairo/Gradient.cs deleted file mode 100644 index 0fb617e4..00000000 --- a/src/Mono.Cairo/Gradient.cs +++ /dev/null @@ -1,66 +0,0 @@ -// -// Mono.Cairo.Gradient.cs -// -// Author: Jordi Mas (jordi@ximian.com) -// Hisham Mardam Bey (hisham.mardambey@gmail.com) -// (C) Ximian Inc, 2004. -// -// Copyright (C) 2004 Novell, Inc (http://www.novell.com) -// -// 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; - -namespace Cairo { - - public class Gradient : Pattern - { - protected Gradient (IntPtr handle, bool owned) : base (handle, owned) - { - } - - [Obsolete] - protected Gradient () - { - } - - public int ColorStopCount { - get { - int cnt; - NativeMethods.cairo_pattern_get_color_stop_count (Handle, out cnt); - return cnt; - } - } - - public Status AddColorStop (double offset, Color c) - { - NativeMethods.cairo_pattern_add_color_stop_rgba (Handle, offset, c.R, c.G, c.B, c.A); - return Status; - } - - public Status AddColorStopRgb (double offset, Color c) - { - NativeMethods.cairo_pattern_add_color_stop_rgb (Handle, offset, c.R, c.G, c.B); - return Status; - } - } -} - diff --git a/src/Mono.Cairo/HintMetrics.cs b/src/Mono.Cairo/HintMetrics.cs deleted file mode 100644 index d4341424..00000000 --- a/src/Mono.Cairo/HintMetrics.cs +++ /dev/null @@ -1,41 +0,0 @@ -// -// Mono.Cairo.HintMetrics.cs -// -// Authors: Duncan Mak (duncan@ximian.com) -// Hisham Mardam Bey (hisham.mardambey@gmail.com) -// -// (C) Ximian, Inc. 2003 -// Copyright (C) 2004 Novell, Inc (http://www.novell.com) -// -// 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; - -namespace Cairo -{ - [Serializable] - public enum HintMetrics - { - Default, - Off, - On, - } -} diff --git a/src/Mono.Cairo/HintStyle.cs b/src/Mono.Cairo/HintStyle.cs deleted file mode 100644 index bb848206..00000000 --- a/src/Mono.Cairo/HintStyle.cs +++ /dev/null @@ -1,43 +0,0 @@ -// -// Mono.Cairo.HintStyle.cs -// -// Authors: Duncan Mak (duncan@ximian.com) -// Hisham Mardam Bey (hisham.mardambey@gmail.com) -// -// (C) Ximian, Inc. 2003 -// Copyright (C) 2004 Novell, Inc (http://www.novell.com) -// -// 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; - -namespace Cairo -{ - [Serializable] - public enum HintStyle - { - Default, - None, - Slight, - Medium, - Full, - } -} diff --git a/src/Mono.Cairo/ImageSurface.cs b/src/Mono.Cairo/ImageSurface.cs deleted file mode 100644 index 98143fe8..00000000 --- a/src/Mono.Cairo/ImageSurface.cs +++ /dev/null @@ -1,104 +0,0 @@ -// -// Mono.Cairo.ImageSurface.cs -// -// Authors: -// Duncan Mak -// Miguel de Icaza. -// -// (C) Ximian Inc, 2003. -// (C) Novell, Inc. 2003. -// -// This is an OO wrapper API for the Cairo API -// -// Copyright (C) 2004 Novell, Inc (http://www.novell.com) -// -// 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.Runtime.InteropServices; - -namespace Cairo { - - public class ImageSurface : Surface - { - internal ImageSurface (IntPtr handle, bool owns) : base (handle, owns) - { - } - - public ImageSurface (Format format, int width, int height) - : base (NativeMethods.cairo_image_surface_create (format, width, height), true) - { - } - - [Obsolete ("Use ImageSurface (byte[] data, Cairo.Format format, int width, int height, int stride)")] - public ImageSurface (ref byte[] data, Cairo.Format format, int width, int height, int stride) - : this (data, format, width, height, stride) - { - } - - public ImageSurface (byte[] data, Format format, int width, int height, int stride) - : base (NativeMethods.cairo_image_surface_create_for_data (data, format, width, height, stride), true) - { - } - - public ImageSurface (IntPtr data, Format format, int width, int height, int stride) - : base (NativeMethods.cairo_image_surface_create_for_data (data, format, width, height, stride), true) - { - } - - public ImageSurface (string filename) - : base (NativeMethods.cairo_image_surface_create_from_png (filename), true) - { - } - - public int Width { - get { return NativeMethods.cairo_image_surface_get_width (Handle); } - } - - public int Height { - get { return NativeMethods.cairo_image_surface_get_height (Handle); } - } - - public byte[] Data { - get { - IntPtr ptr = NativeMethods.cairo_image_surface_get_data (Handle); - int length = Height * Stride; - byte[] data = new byte[length]; - Marshal.Copy (ptr, data, 0, length); - return data; - } - } - - public IntPtr DataPtr { - get { - return NativeMethods.cairo_image_surface_get_data (Handle); - } - } - - public Format Format { - get { return NativeMethods.cairo_image_surface_get_format (Handle); } - } - - public int Stride { - get { return NativeMethods.cairo_image_surface_get_stride (Handle); } - } - } -} diff --git a/src/Mono.Cairo/LineCap.cs b/src/Mono.Cairo/LineCap.cs deleted file mode 100644 index 57cfdec2..00000000 --- a/src/Mono.Cairo/LineCap.cs +++ /dev/null @@ -1,41 +0,0 @@ -// -// Mono.Cairo.LineCap.cs -// -// Authors: Duncan Mak (duncan@ximian.com) -// Hisham Mardam Bey (hisham.mardambey@gmail.com) -// -// (C) Ximian, Inc. 2003 -// Copyright (C) 2004 Novell, Inc (http://www.novell.com) -// -// 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; - -namespace Cairo -{ - [Serializable] - public enum LineCap - { - Butt, - Round, - Square, - } -} diff --git a/src/Mono.Cairo/LineJoin.cs b/src/Mono.Cairo/LineJoin.cs deleted file mode 100644 index 439b2a51..00000000 --- a/src/Mono.Cairo/LineJoin.cs +++ /dev/null @@ -1,42 +0,0 @@ -// -// Mono.Cairo.LineJoin.cs -// -// Authors: Duncan Mak (duncan@ximian.com) -// Hisham Mardam Bey (hisham.mardambey@gmail.com) -// -// (C) Ximian, Inc. 2003 -// Copyright (C) 2004 Novell, Inc (http://www.novell.com) -// -// 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; - -namespace Cairo -{ - [Serializable] - public enum LineJoin - { - Miter, - Round, - Bevel - } -} - diff --git a/src/Mono.Cairo/LinearGradient.cs b/src/Mono.Cairo/LinearGradient.cs deleted file mode 100644 index 85fdea84..00000000 --- a/src/Mono.Cairo/LinearGradient.cs +++ /dev/null @@ -1,59 +0,0 @@ -// -// Mono.Cairo.LinearGradient.cs -// -// Author: Jordi Mas (jordi@ximian.com) -// Hisham Mardam Bey (hisham.mardambey@gmail.com) -// (C) Ximian Inc, 2004. -// -// Copyright (C) 2004 Novell, Inc (http://www.novell.com) -// -// 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; - -namespace Cairo { - - public class LinearGradient : Gradient - { - internal LinearGradient (IntPtr handle, bool owned) : base (handle, owned) - { - } - - public LinearGradient (double x0, double y0, double x1, double y1) - : base (NativeMethods.cairo_pattern_create_linear (x0, y0, x1, y1), true) - { - } - - public PointD[] LinearPoints { - get { - double x0, y0, x1, y1; - PointD[] points = new PointD [2]; - - NativeMethods.cairo_pattern_get_linear_points (Handle, out x0, out y0, out x1, out y1); - - points[0] = new PointD (x0, y0); - points[1] = new PointD (x1, y1); - return points; - } - } - } -} - diff --git a/src/Mono.Cairo/Matrix.cs b/src/Mono.Cairo/Matrix.cs deleted file mode 100644 index 83ffce49..00000000 --- a/src/Mono.Cairo/Matrix.cs +++ /dev/null @@ -1,193 +0,0 @@ -// -// Mono.Cairo.Matrix.cs -// -// Author: Duncan Mak -// Hisham Mardam Bey (hisham.mardambey@gmail.com) -// Idan Gazit (idan@fastmail.fm) -// -// (C) Ximian Inc, 2003 - 2005. -// -// This is an OO wrapper API for the Cairo API -// -// Copyright (C) 2004 Novell, Inc (http://www.novell.com) -// -// 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.Runtime.InteropServices; - -namespace Cairo { - - [StructLayout(LayoutKind.Sequential)] - public class Matrix : ICloneable - { - public double Xx; - public double Yx; - public double Xy; - public double Yy; - public double X0; - public double Y0; - - public Matrix (double xx, double yx, double xy, double yy, - double x0, double y0) - { - this.Xx = xx; this.Yx = yx; this.Xy = xy; - this.Yy = yy; this.X0 = x0; this.Y0 = y0; - } - - public Matrix () - { - this.InitIdentity (); - } - - public bool IsIdentity () - { - return (this == new Matrix ()); - } - - public void InitIdentity () - { - // this.Init(1,0,0,1,0,0); - NativeMethods.cairo_matrix_init_identity (this); - } - - public void Init (double xx, double yx, double xy, double yy, - double x0, double y0) - { - this.Xx = xx; this.Yx = yx; this.Xy = xy; - this.Yy = yy; this.X0 = x0; this.Y0 = y0; - } - - public void InitTranslate (double tx, double ty) - { - //this.Init (1, 0, 0, 1, tx, ty); - NativeMethods.cairo_matrix_init_translate (this, tx, ty); - } - - public void Translate (double tx, double ty) - { - NativeMethods.cairo_matrix_translate (this, tx, ty); - } - - public void InitScale (double sx, double sy) - { - //this.Init (sx, 0, 0, sy, 0, 0); - NativeMethods.cairo_matrix_init_scale (this, sx, sy); - } - - public void Scale (double sx, double sy) - { - NativeMethods.cairo_matrix_scale (this, sx, sy); - } - - public void InitRotate (double radians) - { - /* - double s, c; - s = Math.Sin (radians); - c = Math.Cos (radians); - this.Init (c, s, -s, c, 0, 0); - */ - NativeMethods.cairo_matrix_init_rotate (this, radians); - } - - public void Rotate (double radians) - { - NativeMethods.cairo_matrix_rotate (this, radians); - } - - public Cairo.Status Invert () - { - return NativeMethods.cairo_matrix_invert (this); - } - - public void Multiply (Matrix b) - { - Matrix a = (Matrix) this.Clone (); - NativeMethods.cairo_matrix_multiply (this, a, b); - } - - public static Matrix Multiply (Matrix a, Matrix b) { - Matrix result = new Matrix (); - NativeMethods.cairo_matrix_multiply (result, a, b); - return result; - } - - - public void TransformDistance (ref double dx, ref double dy) - { - NativeMethods.cairo_matrix_transform_distance (this, ref dx, ref dy); - } - - public void TransformPoint (ref double x, ref double y) - { - NativeMethods.cairo_matrix_transform_point (this, ref x, ref y); - } - - public override String ToString () - { - String s = String.Format ("xx:{0:##0.0#} yx:{1:##0.0#} xy:{2:##0.0#} yy:{3:##0.0#} x0:{4:##0.0#} y0:{5:##0.0#}", - this.Xx, this.Yx, this.Xy, this.Yy, this.X0, this.Y0); - return s; - } - - public static bool operator == (Matrix lhs, Matrix rhs) - { - return (lhs.Xx == rhs.Xx && - lhs.Xy == rhs.Xy && - lhs.Yx == rhs.Yx && - lhs.Yy == rhs.Yy && - lhs.X0 == rhs.X0 && - lhs.Y0 == rhs.Y0 ); - } - - public static bool operator != (Matrix lhs, Matrix rhs) - { - return !(lhs==rhs); - } - - - - public override bool Equals(object o) - { - if (! (o is Matrix)) - return false; - else - return (this == (Matrix) o); - } - - public override int GetHashCode() - { - return (int)this.Xx ^ (int)this.Xx>>32 ^ - (int)this.Xy ^ (int)this.Xy>>32 ^ - (int)this.Yx ^ (int)this.Yx>>32 ^ - (int)this.Yy ^ (int)this.Yy>>32 ^ - (int)this.X0 ^ (int)this.X0>>32 ^ - (int)this.Y0 ^ (int)this.Y0>>32; - } - - public object Clone() - { - return this.MemberwiseClone (); - } - - } -} diff --git a/src/Mono.Cairo/MeshPattern.cs b/src/Mono.Cairo/MeshPattern.cs deleted file mode 100644 index b14c709b..00000000 --- a/src/Mono.Cairo/MeshPattern.cs +++ /dev/null @@ -1,98 +0,0 @@ -// -// Mono.Cairo.Pattern.cs -// -// Author: Jordi Mas (jordi@ximian.com) -// Hisham Mardam Bey (hisham.mardambey@gmail.com) -// (C) Ximian Inc, 2004. -// -// Copyright (C) 2004 Novell, Inc (http://www.novell.com) -// -// 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; - -namespace Cairo { - - public class MeshPattern : Pattern - { - internal MeshPattern (IntPtr handle, bool owned) : base (handle, owned) - { - } - - public MeshPattern () - : base (NativeMethods.cairo_pattern_create_mesh(), true) - { - } - - //no idea why this is here, the base one is identical, but we can't remove it now - public new Extend Extend { - set { NativeMethods.cairo_pattern_set_extend (Handle, value); } - get { return NativeMethods.cairo_pattern_get_extend (Handle); } - } - - public Filter Filter { - set { NativeMethods.cairo_pattern_set_filter (Handle, value); } - get { return NativeMethods.cairo_pattern_get_filter (Handle); } - } - - public void BeginPatch(){ - NativeMethods.cairo_mesh_pattern_begin_patch (Handle); - } - public void EndPatch(){ - NativeMethods.cairo_mesh_pattern_end_patch (Handle); - } - public void MoveTo(double x, double y){ - NativeMethods.cairo_mesh_pattern_move_to (Handle, x, y); - } - public void LineTo(double x, double y){ - NativeMethods.cairo_mesh_pattern_line_to (Handle, x, y); - } - public void CurveTo(double x1, double y1, double x2, double y2, double x3, double y3) - { - NativeMethods.cairo_mesh_pattern_curve_to (Handle, x1, y1, x2, y2, x3, y3); - } - public void SetControlPoint(uint point_num, double x, double y){ - NativeMethods.cairo_mesh_pattern_set_control_point (Handle, point_num, x, y); - } - public void SetCornerColorRGB(uint corner_num, double r, double g, double b){ - NativeMethods.cairo_mesh_pattern_set_corner_color_rgb (Handle, corner_num, r, g, b); - } - public void SetCornerColorRGBA(uint corner_num, double r, double g, double b, double a){ - NativeMethods.cairo_mesh_pattern_set_corner_color_rgba (Handle, corner_num, r, g, b, a); - } - public uint PatchCount { - get { - uint count = 0; - NativeMethods.cairo_mesh_pattern_get_patch_count(Handle, out count); - return count; - } - } - public Path GetPath(uint patch_num){ - return new Path(NativeMethods.cairo_mesh_pattern_get_path(Handle, patch_num)); - } - public void GetControlPoint(){ - } - public void GetCornerColorRGBA(){ - - } - } -} - diff --git a/src/Mono.Cairo/NativeMethods.cs b/src/Mono.Cairo/NativeMethods.cs deleted file mode 100644 index 53501369..00000000 --- a/src/Mono.Cairo/NativeMethods.cs +++ /dev/null @@ -1,1065 +0,0 @@ -// -// Cairo.cs - a simplistic binding of the Cairo API to C#. -// -// Authors: Duncan Mak (duncan@ximian.com) -// Hisham Mardam Bey (hisham.mardambey@gmail.com) -// John Luke (john.luke@gmail.com) -// Alp Toker (alp@atoker.com) -// -// (C) Ximian, Inc. 2003 -// Copyright (C) 2004 Novell, Inc (http://www.novell.com) -// Copyright (C) 2005 John Luke -// Copyright (C) 2006 Alp Toker -// -// 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.Runtime.InteropServices; - -namespace Cairo -{ - // sort the functions like in the following page so it is easier to find what is missing - // http://cairographics.org/manual/index-all.html - - internal static class NativeMethods - { -#if MONOTOUCH - const string cairo = "__Internal"; -#else - const string cairo = "libcairo-2.dll"; -#endif - - //[DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - //internal static extern void cairo_append_path (IntPtr cr, Path path); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_arc (IntPtr cr, double xc, double yc, double radius, double angle1, double angle2); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_arc_negative (IntPtr cr, double xc, double yc, double radius, double angle1, double angle2); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_atsui_font_face_create_for_atsu_font_id (IntPtr font_id); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_clip (IntPtr cr); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_clip_preserve (IntPtr cr); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_clip_extents (IntPtr cr, out double x1, out double y1, out double x2, out double y2); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_close_path (IntPtr cr); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_copy_page (IntPtr cr); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_copy_path (IntPtr cr); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_copy_path_flat (IntPtr cr); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_append_path (IntPtr cr, IntPtr path); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_create (IntPtr target); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_curve_to (IntPtr cr, double x1, double y1, double x2, double y2, double x3, double y3); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_debug_reset_static_data (); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_destroy (IntPtr cr); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_device_to_user (IntPtr cr, ref double x, ref double y); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_device_to_user_distance (IntPtr cr, ref double dx, ref double dy); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_fill (IntPtr cr); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_fill_extents (IntPtr cr, out double x1, out double y1, out double x2, out double y2); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_fill_preserve (IntPtr cr); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_font_extents (IntPtr cr, out FontExtents extents); - - #region FontFace - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_font_face_destroy (IntPtr font_face); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern FontType cairo_font_face_get_type (IntPtr font_face); - - //[DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - //internal static extern void cairo_font_face_get_user_data (IntPtr font_face); - - //[DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - //internal static extern void cairo_font_face_set_user_data (IntPtr font_face); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_font_face_reference (IntPtr font_face); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern Status cairo_font_face_status (IntPtr font_face); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern uint cairo_font_face_get_reference_count (IntPtr surface); - #endregion - - #region FontOptions - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_font_options_copy (IntPtr original); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_font_options_create (); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_font_options_destroy (IntPtr options); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - [return: MarshalAs (UnmanagedType.U1)] - internal static extern bool cairo_font_options_equal (IntPtr options, IntPtr other); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern Antialias cairo_font_options_get_antialias (IntPtr options); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern HintMetrics cairo_font_options_get_hint_metrics (IntPtr options); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern HintStyle cairo_font_options_get_hint_style (IntPtr options); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern SubpixelOrder cairo_font_options_get_subpixel_order (IntPtr options); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern long cairo_font_options_hash (IntPtr options); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_font_options_merge (IntPtr options, IntPtr other); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_font_options_set_antialias (IntPtr options, Antialias aa); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_font_options_set_hint_metrics (IntPtr options, HintMetrics metrics); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_font_options_set_hint_style (IntPtr options, HintStyle style); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_font_options_set_subpixel_order (IntPtr options, SubpixelOrder order); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern Status cairo_font_options_status (IntPtr options); - #endregion - - #region Freetype / FontConfig - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_ft_font_face_create_for_ft_face (IntPtr face, int load_flags); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_ft_font_face_create_for_pattern (IntPtr fc_pattern); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_ft_font_options_substitute (FontOptions options, IntPtr pattern); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_ft_scaled_font_lock_face (IntPtr scaled_font); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_ft_scaled_font_unlock_face (IntPtr scaled_font); - #endregion - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern Antialias cairo_get_antialias (IntPtr cr); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_get_current_point (IntPtr cr, out double x, out double y); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern FillRule cairo_get_fill_rule (IntPtr cr); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_get_font_face (IntPtr cr); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_get_font_matrix (IntPtr cr, out Matrix matrix); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_get_font_options (IntPtr cr, IntPtr options); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_get_group_target (IntPtr cr); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern LineCap cairo_get_line_cap (IntPtr cr); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern LineJoin cairo_get_line_join (IntPtr cr); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern double cairo_get_line_width (IntPtr cr); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_get_matrix (IntPtr cr, Matrix matrix); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern double cairo_get_miter_limit (IntPtr cr); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern Operator cairo_get_operator (IntPtr cr); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern uint cairo_get_reference_count (IntPtr surface); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_get_source (IntPtr cr); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_get_target (IntPtr cr); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern double cairo_get_tolerance (IntPtr cr); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_glitz_surface_create (IntPtr surface); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_glyph_extents (IntPtr cr, IntPtr glyphs, int num_glyphs, out TextExtents extents); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_glyph_path (IntPtr cr, IntPtr glyphs, int num_glyphs); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - [return: MarshalAs (UnmanagedType.U1)] - internal static extern bool cairo_has_current_point (IntPtr cr); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_identity_matrix (IntPtr cr); - - #region Image Surface - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_image_surface_create (Cairo.Format format, int width, int height); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_image_surface_create_for_data (byte[] data, Cairo.Format format, int width, int height, int stride); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_image_surface_create_for_data (IntPtr data, Cairo.Format format, int width, int height, int stride); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_image_surface_create_from_png (string filename); - - //[DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - //internal static extern IntPtr cairo_image_surface_create_from_png_stream (string filename); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_image_surface_get_data (IntPtr surface); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern Format cairo_image_surface_get_format (IntPtr surface); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern int cairo_image_surface_get_height (IntPtr surface); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern int cairo_image_surface_get_stride (IntPtr surface); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern int cairo_image_surface_get_width (IntPtr surface); - #endregion - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - [return: MarshalAs (UnmanagedType.U1)] - internal static extern bool cairo_in_clip (IntPtr cr, double x, double y); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - [return: MarshalAs (UnmanagedType.U1)] - internal static extern bool cairo_in_fill (IntPtr cr, double x, double y); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - [return: MarshalAs (UnmanagedType.U1)] - internal static extern bool cairo_in_stroke (IntPtr cr, double x, double y); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_line_to (IntPtr cr, double x, double y); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_mask (IntPtr cr, IntPtr pattern); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_mask_surface (IntPtr cr, IntPtr surface, double x, double y); - - #region Matrix - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_matrix_init (Matrix matrix, double xx, double yx, double xy, double yy, double x0, double y0); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_matrix_init_identity (Matrix matrix); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_matrix_init_rotate (Matrix matrix, double radians); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_matrix_init_scale (Matrix matrix, double sx, double sy); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_matrix_init_translate (Matrix matrix, double tx, double ty); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern Status cairo_matrix_invert (Matrix matrix); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_matrix_multiply (Matrix result, Matrix a, Matrix b); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_matrix_scale (Matrix matrix, double sx, double sy); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_matrix_rotate (Matrix matrix, double radians); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_matrix_transform_distance (Matrix matrix, ref double dx, ref double dy); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_matrix_transform_point (Matrix matrix, ref double x, ref double y); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_matrix_translate (Matrix matrix, double tx, double ty); - #endregion - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_move_to (IntPtr cr, double x, double y); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_new_path (IntPtr cr); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_new_sub_path (IntPtr cr); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_paint (IntPtr cr); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_paint_with_alpha (IntPtr cr, double alpha); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_path_destroy (IntPtr path); - - #region Pattern - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_pattern_add_color_stop_rgb (IntPtr pattern, double offset, double red, double green, double blue); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_pattern_add_color_stop_rgba (IntPtr pattern, double offset, double red, double green, double blue, double alpha); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern Status cairo_pattern_get_color_stop_count (IntPtr pattern, out int count); - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern Status cairo_pattern_get_color_stop_rgba (IntPtr pattern, int index, out double offset, out double red, out double green, out double blue, out double alpha); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_pattern_create_for_surface (IntPtr surface); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern Status cairo_pattern_get_surface (IntPtr pattern, out IntPtr surface); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_pattern_create_linear (double x0, double y0, double x1, double y1); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern Status cairo_pattern_get_linear_points (IntPtr pattern, out double x0, out double y0, out double x1, out double y1); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_pattern_create_radial (double cx0, double cy0, double radius0, double cx1, double cy1, double radius1); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern Status cairo_pattern_get_radial_circles (IntPtr pattern, out double x0, out double y0, out double r0, out double x1, out double y1, out double r1); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_pattern_create_rgb (double r, double g, double b); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_pattern_create_rgba (double r, double g, double b, double a); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern Status cairo_pattern_get_rgba (IntPtr pattern, out double red, out double green, out double blue, out double alpha); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_pattern_destroy (IntPtr pattern); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern Extend cairo_pattern_get_extend (IntPtr pattern); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern Filter cairo_pattern_get_filter (IntPtr pattern); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_pattern_get_matrix (IntPtr pattern, Matrix matrix); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern PatternType cairo_pattern_get_type (IntPtr pattern); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_pattern_reference (IntPtr pattern); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_pattern_set_extend (IntPtr pattern, Extend extend); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_pattern_set_filter (IntPtr pattern, Filter filter); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_pattern_set_matrix (IntPtr pattern, Matrix matrix); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern Status cairo_pattern_status (IntPtr pattern); - - //mesh pattern - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_pattern_create_mesh (); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_mesh_pattern_begin_patch (IntPtr pattern); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_mesh_pattern_end_patch (IntPtr pattern); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_mesh_pattern_move_to (IntPtr pattern, double x, double y); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_mesh_pattern_line_to (IntPtr pattern, double x, double y); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_mesh_pattern_curve_to (IntPtr pattern, double x1, double y1, - double x2, double y2, double x3, double y3); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_mesh_pattern_set_control_point (IntPtr pattern, uint point_num, double x, double y); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_mesh_pattern_set_corner_color_rgb (IntPtr pattern, uint corner_num, - double r, double g, double b); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_mesh_pattern_set_corner_color_rgba (IntPtr pattern, uint corner_num, - double r, double g, double b, double a); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern Status cairo_mesh_pattern_get_patch_count (IntPtr pattern, out uint count); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_mesh_pattern_get_path (IntPtr pattern, uint patch_num); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern Status cairo_mesh_pattern_get_control_point (IntPtr pattern, - uint patch_num, uint point_num, out double x, out double y); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern Status cairo_mesh_pattern_get_corner_color_rgba (IntPtr pattern, - uint patch_num, uint point_num, out double r, out double g, out double b, out double a); - #endregion - - #region PdfSurface - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_pdf_surface_create (string filename, double width, double height); - - //[DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - //internal static extern IntPtr cairo_pdf_surface_create_for_stream (string filename, double width, double height); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_pdf_surface_set_size (IntPtr surface, double x, double y); - #endregion - - #region PostscriptSurface - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_ps_surface_create (string filename, double width, double height); - - //[DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - //internal static extern IntPtr cairo_ps_surface_create_for_stream (string filename, double width, double height); - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_ps_surface_dsc_begin_page_setup (IntPtr surface); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_ps_surface_dsc_begin_setup (IntPtr surface); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_ps_surface_dsc_comment (IntPtr surface, string comment); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_ps_surface_set_size (IntPtr surface, double x, double y); - #endregion - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_pop_group (IntPtr cr); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_pop_group_to_source (IntPtr cr); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_push_group (IntPtr cr); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_push_group_with_content (IntPtr cr, Content content); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_quartz_surface_create (IntPtr context, bool flipped, int width, int height); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_rectangle (IntPtr cr, double x, double y, double width, double height); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_reference (IntPtr cr); - - #region Regions - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern bool cairo_region_contains_point (IntPtr region, int x, int y); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern RegionOverlap cairo_region_contains_rectangle (IntPtr region, ref Crow.Rectangle rectangle); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_region_copy (IntPtr original); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_region_create (); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_region_create_rectangle (ref Crow.Rectangle rect); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_region_create_rectangles (IntPtr rects, int count); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_region_destroy (IntPtr region); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern bool cairo_region_equal (IntPtr a, IntPtr b); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_region_get_extents (IntPtr region, out Crow.Rectangle extents); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_region_get_rectangle (IntPtr region, int nth, out Crow.Rectangle rectangle); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern Status cairo_region_intersect (IntPtr dst, IntPtr other); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern Status cairo_region_intersect_rectangle (IntPtr dst, ref Crow.Rectangle rectangle); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern bool cairo_region_is_empty (IntPtr region); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern int cairo_region_num_rectangles (IntPtr region); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_region_reference (IntPtr region); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern Status cairo_region_status (IntPtr region); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern Status cairo_region_subtract (IntPtr dst, IntPtr other); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern Status cairo_region_subtract_rectangle (IntPtr dst, ref Crow.Rectangle rectangle); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_region_translate (IntPtr region, int dx, int dy); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern Status cairo_region_union (IntPtr dst, IntPtr other); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern Status cairo_region_union_rectangle (IntPtr dst, ref Crow.Rectangle rectangle); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern Status cairo_region_xor (IntPtr dst, IntPtr other); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern Status cairo_region_xor_rectangle (IntPtr dst, ref Crow.Rectangle rectangle); - #endregion - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_rel_curve_to (IntPtr cr, double dx1, double dy1, double dx2, double dy2, double dx3, double dy3); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_rel_line_to (IntPtr cr, double dx, double dy); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_rel_move_to (IntPtr cr, double dx, double dy); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_reset_clip (IntPtr cr); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_restore (IntPtr cr); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_rotate (IntPtr cr, double angle); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_save (IntPtr cr); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_scale (IntPtr cr, double sx, double sy); - - #region ScaledFont - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_scaled_font_create (IntPtr fontFace, Matrix matrix, Matrix ctm, IntPtr options); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_scaled_font_destroy (IntPtr scaled_font); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_scaled_font_extents (IntPtr scaled_font, out FontExtents extents); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_scaled_font_get_ctm (IntPtr scaled_font, out Matrix matrix); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_scaled_font_get_font_face (IntPtr scaled_font); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_scaled_font_get_font_matrix (IntPtr scaled_font, out Matrix matrix); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_scaled_font_get_font_options (IntPtr scaled_font); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern FontType cairo_scaled_font_get_type (IntPtr scaled_font); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_scaled_font_glyph_extents (IntPtr scaled_font, IntPtr glyphs, int num_glyphs, out TextExtents extents); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_scaled_font_reference (IntPtr scaled_font); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern Status cairo_scaled_font_status (IntPtr scaled_font); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_set_scaled_font (IntPtr cr, IntPtr scaled_font); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_get_scaled_font (IntPtr cr); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_scaled_font_text_extents (IntPtr scaled_font, byte[] utf8, out TextExtents extents); - #endregion - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_select_font_face (IntPtr cr, string family, FontSlant slant, FontWeight weight); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_set_antialias (IntPtr cr, Antialias antialias); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_set_dash (IntPtr cr, double [] dashes, int ndash, double offset); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_get_dash (IntPtr cr, IntPtr dashes, out double offset); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern int cairo_get_dash_count (IntPtr cr); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_set_fill_rule (IntPtr cr, Cairo.FillRule fill_rule); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_set_font_face (IntPtr cr, IntPtr fontFace); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_set_font_matrix (IntPtr cr, Matrix matrix); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_set_font_options (IntPtr cr, IntPtr options); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_set_font_size (IntPtr cr, double size); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_set_line_cap (IntPtr cr, LineCap line_cap); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_set_line_join (IntPtr cr, LineJoin line_join); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_set_line_width (IntPtr cr, double width); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_set_matrix (IntPtr cr, Matrix matrix); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_set_miter_limit (IntPtr cr, double limit); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_set_operator (IntPtr cr, Cairo.Operator op); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_set_source (IntPtr cr, IntPtr pattern); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_set_source_rgb (IntPtr cr, double red, double green, double blue); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_set_source_rgba (IntPtr cr, double red, double green, double blue, double alpha); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_set_source_surface (IntPtr cr, IntPtr surface, double x, double y); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_set_tolerance (IntPtr cr, double tolerance); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_show_glyphs (IntPtr ct, IntPtr glyphs, int num_glyphs); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_show_page (IntPtr cr); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_show_text (IntPtr cr, byte[] utf8); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern Status cairo_status (IntPtr cr); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_status_to_string (Status status); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_stroke (IntPtr cr); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_stroke_extents (IntPtr cr, out double x1, out double y1, out double x2, out double y2); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_stroke_preserve (IntPtr cr); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_rectangle_list_destroy (IntPtr rectangle_list); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_copy_clip_rectangle_list (IntPtr cr); - - #region Surface - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_surface_create_similar (IntPtr surface, Cairo.Content content, int width, int height); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_surface_destroy (IntPtr surface); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_surface_finish (IntPtr surface); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_surface_flush (IntPtr surface); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern Content cairo_surface_get_content (IntPtr surface); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_surface_get_device_offset (IntPtr surface, out double x, out double y); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_surface_get_font_options (IntPtr surface, IntPtr FontOptions); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern uint cairo_surface_get_reference_count (IntPtr surface); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern SurfaceType cairo_surface_get_type (IntPtr surface); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_surface_mark_dirty (IntPtr surface); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_surface_mark_dirty_rectangle (IntPtr surface, int x, int y, int width, int height); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_surface_reference (IntPtr surface); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_surface_set_device_offset (IntPtr surface, double x, double y); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_surface_set_fallback_resolution (IntPtr surface, double x, double y); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern Status cairo_surface_status (IntPtr surface); - #endregion - - #region SVG surface - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_surface_write_to_png (IntPtr surface, string filename); - - //[DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - //internal static extern void cairo_surface_write_to_png_stream (IntPtr surface, WriteFunc writeFunc); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_svg_surface_create (string fileName, double width, double height); - - //[DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - //internal static extern IntPtr cairo_svg_surface_create_for_stream (double width, double height); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_svg_surface_restrict_to_version (IntPtr surface, SvgVersion version); - #endregion - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_text_extents (IntPtr cr, byte[] utf8, out TextExtents extents); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_text_path (IntPtr ct, byte[] utf8); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_transform (IntPtr cr, Matrix matrix); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_translate (IntPtr cr, double tx, double ty); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_user_to_device (IntPtr cr, ref double x, ref double y); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_user_to_device_distance (IntPtr cr, ref double dx, ref double dy); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern int cairo_version (); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_version_string (); - - #region DirectFBSurface - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_directfb_surface_create (IntPtr dfb, IntPtr surface); - #endregion - - #region win32 fonts - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_win32_font_face_create_for_logfontw (IntPtr logfontw); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_win32_scaled_font_done_font (IntPtr scaled_font); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern double cairo_win32_scaled_font_get_metrics_factor (IntPtr scaled_font); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern Status cairo_win32_scaled_font_select_font (IntPtr scaled_font, IntPtr hdc); - #endregion - - #region win32 surface - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_win32_surface_create (IntPtr hdc); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_win32_surface_create_with_ddb (IntPtr hdc, Format format, int width, int height); - #endregion - - #region XcbSurface - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_xcb_surface_create (IntPtr connection, uint drawable, IntPtr visual, int width, int height); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_xcb_surface_create_for_bitmap (IntPtr connection, uint bitmap, IntPtr screen, int width, int height); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_xcb_surface_set_size (IntPtr surface, int width, int height); - #endregion - - #region XlibSurface - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_xlib_surface_create (IntPtr display, IntPtr drawable, IntPtr visual, int width, int height); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_xlib_surface_create_for_bitmap (IntPtr display, IntPtr bitmap, IntPtr screen, int width, int height); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern int cairo_xlib_surface_get_depth (IntPtr surface); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_xlib_surface_get_display (IntPtr surface); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_xlib_surface_get_drawable (IntPtr surface); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern int cairo_xlib_surface_get_height (IntPtr surface); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_xlib_surface_get_screen (IntPtr surface); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_xlib_surface_get_visual (IntPtr surface); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern int cairo_xlib_surface_get_width (IntPtr surface); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_xlib_surface_set_drawable (IntPtr surface, IntPtr drawable, int width, int height); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_xlib_surface_set_size (IntPtr surface, int width, int height); - #endregion - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_gl_device_set_thread_aware(IntPtr device, int value); - - #region GLSurface - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_gl_surface_create (IntPtr device, uint content, int width, int height); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_gl_surface_create_for_texture (IntPtr device, uint content, uint tex, int width, int height); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_gl_surface_set_size (IntPtr surface, int width, int height); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern int cairo_gl_surface_get_width (IntPtr surface); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern int cairo_gl_surface_get_height (IntPtr surface); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_gl_surface_swapbuffers (IntPtr surf); - #endregion - - #region GLX Functions - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_glx_device_create (IntPtr dpy, IntPtr gl_ctx); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_glx_device_get_display (IntPtr device); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_glx_device_get_context (IntPtr device); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_gl_surface_create_for_window (IntPtr device, IntPtr window, int width, int height); - #endregion - - #region WGL Fucntions - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_wgl_device_create (IntPtr hglrc); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_wgl_device_get_context (IntPtr device); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_gl_surface_create_for_dc (IntPtr device, IntPtr hdc, int width, int height); - #endregion - - #region EGL Functions - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_egl_device_create (IntPtr dpy, IntPtr gl_ctx); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_gl_surface_create_for_egl (IntPtr device, IntPtr eglSurface, int width, int height); - #endregion - - #region DRM Functions - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_drm_device_get (IntPtr udev_device); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_drm_device_get_for_fd (int fd); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_drm_device_default (); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern int cairo_drm_device_get_fd (IntPtr cairo_device); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_drm_device_throttle (IntPtr cairo_device); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_drm_surface_create (IntPtr cairo_device, Format format, int width, int height); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_drm_surface_create_for_name (IntPtr cairo_device, uint name, Format format, int width, int height, int stride); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_drm_surface_create_from_cacheable_image (IntPtr cairo_device, IntPtr imageSurface); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern Status cairo_drm_surface_enable_scan_out (IntPtr drmSurface); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_drm_surface_get_handle (IntPtr drmSurface); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_drm_surface_get_name (IntPtr drmSurface); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern Format cairo_drm_surface_get_format (IntPtr drmSurface); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern int cairo_drm_surface_get_width (IntPtr drmSurface); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern int cairo_drm_surface_get_height (IntPtr drmSurface); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern int cairo_drm_surface_get_stride (IntPtr drmSurface); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_drm_surface_map_to_image (IntPtr drmSurface); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_drm_surface_unmap (IntPtr drmSurface, IntPtr imageSurface); - #endregion - - #region Device - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern Status cairo_device_acquire(IntPtr device); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_device_destroy (IntPtr device); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern IntPtr cairo_device_reference (IntPtr device); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern void cairo_device_release(IntPtr device); - - [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern Status cairo_device_status(IntPtr device); - #endregion - } -}
\ No newline at end of file diff --git a/src/Mono.Cairo/Operator.cs b/src/Mono.Cairo/Operator.cs deleted file mode 100644 index c1ced71d..00000000 --- a/src/Mono.Cairo/Operator.cs +++ /dev/null @@ -1,56 +0,0 @@ -// -// Mono.Cairo.Operator.cs -// -// Authors: Duncan Mak (duncan@ximian.com) -// Hisham Mardam Bey (hisham.mardambey@gmail.com) -// John Luke (john.luke@gmail.com) -// -// (C) Ximian, Inc. 2003 -// Copyright (C) 2004 Novell, Inc (http://www.novell.com) -// Copyright (C) 2005 John Luke -// -// 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; - -namespace Cairo -{ - [Serializable] - public enum Operator - { - Clear, - Source, - Over, - In, - Out, - Atop, - - Dest, - DestOver, - DestIn, - DestOut, - DestAtop, - - Xor, - Add, - Saturate, - } -} diff --git a/src/Mono.Cairo/PSSurface.cs b/src/Mono.Cairo/PSSurface.cs deleted file mode 100644 index 9d6b73be..00000000 --- a/src/Mono.Cairo/PSSurface.cs +++ /dev/null @@ -1,64 +0,0 @@ -// -// Mono.Cairo.PostscriptSurface.cs -// -// Authors: -// John Luke -// -// (C) John Luke, 2006. -// -// 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; - -namespace Cairo { - - public class PSSurface : Surface - { - internal PSSurface (IntPtr handle, bool owns) : base (handle, owns) - { - } - - public PSSurface (string filename, double width, double height) - : base (NativeMethods.cairo_ps_surface_create (filename, width, height), true) - { - } - - public void BeginPageSetup () - { - NativeMethods.cairo_ps_surface_dsc_begin_page_setup (Handle); - } - - public void BeginSetup () - { - NativeMethods.cairo_ps_surface_dsc_begin_setup (Handle); - } - - public void DscComment (string comment) - { - NativeMethods.cairo_ps_surface_dsc_comment (Handle, comment); - } - - public void SetSize (double width, double height) - { - NativeMethods.cairo_ps_surface_set_size (Handle, width, height); - } - } -} diff --git a/src/Mono.Cairo/Path.cs b/src/Mono.Cairo/Path.cs deleted file mode 100644 index 184c606c..00000000 --- a/src/Mono.Cairo/Path.cs +++ /dev/null @@ -1,73 +0,0 @@ -// -// Mono.Cairo.Context.cs -// -// Author: -// Miguel de Icaza (miguel@novell.com) -// -// This is an OO wrapper API for the Cairo API. -// -// Copyright 2007 Novell, Inc (http://www.novell.com) -// -// 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.Runtime.InteropServices; -using Cairo; - -namespace Cairo { - - public class Path : IDisposable - { - IntPtr handle = IntPtr.Zero; - - internal Path (IntPtr handle) - { - this.handle = handle; - if (CairoDebug.Enabled) - CairoDebug.OnAllocated (handle); - } - - ~Path () - { - Dispose (false); - } - - public IntPtr Handle { get { return handle; } } - - public void Dispose () - { - Dispose (true); - GC.SuppressFinalize (this); - } - - protected virtual void Dispose (bool disposing) - { - if (!disposing || CairoDebug.Enabled) - CairoDebug.OnDisposed<Path> (handle, disposing); - - if (!disposing|| handle == IntPtr.Zero) - return; - - NativeMethods.cairo_path_destroy (handle); - handle = IntPtr.Zero; - } - } -} diff --git a/src/Mono.Cairo/Pattern.cs b/src/Mono.Cairo/Pattern.cs deleted file mode 100644 index bc0a962a..00000000 --- a/src/Mono.Cairo/Pattern.cs +++ /dev/null @@ -1,155 +0,0 @@ -// -// Mono.Cairo.Pattern.cs -// -// Author: Jordi Mas (jordi@ximian.com) -// Hisham Mardam Bey (hisham.mardambey@gmail.com) -// (C) Ximian Inc, 2004. -// -// Copyright (C) 2004 Novell, Inc (http://www.novell.com) -// -// 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; - -namespace Cairo { - - public class Pattern : IDisposable - { - [Obsolete] - protected IntPtr pattern = IntPtr.Zero; - - public static Pattern Lookup (IntPtr pattern, bool owner) - { - if (pattern == IntPtr.Zero) - return null; - - PatternType pt = NativeMethods.cairo_pattern_get_type (pattern); - switch (pt) { - case PatternType.Solid: - return new SolidPattern (pattern, owner); - case PatternType.Surface: - return new SurfacePattern (pattern, owner); - case PatternType.Linear: - return new LinearGradient (pattern, owner); - case PatternType.Radial: - return new RadialGradient (pattern, owner); - default: - return new Pattern (pattern, owner); - } - } - - [Obsolete] - protected Pattern () - { - } - - internal Pattern (IntPtr handle, bool owned) - { - Handle = handle; - if (!owned) - NativeMethods.cairo_pattern_reference (handle); - if (CairoDebug.Enabled) - CairoDebug.OnAllocated (handle); - } - - ~Pattern () - { - Dispose (false); - } - - [Obsolete ("Use the SurfacePattern constructor")] - public Pattern (Surface surface) - : this ( NativeMethods.cairo_pattern_create_for_surface (surface.Handle), true) - { - } - - [Obsolete] - protected void Reference () - { - NativeMethods.cairo_pattern_reference (pattern); - } - - public void Dispose () - { - Dispose (true); - GC.SuppressFinalize (this); - } - - protected virtual void Dispose (bool disposing) - { - if (!disposing || CairoDebug.Enabled) - CairoDebug.OnDisposed<Pattern> (Handle, disposing); - - if (!disposing|| Handle == IntPtr.Zero) - return; - - NativeMethods.cairo_pattern_destroy (Handle); - Handle = IntPtr.Zero; - } - - [Obsolete ("Use Dispose()")] - public void Destroy () - { - Dispose (); - } - - public Status Status - { - get { return NativeMethods.cairo_pattern_status (Handle); } - } - - public Extend Extend - { - get { return NativeMethods.cairo_pattern_get_extend (Handle); } - set { NativeMethods.cairo_pattern_set_extend (Handle, value); } - } - - public Matrix Matrix { - set { - NativeMethods.cairo_pattern_set_matrix (Handle, value); - } - - get { - Matrix m = new Matrix (); - NativeMethods.cairo_pattern_get_matrix (Handle, m); - return m; - } - } - -#pragma warning disable 612 - public IntPtr Handle { - get { return pattern; } - private set { pattern = value; } - } -#pragma warning restore 612 - - [Obsolete] - public IntPtr Pointer { - get { return pattern; } - } - - public PatternType PatternType { - get { return NativeMethods.cairo_pattern_get_type (Handle); } - } - } -} - diff --git a/src/Mono.Cairo/PatternType.cs b/src/Mono.Cairo/PatternType.cs deleted file mode 100644 index 8fe2d85d..00000000 --- a/src/Mono.Cairo/PatternType.cs +++ /dev/null @@ -1,44 +0,0 @@ -// -// Mono.Cairo.PatternType.cs -// -// Authors: -// John Luke -// -// (C) John Luke, 2006. -// -// 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; - -namespace Cairo { - - [Serializable] - public enum PatternType - { - Solid, - Surface, - Linear, - Radial, - Mesh, - RasterSource - } -} - diff --git a/src/Mono.Cairo/PdfSurface.cs b/src/Mono.Cairo/PdfSurface.cs deleted file mode 100644 index c980f249..00000000 --- a/src/Mono.Cairo/PdfSurface.cs +++ /dev/null @@ -1,50 +0,0 @@ -// -// Mono.Cairo.PdfSurface.cs -// -// Authors: -// John Luke -// -// (C) John Luke, 2006. -// -// 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; - -namespace Cairo { - - public class PdfSurface : Surface - { - internal PdfSurface (IntPtr handle, bool owns) : base (handle, owns) - { - } - - public PdfSurface (string filename, double width, double height) - : base (NativeMethods.cairo_pdf_surface_create (filename, width, height), true) - { - } - - public void SetSize (double width, double height) - { - NativeMethods.cairo_pdf_surface_set_size (Handle, width, height); - } - } -} - diff --git a/src/Mono.Cairo/Point.cs b/src/Mono.Cairo/Point.cs deleted file mode 100644 index e72ca6c5..00000000 --- a/src/Mono.Cairo/Point.cs +++ /dev/null @@ -1,57 +0,0 @@ -// -// Mono.Cairo.Context.cs -// -// Author: -// Duncan Mak (duncan@ximian.com) -// Miguel de Icaza (miguel@novell.com) -// Hisham Mardam Bey (hisham.mardambey@gmail.com) -// Alp Toker (alp@atoker.com) -// -// (C) Ximian Inc, 2003. -// (C) Novell Inc, 2003. -// -// This is an OO wrapper API for the Cairo API. -// -// Copyright (C) 2004 Novell, Inc (http://www.novell.com) -// -// 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. -// - -namespace Cairo { - public struct Point - { - public Point (int x, int y) - { - this.x = x; - this.y = y; - } - - int x, y; - public int X { - get { return x; } - set { x = value; } - } - - public int Y { - get { return y; } - set { y = value; } - } - } -} diff --git a/src/Mono.Cairo/PointD.cs b/src/Mono.Cairo/PointD.cs deleted file mode 100644 index c2e3587d..00000000 --- a/src/Mono.Cairo/PointD.cs +++ /dev/null @@ -1,58 +0,0 @@ -// -// Mono.Cairo.Context.cs -// -// Author: -// Duncan Mak (duncan@ximian.com) -// Miguel de Icaza (miguel@novell.com) -// Hisham Mardam Bey (hisham.mardambey@gmail.com) -// Alp Toker (alp@atoker.com) -// -// (C) Ximian Inc, 2003. -// (C) Novell Inc, 2003. -// -// This is an OO wrapper API for the Cairo API. -// -// Copyright (C) 2004 Novell, Inc (http://www.novell.com) -// -// 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. -// - -namespace Cairo { - - public struct PointD - { - public PointD (double x, double y) - { - this.x = x; - this.y = y; - } - - double x, y; - public double X { - get { return x; } - set { x = value; } - } - - public double Y { - get { return y; } - set { y = value; } - } - } -} diff --git a/src/Mono.Cairo/RadialGradient.cs b/src/Mono.Cairo/RadialGradient.cs deleted file mode 100644 index 6422e00d..00000000 --- a/src/Mono.Cairo/RadialGradient.cs +++ /dev/null @@ -1,46 +0,0 @@ -// -// Mono.Cairo.Pattern.cs -// -// Author: Jordi Mas (jordi@ximian.com) -// Hisham Mardam Bey (hisham.mardambey@gmail.com) -// (C) Ximian Inc, 2004. -// -// Copyright (C) 2004 Novell, Inc (http://www.novell.com) -// -// 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; - -namespace Cairo { - - public class RadialGradient : Gradient - { - internal RadialGradient (IntPtr handle, bool owned) : base (handle, owned) - { - } - - public RadialGradient (double cx0, double cy0, double radius0, double cx1, double cy1, double radius1) - : base (NativeMethods.cairo_pattern_create_radial (cx0, cy0, radius0, cx1, cy1, radius1), true) - { - } - } -} - diff --git a/src/Mono.Cairo/Rectangle.cs b/src/Mono.Cairo/Rectangle.cs deleted file mode 100644 index 6766aa45..00000000 --- a/src/Mono.Cairo/Rectangle.cs +++ /dev/null @@ -1,99 +0,0 @@ -// -// Mono.Cairo.Rectangle.cs -// -// Author: -// John Luke (john.luke@gmail.com) -// -// (C) John Luke 2005. -// -// 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; - -namespace Cairo -{ -// public struct Rectangle -// { -// double x; -// double y; -// double width; -// double height; -// -// public Rectangle (double x, double y, double width, double height) -// { -// this.x = x; -// this.y = y; -// this.width = width; -// this.height = height; -// } -// -// public Rectangle (Point point, double width, double height) -// { -// x = point.X; -// y = point.Y; -// this.width = width; -// this.height = height; -// } -// -// public double X { -// get { return x; } -// } -// -// public double Y { -// get { return y; } -// } -// -// public double Width { -// get { return width; } -// } -// -// public double Height { -// get { return height; } -// } -// -// public override bool Equals (object obj) -// { -// if (obj is Rectangle) -// return this == (Rectangle)obj; -// return false; -// } -// -// public override int GetHashCode () -// { -// return (int) (x + y + width + height); -// } -// -// public override string ToString () -// { -// return String.Format ("x:{0} y:{1} w:{2} h:{3}", x, y, width, height); -// } -// -// public static bool operator == (Rectangle rectangle, Rectangle other) -// { -// return rectangle.X == other.X && rectangle.Y == other.Y && rectangle.Width == other.Width && rectangle.Height == other.Height; -// } -// -// public static bool operator != (Rectangle rectangle, Rectangle other) -// { -// return !(rectangle == other); -// } -// } -} diff --git a/src/Mono.Cairo/Region.cs b/src/Mono.Cairo/Region.cs deleted file mode 100644 index 4a82842a..00000000 --- a/src/Mono.Cairo/Region.cs +++ /dev/null @@ -1,196 +0,0 @@ -// Copyright (C) 2011 Novell, Inc (http://www.novell.com) -// -// 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.Runtime.InteropServices; - -namespace Cairo -{ - [StructLayout(LayoutKind.Sequential)] - public struct RectangleList { - public Status Status; - public IntPtr Rectangles; - public int NumRectangles; - } - - public enum RegionOverlap { - In, - Out, - Part, - } - - public class Region : IDisposable { - - IntPtr handle; - public IntPtr Handle { - get { return handle; } - } - - [Obsolete] - public Region (IntPtr handle) : this (handle, false) {} - - public Region (IntPtr handle, bool owned) - { - this.handle = handle; - if (!owned) - NativeMethods.cairo_region_reference (handle); - if (CairoDebug.Enabled) - CairoDebug.OnAllocated (handle); - } - - public Region () : this (NativeMethods.cairo_region_create () , true) - { - } - - public Region (Crow.Rectangle rect) - { - handle = NativeMethods.cairo_region_create_rectangle (ref rect); - } - - public Region (RectangleList rects) - { - handle = NativeMethods.cairo_region_create_rectangles (rects.Rectangles, rects.NumRectangles); - } - - public Region Copy () - { - return new Region (NativeMethods.cairo_region_copy (Handle), true); - } - - #region IDisposable - ~Region () - { - Dispose (false); - } - - public void Dispose () - { - Dispose (true); - GC.SuppressFinalize (this); - } - - protected virtual void Dispose (bool disposing) - { - if (!disposing || CairoDebug.Enabled) - CairoDebug.OnDisposed<Region> (handle, disposing); - - if (!disposing|| handle == IntPtr.Zero) - return; - - NativeMethods.cairo_region_destroy (Handle); - handle = IntPtr.Zero; - } - #endregion - - public override bool Equals (object obj) - { - return (obj is Region) && NativeMethods.cairo_region_equal (Handle, (obj as Region).Handle); - } - - public override int GetHashCode () - { - return Handle.GetHashCode (); - } - - public Status Status { - get { return NativeMethods.cairo_region_status (Handle); } - } - - public Crow.Rectangle Extents { - get { - Crow.Rectangle result; - NativeMethods.cairo_region_get_extents (Handle, out result); - return result; - } - } - - public int NumRectangles { - get { return NativeMethods.cairo_region_num_rectangles (Handle); } - } - - public Crow.Rectangle GetRectangle (int nth) - { - Crow.Rectangle val; - NativeMethods.cairo_region_get_rectangle (Handle, nth, out val); - return val; - } - - public bool IsEmpty { - get { return NativeMethods.cairo_region_is_empty (Handle); } - } - - public RegionOverlap Contains (Crow.Rectangle rectangle) - { - return NativeMethods.cairo_region_contains_rectangle (Handle, ref rectangle); - } - - public bool Contains (int x, int y) - { - return NativeMethods.cairo_region_contains_point (Handle, x, y); - } - - public void Translate (int dx, int dy) - { - NativeMethods.cairo_region_translate (Handle, dx, dy); - } - - public Status Subtract (Region other) - { - return NativeMethods.cairo_region_subtract (Handle, other.Handle); - } - - public Status SubtractRectangle (Crow.Rectangle rectangle) - { - return NativeMethods.cairo_region_subtract_rectangle (Handle, ref rectangle); - } - - public Status Intersect (Region other) - { - return NativeMethods.cairo_region_intersect (Handle, other.Handle); - } - - public Status IntersectRectangle (Crow.Rectangle rectangle) - { - return NativeMethods.cairo_region_intersect_rectangle (Handle, ref rectangle); - } - - public Status Union (Region other) - { - return NativeMethods.cairo_region_union (Handle, other.Handle); - } - - public Status UnionRectangle (Crow.Rectangle rectangle) - { - return NativeMethods.cairo_region_union_rectangle (Handle, ref rectangle); - } - - public Status Xor (Region other) - { - return NativeMethods.cairo_region_xor (Handle, other.Handle); - } - - public Status XorRectangle (Crow.Rectangle rectangle) - { - return NativeMethods.cairo_region_xor_rectangle (Handle, ref rectangle); - } - } -} diff --git a/src/Mono.Cairo/ScaledFont.cs b/src/Mono.Cairo/ScaledFont.cs deleted file mode 100644 index 93719460..00000000 --- a/src/Mono.Cairo/ScaledFont.cs +++ /dev/null @@ -1,123 +0,0 @@ -// -// Mono.Cairo.ScaledFont.cs -// -// (c) 2008 Jordi Mas i Hernandez (jordimash@gmail.com) -// -// 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.Runtime.InteropServices; - -namespace Cairo { - - public class ScaledFont : IDisposable - { - protected IntPtr handle = IntPtr.Zero; - - internal ScaledFont (IntPtr handle, bool owner) - { - this.handle = handle; - if (!owner) - NativeMethods.cairo_scaled_font_reference (handle); - if (CairoDebug.Enabled) - CairoDebug.OnAllocated (handle); - } - - public ScaledFont (FontFace fontFace, Matrix matrix, Matrix ctm, FontOptions options) - : this (NativeMethods.cairo_scaled_font_create (fontFace.Handle, matrix, ctm, options.Handle), true) - { - } - - ~ScaledFont () - { - Dispose (false); - } - - public IntPtr Handle { - get { - return handle; - } - } - - public FontExtents FontExtents { - get { - FontExtents extents; - NativeMethods.cairo_scaled_font_extents (handle, out extents); - return extents; - } - } - - public Matrix FontMatrix { - get { - Matrix m; - NativeMethods.cairo_scaled_font_get_font_matrix (handle, out m); - return m; - } - } - - public FontType FontType { - get { - return NativeMethods.cairo_scaled_font_get_type (handle); - } - } - - public TextExtents GlyphExtents (Glyph[] glyphs) - { - IntPtr ptr = Context.FromGlyphToUnManagedMemory (glyphs); - TextExtents extents; - - NativeMethods.cairo_scaled_font_glyph_extents (handle, ptr, glyphs.Length, out extents); - - Marshal.FreeHGlobal (ptr); - return extents; - } - - public Status Status - { - get { return NativeMethods.cairo_scaled_font_status (handle); } - } - - public void Dispose () - { - Dispose (true); - GC.SuppressFinalize (this); - } - - protected virtual void Dispose (bool disposing) - { - if (!disposing || CairoDebug.Enabled) - CairoDebug.OnDisposed<ScaledFont> (handle, disposing); - - if (!disposing|| handle == IntPtr.Zero) - return; - - NativeMethods.cairo_scaled_font_destroy (handle); - handle = IntPtr.Zero; - } - - [Obsolete] - protected void Reference () - { - NativeMethods.cairo_scaled_font_reference (handle); - } - } -} - diff --git a/src/Mono.Cairo/SolidPattern.cs b/src/Mono.Cairo/SolidPattern.cs deleted file mode 100644 index 875b3fbf..00000000 --- a/src/Mono.Cairo/SolidPattern.cs +++ /dev/null @@ -1,72 +0,0 @@ -// -// Mono.Cairo.Pattern.cs -// -// Author: Jordi Mas (jordi@ximian.com) -// Hisham Mardam Bey (hisham.mardambey@gmail.com) -// (C) Ximian Inc, 2004. -// -// Copyright (C) 2004 Novell, Inc (http://www.novell.com) -// -// 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; - -namespace Cairo { - - public class SolidPattern : Pattern - { - internal SolidPattern (IntPtr handle, bool owned) : base (handle, owned) - { - } - - public SolidPattern (Color color) - : base (NativeMethods.cairo_pattern_create_rgba (color.R, color.G, color.B, color.A), true) - { - } - - public SolidPattern (double r, double g, double b) - : base (NativeMethods.cairo_pattern_create_rgb (r, g, b), true) - { - } - - public SolidPattern (double r, double g, double b, double a) - : base (NativeMethods.cairo_pattern_create_rgba (r, g, b, a), true) - { - } - - public SolidPattern (Color color, bool solid) - : base (solid - ? NativeMethods.cairo_pattern_create_rgb (color.R, color.G, color.B) - : NativeMethods.cairo_pattern_create_rgba (color.R, color.G, color.B, color.A), - true) - { - } - - public Color Color { - get { - double red, green, blue, alpha; - NativeMethods.cairo_pattern_get_rgba (Handle, out red, out green, out blue, out alpha); - return new Color (red, green, blue, alpha); - } - } - } -} - diff --git a/src/Mono.Cairo/Status.cs b/src/Mono.Cairo/Status.cs deleted file mode 100644 index 6e5fbe01..00000000 --- a/src/Mono.Cairo/Status.cs +++ /dev/null @@ -1,64 +0,0 @@ -// -// Mono.Cairo.Status.cs -// -// Authors: -// Duncan Mak (duncan@ximian.com) -// Hisham Mardam Bey (hisham.mardambey@gmail.com) -// John Luke (john.luke@gmail.com) -// Alp Toker (alp@atoker.com) -// -// Copyright (C) 2004 Novell, Inc (http://www.novell.com) -// Copyright (C) 2005 John Luke -// -// 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; - -namespace Cairo -{ - [Serializable] - public enum Status - { - Success = 0, - NoMemory, - InvalidRestore, - InvalidPopGroup, - NoCurrentPoint, - InvalidMatrix, - InvalidStatus, - NullPointer, - InvalidString, - InvalidPathData, - ReadError, - WriteError, - SurfaceFinished, - SurfaceTypeMismatch, - PatternTypeMismatch, - InvalidContent, - InvalidFormat, - InvalidVisual, - FileNotFound, - InvalidDash, - InvalidDscComment, - InvalidIndex, - ClipNotRepresentable, - } -} diff --git a/src/Mono.Cairo/SubpixelOrder.cs b/src/Mono.Cairo/SubpixelOrder.cs deleted file mode 100644 index e8ab6581..00000000 --- a/src/Mono.Cairo/SubpixelOrder.cs +++ /dev/null @@ -1,42 +0,0 @@ -// -// Mono.Cairo.Cairo.cs -// -// Authors: -// John Luke (john.luke@gmail.com) -// -// Copyright (C) John Luke 2005 -// -// 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; - -namespace Cairo -{ - [Serializable] - public enum SubpixelOrder - { - Default, - Rgb, - Bgr, - Vrgb, - Vbgr, - } -} diff --git a/src/Mono.Cairo/Surface.cs b/src/Mono.Cairo/Surface.cs deleted file mode 100644 index 6a55496a..00000000 --- a/src/Mono.Cairo/Surface.cs +++ /dev/null @@ -1,234 +0,0 @@ -// -// Mono.Cairo.Surface.cs -// -// Authors: -// Duncan Mak -// Miguel de Icaza. -// Alp Toker -// -// (C) Ximian Inc, 2003. -// (C) Novell, Inc. 2003. -// -// This is an OO wrapper API for the Cairo API -// -// Copyright (C) 2004 Novell, Inc (http://www.novell.com) -// -// 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; - -namespace Cairo { - - public class Surface : IDisposable - { - [Obsolete] - protected static Hashtable surfaces = new Hashtable (); - - IntPtr handle = IntPtr.Zero; - - [Obsolete] - protected Surface() - { - } - - [Obsolete] - protected Surface (IntPtr ptr) : this (ptr, true) - { - } - - protected Surface (IntPtr handle, bool owner) - { - this.handle = handle; - if (!owner) - NativeMethods.cairo_surface_reference (handle); - if (CairoDebug.Enabled) - CairoDebug.OnAllocated (handle); - } - - public static Surface Lookup (IntPtr surface, bool owned) - { - SurfaceType st = NativeMethods.cairo_surface_get_type (surface); - switch (st) { - case SurfaceType.Image: - return new ImageSurface (surface, owned); - case SurfaceType.Xlib: - return new XlibSurface (surface, owned); - case SurfaceType.Xcb: - return new XcbSurface (surface, owned); - case SurfaceType.Glitz: - return new GlitzSurface (surface, owned); - case SurfaceType.Win32: - return new Win32Surface (surface, owned); - case SurfaceType.Pdf: - return new PdfSurface (surface, owned); - case SurfaceType.PS: - return new PSSurface (surface, owned); - case SurfaceType.DirectFB: - return new DirectFBSurface (surface, owned); - case SurfaceType.Svg: - return new SvgSurface (surface, owned); - case SurfaceType.GL: - return new GLSurface (surface, owned); - default: - return new Surface (surface, owned); - } - } - - [Obsolete ("Use an ImageSurface constructor instead.")] - public static Cairo.Surface CreateForImage ( - ref byte[] data, Cairo.Format format, int width, int height, int stride) - { - IntPtr p = NativeMethods.cairo_image_surface_create_for_data ( - data, format, width, height, stride); - - return new Cairo.Surface (p, true); - } - - [Obsolete ("Use an ImageSurface constructor instead.")] - public static Cairo.Surface CreateForImage ( - Cairo.Format format, int width, int height) - { - IntPtr p = NativeMethods.cairo_image_surface_create ( - format, width, height); - - return new Cairo.Surface (p, true); - } - - - public Cairo.Surface CreateSimilar ( - Cairo.Content content, int width, int height) - { - IntPtr p = NativeMethods.cairo_surface_create_similar ( - this.Handle, content, width, height); - - return new Cairo.Surface (p, true); - } - - ~Surface () - { - Dispose (false); - } - - //[Obsolete ("Use Context.SetSource() followed by Context.Paint()")] - public void Show (Context gr, double x, double y) - { - NativeMethods.cairo_set_source_surface (gr.Handle, handle, x, y); - NativeMethods.cairo_paint (gr.Handle); - } - - public void Dispose () - { - Dispose (true); - GC.SuppressFinalize (this); - } - - protected virtual void Dispose (bool disposing) - { - if (!disposing || CairoDebug.Enabled) - CairoDebug.OnDisposed<Surface> (handle, disposing); - - if (!disposing|| handle == IntPtr.Zero) - return; - - NativeMethods.cairo_surface_destroy (handle); - handle = IntPtr.Zero; - } - - public Status Finish () - { - NativeMethods.cairo_surface_finish (handle); - return Status; - } - - public void Flush () - { - NativeMethods.cairo_surface_flush (handle); - } - - public void MarkDirty () - { - NativeMethods.cairo_surface_mark_dirty (Handle); - } - - public void MarkDirty (Crow.Rectangle rectangle) - { - NativeMethods.cairo_surface_mark_dirty_rectangle (Handle, rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height); - } - - public IntPtr Handle { - get { - return handle; - } - } - - public PointD DeviceOffset { - get { - double x, y; - NativeMethods.cairo_surface_get_device_offset (handle, out x, out y); - return new PointD (x, y); - } - - set { - NativeMethods.cairo_surface_set_device_offset (handle, value.X, value.Y); - } - } - - [Obsolete ("Use Dispose()")] - public void Destroy() - { - Dispose (); - } - - public void SetFallbackResolution (double x, double y) - { - NativeMethods.cairo_surface_set_fallback_resolution (handle, x, y); - } - - public void WriteToPng (string filename) - { - NativeMethods.cairo_surface_write_to_png (handle, filename); - } - - [Obsolete ("Use Handle instead.")] - public IntPtr Pointer { - get { - return handle; - } - } - - public Status Status { - get { return NativeMethods.cairo_surface_status (handle); } - } - - public Content Content { - get { return NativeMethods.cairo_surface_get_content (handle); } - } - - public SurfaceType SurfaceType { - get { return NativeMethods.cairo_surface_get_type (handle); } - } - - public uint ReferenceCount { - get { return NativeMethods.cairo_surface_get_reference_count (handle); } - } - } -} diff --git a/src/Mono.Cairo/SurfacePattern.cs b/src/Mono.Cairo/SurfacePattern.cs deleted file mode 100644 index 4422b11d..00000000 --- a/src/Mono.Cairo/SurfacePattern.cs +++ /dev/null @@ -1,57 +0,0 @@ -// -// Mono.Cairo.Pattern.cs -// -// Author: Jordi Mas (jordi@ximian.com) -// Hisham Mardam Bey (hisham.mardambey@gmail.com) -// (C) Ximian Inc, 2004. -// -// Copyright (C) 2004 Novell, Inc (http://www.novell.com) -// -// 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; - -namespace Cairo { - - public class SurfacePattern : Pattern - { - internal SurfacePattern (IntPtr handle, bool owned) : base (handle, owned) - { - } - - public SurfacePattern (Surface surface) - : base (NativeMethods.cairo_pattern_create_for_surface (surface.Handle), true) - { - } - - //no idea why this is here, the base one is identical, but we can't remove it now - public new Extend Extend { - set { NativeMethods.cairo_pattern_set_extend (Handle, value); } - get { return NativeMethods.cairo_pattern_get_extend (Handle); } - } - - public Filter Filter { - set { NativeMethods.cairo_pattern_set_filter (Handle, value); } - get { return NativeMethods.cairo_pattern_get_filter (Handle); } - } - } -} - diff --git a/src/Mono.Cairo/SurfaceType.cs b/src/Mono.Cairo/SurfaceType.cs deleted file mode 100644 index ae86d134..00000000 --- a/src/Mono.Cairo/SurfaceType.cs +++ /dev/null @@ -1,61 +0,0 @@ -// -// Mono.Cairo.SurfaceType.cs -// -// Authors: -// John Luke -// -// (C) John Luke, 2006. -// -// 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; - -namespace Cairo { - - [Serializable] - public enum SurfaceType - { - Image, - Pdf, - PS, - Xlib, - Xcb, - Glitz, - Quartz, - Win32, - BeOS, - DirectFB, - Svg, - OS2, - Win32Printing, - QuartzImage, - Script, - Qt, - Recording, - VG, - GL, - Drm, - Tee, - Xml, - Skia, - SubSurface - } -} diff --git a/src/Mono.Cairo/SvgSurface.cs b/src/Mono.Cairo/SvgSurface.cs deleted file mode 100644 index 41829501..00000000 --- a/src/Mono.Cairo/SvgSurface.cs +++ /dev/null @@ -1,50 +0,0 @@ -// -// Mono.Cairo.SvgSurface.cs -// -// Authors: -// John Luke -// -// (C) John Luke, 2006. -// -// 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; - -namespace Cairo { - - public class SvgSurface : Surface - { - internal SvgSurface (IntPtr handle, bool owns) : base (handle, owns) - { - } - - public SvgSurface (string filename, double width, double height) - : base (NativeMethods.cairo_svg_surface_create (filename, width, height), true) - { - } - - public void RestrictToVersion (SvgVersion version) - { - NativeMethods.cairo_svg_surface_restrict_to_version (Handle, version); - } - } -} - diff --git a/src/Mono.Cairo/SvgVersion.cs b/src/Mono.Cairo/SvgVersion.cs deleted file mode 100644 index 99cee289..00000000 --- a/src/Mono.Cairo/SvgVersion.cs +++ /dev/null @@ -1,41 +0,0 @@ -// -// Mono.Cairo.SvgVersion.cs -// -// Authors: -// John Luke -// -// (C) John Luke, 2006. -// -// 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; - -namespace Cairo { - - [Serializable] - public enum SvgVersion - { - // FIXME: yuck - OnePointOne = 0, - OnePointTwo, - } -} - diff --git a/src/Mono.Cairo/TextExtents.cs b/src/Mono.Cairo/TextExtents.cs deleted file mode 100644 index f9cd560f..00000000 --- a/src/Mono.Cairo/TextExtents.cs +++ /dev/null @@ -1,98 +0,0 @@ -// -// Mono.Cairo.TextExtents.cs -// -// Authors: -// Duncan Mak (duncan@ximian.com) -// Hisham Mardam Bey (hisham.mardambey@gmail.com) -// -// (C) Ximian, Inc. 2003 -// Copyright (C) 2004 Novell, Inc (http://www.novell.com) -// -// 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.Runtime.InteropServices; - -namespace Cairo -{ - [StructLayout (LayoutKind.Sequential)] - public struct TextExtents - { - double xbearing; - double ybearing; - double width; - double height; - double xadvance; - double yadvance; - - public double XBearing { - get { return xbearing; } - set { xbearing = value; } - } - - public double YBearing { - get { return ybearing; } - set { ybearing = value; } - } - - public double Width { - get { return width; } - set { width = value; } - } - - public double Height { - get { return height; } - set { height = value; } - } - - public double XAdvance { - get { return xadvance; } - set { xadvance = value; } - } - - public double YAdvance { - get { return yadvance; } - set { yadvance = value; } - } - - public override bool Equals (object obj) - { - if (obj is TextExtents) - return this == (TextExtents)obj; - return false; - } - - public override int GetHashCode () - { - return (int)XBearing ^ (int)YBearing ^ (int)Width ^ (int)Height ^ (int)XAdvance ^ (int)YAdvance; - } - - public static bool operator == (TextExtents extents, TextExtents other) - { - return extents.XBearing == other.XBearing && extents.YBearing == other.YBearing && extents.Width == other.Width && extents.Height == other.Height && extents.XAdvance == other.XAdvance && extents.YAdvance == other.YAdvance; - } - - public static bool operator != (TextExtents extents, TextExtents other) - { - return !(extents == other); - } - } -} diff --git a/src/Mono.Cairo/WGLDevice.cs b/src/Mono.Cairo/WGLDevice.cs deleted file mode 100644 index 03f7e3a4..00000000 --- a/src/Mono.Cairo/WGLDevice.cs +++ /dev/null @@ -1,45 +0,0 @@ -// -// Mono.Cairo.Device.cs -// -// Authors: -// JP Bruyère (jp_bruyere@hotmail.com) -// -// This is an OO wrapper API for the Cairo API -// -// Copyright (C) 2016 JP 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; - -namespace Cairo -{ - public class WGLDevice : Device - { - public WGLDevice (IntPtr hglrc) : base (NativeMethods.cairo_wgl_device_create (hglrc), true) - { - } - - public IntPtr Context { - get { return NativeMethods.cairo_wgl_device_get_context (Handle); } - } - } -} - diff --git a/src/Mono.Cairo/Win32Surface.cs b/src/Mono.Cairo/Win32Surface.cs deleted file mode 100644 index dd244286..00000000 --- a/src/Mono.Cairo/Win32Surface.cs +++ /dev/null @@ -1,44 +0,0 @@ -// -// Mono.Cairo.Win32Surface.cs -// -// Authors: -// John Luke -// -// (C) John Luke, 2006. -// -// 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; - -namespace Cairo { - - public class Win32Surface : Surface - { - internal Win32Surface (IntPtr handle, bool owns) : base (handle, owns) - { - } - - public Win32Surface (IntPtr hdc) - : base (NativeMethods.cairo_win32_surface_create (hdc), true) - { - } - } -} diff --git a/src/Mono.Cairo/XcbSurface.cs b/src/Mono.Cairo/XcbSurface.cs deleted file mode 100644 index 142ebf9e..00000000 --- a/src/Mono.Cairo/XcbSurface.cs +++ /dev/null @@ -1,54 +0,0 @@ -// -// Mono.Cairo.XcbSurface.cs -// -// Authors: -// Alp Toker -// -// (C) Alp Toker, 2006. -// -// 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; - -namespace Cairo { - public class XcbSurface : Surface - { - internal XcbSurface (IntPtr handle, bool owns) : base (handle, owns) - { - } - - public XcbSurface (IntPtr connection, uint drawable, IntPtr visual, int width, int height) - : base (NativeMethods.cairo_xcb_surface_create (connection, drawable, visual, width, height), true) - { - } - - public static XcbSurface FromBitmap (IntPtr connection, uint bitmap, IntPtr screen, int width, int height) - { - IntPtr ptr = NativeMethods.cairo_xcb_surface_create_for_bitmap (connection, bitmap, screen, width, height); - return new XcbSurface (ptr, true); - } - - public void SetSize (int width, int height) - { - NativeMethods.cairo_xcb_surface_set_size (Handle, width, height); - } - } -} diff --git a/src/Mono.Cairo/XlibSurface.cs b/src/Mono.Cairo/XlibSurface.cs deleted file mode 100644 index c0003a49..00000000 --- a/src/Mono.Cairo/XlibSurface.cs +++ /dev/null @@ -1,95 +0,0 @@ -// -// Mono.Cairo.XlibSurface.cs -// -// Authors: -// Duncan Mak -// Miguel de Icaza. -// -// (C) Ximian Inc, 2003. -// (C) Novell, Inc. 2003. -// -// This is an OO wrapper API for the Cairo API -// -// Copyright (C) 2004 Novell, Inc (http://www.novell.com) -// -// 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; - -namespace Cairo { - - public class XlibSurface : Surface - { - public XlibSurface (IntPtr display, IntPtr drawable, IntPtr visual, int width, int height) - : base (NativeMethods.cairo_xlib_surface_create (display, drawable, visual, width, height), true) - { - } - - public XlibSurface (IntPtr ptr, bool own) : base (ptr, own) - { - } - - public static XlibSurface FromBitmap (IntPtr display, IntPtr bitmap, IntPtr screen, int width, int height) - { - IntPtr ptr = NativeMethods.cairo_xlib_surface_create_for_bitmap (display, bitmap, screen, width, height); - return new XlibSurface(ptr, true); - } - - public void SetDrawable (IntPtr drawable, int width, int height) - { - NativeMethods.cairo_xlib_surface_set_drawable (Handle, drawable, width, height); - } - - public void SetSize (int width, int height) - { - NativeMethods.cairo_xlib_surface_set_size (Handle, width, height); - } - - public int Depth { - get { return NativeMethods.cairo_xlib_surface_get_depth (Handle); } - } - - public IntPtr Display { - get { return NativeMethods.cairo_xlib_surface_get_display (Handle); } - } - - public IntPtr Drawable { - get { return NativeMethods.cairo_xlib_surface_get_drawable (Handle); } - } - - public int Height { - get { return NativeMethods.cairo_xlib_surface_get_height (Handle); } - } - - public IntPtr Screen { - get { return NativeMethods.cairo_xlib_surface_get_screen (Handle); } - } - - public IntPtr Visual { - get { return NativeMethods.cairo_xlib_surface_get_visual (Handle); } - } - - public int Width { - get { return NativeMethods.cairo_xlib_surface_get_width (Handle); } - } - - } -} diff --git a/src/MouseCursorChangedEventArgs.cs b/src/MouseCursorChangedEventArgs.cs deleted file mode 100644 index 9c63c11f..00000000 --- a/src/MouseCursorChangedEventArgs.cs +++ /dev/null @@ -1,39 +0,0 @@ -// -// MouseCursorChangedEventArgs.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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; - -namespace Crow -{ - public class MouseCursorChangedEventArgs : EventArgs - { - public XCursor NewCursor; - public MouseCursorChangedEventArgs (XCursor newCursor) : base() - { - NewCursor = newCursor; - } - } -} diff --git a/src/ObservableList.cs b/src/ObservableList.cs deleted file mode 100644 index 96bfccc9..00000000 --- a/src/ObservableList.cs +++ /dev/null @@ -1,47 +0,0 @@ -// -// IListChanged.cs -// -// Author: -// Jean-Philippe Bruyère <jp_bruyere@hotmail.com> -// -// 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; - -namespace Crow -{ - public class ObservableList<T> : List<T> , IObservableList { - public event EventHandler<ListChangedEventArg> ListAdd; - public event EventHandler<ListChangedEventArg> ListRemove; - - public void AddElement (T elem) { - this.Add(elem); - ListAdd.Raise (this, new ListChangedEventArg (this.Count - 1, elem)); - } - public void RemoveElement (T elem) { - System.Diagnostics.Debug.WriteLine ("remove elem:" + elem); - int idx = this.IndexOf (elem); - this.RemoveAt (idx); - ListRemove.Raise (this, new ListChangedEventArg (idx, elem)); - } - } -} - diff --git a/src/ParsingException.cs b/src/ParsingException.cs deleted file mode 100644 index 1b596981..00000000 --- a/src/ParsingException.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; - -namespace Crow.Coding -{ - public class ParserException : Exception - { - public int Line; - public int Column; - public string Source; - public ParserException(int line, int column, string txt, string source = null) - : base(txt) - { - Line = line; - Column = column; - Source = source; - } - public ParserException(int line, int column, string txt, Exception innerException, string source = null) - : base(txt, innerException) - { - Line = line; - Column = column; - Source = source; - } - public override string ToString () - { - return string.Format("{3}:({0},{1}): {2}", Line, Column, Message, Source); - } - } -} - diff --git a/src/PerformanceMeasure.cs b/src/PerformanceMeasure.cs deleted file mode 100644 index 3c978e8b..00000000 --- a/src/PerformanceMeasure.cs +++ /dev/null @@ -1,95 +0,0 @@ -// -// PerformanceMeasure.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Diagnostics; - -namespace Crow -{ - public class PerformanceMeasure : IValueChange { - #region IValueChange implementation - public event EventHandler<ValueChangeEventArgs> ValueChanged; - public virtual void NotifyValueChanged(string MemberName, object _value) - { - if (ValueChanged != null) - ValueChanged.Invoke(this, new ValueChangeEventArgs(MemberName, _value)); - } - #endregion - - public Stopwatch timer = new Stopwatch (); - public string Name; - public long current, minimum, maximum, total, cptMeasures; - public long cancelLimit; - - public PerformanceMeasure(string name = "unamed", long _cancelLimit = 0){ - Name = name; - cancelLimit = _cancelLimit; - ResetStats (); - } - - public void StartCycle(){ - timer.Restart(); - } - public void StopCycle(){ - timer.Stop(); - computeStats (); - } - public void NotifyChanges(){ - lock(this){ - if (cptMeasures == 0) - return; - NotifyValueChanged("minimum", minimum); - NotifyValueChanged("maximum", maximum); - NotifyValueChanged("current", current); - // NotifyValueChanged("total", total); - // NotifyValueChanged("cptMeasures", cptMeasures); - NotifyValueChanged("mean", total / cptMeasures); - } - } - - void computeStats(){ - current = timer.ElapsedTicks; - if (current < cancelLimit) - return; - cptMeasures++; - total += timer.ElapsedTicks; - if (timer.ElapsedTicks < minimum) - minimum = timer.ElapsedTicks; - if (timer.ElapsedTicks > maximum) - maximum = timer.ElapsedTicks; - } - void ResetStats(){ - Debug.WriteLine("reset measure cpt:{0}",cptMeasures); - cptMeasures = total = current = maximum = 0; - minimum = long.MaxValue; - } - void onResetClick(object sender, MouseButtonEventArgs e){ - lock(this) - ResetStats(); - } - } -} - diff --git a/src/Picture.cs b/src/Picture.cs deleted file mode 100644 index 3784780b..00000000 --- a/src/Picture.cs +++ /dev/null @@ -1,152 +0,0 @@ -// -// Picture.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.IO; -using Cairo; -using System.Collections.Generic; - -namespace Crow -{ - /// <summary> - /// store data and dimensions for resource sharing - /// </summary> - internal class sharedPicture { - //TODO: restructure this whith clever conceptual classes - public object Data; - public Size Dims; - public sharedPicture (object _data, Size _dims){ - Data = _data; - Dims = _dims; - } - } - /// <summary> - /// virtual class for loading and drawing picture in the interface - /// - /// Every loaded resources are stored in a dictonary with their path as key and shared - /// among interface elements - /// </summary> - public abstract class Picture : Fill - { - /// <summary> - /// share a single store for picture resources among usage in different controls - /// </summary> - internal static Dictionary<string, sharedPicture> sharedResources = new Dictionary<string, sharedPicture>(); - - /// <summary> - /// path of the picture - /// </summary> - public string Path; - /// <summary> - /// unscaled dimensions fetched on loading - /// </summary> - public Size Dimensions; - /// <summary> - /// if true and image has to be scalled, it will be scaled in both direction - /// equaly - /// </summary> - public bool KeepProportions = false; - /// <summary> - /// allow or not the picture to be scalled on request by the painter - /// </summary> - public bool Scaled = true; - - #region CTOR - /// <summary> - /// Initializes a new instance of Picture. - /// </summary> - public Picture () - { - } - /// <summary> - /// Initializes a new instance of Picture by loading the image pointed by the path argument - /// </summary> - /// <param name="path">image path, may be embedded</param> - public Picture (string path) - { - Path = path; - } - #endregion - - #region Image Loading - /// <summary> - /// load the image for rendering from the stream given as argument - /// </summary> - /// <param name="stream">picture stream</param> - public abstract void Load(Interface iface, string path); - #endregion - - /// <summary> - /// abstract method to paint the image in the rectangle given in arguments according - /// to the Scale and keepProportion parameters. - /// </summary> - /// <param name="gr">drawing Backend context</param> - /// <param name="rect">bounds of the target surface to paint</param> - /// <param name="subPart">used for svg only</param> - public abstract void Paint(Context ctx, Rectangle rect, string subPart = ""); - - #region Operators - public static implicit operator Picture(string path) - { - if (string.IsNullOrEmpty (path)) - return null; - - Picture _pic = null; - - if (path.EndsWith (".svg", true, System.Globalization.CultureInfo.InvariantCulture)) - _pic = new SvgPicture (path); - else - _pic = new BmpPicture (path); - - return _pic; - } - public static implicit operator string(Picture _pic) - { - return _pic == null ? null : _pic.Path; - } - #endregion - - public static object Parse(string path) - { - if (string.IsNullOrEmpty (path)) - return null; - - Picture _pic = null; - - if (path.EndsWith (".svg", true, System.Globalization.CultureInfo.InvariantCulture)) - _pic = new SvgPicture (path); - else - _pic = new BmpPicture (path); - - return _pic; - } - public override string ToString () - { - return Path; - } - } -} - diff --git a/src/Point.cs b/src/Point.cs deleted file mode 100644 index 6175efc7..00000000 --- a/src/Point.cs +++ /dev/null @@ -1,188 +0,0 @@ -// -// Point.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Linq; -using System.Text; - -namespace Crow -{ - public struct Point - { - int _x; - int _y; - - public int X - { - get { return _x; } - set { _x = value; } - } - public int Y - { - get { return _y; } - set { _y = value; } - } - public Point(int x, int y) - { - _x = x; - _y = y; - } - - public int Length { - get { return (int)Math.Sqrt (Math.Pow (_x, 2) + Math.Pow (_y, 2)); } - } - public double LengthD { - get { return 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); - } - public static implicit operator Cairo.PointD(Point p) - { - return new Cairo.PointD(p.X, p.Y); - } - public static implicit operator System.Drawing.Point(Point p) - { - return new System.Drawing.Point(p.X, p.Y); - } - public static implicit operator Point(System.Drawing.Point p) - { - return new Point(p.X, p.Y); - } - public static implicit operator Point(int i) - { - return new Point(i, i); - } - public static Point operator /(Point p, int d) - { - return new Point(p.X / d, p.Y / d); - } - public static Point operator *(Point p, int d) - { - return new Point(p.X * d, p.Y * d); - } - public static Point operator /(Point p, double d) - { - return new Point((int)(p.X / d), (int)(p.Y / d)); - } - public static Point operator *(Point p, double d) - { - return new Point((int)(p.X * d), (int)(p.Y * d)); - } - public static Point operator +(Point p1, Point p2) - { - return new Point(p1.X + p2.X, p1.Y + p2.Y); - } - public static Point operator +(Point p, int i) - { - return new Point(p.X + i, p.Y + i); - } - public static Point operator -(Point p1, Point p2) - { - return new Point(p1.X - p2.X, p1.Y - p2.Y); - } - public static bool operator >=(Point p1, Point p2) - { - return p1.X >= p2.X && p1.Y >= p2.Y ? true : false; - } - public static bool operator <=(Point p1, Point p2) - { - return p1.X <= p2.X && p1.Y <= p2.Y ? true : false; - } - public static bool operator ==(Point s, int i) - { - if (s.X == i && s.Y == i) - return true; - else - return false; - } - public static bool operator !=(Point s, int i) - { - if (s.X == i && s.Y == i) - return false; - else - return true; - } - public static bool operator >(Point s, int i) - { - if (s.X > i && s.Y > i) - return true; - else - return false; - } - public static bool operator <(Point s, int i) - { - if (s.X < i && s.Y < i) - return true; - else - return false; - } - public static bool operator ==(Point s1, Point s2) - { - if (s1.X == s2.X && s1.Y == s2.Y) - return true; - else - return false; - } - public static bool operator !=(Point s1, Point s2) - { - if (s1.X == s2.X && s1.Y == s2.Y) - return false; - else - return true; - } - - public override string ToString() - { - return string.Format("({0},{1})", X, Y); - } - - public override bool Equals(object obj) - { - return base.Equals(obj); - } - public override int GetHashCode() - { - return base.GetHashCode(); - } - public static Point Parse(string s) - { - if (string.IsNullOrEmpty (s)) - return default(Point); - string[] d = s.Trim().Split(','); - if (d.Length == 2) - return new Point (int.Parse (d [0]), int.Parse (d [1])); - else if (d.Length == 1) { - int tmp = int.Parse (d [0]); - return new Point (tmp, tmp); - } - throw new Exception ("Crow.Point Parsing Error: " + s); - } - } - -} diff --git a/src/Rectangle.cs b/src/Rectangle.cs deleted file mode 100644 index 56e4148f..00000000 --- a/src/Rectangle.cs +++ /dev/null @@ -1,255 +0,0 @@ -// -// Rectangle.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Text; -using System.Xml.Serialization; -using System.Runtime.InteropServices; - -namespace Crow -{ - [StructLayout(LayoutKind.Sequential)] - public struct Rectangle - { - internal static Type TRectangle = typeof(Rectangle); - - public int X; - public int Y; - public int Width; - public int Height; - - #region ctor - public Rectangle(Point p, Size s): this (p.X, p.Y, s.Width, s.Height) - { - } - public Rectangle(Size s) : this (0, 0, s.Width, s.Height) - { - } - public Rectangle(int x, int y, int width, int height) - { - X = x; - Y = y; - Width = width; - Height = height; - } - #endregion - - #region PROPERTIES - [XmlIgnore]public int Left{ - get { return X; } - set { X = value; } - } - [XmlIgnore]public int Top{ - get { return Y; } - set { Y = value; } - } - [XmlIgnore]public int Right{ - get { return X + Width; } - } - [XmlIgnore]public int Bottom{ - get { return Y + Height; } - } - [XmlIgnore]public Size Size{ - get { return new Size(Width, Height); } - set - { - Width = value.Width; - Height = value.Height; - } - } - [XmlIgnore]public Point Position{ - get { return new Point(X, Y); } - set - { - X = value.X; - Y = value.Y; - } - } - [XmlIgnore]public Point TopLeft{ - set - { - X = value.X; - Y = value.Y; - } - get { return new Point(X, Y); } - } - [XmlIgnore]public Point TopRight{ - get { return new Point(Right, Y); } - } - [XmlIgnore]public Point BottomLeft{ - get { return new Point(X, Bottom); } - } - [XmlIgnore]public Point BottomRight{ - get { return new Point(Right, Bottom); } - } - [XmlIgnore]public Point Center - { - get { return new Point(Left + Width / 2, Top + Height / 2); } - } - #endregion - - #region FUNCTIONS - public void Inflate(int xDelta, int yDelta) - { - this.X -= xDelta; - this.Width += 2 * xDelta; - this.Y -= yDelta; - this.Height += 2 * yDelta; - } - public void Inflate(int delta) - { - Inflate (delta, delta); - } - public Rectangle Inflated (int delta) { - return Inflated (delta,delta); - } - public Rectangle Inflated (int deltaX, int deltaY) { - Rectangle r = this; - r.Inflate (deltaX, deltaY); - return r; - } - public bool ContainsOrIsEqual(Point p) - { - return (p.X >= X && p.X <= X + Width && p.Y >= Y && p.Y <= Y + Height) ? - true : false; - } - public bool ContainsOrIsEqual(Rectangle r) - { - return r.TopLeft >= this.TopLeft && r.BottomRight <= this.BottomRight ? true : false; - } - public bool Intersect(Rectangle r) - { - int maxLeft = Math.Max(this.Left, r.Left); - int minRight = Math.Min(this.Right, r.Right); - int maxTop = Math.Max(this.Top, r.Top); - int minBottom = Math.Min(this.Bottom, r.Bottom); - - return (maxLeft < minRight) && (maxTop < minBottom) ? - true : false; - } - public Rectangle Intersection(Rectangle r) - { - Rectangle result = new Rectangle(); - - if (r.Left >= this.Left) - result.Left = r.Left; - else - result.TopLeft = this.TopLeft; - - if (r.Right >= this.Right) - result.Width = this.Right - result.Left; - else - result.Width = r.Right - result.Left; - - if (r.Top >= this.Top) - result.Top = r.Top; - else - result.Top = this.Top; - - if (r.Bottom >= this.Bottom) - result.Height = this.Bottom - result.Top; - else - result.Height = r.Bottom - result.Top; - - return result; - } - #endregion - - #region operators - public static implicit operator Rectangle(System.Drawing.Rectangle r) - { - return new Rectangle(r.X, r.Y, r.Width, r.Height); - } - public static implicit operator System.Drawing.Rectangle(Rectangle r) - { - return new System.Drawing.Rectangle(r.X, r.Y, r.Width, r.Height); - } - public static Rectangle operator +(Rectangle r1, Rectangle r2) - { - int x = Math.Min(r1.X, r2.X); - int y = Math.Min(r1.Y, r2.Y); - int x2 = Math.Max(r1.Right, r2.Right); - int y2 = Math.Max(r1.Bottom, r2.Bottom); - return new Rectangle(x, y, x2 - x, y2 - y); - } - public static Rectangle operator +(Rectangle r, Point p) - { - return new Rectangle(r.X + p.X, r.Y + p.Y, r.Width, r.Height); - } - public static Rectangle operator -(Rectangle r, Point p) - { - return new Rectangle(r.X - p.X, r.Y - p.Y, r.Width, r.Height); - } - public static bool operator ==(Rectangle r1, Rectangle r2) - { - return r1.TopLeft == r2.TopLeft && r1.Size == r2.Size ? true : false; - } - public static bool operator !=(Rectangle r1, Rectangle r2) - { - return r1.TopLeft == r2.TopLeft && r1.Size == r2.Size ? false : true; - } - #endregion - - public static readonly Rectangle Zero = new Rectangle(0, 0, 0, 0); - public static Rectangle Empty - { - get { return Zero; } - } - public override string ToString() - { - return string.Format("{0},{1},{2},{3}", X, Y, Width, Height); - } - public static Rectangle Parse(string s) - { - string[] d = s.Split(new char[] { ',' }); - return new Rectangle( - int.Parse(d[0]), - int.Parse(d[1]), - int.Parse(d[2]), - int.Parse(d[3])); - } - public override int GetHashCode () - { - unchecked // Overflow is fine, just wrap - { - int hash = 17; - // Suitable nullity checks etc, of course :) - hash = hash * 23 + X.GetHashCode(); - hash = hash * 23 + Y.GetHashCode(); - hash = hash * 23 + Width.GetHashCode(); - hash = hash * 23 + Height.GetHashCode(); - return hash; - } - } - public override bool Equals (object obj) - { - return (obj == null || obj.GetType() != TRectangle) ? - false : - this == (Rectangle)obj; - } - } -} diff --git a/src/ReflexionExtensions.cs b/src/ReflexionExtensions.cs deleted file mode 100644 index 8c0b4f27..00000000 --- a/src/ReflexionExtensions.cs +++ /dev/null @@ -1,62 +0,0 @@ -// -// ReflexionExtensions.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Reflection; - -namespace Crow -{ - 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"; - } - } -} - diff --git a/src/ScrollingEventArgs.cs b/src/ScrollingEventArgs.cs deleted file mode 100644 index 3ff42065..00000000 --- a/src/ScrollingEventArgs.cs +++ /dev/null @@ -1,41 +0,0 @@ -// -// ScrollingEventArgs.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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; - -namespace Crow -{ - public class ScrollingEventArgs: EventArgs - { - public Orientation Direction; - - public ScrollingEventArgs (Orientation _direction) : base() - { - Direction = _direction; - } - } -} - diff --git a/src/SelectionChangeEventArgs.cs b/src/SelectionChangeEventArgs.cs deleted file mode 100644 index 988a6975..00000000 --- a/src/SelectionChangeEventArgs.cs +++ /dev/null @@ -1,42 +0,0 @@ -// -// SelectionChangeEventArgs.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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; - -namespace Crow -{ - public class SelectionChangeEventArgs: EventArgs - { - public object NewValue; - - - public SelectionChangeEventArgs (object _newValue) : base() - { - NewValue = _newValue; - } - } -} - diff --git a/src/Size.cs b/src/Size.cs deleted file mode 100644 index 891c1fb5..00000000 --- a/src/Size.cs +++ /dev/null @@ -1,206 +0,0 @@ -// -// Size.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Linq; -using System.Text; - -namespace Crow -{ - public struct Size - { - internal static Type TSize = typeof(Size); - public static Size Zero - { get { return new Size(0, 0); } } - - int _width; - int _height; - - public Size(int width, int height) - { - _width = width; - _height = height; - } - public Size(int size) - { - _width = size; - _height = size; - } - public int Width - { - get { return _width; } - set { _width = value; } - } - public int Height - { - get { return _height; } - set { _height = value; } - } - - #region operators - public static implicit operator Rectangle(Size s) - { - return new Rectangle (s); - } - public static implicit operator Size(int i) - { - return new Size(i, i); - } - public static implicit operator string(Size s) - { - return s.ToString (); - } - public static implicit operator Size(string s) - { - return string.IsNullOrEmpty (s) ? Size.Zero : Parse (s); - } - public static bool operator ==(Size s1, Size s2) - { - if (s1.Width == s2.Width && s1.Height == s2.Height) - return true; - else - return false; - } - public static bool operator !=(Size s1, Size s2) - { - if (s1.Width == s2.Width && s1.Height == s2.Height) - return false; - else - return true; - } - public static bool operator >(Size s1, Size s2) - { - if (s1.Width > s2.Width && s1.Height > s2.Height) - return true; - else - return false; - } - public static bool operator >=(Size s1, Size s2) - { - if (s1.Width >= s2.Width && s1.Height >= s2.Height) - return true; - else - return false; - } - public static bool operator <(Size s1, Size s2) - { - if (s1.Width < s2.Width) - if (s1.Height <= s2.Height) - return true; - else - return false; - else if (s1.Width == s2.Width && s1.Height < s2.Height) - return true; - - return false; - } - public static bool operator <(Size s, int i) - { - return s.Width < i && s.Height < i ? true : false; - } - public static bool operator <=(Size s, int i) - { - return s.Width <= i && s.Height <= i ? true : false; - } - public static bool operator >(Size s, int i) - { - return s.Width > i && s.Height > i ? true : false; - } - public static bool operator >=(Size s, int i) - { - return s.Width >= i && s.Height >= i ? true : false; - } - public static bool operator <=(Size s1, Size s2) - { - if (s1.Width <= s2.Width && s1.Height <= s2.Height) - return true; - else - return false; - } - public static bool operator ==(Size s, int i) - { - if (s.Width == i && s.Height == i) - return true; - else - return false; - } - public static bool operator !=(Size s, int i) - { - if (s.Width == i && s.Height == i) - return false; - else - return true; - } - public static Size operator +(Size s1, Size s2) - { - return new Size(s1.Width + s2.Width, s1.Height + s2.Height); - } - public static Size operator +(Size s, int i) - { - return new Size(s.Width + i, s.Height + i); - } - public static Size operator *(Size s, int i) - { - return new Size(s.Width * i, s.Height * i); - } - public static Size operator /(Size s, int i) - { - return new Size(s.Width / i, s.Height / i); - } - #endregion - - public override int GetHashCode () - { - unchecked // Overflow is fine, just wrap - { - int hash = 17; - // Suitable nullity checks etc, of course :) - hash = hash * 23 + _width.GetHashCode(); - hash = hash * 23 + _height.GetHashCode(); - return hash; - } - } - public override bool Equals (object obj) - { - return (obj == null || obj.GetType() != TSize) ? - false : - this == (Size)obj; - } - public override string ToString() - { - return string.Format("{0},{1}", Width, Height); - } - public static Size Parse(string s) - { - string[] d = s.Split(new char[] { ',' }); - return d.Length == 1 ? new Size(int.Parse(d[0])) : new Size( - int.Parse(d[0]), - int.Parse(d[1])); - } - } - -} diff --git a/src/SolidColor.cs b/src/SolidColor.cs deleted file mode 100644 index d6423d31..00000000 --- a/src/SolidColor.cs +++ /dev/null @@ -1,129 +0,0 @@ -// -// SolidColor.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.Linq; -using System.Text; -using System.Xml.Serialization; -using System.Reflection; -using System.Diagnostics; -using Cairo; - - - -namespace Crow -{ - public class SolidColor : Fill - { - public Color color = Color.Transparent; - #region CTOR - public SolidColor(Color c) - { - color = c; - } - #endregion - - #region implemented abstract members of Fill - - public override void SetAsSource (Context ctx, Rectangle bounds = default(Rectangle)) - { - ctx.SetSourceRGBA (color.R, color.G, color.B, color.A); - } - public static object Parse(string s) - { - return new SolidColor((Color)s); - } - #endregion - - #region Operators - public static implicit operator Color(SolidColor c) - { - return c.color; - } - public static implicit operator SolidColor(Color c) - { - return new SolidColor (c); - } - public static bool operator ==(SolidColor left, SolidColor right) - { - return left is SolidColor ? right is SolidColor ? true : false : - left.color == right.color ? true : false; - } - public static bool operator !=(SolidColor left, SolidColor right) - { - return left is SolidColor ? right is SolidColor ? false : true : - left.color == right.color ? false : true; - - } - public override int GetHashCode () - { - return color.GetHashCode(); - } - public override bool Equals (object obj) - { - if (obj is Crow.Color) - return color == (Color)obj; - if (obj is SolidColor) - return color == (obj as SolidColor).color; - return false; - } -// public static bool operator ==(SolidColor c, string n) -// { -// return c.color.Name == n ? true : false; -// } -// public static bool operator !=(SolidColor c, string n) -// { -// return c.color.Name == n ? false : true; -// } -// public static bool operator ==(string n, SolidColor c) -// { -// return c.color.Name == n ? true : false; -// } -// public static bool operator !=(string n, SolidColor c) -// { -// return c.color.Name == n ? false : true; -// } - public static SolidColor operator *(SolidColor c, Double f) - { - return new SolidColor(new Color(c.color.R,c.color.G,c.color.B,c.color.A * f)); - } - public static SolidColor operator +(SolidColor c1, SolidColor c2) - { - return new SolidColor(new Color(c1.color.R + c2.color.R,c1.color.G + c2.color.G,c1.color.B + c2.color.B,c1.color.A + c2.color.A)); - } - public static SolidColor operator -(SolidColor c1, SolidColor c2) - { - return new SolidColor(new Color(c1.color.R - c2.color.R,c1.color.G - c2.color.G,c1.color.B - c2.color.B,c1.color.A - c2.color.A)); - } - #endregion - - public override string ToString() - { - return color.ToString (); - } - } -} diff --git a/src/Style.cs b/src/Style.cs deleted file mode 100644 index 58f09f33..00000000 --- a/src/Style.cs +++ /dev/null @@ -1,59 +0,0 @@ -// -// Style.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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; - -namespace Crow -{ - public struct FileLocation { - public string FilePath; - public int Line; - public int Column; - - public FileLocation(string filePath, int line, int column){ - FilePath = filePath; - Line = line; - Column = column; - } - public override string ToString () - { - return string.Format ("{0} ({1},{2})", FilePath, Line, Column); - } - } - public class Style : Dictionary<string, object> - { - #if DESIGN_MODE - public Dictionary<string, FileLocation> Locations = new Dictionary<string, FileLocation>(); - #endif - //public Dictionary<string, Style> SubStyles;//TODO:implement substyles for all tags inside a style - public Style () : base() - { - } - - } -} - diff --git a/src/StyleReader.cs b/src/StyleReader.cs deleted file mode 100644 index 458b7856..00000000 --- a/src/StyleReader.cs +++ /dev/null @@ -1,200 +0,0 @@ -// -// StyleReader.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.IO; -using System.Reflection; -using System.Text.RegularExpressions; -using Crow.Coding; - -namespace Crow -{ - /// <summary> - /// Parser for style files. - /// </summary> - //TODO: style key shared by different class may use only first encouneter class setter, which can cause bug. - public class StyleReader : StreamReader - { - enum States { init, classNames, members, value, endOfStatement } - - States curState = States.init; - - int column = 1; - int line = 1; - - #region Character ValidityCheck - static Regex rxValidChar = new Regex(@"\p{Lu}|\p{Ll}|\p{Lt}|\p{Lm}|\p{Lo}|\p{Nl}|\p{Mn}|\p{Mc}|\p{Nd}|\p{Pc}|\p{Cf}"); - static Regex rxNameStartChar = new Regex(@"_|\p{Lu}|\p{Ll}|\p{Lt}|\p{Lm}|\p{Lo}"); - static Regex rxNameChar = new Regex(@"\p{Lu}|\p{Ll}|\p{Lt}|\p{Lm}|\p{Lo}|\p{Nl}|\p{Mn}|\p{Mc}|\p{Nd}|\p{Pc}|\p{Cf}"); - static Regex rxDecimal = new Regex(@"[0-9]+"); - static Regex rxHexadecimal = new Regex(@"[0-9a-fA-F]+"); - - public bool nextCharIsValidCharStartName - { - get { return rxNameStartChar.IsMatch(new string(new char[]{PeekChar()})); } - } - public bool nextCharIsValidCharName - { - get { return rxNameChar.IsMatch(new string(new char[]{PeekChar()})); } - } - #endregion - - char ReadChar () { - column++; - return (Char)Read(); - } - char PeekChar () { - return (Char)Peek(); - } - void SkipWhiteSpaceAndLineBreak (){ - while (!EndOfStream){ - if (!PeekChar ().IsWhiteSpaceOrNewLine ()) - break; - if (ReadChar () == '\n') { - line++; - column = 0; - } - } - } - - public StyleReader (Dictionary<string, Style> styling, Stream stream, string resId) - : base(stream) - { - string styleKey = resId.Substring (0, resId.Length - 6); - string token = ""; - List<string> targetsClasses = new List<string> (); - string currentProperty = ""; - - while (!EndOfStream) { - SkipWhiteSpaceAndLineBreak (); - if (EndOfStream) - break; - - switch (Peek()) { - case '/': - ReadChar (); - if (PeekChar () != '/') - throw new ParserException (line, column, "Unexpected char '/'", resId); - ReadLine (); - break; - case ',': - ReadChar (); - if (!(curState == States.init || curState == States.classNames) || string.IsNullOrEmpty (token)) - throw new ParserException (line, column, "Unexpected char ','", resId); - targetsClasses.Add (token); - token = ""; - curState = States.classNames; - break; - case '{': - ReadChar (); - if (!(curState == States.init || curState == States.classNames) || string.IsNullOrEmpty (token)) - throw new ParserException (line, column, "Unexpected char '{'", resId); - targetsClasses.Add (token); - token = ""; - curState = States.members; - break; - case '}': - ReadChar (); - if (curState != States.members) - throw new ParserException (line, column, "Unexpected char '}'", resId); - curState = States.classNames; - targetsClasses.Clear (); - break; - case '=': - ReadChar (); - if (!(curState == States.init || curState == States.members)) - throw new ParserException (line, column, "Unexpected char '='", resId); - currentProperty = token; - token = ""; - curState = States.value; - break; - case '"': - if (curState != States.value) - throw new ParserException (line, column, "Unexpected char '\"'", resId); - ReadChar (); - - while (!EndOfStream) { - char c = PeekChar(); - if (c == '\"') { - ReadChar (); - break; - } - token += ReadChar(); - if (c == '\\' && !EndOfStream) - token += ReadChar(); - } - curState = States.endOfStatement; - break; - case ';': - if (curState != States.endOfStatement) - throw new ParserException (line, column, "Unexpected end of statement", resId); - ReadChar (); - foreach (string tc in targetsClasses) { - if (!styling.ContainsKey (tc)) - styling [tc] = new Style (); - else if (styling [tc].ContainsKey (currentProperty)) - continue; - styling [tc] [currentProperty] = token; - #if DESIGN_MODE - styling [tc].Locations[currentProperty] = new FileLocation(resId, line,column); - #endif - //System.Diagnostics.Debug.WriteLine ("Style: {3} : {0}.{1} = {2}", tc, currentProperty, token, resId); - } - token = ""; - curState = States.members; - break; - default: - if (curState == States.value) - throw new ParserException (line, column, "expecting value enclosed in '\"'", resId); - if (curState == States.endOfStatement) - throw new ParserException (line, column, "expecting end of statement", resId); - - if (nextCharIsValidCharStartName) { - token += ReadChar(); - while (nextCharIsValidCharName) - token += ReadChar(); - } - break; - } - } - } - -// public override int Read () -// { -// int tmp = base.Read (); -// char c = (char)tmp; -// if (c == '\n') { -// line++; -// column = 1; -// } else if (c == '\t') -// column += Interface.TabSize; -// else if (c != '\r') -// column++; -// return tmp; -// } - } -} diff --git a/src/SvgPicture.cs b/src/SvgPicture.cs deleted file mode 100644 index f676a497..00000000 --- a/src/SvgPicture.cs +++ /dev/null @@ -1,151 +0,0 @@ -// -// SvgPicture.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.IO; -using Cairo; - -namespace Crow -{ - /// <summary> - /// Derived from FILL for loading and drawing SVG images in the interface - /// </summary> - public class SvgPicture : Picture - { - Rsvg.Handle hSVG; - - #region CTOR - /// <summary> - /// Initializes a new instance of SvgPicture. - /// </summary> - public SvgPicture () - {} - /// <summary> - /// Initializes a new instance of SvgPicture by loading the SVG file pointed by the path argument - /// </summary> - /// <param name="path">image path, may be embedded</param> - public SvgPicture (string path) : base(path) - {} - #endregion - - public override void Load (Interface iface, string path) - { - Path = path; - if (sharedResources.ContainsKey (path)) { - sharedPicture sp = sharedResources [path]; - hSVG = (Rsvg.Handle)sp.Data; - Dimensions = sp.Dims; - return; - } - using (Stream stream = iface.GetStreamFromPath (path)) { - using (MemoryStream ms = new MemoryStream ()) { - stream.CopyTo (ms); - - hSVG = new Rsvg.Handle (ms.ToArray ()); - Dimensions = new Size (hSVG.Dimensions.Width, hSVG.Dimensions.Height); - } - } - sharedResources [path] = new sharedPicture (hSVG, Dimensions); - } - - public void LoadSvgFragment (string fragment) { - hSVG = new Rsvg.Handle (System.Text.Encoding.Unicode.GetBytes(fragment)); - Dimensions = new Size (hSVG.Dimensions.Width, hSVG.Dimensions.Height); - } - - #region implemented abstract members of Fill - - public override void SetAsSource (Context ctx, Rectangle bounds = default(Rectangle)) - { - float widthRatio = 1f; - float heightRatio = 1f; - - if (Scaled){ - widthRatio = (float)bounds.Width / Dimensions.Width; - heightRatio = (float)bounds.Height / Dimensions.Height; - } - - if (KeepProportions) { - if (widthRatio < heightRatio) - heightRatio = widthRatio; - else - widthRatio = heightRatio; - } - - using (ImageSurface tmp = new ImageSurface (Format.Argb32, bounds.Width, bounds.Height)) { - using (Context gr = new Context (tmp)) { - gr.Translate (bounds.Left, bounds.Top); - gr.Scale (widthRatio, heightRatio); - gr.Translate ((bounds.Width/widthRatio - Dimensions.Width)/2, (bounds.Height/heightRatio - Dimensions.Height)/2); - - hSVG.RenderCairo (gr); - } - ctx.SetSource (tmp); - } - } - #endregion - - /// <summary> - /// paint the image in the rectangle given in arguments according - /// to the Scale and keepProportion parameters. - /// </summary> - /// <param name="gr">drawing Backend context</param> - /// <param name="rect">bounds of the target surface to paint</param> - /// <param name="subPart">limit rendering to svg part named 'subPart'</param> - public override void Paint (Context gr, Rectangle rect, string subPart = "") - { - if (hSVG == null) - return; - float widthRatio = 1f; - float heightRatio = 1f; - - if (Scaled) { - widthRatio = (float)rect.Width / Dimensions.Width; - heightRatio = (float)rect.Height / Dimensions.Height; - } - if (KeepProportions) { - if (widthRatio < heightRatio) - heightRatio = widthRatio; - else - widthRatio = heightRatio; - } - - gr.Save (); - - gr.Translate (rect.Left,rect.Top); - gr.Scale (widthRatio, heightRatio); - gr.Translate (((float)rect.Width/widthRatio - Dimensions.Width)/2f, ((float)rect.Height/heightRatio - Dimensions.Height)/2f); - - if (string.IsNullOrEmpty (subPart)) - hSVG.RenderCairo (gr); - else - hSVG.RenderCairoSub (gr, "#" + subPart); - - gr.Restore (); - } - } -} - diff --git a/src/TextChangeEventArgs.cs b/src/TextChangeEventArgs.cs deleted file mode 100644 index 33ca405c..00000000 --- a/src/TextChangeEventArgs.cs +++ /dev/null @@ -1,41 +0,0 @@ -// -// TextChangeEventArgs.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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; - -namespace Crow -{ - public class TextChangeEventArgs: EventArgs - { - public String Text; - - public TextChangeEventArgs (string _newValue) : base() - { - Text = _newValue; - } - } -} - diff --git a/src/ValueChangeEventArgs.cs b/src/ValueChangeEventArgs.cs deleted file mode 100644 index e8293de8..00000000 --- a/src/ValueChangeEventArgs.cs +++ /dev/null @@ -1,44 +0,0 @@ -// -// ValueChangeEventArgs.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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; - -namespace Crow -{ - public class ValueChangeEventArgs: EventArgs - { - public string MemberName; - public object NewValue; - - - public ValueChangeEventArgs (string _memberName, object _newValue) : base() - { - MemberName = _memberName; - NewValue = _newValue; - } - } -} - diff --git a/src/XCursor.cs b/src/XCursor.cs deleted file mode 100644 index 1cca510e..00000000 --- a/src/XCursor.cs +++ /dev/null @@ -1,151 +0,0 @@ -// -// XCursor.cs -// -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// 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.IO; -using System.Diagnostics; -using System.Collections.Generic; - -namespace Crow -{ - public class XCursorFile - { - const uint XC_TYPE_IMG = 0xfffd0002; - - class toc - { - public uint type; - public uint subtype; - public uint pos; - - public toc(BinaryReader sr) - { - type = sr.ReadUInt32(); - subtype = sr.ReadUInt32(); - pos = sr.ReadUInt32(); - } - } - - public List<XCursor> Cursors = new List<XCursor>(); - - - static XCursorFile loadFromStream(Stream s) - { - List<toc> tocList = new List<toc> (); - XCursorFile tmp = new XCursorFile (); - - using (BinaryReader sr = new BinaryReader (s)) { - byte[] data; - //magic: CARD32 ’Xcur’ (0x58, 0x63, 0x75, 0x72) - if (new string (sr.ReadChars (4)) != "Xcur") { - Debug.WriteLine ("XCursor Load error: Wrong magic"); - return null; - } - //header: CARD32 bytes in this header - uint headerLength = sr.ReadUInt32 (); - //version: CARD32 file version number - uint version = sr.ReadUInt32 (); - //ntoc: CARD32 number of toc entries - uint nbToc = sr.ReadUInt32 (); - //toc: LISTofTOC table of contents - for (uint i = 0; i < nbToc; i++) { - tocList.Add (new toc (sr)); - } - - foreach (toc t in tocList) { - if (t.type != XC_TYPE_IMG) - continue; - - sr.BaseStream.Seek (t.pos, SeekOrigin.Begin); - tmp.Cursors.Add(imageLoad (sr)); - } - } - return tmp; - } - - public static XCursorFile Load(Interface iface, string path) - { - return loadFromStream (iface.GetStreamFromPath (path)); - } - - static XCursor imageLoad(BinaryReader sr) - { - XCursor tmp = new XCursor(); - // header: 36 Image headers are 36 bytes - uint header = sr.ReadUInt32(); - // type: 0xfffd0002 Image type is 0xfffd0002 - uint type = sr.ReadUInt32(); - // subtype: CARD32 Image subtype is the nominal size - uint subtype = sr.ReadUInt32(); - // version: 1 - uint version = sr.ReadUInt32(); - // width: CARD32 Must be less than or equal to 0x7fff - tmp.Width = sr.ReadUInt32(); - // height: CARD32 Must be less than or equal to 0x7fff - tmp.Height = sr.ReadUInt32(); - // xhot: CARD32 Must be less than or equal to width - tmp.Xhot = sr.ReadUInt32(); - // yhot: CARD32 Must be less than or equal to height - tmp.Yhot = sr.ReadUInt32(); - // delay: CARD32 Delay between animation frames in milliseconds - tmp.Delay = sr.ReadUInt32(); - // pixels: LISTofCARD32 Packed ARGB format pixels - tmp.data = sr.ReadBytes((int)(tmp.Width * tmp.Height * 4)); - return tmp; - } - } - public class XCursor - { - public static XCursor Default; - public static XCursor Cross; - public static XCursor Arrow; - public static XCursor Text; - public static XCursor SW; - public static XCursor SE; - public static XCursor NW; - public static XCursor NE; - public static XCursor N; - public static XCursor S; - public static XCursor V; - public static XCursor H; - - public uint Width; - public uint Height; - public uint Xhot; - public uint Yhot; - public uint Delay; - public byte[] data; - - public XCursor () - { - } -// public static implicit operator MouseCursor(XCursor xc) -// { -// return new MouseCursor((int)xc.Xhot, (int)xc.Yhot, (int)xc.Width, (int)xc.Height,xc.data); -// } - } -} - diff --git a/src/rsvg/DimensionData.cs b/src/rsvg/DimensionData.cs deleted file mode 100644 index 66aab91c..00000000 --- a/src/rsvg/DimensionData.cs +++ /dev/null @@ -1,24 +0,0 @@ -//Copyright GPL2 -namespace Rsvg { - - using System; - using System.Collections; - using System.Runtime.InteropServices; - - [StructLayout(LayoutKind.Sequential)] - public struct DimensionData { - - public int Width; - public int Height; - public double Em; - public double Ex; - - public static Rsvg.DimensionData Zero = new Rsvg.DimensionData (); - - public static Rsvg.DimensionData New(IntPtr raw) { - if (raw == IntPtr.Zero) - return Rsvg.DimensionData.Zero; - return (Rsvg.DimensionData) Marshal.PtrToStructure (raw, typeof (Rsvg.DimensionData)); - } - } -} diff --git a/src/rsvg/Global.cs b/src/rsvg/Global.cs deleted file mode 100644 index 65917012..00000000 --- a/src/rsvg/Global.cs +++ /dev/null @@ -1,41 +0,0 @@ -// This file was generated by the Gtk# code generator. -// Any changes made will be lost if regenerated. - -namespace Rsvg { - - using System; - using System.Runtime.InteropServices; - -#region Autogenerated code - public class Global { - - [DllImport("rsvg-2")] - static extern void rsvg_set_default_dpi_x_y(double dpi_x, double dpi_y); - - public static void SetDefaultDpiXY(double dpi_x, double dpi_y) { - rsvg_set_default_dpi_x_y(dpi_x, dpi_y); - } - - [DllImport("rsvg-2")] - static extern int rsvg_error_quark(); - - public static int ErrorQuark { - get { - int raw_ret = rsvg_error_quark(); - int ret = raw_ret; - return ret; - } - } - - [DllImport("rsvg-2")] - static extern void rsvg_set_default_dpi(double dpi); - - public static double DefaultDpi { - set { - rsvg_set_default_dpi(value); - } - } - -#endregion - } -} diff --git a/src/rsvg/Handle.cs b/src/rsvg/Handle.cs deleted file mode 100644 index e13f79ad..00000000 --- a/src/rsvg/Handle.cs +++ /dev/null @@ -1,125 +0,0 @@ -//Copyright GPL2 -using Cairo; - - -namespace Rsvg { - - using System; - using System.Collections; - using System.Runtime.InteropServices; - - public class Handle { - - public IntPtr Raw; - - [DllImport("rsvg-2")] - static extern IntPtr rsvg_handle_new(); - - public Handle () - { - Raw = rsvg_handle_new(); - } - - [DllImport("rsvg-2")] - static extern unsafe IntPtr rsvg_handle_new_from_data(byte[] data, UIntPtr n_data, out IntPtr error); - - public unsafe Handle (byte[] data) - { - if (GetType () != typeof (Handle)) { - throw new InvalidOperationException ("Can't override this constructor."); - } - IntPtr error = IntPtr.Zero; - Raw = rsvg_handle_new_from_data(data, new UIntPtr ((ulong) (data == null ? 0 : data.Length)), out error); - if (error != IntPtr.Zero) throw new Exception (error.ToString()); - } - - [DllImport("rsvg-2")] - static extern unsafe IntPtr rsvg_handle_new_from_file(string file_name, out IntPtr error); - - public unsafe Handle (string file_name) - { - IntPtr error = IntPtr.Zero; - Raw = rsvg_handle_new_from_file(file_name, out error); - if (error != IntPtr.Zero) throw new Exception (error.ToString()); - } - - [DllImport("rsvg-2")] - static extern IntPtr rsvg_handle_get_base_uri(IntPtr raw); - - [DllImport("rsvg-2")] - static extern void rsvg_handle_set_dpi(IntPtr raw, double dpi); - - public double Dpi { - set { - rsvg_handle_set_dpi(Raw, value); - } - } - - [DllImport("rsvg-2")] - static extern void rsvg_handle_render_cairo(IntPtr raw, IntPtr cr); - - public void RenderCairo(Context cr) { - unsafe{ - rsvg_handle_render_cairo (Raw, cr == null ? IntPtr.Zero : cr.Handle); - } - } - - [DllImport("rsvg-2")] - static extern void rsvg_handle_set_dpi_x_y(IntPtr raw, double dpi_x, double dpi_y); - - public void SetDpiXY(double dpi_x, double dpi_y) { - rsvg_handle_set_dpi_x_y(Raw, dpi_x, dpi_y); - } - - [DllImport("rsvg-2")] - static extern void rsvg_handle_get_dimensions(IntPtr raw, IntPtr dimension_data); - - public Rsvg.DimensionData Dimensions { - get { - Rsvg.DimensionData dimension_data; - IntPtr native_dimension_data = Marshal.AllocHGlobal (Marshal.SizeOf (typeof (Rsvg.DimensionData))); - rsvg_handle_get_dimensions(Raw, native_dimension_data); - dimension_data = Rsvg.DimensionData.New (native_dimension_data); - Marshal.FreeHGlobal (native_dimension_data); - return dimension_data; - } - } - - [DllImport("rsvg-2")] - static extern unsafe bool rsvg_handle_close(IntPtr raw, out IntPtr error); - - public unsafe bool Close() { - IntPtr error = IntPtr.Zero; - bool raw_ret = rsvg_handle_close(Raw, out error); - if (error != IntPtr.Zero) throw new Exception (error.ToString()); - return raw_ret; - } - - [DllImport("rsvg-2")] - static extern IntPtr rsvg_handle_get_title(IntPtr raw); - - public string Title { - get { - IntPtr raw_ret = rsvg_handle_get_title(Raw); - return "not supported"; - } - } - - [DllImport("rsvg-2")] - static extern void rsvg_handle_render_cairo_sub(IntPtr raw, IntPtr cr, string id); - - public void RenderCairoSub(Cairo.Context cr, string id) { - rsvg_handle_render_cairo_sub(Raw, cr == null ? IntPtr.Zero : cr.Handle, id); - } - - [DllImport("rsvg-2")] - static extern IntPtr rsvg_handle_get_metadata(IntPtr raw); - - public string Metadata { - get { - IntPtr raw_ret = rsvg_handle_get_metadata(Raw); - return "not supported"; - } - } - } -} diff --git a/src/win32/Win32.cs b/src/win32/Win32.cs deleted file mode 100644 index 3249fcee..00000000 --- a/src/win32/Win32.cs +++ /dev/null @@ -1,62 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Runtime.InteropServices; -using System.Diagnostics; - -namespace Crow -{ - public static class Win32 - { - [DllImport("user32.dll")] - public static extern IntPtr GetDC(IntPtr hWnd); - #region mouse winApi - - [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] - public struct Point - { - - /// LONG->int - public int x; - - /// LONG->int - public int y; - } - [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] - public struct HICON__ - { - - /// int - public int unused; - } - -#if _WIN32 || _WIN64 - /// Return Type: HCURSOR->HICON->HICON__* - ///hCursor: HCURSOR->HICON->HICON__* - [System.Runtime.InteropServices.DllImportAttribute("user32.dll", EntryPoint = "SetCursor")] - public static extern System.IntPtr SetCursor([System.Runtime.InteropServices.InAttribute()] System.IntPtr hCursor); -#elif __linux__ - public static System.IntPtr SetCursor(System.IntPtr hCursor) - { - - return (IntPtr)0; - } -#endif - - /// Return Type: BOOL->int - ///lpPoint: LPPOINT->tagPOINT* - [System.Runtime.InteropServices.DllImportAttribute("user32.dll", EntryPoint = "GetCursorPos")] - [return: System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)] - public static extern bool GetCursorPos([System.Runtime.InteropServices.OutAttribute()] out Point lpPoint); - - /// Return Type: BOOL->int - ///X: int - ///Y: int - [System.Runtime.InteropServices.DllImportAttribute("user32.dll", EntryPoint = "SetCursorPos")] - [return: System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)] - public static extern bool SetCursorPos(int X, int Y); - - #endregion - } -} diff --git a/src/win32/winApi.cs b/src/win32/winApi.cs deleted file mode 100755 index 7ed9f90f..00000000 --- a/src/win32/winApi.cs +++ /dev/null @@ -1,1238 +0,0 @@ - /// <summary> - /// Windows Messages - /// Defined in winuser.h from Windows SDK v6.1 - /// Documentation pulled from MSDN. - /// </summary> -using System; - -public enum WM : uint - { - /// <summary> - /// The WM_NULL message performs no operation. An application sends the WM_NULL message if it wants to post a message that the recipient window will ignore. - /// </summary> - NULL = 0x0000, - /// <summary> - /// The WM_CREATE message is sent when an application requests that a window be created by calling the CreateWindowEx or CreateWindow function. (The message is sent before the function returns.) The window procedure of the new window receives this message after the window is created, but before the window becomes visible. - /// </summary> - CREATE = 0x0001, - /// <summary> - /// The WM_DESTROY message is sent when a window is being destroyed. It is sent to the window procedure of the window being destroyed after the window is removed from the screen. - /// This message is sent first to the window being destroyed and then to the child windows (if any) as they are destroyed. During the processing of the message, it can be assumed that all child windows still exist. - /// /// </summary> - DESTROY = 0x0002, - /// <summary> - /// The WM_MOVE message is sent after a window has been moved. - /// </summary> - MOVE = 0x0003, - /// <summary> - /// The WM_SIZE message is sent to a window after its size has changed. - /// </summary> - SIZE = 0x0005, - /// <summary> - /// The WM_ACTIVATE message is sent to both the window being activated and the window being deactivated. If the windows use the same input queue, the message is sent synchronously, first to the window procedure of the top-level window being deactivated, then to the window procedure of the top-level window being activated. If the windows use different input queues, the message is sent asynchronously, so the window is activated immediately. - /// </summary> - ACTIVATE = 0x0006, - /// <summary> - /// The WM_SETFOCUS message is sent to a window after it has gained the keyboard focus. - /// </summary> - SETFOCUS = 0x0007, - /// <summary> - /// The WM_KILLFOCUS message is sent to a window immediately before it loses the keyboard focus. - /// </summary> - KILLFOCUS = 0x0008, - /// <summary> - /// The WM_ENABLE message is sent when an application changes the enabled state of a window. It is sent to the window whose enabled state is changing. This message is sent before the EnableWindow function returns, but after the enabled state (WS_DISABLED style bit) of the window has changed. - /// </summary> - ENABLE = 0x000A, - /// <summary> - /// An application sends the WM_SETREDRAW message to a window to allow changes in that window to be redrawn or to prevent changes in that window from being redrawn. - /// </summary> - SETREDRAW = 0x000B, - /// <summary> - /// An application sends a WM_SETTEXT message to set the text of a window. - /// </summary> - SETTEXT = 0x000C, - /// <summary> - /// An application sends a WM_GETTEXT message to copy the text that corresponds to a window into a buffer provided by the caller. - /// </summary> - GETTEXT = 0x000D, - /// <summary> - /// An application sends a WM_GETTEXTLENGTH message to determine the length, in characters, of the text associated with a window. - /// </summary> - GETTEXTLENGTH = 0x000E, - /// <summary> - /// The WM_PAINT message is sent when the system or another application makes a request to paint a portion of an application's window. The message is sent when the UpdateWindow or RedrawWindow function is called, or by the DispatchMessage function when the application obtains a WM_PAINT message by using the GetMessage or PeekMessage function. - /// </summary> - PAINT = 0x000F, - /// <summary> - /// The WM_CLOSE message is sent as a signal that a window or an application should terminate. - /// </summary> - CLOSE = 0x0010, - /// <summary> - /// The WM_QUERYENDSESSION message is sent when the user chooses to end the session or when an application calls one of the system shutdown functions. If any application returns zero, the session is not ended. The system stops sending WM_QUERYENDSESSION messages as soon as one application returns zero. - /// After processing this message, the system sends the WM_ENDSESSION message with the wParam parameter set to the results of the WM_QUERYENDSESSION message. - /// </summary> - QUERYENDSESSION = 0x0011, - /// <summary> - /// The WM_QUERYOPEN message is sent to an icon when the user requests that the window be restored to its previous size and position. - /// </summary> - QUERYOPEN = 0x0013, - /// <summary> - /// The WM_ENDSESSION message is sent to an application after the system processes the results of the WM_QUERYENDSESSION message. The WM_ENDSESSION message informs the application whether the session is ending. - /// </summary> - ENDSESSION = 0x0016, - /// <summary> - /// The WM_QUIT message indicates a request to terminate an application and is generated when the application calls the PostQuitMessage function. It causes the GetMessage function to return zero. - /// </summary> - QUIT = 0x0012, - /// <summary> - /// The WM_ERASEBKGND message is sent when the window background must be erased (for example, when a window is resized). The message is sent to prepare an invalidated portion of a window for painting. - /// </summary> - ERASEBKGND = 0x0014, - /// <summary> - /// This message is sent to all top-level windows when a change is made to a system color setting. - /// </summary> - SYSCOLORCHANGE = 0x0015, - /// <summary> - /// The WM_SHOWWINDOW message is sent to a window when the window is about to be hidden or shown. - /// </summary> - SHOWWINDOW = 0x0018, - /// <summary> - /// An application sends the WM_WININICHANGE message to all top-level windows after making a change to the WIN.INI file. The SystemParametersInfo function sends this message after an application uses the function to change a setting in WIN.INI. - /// Note The WM_WININICHANGE message is provided only for compatibility with earlier versions of the system. Applications should use the WM_SETTINGCHANGE message. - /// </summary> - WININICHANGE = 0x001A, - /// <summary> - /// An application sends the WM_WININICHANGE message to all top-level windows after making a change to the WIN.INI file. The SystemParametersInfo function sends this message after an application uses the function to change a setting in WIN.INI. - /// Note The WM_WININICHANGE message is provided only for compatibility with earlier versions of the system. Applications should use the WM_SETTINGCHANGE message. - /// </summary> - SETTINGCHANGE = WININICHANGE, - /// <summary> - /// The WM_DEVMODECHANGE message is sent to all top-level windows whenever the user changes device-mode settings. - /// </summary> - DEVMODECHANGE = 0x001B, - /// <summary> - /// The WM_ACTIVATEAPP message is sent when a window belonging to a different application than the active window is about to be activated. The message is sent to the application whose window is being activated and to the application whose window is being deactivated. - /// </summary> - ACTIVATEAPP = 0x001C, - /// <summary> - /// An application sends the WM_FONTCHANGE message to all top-level windows in the system after changing the pool of font resources. - /// </summary> - FONTCHANGE = 0x001D, - /// <summary> - /// A message that is sent whenever there is a change in the system time. - /// </summary> - TIMECHANGE = 0x001E, - /// <summary> - /// The WM_CANCELMODE message is sent to cancel certain modes, such as mouse capture. For example, the system sends this message to the active window when a dialog box or message box is displayed. Certain functions also send this message explicitly to the specified window regardless of whether it is the active window. For example, the EnableWindow function sends this message when disabling the specified window. - /// </summary> - CANCELMODE = 0x001F, - /// <summary> - /// The WM_SETCURSOR message is sent to a window if the mouse causes the cursor to move within a window and mouse input is not captured. - /// </summary> - SETCURSOR = 0x0020, - /// <summary> - /// The WM_MOUSEACTIVATE message is sent when the cursor is in an inactive window and the user presses a mouse button. The parent window receives this message only if the child window passes it to the DefWindowProc function. - /// </summary> - MOUSEACTIVATE = 0x0021, - /// <summary> - /// The WM_CHILDACTIVATE message is sent to a child window when the user clicks the window's title bar or when the window is activated, moved, or sized. - /// </summary> - CHILDACTIVATE = 0x0022, - /// <summary> - /// The WM_QUEUESYNC message is sent by a computer-based training (CBT) application to separate user-input messages from other messages sent through the WH_JOURNALPLAYBACK Hook procedure. - /// </summary> - QUEUESYNC = 0x0023, - /// <summary> - /// The WM_GETMINMAXINFO message is sent to a window when the size or position of the window is about to change. An application can use this message to override the window's default maximized size and position, or its default minimum or maximum tracking size. - /// </summary> - GETMINMAXINFO = 0x0024, - /// <summary> - /// Windows NT 3.51 and earlier: The WM_PAINTICON message is sent to a minimized window when the icon is to be painted. This message is not sent by newer versions of Microsoft Windows, except in unusual circumstances explained in the Remarks. - /// </summary> - PAINTICON = 0x0026, - /// <summary> - /// Windows NT 3.51 and earlier: The WM_ICONERASEBKGND message is sent to a minimized window when the background of the icon must be filled before painting the icon. A window receives this message only if a class icon is defined for the window; otherwise, WM_ERASEBKGND is sent. This message is not sent by newer versions of Windows. - /// </summary> - ICONERASEBKGND = 0x0027, - /// <summary> - /// The WM_NEXTDLGCTL message is sent to a dialog box procedure to set the keyboard focus to a different control in the dialog box. - /// </summary> - NEXTDLGCTL = 0x0028, - /// <summary> - /// The WM_SPOOLERSTATUS message is sent from Print Manager whenever a job is added to or removed from the Print Manager queue. - /// </summary> - SPOOLERSTATUS = 0x002A, - /// <summary> - /// The WM_DRAWITEM message is sent to the parent window of an owner-drawn button, combo box, list box, or menu when a visual aspect of the button, combo box, list box, or menu has changed. - /// </summary> - DRAWITEM = 0x002B, - /// <summary> - /// The WM_MEASUREITEM message is sent to the owner window of a combo box, list box, list view control, or menu item when the control or menu is created. - /// </summary> - MEASUREITEM = 0x002C, - /// <summary> - /// Sent to the owner of a list box or combo box when the list box or combo box is destroyed or when items are removed by the LB_DELETESTRING, LB_RESETCONTENT, CB_DELETESTRING, or CB_RESETCONTENT message. The system sends a WM_DELETEITEM message for each deleted item. The system sends the WM_DELETEITEM message for any deleted list box or combo box item with nonzero item data. - /// </summary> - DELETEITEM = 0x002D, - /// <summary> - /// Sent by a list box with the LBS_WANTKEYBOARDINPUT style to its owner in response to a WM_KEYDOWN message. - /// </summary> - VKEYTOITEM = 0x002E, - /// <summary> - /// Sent by a list box with the LBS_WANTKEYBOARDINPUT style to its owner in response to a WM_CHAR message. - /// </summary> - CHARTOITEM = 0x002F, - /// <summary> - /// An application sends a WM_SETFONT message to specify the font that a control is to use when drawing text. - /// </summary> - SETFONT = 0x0030, - /// <summary> - /// An application sends a WM_GETFONT message to a control to retrieve the font with which the control is currently drawing its text. - /// </summary> - GETFONT = 0x0031, - /// <summary> - /// An application sends a WM_SETHOTKEY message to a window to associate a hot key with the window. When the user presses the hot key, the system activates the window. - /// </summary> - SETHOTKEY = 0x0032, - /// <summary> - /// An application sends a WM_GETHOTKEY message to determine the hot key associated with a window. - /// </summary> - GETHOTKEY = 0x0033, - /// <summary> - /// The WM_QUERYDRAGICON message is sent to a minimized (iconic) window. The window is about to be dragged by the user but does not have an icon defined for its class. An application can return a handle to an icon or cursor. The system displays this cursor or icon while the user drags the icon. - /// </summary> - QUERYDRAGICON = 0x0037, - /// <summary> - /// The system sends the WM_COMPAREITEM message to determine the relative position of a new item in the sorted list of an owner-drawn combo box or list box. Whenever the application adds a new item, the system sends this message to the owner of a combo box or list box created with the CBS_SORT or LBS_SORT style. - /// </summary> - COMPAREITEM = 0x0039, - /// <summary> - /// Active Accessibility sends the WM_GETOBJECT message to obtain information about an accessible object contained in a server application. - /// Applications never send this message directly. It is sent only by Active Accessibility in response to calls to AccessibleObjectFromPoint, AccessibleObjectFromEvent, or AccessibleObjectFromWindow. However, server applications handle this message. - /// </summary> - GETOBJECT = 0x003D, - /// <summary> - /// The WM_COMPACTING message is sent to all top-level windows when the system detects more than 12.5 percent of system time over a 30- to 60-second interval is being spent compacting memory. This indicates that system memory is low. - /// </summary> - COMPACTING = 0x0041, - /// <summary> - /// WM_COMMNOTIFY is Obsolete for Win32-Based Applications - /// </summary> - [Obsolete] - COMMNOTIFY = 0x0044, - /// <summary> - /// The WM_WINDOWPOSCHANGING message is sent to a window whose size, position, or place in the Z order is about to change as a result of a call to the SetWindowPos function or another window-management function. - /// </summary> - WINDOWPOSCHANGING = 0x0046, - /// <summary> - /// The WM_WINDOWPOSCHANGED message is sent to a window whose size, position, or place in the Z order has changed as a result of a call to the SetWindowPos function or another window-management function. - /// </summary> - WINDOWPOSCHANGED = 0x0047, - /// <summary> - /// Notifies applications that the system, typically a battery-powered personal computer, is about to enter a suspended mode. - /// Use: POWERBROADCAST - /// </summary> - [Obsolete] - POWER = 0x0048, - /// <summary> - /// An application sends the WM_COPYDATA message to pass data to another application. - /// </summary> - COPYDATA = 0x004A, - /// <summary> - /// The WM_CANCELJOURNAL message is posted to an application when a user cancels the application's journaling activities. The message is posted with a NULL window handle. - /// </summary> - CANCELJOURNAL = 0x004B, - /// <summary> - /// Sent by a common control to its parent window when an event has occurred or the control requires some information. - /// </summary> - NOTIFY = 0x004E, - /// <summary> - /// The WM_INPUTLANGCHANGEREQUEST message is posted to the window with the focus when the user chooses a new input language, either with the hotkey (specified in the Keyboard control panel application) or from the indicator on the system taskbar. An application can accept the change by passing the message to the DefWindowProc function or reject the change (and prevent it from taking place) by returning immediately. - /// </summary> - INPUTLANGCHANGEREQUEST = 0x0050, - /// <summary> - /// The WM_INPUTLANGCHANGE message is sent to the topmost affected window after an application's input language has been changed. You should make any application-specific settings and pass the message to the DefWindowProc function, which passes the message to all first-level child windows. These child windows can pass the message to DefWindowProc to have it pass the message to their child windows, and so on. - /// </summary> - INPUTLANGCHANGE = 0x0051, - /// <summary> - /// Sent to an application that has initiated a training card with Microsoft Windows Help. The message informs the application when the user clicks an authorable button. An application initiates a training card by specifying the HELP_TCARD command in a call to the WinHelp function. - /// </summary> - TCARD = 0x0052, - /// <summary> - /// Indicates that the user pressed the F1 key. If a menu is active when F1 is pressed, WM_HELP is sent to the window associated with the menu; otherwise, WM_HELP is sent to the window that has the keyboard focus. If no window has the keyboard focus, WM_HELP is sent to the currently active window. - /// </summary> - HELP = 0x0053, - /// <summary> - /// The WM_USERCHANGED message is sent to all windows after the user has logged on or off. When the user logs on or off, the system updates the user-specific settings. The system sends this message immediately after updating the settings. - /// </summary> - USERCHANGED = 0x0054, - /// <summary> - /// Determines if a window accepts ANSI or Unicode structures in the WM_NOTIFY notification message. WM_NOTIFYFORMAT messages are sent from a common control to its parent window and from the parent window to the common control. - /// </summary> - NOTIFYFORMAT = 0x0055, - /// <summary> - /// The WM_CONTEXTMENU message notifies a window that the user clicked the right mouse button (right-clicked) in the window. - /// </summary> - CONTEXTMENU = 0x007B, - /// <summary> - /// The WM_STYLECHANGING message is sent to a window when the SetWindowLong function is about to change one or more of the window's styles. - /// </summary> - STYLECHANGING = 0x007C, - /// <summary> - /// The WM_STYLECHANGED message is sent to a window after the SetWindowLong function has changed one or more of the window's styles - /// </summary> - STYLECHANGED = 0x007D, - /// <summary> - /// The WM_DISPLAYCHANGE message is sent to all windows when the display resolution has changed. - /// </summary> - DISPLAYCHANGE = 0x007E, - /// <summary> - /// The WM_GETICON message is sent to a window to retrieve a handle to the large or small icon associated with a window. The system displays the large icon in the ALT+TAB dialog, and the small icon in the window caption. - /// </summary> - GETICON = 0x007F, - /// <summary> - /// An application sends the WM_SETICON message to associate a new large or small icon with a window. The system displays the large icon in the ALT+TAB dialog box, and the small icon in the window caption. - /// </summary> - SETICON = 0x0080, - /// <summary> - /// The WM_NCCREATE message is sent prior to the WM_CREATE message when a window is first created. - /// </summary> - NCCREATE = 0x0081, - /// <summary> - /// The WM_NCDESTROY message informs a window that its nonclient area is being destroyed. The DestroyWindow function sends the WM_NCDESTROY message to the window following the WM_DESTROY message. WM_DESTROY is used to free the allocated memory object associated with the window. - /// The WM_NCDESTROY message is sent after the child windows have been destroyed. In contrast, WM_DESTROY is sent before the child windows are destroyed. - /// </summary> - NCDESTROY = 0x0082, - /// <summary> - /// The WM_NCCALCSIZE message is sent when the size and position of a window's client area must be calculated. By processing this message, an application can control the content of the window's client area when the size or position of the window changes. - /// </summary> - NCCALCSIZE = 0x0083, - /// <summary> - /// The WM_NCHITTEST message is sent to a window when the cursor moves, or when a mouse button is pressed or released. If the mouse is not captured, the message is sent to the window beneath the cursor. Otherwise, the message is sent to the window that has captured the mouse. - /// </summary> - NCHITTEST = 0x0084, - /// <summary> - /// The WM_NCPAINT message is sent to a window when its frame must be painted. - /// </summary> - NCPAINT = 0x0085, - /// <summary> - /// The WM_NCACTIVATE message is sent to a window when its nonclient area needs to be changed to indicate an active or inactive state. - /// </summary> - NCACTIVATE = 0x0086, - /// <summary> - /// The WM_GETDLGCODE message is sent to the window procedure associated with a control. By default, the system handles all keyboard input to the control; the system interprets certain types of keyboard input as dialog box navigation keys. To override this default behavior, the control can respond to the WM_GETDLGCODE message to indicate the types of input it wants to process itself. - /// </summary> - GETDLGCODE = 0x0087, - /// <summary> - /// The WM_SYNCPAINT message is used to synchronize painting while avoiding linking independent GUI threads. - /// </summary> - SYNCPAINT = 0x0088, - /// <summary> - /// The WM_NCMOUSEMOVE message is posted to a window when the cursor is moved within the nonclient area of the window. This message is posted to the window that contains the cursor. If a window has captured the mouse, this message is not posted. - /// </summary> - NCMOUSEMOVE = 0x00A0, - /// <summary> - /// The WM_NCLBUTTONDOWN message is posted when the user presses the left mouse button while the cursor is within the nonclient area of a window. This message is posted to the window that contains the cursor. If a window has captured the mouse, this message is not posted. - /// </summary> - NCLBUTTONDOWN = 0x00A1, - /// <summary> - /// The WM_NCLBUTTONUP message is posted when the user releases the left mouse button while the cursor is within the nonclient area of a window. This message is posted to the window that contains the cursor. If a window has captured the mouse, this message is not posted. - /// </summary> - NCLBUTTONUP = 0x00A2, - /// <summary> - /// The WM_NCLBUTTONDBLCLK message is posted when the user double-clicks the left mouse button while the cursor is within the nonclient area of a window. This message is posted to the window that contains the cursor. If a window has captured the mouse, this message is not posted. - /// </summary> - NCLBUTTONDBLCLK = 0x00A3, - /// <summary> - /// The WM_NCRBUTTONDOWN message is posted when the user presses the right mouse button while the cursor is within the nonclient area of a window. This message is posted to the window that contains the cursor. If a window has captured the mouse, this message is not posted. - /// </summary> - NCRBUTTONDOWN = 0x00A4, - /// <summary> - /// The WM_NCRBUTTONUP message is posted when the user releases the right mouse button while the cursor is within the nonclient area of a window. This message is posted to the window that contains the cursor. If a window has captured the mouse, this message is not posted. - /// </summary> - NCRBUTTONUP = 0x00A5, - /// <summary> - /// The WM_NCRBUTTONDBLCLK message is posted when the user double-clicks the right mouse button while the cursor is within the nonclient area of a window. This message is posted to the window that contains the cursor. If a window has captured the mouse, this message is not posted. - /// </summary> - NCRBUTTONDBLCLK = 0x00A6, - /// <summary> - /// The WM_NCMBUTTONDOWN message is posted when the user presses the middle mouse button while the cursor is within the nonclient area of a window. This message is posted to the window that contains the cursor. If a window has captured the mouse, this message is not posted. - /// </summary> - NCMBUTTONDOWN = 0x00A7, - /// <summary> - /// The WM_NCMBUTTONUP message is posted when the user releases the middle mouse button while the cursor is within the nonclient area of a window. This message is posted to the window that contains the cursor. If a window has captured the mouse, this message is not posted. - /// </summary> - NCMBUTTONUP = 0x00A8, - /// <summary> - /// The WM_NCMBUTTONDBLCLK message is posted when the user double-clicks the middle mouse button while the cursor is within the nonclient area of a window. This message is posted to the window that contains the cursor. If a window has captured the mouse, this message is not posted. - /// </summary> - NCMBUTTONDBLCLK = 0x00A9, - /// <summary> - /// The WM_NCXBUTTONDOWN message is posted when the user presses the first or second X button while the cursor is in the nonclient area of a window. This message is posted to the window that contains the cursor. If a window has captured the mouse, this message is not posted. - /// </summary> - NCXBUTTONDOWN = 0x00AB, - /// <summary> - /// The WM_NCXBUTTONUP message is posted when the user releases the first or second X button while the cursor is in the nonclient area of a window. This message is posted to the window that contains the cursor. If a window has captured the mouse, this message is not posted. - /// </summary> - NCXBUTTONUP = 0x00AC, - /// <summary> - /// The WM_NCXBUTTONDBLCLK message is posted when the user double-clicks the first or second X button while the cursor is in the nonclient area of a window. This message is posted to the window that contains the cursor. If a window has captured the mouse, this message is not posted. - /// </summary> - NCXBUTTONDBLCLK = 0x00AD, - /// <summary> - /// The WM_INPUT_DEVICE_CHANGE message is sent to the window that registered to receive raw input. A window receives this message through its WindowProc function. - /// </summary> - INPUT_DEVICE_CHANGE = 0x00FE, - /// <summary> - /// The WM_INPUT message is sent to the window that is getting raw input. - /// </summary> - INPUT = 0x00FF, - /// <summary> - /// This message filters for keyboard messages. - /// </summary> - KEYFIRST = 0x0100, - /// <summary> - /// The WM_KEYDOWN message is posted to the window with the keyboard focus when a nonsystem key is pressed. A nonsystem key is a key that is pressed when the ALT key is not pressed. - /// </summary> - KEYDOWN = 0x0100, - /// <summary> - /// The WM_KEYUP message is posted to the window with the keyboard focus when a nonsystem key is released. A nonsystem key is a key that is pressed when the ALT key is not pressed, or a keyboard key that is pressed when a window has the keyboard focus. - /// </summary> - KEYUP = 0x0101, - /// <summary> - /// The WM_CHAR message is posted to the window with the keyboard focus when a WM_KEYDOWN message is translated by the TranslateMessage function. The WM_CHAR message contains the character code of the key that was pressed. - /// </summary> - CHAR = 0x0102, - /// <summary> - /// The WM_DEADCHAR message is posted to the window with the keyboard focus when a WM_KEYUP message is translated by the TranslateMessage function. WM_DEADCHAR specifies a character code generated by a dead key. A dead key is a key that generates a character, such as the umlaut (double-dot), that is combined with another character to form a composite character. For example, the umlaut-O character (Ö) is generated by typing the dead key for the umlaut character, and then typing the O key. - /// </summary> - DEADCHAR = 0x0103, - /// <summary> - /// The WM_SYSKEYDOWN message is posted to the window with the keyboard focus when the user presses the F10 key (which activates the menu bar) or holds down the ALT key and then presses another key. It also occurs when no window currently has the keyboard focus; in this case, the WM_SYSKEYDOWN message is sent to the active window. The window that receives the message can distinguish between these two contexts by checking the context code in the lParam parameter. - /// </summary> - SYSKEYDOWN = 0x0104, - /// <summary> - /// The WM_SYSKEYUP message is posted to the window with the keyboard focus when the user releases a key that was pressed while the ALT key was held down. It also occurs when no window currently has the keyboard focus; in this case, the WM_SYSKEYUP message is sent to the active window. The window that receives the message can distinguish between these two contexts by checking the context code in the lParam parameter. - /// </summary> - SYSKEYUP = 0x0105, - /// <summary> - /// The WM_SYSCHAR message is posted to the window with the keyboard focus when a WM_SYSKEYDOWN message is translated by the TranslateMessage function. It specifies the character code of a system character key — that is, a character key that is pressed while the ALT key is down. - /// </summary> - SYSCHAR = 0x0106, - /// <summary> - /// The WM_SYSDEADCHAR message is sent to the window with the keyboard focus when a WM_SYSKEYDOWN message is translated by the TranslateMessage function. WM_SYSDEADCHAR specifies the character code of a system dead key — that is, a dead key that is pressed while holding down the ALT key. - /// </summary> - SYSDEADCHAR = 0x0107, - /// <summary> - /// The WM_UNICHAR message is posted to the window with the keyboard focus when a WM_KEYDOWN message is translated by the TranslateMessage function. The WM_UNICHAR message contains the character code of the key that was pressed. - /// The WM_UNICHAR message is equivalent to WM_CHAR, but it uses Unicode Transformation Format (UTF)-32, whereas WM_CHAR uses UTF-16. It is designed to send or post Unicode characters to ANSI windows and it can can handle Unicode Supplementary Plane characters. - /// </summary> - UNICHAR = 0x0109, - /// <summary> - /// This message filters for keyboard messages. - /// </summary> - KEYLAST = 0x0109, - /// <summary> - /// Sent immediately before the IME generates the composition string as a result of a keystroke. A window receives this message through its WindowProc function. - /// </summary> - IME_STARTCOMPOSITION = 0x010D, - /// <summary> - /// Sent to an application when the IME ends composition. A window receives this message through its WindowProc function. - /// </summary> - IME_ENDCOMPOSITION = 0x010E, - /// <summary> - /// Sent to an application when the IME changes composition status as a result of a keystroke. A window receives this message through its WindowProc function. - /// </summary> - IME_COMPOSITION = 0x010F, - IME_KEYLAST = 0x010F, - /// <summary> - /// The WM_INITDIALOG message is sent to the dialog box procedure immediately before a dialog box is displayed. Dialog box procedures typically use this message to initialize controls and carry out any other initialization tasks that affect the appearance of the dialog box. - /// </summary> - INITDIALOG = 0x0110, - /// <summary> - /// The WM_COMMAND message is sent when the user selects a command item from a menu, when a control sends a notification message to its parent window, or when an accelerator keystroke is translated. - /// </summary> - COMMAND = 0x0111, - /// <summary> - /// A window receives this message when the user chooses a command from the Window menu, clicks the maximize button, minimize button, restore button, close button, or moves the form. You can stop the form from moving by filtering this out. - /// </summary> - SYSCOMMAND = 0x0112, - /// <summary> - /// The WM_TIMER message is posted to the installing thread's message queue when a timer expires. The message is posted by the GetMessage or PeekMessage function. - /// </summary> - TIMER = 0x0113, - /// <summary> - /// The WM_HSCROLL message is sent to a window when a scroll event occurs in the window's standard horizontal scroll bar. This message is also sent to the owner of a horizontal scroll bar control when a scroll event occurs in the control. - /// </summary> - HSCROLL = 0x0114, - /// <summary> - /// The WM_VSCROLL message is sent to a window when a scroll event occurs in the window's standard vertical scroll bar. This message is also sent to the owner of a vertical scroll bar control when a scroll event occurs in the control. - /// </summary> - VSCROLL = 0x0115, - /// <summary> - /// The WM_INITMENU message is sent when a menu is about to become active. It occurs when the user clicks an item on the menu bar or presses a menu key. This allows the application to modify the menu before it is displayed. - /// </summary> - INITMENU = 0x0116, - /// <summary> - /// The WM_INITMENUPOPUP message is sent when a drop-down menu or submenu is about to become active. This allows an application to modify the menu before it is displayed, without changing the entire menu. - /// </summary> - INITMENUPOPUP = 0x0117, - /// <summary> - /// The WM_MENUSELECT message is sent to a menu's owner window when the user selects a menu item. - /// </summary> - MENUSELECT = 0x011F, - /// <summary> - /// The WM_MENUCHAR message is sent when a menu is active and the user presses a key that does not correspond to any mnemonic or accelerator key. This message is sent to the window that owns the menu. - /// </summary> - MENUCHAR = 0x0120, - /// <summary> - /// The WM_ENTERIDLE message is sent to the owner window of a modal dialog box or menu that is entering an idle state. A modal dialog box or menu enters an idle state when no messages are waiting in its queue after it has processed one or more previous messages. - /// </summary> - ENTERIDLE = 0x0121, - /// <summary> - /// The WM_MENURBUTTONUP message is sent when the user releases the right mouse button while the cursor is on a menu item. - /// </summary> - MENURBUTTONUP = 0x0122, - /// <summary> - /// The WM_MENUDRAG message is sent to the owner of a drag-and-drop menu when the user drags a menu item. - /// </summary> - MENUDRAG = 0x0123, - /// <summary> - /// The WM_MENUGETOBJECT message is sent to the owner of a drag-and-drop menu when the mouse cursor enters a menu item or moves from the center of the item to the top or bottom of the item. - /// </summary> - MENUGETOBJECT = 0x0124, - /// <summary> - /// The WM_UNINITMENUPOPUP message is sent when a drop-down menu or submenu has been destroyed. - /// </summary> - UNINITMENUPOPUP = 0x0125, - /// <summary> - /// The WM_MENUCOMMAND message is sent when the user makes a selection from a menu. - /// </summary> - MENUCOMMAND = 0x0126, - /// <summary> - /// An application sends the WM_CHANGEUISTATE message to indicate that the user interface (UI) state should be changed. - /// </summary> - CHANGEUISTATE = 0x0127, - /// <summary> - /// An application sends the WM_UPDATEUISTATE message to change the user interface (UI) state for the specified window and all its child windows. - /// </summary> - UPDATEUISTATE = 0x0128, - /// <summary> - /// An application sends the WM_QUERYUISTATE message to retrieve the user interface (UI) state for a window. - /// </summary> - QUERYUISTATE = 0x0129, - /// <summary> - /// The WM_CTLCOLORMSGBOX message is sent to the owner window of a message box before Windows draws the message box. By responding to this message, the owner window can set the text and background colors of the message box by using the given display device context handle. - /// </summary> - CTLCOLORMSGBOX = 0x0132, - /// <summary> - /// An edit control that is not read-only or disabled sends the WM_CTLCOLOREDIT message to its parent window when the control is about to be drawn. By responding to this message, the parent window can use the specified device context handle to set the text and background colors of the edit control. - /// </summary> - CTLCOLOREDIT = 0x0133, - /// <summary> - /// Sent to the parent window of a list box before the system draws the list box. By responding to this message, the parent window can set the text and background colors of the list box by using the specified display device context handle. - /// </summary> - CTLCOLORLISTBOX = 0x0134, - /// <summary> - /// The WM_CTLCOLORBTN message is sent to the parent window of a button before drawing the button. The parent window can change the button's text and background colors. However, only owner-drawn buttons respond to the parent window processing this message. - /// </summary> - CTLCOLORBTN = 0x0135, - /// <summary> - /// The WM_CTLCOLORDLG message is sent to a dialog box before the system draws the dialog box. By responding to this message, the dialog box can set its text and background colors using the specified display device context handle. - /// </summary> - CTLCOLORDLG = 0x0136, - /// <summary> - /// The WM_CTLCOLORSCROLLBAR message is sent to the parent window of a scroll bar control when the control is about to be drawn. By responding to this message, the parent window can use the display context handle to set the background color of the scroll bar control. - /// </summary> - CTLCOLORSCROLLBAR = 0x0137, - /// <summary> - /// A static control, or an edit control that is read-only or disabled, sends the WM_CTLCOLORSTATIC message to its parent window when the control is about to be drawn. By responding to this message, the parent window can use the specified device context handle to set the text and background colors of the static control. - /// </summary> - CTLCOLORSTATIC = 0x0138, - /// <summary> - /// Use WM_MOUSEFIRST to specify the first mouse message. Use the PeekMessage() Function. - /// </summary> - MOUSEFIRST = 0x0200, - /// <summary> - /// The WM_MOUSEMOVE message is posted to a window when the cursor moves. If the mouse is not captured, the message is posted to the window that contains the cursor. Otherwise, the message is posted to the window that has captured the mouse. - /// </summary> - MOUSEMOVE = 0x0200, - /// <summary> - /// The WM_LBUTTONDOWN message is posted when the user presses the left mouse button while the cursor is in the client area of a window. If the mouse is not captured, the message is posted to the window beneath the cursor. Otherwise, the message is posted to the window that has captured the mouse. - /// </summary> - LBUTTONDOWN = 0x0201, - /// <summary> - /// The WM_LBUTTONUP message is posted when the user releases the left mouse button while the cursor is in the client area of a window. If the mouse is not captured, the message is posted to the window beneath the cursor. Otherwise, the message is posted to the window that has captured the mouse. - /// </summary> - LBUTTONUP = 0x0202, - /// <summary> - /// The WM_LBUTTONDBLCLK message is posted when the user double-clicks the left mouse button while the cursor is in the client area of a window. If the mouse is not captured, the message is posted to the window beneath the cursor. Otherwise, the message is posted to the window that has captured the mouse. - /// </summary> - LBUTTONDBLCLK = 0x0203, - /// <summary> - /// The WM_RBUTTONDOWN message is posted when the user presses the right mouse button while the cursor is in the client area of a window. If the mouse is not captured, the message is posted to the window beneath the cursor. Otherwise, the message is posted to the window that has captured the mouse. - /// </summary> - RBUTTONDOWN = 0x0204, - /// <summary> - /// The WM_RBUTTONUP message is posted when the user releases the right mouse button while the cursor is in the client area of a window. If the mouse is not captured, the message is posted to the window beneath the cursor. Otherwise, the message is posted to the window that has captured the mouse. - /// </summary> - RBUTTONUP = 0x0205, - /// <summary> - /// The WM_RBUTTONDBLCLK message is posted when the user double-clicks the right mouse button while the cursor is in the client area of a window. If the mouse is not captured, the message is posted to the window beneath the cursor. Otherwise, the message is posted to the window that has captured the mouse. - /// </summary> - RBUTTONDBLCLK = 0x0206, - /// <summary> - /// The WM_MBUTTONDOWN message is posted when the user presses the middle mouse button while the cursor is in the client area of a window. If the mouse is not captured, the message is posted to the window beneath the cursor. Otherwise, the message is posted to the window that has captured the mouse. - /// </summary> - MBUTTONDOWN = 0x0207, - /// <summary> - /// The WM_MBUTTONUP message is posted when the user releases the middle mouse button while the cursor is in the client area of a window. If the mouse is not captured, the message is posted to the window beneath the cursor. Otherwise, the message is posted to the window that has captured the mouse. - /// </summary> - MBUTTONUP = 0x0208, - /// <summary> - /// The WM_MBUTTONDBLCLK message is posted when the user double-clicks the middle mouse button while the cursor is in the client area of a window. If the mouse is not captured, the message is posted to the window beneath the cursor. Otherwise, the message is posted to the window that has captured the mouse. - /// </summary> - MBUTTONDBLCLK = 0x0209, - /// <summary> - /// The WM_MOUSEWHEEL message is sent to the focus window when the mouse wheel is rotated. The DefWindowProc function propagates the message to the window's parent. There should be no internal forwarding of the message, since DefWindowProc propagates it up the parent chain until it finds a window that processes it. - /// </summary> - MOUSEWHEEL = 0x020A, - /// <summary> - /// The WM_XBUTTONDOWN message is posted when the user presses the first or second X button while the cursor is in the client area of a window. If the mouse is not captured, the message is posted to the window beneath the cursor. Otherwise, the message is posted to the window that has captured the mouse. - /// </summary> - XBUTTONDOWN = 0x020B, - /// <summary> - /// The WM_XBUTTONUP message is posted when the user releases the first or second X button while the cursor is in the client area of a window. If the mouse is not captured, the message is posted to the window beneath the cursor. Otherwise, the message is posted to the window that has captured the mouse. - /// </summary> - XBUTTONUP = 0x020C, - /// <summary> - /// The WM_XBUTTONDBLCLK message is posted when the user double-clicks the first or second X button while the cursor is in the client area of a window. If the mouse is not captured, the message is posted to the window beneath the cursor. Otherwise, the message is posted to the window that has captured the mouse. - /// </summary> - XBUTTONDBLCLK = 0x020D, - /// <summary> - /// The WM_MOUSEHWHEEL message is sent to the focus window when the mouse's horizontal scroll wheel is tilted or rotated. The DefWindowProc function propagates the message to the window's parent. There should be no internal forwarding of the message, since DefWindowProc propagates it up the parent chain until it finds a window that processes it. - /// </summary> - MOUSEHWHEEL = 0x020E, - /// <summary> - /// Use WM_MOUSELAST to specify the last mouse message. Used with PeekMessage() Function. - /// </summary> - MOUSELAST = 0x020E, - /// <summary> - /// The WM_PARENTNOTIFY message is sent to the parent of a child window when the child window is created or destroyed, or when the user clicks a mouse button while the cursor is over the child window. When the child window is being created, the system sends WM_PARENTNOTIFY just before the CreateWindow or CreateWindowEx function that creates the window returns. When the child window is being destroyed, the system sends the message before any processing to destroy the window takes place. - /// </summary> - PARENTNOTIFY = 0x0210, - /// <summary> - /// The WM_ENTERMENULOOP message informs an application's main window procedure that a menu modal loop has been entered. - /// </summary> - ENTERMENULOOP = 0x0211, - /// <summary> - /// The WM_EXITMENULOOP message informs an application's main window procedure that a menu modal loop has been exited. - /// </summary> - EXITMENULOOP = 0x0212, - /// <summary> - /// The WM_NEXTMENU message is sent to an application when the right or left arrow key is used to switch between the menu bar and the system menu. - /// </summary> - NEXTMENU = 0x0213, - /// <summary> - /// The WM_SIZING message is sent to a window that the user is resizing. By processing this message, an application can monitor the size and position of the drag rectangle and, if needed, change its size or position. - /// </summary> - SIZING = 0x0214, - /// <summary> - /// The WM_CAPTURECHANGED message is sent to the window that is losing the mouse capture. - /// </summary> - CAPTURECHANGED = 0x0215, - /// <summary> - /// The WM_MOVING message is sent to a window that the user is moving. By processing this message, an application can monitor the position of the drag rectangle and, if needed, change its position. - /// </summary> - MOVING = 0x0216, - /// <summary> - /// Notifies applications that a power-management event has occurred. - /// </summary> - POWERBROADCAST = 0x0218, - /// <summary> - /// Notifies an application of a change to the hardware configuration of a device or the computer. - /// </summary> - DEVICECHANGE = 0x0219, - /// <summary> - /// An application sends the WM_MDICREATE message to a multiple-document interface (MDI) client window to create an MDI child window. - /// </summary> - MDICREATE = 0x0220, - /// <summary> - /// An application sends the WM_MDIDESTROY message to a multiple-document interface (MDI) client window to close an MDI child window. - /// </summary> - MDIDESTROY = 0x0221, - /// <summary> - /// An application sends the WM_MDIACTIVATE message to a multiple-document interface (MDI) client window to instruct the client window to activate a different MDI child window. - /// </summary> - MDIACTIVATE = 0x0222, - /// <summary> - /// An application sends the WM_MDIRESTORE message to a multiple-document interface (MDI) client window to restore an MDI child window from maximized or minimized size. - /// </summary> - MDIRESTORE = 0x0223, - /// <summary> - /// An application sends the WM_MDINEXT message to a multiple-document interface (MDI) client window to activate the next or previous child window. - /// </summary> - MDINEXT = 0x0224, - /// <summary> - /// An application sends the WM_MDIMAXIMIZE message to a multiple-document interface (MDI) client window to maximize an MDI child window. The system resizes the child window to make its client area fill the client window. The system places the child window's window menu icon in the rightmost position of the frame window's menu bar, and places the child window's restore icon in the leftmost position. The system also appends the title bar text of the child window to that of the frame window. - /// </summary> - MDIMAXIMIZE = 0x0225, - /// <summary> - /// An application sends the WM_MDITILE message to a multiple-document interface (MDI) client window to arrange all of its MDI child windows in a tile format. - /// </summary> - MDITILE = 0x0226, - /// <summary> - /// An application sends the WM_MDICASCADE message to a multiple-document interface (MDI) client window to arrange all its child windows in a cascade format. - /// </summary> - MDICASCADE = 0x0227, - /// <summary> - /// An application sends the WM_MDIICONARRANGE message to a multiple-document interface (MDI) client window to arrange all minimized MDI child windows. It does not affect child windows that are not minimized. - /// </summary> - MDIICONARRANGE = 0x0228, - /// <summary> - /// An application sends the WM_MDIGETACTIVE message to a multiple-document interface (MDI) client window to retrieve the handle to the active MDI child window. - /// </summary> - MDIGETACTIVE = 0x0229, - /// <summary> - /// An application sends the WM_MDISETMENU message to a multiple-document interface (MDI) client window to replace the entire menu of an MDI frame window, to replace the window menu of the frame window, or both. - /// </summary> - MDISETMENU = 0x0230, - /// <summary> - /// The WM_ENTERSIZEMOVE message is sent one time to a window after it enters the moving or sizing modal loop. The window enters the moving or sizing modal loop when the user clicks the window's title bar or sizing border, or when the window passes the WM_SYSCOMMAND message to the DefWindowProc function and the wParam parameter of the message specifies the SC_MOVE or SC_SIZE value. The operation is complete when DefWindowProc returns. - /// The system sends the WM_ENTERSIZEMOVE message regardless of whether the dragging of full windows is enabled. - /// </summary> - ENTERSIZEMOVE = 0x0231, - /// <summary> - /// The WM_EXITSIZEMOVE message is sent one time to a window, after it has exited the moving or sizing modal loop. The window enters the moving or sizing modal loop when the user clicks the window's title bar or sizing border, or when the window passes the WM_SYSCOMMAND message to the DefWindowProc function and the wParam parameter of the message specifies the SC_MOVE or SC_SIZE value. The operation is complete when DefWindowProc returns. - /// </summary> - EXITSIZEMOVE = 0x0232, - /// <summary> - /// Sent when the user drops a file on the window of an application that has registered itself as a recipient of dropped files. - /// </summary> - DROPFILES = 0x0233, - /// <summary> - /// An application sends the WM_MDIREFRESHMENU message to a multiple-document interface (MDI) client window to refresh the window menu of the MDI frame window. - /// </summary> - MDIREFRESHMENU = 0x0234, - /// <summary> - /// Sent to an application when a window is activated. A window receives this message through its WindowProc function. - /// </summary> - IME_SETCONTEXT = 0x0281, - /// <summary> - /// Sent to an application to notify it of changes to the IME window. A window receives this message through its WindowProc function. - /// </summary> - IME_NOTIFY = 0x0282, - /// <summary> - /// Sent by an application to direct the IME window to carry out the requested command. The application uses this message to control the IME window that it has created. To send this message, the application calls the SendMessage function with the following parameters. - /// </summary> - IME_CONTROL = 0x0283, - /// <summary> - /// Sent to an application when the IME window finds no space to extend the area for the composition window. A window receives this message through its WindowProc function. - /// </summary> - IME_COMPOSITIONFULL = 0x0284, - /// <summary> - /// Sent to an application when the operating system is about to change the current IME. A window receives this message through its WindowProc function. - /// </summary> - IME_SELECT = 0x0285, - /// <summary> - /// Sent to an application when the IME gets a character of the conversion result. A window receives this message through its WindowProc function. - /// </summary> - IME_CHAR = 0x0286, - /// <summary> - /// Sent to an application to provide commands and request information. A window receives this message through its WindowProc function. - /// </summary> - IME_REQUEST = 0x0288, - /// <summary> - /// Sent to an application by the IME to notify the application of a key press and to keep message order. A window receives this message through its WindowProc function. - /// </summary> - IME_KEYDOWN = 0x0290, - /// <summary> - /// Sent to an application by the IME to notify the application of a key release and to keep message order. A window receives this message through its WindowProc function. - /// </summary> - IME_KEYUP = 0x0291, - /// <summary> - /// The WM_MOUSEHOVER message is posted to a window when the cursor hovers over the client area of the window for the period of time specified in a prior call to TrackMouseEvent. - /// </summary> - MOUSEHOVER = 0x02A1, - /// <summary> - /// The WM_MOUSELEAVE message is posted to a window when the cursor leaves the client area of the window specified in a prior call to TrackMouseEvent. - /// </summary> - MOUSELEAVE = 0x02A3, - /// <summary> - /// The WM_NCMOUSEHOVER message is posted to a window when the cursor hovers over the nonclient area of the window for the period of time specified in a prior call to TrackMouseEvent. - /// </summary> - NCMOUSEHOVER = 0x02A0, - /// <summary> - /// The WM_NCMOUSELEAVE message is posted to a window when the cursor leaves the nonclient area of the window specified in a prior call to TrackMouseEvent. - /// </summary> - NCMOUSELEAVE = 0x02A2, - /// <summary> - /// The WM_WTSSESSION_CHANGE message notifies applications of changes in session state. - /// </summary> - WTSSESSION_CHANGE = 0x02B1, - TABLET_FIRST = 0x02c0, - TABLET_LAST = 0x02df, - /// <summary> - /// An application sends a WM_CUT message to an edit control or combo box to delete (cut) the current selection, if any, in the edit control and copy the deleted text to the clipboard in CF_TEXT format. - /// </summary> - CUT = 0x0300, - /// <summary> - /// An application sends the WM_COPY message to an edit control or combo box to copy the current selection to the clipboard in CF_TEXT format. - /// </summary> - COPY = 0x0301, - /// <summary> - /// An application sends a WM_PASTE message to an edit control or combo box to copy the current content of the clipboard to the edit control at the current caret position. Data is inserted only if the clipboard contains data in CF_TEXT format. - /// </summary> - PASTE = 0x0302, - /// <summary> - /// An application sends a WM_CLEAR message to an edit control or combo box to delete (clear) the current selection, if any, from the edit control. - /// </summary> - CLEAR = 0x0303, - /// <summary> - /// An application sends a WM_UNDO message to an edit control to undo the last operation. When this message is sent to an edit control, the previously deleted text is restored or the previously added text is deleted. - /// </summary> - UNDO = 0x0304, - /// <summary> - /// The WM_RENDERFORMAT message is sent to the clipboard owner if it has delayed rendering a specific clipboard format and if an application has requested data in that format. The clipboard owner must render data in the specified format and place it on the clipboard by calling the SetClipboardData function. - /// </summary> - RENDERFORMAT = 0x0305, - /// <summary> - /// The WM_RENDERALLFORMATS message is sent to the clipboard owner before it is destroyed, if the clipboard owner has delayed rendering one or more clipboard formats. For the content of the clipboard to remain available to other applications, the clipboard owner must render data in all the formats it is capable of generating, and place the data on the clipboard by calling the SetClipboardData function. - /// </summary> - RENDERALLFORMATS = 0x0306, - /// <summary> - /// The WM_DESTROYCLIPBOARD message is sent to the clipboard owner when a call to the EmptyClipboard function empties the clipboard. - /// </summary> - DESTROYCLIPBOARD = 0x0307, - /// <summary> - /// The WM_DRAWCLIPBOARD message is sent to the first window in the clipboard viewer chain when the content of the clipboard changes. This enables a clipboard viewer window to display the new content of the clipboard. - /// </summary> - DRAWCLIPBOARD = 0x0308, - /// <summary> - /// The WM_PAINTCLIPBOARD message is sent to the clipboard owner by a clipboard viewer window when the clipboard contains data in the CF_OWNERDISPLAY format and the clipboard viewer's client area needs repainting. - /// </summary> - PAINTCLIPBOARD = 0x0309, - /// <summary> - /// The WM_VSCROLLCLIPBOARD message is sent to the clipboard owner by a clipboard viewer window when the clipboard contains data in the CF_OWNERDISPLAY format and an event occurs in the clipboard viewer's vertical scroll bar. The owner should scroll the clipboard image and update the scroll bar values. - /// </summary> - VSCROLLCLIPBOARD = 0x030A, - /// <summary> - /// The WM_SIZECLIPBOARD message is sent to the clipboard owner by a clipboard viewer window when the clipboard contains data in the CF_OWNERDISPLAY format and the clipboard viewer's client area has changed size. - /// </summary> - SIZECLIPBOARD = 0x030B, - /// <summary> - /// The WM_ASKCBFORMATNAME message is sent to the clipboard owner by a clipboard viewer window to request the name of a CF_OWNERDISPLAY clipboard format. - /// </summary> - ASKCBFORMATNAME = 0x030C, - /// <summary> - /// The WM_CHANGECBCHAIN message is sent to the first window in the clipboard viewer chain when a window is being removed from the chain. - /// </summary> - CHANGECBCHAIN = 0x030D, - /// <summary> - /// The WM_HSCROLLCLIPBOARD message is sent to the clipboard owner by a clipboard viewer window. This occurs when the clipboard contains data in the CF_OWNERDISPLAY format and an event occurs in the clipboard viewer's horizontal scroll bar. The owner should scroll the clipboard image and update the scroll bar values. - /// </summary> - HSCROLLCLIPBOARD = 0x030E, - /// <summary> - /// This message informs a window that it is about to receive the keyboard focus, giving the window the opportunity to realize its logical palette when it receives the focus. - /// </summary> - QUERYNEWPALETTE = 0x030F, - /// <summary> - /// The WM_PALETTEISCHANGING message informs applications that an application is going to realize its logical palette. - /// </summary> - PALETTEISCHANGING = 0x0310, - /// <summary> - /// This message is sent by the OS to all top-level and overlapped windows after the window with the keyboard focus realizes its logical palette. - /// This message enables windows that do not have the keyboard focus to realize their logical palettes and update their client areas. - /// </summary> - PALETTECHANGED = 0x0311, - /// <summary> - /// The WM_HOTKEY message is posted when the user presses a hot key registered by the RegisterHotKey function. The message is placed at the top of the message queue associated with the thread that registered the hot key. - /// </summary> - HOTKEY = 0x0312, - /// <summary> - /// The WM_PRINT message is sent to a window to request that it draw itself in the specified device context, most commonly in a printer device context. - /// </summary> - PRINT = 0x0317, - /// <summary> - /// The WM_PRINTCLIENT message is sent to a window to request that it draw its client area in the specified device context, most commonly in a printer device context. - /// </summary> - PRINTCLIENT = 0x0318, - /// <summary> - /// The WM_APPCOMMAND message notifies a window that the user generated an application command event, for example, by clicking an application command button using the mouse or typing an application command key on the keyboard. - /// </summary> - APPCOMMAND = 0x0319, - /// <summary> - /// The WM_THEMECHANGED message is broadcast to every window following a theme change event. Examples of theme change events are the activation of a theme, the deactivation of a theme, or a transition from one theme to another. - /// </summary> - THEMECHANGED = 0x031A, - /// <summary> - /// Sent when the contents of the clipboard have changed. - /// </summary> - CLIPBOARDUPDATE = 0x031D, - /// <summary> - /// The system will send a window the WM_DWMCOMPOSITIONCHANGED message to indicate that the availability of desktop composition has changed. - /// </summary> - DWMCOMPOSITIONCHANGED = 0x031E, - /// <summary> - /// WM_DWMNCRENDERINGCHANGED is called when the non-client area rendering status of a window has changed. Only windows that have set the flag DWM_BLURBEHIND.fTransitionOnMaximized to true will get this message. - /// </summary> - DWMNCRENDERINGCHANGED = 0x031F, - /// <summary> - /// Sent to all top-level windows when the colorization color has changed. - /// </summary> - DWMCOLORIZATIONCOLORCHANGED = 0x0320, - /// <summary> - /// WM_DWMWINDOWMAXIMIZEDCHANGE will let you know when a DWM composed window is maximized. You also have to register for this message as well. You'd have other windowd go opaque when this message is sent. - /// </summary> - DWMWINDOWMAXIMIZEDCHANGE = 0x0321, - /// <summary> - /// Sent to request extended title bar information. A window receives this message through its WindowProc function. - /// </summary> - GETTITLEBARINFOEX = 0x033F, - HANDHELDFIRST = 0x0358, - HANDHELDLAST = 0x035F, - AFXFIRST = 0x0360, - AFXLAST = 0x037F, - PENWINFIRST = 0x0380, - PENWINLAST = 0x038F, - /// <summary> - /// The WM_APP constant is used by applications to help define private messages, usually of the form WM_APP+X, where X is an integer value. - /// </summary> - APP = 0x8000, - /// <summary> - /// The WM_USER constant is used by applications to help define private messages for use by private window classes, usually of the form WM_USER+X, where X is an integer value. - /// </summary> - USER = 0x0400, - - /// <summary> - /// An application sends the WM_CPL_LAUNCH message to Windows Control Panel to request that a Control Panel application be started. - /// </summary> - CPL_LAUNCH = USER+0x1000, - /// <summary> - /// The WM_CPL_LAUNCHED message is sent when a Control Panel application, started by the WM_CPL_LAUNCH message, has closed. The WM_CPL_LAUNCHED message is sent to the window identified by the wParam parameter of the WM_CPL_LAUNCH message that started the application. - /// </summary> - CPL_LAUNCHED = USER+0x1001, - /// <summary> - /// WM_SYSTIMER is a well-known yet still undocumented message. Windows uses WM_SYSTIMER for internal actions like scrolling. - /// </summary> - SYSTIMER = 0x118, - - /// <summary> - /// The accessibility state has changed. - /// </summary> - HSHELL_ACCESSIBILITYSTATE = 11, - /// <summary> - /// The shell should activate its main window. - /// </summary> - HSHELL_ACTIVATESHELLWINDOW = 3, - /// <summary> - /// The user completed an input event (for example, pressed an application command button on the mouse or an application command key on the keyboard), and the application did not handle the WM_APPCOMMAND message generated by that input. - /// If the Shell procedure handles the WM_COMMAND message, it should not call CallNextHookEx. See the Return Value section for more information. - /// </summary> - HSHELL_APPCOMMAND = 12, - /// <summary> - /// A window is being minimized or maximized. The system needs the coordinates of the minimized rectangle for the window. - /// </summary> - HSHELL_GETMINRECT = 5, - /// <summary> - /// Keyboard language was changed or a new keyboard layout was loaded. - /// </summary> - HSHELL_LANGUAGE = 8, - /// <summary> - /// The title of a window in the task bar has been redrawn. - /// </summary> - HSHELL_REDRAW = 6, - /// <summary> - /// The user has selected the task list. A shell application that provides a task list should return TRUE to prevent Windows from starting its task list. - /// </summary> - HSHELL_TASKMAN = 7, - /// <summary> - /// A top-level, unowned window has been created. The window exists when the system calls this hook. - /// </summary> - HSHELL_WINDOWCREATED = 1, - /// <summary> - /// A top-level, unowned window is about to be destroyed. The window still exists when the system calls this hook. - /// </summary> - HSHELL_WINDOWDESTROYED = 2, - /// <summary> - /// The activation has changed to a different top-level, unowned window. - /// </summary> - HSHELL_WINDOWACTIVATED = 4, - /// <summary> - /// A top-level window is being replaced. The window exists when the system calls this hook. - /// </summary> - HSHELL_WINDOWREPLACED = 13 -} - -/// <summary> -/// Window Styles. -/// The following styles can be specified wherever a window style is required. After the control has been created, these styles cannot be modified, except as noted. -/// </summary> -[Flags()] -public enum WindowStyles : uint -{ - /// <summary>The window has a thin-line border.</summary> - WS_BORDER = 0x800000, - - /// <summary>The window has a title bar (includes the WS_BORDER style).</summary> - WS_CAPTION = 0xc00000, - - /// <summary>The window is a child window. A window with this style cannot have a menu bar. This style cannot be used with the WS_POPUP style.</summary> - WS_CHILD = 0x40000000, - - /// <summary>Excludes the area occupied by child windows when drawing occurs within the parent window. This style is used when creating the parent window.</summary> - WS_CLIPCHILDREN = 0x2000000, - - /// <summary> - /// Clips child windows relative to each other; that is, when a particular child window receives a WM_PAINT message, the WS_CLIPSIBLINGS style clips all other overlapping child windows out of the region of the child window to be updated. - /// If WS_CLIPSIBLINGS is not specified and child windows overlap, it is possible, when drawing within the client area of a child window, to draw within the client area of a neighboring child window. - /// </summary> - WS_CLIPSIBLINGS = 0x4000000, - - /// <summary>The window is initially disabled. A disabled window cannot receive input from the user. To change this after a window has been created, use the EnableWindow function.</summary> - WS_DISABLED = 0x8000000, - - /// <summary>The window has a border of a style typically used with dialog boxes. A window with this style cannot have a title bar.</summary> - WS_DLGFRAME = 0x400000, - - /// <summary> - /// The window is the first control of a group of controls. The group consists of this first control and all controls defined after it, up to the next control with the WS_GROUP style. - /// The first control in each group usually has the WS_TABSTOP style so that the user can move from group to group. The user can subsequently change the keyboard focus from one control in the group to the next control in the group by using the direction keys. - /// You can turn this style on and off to change dialog box navigation. To change this style after a window has been created, use the SetWindowLong function. - /// </summary> - WS_GROUP = 0x20000, - - /// <summary>The window has a horizontal scroll bar.</summary> - WS_HSCROLL = 0x100000, - - /// <summary>The window is initially maximized.</summary> - WS_MAXIMIZE = 0x1000000, - - /// <summary>The window has a maximize button. Cannot be combined with the WS_EX_CONTEXTHELP style. The WS_SYSMENU style must also be specified.</summary> - WS_MAXIMIZEBOX = 0x10000, - - /// <summary>The window is initially minimized.</summary> - WS_MINIMIZE = 0x20000000, - - /// <summary>The window has a minimize button. Cannot be combined with the WS_EX_CONTEXTHELP style. The WS_SYSMENU style must also be specified.</summary> - WS_MINIMIZEBOX = 0x20000, - - /// <summary>The window is an overlapped window. An overlapped window has a title bar and a border.</summary> - WS_OVERLAPPED = 0x0, - - /// <summary>The window is an overlapped window.</summary> - WS_OVERLAPPEDWINDOW = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_SIZEFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX, - - /// <summary>The window is a pop-up window. This style cannot be used with the WS_CHILD style.</summary> - WS_POPUP = 0x80000000u, - - /// <summary>The window is a pop-up window. The WS_CAPTION and WS_POPUPWINDOW styles must be combined to make the window menu visible.</summary> - WS_POPUPWINDOW = WS_POPUP | WS_BORDER | WS_SYSMENU, - - /// <summary>The window has a sizing border.</summary> - WS_SIZEFRAME = 0x40000, - - /// <summary>The window has a window menu on its title bar. The WS_CAPTION style must also be specified.</summary> - WS_SYSMENU = 0x80000, - - /// <summary> - /// The window is a control that can receive the keyboard focus when the user presses the TAB key. - /// Pressing the TAB key changes the keyboard focus to the next control with the WS_TABSTOP style. - /// You can turn this style on and off to change dialog box navigation. To change this style after a window has been created, use the SetWindowLong function. - /// For user-created windows and modeless dialogs to work with tab stops, alter the message loop to call the IsDialogMessage function. - /// </summary> - WS_TABSTOP = 0x10000, - - /// <summary>The window is initially visible. This style can be turned on and off by using the ShowWindow or SetWindowPos function.</summary> - WS_VISIBLE = 0x10000000, - - /// <summary>The window has a vertical scroll bar.</summary> - WS_VSCROLL = 0x200000 -} - -[Flags] -public enum WindowStylesEx : uint -{ - /// <summary> - /// Specifies that a window created with this style accepts drag-drop files. - /// </summary> - WS_EX_ACCEPTFILES = 0x00000010, - /// <summary> - /// Forces a top-level window onto the taskbar when the window is visible. - /// </summary> - WS_EX_APPWINDOW = 0x00040000, - /// <summary> - /// Specifies that a window has a border with a sunken edge. - /// </summary> - WS_EX_CLIENTEDGE = 0x00000200, - /// <summary> - /// Windows XP: Paints all descendants of a window in bottom-to-top painting order using double-buffering. For more information, see Remarks. This cannot be used if the window has a class style of either CS_OWNDC or CS_CLASSDC. - /// </summary> - WS_EX_COMPOSITED = 0x02000000, - /// <summary> - /// Includes a question mark in the title bar of the window. When the user clicks the question mark, the cursor changes to a question mark with a pointer. If the user then clicks a child window, the child receives a WM_HELP message. The child window should pass the message to the parent window procedure, which should call the WinHelp function using the HELP_WM_HELP command. The Help application displays a pop-up window that typically contains help for the child window. - /// WS_EX_CONTEXTHELP cannot be used with the WS_MAXIMIZEBOX or WS_MINIMIZEBOX styles. - /// </summary> - WS_EX_CONTEXTHELP = 0x00000400, - /// <summary> - /// The window itself contains child windows that should take part in dialog box navigation. If this style is specified, the dialog manager recurses into children of this window when performing navigation operations such as handling the TAB key, an arrow key, or a keyboard mnemonic. - /// </summary> - WS_EX_CONTROLPARENT = 0x00010000, - /// <summary> - /// Creates a window that has a double border; the window can, optionally, be created with a title bar by specifying the WS_CAPTION style in the dwStyle parameter. - /// </summary> - WS_EX_DLGMODALFRAME = 0x00000001, - /// <summary> - /// Windows 2000/XP: Creates a layered window. Note that this cannot be used for child windows. Also, this cannot be used if the window has a class style of either CS_OWNDC or CS_CLASSDC. - /// </summary> - WS_EX_LAYERED = 0x00080000, - /// <summary> - /// Arabic and Hebrew versions of Windows 98/Me, Windows 2000/XP: Creates a window whose horizontal origin is on the right edge. Increasing horizontal values advance to the left. - /// </summary> - WS_EX_LAYOUTRTL = 0x00400000, - /// <summary> - /// Creates a window that has generic left-aligned properties. This is the default. - /// </summary> - WS_EX_LEFT = 0x00000000, - /// <summary> - /// If the shell language is Hebrew, Arabic, or another language that supports reading order alignment, the vertical scroll bar (if present) is to the left of the client area. For other languages, the style is ignored. - /// </summary> - WS_EX_LEFTSCROLLBAR = 0x00004000, - /// <summary> - /// The window text is displayed using left-to-right reading-order properties. This is the default. - /// </summary> - WS_EX_LTRREADING = 0x00000000, - /// <summary> - /// Creates a multiple-document interface (MDI) child window. - /// </summary> - WS_EX_MDICHILD = 0x00000040, - /// <summary> - /// Windows 2000/XP: A top-level window created with this style does not become the foreground window when the user clicks it. The system does not bring this window to the foreground when the user minimizes or closes the foreground window. - /// To activate the window, use the SetActiveWindow or SetForegroundWindow function. - /// The window does not appear on the taskbar by default. To force the window to appear on the taskbar, use the WS_EX_APPWINDOW style. - /// </summary> - WS_EX_NOACTIVATE = 0x08000000, - /// <summary> - /// Windows 2000/XP: A window created with this style does not pass its window layout to its child windows. - /// </summary> - WS_EX_NOINHERITLAYOUT = 0x00100000, - /// <summary> - /// Specifies that a child window created with this style does not send the WM_PARENTNOTIFY message to its parent window when it is created or destroyed. - /// </summary> - WS_EX_NOPARENTNOTIFY = 0x00000004, - /// <summary> - /// Combines the WS_EX_CLIENTEDGE and WS_EX_WINDOWEDGE styles. - /// </summary> - WS_EX_OVERLAPPEDWINDOW = WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE, - /// <summary> - /// Combines the WS_EX_WINDOWEDGE, WS_EX_TOOLWINDOW, and WS_EX_TOPMOST styles. - /// </summary> - WS_EX_PALETTEWINDOW = WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW | WS_EX_TOPMOST, - /// <summary> - /// The window has generic "right-aligned" properties. This depends on the window class. This style has an effect only if the shell language is Hebrew, Arabic, or another language that supports reading-order alignment; otherwise, the style is ignored. - /// Using the WS_EX_RIGHT style for static or edit controls has the same effect as using the SS_RIGHT or ES_RIGHT style, respectively. Using this style with button controls has the same effect as using BS_RIGHT and BS_RIGHTBUTTON styles. - /// </summary> - WS_EX_RIGHT = 0x00001000, - /// <summary> - /// Vertical scroll bar (if present) is to the right of the client area. This is the default. - /// </summary> - WS_EX_RIGHTSCROLLBAR = 0x00000000, - /// <summary> - /// If the shell language is Hebrew, Arabic, or another language that supports reading-order alignment, the window text is displayed using right-to-left reading-order properties. For other languages, the style is ignored. - /// </summary> - WS_EX_RTLREADING = 0x00002000, - /// <summary> - /// Creates a window with a three-dimensional border style intended to be used for items that do not accept user input. - /// </summary> - WS_EX_STATICEDGE = 0x00020000, - /// <summary> - /// Creates a tool window; that is, a window intended to be used as a floating toolbar. A tool window has a title bar that is shorter than a normal title bar, and the window title is drawn using a smaller font. A tool window does not appear in the taskbar or in the dialog that appears when the user presses ALT+TAB. If a tool window has a system menu, its icon is not displayed on the title bar. However, you can display the system menu by right-clicking or by typing ALT+SPACE. - /// </summary> - WS_EX_TOOLWINDOW = 0x00000080, - /// <summary> - /// Specifies that a window created with this style should be placed above all non-topmost windows and should stay above them, even when the window is deactivated. To add or remove this style, use the SetWindowPos function. - /// </summary> - WS_EX_TOPMOST = 0x00000008, - /// <summary> - /// Specifies that a window created with this style should not be painted until siblings beneath the window (that were created by the same thread) have been painted. The window appears transparent because the bits of underlying sibling windows have already been painted. - /// To achieve transparency without these restrictions, use the SetWindowRgn function. - /// </summary> - WS_EX_TRANSPARENT = 0x00000020, - /// <summary> - /// Specifies that a window has a border with a raised edge. - /// </summary> - WS_EX_WINDOWEDGE = 0x00000100 -} - -public enum ShowWindowCommands -{ - /// <summary> - /// Hides the window and activates another window. - /// </summary> - Hide = 0, - /// <summary> - /// Activates and displays a window. If the window is minimized or - /// maximized, the system restores it to its original size and position. - /// An application should specify this flag when displaying the window - /// for the first time. - /// </summary> - Normal = 1, - /// <summary> - /// Activates the window and displays it as a minimized window. - /// </summary> - ShowMinimized = 2, - /// <summary> - /// Maximizes the specified window. - /// </summary> - Maximize = 3, // is this the right value? - /// <summary> - /// Activates the window and displays it as a maximized window. - /// </summary> - ShowMaximized = 3, - /// <summary> - /// Displays a window in its most recent size and position. This value - /// is similar to <see cref="Win32.ShowWindowCommand.Normal"/>, except - /// the window is not activated. - /// </summary> - ShowNoActivate = 4, - /// <summary> - /// Activates the window and displays it in its current size and position. - /// </summary> - Show = 5, - /// <summary> - /// Minimizes the specified window and activates the next top-level - /// window in the Z order. - /// </summary> - Minimize = 6, - /// <summary> - /// Displays the window as a minimized window. This value is similar to - /// <see cref="Win32.ShowWindowCommand.ShowMinimized"/>, except the - /// window is not activated. - /// </summary> - ShowMinNoActive = 7, - /// <summary> - /// Displays the window in its current size and position. This value is - /// similar to <see cref="Win32.ShowWindowCommand.Show"/>, except the - /// window is not activated. - /// </summary> - ShowNA = 8, - /// <summary> - /// Activates and displays the window. If the window is minimized or - /// maximized, the system restores it to its original size and position. - /// An application should specify this flag when restoring a minimized window. - /// </summary> - Restore = 9, - /// <summary> - /// Sets the show state based on the SW_* value specified in the - /// STARTUPINFO structure passed to the CreateProcess function by the - /// program that started the application. - /// </summary> - ShowDefault = 10, - /// <summary> - /// <b>Windows 2000/XP:</b> Minimizes a window, even if the thread - /// that owns the window is not responding. This flag should only be - /// used when minimizing windows from a different thread. - /// </summary> - ForceMinimize = 11 -} |