diff options
Diffstat (limited to 'winrt/winapp/MainPage.xaml.cpp')
-rw-r--r-- | winrt/winapp/MainPage.xaml.cpp | 114 |
1 files changed, 93 insertions, 21 deletions
diff --git a/winrt/winapp/MainPage.xaml.cpp b/winrt/winapp/MainPage.xaml.cpp index e93682f7..a649d1e5 100644 --- a/winrt/winapp/MainPage.xaml.cpp +++ b/winrt/winapp/MainPage.xaml.cpp @@ -105,19 +105,6 @@ MainPage::MainPage() ctx = fz_new_context(NULL, NULL, 128<<20); } -void run_async_non_interactive(std::function<void ()>&& action) -{ - Windows::UI::Core::CoreWindow^ wnd = Windows::ApplicationModel::Core::CoreApplication::MainView->CoreWindow; - assert(wnd != nullptr); - - wnd->Dispatcher->RunAsync( - Windows::UI::Core::CoreDispatcherPriority::Low, - ref new Windows::UI::Core::DispatchedHandler([action]() - { - action(); - })); -} - /// <summary> /// Invoked when this page is about to be displayed in a Frame. /// </summary> @@ -128,9 +115,69 @@ void MainPage::OnNavigatedTo(NavigationEventArgs^ e) (void) e; // Unused parameter } +void winapp::MainPage::ExitInvokedHandler(Windows::UI::Popups::IUICommand^ command) +{ + +} + +void winapp::MainPage::OKInvokedHandler(Windows::UI::Popups::IUICommand^ command) +{ + +} + +void winapp::MainPage::NotifyUser(String^ strMessage, NotifyType_t type) +{ + MessageDialog^ msg = ref new MessageDialog(strMessage); + UICommand^ ExitCommand = nullptr; + UICommand^ OKCommand = nullptr; + + switch (type) + { + case StatusMessage: + OKCommand = ref new UICommand("OK", + ref new UICommandInvokedHandler(this, &winapp::MainPage::OKInvokedHandler)); + msg->Commands->Append(OKCommand); + /// Set the command that will be invoked by default + msg->DefaultCommandIndex = 0; + // Set the command to be invoked when escape is pressed + msg->CancelCommandIndex = 1; + break; + case ErrorMessage: + ExitCommand = ref new UICommand("Exit", + ref new UICommandInvokedHandler(this, &winapp::MainPage::ExitInvokedHandler)); + msg->Commands->Append(ExitCommand); + /// Set the command that will be invoked by default + msg->DefaultCommandIndex = 0; + // Set the command to be invoked when escape is pressed + msg->CancelCommandIndex = 1; + break; + default: + break; + } + // Show the message dialog + msg->ShowAsync(); +} + +bool winapp::MainPage::EnsureUnsnapped() +{ + // FilePicker APIs will not work if the application is in a snapped state. + // If an app wants to show a FilePicker while snapped, it must attempt to unsnap first + + bool unsnapped = (ApplicationView::Value != ApplicationViewState::Snapped || + ApplicationView::TryUnsnap()); + if (!unsnapped) + { + NotifyUser("Cannot unsnap the application", StatusMessage); + } + return unsnapped; +} + void winapp::MainPage::Picker(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) { - FileOpenPicker^ openPicker = ref new FileOpenPicker(); + if (!EnsureUnsnapped()) + return; + + FileOpenPicker^ openPicker = ref new FileOpenPicker(); openPicker->ViewMode = PickerViewMode::List; openPicker->SuggestedStartLocation = PickerLocationId::PicturesLibrary; openPicker->FileTypeFilter->Append(".pdf"); @@ -414,12 +461,8 @@ static void win_close_file(fz_context *ctx, void *state) delete dataReader; } -void PixToMemStream(fz_pixmap *pix, DataWriter ^dw, Platform::Array<unsigned char> ^arr) +void PixToMemStream(DataWriter ^dw, Platform::Array<unsigned char> ^arr) { - unsigned char *samples = fz_pixmap_samples(ctx, pix); - int w = fz_pixmap_width(ctx, pix); - int h = fz_pixmap_height(ctx, pix); - /* Write the data */ dw->WriteBytes(arr); @@ -492,7 +535,7 @@ InMemoryRandomAccessStream^ RenderBitMap(fz_document *doc, fz_page *page, int *w fz_run_page(doc, page, dev, pctm, NULL); fz_free_device(dev); /* Now the data into the memory stream */ - PixToMemStream(pix, dw, bmp_data); + PixToMemStream(dw, bmp_data); /* Return raster stream */ return ras; } @@ -599,7 +642,7 @@ void winapp::MainPage::CleanUp() fz_close_document(m_doc); this->m_curr_flipView = nullptr; - m_currpage = 0; + m_currpage = -1; m_file_open = false; m_doc = NULL; m_slider_min = 0; @@ -1233,6 +1276,12 @@ void winapp::MainPage::Searcher(Platform::Object^ sender, Windows::UI::Xaml::Rou } else if (leftPanel != nullptr && !m_insearch) { + /* Search is not going to work in snapped view for now to simplify UI + in this cramped case. So see if we can get out of snapped mode. */ + + if (!EnsureUnsnapped()) + return; + m_insearch = true; Windows::UI::Xaml::Controls::Button^ PrevButton = ref new Button(); PrevButton->Style = safe_cast<Windows::UI::Xaml::Style^>(App::Current->Resources->Lookup("PreviousAppBarButtonStyle")); @@ -1499,6 +1548,12 @@ void winapp::MainPage::GridSizeChanged() int width = this->ActualWidth; FlipView^ old_flip = m_curr_flipView; + + if (TopAppBar1->IsOpen) + { + UpdateAppBarButtonViewState(); + } + if (m_zoom_mode) { Canvas_Double(nullptr, nullptr); @@ -1969,3 +2024,20 @@ void winapp::MainPage::Reflower(Platform::Object^ sender, Windows::UI::Xaml::Rou }, task_continuation_context::use_current()); } } + +/* Need to handle resizing of app bar to make sure everything fits */ + +void winapp::MainPage::topAppBar_Loaded(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) +{ + UpdateAppBarButtonViewState(); +} + +void winapp::MainPage::UpdateAppBarButtonViewState() +{ + String ^viewState = Windows::UI::ViewManagement::ApplicationView::Value.ToString(); + VisualStateManager::GoToState(Search, viewState, true); + VisualStateManager::GoToState(Contents, viewState, true); + VisualStateManager::GoToState(Links, viewState, true); + VisualStateManager::GoToState(Reflow, viewState, true); + VisualStateManager::GoToState(Help, viewState, true); +}
\ No newline at end of file |