1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <strings.hrc>
24 #include <toolkit/awt/vclxdevice.hxx>
25 #include <tools/multisel.hxx>
26 #include <cppuhelper/compbase.hxx>
27 #include <comphelper/propertysequence.hxx>
32 using namespace com::sun::star
;
33 using namespace com::sun::star::uno
;
35 Renderable::Renderable (BaseWindow
* pWin
)
36 : cppu::WeakComponentImplHelper
< css::view::XRenderable
>( maMutex
)
39 m_aUIProperties
.resize( 3 );
41 // show Subgroup for print range
42 vcl::PrinterOptionsHelper::UIControlOptions aPrintRangeOpt
;
43 aPrintRangeOpt
.maGroupHint
= "PrintRange" ;
44 aPrintRangeOpt
.mbInternalOnly
= true;
45 m_aUIProperties
[0].Value
= setSubgroupControlOpt("printrange",
46 IDEResId( RID_STR_PRINTDLG_RANGE
), OUString(), aPrintRangeOpt
);
48 // create a choice for the range to print
49 OUString
aPrintContentName( "PrintContent" );
50 const Sequence
<OUString
> aChoices
{IDEResId(RID_STR_PRINTDLG_ALLPAGES
),
51 IDEResId(RID_STR_PRINTDLG_PAGES
)};
52 const Sequence
<OUString
> aHelpIds
{".HelpID:vcl:PrintDialog:PrintContent:RadioButton:0",
53 ".HelpID:vcl:PrintDialog:PrintContent:RadioButton:1"};
54 const Sequence
<OUString
> aWidgetIds
{"printallpages",
56 m_aUIProperties
[1].Value
= setChoiceRadiosControlOpt(aWidgetIds
, OUString(),
57 aHelpIds
, aPrintContentName
,
60 // create a an Edit dependent on "Pages" selected
61 vcl::PrinterOptionsHelper::UIControlOptions
aPageRangeOpt(aPrintContentName
, 1, true);
62 m_aUIProperties
[2].Value
= setEditControlOpt("pagerange", OUString(),
63 OUString(), "PageRange",
64 OUString(), aPageRangeOpt
);
67 Renderable::~Renderable()
71 VclPtr
< Printer
> Renderable::getPrinter()
73 VclPtr
< Printer
> pPrinter
;
74 Any
aValue( getValue( "RenderDevice" ) );
75 Reference
<awt::XDevice
> xRenderDevice
;
77 if( aValue
>>= xRenderDevice
)
79 VCLXDevice
* pDevice
= VCLXDevice::GetImplementation(xRenderDevice
);
80 VclPtr
< OutputDevice
> pOut
= pDevice
? pDevice
->GetOutputDevice() : VclPtr
< OutputDevice
>();
81 pPrinter
= dynamic_cast<Printer
*>(pOut
.get());
86 sal_Int32 SAL_CALL
Renderable::getRendererCount (
87 const Any
&, const Sequence
<beans::PropertyValue
>& i_xOptions
90 processProperties( i_xOptions
);
95 VclPtr
<Printer
> pPrinter
= getPrinter();
97 throw lang::IllegalArgumentException();
99 nCount
= mpWindow
->countPages( pPrinter
);
100 sal_Int64 nContent
= getIntValue( "PrintContent", -1 );
103 OUString
aPageRange( getStringValue( "PageRange" ) );
104 if( !aPageRange
.isEmpty() )
106 StringRangeEnumerator
aRangeEnum( aPageRange
, 0, nCount
-1 );
107 sal_Int32 nSelCount
= aRangeEnum
.size();
117 Sequence
<beans::PropertyValue
> SAL_CALL
Renderable::getRenderer (
118 sal_Int32
, const Any
&, const Sequence
<beans::PropertyValue
>& i_xOptions
121 processProperties( i_xOptions
);
123 Sequence
< beans::PropertyValue
> aVals
;
124 // insert page size here
125 VclPtr
<Printer
> pPrinter
= getPrinter();
126 // no renderdevice is legal; the first call is to get our print ui options
129 Size
aPageSize( pPrinter
->PixelToLogic( pPrinter
->GetPaperSizePixel(), MapMode( MapUnit::Map100thMM
) ) );
132 aSize
.Width
= aPageSize
.Width();
133 aSize
.Height
= aPageSize
.Height();
134 aVals
= ::comphelper::InitPropertySequence({
135 { "PageSize", Any(aSize
) }
139 appendPrintUIOptions( aVals
);
144 void SAL_CALL
Renderable::render (
145 sal_Int32 nRenderer
, const Any
&,
146 const Sequence
<beans::PropertyValue
>& i_xOptions
149 processProperties( i_xOptions
);
153 VclPtr
<Printer
> pPrinter
= getPrinter();
155 throw lang::IllegalArgumentException();
157 sal_Int64 nContent
= getIntValue( "PrintContent", -1 );
160 OUString
aPageRange( getStringValue( "PageRange" ) );
161 if( !aPageRange
.isEmpty() )
163 sal_Int32 nPageCount
= mpWindow
->countPages( pPrinter
);
164 StringRangeEnumerator
aRangeEnum( aPageRange
, 0, nPageCount
-1 );
165 StringRangeEnumerator::Iterator it
= aRangeEnum
.begin();
166 for( ; it
!= aRangeEnum
.end() && nRenderer
; --nRenderer
)
169 sal_Int32 nPage
= ( it
!= aRangeEnum
.end() ) ? *it
: nRenderer
;
170 mpWindow
->printPage( nPage
, pPrinter
);
173 mpWindow
->printPage( nRenderer
, pPrinter
);
176 mpWindow
->printPage( nRenderer
, pPrinter
);
180 } // namespace basctl
182 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */