private static bool GridSync_DisplayMode(IGridBlock_Base grid, IGridControl gridControl, enGrid_BlockDisplayType displayMode)
        {
            var result = false;

            switch (displayMode)
            {
            case enGrid_BlockDisplayType.Address: gridControl.Text = grid.Name_Caption; break;

            case enGrid_BlockDisplayType.Name: gridControl.Text = grid.Name_Control; break;

            case enGrid_BlockDisplayType.Value:
            {
                var state = grid as IGridBlock_State;
                if (state == null)
                {
                    return(false);
                }
                if (Double.IsNaN(state.State_ValueDouble))
                {
                    gridControl.Text = "?";
                }
                else
                {
                    gridControl.Text = state.State_ValueDouble.zObject().AsStr();
                }
                break;
            }
            }
            return(result);
        }
        private void onGridClick(IGridControl sender)
        {
            // Fired when mouse click on a grid

            IGridBlock_Base gridData = sender.GridState;
            var             caption  = gridData.Name_Caption;

            if (radioClick.Checked)
            {
                // Click event message
                if (gridData._Parent != null)
                {
                    caption = gridData._Parent.Name_Caption + " x " + caption;
                    if (gridData._Parent._Parent != null)
                    {
                        caption = gridData._Parent._Parent.Name_Caption + " x " + caption;
                    }
                }
                MessageBox.Show(caption, "Grid Feedback");
            }
            if (radioSelect.Checked)
            {
                // Do selection of grids
                if (ModifierKeys.HasFlag(Keys.Control) == false && ModifierKeys.HasFlag(Keys.Shift) == false)
                {
                    RefreshGrid();                                                                                            // Remove previous selections
                }
                _SelectedControls.Add(sender);
                var gridState = gridData as IGridBlock_State;
                sender.BackColor = Color.CadetBlue;
            }
        }
 ///<summary>
 /// Initialise the grid with the appropriate control factory.
 ///</summary>
 ///<param name="gridControl"></param>
 ///<param name="controlFactory"></param>
 public GridInitialiser(IGridControl gridControl, IControlFactory controlFactory)
 {
     if (gridControl == null) throw new ArgumentNullException("gridControl");
     if (controlFactory == null) throw new ArgumentNullException("controlFactory");
     Grid = gridControl;
     _controlFactory = controlFactory;
     _gridBaseInitialiser = new GridBaseInitialiser(Grid.Grid, controlFactory);
 }
Example #4
0
 /// <summary>Try to find the specific grid control.</summary>
 /// <param name="childname">The name of the control to find.</param>
 /// <param name="gridControl">The grid control.</param>
 /// <returns></returns>
 private bool GridControl_Get(string childname, out IGridControl gridControl)
 {
     if (_gridControls.TryGetValue(childname, out gridControl))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
        private static bool GridSync_Visible(IGridControl gridControl, bool visible)
        {
            var result = false;

            if (gridControl.Visible != visible)
            {
                gridControl.Visible         = visible;
                gridControl._Parent.Visible = visible;
                result = true;
            }
            return(result);
        }
Example #6
0
 ///<summary>
 /// Initialise the grid with the appropriate control factory.
 ///</summary>
 ///<param name="gridControl"></param>
 ///<param name="controlFactory"></param>
 public GridInitialiser(IGridControl gridControl, IControlFactory controlFactory)
 {
     if (gridControl == null)
     {
         throw new ArgumentNullException("gridControl");
     }
     if (controlFactory == null)
     {
         throw new ArgumentNullException("controlFactory");
     }
     Grid                 = gridControl;
     _controlFactory      = controlFactory;
     _gridBaseInitialiser = new GridBaseInitialiser(Grid.Grid, controlFactory);
 }
Example #7
0
        private void onGridClick(IGridControl sender)
        {
            // Fired when mouse click on a grid
            var state   = sender.GridState;
            var caption = state.Name_Caption;

            if (state._Parent != null)
            {
                caption = state._Parent.Name_Caption + " x " + caption;
                if (state._Parent._Parent != null)
                {
                    caption = state._Parent._Parent.Name_Caption + " x " + caption;
                }
            }
            MessageBox.Show(caption, "GridFeedback");
        }
Example #8
0
        /// <summary>Setup a new grids control (micro, sub or macro).</summary>
        /// <param name="parentRowControl">The parent control.</param>
        /// <param name="gridControl">The grid control.</param>
        /// <param name="width">The width.</param>
        /// <param name="color"></param>
        /// <exception cref="System.ArgumentNullException">
        /// </exception>
        private void GridControl_SetupBlock(IGridControl parentRowControl, IGridControl gridControl, int width, Color color)
        {
            #region Check input parameters
            // Check the control
            if (gridControl == null)
            {
                throw new ArgumentNullException(nameof(gridControl));
            }

            // Check parent
            if (parentRowControl == null)
            {
                throw new ArgumentNullException(nameof(parentRowControl));
            }
            var parent = parentRowControl as GridControl_Row;
            if (parent == null)
            {
                throw new ArgumentNullException(nameof(parent));
            }
            #endregion

            // Set the parent & add events
            var control = gridControl as Control;
            if (control != null)
            {
                if (control.Parent != parent)
                {
                    parent.Controls.Add(control);
                }
                control.Click -= ClickEvent;
                control.Click += ClickEvent;
                control.BringToFront();
                control.Dock      = DockStyle.Left;
                control.Top       = 0;
                control.Left      = 0;
                control.Width     = width;
                control.BackColor = color;
            }

            #region These properties are not used

            //gridBlock.Height = 20;   // The height does not matter
            //gridBlock.BackColor = System.Drawing.Color.White;
            //button.UseVisualStyleBackColor = false;

            #endregion
        }
        /// <summary>Creates the new child grids.</summary>
        /// <param name="grid">The grid.</param>
        /// <param name="settings">The settings.</param>
        /// <param name="rows">The rows.</param>
        /// <param name="cols">The cols.</param>
        public void CreateNewChildGrids(IGridControl grid, GridControl_Settings settings, int rows, int cols)
        {
            var gridState = grid.GridState;
            var gridMacro = gridState as GridBlock_3Macro;

            if (gridMacro != null)
            {
                gridMacro.CreateSubGrids(OnGridCreate, OnGridRowCreate, settings, rows, cols, 0, 0);
            }

            var gridsub = gridState as GridBlock_2Sub;

            if (gridsub != null)
            {
                gridsub.CreateMicroGrids(OnGridCreate, OnGridRowCreate, settings, rows, cols);
            }
        }
        private static bool GridSync_Color(IGridBlock_State grid, IGridControl gridControl, Color defaultColor)
        {
            var result = false;

            if (grid == null || grid.State_Color == Color.Black)  // Default color
            {
                if (gridControl.BackColor != defaultColor)
                {
                    gridControl.BackColor = defaultColor;
                    result = true;
                }
            }
            else
            {
                gridControl.BackColor = grid.State_Color;
            }
            return(result);
        }
        private static bool GridSync_Size(IGridBlock_State grid, IGridControl gridControl, int controlWidth, int controlHeight)
        {
            return(false);
            ////if (gridControl.Text == "5.1") gridControl.Text = "5.1";
            //var result = false;
            //if (gridControl.Width != controlWidth)
            //{
            //    gridControl.Width = controlWidth;
            //    result = true;
            //}
            //if (grid != null && grid.State_Col != 1) return result;

            //var parent = gridControl._Parent;
            //if (parent.Height != controlHeight)
            //{
            //    parent.Height = controlHeight;
            //    result = true;
            //}
            //return result;
        }
Example #12
0
        /// <summary>Setup a new row control.</summary>
        /// <param name="parentControl">The parent control.</param>
        /// <param name="rowControl">The row control.</param>
        /// <param name="height">The height.</param>
        /// <exception cref="System.ArgumentNullException">
        /// </exception>
        private void GridControl_SetupRow(IGridControl parentControl, IGridControl rowControl, int height)
        {
            #region Check input parameters
            // Check row
            if (rowControl == null)
            {
                throw new ArgumentNullException(nameof(rowControl));
            }
            var row = rowControl as GridControl_Row;
            if (row == null)
            {
                throw new ArgumentNullException(nameof(row));
            }

            // Check parent
            if (parentControl == null)
            {
                throw new ArgumentNullException(nameof(parentControl));
            }
            var parent = parentControl as GridControl_Block;
            if (parent == null)
            {
                throw new ArgumentNullException(nameof(parent));
            }
            #endregion

            if (row.Parent != parent)
            {
                parent.Controls.Add(row);
            }
            row.BringToFront();

            row.BorderStyle = BorderStyle.FixedSingle;
            row.Dock        = DockStyle.Top;
            row.Location    = new Point(3, 16);
            //rowPanel.Name = name;
            row.Height = height;
            //panel.TabIndex = 2;
            //row.Click -= ClickEvent;
            //row.Click += ClickEvent;
        }
Example #13
0
        public IResultGrid GetFocusedResultGrid()
        {
            BindingFlags bindingFlags = BindingFlags.NonPublic | BindingFlags.Instance;

            IScriptFactory      scriptFactor     = ServiceCache.ScriptFactory;
            IVsMonitorSelection monitorSelection = ServiceCache.VSMonitorSelection;

            object editorControl = ServiceCache.ScriptFactory
                                   .GetType()
                                   .GetMethod("GetCurrentlyActiveFrameDocView", bindingFlags)
                                   .Invoke(scriptFactor, new object[] { monitorSelection, false, null });

            FieldInfo resultControlField = editorControl.GetType()
                                           .GetField("m_sqlResultsControl", bindingFlags);

            if (resultControlField == null)
            {
                return(null);
            }

            object resultsControl = resultControlField.GetValue(editorControl);

            object resultsTabPage = resultsControl
                                    .GetType()
                                    .GetField("m_gridResultsPage", bindingFlags)
                                    .GetValue(resultsControl);

            IGridControl grid = (IGridControl)resultsTabPage
                                .GetType()
                                .BaseType
                                .GetProperty("FocusedGrid", bindingFlags)
                                .GetValue(resultsTabPage, null);

            if (grid == null)
            {
                return(null);
            }

            return(new ResultGrid(grid));
        }
        private static bool GridSync_StateColor(IGridBlock_Base grid, IGridControl gridFrontend, GridControl_Settings settings)
        {
            var state = grid as IGridBlock_State;

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

            var   result = false;
            Color color;

            if (settings.Color_ID.TryGetValue(state.State_Id, out color))
            {
                if (gridFrontend.BackColor != color)
                {
                    gridFrontend.BackColor = color;
                    result = true;
                }
            }
            return(result);
        }
        private static void GridSync_CalcSize(IGridBlock_Base grid, ref int width, ref int height)
        {
            IGridControl gridControl = grid.zGridControl;
            var          child       = grid as IGridBlock_State;

            if (child != null)
            {
                // Recalc sizes
                if (child.State_Row != rowMax)
                {
                    // reset the row
                    width  = 0;
                    rowMax = child.State_Row;
                }
                width += gridControl.Width; // Only increase width on first row

                if (child.State_Col == 1)
                {
                    height += gridControl._Parent.Height;                       // Only increase height on first col
                }
            }
        }
Example #16
0
 private void OnGridChangeEvent(IGridControl gridcontrol, enGrid_ChangeType changetype)
 {
     // Fire when change happened
 }
        private static void GridSync(IGridBlock_Base grid, GridControl_Settings settings, bool resetColors, onGrid_ChangeEvent onGridChangeEvent)
        {
            IGridControl gridControl = grid.zGridControl;

            if (gridControl == null)
            {
                return;                       // Testing code
            }
            var parent = grid._Parent as IGridBlock_ChildState;
            var child  = grid as IGridBlock_State;

            if (parent == null)
            {
                // Cuboid
                if (GridSync_Size(child, gridControl, settings.Size_CuboidWidth, settings.Size_CuboidHeight))
                {
                    onGridChangeEvent(gridControl, enGrid_ChangeType.Size);                                                                                           // Check size
                }
                if (resetColors && GridSync_Color(child, gridControl, settings.ColorDefault_CuboidGrid))
                {
                    onGridChangeEvent(gridControl, enGrid_ChangeType.Color);                                                                                      // Check size
                }
                //if (GridSync_Visible(gridControl, Visible_CuboidGrids)) onGridChange?.Invoke(gridControl, enGridChangeType.Visible); // Check size
                //if (GridSync_DisplayMode(grid, gridControl, DisplayMode_CuboidGrids)) onGridChange?.Invoke(gridControl, enGridChangeType.DisplayMode); // Check size
            }
            else if (parent.Child_BlockType == enGrid_BlockType.MacroBlock)
            {
                // Macro
                if (GridSync_Size(child, gridControl, settings.Size_MacroWidth, settings.Size_MacroHeight))
                {
                    onGridChangeEvent(gridControl, enGrid_ChangeType.Size);                                                                                         // Check size
                }
                if (resetColors && GridSync_Color(child, gridControl, settings.ColorDefault_MacroGrid))
                {
                    onGridChangeEvent(gridControl, enGrid_ChangeType.Color);                                                                                     // Check size
                }
                if (GridSync_Visible(gridControl, settings.Visible_MacroGrids))
                {
                    onGridChangeEvent(gridControl, enGrid_ChangeType.Visible);                                                             // Check size
                }
                //if (GridSync_DisplayMode(grid, gridControl, DisplayMode_MacroGrids)) onGridChange?.Invoke(gridControl, enGridChangeType.DisplayMode); // Check size
            }
            else if (parent.Child_BlockType == enGrid_BlockType.SubBlock)
            {
                // Sub
                if (GridSync_Size(child, gridControl, settings.Size_SubWidth, settings.Size_SubHeight))
                {
                    onGridChangeEvent(gridControl, enGrid_ChangeType.Size);                                                                                     // Check size
                }
                if (resetColors && GridSync_Color(child, gridControl, settings.ColorDefault_SubGrid))
                {
                    onGridChangeEvent(gridControl, enGrid_ChangeType.Color);                                                                                   // Check size
                }
                if (GridSync_Visible(gridControl, settings.Visible_SubGrids))
                {
                    onGridChangeEvent(gridControl, enGrid_ChangeType.Visible);                                                           // Check size
                }
                //if (GridSync_DisplayMode(grid, gridControl, DisplayMode_SubGrids)) onGridChange?.Invoke(gridControl, enGridChangeType.DisplayMode); // Check size
            }
            else if (parent.Child_BlockType == enGrid_BlockType.MicroBlock)
            {
                // Micro
                if (GridSync_Size(child, gridControl, settings.Size_MicroWidth, settings.Size_MicroHeight))
                {
                    onGridChangeEvent(gridControl, enGrid_ChangeType.Size);                                                                                         // Check size
                }
                if (resetColors && GridSync_Color(child, gridControl, settings.ColorDefault_MicroGrid))
                {
                    onGridChangeEvent(gridControl, enGrid_ChangeType.Color);                                                                                     // Check size
                }
                if (GridSync_Visible(gridControl, settings.Visible_MicroGrids))
                {
                    onGridChangeEvent(gridControl, enGrid_ChangeType.Visible);                                                             // Check size
                }
                if (GridSync_DisplayMode(grid, gridControl, settings.DisplayMode_MicroGrids))
                {
                    onGridChangeEvent(gridControl, enGrid_ChangeType.DisplayMode);                                                                           // Check size
                }
            }

            // Color ID is always the same for all grids
            if (settings.Color_ID.Count != 0 && GridSync_StateColor(grid, gridControl, settings))
            {
                onGridChangeEvent(gridControl, enGrid_ChangeType.StateColor);                                                                                   // Check size
            }
        }
Example #18
0
 private void onGridChange(IGridControl gridcontrol, enGrid_ChangeType changetype)
 {
     // Fired when something changed.
 }
Example #19
0
 private void OnCreateGridControl1(IGridBlock_Base sender, enGrid_ControlType gridcontroltype, string parentname, string childname,
                                   enGrid_BlockType blocktype, ref IGridControl gridcontrol)
 {
     //gridcontrol = new object() as IGridControl;
     _ListTest1.Add(ControlToStr(gridcontroltype, parentname, childname, blocktype));
 }
Example #20
0
 public override void AddFrom(IGridControl gridControl, IGridItem item)
 {
     throw new System.NotImplementedException();
 }
 public ResultGrid(IGridControl grid)
 {
     _grid = grid;
 }
Example #22
0
        private void onCreateGridControl(IGridBlock_Base sender, enGrid_ControlType gridcontroltype, string parentname, string childname,
                                         enGrid_BlockType blocktype, ref IGridControl gridcontrol)
        {
            if (gridcontrol != null)
            {
                throw new ArgumentException(nameof(gridcontrol), "Error!. Grid control must be null in order to be created.");
            }
            #region Sample of a simple 1x1,1x1,1x1 grid
            // R1
            // R1cub1_1
            // R1cub1_1R1
            // R1cub1_1R1mac1_1
            // R1cub1_1R1mac1_1R1
            // R1cub1_1R1mac1_1R1sub1_1
            // R1cub1_1R1mac1_1R1sub1_1R1
            // R1cub1_1R1mac1_1R1sub1_1R1mic1_1

            // Row//?//R1//CuboidGrid
            // Grid//R1//R1cub1_1//CuboidGrid
            // Row//R1cub1_1//R1cub1_1R1//MacroBlock
            // Grid//R1cub1_1R1//R1cub1_1R1mac1_1//MacroBlock
            // Row//R1cub1_1R1mac1_1//R1cub1_1R1mac1_1R1//SubBlock
            // Grid//R1cub1_1R1mac1_1R1//R1cub1_1R1mac1_1R1sub1_1//SubBlock
            // Row//R1cub1_1R1mac1_1R1sub1_1//R1cub1_1R1mac1_1R1sub1_1R1//MicroBlock
            // Grid//R1cub1_1R1mac1_1R1sub1_1R1//R1cub1_1R1mac1_1R1sub1_1R1mic1_1//MicroBlock
            #endregion

            // Find the grid control
            bool created;
            gridcontrol = GridControl_Get(gridcontroltype, childname, blocktype, out created);
            if (created == false)
            {
                return;                     // The control exists, we do not need to do anything.
            }
            // Find the parent
            IGridControl parent;
            if (GridControl_Get(parentname, out parent) == false)
            {
                throw new InvalidOperationException($"Error! Parent '{parentname}' does not exist.");
            }

            // Setup the row / grid properties
            gridcontrol.GridState = sender;
            gridcontrol.Text      = sender.Name_Caption; // Set the caption of the control
            if (gridcontroltype == enGrid_ControlType.Row)
            {
                #region Row setup
                // ==================
                int height = 100;
                if (blocktype == enGrid_BlockType.CuboidGrid)
                {
                    height = _Settings.Size_CuboidHeight;                                            // These settings need to be calculated
                }
                else if (blocktype == enGrid_BlockType.MacroBlock)
                {
                    height = _Settings.Size_MacroHeight;                                                 // These settings need to be calculated
                }
                else if (blocktype == enGrid_BlockType.SubBlock)
                {
                    height = _Settings.Size_SubHeight;
                }
                else if (blocktype == enGrid_BlockType.MicroBlock)
                {
                    height = _Settings.Size_MicroHeight;
                }

                GridControl_SetupRow(parent, gridcontrol, height);
                #endregion
            }
            else
            {
                #region Grid setup
                // ===================
                var color = Color.Gray;
                int width = 30;
                if (blocktype == enGrid_BlockType.CuboidGrid)
                {
                    color = _Settings.ColorDefault_CuboidGrid;
                    width = _Settings.Size_CuboidWidth; // These settings need to be calculated
                }
                else if (blocktype == enGrid_BlockType.MacroBlock)
                {
                    width = _Settings.Size_MacroWidth; // These settings need to be calculated
                    color = _Settings.ColorDefault_MacroGrid;
                }
                else if (blocktype == enGrid_BlockType.SubBlock)
                {
                    width = _Settings.Size_SubWidth;
                    color = _Settings.ColorDefault_SubGrid;
                }
                else if (blocktype == enGrid_BlockType.MicroBlock)
                {
                    var display = _Settings.DisplayMode_MicroGrids;
                    if (display == enGrid_BlockDisplayType.Address)
                    {
                        gridcontrol.Text = sender.Name_Caption;                                               // Set the caption of the control
                    }
                    if (display == enGrid_BlockDisplayType.Name)
                    {
                        gridcontrol.Text = sender.Name_Control;                                            // Set the caption of the control
                    }
                    if (display == enGrid_BlockDisplayType.Value)
                    {
                        gridcontrol.Text = "?";                                             //There is no value yet
                    }
                    width = _Settings.Size_MicroWidth;
                    color = _Settings.ColorDefault_MicroGrid;
                }
                GridControl_SetupBlock(parent, gridcontrol, width, color);

                #endregion
            }
        }
 /// <summary>
 /// Creates the child grids.
 /// </summary>
 /// <param name="grid">The grid.</param>
 /// <param name="rows">The rows.</param>
 /// <param name="cols">The cols.</param>
 public void CreateChildGrids(GridControl_Row rootRow, IGridControl grid, int rows, int cols)
 {
     Cuboid.CreateNewChildGrids(grid, onCreateGridControl, rows, cols);
     Layout_Resume(rootRow);
 }