xref: /AOO41X/main/basctl/source/basicide/basicrenderable.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir #include "precompiled_basctl.hxx"
28*cdf0e10cSrcweir 
29*cdf0e10cSrcweir #include "basicrenderable.hxx"
30*cdf0e10cSrcweir #include "bastypes.hxx"
31*cdf0e10cSrcweir #include "basidesh.hrc"
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include "com/sun/star/awt/XDevice.hpp"
34*cdf0e10cSrcweir #include "toolkit/awt/vclxdevice.hxx"
35*cdf0e10cSrcweir #include "vcl/print.hxx"
36*cdf0e10cSrcweir #include "tools/multisel.hxx"
37*cdf0e10cSrcweir #include "tools/resary.hxx"
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir using namespace com::sun::star;
40*cdf0e10cSrcweir using namespace com::sun::star::uno;
41*cdf0e10cSrcweir using namespace basicide;
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir BasicRenderable::BasicRenderable( IDEBaseWindow* pWin )
44*cdf0e10cSrcweir : cppu::WeakComponentImplHelper1< com::sun::star::view::XRenderable >( maMutex )
45*cdf0e10cSrcweir , mpWindow( pWin )
46*cdf0e10cSrcweir {
47*cdf0e10cSrcweir     ResStringArray aStrings( IDEResId( RID_PRINTDLG_STRLIST )  );
48*cdf0e10cSrcweir     DBG_ASSERT( aStrings.Count() >= 3, "resource incomplete" );
49*cdf0e10cSrcweir     if( aStrings.Count() < 3 ) // bad resource ?
50*cdf0e10cSrcweir         return;
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir     m_aUIProperties.realloc( 3 );
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir     // create Subgroup for print range
55*cdf0e10cSrcweir     vcl::PrinterOptionsHelper::UIControlOptions aPrintRangeOpt;
56*cdf0e10cSrcweir     aPrintRangeOpt.maGroupHint = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrintRange" ) );
57*cdf0e10cSrcweir     aPrintRangeOpt.mbInternalOnly = sal_True;
58*cdf0e10cSrcweir     m_aUIProperties[0].Value = getSubgroupControlOpt( rtl::OUString( aStrings.GetString( 0 ) ),
59*cdf0e10cSrcweir                                                       rtl::OUString(),
60*cdf0e10cSrcweir                                                       aPrintRangeOpt
61*cdf0e10cSrcweir                                                       );
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir     // create a choice for the range to print
64*cdf0e10cSrcweir     rtl::OUString aPrintContentName( RTL_CONSTASCII_USTRINGPARAM( "PrintContent" ) );
65*cdf0e10cSrcweir     Sequence< rtl::OUString > aChoices( 2 );
66*cdf0e10cSrcweir     Sequence< rtl::OUString > aHelpIds( 2 );
67*cdf0e10cSrcweir     aChoices[0] = aStrings.GetString( 1 );
68*cdf0e10cSrcweir     aHelpIds[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".HelpID:vcl:PrintDialog:PrintContent:RadioButton:0" ) );
69*cdf0e10cSrcweir     aChoices[1] = aStrings.GetString( 2 );
70*cdf0e10cSrcweir     aHelpIds[1] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".HelpID:vcl:PrintDialog:PrintContent:RadioButton:1" ) );
71*cdf0e10cSrcweir     m_aUIProperties[1].Value = getChoiceControlOpt( rtl::OUString(),
72*cdf0e10cSrcweir                                                     aHelpIds,
73*cdf0e10cSrcweir                                                     aPrintContentName,
74*cdf0e10cSrcweir                                                     aChoices,
75*cdf0e10cSrcweir                                                     0 );
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir     // create a an Edit dependent on "Pages" selected
78*cdf0e10cSrcweir     vcl::PrinterOptionsHelper::UIControlOptions aPageRangeOpt( aPrintContentName, 1, sal_True );
79*cdf0e10cSrcweir     m_aUIProperties[2].Value = getEditControlOpt( rtl::OUString(),
80*cdf0e10cSrcweir                                                   rtl::OUString(),
81*cdf0e10cSrcweir                                                   rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PageRange" ) ),
82*cdf0e10cSrcweir                                                   rtl::OUString(),
83*cdf0e10cSrcweir                                                   aPageRangeOpt
84*cdf0e10cSrcweir                                                   );
85*cdf0e10cSrcweir }
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir BasicRenderable::~BasicRenderable()
88*cdf0e10cSrcweir {
89*cdf0e10cSrcweir }
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir Printer* BasicRenderable::getPrinter()
92*cdf0e10cSrcweir {
93*cdf0e10cSrcweir     Printer* pPrinter = NULL;
94*cdf0e10cSrcweir     Any aValue( getValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "RenderDevice" ) ) ) );
95*cdf0e10cSrcweir     Reference<awt::XDevice> xRenderDevice;
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir     if( aValue >>= xRenderDevice )
98*cdf0e10cSrcweir     {
99*cdf0e10cSrcweir         VCLXDevice* pDevice = VCLXDevice::GetImplementation(xRenderDevice);
100*cdf0e10cSrcweir         OutputDevice* pOut = pDevice ? pDevice->GetOutputDevice() : NULL;
101*cdf0e10cSrcweir         pPrinter = dynamic_cast<Printer*>(pOut);
102*cdf0e10cSrcweir     }
103*cdf0e10cSrcweir     return pPrinter;
104*cdf0e10cSrcweir }
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir sal_Int32 SAL_CALL BasicRenderable::getRendererCount (
107*cdf0e10cSrcweir         const Any&, const Sequence<beans::PropertyValue >& i_xOptions
108*cdf0e10cSrcweir         ) throw (lang::IllegalArgumentException, RuntimeException)
109*cdf0e10cSrcweir {
110*cdf0e10cSrcweir     processProperties( i_xOptions );
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir     sal_Int32 nCount = 0;
113*cdf0e10cSrcweir     if( mpWindow )
114*cdf0e10cSrcweir     {
115*cdf0e10cSrcweir         Printer* pPrinter = getPrinter();
116*cdf0e10cSrcweir         if( pPrinter )
117*cdf0e10cSrcweir         {
118*cdf0e10cSrcweir             nCount = mpWindow->countPages( pPrinter );
119*cdf0e10cSrcweir             sal_Int64 nContent = getIntValue( "PrintContent", -1 );
120*cdf0e10cSrcweir             if( nContent == 1 )
121*cdf0e10cSrcweir             {
122*cdf0e10cSrcweir                 rtl::OUString aPageRange( getStringValue( "PageRange" ) );
123*cdf0e10cSrcweir                 MultiSelection aSel( aPageRange );
124*cdf0e10cSrcweir                 long nSelCount = aSel.GetSelectCount();
125*cdf0e10cSrcweir                 if( nSelCount >= 0 && nSelCount < nCount )
126*cdf0e10cSrcweir                     nCount = nSelCount;
127*cdf0e10cSrcweir             }
128*cdf0e10cSrcweir         }
129*cdf0e10cSrcweir         else
130*cdf0e10cSrcweir             throw lang::IllegalArgumentException();
131*cdf0e10cSrcweir     }
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir     return nCount;
134*cdf0e10cSrcweir }
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir Sequence<beans::PropertyValue> SAL_CALL BasicRenderable::getRenderer (
137*cdf0e10cSrcweir         sal_Int32, const Any&, const Sequence<beans::PropertyValue>& i_xOptions
138*cdf0e10cSrcweir         ) throw (lang::IllegalArgumentException, RuntimeException)
139*cdf0e10cSrcweir {
140*cdf0e10cSrcweir     processProperties( i_xOptions );
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir     Sequence< beans::PropertyValue > aVals;
143*cdf0e10cSrcweir     // insert page size here
144*cdf0e10cSrcweir     Printer* pPrinter = getPrinter();
145*cdf0e10cSrcweir     // no renderdevice is legal; the first call is to get our print ui options
146*cdf0e10cSrcweir     if( pPrinter )
147*cdf0e10cSrcweir     {
148*cdf0e10cSrcweir         Size aPageSize( pPrinter->PixelToLogic( pPrinter->GetPaperSizePixel(), MapMode( MAP_100TH_MM ) ) );
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir         aVals.realloc( 1 );
151*cdf0e10cSrcweir         aVals[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PageSize" ) );
152*cdf0e10cSrcweir         awt::Size aSize;
153*cdf0e10cSrcweir         aSize.Width  = aPageSize.Width();
154*cdf0e10cSrcweir         aSize.Height = aPageSize.Height();
155*cdf0e10cSrcweir         aVals[0].Value <<= aSize;
156*cdf0e10cSrcweir     }
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir     appendPrintUIOptions( aVals );
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir     return aVals;
161*cdf0e10cSrcweir }
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir void SAL_CALL BasicRenderable::render (
164*cdf0e10cSrcweir         sal_Int32 nRenderer, const Any&,
165*cdf0e10cSrcweir         const Sequence<beans::PropertyValue>& i_xOptions
166*cdf0e10cSrcweir         ) throw (lang::IllegalArgumentException, RuntimeException)
167*cdf0e10cSrcweir {
168*cdf0e10cSrcweir     processProperties( i_xOptions );
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir     if( mpWindow )
171*cdf0e10cSrcweir     {
172*cdf0e10cSrcweir         Printer* pPrinter = getPrinter();
173*cdf0e10cSrcweir         if( pPrinter )
174*cdf0e10cSrcweir         {
175*cdf0e10cSrcweir             sal_Int64 nContent = getIntValue( "PrintContent", -1 );
176*cdf0e10cSrcweir             if( nContent == 1 )
177*cdf0e10cSrcweir             {
178*cdf0e10cSrcweir                 rtl::OUString aPageRange( getStringValue( "PageRange" ) );
179*cdf0e10cSrcweir                 MultiSelection aSel( aPageRange );
180*cdf0e10cSrcweir                 long nSelect = aSel.FirstSelected();
181*cdf0e10cSrcweir                 while( nSelect != long(SFX_ENDOFSELECTION) && nRenderer-- )
182*cdf0e10cSrcweir                     nSelect = aSel.NextSelected();
183*cdf0e10cSrcweir                 if( nSelect != long(SFX_ENDOFSELECTION) )
184*cdf0e10cSrcweir                     mpWindow->printPage( sal_Int32(nSelect-1), pPrinter );
185*cdf0e10cSrcweir             }
186*cdf0e10cSrcweir             else
187*cdf0e10cSrcweir                 mpWindow->printPage( nRenderer, pPrinter );
188*cdf0e10cSrcweir         }
189*cdf0e10cSrcweir         else
190*cdf0e10cSrcweir             throw lang::IllegalArgumentException();
191*cdf0e10cSrcweir     }
192*cdf0e10cSrcweir }
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir 
195