private static Gizmox.WebGUI.Forms.DataGridViewCell GetCell(int rowIndex, string propName,
                                                             IGridBase gridBase)
 {
     Gizmox.WebGUI.Forms.DataGridView dgv = (Gizmox.WebGUI.Forms.DataGridView)gridBase;
     Gizmox.WebGUI.Forms.DataGridViewRow row = dgv.Rows[rowIndex];
     return row.Cells[propName];
 }
        public GenericGridFilterControlWin(IGridBase grid)
        {
            var ds = grid.DataSource as DataView;
            if (ds != null) this._originalView = ds;
            (grid as DataGridView).DataSourceChanged += this.DataSourceChanged;

            this._lastForcedEvents = DateTime.Now;
            this.Grid = grid;
            this._timer = new Timer()
            {
                Enabled = true,
                Interval = 500,
            };
            this._timer.Tick += (sender, e) => 
            {
                if ((this._filterRequired) && (this._lastFilterChanged.AddMilliseconds(this._timer.Interval) < DateTime.Now))
                {
                    if (this._inFilter)
                        this._cancelCurrentFilter = true;
                    this._filterRequired = false;
                    this.DoFilter();
                }
            };

            var factory = new ControlFactoryWin();
            this._filterLabel = factory.CreateLabel("Filter:");
            this._filterTextBox = factory.CreateTextBox();
            var txt = this._filterTextBox as TextBox;
            txt.TextChanged += (sender, e) =>
                {
                    if (txt.Text == this._lastFilterText) return;
                    this._lastFilterChanged = DateTime.Now;
                    this._filterRequired = true;
                };
            var manager = factory.CreateBorderLayoutManager(this);
            manager.AddControl(this._filterLabel, BorderLayoutManager.Position.West);
            manager.AddControl(this._filterTextBox, BorderLayoutManager.Position.Centre);
            var vgap = manager.VerticalGapSize + manager.BorderSize;
            this.Height = this._filterTextBox.Height + 2 * vgap;

            this.FilterStarted += (sender, e) =>
                {
                    this.SetUIState(true);
                };
            this.FilterCompleted += (sender, e) =>
                {
                    this.SetUIState(false);
                };
            var wingrid = Grid as DataGridView;
            if (wingrid != null)
            {
                this._gridOriginalAlternatingStyle = wingrid.AlternatingRowsDefaultCellStyle;
                wingrid.AlternatingRowsDefaultCellStyleChanged += this.RecordGridAltStyle;
            }
        }
        ///<summary>
        /// Constructor
        ///</summary>
        ///<param name="gridBase"></param>
        ///<param name="uiDefName"></param>
        public GridBaseManager(IGridBase gridBase, string uiDefName)
        {
            _gridBase = gridBase;
            UiDefName = uiDefName;
            _gridBase.AutoGenerateColumns = false;
            GridLoader = DefaultGridLoader;
            _gridBase.AllowUserToAddRows = false;

            _gridBaseOnSelectionChangedHandler = GridBase_OnSelectionChanged;
            _gridBase.SelectionChanged += _gridBaseOnSelectionChangedHandler;
            AutoSelectFirstItem = true;
        }
        ///<summary>
        /// Returns the Total width of the Selector. <see cref="IGridBase"/>. This is used so that the
        ///   Selector and BOEditor can be layed out.
        ///</summary>
        ///<param name="grid"></param>
        ///<returns></returns>
        public static int GetGridWidthToFitColumns(IGridBase grid)
        {
            int width = 0;

            if (grid.RowHeadersVisible)
            {
                width = grid.RowHeadersWidth;
            }
            foreach (IDataGridViewColumn column in grid.Columns)
            {
                if (column.Visible)
                {
                    width += column.Width;
                }
            }
            return(width);
        }
Example #5
0
        public GenericGridFilterControlVwg(IGridBase grid)
        {
            this.Grid   = grid;
            this._timer = new Timer()
            {
                Enabled  = true,
                Interval = 500,
            };
            this._timer.Tick += (sender, e) =>
            {
                if ((!this._inFilter) && (this._filterRequired) && (this._lastFilterChanged.AddMilliseconds(this._timer.Interval) < DateTime.Now))
                {
                    this._filterRequired = false;
                    this.DoFilter();
                }
            };

            var factory = new ControlFactoryVWG();

            this._filterLabel   = factory.CreateLabel("Filter:");
            this._filterTextBox = factory.CreateTextBox();
            var txt = this._filterTextBox as TextBox;

            txt.KeyPress += (sender, e) =>
            {
                this._lastFilterChanged = DateTime.Now;
                this._filterRequired    = true;
            };
            var manager = factory.CreateBorderLayoutManager(this);

            manager.AddControl(this._filterLabel, BorderLayoutManager.Position.West);
            manager.AddControl(this._filterTextBox, BorderLayoutManager.Position.Centre);
            var vgap = manager.VerticalGapSize + manager.BorderSize;

            this.Height = this._filterTextBox.Height + 2 * vgap;

            this.FilterStarted += (sender, e) =>
            {
                this.SetUIState(true);
            };
            this.FilterCompleted += (sender, e) =>
            {
                this.SetUIState(false);
            };
        }
        public void Test_StringIndexerReturnsImageColumn()
        {
            //---------------Set up test pack-------------------
            IGridBase gridBase = CreateGridBaseStub();
            IDataGridViewImageColumn imgColumn  = GetControlFactory().CreateDataGridViewImageColumn();
            const string             columnName = "Name";

            imgColumn.Name = columnName;
            gridBase.Columns.Add(imgColumn);
            //--------------Assert PreConditions----------------
            Assert.AreEqual(1, gridBase.Columns.Count);
            //---------------Execute Test ----------------------
            IDataGridViewColumn col = gridBase.Columns[columnName];

            //---------------Test Result -----------------------
            Assert.IsInstanceOf(typeof(IDataGridViewImageColumn), col);
            //---------------Tear Down -------------------------
        }
Example #7
0
        private static int GetColumnCount(IGridBase dataGrid)
        {
            var test  = 0;
            var error = false;

            while (!error)
            {
                try
                {
                    var testVal = dataGrid.Rows[0].Cells[test];
                    test++;
                }
                catch (Exception)
                {
                    error = true;
                }
            }
            return(test);
        }
Example #8
0
        public void TestWinRowIsRefreshed()
        {
            //---------------Set up test pack-------------------
            BusinessObjectCollection <MyBO> col;
            IGridBase gridBase = GetGridBaseWith_4_Rows(out col);
            MyBO      bo       = col[0];

            //---------------Execute Test ----------------------
            const string propName = "TestProp";

            bo.SetPropertyValue(propName, "UpdatedValue");

            //---------------Test Result -----------------------
            gridBase.SelectedBusinessObject = bo;
            //System.Windows.Forms.DataGridViewRow row = (System.Windows.Forms.DataGridViewRow) gridBase.Rows[0];
            //System.Windows.Forms.DataGridViewCell cell = row.Cells[propName];
            System.Windows.Forms.DataGridViewCell cell = GetCell(0, propName, gridBase);
            Assert.AreEqual("UpdatedValue", cell.Value);
        }
Example #9
0
        public void WorkingWithTasks_()
        {
            commandAdapter.DoAction("Navigation", "Task");
            commandAdapter.ProcessRecord("Task", new string[] { "Subject" }, new string[] { "Fix breakfast" }, "");

            ITestControl control = adapter.CreateTestControl(TestControlType.Table, "Contacts");
            IGridBase    table   = control.GetInterface <IGridBase>();

            Assert.AreEqual(0, table.GetRowCount());

            commandAdapter.DoAction("Contacts.Link", null);
            control = adapter.CreateTestControl(TestControlType.Table, "Contact");
            control.GetInterface <IGridRowsSelection>().SelectRow(0);
            commandAdapter.DoAction("OK", null);

            control = adapter.CreateTestControl(TestControlType.Table, "Contacts");
            table   = control.GetInterface <IGridBase>();
            Assert.AreEqual(1, table.GetRowCount());
            Assert.AreEqual("John Nilsen", commandAdapter.GetCellValue("Contacts", 0, "Full Name"));
        }
Example #10
0
        public void TestSelectedBusinessObject_SetsCurrentRow_2()
        {
            //---------------Set up test pack-------------------
            BusinessObjectCollection <MyBO> col;
            IGridBase gridBase = GetGridBaseWith_4_Rows(out col);

            SetupGridColumnsForMyBo(gridBase);
            MyBO firstBO  = col[0];
            MyBO secondBO = col[1];

            //---------------Assert Precondition----------------
            Assert.AreEqual(firstBO, gridBase.SelectedBusinessObject);
            Assert.IsNull(gridBase.CurrentRow);
            //Assert.AreEqual(0, gridBase.Rows.IndexOf(gridBase.CurrentRow));   //surely the currentrow should be active on setCol?
            //---------------Execute Test ----------------------
            gridBase.SelectedBusinessObject = secondBO;
            //---------------Test Result -----------------------
            Assert.AreEqual(secondBO, gridBase.SelectedBusinessObject);
            Assert.AreEqual(1, gridBase.Rows.IndexOf(gridBase.CurrentRow));
        }
        public GenericGridFilterControlVwg(IGridBase grid)
        {
            this.Grid = grid;
            this._timer = new Timer()
            {
                Enabled = true,
                Interval = 500,
            };
            this._timer.Tick += (sender, e) => 
            {
                if ((!this._inFilter) && (this._filterRequired) && (this._lastFilterChanged.AddMilliseconds(this._timer.Interval) < DateTime.Now))
                {
                    this._filterRequired = false;
                    this.DoFilter();
                }
            };

            var factory = new ControlFactoryVWG();
            this._filterLabel = factory.CreateLabel("Filter:");
            this._filterTextBox = factory.CreateTextBox();
            var txt = this._filterTextBox as TextBox;
            txt.KeyPress += (sender, e) =>
                {
                    this._lastFilterChanged = DateTime.Now;
                    this._filterRequired = true;
                };
            var manager = factory.CreateBorderLayoutManager(this);
            manager.AddControl(this._filterLabel, BorderLayoutManager.Position.West);
            manager.AddControl(this._filterTextBox, BorderLayoutManager.Position.Centre);
            var vgap = manager.VerticalGapSize + manager.BorderSize;
            this.Height = this._filterTextBox.Height + 2 * vgap;

            this.FilterStarted += (sender, e) =>
                {
                    this.SetUIState(true);
                };
            this.FilterCompleted += (sender, e) =>
                {
                    this.SetUIState(false);
                };
        }
Example #12
0
        public override void TestGetBusinessObjectAtRow_WhenDataSourceNotNullButDataSetProviderNull_ShouldReturnBO()
        {
            //---------------Set up test pack-------------------
            MyBO.LoadDefaultClassDef();
            BusinessObjectCollection <MyBO> col = CreateCollectionWith_4_Objects();
            IGridBase gridBase = CreateGridBaseStub();

            gridBase.GridLoader = GridLoaderDelegateSetDataSource;
            SetupGridColumnsForMyBo(gridBase);
            gridBase.BusinessObjectCollection = col;
            //---------------Assert Preconditions---------------
            Assert.IsNull(gridBase.DataSetProvider);
            Assert.IsNotNull(gridBase.DataSource);
            //---------------Execute Test ----------------------
            IBusinessObject businessObject2 = gridBase.GetBusinessObjectAtRow(2);
            IBusinessObject businessObject3 = gridBase.GetBusinessObjectAtRow(3);

            //---------------Test Result -----------------------
            Assert.AreSame(col[2], businessObject2);
            Assert.AreSame(col[3], businessObject3);
        }
Example #13
0
        public void TestVWG_Set_BusinessObjectCollection()
        {
            //---------------Set up test pack-------------------
            MyBO.LoadDefaultClassDef();
            BusinessObjectCollection <MyBO> col = CreateCollectionWith_4_Objects();
            IGridBase gridBase = CreateGridBaseStub();

            SetupGridColumnsForMyBo(gridBase);
            const string propName = "TestProp";
            const int    rowIndex = 1;

            //---------------Execute Test ----------------------
            gridBase.BusinessObjectCollection = col;

            //---------------Test Result -----------------------
            MyBO              selectedBo = (MyBO)gridBase.GetBusinessObjectAtRow(rowIndex);
            IDataGridViewRow  row        = gridBase.Rows[rowIndex];
            IDataGridViewCell cell       = row.Cells[propName];

            Assert.AreEqual(selectedBo.TestProp, cell.Value);
        }
Example #14
0
        public void TestVWG_RowShowingBusinessObjectsValues()
        {
            //---------------Set up test pack-------------------
            MyBO.LoadDefaultClassDef();
            BusinessObjectCollection <MyBO> col = CreateCollectionWith_4_Objects();
            IGridBase gridBase = CreateGridBaseStub();

            SetupGridColumnsForMyBo(gridBase);
            const string propName = "TestProp";
            const int    rowIndex = 1;

            //---------------Execute Test ----------------------
#pragma warning disable 618,612 //Maintained for backward compatibility testing
            gridBase.SetBusinessObjectCollection(col);
#pragma warning restore 618,612

            //---------------Test Result -----------------------
            MyBO              selectedBo = (MyBO)gridBase.GetBusinessObjectAtRow(rowIndex);
            IDataGridViewRow  row        = gridBase.Rows[rowIndex];
            IDataGridViewCell cell       = row.Cells[propName];
            Assert.AreEqual(selectedBo.TestProp, cell.Value);
        }
Example #15
0
        public override void Test_SetDateToGridCustomFormat_LoadViaDataTable()
        {
            //---------------Set up test pack-------------------
            MyBO.LoadClassDefWithDateTime();
            IDataGridViewColumn column;
            const string        requiredFormat = "dd.MMM.yyyy";
            IGridBase           gridBase       = CreateGridBaseWithDateCustomFormatCol(out column, requiredFormat);
            DataTable           dataTable      = new DataTable();
            const string        dateTimeProp   = "TestDateTime";

            dataTable.Columns.Add(dateTimeProp, typeof(DateTime));
            DateTime expectedDate = DateTime.Now;

            dataTable.Rows.Add(expectedDate);
            //--------------Assert PreConditions----------------
            //---------------Execute Test ----------------------
            gridBase.DataSource = dataTable.DefaultView;
            //---------------Test Result -----------------------
            IDataGridViewCell dataGridViewCell = gridBase.Rows[0].Cells[0];

            Assert.AreEqual(expectedDate.ToString(requiredFormat), dataGridViewCell.FormattedValue);
        }
        private ITestControl GetNavigationTestControl(ICommandAdapter adapter)
        {
            string controlNames = "";

            for (int i = 0; i < _navigationControlPossibleNames.Length; i++)
            {
                if (adapter.IsControlExist(TestControlType.Action, _navigationControlPossibleNames[i]))
                {
                    try {
                        ITestControl testControl       = adapter.CreateTestControl(TestControlType.Action, _navigationControlPossibleNames[i]);
                        IGridBase    gridBaseInterface = testControl.GetInterface <IGridBase>();
                        int          itemsCount        = gridBaseInterface.GetRowCount();
                        if (itemsCount > 0)
                        {
                            return(testControl);
                        }
                    }
                    catch (WarningException) { }
                }
                controlNames += (i <= _navigationControlPossibleNames.Length) ? _navigationControlPossibleNames[i] + " or " : _navigationControlPossibleNames[i];
            }
            throw new WarningException($"Cannot find the '{controlNames}' control");
        }
Example #17
0
        public void TestClearFilter1()
        {
            //---------------Set up test pack-------------------
            BusinessObjectCollection <MyBO> col;
            IGridBase            gridBase     = GetGridBaseWith_4_Rows(out col);
            string               filterString = col[2].TestProp.ToString().Substring(0, 10);
            IFilterClauseFactory factory      = new DataViewFilterClauseFactory();
            IFilterClause        filterClause =
                factory.CreateStringFilterClause("TestProp", FilterClauseOperator.OpLike, filterString);

            gridBase.ApplyFilter(filterClause);

            //---------------Verify PreConditions --------------
            Assert.AreEqual(1, gridBase.Rows.Count, "Filtered Grid should have 1 item");

            //---------------Execute Test ----------------------
            gridBase.ApplyFilter(null);

            //---------------Test Result -----------------------

            Assert.AreEqual(4, gridBase.Rows.Count);
            //---------------Tear Down -------------------------
        }
Example #18
0
 private void GridLoaderDelegateSetDataSource(IGridBase grid, IBusinessObjectCollection col)
 {
     if (col == null)
     {
         grid.DataSource = null;
         return;
     }
     var dataSetProvider = new ReadOnlyDataSetProvider(col);
     IUIDef uiDef = ((ClassDef)col.ClassDef).GetUIDef(grid.UiDefName);
     grid.DataSource = dataSetProvider.GetDataView(uiDef.UIGrid);
 }
 private static object GetCellValue(int rowIndex, IGridBase gridBase, string propName)
 {
     Gizmox.WebGUI.Forms.DataGridViewCell cell = GetCell(rowIndex, propName, gridBase);
     return cell.Value;
 }
 protected override void AssertCorrectSelectionMode(IGridBase dataGridView)
 {
     Gizmox.WebGUI.Forms.DataGridView grid = (Gizmox.WebGUI.Forms.DataGridView)dataGridView;
     Assert.AreEqual(Gizmox.WebGUI.Forms.DataGridViewSelectionMode.RowHeaderSelect, grid.SelectionMode);
 }
Example #21
0
 private static object GetCellValue(int rowIndex, IGridBase gridBase, string propName)
 {
     Gizmox.WebGUI.Forms.DataGridViewCell cell = GetCell(rowIndex, propName, gridBase);
     return(cell.Value);
 }
        //protected override IGridBase CreateGridBaseStub()
        //{
        //    GridBaseWinStub gridBase = new GridBaseWinStub();
        //    System.Windows.Forms.Form frm = new System.Windows.Forms.Form();
        //    frm.Controls.Add(gridBase);
        //    return gridBase;
        //}

        //            private static System.Windows.Forms.DataGridViewCell GetCell(int rowIndex, string propName,
        //                                                                         IGridBase gridBase)
        //            {
        //                System.Windows.Forms.DataGridView dgv = (System.Windows.Forms.DataGridView)gridBase;
        //                System.Windows.Forms.DataGridViewRow row = dgv.Rows[rowIndex];
        //                return row.Cells[propName];
        //            }

        protected override IFormHabanero AddControlToForm(IGridBase gridBase)
        {
            IFormHabanero frm = GetControlFactory().CreateForm();
            DisposeOnTearDown(frm);
            frm.Controls.Add(gridBase);
            return frm;
        }
Example #23
0
        internal object GetTableRowCount(string tableName)
        {
            IGridBase gridControl = adapter.CreateTestControl(TestControlType.Table, tableName).GetInterface <IGridBase>();

            return(gridControl.GetRowCount());
        }
 ///<summary>
 /// Initialise the grid with the appropriate control factory.
 ///</summary>
 ///<param name="gridBase"></param>
 ///<param name="controlFactory"></param>
 public GridBaseInitialiser(IGridBase gridBase, IControlFactory controlFactory)
 {
     if (gridBase == null) throw new ArgumentNullException("gridBase");
     this.GridBase = gridBase;
     _controlFactory = controlFactory;
 }
Example #25
0
        private static void SizeRows(IGridBase grid, double minimumHeight, double availableHeight, List <Row> rows, Space[] rowSpaces, int baseStarIndex, double scale)
        {
            for (int i = 0; i < rows.Count; i++)
            {
                if (rows[i].UnitType == LayoutUnitType.Auto)
                {
                    var space = rowSpaces[i];
                    if (space.Size > availableHeight)
                    {
                        space.Size      = availableHeight;
                        availableHeight = 0;
                        rowSpaces[i]    = space;
                    }
                    else
                    {
                        if (space.Size < 0)
                        {
                            space.Size   = 0;
                            rowSpaces[i] = space;
                        }
                        availableHeight -= rowSpaces[i].Size;
                    }
                }
            }

            double weightSum  = rows.Where(r => r.UnitType == LayoutUnitType.Star).Sum(r => r.Height);
            double starHeight = availableHeight / weightSum;

            if (baseStarIndex >= 0)
            {
                weightSum += rows[baseStarIndex].Height;
                starHeight = rowSpaces[baseStarIndex].Size * rows[baseStarIndex].Height;

                // check if starHeight is sufficient to cover minimum height
                double consumedHeight = starHeight * weightSum;
                for (int i = 0; i < rows.Count; i++)
                {
                    if (i == baseStarIndex)
                    {
                        continue;
                    }

                    var row = rows[i];
                    if (row.UnitType != LayoutUnitType.Star)
                    {
                        consumedHeight += rowSpaces[i].Size;
                    }
                }

                double minHeight = minimumHeight - ((grid.Padding.Top + grid.Padding.Bottom) * scale);
                if (consumedHeight < minHeight)
                {
                    starHeight += (minHeight - consumedHeight) / weightSum;
                    rowSpaces[baseStarIndex] = new Space()
                    {
                        Size = starHeight * rows[baseStarIndex].Height
                    };
                }
            }

            for (int rIndex = 0; rIndex < rows.Count; rIndex++)
            {
                var row   = rows[rIndex];
                var space = rowSpaces[rIndex];
                if (row.UnitType == LayoutUnitType.Star)
                {
                    space.Size        = row.Height * starHeight;
                    rowSpaces[rIndex] = space;
                }

                if (grid.Rows.Count > rIndex)
                {
                    grid.Rows[rIndex] = new Row(row, space.Size / scale);
                }
            }

            // if height is less than minimum, stretch the last auto row that has a size
            double extraCellHeight = minimumHeight - rowSpaces.Sum(r => r.Size) - ((grid.Padding.Top + grid.Padding.Bottom) * scale);

            if (extraCellHeight > 0)
            {
                for (int i = rows.Count - 1; i >= 0; i--)
                {
                    var row   = rows[i];
                    var space = rowSpaces[i];
                    if (row.UnitType != LayoutUnitType.Auto || space.Size <= 0)
                    {
                        continue;
                    }

                    space.Size  += extraCellHeight;
                    rowSpaces[i] = space;

                    if (grid.Rows.Count > i)
                    {
                        grid.Rows[i] = new Row(row, space.Size / scale);
                    }
                    break;
                }
            }

            rowSpaces[0].Origin = grid.Padding.Top * scale;
            for (int rIndex = 1; rIndex < rowSpaces.Length; rIndex++)
            {
                var previous = rowSpaces[rIndex - 1];
                rowSpaces[rIndex].Origin = previous.Origin + previous.Size;
            }
        }
 private static System.Windows.Forms.DataGridViewCell GetCell(int rowIndex, string propName,
                                                              IGridBase gridBase)
 {
     System.Windows.Forms.DataGridView dgv = (System.Windows.Forms.DataGridView)gridBase.GetControl();
     System.Windows.Forms.DataGridViewRow row = dgv.Rows[rowIndex];
     return row.Cells[propName];
 }
 protected override void AddControlToForm(IGridBase gridBase)
 {
     System.Windows.Forms.Form frm = new System.Windows.Forms.Form();
     frm.Controls.Add((System.Windows.Forms.Control)gridBase);
 }
Example #28
0
 public void GridLoaderDelegateStub_LoadAllItems(IGridBase grid, IBusinessObjectCollection col)
 {
     if (col == null)
     {
         grid.Rows.Clear();
         return;
     }
     foreach (IBusinessObject businessObject in col)
     {
         MyBO cp = (MyBO) businessObject;
         grid.Rows.Add(cp.ID, cp.TestProp);               
     }
 }
Example #29
0
 public void GridLoaderDelegateStub(IGridBase grid, IBusinessObjectCollection col)
 {
     MyBO cp = new MyBO();
     cp.TestProp = "b";
     grid.Rows.Add(cp.ID,cp.TestProp);
 }
Example #30
0
 protected abstract void AddControlToForm(IGridBase gridBase);
Example #31
0
        /// <summary>
        /// Positions and sizes the children of a grid using the grid's columns and rows.
        /// </summary>
        /// <param name="grid">The grid object.</param>
        /// <param name="minimumSize">The minimum size of the area in which the children are placed.</param>
        /// <param name="maximumSize">The maximum size of the area in which the children are placed.</param>
        /// <exception cref="ArgumentNullException">Thrown when the <paramref name="grid"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="minimumSize"/> or <paramref name="maximumSize"/> contains a negative value.</exception>
        /// <exception cref="ArgumentException">Thrown when <paramref name="minimumSize"/> has an infinite width or height -or- when the width of <paramref name="maximumSize"/> is infinite and the grid contains at least one star-sized column -or- when the height of <paramref name="maximumSize"/> is infinite and the grid contains at least one star-sized row.</exception>
        public static Size PerformLayout(this IGridBase grid, Size minimumSize, Size maximumSize)
        {
            if (grid == null)
            {
                throw new ArgumentNullException("grid");
            }

            #region ILayoutInstruction layout preprocessors

            var instruction = grid as ILayoutInstruction;
            if (instruction == null)
            {
                var pairable = grid as IPairable;
                if (pairable != null)
                {
                    instruction = pairable.Pair as ILayoutInstruction;
                }
            }

            if (instruction != null)
            {
                iApp.Factory.Instructor.Layout(instruction);

                IPairable pair     = null;
                var       pairable = grid as IPairable;
                if (pairable != null)
                {
                    pair = pairable.Pair;
                }

                var cell = grid as IGridCell ?? pair as IGridCell;
                if (cell != null)
                {
                    minimumSize.Height = cell.MinHeight;
                    maximumSize.Height = cell.MaxHeight;
                }
            }

            #endregion

            maximumSize.Width  = Math.Max(maximumSize.Width, minimumSize.Width);
            maximumSize.Height = Math.Max(maximumSize.Height, minimumSize.Height);

            if (double.IsInfinity(minimumSize.Width) || double.IsInfinity(minimumSize.Height))
            {
                throw new ArgumentException("Minimum size must not have an infinite width or height.", "minimumSize");
            }

            if (minimumSize.Width < 0 || minimumSize.Height < 0)
            {
                throw new ArgumentOutOfRangeException("minimumSize", "The given size must not contain any negative values.");
            }

            if (maximumSize.Width < 0 || maximumSize.Height < 0)
            {
                throw new ArgumentOutOfRangeException("maximumSize", "The given size must not contain any negative values.");
            }

            // if the grid has no rows or columns, provide one
            var rows = grid.Rows.Count == 0 ? new List <Row> {
                new Row(1, LayoutUnitType.Auto)
            } : grid.Rows.ToList();
            var columns = grid.Columns.Count == 0 ? new List <Column> {
                new Column(1, LayoutUnitType.Auto)
            } : grid.Columns.ToList();

            #region Build index dictionary

            var actualIndices = new Dictionary <IElement, IndexPair>();
            foreach (var element in grid.Children)
            {
                if (element.ColumnSpan < 1 || element.RowSpan < 1)
                {
                    throw new ArgumentOutOfRangeException("grid", "UI elements must not have negative column or row spans.");
                }

                actualIndices.Add(element, new IndexPair
                {
                    ColumnIndex = Math.Min(element.ColumnIndex, columns.Count - 1),
                    RowIndex    = Math.Min(element.RowIndex, rows.Count - 1)
                });
            }

            #endregion

            #region Find indices of auto controls

            if (actualIndices.Keys.Any(control => control.RowIndex < 0 || control.ColumnIndex < 0))
            {
                var columnHeights = new int[columns.Count];

                //Copy controls to an array in case the controls collection is modified
                var controls = new IElement[actualIndices.Count];
                actualIndices.Keys.CopyTo(controls, 0);

                foreach (var control in controls)
                {
                    var controlIndex = actualIndices[control];
                    var autoControl  = controlIndex.RowIndex == Element.AutoLayoutIndex || controlIndex.ColumnIndex == Element.AutoLayoutIndex;

                    if (controlIndex.RowIndex == Element.AutoLayoutIndex)
                    {
                        // If we have a column index, honor it
                        if (controlIndex.ColumnIndex >= 0)
                        {
                            controlIndex.RowIndex = columnHeights.Skip(controlIndex.ColumnIndex).Take(control.ColumnSpan).Max();
                            var obstructors = GetGridControls(actualIndices, controlIndex.RowIndex, controlIndex.ColumnIndex, control).ToList();
                            while (obstructors.Any())
                            {
                                // Try the next available row
                                controlIndex.RowIndex = obstructors.Max(p => p.Value.RowIndex + p.Key.RowSpan);
                                obstructors           = GetGridControls(actualIndices, controlIndex.RowIndex, controlIndex.ColumnIndex, control).ToList();
                            }
                        }
                        else
                        {
                            // Set a minimum row and drop to auto-column logic
                            controlIndex.RowIndex = columnHeights.Min();
                        }
                    }

                    // Place in specified row or one with an available span of columns
                    while (controlIndex.ColumnIndex == Element.AutoLayoutIndex)
                    {
                        controlIndex.ColumnIndex = GetColumnForRow(controlIndex.RowIndex, columns.Count, control, actualIndices);
                        if (controlIndex.ColumnIndex > Element.AutoLayoutIndex)
                        {
                            break;
                        }
                        var candidates = columnHeights.Where(r => r > controlIndex.RowIndex).ToList();
                        controlIndex.RowIndex = candidates.Any() ? candidates.Min() : rows.Count;
                    }

                    while (control.RowSpan + controlIndex.RowIndex > rows.Count)
                    {
                        rows.Add(Row.AutoSized);
                    }

                    actualIndices[control] = controlIndex;

                    // Record high water mark for each column the control occludes.
                    for (int i = 0; i < control.ColumnSpan && controlIndex.ColumnIndex + i < columnHeights.Length; i++)
                    {
                        int nextAvailableRow = controlIndex.RowIndex + control.RowSpan;

                        // Auto controls always leave a high water mark. Manually-placed controls only occlude
                        // completely filled columns so that auto controls may be placed above them.
                        if (autoControl || controlIndex.RowIndex == columnHeights[controlIndex.ColumnIndex + i])
                        {
                            //If a manual control blocks the next row, include it in the high water mark.
                            Dictionary <IElement, IndexPair> idxs;
                            while ((idxs = actualIndices.Where(v =>
                                                               v.Value.ColumnIndex <= controlIndex.ColumnIndex + i &&
                                                               v.Value.ColumnIndex + v.Key.ColumnSpan > controlIndex.ColumnIndex + i &&
                                                               v.Value.RowIndex <= nextAvailableRow &&
                                                               v.Value.RowIndex + v.Key.RowSpan > nextAvailableRow)
                                           .ToDictionary(p => p.Key, p => p.Value)).Any())
                            {
                                nextAvailableRow = idxs.Max(p => p.Value.RowIndex + p.Key.RowSpan);
                            }
                            columnHeights[controlIndex.ColumnIndex + i] = nextAvailableRow;
                        }
                    }
                }
            }

            #endregion

            var scale = iApp.Factory.GetDisplayScale();
            maximumSize.Height *= scale;
            minimumSize.Height *= scale;

            // total grid size minus grid padding
            double totalGridWidth  = double.IsInfinity(maximumSize.Width) ? double.MaxValue : maximumSize.Width;
            double totalGridHeight = double.IsInfinity(maximumSize.Height) ? double.MaxValue : maximumSize.Height;
            totalGridWidth  -= (grid.Padding.Left + grid.Padding.Right) * scale;
            totalGridHeight -= (grid.Padding.Top + grid.Padding.Bottom) * scale;

            // available grid size for autos
            double availableGridWidth  = totalGridWidth;
            double availableGridHeight = totalGridHeight;

            var rowSpaces    = new Space[rows.Count];
            var columnSpaces = new Space[columns.Count];
            var elementSizes = new Dictionary <IElement, Size>(actualIndices.Count);

            #region Star sizing with no size limit

            // if there are any star rows or columns and the maximum size is infinite,
            // treat the star with the smallest weight as an auto and use it to size the others.
            int baseStarRowIndex = -1;
            if (double.IsInfinity(maximumSize.Height))
            {
                double minWeight = double.MaxValue;
                for (int i = 0; i < rows.Count; i++)
                {
                    var row = rows[i];
                    if (row.UnitType == LayoutUnitType.Star && minWeight > row.Height)
                    {
                        minWeight        = row.Height;
                        baseStarRowIndex = i;
                    }
                }

                if (baseStarRowIndex >= 0)
                {
                    rows[baseStarRowIndex] = new Row(rows[baseStarRowIndex].Height, LayoutUnitType.Auto);
                }
            }

            int baseStarColumnIndex = -1;
            if (double.IsInfinity(maximumSize.Width))
            {
                double minWeight = double.MaxValue;
                for (int i = 0; i < columns.Count; i++)
                {
                    var column = columns[i];
                    if (column.UnitType == LayoutUnitType.Star && minWeight > column.Width)
                    {
                        minWeight           = column.Width;
                        baseStarColumnIndex = i;
                    }
                }

                if (baseStarColumnIndex >= 0)
                {
                    columns[baseStarColumnIndex] = new Column(columns[baseStarColumnIndex].Width, LayoutUnitType.Auto);
                }
            }

            #endregion

            #region Absolute sizing

            for (int rIndex = 0; rIndex < rows.Count; rIndex++)
            {
                Row row = rows[rIndex];
                if (row.UnitType == LayoutUnitType.Absolute)
                {
                    availableGridHeight   -= row.Height * scale;
                    rowSpaces[rIndex].Size = row.Height * scale;
                }
            }

            for (int cIndex = 0; cIndex < columns.Count; cIndex++)
            {
                Column column = columns[cIndex];
                if (column.UnitType == LayoutUnitType.Absolute)
                {
                    availableGridWidth       -= column.Width * scale;
                    columnSpaces[cIndex].Size = column.Width * scale;
                }
            }

            #endregion

            // loop through every child element, regardless of column/row indices or spans, and determine its desired size.
            // this is considered the 'measure' pass and is just to get an idea of how much space each element wants.
            foreach (var kvp in actualIndices)
            {
                var element   = kvp.Key;
                var indexPair = kvp.Value;

                if (element.Visibility == Visibility.Collapsed)
                {
                    elementSizes[element] = Size.Empty;
                    continue;
                }

                double maxElementWidth  = 0;
                double maxElementHeight = 0;

                bool inAutoColumn = false, inAutoRow = false, takeAll = false;
                int  lastColumn = Math.Min(columns.Count, indexPair.ColumnIndex + element.ColumnSpan);
                for (int i = indexPair.ColumnIndex; i < lastColumn; i++)
                {
                    var column = columns[i];
                    if (column.UnitType == LayoutUnitType.Absolute)
                    {
                        maxElementWidth += column.Width;
                    }
                    else if (!takeAll)
                    {
                        // if the element spans any auto or star column, its constraining width will include the
                        // entire available grid width minus any absolutes that the element is not a part of.
                        // this is because we don't know the final size of these columns yet, and we need to assume
                        // that they will take all of the grid's remaining available space.
                        takeAll          = true;
                        maxElementWidth += availableGridWidth;
                    }

                    if (column.UnitType == LayoutUnitType.Auto)
                    {
                        inAutoColumn = true;
                    }
                }

                takeAll = false;
                int lastRow = Math.Min(rows.Count, indexPair.RowIndex + element.RowSpan);
                for (int i = indexPair.RowIndex; i < lastRow; i++)
                {
                    var row = rows[i];
                    if (row.UnitType == LayoutUnitType.Absolute)
                    {
                        maxElementHeight += row.Height;
                    }
                    else if (!takeAll)
                    {
                        // if the element spans any auto row, its constraining height will include the
                        // entire available grid height minus any absolutes that the element is not a part of.
                        // this is because we don't know the final size of these rows yet, and we need to assume
                        // that they will take all of the grid's remaining available space.
                        takeAll           = true;
                        maxElementHeight += availableGridHeight;
                    }

                    if (row.UnitType == LayoutUnitType.Auto)
                    {
                        inAutoRow = true;
                    }
                }

                // if the element doesn't span any autos, we don't need to measure it in this pass
                if (!inAutoColumn && !inAutoRow)
                {
                    continue;
                }

                var desiredSize = element.Measure(new Size(Math.Max(0, maxElementWidth - (element.Margin.Left + element.Margin.Right) * scale),
                                                           Math.Max(0, maxElementHeight - (element.Margin.Top + element.Margin.Bottom) * scale)));

                elementSizes[element] = desiredSize;

                // if the element only spans one auto column, we can use it to determine the ultimate width for the column
                if (indexPair.ColumnIndex == (lastColumn - 1) && columns[indexPair.ColumnIndex].UnitType == LayoutUnitType.Auto)
                {
                    double totalWidth = Math.Max(desiredSize.Width + (element.Margin.Left + element.Margin.Right) * scale, 0);

                    var space = columnSpaces[indexPair.ColumnIndex];
                    if (space.Size < totalWidth)
                    {
                        space.Size = totalWidth;
                        columnSpaces[indexPair.ColumnIndex] = space;
                    }
                }

                // if the element only spans one auto row, we can use it to determine the ultimate height for the row
                if (indexPair.RowIndex == (lastRow - 1) && rows[indexPair.RowIndex].UnitType == LayoutUnitType.Auto)
                {
                    double totalHeight = Math.Max(desiredSize.Height + (element.Margin.Top + element.Margin.Bottom) * scale, 0);

                    var space = rowSpaces[indexPair.RowIndex];
                    if (space.Size < totalHeight)
                    {
                        space.Size = totalHeight;
                        rowSpaces[indexPair.RowIndex] = space;
                    }
                }
            }

            SizeColumns(grid, minimumSize.Width, availableGridWidth, columns, columnSpaces, baseStarColumnIndex, scale);
            SizeRows(grid, minimumSize.Height, availableGridHeight, rows, rowSpaces, baseStarRowIndex, scale);

            // this is considered the 'arrange' pass and is where we get the final size of each element before giving them an XY position.
            // at this point, all columns and rows should have a size that's pretty close to their final size.
            // some adjustments may be required if the second measurement of an element causes an auto row or column to be resized.
            foreach (var keyValue in actualIndices)
            {
                var element   = keyValue.Key;
                var indexPair = keyValue.Value;

                if (element.Visibility == Visibility.Collapsed)
                {
                    element.SetLocation(new Point(columnSpaces[indexPair.ColumnIndex].Origin, rowSpaces[indexPair.RowIndex].Origin), Size.Empty);
                    continue;
                }

                var marginLeft   = element.Margin.Left * scale;
                var marginTop    = element.Margin.Top * scale;
                var marginRight  = element.Margin.Right * scale;
                var marginBottom = element.Margin.Bottom * scale;

                Space rowSpace = rowSpaces[indexPair.RowIndex];
                for (int i = indexPair.RowIndex + 1; i < (indexPair.RowIndex + element.RowSpan) && i < rows.Count; i++)
                {
                    rowSpace.Size += rowSpaces[i].Size;
                }

                Space columnSpace = columnSpaces[indexPair.ColumnIndex];
                for (int i = indexPair.ColumnIndex + 1; i < (indexPair.ColumnIndex + element.ColumnSpan) && i < columns.Count; i++)
                {
                    columnSpace.Size += columnSpaces[i].Size;
                }

                var constraints = new Size(columnSpace.Size - (marginLeft + marginRight), rowSpace.Size - (marginTop + marginBottom));

                // labels are a bit special; as one dimension expands or contracts, the other dimension inversely contracts or expands.
                // because of this, if the column width is shorter than the label's desired width, the label will likely want more
                // vertical space than its desired height suggests.  to compensate for this, if the label spans any auto row,
                // we reset the vertical constraint before the label's final measurement and adjust any rows as needed.
                if (element is ILabel)
                {
                    int lastRow = Math.Min(rows.Count, indexPair.RowIndex + element.RowSpan);
                    for (int i = indexPair.RowIndex; i < lastRow; i++)
                    {
                        if (rows[i].UnitType == LayoutUnitType.Auto)
                        {
                            constraints.Height = double.MaxValue;
                            break;
                        }
                    }
                }

                constraints.Width  = Math.Max(constraints.Width, 0);
                constraints.Height = Math.Max(constraints.Height, 0);

                var finalSize      = element.Measure(constraints);
                var totalFinalSize = new Size(finalSize.Width + (marginLeft + marginRight), finalSize.Height + (marginTop + marginBottom));

                var desiredSize      = elementSizes.GetValueOrDefault(element);
                var totalDesiredSize = new Size(desiredSize.Width + (marginLeft + marginRight), desiredSize.Height + (marginTop + marginBottom));

                // if the final size is different from the desired size, see if any row or column needs adjustment.
                if (Math.Abs(totalFinalSize.Width - totalDesiredSize.Width) > 0.01)
                {
                    int trueColumnSpan = Math.Min(columns.Count - indexPair.ColumnIndex, element.ColumnSpan);
                    if (trueColumnSpan == 1 && columns[indexPair.ColumnIndex].UnitType == LayoutUnitType.Auto)
                    {
                        // if the final width is larger than the current size of the column, we need to expand the column.
                        // on the other hand, if this element is what determined the column's initial size and its final
                        // width is smaller, we need to shrink the column.
                        if (totalFinalSize.Width > columnSpace.Size || (totalDesiredSize.Width == columnSpace.Size &&
                                                                        !elementSizes.Any(e => e.Key != element && actualIndices[e.Key].ColumnIndex == indexPair.ColumnIndex &&
                                                                                          e.Value.Width + (marginLeft + marginRight) >= columnSpace.Size)))
                        {
                            columnSpace.Size = totalFinalSize.Width;
                            columnSpaces[indexPair.ColumnIndex] = columnSpace;
                            SizeColumns(grid, minimumSize.Width, availableGridWidth, columns, columnSpaces, baseStarColumnIndex, scale);

                            // SizeColumns may have shrunk the column if it was too large to fit in the grid
                            totalFinalSize.Width = columnSpaces[indexPair.ColumnIndex].Size;
                        }
                    }
                }

                if (Math.Abs(totalFinalSize.Height - totalDesiredSize.Height) > 0.01)
                {
                    int trueRowSpan = Math.Min(rows.Count - indexPair.RowIndex, element.RowSpan);
                    if (trueRowSpan == 1 && rows[indexPair.RowIndex].UnitType == LayoutUnitType.Auto)
                    {
                        // if the final height is larger than the current size of the row, we need to expand the row.
                        // on the other hand, if this element is what determined the row's initial size and its final
                        // height is smaller, we need to shrink the row.
                        if (totalFinalSize.Height > rowSpace.Size || (totalDesiredSize.Height == rowSpace.Size &&
                                                                      !elementSizes.Any(e => e.Key != element && actualIndices[e.Key].RowIndex == indexPair.RowIndex &&
                                                                                        e.Value.Height + (marginTop + marginBottom) >= rowSpace.Size)))
                        {
                            rowSpace.Size = totalFinalSize.Height;
                            rowSpaces[indexPair.RowIndex] = rowSpace;
                            SizeRows(grid, minimumSize.Height, availableGridHeight, rows, rowSpaces, baseStarRowIndex, scale);

                            // SizeRows may have shrunk the row if it was too large to fit in the grid
                            totalFinalSize.Height = rowSpaces[indexPair.RowIndex].Size;
                        }
                    }
                }

                finalSize = new Size(totalFinalSize.Width - (marginLeft + marginRight), totalFinalSize.Height - (marginTop + marginBottom));
                var availableArea = new Size(columnSpace.Size - (marginLeft + marginRight), rowSpace.Size - (marginTop + marginBottom));

                var image = element as IImage;
                if (image == null)
                {
                    var button = element as IButton;
                    if (button != null)
                    {
                        image = button.Image;
                    }
                }

                if (image != null)
                {
                    var dimensions = image.Dimensions;
                    var ratio      = dimensions.Width / dimensions.Height;
                    switch (image.Stretch)
                    {
                    case ContentStretch.Fill:
                    case ContentStretch.UniformToFill:
                        // in the case of UniformToFill, it is the platform's responsibility to clip the image
                        finalSize.Width  = availableArea.Width;
                        finalSize.Height = availableArea.Height;
                        break;

                    case ContentStretch.None:
                        // Stretch.None should still shrink the image if it's too large to fit in its space
                        if (finalSize.Width < dimensions.Width || finalSize.Height < dimensions.Height)
                        {
                            if (finalSize.Width > finalSize.Height * ratio)
                            {
                                finalSize.Width = finalSize.Height * ratio;
                            }
                            else if (finalSize.Width < finalSize.Height * ratio)
                            {
                                finalSize.Height = finalSize.Width / ratio;
                            }
                        }
                        break;

                    case ContentStretch.Uniform:
                        if (availableArea.Width > availableArea.Height * ratio)
                        {
                            finalSize.Width  = availableArea.Height * ratio;
                            finalSize.Height = availableArea.Height;
                        }
                        else if (availableArea.Width < availableArea.Height * ratio)
                        {
                            finalSize.Width  = availableArea.Width;
                            finalSize.Height = availableArea.Width / ratio;
                        }
                        break;
                    }
                }

                var location = new Point(columnSpace.Origin, rowSpace.Origin);

                switch (element.VerticalAlignment)
                {
                case VerticalAlignment.Stretch:
                    location.Y       = rowSpace.Origin + marginTop;
                    finalSize.Height = availableArea.Height;
                    break;

                case VerticalAlignment.Top:
                    location.Y       = rowSpace.Origin + marginTop;
                    finalSize.Height = Math.Min(finalSize.Height, availableArea.Height);
                    break;

                case VerticalAlignment.Bottom:
                    location.Y       = (rowSpace.Origin + rowSpace.Size) - (finalSize.Height + marginBottom);
                    finalSize.Height = Math.Min(finalSize.Height, availableArea.Height);
                    break;

                case VerticalAlignment.Center:
                    location.Y       = (availableArea.Height / 2f) - (finalSize.Height / 2f) + (rowSpace.Origin + marginTop);
                    finalSize.Height = Math.Min(finalSize.Height, availableArea.Height);
                    break;
                }

                switch (element.HorizontalAlignment)
                {
                case HorizontalAlignment.Stretch:
                    location.X      = columnSpace.Origin + marginLeft;
                    finalSize.Width = availableArea.Width;
                    break;

                case HorizontalAlignment.Left:
                    location.X      = columnSpace.Origin + marginLeft;
                    finalSize.Width = Math.Min(finalSize.Width, availableArea.Width);
                    break;

                case HorizontalAlignment.Right:
                    location.X      = (columnSpace.Origin + columnSpace.Size) - (finalSize.Width + marginRight);
                    finalSize.Width = Math.Min(finalSize.Width, availableArea.Width);
                    break;

                case HorizontalAlignment.Center:
                    location.X      = (availableArea.Width / 2f) - (finalSize.Width / 2f) + (columnSpace.Origin + marginLeft);
                    finalSize.Width = Math.Min(finalSize.Width, columnSpace.Size - marginLeft - marginRight);
                    break;
                }

                finalSize.Width  = Math.Max(finalSize.Width, 0);
                finalSize.Height = Math.Max(finalSize.Height, 0);

                elementSizes[element] = finalSize;
                element.SetLocation(location, finalSize);
            }

            // everything is laid out to the maximum size, so we know that we haven't exceeded it
            return(new Size(Math.Max(columnSpaces.Sum(c => c.Size) + scale * (grid.Padding.Left + grid.Padding.Right), minimumSize.Width),
                            Math.Max(rowSpaces.Sum(r => r.Size) + (grid.Padding.Top + grid.Padding.Bottom) * scale, minimumSize.Height)));
        }
Example #32
0
 public void GridLoaderDelegateLoadFromDiffCol(IGridBase grid, IBusinessObjectCollection col)
 {
     var dataSetProvider = new ReadOnlyDataSetProvider(_colToLoadFrom);
     IUIDef uiDef = ((ClassDef)col.ClassDef).GetUIDef(grid.UiDefName);
     var bindingListView = dataSetProvider.GetDataView(uiDef.UIGrid);
     grid.DataSource = bindingListView;
 }
Example #33
0
        private static void SizeColumns(IGridBase grid, double minimumWidth, double availableWidth, List <Column> columns, Space[] columnSpaces, int baseStarIndex, double scale)
        {
            for (int i = 0; i < columns.Count; i++)
            {
                if (columns[i].UnitType == LayoutUnitType.Auto)
                {
                    var space = columnSpaces[i];
                    if (space.Size > availableWidth)
                    {
                        space.Size      = availableWidth;
                        availableWidth  = 0;
                        columnSpaces[i] = space;
                    }
                    else
                    {
                        if (space.Size < 0)
                        {
                            space.Size      = 0;
                            columnSpaces[i] = space;
                        }
                        availableWidth -= columnSpaces[i].Size;
                    }
                }
            }

            double weightSum = columns.Where(c => c.UnitType == LayoutUnitType.Star).Sum(c => c.Width);
            double starWidth = availableWidth / weightSum;

            if (baseStarIndex >= 0)
            {
                weightSum += columns[baseStarIndex].Width;
                starWidth  = columnSpaces[baseStarIndex].Size * columns[baseStarIndex].Width;

                // check if starWidth is sufficient to cover minimum width
                double consumedWidth = starWidth * weightSum;
                for (int i = 0; i < columns.Count; i++)
                {
                    if (i == baseStarIndex)
                    {
                        continue;
                    }

                    var column = columns[i];
                    if (column.UnitType != LayoutUnitType.Star)
                    {
                        consumedWidth += columnSpaces[i].Size;
                    }
                }

                double minWidth = minimumWidth - ((grid.Padding.Left + grid.Padding.Right) * scale);
                if (consumedWidth < minWidth)
                {
                    starWidth += (minWidth - consumedWidth) / weightSum;
                    columnSpaces[baseStarIndex] = new Space()
                    {
                        Size = starWidth * columns[baseStarIndex].Width
                    };
                }
            }

            for (int cIndex = 0; cIndex < columns.Count; cIndex++)
            {
                var column = columns[cIndex];
                var space  = columnSpaces[cIndex];
                if (column.UnitType == LayoutUnitType.Star)
                {
                    space.Size           = column.Width * starWidth;
                    columnSpaces[cIndex] = space;
                }

                if (grid.Columns.Count > cIndex)
                {
                    grid.Columns[cIndex] = new Column(column, space.Size / scale);
                }
            }

            // if width is less than minimum, stretch the last auto column that has a size > 0
            double extraCellWidth = minimumWidth - columnSpaces.Sum(c => c.Size) - ((grid.Padding.Left + grid.Padding.Right) * scale);

            if (extraCellWidth > 0)
            {
                for (int i = columns.Count - 1; i >= 0; i--)
                {
                    var column = columns[i];
                    var space  = columnSpaces[i];
                    if (column.UnitType != LayoutUnitType.Auto || space.Size <= 0)
                    {
                        continue;
                    }

                    space.Size     += extraCellWidth;
                    columnSpaces[i] = space;

                    if (grid.Columns.Count > i)
                    {
                        grid.Columns[i] = new Column(column, space.Size / scale);
                    }
                    break;
                }
            }

            columnSpaces[0].Origin = grid.Padding.Left * scale;
            for (int cIndex = 1; cIndex < columnSpaces.Length; cIndex++)
            {
                var previous = columnSpaces[cIndex - 1];
                columnSpaces[cIndex].Origin = previous.Origin + previous.Size;
            }
        }
 ///<summary>
 /// Initialise the grid with the appropriate control factory.
 ///</summary>
 ///<param name="gridBase"></param>
 ///<param name="controlFactory"></param>
 internal GridBaseInitialiserSpy(IGridBase gridBase, IControlFactory controlFactory): base(gridBase, controlFactory)
 {
 }
 public GridBaseManagerBindingList(IGridBase gridBase) : base(gridBase)
 {
 }
 protected override IFormHabanero AddControlToForm(IGridBase gridBase)
 {
     Gizmox.WebGUI.Forms.Form frm = new Gizmox.WebGUI.Forms.Form();
     frm.Controls.Add((Gizmox.WebGUI.Forms.Control)gridBase);
     return(null);
 }
 protected override void AssertCorrectSelectionMode(IGridBase dataGridView)
 {
     System.Windows.Forms.DataGridView grid = (System.Windows.Forms.DataGridView)dataGridView;
     Assert.AreEqual(System.Windows.Forms.DataGridViewSelectionMode.RowHeaderSelect, grid.SelectionMode);
 }
 protected override IFormHabanero AddControlToForm(IGridBase gridBase)
 {
     Gizmox.WebGUI.Forms.Form frm = new Gizmox.WebGUI.Forms.Form();
     frm.Controls.Add((Gizmox.WebGUI.Forms.Control)gridBase);
     return null;
 }
 ///<summary>
 /// Returns the Total width of the Selector. <see cref="IGridBase"/>. This is used so that the 
 ///   Selector and BOEditor can be layed out.
 ///</summary>
 ///<param name="grid"></param>
 ///<returns></returns>
 public static int GetGridWidthToFitColumns(IGridBase grid)
 {
     int width = 0;
     if (grid.RowHeadersVisible)
     {
         width = grid.RowHeadersWidth;
     }
     foreach (IDataGridViewColumn column in grid.Columns)
     {
         if (column.Visible) width += column.Width;
     }
     return width;
 }
 protected abstract void AssertCorrectSelectionMode(IGridBase dataGridView);
Example #41
0
 protected override void AddControlToForm(IGridBase gridBase)
 {
     Gizmox.WebGUI.Forms.Form frm = new Gizmox.WebGUI.Forms.Form();
     frm.Controls.Add((Gizmox.WebGUI.Forms.Control)gridBase);
 }
 protected abstract IFormHabanero AddControlToForm(IGridBase gridBase);
Example #43
0
 public GridBaseManagerBindingList(IGridBase gridBase) : base(gridBase)
 {
 }
Example #44
0
 private static void GridLoaderDelegate(IGridBase grid, IBusinessObjectCollection col)
 {
     //grid.Rows.Clear();
     if (col == null)
     {
         grid.DataSource = null;
         return;
     }
     foreach (IBusinessObject businessObject in col)
     {
         MyBO asset = (MyBO)businessObject;
         grid.Rows.Add(
             asset.ID.ObjectID,
             asset.TestProp);
     }
 }
 protected override void AssertCorrectSelectionMode(IGridBase dataGridView)
 {
     Gizmox.WebGUI.Forms.DataGridView grid = (Gizmox.WebGUI.Forms.DataGridView)dataGridView;
     Assert.AreEqual(Gizmox.WebGUI.Forms.DataGridViewSelectionMode.RowHeaderSelect, grid.SelectionMode);
 }
Example #46
0
 ///<summary>
 /// Constructor
 ///</summary>
 ///<param name="gridBase"></param>
 public GridBaseManager(IGridBase gridBase) : this(gridBase, "default")
 {
 }
 protected override void AddControlToForm(IGridBase gridBase)
 {
     Gizmox.WebGUI.Forms.Form frm = new Gizmox.WebGUI.Forms.Form();
     frm.Controls.Add((Gizmox.WebGUI.Forms.Control)gridBase);
 }
 private static int GetColumnCount(IGridBase dataGrid)
 {
     var test = 0;
     var error = false;
     while (!error)
     {
         try
         {
             var testVal = dataGrid.Rows[0].Cells[test];
             test++;
         }
         catch (Exception)
         {
             error = true;
         }
     }
     return test;
 }
Example #49
0
 protected override void AddControlToForm(IGridBase gridBase)
 {
     System.Windows.Forms.Form frm = new System.Windows.Forms.Form();
     frm.Controls.Add((System.Windows.Forms.Control)gridBase);
 }
Example #50
0
        public GenericGridFilterControlWin(IGridBase grid)
        {
            var ds = grid.DataSource as DataView;

            if (ds != null)
            {
                this._originalView = ds;
            }
            (grid as DataGridView).DataSourceChanged += this.DataSourceChanged;

            this._lastForcedEvents = DateTime.Now;
            this.Grid   = grid;
            this._timer = new Timer()
            {
                Enabled  = true,
                Interval = 500,
            };
            this._timer.Tick += (sender, e) =>
            {
                if ((this._filterRequired) && (this._lastFilterChanged.AddMilliseconds(this._timer.Interval) < DateTime.Now))
                {
                    if (this._inFilter)
                    {
                        this._cancelCurrentFilter = true;
                    }
                    this._filterRequired = false;
                    this.DoFilter();
                }
            };

            var factory = new ControlFactoryWin();

            this._filterLabel   = factory.CreateLabel("Filter:");
            this._filterTextBox = factory.CreateTextBox();
            var txt = this._filterTextBox as TextBox;

            txt.TextChanged += (sender, e) =>
            {
                if (txt.Text == this._lastFilterText)
                {
                    return;
                }
                this._lastFilterChanged = DateTime.Now;
                this._filterRequired    = true;
            };
            var manager = factory.CreateBorderLayoutManager(this);

            manager.AddControl(this._filterLabel, BorderLayoutManager.Position.West);
            manager.AddControl(this._filterTextBox, BorderLayoutManager.Position.Centre);
            var vgap = manager.VerticalGapSize + manager.BorderSize;

            this.Height = this._filterTextBox.Height + 2 * vgap;

            this.FilterStarted += (sender, e) =>
            {
                this.SetUIState(true);
            };
            this.FilterCompleted += (sender, e) =>
            {
                this.SetUIState(false);
            };
            var wingrid = Grid as DataGridView;

            if (wingrid != null)
            {
                this._gridOriginalAlternatingStyle              = wingrid.AlternatingRowsDefaultCellStyle;
                wingrid.AlternatingRowsDefaultCellStyleChanged += this.RecordGridAltStyle;
            }
        }
 /// <summary>
 /// Sets the default grid loader which is used as the default for the GridLoader delegate.
 /// If you want to load in any other way then please set the <see cref="GridLoader"/>
 /// delegate to load your business objects as you require.
 /// </summary>
 public void DefaultGridLoader(IGridBase gridBase, IBusinessObjectCollection boCol)
 {
     if (boCol == null)
     {
         gridBase.DataSource = null;
         return;
     }
     var bindingListView = GetBindingListView(boCol);
     try
     {
         gridBase.SelectionChanged -= _gridBaseOnSelectionChangedHandler;
         _fireBusinessObjectSelectedEvent = false;
         gridBase.DataSource = bindingListView;
         if (!AutoSelectFirstItem) gridBase.SelectedBusinessObject = null;
     }
     finally
     {
         gridBase.SelectionChanged += _gridBaseOnSelectionChangedHandler;
         _fireBusinessObjectSelectedEvent = true;
     }
 }
 protected abstract void AssertCorrectSelectionMode(IGridBase dataGridView);
 ///<summary>
 /// Constructor
 ///</summary>
 ///<param name="gridBase"></param>
 public GridBaseManager(IGridBase gridBase) : this(gridBase, "default")
 {
 }
 protected abstract IFormHabanero AddControlToForm(IGridBase gridBase);
Example #55
0
 protected override void AssertCorrectSelectionMode(IGridBase dataGridView)
 {
     System.Windows.Forms.DataGridView grid = (System.Windows.Forms.DataGridView)dataGridView;
     Assert.AreEqual(System.Windows.Forms.DataGridViewSelectionMode.RowHeaderSelect, grid.SelectionMode);
 }
 ///<summary>
 /// Initialise the grid with the appropriate control factory.
 ///</summary>
 ///<param name="gridBase"></param>
 ///<param name="controlFactory"></param>
 internal GridBaseInitialiserSpy(IGridBase gridBase, IControlFactory controlFactory) : base(gridBase, controlFactory)
 {
 }