Home | History | Annotate | Download | only in video_capture_xaml.Shared
      1 //
      2 // App.xaml.cpp
      3 // Implementation of the App class.
      4 //
      5 
      6 // Copyright (c) Microsoft Open Technologies, Inc.
      7 // All rights reserved.
      8 //
      9 // (3 - clause BSD License)
     10 //
     11 // Redistribution and use in source and binary forms, with or without modification, are permitted provided that
     12 // the following conditions are met:
     13 //
     14 // 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
     15 // following disclaimer.
     16 // 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
     17 // following disclaimer in the documentation and/or other materials provided with the distribution.
     18 // 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or
     19 // promote products derived from this software without specific prior written permission.
     20 //
     21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
     22 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
     23 // PARTICULAR PURPOSE ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
     24 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO,
     25 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING
     27 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     28 // POSSIBILITY OF SUCH DAMAGE.
     29 
     30 #include "pch.h"
     31 #include "MainPage.xaml.h"
     32 #include "App.xaml.h"
     33 
     34 using namespace video_capture_xaml;
     35 
     36 using namespace Platform;
     37 using namespace Windows::ApplicationModel;
     38 using namespace Windows::ApplicationModel::Activation;
     39 using namespace Windows::Foundation;
     40 using namespace Windows::Foundation::Collections;
     41 using namespace Windows::UI::Xaml::Media::Animation;
     42 using namespace Windows::UI::Xaml;
     43 using namespace Windows::UI::Xaml::Controls;
     44 using namespace Windows::UI::Xaml::Controls::Primitives;
     45 using namespace Windows::UI::Xaml::Data;
     46 using namespace Windows::UI::Xaml::Input;
     47 using namespace Windows::UI::Xaml::Interop;
     48 using namespace Windows::UI::Xaml::Media;
     49 using namespace Windows::UI::Xaml::Navigation;
     50 
     51 // The Blank Application template is documented at http://go.microsoft.com/fwlink/?LinkId=234227
     52 
     53 /// <summary>
     54 /// Initializes the singleton application object. This is the first line of authored code
     55 /// executed, and as such is the logical equivalent of main() or WinMain().
     56 /// </summary>
     57 App::App()
     58 {
     59     InitializeComponent();
     60     Suspending += ref new SuspendingEventHandler(this, &App::OnSuspending);
     61     Resuming += ref new Windows::Foundation::EventHandler<Platform::Object ^>(this, &video_capture_xaml::App::OnResuming);
     62 }
     63 
     64 /// <summary>
     65 /// Invoked when the application is launched normally by the end user. Other entry points
     66 /// will be used when the application is launched to open a specific file, to display
     67 /// search results, and so forth.
     68 /// </summary>
     69 /// <param name="e">Details about the launch request and process.</param>
     70 void App::OnLaunched(LaunchActivatedEventArgs^ e)
     71 {
     72 #if _DEBUG
     73     if (IsDebuggerPresent())
     74     {
     75         DebugSettings->EnableFrameRateCounter = true;
     76     }
     77 #endif
     78 
     79     auto rootFrame = dynamic_cast<Frame^>(Window::Current->Content);
     80 
     81     // Do not repeat app initialization when the Window already has content,
     82     // just ensure that the window is active.
     83     if (rootFrame == nullptr)
     84     {
     85         // Create a Frame to act as the navigation context and associate it with
     86         // a SuspensionManager key
     87         rootFrame = ref new Frame();
     88 
     89         // TODO: Change this value to a cache size that is appropriate for your application.
     90         rootFrame->CacheSize = 1;
     91 
     92         if (e->PreviousExecutionState == ApplicationExecutionState::Terminated)
     93         {
     94             // TODO: Restore the saved session state only when appropriate, scheduling the
     95             // final launch steps after the restore is complete.
     96         }
     97 
     98         // Place the frame in the current Window
     99         Window::Current->Content = rootFrame;
    100     }
    101 
    102     if (rootFrame->Content == nullptr)
    103     {
    104 #if WINAPI_FAMILY==WINAPI_FAMILY_PHONE_APP
    105         // Removes the turnstile navigation for startup.
    106         if (rootFrame->ContentTransitions != nullptr)
    107         {
    108             _transitions = ref new TransitionCollection();
    109             for (auto transition : rootFrame->ContentTransitions)
    110             {
    111                 _transitions->Append(transition);
    112             }
    113         }
    114 
    115         rootFrame->ContentTransitions = nullptr;
    116         _firstNavigatedToken = rootFrame->Navigated += ref new NavigatedEventHandler(this, &App::RootFrame_FirstNavigated);
    117 #endif
    118 
    119         // When the navigation stack isn't restored navigate to the first page,
    120         // configuring the new page by passing required information as a navigation
    121         // parameter.
    122         if (!rootFrame->Navigate(MainPage::typeid, e->Arguments))
    123         {
    124             throw ref new FailureException("Failed to create initial page");
    125         }
    126     }
    127 
    128     // Ensure the current window is active
    129     Window::Current->Activate();
    130 }
    131 
    132 #if WINAPI_FAMILY==WINAPI_FAMILY_PHONE_APP
    133 /// <summary>
    134 /// Restores the content transitions after the app has launched.
    135 /// </summary>
    136 void App::RootFrame_FirstNavigated(Object^ sender, NavigationEventArgs^ e)
    137 {
    138     auto rootFrame = safe_cast<Frame^>(sender);
    139 
    140     TransitionCollection^ newTransitions;
    141     if (_transitions == nullptr)
    142     {
    143         newTransitions = ref new TransitionCollection();
    144         newTransitions->Append(ref new NavigationThemeTransition());
    145     }
    146     else
    147     {
    148         newTransitions = _transitions;
    149     }
    150 
    151     rootFrame->ContentTransitions = newTransitions;
    152 
    153     rootFrame->Navigated -= _firstNavigatedToken;
    154 }
    155 #endif
    156 
    157 /// <summary>
    158 /// Invoked when application execution is being suspended. Application state is saved
    159 /// without knowing whether the application will be terminated or resumed with the contents
    160 /// of memory still intact.
    161 /// </summary>
    162 void App::OnSuspending(Object^ sender, SuspendingEventArgs^ e)
    163 {
    164     (void) sender;	// Unused parameter
    165     (void) e;		// Unused parameter
    166 
    167     // TODO: Save application state and stop any background activity
    168 }
    169 
    170 void video_capture_xaml::App::OnResuming(Platform::Object ^sender, Platform::Object ^args)
    171 {
    172     // throw ref new Platform::NotImplementedException();
    173 }