xref: /aoo41x/main/sfx2/source/view/viewprn.cxx (revision 3d720f72)
1d119d52dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3d119d52dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4d119d52dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5d119d52dSAndrew Rist  * distributed with this work for additional information
6d119d52dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7d119d52dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8d119d52dSAndrew Rist  * "License"); you may not use this file except in compliance
9d119d52dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10d119d52dSAndrew Rist  *
11d119d52dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12d119d52dSAndrew Rist  *
13d119d52dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14d119d52dSAndrew Rist  * software distributed under the License is distributed on an
15d119d52dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16d119d52dSAndrew Rist  * KIND, either express or implied.  See the License for the
17d119d52dSAndrew Rist  * specific language governing permissions and limitations
18d119d52dSAndrew Rist  * under the License.
19d119d52dSAndrew Rist  *
20d119d52dSAndrew Rist  *************************************************************/
21d119d52dSAndrew Rist 
22d119d52dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sfx2.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <com/sun/star/document/XDocumentProperties.hpp>
28cdf0e10cSrcweir #include "com/sun/star/view/XRenderable.hpp"
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include <svl/itempool.hxx>
31cdf0e10cSrcweir #include <vcl/msgbox.hxx>
32cdf0e10cSrcweir #include <svtools/prnsetup.hxx>
33cdf0e10cSrcweir #include <svl/flagitem.hxx>
34cdf0e10cSrcweir #include <svl/stritem.hxx>
35cdf0e10cSrcweir #include <svl/intitem.hxx>
36cdf0e10cSrcweir #include <svl/eitem.hxx>
37cdf0e10cSrcweir #include <sfx2/app.hxx>
38cdf0e10cSrcweir #include <unotools/useroptions.hxx>
39cdf0e10cSrcweir #include <unotools/printwarningoptions.hxx>
40cdf0e10cSrcweir #include <tools/datetime.hxx>
41cdf0e10cSrcweir #include <sfx2/bindings.hxx>
42cdf0e10cSrcweir #include <sfx2/objface.hxx>
43cdf0e10cSrcweir #include <sfx2/viewsh.hxx>
44cdf0e10cSrcweir #include "viewimp.hxx"
45cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
46cdf0e10cSrcweir #include <sfx2/prnmon.hxx>
47cdf0e10cSrcweir #include "sfx2/sfxresid.hxx"
48cdf0e10cSrcweir #include <sfx2/request.hxx>
49cdf0e10cSrcweir #include <sfx2/objsh.hxx>
50cdf0e10cSrcweir #include "sfxtypes.hxx"
51cdf0e10cSrcweir #include <sfx2/event.hxx>
52cdf0e10cSrcweir #include <sfx2/docfile.hxx>
53cdf0e10cSrcweir #include <sfx2/docfilt.hxx>
54cdf0e10cSrcweir 
55cdf0e10cSrcweir #include "toolkit/awt/vclxdevice.hxx"
56cdf0e10cSrcweir 
57cdf0e10cSrcweir #include "view.hrc"
58cdf0e10cSrcweir #include "helpid.hrc"
59cdf0e10cSrcweir 
60cdf0e10cSrcweir using namespace com::sun::star;
61cdf0e10cSrcweir using namespace com::sun::star::uno;
62cdf0e10cSrcweir 
63*3d720f72SAriel Constenla-Haile TYPEINIT1(SfxPrintingHint, SfxViewEventHint);
64cdf0e10cSrcweir 
65cdf0e10cSrcweir // -----------------------------------------------------------------------
66cdf0e10cSrcweir class SfxPrinterController : public vcl::PrinterController, public SfxListener
67cdf0e10cSrcweir {
68cdf0e10cSrcweir     Any                                     maCompleteSelection;
69cdf0e10cSrcweir     Any                                     maSelection;
70cdf0e10cSrcweir     Reference< view::XRenderable >          mxRenderable;
71cdf0e10cSrcweir     mutable Printer*                        mpLastPrinter;
72cdf0e10cSrcweir     mutable Reference<awt::XDevice>         mxDevice;
73cdf0e10cSrcweir 	SfxViewShell*							mpViewShell;
74cdf0e10cSrcweir 	SfxObjectShell*							mpObjectShell;
75cdf0e10cSrcweir 	sal_Bool		m_bOrigStatus;
76cdf0e10cSrcweir 	sal_Bool		m_bNeedsChange;
77cdf0e10cSrcweir 	sal_Bool		m_bApi;
78cdf0e10cSrcweir 	sal_Bool        m_bTempPrinter;
79cdf0e10cSrcweir 	util::DateTime	m_aLastPrinted;
80cdf0e10cSrcweir 	::rtl::OUString	m_aLastPrintedBy;
81cdf0e10cSrcweir 
82cdf0e10cSrcweir     Sequence< beans::PropertyValue > getMergedOptions() const;
83cdf0e10cSrcweir     const Any& getSelectionObject() const;
84cdf0e10cSrcweir public:
85cdf0e10cSrcweir     SfxPrinterController( const boost::shared_ptr<Printer>& i_rPrinter,
86cdf0e10cSrcweir                           const Any& i_rComplete,
87cdf0e10cSrcweir                           const Any& i_rSelection,
88cdf0e10cSrcweir                           const Any& i_rViewProp,
89cdf0e10cSrcweir                           const Reference< view::XRenderable >& i_xRender,
90cdf0e10cSrcweir                           sal_Bool i_bApi, sal_Bool i_bDirect,
91cdf0e10cSrcweir 						  SfxViewShell* pView,
92cdf0e10cSrcweir                           const uno::Sequence< beans::PropertyValue >& rProps
93cdf0e10cSrcweir                         );
94cdf0e10cSrcweir 
95cdf0e10cSrcweir     virtual ~SfxPrinterController();
96cdf0e10cSrcweir 	virtual void Notify( SfxBroadcaster&, const SfxHint& );
97cdf0e10cSrcweir 
98cdf0e10cSrcweir     virtual int  getPageCount() const;
99cdf0e10cSrcweir     virtual Sequence< beans::PropertyValue > getPageParameters( int i_nPage ) const;
100cdf0e10cSrcweir     virtual void printPage( int i_nPage ) const;
101cdf0e10cSrcweir     virtual void jobStarted();
102cdf0e10cSrcweir     virtual void jobFinished( com::sun::star::view::PrintableState );
103cdf0e10cSrcweir };
104cdf0e10cSrcweir 
SfxPrinterController(const boost::shared_ptr<Printer> & i_rPrinter,const Any & i_rComplete,const Any & i_rSelection,const Any & i_rViewProp,const Reference<view::XRenderable> & i_xRender,sal_Bool i_bApi,sal_Bool i_bDirect,SfxViewShell * pView,const uno::Sequence<beans::PropertyValue> & rProps)105cdf0e10cSrcweir SfxPrinterController::SfxPrinterController( const boost::shared_ptr<Printer>& i_rPrinter,
106cdf0e10cSrcweir                                             const Any& i_rComplete,
107cdf0e10cSrcweir                                             const Any& i_rSelection,
108cdf0e10cSrcweir                                             const Any& i_rViewProp,
109cdf0e10cSrcweir                                             const Reference< view::XRenderable >& i_xRender,
110cdf0e10cSrcweir                                             sal_Bool i_bApi, sal_Bool i_bDirect,
111cdf0e10cSrcweir 										    SfxViewShell* pView,
112cdf0e10cSrcweir                                             const uno::Sequence< beans::PropertyValue >& rProps
113cdf0e10cSrcweir                                           )
114cdf0e10cSrcweir     : PrinterController( i_rPrinter)
115cdf0e10cSrcweir     , maCompleteSelection( i_rComplete )
116cdf0e10cSrcweir     , maSelection( i_rSelection )
117cdf0e10cSrcweir     , mxRenderable( i_xRender )
118cdf0e10cSrcweir     , mpLastPrinter( NULL )
119cdf0e10cSrcweir 	, mpViewShell( pView )
120cdf0e10cSrcweir 	, mpObjectShell(0)
121cdf0e10cSrcweir 	, m_bOrigStatus( sal_False )
122cdf0e10cSrcweir 	, m_bNeedsChange( sal_False )
123cdf0e10cSrcweir 	, m_bApi(i_bApi)
124cdf0e10cSrcweir 	, m_bTempPrinter( i_rPrinter.get() != NULL )
125cdf0e10cSrcweir {
126cdf0e10cSrcweir 	if ( mpViewShell )
127cdf0e10cSrcweir 	{
128cdf0e10cSrcweir 		StartListening( *mpViewShell );
129cdf0e10cSrcweir 		mpObjectShell = mpViewShell->GetObjectShell();
130cdf0e10cSrcweir 		StartListening( *mpObjectShell );
131cdf0e10cSrcweir 	}
132cdf0e10cSrcweir 
133cdf0e10cSrcweir     // initialize extra ui options
134cdf0e10cSrcweir     if( mxRenderable.is() )
135cdf0e10cSrcweir     {
136cdf0e10cSrcweir 	    for (sal_Int32 nProp=0; nProp<rProps.getLength(); nProp++)
137cdf0e10cSrcweir 		    setValue( rProps[nProp].Name, rProps[nProp].Value );
138cdf0e10cSrcweir 
139cdf0e10cSrcweir         Sequence< beans::PropertyValue > aRenderOptions( 3 );
140cdf0e10cSrcweir         aRenderOptions[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ExtraPrintUIOptions" ) );
141cdf0e10cSrcweir         aRenderOptions[1].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "View" ) );
142cdf0e10cSrcweir         aRenderOptions[1].Value = i_rViewProp;
143cdf0e10cSrcweir         aRenderOptions[2].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsPrinter" ) );
144cdf0e10cSrcweir         aRenderOptions[2].Value <<= sal_True;
145cdf0e10cSrcweir         try
146cdf0e10cSrcweir         {
147cdf0e10cSrcweir             Sequence< beans::PropertyValue > aRenderParms( mxRenderable->getRenderer( 0 , getSelectionObject(), aRenderOptions ) );
148cdf0e10cSrcweir             int nProps = aRenderParms.getLength();
149cdf0e10cSrcweir             for( int i = 0; i < nProps; i++ )
150cdf0e10cSrcweir             {
151cdf0e10cSrcweir                 if( aRenderParms[i].Name.equalsAscii( "ExtraPrintUIOptions" ) )
152cdf0e10cSrcweir                 {
153cdf0e10cSrcweir                     Sequence< beans::PropertyValue > aUIProps;
154cdf0e10cSrcweir                     aRenderParms[i].Value >>= aUIProps;
155cdf0e10cSrcweir                     setUIOptions( aUIProps );
1560dccdc5dSMichael Stahl                 }
1570dccdc5dSMichael Stahl                 else if( aRenderParms[i].Name.compareToAscii( "NUp", 3 ) == 0 )
1580dccdc5dSMichael Stahl                 {
1590dccdc5dSMichael Stahl                     setValue( aRenderParms[i].Name, aRenderParms[i].Value );
160cdf0e10cSrcweir                 }
161cdf0e10cSrcweir             }
162cdf0e10cSrcweir         }
163cdf0e10cSrcweir         catch( lang::IllegalArgumentException& )
164cdf0e10cSrcweir         {
165cdf0e10cSrcweir             // the first renderer should always be available for the UI options,
166cdf0e10cSrcweir             // but catch the exception to be safe
167cdf0e10cSrcweir         }
168cdf0e10cSrcweir     }
169cdf0e10cSrcweir 
170cdf0e10cSrcweir     // set some job parameters
171cdf0e10cSrcweir     setValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsApi" ) ), makeAny( i_bApi ) );
172cdf0e10cSrcweir     setValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsDirect" ) ), makeAny( i_bDirect ) );
173cdf0e10cSrcweir     setValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsPrinter" ) ), makeAny( sal_True ) );
174cdf0e10cSrcweir     setValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "View" ) ), i_rViewProp );
175cdf0e10cSrcweir }
176cdf0e10cSrcweir 
Notify(SfxBroadcaster &,const SfxHint & rHint)177cdf0e10cSrcweir void SfxPrinterController::Notify( SfxBroadcaster& , const SfxHint& rHint )
178cdf0e10cSrcweir {
179cdf0e10cSrcweir 	if ( rHint.IsA(TYPE(SfxSimpleHint)) )
180cdf0e10cSrcweir     {
181cdf0e10cSrcweir         if ( ((SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
182cdf0e10cSrcweir         {
183cdf0e10cSrcweir 			EndListening(*mpViewShell);
184cdf0e10cSrcweir 			EndListening(*mpObjectShell);
185cdf0e10cSrcweir             mpViewShell = 0;
186cdf0e10cSrcweir 			mpObjectShell = 0;
187cdf0e10cSrcweir 		}
188cdf0e10cSrcweir 	}
189cdf0e10cSrcweir }
190cdf0e10cSrcweir 
~SfxPrinterController()191cdf0e10cSrcweir SfxPrinterController::~SfxPrinterController()
192cdf0e10cSrcweir {
193cdf0e10cSrcweir }
194cdf0e10cSrcweir 
getSelectionObject() const195cdf0e10cSrcweir const Any& SfxPrinterController::getSelectionObject() const
196cdf0e10cSrcweir {
197cdf0e10cSrcweir     const beans::PropertyValue* pVal = getValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrintSelectionOnly" ) ) );
198cdf0e10cSrcweir     if( pVal )
199cdf0e10cSrcweir     {
200cdf0e10cSrcweir         sal_Bool bSel = sal_False;
201cdf0e10cSrcweir         pVal->Value >>= bSel;
202cdf0e10cSrcweir         return bSel ? maSelection : maCompleteSelection;
203cdf0e10cSrcweir     }
204cdf0e10cSrcweir 
205cdf0e10cSrcweir     sal_Int32 nChoice = 0;
206cdf0e10cSrcweir     pVal = getValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrintContent" ) ) );
207cdf0e10cSrcweir     if( pVal )
208cdf0e10cSrcweir         pVal->Value >>= nChoice;
209cdf0e10cSrcweir     return (nChoice > 1) ? maSelection : maCompleteSelection;
210cdf0e10cSrcweir }
211cdf0e10cSrcweir 
getMergedOptions() const212cdf0e10cSrcweir Sequence< beans::PropertyValue > SfxPrinterController::getMergedOptions() const
213cdf0e10cSrcweir {
214cdf0e10cSrcweir     boost::shared_ptr<Printer> pPrinter( getPrinter() );
215cdf0e10cSrcweir     if( pPrinter.get() != mpLastPrinter )
216cdf0e10cSrcweir     {
217cdf0e10cSrcweir         mpLastPrinter = pPrinter.get();
218cdf0e10cSrcweir         VCLXDevice* pXDevice = new VCLXDevice();
219cdf0e10cSrcweir         pXDevice->SetOutputDevice( mpLastPrinter );
220cdf0e10cSrcweir         mxDevice = Reference< awt::XDevice >( pXDevice );
221cdf0e10cSrcweir     }
222cdf0e10cSrcweir 
223cdf0e10cSrcweir     Sequence< beans::PropertyValue > aRenderOptions( 1 );
224cdf0e10cSrcweir     aRenderOptions[ 0 ].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "RenderDevice" ) );
225cdf0e10cSrcweir     aRenderOptions[ 0 ].Value <<= mxDevice;
226cdf0e10cSrcweir 
227cdf0e10cSrcweir     aRenderOptions = getJobProperties( aRenderOptions );
228cdf0e10cSrcweir     return aRenderOptions;
229cdf0e10cSrcweir }
230cdf0e10cSrcweir 
getPageCount() const231cdf0e10cSrcweir int SfxPrinterController::getPageCount() const
232cdf0e10cSrcweir {
233cdf0e10cSrcweir     int nPages = 0;
234cdf0e10cSrcweir     boost::shared_ptr<Printer> pPrinter( getPrinter() );
235cdf0e10cSrcweir     if( mxRenderable.is() && pPrinter )
236cdf0e10cSrcweir     {
237cdf0e10cSrcweir         Sequence< beans::PropertyValue > aJobOptions( getMergedOptions() );
238cdf0e10cSrcweir         nPages = mxRenderable->getRendererCount( getSelectionObject(), aJobOptions );
239cdf0e10cSrcweir     }
240cdf0e10cSrcweir     return nPages;
241cdf0e10cSrcweir }
242cdf0e10cSrcweir 
getPageParameters(int i_nPage) const243cdf0e10cSrcweir Sequence< beans::PropertyValue > SfxPrinterController::getPageParameters( int i_nPage ) const
244cdf0e10cSrcweir {
245cdf0e10cSrcweir     boost::shared_ptr<Printer> pPrinter( getPrinter() );
246cdf0e10cSrcweir     Sequence< beans::PropertyValue > aResult;
247cdf0e10cSrcweir 
248cdf0e10cSrcweir     if( mxRenderable.is() && pPrinter )
249cdf0e10cSrcweir     {
250cdf0e10cSrcweir         Sequence< beans::PropertyValue > aJobOptions( getMergedOptions() );
251cdf0e10cSrcweir         try
252cdf0e10cSrcweir         {
253cdf0e10cSrcweir             aResult = mxRenderable->getRenderer( i_nPage, getSelectionObject(), aJobOptions );
254cdf0e10cSrcweir         }
255cdf0e10cSrcweir         catch( lang::IllegalArgumentException& )
256cdf0e10cSrcweir         {
257cdf0e10cSrcweir         }
258cdf0e10cSrcweir     }
259cdf0e10cSrcweir     return aResult;
260cdf0e10cSrcweir }
261cdf0e10cSrcweir 
printPage(int i_nPage) const262cdf0e10cSrcweir void SfxPrinterController::printPage( int i_nPage ) const
263cdf0e10cSrcweir {
264cdf0e10cSrcweir     boost::shared_ptr<Printer> pPrinter( getPrinter() );
265cdf0e10cSrcweir     if( mxRenderable.is() && pPrinter )
266cdf0e10cSrcweir     {
267cdf0e10cSrcweir         Sequence< beans::PropertyValue > aJobOptions( getMergedOptions() );
268cdf0e10cSrcweir         try
269cdf0e10cSrcweir         {
270cdf0e10cSrcweir             mxRenderable->render( i_nPage, getSelectionObject(), aJobOptions );
271cdf0e10cSrcweir         }
272cdf0e10cSrcweir         catch( lang::IllegalArgumentException& )
273cdf0e10cSrcweir         {
274cdf0e10cSrcweir             // don't care enough about nonexistant page here
275cdf0e10cSrcweir             // to provoke a crash
276cdf0e10cSrcweir         }
277cdf0e10cSrcweir     }
278cdf0e10cSrcweir }
279cdf0e10cSrcweir 
jobStarted()280cdf0e10cSrcweir void SfxPrinterController::jobStarted()
281cdf0e10cSrcweir {
282cdf0e10cSrcweir 	if ( mpObjectShell )
283cdf0e10cSrcweir 	{
284cdf0e10cSrcweir 		m_bOrigStatus = mpObjectShell->IsEnableSetModified();
285cdf0e10cSrcweir 
286cdf0e10cSrcweir         // check configuration: shall update of printing information in DocInfo set the document to "modified"?
287cdf0e10cSrcweir         if ( m_bOrigStatus && !SvtPrintWarningOptions().IsModifyDocumentOnPrintingAllowed() )
288cdf0e10cSrcweir 		{
289cdf0e10cSrcweir             mpObjectShell->EnableSetModified( sal_False );
290cdf0e10cSrcweir 			m_bNeedsChange = sal_True;
291cdf0e10cSrcweir 		}
292cdf0e10cSrcweir 
293cdf0e10cSrcweir         // refresh document info
294cdf0e10cSrcweir         uno::Reference<document::XDocumentProperties> xDocProps(mpObjectShell->getDocProperties());
295cdf0e10cSrcweir 		m_aLastPrintedBy = xDocProps->getPrintedBy();
296cdf0e10cSrcweir 		m_aLastPrinted = xDocProps->getPrintDate();
297cdf0e10cSrcweir 
298cdf0e10cSrcweir         xDocProps->setPrintedBy( mpObjectShell->IsUseUserData()
299cdf0e10cSrcweir             ? ::rtl::OUString( SvtUserOptions().GetFullName() )
300cdf0e10cSrcweir             : ::rtl::OUString() );
301cdf0e10cSrcweir         ::DateTime now;
302cdf0e10cSrcweir 
303cdf0e10cSrcweir 		xDocProps->setPrintDate( util::DateTime(
304cdf0e10cSrcweir             now.Get100Sec(), now.GetSec(), now.GetMin(), now.GetHour(),
305cdf0e10cSrcweir             now.GetDay(), now.GetMonth(), now.GetYear() ) );
306cdf0e10cSrcweir 
307cdf0e10cSrcweir 		uno::Sequence < beans::PropertyValue > aOpts;
308*3d720f72SAriel Constenla-Haile         aOpts = getJobProperties( aOpts );
309*3d720f72SAriel Constenla-Haile 
310*3d720f72SAriel Constenla-Haile         uno::Reference< frame::XController2 > xController;
311*3d720f72SAriel Constenla-Haile         if ( mpViewShell )
312*3d720f72SAriel Constenla-Haile             xController.set( mpViewShell->GetController(), uno::UNO_QUERY );
313*3d720f72SAriel Constenla-Haile 
314*3d720f72SAriel Constenla-Haile         mpObjectShell->Broadcast( SfxPrintingHint(
315*3d720f72SAriel Constenla-Haile             view::PrintableState_JOB_STARTED, aOpts, mpObjectShell, xController ) );
316cdf0e10cSrcweir 	}
317cdf0e10cSrcweir }
318cdf0e10cSrcweir 
jobFinished(com::sun::star::view::PrintableState nState)319cdf0e10cSrcweir void SfxPrinterController::jobFinished( com::sun::star::view::PrintableState nState )
320cdf0e10cSrcweir {
321cdf0e10cSrcweir 	if ( mpObjectShell )
322cdf0e10cSrcweir 	{
323cdf0e10cSrcweir 	    bool bCopyJobSetup = false;
324cdf0e10cSrcweir 	    mpObjectShell->Broadcast( SfxPrintingHint( nState ) );
325cdf0e10cSrcweir 		switch ( nState )
326cdf0e10cSrcweir 		{
327cdf0e10cSrcweir 			case view::PrintableState_JOB_FAILED :
328cdf0e10cSrcweir 			{
329cdf0e10cSrcweir 				// "real" problem (not simply printing cancelled by user)
330cdf0e10cSrcweir 				String aMsg( SfxResId( STR_NOSTARTPRINTER ) );
331cdf0e10cSrcweir 				if ( !m_bApi )
332cdf0e10cSrcweir 					ErrorBox( mpViewShell->GetWindow(), WB_OK | WB_DEF_OK,  aMsg ).Execute();
333cdf0e10cSrcweir 				// intentionally no break
334cdf0e10cSrcweir 			}
335cdf0e10cSrcweir 			case view::PrintableState_JOB_ABORTED :
336cdf0e10cSrcweir 			{
337cdf0e10cSrcweir 				// printing not succesful, reset DocInfo
338cdf0e10cSrcweir 				uno::Reference<document::XDocumentProperties> xDocProps(mpObjectShell->getDocProperties());
339cdf0e10cSrcweir 				xDocProps->setPrintedBy(m_aLastPrintedBy);
340cdf0e10cSrcweir 				xDocProps->setPrintDate(m_aLastPrinted);
341cdf0e10cSrcweir 				break;
342cdf0e10cSrcweir 			}
343cdf0e10cSrcweir 
344cdf0e10cSrcweir 			case view::PrintableState_JOB_SPOOLED :
345cdf0e10cSrcweir 			case view::PrintableState_JOB_COMPLETED :
346cdf0e10cSrcweir 			{
347cdf0e10cSrcweir 				SfxBindings& rBind = mpViewShell->GetViewFrame()->GetBindings();
348cdf0e10cSrcweir 				rBind.Invalidate( SID_PRINTDOC );
349cdf0e10cSrcweir 				rBind.Invalidate( SID_PRINTDOCDIRECT );
350cdf0e10cSrcweir 				rBind.Invalidate( SID_SETUPPRINTER );
351cdf0e10cSrcweir 				bCopyJobSetup = ! m_bTempPrinter;
352cdf0e10cSrcweir 				break;
353cdf0e10cSrcweir 			}
354cdf0e10cSrcweir 
355cdf0e10cSrcweir 			default:
356cdf0e10cSrcweir 				break;
357cdf0e10cSrcweir 		}
358cdf0e10cSrcweir 
359cdf0e10cSrcweir 		if( bCopyJobSetup && mpViewShell )
360cdf0e10cSrcweir 		{
361cdf0e10cSrcweir 		    // #i114306#
362cdf0e10cSrcweir 		    // Note: this possibly creates a printer that gets immediately replaced
363cdf0e10cSrcweir 		    // by a new one. The reason for this is that otherwise we would not get
364cdf0e10cSrcweir 		    // the printer's SfxItemSet here to copy. Awkward, but at the moment there is no
365cdf0e10cSrcweir 		    // other way here to get the item set.
366cdf0e10cSrcweir 		    SfxPrinter* pDocPrt = mpViewShell->GetPrinter(sal_True);
367cdf0e10cSrcweir 		    if( pDocPrt )
368cdf0e10cSrcweir 		    {
369cdf0e10cSrcweir 		        if( pDocPrt->GetName() == getPrinter()->GetName() )
370cdf0e10cSrcweir 		            pDocPrt->SetJobSetup( getPrinter()->GetJobSetup() );
371cdf0e10cSrcweir 		        else
372cdf0e10cSrcweir 		        {
373cdf0e10cSrcweir 		            SfxPrinter* pNewPrt = new SfxPrinter( pDocPrt->GetOptions().Clone(), getPrinter()->GetName() );
374cdf0e10cSrcweir 		            pNewPrt->SetJobSetup( getPrinter()->GetJobSetup() );
375cdf0e10cSrcweir 		            mpViewShell->SetPrinter( pNewPrt, SFX_PRINTER_PRINTER | SFX_PRINTER_JOBSETUP );
376cdf0e10cSrcweir 		        }
377cdf0e10cSrcweir 		    }
378cdf0e10cSrcweir 		}
379cdf0e10cSrcweir 
380cdf0e10cSrcweir 		if ( m_bNeedsChange )
381cdf0e10cSrcweir 			mpObjectShell->EnableSetModified( m_bOrigStatus );
382cdf0e10cSrcweir 
383cdf0e10cSrcweir 		if ( mpViewShell )
384cdf0e10cSrcweir         {
385cdf0e10cSrcweir             mpViewShell->pImp->m_pPrinterController.reset();
386cdf0e10cSrcweir         }
387cdf0e10cSrcweir 	}
388cdf0e10cSrcweir }
389cdf0e10cSrcweir 
390cdf0e10cSrcweir //====================================================================
391cdf0e10cSrcweir 
392cdf0e10cSrcweir class SfxDialogExecutor_Impl
393cdf0e10cSrcweir 
394cdf0e10cSrcweir /*  [Beschreibung]
395cdf0e10cSrcweir 
396cdf0e10cSrcweir 	Eine Instanz dieser Klasse wird f"ur die Laufzeit des Printer-Dialogs
397cdf0e10cSrcweir 	erzeugt, um im dessen Click-Handler f"ur die Zus"atze den per
398cdf0e10cSrcweir 	virtueller Methode von der abgeleiteten SfxViewShell erzeugten
399cdf0e10cSrcweir 	Print-Options-Dialog zu erzeugen und die dort eingestellten Optionen
400cdf0e10cSrcweir 	als SfxItemSet zu zwischenzuspeichern.
401cdf0e10cSrcweir */
402cdf0e10cSrcweir 
403cdf0e10cSrcweir {
404cdf0e10cSrcweir private:
405cdf0e10cSrcweir 	SfxViewShell*           _pViewSh;
406cdf0e10cSrcweir     PrinterSetupDialog*     _pSetupParent;
407cdf0e10cSrcweir 	SfxItemSet*             _pOptions;
408cdf0e10cSrcweir 	sal_Bool                _bModified;
409cdf0e10cSrcweir 	sal_Bool				_bHelpDisabled;
410cdf0e10cSrcweir 
411cdf0e10cSrcweir 	DECL_LINK( Execute, void * );
412cdf0e10cSrcweir 
413cdf0e10cSrcweir public:
414cdf0e10cSrcweir 			SfxDialogExecutor_Impl( SfxViewShell* pViewSh, PrinterSetupDialog* pParent );
~SfxDialogExecutor_Impl()415cdf0e10cSrcweir 			~SfxDialogExecutor_Impl() { delete _pOptions; }
416cdf0e10cSrcweir 
GetLink() const417cdf0e10cSrcweir 	Link				GetLink() const { return LINK( this, SfxDialogExecutor_Impl, Execute); }
GetOptions() const418cdf0e10cSrcweir 	const SfxItemSet*	GetOptions() const { return _pOptions; }
DisableHelp()419cdf0e10cSrcweir 	void				DisableHelp() { _bHelpDisabled = sal_True; }
420cdf0e10cSrcweir };
421cdf0e10cSrcweir 
422cdf0e10cSrcweir //--------------------------------------------------------------------
423cdf0e10cSrcweir 
SfxDialogExecutor_Impl(SfxViewShell * pViewSh,PrinterSetupDialog * pParent)424cdf0e10cSrcweir SfxDialogExecutor_Impl::SfxDialogExecutor_Impl( SfxViewShell* pViewSh, PrinterSetupDialog* pParent ) :
425cdf0e10cSrcweir 
426cdf0e10cSrcweir 	_pViewSh		( pViewSh ),
427cdf0e10cSrcweir 	_pSetupParent	( pParent ),
428cdf0e10cSrcweir 	_pOptions		( NULL ),
429cdf0e10cSrcweir 	_bModified		( sal_False ),
430cdf0e10cSrcweir 	_bHelpDisabled	( sal_False )
431cdf0e10cSrcweir 
432cdf0e10cSrcweir {
433cdf0e10cSrcweir }
434cdf0e10cSrcweir 
435cdf0e10cSrcweir //--------------------------------------------------------------------
436cdf0e10cSrcweir 
IMPL_LINK(SfxDialogExecutor_Impl,Execute,void *,EMPTYARG)437cdf0e10cSrcweir IMPL_LINK( SfxDialogExecutor_Impl, Execute, void *, EMPTYARG )
438cdf0e10cSrcweir {
439cdf0e10cSrcweir 	// Options lokal merken
440cdf0e10cSrcweir 	if ( !_pOptions )
441cdf0e10cSrcweir     {
442cdf0e10cSrcweir         DBG_ASSERT( _pSetupParent, "no dialog parent" );
443cdf0e10cSrcweir         if( _pSetupParent )
444cdf0e10cSrcweir             _pOptions = ( (SfxPrinter*)_pSetupParent->GetPrinter() )->GetOptions().Clone();
445cdf0e10cSrcweir     }
446cdf0e10cSrcweir 
447cdf0e10cSrcweir 	// Dialog ausf"uhren
448cdf0e10cSrcweir 	SfxPrintOptionsDialog* pDlg = new SfxPrintOptionsDialog( static_cast<Window*>(_pSetupParent),
449cdf0e10cSrcweir                                                              _pViewSh, _pOptions );
450cdf0e10cSrcweir 	if ( _bHelpDisabled )
451cdf0e10cSrcweir 		pDlg->DisableHelp();
452cdf0e10cSrcweir 	if ( pDlg->Execute() == RET_OK )
453cdf0e10cSrcweir 	{
454cdf0e10cSrcweir 		delete _pOptions;
455cdf0e10cSrcweir 		_pOptions = pDlg->GetOptions().Clone();
456cdf0e10cSrcweir 
457cdf0e10cSrcweir 	}
458cdf0e10cSrcweir 	delete pDlg;
459cdf0e10cSrcweir 
460cdf0e10cSrcweir 	return 0;
461cdf0e10cSrcweir }
462cdf0e10cSrcweir 
463cdf0e10cSrcweir //-------------------------------------------------------------------------
464cdf0e10cSrcweir 
UseStandardPrinter_Impl(Window *,SfxPrinter * pDocPrinter)465cdf0e10cSrcweir sal_Bool UseStandardPrinter_Impl( Window* /*pParent*/, SfxPrinter* pDocPrinter )
466cdf0e10cSrcweir {
467cdf0e10cSrcweir 	// Optionen abfragen, ob gewarnt werden soll (Doc uebersteuert App)
468cdf0e10cSrcweir 	sal_Bool bWarn = sal_False;
469cdf0e10cSrcweir 	const SfxItemSet *pDocOptions = &pDocPrinter->GetOptions();
470cdf0e10cSrcweir 	if ( pDocOptions )
471cdf0e10cSrcweir 	{
472cdf0e10cSrcweir 		sal_uInt16 nWhich = pDocOptions->GetPool()->GetWhich(SID_PRINTER_NOTFOUND_WARN);
473cdf0e10cSrcweir 		const SfxBoolItem* pBoolItem = NULL;
474cdf0e10cSrcweir 		pDocPrinter->GetOptions().GetItemState( nWhich, sal_False, (const SfxPoolItem**) &pBoolItem );
475cdf0e10cSrcweir 		if ( pBoolItem )
476cdf0e10cSrcweir 			bWarn = pBoolItem->GetValue();
477cdf0e10cSrcweir 	}
478cdf0e10cSrcweir /*
479cdf0e10cSrcweir 	// ggf. den User fragen
480cdf0e10cSrcweir 	if ( bWarn )
481cdf0e10cSrcweir 	{
482cdf0e10cSrcweir 		// Geht nicht mehr ohne OrigJobSetup!
483cdf0e10cSrcweir 		String aTmp( SfxResId( STR_PRINTER_NOTAVAIL ) );
484cdf0e10cSrcweir 		QueryBox aBox( pParent, WB_OK_CANCEL | WB_DEF_OK, aTmp );
485cdf0e10cSrcweir 		return RET_OK == aBox.Execute();
486cdf0e10cSrcweir 	}
487cdf0e10cSrcweir */
488cdf0e10cSrcweir 	// nicht gewarnt => einfach so den StandardDrucker nehmen
489cdf0e10cSrcweir 	return sal_True;
490cdf0e10cSrcweir }
491cdf0e10cSrcweir //-------------------------------------------------------------------------
492cdf0e10cSrcweir 
SetPrinter_Impl(SfxPrinter * pNewPrinter)493cdf0e10cSrcweir SfxPrinter* SfxViewShell::SetPrinter_Impl( SfxPrinter *pNewPrinter )
494cdf0e10cSrcweir 
495cdf0e10cSrcweir /*  Interne Methode zum Setzen der Unterschiede von 'pNewPrinter' zum
496cdf0e10cSrcweir 	aktuellen Printer. pNewPrinter wird entweder "ubernommen oder gel"oscht.
497cdf0e10cSrcweir */
498cdf0e10cSrcweir 
499cdf0e10cSrcweir {
500cdf0e10cSrcweir 	// aktuellen Printer holen
501cdf0e10cSrcweir 	SfxPrinter *pDocPrinter = GetPrinter();
502cdf0e10cSrcweir 
503cdf0e10cSrcweir 	// Printer-Options auswerten
504cdf0e10cSrcweir 	bool bOriToDoc = false;
505cdf0e10cSrcweir 	bool bSizeToDoc = false;
506cdf0e10cSrcweir 	if ( &pDocPrinter->GetOptions() )
507cdf0e10cSrcweir 	{
508cdf0e10cSrcweir         sal_uInt16 nWhich = GetPool().GetWhich(SID_PRINTER_CHANGESTODOC);
509cdf0e10cSrcweir         const SfxFlagItem *pFlagItem = 0;
510cdf0e10cSrcweir         pDocPrinter->GetOptions().GetItemState( nWhich, sal_False, (const SfxPoolItem**) &pFlagItem );
511cdf0e10cSrcweir         bOriToDoc = pFlagItem ? (pFlagItem->GetValue() & SFX_PRINTER_CHG_ORIENTATION) : sal_False;
512cdf0e10cSrcweir         bSizeToDoc = pFlagItem ? (pFlagItem->GetValue() & SFX_PRINTER_CHG_SIZE) : sal_False;
513cdf0e10cSrcweir 	}
514cdf0e10cSrcweir 
515cdf0e10cSrcweir 	// vorheriges Format und Size feststellen
516cdf0e10cSrcweir 	Orientation eOldOri = pDocPrinter->GetOrientation();
517cdf0e10cSrcweir 	Size aOldPgSz = pDocPrinter->GetPaperSizePixel();
518cdf0e10cSrcweir 
519cdf0e10cSrcweir 	// neues Format und Size feststellen
520cdf0e10cSrcweir 	Orientation eNewOri = pNewPrinter->GetOrientation();
521cdf0e10cSrcweir 	Size aNewPgSz = pNewPrinter->GetPaperSizePixel();
522cdf0e10cSrcweir 
523cdf0e10cSrcweir 	// "Anderungen am Seitenformat feststellen
524cdf0e10cSrcweir 	sal_Bool bOriChg = (eOldOri != eNewOri) && bOriToDoc;
525cdf0e10cSrcweir 	sal_Bool bPgSzChg = ( aOldPgSz.Height() !=
526cdf0e10cSrcweir 			( bOriChg ? aNewPgSz.Width() : aNewPgSz.Height() ) ||
527cdf0e10cSrcweir 			aOldPgSz.Width() !=
528cdf0e10cSrcweir 			( bOriChg ? aNewPgSz.Height() : aNewPgSz.Width() ) ) &&
529cdf0e10cSrcweir 			bSizeToDoc;
530cdf0e10cSrcweir 
531cdf0e10cSrcweir 	// Message und Flags f"ur Seitenformat-"Anderung zusammenstellen
532cdf0e10cSrcweir 	String aMsg;
533cdf0e10cSrcweir 	sal_uInt16 nNewOpt=0;
534cdf0e10cSrcweir 	if( bOriChg && bPgSzChg )
535cdf0e10cSrcweir 	{
536cdf0e10cSrcweir         aMsg = String(SfxResId(STR_PRINT_NEWORISIZE));
537cdf0e10cSrcweir         nNewOpt = SFX_PRINTER_CHG_ORIENTATION | SFX_PRINTER_CHG_SIZE;
538cdf0e10cSrcweir 	}
539cdf0e10cSrcweir 	else if (bOriChg )
540cdf0e10cSrcweir 	{
541cdf0e10cSrcweir         aMsg = String(SfxResId(STR_PRINT_NEWORI));
542cdf0e10cSrcweir         nNewOpt = SFX_PRINTER_CHG_ORIENTATION;
543cdf0e10cSrcweir 	}
544cdf0e10cSrcweir 	else if (bPgSzChg)
545cdf0e10cSrcweir 	{
546cdf0e10cSrcweir         aMsg = String(SfxResId(STR_PRINT_NEWSIZE));
547cdf0e10cSrcweir         nNewOpt = SFX_PRINTER_CHG_SIZE;
548cdf0e10cSrcweir 	}
549cdf0e10cSrcweir 
550cdf0e10cSrcweir 	// in dieser Variable sammeln, was sich so ge"aendert hat
551cdf0e10cSrcweir 	sal_uInt16 nChangedFlags = 0;
552cdf0e10cSrcweir 
553cdf0e10cSrcweir 	// ggf. Nachfrage, ob Seitenformat vom Drucker "ubernommen werden soll
554cdf0e10cSrcweir 	if ( ( bOriChg  || bPgSzChg ) &&
555cdf0e10cSrcweir 		RET_YES == QueryBox(0, WB_YES_NO | WB_DEF_OK, aMsg).Execute() )
556cdf0e10cSrcweir 	// Flags mit "Anderungen f"ur <SetPrinter(SfxPrinter*)> mitpflegen
557cdf0e10cSrcweir 	nChangedFlags |= nNewOpt;
558cdf0e10cSrcweir 
559cdf0e10cSrcweir 	// fuer den MAC sein "temporary of class String" im naechsten if()
560cdf0e10cSrcweir 	String aTempPrtName = pNewPrinter->GetName();
561cdf0e10cSrcweir 	String aDocPrtName = pDocPrinter->GetName();
562cdf0e10cSrcweir 
563cdf0e10cSrcweir 	// Wurde der Drucker gewechselt oder von Default auf Specific
564cdf0e10cSrcweir 	// oder umgekehrt geaendert?
565cdf0e10cSrcweir     if ( (aTempPrtName != aDocPrtName) || (pDocPrinter->IsDefPrinter() != pNewPrinter->IsDefPrinter()) )
566cdf0e10cSrcweir 	{
567cdf0e10cSrcweir         // neuen Printer "ubernehmen
568cdf0e10cSrcweir         // pNewPrinter->SetOrigJobSetup( pNewPrinter->GetJobSetup() );
569cdf0e10cSrcweir         nChangedFlags |= SFX_PRINTER_PRINTER|SFX_PRINTER_JOBSETUP;
570cdf0e10cSrcweir         pDocPrinter = pNewPrinter;
571cdf0e10cSrcweir 	}
572cdf0e10cSrcweir 	else
573cdf0e10cSrcweir 	{
574cdf0e10cSrcweir         // Extra-Optionen vergleichen
575cdf0e10cSrcweir         if ( ! (pNewPrinter->GetOptions() == pDocPrinter->GetOptions()) )
576cdf0e10cSrcweir         {
577cdf0e10cSrcweir             // Options haben sich geaendert
578cdf0e10cSrcweir             pDocPrinter->SetOptions( pNewPrinter->GetOptions() );
579cdf0e10cSrcweir             nChangedFlags |= SFX_PRINTER_OPTIONS;
580cdf0e10cSrcweir         }
581cdf0e10cSrcweir 
582cdf0e10cSrcweir         // JobSetups vergleichen
583cdf0e10cSrcweir         JobSetup aNewJobSetup = pNewPrinter->GetJobSetup();
584cdf0e10cSrcweir         JobSetup aOldJobSetup = pDocPrinter->GetJobSetup();
585cdf0e10cSrcweir         if ( aNewJobSetup != aOldJobSetup )
586cdf0e10cSrcweir         {
587cdf0e10cSrcweir             // JobSetup hat sich geaendert (=> App mu\s neu formatieren)
588cdf0e10cSrcweir             // pDocPrinter->SetOrigJobSetup( aNewJobSetup );
589cdf0e10cSrcweir             nChangedFlags |= SFX_PRINTER_JOBSETUP;
590cdf0e10cSrcweir         }
591cdf0e10cSrcweir 
592cdf0e10cSrcweir         // alten, ver"anderten Printer behalten
593cdf0e10cSrcweir         pDocPrinter->SetPrinterProps( pNewPrinter );
594cdf0e10cSrcweir         delete pNewPrinter;
595cdf0e10cSrcweir 	}
596cdf0e10cSrcweir 
597cdf0e10cSrcweir 	if ( 0 != nChangedFlags )
598cdf0e10cSrcweir         // SetPrinter will delete the old printer if it changes
599cdf0e10cSrcweir         SetPrinter( pDocPrinter, nChangedFlags );
600cdf0e10cSrcweir 	return pDocPrinter;
601cdf0e10cSrcweir }
602cdf0e10cSrcweir 
603cdf0e10cSrcweir //-------------------------------------------------------------------------
604cdf0e10cSrcweir // Unter WIN32 tritt leider das Problem auf, dass nichts gedruckt
605cdf0e10cSrcweir // wird, wenn SID_PRINTDOCDIRECT auflaueft; bisher bekannte,
606cdf0e10cSrcweir // einzige Abhilfe ist in diesem Fall das Abschalten der Optimierungen
607cdf0e10cSrcweir // (KA 17.12.95)
608cdf0e10cSrcweir #ifdef _MSC_VER
609cdf0e10cSrcweir #pragma optimize ( "", off )
610cdf0e10cSrcweir #endif
611cdf0e10cSrcweir 
ExecPrint(const uno::Sequence<beans::PropertyValue> & rProps,sal_Bool bIsAPI,sal_Bool bIsDirect)612cdf0e10cSrcweir void SfxViewShell::ExecPrint( const uno::Sequence < beans::PropertyValue >& rProps, sal_Bool bIsAPI, sal_Bool bIsDirect )
613cdf0e10cSrcweir {
614cdf0e10cSrcweir 	// get the current selection; our controller should know it
615cdf0e10cSrcweir     Reference< frame::XController > xController( GetController() );
616cdf0e10cSrcweir     Reference< view::XSelectionSupplier > xSupplier( xController, UNO_QUERY );
617cdf0e10cSrcweir 
618cdf0e10cSrcweir     Any aSelection;
619cdf0e10cSrcweir     if( xSupplier.is() )
620cdf0e10cSrcweir         aSelection = xSupplier->getSelection();
621cdf0e10cSrcweir     else
622cdf0e10cSrcweir         aSelection <<= GetObjectShell()->GetModel();
623cdf0e10cSrcweir     Any aComplete( makeAny( GetObjectShell()->GetModel() ) );
624cdf0e10cSrcweir     Any aViewProp( makeAny( xController ) );
625cdf0e10cSrcweir     boost::shared_ptr<Printer> aPrt;
626cdf0e10cSrcweir 
627cdf0e10cSrcweir     const beans::PropertyValue* pVal = rProps.getConstArray();
628cdf0e10cSrcweir     for( sal_Int32 i = 0; i < rProps.getLength(); i++ )
629cdf0e10cSrcweir     {
630cdf0e10cSrcweir         if( pVal[i].Name.equalsAscii( "PrinterName" ) )
631cdf0e10cSrcweir         {
632cdf0e10cSrcweir             rtl::OUString aPrinterName;
633cdf0e10cSrcweir             pVal[i].Value >>= aPrinterName;
634cdf0e10cSrcweir             aPrt.reset( new Printer( aPrinterName ) );
635cdf0e10cSrcweir             break;
636cdf0e10cSrcweir         }
637cdf0e10cSrcweir     }
638cdf0e10cSrcweir 
639cdf0e10cSrcweir     boost::shared_ptr<vcl::PrinterController> pController( new SfxPrinterController(
640cdf0e10cSrcweir                                                                                aPrt,
641cdf0e10cSrcweir                                                                                aComplete,
642cdf0e10cSrcweir                                                                                aSelection,
643cdf0e10cSrcweir                                                                                aViewProp,
644cdf0e10cSrcweir                                                                                GetRenderable(),
645cdf0e10cSrcweir                                                                                bIsAPI,
646cdf0e10cSrcweir                                                                                bIsDirect,
647cdf0e10cSrcweir 																			   this,
648cdf0e10cSrcweir                                                                                rProps
649cdf0e10cSrcweir                                                                                ) );
650cdf0e10cSrcweir     pImp->m_pPrinterController = pController;
651cdf0e10cSrcweir 
652cdf0e10cSrcweir     SfxObjectShell *pObjShell = GetObjectShell();
653cdf0e10cSrcweir     pController->setValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "JobName" ) ),
654cdf0e10cSrcweir                         makeAny( rtl::OUString( pObjShell->GetTitle(0) ) ) );
655cdf0e10cSrcweir 
656cdf0e10cSrcweir     // FIXME: job setup
657cdf0e10cSrcweir     SfxPrinter* pDocPrt = GetPrinter(sal_False);
658cdf0e10cSrcweir     JobSetup aJobSetup = pDocPrt ? pDocPrt->GetJobSetup() : GetJobSetup();
659cdf0e10cSrcweir     if( bIsDirect )
660cdf0e10cSrcweir         aJobSetup.SetValue( String( RTL_CONSTASCII_USTRINGPARAM( "IsQuickJob" ) ),
661cdf0e10cSrcweir                             String( RTL_CONSTASCII_USTRINGPARAM( "true" ) ) );
662cdf0e10cSrcweir 
663cdf0e10cSrcweir     Printer::PrintJob( pController, aJobSetup );
664cdf0e10cSrcweir }
665cdf0e10cSrcweir 
GetActivePrinter() const666cdf0e10cSrcweir Printer* SfxViewShell::GetActivePrinter() const
667cdf0e10cSrcweir {
668cdf0e10cSrcweir     return (pImp->m_pPrinterController)
669cdf0e10cSrcweir         ?  pImp->m_pPrinterController->getPrinter().get() : 0;
670cdf0e10cSrcweir }
671cdf0e10cSrcweir 
ExecPrint_Impl(SfxRequest & rReq)672cdf0e10cSrcweir void SfxViewShell::ExecPrint_Impl( SfxRequest &rReq )
673cdf0e10cSrcweir {
674cdf0e10cSrcweir 	// sal_uInt16                  nCopies=1;
675cdf0e10cSrcweir 	sal_uInt16                  nDialogRet = RET_CANCEL;
676cdf0e10cSrcweir 	// sal_Bool                    bCollate=sal_False;
677cdf0e10cSrcweir 	SfxPrinter*             pPrinter = 0;
678cdf0e10cSrcweir 	SfxDialogExecutor_Impl* pExecutor = 0;
679cdf0e10cSrcweir 	bool                    bSilent = false;
680cdf0e10cSrcweir     sal_Bool bIsAPI = rReq.GetArgs() && rReq.GetArgs()->Count();
681cdf0e10cSrcweir 	if ( bIsAPI )
682cdf0e10cSrcweir 	{
683cdf0e10cSrcweir 		SFX_REQUEST_ARG(rReq, pSilentItem, SfxBoolItem, SID_SILENT, sal_False);
684cdf0e10cSrcweir 		bSilent = pSilentItem && pSilentItem->GetValue();
685cdf0e10cSrcweir 	}
686cdf0e10cSrcweir 
687cdf0e10cSrcweir 	//FIXME: how to transport "bPrintOnHelp"?
688cdf0e10cSrcweir 
689cdf0e10cSrcweir     // no help button in dialogs if called from the help window
690cdf0e10cSrcweir     // (pressing help button would exchange the current page inside the help document that is going to be printed!)
691cdf0e10cSrcweir 	String aHelpFilterName( DEFINE_CONST_UNICODE("writer_web_HTML_help") );
692cdf0e10cSrcweir 	SfxMedium* pMedium = GetViewFrame()->GetObjectShell()->GetMedium();
693cdf0e10cSrcweir 	const SfxFilter* pFilter = pMedium ? pMedium->GetFilter() : NULL;
694cdf0e10cSrcweir 	sal_Bool bPrintOnHelp = ( pFilter && pFilter->GetFilterName() == aHelpFilterName );
695cdf0e10cSrcweir 
696cdf0e10cSrcweir 	const sal_uInt16 nId = rReq.GetSlot();
697cdf0e10cSrcweir 	switch( nId )
698cdf0e10cSrcweir 	{
699cdf0e10cSrcweir 		// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
700cdf0e10cSrcweir 		case SID_PRINTDOC:
701cdf0e10cSrcweir 		case SID_PRINTDOCDIRECT:
702cdf0e10cSrcweir         {
703cdf0e10cSrcweir 			SfxObjectShell* pDoc = GetObjectShell();
704cdf0e10cSrcweir 
705cdf0e10cSrcweir             // derived class may decide to abort this
706cdf0e10cSrcweir             if( !pDoc->QuerySlotExecutable( nId ) )
707cdf0e10cSrcweir             {
708cdf0e10cSrcweir                 rReq.SetReturnValue( SfxBoolItem( 0, sal_False ) );
709cdf0e10cSrcweir                 return;
710cdf0e10cSrcweir             }
711cdf0e10cSrcweir 
712cdf0e10cSrcweir 			bool bDetectHidden = ( !bSilent && pDoc );
713cdf0e10cSrcweir 			if ( bDetectHidden && pDoc->QueryHiddenInformation( WhenPrinting, NULL ) != RET_YES )
714cdf0e10cSrcweir 				break;
715cdf0e10cSrcweir 
716cdf0e10cSrcweir             SFX_REQUEST_ARG(rReq, pSelectItem, SfxBoolItem, SID_SELECTION, sal_False);
717cdf0e10cSrcweir             sal_Bool bSelection = pSelectItem && pSelectItem->GetValue();
718cdf0e10cSrcweir             if( pSelectItem && rReq.GetArgs()->Count() == 1 )
719cdf0e10cSrcweir                 bIsAPI = sal_False;
720cdf0e10cSrcweir 
721cdf0e10cSrcweir 			uno::Sequence < beans::PropertyValue > aProps;
722cdf0e10cSrcweir 			if ( bIsAPI )
723cdf0e10cSrcweir             {
724cdf0e10cSrcweir                 // supported properties:
725cdf0e10cSrcweir 			    // String PrinterName
726cdf0e10cSrcweir 			    // String FileName
727cdf0e10cSrcweir 			    // Int16 From
728cdf0e10cSrcweir 			    // Int16 To
729cdf0e10cSrcweir 			    // In16 Copies
730cdf0e10cSrcweir 			    // String RangeText
731cdf0e10cSrcweir 			    // bool Selection
732cdf0e10cSrcweir 			    // bool Asynchron
733cdf0e10cSrcweir 			    // bool Collate
734cdf0e10cSrcweir 			    // bool Silent
735cdf0e10cSrcweir 			    TransformItems( nId, *rReq.GetArgs(), aProps, GetInterface()->GetSlot(nId) );
736cdf0e10cSrcweir 			    for ( sal_Int32 nProp=0; nProp<aProps.getLength(); nProp++ )
737cdf0e10cSrcweir 			    {
738cdf0e10cSrcweir 				    if ( aProps[nProp].Name.equalsAscii("Copies") )
739cdf0e10cSrcweir 					    aProps[nProp]. Name = rtl::OUString::createFromAscii("CopyCount");
740cdf0e10cSrcweir 				    else if ( aProps[nProp].Name.equalsAscii("RangeText") )
741cdf0e10cSrcweir 					    aProps[nProp]. Name = rtl::OUString::createFromAscii("Pages");
742cdf0e10cSrcweir 				    if ( aProps[nProp].Name.equalsAscii("Asynchron") )
743cdf0e10cSrcweir 				    {
744cdf0e10cSrcweir 					    aProps[nProp]. Name = rtl::OUString::createFromAscii("Wait");
745cdf0e10cSrcweir 					    sal_Bool bAsynchron = sal_False;
746cdf0e10cSrcweir 					    aProps[nProp].Value >>= bAsynchron;
747cdf0e10cSrcweir 					    aProps[nProp].Value <<= (sal_Bool) (!bAsynchron);
748cdf0e10cSrcweir 				    }
749cdf0e10cSrcweir 				    if ( aProps[nProp].Name.equalsAscii("Silent") )
750cdf0e10cSrcweir 				    {
751cdf0e10cSrcweir 					    aProps[nProp]. Name = rtl::OUString::createFromAscii("MonitorVisible");
752cdf0e10cSrcweir 					    sal_Bool bPrintSilent = sal_False;
753cdf0e10cSrcweir 					    aProps[nProp].Value >>= bPrintSilent;
754cdf0e10cSrcweir 					    aProps[nProp].Value <<= (sal_Bool) (!bPrintSilent);
755cdf0e10cSrcweir 				    }
756cdf0e10cSrcweir 			    }
757cdf0e10cSrcweir             }
758cdf0e10cSrcweir             // HACK: writer sets the SID_SELECTION item when printing directly and expects
759cdf0e10cSrcweir             // to get only the selection document in that case (see getSelectionObject)
760cdf0e10cSrcweir             // however it also reacts to the PrintContent property. We need this distinction here, too,
761cdf0e10cSrcweir             // else one of the combinations print / print direct and selection / all will not work.
762cdf0e10cSrcweir             // it would be better if writer handled this internally
763cdf0e10cSrcweir             if( nId == SID_PRINTDOCDIRECT )
764cdf0e10cSrcweir             {
765cdf0e10cSrcweir                 sal_Int32 nLen = aProps.getLength();
766cdf0e10cSrcweir                 aProps.realloc( nLen + 1 );
767cdf0e10cSrcweir                 aProps[nLen].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrintSelectionOnly" ) );
768cdf0e10cSrcweir                 aProps[nLen].Value = makeAny( bSelection );
769cdf0e10cSrcweir             }
770cdf0e10cSrcweir 
771cdf0e10cSrcweir 			ExecPrint( aProps, bIsAPI, (nId == SID_PRINTDOCDIRECT) );
772cdf0e10cSrcweir 
773cdf0e10cSrcweir 			// FIXME: Recording
774cdf0e10cSrcweir 			rReq.Done();
775cdf0e10cSrcweir 	        break;
776cdf0e10cSrcweir         }
777cdf0e10cSrcweir 
778cdf0e10cSrcweir 		case SID_SETUPPRINTER :
779cdf0e10cSrcweir 	    case SID_PRINTER_NAME : // only for recorded macros
780cdf0e10cSrcweir 		{
781cdf0e10cSrcweir 	        // get printer and printer settings from the document
782cdf0e10cSrcweir 			SfxPrinter *pDocPrinter = GetPrinter(sal_True);
783cdf0e10cSrcweir 
784cdf0e10cSrcweir 	        // look for printer in parameters
785cdf0e10cSrcweir 	        SFX_REQUEST_ARG( rReq, pPrinterItem, SfxStringItem, SID_PRINTER_NAME, sal_False );
786cdf0e10cSrcweir 			if ( pPrinterItem )
787cdf0e10cSrcweir 			{
788cdf0e10cSrcweir 	            // use PrinterName parameter to create a printer
789cdf0e10cSrcweir 	            pPrinter = new SfxPrinter( pDocPrinter->GetOptions().Clone(), ((const SfxStringItem*) pPrinterItem)->GetValue() );
790cdf0e10cSrcweir 
791cdf0e10cSrcweir 	            // if printer is unknown, it can't be used - now printer from document will be used
792cdf0e10cSrcweir 				if ( !pPrinter->IsOriginal() )
793cdf0e10cSrcweir 					DELETEZ(pPrinter);
794cdf0e10cSrcweir 			}
795cdf0e10cSrcweir 
796cdf0e10cSrcweir 	        if ( SID_PRINTER_NAME == nId )
797cdf0e10cSrcweir 	        {
798cdf0e10cSrcweir 	            // just set a recorded printer name
799cdf0e10cSrcweir 	            if ( pPrinter )
800cdf0e10cSrcweir 	                SetPrinter( pPrinter, SFX_PRINTER_PRINTER  );
801cdf0e10cSrcweir 	            break;
802cdf0e10cSrcweir 	        }
803cdf0e10cSrcweir 
804cdf0e10cSrcweir 	        // no PrinterName parameter in ItemSet or the PrinterName points to an unknown printer
805cdf0e10cSrcweir 	        if ( !pPrinter )
806cdf0e10cSrcweir 	            // use default printer from document
807cdf0e10cSrcweir 				pPrinter = pDocPrinter;
808cdf0e10cSrcweir 
809cdf0e10cSrcweir 	        if( !pPrinter || !pPrinter->IsValid() )
810cdf0e10cSrcweir 			{
811cdf0e10cSrcweir 	            // no valid printer either in ItemSet or at the document
812cdf0e10cSrcweir 	            if ( bSilent )
813cdf0e10cSrcweir 				{
814cdf0e10cSrcweir 				    rReq.SetReturnValue(SfxBoolItem(0,sal_False));
815cdf0e10cSrcweir 				    break;
816cdf0e10cSrcweir 				}
817cdf0e10cSrcweir 	            else
818cdf0e10cSrcweir 	                ErrorBox( NULL, WB_OK | WB_DEF_OK, String( SfxResId( STR_NODEFPRINTER ) ) ).Execute();
819cdf0e10cSrcweir 			}
820cdf0e10cSrcweir 
821cdf0e10cSrcweir 	        if ( !pPrinter->IsOriginal() && rReq.GetArgs() && !UseStandardPrinter_Impl( NULL, pPrinter ) )
822cdf0e10cSrcweir 			{
823cdf0e10cSrcweir 	            // printer is not available, but standard printer should not be used
824cdf0e10cSrcweir 				rReq.SetReturnValue(SfxBoolItem(0,sal_False));
825cdf0e10cSrcweir 				break;
826cdf0e10cSrcweir 			}
827cdf0e10cSrcweir 
828cdf0e10cSrcweir 			// FIXME: printer isn't used for printing anymore!
829cdf0e10cSrcweir 			if( pPrinter->IsPrinting() )
830cdf0e10cSrcweir 			{
831cdf0e10cSrcweir 	            // if printer is busy, abort printing
832cdf0e10cSrcweir 	            if ( !bSilent )
833cdf0e10cSrcweir 					InfoBox( NULL, String( SfxResId( STR_ERROR_PRINTER_BUSY ) ) ).Execute();
834cdf0e10cSrcweir 				rReq.SetReturnValue(SfxBoolItem(0,sal_False));
835cdf0e10cSrcweir 				break;
836cdf0e10cSrcweir 			}
837cdf0e10cSrcweir 
838cdf0e10cSrcweir 	        // if no arguments are given, retrieve them from a dialog
839cdf0e10cSrcweir 	        if ( !bIsAPI )
840cdf0e10cSrcweir 			{
841cdf0e10cSrcweir 	            // PrinterDialog needs a temporary printer
842cdf0e10cSrcweir 				SfxPrinter* pDlgPrinter = pPrinter->Clone();
843cdf0e10cSrcweir 				nDialogRet = 0;
844cdf0e10cSrcweir 
845cdf0e10cSrcweir                 // execute PrinterSetupDialog
846cdf0e10cSrcweir                 PrinterSetupDialog* pPrintSetupDlg = new PrinterSetupDialog( GetWindow() );
847cdf0e10cSrcweir 
848cdf0e10cSrcweir                 if (pImp->m_bHasPrintOptions)
849cdf0e10cSrcweir                 {
850cdf0e10cSrcweir                     // additional controls for dialog
851cdf0e10cSrcweir                     pExecutor = new SfxDialogExecutor_Impl( this, pPrintSetupDlg );
852cdf0e10cSrcweir                     if ( bPrintOnHelp )
853cdf0e10cSrcweir                         pExecutor->DisableHelp();
854cdf0e10cSrcweir                     pPrintSetupDlg->SetOptionsHdl( pExecutor->GetLink() );
855cdf0e10cSrcweir                 }
856cdf0e10cSrcweir 
857cdf0e10cSrcweir 				pPrintSetupDlg->SetPrinter( pDlgPrinter );
858cdf0e10cSrcweir 				nDialogRet = pPrintSetupDlg->Execute();
859cdf0e10cSrcweir 
860cdf0e10cSrcweir                 if ( pExecutor && pExecutor->GetOptions() )
861cdf0e10cSrcweir                 {
862cdf0e10cSrcweir                     if ( nDialogRet == RET_OK )
863cdf0e10cSrcweir                         // remark: have to be recorded if possible!
864cdf0e10cSrcweir                         pDlgPrinter->SetOptions( *pExecutor->GetOptions() );
865cdf0e10cSrcweir                     else
866cdf0e10cSrcweir                     {
867cdf0e10cSrcweir                         pPrinter->SetOptions( *pExecutor->GetOptions() );
868cdf0e10cSrcweir                         SetPrinter( pPrinter, SFX_PRINTER_OPTIONS );
869cdf0e10cSrcweir                     }
870cdf0e10cSrcweir                 }
871cdf0e10cSrcweir 
872cdf0e10cSrcweir                 DELETEZ( pPrintSetupDlg );
873cdf0e10cSrcweir 
874cdf0e10cSrcweir                 // no recording of PrinterSetup except printer name (is printer dependent)
875cdf0e10cSrcweir                 rReq.Ignore();
876cdf0e10cSrcweir 
877cdf0e10cSrcweir 				if ( nDialogRet == RET_OK )
878cdf0e10cSrcweir 				{
879cdf0e10cSrcweir 	                if ( pPrinter->GetName() != pDlgPrinter->GetName() )
880cdf0e10cSrcweir 	                {
881cdf0e10cSrcweir 	                    // user has changed the printer -> macro recording
882cdf0e10cSrcweir 	                    SfxRequest aReq( GetViewFrame(), SID_PRINTER_NAME );
883cdf0e10cSrcweir 	                    aReq.AppendItem( SfxStringItem( SID_PRINTER_NAME, pDlgPrinter->GetName() ) );
884cdf0e10cSrcweir 	                    aReq.Done();
885cdf0e10cSrcweir 	                }
886cdf0e10cSrcweir 
887cdf0e10cSrcweir 	                // take the changes made in the dialog
888cdf0e10cSrcweir 					pPrinter = SetPrinter_Impl( pDlgPrinter );
889cdf0e10cSrcweir 
890cdf0e10cSrcweir 	                // forget new printer, it was taken over (as pPrinter) or deleted
891cdf0e10cSrcweir 	                pDlgPrinter = NULL;
892cdf0e10cSrcweir 
893cdf0e10cSrcweir 				}
894cdf0e10cSrcweir 				else
895cdf0e10cSrcweir 	            {
896cdf0e10cSrcweir 	                // PrinterDialog is used to transfer information on printing,
897cdf0e10cSrcweir 	                // so it will only be deleted here if dialog was cancelled
898cdf0e10cSrcweir 	                DELETEZ( pDlgPrinter );
899cdf0e10cSrcweir 	                rReq.Ignore();
900cdf0e10cSrcweir 					if ( SID_PRINTDOC == nId )
901cdf0e10cSrcweir 	                    rReq.SetReturnValue(SfxBoolItem(0,sal_False));
902cdf0e10cSrcweir 	            }
903cdf0e10cSrcweir 			}
904cdf0e10cSrcweir 		}
905cdf0e10cSrcweir 
906cdf0e10cSrcweir         break;
907cdf0e10cSrcweir 	}
908cdf0e10cSrcweir }
909cdf0e10cSrcweir 
910cdf0e10cSrcweir // Optimierungen wieder einschalten
911cdf0e10cSrcweir #ifdef _MSC_VER
912cdf0e10cSrcweir #pragma optimize ( "", on )
913cdf0e10cSrcweir #endif
914cdf0e10cSrcweir 
915cdf0e10cSrcweir //--------------------------------------------------------------------
916cdf0e10cSrcweir 
IsPrinterLocked() const917cdf0e10cSrcweir sal_Bool SfxViewShell::IsPrinterLocked() const
918cdf0e10cSrcweir {
919cdf0e10cSrcweir     return pImp->m_nPrinterLocks > 0;
920cdf0e10cSrcweir }
921cdf0e10cSrcweir 
922cdf0e10cSrcweir //--------------------------------------------------------------------
923cdf0e10cSrcweir 
LockPrinter(sal_Bool bLock)924cdf0e10cSrcweir void SfxViewShell::LockPrinter( sal_Bool bLock)
925cdf0e10cSrcweir {
926cdf0e10cSrcweir 	sal_Bool bChanged = sal_False;
927cdf0e10cSrcweir 	if ( bLock )
928cdf0e10cSrcweir     {
929cdf0e10cSrcweir         bChanged = 1 == ++pImp->m_nPrinterLocks;
930cdf0e10cSrcweir     }
931cdf0e10cSrcweir 	else
932cdf0e10cSrcweir     {
933cdf0e10cSrcweir         bChanged = 0 == --pImp->m_nPrinterLocks;
934cdf0e10cSrcweir     }
935cdf0e10cSrcweir 
936cdf0e10cSrcweir 	if ( bChanged )
937cdf0e10cSrcweir 	{
938cdf0e10cSrcweir 		Invalidate( SID_PRINTDOC );
939cdf0e10cSrcweir 		Invalidate( SID_PRINTDOCDIRECT );
940cdf0e10cSrcweir 		Invalidate( SID_SETUPPRINTER );
941cdf0e10cSrcweir 	}
942cdf0e10cSrcweir }
943cdf0e10cSrcweir 
944cdf0e10cSrcweir //--------------------------------------------------------------------
945cdf0e10cSrcweir 
GetPrinter(sal_Bool)946cdf0e10cSrcweir SfxPrinter* SfxViewShell::GetPrinter( sal_Bool /*bCreate*/ )
947cdf0e10cSrcweir {
948cdf0e10cSrcweir 	return 0;
949cdf0e10cSrcweir }
950cdf0e10cSrcweir 
951cdf0e10cSrcweir //--------------------------------------------------------------------
952cdf0e10cSrcweir 
SetPrinter(SfxPrinter *,sal_uInt16,bool)953cdf0e10cSrcweir sal_uInt16 SfxViewShell::SetPrinter( SfxPrinter* /*pNewPrinter*/, sal_uInt16 /*nDiffFlags*/, bool )
954cdf0e10cSrcweir {
955cdf0e10cSrcweir 	return 0;
956cdf0e10cSrcweir }
957cdf0e10cSrcweir 
958cdf0e10cSrcweir //--------------------------------------------------------------------
959cdf0e10cSrcweir 
CreatePrintOptionsPage(Window *,const SfxItemSet &)960cdf0e10cSrcweir SfxTabPage* SfxViewShell::CreatePrintOptionsPage
961cdf0e10cSrcweir (
962cdf0e10cSrcweir 	Window*             /*pParent*/,
963cdf0e10cSrcweir 	const SfxItemSet&   /*rOptions*/
964cdf0e10cSrcweir )
965cdf0e10cSrcweir {
966cdf0e10cSrcweir 	return 0;
967cdf0e10cSrcweir }
968cdf0e10cSrcweir 
GetJobSetup() const969cdf0e10cSrcweir JobSetup SfxViewShell::GetJobSetup() const
970cdf0e10cSrcweir {
971cdf0e10cSrcweir 	return JobSetup();
972cdf0e10cSrcweir }
973cdf0e10cSrcweir 
974