示例#1
0
        private void FitColumnWidthToHeaderAndContents(GridRow currentRow, Point p)
        {
            GridHeaderItem headerItem = (GridHeaderItem)currentRow.FindItemFromPoint(new Point(p.X - GridHeaderItem.ResizeGutter, p.Y), out ResizeColumnsInitialMouseLocation);

            ResizeColumnsInitialMouseLocation.X += GridHeaderItem.ResizeGutter;
            ActiveColumn = headerItem.ColumnName;

            if (HeaderRow.Items.ContainsKey(ActiveColumn))
            {
                int maxWidth = headerItem.MinimumWidth;

                foreach (GridRow row in RowsAndChildren)
                {
                    GridItemBase _item     = row.GetItem(ActiveColumn);
                    int          itemWidth = _item.GetGridItemWidth(ActiveColumn);

                    if (itemWidth > maxWidth)
                    {
                        maxWidth = itemWidth;
                    }
                }

                headerItem.Width = maxWidth;
                Refresh();
            }
        }
        public void UpdateCompareOrder()
        {
            List <SortParams> lst = new List <SortParams>();

            for (int i = 0; i < Items.Count; i++)
            {
                foreach (string col in Items.Keys)
                {
                    GridHeaderItem ghi = (GridHeaderItem)Items[col];
                    if (ghi.SortPriority == i)
                    {
                        lst.Add(new SortParams(col, ghi.Sort));
                        break;
                    }
                }
            }
            CompareOrder = lst;
        }
        public override void AddItem(string col, GridItemBase item)
        {
            GridHeaderItem headerItem = item as GridHeaderItem;

            if (headerItem == null)
            {
                return;
            }

            if (headerItem.IsDefaultSortColumn)
            {
                DefaultSortColumn = headerItem;
            }

            Columns.Add(col);
            headerItem.ColumnName = col;
            base.AddItem(col, item);
        }
        public void UpdateCellSorts(List <SortParams> lst)
        {
            foreach (string col in Items.Keys)
            {
                GridHeaderItem ghi = (GridHeaderItem)Items[col];
                ghi.UnsetSort();
            }

            int i = 0;

            foreach (SortParams sp in lst)
            {
                if (!Items.ContainsKey(sp.Column))
                {
                    continue;
                }

                GridHeaderItem ghi = (GridHeaderItem)Items[sp.Column];
                ghi.SetSort(i++, sp.SortOrder);
            }

            UpdateCompareOrder();  // don't just set it to lst in case we had to leave some out
        }
示例#5
0
        private bool PreviousUnsizable()
        {
            GridHeaderRow hr     = (GridHeaderRow)Row;
            int           tindex = hr.Columns.IndexOf(ColumnName);

            if (tindex <= 0)
            {
                return(true);
            }
            string       tother = hr.Columns[tindex - 1];
            GridItemBase prevItem;

            if (!hr.Items.TryGetValue(tother, out prevItem))
            {
                return(true);
            }
            GridHeaderItem prevHeader = prevItem as GridHeaderItem;

            if (prevHeader == null)
            {
                return(true);
            }
            return(prevHeader.UnSizable);
        }
示例#6
0
        private void OnMouseMove_(MouseEventArgs e)
        {
            if (Disposing || IsDisposed || Program.Exiting)
            {
                return;
            }

            if (HeaderRow == null)
            {
                return;
            }

            if (DraggingItems)
            {
                return;
            }

            if (DraggingColumns)
            {
                int x    = e.Location.X - DragColumnsMouseLocation.X;
                int xmax = TotalWidth() - DragColumnsData.Width;
                DragColumnsWindowPosition = new Point(x <= 0 ? 0 : x < xmax ? x : xmax, 0);
                string swapwith = "";
                int    left     = Padding.Left;
                foreach (string index in HeaderRow.Columns)
                {
                    int width = GetColumnWidth(index, 1);
                    if (((GridHeaderItem)HeaderRow.Items[index]).Immovable)
                    {
                        left += width;
                        continue;
                    }
                    if (e.X - AutoScrollPosition.X < left + (width / 2))
                    {
                        swapwith = index;
                        break;
                    }
                    left += width;
                }

                if (string.IsNullOrEmpty(swapwith))
                {
                    swapwith = "end";
                }

                if (swapwith != DragColumnsLastEntered)
                {
                    if (swapwith == "end")
                    {
                        HeaderRow.Columns.Remove(ActiveColumn);
                        HeaderRow.Columns.Add(ActiveColumn);
                    }
                    else
                    {
                        int movedn    = HeaderRow.Columns.IndexOf(ActiveColumn);
                        int replacedn = HeaderRow.Columns.IndexOf(swapwith);
                        if (movedn > replacedn)
                        {
                            HeaderRow.Columns.Remove(ActiveColumn);
                            HeaderRow.Columns.Insert(replacedn, ActiveColumn);
                        }
                        else if (movedn < replacedn)
                        {
                            HeaderRow.Columns.Insert(replacedn, ActiveColumn);
                            HeaderRow.Columns.Remove(ActiveColumn);
                        }
                    }
                    DragColumnsLastEntered = swapwith;
                    Refresh();
                }
                else
                {
                    OnPaint(null);
                }
            }
            else if (ResizingColumns)
            {
                if (HeaderRow.Items.ContainsKey(ActiveColumn))
                {
                    GridHeaderItem item     = (HeaderRow.Items[ActiveColumn] as GridHeaderItem);
                    int            newWidth = item.Width + (e.Location.X - ResizeColumnsInitialMouseLocation.X);
                    if (newWidth > item.MinimumWidth)
                    {
                        item.Width = newWidth;
                        ResizeColumnsInitialMouseLocation = e.Location;
                    }
                    else
                    {
                        item.Width = item.MinimumWidth;
                    }
                    Refresh();
                }
            }
            else if (e.Button == MouseButtons.Left && string.IsNullOrEmpty(ActiveColumn) &&
                     DragDistance(lastClickedPoint, e.Location) >= 2) // don't start dragging unles we've moved a little distance
            // TODO: consider replacing the above with SystemParameters.MinimumHorizontalDragDistance etc. when we move to .NET 3.0
            {
                Point   p;
                GridRow row = FindRowFromPoint(lastClickedPoint, out p);  // the drag is then based on the mouse-down location
                if (row is GridHeaderRow)
                {
                    GridHeaderItem item = (GridHeaderItem)row.FindItemFromPoint(new Point(p.X - GridHeaderItem.ResizeGutter, p.Y), out DragColumnsMouseLocation);
                    DragColumnsMouseLocation.X += GridHeaderItem.ResizeGutter;
                    if (item == null)
                    {
                        return;
                    }

                    ActiveColumn = item.ColumnName;
                    int colwidth = GetColumnWidth(ActiveColumn, 1);

                    if (!item.UnSizable && DragColumnsMouseLocation.X >= colwidth - GridHeaderItem.ResizeGutter)
                    {
                        ResizingColumns = true;
                        ResizeColumnsInitialMouseLocation = lastClickedPoint;
                    }
                    else if (!item.Immovable)
                    {
                        DraggingColumns = true;
                        item.GreyOut    = true;
                        DragColumnsData = new Bitmap(GetColumnWidth(ActiveColumn, 1), ClientSize.Height);

                        Graphics ddGraphics = Graphics.FromImage(DragColumnsData);
                        ddGraphics.Clear(BackColor);
                        XenAdmin.Core.Drawing.QuickDraw(ddGraphics, BackBuffer, new Point((lastClickedPoint.X - DragColumnsMouseLocation.X), 0), new Rectangle(0, 0, DragColumnsData.Width, DragColumnsData.Height));
                        ddGraphics.Dispose();

                        DragColumnsBuffer   = new Bitmap(ClientSize.Width, ClientSize.Height);
                        DragColumnsGraphics = Graphics.FromImage(DragColumnsBuffer);
                    }
                }
                else if (row != null)
                {
                    row.OnMouseButtonAction(p, MouseButtonAction.StartDrag);
                }
            }
            else
            {
                Point   p;
                GridRow row = FindRowFromPoint(e.Location, out p);
                if (LastRow == null && row == null)
                {
                    return;
                }

                if (LastRow == row)
                {
                    LastRow.OnMouseMove(p);
                }
                else
                {
                    if (LastRow != null)
                    {
                        LastRow.OnLeave();
                    }

                    LastRow = row;

                    if (LastRow != null)
                    {
                        LastRow.OnEnter(p);
                    }
                }
            }
        }
示例#7
0
        public override void AddItem(string col, GridItemBase item)
        {
            GridHeaderItem headerItem = item as GridHeaderItem;
            if (headerItem == null)
                return;

            if (headerItem.IsDefaultSortColumn)
                DefaultSortColumn = headerItem;

            Columns.Add(col);
            headerItem.ColumnName = col;
            base.AddItem(col, item);
        }