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