Esempio 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);
                    }
                }
            });
        }
Esempio 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);
                    }
                }
            });
        }
Esempio 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();
            }
        }
Esempio n. 4
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);
            }
        }
Esempio n. 5
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);
            }
        }
Esempio n. 6
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);
            }
        }