Ejemplo n.º 1
0
        public override Reply Run <T>(ControlsStorage <T> controls, IDictionary <string, dynamic> args)
        {
            CheckParamExists(args, "element_id");
            CheckValidControlId <T>(args["element_id"], controls);

            DynamicValueReply reply = new DynamicValueReply(-1);

            dynamic c = controls.GetControl(args["element_id"]);

            if (c is Visual)
            {
                Application.Current.Dispatcher.Invoke((Action) delegate
                {
                    HwndSource source = (HwndSource)HwndSource.FromVisual(c);
                    if (source != null)
                    {
                        IntPtr hWnd = source.Handle;
                        reply       = new DynamicValueReply(hWnd.ToInt64());
                    }
                    else
                    {
                        reply = new DynamicValueReply(null);
                    }
                });
            }
            return(reply);
        }
Ejemplo n.º 2
0
        public override Reply Run <T>(ControlsStorage <T> controls, IDictionary <string, dynamic> args)
        {
            CheckParamExists(args, "element_id");
            CheckValidControlId <T>(args["element_id"], controls);
            CheckParamExists(args, "name");

            object c = controls.GetControl(args["element_id"]);

            bool isExists           = false;
            DynamicValueReply reply = null;

            Application.Current.Dispatcher.Invoke((Action) delegate
            {
                PropertyInfo prop = c.GetType().GetProperty(args["name"]);
                FieldInfo field   = c.GetType().GetField(args["name"]);
                if (prop != null)
                {
                    isExists = true;
                    reply    = new DynamicValueReply(prop.GetValue(c, null));
                }
                else if (field != null)
                {
                    isExists = true;
                    reply    = new DynamicValueReply(field.GetValue(c));
                }
            });
            if (isExists)
            {
                return(reply);
            }
            else
            {
                throw new ErrorReplyException(ErrorCodes.NOT_FOUND, "no such field or property: " + args["name"]);
            }
        }
Ejemplo n.º 3
0
        public override Reply Run <T>(ControlsStorage <T> controls, IDictionary <string, dynamic> args)
        {
            CheckParamExists(args, "element_id");
            CheckValidControlId <T>(args["element_id"], controls);

            object c = controls.GetControl(args["element_id"]);

            DynamicValueReply reply = null;

            Application.Current.Dispatcher.Invoke((Action) delegate
            {
                Visual control = c as Visual;
                if (control != null)
                {
                    DependencyObject parentControl = VisualTreeHelper.GetParent(control);
                    if (parentControl != null)
                    {
                        reply = new DynamicValueReply((controls as ControlsStorage <DependencyObject>).RegisterControl(parentControl));
                    }
                    else
                    {
                        reply = new DynamicValueReply(null);
                    }
                }
                else
                {
                    reply = new DynamicValueReply(null);
                }
            });

            return(reply);
        }
Ejemplo n.º 4
0
        public override Reply Run <T>(ControlsStorage <T> controls, IDictionary <string, dynamic> args)
        {
            CheckParamExists(args, "element_id");
            CheckValidControlId <T>(args["element_id"], controls);

            dynamic           c     = controls.GetControl(args["element_id"]);
            DynamicValueReply reply = new DynamicValueReply(this.GetRect(c));

            return(reply);
        }
Ejemplo n.º 5
0
        public override Reply Run <T>(ControlsStorage <T> controls, IDictionary <string, dynamic> args)
        {
            CheckParamExists(args, "element_id");
            CheckValidControlId <T>(args["element_id"], controls);

            dynamic           c     = controls.GetControl(args["element_id"]);
            DynamicValueReply reply = null;

            Application.Current.Dispatcher.Invoke((Action) delegate
            {
                reply = new DynamicValueReply(GetNameString(c));
            });
            return(reply);
        }
Ejemplo n.º 6
0
        public override Reply Run <T>(ControlsStorage <T> controls, IDictionary <string, dynamic> args)
        {
            DynamicValueReply reply = new DynamicValueReply(-1);

            // In WPF there are two main concepts that pertain to focus: keyboard focus and logical focus.
            // Keyboard focus is used here (more: https://docs.microsoft.com/en-us/dotnet/desktop/wpf/advanced/focus-overview?view=netframeworkdesktop-4.8)
            IInputElement inputElem = null;

            Application.Current.Dispatcher.Invoke((Action) delegate
            {
                inputElem = Keyboard.FocusedElement;
            });

            if (inputElem != null && inputElem is DependencyObject)
            {
                DependencyObject focusedElem = inputElem as DependencyObject;
                reply = new DynamicValueReply((controls as ControlsStorage <DependencyObject>).RegisterControl(focusedElem));
            }

            return(reply);
        }