Kaydet (Commit) 8a109230 authored tarafından Caolán McNamara's avatar Caolán McNamara

weld PrintProgressDialog

Change-Id: Icb37642bf3ef0ddd1b31d25b80564cdcbb86e653
Reviewed-on: https://gerrit.libreoffice.org/69743
Tested-by: Jenkins
Reviewed-by: 's avatarCaolán McNamara <caolanm@redhat.com>
Tested-by: 's avatarCaolán McNamara <caolanm@redhat.com>
üst 830345be
...@@ -250,23 +250,22 @@ namespace vcl ...@@ -250,23 +250,22 @@ namespace vcl
}; };
class PrintProgressDialog : public ModelessDialog class PrintProgressDialog : public weld::GenericDialogController
{ {
OUString maStr; OUString maStr;
VclPtr<FixedText> mpText;
VclPtr<ProgressBar> mpProgress;
VclPtr<CancelButton> mpButton;
bool mbCanceled; bool mbCanceled;
sal_Int32 mnCur; sal_Int32 mnCur;
sal_Int32 mnMax; 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: public:
PrintProgressDialog(vcl::Window* i_pParent, int i_nMax); PrintProgressDialog(weld::Window* i_pParent, int i_nMax);
virtual ~PrintProgressDialog() override; virtual ~PrintProgressDialog() override;
virtual void dispose() override;
bool isCanceled() const { return mbCanceled; } bool isCanceled() const { return mbCanceled; }
void setProgress( int i_nCurrent ); void setProgress( int i_nCurrent );
void tick(); void tick();
......
...@@ -159,7 +159,7 @@ public: ...@@ -159,7 +159,7 @@ public:
vcl::PrinterController::MultiPageSetup maMultiPage; vcl::PrinterController::MultiPageSetup maMultiPage;
VclPtr<vcl::PrintProgressDialog> mpProgress; std::shared_ptr<vcl::PrintProgressDialog> mxProgress;
ImplPageCache maPageCache; ImplPageCache maPageCache;
...@@ -194,11 +194,18 @@ public: ...@@ -194,11 +194,18 @@ public:
mbPapersizeFromUser( false ), mbPapersizeFromUser( false ),
mbPrinterModified( false ), mbPrinterModified( false ),
meJobState( css::view::PrintableState_JOB_STARTED ), meJobState( css::view::PrintableState_JOB_STARTED ),
mpProgress( nullptr ),
mnDefaultPaperBin( -1 ), mnDefaultPaperBin( -1 ),
mnFixedPaperBin( -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 const Size& getRealPaperSize( const Size& i_rPageSize, bool bNoNUP ) const
{ {
...@@ -973,12 +980,12 @@ css::uno::Sequence< css::beans::PropertyValue > PrinterController::getPageParame ...@@ -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 ) PrinterController::PageSize PrinterController::getPageFile( int i_nUnfilteredPage, GDIMetaFile& o_rMtf, bool i_bMayUseCache )
{ {
// update progress if necessary // update progress if necessary
if( mpImplData->mpProgress ) if( mpImplData->mxProgress )
{ {
// do nothing if printing is canceled // do nothing if printing is canceled
if( mpImplData->mpProgress->isCanceled() ) if( mpImplData->mxProgress->isCanceled() )
return PrinterController::PageSize(); return PrinterController::PageSize();
mpImplData->mpProgress->tick(); mpImplData->mxProgress->tick();
Application::Reschedule( true ); Application::Reschedule( true );
} }
...@@ -1284,10 +1291,10 @@ void PrinterController::printFilteredPage( int i_nPage ) ...@@ -1284,10 +1291,10 @@ void PrinterController::printFilteredPage( int i_nPage )
GDIMetaFile aPageFile; GDIMetaFile aPageFile;
PrinterController::PageSize aPageSize = getFilteredPageFile( i_nPage, aPageFile ); PrinterController::PageSize aPageSize = getFilteredPageFile( i_nPage, aPageFile );
if( mpImplData->mpProgress ) if( mpImplData->mxProgress )
{ {
// do nothing if printing is canceled // do nothing if printing is canceled
if( mpImplData->mpProgress->isCanceled() ) if( mpImplData->mxProgress->isCanceled() )
{ {
setJobState( css::view::PrintableState_JOB_ABORTED ); setJobState( css::view::PrintableState_JOB_ABORTED );
return; return;
...@@ -1344,7 +1351,13 @@ void PrinterController::abortJob() ...@@ -1344,7 +1351,13 @@ void PrinterController::abortJob()
// applications (well, sw) depend on a page request with "IsLastPage" = true // applications (well, sw) depend on a page request with "IsLastPage" = true
// to free resources, else they (well, sw) will crash eventually // to free resources, else they (well, sw) will crash eventually
setLastPage( true ); setLastPage( true );
mpImplData->mpProgress.disposeAndClear();
if (mpImplData->mxProgress)
{
mpImplData->mxProgress->response(RET_CANCEL);
mpImplData->mxProgress.reset();
}
GDIMetaFile aMtf; GDIMetaFile aMtf;
getPageFile( 0, aMtf ); getPageFile( 0, aMtf );
} }
...@@ -1667,7 +1680,7 @@ OUString PrinterController::makeEnabled( const OUString& i_rProperty ) ...@@ -1667,7 +1680,7 @@ OUString PrinterController::makeEnabled( const OUString& i_rProperty )
void PrinterController::createProgressDialog() void PrinterController::createProgressDialog()
{ {
if( ! mpImplData->mpProgress ) if (!mpImplData->mxProgress)
{ {
bool bShow = true; bool bShow = true;
css::beans::PropertyValue* pMonitor = getValue( OUString( "MonitorVisible" ) ); css::beans::PropertyValue* pMonitor = getValue( OUString( "MonitorVisible" ) );
...@@ -1686,17 +1699,21 @@ void PrinterController::createProgressDialog() ...@@ -1686,17 +1699,21 @@ void PrinterController::createProgressDialog()
if( bShow && ! Application::IsHeadlessModeEnabled() ) if( bShow && ! Application::IsHeadlessModeEnabled() )
{ {
mpImplData->mpProgress = VclPtr<PrintProgressDialog>::Create( nullptr, getPageCountProtected() ); VclPtr<vcl::Window> xParent = getWindow();
mpImplData->mpProgress->Show(); mpImplData->mxProgress.reset(new PrintProgressDialog(xParent ? xParent->GetFrameWeld() : nullptr, getPageCountProtected()));
weld::DialogController::runAsync(mpImplData->mxProgress, [](sal_Int32 /*nResult*/){});
} }
} }
else else
mpImplData->mpProgress->reset(); {
mpImplData->mxProgress->response(RET_CANCEL);
mpImplData->mxProgress.reset();
}
} }
bool PrinterController::isProgressCanceled() const bool PrinterController::isProgressCanceled() const
{ {
return mpImplData->mpProgress && mpImplData->mpProgress->isCanceled(); return mpImplData->mxProgress && mpImplData->mxProgress->isCanceled();
} }
void PrinterController::setMultipage( const MultiPageSetup& i_rMPS ) void PrinterController::setMultipage( const MultiPageSetup& i_rMPS )
......
...@@ -2129,55 +2129,41 @@ void PrintDialog::previewBackward() ...@@ -2129,55 +2129,41 @@ void PrintDialog::previewBackward()
mpPageEdit->Down(); mpPageEdit->Down();
} }
// PrintProgressDialog // PrintProgressDialog
PrintProgressDialog::PrintProgressDialog(weld::Window* i_pParent, int i_nMax)
PrintProgressDialog::PrintProgressDialog(vcl::Window* i_pParent, int i_nMax) : GenericDialogController(i_pParent, "vcl/ui/printprogressdialog.ui", "PrintProgressDialog")
: ModelessDialog(i_pParent, "PrintProgressDialog", "vcl/ui/printprogressdialog.ui")
, mbCanceled(false) , mbCanceled(false)
, mnCur(0) , mnCur(0)
, mnMax(i_nMax) , 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 ) if( mnMax < 1 )
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 //just multiply largest value by 10 and take the width of that string as
//the max size we will want //the max size we will want
OUString aNewText( maStr.replaceFirst( "%p", OUString::number( mnMax * 10 ) ) ); OUString aNewText( maStr.replaceFirst( "%p", OUString::number( mnMax * 10 ) ) );
aNewText = aNewText.replaceFirst( "%n", OUString::number( mnMax * 10 ) ); aNewText = aNewText.replaceFirst( "%n", OUString::number( mnMax * 10 ) );
mpText->SetText( aNewText ); mxText->set_label( aNewText );
mpText->set_width_request(mpText->get_preferred_size().Width()); mxText->set_size_request(mxText->get_preferred_size().Width(), -1);
//Pick a useful max width //Pick a useful max width
mpProgress->set_width_request(mpProgress->LogicToPixel(Size(100, 0), MapMode(MapUnit::MapAppFont)).Width()); mxProgress->set_size_request(mxProgress->get_approximate_digit_width() * 25, -1);
mpButton->SetClickHdl( LINK( this, PrintProgressDialog, ClickHdl ) );
mxButton->connect_clicked( LINK( this, PrintProgressDialog, ClickHdl ) );
} }
PrintProgressDialog::~PrintProgressDialog() 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 ) void PrintProgressDialog::setProgress( int i_nCurrent )
...@@ -2187,11 +2173,11 @@ void PrintProgressDialog::setProgress( int i_nCurrent ) ...@@ -2187,11 +2173,11 @@ void PrintProgressDialog::setProgress( int i_nCurrent )
if( mnMax < 1 ) if( mnMax < 1 )
mnMax = 1; mnMax = 1;
mpProgress->SetValue(mnCur*100/mnMax); mxProgress->set_percentage(mnCur*100/mnMax);
OUString aNewText( maStr.replaceFirst( "%p", OUString::number( mnCur ) ) ); OUString aNewText( maStr.replaceFirst( "%p", OUString::number( mnCur ) ) );
aNewText = aNewText.replaceFirst( "%n", OUString::number( mnMax ) ); aNewText = aNewText.replaceFirst( "%n", OUString::number( mnMax ) );
mpText->SetText( aNewText ); mxText->set_label( aNewText );
} }
void PrintProgressDialog::tick() void PrintProgressDialog::tick()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment