diff options
author | Michael Vrhel <michael.vrhel@artifex.com> | 2013-06-18 12:59:52 -0700 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2013-06-19 15:41:00 +0100 |
commit | 86a56e1c36ce3936b9f6065b7f055cdc986e7f55 (patch) | |
tree | 2d4521519bf07dfeb6b9149f33c4cb462af1531e /winrt/mupdf_cpp | |
parent | 8a22a7a76be8d9b439ee73383edbdf9d554bf3eb (diff) | |
download | mupdf-86a56e1c36ce3936b9f6065b7f055cdc986e7f55.tar.xz |
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.
Diffstat (limited to 'winrt/mupdf_cpp')
-rw-r--r-- | winrt/mupdf_cpp/App.xaml.cpp | 18 | ||||
-rw-r--r-- | winrt/mupdf_cpp/App.xaml.h | 2 | ||||
-rw-r--r-- | winrt/mupdf_cpp/MainPage.xaml.cpp | 31 | ||||
-rw-r--r-- | winrt/mupdf_cpp/MainPage.xaml.h | 16 | ||||
-rw-r--r-- | winrt/mupdf_cpp/Package.appxmanifest | 11 | ||||
-rw-r--r-- | winrt/mupdf_cpp/mupdf_cpp.vcxproj | 1 |
6 files changed, 58 insertions, 21 deletions
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<MainPage^>(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<MainPage^>(rootFrame->Content); + rootPage->FileEvent = args; + rootPage->ProtocolEvent = nullptr; + + Window::Current->Activate(); +} + /// <summary> /// 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<int>(); 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<MainPage^>(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<StorageFile^>(file); + + OpenDocumentPrep(sfile); + } + } } /// <summary> @@ -98,7 +117,7 @@ MainPage::MainPage() /// property is typically used to configure the page.</param> 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<DocumentPage^>^ m_docPages; Vector<DocumentPage^>^ m_thumbnails; Vector<IVector<RectList^>^>^ 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 @@ <?xml version="1.0" encoding="utf-8"?> <Package xmlns="http://schemas.microsoft.com/appx/2010/manifest"> - <Identity Name="faab8eca-be5e-4e0d-b782-213ccbbc5f34" Publisher="CN=michaelv" Version="1.0.0.0" /> + <Identity Name="faab8eca-be5e-4e0d-b782-213ccbbc5f34" Publisher="CN=Artifex Software" Version="1.0.0.0" /> <Properties> <DisplayName>mupdf_cpp</DisplayName> <PublisherDisplayName>Artifex Software Inc.</PublisherDisplayName> @@ -20,15 +20,6 @@ <SplashScreen Image="Assets\mupdf_splash.png" /> </VisualElements> <Extensions> - <Extension Category="windows.fileOpenPicker"> - <FileOpenPicker> - <SupportedFileTypes> - <FileType>.pdf</FileType> - <FileType>.xps</FileType> - <FileType>.cbz</FileType> - </SupportedFileTypes> - </FileOpenPicker> - </Extension> <Extension Category="windows.fileTypeAssociation"> <FileTypeAssociation Name=".pdf"> <EditFlags OpenIsSafe="true" /> 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 @@ <PropertyGroup Label="UserMacros" /> <PropertyGroup> <PackageCertificateKeyFile>mupdf_cpp_TemporaryKey.pfx</PackageCertificateKeyFile> + <PackageCertificateThumbprint>9417B1B38E16F42A27C3D0AA69B4CE6DEB584BAC</PackageCertificateThumbprint> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <IntDir>$(Platform)\$(Configuration)\$(ProjectName)\</IntDir> |