// check configuration: shall update of printing information in DocInfo set the document to "modified"? if (m_bOrigStatus && !officecfg::Office::Common::Print::PrintingModifiesDocument::get())
{
mpObjectShell->EnableSetModified( false );
m_bNeedsChange = true;
}
bool bCopyJobSetup = false;
mpObjectShell->Broadcast( SfxPrintingHint( nState ) ); switch ( nState )
{ case view::PrintableState_JOB_SPOOLING_FAILED : case view::PrintableState_JOB_FAILED :
{ // "real" problem (not simply printing cancelled by user)
OUString aMsg( SfxResId(STR_NOSTARTPRINTER) ); if ( !m_bApi && mpViewShell )
{
std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(mpViewShell->GetFrameWeld(),
VclMessageType::Warning, VclButtonsType::Ok,
aMsg));
xBox->run();
}
[[fallthrough]];
} case view::PrintableState_JOB_ABORTED :
{ // printing not successful, reset DocInfo if the job started and so DocInfo was modified if (m_bJobStarted)
{
uno::Reference<document::XDocumentProperties> xDocProps(mpObjectShell->getDocProperties());
xDocProps->setPrintedBy(m_aLastPrintedBy);
xDocProps->setPrintDate(m_aLastPrinted);
} break;
}
case view::PrintableState_JOB_SPOOLED : case view::PrintableState_JOB_COMPLETED :
{ if (mpViewShell)
{
SfxBindings& rBind = mpViewShell->GetViewFrame().GetBindings();
rBind.Invalidate( SID_PRINTDOC );
rBind.Invalidate( SID_PRINTDOCDIRECT );
rBind.Invalidate( SID_SETUPPRINTER );
bCopyJobSetup = ! m_bTempPrinter;
} break;
}
default: break;
}
if( bCopyJobSetup && mpViewShell )
{ // #i114306# // Note: this possibly creates a printer that gets immediately replaced // by a new one. The reason for this is that otherwise we would not get // the printer's SfxItemSet here to copy. Awkward, but at the moment there is no // other way here to get the item set.
SfxPrinter* pDocPrt = mpViewShell->GetPrinter(true); if( pDocPrt )
{ if( pDocPrt->GetName() == getPrinter()->GetName() )
pDocPrt->SetJobSetup( getPrinter()->GetJobSetup() ); else
{
VclPtr<SfxPrinter> pNewPrt = VclPtr<SfxPrinter>::Create( pDocPrt->GetOptions().Clone(), getPrinter()->GetName() );
pNewPrt->SetJobSetup( getPrinter()->GetJobSetup() );
mpViewShell->SetPrinter( pNewPrt, SfxPrinterChangeFlags::PRINTER | SfxPrinterChangeFlags::JOBSETUP );
}
}
}
if ( m_bNeedsChange )
mpObjectShell->EnableSetModified( m_bOrigStatus );
if ( mpViewShell )
{
mpViewShell->pImpl->m_xPrinterController.reset();
}
}
// Summarize in this variable what has been changed.
SfxPrinterChangeFlags nChangedFlags = SfxPrinterChangeFlags::NONE;
// Ask if possible, if page format should be taken over from printer. if (bOriChg || bPgSzChg)
{
std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(nullptr,
VclMessageType::Question, VclButtonsType::YesNo,
aMsg)); if (RET_YES == xBox->run())
{ // Flags with changes for <SetPrinter(SfxPrinter*)> are maintained
nChangedFlags |= nNewOpt;
}
}
// Was the printer selection changed from Default to Specific // or the other way around? if ( (pNewPrinter->GetName() != pDocPrinter->GetName())
|| (pDocPrinter->IsDefPrinter() != pNewPrinter->IsDefPrinter()) )
{
nChangedFlags |= SfxPrinterChangeFlags::PRINTER|SfxPrinterChangeFlags::JOBSETUP; if ( ! (pNewPrinter->GetOptions() == pDocPrinter->GetOptions()) )
{
nChangedFlags |= SfxPrinterChangeFlags::OPTIONS;
}
pDocPrinter = pNewPrinter;
} else
{ // Compare extra options if ( ! (pNewPrinter->GetOptions() == pDocPrinter->GetOptions()) )
{ // Option have changed
pDocPrinter->SetOptions( pNewPrinter->GetOptions() );
nChangedFlags |= SfxPrinterChangeFlags::OPTIONS;
}
// Keep old changed Printer.
pDocPrinter->SetPrinterProps( pNewPrinter );
pNewPrinter.disposeAndClear();
}
if ( SfxPrinterChangeFlags::NONE != nChangedFlags ) // SetPrinter will delete the old printer if it changes
SetPrinter( pDocPrinter, nChangedFlags );
}
// get the current selection; our controller should know it
Reference< frame::XController > xController( GetController() );
Reference< view::XSelectionSupplier > xSupplier( xController, UNO_QUERY );
Any aSelection; if( xSupplier.is() )
aSelection = xSupplier->getSelection(); else
aSelection <<= GetObjectShell()->GetModel();
Any aComplete( Any( GetObjectShell()->GetModel() ) );
Any aViewProp( xController );
VclPtr<Printer> aPrt;
// When no JobName was specified via com::sun::star::view::PrintOptions::JobName , // use the document title as default job name
css::beans::PropertyValue* pJobNameVal = xNewController->getValue(u"JobName"_ustr); if (!pJobNameVal)
{ if (SfxObjectShell* pDoc = GetObjectShell())
{
xNewController->setValue(u"JobName"_ustr, Any(pDoc->GetTitle(1)));
xNewController->setPrinterModified(mbPrinterSettingsModified);
}
}
}
// does the function have been called by the user interface or by an API call bool bIsAPI = rReq.GetArgs() && rReq.GetArgs()->Count(); if ( bIsAPI )
{ // the function have been called by the API
// Should it be visible on the user interface, // should it launch popup dialogue ? const SfxBoolItem* pSilentItem = rReq.GetArg<SfxBoolItem>(SID_SILENT);
bSilent = pSilentItem && pSilentItem->GetValue();
}
// no help button in dialogs if called from the help window // (pressing help button would exchange the current page inside the help // document that is going to be printed!)
SfxMedium* pMedium = GetViewFrame().GetObjectShell()->GetMedium();
std::shared_ptr<const SfxFilter> pFilter = pMedium ? pMedium->GetFilter() : nullptr; bool bPrintOnHelp = ( pFilter && pFilter->GetFilterName() == "writer_web_HTML_help" );
const sal_uInt16 nId = rReq.GetSlot(); switch( nId )
{ case SID_PRINTDOC: // display the printer selection and properties dialogue : File > Print... case SID_PRINTDOCDIRECT: // Print the document directly, without displaying the dialogue
{
SfxObjectShell* pDoc = GetObjectShell();
// derived class may decide to abort this if( pDoc == nullptr || !pDoc->QuerySlotExecutable( nId ) )
{
rReq.SetReturnValue( SfxBoolItem( 0, false ) ); return;
}
// should we print only the selection or the whole document const SfxBoolItem* pSelectItem = rReq.GetArg<SfxBoolItem>(SID_SELECTION); bool bSelection = ( pSelectItem != nullptr && pSelectItem->GetValue() ); // detect non api call from writer ( that adds SID_SELECTION ) and reset bIsAPI if ( pSelectItem && rReq.GetArgs()->Count() == 1 )
bIsAPI = false;
// we will add the "PrintSelectionOnly" or "HideHelpButton" properties // we have to increase the capacity of aProps
sal_Int32 nLen = aProps.getLength();
aProps.realloc( nLen + 1 ); auto pProps = aProps.getArray();
// HACK: writer sets the SID_SELECTION item when printing directly and expects // to get only the selection document in that case (see getSelectionObject) // however it also reacts to the PrintContent property. We need this distinction here, too, // else one of the combinations print / print direct and selection / all will not work. // it would be better if writer handled this internally if( nId == SID_PRINTDOCDIRECT )
{
pProps[nLen].Name = "PrintSelectionOnly";
pProps[nLen].Value <<= bSelection;
} else// if nId == SID_PRINTDOC ; nothing to do with the previous HACK
{ // should the printer selection and properties dialogue display an help button
pProps[nLen].Name = "HideHelpButton";
pProps[nLen].Value <<= bPrintOnHelp;
}
case SID_PRINTER_NAME: // for recorded macros
{ // get printer and printer settings from the document
SfxPrinter* pDocPrinter = GetPrinter(true); const SfxStringItem* pPrinterItem = rReq.GetArg<SfxStringItem>(SID_PRINTER_NAME); if (!pPrinterItem)
{
rReq.Ignore(); break;
} // use PrinterName parameter to create a printer
pPrinter = VclPtr<SfxPrinter>::Create(pDocPrinter->GetOptions().Clone(),
pPrinterItem->GetValue());
if (!pPrinter->IsKnown())
{
pPrinter.disposeAndClear();
rReq.Ignore(); break;
}
SetPrinter(pPrinter, SfxPrinterChangeFlags::PRINTER);
rReq.Done(); break;
} case SID_SETUPPRINTER : // display the printer settings dialog : File > Printer Settings...
{ // get printer and printer settings from the document
SfxPrinter *pDocPrinter = GetPrinter(true);
// look for printer in parameters const SfxStringItem* pPrinterItem = rReq.GetArg<SfxStringItem>(SID_PRINTER_NAME); if ( pPrinterItem )
{ // use PrinterName parameter to create a printer
pPrinter = VclPtr<SfxPrinter>::Create( pDocPrinter->GetOptions().Clone(), pPrinterItem->GetValue() );
// if printer is unknown, it can't be used - now printer from document will be used if ( !pPrinter->IsKnown() )
pPrinter.disposeAndClear();
}
// no PrinterName parameter in ItemSet or the PrinterName points to an unknown printer if ( !pPrinter ) // use default printer from document
pPrinter = pDocPrinter;
if( !pPrinter || !pPrinter->IsValid() )
{ // no valid printer either in ItemSet or at the document if ( !bSilent )
{
std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(nullptr,
VclMessageType::Warning, VclButtonsType::Ok,
SfxResId(STR_NODEFPRINTER)));
xBox->run();
}
rReq.SetReturnValue(SfxBoolItem(0,false));
break;
}
// FIXME: printer isn't used for printing anymore! if( pPrinter->IsPrinting() )
{ // if printer is busy, abort configuration if ( !bSilent )
{
std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(nullptr,
VclMessageType::Info, VclButtonsType::Ok,
SfxResId(STR_ERROR_PRINTER_BUSY)));
xBox->run();
}
rReq.SetReturnValue(SfxBoolItem(0,false));
return;
}
// Open Printer Setup dialog (needs a temporary printer)
VclPtr<SfxPrinter> pDlgPrinter = pPrinter->Clone();
PrinterSetupDialog aPrintSetupDlg(GetFrameWeld());
std::unique_ptr<SfxDialogExecutor_Impl> pExecutor;
if (pImpl->m_bHasPrintOptions && HasPrintOptionsPage())
{ // additional controls for dialog
pExecutor.reset(new SfxDialogExecutor_Impl(this, aPrintSetupDlg)); if (bPrintOnHelp)
pExecutor->DisableHelp();
aPrintSetupDlg.SetOptionsHdl(pExecutor->GetLink());
}
if (pExecutor && pExecutor->GetOptions())
{ if (nDialogRet == RET_OK) // remark: have to be recorded if possible!
pDlgPrinter->SetOptions(*pExecutor->GetOptions()); else
{
pPrinter->SetOptions(*pExecutor->GetOptions());
SetPrinter(pPrinter, SfxPrinterChangeFlags::OPTIONS);
}
}
// no recording of PrinterSetup except printer name (is printer dependent)
rReq.Ignore();
if (nDialogRet == RET_OK)
{ if (pPrinter->GetName() != pDlgPrinter->GetName())
{ // user has changed the printer -> macro recording
SfxRequest aReq(GetViewFrame(), SID_PRINTER_NAME);
aReq.AppendItem(SfxStringItem(SID_PRINTER_NAME, pDlgPrinter->GetName()));
aReq.Done();
}
// take the changes made in the dialog
SetPrinter_Impl(pDlgPrinter);
// forget new printer, it was taken over (as pPrinter) or deleted
pDlgPrinter = nullptr;
mbPrinterSettingsModified = true;
} else
{ // PrinterDialog is used to transfer information on printing, // so it will only be deleted here if dialog was cancelled
pDlgPrinter.disposeAndClear();
rReq.Ignore();
} break;
}
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.