From 14a5e74d3213dd4f2a1acbcd35500cf0f8a815b9 Mon Sep 17 00:00:00 2001 From: Matt Cooley Date: Thu, 31 Jan 2019 17:04:48 -0800 Subject: [PATCH] Delete unused functionality from LayoutAwarePage --- src/Calculator/Common/LayoutAwarePage.cpp | 209 ---------------------- src/Calculator/Common/LayoutAwarePage.h | 46 ----- 2 files changed, 255 deletions(-) diff --git a/src/Calculator/Common/LayoutAwarePage.cpp b/src/Calculator/Common/LayoutAwarePage.cpp index c4856407..8af8e264 100644 --- a/src/Calculator/Common/LayoutAwarePage.cpp +++ b/src/Calculator/Common/LayoutAwarePage.cpp @@ -31,218 +31,9 @@ LayoutAwarePage::LayoutAwarePage() return; } - // Create an empty default view model - DefaultViewModel = ref new Map(std::less()); - - // When this page is part of the visual tree make two changes: - // 1) Map application view state to visual state for the page - // 2) Handle keyboard and mouse navigation requests - Loaded += ref new RoutedEventHandler(this, &LayoutAwarePage::OnLoaded); - - // Undo the same changes when the page is no longer visible - Unloaded += ref new RoutedEventHandler(this, &LayoutAwarePage::OnUnloaded); - Language = LocalizationService::GetInstance()->GetLanguage(); } -static DependencyProperty^ _defaultViewModelProperty = - DependencyProperty::Register("DefaultViewModel", - TypeName(IObservableMap::typeid), TypeName(LayoutAwarePage::typeid), nullptr); - -/// -/// Identifies the dependency property. -/// -DependencyProperty^ LayoutAwarePage::DefaultViewModelProperty::get() -{ - return _defaultViewModelProperty; -} - -/// -/// Gets an implementation of designed to be -/// used as a trivial view model. -/// -IObservableMap^ LayoutAwarePage::DefaultViewModel::get() -{ - return safe_cast^>(GetValue(DefaultViewModelProperty)); -} - -/// -/// Sets an implementation of designed to be -/// used as a trivial view model. -/// -void LayoutAwarePage::DefaultViewModel::set(IObservableMap^ value) -{ - SetValue(DefaultViewModelProperty, value); -} - -/// -/// Invoked when the page is part of the visual tree -/// -/// Instance that triggered the event. -/// Event data describing the conditions that led to the event. -void LayoutAwarePage::OnLoaded(Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) -{ - // Keyboard and mouse navigation only apply when occupying the entire window - if (this->ActualHeight == Window::Current->Bounds.Height && - this->ActualWidth == Window::Current->Bounds.Width) - { - // Listen to the window directly so focus isn't required - _acceleratorKeyEventToken = Window::Current->CoreWindow->Dispatcher->AcceleratorKeyActivated += - ref new TypedEventHandler(this, - &LayoutAwarePage::CoreDispatcher_AcceleratorKeyActivated); - _pointerPressedEventToken = Window::Current->CoreWindow->PointerPressed += - ref new TypedEventHandler(this, - &LayoutAwarePage::CoreWindow_PointerPressed); - _navigationShortcutsRegistered = true; - } -} - -/// -/// Invoked when the page is removed from visual tree -/// -/// Instance that triggered the event. -/// Event data describing the conditions that led to the event. -void LayoutAwarePage::OnUnloaded(Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) -{ - if (_navigationShortcutsRegistered) - { - Window::Current->CoreWindow->Dispatcher->AcceleratorKeyActivated -= _acceleratorKeyEventToken; - Window::Current->CoreWindow->PointerPressed -= _pointerPressedEventToken; - _navigationShortcutsRegistered = false; - } -} - -#pragma region Navigation support - -/// -/// Invoked as an event handler to navigate backward in the page's associated -/// until it reaches the top of the navigation stack. -/// -/// Instance that triggered the event. -/// Event data describing the conditions that led to the event. -void LayoutAwarePage::GoHome(Object^ sender, RoutedEventArgs^ e) -{ - (void) sender; // Unused parameter - (void) e; // Unused parameter - - // Use the navigation frame to return to the topmost page - if (Frame != nullptr) - { - while (Frame->CanGoBack) - { - Frame->GoBack(); - } - } -} - -/// -/// Invoked as an event handler to navigate backward in the navigation stack -/// associated with this page's . -/// -/// Instance that triggered the event. -/// Event data describing the conditions that led to the event. -void LayoutAwarePage::GoBack(Object^ sender, RoutedEventArgs^ e) -{ - (void) sender; // Unused parameter - (void) e; // Unused parameter - - // Use the navigation frame to return to the previous page - if (Frame != nullptr && Frame->CanGoBack) - { - Frame->GoBack(); - } -} - -/// -/// Invoked as an event handler to navigate forward in the navigation stack -/// associated with this page's . -/// -/// Instance that triggered the event. -/// Event data describing the conditions that led to the event. -void LayoutAwarePage::GoForward(Object^ sender, RoutedEventArgs^ e) -{ - (void) sender; // Unused parameter - (void) e; // Unused parameter - - // Use the navigation frame to advance to the next page - if (Frame != nullptr && Frame->CanGoForward) - { - Frame->GoForward(); - } -} - -/// -/// Invoked on every keystroke, including system keys such as Alt key combinations, when -/// this page is active and occupies the entire window. Used to detect keyboard navigation -/// between pages even when the page itself doesn't have focus. -/// -/// Instance that triggered the event. -/// Event data describing the conditions that led to the event. -void LayoutAwarePage::CoreDispatcher_AcceleratorKeyActivated(CoreDispatcher^ sender, - AcceleratorKeyEventArgs^ args) -{ - auto virtualKey = args->VirtualKey; - - // Only investigate further when Left, Right, or the dedicated Previous or Next keys - // are pressed - if ((args->EventType == CoreAcceleratorKeyEventType::SystemKeyDown || - args->EventType == CoreAcceleratorKeyEventType::KeyDown) && - (virtualKey == VirtualKey::Left || virtualKey == VirtualKey::Right || - (int)virtualKey == 166 || (int)virtualKey == 167)) - { - auto coreWindow = Window::Current->CoreWindow; - auto downState = Windows::UI::Core::CoreVirtualKeyStates::Down; - bool menuKey = (coreWindow->GetKeyState(VirtualKey::Menu) & downState) == downState; - bool controlKey = (coreWindow->GetKeyState(VirtualKey::Control) & downState) == downState; - bool shiftKey = (coreWindow->GetKeyState(VirtualKey::Shift) & downState) == downState; - bool noModifiers = !menuKey && !controlKey && !shiftKey; - bool onlyAlt = menuKey && !controlKey && !shiftKey; - - if (((int)virtualKey == 166 && noModifiers) || - (virtualKey == VirtualKey::Left && onlyAlt)) - { - // When the previous key or Alt+Left are pressed navigate back - args->Handled = true; - GoBack(this, ref new RoutedEventArgs()); - } - else if (((int)virtualKey == 167 && noModifiers) || - (virtualKey == VirtualKey::Right && onlyAlt)) - { - // When the next key or Alt+Right are pressed navigate forward - args->Handled = true; - GoForward(this, ref new RoutedEventArgs()); - } - } -} - -/// -/// Invoked on every mouse click, touch screen tap, or equivalent interaction when this -/// page is active and occupies the entire window. Used to detect browser-style next and -/// previous mouse button clicks to navigate between pages. -/// -/// Instance that triggered the event. -/// Event data describing the conditions that led to the event. -void LayoutAwarePage::CoreWindow_PointerPressed(CoreWindow^ sender, PointerEventArgs^ args) -{ - auto properties = args->CurrentPoint->Properties; - - // Ignore button chords with the left, right, and middle buttons - if (properties->IsLeftButtonPressed || properties->IsRightButtonPressed || - properties->IsMiddleButtonPressed) return; - - // If back or foward are pressed (but not both) navigate appropriately - bool backPressed = properties->IsXButton1Pressed; - bool forwardPressed = properties->IsXButton2Pressed; - if (backPressed ^ forwardPressed) - { - args->Handled = true; - if (backPressed) GoBack(this, ref new RoutedEventArgs()); - if (forwardPressed) GoForward(this, ref new RoutedEventArgs()); - } -} - -#pragma endregion - #pragma region Process lifetime management /// diff --git a/src/Calculator/Common/LayoutAwarePage.h b/src/Calculator/Common/LayoutAwarePage.h index 298b58b3..c62559aa 100644 --- a/src/Calculator/Common/LayoutAwarePage.h +++ b/src/Calculator/Common/LayoutAwarePage.h @@ -9,47 +9,13 @@ namespace CalculatorApp { namespace Common { - /// - /// Typical implementation of Page that provides several important conveniences: - /// - /// - /// Application view state to visual state mapping - /// - /// - /// GoBack, GoForward, and GoHome event handlers - /// - /// - /// Mouse and keyboard shortcuts for navigation - /// - /// - /// State management for navigation and process lifetime management - /// - /// - /// A default view model - /// - /// - /// [Windows::Foundation::Metadata::WebHostHidden] public ref class LayoutAwarePage : Windows::UI::Xaml::Controls::Page { internal: LayoutAwarePage(); - public: - static property Windows::UI::Xaml::DependencyProperty^ DefaultViewModelProperty - { - Windows::UI::Xaml::DependencyProperty^ get(); - }; - property Windows::Foundation::Collections::IObservableMap^ DefaultViewModel - { - Windows::Foundation::Collections::IObservableMap^ get(); - void set(Windows::Foundation::Collections::IObservableMap^ value); - } - protected: - virtual void GoHome(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); - virtual void GoBack(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); - virtual void GoForward(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); virtual void OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override; virtual void OnNavigatedFrom(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override; virtual void LoadState(Platform::Object^ navigationParameter, @@ -58,18 +24,6 @@ namespace CalculatorApp private: Platform::String^ _pageKey; - bool _navigationShortcutsRegistered; - Platform::Collections::Map^ _defaultViewModel; - Windows::Foundation::EventRegistrationToken _windowSizeEventToken, - _acceleratorKeyEventToken, _pointerPressedEventToken; - Platform::Collections::Vector^ _layoutAwareControls; - void OnLoaded(Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); - void OnUnloaded(Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); - void CoreDispatcher_AcceleratorKeyActivated(Windows::UI::Core::CoreDispatcher^ sender, - Windows::UI::Core::AcceleratorKeyEventArgs^ args); - void CoreWindow_PointerPressed(Windows::UI::Core::CoreWindow^ sender, - Windows::UI::Core::PointerEventArgs^ args); - LayoutAwarePage^ _this; // Strong reference to self, cleaned up in OnUnload }; } }