diff options
Diffstat (limited to 'winrt/mupdf_cpp')
-rw-r--r-- | winrt/mupdf_cpp/MainPage.xaml | 22 | ||||
-rw-r--r-- | winrt/mupdf_cpp/MainPage.xaml.cpp | 111 | ||||
-rw-r--r-- | winrt/mupdf_cpp/MainPage.xaml.h | 6 | ||||
-rw-r--r-- | winrt/mupdf_cpp/mupdf_cpp.vcxproj | 4 | ||||
-rw-r--r-- | winrt/mupdf_cpp/mupdf_cpp.vcxproj.filters | 4 |
5 files changed, 91 insertions, 56 deletions
diff --git a/winrt/mupdf_cpp/MainPage.xaml b/winrt/mupdf_cpp/MainPage.xaml index 3c59d615..aa4502f0 100644 --- a/winrt/mupdf_cpp/MainPage.xaml +++ b/winrt/mupdf_cpp/MainPage.xaml @@ -33,7 +33,6 @@ <Button x:Name="Contents" Style="{StaticResource ContentsBarButtonStyle}" Tag="Contents" Click="ContentDisplay"/> <Button x:Name="Links" Style="{StaticResource LinksAppBarButtonStyle}" Tag="Links" Click="Linker"/> <Button x:Name="Reflow" Style="{StaticResource ReflowAppBarButtonStyle}" Tag="Reflow" Click="Reflower"/> - <Button x:Name="Help" Style="{StaticResource HelpAppBarButtonStyle}" Tag="Help"/> </StackPanel> </Grid> </AppBar> @@ -72,6 +71,7 @@ <FlipView.ItemTemplate> <DataTemplate> <ScrollViewer + Name="xaml_ScrollView_h" ZoomMode="Enabled" ViewChanged="ScrollChanged" HorizontalScrollMode="Auto" @@ -150,6 +150,7 @@ <FlipView.ItemTemplate> <DataTemplate> <ScrollViewer + Name="xaml_ScrollView_v" ZoomMode="Enabled" ViewChanged="ScrollChanged" HorizontalScrollMode="Auto" @@ -239,9 +240,9 @@ 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" > + <StackPanel x:Name="xaml_ProgressStack" Opacity="1" VerticalAlignment="Center" Margin="0,15" HorizontalAlignment="Center" Visibility="Collapsed"> + <Border BorderThickness="5" BorderBrush="Black" > + <StackPanel Background="LightGray" HorizontalAlignment="Left" Width="756" > <TextBlock HorizontalAlignment="Center" Margin="10" Text="Text Search Progress" FontSize="20"/> <ProgressBar x:Name="xaml_Progress" Margin="5" Height="15" @@ -253,24 +254,17 @@ </Border> </StackPanel> - <StackPanel x:Name="xaml_PasswordStack" Opacity="1" VerticalAlignment="Center" Visibility="Collapsed"> - <Border BorderThickness="5" BorderBrush="Black" Margin="300"> + <StackPanel x:Name="xaml_PasswordStack" Opacity="1" VerticalAlignment="Center" HorizontalAlignment="Center" Visibility="Collapsed"> + <Border BorderThickness="5" BorderBrush="Black" > <StackPanel Background="LightGray" > <TextBlock HorizontalAlignment="Center" Margin="10" Text="Password Required" FontSize="20"/> - <PasswordBox x:Name="xaml_password" Height="35" Width="300"/> + <PasswordBox x:Name="xaml_password" Height="35" Width="400" Margin="20"/> <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 86d06f49..e7141a40 100644 --- a/winrt/mupdf_cpp/MainPage.xaml.cpp +++ b/winrt/mupdf_cpp/MainPage.xaml.cpp @@ -15,6 +15,10 @@ #define BLANK_WIDTH 17 #define BLANK_HEIGHT 22 +#define KEYBOARD_ZOOM_STEP 0.25 +#define ZOOM_MAX 4 +#define ZOOM_MIN 0.25 + #define KEY_PLUS 0xbb #define KEY_MINUS 0xbd @@ -71,6 +75,8 @@ extern "C" { MainPage::MainPage() { InitializeComponent(); + Application::Current->Suspending += + ref new SuspendingEventHandler(this, &MainPage::App_Suspending); m_textcolor="#402572AC"; m_linkcolor="#40AC7225"; mu_doc = nullptr; @@ -93,6 +99,11 @@ void MainPage::OnNavigatedTo(NavigationEventArgs^ e) (void) e; // Unused parameter } +void mupdf_cpp::MainPage::App_Suspending(Object^ sender, SuspendingEventArgs^ e) +{ + +} + void mupdf_cpp::MainPage::ExitInvokedHandler(Windows::UI::Popups::IUICommand^ command) { @@ -479,6 +490,7 @@ void mupdf_cpp::MainPage::RenderThumbs() } catch (const task_canceled& e) { + (void) e; // Unused parameter is_cancelled = true; } if (!is_cancelled) @@ -877,7 +889,7 @@ void mupdf_cpp::MainPage::SearchNext(Platform::Object^ sender, Windows::UI::Xaml TextBox^ findBox = (TextBox^) leftPanel->FindName("findBox"); String^ textToFind = findBox->Text; - if (this->m_search_active == false) + if (this->m_search_active == false && textToFind != nullptr) SearchInDirection(1, textToFind); } @@ -887,7 +899,7 @@ void mupdf_cpp::MainPage::SearchPrev(Platform::Object^ sender, Windows::UI::Xaml TextBox^ findBox = (TextBox^) leftPanel->FindName("findBox"); String^ textToFind = findBox->Text; - if (this->m_search_active == false) + if (this->m_search_active == false && textToFind != nullptr) SearchInDirection(-1, textToFind); } @@ -978,27 +990,24 @@ void mupdf_cpp::MainPage::GridSizeChanged() if (height > width) { m_curr_flipView = this->xaml_vert_flipView; - if (!m_zoom_mode) - { - this->xaml_zoomCanvas->Height = height; - this->xaml_zoomCanvas->Width = width; - this->m_curr_flipView->Height = height; - this->m_curr_flipView->Width = width; - } + this->xaml_zoomCanvas->Height = height; + this->xaml_zoomCanvas->Width = width; + this->m_curr_flipView->Height = height; + this->m_curr_flipView->Width = width; + xaml_vert_flipView->IsEnabled = true; xaml_vert_flipView->Opacity = 1; xaml_horiz_flipView->IsEnabled = false; - xaml_horiz_flipView->Opacity = 0; } + xaml_horiz_flipView->Opacity = 0; + } else { m_curr_flipView = this->xaml_horiz_flipView; - if (!m_zoom_mode) - { - this->xaml_zoomCanvas->Height = height; - this->xaml_zoomCanvas->Width = width; - this->m_curr_flipView->Height = height; - this->m_curr_flipView->Width = width; - } + this->xaml_zoomCanvas->Height = height; + this->xaml_zoomCanvas->Width = width; + this->m_curr_flipView->Height = height; + this->m_curr_flipView->Width = width; + xaml_horiz_flipView->IsEnabled = true; xaml_horiz_flipView->Opacity = 1; xaml_vert_flipView->IsEnabled = false; @@ -1285,7 +1294,6 @@ void mupdf_cpp::MainPage::UpdateAppBarButtonViewState() VisualStateManager::GoToState(Contents, viewState, true); VisualStateManager::GoToState(Links, viewState, true); VisualStateManager::GoToState(Reflow, viewState, true); - VisualStateManager::GoToState(Help, viewState, true); } /* Manipulation zooming with touch input */ @@ -1316,40 +1324,65 @@ void mupdf_cpp::MainPage::ScrollChanged(Platform::Object^ sender, } } -/* Zoom in and out for keyboard only case */ +/* Needed to find scrollviewer child from template of flipview item */ +Windows::UI::Xaml::FrameworkElement^ FindVisualChildByName(DependencyObject^ obj, String^ name) +{ + FrameworkElement^ ret; + int numChildren = VisualTreeHelper::GetChildrenCount(obj); + + for (int i = 0; i < numChildren; i++) + { + auto objChild = VisualTreeHelper::GetChild(obj, i); + auto child = safe_cast<FrameworkElement^>(objChild); + if (child != nullptr && child->Name == name) + { + return child; + } + ret = FindVisualChildByName(objChild, name); + if (ret != nullptr) + break; + } + return ret; +} + +/* Zoom in and out for keyboard only case. */ void MainPage::OnKeyDown(KeyRoutedEventArgs^ e) { - return; /* Waiting until I can get zoom factor in scroll viewer. */ + ScrollViewer^ scrollviewer; + FlipViewItem^ item = safe_cast<FlipViewItem^> + (m_curr_flipView->ItemContainerGenerator->ContainerFromIndex(m_currpage)); + auto item2 = m_curr_flipView->ItemContainerGenerator->ContainerFromIndex(m_currpage); + + /* We don't know which one so check for both */ + ScrollViewer^ t1 = + safe_cast<ScrollViewer^> (FindVisualChildByName(item2, "xaml_ScrollView_v")); + ScrollViewer^ t2 = + safe_cast<ScrollViewer^> (FindVisualChildByName(item2, "xaml_ScrollView_h")); + + if (t1 != nullptr) + scrollviewer = t1; + else + scrollviewer = t2; - auto doc_page = this->m_docPages->GetAt(m_currpage); - double curr_zoom = doc_page->Zoom; + if (scrollviewer == nullptr) + return; + + double curr_zoom = scrollviewer->ZoomFactor; long val = (long) (e->Key); if (val == KEY_PLUS) { - curr_zoom = curr_zoom + 0.25; - if (curr_zoom > 4) curr_zoom = 4; + curr_zoom = curr_zoom + KEYBOARD_ZOOM_STEP; + if (curr_zoom > ZOOM_MAX) curr_zoom = ZOOM_MAX; } else if (val == KEY_MINUS) { - curr_zoom = curr_zoom - 0.25; - if (curr_zoom < 0.25) curr_zoom = 0.25; + curr_zoom = curr_zoom - KEYBOARD_ZOOM_STEP; + if (curr_zoom < ZOOM_MIN) curr_zoom = ZOOM_MIN; } 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()); + scrollviewer->ZoomToFactor(curr_zoom); } void mupdf_cpp::MainPage::PasswordOK(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) diff --git a/winrt/mupdf_cpp/MainPage.xaml.h b/winrt/mupdf_cpp/MainPage.xaml.h index 162e0985..bcc590d4 100644 --- a/winrt/mupdf_cpp/MainPage.xaml.h +++ b/winrt/mupdf_cpp/MainPage.xaml.h @@ -29,6 +29,7 @@ using namespace Platform::Collections; using namespace Windows::UI::ViewManagement; using namespace Windows::UI::Popups; using namespace Windows::UI::Xaml::Navigation; +using namespace Windows::ApplicationModel; using namespace mupdfwinrt; typedef enum @@ -64,7 +65,6 @@ namespace mupdf_cpp virtual void OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override; virtual void OnKeyDown(Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e) override; - /* added */ private: Vector<DocumentPage^>^ m_docPages; Vector<DocumentPage^>^ m_thumbnails; @@ -92,8 +92,7 @@ namespace mupdf_cpp FlipView^ m_curr_flipView; RenderingStatus_t m_ren_status; cancellation_token_source m_ThumbCancel; - bool m_zoom_mode; // remove - bool m_insearch; /* Used for UI display */ + bool m_insearch; /* Used for UI display */ bool m_search_active; /* Used to avoid multiple UI clicks */ bool m_sliderchange; bool m_update_flip; @@ -152,5 +151,6 @@ namespace mupdf_cpp 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); + void App_Suspending(Object^ sender, SuspendingEventArgs^ e); }; } diff --git a/winrt/mupdf_cpp/mupdf_cpp.vcxproj b/winrt/mupdf_cpp/mupdf_cpp.vcxproj index 25964a7f..9e5c92be 100644 --- a/winrt/mupdf_cpp/mupdf_cpp.vcxproj +++ b/winrt/mupdf_cpp/mupdf_cpp.vcxproj @@ -152,6 +152,7 @@ <DependentUpon>MainPage.xaml</DependentUpon> </ClInclude> <ClInclude Include="RectList.h" /> + <ClInclude Include="resource.h" /> </ItemGroup> <ItemGroup> <ApplicationDefinition Include="App.xaml"> @@ -194,6 +195,9 @@ <Image Include="Assets\mupdf_splash.png" /> <Image Include="Assets\mupdf_storelogo.png" /> </ItemGroup> + <ItemGroup> + <ResourceCompile Include="mupdf_cpp.rc" /> + </ItemGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> </ImportGroup> diff --git a/winrt/mupdf_cpp/mupdf_cpp.vcxproj.filters b/winrt/mupdf_cpp/mupdf_cpp.vcxproj.filters index 8b87ed11..2d4effa1 100644 --- a/winrt/mupdf_cpp/mupdf_cpp.vcxproj.filters +++ b/winrt/mupdf_cpp/mupdf_cpp.vcxproj.filters @@ -27,6 +27,7 @@ <ClInclude Include="MainPage.xaml.h" /> <ClInclude Include="DocumentPage.h" /> <ClInclude Include="RectList.h" /> + <ClInclude Include="resource.h" /> </ItemGroup> <ItemGroup> <AppxManifest Include="Package.appxmanifest" /> @@ -51,4 +52,7 @@ <Filter>Assets</Filter> </Image> </ItemGroup> + <ItemGroup> + <ResourceCompile Include="mupdf_cpp.rc" /> + </ItemGroup> </Project>
\ No newline at end of file |