Stream s;
if (!string.IsNullOrEmpty (VertSourcePath)) {
- s = Crow.Interface.GetStreamFromPath (VertSourcePath);
+ s = Crow.Interface.StaticGetStreamFromPath (VertSourcePath);
if (s != null) {
using (StreamReader sr = new StreamReader (s)) {
vertSource = sr.ReadToEnd ();
}
if (!string.IsNullOrEmpty (FragSourcePath)) {
- s = Crow.Interface.GetStreamFromPath (FragSourcePath);
+ s = Crow.Interface.StaticGetStreamFromPath (FragSourcePath);
if (s != null) {
using (StreamReader sr = new StreamReader (s)) {
fragSource = sr.ReadToEnd ();
}
if (!string.IsNullOrEmpty (GeomSourcePath)) {
- s = Crow.Interface.GetStreamFromPath (GeomSourcePath);
+ s = Crow.Interface.StaticGetStreamFromPath (GeomSourcePath);
if (s != null) {
using (StreamReader sr = new StreamReader (s)) {
geomSource = sr.ReadToEnd ();
public Texture(string _mapPath, bool flipY = true)
{
- using (Stream s = Interface.GetStreamFromPath (_mapPath)) {
+ using (Stream s = Interface.StaticGetStreamFromPath (_mapPath)) {
try {
Map = _mapPath;
/// 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 (string path)
+ public override void Load (Interface iface, string path)
{
Path = path;
if (sharedResources.ContainsKey (path)) {
Dimensions = sp.Dims;
return;
}
- using (Stream stream = Interface.GetStreamFromPath (path)) {
- using (MemoryStream ms = new MemoryStream ()) {
- stream.CopyTo (ms);
- loadBitmap (new System.Drawing.Bitmap (ms));
- }
+ using (Stream stream = iface.GetStreamFromPath (path)) {
+ loadBitmap (new System.Drawing.Bitmap (stream));
}
sharedResources [path] = new sharedPicture (image, Dimensions);
}
#region Reflexion helpers
static MemberInfo getMemberInfoWithReflexion(object instance, string member){
- return instance.GetType ().GetMember (member)?.FirstOrDefault();
+ 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);
PropertyInfo pi = mi as PropertyInfo;
tmp = pi.GetValue (instance);
dstType = pi.PropertyType;
- }
- if (mi.MemberType == MemberTypes.Field) {
+ }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 ""
/// <summary>
/// create delegate helper
/// </summary>
- static Delegate createDel(Type eventType, object instance, string method){
+ 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) {
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);
IFace.currentLQI.NewSlot = Slot;
Debug.WriteLine ("\t\t{0} => {1}",LastSlots,Slot);
#endif
- #if DESIGN_MODE
- if (IFace.GetType().Name == "DesignInterface"){
- Debug.WriteLine ("\t\t{2}: {0} => {1}",LastSlots,Slot,this.name);
- }
- #endif
+// #if DESIGN_MODE
+// if (IFace.GetType().Name == "DesignInterface"){
+// Debug.WriteLine ("\t\t{2}: {0} => {1}",LastSlots,Slot,this.name);
+// }
+// #endif
switch (layoutType) {
case LayoutingType.Width:
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)
{
}
#region GraphicObject overrides
- 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 override GraphicObject FindByName (string nameToFind)
{
if (Name == nameToFind)
{
Picture pic;
if (path.EndsWith (".svg", true, System.Globalization.CultureInfo.InvariantCulture))
- pic = new SvgPicture ();
+ pic = new SvgPicture (path);
else
- pic = new BmpPicture ();
+ pic = new BmpPicture (path);
- pic.Load (path);
+ pic.Load (IFace, path);
pic.Scaled = scaled;
pic.KeepProportions = keepProps;
}
}
- [XmlAttributeAttribute][DefaultValue(0)]
+ [DefaultValue(0)]
public int TabOffset {
get { return tabOffset; }
set {
public Measure TabWidth {
get { return tview == null ? Measure.Fit : tview.TabWidth; }
}
- [XmlAttributeAttribute][DefaultValue(false)]
+ [DefaultValue(false)]
public virtual bool IsSelected {
get { return isSelected; }
set {
/// <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 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.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
/// <summary>
/// Initializes a new instance of the Instantiator class.
/// </summary>
- public Instantiator (Interface _iface, string path) : this (_iface, Interface.GetStreamFromPath(path), path) {
+ public Instantiator (Interface _iface, string path) : this (_iface, _iface.GetStreamFromPath(path), path) {
}
/// <summary>
if (iface.Instantiators.ContainsKey (itemTemplatePath)) {
itemTemplateIds.Add (new string [] { "default", itemTemplatePath, "" });
} else {
- using (Stream stream = Interface.GetStreamFromPath (itemTemplatePath)) {
+ 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)) {
}
}
- loadCursors ();
-
FontRenderingOptions = new FontOptions ();
FontRenderingOptions.Antialias = Antialias.Subpixel;
FontRenderingOptions.HintMetrics = HintMetrics.On;
public void Init () {
CurrentInterface = this;
+ loadCursors ();
loadStyling ();
findAvailableTemplates ();
initTooltip ();
}
}
- static void loadCursors(){
+ void loadCursors(){
//Load cursors
- XCursor.Cross = XCursorFile.Load("#Crow.Images.Icons.Cursors.cross").Cursors[0];
- XCursor.Default = XCursorFile.Load("#Crow.Images.Icons.Cursors.arrow").Cursors[0];
- XCursor.NW = XCursorFile.Load("#Crow.Images.Icons.Cursors.top_left_corner").Cursors[0];
- XCursor.NE = XCursorFile.Load("#Crow.Images.Icons.Cursors.top_right_corner").Cursors[0];
- XCursor.SW = XCursorFile.Load("#Crow.Images.Icons.Cursors.bottom_left_corner").Cursors[0];
- XCursor.SE = XCursorFile.Load("#Crow.Images.Icons.Cursors.bottom_right_corner").Cursors[0];
- XCursor.H = XCursorFile.Load("#Crow.Images.Icons.Cursors.sb_h_double_arrow").Cursors[0];
- XCursor.V = XCursorFile.Load("#Crow.Images.Icons.Cursors.sb_v_double_arrow").Cursors[0];
- XCursor.Text = XCursorFile.Load("#Crow.Images.Icons.Cursors.ibeam").Cursors[0];
+ 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
/// <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 static Stream GetStreamFromPath (string path)
+ 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;
/// <param name="path">image path, may be embedded</param>
public Picture (string path)
{
- Load (path);
+ Path = path;
}
#endregion
/// load the image for rendering from the stream given as argument
/// </summary>
/// <param name="stream">picture stream</param>
- public abstract void Load(string path);
+ public abstract void Load(Interface iface, string path);
#endregion
/// <summary>
Picture _pic = null;
if (path.EndsWith (".svg", true, System.Globalization.CultureInfo.InvariantCulture))
- _pic = new SvgPicture ();
+ _pic = new SvgPicture (path);
else
- _pic = new BmpPicture ();
-
- _pic.Load (path);
+ _pic = new BmpPicture (path);
return _pic;
}
Picture _pic = null;
if (path.EndsWith (".svg", true, System.Globalization.CultureInfo.InvariantCulture))
- _pic = new SvgPicture ();
+ _pic = new SvgPicture (path);
else
- _pic = new BmpPicture ();
-
- _pic.Load (path);
+ _pic = new BmpPicture (path);
return _pic;
}
{}
#endregion
- public override void Load (string path)
+ public override void Load (Interface iface, string path)
{
Path = path;
if (sharedResources.ContainsKey (path)) {
Dimensions = sp.Dims;
return;
}
- using (Stream stream = Interface.GetStreamFromPath (path)) {
+ using (Stream stream = iface.GetStreamFromPath (path)) {
using (MemoryStream ms = new MemoryStream ()) {
stream.CopyTo (ms);
return tmp;
}
- public static XCursorFile Load(string path)
+ public static XCursorFile Load(Interface iface, string path)
{
- return loadFromStream (Interface.GetStreamFromPath (path));
+ return loadFromStream (iface.GetStreamFromPath (path));
}
static XCursor imageLoad(BinaryReader sr)