protected override void Setup()
        {
            currentCellService = UIServiceProvider.GetService <ICurrentCellService>(TargetElement);
            Debug.Assert(currentCellService != null);

            inputService = UIServiceProvider.GetService <InputService>(TargetElement);
            Debug.Assert(inputService != null);

            scrollService = UIServiceProvider.GetService <IVerticalScrollService>(TargetElement);
            Debug.Assert(scrollService != null);

            inputService.RegisterKeyActionGestures(AsLineKeyAction(MoveLineDown), new KeyGesturesFactory(Key.Down, InputGesturesFactory.AllCombinationsOf(ModifierKeys.Control, ModifierKeys.Shift)));
            inputService.RegisterKeyActionGestures(AsLineKeyAction(MoveLineUp), new KeyGesturesFactory(Key.Up, InputGesturesFactory.AllCombinationsOf(ModifierKeys.Control, ModifierKeys.Shift)));
            inputService.RegisterKeyActionGestures(AsLineKeyAction(MovePageDown), new KeyGesturesFactory(Key.PageDown, InputGesturesFactory.AllCombinationsOf(ModifierKeys.Control, ModifierKeys.Shift)));
            inputService.RegisterKeyActionGestures(AsLineKeyAction(MovePageUp), new KeyGesturesFactory(Key.PageUp, InputGesturesFactory.AllCombinationsOf(ModifierKeys.Control, ModifierKeys.Shift)));
            inputService.RegisterKeyActionGestures(AsLineKeyAction(MoveToTop), new KeyGesturesFactory(Key.Home, ModifierKeys.Control));
            inputService.RegisterKeyActionGestures(AsLineKeyAction(MoveToBottom), new KeyGesturesFactory(Key.End, ModifierKeys.Control));

            inputService.RegisterKeyActionGestures(AsFieldKeyAction(MoveRight), new KeyGesturesFactory(Key.Tab));
            inputService.RegisterKeyActionGestures(AsFieldKeyAction(MoveRight), new KeyGesturesFactory(Key.Right, InputGesturesFactory.AllCombinationsOf(ModifierKeys.Control, ModifierKeys.Shift)));

            inputService.RegisterKeyActionGestures(AsFieldKeyAction(MoveLeft), new KeyGesturesFactory(Key.Tab, ModifierKeys.Shift));
            inputService.RegisterKeyActionGestures(AsFieldKeyAction(MoveLeft), new KeyGesturesFactory(Key.Left, InputGesturesFactory.AllCombinationsOf(ModifierKeys.Control, ModifierKeys.Shift)));

            inputService.RegisterKeyActionGestures(AsFieldKeyAction(MoveToLeftMost), new KeyGesturesFactory(Key.Home));
            inputService.RegisterKeyActionGestures(AsFieldKeyAction(MoveToRightMost), new KeyGesturesFactory(Key.End));

            inputService.RegisterMouseActionGestures(MouseClicked, new MouseGesturesFactory(MouseAction.LeftClick, InputGesturesFactory.AllCombinationsOf(ModifierKeys.Shift, ModifierKeys.Control)));
        }
        private void TargetElement_PreviewLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
        {
            log.DebugFormat("Losing keyboard focus: {0}, from {1}, to {2}", sender, e.OldFocus, e.NewFocus);

            DependencyObject oldFocus = e.OldFocus as DependencyObject;
            DependencyObject newFocus = e.NewFocus as DependencyObject;

            if (oldFocus != null & newFocus != null)
            {
                if (TargetElement.IsAncestorOf(oldFocus) && TargetElement.IsAncestorOf(newFocus))
                {
                    // Focus moved within the container.
                    return;
                }
            }

            log.Debug("Saving state on UI service providers");

            var statePersistentServices = UIServiceProvider.GetAllServices <IStatePersistency>(TargetElement);

            foreach (var service in statePersistentServices)
            {
                service.SaveCurrentState();
            }
        }
예제 #3
0
        private static void OnServiceListChanged(DependencyObject sender, DependencyPropertyChangedEventArgs changeArgs)
        {
            var element = sender as FrameworkElement;
            var oldList = changeArgs.OldValue as UIServiceCollection;

            if (element != null)
            {
                if (oldList != null)
                {
                    var oldProvider = GetServiceProvider(element);
                    if (oldProvider != null)
                    {
                        oldProvider.Dispose();
                    }
                }

                // Create a service provider for the element.
                UIServiceProvider newProvider = null;
                var newList = changeArgs.NewValue as UIServiceCollection;
                if (newList != null)
                {
                    newProvider = new UIServiceProvider();
                    newProvider.AttachToElement(element, newList);
                }
                SetServiceProvider(element, newProvider);
            }
        }
예제 #4
0
        public void AttachToElement(FrameworkElement element)
        {
            //if (TargetElement != null)
            //{
            //   if (ReferenceEquals(TargetElement.ElementSelectionService, element))
            //   {
            //      log.DebugFormat("Extender {0} is already attached to element {1}", this, element);
            //      return;
            //   }
            //   throw new InvalidOperationException("Cannot re-attach an attached extender");
            //}

            TargetElementProxy = UIServiceProvider.GetService <IMultiSelectionService>(element);
            SetSelectionExtender(element, this);
            var selectionView = GetSelectionView(element);

            this.AttachSelectionModel(null, selectionView);
            TargetElementProxy.SelectionChanged += TargetElement_SelectionChanged;

            currentItemTracker = UIServiceProvider.GetService <ICurrentItemService>(element, false);
            currentItemTracker.CurrentChanged         += new EventHandler(currentItemTracker_CurrentChanged);
            currentItemTracker.PreviewCurrentChanging += CurrentItemTracker_PreviewCurrentChanging;
            //if (currentItemTracker != null)
            //{
            //   selectionModeManager = new SelectionModeManager(TargetElement);
            //}

            var inputService = UIServiceProvider.GetService <InputService>(TargetElement);

            inputService.RegisterMouseActionGestures(ToggleSelection, new MouseGesturesFactory(MouseAction.LeftClick, ModifierKeys.Control));
            inputService.RegisterKeyActionGestures(ToggleSelection, new KeyGesturesFactory(Key.Space, ModifierKeys.Control));
            //inputService.RegisterMouseActionGestures(SelectRange, new MouseGesturesFactory(MouseAction.LeftClick, ModifierKeys.Shift));
        }
        private void DataGrid_CurrentCellChanged(object sender, EventArgs e)
        {
            var fm = UIServiceProvider.GetService <IFocusManagementService>(dataGrid);

            if (fm.IsRestoringFocusOnElement)
            {
                // The data grid is loosing focus, in which case it automatically sets 'CurrentCell' to be 'null'.
                // We need to ignore this case so nothing will be changed on screen.
                return;
            }

            if (!isSelfInducedCellChange.IsSet)
            {
                RaiseNonCancelablePreviewCurrentCellChangingEvent(CurrentCell);
                var newRowService = GetRowEnumerationServiceForItem(dataGrid.CurrentCell.Item);
                if (newRowService != null)
                {
                    var columnIndex = 0;
                    if (dataGrid.CurrentCell.Column != null)
                    {
                        columnIndex = dataGrid.CurrentCell.Column.DisplayIndex;
                    }

                    currentCellPosition.SetCurrentCellIndex(newRowService, columnIndex);
                }
            }
            UpdateCurrentCell();
            if (!isSelfInducedCellChange.IsSet)
            {
                RaiseCurrentCellChangedEvent();
            }
        }
        public bool MoveTo(UniversalCellInfo targetCell)
        {
            if (inMoveTo.IsSet)
            {
                return(true);
            }

            return((bool)dataGrid.Dispatcher.Invoke(DispatcherPriority.Loaded, new Func <bool>(() =>
            {
                bool canceled;

                log.DebugFormat("Moving to cell {0}", targetCell);

                UpdateCurrentCell();

                if (!CanMoveTo(targetCell))
                {
                    return CannotMoveToCell(targetCell);
                }

                if (!suppressChangeNotifications.IsSet)
                {
                    RaisePreviewCurrentCellChangingEvent(targetCell, out canceled);
                    if (canceled)
                    {
                        return OperationCanceled();
                    }
                }

                using (isSelfInducedCellChange.Set())
                {
                    if (targetCell.CellIndex >= dataGrid.Columns.Count)
                    {
                        return false;
                    }

                    var rowEnumSvc = GetRowEnumerationServiceForItem(targetCell.Item);
                    // If changing the row type (according to the row service), we should retake the cell index.
                    if (CurrentRowCellEnumerationService == null ||
                        rowEnumSvc.ServiceGroupIdentifier.Equals(CurrentRowCellEnumerationService.ServiceGroupIdentifier))
                    {
                        currentCellPosition.SetCurrentCellIndex(rowEnumSvc, targetCell.CellIndex);
                    }

                    var newCell = rowEnumSvc.GetCellInfo(currentCellPosition.GetCurrentCellIndex(rowEnumSvc));
                    var fm = UIServiceProvider.GetService <IFocusManagementService>(dataGrid);
                    elementTraits.SetCurrentCell(this.dataGrid, newCell);
                    UpdateCurrentCell();
                    fm.SetFocusOnTargetElement();

                    if (!suppressChangeNotifications.IsSet)
                    {
                        RaiseCurrentCellChangedEvent();
                    }
                }
                return CurrentCell.Equals(targetCell);
            })));
        }
예제 #7
0
        private void EnableEditing()
        {
            var editSvc = UIServiceProvider.GetService <IElementEditStateService>(TargetElement, false);

            if (editSvc != null)
            {
                editSvc.EnableEditing();
            }
        }
        public void AttachToElement(FrameworkElement element)
        {
            TargetElement      = element;
            currentCellService = UIServiceProvider.GetService <ICurrentCellService>(TargetElement);
            currentCellService.CurrentCellChanged += new EventHandler(currentCellService_CurrentCellChanged);

            TargetElement.PreviewGotKeyboardFocus  += TargetElement_PreviewGotKeyboardFocus;
            TargetElement.PreviewLostKeyboardFocus += TargetElement_PreviewLostKeyboardFocus;
        }
예제 #9
0
        private bool DisableEditing()
        {
            var editSvc = UIServiceProvider.GetService <IElementEditStateService>(TargetElement, false);

            if (editSvc != null)
            {
                return(editSvc.DisableEditing());
            }
            return(true);
        }
예제 #10
0
        public void AttachToElement(FrameworkElement element)
        {
            this.dataGrid                  = (DataGrid)element;
            dataGrid.BeginningEdit        += dataGrid_BeginningEdit;
            dataGrid.CellEditEnding       += dataGrid_CellEditEnding;
            dataGrid.RowEditEnding        += dataGrid_RowEditEnding;
            dataGrid.PreparingCellForEdit += dataGrid_PreparingCellForEdit;

            UIServiceProvider.AddServiceProviderFullyAttachedHandler(dataGrid, ServiceProvider_FullyAttached);
        }
        private void TargetElement_PreviewGotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
        {
            log.DebugFormat("Regaining keyboard focus: {0}, from {1}, to {2}", sender, e.OldFocus, e.NewFocus);

            //if (isUpdatingFocus.IsSet)
            //   return;

            if (isFirstFocus)
            {
                isFirstFocus = false;
                log.Debug("Got focus for the first time.");
                UpdateFocus();
                return;
            }

            if (isRestoringState.IsSet)
            {
                return;
            }

            using (isRestoringState.Set())
            {
                DependencyObject oldFocus = e.OldFocus as DependencyObject;

                if (oldFocus == null)
                {
                    log.Debug("Old focus is null. Not restoring focus.");
                    return;
                }

                DependencyObject newFocus = e.NewFocus as DependencyObject;

                if (newFocus != null)
                {
                    if (TargetElement.IsAncestorOf(oldFocus) && TargetElement.IsAncestorOf(newFocus))
                    {
                        log.DebugFormat("Focus changed within the same element");
                        // Focus moved within the container.
                        return;
                    }
                }

                log.Debug("Restoring state on UI service providers");

                var statePersistentServices = UIServiceProvider.GetAllServices <IStatePersistency>(TargetElement);
                foreach (var service in statePersistentServices)
                {
                    service.RestoreState();
                }
            }
        }
예제 #12
0
        private static UIServiceProvider CreateServiceProvider(FrameworkElement element)
        {
            var serviceList = GetServiceList(element);

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

            log.DebugFormat("Creating a new service provider for {0}", element);
            var serviceProvider = new UIServiceProvider();

            SetServiceProvider(element, serviceProvider);
            serviceProvider.AttachToElement(element, serviceList);
            return(serviceProvider);
        }
        private ICellEnumerationService GetRowEnumerationServiceForItem(object item)
        {
            log.DebugFormat(FrameworkElementFormatter.GetInstance(), "Trying to get row enumeration service for {0}", item);

            var currentRow = GetItemContainer(item) as DataGridRow;

            if (currentRow == null)
            {
                log.DebugFormat("-- Failed retrieving item container from '{0}'", item);
                return(null);
            }

            var service = UIServiceProvider.GetService <ICellEnumerationService>(currentRow);

            log.DebugFormat("-- Found service provider {0}", service);

            //((IUIService)service).AttachToElement(currentRow);

            return(service);
        }
        private void MouseClicked(MouseEventArgs eventArgs)
        {
            log.Debug("Mouse was clicked on " + eventArgs.OriginalSource);

            var focusManager = UIServiceProvider.GetService <IFocusManagementService>(TargetElement);

            focusManager.SetFocusOnTargetElement();

            HitTestResult hitTestResult = VisualTreeHelper.HitTest(TargetElement, Mouse.GetPosition(TargetElement));
            var           row           = UIUtils.GetAncestor <DataGridRow>((Visual)hitTestResult.VisualHit);

            if (row != null)
            {
                var rowEnumSvc             = UIServiceProvider.GetService <ICellEnumerationService>(row);
                UniversalCellInfo cellInfo = rowEnumSvc.GetCellContaining(hitTestResult.VisualHit);
                if (!currentCellService.CurrentCell.Equals(cellInfo))
                {
                    currentCellService.MoveTo(cellInfo);
                    eventArgs.Handled = true;
                }
            }
        }
예제 #15
0
 public virtual void AttachToElement(FrameworkElement servedElement)
 {
     sharedObjectsService = UIServiceProvider.GetService <SharedObjectsService>(servedElement);
     element = servedElement;
 }
예제 #16
0
 private void ServiceProvider_FullyAttached(object obj, EventArgs args)
 {
     commandRegulator = UIServiceProvider.GetService <ICommandRegulationService>(dataGrid);
 }
예제 #17
0
 private static void SetServiceProvider(DependencyObject obj, UIServiceProvider value)
 {
     obj.SetValue(ServiceProviderProperty, value);
 }