Ejemplo n.º 1
0
        private long OnChangeControl(IntPtr es, long obj,
                                     IntPtr args, int argCount)
        {
            if (argCount != 5)
            {
                return(MBApi.jsUndefined());
            }
            var    vPtr       = MBApi.jsArg(es, 0);
            var    vX         = MBApi.jsArg(es, 1);
            var    vY         = MBApi.jsArg(es, 2);
            var    vWidth     = MBApi.jsArg(es, 3);
            var    vHeight    = MBApi.jsArg(es, 4);
            IntPtr controlPtr = IntPtr.Zero;

            if (MBApi.jsIsString(vPtr))
            {
                var strPtr = ExtApi.GetJsString(es, vPtr);
                int n      = 0;
                if (!int.TryParse(strPtr, out n))
                {
                    return(MBApi.jsUndefined());
                }
                controlPtr = new IntPtr(n);
            }
            else if (MBApi.jsIsNumber(vPtr))
            {
                var ptr = MBApi.jsToInt(es, vPtr);
                controlPtr = new IntPtr(ptr);
            }
            else
            {
                return(MBApi.jsUndefined());
            }
            NativeControl control = NativeControl.FromHandle(controlPtr) as NativeControl;

            if (control == null)
            {
                return(MBApi.jsUndefined());
            }
            int x, y, width, height = 0;

            if (!MBApi.jsIsNumber(vX) ||
                !MBApi.jsIsNumber(vY) ||
                !MBApi.jsIsNumber(vWidth) ||
                !MBApi.jsIsNumber(vHeight))
            {
                return(MBApi.jsUndefined());
            }
            x      = MBApi.jsToInt(es, vX);
            y      = MBApi.jsToInt(es, vY);
            width  = MBApi.jsToInt(es, vWidth);
            height = MBApi.jsToInt(es, vHeight);
            control.SetBounds(x, y, width, height);
            return(MBApi.jsTrue());
        }
Ejemplo n.º 2
0
        private long OnCreateControl(IntPtr es, long obj,
                                     IntPtr args, int argCount)
        {
            if (argCount < 4)
            {
                return(MBApi.jsUndefined());
            }
            var vX = MBApi.jsArg(es, 0);
            var vY = MBApi.jsArg(es, 1);
            var vWidth = MBApi.jsArg(es, 2);
            var vHeight = MBApi.jsArg(es, 3);
            var disposeFun = MBApi.jsArg(es, 4);
            int x, y, width, height = 0;

            if (!MBApi.jsIsNumber(vX) ||
                !MBApi.jsIsNumber(vY) ||
                !MBApi.jsIsNumber(vWidth) ||
                !MBApi.jsIsNumber(vHeight))
            {
                return(MBApi.jsUndefined());
            }
            x      = MBApi.jsToInt(es, vX);
            y      = MBApi.jsToInt(es, vY);
            width  = MBApi.jsToInt(es, vWidth);
            height = MBApi.jsToInt(es, vHeight);
            string jsData = null;

            if (!MBApi.jsIsUndefined(disposeFun))
            {
                jsData = ExtApi.GetJsString(es, disposeFun);
            }
            var           mHandle = MBApi.jsGetWebView(es);
            NativeControl control = new NativeControl();

            control.WebView    = mHandle;
            control.Location   = new Point(x, y);
            control.Width      = width;
            control.Height     = height;
            control.DisposeFun = jsData;
            WebView parentView = GetParent(mHandle);

            if (parentView == null)
            {
                return(MBApi.jsUndefined());
            }
            parentView.Controls.Add(control);
            control.BringToFront();
            var handle = control.Handle.ToInt32();

            return(MBApi.jsToInt(es, handle));
        }