public void TestSciterValue() { //string[] arr = new string[] { "A", "B", "C" }; int[] arr = new int[] { 1, 2, 3 }; //SciterValue res = SciterValue.FromList(arr); SciterValue res = new SciterValue(); res.Append(new SciterValue(1)); res.Append(new SciterValue(1)); res.Append(new SciterValue(1)); string r = res.ToString(); string r2 = res.ToString(); string r3 = res.ToJSONString(SciterSharp.Interop.SciterXValue.VALUE_STRING_CVT_TYPE.CVT_JSON_LITERAL); { // http://sciter.com/forums/topic/erasing-sequence-elements-with-scitervalue/ SciterValue sv = SciterValue.FromJSONString("[1,2,3,4,5])"); sv[0] = SciterValue.Undefined; sv[2] = SciterValue.Undefined; SciterValue sv2 = SciterValue.FromJSONString("{one: 1, two: 2, three: 3}"); sv2["one"] = SciterValue.Undefined; } // Datetime { SciterValue sv = new SciterValue(DateTime.Now); } }
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; }
public SciterValue ToSV() { SciterValue sv = new SciterValue(); sv["kind"] = new SciterValue((int)kind); sv["hash"] = new SciterValue(hash); sv["arr_tags"] = SciterValue.FromList(arr_tags); sv["source"] = source; if (kind == EIconKind.COLLECTION) { sv["path"] = new SciterValue(path); } return(sv); }
protected override bool OnEvent(SciterElement sourceElement, SciterElement targetElement, BehaviorEvents type, IntPtr reason, SciterValue data, string eventName) { if (type == BehaviorEvents.DocumentReady) { //Host.ConnectToInspector(); } _logger?.LogTrace( "{NameOfMethod}(sourceElement: {SourceElement}; targetElement: {TargetElement}; type: {Type}; data: {DataString}; eventName: {EventName})", nameof(OnEvent), sourceElement?.Tag, targetElement?.Tag, type, data.AsString(), eventName); return(base.OnEvent(sourceElement, targetElement, type, reason, data, eventName)); }
public void Value_from_Dictionary() { var dictionary = new Dictionary <string, SciterValue> { { "int", SciterValue.Create(1) }, { "string", SciterValue.Create("string") }, { "double", SciterValue.Create(3d) }, { "color", SciterValue.Create(SciterColor.Khaki) } }; var actual = SciterValue.Create(dictionary); Assert.IsTrue(actual.IsMap); }
public static List <SciterElement> TreeNavigateTo(SciterElement origin_el, bool tree_nav) { Debug.Assert(origin_el != null); List <SciterElement> elstack = new List <SciterElement>(); List <uint> uidstack = new List <uint>(); List <string> tagnames = new List <string>(); SciterElement el_it = origin_el; do { elstack.Add(el_it); tagnames.Add(el_it.TagName()); uidstack.Add(el_it.UID); var el_parent = el_it.Parent; if (el_parent == null) { return(null); } el_it = el_parent; } while(el_it._he != State.g_el_frameroot._he); uidstack.Reverse(); tagnames.Reverse(); SciterValue sv_uid = new SciterValue(origin_el.UID); SciterValue sv_uidstack = SciterValue.FromList(uidstack); SciterValue sv_tagnames = SciterValue.FromList(tagnames); if (tree_nav) { dbg_on_navigate = true; el_tree.CallMethod("NavigateToPath", sv_uid, sv_uidstack); // does not generate Event.SELECT_SELECTION_CHANGED dbg_on_navigate = false; } WidgetTreePath.Instance.RecreateTagPath(origin_el.UID, uidstack, tagnames); SciterValue sv_details = Inspecting.ElemDetails(); if (sv_details != null && !sv_details.IsUndefined) // happens while waiting for CONTENT_CHANGED arriving { el_tree.CallMethod("RenderDetails", sv_details); } return(elstack); }
public bool Host_StartDnD(SciterElement el, SciterValue[] args, out SciterValue result) { string file = args[0].Get(""); int xView = args[1].Get(-1); int yView = args[2].Get(-1); new DnDOSX().StartDnD(file, xView, yView, () => { args[3].Call(); }); result = null; return(true); }
static void Main(string[] args) { var list = new List <int> { 123 }; var ss = SciterValue.FromObject(new { aa = list }); Console.WriteLine("Sciter: " + SciterX.Version); Console.WriteLine("Bitness: " + IntPtr.Size); // Sciter needs this for drag'n'drop support; STAThread is required for OleInitialize succeess int oleres = PInvokeWindows.OleInitialize(IntPtr.Zero); Debug.Assert(oleres == 0); // Create the window AppWnd = new SciterWindow(); var rc = new PInvokeUtils.RECT(); rc.right = 800; rc.bottom = 600; var wnd = AppWnd; //wnd.CreateWindow(rc, SciterXDef.SCITER_CREATE_WINDOW_FLAGS.SW_POPUP | SciterXDef.SCITER_CREATE_WINDOW_FLAGS.SW_MAIN | SciterXDef.SCITER_CREATE_WINDOW_FLAGS.SW_RESIZEABLE); wnd.CreateMainWindow(1500, 800); wnd.CenterTopLevelWindow(); wnd.Title = "TestCore"; wnd.Icon = Properties.Resources.IconMain; // Prepares SciterHost and then load the page AppHost = new Host(); var host = AppHost; host.Setup(wnd); host.AttachEvh(new HostEvh()); host.SetupPage("index.html"); //host.DebugInspect(); //byte[] css_bytes = File.ReadAllBytes(@"D:\ProjetosSciter\AssetsDrop\AssetsDrop\res\css\global.css"); //SciterX.API.SciterAppendMasterCSS(css_bytes, (uint) css_bytes.Length); Debug.Assert(!host.EvalScript("Utils").IsUndefined); // Show window and Run message loop wnd.Show(); PInvokeUtils.RunMsgLoop(); }
public Task ThrowException(SciterValue numerator, SciterValue denominator) { try { //This will purposely throw an exception! var value = numerator.AsInt32() / denominator.AsInt32(); return(Task.FromResult(SciterValue.Create(value))); } catch (Exception ex) { _logger.LogError(exception: ex, message: "{Message}", ex.Message); throw; } }
public static Library FromSV(SciterValue sv) { var lib = new Library() { sources = new List <Source>(), sources_sv = new List <SciterValue>() }; foreach (var sv_source in sv["sources"].AsEnumerable()) { Source source = new Source() { name = sv_source["name"].Get(""), url = sv_source["url"].Get(""), license = sv_source["license"].Get(""), licenseURL = sv_source["licenseURL"].Get(""), designer = sv_source["designer"].Get(""), designerURL = sv_source["designerURL"].Get(""), icons = new List <Icon>() }; lib.sources.Add(source); foreach (var sv_icon in sv_source["icons"].AsEnumerable()) { Icon icon = new Icon(); icon.kind = EIconKind.LIBRARY; icon.bounds.l = sv_icon["bounds"]["l"].Get(0.0); icon.bounds.t = sv_icon["bounds"]["t"].Get(0.0); icon.bounds.w = sv_icon["bounds"]["w"].Get(0.0); icon.bounds.h = sv_icon["bounds"]["h"].Get(0.0); source.icons.Add(icon); foreach (var sv_tag in sv_icon["arr_svgpath"].AsEnumerable()) { icon.arr_svgpath.Add(sv_tag.Get("")); } foreach (var sv_tag in sv_icon["arr_fill"].AsEnumerable()) { icon.arr_fill.Add(sv_tag.Get("")); } foreach (var sv_tag in sv_icon["arr_tags"].AsEnumerable()) { icon.arr_tags.Add(sv_tag.Get("")); } } } return(lib); }
public void Value_get_Keys() { var dictionary = new Dictionary <string, IConvertible> { { "key1", null }, { "key2", true }, { "key3", (byte)1 }, { "key4", 1 } }; var actual = SciterValue.Create(dictionary); Assert.IsTrue(actual.IsMap); Assert.AreEqual(dictionary.Keys, actual.Keys.Select(s => s.AsString())); }
public bool ResetByProj(SciterElement el, SciterValue[] args, out SciterValue result) { args[0].Isolate(); var hashes = args[0].Keys.Select(k => k.Get("")).ToList(); List <Icon> list = new List <Icon>(); foreach (var hash in hashes) { list.Add(Joiner._iconsByHash[hash]); } SetIconList(list); result = null; return(true); }
private ScriptExecutioner(object owner, SciterElement element, MethodInfo methodInfo, SciterValue[] arguments) { _owner = owner; _element = element; _methodInfo = methodInfo; _arguments = arguments; _methodParameters = _methodInfo.GetParameters(); _isAwaitable = _methodInfo.ReturnType.GetMethod(nameof(Task.GetAwaiter)) != null; _isWrappedCallback = _methodInfo.GetCustomAttribute <SciterCallbackWrapperAttribute>() != null; _callbackValue = _isWrappedCallback ? _arguments.Last() : null; _returnType = GetReturnType(); }
public OmniViewHost(SciterWindow wnd) { //Debug.Assert(wnd.VM == _vm_wnd.VM); SetupWindow(wnd._hwnd); _wnd = wnd; _doh = new SciterDOH(this); SciterValue sv = new SciterValue(); sv["omniview"] = new SciterValue(true); _wnd.SetMediaVars(sv); AttachEvh(new OmniViewEVH(wnd)); }
public bool ResetBySource(SciterElement el, SciterValue[] args, out SciterValue result) { int isource = args[0].Get(-1); List <Icon> icons = new List <Icon>(); Source source = Library._lib.sources[isource]; foreach (var icon in source.icons) { icons.Add(icon); } SetIconList(icons, false); result = null; return(true); }
public static DateTime GetDateTime() { if (!File.Exists(PathUpdateInfo)) { return(DateTime.Now); } SciterValue sv = SciterValue.FromJSONString(File.ReadAllText(PathUpdateInfo)); int epoch = sv["n"].Get(0); DateTime dt_ntp = Utils.FromUnixTime(epoch); if (DateTime.UtcNow > dt_ntp) { dt_ntp = DateTime.UtcNow; } return(dt_ntp); }
public SciterValue NativeGetPath(SciterValue vx, SciterValue vy, SciterValue vw, SciterValue vh, SciterValue vt, SciterValue vclosed) { double x = vx.AsDouble(); double y = vy.AsDouble(); double w = vw.AsDouble(); double h = vh.AsDouble(); double t = vt.AsDouble(); bool closed = vclosed.AsBoolean(); double[] samples = new double[6]; double[] sx = new double[6]; double[] sy = new double[6]; double dx = w / 5.0f; samples[0] = (1 + Math.Sin(t * 1.2345f + Math.Cos(t * 0.33457f) * 0.44f)) * 0.5f; samples[1] = (1 + Math.Sin(t * 0.68363f + Math.Cos(t * 1.3f) * 1.55f)) * 0.5f; samples[2] = (1 + Math.Sin(t * 1.1642f + Math.Cos(t * 0.33457f) * 1.24f)) * 0.5f; samples[3] = (1 + Math.Sin(t * 0.56345f + Math.Cos(t * 1.63f) * 0.14f)) * 0.5f; samples[4] = (1 + Math.Sin(t * 1.6245f + Math.Cos(t * 0.254f) * 0.3f)) * 0.5f; samples[5] = (1 + Math.Sin(t * 0.345f + Math.Cos(t * 0.03f) * 0.6f)) * 0.5f; for (int i = 0; i < 6; i++) { sx[i] = x + i * dx; sy[i] = y + h * samples[i] * 0.8f; } // creating path: var p = SciterPath.Create(); p.MoveTo(sx[0], sy[0], false); for (var i = 1; i < 6; ++i) { p.BezierCurveTo((sx[i - 1]) + dx * 0.5f, sy[i - 1], sx[i] - dx * 0.5f, sy[i], sx[i], sy[i], false); } if (closed) { p.LineTo(x + w, y + h, false); p.LineTo(x + 0, y + h, false); p.ClosePath(); } return(p.ToValue()); // wrap the path into sciter::value; }
public static void Setup() { var data = File.ReadAllBytes(Consts.AppDir_Shared + "id_store.json"); string json = Encoding.UTF8.GetString(data); SciterValue sv = SciterValue.FromJSONString(json); foreach (var sv_pack in sv.AsEnumerable()) { var pack = new StorePack() { id = sv_pack["id"].Get(""), name = sv_pack["name"].Get(""), author = sv_pack["author"].Get(""), url = sv_pack["url"].Get(""), icons = new List <Icon>(), colored = sv_pack["colored"].Get(false) }; Debug.Assert(pack.name != "" && pack.author != "" && pack.url != ""); pack.sv = pack.ToSV(); foreach (var sv_file in sv_pack["files"].AsEnumerable()) { string filename = sv_file.Get(""); string hash = Utils.CalculateMD5Hash($"Store-{pack.id}-{filename}"); pack.icons.Add(new Icon() { kind = EIconKind.STORE, hash = hash, path = Consts.DirUserData_Store + pack.id + "/" + filename, source = pack.sv, colored = pack.colored, arr_tags = new List <string>() { filename } }); } _store_packs.Add(pack); } Utils.Shuffle(_store_packs); }
public static bool Setup() { Console.WriteLine("Sciter " + SciterX.Version); #region Ion if (IonApp.GetStatus() != EIonStatus.ACTIVE || IonApp.IsTrial) { DlgLicense.ShowDialog(); } if (IonApp.GetStatus() != EIonStatus.ACTIVE) { return(false); } UpdateControl.Setup(); #endregion // Create the window AppWindow = new Window(); AppDebugger = new DebuggerHost(); AppHost = new Host(AppWindow); State.Setup(); // Args passing var sv = new SciterValue(); sv["t"] = new SciterValue(App.g_arg_t); sv["r"] = new SciterValue(App.g_arg_r); AppHost.CallFunction("View_Setup", sv); if (!string.IsNullOrEmpty(g_arg_page)) { //MessageBox.ShowMessageBox(AppWindow, g_arg_page); State.LoadURL(g_arg_page); } AppWindow.CenterTopLevelWindow(); AppWindow.Show(); #if DEBUG //AppHost.InvokePost(() => Tests.Run()); #endif return(true); }
public static SciterValue ElemDetails() { if (in_content_change) { return(null); } SciterElement el = g_el_inspected; SciterValue r = new SciterValue(); r["applied_rules"] = el.CallMethod("_applied_style_rules_"); r["used_style"] = el.CallMethod("_used_style_properties_"); r["states"] = new SciterValue((int)el.State); //import std.stdio; writeln("_applied_style_rules_ ", v1.to_string(), v1.is_undefined()); stdout.flush(); //import std.stdio; writeln("_used_style_properties_ ", v2.to_string()); stdout.flush(); return(r); }
public async Task CallMeBack(SciterElement element, SciterValue value, SciterValue onProgress, SciterValue onCompleted) { _callMeBackResetEvent = new ManualResetEventSlim(false); for (var i = 0; i < 201; i++) { if (_callMeBackResetEvent.IsSet) { break; } //Simulates a delay await Task.Delay(10); onProgress.Invoke(SciterValue.Create(i), SciterValue.Create(i / 200d * 100)); } onCompleted.Invoke(SciterValue.Create($"You have {(!_callMeBackResetEvent.IsSet ? "successfully completed" : "cancelled")} your task!"), SciterValue.Create(!_callMeBackResetEvent.IsSet)); }
protected override bool OnEvent(SciterElement sourceElement, SciterElement targetElement, BehaviorEvents type, IntPtr reason, SciterValue data, string eventName) { switch (type) { case BehaviorEvents.ElementExpanded: expandOption(targetElement); targetElement.CallMethod("optionExpanded", targetElement.Value); return(true); case BehaviorEvents.ElementCollapsed: collapseOption(targetElement); targetElement.CallMethod("optionCollapsed", targetElement.Value); return(true); } return(base.OnEvent(sourceElement, targetElement, type, reason, data, eventName)); }
public ApplicationHost(ILogger <ApplicationHost> logger, ApplicationWindow wnd, HostEventHandler hostEventHandler) : base(logger, wnd) { var host = this; host .AttachEventHandler(hostEventHandler) //.RegisterBehaviorHandler<VirtualTreeBehavior>() .RegisterBehaviorHandler <DragDropBehavior>() .RegisterBehaviorHandler <CustomWindowEventHandler>(); host.LoadPage("vtree.html", onFailed: (sciterHost, window) => throw new InvalidOperationException("Unable to load the requested page.")); host.Window.OnShow += (sender, args) => { var treeElement = wnd.RootElement.SelectFirst("widget#tree"); treeElement.AttachEventHandler <VirtualTreeBehavior>(); var button = wnd.RootElement.SelectFirst("#new-dialog"); button.FireEvent(new SciterBehaviorArgs() { Command = BehaviorEvents.ButtonClick, Target = button, Source = button, Name = "Hello", Data = SciterValue.Create("World!"), }); //var window2 = DevZH.UI.Window.AttachWindow(host.Window.WindowHandle); //var window3 = DevZH.UI.Window.AttachWindow(host.Window.WindowHandle); //window2.Title = window2.Title += "::libui"; //var t = window2.Title; //var t3 = window3.Title; #if DEBUG host.ConnectToInspector(); #endif }; }
static void Main(string[] args) { var list = new List <int> { 123 }; var ss = SciterValue.Create(new { aa = list }); Console.WriteLine($@"Sciter: {Sciter.SciterApi.SciterVersion()}"); Console.WriteLine("Bitness: " + IntPtr.Size); // Platform specific (required for GTK) SciterPlatform.Initialize(); // SciterCore needs this for drag 'n drop support (on Windows) SciterPlatform.EnableDragAndDrop(); // Create the window AppWindow = new SciterWindow() .CreateMainWindow(800, 600) .CenterWindow() .SetTitle("SciterCore.Windows::Core") .SetIcon(SciterTest.Core.Properties.Resources.IconMain); // Prepares SciterHost and then load the page AppHost = new AppHost(AppWindow); AppHost .SetupWindow(AppWindow) .AttachEventHandler(new AppEventHandler()); AppHost.SetupPage("index.html"); //AppHost.ConnectToInspector(); //byte[] css_bytes = File.ReadAllBytes(@"D:\ProjetosSciter\AssetsDrop\AssetsDrop\res\css\global.css"); //SciterX.API.SciterAppendMasterCSS(css_bytes, (uint) css_bytes.Length); Debug.Assert(!AppHost.EvalScript("Utils").IsUndefined); // Show window and Run message loop AppWindow.Show(); SciterPlatform.RunMessageLoop(); }
public Task StackTrace(SciterElement element, SciterValue onCompleted) { var stackTrace = new StackTrace(true); var stackFrame = stackTrace.GetFrame(0); var value = SciterValue.Create( new { MethodName = stackFrame?.GetMethod()?.Name, Parameters = stackFrame?.GetMethod()?.GetParameters().Select(s => new { s.Name, s.Position, Type = s.ParameterType.Name }), FileUri = new Uri(stackFrame?.GetFileName() ?? string.Empty).AbsoluteUri, FileName = Path.GetFileName(stackFrame?.GetFileName()), LineNumber = stackFrame?.GetFileLineNumber(), ColumnNumber = stackFrame?.GetFileColumnNumber() }); onCompleted.Invoke(value); return(Task.CompletedTask); }
public Task GetRuntimeInfo(SciterElement element, SciterValue onCompleted, SciterValue onError) { try { var value = SciterValue.Create( new { FrameworkDescription = System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription, ProcessArchitecture = System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture.ToString(), OSArchitecture = System.Runtime.InteropServices.RuntimeInformation.OSArchitecture.ToString(), OSDescription = System.Runtime.InteropServices.RuntimeInformation.OSDescription, SystemVersion = System.Runtime.InteropServices.RuntimeEnvironment.GetSystemVersion() }); onCompleted.Invoke(value); } catch (Exception e) { onError.Invoke(SciterValue.MakeError(e.Message)); } return(Task.CompletedTask); }
private ScriptEventResult ExceptionCallbackResult(Exception e) { if (!_isWrappedCallback || !_isAwaitable) { return(ScriptEventResult.Successful(SciterValue.MakeError(e?.Message))); } //TODO: Clean this up, maybe change the Dictionary<> implementation? var properties = (e) .GetType() .GetProperties(BindingFlags.Instance | BindingFlags.Public) .Where(w => typeof(IConvertible).IsAssignableFrom(w.PropertyType)) .ToDictionary(key => key.Name, value => value.GetValue(e) as IConvertible); //.ToDictionary(key => key.Name, value => SciterValue.Create(value.GetValue(e.InnerException))); properties.Add(nameof(Type), e?.GetType().FullName); _callbackValue?.Invoke(SciterValue.Null, SciterValue.Create(properties)); return(ScriptEventResult.Successful()); }
public void TestSciterValue() { //string[] arr = new string[] { "A", "B", "C" }; int[] arr = new int[] { 1, 2, 3 }; //SciterValue res = SciterValue.FromList(arr); SciterValue res = new SciterValue(); res.Append(new SciterValue(1)); res.Append(new SciterValue(1)); res.Append(new SciterValue(1)); string r = res.ToString(); string r2 = res.ToString(); string r3 = res.ToJSONString(SciterXValue.VALUE_STRING_CVT_TYPE.CVT_JSON_LITERAL); { // http://sciter.com/forums/topic/erasing-sequence-elements-with-scitervalue/ SciterValue sv = SciterValue.FromJSONString("[1,2,3,4,5])"); sv[0] = SciterValue.Undefined; sv[2] = SciterValue.Undefined; SciterValue sv2 = SciterValue.FromJSONString("{one: 1, two: 2, three: 3}"); sv2["one"] = SciterValue.Undefined; Assert.IsTrue(sv2["two"].Get(0) == 2); } // Datetime { var now = DateTime.Now; SciterValue sv = new SciterValue(now); Assert.IsTrue(sv.GetDate() == now); } // SciterValue.AsDictionary { SciterValue sv = SciterValue.FromJSONString("{ a: 1, b: true }"); var dic = sv.AsDictionary(); Assert.IsTrue(dic.Count == 2); } }
public void Value_from_IConvertible_Dictionary() { var dictionary = new Dictionary <string, IConvertible> { { "null", null }, { "bool", true }, { "byte", (byte)1 }, { "int", 1 }, { "string", "string" }, { "double", 0d }, { "uint", 0u }, { "decimal", 0m }, { "dateTime", DateTime.UtcNow.ToFileTime() }, { "color", SciterColor.Khaki } }; var actual = SciterValue.Create(dictionary); Assert.IsTrue(actual.IsMap); Assert.AreEqual(dictionary, actual.AsDictionary()); }
public SciterElement(SciterValue sv) { if (!sv.IsObject) { throw new ArgumentException("The given SciterValue is not a TIScript Element reference"); } var elementHandle = sv.GetObjectData(); if (elementHandle == IntPtr.Zero) { throw new ArgumentException("IntPtr.Zero received at SciterElement constructor"); } if (SciterApi.Sciter_UseElement(this.Handle).IsOk()) { _unuseElement = true; } _elementHandle = elementHandle; }
protected override bool OnEvent(SciterElement sourceElement, SciterElement targetElement, BehaviorEvents eventType, IntPtr reason, SciterValue data, string eventName) { switch (eventName) { case "waiting": if (data.IsString) { //element.SetHtml($"<text>{value.AsString()}</text>"); //source.SetAttributeValue("waiting", "true"); } else if (data.IsBool) { //source.SetAttributeValue("waiting", (string) null); //element.ClearText(); } break; } return(base.OnEvent(sourceElement, targetElement, eventType, reason, data, eventName)); }
public void TestSciterValue() { //string[] arr = new string[] { "A", "B", "C" }; int[] arr = new int[] { 1, 2, 3 }; //SciterValue res = SciterValue.FromList(arr); SciterCore.SciterValue res = new SciterCore.SciterValue(); res.Append(SciterValue.Create(1)); res.Append(SciterValue.Create(1)); res.Append(SciterValue.Create(1)); res.Append(SciterValue.MakeSymbol("symbol").Append(SciterValue.Create(1))); string r = res.ToString(); string r2 = res.ToString(); string r3 = res.AsJsonString(StringConversionType.JsonLiteral); { // http://sciter.com/forums/topic/erasing-sequence-elements-with-scitervalue/ SciterCore.SciterValue sv = SciterCore.SciterValue.FromJsonString("[1,2,3,4,5])"); sv[0] = SciterCore.SciterValue.Undefined; sv[2] = SciterCore.SciterValue.Undefined; SciterCore.SciterValue sv2 = SciterCore.SciterValue.FromJsonString("{one: 1, two: 2, three: 3}"); sv2["one"] = SciterCore.SciterValue.Undefined; Assert.IsTrue(sv2["two"].AsInt32(0) == 2); } // Datetime { var now = DateTime.Now; SciterValue sv = SciterValue.Create(now); Assert.IsTrue(sv.AsDateTime(false) == now); } // SciterValue.AsDictionary { SciterCore.SciterValue sv = SciterCore.SciterValue.FromJsonString("{ a: 1, b: true }"); var dic = sv.AsDictionary(); Assert.IsTrue(dic.Count == 2); } }
protected override bool OnScriptCall(SciterElement se, string name, SciterValue[] args, out SciterValue result) { switch(name) { case "Host_HelloWorld": result = new SciterValue("Hello World! (from native side)"); return true; } result = null; return false; }
protected override bool OnScriptCall(SciterElement se, string name, SciterValue[] args, out SciterValue result) { result = null; return false; }
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; }
public bool OnWhat(SciterElement el, SciterValue[] args, out SciterValue result) { result = null; return true; }
protected virtual bool OnEvent(SciterElement elSource, SciterElement elTarget, SciterXBehaviors.BEHAVIOR_EVENTS type, IntPtr reason, SciterValue data) { return false; }
protected override bool OnScriptCall(SciterElement se, string name, SciterValue[] args, out SciterValue result) { result = null; switch(name) { case "Host_DownloadFont": string savefolder = args[0].Get(""); string family = args[1].Get(""); SciterValue async_cbk = args[2]; string str = async_cbk.ToString(); Task.Run(() => { bool res; try { GAPI.DownloadFont(family, savefolder); res = true; } catch(Exception) { res = false; } Program.HostInstance.InvokePost(() => { async_cbk.Call(new SciterValue(res)); }); }); return true; } return false; }
public SCRIPTING_METHOD_PARAMS_Wraper(SCRIPTING_METHOD_PARAMS prms) { name = Marshal.PtrToStringAnsi(prms.name); args = new SciterValue[prms.argc]; result = SciterValue.Undefined; for(int i = 0; i < prms.argc; i++) args[i] = new SciterValue( (SciterXValue.VALUE) Marshal.PtrToStructure(IntPtr.Add(prms.argv, i * Marshal.SizeOf(typeof(SciterXValue.VALUE))), typeof(SciterXValue.VALUE)) ); }
/// <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); }