示例#1
0
 void EndFloatingObjectsMoving()
 {
     if ((((_dragStartRowViewport == -2) || (_dragStartColumnViewport == -2)) || ((_floatingObjectsMovingResizingStartRow == -2) || (_floatingObjectsMovingResizingStartColumn == -2))) || (((_dragToRowViewport == -2) || (_dragToColumnViewport == -2)) || ((_dragToRow == -2) || (_dragToColumn == -2))))
     {
         ResetFloatingObjectsMovingResizing();
         StopScrollTimer();
     }
     else
     {
         bool ctrl  = false;
         bool shift = false;
         KeyboardHelper.GetMetaKeyState(out shift, out ctrl);
         if (ctrl)
         {
             DoDragFloatingObjects();
         }
         else
         {
             DoMoveFloatingObjects();
         }
         InvalidateFloatingObjectsLayoutModel();
         RefreshViewportFloatingObjectsLayout();
         ResetFloatingObjectsMovingResizing();
         StopScrollTimer();
         if (InputDeviceType == InputDeviceType.Touch)
         {
             base.InvalidateMeasure();
         }
     }
 }
示例#2
0
        private void Cell_Click(object sender, RoutedEventArgs e)
        {
            if (this.Owner != null)
            {
                bool ctrl, shift;
                KeyboardHelper.GetMetaKeyState(out ctrl, out shift);

                if (ctrl && this.Owner.SelectionMode == CalendarSelectionMode.MultipleRange)
                {
                    CalendarDayButton b = sender as CalendarDayButton;
                    Debug.Assert(b != null);

                    if (b.IsSelected)
                    {
                        this.Owner._hoverStart      = null;
                        this._isMouseLeftButtonDown = false;
                        b.IsSelected = false;
                        if (b.DataContext != null)
                        {
                            this.Owner.SelectedDates.Remove((DateTime)b.DataContext);
                        }
                    }
                }
            }
        }
示例#3
0
 void SetCursor(HitTestInformation hi)
 {
     if (CanUserDragFill && hi.ViewportInfo.InDragFillIndicator)
     {
         bool flag;
         bool flag2;
         KeyboardHelper.GetMetaKeyState(out flag, out flag2);
         CursorType cursorType = flag2 ? CursorType.DragFill_CtrlDragCursor : CursorType.DragFill_DragCursor;
         SetMouseCursor(cursorType);
     }
     else if (CanUserDragDrop && hi.ViewportInfo.InSelectionDrag)
     {
         bool flag3;
         bool flag4;
         KeyboardHelper.GetMetaKeyState(out flag3, out flag4);
         CursorType type2 = flag4 ? CursorType.DragCell_CtrlDragCursor : CursorType.DragCell_DragCursor;
         SetMouseCursor(type2);
     }
     else
     {
         if (_mouseCursor != null)
         {
             _mouseCursor.Opacity = 0.0;
         }
         ResetCursor();
     }
 }
示例#4
0
        private void Cell_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (this.Owner != null)
            {
                bool ctrl, shift;
                KeyboardHelper.GetMetaKeyState(out ctrl, out shift);
                CalendarDayButton b = sender as CalendarDayButton;
                if (b != null && !b.IsDisabled)
                {
                    this.Owner.OnDayButtonMouseUp(e);
                }
                _isMouseLeftButtonDown = false;
                if (b != null && b.DataContext != null)
                {
                    if (this.Owner.SelectionMode == CalendarSelectionMode.None || this.Owner.SelectionMode == CalendarSelectionMode.SingleDate)
                    {
                        this.Owner.OnDayClick((DateTime)b.DataContext);
                        return;
                    }
                    if (this.Owner._hoverStart.HasValue)
                    {
                        switch (this.Owner.SelectionMode)
                        {
                        case CalendarSelectionMode.SingleRange:
                        {
                            //Update SelectedDates
                            foreach (DateTime item in this.Owner.SelectedDates)
                            {
                                this.Owner._removedItems.Add(item);
                            }
                            this.Owner.SelectedDates.ClearInternal();
                            AddSelection(b);
                            return;
                        }

                        case CalendarSelectionMode.MultipleRange:
                        {
                            //add the selection (either single day or SingleRange day)
                            AddSelection(b);
                            return;
                        }
                        }
                    }
                    else
                    {
                        //If the day is Disabled but a trailing day we should be able to switch months
                        if (b.IsInactive && b.IsDisabled)
                        {
                            this.Owner.OnDayClick((DateTime)b.DataContext);
                        }
                    }
                }
            }
        }
示例#5
0
        bool AllowEnterEditing(KeyRoutedEventArgs e)
        {
            bool flag;
            bool flag2;
            bool flag3;

            KeyboardHelper.GetMetaKeyState(out flag, out flag2, out flag3);
            if (flag2 || flag3)
            {
                return(false);
            }
            if (((((e.Key != VirtualKey.Space) && (((VirtualKey.Search | VirtualKey.Shift) > e.Key) || (e.Key > ((VirtualKey)0xc0)))) && (((VirtualKey.Scroll | VirtualKey.J) > e.Key) || (e.Key > (VirtualKey.NumberKeyLock | VirtualKey.N)))) && (((VirtualKey.Number0 > e.Key) || (e.Key > VirtualKey.Number9)) && ((VirtualKey.A > e.Key) || (e.Key > VirtualKey.Z)))) && ((VirtualKey.NumberPad0 > e.Key) || (e.Key > VirtualKey.NumberPad9)))
            {
                return((VirtualKey.Multiply <= e.Key) && (e.Key <= VirtualKey.Divide));
            }
            return(true);
        }
示例#6
0
        private void FinishSelection(DateTime selectedDate)
        {
            bool ctrl, shift;

            KeyboardHelper.GetMetaKeyState(out ctrl, out shift);

            if (this.Owner.SelectionMode == CalendarSelectionMode.None || this.Owner.SelectionMode == CalendarSelectionMode.SingleDate)
            {
                this.Owner.OnDayClick(selectedDate);
                return;
            }

            if (this.Owner.HoverStart.HasValue)
            {
                switch (this.Owner.SelectionMode)
                {
                case CalendarSelectionMode.SingleRange:
                {
                    // Update SelectedDates
                    this.Owner.SelectedDates.ClearInternal();
                    EndDrag(ctrl, selectedDate);
                    break;
                }

                case CalendarSelectionMode.MultipleRange:
                {
                    // add the selection (either single day or SingleRange day)
                    EndDrag(ctrl, selectedDate);
                    break;
                }
                }
            }
            else
            {
                // If the day is blacked out but also a trailing day we should be able to switch months
                CalendarDayButton b = GetCalendarDayButton(selectedDate);
                if (b != null && b.IsInactive && b.IsBlackedOut)
                {
                    this.Owner.OnDayClick(selectedDate);
                }
            }
        }
示例#7
0
 void UnSelectFloatingObject(FloatingObject floatingObject)
 {
     try
     {
         if (!_isMouseDownFloatingObject)
         {
             bool flag;
             bool flag2;
             KeyboardHelper.GetMetaKeyState(out flag, out flag2);
             if (((flag2 || flag) && !(floatingObject.Locked && ActiveSheet.Protect)) && floatingObject.IsSelected)
             {
                 floatingObject.IsSelected = false;
             }
         }
     }
     finally
     {
         _isMouseDownFloatingObject = false;
     }
 }
示例#8
0
        internal Rect[] GetFloatingObjectsMovingFrameRects(int rowViewport, int columnViewport)
        {
            var allSelectedFloatingObjects = GetAllSelectedFloatingObjects();

            if ((allSelectedFloatingObjects == null) || (allSelectedFloatingObjects.Count == 0))
            {
                return(null);
            }
            List <Rect> list          = new List <Rect>();
            Point       mousePosition = MousePosition;

            new Point(mousePosition.X - _floatingObjectsMovingResizingStartPoint.X, mousePosition.Y - _floatingObjectsMovingResizingStartPoint.Y);
            FloatingObjectLayoutModel cacheFloatingObjectsMovingResizingLayoutModels = GetCacheFloatingObjectsMovingResizingLayoutModels(rowViewport, columnViewport);

            foreach (FloatingObject obj2 in allSelectedFloatingObjects)
            {
                bool flag;
                bool flag2;
                FloatingObjectLayout layout = cacheFloatingObjectsMovingResizingLayoutModels.Find(obj2.Name);
                Point  point2 = new Point(_floatingObjectsMovingResizingStartPoint.X - layout.X, _floatingObjectsMovingResizingStartPoint.Y - layout.Y);
                double x      = mousePosition.X - point2.X;
                double y      = mousePosition.Y - point2.Y;
                KeyboardHelper.GetMetaKeyState(out flag, out flag2);
                if (flag)
                {
                    double num3 = x - layout.X;
                    double num4 = y - layout.Y;
                    if (Math.Abs(num3) > Math.Abs(num4))
                    {
                        y = layout.Y;
                    }
                    else
                    {
                        x = layout.X;
                    }
                }
                list.Add(new Rect(x, y, layout.Width, layout.Height));
            }
            return(list.ToArray());
        }
示例#9
0
 void OnKeyUp(object sender, KeyRoutedEventArgs e)
 {
     UpdateCursorType();
     if (!IsEditing)
     {
         bool       flag;
         bool       flag2;
         VirtualKey keyCode = e.Key;
         KeyboardHelper.GetMetaKeyState(out flag, out flag2);
         VirtualKeyModifiers none = VirtualKeyModifiers.None;
         if (flag2)
         {
             none |= VirtualKeyModifiers.Control;
         }
         if (flag)
         {
             none |= VirtualKeyModifiers.None | VirtualKeyModifiers.Shift;
         }
         KeyStroke stroke = new KeyStroke(keyCode, none, true);
         if (KeyMap.ContainsKey(stroke))
         {
             SpreadAction action = KeyMap[stroke];
             if (action != null)
             {
                 ActionEventArgs args = new ActionEventArgs();
                 action(this, args);
                 if (args.Handled)
                 {
                     e.Handled = true;
                 }
             }
         }
     }
     if (IsDragDropping)
     {
         SwitchDragDropIndicator();
     }
 }
示例#10
0
 void UpdateCursorType()
 {
     if ((_mouseCursor != null) && (_mouseCursor.Opacity != 0.0))
     {
         HitTestInformation savedHitTestInformation = GetHitInfo();
         if ((((savedHitTestInformation != null) && (savedHitTestInformation.ViewportInfo != null)) && savedHitTestInformation.ViewportInfo.InDragFillIndicator) || IsDraggingFill)
         {
             bool flag;
             bool flag2;
             KeyboardHelper.GetMetaKeyState(out flag, out flag2);
             CursorType cursorType = flag2 ? CursorType.DragFill_CtrlDragCursor : CursorType.DragFill_DragCursor;
             UpdateMouseCursorType(cursorType);
         }
         else if ((((savedHitTestInformation != null) && (savedHitTestInformation.ViewportInfo != null)) && savedHitTestInformation.ViewportInfo.InSelectionDrag) || IsDragDropping)
         {
             bool flag3;
             bool flag4;
             KeyboardHelper.GetMetaKeyState(out flag3, out flag4);
             CursorType type2 = flag4 ? CursorType.DragCell_CtrlDragCursor : CursorType.DragCell_DragCursor;
             UpdateMouseCursorType(type2);
         }
     }
 }
示例#11
0
        private void Cell_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            CalendarDayButton b = sender as CalendarDayButton;

            if (b == null)
            {
                return;
            }

            if (this.Owner == null || !(b.DataContext is DateTime))
            {
                return;
            }

            if (b.IsBlackedOut)
            {
                this.Owner.HoverStart = null;
            }
            else
            {
                this._isDayPressed = true;
                Mouse.Capture(this, CaptureMode.SubTree);

                b.MoveFocus(new TraversalRequest(FocusNavigationDirection.First));

                bool ctrl, shift;
                KeyboardHelper.GetMetaKeyState(out ctrl, out shift);

                DateTime selectedDate = (DateTime)b.DataContext;
                Debug.Assert(selectedDate != null);

                switch (this.Owner.SelectionMode)
                {
                case CalendarSelectionMode.None:
                {
                    break;
                }

                case CalendarSelectionMode.SingleDate:
                {
                    this.Owner.DatePickerDisplayDateFlag = true;
                    if (!ctrl)
                    {
                        this.Owner.SelectedDate = selectedDate;
                    }
                    else
                    {
                        this.Owner.SelectedDates.Toggle(selectedDate);
                    }

                    break;
                }

                case CalendarSelectionMode.SingleRange:
                {
                    this.Owner.SelectedDates.ClearInternal();

                    if (shift)
                    {
                        if (!this.Owner.HoverStart.HasValue)
                        {
                            this.Owner.HoverStart = this.Owner.HoverEnd = this.Owner.CurrentDate;
                        }
                    }
                    else
                    {
                        this.Owner.HoverStart = this.Owner.HoverEnd = selectedDate;
                    }

                    break;
                }

                case CalendarSelectionMode.MultipleRange:
                {
                    if (!ctrl)
                    {
                        this.Owner.SelectedDates.ClearInternal();
                    }

                    if (shift)
                    {
                        if (!this.Owner.HoverStart.HasValue)
                        {
                            this.Owner.HoverStart = this.Owner.HoverEnd = this.Owner.CurrentDate;
                        }
                    }
                    else
                    {
                        this.Owner.HoverStart = this.Owner.HoverEnd = selectedDate;
                    }

                    break;
                }
                }

                this.Owner.CurrentDate = selectedDate;
                this.Owner.UpdateCellItems();
            }
        }
        private void ProcessSort()
        {
            if (this.OwningColumn != null &&
                this.OwningGrid != null &&
                this.OwningGrid.EditingRow == null &&
                this.OwningColumn != this.OwningGrid.ColumnsInternal.FillerColumn &&
                this.OwningGrid.CanUserSortColumns &&
                this.OwningColumn.CanUserSort)
            {
                DataGridColumnEventArgs ea = new DataGridColumnEventArgs(this.OwningColumn);
                this.OwningGrid.OnColumnSorting(ea);

#if FEATURE_ICOLLECTIONVIEW_SORT
                if (!ea.Handled && this.OwningGrid.DataConnection.AllowSort && this.OwningGrid.DataConnection.SortDescriptions != null)
                {
                    // - DataConnection.AllowSort is true, and
                    // - SortDescriptionsCollection exists, and
                    // - the column's data type is comparable
                    DataGrid          owningGrid = this.OwningGrid;
                    ListSortDirection newSortDirection;
                    SortDescription   newSort;

                    bool ctrl;
                    bool shift;

                    KeyboardHelper.GetMetaKeyState(out ctrl, out shift);

                    SortDescription?sort           = this.OwningColumn.GetSortDescription();
                    ICollectionView collectionView = owningGrid.DataConnection.CollectionView;
                    Debug.Assert(collectionView != null);
                    try
                    {
                        owningGrid.OnUserSorting();
                        using (collectionView.DeferRefresh())
                        {
                            // If shift is held down, we multi-sort, therefore if it isn't, we'll clear the sorts beforehand
                            if (!shift || owningGrid.DataConnection.SortDescriptions.Count == 0)
                            {
                                if (collectionView.CanGroup && collectionView.GroupDescriptions != null)
                                {
                                    // Make sure we sort by the GroupDescriptions first
                                    for (int i = 0; i < collectionView.GroupDescriptions.Count; i++)
                                    {
                                        PropertyGroupDescription groupDescription = collectionView.GroupDescriptions[i] as PropertyGroupDescription;
                                        if (groupDescription != null && collectionView.SortDescriptions.Count <= i || collectionView.SortDescriptions[i].PropertyName != groupDescription.PropertyName)
                                        {
                                            collectionView.SortDescriptions.Insert(Math.Min(i, collectionView.SortDescriptions.Count), new SortDescription(groupDescription.PropertyName, ListSortDirection.Ascending));
                                        }
                                    }
                                    while (collectionView.SortDescriptions.Count > collectionView.GroupDescriptions.Count)
                                    {
                                        collectionView.SortDescriptions.RemoveAt(collectionView.GroupDescriptions.Count);
                                    }
                                }
                                else if (!shift)
                                {
                                    owningGrid.DataConnection.SortDescriptions.Clear();
                                }
                            }

                            if (sort.HasValue)
                            {
                                // swap direction
                                switch (sort.Value.Direction)
                                {
                                case ListSortDirection.Ascending:
                                    newSortDirection = ListSortDirection.Descending;
                                    break;

                                default:
                                    newSortDirection = ListSortDirection.Ascending;
                                    break;
                                }

                                newSort = new SortDescription(sort.Value.PropertyName, newSortDirection);

                                // changing direction should not affect sort order, so we replace this column's
                                // sort description instead of just adding it to the end of the collection
                                int oldIndex = owningGrid.DataConnection.SortDescriptions.IndexOf(sort.Value);
                                if (oldIndex >= 0)
                                {
                                    owningGrid.DataConnection.SortDescriptions.Remove(sort.Value);
                                    owningGrid.DataConnection.SortDescriptions.Insert(oldIndex, newSort);
                                }
                                else
                                {
                                    owningGrid.DataConnection.SortDescriptions.Add(newSort);
                                }
                            }
                            else
                            {
                                // start new sort
                                newSortDirection = ListSortDirection.Ascending;

                                string propertyName = this.OwningColumn.GetSortPropertyName();

                                // no-opt if we couldn't find a property to sort on
                                if (string.IsNullOrEmpty(propertyName))
                                {
                                    return;
                                }

                                newSort = new SortDescription(propertyName, newSortDirection);

                                owningGrid.DataConnection.SortDescriptions.Add(newSort);
                            }
                        }
                    }
                    finally
                    {
                        owningGrid.OnUserSorted();
                    }

                    sortProcessed = true;
                }
#endif

                // Send the Invoked event for the column header's automation peer.
                DataGridAutomationPeer.RaiseAutomationInvokeEvent(this);
            }
        }
示例#13
0
        //TODO GroupSorting
        internal void ProcessSort(KeyModifiers keyModifiers)
        {
            // if we can sort:
            //  - DataConnection.AllowSort is true, and
            //  - AllowUserToSortColumns and CanSort are true, and
            //  - OwningColumn is bound, and
            //  - SortDescriptionsCollection exists, and
            //  - the column's data type is comparable
            // then try to sort
            if (OwningColumn != null &&
                OwningGrid != null &&
                OwningGrid.EditingRow == null &&
                OwningColumn != OwningGrid.ColumnsInternal.FillerColumn &&
                OwningGrid.DataConnection.AllowSort &&
                OwningGrid.CanUserSortColumns &&
                OwningColumn.CanUserSort &&
                OwningGrid.DataConnection.SortDescriptions != null)
            {
                DataGrid owningGrid = OwningGrid;

                DataGridSortDescription newSort;

                KeyboardHelper.GetMetaKeyState(keyModifiers, out bool ctrl, out bool shift);

                DataGridSortDescription sort           = OwningColumn.GetSortDescription();
                IDataGridCollectionView collectionView = owningGrid.DataConnection.CollectionView;
                Debug.Assert(collectionView != null);
                using (collectionView.DeferRefresh())
                {
                    // if shift is held down, we multi-sort, therefore if it isn't, we'll clear the sorts beforehand
                    if (!shift || owningGrid.DataConnection.SortDescriptions.Count == 0)
                    {
                        owningGrid.DataConnection.SortDescriptions.Clear();
                    }

                    // if ctrl is held down, we only clear the sort directions
                    if (!ctrl)
                    {
                        if (sort != null)
                        {
                            newSort = sort.SwitchSortDirection();

                            // changing direction should not affect sort order, so we replace this column's
                            // sort description instead of just adding it to the end of the collection
                            int oldIndex = owningGrid.DataConnection.SortDescriptions.IndexOf(sort);
                            if (oldIndex >= 0)
                            {
                                owningGrid.DataConnection.SortDescriptions.Remove(sort);
                                owningGrid.DataConnection.SortDescriptions.Insert(oldIndex, newSort);
                            }
                            else
                            {
                                owningGrid.DataConnection.SortDescriptions.Add(newSort);
                            }
                        }
                        else
                        {
                            string propertyName = OwningColumn.GetSortPropertyName();
                            // no-opt if we couldn't find a property to sort on
                            if (string.IsNullOrEmpty(propertyName))
                            {
                                return;
                            }

                            newSort = DataGridSortDescription.FromPath(propertyName, culture: collectionView.Culture);
                            owningGrid.DataConnection.SortDescriptions.Add(newSort);
                        }
                    }
                }
            }
        }
示例#14
0
        private void Cell_Clicked(object sender, RoutedEventArgs e)
        {
            if (this.Owner == null)
            {
                return;
            }

            CalendarDayButton b = sender as CalendarDayButton;

            Debug.Assert(b != null);

            if (!(b.DataContext is DateTime))
            {
                return;
            }

            // If the day is a blackout day selection is not allowed
            if (!b.IsBlackedOut)
            {
                DateTime clickedDate = (DateTime)b.DataContext;
                bool     ctrl, shift;

                KeyboardHelper.GetMetaKeyState(out ctrl, out shift);

                switch (this.Owner.SelectionMode)
                {
                case CalendarSelectionMode.None:
                {
                    break;
                }

                case CalendarSelectionMode.SingleDate:
                {
                    if (!ctrl)
                    {
                        this.Owner.SelectedDate = clickedDate;
                    }
                    else
                    {
                        this.Owner.SelectedDates.Toggle(clickedDate);
                    }

                    break;
                }

                case CalendarSelectionMode.SingleRange:
                {
                    DateTime?lastDate = this.Owner.CurrentDate;
                    this.Owner.SelectedDates.ClearInternal(true /*fireChangeNotification*/);
                    if (shift && lastDate.HasValue)
                    {
                        this.Owner.SelectedDates.AddRangeInternal(lastDate.Value, clickedDate);
                    }
                    else
                    {
                        this.Owner.SelectedDate = clickedDate;
                        this.Owner.HoverStart   = null;
                        this.Owner.HoverEnd     = null;
                    }

                    break;
                }

                case CalendarSelectionMode.MultipleRange:
                {
                    if (!ctrl)
                    {
                        this.Owner.SelectedDates.ClearInternal(true /*fireChangeNotification*/);
                    }

                    if (shift)
                    {
                        this.Owner.SelectedDates.AddRangeInternal(this.Owner.CurrentDate, clickedDate);
                    }
                    else
                    {
                        if (!ctrl)
                        {
                            this.Owner.SelectedDate = clickedDate;
                        }
                        else
                        {
                            this.Owner.SelectedDates.Toggle(clickedDate);
                            this.Owner.HoverStart = null;
                            this.Owner.HoverEnd   = null;
                        }
                    }

                    break;
                }
                }

                this.Owner.OnDayClick(clickedDate);
            }
        }
示例#15
0
        private void Cell_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            CalendarDayButton b = sender as CalendarDayButton;

            if (b == null)
            {
                return;
            }

            if (this.Owner == null)
            {
                return;
            }

            if (!b.IsBlackedOut)
            {
                this.Owner.OnDayButtonMouseUp(e);
            }

            if (!(b.DataContext is DateTime))
            {
                return;
            }

            bool ctrl, shift;

            KeyboardHelper.GetMetaKeyState(out ctrl, out shift);

            if (this.Owner.SelectionMode == CalendarSelectionMode.None || this.Owner.SelectionMode == CalendarSelectionMode.SingleDate)
            {
                this.Owner.OnDayClick((DateTime)b.DataContext);
                return;
            }

            if (this.Owner.HoverStart.HasValue)
            {
                switch (this.Owner.SelectionMode)
                {
                case CalendarSelectionMode.SingleRange:
                {
                    // Update SelectedDates
                    this.Owner.SelectedDates.ClearInternal();
                    EndDrag(ctrl, b);
                    break;
                }

                case CalendarSelectionMode.MultipleRange:
                {
                    // add the selection (either single day or SingleRange day)
                    EndDrag(ctrl, b);
                    break;
                }
                }
            }
            else
            {
                // If the day is blacked out but also a trailing day we should be able to switch months
                if (b.IsInactive && b.IsBlackedOut)
                {
                    this.Owner.OnDayClick((DateTime)b.DataContext);
                }
            }
        }
示例#16
0
        internal void ProcessSort()
        {
            // if we can sort:
            //  - DataConnection.AllowSort is true, and
            //  - AllowUserToSortColumns and CanSort are true, and
            //  - OwningColumn is bound, and
            //  - SortDescriptionsCollection exists, and
            //  - the column's data type is comparable
            // then try to sort
            if (this.OwningColumn != this.OwningGrid.ColumnsInternal.FillerColumn &&
                this.OwningGrid.DataConnection.AllowSort &&
                this.OwningGrid.CanUserSortColumns &&
                this.OwningColumn.CanUserSort &&
                this.OwningGrid.DataConnection.SortDescriptions != null)
            {
                ListSortDirection newSortDirection;
                SortDescription   newSort;

                bool ctrl;
                bool shift;

                KeyboardHelper.GetMetaKeyState(out ctrl, out shift);

                SortDescription?sort = this.OwningColumn.GetSortDescription();

                // if shift is held down, we multi-sort, therefore if it isn't, we'll clear the sorts beforehand
                if (!shift)
                {
                    this.OwningGrid.DataConnection.SortDescriptions.Clear();
                }

                if (sort.HasValue)
                {
                    // swap direction
                    switch (sort.Value.Direction)
                    {
                    case ListSortDirection.Ascending:
                        newSortDirection = ListSortDirection.Descending;
                        break;

                    default:
                        newSortDirection = ListSortDirection.Ascending;
                        break;
                    }

                    newSort = new SortDescription(sort.Value.PropertyName, newSortDirection);

                    // changing direction should not affect sort order, so we replace this column's
                    // sort description instead of just adding it to the end of the collection
                    int oldIndex = this.OwningGrid.DataConnection.SortDescriptions.IndexOf(sort.Value);
                    if (oldIndex >= 0)
                    {
                        this.OwningGrid.DataConnection.SortDescriptions.Remove(sort.Value);
                        this.OwningGrid.DataConnection.SortDescriptions.Insert(oldIndex, newSort);
                    }
                    else
                    {
                        this.OwningGrid.DataConnection.SortDescriptions.Add(newSort);
                    }
                }
                else
                {
                    // start new sort
                    newSortDirection = ListSortDirection.Ascending;

                    string propertyName = this.OwningColumn.GetSortPropertyName();
                    // no-opt if we couldn't find a property to sort on
                    if (string.IsNullOrEmpty(propertyName))
                    {
                        return;
                    }

                    newSort = new SortDescription(propertyName, newSortDirection);

                    this.OwningGrid.DataConnection.SortDescriptions.Add(newSort);
                }

                // We've completed the sort, so send the Invoked event for the column header's automation peer
                if (AutomationPeer.ListenerExists(AutomationEvents.InvokePatternOnInvoked))
                {
                    AutomationPeer peer = FrameworkElementAutomationPeer.FromElement(this);
                    if (peer != null)
                    {
                        peer.RaiseAutomationEvent(AutomationEvents.InvokePatternOnInvoked);
                    }
                }
            }
        }
示例#17
0
        private void Cell_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (this.Owner != null)
            {
                if (!this.Owner._hasFocus)
                {
                    this.Owner.Focus();
                }

                bool ctrl, shift;
                KeyboardHelper.GetMetaKeyState(out ctrl, out shift);
                CalendarDayButton b = sender as CalendarDayButton;

                if (b != null)
                {
                    if (b.IsEnabled && !b.IsDisabled)
                    {
                        DateTime selectedDate = (DateTime)b.DataContext;
                        Debug.Assert(selectedDate != null);
                        _isMouseLeftButtonDown = true;
                        //null check is added for unit tests
                        if (e != null)
                        {
                            _downEventArg = e;
                        }

                        switch (this.Owner.SelectionMode)
                        {
                        case CalendarSelectionMode.None:
                        {
                            return;
                        }

                        case CalendarSelectionMode.SingleDate:
                        {
                            this.Owner.DatePickerDisplayDateFlag = true;
                            if (this.Owner.SelectedDates.Count == 0)
                            {
                                this.Owner.SelectedDates.Add(selectedDate);
                            }
                            else
                            {
                                this.Owner.SelectedDates[0] = selectedDate;
                            }
                            return;
                        }

                        case CalendarSelectionMode.SingleRange:
                        {
                            //Set the start or end of the selection range
                            if (shift)
                            {
                                this.Owner.UnHighlightDays();
                                this.Owner.HoverEnd       = selectedDate;
                                this.Owner._hoverEndIndex = b.Index;
                                this.Owner.HighlightDays();
                            }
                            else
                            {
                                this.Owner.UnHighlightDays();
                                this.Owner._hoverStart      = selectedDate;
                                this.Owner._hoverStartIndex = b.Index;
                            }
                            return;
                        }

                        case CalendarSelectionMode.MultipleRange:
                        {
                            if (shift)
                            {
                                if (!ctrl)
                                {
                                    //clear the list, set the states to default
                                    foreach (DateTime item in this.Owner.SelectedDates)
                                    {
                                        this.Owner._removedItems.Add(item);
                                    }
                                    this.Owner.SelectedDates.ClearInternal();
                                }
                                this.Owner.HoverEnd       = selectedDate;
                                this.Owner._hoverEndIndex = b.Index;
                                this.Owner.HighlightDays();
                            }
                            else
                            {
                                if (!ctrl)
                                {
                                    //clear the list, set the states to default
                                    foreach (DateTime item in this.Owner.SelectedDates)
                                    {
                                        this.Owner._removedItems.Add(item);
                                    }
                                    this.Owner.SelectedDates.ClearInternal();
                                    this.Owner.UnHighlightDays();
                                }
                                this.Owner._hoverStart      = selectedDate;
                                this.Owner._hoverStartIndex = b.Index;
                            }
                            return;
                        }
                        }
                    }
                    else
                    {
                        //If a click occurs on a BlackOutDay we set the HoverStart to be null
                        this.Owner._hoverStart = null;
                    }
                }
            }
        }
示例#18
0
        void OnKeyDown(object sender, KeyRoutedEventArgs e)
        {
            if ((_tabStrip != null) && _tabStrip.IsEditing)
            {
                if ((e.Key == (VirtualKey)13) || (e.Key == (VirtualKey)9))
                {
                    _tabStrip.StopTabEditing(false);
                    e.Handled = true;
                }
                else if (e.Key == (VirtualKey)0x1b)
                {
                    _tabStrip.StopTabEditing(true);
                }
                return;
            }

            bool flag2;
            bool flag3;
            bool flag4;
            bool flag = AllowEnterEditing(e);

            if (InputDeviceType == InputDeviceType.Touch)
            {
                RefreshSelection();
            }
            InputDeviceType = InputDeviceType.Keyboard;
            UpdateCursorType();
            VirtualKey keyCode = e.Key;

            if (keyCode == VirtualKey.Enter)
            {
                Worksheet activeSheet = ActiveSheet;
                if (EditorInfo.Sheet != activeSheet)
                {
                    int index = activeSheet.Workbook.Sheets.IndexOf(EditorInfo.Sheet);
                    activeSheet.Workbook.ActiveSheetIndex = index;
                    StopCellEditing(false);
                    e.Handled = true;
                    return;
                }
            }
            KeyboardHelper.GetMetaKeyState(out flag3, out flag2, out flag4);
            VirtualKeyModifiers none = VirtualKeyModifiers.None;

            if (flag2)
            {
                none |= VirtualKeyModifiers.Control;
            }
            if (flag3)
            {
                none |= VirtualKeyModifiers.None | VirtualKeyModifiers.Shift;
            }
            if (flag4)
            {
                none |= VirtualKeyModifiers.Menu;
            }
            KeyStroke ks = new KeyStroke(keyCode, none, false);

            if (ProcessKeyDownOnFloatingObjectSelected(ks))
            {
                e.Handled = true;
            }
            else
            {
                if (KeyMap.ContainsKey(ks))
                {
                    SpreadAction action = KeyMap[ks];
                    if (action != null)
                    {
                        CloseDragFillPopup();
                        ActionEventArgs args = new ActionEventArgs();
                        action(this, args);
                        if (args.Handled)
                        {
                            e.Handled = true;
                        }
                    }
                }
                if (IsDragDropping)
                {
                    SwitchDragDropIndicator();
                }
                else
                {
                    if (!IsEditing && flag)
                    {
                        // Enter状态表示因键盘输入触发,Edit状态表示双击触发
                        StartCellEditing(true, null, EditorStatus.Enter);
                    }
                    if (!IsEditing)
                    {
                        FocusInternal();
                    }
                }
            }
        }
示例#19
0
        //TODO GroupSorting
        internal void ProcessSort(InputModifiers inputModifiers)
        {
            // if we can sort:
            //  - DataConnection.AllowSort is true, and
            //  - AllowUserToSortColumns and CanSort are true, and
            //  - OwningColumn is bound, and
            //  - SortDescriptionsCollection exists, and
            //  - the column's data type is comparable
            // then try to sort
            if (OwningColumn != null
                && OwningGrid != null
                && OwningGrid.EditingRow == null
                && OwningColumn != OwningGrid.ColumnsInternal.FillerColumn
                && OwningGrid.DataConnection.AllowSort
                && OwningGrid.CanUserSortColumns
                && OwningColumn.CanUserSort
                && OwningGrid.DataConnection.SortDescriptions != null)
            {
                DataGrid owningGrid = OwningGrid;
                bool desending;
                AvaloniaSortDescription newSort;

                KeyboardHelper.GetMetaKeyState(inputModifiers, out bool ctrl, out bool shift);

                AvaloniaSortDescription sort = OwningColumn.GetSortDescription();
                ICollectionView collectionView = owningGrid.DataConnection.CollectionView;
                Debug.Assert(collectionView != null);
                using (collectionView.DeferRefresh())
                {
                    // if shift is held down, we multi-sort, therefore if it isn't, we'll clear the sorts beforehand
                    if (!shift || owningGrid.DataConnection.SortDescriptions.Count == 0)
                    {
                        /*if (collectionView.CanGroup && collectionView.GroupDescriptions != null)
                        {
                            // Make sure we sort by the GroupDescriptions first
                            for (int i = 0; i < collectionView.GroupDescriptions.Count; i++)
                            {
                                PropertyGroupDescription groupDescription = collectionView.GroupDescriptions[i] as PropertyGroupDescription;
                                if (groupDescription != null && collectionView.SortDescriptions.Count <= i || collectionView.SortDescriptions[i].PropertyName != groupDescription.PropertyName)
                                {
                                    collectionView.SortDescriptions.Insert(Math.Min(i, collectionView.SortDescriptions.Count), new SortDescription(groupDescription.PropertyName, ListSortDirection.Ascending));
                                }
                            }
                            while (collectionView.SortDescriptions.Count > collectionView.GroupDescriptions.Count)
                            {
                                collectionView.SortDescriptions.RemoveAt(collectionView.GroupDescriptions.Count);
                            }
                        }
                        else if (!shift)
                        {
                            owningGrid.DataConnection.SortDescriptions.Clear();
                        }*/
                        owningGrid.DataConnection.SortDescriptions.Clear();
                    }

                    if (sort != null)
                    {
                        newSort = sort.SwitchSortDirection();

                        // changing direction should not affect sort order, so we replace this column's
                        // sort description instead of just adding it to the end of the collection
                        int oldIndex = owningGrid.DataConnection.SortDescriptions.IndexOf(sort);
                        if (oldIndex >= 0)
                        {
                            owningGrid.DataConnection.SortDescriptions.Remove(sort);
                            owningGrid.DataConnection.SortDescriptions.Insert(oldIndex, newSort);
                        }
                        else
                        {
                            owningGrid.DataConnection.SortDescriptions.Add(newSort);
                        }
                    }
                    else
                    {
                        string propertyName = OwningColumn.GetSortPropertyName();
                        // no-opt if we couldn't find a property to sort on
                        if (string.IsNullOrEmpty(propertyName))
                        {
                            return;
                        }

                        newSort = AvaloniaSortDescription.FromPath(propertyName, culture: collectionView.Culture);
                        owningGrid.DataConnection.SortDescriptions.Add(newSort);
                    }
                }

                // We've completed the sort, so send the Invoked event for the column header's automation peer
                /*if (AutomationPeer.ListenerExists(AutomationEvents.InvokePatternOnInvoked))
                {
                    AutomationPeer peer = FrameworkElementAutomationPeer.FromElement(this);
                    if (peer != null)
                    {
                        peer.RaiseAutomationEvent(AutomationEvents.InvokePatternOnInvoked);
                    }
                }*/

            }
        }