Exemplo n.º 1
0
        /// <summary>
        /// Creates a scripting method definition from the reflection info
        /// </summary>
        private static SciterNativeMethodDef DefineScriptingMethod(MethodInfo methodInfo, ScriptingMethodAttribute methodAttr)
        {
            return(new SciterNativeMethodDef()
            {
                name = methodAttr.Name ?? methodInfo.Name,

                // Method callback implementation
                method = (IntPtr hvm, ref JsonValue p_data_slot, IntPtr argv, int argc, ref JsonValue retval) =>
                {
                    try
                    {
                        var instance = default(object);
                        if (!methodInfo.IsStatic)
                        {
                            instance = InstanceProtector.GetInstance(p_data_slot.GetNativeObject());
                        }

                        var result = methodInfo.Invoke(instance, JsonPtrToArray(argv, argc));
                        retval = result == null ? new JsonValue() : new JsonValue(result);
                    }
                    catch (Exception ex)
                    {
                        SciterHostApi.SciterNativeThrow(hvm, ex.Message);
                    }
                }
            });
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a scripting property definitions
        /// </summary>
        private static SciterNativePropertyDef DefineScriptingProperty(PropertyInfo propertyInfo, ScriptingPropertyAttribute propertyAttr)
        {
            return(new SciterNativePropertyDef()
            {
                name = propertyAttr.Name ?? propertyInfo.Name,

                // Property callback implementation
                property = (IntPtr hvm, ref JsonValue p_data_slot, bool set, ref JsonValue retval) =>
                {
                    try
                    {
                        var instance = default(object);
                        if (!propertyInfo.GetGetMethod().IsStatic)
                        {
                            instance = InstanceProtector.GetInstance(p_data_slot.GetNativeObject());
                        }

                        retval = new JsonValue();
                        if (set)
                        {
                            propertyInfo.SetValue(instance, retval.GetValue(), null);
                        }
                        else
                        {
                            retval = new JsonValue(propertyInfo.GetValue(instance, null));
                        }
                    }
                    catch (Exception ex)
                    {
                        SciterHostApi.SciterNativeThrow(hvm, ex.Message);
                    }
                }
            });
        }
Exemplo n.º 3
0
        /// <summary>
        /// Releases resources associated with class instance
        /// </summary>
        private static void ScriptingDtor(IntPtr hvm, IntPtr p_data_slot)
        {
            var p_data_slot_value = Marshal.ReadIntPtr(p_data_slot);

            _registrations[hvm].Instances.Remove(p_data_slot_value);

            var instance = InstanceProtector.GetInstance(p_data_slot_value) as IDisposable;

            if (instance != null)
            {
                instance.Dispose();
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Handles behavior attach
        /// </summary>
        unsafe static partial void Host_HandleAttachBehavior(ISciterNotifications host, IntPtr pns)
        {
            var datantf = (SCN_ATTACH_BEHAVIOR *)pns;
            var e       = new AttachBehaviorEventArgs(Element.Create(datantf->element), datantf->GetBehaviorName());

            host.ProcessAttachBehavior(e);

            e.Behavior = e.Behavior ?? SciterFactory.ResolveBehavior(e.BehaviorName);
            if (e.Behavior != null)
            {
                datantf->elementProc   = ElementEventProcEntryPoint;
                datantf->elementTag    = InstanceProtector.Protect(e.Behavior);
                datantf->elementEvents = (EVENT_GROUPS)e.EventGroups;
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Bridge to sciter host callbacks
        /// </summary>
        private unsafe static IntPtr Host_NativeCallback(int uMsg, IntPtr wParam, IntPtr pns, IntPtr vParam)
        {
            using (var prot = ElementScope.Create())
            {
                var host = InstanceProtector.GetInstance(vParam) as ISciterNotifications;
                if (host != null)
                {
                    var ntf = (HL_NMHDR *)pns;
                    switch (ntf->code)
                    {
                    case HTMLAYOUT_NOTIFICATION.HLN_ATTACH_BEHAVIOR:
                        Host_HandleAttachBehavior(host, pns);
                        break;

                    case HTMLAYOUT_NOTIFICATION.HLN_DATA_LOADED:
                        Host_HandleDataLoaded(host, pns);
                        break;

                    case HTMLAYOUT_NOTIFICATION.HLN_LOAD_DATA:
                        Host_HandleLoadData(host, pns);
                        break;

                    case HTMLAYOUT_NOTIFICATION.HLN_DOCUMENT_COMPLETE:
                        Host_HandleDocumentComplete(host, pns);
                        break;

                    case HTMLAYOUT_NOTIFICATION.HLN_BEHAVIOR_CHANGED:
                    case HTMLAYOUT_NOTIFICATION.HLN_CONTROL_CREATED:
                    case HTMLAYOUT_NOTIFICATION.HLN_CREATE_CONTROL:
                    case HTMLAYOUT_NOTIFICATION.HLN_DESTROY_CONTROL:
                    case HTMLAYOUT_NOTIFICATION.HLN_DIALOG_CLOSE_RQ:
                    case HTMLAYOUT_NOTIFICATION.HLN_DIALOG_CREATED:
                    case HTMLAYOUT_NOTIFICATION.HLN_DOCUMENT_LOADED:
                    case HTMLAYOUT_NOTIFICATION.HLN_UPDATE_UI:
                        break;

                    default:
                        //There is a lot of notifications besides the HLN_
                        //Debug.WriteLine(String.Format("Invalid notification code: {0}", ntf->code));
                        break;
                    }
                }

                Debug.Assert(host != null, "Behavior object has been garbage collected");
                return(IntPtr.Zero);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Bridge to sciter host callbacks
        /// </summary>
        private unsafe static uint Host_NativeCallback(IntPtr pns, IntPtr callbackParam)
        {
            using (var prot = ElementScope.Create())
            {
                var host = InstanceProtector.GetInstance(callbackParam) as ISciterNotifications;
                if (host != null)
                {
                    var ntf = (SCN_CALLBACK_NOTIFICATION *)pns;
                    switch (ntf->code)
                    {
                    case SCITER_NOTIFICATION.SC_ATTACH_BEHAVIOR:
                        Host_HandleAttachBehavior(host, pns);
                        break;

                    case SCITER_NOTIFICATION.SC_DATA_LOADED:
                        Host_HandleDataLoaded(host, pns);
                        break;

                    case SCITER_NOTIFICATION.SC_LOAD_DATA:
                        Host_HandleLoadData(host, pns);
                        break;

                    case SCITER_NOTIFICATION.SC_CALLBACK_HOST:
                        Host_HandleCallbackHost(host, pns);
                        break;

                    case SCITER_NOTIFICATION.SC_DOCUMENT_COMPLETE:
                        Host_HandleDocumentComplete(host, pns);
                        break;

                    default:
                        Debug.Fail(String.Format("Invalid notification code: {0}", ntf->code));
                        break;
                    }
                }

                Debug.Assert(host != null, "Behavior object has been garbage collected");
                return(0);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Creates a scripting ctor definition from the reflection info
        /// </summary>
        private static SciterNativeMethodDef DefineCtorMethod(Type type)
        {
            return(new SciterNativeMethodDef()
            {
                name = "this",

                // Construction callback implementation
                method = (IntPtr hvm, ref JsonValue p_data_slot, IntPtr argv, int argc, ref JsonValue retval) =>
                {
                    try
                    {
                        var result = Activator.CreateInstance(type, JsonPtrToArray(argv, argc));
                        var data_slot_value = InstanceProtector.Protect(result);

                        p_data_slot.SetNativeObject(data_slot_value);
                        _registrations[hvm].Instances.Add(data_slot_value, result);
                    }
                    catch (Exception ex)
                    {
                        SciterHostApi.SciterNativeThrow(hvm, ex.Message);
                    }
                }
            });
        }
Exemplo n.º 8
0
        /// <summary>
        /// Bridge to sciter element callbacks
        /// </summary>
        private static unsafe bool Behavior_NativeCallback(IntPtr tag, IntPtr he, EVENT_GROUPS evtg, IntPtr prms)
        {
            using (var prot = ElementScope.Create())
            {
                bool handled  = false;
                var  behavior = InstanceProtector.GetInstance(tag) as ISciterBehavior;
                if (behavior != null)
                {
                    // TODO: Timer
                    switch (evtg)
                    {
                    case EVENT_GROUPS.HANDLE_INITIALIZATION:
                        Behavior_HandleInitialization(behavior, he, prms, ref handled);
                        break;

                    case EVENT_GROUPS.HANDLE_MOUSE:
                        Behavior_HandleMouseEvent(behavior, he, prms, ref handled);
                        break;

                    case EVENT_GROUPS.HANDLE_KEY:
                        Behavior_HandleKey(behavior, he, prms, ref handled);
                        break;

                    case EVENT_GROUPS.HANDLE_FOCUS:
                        Behavior_HandleFocusEvent(behavior, he, prms, ref handled);
                        break;

                    case EVENT_GROUPS.HANDLE_SCROLL:
                        Behavior_HandleScroll(behavior, he, prms, ref handled);
                        break;

                    case EVENT_GROUPS.HANDLE_TIMER:
                        Behavior_HandleTimer(behavior, he, prms, ref handled);
                        break;

                    case EVENT_GROUPS.HANDLE_SIZE:
                        Behavior_HandleSize(behavior, he, prms, ref handled);
                        break;

                    case EVENT_GROUPS.HANDLE_DRAW:
                        Behavior_HandleDraw(behavior, he, prms, ref handled);
                        break;

                    case EVENT_GROUPS.HANDLE_DATA_ARRIVED:
                        Behavior_HandleDataArrived(behavior, he, prms, ref handled);
                        break;

                    case EVENT_GROUPS.HANDLE_BEHAVIOR_EVENT:
                        Behavior_HandleBehaviorEvent(behavior, he, prms, ref handled);
                        break;

                    case EVENT_GROUPS.HANDLE_METHOD_CALL:
                        Behavior_HandleMethodCall(behavior, he, prms, ref handled);
                        break;

                    case EVENT_GROUPS.HANDLE_SCRIPTING_METHOD_CALL:
                        Behavior_HandleScriptingMethodCall(behavior, he, prms, ref handled);
                        break;

                    default:
                        break;
                    }
                }

                Debug.Assert(behavior != null, "Behavior object has been garbage collected");
                return(handled);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Assings host callback to the sciter window
        /// </summary>
        /// <param name="hWndSciter"></param>
        /// <param name="ntf"></param>
        public static void SciterSetCallback(IntPtr hWndSciter, ISciterNotifications ntf)
        {
            Debug.Assert(ntf != null, "Notification callback cannot be null");

            HTMLayoutSetCallback(hWndSciter, _nativeCallback, InstanceProtector.Protect(ntf));
        }
Exemplo n.º 10
0
 /// <summary>
 /// Attach/Detach ElementEventProc to the Sciter window.
 /// All events will start first here (in SINKING phase) and if not consumed will end up here.
 /// You can install Window EventHandler only once - it will survive all document reloads.
 /// </summary>
 public void WindowDetachEventHandler(IntPtr hWnd, ISciterBehavior bhv)
 {
     CheckResult(SciterWindowDetachEventHandler(hWnd, SciterHostApi.ElementEventProcEntryPoint, InstanceProtector.Protect(bhv)));
 }
Exemplo n.º 11
0
 /// <summary>
 /// Attach ElementEventProc to the element and subscribe it to events providede by subscription parameter
 /// See Sciter::attach_event_handler.
 /// </summary>
 public void AttachEventHandler(Element he, ISciterBehavior behavior)
 {
     CheckResult(SciterAttachEventHandler(he.Handle, SciterHostApi.ElementEventProcEntryPoint, InstanceProtector.Protect(behavior)));
 }
Exemplo n.º 12
0
        /// <summary>
        /// Attach/Detach ElementEventProc to the element
        /// See Sciter::event_handler.
        /// </summary>
        public void DetachEventHandler(Element he, ISciterBehavior behavior)
        {
            var r = SciterDetachEventHandler(he.Handle, SciterHostApi.ElementEventProcEntryPoint, InstanceProtector.Protect(behavior));

            // DetachEventHandler can return SCDOM_PASSIVE_HANDLE if element was detached from the tree
            CheckResult(r == ScDomResult.SCDOM_PASSIVE_HANDLE ? ScDomResult.SCDOM_OK : r);
        }
Exemplo n.º 13
0
 /// <summary>
 /// Assings host callback to the sciter window
 /// </summary>
 /// <param name="hWndSciter"></param>
 /// <param name="ntf"></param>
 public static void SciterSetCallback(IntPtr hWndSciter, ISciterNotifications ntf)
 {
     SciterSetCallback(hWndSciter, _nativeCallback, InstanceProtector.Protect(ntf));
 }