summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Vrhel <michael.vrhel@artifex.com>2013-06-18 12:59:52 -0700
committerRobin Watts <robin.watts@artifex.com>2013-06-19 15:41:00 +0100
commit86a56e1c36ce3936b9f6065b7f055cdc986e7f55 (patch)
tree2d4521519bf07dfeb6b9149f33c4cb462af1531e
parent8a22a7a76be8d9b439ee73383edbdf9d554bf3eb (diff)
downloadmupdf-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.
-rw-r--r--winrt/mupdf_cpp/App.xaml.cpp18
-rw-r--r--winrt/mupdf_cpp/App.xaml.h2
-rw-r--r--winrt/mupdf_cpp/MainPage.xaml.cpp31
-rw-r--r--winrt/mupdf_cpp/MainPage.xaml.h16
-rw-r--r--winrt/mupdf_cpp/Package.appxmanifest11
-rw-r--r--winrt/mupdf_cpp/mupdf_cpp.vcxproj1
-rw-r--r--winrt/mupdfwinrt/Cache.cpp22
-rw-r--r--winrt/mupdfwinrt/muctx.cpp12
-rw-r--r--winrt/mupdfwinrt/mudocument.cpp4
9 files changed, 78 insertions, 39 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>
diff --git a/winrt/mupdfwinrt/Cache.cpp b/winrt/mupdfwinrt/Cache.cpp
index e1e68241..77e253f0 100644
--- a/winrt/mupdfwinrt/Cache.cpp
+++ b/winrt/mupdfwinrt/Cache.cpp
@@ -14,18 +14,20 @@ Cache::~Cache(void)
void Cache::Empty(fz_context *mu_ctx)
{
- cache_entry_t *curr_entry = this->head;
+ if (this != nullptr) {
+ cache_entry_t *curr_entry = this->head;
- while (curr_entry != NULL)
- {
- cache_entry_t *old_entry = curr_entry;
- curr_entry = old_entry->next;
- fz_drop_display_list(mu_ctx, old_entry->dlist);
- delete old_entry;
+ while (curr_entry != NULL)
+ {
+ cache_entry_t *old_entry = curr_entry;
+ curr_entry = old_entry->next;
+ fz_drop_display_list(mu_ctx, old_entry->dlist);
+ delete old_entry;
+ }
+ this->size = 0;
+ this->head = NULL;
+ this->tail = NULL;
}
- this->size = 0;
- this->head = NULL;
- this->tail = NULL;
}
void Cache::AddEntry(int value, fz_display_list *dlist, fz_context *mu_ctx)
diff --git a/winrt/mupdfwinrt/muctx.cpp b/winrt/mupdfwinrt/muctx.cpp
index 11fd77b3..d8f3c6b2 100644
--- a/winrt/mupdfwinrt/muctx.cpp
+++ b/winrt/mupdfwinrt/muctx.cpp
@@ -92,13 +92,13 @@ static void unlock_mutex(void *user, int lock)
void muctx::CleanUp(void)
{
- if (mu_outline != NULL)
- fz_free_outline(mu_ctx, mu_outline);
- if (mu_doc != NULL)
- fz_close_document(mu_doc);
- if (mu_ctx != NULL)
- fz_free_context(mu_ctx);
+ fz_free_outline(mu_ctx, mu_outline);
+ fz_close_document(mu_doc);
+ display_list_cache->Empty(mu_ctx);
+ fz_free_context(mu_ctx);
+ delete display_list_cache;
+ display_list_cache = NULL;
this->mu_ctx = NULL;
this->mu_doc = NULL;
this->mu_outline = NULL;
diff --git a/winrt/mupdfwinrt/mudocument.cpp b/winrt/mupdfwinrt/mudocument.cpp
index b33be118..abcbce70 100644
--- a/winrt/mupdfwinrt/mudocument.cpp
+++ b/winrt/mupdfwinrt/mudocument.cpp
@@ -50,8 +50,8 @@ Windows::Foundation::IAsyncOperation<int>^ mudocument::OpenFileAsync(StorageFile
{
return create_async([this, file]()
{
- String^ path = file->Path;
- const wchar_t *w = path->Data();
+ String^ filetype = file->FileType;
+ const wchar_t *w = filetype->Data();
int cb = WideCharToMultiByte(CP_UTF8, 0, w, -1, nullptr, 0, nullptr, nullptr);
char* name = new char[cb];