diff options
author | Michael Vrhel <michael.vrhel@artifex.com> | 2013-03-09 13:41:10 -0800 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2013-05-16 19:25:28 +0100 |
commit | f45abbc602bb908dd09ea0d053ea08dc03928a40 (patch) | |
tree | e4523a9974de6fc43a4841fc3ec6f693c2c9d28a | |
parent | 07a9f2f52e446283c088fc05b5a81b1d7293559d (diff) | |
download | mupdf-f45abbc602bb908dd09ea0d053ea08dc03928a40.tar.xz |
Addition of XPS, fix of rotation, enable slide selector
-rw-r--r-- | winRT/winapp/Common/StandardStyles.xaml | 5 | ||||
-rw-r--r-- | winRT/winapp/MainPage.xaml | 9 | ||||
-rw-r--r-- | winRT/winapp/MainPage.xaml.cpp | 105 | ||||
-rw-r--r-- | winRT/winapp/MainPage.xaml.h | 8 |
4 files changed, 103 insertions, 24 deletions
diff --git a/winRT/winapp/Common/StandardStyles.xaml b/winRT/winapp/Common/StandardStyles.xaml index 71c4e4ba..bab6884f 100644 --- a/winRT/winapp/Common/StandardStyles.xaml +++ b/winRT/winapp/Common/StandardStyles.xaml @@ -435,6 +435,11 @@ <Setter Property="AutomationProperties.Name" Value="No"/> <Setter Property="Content" Value=""/> </Style> + <Style x:Key="SettingsAppBarButtonStyle" TargetType="ButtonBase" BasedOn="{StaticResource AppBarButtonStyle}"> + <Setter Property="AutomationProperties.AutomationId" Value="SettingsAppBarButton"/> + <Setter Property="AutomationProperties.Name" Value="Settings"/> + <Setter Property="Content" Value=""/> + </Style> <!-- diff --git a/winRT/winapp/MainPage.xaml b/winRT/winapp/MainPage.xaml index aedd8c23..cfd2c785 100644 --- a/winRT/winapp/MainPage.xaml +++ b/winRT/winapp/MainPage.xaml @@ -8,12 +8,12 @@ mc:Ignorable="d"> <Page.BottomAppBar> <AppBar> - <Grid> + <Grid Margin="38,0,0,0"> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"/> <ColumnDefinition Width="Auto"/> </Grid.ColumnDefinitions> - <Slider x:Name="xaml_PageSlider" Minimum="0" Maximum="10" ValueChanged="Slider_ValueChanged" Grid.Column="0" Margin="10,0" VerticalAlignment="Center" /> + <Slider x:Name="xaml_PageSlider" Minimum="0" Maximum="10" ValueChanged="Slider_ValueChanged" LostFocus="Slider_Released" Grid.Column="0" Margin="10,0" VerticalAlignment="Center" /> <Button x:Name="Find_File" Style="{StaticResource OpenFileAppBarButtonStyle}" Tag="OpenFile" HorizontalAlignment="Right" Grid.Column="1" Click="Picker"/> </Grid> </AppBar> @@ -63,6 +63,11 @@ ManipulationStarting="Canvas_ManipulationStarting" ManipulationMode="All"> <FlipView x:Name="xaml_flipView" SelectionChanged="FlipView_SelectionChanged" DoubleTapped="FlipView_Double" VerticalAlignment="Center" HorizontalAlignment="Center"> + <FlipView.ItemsPanel> + <ItemsPanelTemplate> + <VirtualizingStackPanel Orientation="Horizontal"/> + </ItemsPanelTemplate> + </FlipView.ItemsPanel> </FlipView> </Canvas> </Grid> diff --git a/winRT/winapp/MainPage.xaml.cpp b/winRT/winapp/MainPage.xaml.cpp index 93a40a04..4a9f8726 100644 --- a/winRT/winapp/MainPage.xaml.cpp +++ b/winRT/winapp/MainPage.xaml.cpp @@ -398,6 +398,7 @@ void winapp::MainPage::CleanUp() m_zoom_handled = false; m_first_time = false; m_insearch = false; + m_sliderchange = false; m_flip_from_search = false; m_num_pages = -1; ResetSearch(); @@ -408,21 +409,26 @@ void winapp::MainPage::CleanUp() this->xaml_PageSlider->Minimum = m_slider_min; this->xaml_PageSlider->Maximum = m_slider_max; - this->xaml_PageSlider->IsEnabled = false; + this->xaml_PageSlider->IsEnabled = false; + } void winapp::MainPage::OpenDocument(StorageFile^ file) { String^ path = file->Path; const wchar_t *w = path->Data(); - int size = wcslen(w); + 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, '.'); if (this->m_num_pages != -1) CleanUp(); this->SetupZoomCanvas(); - create_task(file->OpenAsync(FileAccessMode::Read)).then([this, file](task<IRandomAccessStream^> task) + create_task(file->OpenAsync(FileAccessMode::Read)).then([this, file, ext](task<IRandomAccessStream^> task) { try { @@ -440,7 +446,8 @@ void winapp::MainPage::OpenDocument(StorageFile^ file) str->state = reinterpret_cast <void*> (&win_stream); /* Now lets see if we can render the file */ - m_doc = fz_open_document_with_stream(ctx, "pdf", str); + + m_doc = fz_open_document_with_stream(ctx, ext, str); m_num_pages = m_doc->count_pages(m_doc); /* Set up the search progress bar */ @@ -525,19 +532,40 @@ void winapp::MainPage::RenderRange(int curr_page, int *height, int *width) m_currpage = curr_page; } +void winapp::MainPage::Slider_Released(Platform::Object^ sender, Windows::UI::Xaml::Controls::Primitives::RangeBaseValueChangedEventArgs^ e) +{ + int height, width; + int newValue = (int) this->xaml_PageSlider->Value - 1; /* zero based */ + + this->RenderRange(newValue, &height, &width); + this->m_currpage = newValue; +} + void winapp::MainPage::Slider_ValueChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::Primitives::RangeBaseValueChangedEventArgs^ e) { int newValue = (int) this->xaml_PageSlider->Value - 1; /* zero based */ - return; + if (m_update_flip) + { + m_update_flip = false; + return; + } if (m_init_done && this->xaml_PageSlider->IsEnabled) { + FlipViewItem ^flipview_temp = (FlipViewItem^) xaml_flipView->Items->GetAt(newValue); + if (flipview_temp->Background == this->m_blankPage) + { + int width, height; + fz_page *page = fz_load_page(m_doc, newValue); + this->RenderPage(m_doc, page, &width, &height, 1); + ReplacePage(newValue); + this->m_currpage = newValue; + fz_free_page(m_doc, page); + } + m_sliderchange = true; this->xaml_flipView->SelectedIndex = newValue; - int height, width; - this->RenderRange(newValue, &height, &width); ResetSearch(); } - Windows::UI::Xaml::Input::ManipulationModes temp = xaml_flipView->ManipulationMode; } void winapp::MainPage::FlipView_SelectionChanged(Object^ sender, SelectionChangedEventArgs^ e) @@ -545,6 +573,12 @@ void winapp::MainPage::FlipView_SelectionChanged(Object^ sender, SelectionChange int pos = this->xaml_flipView->SelectedIndex; int height, width; + m_update_flip = true; + if (xaml_PageSlider->IsEnabled) + { + xaml_PageSlider->Value = pos; + } + if (pos >= 0) { if (m_flip_from_search) @@ -552,11 +586,15 @@ void winapp::MainPage::FlipView_SelectionChanged(Object^ sender, SelectionChange m_flip_from_search = false; return; } + else if (m_sliderchange) + { + m_sliderchange = false; + return; + } else { ResetSearch(); } - if (m_init_done) this->RenderRange(pos, &height, &width); } @@ -892,26 +930,51 @@ void winapp::MainPage::SearchInDirection(int dir, String^ textToFind) }, ui); } -/* This is here to handle when we rotate or go into the snapview mode */ +/* This is here to handle when we rotate or go into the snapview mode + ToDo add in data binding to change the scroll direction */ void winapp::MainPage::GridSizeChanged() { + + int height = this->ActualHeight; + int width = this->ActualWidth; + if (DisplayProperties::CurrentOrientation == DisplayOrientations::Portrait || DisplayProperties::CurrentOrientation == DisplayOrientations::PortraitFlipped) { - - int t; - - t = 1; - + if (!m_zoom_mode) + { + this->xaml_zoomCanvas->Height = height; + this->xaml_zoomCanvas->Width = width; + this->xaml_flipView->Height = height; + this->xaml_flipView->Width = width; + } } else { - - int s; - - s = 1; - + if (!m_zoom_mode) + { + this->xaml_zoomCanvas->Height = height; + this->xaml_zoomCanvas->Width = width; + this->xaml_flipView->Height = height; + this->xaml_flipView->Width = width; + } } - + UpDatePageSizes(); } +void winapp::MainPage::UpDatePageSizes() +{ + int width, height; + + /* Render our current pages at the new resolution and mark the rest with the blank */ + if (m_num_pages > 0) + { + for (int i = 0; i < m_num_pages; i++) + { + FlipViewItem ^flipview_temp = (FlipViewItem^) xaml_flipView->Items->GetAt(i); + flipview_temp->Content = nullptr; + flipview_temp->Background = this->m_blankPage; + } + this->RenderRange(this->m_currpage, &height, &width); + } +}; diff --git a/winRT/winapp/MainPage.xaml.h b/winRT/winapp/MainPage.xaml.h index 6c16b09b..d2cec4d2 100644 --- a/winRT/winapp/MainPage.xaml.h +++ b/winRT/winapp/MainPage.xaml.h @@ -11,6 +11,7 @@ #include "muxps.h" #include "mupdf.h" #include "ppl.h" +#include "Binding.h" using namespace Platform; using namespace Concurrency; @@ -22,6 +23,7 @@ using namespace Windows::Foundation; using namespace Windows::UI::Xaml::Controls; using namespace Windows::UI::Xaml::Media; using namespace Windows::UI::Xaml::Input; +using namespace winapp::DataBinding; typedef struct SearchResult_s { @@ -72,10 +74,12 @@ namespace winapp ImageBrush^ m_blankPage; Canvas^ m_renderedCanvas; ImageBrush^ m_zoomedImage; - SolidColorBrush^ m_color_brush; + SolidColorBrush^ m_color_brush; bool m_zoom_mode; bool m_zoom_handled; bool m_insearch; + bool m_sliderchange; + bool m_update_flip; void Picker(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); void Searcher(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); void OpenDocument(StorageFile^ file); @@ -93,6 +97,7 @@ namespace winapp void Prepare_bmp(int width, int height, DataWriter ^dw); void PixToMemStream(fz_pixmap *pix, DataWriter ^dw, Platform::Array<unsigned char> ^arr); void Slider_ValueChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::Primitives::RangeBaseValueChangedEventArgs^ e); + void Slider_Released(Platform::Object^ sender, Windows::UI::Xaml::Controls::Primitives::RangeBaseValueChangedEventArgs^ e); void FlipView_SelectionChanged(Object^ sender, SelectionChangedEventArgs^ e); void FlipView_Double(Object^ sender, DoubleTappedRoutedEventArgs^ e); void Canvas_ManipulationDelta(Object^ sender, ManipulationDeltaRoutedEventArgs^ e); @@ -106,5 +111,6 @@ namespace winapp void SearchInDirection(int dir, String^ textToFind); void ShowSearchResults(SearchResult_t result); void GridSizeChanged(); + void UpDatePageSizes(); }; } |