public static SciterPath FromSV(SciterValue sv) { IntPtr hpath; SciterXValue.VALUE v = sv.ToVALUE(); var r = _gapi.vUnWrapPath(ref v, out hpath); Debug.Assert(r == SciterXGraphics.GRAPHIN_RESULT.GRAPHIN_OK); SciterPath st = new SciterPath(); st._hpath = hpath; return(st); }
public static SciterValue CreateFunctor(object f) { SciterValue sv = new SciterValue(); List <MethodInfo> l = new List <MethodInfo>(); foreach (var mi in f.GetType().GetMethods()) { var mparams = mi.GetParameters(); if (mi.Attributes.HasFlag(MethodAttributes.Public) && mi.ReturnType == typeof(SciterValue) && mparams.Length == 1 && mparams[0].ParameterType == typeof(SciterValue[])) { sv[mi.Name] = new SciterValueFunctor(); } } return(sv); }
public SciterValue Call(IList <SciterValue> args, SciterValue self = null, string url_or_script_name = null) { Debug.Assert(IsFunction || IsObjectFunction); SciterValue rv = new SciterValue(); SciterXValue.VALUE[] arr_VALUE = args.Select(sv => sv.data).ToArray(); if (self == null) { self = SciterValue.Undefined; } _api.ValueInvoke(ref data, ref self.data, (uint)args.Count, args.Count == 0 ? null : arr_VALUE, out rv.data, null); return(rv); }
public static SciterText FromSV(SciterValue sv) { IntPtr htext; SciterXValue.VALUE v = sv.ToVALUE(); var r = _gapi.vUnWrapText(ref v, out htext); Debug.Assert(r == SciterXGraphics.GRAPHIN_RESULT.GRAPHIN_OK); SciterText st = new SciterText(); st._htext = htext; return(st); }
public SciterElement(SciterValue sv) { if (!sv.IsObject) { throw new ArgumentException("The given SciterValue is not a TIScript Element reference"); } IntPtr he = sv.GetObjectData(); if (he == IntPtr.Zero) { throw new ArgumentException("IntPtr.Zero received at SciterElement constructor"); } _he = he; }
private static SciterValue FromObjectRecurse(object obj, List <object> anti_recurse, int deep) { if (deep++ == 10) { throw new Exception("Recursion too deep"); } if (obj is IConvertible) { return(new SciterValue(obj as IConvertible)); } if (anti_recurse.Contains(obj)) { throw new Exception("Found recursive property"); } anti_recurse.Add(anti_recurse); var t = obj.GetType(); if (t.GetInterface("IEnumerable") != null) { SciterValue sv_arr = new SciterValue(); MethodInfo castMethod = typeof(Enumerable).GetMethod("Cast") .MakeGenericMethod(new Type[] { typeof(object) }); var castedObject = (IEnumerable <object>)castMethod.Invoke(null, new object[] { obj }); foreach (var item in castedObject) { sv_arr.Append(FromObjectRecurse(item, anti_recurse, deep)); } return(sv_arr); } var sv = new SciterValue(); foreach (var prop in t.GetProperties()) { if (prop.CanRead) { var val = prop.GetValue(obj); sv[prop.Name] = FromObjectRecurse(val, anti_recurse, deep); } } return(sv); }
public SciterValue Call(IList <SciterValue> args, SciterValue self = null, string url_or_script_name = null) { if (!IsFunction && !IsObjectFunction) { throw new Exception("Can't Call() this SciterValue because it is not a function"); } SciterValue rv = new SciterValue(); SciterXValue.VALUE[] arr_VALUE = args.Select(sv => sv._data).ToArray(); if (self == null) { self = SciterValue.Undefined; } _api.ValueInvoke(ref _data, ref self._data, (uint)args.Count, args.Count == 0 ? null : arr_VALUE, out rv._data, null); return(rv); }
public static SciterValue FromList <T>(IList <T> list) where T : /*struct,*/ IConvertible { Debug.Assert(list != null); SciterValue sv = new SciterValue(); if (list.Count == 0) { _api.ValueIntDataSet(ref sv._data, 0, (uint)SciterXValue.VALUE_TYPE.T_ARRAY, 0); return(sv); } for (int i = 0; i < list.Count; i++) { sv.SetItem(i, new SciterValue(list[i])); } return(sv); }
/// <summary> /// Constructs a TIScript array T[] where T is a basic type like int or string /// </summary> public static SciterValue FromList <T>(IEnumerable <T> list) where T : /*struct,*/ IConvertible { Debug.Assert(list != null); SciterValue sv = new SciterValue(); if (list.Count() == 0) { _api.ValueIntDataSet(ref sv._data, 0, (uint)SciterXValue.VALUE_TYPE.T_ARRAY, 0); return(sv); } int i = 0; foreach (var item in list) { sv.SetItem(i++, new SciterValue(item)); } return(sv); }
/// <summary> /// Runs the inspector process, waits 1 second, and calls view.connectToInspector() to inspect your page. /// (Before everything it kills any previous instance of the inspector process) /// </summary> /// <param name="inspector_exe_path">Path to the inspector executable, can be an absolute or relative path.</param> public void DebugInspect(string inspector_exe_path) { var ps = Process.GetProcessesByName(inspector_exe_path); foreach (var p in ps) { p.Kill(); } #if WINDOWS if (!File.Exists(inspector_exe_path) && !File.Exists(inspector_exe_path + ".exe")) { inspector_exe_path = AppDomain.CurrentDomain.BaseDirectory + inspector_exe_path; } #elif OSX if (!File.Exists(inspector_exe_path)) { inspector_exe_path = AppDomain.CurrentDomain.BaseDirectory + "../../../" + inspector_exe_path; } #else if (!File.Exists(inspector_exe_path)) { inspector_exe_path = AppDomain.CurrentDomain.BaseDirectory + inspector_exe_path; } #endif var po = Process.Start(inspector_exe_path); if (po.HasExited) { throw new Exception("Could not run inspector. Make sure Sciter DLL is also present in the inspector tool directory."); } Task.Run(() => { Thread.Sleep(1000); InvokePost(() => { SciterValue connect_api = EvalScript("view.connectToInspector()"); }); }); }
public SciterValue(Action <SciterValue[]> func) { SciterXValue.FPTR_NATIVE_FUNCTOR_INVOKE fnfi; SciterXValue.FPTR_NATIVE_FUNCTOR_RELEASE fnfr; GCHandle fnfi_gch = new GCHandle(); GCHandle fnfr_gch = new GCHandle(); GCHandle func_gch = GCHandle.Alloc(func); fnfi = (IntPtr tag, uint argc, IntPtr argv, out SciterXValue.VALUE retval) => { // Get the list of SciterXValue.VALUE from the ptr SciterValue[] args = new SciterValue[argc]; for (int i = 0; i < argc; i++) { args[i] = new SciterValue((SciterXValue.VALUE)Marshal.PtrToStructure(IntPtr.Add(argv, i * Marshal.SizeOf(typeof(SciterXValue.VALUE))), typeof(SciterXValue.VALUE))); } func(args); retval = new SciterXValue.VALUE(); return(true); }; fnfr = (IntPtr tag) => { // seems to never be called -> Sciter engine bug fnfi_gch.Free(); fnfr_gch.Free(); func_gch.Free(); return(true); }; fnfi_gch = GCHandle.Alloc(fnfi, GCHandleType.Normal); fnfr_gch = GCHandle.Alloc(fnfr, GCHandleType.Normal); func_gch = GCHandle.Alloc(func, GCHandleType.Normal); _api.ValueInit(out _data); _api.ValueNativeFunctorSet(ref _data, fnfi, fnfr, IntPtr.Zero); }
public SciterValue(Func <SciterValue[], SciterValue> func) { SciterXValue.FPTR_NATIVE_FUNCTOR_INVOKE fnfi = (IntPtr tag, uint argc, IntPtr argv, out SciterXValue.VALUE retval) => { // Get the list of SciterXValue.VALUE from the ptr SciterValue[] args = new SciterValue[argc]; for (int i = 0; i < argc; i++) { args[i] = new SciterValue((SciterXValue.VALUE)Marshal.PtrToStructure(IntPtr.Add(argv, i * Marshal.SizeOf(typeof(SciterXValue.VALUE))), typeof(SciterXValue.VALUE))); } retval = func(args).ToVALUE(); return(true); }; SciterXValue.FPTR_NATIVE_FUNCTOR_RELEASE fnfr = (IntPtr tag) => { return(true); }; _api.ValueInit(out _data); _api.ValueNativeFunctorSet(ref _data, fnfi, fnfr, IntPtr.Zero); }
protected virtual bool OnScriptCall(SciterElement se, string name, SciterValue[] args, out SciterValue result) { var method = this.GetType().GetMethod(name); if (method != null) { // This base class tries to handle it by searching for a method with the same 'name' object[] call_parameters = new object[] { se, args, null }; Debug.Assert(call_parameters.Length == 3); // Signature of that method should be: // bool MethodName(SciterElement el, SciterValue[] args, out SciterValue result) // // Verify correct signature: Debug.Assert(method.ReturnType == typeof(Boolean)); Debug.Assert(method.GetParameters().Length == 3); Debug.Assert(method.GetParameters()[0].ParameterType.Name == "SciterElement"); Debug.Assert(method.GetParameters()[1].ParameterType.Name == "SciterValue[]"); Debug.Assert(method.GetParameters()[2].ParameterType.Name == "SciterValue&"); // invoke method and verify return bool res = (bool)method.Invoke(this, call_parameters); Debug.Assert(call_parameters[2] == null || call_parameters[2].GetType().IsAssignableFrom(typeof(SciterValue))); result = call_parameters[2] as SciterValue; return(res); } // not handled result = null; return(false); }
/// <summary> /// For example media type can be "handheld:true", "projection:true", "screen:true", etc. /// By default sciter window has "screen:true" and "desktop:true"/"handheld:true" media variables. /// Media variables can be changed in runtime. This will cause styles of the document to be reset. /// </summary> /// <param name="mediaVars">Map that contains name/value pairs - media variables to be set</param> public bool SetMediaVars(SciterValue mediaVars) { SciterXValue.VALUE v = mediaVars.ToVALUE(); return(_api.SciterSetMediaVars(_hwnd, ref v)); }
public SciterValue(SciterValue vother) { _api.ValueInit(out data); _api.ValueCopy(out data, ref vother.data); }
protected virtual bool OnScriptCall(SciterElement se, string name, SciterValue[] args, out SciterValue result) { result = null; return(false); }
public void Append(SciterValue val) { _api.ValueNthElementValueSet(ref data, Length, ref val.data); }
public void SetItem(SciterValue key, SciterValue val) { var vr = _api.ValueSetValueToKey(ref data, ref key.data, ref val.data); Debug.Assert(vr == SciterXValue.VALUE_RESULT.HV_OK); }
public void SetItem(int i, SciterValue val) { var vr = _api.ValueNthElementValueSet(ref data, i, ref val.data); Debug.Assert(vr == SciterXValue.VALUE_RESULT.HV_OK); }
static SciterValue() { Undefined = new SciterValue(); Null = new SciterValue(); Null.data.t = (uint)SciterXValue.VALUE_TYPE.T_NULL; }
protected virtual bool OnScriptCall(SciterElement se, string name, SciterValue[] args, out SciterValue result) { result = null; var method = GetType().GetMethod(name); if (method != null) { // This base class tries to handle it by searching for a method with the same 'name' var mparams = method.GetParameters(); // match signature: // 'void MethodName()' or 'SciterValue MethodName()' { if (mparams.Length == 0 && (method.ReturnType == typeof(void) || method.ReturnType == typeof(SciterValue))) { var ret = method.Invoke(this, null); if (method.ReturnType == typeof(SciterValue)) { result = (SciterValue)ret; } return(true); } } // match signature: // 'void MethodName(SciterValue[] args)' or 'SciterValue MethodName(SciterValue[] args)' { if (mparams.Length == 1 && mparams[0].ParameterType.Name == "SciterValue[]" && (method.ReturnType == typeof(void) || method.ReturnType == typeof(SciterValue))) { object[] call_parameters = new object[] { args }; var ret = method.Invoke(this, call_parameters); if (method.ReturnType == typeof(SciterValue)) { result = (SciterValue)ret; } return(true); } } // match signature: // bool MethodName(SciterElement el, SciterValue[] args, out SciterValue result) { if (method.ReturnType == typeof(bool) && mparams.Length == 3 && mparams[0].ParameterType.Name == "SciterElement" && mparams[1].ParameterType.Name == "SciterValue[]" && mparams[2].ParameterType.Name == "SciterValue&") { object[] call_parameters = new object[] { se, args, null }; bool res = (bool)method.Invoke(this, call_parameters); Debug.Assert(call_parameters[2] == null || call_parameters[2].GetType().IsAssignableFrom(typeof(SciterValue))); result = call_parameters[2] as SciterValue; return(res); } } } // not handled return(false); }
protected virtual bool OnEvent(SciterElement elSource, SciterElement elTarget, SciterXBehaviors.BEHAVIOR_EVENTS type, IntPtr reason, SciterValue data) { return(false); }