mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-21 05:43:10 -07:00
Delete unused functionality from LayoutAwarePage
This commit is contained in:
parent
278a1e714e
commit
14a5e74d32
2 changed files with 0 additions and 255 deletions
|
@ -31,218 +31,9 @@ LayoutAwarePage::LayoutAwarePage()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create an empty default view model
|
|
||||||
DefaultViewModel = ref new Map<String^, Object^>(std::less<String^>());
|
|
||||||
|
|
||||||
// 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();
|
Language = LocalizationService::GetInstance()->GetLanguage();
|
||||||
}
|
}
|
||||||
|
|
||||||
static DependencyProperty^ _defaultViewModelProperty =
|
|
||||||
DependencyProperty::Register("DefaultViewModel",
|
|
||||||
TypeName(IObservableMap<String^, Object^>::typeid), TypeName(LayoutAwarePage::typeid), nullptr);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Identifies the <see cref="DefaultViewModel"/> dependency property.
|
|
||||||
/// </summary>
|
|
||||||
DependencyProperty^ LayoutAwarePage::DefaultViewModelProperty::get()
|
|
||||||
{
|
|
||||||
return _defaultViewModelProperty;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets an implementation of <see cref="IObservableMap<String, Object>"/> designed to be
|
|
||||||
/// used as a trivial view model.
|
|
||||||
/// </summary>
|
|
||||||
IObservableMap<String^, Object^>^ LayoutAwarePage::DefaultViewModel::get()
|
|
||||||
{
|
|
||||||
return safe_cast<IObservableMap<String^, Object^>^>(GetValue(DefaultViewModelProperty));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Sets an implementation of <see cref="IObservableMap<String, Object>"/> designed to be
|
|
||||||
/// used as a trivial view model.
|
|
||||||
/// </summary>
|
|
||||||
void LayoutAwarePage::DefaultViewModel::set(IObservableMap<String^, Object^>^ value)
|
|
||||||
{
|
|
||||||
SetValue(DefaultViewModelProperty, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Invoked when the page is part of the visual tree
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sender">Instance that triggered the event.</param>
|
|
||||||
/// <param name="e">Event data describing the conditions that led to the event.</param>
|
|
||||||
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<CoreDispatcher^, AcceleratorKeyEventArgs^>(this,
|
|
||||||
&LayoutAwarePage::CoreDispatcher_AcceleratorKeyActivated);
|
|
||||||
_pointerPressedEventToken = Window::Current->CoreWindow->PointerPressed +=
|
|
||||||
ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this,
|
|
||||||
&LayoutAwarePage::CoreWindow_PointerPressed);
|
|
||||||
_navigationShortcutsRegistered = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Invoked when the page is removed from visual tree
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sender">Instance that triggered the event.</param>
|
|
||||||
/// <param name="e">Event data describing the conditions that led to the event.</param>
|
|
||||||
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
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Invoked as an event handler to navigate backward in the page's associated <see cref="Frame"/>
|
|
||||||
/// until it reaches the top of the navigation stack.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sender">Instance that triggered the event.</param>
|
|
||||||
/// <param name="e">Event data describing the conditions that led to the event.</param>
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Invoked as an event handler to navigate backward in the navigation stack
|
|
||||||
/// associated with this page's <see cref="Frame"/>.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sender">Instance that triggered the event.</param>
|
|
||||||
/// <param name="e">Event data describing the conditions that led to the event.</param>
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Invoked as an event handler to navigate forward in the navigation stack
|
|
||||||
/// associated with this page's <see cref="Frame"/>.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sender">Instance that triggered the event.</param>
|
|
||||||
/// <param name="e">Event data describing the conditions that led to the event.</param>
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 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.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sender">Instance that triggered the event.</param>
|
|
||||||
/// <param name="args">Event data describing the conditions that led to the event.</param>
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 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.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sender">Instance that triggered the event.</param>
|
|
||||||
/// <param name="args">Event data describing the conditions that led to the event.</param>
|
|
||||||
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
|
#pragma region Process lifetime management
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -9,47 +9,13 @@ namespace CalculatorApp
|
||||||
{
|
{
|
||||||
namespace Common
|
namespace Common
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Typical implementation of Page that provides several important conveniences:
|
|
||||||
/// <list type="bullet">
|
|
||||||
/// <item>
|
|
||||||
/// <description>Application view state to visual state mapping</description>
|
|
||||||
/// </item>
|
|
||||||
/// <item>
|
|
||||||
/// <description>GoBack, GoForward, and GoHome event handlers</description>
|
|
||||||
/// </item>
|
|
||||||
/// <item>
|
|
||||||
/// <description>Mouse and keyboard shortcuts for navigation</description>
|
|
||||||
/// </item>
|
|
||||||
/// <item>
|
|
||||||
/// <description>State management for navigation and process lifetime management</description>
|
|
||||||
/// </item>
|
|
||||||
/// <item>
|
|
||||||
/// <description>A default view model</description>
|
|
||||||
/// </item>
|
|
||||||
/// </list>
|
|
||||||
/// </summary>
|
|
||||||
[Windows::Foundation::Metadata::WebHostHidden]
|
[Windows::Foundation::Metadata::WebHostHidden]
|
||||||
public ref class LayoutAwarePage : Windows::UI::Xaml::Controls::Page
|
public ref class LayoutAwarePage : Windows::UI::Xaml::Controls::Page
|
||||||
{
|
{
|
||||||
internal:
|
internal:
|
||||||
LayoutAwarePage();
|
LayoutAwarePage();
|
||||||
|
|
||||||
public:
|
|
||||||
static property Windows::UI::Xaml::DependencyProperty^ DefaultViewModelProperty
|
|
||||||
{
|
|
||||||
Windows::UI::Xaml::DependencyProperty^ get();
|
|
||||||
};
|
|
||||||
property Windows::Foundation::Collections::IObservableMap<Platform::String^, Platform::Object^>^ DefaultViewModel
|
|
||||||
{
|
|
||||||
Windows::Foundation::Collections::IObservableMap<Platform::String^, Platform::Object^>^ get();
|
|
||||||
void set(Windows::Foundation::Collections::IObservableMap<Platform::String^, Platform::Object^>^ value);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
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 OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override;
|
||||||
virtual void OnNavigatedFrom(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override;
|
virtual void OnNavigatedFrom(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override;
|
||||||
virtual void LoadState(Platform::Object^ navigationParameter,
|
virtual void LoadState(Platform::Object^ navigationParameter,
|
||||||
|
@ -58,18 +24,6 @@ namespace CalculatorApp
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Platform::String^ _pageKey;
|
Platform::String^ _pageKey;
|
||||||
bool _navigationShortcutsRegistered;
|
|
||||||
Platform::Collections::Map<Platform::String^, Platform::Object^>^ _defaultViewModel;
|
|
||||||
Windows::Foundation::EventRegistrationToken _windowSizeEventToken,
|
|
||||||
_acceleratorKeyEventToken, _pointerPressedEventToken;
|
|
||||||
Platform::Collections::Vector<Windows::UI::Xaml::Controls::Control^>^ _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
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue