diff options
author | Michael Vrhel <michael.vrhel@artifex.com> | 2013-05-08 16:59:01 -0700 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2013-05-16 19:25:53 +0100 |
commit | 165a3528f5a48ba9c4f30d18330875b6070ddf96 (patch) | |
tree | 1abceb81e34769b2523701622d24923d7350fd9b /winrt | |
parent | 3824bf32f8595c2f037db14e133b798bfae65027 (diff) | |
download | mupdf-165a3528f5a48ba9c4f30d18330875b6070ddf96.tar.xz |
Support for going to the links.
Used tag attribute in rectangle object to store the index value into the collection of rectangles
to get back the page number or uri.
Diffstat (limited to 'winrt')
-rw-r--r-- | winrt/mupdf_cpp/MainPage.xaml | 6 | ||||
-rw-r--r-- | winrt/mupdf_cpp/MainPage.xaml.cpp | 106 | ||||
-rw-r--r-- | winrt/mupdf_cpp/MainPage.xaml.h | 5 | ||||
-rw-r--r-- | winrt/mupdf_cpp/RectList.h | 26 |
4 files changed, 58 insertions, 85 deletions
diff --git a/winrt/mupdf_cpp/MainPage.xaml b/winrt/mupdf_cpp/MainPage.xaml index 770d8bd3..23413db9 100644 --- a/winrt/mupdf_cpp/MainPage.xaml +++ b/winrt/mupdf_cpp/MainPage.xaml @@ -104,7 +104,7 @@ </ItemsControl.ItemContainerStyle> <ItemsControl.ItemTemplate> <DataTemplate> - <Rectangle Width="{Binding Path=Width}" Height="{Binding Path=Height}" Fill="{Binding Path=Color}"> + <Rectangle Name="{Binding Index}" Width="{Binding Path=Width}" Height="{Binding Path=Height}" Fill="{Binding Path=Color}"> <Rectangle.RenderTransform> <TranslateTransform X="{Binding Path=X}" Y="{Binding Path=Y}"/> </Rectangle.RenderTransform> @@ -127,7 +127,7 @@ </ItemsControl.ItemContainerStyle> <ItemsControl.ItemTemplate> <DataTemplate> - <Rectangle Width="{Binding Path=Width}" Height="{Binding Path=Height}" Fill="{Binding Path=Color}"> + <Rectangle Tag="{Binding Path=Index}" Width="{Binding Path=Width}" Height="{Binding Path=Height}" Fill="{Binding Path=Color}" IsTapEnabled="True" Tapped="LinkTapped"> <Rectangle.RenderTransform> <TranslateTransform X="{Binding Path=X}" Y="{Binding Path=Y}"/> </Rectangle.RenderTransform> @@ -179,7 +179,7 @@ </ItemsControl.ItemContainerStyle> <ItemsControl.ItemTemplate> <DataTemplate> - <Rectangle Width="{Binding Path=Width}" Height="{Binding Path=Height}" Fill="{Binding Path=Color}"> + <Rectangle Width="{Binding Path=Width}" Height="{Binding Path=Height}" Fill="{Binding Path=Color}" IsTapEnabled="True" Tapped="LinkTapped"> <Rectangle.RenderTransform> <TranslateTransform X="{Binding Path=X}" Y="{Binding Path=Y}"/> </Rectangle.RenderTransform> diff --git a/winrt/mupdf_cpp/MainPage.xaml.cpp b/winrt/mupdf_cpp/MainPage.xaml.cpp index d8e97586..60350170 100644 --- a/winrt/mupdf_cpp/MainPage.xaml.cpp +++ b/winrt/mupdf_cpp/MainPage.xaml.cpp @@ -656,9 +656,7 @@ void mupdf_cpp::MainPage::RenderRange(int curr_page) } m_currpage = curr_page; if (this->m_links_on) - { AddLinkCanvas(); - } } void mupdf_cpp::MainPage::Slider_ValueChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::Primitives::RangeBaseValueChangedEventArgs^ e) @@ -1134,6 +1132,7 @@ void mupdf_cpp::MainPage::AddLinkCanvas() rect_item->Type = curr_link->Type; rect_item->Urilink = curr_link->Uri; rect_item->PageNum = curr_link->PageNum; + rect_item->Index = k.ToString(); link_list->Append(rect_item); } } @@ -1148,82 +1147,45 @@ void mupdf_cpp::MainPage::AddLinkCanvas() m_page_update = false; } -bool mupdf_cpp::MainPage::CheckRect(Rectangle^ curr_rect, Point pt) -{ - TranslateTransform ^trans_transform = (TranslateTransform^) curr_rect->RenderTransform; - Point rect_start; - Point rect_end; - - rect_start.X = trans_transform->X; - rect_start.Y = trans_transform->Y; - rect_end.X = rect_start.X + curr_rect->Width; - rect_end.Y = rect_start.Y + curr_rect->Height; - if ((rect_start.X < pt.X) && (pt.X < rect_end.X) && (rect_start.Y < pt.Y) && (pt.Y < rect_end.Y)) - return true; - return false; -} - -void mupdf_cpp::MainPage::Canvas_Single_Tap(Platform::Object^ sender, Windows::UI::Xaml::Input::TappedRoutedEventArgs^ e) +/* A link was tapped */ +void mupdf_cpp::MainPage::LinkTapped(Platform::Object^ sender, Windows::UI::Xaml::Input::TappedRoutedEventArgs^ e) { - /* See if we are currently viewing any links */ - if (m_links_on) + Rectangle^ rect = safe_cast<Rectangle^>(e->OriginalSource); + String^ str_index = safe_cast<String^>(rect->Tag); + int index = _wtof(str_index->Data()); + + if (index >= 0 && index < m_num_pages) { - Point pt; - Canvas^ link_canvas = (Canvas^) (m_curr_flipView->FindName("linkCanvas")); - if (link_canvas != nullptr) + auto link_list = m_page_link_list->GetAt(m_currpage); + auto link = link_list->GetAt(index); + + if (link->Type == LINK_GOTO) { - pt = e->GetPosition(link_canvas); - IIterator<UIElement^> ^it = link_canvas->Children->First(); - int count = 0; - while (it->HasCurrent) - { - Rectangle^ curr_rect = (Rectangle^) (it->Current); - if (CheckRect(curr_rect, pt)) - { - int page = JumpToLink(count); - if (page >= 0) - this->m_curr_flipView->SelectedIndex = page; - return; - } - it->MoveNext(); - count += 1; - } + this->m_curr_flipView->SelectedIndex = link->PageNum; + } + else if (link->Type == LINK_URI) + { + // Set the option to show a warning + auto launchOptions = ref new Windows::System::LauncherOptions(); + launchOptions->TreatAsUntrusted = true; + + // 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 + } + }); } } } -int mupdf_cpp::MainPage::JumpToLink(int index) -{ - auto link = mu_doc->GetLink(index); - - if (link->Type == LINK_GOTO) - { - return link->PageNum; - } - else if (link->Type == LINK_URI) - { - // Set the option to show a warning - auto launchOptions = ref new Windows::System::LauncherOptions(); - launchOptions->TreatAsUntrusted = true; - - // Launch the URI with a warning prompt - concurrency::task<bool> launchUriOperation(Windows::System::Launcher::LaunchUriAsync(link->Uri, launchOptions)); - launchUriOperation.then([](bool success) - { - if (success) - { - // URI launched - } - else - { - // URI launch failed - } - }); - return -1; - } - return 0; -} - /* Bring up the contents */ void mupdf_cpp::MainPage::ContentDisplay(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) { @@ -1332,3 +1294,5 @@ void mupdf_cpp::MainPage::ScrollChanged(Platform::Object^ sender, Windows::UI::X int zz = 1; } + + diff --git a/winrt/mupdf_cpp/MainPage.xaml.h b/winrt/mupdf_cpp/MainPage.xaml.h index 9c39534e..2c73b67d 100644 --- a/winrt/mupdf_cpp/MainPage.xaml.h +++ b/winrt/mupdf_cpp/MainPage.xaml.h @@ -135,8 +135,6 @@ namespace mupdf_cpp void ReleasePages(int old_page, int new_page); void Linker(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); void AddLinkCanvas(); - void Canvas_Single_Tap(Platform::Object^ sender, Windows::UI::Xaml::Input::TappedRoutedEventArgs^ e); - bool CheckRect(Rectangle^ curr_rect, Point pt); int JumpToLink(int index); void ContentDisplay(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); void FlattenOutline(fz_outline *outline, int level); @@ -152,5 +150,6 @@ namespace mupdf_cpp void OKInvokedHandler(Windows::UI::Popups::IUICommand^ command); 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); + }; } diff --git a/winrt/mupdf_cpp/RectList.h b/winrt/mupdf_cpp/RectList.h index d138397a..d3f0527f 100644 --- a/winrt/mupdf_cpp/RectList.h +++ b/winrt/mupdf_cpp/RectList.h @@ -21,19 +21,16 @@ namespace mupdf_cpp int type; int pagenum; Windows::Foundation::Uri ^uri; + String^ index; // For identify which rectangle was tapped public: RectList(void); - property int Height + property String^ Index { - int get() { return ((int) height); } - void set(int value) + String^ get() { return ((String^) index); } + void set(String^ value) { - if (value < 0) - { - throw ref new Platform::InvalidArgumentException(); - } - height = value; + index = value; } } @@ -46,6 +43,19 @@ namespace mupdf_cpp } } + property int Height + { + int get() { return ((int) height); } + void set(int value) + { + if (value < 0) + { + throw ref new Platform::InvalidArgumentException(); + } + height = value; + } + } + property int Width { int get() { return width; } |