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