diff options
author | Michael Vrhel <michael.vrhel@artifex.com> | 2013-05-16 07:28:26 -0700 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2013-05-16 19:26:02 +0100 |
commit | 4a7e2298fff3a1972fda5c537a8c5e7c6d8f8292 (patch) | |
tree | df676cc48957ea4c32f685110bd5f06171f1464c /winrt/mupdf_cpp | |
parent | 97829a9ce4b9818207d5e286179840e0b63c1938 (diff) | |
download | mupdf-4a7e2298fff3a1972fda5c537a8c5e7c6d8f8292.tar.xz |
Addition of progress bar code with cancel during text search.
Also place holders for password support and initial work towards
keyboard based zooming.
Diffstat (limited to 'winrt/mupdf_cpp')
-rw-r--r-- | winrt/mupdf_cpp/MainPage.xaml | 17 | ||||
-rw-r--r-- | winrt/mupdf_cpp/MainPage.xaml.cpp | 153 | ||||
-rw-r--r-- | winrt/mupdf_cpp/MainPage.xaml.h | 11 |
3 files changed, 111 insertions, 70 deletions
diff --git a/winrt/mupdf_cpp/MainPage.xaml b/winrt/mupdf_cpp/MainPage.xaml index 54226eac..184b3668 100644 --- a/winrt/mupdf_cpp/MainPage.xaml +++ b/winrt/mupdf_cpp/MainPage.xaml @@ -59,8 +59,6 @@ </LinearGradientBrush> </Grid.Background> - <ProgressBar x:Name="xaml_Progress" IsIndeterminate="False" Maximum="100" Value="0" Height="10" Width="400" IsEnabled="False" Opacity="0"/> - <Grid x:Name="xaml_MainGrid" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" SizeChanged="GridSizeChanged"> <Canvas x:Name="xaml_zoomCanvas" HorizontalAlignment="Center" VerticalAlignment="Center" ManipulationMode="All" > <!-- Horizontal flip view --> @@ -240,6 +238,21 @@ ScrollViewer.VerticalScrollMode="Enabled" ScrollViewer.HorizontalScrollMode="Enabled" ScrollViewer.ZoomMode="Enabled"/> + + <StackPanel x:Name="xaml_ProgressStack" Opacity="1" VerticalAlignment="Center" Visibility="Collapsed"> + <Border BorderThickness="5" BorderBrush="Black" Margin="300"> + <StackPanel Background="LightGray" > + <TextBlock HorizontalAlignment="Center" Margin="10" + Text="Text Search Progress" FontSize="20"/> + <ProgressBar x:Name="xaml_Progress" Margin="5" Height="15" + IsIndeterminate="False" Maximum="100" VerticalAlignment="Stretch" /> + <Button HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,10" Click="CancelSearch" Height="39"> + <TextBlock HorizontalAlignment="Center" Text="Cancel"/> + </Button> + </StackPanel> + </Border> + </StackPanel> + </Grid> </Page> diff --git a/winrt/mupdf_cpp/MainPage.xaml.cpp b/winrt/mupdf_cpp/MainPage.xaml.cpp index 76c0ecf3..5b8dfeab 100644 --- a/winrt/mupdf_cpp/MainPage.xaml.cpp +++ b/winrt/mupdf_cpp/MainPage.xaml.cpp @@ -6,24 +6,21 @@ #include "pch.h" #include "MainPage.xaml.h" -#define LOOK_AHEAD 1 /* A +/- count on the pages to pre-render */ +#define LOOK_AHEAD 0 /* A +/- count on the pages to pre-render */ #define THUMB_PREADD 10 #define MIN_SCALE 0.5 -#define MAX_SCALE 4 -#define MARGIN_BUFF 400 -#define MAX_SEARCH 500 + #define SCALE_THUMB 0.1 #define BLANK_WIDTH 17 #define BLANK_HEIGHT 22 -static float screenScale = 1; +#define KEY_PLUS 0xbb +#define KEY_MINUS 0xbd -int linkPage[MAX_SEARCH]; -char *linkUrl[MAX_SEARCH]; +static float screenScale = 1; using namespace mupdf_cpp; - using namespace Windows::Foundation; using namespace Windows::UI::Xaml; using namespace Windows::UI::Xaml::Controls; @@ -405,6 +402,7 @@ void mupdf_cpp::MainPage::CleanUp() m_ren_status = REN_AVAILABLE; m_links_on = false; m_rectlist_page = -1; + m_Progress = 0.0; this->xaml_PageSlider->Minimum = m_slider_min; this->xaml_PageSlider->Maximum = m_slider_max; @@ -433,7 +431,7 @@ void mupdf_cpp::MainPage::RenderThumbs() Point ras_size = ComputePageSize(spatial_info_local, k); bool done = false; DWORD thread1_id = GetCurrentThreadId(); - auto task2 = create_task(mu_doc->RenderPage(k, ras_size.X, ras_size.Y)); + auto task2 = create_task(mu_doc->RenderPageAsync(k, ras_size.X, ras_size.Y)); task2.then([this, k, thumbnails, ras_size](InMemoryRandomAccessStream^ ras) { @@ -492,6 +490,7 @@ void mupdf_cpp::MainPage::RenderThumbs() } this->m_ren_status = REN_AVAILABLE; }, task_continuation_context::use_current()); + } void mupdf_cpp::MainPage::OpenDocumentPrep(StorageFile^ file) @@ -544,13 +543,14 @@ void mupdf_cpp::MainPage::OpenDocument(StorageFile^ file) this->SetFlipView(); /* Open document and when open, push on */ - auto open_task = create_task(mu_doc->OpenFile(file)); + auto open_task = create_task(mu_doc->OpenFileAsync(file)); open_task.then([this] { assert(IsMainThread()); m_num_pages = mu_doc->GetNumPages(); + if ((m_currpage) >= m_num_pages) { m_currpage = m_num_pages - 1; @@ -559,7 +559,6 @@ void mupdf_cpp::MainPage::OpenDocument(StorageFile^ file) { m_currpage = 0; } - /* Initialize all the flipvew items with blanks and the thumbnails. */ for (int k = 0; k < m_num_pages; k++) { @@ -592,7 +591,7 @@ void mupdf_cpp::MainPage::OpenDocument(StorageFile^ file) Point ras_size = ComputePageSize(spatial_info, k); auto render_task = - create_task(mu_doc->RenderPage(k, ras_size.X, ras_size.Y)); + create_task(mu_doc->RenderPageAsync(k, ras_size.X, ras_size.Y)); render_task.then([this, k, ras_size] (InMemoryRandomAccessStream^ ras) { @@ -641,7 +640,7 @@ void mupdf_cpp::MainPage::RenderRange(int curr_page) { Point ras_size = ComputePageSize(spatial_info, k); auto render_task = - create_task(mu_doc->RenderPage(k, ras_size.X, ras_size.Y)); + create_task(mu_doc->RenderPageAsync(k, ras_size.X, ras_size.Y)); render_task.then([this, k, ras_size] (InMemoryRandomAccessStream^ ras) { @@ -699,7 +698,7 @@ void mupdf_cpp::MainPage::Slider_ValueChanged(Platform::Object^ sender, Windows: spatial_info_t spatial_info = InitSpatial(1); Point ras_size = ComputePageSize(spatial_info, newValue); auto render_task = - create_task(mu_doc->RenderPage(newValue, ras_size.X, ras_size.Y)); + create_task(mu_doc->RenderPageAsync(newValue, ras_size.X, ras_size.Y)); render_task.then([this, newValue, ras_size] (InMemoryRandomAccessStream^ ras) { @@ -793,10 +792,10 @@ void mupdf_cpp::MainPage::ClearTextSearch() m_text_list->Clear(); } -void mupdf_cpp::MainPage::ShowSearchResults(SearchResult_t result) +void mupdf_cpp::MainPage::ShowSearchResults(int page_num, int box_count) { int old_page = this->m_currpage; - int new_page = result.page_num; + int new_page = page_num; ClearTextSearch(); @@ -814,7 +813,7 @@ void mupdf_cpp::MainPage::ShowSearchResults(SearchResult_t result) auto doc_page = this->m_docPages->GetAt(old_page); /* Construct our list of rectangles */ - for (int k = 0; k < result.box_count; k++) + for (int k = 0; k < box_count; k++) { RectList^ rect_item = ref new RectList(); auto curr_box = mu_doc->GetTextSearch(k); @@ -869,7 +868,9 @@ void mupdf_cpp::MainPage::SearchPrev(Platform::Object^ sender, Windows::UI::Xaml void mupdf_cpp::MainPage::CancelSearch(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) { - m_searchcts.cancel(); + m_searchcts.cancel(); + xaml_ProgressStack->Visibility = Windows::UI::Xaml::Visibility::Collapsed; + this->m_search_active = false; } void mupdf_cpp::MainPage::AddTextCanvas() @@ -884,6 +885,11 @@ void mupdf_cpp::MainPage::AddTextCanvas() this->m_search_active = false; } +void mupdf_cpp::MainPage::SearchProgress(IAsyncOperationWithProgress<int, double>^ operation, double status) +{ + xaml_Progress->Value = status; +} + void mupdf_cpp::MainPage::SearchInDirection(int dir, String^ textToFind) { cancellation_token_source cts; @@ -891,55 +897,43 @@ void mupdf_cpp::MainPage::SearchInDirection(int dir, String^ textToFind) m_searchcts = cts; int pos = m_currpage; int start; - SearchResult_t result; - - result.box_count = 0; - result.page_num = -1; if (m_searchpage == pos) start = pos + dir; else start = pos; - /* ProgressBar^ my_xaml_Progress = (ProgressBar^) (this->FindName("xaml_Progress")); - my_xaml_Progress->Value = start; - my_xaml_Progress->IsEnabled = true; - my_xaml_Progress->Opacity = 1.0; */ - if (start < 0) return; if (start > this->m_num_pages - 1) return; this->m_search_active = true; - /* Do task lambdas here to avoid UI blocking issues */ - auto search_task = create_task([this, textToFind, dir, start, &result]()->SearchResult_t - { - for (int i = start; i >= 0 && i < this->m_num_pages; i += dir) - { - result.box_count = this->mu_doc->ComputeTextSearch(textToFind, i); - result.page_num = i; + ProgressBar^ my_xaml_Progress = (ProgressBar^) (this->FindName("xaml_Progress")); + xaml_ProgressStack->Visibility = Windows::UI::Xaml::Visibility::Visible; + auto temp = mu_doc->SearchDocumentWithProgressAsync(textToFind, dir, start); + temp->Progress = ref new AsyncOperationProgressHandler<int, double>(this, &MainPage::SearchProgress); - // my_xaml_Progress->Value = i; + auto search_task = create_task(temp, token); - if (result.box_count > 0) - { - return result; - } - if (is_task_cancellation_requested()) - { - } - } - /* Todo no matches found alert */ - return result; - }, token); /* Do the continuation on the ui thread */ - search_task.then([this](task<SearchResult_t> the_task) + auto con_task = search_task.then([this, textToFind](int page_num) { - SearchResult_t the_result = the_task.get(); - if (the_result.box_count > 0) + xaml_ProgressStack->Visibility = Windows::UI::Xaml::Visibility::Collapsed; + if (page_num == TEXT_NOT_FOUND) { - this->ShowSearchResults(the_result); + auto str1 = "\"" + textToFind + "\" Was Not Found In The Search"; + NotifyUser(str1, StatusMessage); + this->m_search_active = false; + } + else + { + int box_count = mu_doc->TextSearchCount(); + + if (box_count > 0) + { + this->ShowSearchResults(page_num, box_count); + } } }, task_continuation_context::use_current()); } @@ -1140,16 +1134,16 @@ void mupdf_cpp::MainPage::LinkTapped(Platform::Object^ sender, Windows::UI::Xaml // Launch the URI with a warning prompt concurrency::task<bool> launchUriOperation(Windows::System::Launcher::LaunchUriAsync(link->Urilink, launchOptions)); launchUriOperation.then([](bool success) - { - if (success) - { - // URI launched - } - else - { - // URI launch failed - } - }); + { + if (success) + { + // URI launched + } + else + { + // URI launch failed + } + }); } } } @@ -1257,6 +1251,7 @@ void mupdf_cpp::MainPage::UpdateAppBarButtonViewState() VisualStateManager::GoToState(Help, viewState, true); } +/* Manipulation zooming with touch input */ void mupdf_cpp::MainPage::ScrollChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::ScrollViewerViewChangedEventArgs^ e) { @@ -1275,7 +1270,7 @@ void mupdf_cpp::MainPage::ScrollChanged(Platform::Object^ sender, Point ras_size = ComputePageSize(spatial_info, page); auto render_task = - create_task(mu_doc->RenderPage(page, ras_size.X, ras_size.Y)); + create_task(mu_doc->RenderPageAsync(page, ras_size.X, ras_size.Y)); render_task.then([this, page, ras_size] (InMemoryRandomAccessStream^ ras) { @@ -1283,3 +1278,39 @@ void mupdf_cpp::MainPage::ScrollChanged(Platform::Object^ sender, }, task_continuation_context::use_current()); } } + +/* Zoom in and out for keyboard only case */ +void MainPage::OnKeyDown(KeyRoutedEventArgs^ e) +{ + return; /* Waiting until I can get zoom factor in scroll viewer. */ + + auto doc_page = this->m_docPages->GetAt(m_currpage); + double curr_zoom = doc_page->Zoom; + + long val = (long) (e->Key); + if (val == KEY_PLUS) + { + curr_zoom = curr_zoom + 0.25; + if (curr_zoom > 4) curr_zoom = 4; + } + else if (val == KEY_MINUS) + { + curr_zoom = curr_zoom - 0.25; + if (curr_zoom < 0.25) curr_zoom = 0.25; + } else + return; + + doc_page->Zoom = curr_zoom; + int page = m_currpage; + /* Render at new resolution */ + spatial_info_t spatial_info = InitSpatial(doc_page->Zoom); + Point ras_size = ComputePageSize(spatial_info, page); + + auto render_task = + create_task(mu_doc->RenderPageAsync(page, ras_size.X, ras_size.Y)); + + render_task.then([this, page, ras_size] (InMemoryRandomAccessStream^ ras) + { + ReplaceImage(page, ras, ras_size); + }, task_continuation_context::use_current()); +} diff --git a/winrt/mupdf_cpp/MainPage.xaml.h b/winrt/mupdf_cpp/MainPage.xaml.h index 869297f4..f6cdb218 100644 --- a/winrt/mupdf_cpp/MainPage.xaml.h +++ b/winrt/mupdf_cpp/MainPage.xaml.h @@ -44,12 +44,6 @@ typedef enum { REN_PAGE /* Used to ignore value when source based setting */ } RenderingStatus_t; -typedef struct SearchResult_s -{ - int box_count; - int page_num; -} SearchResult_t; - typedef struct spatial_info_s { Point size; @@ -68,6 +62,7 @@ namespace mupdf_cpp protected: virtual void OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override; + virtual void OnKeyDown(Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e) override; /* added */ private: @@ -102,6 +97,7 @@ namespace mupdf_cpp bool m_search_active; /* Used to avoid multiple UI clicks */ bool m_sliderchange; bool m_update_flip; + double m_Progress; void ReplaceImage(int page_num, InMemoryRandomAccessStream^ ras, Point ras_size); void Picker(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); @@ -122,7 +118,7 @@ namespace mupdf_cpp void SearchPrev(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); void CancelSearch(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); void SearchInDirection(int dir, String^ textToFind); - void ShowSearchResults(SearchResult_t result); + void ShowSearchResults(int page_num, int box_count); void ClearTextSearch(); void AddTextCanvas(); void GridSizeChanged(); @@ -151,5 +147,6 @@ namespace mupdf_cpp Point ComputePageSize(spatial_info_t spatial_info, int page_num); 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); }; } |