bump product version to 5.0.4.1
[LibreOffice.git] / basctl / source / basicide / basicrenderable.cxx
blob72814178984be79dfbc482e2370705dff29fc868
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "basicrenderable.hxx"
21 #include "bastypes.hxx"
22 #include "basidesh.hrc"
24 #include <toolkit/awt/vclxdevice.hxx>
25 #include <tools/multisel.hxx>
26 #include <tools/resary.hxx>
28 #include <comphelper/propertysequence.hxx>
30 namespace basctl
33 using namespace com::sun::star;
34 using namespace com::sun::star::uno;
36 Renderable::Renderable (BaseWindow* pWin)
37 : cppu::WeakComponentImplHelper1< com::sun::star::view::XRenderable >( maMutex )
38 , mpWindow( pWin )
40 ResStringArray aStrings( IDEResId( RID_PRINTDLG_STRLIST ) );
41 DBG_ASSERT( aStrings.Count() >= 3, "resource incomplete" );
42 if( aStrings.Count() < 3 ) // bad resource ?
43 return;
45 m_aUIProperties.realloc( 3 );
47 // show Subgroup for print range
48 vcl::PrinterOptionsHelper::UIControlOptions aPrintRangeOpt;
49 aPrintRangeOpt.maGroupHint = "PrintRange" ;
50 aPrintRangeOpt.mbInternalOnly = true;
51 m_aUIProperties[0].Value = setSubgroupControlOpt("printrange",
52 OUString(aStrings.GetString(0)), OUString(), aPrintRangeOpt);
54 // create a choice for the range to print
55 OUString aPrintContentName( "PrintContent" );
56 Sequence< OUString > aChoices( 2 );
57 Sequence< OUString > aHelpIds( 2 );
58 Sequence< OUString > aWidgetIds( 2 );
59 aChoices[0] = aStrings.GetString( 1 );
60 aHelpIds[0] = ".HelpID:vcl:PrintDialog:PrintContent:RadioButton:0" ;
61 aChoices[1] = aStrings.GetString( 2 );
62 aHelpIds[1] = ".HelpID:vcl:PrintDialog:PrintContent:RadioButton:1" ;
63 aWidgetIds[0] = "printallpages" ;
64 aWidgetIds[1] = "printpages" ;
65 m_aUIProperties[1].Value = setChoiceRadiosControlOpt(aWidgetIds, OUString(),
66 aHelpIds, aPrintContentName,
67 aChoices, 0);
69 // create a an Edit dependent on "Pages" selected
70 vcl::PrinterOptionsHelper::UIControlOptions aPageRangeOpt(aPrintContentName, 1, true);
71 m_aUIProperties[2].Value = setEditControlOpt("pagerange", OUString(),
72 OUString(), "PageRange",
73 OUString(), aPageRangeOpt);
76 Renderable::~Renderable()
80 VclPtr< Printer > Renderable::getPrinter()
82 VclPtr< Printer > pPrinter;
83 Any aValue( getValue( "RenderDevice" ) );
84 Reference<awt::XDevice> xRenderDevice;
86 if( aValue >>= xRenderDevice )
88 VCLXDevice* pDevice = VCLXDevice::GetImplementation(xRenderDevice);
89 VclPtr< OutputDevice > pOut = pDevice ? pDevice->GetOutputDevice() : VclPtr< OutputDevice >();
90 pPrinter = dynamic_cast<Printer*>(pOut.get());
92 return pPrinter;
95 sal_Int32 SAL_CALL Renderable::getRendererCount (
96 const Any&, const Sequence<beans::PropertyValue >& i_xOptions
97 ) throw (lang::IllegalArgumentException, RuntimeException, std::exception)
99 processProperties( i_xOptions );
101 sal_Int32 nCount = 0;
102 if( mpWindow )
104 if (Printer* pPrinter = getPrinter())
106 nCount = mpWindow->countPages( pPrinter );
107 sal_Int64 nContent = getIntValue( "PrintContent", -1 );
108 if( nContent == 1 )
110 OUString aPageRange( getStringValue( "PageRange" ) );
111 if( !aPageRange.isEmpty() )
113 StringRangeEnumerator aRangeEnum( aPageRange, 0, nCount-1 );
114 sal_Int32 nSelCount = aRangeEnum.size();
115 if( nSelCount >= 0 )
116 nCount = nSelCount;
120 else
121 throw lang::IllegalArgumentException();
124 return nCount;
127 Sequence<beans::PropertyValue> SAL_CALL Renderable::getRenderer (
128 sal_Int32, const Any&, const Sequence<beans::PropertyValue>& i_xOptions
129 ) throw (lang::IllegalArgumentException, RuntimeException, std::exception)
131 processProperties( i_xOptions );
133 Sequence< beans::PropertyValue > aVals;
134 // insert page size here
135 Printer* pPrinter = getPrinter();
136 // no renderdevice is legal; the first call is to get our print ui options
137 if( pPrinter )
139 Size aPageSize( pPrinter->PixelToLogic( pPrinter->GetPaperSizePixel(), MapMode( MAP_100TH_MM ) ) );
141 awt::Size aSize;
142 aSize.Width = aPageSize.Width();
143 aSize.Height = aPageSize.Height();
144 aVals = ::comphelper::InitPropertySequence({
145 { "PageSize", makeAny(aSize) }
149 appendPrintUIOptions( aVals );
151 return aVals;
154 void SAL_CALL Renderable::render (
155 sal_Int32 nRenderer, const Any&,
156 const Sequence<beans::PropertyValue>& i_xOptions
157 ) throw (lang::IllegalArgumentException, RuntimeException, std::exception)
159 processProperties( i_xOptions );
161 if( mpWindow )
163 if (Printer* pPrinter = getPrinter())
165 sal_Int64 nContent = getIntValue( "PrintContent", -1 );
166 if( nContent == 1 )
168 OUString aPageRange( getStringValue( "PageRange" ) );
169 if( !aPageRange.isEmpty() )
171 sal_Int32 nPageCount = mpWindow->countPages( pPrinter );
172 StringRangeEnumerator aRangeEnum( aPageRange, 0, nPageCount-1 );
173 StringRangeEnumerator::Iterator it = aRangeEnum.begin();
174 for( ; it != aRangeEnum.end() && nRenderer; --nRenderer )
175 ++it;
177 sal_Int32 nPage = ( it != aRangeEnum.end() ) ? *it : nRenderer;
178 mpWindow->printPage( nPage, pPrinter );
180 else
181 mpWindow->printPage( nRenderer, pPrinter );
183 else
184 mpWindow->printPage( nRenderer, pPrinter );
186 else
187 throw lang::IllegalArgumentException();
191 } // namespace basctl
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */