summaryrefslogtreecommitdiff
path: root/winrt
diff options
context:
space:
mode:
authorMichael Vrhel <michael.vrhel@artifex.com>2013-05-31 08:54:44 -0700
committerRobin Watts <robin.watts@artifex.com>2013-06-03 15:23:28 +0100
commit5ab3dae36c45173236f552ef260c58ec41db6945 (patch)
tree9dd73f383e2534e35e99d6beace381b3154ff4f2 /winrt
parent16b8e2856cdfed478039dc29f6a2c6645c14fe69 (diff)
downloadmupdf-5ab3dae36c45173236f552ef260c58ec41db6945.tar.xz
Added support for keyboard zooming (+/- key). Fixed issues when orientation changes.
Also minor fixes for memory leaks in muctx.cpp, and clean up of some of the xaml code.
Diffstat (limited to 'winrt')
-rw-r--r--winrt/mupdf_cpp/MainPage.xaml22
-rw-r--r--winrt/mupdf_cpp/MainPage.xaml.cpp111
-rw-r--r--winrt/mupdf_cpp/MainPage.xaml.h6
-rw-r--r--winrt/mupdf_cpp/mupdf_cpp.vcxproj4
-rw-r--r--winrt/mupdf_cpp/mupdf_cpp.vcxproj.filters4
-rw-r--r--winrt/mupdfwinrt/muctx.cpp46
-rw-r--r--winrt/mupdfwinrt/muctx.h1
7 files changed, 104 insertions, 90 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
diff --git a/winrt/mupdfwinrt/muctx.cpp b/winrt/mupdfwinrt/muctx.cpp
index ec088708..17a62535 100644
--- a/winrt/mupdfwinrt/muctx.cpp
+++ b/winrt/mupdfwinrt/muctx.cpp
@@ -24,11 +24,10 @@ static int win_read_file(fz_stream *stm, unsigned char *buf, int len)
DataReader^ local_reader = ref new DataReader(Stream);
DataReaderLoadOperation^ result = local_reader->LoadAsync(len);
- /* Block on the Async call */
+ /* Block on the Async call. This is not on the UI thread. */
while(result->Status != AsyncStatus::Completed) {
}
-
result->GetResults();
int curr_len2 = local_reader->UnconsumedBufferLength;
if (curr_len2 < len)
@@ -93,7 +92,6 @@ static void unlock_mutex(void *user, int lock)
void muctx::CleanUp(void)
{
- free(this->mu_cookie);
if (mu_outline != NULL)
fz_free_outline(mu_ctx, mu_outline);
if (mu_doc != NULL)
@@ -101,7 +99,6 @@ void muctx::CleanUp(void)
if (mu_ctx != NULL)
fz_free_context(mu_ctx);
- this->mu_cookie = NULL;
this->mu_ctx = NULL;
this->mu_doc = NULL;
this->mu_outline = NULL;
@@ -128,21 +125,13 @@ HRESULT muctx::InitializeContext()
}
else
{
- /* If we are fine, allocate the cookie for progress etc. */
- this->mu_cookie = (fz_cookie*)malloc(sizeof(fz_cookie));
- if (this->mu_cookie == NULL) {
- fz_free_context(this->mu_ctx);
- return E_OUTOFMEMORY;
- }
- else
- return S_OK;
+ return S_OK;
}
}
/* Initializer */
muctx::muctx(void)
{
- this->mu_cookie = NULL;
this->mu_ctx = NULL;
this->mu_doc = NULL;
this->mu_outline = NULL;
@@ -152,7 +141,6 @@ muctx::muctx(void)
/* Destructor */
muctx::~muctx(void)
{
- free(this->mu_cookie);
if (mu_outline != NULL)
fz_free_outline(mu_ctx, mu_outline);
if (mu_doc != NULL)
@@ -160,7 +148,6 @@ muctx::~muctx(void)
if (mu_ctx != NULL)
fz_free_context(mu_ctx);
- this->mu_cookie = NULL;
this->mu_ctx = NULL;
this->mu_doc = NULL;
this->mu_outline = NULL;
@@ -262,9 +249,6 @@ int muctx::GetContents(sh_vector_content contents_vec)
fz_context *ctx_clone = NULL;
int has_content = 0;
- if (mu_cookie->abort == 1)
- return has_content;
-
ctx_clone = fz_clone_context(mu_ctx);
fz_var(root);
@@ -303,9 +287,6 @@ int muctx::GetTextSearch(int page_num, char* needle, sh_vector_text texts_vec)
int hit_count = 0;
int k;
- if (mu_cookie->abort == 1)
- return hit_count;
-
ctx_clone = fz_clone_context(mu_ctx);
fz_var(page);
@@ -315,7 +296,7 @@ int muctx::GetTextSearch(int page_num, char* needle, sh_vector_text texts_vec)
{
page = fz_load_page(mu_doc, page_num);
sheet = fz_new_text_sheet(ctx_clone);
- text = fz_new_text_page(ctx_clone, &fz_empty_rect); // Free?
+ text = fz_new_text_page(ctx_clone, &fz_empty_rect);
dev = fz_new_text_device(ctx_clone, sheet, text);
fz_run_page(mu_doc, page, dev, &fz_identity, NULL);
fz_free_device(dev); /* Why does this need to be done here? Seems odd */
@@ -369,9 +350,6 @@ int muctx::GetLinks(int page_num, sh_vector_link links_vec)
int k = 0;
int num_links = 0;
- if (mu_cookie->abort == 1)
- return num_links;
-
ctx_clone = fz_clone_context(mu_ctx);
fz_var(page);
@@ -454,9 +432,6 @@ HRESULT muctx::RenderPage(int page_num, int width, int height,
Point page_size;
fz_context *ctx_clone = NULL;
- if (mu_cookie->abort == 1)
- return S_OK;
-
ctx_clone = fz_clone_context(mu_ctx);
fz_var(dev);
@@ -523,16 +498,13 @@ String^ muctx::GetHTML(int page_num)
fz_buffer *buf = NULL;
String^ html;
- if (mu_cookie->abort == 1)
- return nullptr;
-
ctx_clone = fz_clone_context(mu_ctx);
fz_var(dev);
fz_var(page);
fz_var(sheet);
- fz_var(text); // Free?
- fz_var(buf); // Free?
+ fz_var(text);
+ fz_var(buf);
fz_try(ctx_clone)
{
page = fz_load_page(mu_doc, page_num);
@@ -562,6 +534,14 @@ String^ muctx::GetHTML(int page_num)
{
fz_free_text_sheet(ctx_clone, sheet);
}
+ if (text != NULL)
+ {
+ fz_free_text_page(ctx_clone, text);
+ }
+ if (buf != NULL)
+ {
+ fz_drop_buffer(ctx_clone, buf);
+ }
}
fz_catch(ctx_clone)
{
diff --git a/winrt/mupdfwinrt/muctx.h b/winrt/mupdfwinrt/muctx.h
index d1053275..2175884a 100644
--- a/winrt/mupdfwinrt/muctx.h
+++ b/winrt/mupdfwinrt/muctx.h
@@ -76,7 +76,6 @@ private:
fz_document *mu_doc;
fz_outline *mu_outline;
fz_rect mu_hit_bbox[MAX_SEARCH];
- fz_cookie *mu_cookie;
fz_stream *mu_stream;
void FlattenOutline(fz_outline *outline, int level,
sh_vector_content contents_vec);