From 86a56e1c36ce3936b9f6065b7f055cdc986e7f55 Mon Sep 17 00:00:00 2001 From: Michael Vrhel Date: Tue, 18 Jun 2013 12:59:52 -0700 Subject: Addition of code to allow files to be opened from skydrive and for app to be file activated. Also fixed a few issues for when we open a new file and close the current contents. There was an issue with the displaylist cache clean up. --- winrt/mupdf_cpp/App.xaml.cpp | 18 ++++++++++++++++++ winrt/mupdf_cpp/App.xaml.h | 2 +- winrt/mupdf_cpp/MainPage.xaml.cpp | 31 +++++++++++++++++++++---------- winrt/mupdf_cpp/MainPage.xaml.h | 16 ++++++++++++++++ winrt/mupdf_cpp/Package.appxmanifest | 11 +---------- winrt/mupdf_cpp/mupdf_cpp.vcxproj | 1 + 6 files changed, 58 insertions(+), 21 deletions(-) (limited to 'winrt/mupdf_cpp') diff --git a/winrt/mupdf_cpp/App.xaml.cpp b/winrt/mupdf_cpp/App.xaml.cpp index 1b84a1ab..d0b9d8c7 100644 --- a/winrt/mupdf_cpp/App.xaml.cpp +++ b/winrt/mupdf_cpp/App.xaml.cpp @@ -71,6 +71,10 @@ void App::OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEvent } // Place the frame in the current Window Window::Current->Content = rootFrame; + auto rootPage = safe_cast(rootFrame->Content); + rootPage->FileEvent = nullptr; + rootPage->ProtocolEvent = nullptr; + // Ensure the current window is active Window::Current->Activate(); } @@ -91,6 +95,20 @@ void App::OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEvent } } +// Handle file activations. +void App::OnFileActivated(Windows::ApplicationModel::Activation::FileActivatedEventArgs^ args) +{ + auto rootFrame = ref new Frame(); + TypeName pageType = { "mupdf_cpp.MainPage", TypeKind::Custom }; + rootFrame->Navigate(pageType, args); + Window::Current->Content = rootFrame; + auto rootPage = safe_cast(rootFrame->Content); + rootPage->FileEvent = args; + rootPage->ProtocolEvent = nullptr; + + Window::Current->Activate(); +} + /// /// Invoked when application execution is being suspended. Application state is saved /// without knowing whether the application will be terminated or resumed with the contents diff --git a/winrt/mupdf_cpp/App.xaml.h b/winrt/mupdf_cpp/App.xaml.h index 2ed35bd1..b62c9979 100644 --- a/winrt/mupdf_cpp/App.xaml.h +++ b/winrt/mupdf_cpp/App.xaml.h @@ -17,7 +17,7 @@ namespace mupdf_cpp public: App(); virtual void OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ args) override; - + virtual void App::OnFileActivated(Windows::ApplicationModel::Activation::FileActivatedEventArgs^ args) override; private: void OnSuspending(Platform::Object^ sender, Windows::ApplicationModel::SuspendingEventArgs^ e); }; diff --git a/winrt/mupdf_cpp/MainPage.xaml.cpp b/winrt/mupdf_cpp/MainPage.xaml.cpp index 514cf27b..d31c2b94 100644 --- a/winrt/mupdf_cpp/MainPage.xaml.cpp +++ b/winrt/mupdf_cpp/MainPage.xaml.cpp @@ -74,7 +74,7 @@ extern "C" { #endif /* not NDEBUG */ -MainPage::MainPage() +mupdf_cpp::MainPage::MainPage() { InitializeComponent(); Application::Current->Suspending += @@ -89,6 +89,25 @@ MainPage::MainPage() m_linkset = ref new Platform::Collections::Vector(); CleanUp(); RecordMainThread(); + /* So that we can catch special loading events (e.g. open with) */ + _pageLoadedHandlerToken = Loaded += ref new RoutedEventHandler(this, &MainPage::Page_Loaded); +} + +/* Used during launch of application from file */ +void MainPage::Page_Loaded(Object^ sender, RoutedEventArgs^ e) +{ + MainPage^ rootPage = dynamic_cast(sender); + if (rootPage->FileEvent != nullptr) + { + /* Launched with an "open with", or as default app */ + if (rootPage->FileEvent->Files->Size > 0) + { + IStorageItem ^file = rootPage->FileEvent->Files->GetAt(0); + StorageFile ^sfile = safe_cast(file); + + OpenDocumentPrep(sfile); + } + } } /// @@ -98,7 +117,7 @@ MainPage::MainPage() /// property is typically used to configure the page. void MainPage::OnNavigatedTo(NavigationEventArgs^ e) { - (void) e; // Unused parameter + } void mupdf_cpp::MainPage::App_Suspending(Object^ sender, SuspendingEventArgs^ e) @@ -545,14 +564,6 @@ void mupdf_cpp::MainPage::OpenDocumentPrep(StorageFile^ file) void mupdf_cpp::MainPage::OpenDocument(StorageFile^ file) { - String^ path = file->Path; - const wchar_t *w = path->Data(); - int cb = WideCharToMultiByte(CP_UTF8, 0, w, -1, nullptr, 0, nullptr, nullptr); - char* name = new char[cb]; - - WideCharToMultiByte(CP_UTF8, 0, w ,-1 ,name ,cb ,nullptr, nullptr); - char *ext = strrchr(name, '.'); - this->SetFlipView(); /* Open document and when open, push on */ diff --git a/winrt/mupdf_cpp/MainPage.xaml.h b/winrt/mupdf_cpp/MainPage.xaml.h index 5769389d..203ad64e 100644 --- a/winrt/mupdf_cpp/MainPage.xaml.h +++ b/winrt/mupdf_cpp/MainPage.xaml.h @@ -61,11 +61,24 @@ namespace mupdf_cpp public: MainPage(); + property Windows::ApplicationModel::Activation::ProtocolActivatedEventArgs^ ProtocolEvent + { + Windows::ApplicationModel::Activation::ProtocolActivatedEventArgs^ get() { return _protocolEventArgs; } + void set(Windows::ApplicationModel::Activation::ProtocolActivatedEventArgs^ value) { _protocolEventArgs = value; } + } + + property Windows::ApplicationModel::Activation::FileActivatedEventArgs^ FileEvent + { + Windows::ApplicationModel::Activation::FileActivatedEventArgs^ get() { return _fileEventArgs; } + void set(Windows::ApplicationModel::Activation::FileActivatedEventArgs^ value) { _fileEventArgs = value; } + } + protected: virtual void OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override; virtual void OnKeyDown(Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e) override; private: + Windows::Foundation::EventRegistrationToken _pageLoadedHandlerToken; Vector^ m_docPages; Vector^ m_thumbnails; Vector^>^ m_page_link_list; @@ -157,5 +170,8 @@ namespace mupdf_cpp void NonTouchZoom(int zoom); void ShowSearchBox(); bool IsNotStandardView(); + void Page_Loaded(Object^ sender, RoutedEventArgs^ e); + Windows::ApplicationModel::Activation::ProtocolActivatedEventArgs^ _protocolEventArgs; + Windows::ApplicationModel::Activation::FileActivatedEventArgs^ _fileEventArgs; }; } diff --git a/winrt/mupdf_cpp/Package.appxmanifest b/winrt/mupdf_cpp/Package.appxmanifest index f4315785..b4b59afd 100644 --- a/winrt/mupdf_cpp/Package.appxmanifest +++ b/winrt/mupdf_cpp/Package.appxmanifest @@ -1,6 +1,6 @@  - + mupdf_cpp Artifex Software Inc. @@ -20,15 +20,6 @@ - - - - .pdf - .xps - .cbz - - - diff --git a/winrt/mupdf_cpp/mupdf_cpp.vcxproj b/winrt/mupdf_cpp/mupdf_cpp.vcxproj index fbab6dbd..719fe6be 100644 --- a/winrt/mupdf_cpp/mupdf_cpp.vcxproj +++ b/winrt/mupdf_cpp/mupdf_cpp.vcxproj @@ -91,6 +91,7 @@ mupdf_cpp_TemporaryKey.pfx + 9417B1B38E16F42A27C3D0AA69B4CE6DEB584BAC $(Platform)\$(Configuration)\$(ProjectName)\ -- cgit v1.2.3