summaryrefslogtreecommitdiff
path: root/winrt
diff options
context:
space:
mode:
authorMichael Vrhel <michael.vrhel@artifex.com>2013-05-21 08:04:33 -0700
committerRobin Watts <robin.watts@artifex.com>2013-05-21 17:00:53 +0100
commitf095f7ff494ae6c59dc72b5d4feeac5db5a27351 (patch)
tree9694de9bbe0602c9f2e3fe8d975517af1484fb62 /winrt
parent23dea6df2cb85a136ba6d8d8e34eebe4e105db24 (diff)
downloadmupdf-f095f7ff494ae6c59dc72b5d4feeac5db5a27351.tar.xz
Addition of support for password input.
Also rework of startup based upon password entry. Fix for bug that caused a crash when slider was used, thumbs were still rendering and a new document was opened.
Diffstat (limited to 'winrt')
-rw-r--r--winrt/mupdf_cpp/MainPage.xaml19
-rw-r--r--winrt/mupdf_cpp/MainPage.xaml.cpp175
-rw-r--r--winrt/mupdf_cpp/MainPage.xaml.h2
-rw-r--r--winrt/mupdfwinrt/muctx.cpp6
-rw-r--r--winrt/mupdfwinrt/muctx.h4
-rw-r--r--winrt/mupdfwinrt/mudocument.cpp5
6 files changed, 136 insertions, 75 deletions
diff --git a/winrt/mupdf_cpp/MainPage.xaml b/winrt/mupdf_cpp/MainPage.xaml
index 9ddd2873..3c59d615 100644
--- a/winrt/mupdf_cpp/MainPage.xaml
+++ b/winrt/mupdf_cpp/MainPage.xaml
@@ -253,5 +253,24 @@
</Border>
</StackPanel>
+ <StackPanel x:Name="xaml_PasswordStack" Opacity="1" VerticalAlignment="Center" Visibility="Collapsed">
+ <Border BorderThickness="5" BorderBrush="Black" Margin="300">
+ <StackPanel Background="LightGray" >
+ <TextBlock HorizontalAlignment="Center" Margin="10"
+ Text="Password Required" FontSize="20"/>
+ <PasswordBox x:Name="xaml_password" Height="35" Width="300"/>
+ <Button HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,10" Click="PasswordOK" Height="39">
+ <TextBlock HorizontalAlignment="Center" Text="OK"/>
+ </Button>
+ </StackPanel>
+ </Border>
+ </StackPanel>
+
+
+
+
+
+
+
</Grid>
</Page>
diff --git a/winrt/mupdf_cpp/MainPage.xaml.cpp b/winrt/mupdf_cpp/MainPage.xaml.cpp
index 0e36ffbe..d5fb96b5 100644
--- a/winrt/mupdf_cpp/MainPage.xaml.cpp
+++ b/winrt/mupdf_cpp/MainPage.xaml.cpp
@@ -366,6 +366,7 @@ void mupdf_cpp::MainPage::SetFlipView()
one open */
void mupdf_cpp::MainPage::CleanUp()
{
+ m_init_done = false;
/* Remove current pages in the flipviews */
if (m_docPages != nullptr && m_docPages->Size > 0)
m_docPages->Clear();
@@ -391,7 +392,6 @@ void mupdf_cpp::MainPage::CleanUp()
m_file_open = false;
m_slider_min = 0;
m_slider_max = 0;
- m_init_done = false;
m_memory_use = 0;
m_insearch = false;
m_search_active = false;
@@ -421,7 +421,7 @@ void mupdf_cpp::MainPage::RenderThumbs()
this->m_ren_status = REN_THUMBS;
Vector<DocumentPage^>^ thumbnails = m_thumbnails;
auto ui = task_continuation_context::use_current();
- create_task([spatial_info, num_pages, thumbnails, this, ui, token]()-> int
+ auto task_thumb = create_task([spatial_info, num_pages, thumbnails, this, ui, token]()-> int
{
spatial_info_t spatial_info_local = spatial_info;
spatial_info_local.scale_factor = SCALE_THUMB;
@@ -429,8 +429,6 @@ void mupdf_cpp::MainPage::RenderThumbs()
for (int k = 0; k < num_pages; k++)
{
Point ras_size = ComputePageSize(spatial_info_local, k);
- bool done = false;
- DWORD thread1_id = GetCurrentThreadId();
auto task2 = create_task(mu_doc->RenderPageAsync(k, ras_size.X, ras_size.Y));
task2.then([this, k, thumbnails, ras_size](InMemoryRandomAccessStream^ ras)
@@ -445,10 +443,10 @@ void mupdf_cpp::MainPage::RenderThumbs()
doc_page->Content = THUMBNAIL;
doc_page->TextBox = nullptr;
doc_page->LinkBox = nullptr;
- if (this->m_ren_status == REN_THUMBS) {
+ if (m_init_done)
+ {
m_thumbnails->SetAt(k, doc_page); /* This avoids out of order returns from task */
- /* Flipview object gets overwhelmed unless I do this */
- if ((k < THUMB_PREADD))
+ if (k < THUMB_PREADD) /* Flip view gets overwhelmed if I don't do this */
SetThumb(k, false);
}
}, ui).then([this] (task<void> t)
@@ -477,7 +475,7 @@ void mupdf_cpp::MainPage::RenderThumbs()
bool is_cancelled = false;
try
{
- the_task.get();
+ the_task.get();
}
catch (const task_canceled& e)
{
@@ -544,80 +542,108 @@ void mupdf_cpp::MainPage::OpenDocument(StorageFile^ file)
/* Open document and when open, push on */
auto open_task = create_task(mu_doc->OpenFileAsync(file));
-
- open_task.then([this]
+ open_task.then([this]() -> bool
{
assert(IsMainThread());
-
- m_num_pages = mu_doc->GetNumPages();
-
- if ((m_currpage) >= m_num_pages)
+ /* We need to check if password is required */
+ if (mu_doc->RequiresPassword())
{
- m_currpage = m_num_pages - 1;
+ xaml_PasswordStack->Visibility = Windows::UI::Xaml::Visibility::Visible;
+ return false;
}
- else if (m_currpage < 0)
+ else
{
- m_currpage = 0;
+ xaml_PasswordStack->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
+ return true;
}
- /* Initialize all the flipvew items with blanks and the thumbnails. */
- for (int k = 0; k < m_num_pages; k++)
+ }).then([this](bool password_ok)->bool
+ {
+ assert(IsMainThread());
+ if (!password_ok)
+ return password_ok;
+ else
{
- /* Blank pages */
- DocumentPage^ doc_page = ref new DocumentPage();
- doc_page->Image = m_BlankBmp;
- doc_page->Height = BLANK_HEIGHT;
- doc_page->Width = BLANK_WIDTH;
- doc_page->Content = DUMMY;
- doc_page->TextBox = nullptr;
- doc_page->LinkBox = nullptr;
- m_docPages->Append(doc_page);
- m_thumbnails->Append(doc_page);
- /* Create empty lists for our links and specify that they have not
- been computed for these pages */
- Vector<RectList^>^ temp_link = ref new Vector<RectList^>();
- m_page_link_list->Append(temp_link);
- m_linkset->Append(false);
+ InitialRender();
+ return password_ok;
}
+ }, task_continuation_context::use_current()).then([this](bool password_ok)
+ {
+ if (password_ok)
+ RenderThumbs();
+ }, task_continuation_context::use_current());
+}
- this->xaml_horiz_flipView->ItemsSource = m_docPages;
- this->xaml_vert_flipView->ItemsSource = m_docPages;
+void mupdf_cpp::MainPage::InitialRender()
+{
+ assert(IsMainThread());
+ m_num_pages = mu_doc->GetNumPages();
- /* Do the first few pages, then start the thumbs */
- spatial_info_t spatial_info = InitSpatial(1);
- for (int k = 0; k < LOOK_AHEAD + 2; k++)
- {
- if (m_num_pages > k )
- {
- Point ras_size = ComputePageSize(spatial_info, k);
+ if ((m_currpage) >= m_num_pages)
+ {
+ m_currpage = m_num_pages - 1;
+ }
+ else if (m_currpage < 0)
+ {
+ m_currpage = 0;
+ }
- auto render_task =
- create_task(mu_doc->RenderPageAsync(k, ras_size.X, ras_size.Y));
+ /* Initialize all the flipvew items with blanks and the thumbnails. */
+ for (int k = 0; k < m_num_pages; k++)
+ {
+ /* Blank pages */
+ DocumentPage^ doc_page = ref new DocumentPage();
+ doc_page->Image = m_BlankBmp;
+ doc_page->Height = BLANK_HEIGHT;
+ doc_page->Width = BLANK_WIDTH;
+ doc_page->Content = DUMMY;
+ doc_page->TextBox = nullptr;
+ doc_page->LinkBox = nullptr;
+ m_docPages->Append(doc_page);
+ m_thumbnails->Append(doc_page);
+ /* Create empty lists for our links and specify that they have
+ not been computed for these pages */
+ Vector<RectList^>^ temp_link = ref new Vector<RectList^>();
+ m_page_link_list->Append(temp_link);
+ m_linkset->Append(false);
+ }
- render_task.then([this, k, ras_size] (InMemoryRandomAccessStream^ ras)
- {
- UpdatePage(k, ras, ras_size, FULL_RESOLUTION);
- }, task_continuation_context::use_current());
- }
- }
- /* Update the slider settings, if more than one page */
- if (m_num_pages > 1)
- {
- this->xaml_PageSlider->Maximum = m_num_pages;
- this->xaml_PageSlider->Minimum = 1;
- this->xaml_PageSlider->IsEnabled = true;
- }
- else
+ this->xaml_horiz_flipView->ItemsSource = m_docPages;
+ this->xaml_vert_flipView->ItemsSource = m_docPages;
+
+ /* Do the first few pages, then start the thumbs */
+ spatial_info_t spatial_info = InitSpatial(1);
+ for (int k = 0; k < LOOK_AHEAD + 2; k++)
+ {
+ if (m_num_pages > k )
{
- this->xaml_PageSlider->Maximum = 0;
- this->xaml_PageSlider->Minimum = 0;
- this->xaml_PageSlider->IsEnabled = false;
+ Point ras_size = ComputePageSize(spatial_info, k);
+
+ auto render_task =
+ create_task(mu_doc->RenderPageAsync(k, ras_size.X, ras_size.Y));
+
+ render_task.then([this, k, ras_size] (InMemoryRandomAccessStream^ ras)
+ {
+ UpdatePage(k, ras, ras_size, FULL_RESOLUTION);
+ }, task_continuation_context::use_current());
}
- /* All done with initial pages */
- this->m_init_done = true;
- }).then([this]
+ }
+
+ /* Update the slider settings, if more than one page */
+ if (m_num_pages > 1)
{
- this->RenderThumbs();
- }, task_continuation_context::use_current());
+ this->xaml_PageSlider->Maximum = m_num_pages;
+ this->xaml_PageSlider->Minimum = 1;
+ this->xaml_PageSlider->IsEnabled = true;
+ }
+ else
+ {
+ this->xaml_PageSlider->Maximum = 0;
+ this->xaml_PageSlider->Minimum = 0;
+ this->xaml_PageSlider->IsEnabled = false;
+ }
+
+ /* All done with initial pages */
+ this->m_init_done = true;
}
void mupdf_cpp::MainPage::RenderRange(int curr_page)
@@ -703,7 +729,6 @@ void mupdf_cpp::MainPage::Slider_ValueChanged(Platform::Object^ sender, Windows:
render_task.then([this, newValue, ras_size] (InMemoryRandomAccessStream^ ras)
{
UpdatePage(newValue, ras, ras_size, FULL_RESOLUTION);
- this->m_ren_status = REN_AVAILABLE;
this->m_currpage = newValue;
m_sliderchange = true;
this->m_curr_flipView->SelectedIndex = newValue;
@@ -1314,3 +1339,17 @@ void MainPage::OnKeyDown(KeyRoutedEventArgs^ e)
ReplaceImage(page, ras, ras_size);
}, task_continuation_context::use_current());
}
+
+void mupdf_cpp::MainPage::PasswordOK(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
+{
+ /* If password checks out then go ahead and start rendering */
+ if (mu_doc->ApplyPassword(xaml_password->Password))
+ {
+ xaml_password->Password = nullptr;
+ xaml_PasswordStack->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
+ InitialRender();
+ RenderThumbs();
+ }
+ else
+ NotifyUser("Incorrect Password", StatusMessage);
+}
diff --git a/winrt/mupdf_cpp/MainPage.xaml.h b/winrt/mupdf_cpp/MainPage.xaml.h
index 040d03c4..96476361 100644
--- a/winrt/mupdf_cpp/MainPage.xaml.h
+++ b/winrt/mupdf_cpp/MainPage.xaml.h
@@ -104,6 +104,7 @@ namespace mupdf_cpp
void Searcher(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void OpenDocumentPrep(StorageFile^ file);
void OpenDocument(StorageFile^ file);
+ void InitialRender();
void RenderRange(int curr_page);
void CleanUp();
void UpdatePage(int page_num, InMemoryRandomAccessStream^ ras, Point ras_size, Page_Content_t content_type);
@@ -148,5 +149,6 @@ namespace mupdf_cpp
void ScrollChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::ScrollViewerViewChangedEventArgs^ e);
void LinkTapped(Platform::Object^ sender, Windows::UI::Xaml::Input::TappedRoutedEventArgs^ e);
void SearchProgress(IAsyncOperationWithProgress<int, double>^ operation, double status);
+ void PasswordOK(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
};
}
diff --git a/winrt/mupdfwinrt/muctx.cpp b/winrt/mupdfwinrt/muctx.cpp
index f855e1b3..1b30b31b 100644
--- a/winrt/mupdfwinrt/muctx.cpp
+++ b/winrt/mupdfwinrt/muctx.cpp
@@ -507,11 +507,9 @@ bool muctx::RequiresPassword(void)
return fz_needs_password(mu_doc);
}
-bool muctx::ApplyPassword(String^ password)
+bool muctx::ApplyPassword(char* password)
{
- /* Need to do String to char here */
- // return fz_authenticate_password(mu_doc, password) != 0;
- return 0;
+ return fz_authenticate_password(mu_doc, password);
}
String^ muctx::GetHTML(int page_num)
diff --git a/winrt/mupdfwinrt/muctx.h b/winrt/mupdfwinrt/muctx.h
index c2a49ae1..d1053275 100644
--- a/winrt/mupdfwinrt/muctx.h
+++ b/winrt/mupdfwinrt/muctx.h
@@ -79,7 +79,7 @@ private:
fz_cookie *mu_cookie;
fz_stream *mu_stream;
void FlattenOutline(fz_outline *outline, int level,
- sh_vector_content contents_vec);
+ sh_vector_content contents_vec);
public:
muctx(void);
@@ -96,5 +96,5 @@ public:
int GetContents(sh_vector_content contents_vec);
String^ GetHTML(int page_num);
bool RequiresPassword(void);
- bool ApplyPassword(String^ password);
+ bool ApplyPassword(char* password);
};
diff --git a/winrt/mupdfwinrt/mudocument.cpp b/winrt/mupdfwinrt/mudocument.cpp
index 2779bb25..e05ee846 100644
--- a/winrt/mupdfwinrt/mudocument.cpp
+++ b/winrt/mupdfwinrt/mudocument.cpp
@@ -24,7 +24,10 @@ bool mudocument::RequiresPassword()
bool mudocument::ApplyPassword(String^ password)
{
- return mu_object.ApplyPassword(password);
+ char* pass_char = String_to_char(password);
+ bool ok = mu_object.ApplyPassword(pass_char);
+ delete []pass_char;
+ return ok;
}
void mudocument::CleanUp()