1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #include "precompiled_basctl.hxx"
24 
25 #include "basicrenderable.hxx"
26 #include "bastypes.hxx"
27 #include "basidesh.hrc"
28 
29 #include "com/sun/star/awt/XDevice.hpp"
30 #include "toolkit/awt/vclxdevice.hxx"
31 #include "vcl/print.hxx"
32 #include "tools/multisel.hxx"
33 #include "tools/resary.hxx"
34 
35 using namespace com::sun::star;
36 using namespace com::sun::star::uno;
37 using namespace basicide;
38 
BasicRenderable(IDEBaseWindow * pWin)39 BasicRenderable::BasicRenderable( IDEBaseWindow* pWin )
40 : cppu::WeakComponentImplHelper1< com::sun::star::view::XRenderable >( maMutex )
41 , mpWindow( pWin )
42 {
43     ResStringArray aStrings( IDEResId( RID_PRINTDLG_STRLIST )  );
44     DBG_ASSERT( aStrings.Count() >= 3, "resource incomplete" );
45     if( aStrings.Count() < 3 ) // bad resource ?
46         return;
47 
48     m_aUIProperties.realloc( 3 );
49 
50     // create Subgroup for print range
51     vcl::PrinterOptionsHelper::UIControlOptions aPrintRangeOpt;
52     aPrintRangeOpt.maGroupHint = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrintRange" ) );
53     aPrintRangeOpt.mbInternalOnly = sal_True;
54     m_aUIProperties[0].Value = getSubgroupControlOpt( rtl::OUString( aStrings.GetString( 0 ) ),
55                                                       rtl::OUString(),
56                                                       aPrintRangeOpt
57                                                       );
58 
59     // create a choice for the range to print
60     rtl::OUString aPrintContentName( RTL_CONSTASCII_USTRINGPARAM( "PrintContent" ) );
61     Sequence< rtl::OUString > aChoices( 2 );
62     Sequence< rtl::OUString > aHelpIds( 2 );
63     aChoices[0] = aStrings.GetString( 1 );
64     aHelpIds[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".HelpID:vcl:PrintDialog:PrintContent:RadioButton:0" ) );
65     aChoices[1] = aStrings.GetString( 2 );
66     aHelpIds[1] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".HelpID:vcl:PrintDialog:PrintContent:RadioButton:1" ) );
67     m_aUIProperties[1].Value = getChoiceControlOpt( rtl::OUString(),
68                                                     aHelpIds,
69                                                     aPrintContentName,
70                                                     aChoices,
71                                                     0 );
72 
73     // create a an Edit dependent on "Pages" selected
74     vcl::PrinterOptionsHelper::UIControlOptions aPageRangeOpt( aPrintContentName, 1, sal_True );
75     m_aUIProperties[2].Value = getEditControlOpt( rtl::OUString(),
76                                                   rtl::OUString(),
77                                                   rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PageRange" ) ),
78                                                   rtl::OUString(),
79                                                   aPageRangeOpt
80                                                   );
81 }
82 
~BasicRenderable()83 BasicRenderable::~BasicRenderable()
84 {
85 }
86 
getPrinter()87 Printer* BasicRenderable::getPrinter()
88 {
89     Printer* pPrinter = NULL;
90     Any aValue( getValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "RenderDevice" ) ) ) );
91     Reference<awt::XDevice> xRenderDevice;
92 
93     if( aValue >>= xRenderDevice )
94     {
95         VCLXDevice* pDevice = VCLXDevice::GetImplementation(xRenderDevice);
96         OutputDevice* pOut = pDevice ? pDevice->GetOutputDevice() : NULL;
97         pPrinter = dynamic_cast<Printer*>(pOut);
98     }
99     return pPrinter;
100 }
101 
getRendererCount(const Any &,const Sequence<beans::PropertyValue> & i_xOptions)102 sal_Int32 SAL_CALL BasicRenderable::getRendererCount (
103         const Any&, const Sequence<beans::PropertyValue >& i_xOptions
104         ) throw (lang::IllegalArgumentException, RuntimeException)
105 {
106     processProperties( i_xOptions );
107 
108     sal_Int32 nCount = 0;
109     if( mpWindow )
110     {
111         Printer* pPrinter = getPrinter();
112         if( pPrinter )
113         {
114             nCount = mpWindow->countPages( pPrinter );
115             sal_Int64 nContent = getIntValue( "PrintContent", -1 );
116             if( nContent == 1 )
117             {
118                 rtl::OUString aPageRange( getStringValue( "PageRange" ) );
119                 MultiSelection aSel( aPageRange );
120                 long nSelCount = aSel.GetSelectCount();
121                 if( nSelCount >= 0 && nSelCount < nCount )
122                     nCount = nSelCount;
123             }
124         }
125         else
126             throw lang::IllegalArgumentException();
127     }
128 
129     return nCount;
130 }
131 
getRenderer(sal_Int32,const Any &,const Sequence<beans::PropertyValue> & i_xOptions)132 Sequence<beans::PropertyValue> SAL_CALL BasicRenderable::getRenderer (
133         sal_Int32, const Any&, const Sequence<beans::PropertyValue>& i_xOptions
134         ) throw (lang::IllegalArgumentException, RuntimeException)
135 {
136     processProperties( i_xOptions );
137 
138     Sequence< beans::PropertyValue > aVals;
139     // insert page size here
140     Printer* pPrinter = getPrinter();
141     // no renderdevice is legal; the first call is to get our print ui options
142     if( pPrinter )
143     {
144         Size aPageSize( pPrinter->PixelToLogic( pPrinter->GetPaperSizePixel(), MapMode( MAP_100TH_MM ) ) );
145 
146         aVals.realloc( 1 );
147         aVals[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PageSize" ) );
148         awt::Size aSize;
149         aSize.Width  = aPageSize.Width();
150         aSize.Height = aPageSize.Height();
151         aVals[0].Value <<= aSize;
152     }
153 
154     appendPrintUIOptions( aVals );
155 
156     return aVals;
157 }
158 
render(sal_Int32 nRenderer,const Any &,const Sequence<beans::PropertyValue> & i_xOptions)159 void SAL_CALL BasicRenderable::render (
160         sal_Int32 nRenderer, const Any&,
161         const Sequence<beans::PropertyValue>& i_xOptions
162         ) throw (lang::IllegalArgumentException, RuntimeException)
163 {
164     processProperties( i_xOptions );
165 
166     if( mpWindow )
167     {
168         Printer* pPrinter = getPrinter();
169         if( pPrinter )
170         {
171             sal_Int64 nContent = getIntValue( "PrintContent", -1 );
172             if( nContent == 1 )
173             {
174                 rtl::OUString aPageRange( getStringValue( "PageRange" ) );
175                 MultiSelection aSel( aPageRange );
176                 long nSelect = aSel.FirstSelected();
177                 while( nSelect != long(SFX_ENDOFSELECTION) && nRenderer-- )
178                     nSelect = aSel.NextSelected();
179                 if( nSelect != long(SFX_ENDOFSELECTION) )
180                     mpWindow->printPage( sal_Int32(nSelect-1), pPrinter );
181             }
182             else
183                 mpWindow->printPage( nRenderer, pPrinter );
184         }
185         else
186             throw lang::IllegalArgumentException();
187     }
188 }
189 
190 
191