0029021: Coding Rules - eliminate GCC warnings in Qt sample
[occt.git] / samples / xaml / App.xaml.cpp
CommitLineData
742cc8b0 1//
2// App.xaml.cpp
3// Implementation of the App class.
4//
5
6#include "pch.h"
7#include "MainPage.xaml.h"
8
9using namespace uwp;
10
11using namespace Platform;
12using namespace Windows::ApplicationModel;
13using namespace Windows::ApplicationModel::Activation;
14using namespace Windows::Foundation;
15using namespace Windows::Foundation::Collections;
16using namespace Windows::UI::Xaml;
17using namespace Windows::UI::Xaml::Controls;
18using namespace Windows::UI::Xaml::Controls::Primitives;
19using namespace Windows::UI::Xaml::Data;
20using namespace Windows::UI::Xaml::Input;
21using namespace Windows::UI::Xaml::Interop;
22using namespace Windows::UI::Xaml::Media;
23using namespace Windows::UI::Xaml::Navigation;
24
25/// <summary>
26/// Initializes the singleton application object. This is the first line of authored code
27/// executed, and as such is the logical equivalent of main() or WinMain().
28/// </summary>
29App::App()
30{
31 InitializeComponent();
32 Suspending += ref new SuspendingEventHandler(this, &App::OnSuspending);
33}
34
35/// <summary>
36/// Invoked when the application is launched normally by the end user. Other entry points
37/// will be used such as when the application is launched to open a specific file.
38/// </summary>
39/// <param name="theEvent">Details about the launch request and process.</param>
40void App::OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ theEvent)
41{
42#if _DEBUG
43 // Show graphics profiling information while debugging.
44 if (IsDebuggerPresent())
45 {
46 // Display the current frame rate counters
47 DebugSettings->EnableFrameRateCounter = true;
48 }
49#endif
50 auto rootFrame = dynamic_cast<Frame^>(Window::Current->Content);
51
52 // Do not repeat app initialization when the Window already has content,
53 // just ensure that the window is active
54 if (rootFrame == nullptr)
55 {
56 // Create a Frame to act as the navigation context and associate it with
57 // a SuspensionManager key
58 rootFrame = ref new Frame();
59
60 rootFrame->NavigationFailed += ref new Windows::UI::Xaml::Navigation::NavigationFailedEventHandler(this, &App::OnNavigationFailed);
61
62 if (theEvent->PreviousExecutionState == ApplicationExecutionState::Terminated)
63 {
64 // TODO: Restore the saved session state only when appropriate, scheduling the
65 // final launch steps after the restore is complete
66
67 }
68
69 if (theEvent->PrelaunchActivated == false)
70 {
71 if (rootFrame->Content == nullptr)
72 {
73 // When the navigation stack isn't restored navigate to the first page,
74 // configuring the new page by passing required information as a navigation
75 // parameter
76 rootFrame->Navigate(TypeName(MainPage::typeid), theEvent->Arguments);
77 }
78 // Place the frame in the current Window
79 Window::Current->Content = rootFrame;
80 // Ensure the current window is active
81 Window::Current->Activate();
82 }
83 }
84 else
85 {
86 if (theEvent->PrelaunchActivated == false)
87 {
88 if (rootFrame->Content == nullptr)
89 {
90 // When the navigation stack isn't restored navigate to the first page,
91 // configuring the new page by passing required information as a navigation
92 // parameter
93 rootFrame->Navigate(TypeName(MainPage::typeid), theEvent->Arguments);
94 }
95 // Ensure the current window is active
96 Window::Current->Activate();
97 }
98 }
99}
100
101/// <summary>
102/// Invoked when application execution is being suspended. Application state is saved
103/// without knowing whether the application will be terminated or resumed with the contents
104/// of memory still intact.
105/// </summary>
106/// <param name="theSender">The source of the suspend request.</param>
107/// <param name="theEvent">Details about the suspend request.</param>
108void App::OnSuspending(Object^ theSender, SuspendingEventArgs^ theEvent)
109{
110 (void)theSender; // Unused parameter
111 (void)theEvent; // Unused parameter
112
113 //TODO: Save application state and stop any background activity
114}
115
116/// <summary>
117/// Invoked when Navigation to a certain page fails
118/// </summary>
119/// <param name="theSender">The Frame which failed navigation</param>
120/// <param name="theEvent">Details about the navigation failure</param>
121void App::OnNavigationFailed(Platform::Object ^theSender, Windows::UI::Xaml::Navigation::NavigationFailedEventArgs ^theEvent)
122{
123 throw ref new FailureException("Failed to load Page " + theEvent->SourcePageType.Name);
124}