<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<PackOnBuild>true</PackOnBuild>
<PackageId>Crow</PackageId>
- <PackageVersion>0.8.0-beta</PackageVersion>
+ <PackageVersion>0.8.0.1-beta</PackageVersion>
<!-- <PackageVersionSuffix>-beta</PackageVersionSuffix>not working-->
<Authors>JP Bruyère</Authors>
<Title>C# Rapid Open Widget Toolkit</Title>
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
<Optimize>false</Optimize>
<OutputPath>$(SolutionDir)build\Debug</OutputPath>
- <DefineConstants>DEBUG_DRAGNDROP0;DEBUG_LOG0;XLIB_BACKEND0;DESIGN_MODE;DEBUG_UPDATE0;DEBUG_FOCUS0;DEBUG_DISPOSE0;TRACE0;DEBUG;MEASURE_TIME;DEBUG_LOAD0;DEBUG_BINDING0;DEBUG_CLIP_RECTANGLE0</DefineConstants>
+ <DefineConstants>DEBUG_BINDING_FUNC_CALLS0;DEBUG_DRAGNDROP0;DEBUG_LOG0;XLIB_BACKEND0;DESIGN_MODE;DEBUG_UPDATE0;DEBUG_FOCUS0;DEBUG_DISPOSE0;TRACE0;DEBUG;MEASURE_TIME;DEBUG_LOAD0;DEBUG_BINDING0;DEBUG_CLIP_RECTANGLE0</DefineConstants>
<EnvironmentVariables>
<EnvironmentVariables>
<Variable name="MONO_CAIRO_DEBUG_DISPOSE" value="1" />
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 miIFaceLoad = typeof(Interface).GetMethod ("CreateInstance", 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) });
#region Reflexion helpers
static MemberInfo getMemberInfoWithReflexion(object instance, string member){
- Type t = instance.GetType();
- MemberInfo mi = t.GetMember (member)?.FirstOrDefault();
+ Type t = instance.GetType();
+#if DEBUG_BINDING_FUNC_CALLS
+ Console.WriteLine ($"getMemberInfoWithReflexion ({instance},{member}); type:{t}");
+#endif
+ 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);
+#if DEBUG_BINDING_FUNC_CALLS
+ Console.WriteLine ($"getMethodInfoWithReflexion ({instance},{method}); type:{instance.GetType ()}");
+#endif
+ return instance.GetType ().GetMethod (method, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
}
/// <summary>
/// set value, convert if required
/// <param name="value">Value</param>
/// <param name="destMember">Destination member</param>
static void setValueWithReflexion(object dest, object value, string destMember){
- Type destType = null;
+#if DEBUG_BINDING_FUNC_CALLS
+ Console.WriteLine ($"setValueWithReflexion (dest:{dest},value:{value},member:{destMember});");
+#endif
+ Type destType = null;
Type origType = null;
object convertedVal = null;
/// default value for valueType data.
/// </summary>
static object getValueWithReflexion(object instance, MemberInfo mi){
- object tmp = null;
+#if DEBUG_BINDING_FUNC_CALLS
+ Console.WriteLine ($"getValueWithReflexion ({instance},{mi});");
+#endif
+ object tmp = null;
Type dstType = null;
if (mi == null)
return null;
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 assembly where the type is defined
/// </summary>
//Console.WriteLine ($"*** search extension method: {t};{methodName} => key={key}");
MethodInfo mi = null;
- mi = GetExtensionMethods2 (Assembly.GetEntryAssembly (), t, methodName);
+ mi = GetExtensionMethods (Assembly.GetEntryAssembly (), t, methodName);
if (mi == null)
- mi = GetExtensionMethods2 (t.Module.Assembly, t, methodName);
+ mi = GetExtensionMethods (t.Module.Assembly, t, methodName);
//add key even if mi is null to prevent searching again and again for propertyless bindings
knownExtMethods.Add (key, mi);
return mi;
}
- static MethodInfo GetExtensionMethods2 (Assembly assembly, Type extendedType, string methodName)
+ public static MethodInfo GetExtensionMethods (Assembly assembly, Type extendedType, string methodName)
{
foreach (Type t in assembly.GetTypes ().Where
(ty => ty.IsDefined (typeof (ExtensionAttribute), false))) {
}
return null;
}
- #endregion
+#endregion
/// <summary>
/// Emits tree parsing command to fetch dest instance starting from orig node
Type t = instance.GetType ();
FieldInfo fiEvt = getEventHandlerField (t, eventName);
if (fiEvt == null) {
- #if DEBUG_BINDING
+#if DEBUG_BINDING
Debug.WriteLine ("RemoveHandlerByName: Event '" + eventName + "' not found in " + instance);
- #endif
+#endif
return;
}
EventInfo eiEvt = t.GetEvent (eventName);
foreach (Delegate d in multiDel.GetInvocationList()) {
if (d.Method.Name == delegateName) {
eiEvt.RemoveEventHandler (instance, d);
- #if DEBUG_BINDING
+#if DEBUG_BINDING
Debug.WriteLine ("\t{0} handler removed in {1} for: {2}", d.Method.Name,instance, eventName);
- #endif
+#endif
}
}
}
foreach (Delegate d in multiDel.GetInvocationList()) {
if (d.Target == target) {
eiEvt.RemoveEventHandler (instance, d);
- #if DEBUG_BINDING
+#if DEBUG_BINDING
Debug.WriteLine ("\t{0} handler removed in {1} for: {2}", d.Method.Name,instance, eventName);
- #endif
+#endif
}
}
}
}
internal static Delegate compileDynEventHandler(EventInfo sourceEvent, string expression, NodeAddress currentNode = null){
- #if DEBUG_BINDING
+#if DEBUG_BINDING
Debug.WriteLine ("\tCompile Event {0}: {1}", sourceEvent.Name, expression);
- #endif
+#endif
Type lopType = null;
else
lopType = currentNode.NodeType;
- #region Retrieve EventHandler parameter type
+#region Retrieve EventHandler parameter type
MethodInfo evtInvoke = sourceEvent.EventHandlerType.GetMethod ("Invoke");
ParameterInfo [] evtParams = evtInvoke.GetParameters ();
Type handlerArgsType = evtParams [1].ParameterType;
- #endregion
+#endregion
Type [] args = { CompilerServices.TObject, handlerArgsType };
DynamicMethod dm = new DynamicMethod ("dyn_eventHandler",
il.Emit (OpCodes.Ldarg_0); //load sender ref onto the stack, the current node
- #region Left operande
+#region Left operande
PropertyInfo lopPI = null;
//in dyn handler, no datasource binding, so single name in expression are also handled as current node property
lopPI = lopType.GetProperty (lop.Tokens [1]);
else
lop.emitGetTarget (il, cancel);
- #endregion
+#endregion
- #region RIGHT OPERANDES
+#region RIGHT OPERANDES
if (rop.IsStringConstant){
il.Emit (OpCodes.Ldstr, rop.Tokens[0]);
lop.emitSetProperty (il);
rop.emitGetProperty (il, cancelFinalSet);
lop.emitSetProperty (il);
}
- #endregion
+#endregion
il.Emit (OpCodes.Br, success);
DockWindow dw = null;
string wName = getConfAttrib (conf, ref i);
try {
- dw = IFace.Load (wName) as DockWindow;
+ dw = IFace.CreateInstance (wName) as DockWindow;
} catch {
dw = new DockWindow (IFace);
}
if (path == value)
return;
path = value;
- this.SetChild (IFace.Load (path));
+ this.SetChild (IFace.CreateInstance (path));
NotifyValueChanged ("Path", path);
}
}
if (string.IsNullOrEmpty(_template))
loadTemplate ();
else
- loadTemplate (IFace.Load (_template));
+ loadTemplate (IFace.CreateInstance (_template));
}
}
/// <summary>
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]));
+ this.SetChild (IFace.CreateInstance (IFace.DefaultTemplates[this.GetType ().FullName]));
}else
this.SetChild (template);
}
public static Window Show (Interface iface, string imlPath, bool modal = false){
lock (iface.UpdateMutex) {
- Window w = iface.AddWidget (imlPath) as Window;
+ Window w = iface.Load (imlPath) as Window;
w.Modal = modal;
return w;
}
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)
{
bool tryFindMember ()
{
+#if DEBUG_BINDING_FUNC_CALLS
+ Console.WriteLine ($"tryFindMember ({Address},{member})");
+#endif
if (member != null)
throw new Exception ("member already found");
if (Address == null)
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
+#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 ();
+ member = CompilerServices.GetExtensionMethods (a, t, mn);
}
- #endregion
+#endregion
return member != null;
}
/// create the valuechanged handler, the datasourcechanged handler and emit event handling
/// </summary>
void emitDataSourceBindings(IMLContext ctx, BindingDefinition bindingDef){
+#if DEBUG_BINDING_FUNC_CALLS
+ Console.WriteLine ($"emitDataSourceBindings: {bindingDef}");
+#endif
DynamicMethod dm = null;
ILGenerator il = null;
int dmVC = 0;
//will be used as origine value
string delName = "dyn_DSvalueChanged" + NewId;
if (!string.IsNullOrEmpty(bindingDef.TargetMember)){
- #region create valuechanged method
+#region create valuechanged method
dm = new DynamicMethod (delName,
typeof (void),
CompilerServices.argsBoundValueChange, true);
//when datasource of source graphic object changed
dmVC = dsValueChangedDynMeths.Count;
dsValueChangedDynMeths.Add (dm);
- #endregion
+#endregion
}
- #region emit dataSourceChanged event handler
+#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.
il.Emit (OpCodes.Brfalse, newDSIsNull);//new ds is null
}
- #region fetch initial Value
+#region fetch initial Value
if (!string.IsNullOrEmpty(bindingDef.TargetMember)){
il.Emit (OpCodes.Ldarg_2);//load new datasource
il.Emit (OpCodes.Ldfld, CompilerServices.fiDSCNewDS);
}
CompilerServices.emitConvert (il, piSource.PropertyType);
il.Emit (OpCodes.Callvirt, piSource.GetSetMethod ());
- #endregion
+#endregion
if (!string.IsNullOrEmpty(bindingDef.TargetMember)){
il.MarkLabel(cancelInit);
//store dschange delegate in instatiator instance for access while instancing graphic object
int delDSIndex = cachedDelegates.Count;
cachedDelegates.Add(dm.CreateDelegate (CompilerServices.ehTypeDSChange, this));
- #endregion
+#endregion
ctx.emitCachedDelegateHandlerAddition(delDSIndex, CompilerServices.eiDSChange);
- #if DEBUG_BINDING
+#if DEBUG_BINDING
Debug.WriteLine("\tDataSource ValueChanged: " + delName);
Debug.WriteLine("\tDataSource Changed: " + dm.Name);
- #endif
+#endif
}
/// <summary>
/// Two way binding for datasource, graphicObj=>dataSource link, datasource value has priority
Debug.WriteLine ("Member '{0}' not found in new DataSource '{1}' of '{2}'", destMember, dest, orig);
return;
}
- #if DEBUG_BINDING
+#if DEBUG_BINDING
Debug.WriteLine ("DS Reverse binding: Member '{0}' found in new DS '{1}' of '{2}'", destMember, dest, orig);
- #endif
+#endif
- #region ValueChanged emit
+#region ValueChanged emit
DynamicMethod dm = new DynamicMethod ("dyn_valueChanged" + NewId,
typeof (void), CompilerServices.argsBoundValueChange, true);
ILGenerator il = dm.GetILGenerator (256);
il.MarkLabel (endMethod);
il.Emit (OpCodes.Ret);
- #endregion
+#endregion
orig.ValueChanged += (EventHandler<ValueChangeEventArgs>)dm.CreateDelegate (typeof(EventHandler<ValueChangeEventArgs>), dest);
}
- #endregion
+#endregion
/// <summary>
/// search for graphic object type in crow assembly, if not found,
/// </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)
+ public GraphicObject Load (string path)
{
lock (UpdateMutex) {
- GraphicObject tmp = Load (path);
+ GraphicObject tmp = CreateInstance (path);
AddWidget (tmp);
return tmp;
}
/// </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)
+ public virtual GraphicObject CreateInstance (string path)
{
try {
return GetInstantiator (path).CreateInstance ();
volatile bool tooltipVisible = false;
protected void initTooltip () {
- ToolTipContainer = Load ("#Crow.Tooltip.template");
+ ToolTipContainer = CreateInstance ("#Crow.Tooltip.template");
Thread t = new Thread (toolTipThreadFunc);
t.IsBackground = true;
t.Start ();
#region Contextual menu
MenuItem ctxMenuContainer;
protected void initContextMenus (){
- ctxMenuContainer = Load ("#Crow.ContextMenu.template") as MenuItem;
+ ctxMenuContainer = CreateInstance ("#Crow.ContextMenu.template") as MenuItem;
ctxMenuContainer.LayoutChanged += CtxMenuContainer_LayoutChanged;
}
initCommands ();
- GraphicObject go = AddWidget (@"#Crow.Coding.ui.CrowIDE.crow");
+ GraphicObject go = Load (@"#Crow.Coding.ui.CrowIDE.crow");
go.DataSource = this;
mainDock = go.FindByName ("mainDock") as DockStack;
GraphicObject g = MainIFace.FindByName (path);
if (g != null)
return g as Window;
- g = MainIFace.AddWidget (path);
+ g = MainIFace.Load (path);
g.Name = path;
g.DataSource = dataSource;
return g as Window;
}
}
- public override GraphicObject Load (string path)
+ public override GraphicObject CreateInstance (string path)
{
ProjectFile pi;
//app.AddWidget (@"Interfaces/Divers/testFocus.crow").DataSource = app;
//app.AddWidget (@"Interfaces/Divers/testMenu.crow").DataSource = app;
//app.AddWidget (@"Interfaces/Divers/testVisibility.crow").DataSource = app;
- app.AddWidget (@"Interfaces/Divers/0.crow").DataSource = app;
+ app.Load (@"Interfaces/Divers/0.crow").DataSource = app;
//app.AddWidget (@"Interfaces/Splitter/1.crow").DataSource = app;
//app.AddWidget (@"Interfaces/GraphicObject/0.crow").DataSource = app;
//app.AddWidget (@"Interfaces/TemplatedContainer/test_Listbox.crow").DataSource = app;
using (Showcase app = new Showcase ()) {
//app.Keyboard.KeyDown += App_KeyboardKeyDown;
- GraphicObject g = app.AddWidget ("#Tests.ui.showcase.crow");
+ GraphicObject g = app.Load ("#Tests.ui.showcase.crow");
g.DataSource = app;
app.crowContainer = g.FindByName ("CrowContainer") as Container;
//I set an empty object as datasource at this level to force update when new
lock (UpdateMutex) {
try
{
- GraphicObject g = Load(fi.FullName);
+ GraphicObject g = CreateInstance(fi.FullName);
crowContainer.SetChild(g);
g.DataSource = this;
}
<OutputType>Exe</OutputType>
<RootNamespace>Tests</RootNamespace>
<AssemblyName>Tests</AssemblyName>
- <StartupObject>tests.MainClass</StartupObject>
+ <StartupObject>tests.Showcase</StartupObject>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ReleaseVersion>0.8.0</ReleaseVersion>
<OutputPath>$(SolutionDir)build/$(Configuration)</OutputPath>
<DefineConstants>DEBUG;TRACE;MEASURE_TIME</DefineConstants>
<IntermediateOutputPath>$(SolutionDir)build\obj\$(Configuration)</IntermediateOutputPath>
<OutputPath>$(SolutionDir)build\Debug</OutputPath>
- <EnvironmentVariables>
+<!-- <EnvironmentVariables>
<EnvironmentVariables>
<Variable name="MONO_CAIRO_DEBUG_DISPOSE" value="1" />
</EnvironmentVariables>
- </EnvironmentVariables>
+ </EnvironmentVariables>-->
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">