diff options
author | Caolán McNamara <caolanm@redhat.com> | 2019-03-26 13:05:17 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2019-03-26 16:03:38 +0100 |
commit | 8a109230486166b36c1a097b838c9d0a1d2af1c3 (patch) | |
tree | 02da7a049d23a2e3e0abf9c35271a895dba62a4f /vcl | |
parent | 830345be2d96d8f699e8cbf33646721fa8c65baf (diff) |
weld PrintProgressDialog
Change-Id: Icb37642bf3ef0ddd1b31d25b80564cdcbb86e653
Reviewed-on: https://gerrit.libreoffice.org/69743
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/inc/printdlg.hxx | 15 | ||||
-rw-r--r-- | vcl/source/gdi/print3.cxx | 45 | ||||
-rw-r--r-- | vcl/source/window/printdlg.cxx | 42 |
3 files changed, 52 insertions, 50 deletions
diff --git a/vcl/inc/printdlg.hxx b/vcl/inc/printdlg.hxx index 05985ecdc309..e3ea1cdba505 100644 --- a/vcl/inc/printdlg.hxx +++ b/vcl/inc/printdlg.hxx @@ -250,23 +250,22 @@ namespace vcl }; - class PrintProgressDialog : public ModelessDialog + class PrintProgressDialog : public weld::GenericDialogController { OUString maStr; - VclPtr<FixedText> mpText; - VclPtr<ProgressBar> mpProgress; - VclPtr<CancelButton> mpButton; - bool mbCanceled; sal_Int32 mnCur; sal_Int32 mnMax; - DECL_LINK( ClickHdl, Button*, void ); + std::unique_ptr<weld::Label> mxText; + std::unique_ptr<weld::ProgressBar> mxProgress; + std::unique_ptr<weld::Button> mxButton; + + DECL_LINK( ClickHdl, weld::Button&, void ); public: - PrintProgressDialog(vcl::Window* i_pParent, int i_nMax); + PrintProgressDialog(weld::Window* i_pParent, int i_nMax); virtual ~PrintProgressDialog() override; - virtual void dispose() override; bool isCanceled() const { return mbCanceled; } void setProgress( int i_nCurrent ); void tick(); diff --git a/vcl/source/gdi/print3.cxx b/vcl/source/gdi/print3.cxx index 96ebfc7197a9..603ec9056212 100644 --- a/vcl/source/gdi/print3.cxx +++ b/vcl/source/gdi/print3.cxx @@ -159,7 +159,7 @@ public: vcl::PrinterController::MultiPageSetup maMultiPage; - VclPtr<vcl::PrintProgressDialog> mpProgress; + std::shared_ptr<vcl::PrintProgressDialog> mxProgress; ImplPageCache maPageCache; @@ -194,11 +194,18 @@ public: mbPapersizeFromUser( false ), mbPrinterModified( false ), meJobState( css::view::PrintableState_JOB_STARTED ), - mpProgress( nullptr ), mnDefaultPaperBin( -1 ), mnFixedPaperBin( -1 ) {} - ~ImplPrinterControllerData() { mpProgress.disposeAndClear(); } + + ~ImplPrinterControllerData() + { + if (mxProgress) + { + mxProgress->response(RET_CANCEL); + mxProgress.reset(); + } + } const Size& getRealPaperSize( const Size& i_rPageSize, bool bNoNUP ) const { @@ -973,12 +980,12 @@ css::uno::Sequence< css::beans::PropertyValue > PrinterController::getPageParame PrinterController::PageSize PrinterController::getPageFile( int i_nUnfilteredPage, GDIMetaFile& o_rMtf, bool i_bMayUseCache ) { // update progress if necessary - if( mpImplData->mpProgress ) + if( mpImplData->mxProgress ) { // do nothing if printing is canceled - if( mpImplData->mpProgress->isCanceled() ) + if( mpImplData->mxProgress->isCanceled() ) return PrinterController::PageSize(); - mpImplData->mpProgress->tick(); + mpImplData->mxProgress->tick(); Application::Reschedule( true ); } @@ -1284,10 +1291,10 @@ void PrinterController::printFilteredPage( int i_nPage ) GDIMetaFile aPageFile; PrinterController::PageSize aPageSize = getFilteredPageFile( i_nPage, aPageFile ); - if( mpImplData->mpProgress ) + if( mpImplData->mxProgress ) { // do nothing if printing is canceled - if( mpImplData->mpProgress->isCanceled() ) + if( mpImplData->mxProgress->isCanceled() ) { setJobState( css::view::PrintableState_JOB_ABORTED ); return; @@ -1344,7 +1351,13 @@ void PrinterController::abortJob() // applications (well, sw) depend on a page request with "IsLastPage" = true // to free resources, else they (well, sw) will crash eventually setLastPage( true ); - mpImplData->mpProgress.disposeAndClear(); + + if (mpImplData->mxProgress) + { + mpImplData->mxProgress->response(RET_CANCEL); + mpImplData->mxProgress.reset(); + } + GDIMetaFile aMtf; getPageFile( 0, aMtf ); } @@ -1667,7 +1680,7 @@ OUString PrinterController::makeEnabled( const OUString& i_rProperty ) void PrinterController::createProgressDialog() { - if( ! mpImplData->mpProgress ) + if (!mpImplData->mxProgress) { bool bShow = true; css::beans::PropertyValue* pMonitor = getValue( OUString( "MonitorVisible" ) ); @@ -1686,17 +1699,21 @@ void PrinterController::createProgressDialog() if( bShow && ! Application::IsHeadlessModeEnabled() ) { - mpImplData->mpProgress = VclPtr<PrintProgressDialog>::Create( nullptr, getPageCountProtected() ); - mpImplData->mpProgress->Show(); + VclPtr<vcl::Window> xParent = getWindow(); + mpImplData->mxProgress.reset(new PrintProgressDialog(xParent ? xParent->GetFrameWeld() : nullptr, getPageCountProtected())); + weld::DialogController::runAsync(mpImplData->mxProgress, [](sal_Int32 /*nResult*/){}); } } else - mpImplData->mpProgress->reset(); + { + mpImplData->mxProgress->response(RET_CANCEL); + mpImplData->mxProgress.reset(); + } } bool PrinterController::isProgressCanceled() const { - return mpImplData->mpProgress && mpImplData->mpProgress->isCanceled(); + return mpImplData->mxProgress && mpImplData->mxProgress->isCanceled(); } void PrinterController::setMultipage( const MultiPageSetup& i_rMPS ) diff --git a/vcl/source/window/printdlg.cxx b/vcl/source/window/printdlg.cxx index 36a84c8bc2d0..2ab9b47a1106 100644 --- a/vcl/source/window/printdlg.cxx +++ b/vcl/source/window/printdlg.cxx @@ -2129,55 +2129,41 @@ void PrintDialog::previewBackward() mpPageEdit->Down(); } - // PrintProgressDialog - -PrintProgressDialog::PrintProgressDialog(vcl::Window* i_pParent, int i_nMax) - : ModelessDialog(i_pParent, "PrintProgressDialog", "vcl/ui/printprogressdialog.ui") +PrintProgressDialog::PrintProgressDialog(weld::Window* i_pParent, int i_nMax) + : GenericDialogController(i_pParent, "vcl/ui/printprogressdialog.ui", "PrintProgressDialog") , mbCanceled(false) , mnCur(0) , mnMax(i_nMax) + , mxText(m_xBuilder->weld_label("label")) + , mxProgress(m_xBuilder->weld_progress_bar("progressbar")) + , mxButton(m_xBuilder->weld_button("cancel")) { - get(mpButton, "cancel"); - get(mpProgress, "progressbar"); - get(mpText, "label"); - if( mnMax < 1 ) mnMax = 1; - maStr = mpText->GetText(); + maStr = mxText->get_label(); //just multiply largest value by 10 and take the width of that string as //the max size we will want OUString aNewText( maStr.replaceFirst( "%p", OUString::number( mnMax * 10 ) ) ); aNewText = aNewText.replaceFirst( "%n", OUString::number( mnMax * 10 ) ); - mpText->SetText( aNewText ); - mpText->set_width_request(mpText->get_preferred_size().Width()); + mxText->set_label( aNewText ); + mxText->set_size_request(mxText->get_preferred_size().Width(), -1); //Pick a useful max width - mpProgress->set_width_request(mpProgress->LogicToPixel(Size(100, 0), MapMode(MapUnit::MapAppFont)).Width()); - - mpButton->SetClickHdl( LINK( this, PrintProgressDialog, ClickHdl ) ); + mxProgress->set_size_request(mxProgress->get_approximate_digit_width() * 25, -1); + mxButton->connect_clicked( LINK( this, PrintProgressDialog, ClickHdl ) ); } PrintProgressDialog::~PrintProgressDialog() { - disposeOnce(); -} - -void PrintProgressDialog::dispose() -{ - mpText.clear(); - mpProgress.clear(); - mpButton.clear(); - ModelessDialog::dispose(); } -IMPL_LINK( PrintProgressDialog, ClickHdl, Button*, pButton, void ) +IMPL_LINK_NOARG(PrintProgressDialog, ClickHdl, weld::Button&, void) { - if( pButton == mpButton ) - mbCanceled = true; + mbCanceled = true; } void PrintProgressDialog::setProgress( int i_nCurrent ) @@ -2187,11 +2173,11 @@ void PrintProgressDialog::setProgress( int i_nCurrent ) if( mnMax < 1 ) mnMax = 1; - mpProgress->SetValue(mnCur*100/mnMax); + mxProgress->set_percentage(mnCur*100/mnMax); OUString aNewText( maStr.replaceFirst( "%p", OUString::number( mnCur ) ) ); aNewText = aNewText.replaceFirst( "%n", OUString::number( mnMax ) ); - mpText->SetText( aNewText ); + mxText->set_label( aNewText ); } void PrintProgressDialog::tick() |