Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "basicrenderable.hxx"
21 : #include "bastypes.hxx"
22 : #include "basidesh.hrc"
23 :
24 : #include <com/sun/star/awt/XDevice.hpp>
25 : #include <toolkit/awt/vclxdevice.hxx>
26 : #include <vcl/print.hxx>
27 : #include <tools/multisel.hxx>
28 : #include <tools/resary.hxx>
29 :
30 : namespace basctl
31 : {
32 :
33 : using namespace com::sun::star;
34 : using namespace com::sun::star::uno;
35 :
36 0 : Renderable::Renderable (BaseWindow* pWin)
37 : : cppu::WeakComponentImplHelper1< com::sun::star::view::XRenderable >( maMutex )
38 0 : , mpWindow( pWin )
39 : {
40 0 : ResStringArray aStrings( IDEResId( RID_PRINTDLG_STRLIST ) );
41 : DBG_ASSERT( aStrings.Count() >= 3, "resource incomplete" );
42 0 : if( aStrings.Count() < 3 ) // bad resource ?
43 0 : return;
44 :
45 0 : m_aUIProperties.realloc( 3 );
46 :
47 : // show Subgroup for print range
48 0 : vcl::PrinterOptionsHelper::UIControlOptions aPrintRangeOpt;
49 0 : aPrintRangeOpt.maGroupHint = "PrintRange" ;
50 0 : aPrintRangeOpt.mbInternalOnly = true;
51 0 : m_aUIProperties[0].Value = setSubgroupControlOpt("printrange",
52 0 : OUString(aStrings.GetString(0)), OUString(), aPrintRangeOpt);
53 :
54 : // create a choice for the range to print
55 0 : OUString aPrintContentName( "PrintContent" );
56 0 : Sequence< OUString > aChoices( 2 );
57 0 : Sequence< OUString > aHelpIds( 2 );
58 0 : Sequence< OUString > aWidgetIds( 2 );
59 0 : aChoices[0] = aStrings.GetString( 1 );
60 0 : aHelpIds[0] = ".HelpID:vcl:PrintDialog:PrintContent:RadioButton:0" ;
61 0 : aChoices[1] = aStrings.GetString( 2 );
62 0 : aHelpIds[1] = ".HelpID:vcl:PrintDialog:PrintContent:RadioButton:1" ;
63 0 : aWidgetIds[0] = "printallpages" ;
64 0 : aWidgetIds[1] = "printpages" ;
65 0 : m_aUIProperties[1].Value = setChoiceRadiosControlOpt(aWidgetIds, OUString(),
66 : aHelpIds, aPrintContentName,
67 0 : aChoices, 0);
68 :
69 : // create a an Edit dependent on "Pages" selected
70 0 : vcl::PrinterOptionsHelper::UIControlOptions aPageRangeOpt(aPrintContentName, 1, true);
71 0 : m_aUIProperties[2].Value = setEditControlOpt("pagerange", OUString(),
72 : OUString(), "PageRange",
73 0 : OUString(), aPageRangeOpt);
74 : }
75 :
76 0 : Renderable::~Renderable()
77 : {
78 0 : }
79 :
80 0 : Printer* Renderable::getPrinter()
81 : {
82 0 : Printer* pPrinter = NULL;
83 0 : Any aValue( getValue( "RenderDevice" ) );
84 0 : Reference<awt::XDevice> xRenderDevice;
85 :
86 0 : if( aValue >>= xRenderDevice )
87 : {
88 0 : VCLXDevice* pDevice = VCLXDevice::GetImplementation(xRenderDevice);
89 0 : OutputDevice* pOut = pDevice ? pDevice->GetOutputDevice() : NULL;
90 0 : pPrinter = dynamic_cast<Printer*>(pOut);
91 : }
92 0 : return pPrinter;
93 : }
94 :
95 0 : sal_Int32 SAL_CALL Renderable::getRendererCount (
96 : const Any&, const Sequence<beans::PropertyValue >& i_xOptions
97 : ) throw (lang::IllegalArgumentException, RuntimeException, std::exception)
98 : {
99 0 : processProperties( i_xOptions );
100 :
101 0 : sal_Int32 nCount = 0;
102 0 : if( mpWindow )
103 : {
104 0 : if (Printer* pPrinter = getPrinter())
105 : {
106 0 : nCount = mpWindow->countPages( pPrinter );
107 0 : sal_Int64 nContent = getIntValue( "PrintContent", -1 );
108 0 : if( nContent == 1 )
109 : {
110 0 : OUString aPageRange( getStringValue( "PageRange" ) );
111 0 : if( !aPageRange.isEmpty() )
112 : {
113 0 : StringRangeEnumerator aRangeEnum( aPageRange, 0, nCount-1 );
114 0 : sal_Int32 nSelCount = aRangeEnum.size();
115 0 : if( nSelCount >= 0 )
116 0 : nCount = nSelCount;
117 0 : }
118 : }
119 : }
120 : else
121 0 : throw lang::IllegalArgumentException();
122 : }
123 :
124 0 : return nCount;
125 : }
126 :
127 0 : 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)
130 : {
131 0 : processProperties( i_xOptions );
132 :
133 0 : Sequence< beans::PropertyValue > aVals;
134 : // insert page size here
135 0 : Printer* pPrinter = getPrinter();
136 : // no renderdevice is legal; the first call is to get our print ui options
137 0 : if( pPrinter )
138 : {
139 0 : Size aPageSize( pPrinter->PixelToLogic( pPrinter->GetPaperSizePixel(), MapMode( MAP_100TH_MM ) ) );
140 :
141 0 : aVals.realloc( 1 );
142 0 : aVals[0].Name = "PageSize" ;
143 0 : awt::Size aSize;
144 0 : aSize.Width = aPageSize.Width();
145 0 : aSize.Height = aPageSize.Height();
146 0 : aVals[0].Value <<= aSize;
147 : }
148 :
149 0 : appendPrintUIOptions( aVals );
150 :
151 0 : return aVals;
152 : }
153 :
154 0 : 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)
158 : {
159 0 : processProperties( i_xOptions );
160 :
161 0 : if( mpWindow )
162 : {
163 0 : if (Printer* pPrinter = getPrinter())
164 : {
165 0 : sal_Int64 nContent = getIntValue( "PrintContent", -1 );
166 0 : if( nContent == 1 )
167 : {
168 0 : OUString aPageRange( getStringValue( "PageRange" ) );
169 0 : if( !aPageRange.isEmpty() )
170 : {
171 0 : sal_Int32 nPageCount = mpWindow->countPages( pPrinter );
172 0 : StringRangeEnumerator aRangeEnum( aPageRange, 0, nPageCount-1 );
173 0 : StringRangeEnumerator::Iterator it = aRangeEnum.begin();
174 0 : for( ; it != aRangeEnum.end() && nRenderer; --nRenderer )
175 0 : ++it;
176 :
177 0 : sal_Int32 nPage = ( it != aRangeEnum.end() ) ? *it : nRenderer;
178 0 : mpWindow->printPage( nPage, pPrinter );
179 : }
180 : else
181 0 : mpWindow->printPage( nRenderer, pPrinter );
182 : }
183 : else
184 0 : mpWindow->printPage( nRenderer, pPrinter );
185 : }
186 : else
187 0 : throw lang::IllegalArgumentException();
188 : }
189 0 : }
190 :
191 : } // namespace basctl
192 :
193 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|