示例#1
0
        private Point?TranslateMagnifiedSelectionPoint(Point point)
        {
            Point?translatedPoint = null;

            var image = VisualAndLogicalTreeHelper.FindLogicalChildren <Image>(this).First();

            var imagePoint  = image.PointFromScreen(point); //Convert screen to point on image co-ord system
            var imageWidth  = image.ActualWidth;
            var imageHeight = image.ActualHeight;

            if (imagePoint.X >= 0 && imagePoint.X < imageWidth &&
                imagePoint.Y >= 0 && imagePoint.Y < imageHeight)
            {
                //Point is within the magnified image
                var sourceXRatio = imagePoint.X / imageWidth;
                var sourceYRatio = imagePoint.Y / imageHeight;

                var destX = (sourceXRatio * sourceArea.Width) + sourceArea.X;
                var destY = (sourceYRatio * sourceArea.Height) + sourceArea.Y;

                translatedPoint = new Point(destX, destY);
            }

            return(translatedPoint);
        }
示例#2
0
        private void TraverseAllKeysAndBuildPointToKeyValueMap()
        {
            var allKeys = VisualAndLogicalTreeHelper.FindVisualChildren <Key>(this).ToList();

            var pointToKeyValueMap = new Dictionary <Rect, KeyValue>();

            var topLeftPoint = new Point(0, 0);

            foreach (var key in allKeys)
            {
                if (key.Value.FunctionKey != null ||
                    key.Value.String != null)
                {
                    var rect = new Rect
                    {
                        Location = key.PointToScreen(topLeftPoint),
                        Size     = (Size)key.GetTransformToDevice().Transform((Vector)key.RenderSize)
                    };

                    if (rect.Size.Width != 0 && rect.Size.Height != 0)
                    {
                        pointToKeyValueMap.Add(rect, key.Value);
                    }
                }
            }

            PointToKeyValueMap = pointToKeyValueMap;
        }
示例#3
0
        private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
        {
            Log.Debug("KeyboardHost loaded.");

            BuildPointToKeyMap();

            SubscribeToSizeChanges();

            mainWindow = VisualAndLogicalTreeHelper.FindVisualParent <MainWindow>(this);

            var parentWindow = Window.GetWindow(this);

            if (parentWindow == null)
            {
                var windowException = new ApplicationException(Properties.Resources.PARENT_WINDOW_COULD_NOT_BE_FOUND);

                Log.Error(windowException);

                throw windowException;
            }

            SubscribeToParentWindowMoves(parentWindow);
            SubscribeToParentWindowStateChanges(parentWindow);

            Loaded -= OnLoaded; //Ensure this logic only runs once
        }
示例#4
0
        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            //Get references to window, screen, toastNotification and mainViewModel
            window            = Window.GetWindow(this);
            screen            = window.GetScreen();
            toastNotification = VisualAndLogicalTreeHelper.FindLogicalChildren <ToastNotification>(this).First();
            var mainViewModel = DataContext as MainViewModel;

            //Handle ToastNotification event
            mainViewModel.ToastNotification += (o, args) =>
            {
                SetSizeAndPosition();

                Title            = args.Title;
                Content          = args.Content;
                NotificationType = args.NotificationType;

                Action closePopup = () =>
                {
                    if (IsOpen)
                    {
                        IsOpen = false;
                        if (args.Callback != null)
                        {
                            args.Callback();
                        }
                    }
                };

                AnimateTarget(args.Content, toastNotification, closePopup);
                IsOpen = true;
            };
        }
示例#5
0
        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            var window            = VisualAndLogicalTreeHelper.FindLogicalParent <Window>(this);
            var toastNotification = VisualAndLogicalTreeHelper.FindLogicalChildren <ToastNotification>(this).First();
            var mainViewModel     = DataContext as MainViewModel;

            //Handle ToastNotification event
            mainViewModel.ToastNotification += (o, args) =>
            {
                //Set size and position
                SetSize(toastNotification, window);
                SetPosition(window);

                Title            = args.Title;
                Content          = args.Content;
                NotificationType = args.NotificationType;

                Action closePopup = () =>
                {
                    if (IsOpen)
                    {
                        IsOpen = false;
                        if (args.Callback != null)
                        {
                            args.Callback();
                        }
                    }
                };

                AnimateTarget(args.Content, toastNotification, closePopup);
                IsOpen = true;
            };
        }
示例#6
0
        protected override void Invoke(object parameter)
        {
            var args = parameter as InteractionRequestedEventArgs;

            if (args != null)
            {
                Log.Info("Opening confirmation window");
                var childWindow = new ConfirmationWindow {
                    DataContext = args.Context
                };

                EventHandler closeHandler = null;
                closeHandler = (sender, e) =>
                {
                    childWindow.Closed -= closeHandler;
                    args.Callback();
                };
                childWindow.Closed += closeHandler;

                childWindow.Owner = AssociatedObject != null
                    ? AssociatedObject as Window ?? VisualAndLogicalTreeHelper.FindVisualParent <Window>(AssociatedObject)
                    : childWindow.Owner;

                childWindow.ShowDialog();
            }
        }
        protected override void Invoke(object parameter)
        {
            var args = parameter as InteractionRequestedEventArgs;

            if (args != null)
            {
                var notificationWithServicesAndState = args.Context as NotificationWithServicesAndState;

                if (notificationWithServicesAndState == null ||
                    notificationWithServicesAndState.AudioService == null ||
                    notificationWithServicesAndState.DictionaryService == null)
                {
                    throw new ApplicationException(Resources.REQUIRED_SERVICES_NOT_PASSED_TO_MANAGEMENT_WINDOW);
                }

                var childWindow = new ManagementWindow(notificationWithServicesAndState.AudioService, notificationWithServicesAndState.DictionaryService);

                EventHandler closeHandler = null;
                closeHandler = (sender, e) =>
                {
                    childWindow.Closed -= closeHandler;
                    args.Callback();
                };
                childWindow.Closed += closeHandler;

                var parentWindow = AssociatedObject != null
                    ? AssociatedObject as Window ?? VisualAndLogicalTreeHelper.FindVisualParent <Window>(AssociatedObject)
                    : null;

                bool parentWindowHadFocus = false;
                if (parentWindow != null &&
                    notificationWithServicesAndState.ModalWindow)
                {
                    childWindow.Owner    = parentWindow; //Setting the owner preserves the z-order of the parent and child windows when the focus is shifted back to the parent (otherwise the child popup will be hidden)
                    parentWindowHadFocus = parentWindow.IsFocused;
                }

                if (notificationWithServicesAndState.ModalWindow)
                {
                    Log.Info("Showing Management Window (modal)");
                    childWindow.Topmost = true;
                    childWindow.ShowDialog();
                }
                else
                {
                    Log.Info("Showing Management Window (non-modal)");
                    childWindow.Show();
                }

                if (parentWindow != null &&
                    notificationWithServicesAndState.ModalWindow)
                {
                    if (parentWindowHadFocus)
                    {
                        Log.Debug("Parent Window was previously focussed - giving it focus again.");
                        parentWindow.Focus();
                    }
                }
            }
        }
        protected override void Invoke(object parameter)
        {
            var args = parameter as InteractionRequestedEventArgs;

            if (args != null)
            {
                var notificationWithServices = args.Context as NotificationWithServices;

                if (notificationWithServices == null ||
                    notificationWithServices.AudioService == null ||
                    notificationWithServices.DictionaryService == null)
                {
                    throw new ApplicationException("Audio and/or Dictionary service(s) were/was not supplied to the management window action.");
                }

                var childWindow = new ManagementWindow(notificationWithServices.AudioService, notificationWithServices.DictionaryService);

                EventHandler closeHandler = null;
                closeHandler = (sender, e) =>
                {
                    childWindow.Closed -= closeHandler;
                    args.Callback();
                };
                childWindow.Closed += closeHandler;

                var parentWindow = AssociatedObject != null
                    ? AssociatedObject as Window ?? VisualAndLogicalTreeHelper.FindVisualParent <Window>(AssociatedObject)
                    : null;

                bool parentWindowHadFocus   = false;
                bool parentWindowWasTopmost = false;
                if (parentWindow != null)
                {
                    childWindow.Owner      = parentWindow; //Setting the owner preserves the z-order of the parent and child windows when the focus is shifted back to the parent (otherwise the child popup will be hidden)
                    parentWindowHadFocus   = parentWindow.IsFocused;
                    parentWindowWasTopmost = parentWindow.Topmost;
                    parentWindow.Topmost   = false; //Topmost must be revoked otherwise it cannot be reinstated correctly once the child window is closed
                }

                Log.Info("Showing Management window");
                childWindow.ShowDialog();

                if (parentWindow != null)
                {
                    if (parentWindowHadFocus)
                    {
                        Log.Debug("Parent Window was previously focussed - giving it focus again.");
                        parentWindow.Focus();
                    }

                    if (parentWindowWasTopmost)
                    {
                        Log.Debug("Parent Window was previously top most - setting it back to top most window.");
                        parentWindow.Topmost = true;
                    }
                }
            }
        }
示例#9
0
        protected async override void Invoke(object parameter)
        {
            var args = parameter as InteractionRequestedEventArgs;

            if (args == null)
            {
                return;
            }

            if (CalibrationService == null)
            {
                Log.Error("CalibrateWindowAction was invoked, but the CalibrationService (dependency property) is not set. Calibration is not possible.");
                return;
            }

            Window parentWindow         = null;
            bool   parentWindowHadFocus = false;

            if (AssociatedObject != null)
            {
                parentWindow = AssociatedObject as Window ?? VisualAndLogicalTreeHelper.FindVisualParent <Window>(AssociatedObject);
                if (parentWindow != null)
                {
                    parentWindowHadFocus = parentWindow.IsFocused;
                }
            }

            var calibrationResult = args.Context as NotificationWithCalibrationResult;

            try
            {
                Log.Info("Starting a calibration");
                var message = await CalibrationService.Calibrate(parentWindow);

                if (calibrationResult != null)
                {
                    calibrationResult.Success = true;
                    calibrationResult.Message = message;
                }
            }
            catch (Exception exception)
            {
                if (calibrationResult != null)
                {
                    calibrationResult.Success   = false;
                    calibrationResult.Exception = exception;
                }
            }

            args.Callback();

            if (parentWindow != null &&
                parentWindowHadFocus)
            {
                Log.Debug("Parent Window was previously focussed - giving it focus again.");
                parentWindow.Focus();
            }
        }
示例#10
0
        private void TraverseAllKeysAndBuildPointToKeyValueMap()
        {
            var allKeys = VisualAndLogicalTreeHelper.FindVisualChildren <Key>(this).ToList();

            InstanceGetter.Instance.allKeys = allKeys;

            var pointToKeyValueMap = new Dictionary <Rect, KeyValue>();

            var topLeftPoint = new Point(0, 0);

            foreach (var key in allKeys)
            {
                if (key.IsVisible &&
                    PresentationSource.FromVisual(key) != null &&
                    key.Value != null &&
                    key.Value.HasContent())
                {
                    var rect = new Rect
                    {
                        Location = key.PointToScreen(topLeftPoint),
                        Size     = (Size)key.GetTransformToDevice().Transform((Vector)key.RenderSize)
                    };

                    if (rect.Size.Width != 0 && rect.Size.Height != 0)
                    {
                        if (pointToKeyValueMap.ContainsKey(rect))
                        {
                            // In Release, just log error
                            KeyValue existingKeyValue = pointToKeyValueMap[rect];
                            Log.ErrorFormat("Overlapping keys {0} and {1}, cannot add {1} to map", existingKeyValue, key.Value);

                            Debug.Assert(!pointToKeyValueMap.ContainsKey(rect));
                        }
                        else
                        {
                            pointToKeyValueMap.Add(rect, key.Value);
                        }
                    }

                    var keyValueChangedSubscription = key.OnPropertyChanges <KeyValue>(Key.ValueProperty).Subscribe(kv =>
                    {
                        KeyValue mapValue;
                        if (pointToKeyValueMap.TryGetValue(rect, out mapValue))
                        {
                            pointToKeyValueMap[rect] = kv;
                        }
                    });
                    currentKeyboardKeyValueSubscriptions.Add(keyValueChangedSubscription);
                }
            }

            Log.InfoFormat("PointToKeyValueMap rebuilt with {0} keys.", pointToKeyValueMap.Keys.Count);
            PointToKeyValueMap = pointToKeyValueMap;
        }
示例#11
0
        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            //Get references to window, screen, toastNotification and mainViewModel
            window            = Window.GetWindow(this);
            screen            = window.GetScreen();
            toastNotification = VisualAndLogicalTreeHelper.FindLogicalChildren <ToastNotification>(this).First();
            var mainViewModel = DataContext as MainViewModel;

            //Handle ToastNotification event: producer will push the message into the queue
            mainViewModel.ToastNotification += (o, args) =>
            {
                messageQueue.Enqueue(args);

                if (messageQueue.Count == 1)
                {
                    // if the first message, start the message chain
                    RaiseNotificationChain();
                }
            };
        }
示例#12
0
        private void TraverseAllKeysAndBuildPointToKeyValueMap()
        {
            var allKeys = VisualAndLogicalTreeHelper.FindVisualChildren <Key>(this).ToList();

            var pointToKeyValueMap = new Dictionary <Rect, KeyValue>();

            var topLeftPoint = new Point(0, 0);

            foreach (var key in allKeys)
            {
                if (key.IsVisible &&
                    PresentationSource.FromVisual(key) != null &&
                    (key.Value.FunctionKey != null || key.Value.String != null))
                {
                    var rect = new Rect
                    {
                        Location = key.PointToScreen(topLeftPoint),
                        Size     = (Size)key.GetTransformToDevice().Transform((Vector)key.RenderSize)
                    };

                    if (rect.Size.Width != 0 && rect.Size.Height != 0)
                    {
                        if (pointToKeyValueMap.ContainsKey(rect))
                        {
                            // In Release, just log error
                            KeyValue existingKeyValue = pointToKeyValueMap[rect];
                            Log.ErrorFormat("Overlapping keys {0} and {1}, cannot add {1} to map",
                                            existingKeyValue.ToString(), key.Value.ToString());

                            Debug.Assert(!pointToKeyValueMap.ContainsKey(rect));
                        }
                        else
                        {
                            pointToKeyValueMap.Add(rect, key.Value);
                        }
                    }
                }
            }

            PointToKeyValueMap = pointToKeyValueMap;
        }
示例#13
0
文件: Key.cs 项目: samgled/OptiKey
        private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
        {
            onUnloaded = new CompositeDisposable();

            var keyboardHost = VisualAndLogicalTreeHelper.FindVisualParent <KeyboardHost>(this);

            // If key isn't visible, it won't have a visual parent and this is okay.
            if (keyboardHost == null && !this.IsVisible)
            {
                return;
            }

            var mainViewModel         = keyboardHost.DataContext as MainViewModel;
            var keyStateService       = mainViewModel.KeyStateService;
            var capturingStateManager = mainViewModel.CapturingStateManager;

            //Calculate KeyDownState
            if (Value != null)
            {
                var keyStateSubscription = keyStateService.KeyDownStates[Value]
                                           .OnPropertyChanges(kds => kds.Value)
                                           .Subscribe(value => KeyDownState = value);
                onUnloaded.Add(keyStateSubscription);
            }
            KeyDownState = (Value == null) ? KeyDownStates.Up : keyStateService.KeyDownStates[Value].Value;

            //Calculate SelectionProgress and SelectionInProgress
            if (Value != null)
            {
                var keySelectionProgressSubscription = keyStateService.KeySelectionProgress[Value]
                                                       .OnPropertyChanges(ksp => ksp.Value)
                                                       .Subscribe(value =>
                {
                    SelectionProgress   = value;
                    SelectionInProgress = value > 0d;
                });
                onUnloaded.Add(keySelectionProgressSubscription);
            }
            var progress = (Value == null) ? 0 : keyStateService.KeySelectionProgress[Value].Value;

            SelectionProgress   = progress;
            SelectionInProgress = progress > 0d;

            //Calculate IsEnabled
            Action calculateIsEnabled     = () => IsEnabled = keyStateService.KeyEnabledStates[Value];
            var    keyEnabledSubscription = keyStateService.KeyEnabledStates
                                            .OnAnyPropertyChanges()
                                            .Subscribe(_ => calculateIsEnabled());

            onUnloaded.Add(keyEnabledSubscription);
            calculateIsEnabled();

            //Calculate IsCurrent
            Action <KeyValue> calculateIsCurrent = value => IsCurrent = value != null && Value != null && value.Equals(Value);
            var currentPositionSubscription      = mainViewModel.OnPropertyChanges(vm => vm.CurrentPositionKey)
                                                   .Subscribe(calculateIsCurrent);

            onUnloaded.Add(currentPositionSubscription);
            calculateIsCurrent(mainViewModel.CurrentPositionKey);

            //Calculate DisplayShiftDownText
            //Display shift down text (upper case text) if shift is locked down, or down (but NOT when we are capturing a multi key selection)
            Action <KeyDownStates, bool> calculateDisplayShiftDownText = (shiftDownState, capturingMultiKeySelection) =>
                                                                         DisplayShiftDownText = shiftDownState == KeyDownStates.LockedDown ||
                                                                                                (shiftDownState == KeyDownStates.Down && !capturingMultiKeySelection);

            var capturingMultiKeySelectionSubscription = capturingStateManager
                                                         .OnPropertyChanges(csm => csm.CapturingMultiKeySelection)
                                                         .Subscribe(value => calculateDisplayShiftDownText(keyStateService.KeyDownStates[KeyValues.LeftShiftKey].Value, value));

            onUnloaded.Add(capturingMultiKeySelectionSubscription);

            var leftShiftKeyStateSubscription = keyStateService.KeyDownStates[KeyValues.LeftShiftKey]
                                                .OnPropertyChanges(sds => sds.Value)
                                                .Subscribe(value => calculateDisplayShiftDownText(value, capturingStateManager.CapturingMultiKeySelection));

            onUnloaded.Add(leftShiftKeyStateSubscription);
            calculateDisplayShiftDownText(keyStateService.KeyDownStates[KeyValues.LeftShiftKey].Value, capturingStateManager.CapturingMultiKeySelection);

            //Publish own version of KeySelection event
            var keySelectionSubscription = Observable.FromEventPattern <KeyValue>(
                handler => mainViewModel.KeySelection += handler,
                handler => mainViewModel.KeySelection -= handler)
                                           .Subscribe(pattern =>
            {
                if (Value != null &&
                    pattern.EventArgs.Equals(Value) &&
                    Selection != null)
                {
                    Selection(this, null);
                }
            });

            onUnloaded.Add(keySelectionSubscription);
        }
示例#14
0
        private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
        {
            onUnloaded = new CompositeDisposable();

            var keyboardHost    = VisualAndLogicalTreeHelper.FindVisualParent <KeyboardHost>(this);
            var mainViewModel   = keyboardHost.DataContext as MainViewModel;
            var keyStateService = mainViewModel.KeyStateService;

            //Calculate SelectionProgress and SelectionInProgress
            var keySelectionProgressSubscription = keyStateService.KeySelectionProgress[Value]
                                                   .OnPropertyChanges(ksp => ksp.Value)
                                                   .Subscribe(value =>
            {
                SelectionProgress   = value;
                SelectionInProgress = value > 0d;
            });

            onUnloaded.Add(keySelectionProgressSubscription);
            var progress = keyStateService.KeySelectionProgress[Value].Value;

            SelectionProgress   = progress;
            SelectionInProgress = progress > 0d;

            //Calculate IsCurrent
            Action <KeyValue?> calculateIsCurrent = value => IsCurrent = value != null && value.Value.Equals(Value);
            var currentPositionSubscription       = mainViewModel.OnPropertyChanges(vm => vm.CurrentPositionKey)
                                                    .Subscribe(calculateIsCurrent);

            onUnloaded.Add(currentPositionSubscription);
            calculateIsCurrent(mainViewModel.CurrentPositionKey);

            //Publish own version of CorrectKeySelection event
            var correctKeySelectionSubscription = Observable.FromEventPattern <KeyValue>(
                handler => mainViewModel.CorrectKeySelection += handler,
                handler => mainViewModel.CorrectKeySelection -= handler)
                                                  .Subscribe(pattern =>
            {
                if (pattern.EventArgs.Equals(Value) &&
                    CorrectSelection != null)
                {
                    CorrectSelection(this, null);
                }
            });

            onUnloaded.Add(correctKeySelectionSubscription);

            //Publish own version of IncorrectKeySelection event
            var incorrectKeySelectionSubscription = Observable.FromEventPattern <KeyValue>(
                handler => mainViewModel.IncorrectKeySelection += handler,
                handler => mainViewModel.IncorrectKeySelection -= handler)
                                                    .Subscribe(pattern =>
            {
                if (pattern.EventArgs.Equals(Value) &&
                    IncorrectSelection != null)
                {
                    IncorrectSelection(this, null);
                }
            });

            onUnloaded.Add(incorrectKeySelectionSubscription);
        }
示例#15
0
        private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
        {
            onUnloaded = new CompositeDisposable();

            var keyboardHost          = VisualAndLogicalTreeHelper.FindVisualParent <KeyboardHost>(this);
            var mainViewModel         = keyboardHost.DataContext as MainViewModel;
            var keyStateService       = mainViewModel.KeyStateService;
            var capturingStateManager = mainViewModel.CapturingStateManager;

            //Calculate KeyDownState
            var keyStateSubscription = keyStateService.KeyDownStates[Value]
                                       .OnPropertyChanges(kds => kds.Value)
                                       .Subscribe(value => KeyDownState = value);

            onUnloaded.Add(keyStateSubscription);
            KeyDownState = keyStateService.KeyDownStates[Value].Value;

            //Calculate SelectionProgress
            var keySelectionProgressSubscription = keyStateService.KeySelectionProgress[Value]
                                                   .OnPropertyChanges(ksp => ksp.Value)
                                                   .Subscribe(value => SelectionProgress = value);

            onUnloaded.Add(keySelectionProgressSubscription);
            SelectionProgress = keyStateService.KeySelectionProgress[Value].Value;

            //Calculate IsEnabled
            Action calculateIsEnabled     = () => IsEnabled = keyStateService.KeyEnabledStates[Value];
            var    keyEnabledSubscription = keyStateService.KeyEnabledStates
                                            .OnAnyPropertyChanges()
                                            .Subscribe(_ => calculateIsEnabled());

            onUnloaded.Add(keyEnabledSubscription);
            calculateIsEnabled();

            //Calculate IsCurrent
            Action <KeyValue?> calculateIsCurrent = value => IsCurrent = value != null && value.Value.Equals(Value);
            var currentPositionSubscription       = mainViewModel.OnPropertyChanges(vm => vm.CurrentPositionKey)
                                                    .Subscribe(calculateIsCurrent);

            onUnloaded.Add(currentPositionSubscription);
            calculateIsCurrent(mainViewModel.CurrentPositionKey);

            //Calculate DisplayShiftDownText
            Action <KeyDownStates, bool> calculateDisplayShiftDownText = (shiftDownState, capturingMultiKeySelection) =>
                                                                         DisplayShiftDownText = shiftDownState == KeyDownStates.LockedDown ||
                                                                                                (shiftDownState == KeyDownStates.Down && !capturingMultiKeySelection);
            var capturingMultiKeySelectionSubscription = capturingStateManager
                                                         .OnPropertyChanges(csm => csm.CapturingMultiKeySelection)
                                                         .Subscribe(value => calculateDisplayShiftDownText(keyStateService.KeyDownStates[KeyValues.LeftShiftKey].Value, value));

            onUnloaded.Add(capturingMultiKeySelectionSubscription);
            var leftShiftKeyStateSubscription = keyStateService.KeyDownStates[KeyValues.LeftShiftKey]
                                                .OnPropertyChanges(sds => sds.Value)
                                                .Subscribe(value => calculateDisplayShiftDownText(value, capturingStateManager.CapturingMultiKeySelection));

            onUnloaded.Add(leftShiftKeyStateSubscription);
            calculateDisplayShiftDownText(keyStateService.KeyDownStates[KeyValues.LeftShiftKey].Value, capturingStateManager.CapturingMultiKeySelection);

            //Publish own version of KeySelection event
            var keySelectionSubscription = Observable.FromEventPattern <KeyValue>(
                handler => mainViewModel.KeySelection += handler,
                handler => mainViewModel.KeySelection -= handler)
                                           .Subscribe(pattern =>
            {
                if (pattern.EventArgs.Equals(Value) &&
                    Selection != null)
                {
                    Selection(this, null);
                }
            });

            onUnloaded.Add(keySelectionSubscription);
        }
示例#16
0
        private void GenerateContent()
        {
            Log.DebugFormat("GenerateContent called. Keyboard language is '{0}' and Keyboard type is '{1}'",
                            Settings.Default.KeyboardAndDictionaryLanguage, Keyboard != null ? Keyboard.GetType() : null);

            //Clear out point to key map
            PointToKeyValueMap = null;

            mainWindow = mainWindow != null ? mainWindow : VisualAndLogicalTreeHelper.FindVisualParent <MainWindow>(this);

            //Clear any potential main window color overrides
            if (mainWindow != null)
            {
                keyFamily                           = mainWindow.KeyFamily;
                keyValueByGroup                     = mainWindow.KeyValueByGroup;
                overrideTimesByKey                  = mainWindow.OverrideTimesByKey;
                windowManipulationService           = mainWindow.WindowManipulationService;
                mainWindow.BackgroundColourOverride = null;
                mainWindow.BorderBrushOverride      = null;

                //Clear the dictionaries
                keyFamily?.Clear();
                keyValueByGroup?.Clear();
                overrideTimesByKey?.Clear();

                //https://github.com/OptiKey/OptiKey/pull/715
                //Fixing issue where navigating between dynamic and conversation keyboards causing sizing problems:
                //https://github.com/AdamRoden: "I think that because we use a dispatcher to apply the saved size and position,
                //we get in a situation where the main thread maximizes the window before it gets resized by the dispatcher thread.
                //My fix basically says, "don't try restoring the persisted state if we're navigating a maximized keyboard.""
                if (!(Keyboard is ViewModelKeyboards.DynamicKeyboard) &&
                    !(Keyboard is ViewModelKeyboards.ConversationAlpha1) &&
                    !(Keyboard is ViewModelKeyboards.ConversationAlpha2) &&
                    !(Keyboard is ViewModelKeyboards.ConversationConfirm) &&
                    !(Keyboard is ViewModelKeyboards.ConversationNumericAndSymbols))
                {
                    windowManipulationService.RestorePersistedState();
                }
            }

            object newContent = ErrorContent;

            if (Keyboard is ViewModelKeyboards.Alpha1)
            {
                if (Settings.Default.UsingCommuniKateKeyboardLayout)
                {
                    newContent = (object)new CommonViews.CommuniKate {
                        DataContext = Keyboard
                    };
                }
                else
                {
                    switch (Settings.Default.KeyboardAndDictionaryLanguage)
                    {
                    case Languages.CatalanSpain:
                        newContent = new CatalanViews.Alpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.CroatianCroatia:
                        newContent = new CroatianViews.Alpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.CzechCzechRepublic:
                        newContent = new CzechViews.Alpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.DanishDenmark:
                        newContent = new DanishViews.Alpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.DutchBelgium:
                        newContent = new DutchViews.BelgiumAlpha {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.DutchNetherlands:
                        newContent = new DutchViews.NetherlandsAlpha {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.FinnishFinland:
                        newContent = new FinnishViews.Alpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.FrenchCanada:
                        newContent = new FrenchViews.CanadaAlpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.FrenchFrance:
                        newContent = new FrenchViews.FranceAlpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.GeorgianGeorgia:
                        newContent = Settings.Default.UseSimplifiedKeyboardLayout
                            ? (object)new GeorgianViews.SimplifiedAlpha1 {
                            DataContext = Keyboard
                        }
                            : new GeorgianViews.Alpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.GermanGermany:
                        newContent = Settings.Default.UseSimplifiedKeyboardLayout
                            ? (object)new GermanViews.SimplifiedAlpha1 {
                            DataContext = Keyboard
                        }
                            : Settings.Default.UseAlphabeticalKeyboardLayout
                                ? (object)new GermanViews.AlphabeticalAlpha1 {
                            DataContext = Keyboard
                        }
                                : new GermanViews.Alpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.GreekGreece:
                        newContent = new GreekViews.Alpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.HebrewIsrael:
                        newContent = Settings.Default.UseSimplifiedKeyboardLayout
                            ? (object)new HebrewViews.SimplifiedAlpha1 {
                            DataContext = Keyboard
                        }
                            : new HebrewViews.Alpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.HindiIndia:
                        newContent = new HindiViews.Alpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.HungarianHungary:
                        newContent = new HungarianViews.Alpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.ItalianItaly:
                        newContent = Settings.Default.UseAlphabeticalKeyboardLayout
                            ? (object)new ItalianViews.AlphabeticalAlpha1 {
                            DataContext = Keyboard
                        }
                            : new ItalianViews.Alpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.JapaneseJapan:
                        newContent = Settings.Default.UseSimplifiedKeyboardLayout
                            ? (object)new JapaneseViews.SimplifiedAlpha1 {
                            DataContext = Keyboard
                        }
                            : new JapaneseViews.Alpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.KoreanKorea:
                        newContent = new KoreanViews.Alpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.PersianIran:
                        newContent = new PersianViews.Alpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.PolishPoland:
                        newContent = new PolishViews.Alpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.PortuguesePortugal:
                        newContent = new PortugueseViews.Alpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.RussianRussia:
                        newContent = new RussianViews.Alpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.SerbianSerbia:
                        newContent = new SerbianViews.Alpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.SlovakSlovakia:
                        newContent = new SlovakViews.Alpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.SlovenianSlovenia:
                        newContent = new SlovenianViews.Alpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.SpanishSpain:
                        newContent = new SpanishViews.Alpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.TurkishTurkey:
                        newContent = Settings.Default.UseSimplifiedKeyboardLayout
                            ? (object)new TurkishViews.SimplifiedAlpha1 {
                            DataContext = Keyboard
                        }
                            : new TurkishViews.Alpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.UkrainianUkraine:
                        newContent = new UkrainianViews.Alpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.UrduPakistan:
                        newContent = new UrduViews.Alpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    default:
                        newContent = Settings.Default.UseSimplifiedKeyboardLayout
                            ? (object)new EnglishViews.SimplifiedAlpha1 {
                            DataContext = Keyboard
                        }
                            : Settings.Default.UseAlphabeticalKeyboardLayout
                                ? (object)new EnglishViews.AlphabeticalAlpha1 {
                            DataContext = Keyboard
                        }
                                : new EnglishViews.Alpha1 {
                            DataContext = Keyboard
                        };
                        break;
                    }
                }
            }
            else if (Keyboard is ViewModelKeyboards.Alpha2)
            {
                switch (Settings.Default.KeyboardAndDictionaryLanguage)
                {
                case Languages.HebrewIsrael:
                    newContent = new HebrewViews.Alpha2 {
                        DataContext = Keyboard
                    };
                    break;

                case Languages.HindiIndia:
                    newContent = new HindiViews.Alpha2 {
                        DataContext = Keyboard
                    };
                    break;

                case Languages.JapaneseJapan:
                    newContent = Settings.Default.UseSimplifiedKeyboardLayout
                            ? (object)new JapaneseViews.SimplifiedAlpha2 {
                        DataContext = Keyboard
                    }
                            : new JapaneseViews.Alpha2 {
                        DataContext = Keyboard
                    };
                    break;

                case Languages.KoreanKorea:
                    newContent = new KoreanViews.Alpha2 {
                        DataContext = Keyboard
                    };
                    break;

                case Languages.PersianIran:
                    newContent = new PersianViews.Alpha2 {
                        DataContext = Keyboard
                    };
                    break;

                case Languages.UrduPakistan:
                    newContent = new UrduViews.Alpha2 {
                        DataContext = Keyboard
                    };
                    break;
                }
            }
            //else if (Keyboard is ViewModelKeyboards.Alpha3)
            //{
            //    switch (Settings.Default.KeyboardAndDictionaryLanguage)
            //    {
            //        case Languages.PlaceholderForALanguageWith3AlphaKeyboards:
            //            newContent = new PlaceholderForALanguageWith3AlphaKeyboardsViews.Alpha3 {DataContext = Keyboard};
            //            break;
            //    }
            //}
            else if (Keyboard is ViewModelKeyboards.ConversationAlpha1)
            {
                if (Settings.Default.UsingCommuniKateKeyboardLayout)
                {
                    newContent = (object)new CommonViews.CommuniKate {
                        DataContext = Keyboard
                    };
                }
                else
                {
                    switch (Settings.Default.KeyboardAndDictionaryLanguage)
                    {
                    case Languages.CatalanSpain:
                        newContent = new CatalanViews.ConversationAlpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.CroatianCroatia:
                        newContent = new CroatianViews.ConversationAlpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.CzechCzechRepublic:
                        newContent = new CzechViews.ConversationAlpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.DanishDenmark:
                        newContent = new DanishViews.ConversationAlpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.DutchBelgium:
                        newContent = new DutchViews.BelgiumConversationAlpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.DutchNetherlands:
                        newContent = new DutchViews.NetherlandsConversationAlpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.FinnishFinland:
                        newContent = new FinnishViews.ConversationAlpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.FrenchCanada:
                        newContent = new FrenchViews.CanadaConversationAlpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.FrenchFrance:
                        newContent = new FrenchViews.FranceConversationAlpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.GeorgianGeorgia:
                        newContent = Settings.Default.UseSimplifiedKeyboardLayout
                            ? (object)new GeorgianViews.SimplifiedConversationAlpha1 {
                            DataContext = Keyboard
                        }
                            : new GeorgianViews.ConversationAlpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.GermanGermany:
                        newContent = Settings.Default.UseSimplifiedKeyboardLayout
                            ? (object)new GermanViews.SimplifiedConversationAlpha1 {
                            DataContext = Keyboard
                        }
                            : Settings.Default.UseAlphabeticalKeyboardLayout
                                ? (object)new GermanViews.AlphabeticalConversationAlpha1 {
                            DataContext = Keyboard
                        }
                                : new GermanViews.ConversationAlpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.GreekGreece:
                        newContent = new GreekViews.ConversationAlpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.HebrewIsrael:
                        newContent = Settings.Default.UseSimplifiedKeyboardLayout
                            ? (object)new HebrewViews.SimplifiedConversationAlpha1 {
                            DataContext = Keyboard
                        }
                            : new HebrewViews.ConversationAlpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.HindiIndia:
                        newContent = new HindiViews.ConversationAlpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.HungarianHungary:
                        newContent = new HungarianViews.ConversationAlpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.ItalianItaly:
                        newContent = Settings.Default.UseAlphabeticalKeyboardLayout
                            ? (object)new ItalianViews.AlphabeticalConversationAlpha1 {
                            DataContext = Keyboard
                        }
                            : new ItalianViews.ConversationAlpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.JapaneseJapan:
                        newContent = new JapaneseViews.ConversationAlpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.KoreanKorea:
                        newContent = new KoreanViews.ConversationAlpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.PersianIran:
                        newContent = new PersianViews.ConversationAlpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.PolishPoland:
                        newContent = new PolishViews.ConversationAlpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.PortuguesePortugal:
                        newContent = new PortugueseViews.ConversationAlpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.RussianRussia:
                        newContent = new RussianViews.ConversationAlpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.SerbianSerbia:
                        newContent = new SerbianViews.ConversationAlpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.SlovakSlovakia:
                        newContent = new SlovakViews.ConversationAlpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.SlovenianSlovenia:
                        newContent = new SlovenianViews.ConversationAlpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.SpanishSpain:
                        newContent = new SpanishViews.ConversationAlpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.TurkishTurkey:
                        newContent = Settings.Default.UseSimplifiedKeyboardLayout
                            ? (object)new TurkishViews.SimplifiedConversationAlpha1 {
                            DataContext = Keyboard
                        }
                            : new TurkishViews.ConversationAlpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.UkrainianUkraine:
                        newContent = new UkrainianViews.ConversationAlpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    case Languages.UrduPakistan:
                        newContent = new UrduViews.ConversationAlpha1 {
                            DataContext = Keyboard
                        };
                        break;

                    default:
                        newContent = Settings.Default.UseSimplifiedKeyboardLayout
                            ? (object)new EnglishViews.SimplifiedConversationAlpha1 {
                            DataContext = Keyboard
                        }
                            : Settings.Default.UseAlphabeticalKeyboardLayout
                                ? (object)new EnglishViews.AlphabeticalConversationAlpha1 {
                            DataContext = Keyboard
                        }
                                : new EnglishViews.ConversationAlpha1 {
                            DataContext = Keyboard
                        };
                        break;
                    }
                }
            }
            else if (Keyboard is ViewModelKeyboards.ConversationAlpha2)
            {
                switch (Settings.Default.KeyboardAndDictionaryLanguage)
                {
                case Languages.HindiIndia:
                    newContent = new HindiViews.ConversationAlpha2 {
                        DataContext = Keyboard
                    };
                    break;

                case Languages.JapaneseJapan:
                    newContent = new JapaneseViews.ConversationAlpha2 {
                        DataContext = Keyboard
                    };
                    break;

                case Languages.KoreanKorea:
                    newContent = new KoreanViews.ConversationAlpha2 {
                        DataContext = Keyboard
                    };
                    break;

                case Languages.PersianIran:
                    newContent = new PersianViews.ConversationAlpha2 {
                        DataContext = Keyboard
                    };
                    break;

                case Languages.UrduPakistan:
                    newContent = new UrduViews.ConversationAlpha2 {
                        DataContext = Keyboard
                    };
                    break;
                }
            }
            //else if (Keyboard is ViewModelKeyboards.ConversationAlpha3)
            //{
            //    switch (Settings.Default.KeyboardAndDictionaryLanguage)
            //    {
            //        case Languages.PlaceholderForALanguageWith3AlphaKeyboards:
            //            newContent = new PlaceholderForALanguageWith3AlphaKeyboardsViews.ConversationAlpha3 { DataContext = Keyboard };
            //            break;
            //    }
            //}
            else if (Keyboard is ViewModelKeyboards.ConversationConfirm)
            {
                newContent = new CommonViews.ConversationConfirm {
                    DataContext = Keyboard
                };
            }
            else if (Keyboard is ViewModelKeyboards.ConversationNumericAndSymbols)
            {
                switch (Settings.Default.KeyboardAndDictionaryLanguage)
                {
                case Languages.HindiIndia:
                    newContent = new HindiViews.ConversationNumericAndSymbols {
                        DataContext = Keyboard
                    };
                    break;

                case Languages.PersianIran:
                    newContent = new PersianViews.ConversationNumericAndSymbols {
                        DataContext = Keyboard
                    };
                    break;

                case Languages.UrduPakistan:
                    newContent = new UrduViews.ConversationNumericAndSymbols {
                        DataContext = Keyboard
                    };
                    break;

                default:
                    newContent = new CommonViews.ConversationNumericAndSymbols {
                        DataContext = Keyboard
                    };
                    break;
                }
            }
            else if (Keyboard is ViewModelKeyboards.Currencies1)
            {
                newContent = new CommonViews.Currencies1 {
                    DataContext = Keyboard
                };
            }
            else if (Keyboard is ViewModelKeyboards.Currencies2)
            {
                newContent = new CommonViews.Currencies2 {
                    DataContext = Keyboard
                };
            }
            else if (Keyboard is ViewModelKeyboards.Diacritics1)
            {
                newContent = new CommonViews.Diacritics1 {
                    DataContext = Keyboard
                };
            }
            else if (Keyboard is ViewModelKeyboards.Diacritics2)
            {
                newContent = new CommonViews.Diacritics2 {
                    DataContext = Keyboard
                };
            }
            else if (Keyboard is ViewModelKeyboards.Diacritics3)
            {
                newContent = new CommonViews.Diacritics3 {
                    DataContext = Keyboard
                };
            }
            else if (Keyboard is ViewModelKeyboards.Language)
            {
                newContent = new CommonViews.Language {
                    DataContext = Keyboard
                };
            }
            else if (Keyboard is ViewModelKeyboards.Voice)
            {
                var voice = Keyboard as ViewModelKeyboards.Voice;

                // Since the Voice keyboard's view-model is in charge of creating the keys instead of the
                // view, we need to make sure any localized text is up-to-date with the current UI language.
                voice.LocalizeKeys();

                newContent = new CommonViews.Voice {
                    DataContext = Keyboard
                };
            }
            else if (Keyboard is ViewModelKeyboards.Menu)
            {
                newContent = new CommonViews.Menu {
                    DataContext = Keyboard
                };
            }
            else if (Keyboard is ViewModelKeyboards.Minimised)
            {
                newContent = new CommonViews.Minimised {
                    DataContext = Keyboard
                };
            }
            else if (Keyboard is ViewModelKeyboards.Mouse)
            {
                newContent = new CommonViews.Mouse {
                    DataContext = Keyboard
                };
            }
            else if (Keyboard is ViewModelKeyboards.NumericAndSymbols1)
            {
                switch (Settings.Default.KeyboardAndDictionaryLanguage)
                {
                case Languages.HindiIndia:
                    newContent = new HindiViews.NumericAndSymbols1 {
                        DataContext = Keyboard
                    };
                    break;

                case Languages.PersianIran:
                    newContent = new PersianViews.NumericAndSymbols1 {
                        DataContext = Keyboard
                    };
                    break;

                case Languages.UrduPakistan:
                    newContent = new UrduViews.NumericAndSymbols1 {
                        DataContext = Keyboard
                    };
                    break;

                default:
                    newContent = new CommonViews.NumericAndSymbols1 {
                        DataContext = Keyboard
                    };
                    break;
                }
            }
            else if (Keyboard is ViewModelKeyboards.NumericAndSymbols2)
            {
                switch (Settings.Default.KeyboardAndDictionaryLanguage)
                {
                case Languages.HindiIndia:
                    newContent = new HindiViews.NumericAndSymbols2 {
                        DataContext = Keyboard
                    };
                    break;

                case Languages.PersianIran:
                    newContent = new PersianViews.NumericAndSymbols2 {
                        DataContext = Keyboard
                    };
                    break;

                case Languages.UrduPakistan:
                    newContent = new UrduViews.NumericAndSymbols2 {
                        DataContext = Keyboard
                    };
                    break;

                default:
                    newContent = new CommonViews.NumericAndSymbols2 {
                        DataContext = Keyboard
                    };
                    break;
                }
            }
            else if (Keyboard is ViewModelKeyboards.NumericAndSymbols3)
            {
                switch (Settings.Default.KeyboardAndDictionaryLanguage)
                {
                case Languages.HindiIndia:
                    newContent = new HindiViews.NumericAndSymbols3 {
                        DataContext = Keyboard
                    };
                    break;

                case Languages.PersianIran:
                    newContent = new PersianViews.NumericAndSymbols3 {
                        DataContext = Keyboard
                    };
                    break;

                case Languages.UrduPakistan:
                    newContent = new UrduViews.NumericAndSymbols3 {
                        DataContext = Keyboard
                    };
                    break;

                default:
                    newContent = new CommonViews.NumericAndSymbols3 {
                        DataContext = Keyboard
                    };
                    break;
                }
            }
            else if (Keyboard is ViewModelKeyboards.PhysicalKeys)
            {
                newContent = new CommonViews.PhysicalKeys {
                    DataContext = Keyboard
                };
            }
            else if (Keyboard is ViewModelKeyboards.SizeAndPosition)
            {
                newContent = new CommonViews.SizeAndPosition {
                    DataContext = Keyboard
                };
            }
            else if (Keyboard is ViewModelKeyboards.WebBrowsing)
            {
                newContent = new CommonViews.WebBrowsing {
                    DataContext = Keyboard
                };
            }
            else if (Keyboard is ViewModelKeyboards.YesNoQuestion)
            {
                newContent = new CommonViews.YesNoQuestion {
                    DataContext = Keyboard
                };
            }
            else if (Keyboard is ViewModelKeyboards.DynamicKeyboard)
            {
                var kb = Keyboard as ViewModelKeyboards.DynamicKeyboard;
                newContent = new CommonViews.DynamicKeyboard(mainWindow, kb.Link, keyFamily, keyValueByGroup, overrideTimesByKey, windowManipulationService)
                {
                    DataContext = Keyboard
                };
            }
            else if (Keyboard is ViewModelKeyboards.DynamicKeyboardSelector)
            {
                var kb = Keyboard as ViewModelKeyboards.DynamicKeyboardSelector;
                newContent = new CommonViews.DynamicKeyboardSelector(kb.PageIndex)
                {
                    DataContext = Keyboard
                };
            }
            Content = newContent;
        }