Exemplo n.º 1
0
        private void PopulateEmptyCells(MapDocumentContainer container)
        {
            var loop  = HostedControl.Default(container.WindowID);
            var index = 0;

            foreach (var rec in container.Table.Configuration.Rectangles)
            {
                var i = rec.Y;
                var j = rec.X;

                var c = container.MapDocumentControls.FirstOrDefault(x => x.Row == i && x.Column == j);
                if (c != null)
                {
                    continue;
                }

                var hc = new HostedControl
                {
                    WindowID   = container.WindowID,
                    Row        = i,
                    Column     = j,
                    Type       = loop[index].Type,
                    Serialised = loop[index].Serialised
                };
                index = (index + 1) % loop.Count;

                var ctrl = MakeControl(hc.Type, hc.Serialised);
                if (ctrl != null)
                {
                    container.SetControl(ctrl, hc.Column, hc.Row);
                }
            }
        }
Exemplo n.º 2
0
        private bool InterceptRightClick()
        {
            var mousePosition = MousePosition;

            foreach (var container in GetContainers())
            {
                var client = container.PointToClient(mousePosition);
                if (!container.ClientRectangle.Contains(client))
                {
                    continue;
                }

                foreach (var control in container.Table.Controls.OfType <Control>())
                {
                    var mapped = control.PointToClient(mousePosition);

                    if (mapped.X >= 0 && mapped.X < 40 && mapped.Y >= 0 && mapped.Y < FontHeight + 2)
                    {
                        var pos = container.Table.GetPositionFromControl(control);
                        var hc  = new HostedControl
                        {
                            WindowID = container.WindowID,
                            Row      = pos.Row,
                            Column   = pos.Column,
                        };
                        var mdc = GetControls().FirstOrDefault(x => x.Control == control);
                        ShowContextMenu(hc, mdc, mousePosition);
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemplo n.º 3
0
        internal virtual void Edit(CurrencyManager source, int row, int column)
        {
            if (!_isEditing) //if cell is just entering edit
            {
                object cellValue = base.GetCellValue(source, row);
                _orgValue = cellValue;
                UpdateHostedControl(cellValue);
                HostedControl.Focus();
            }
            _isEditing = true;

            this.EditRow = row;
        }
Exemplo n.º 4
0
        private void ShowContextMenu(HostedControl control, IMapDocumentControl mdc, Point screenPoint)
        {
            CreateContextMenu();

            foreach (var cmi in _contextMenu.Items.OfType <ContextMenuItem>())
            {
                var f = _controlFactories.Select(x => x.Value).FirstOrDefault(x => x.Type == cmi.Type);
                cmi.Checked = f != null && mdc != null && f.IsStyle(mdc, cmi.Style);
            }

            _contextControl = control;
            _contextMenu.Show(this, PointToClient(screenPoint));
        }
Exemplo n.º 5
0
        /// <summary>
        /// This method performs the login operation with the given credential field
        /// information to identify the controls in the form and the credentials to be populated.
        /// </summary>
        /// <param name="application"></param>
        public void DoLogin(object application)
        {
            HostedControl hostedApp               = (HostedControl)application;
            IntPtr        topWindowHandle         = hostedApp.TopLevelWindow.Handle;
            BindingList <LoginFieldRecord> fields = hostedApp.LoginFields;

            if (null == fields || fields.Count == 0)
            {
                return;
            }

            int setFieldCount = 0;

            // For each credential field, perform the required operation.
            foreach (LoginFieldRecord field in fields)
            {
                // Get the handle of the child control corresponding to the login field.
                IntPtr controlHandle = GetControlHandle(topWindowHandle, field.ControlSequence);

                // If the credential field is not found, then the auto sign-on is failed.
                if (IntPtr.Zero == controlHandle)
                {
                    throw new LoginFieldNotFoundException(field.LabelName);
                }

                switch (field.Operation)
                {
                // Set the text of the child window to the corresponding credential.
                case SET_OPERATION:
                {
                    Set(controlHandle, hostedApp.AgentCreds[setFieldCount]);
                    setFieldCount++;
                    break;
                }

                case CLICK_OPERATION:
                {
                    Click(topWindowHandle, controlHandle);
                    break;
                }
                }
            }
        }
        private static TreeNode GenerateHostedControlNode(HostedControl hostedControl, bool showInactive)
        {
            var hostedControlNode = new TreeNode(hostedControl.Name);

            hostedControlNode.Tag = hostedControl;
            if (hostedControl.StateCode == StateCode.Inactive)
            {
                hostedControlNode.ForeColor = Color.Gray;
            }

            foreach (var @event in hostedControl.Events)
            {
                if (@event.StateCode != StateCode.Inactive || (@event.StateCode == StateCode.Inactive && showInactive))
                {
                    var eventNode = GenerateEventNode(@event, showInactive);
                    hostedControlNode.Nodes.Add(eventNode);
                }
            }
            return(hostedControlNode);
        }
Exemplo n.º 7
0
 public void CreateNewWindow()
 {
     _shell.InvokeSync(() =>
     {
         var nextId    = Enumerable.Range(1, Windows.Count + 1).Except(Windows.Select(x => x.MapDocumentContainer.WindowID)).First();
         var window    = CreateWindow(MapDocumentControlWindowConfiguration.Default(nextId));
         var container = window.MapDocumentContainer;
         foreach (var hc in HostedControl.Default(nextId))
         {
             if (UpdateControl(hc))
             {
                 continue;
             }
             var ctrl = MakeControl(hc.Type, hc.Serialised);
             if (ctrl != null)
             {
                 container.SetControl(ctrl, hc.Column, hc.Row);
             }
         }
     });
 }
Exemplo n.º 8
0
        private void CreateContextMenu()
        {
            if (_contextMenu != null)
            {
                return;
            }

            _contextMenu = new ContextMenuStrip();
            foreach (var cf in _controlFactories.Select(x => x.Value))
            {
                if (_contextMenu.Items.Count > 0)
                {
                    _contextMenu.Items.Add(new ToolStripSeparator());
                }
                foreach (var kv in cf.GetStyles())
                {
                    _contextMenu.Items.Add(new ContextMenuItem(kv.Value, cf.Type, kv.Key));
                }
            }

            _contextMenu.Closed      += (s, e) => _contextControl = null;
            _contextMenu.ItemClicked += SetContextControl;
        }
Exemplo n.º 9
0
        private bool UpdateControl(HostedControl hc)
        {
            var container = GetContainer(hc.WindowID);

            if (container == null)
            {
                return(false);
            }

            // Try and find the control in the same slot
            var controlAt = container.Table.GetControlFromPosition(hc.Column, hc.Row);

            if (controlAt == null)
            {
                return(false);
            }

            // Find the corresponding map document control
            var mdc = container.MapDocumentControls.FirstOrDefault(x => x.Control.Control == controlAt);

            if (mdc == null)
            {
                return(false);
            }

            // Ensure that the control is the type we want
            var factory = _controlFactories.FirstOrDefault(x => x.Value.Type == hc.Type)?.Value;

            if (factory == null || !factory.IsType(mdc.Control))
            {
                return(false);
            }

            // Update the control instead of replacing it
            mdc.Control.SetSerialisedSettings(hc.Serialised);
            return(true);
        }
Exemplo n.º 10
0
        private void SetContextControl(object sender, ToolStripItemClickedEventArgs e)
        {
            if (_contextControl == null || !(e.ClickedItem is ContextMenuItem mi))
            {
                return;
            }

            var container = GetContainer(_contextControl.WindowID);

            if (container == null)
            {
                return;
            }

            var hc = new HostedControl
            {
                WindowID   = _contextControl.WindowID,
                Row        = _contextControl.Row,
                Column     = _contextControl.Column,
                Type       = mi.Type,
                Serialised = mi.Style
            };

            _shell.InvokeSync(() =>
            {
                if (UpdateControl(hc))
                {
                    return;
                }
                var ctrl = MakeControl(hc.Type, hc.Serialised);
                if (ctrl != null)
                {
                    container.SetControl(ctrl, hc.Column, hc.Row);
                }
            });
        }
Exemplo n.º 11
0
        public void LoadValues(ISettingsStore store)
        {
            var windowConfigs = store.Get <List <MapDocumentControlWindowConfiguration> >("WindowConfigurations")
                                ?? new List <MapDocumentControlWindowConfiguration> {
                new MapDocumentControlWindowConfiguration()
            };

            var containers = GetContainers().ToList();
            var windowIds  = windowConfigs.Select(x => x.WindowID).Union(containers.Select(x => x.WindowID)).ToList();

            // Ensure that controls are created on the UI thread
            _shell.InvokeSync(() =>
            {
                foreach (var id in windowIds)
                {
                    var config    = windowConfigs.FirstOrDefault(x => x.WindowID == id);
                    var container = containers.FirstOrDefault(x => x.WindowID == id);
                    if (config == null)
                    {
                        if (!(container?.WindowID > 0))
                        {
                            continue;
                        }

                        var window = GetWindow(container.WindowID);
                        if (window != null)
                        {
                            DestroyWindow(window, EventArgs.Empty);
                        }
                    }
                    else if (container == null)
                    {
                        CreateWindow(config);
                    }
                    else if (config.WindowID > 0)
                    {
                        var window = GetWindow(container.WindowID);
                        window?.SetConfiguration(config);
                    }
                    else
                    {
                        if (config.Configuration.IsValid())
                        {
                            container.Table.Configuration = config.Configuration;
                        }
                        container.Table.RowSizes    = config.RowSizes;
                        container.Table.ColumnSizes = config.ColumnSizes;
                    }
                }

                var controls = store.Get <List <HostedControl> >("Controls");
                if (controls == null || !controls.Any())
                {
                    controls = HostedControl.Default(0);
                }

                foreach (var hc in controls)
                {
                    if (UpdateControl(hc))
                    {
                        continue;
                    }
                    var ctrl      = MakeControl(hc.Type, hc.Serialised);
                    var container = GetContainer(hc.WindowID);
                    if (container != null && ctrl != null)
                    {
                        container.SetControl(ctrl, hc.Column, hc.Row);
                    }
                }
            });
        }
Exemplo n.º 12
0
 public GLFormRenderer(HostedControl control,
                       GLWindowsContext context)
 {
     _host    = control;
     _context = context;
 }