Branch data 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 : : using namespace com::sun::star;
31 : : using namespace com::sun::star::uno;
32 : : using namespace basicide;
33 : :
34 : 0 : BasicRenderable::BasicRenderable( IDEBaseWindow* pWin )
35 : : : cppu::WeakComponentImplHelper1< com::sun::star::view::XRenderable >( maMutex )
36 : 0 : , mpWindow( pWin )
37 : : {
38 : 0 : ResStringArray aStrings( IDEResId( RID_PRINTDLG_STRLIST ) );
39 : : DBG_ASSERT( aStrings.Count() >= 3, "resource incomplete" );
40 : 0 : if( aStrings.Count() < 3 ) // bad resource ?
41 : 0 : return;
42 : :
43 : 0 : m_aUIProperties.realloc( 3 );
44 : :
45 : : // create Subgroup for print range
46 : 0 : vcl::PrinterOptionsHelper::UIControlOptions aPrintRangeOpt;
47 : 0 : aPrintRangeOpt.maGroupHint = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrintRange" ) );
48 : 0 : aPrintRangeOpt.mbInternalOnly = true;
49 : 0 : m_aUIProperties[0].Value = getSubgroupControlOpt( rtl::OUString( aStrings.GetString( 0 ) ),
50 : : rtl::OUString(),
51 : : aPrintRangeOpt
52 : 0 : );
53 : :
54 : : // create a choice for the range to print
55 : 0 : rtl::OUString aPrintContentName( RTL_CONSTASCII_USTRINGPARAM( "PrintContent" ) );
56 : 0 : Sequence< rtl::OUString > aChoices( 2 );
57 : 0 : Sequence< rtl::OUString > aHelpIds( 2 );
58 : 0 : aChoices[0] = aStrings.GetString( 1 );
59 : 0 : aHelpIds[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".HelpID:vcl:PrintDialog:PrintContent:RadioButton:0" ) );
60 : 0 : aChoices[1] = aStrings.GetString( 2 );
61 : 0 : aHelpIds[1] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".HelpID:vcl:PrintDialog:PrintContent:RadioButton:1" ) );
62 : 0 : m_aUIProperties[1].Value = getChoiceControlOpt( rtl::OUString(),
63 : : aHelpIds,
64 : : aPrintContentName,
65 : : aChoices,
66 : 0 : 0 );
67 : :
68 : : // create a an Edit dependent on "Pages" selected
69 : 0 : vcl::PrinterOptionsHelper::UIControlOptions aPageRangeOpt(aPrintContentName, 1, true);
70 : 0 : m_aUIProperties[2].Value = getEditControlOpt( rtl::OUString(),
71 : : rtl::OUString(),
72 : : rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PageRange" ) ),
73 : : rtl::OUString(),
74 : : aPageRangeOpt
75 : 0 : );
76 : : }
77 : :
78 : 0 : BasicRenderable::~BasicRenderable()
79 : : {
80 : 0 : }
81 : :
82 : 0 : Printer* BasicRenderable::getPrinter()
83 : : {
84 : 0 : Printer* pPrinter = NULL;
85 : 0 : Any aValue( getValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "RenderDevice" ) ) ) );
86 : 0 : Reference<awt::XDevice> xRenderDevice;
87 : :
88 : 0 : if( aValue >>= xRenderDevice )
89 : : {
90 : 0 : VCLXDevice* pDevice = VCLXDevice::GetImplementation(xRenderDevice);
91 : 0 : OutputDevice* pOut = pDevice ? pDevice->GetOutputDevice() : NULL;
92 : 0 : pPrinter = dynamic_cast<Printer*>(pOut);
93 : : }
94 : 0 : return pPrinter;
95 : : }
96 : :
97 : 0 : sal_Int32 SAL_CALL BasicRenderable::getRendererCount (
98 : : const Any&, const Sequence<beans::PropertyValue >& i_xOptions
99 : : ) throw (lang::IllegalArgumentException, RuntimeException)
100 : : {
101 : 0 : processProperties( i_xOptions );
102 : :
103 : 0 : sal_Int32 nCount = 0;
104 : 0 : if( mpWindow )
105 : : {
106 : 0 : Printer* pPrinter = getPrinter();
107 : 0 : if( pPrinter )
108 : : {
109 : 0 : nCount = mpWindow->countPages( pPrinter );
110 : 0 : sal_Int64 nContent = getIntValue( "PrintContent", -1 );
111 : 0 : if( nContent == 1 )
112 : : {
113 : 0 : rtl::OUString aPageRange( getStringValue( "PageRange" ) );
114 : 0 : if( !aPageRange.isEmpty() )
115 : : {
116 : 0 : StringRangeEnumerator aRangeEnum( aPageRange, 0, nCount-1 );
117 : 0 : sal_Int32 nSelCount = aRangeEnum.size();
118 : 0 : if( nSelCount >= 0 )
119 : 0 : nCount = nSelCount;
120 : 0 : }
121 : : }
122 : : }
123 : : else
124 : 0 : throw lang::IllegalArgumentException();
125 : : }
126 : :
127 : 0 : return nCount;
128 : : }
129 : :
130 : 0 : Sequence<beans::PropertyValue> SAL_CALL BasicRenderable::getRenderer (
131 : : sal_Int32, const Any&, const Sequence<beans::PropertyValue>& i_xOptions
132 : : ) throw (lang::IllegalArgumentException, RuntimeException)
133 : : {
134 : 0 : processProperties( i_xOptions );
135 : :
136 : 0 : Sequence< beans::PropertyValue > aVals;
137 : : // insert page size here
138 : 0 : Printer* pPrinter = getPrinter();
139 : : // no renderdevice is legal; the first call is to get our print ui options
140 : 0 : if( pPrinter )
141 : : {
142 : 0 : Size aPageSize( pPrinter->PixelToLogic( pPrinter->GetPaperSizePixel(), MapMode( MAP_100TH_MM ) ) );
143 : :
144 : 0 : aVals.realloc( 1 );
145 : 0 : aVals[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PageSize" ) );
146 : 0 : awt::Size aSize;
147 : 0 : aSize.Width = aPageSize.Width();
148 : 0 : aSize.Height = aPageSize.Height();
149 : 0 : aVals[0].Value <<= aSize;
150 : : }
151 : :
152 : 0 : appendPrintUIOptions( aVals );
153 : :
154 : 0 : return aVals;
155 : : }
156 : :
157 : 0 : void SAL_CALL BasicRenderable::render (
158 : : sal_Int32 nRenderer, const Any&,
159 : : const Sequence<beans::PropertyValue>& i_xOptions
160 : : ) throw (lang::IllegalArgumentException, RuntimeException)
161 : : {
162 : 0 : processProperties( i_xOptions );
163 : :
164 : 0 : if( mpWindow )
165 : : {
166 : 0 : Printer* pPrinter = getPrinter();
167 : 0 : if( pPrinter )
168 : : {
169 : 0 : sal_Int64 nContent = getIntValue( "PrintContent", -1 );
170 : 0 : if( nContent == 1 )
171 : : {
172 : 0 : rtl::OUString aPageRange( getStringValue( "PageRange" ) );
173 : 0 : if( !aPageRange.isEmpty() )
174 : : {
175 : 0 : sal_Int32 nPageCount = mpWindow->countPages( pPrinter );
176 : 0 : StringRangeEnumerator aRangeEnum( aPageRange, 0, nPageCount-1 );
177 : 0 : StringRangeEnumerator::Iterator it = aRangeEnum.begin();
178 : 0 : for( ; it != aRangeEnum.end() && nRenderer; --nRenderer )
179 : 0 : ++it;
180 : :
181 : 0 : sal_Int32 nPage = ( it != aRangeEnum.end() ) ? *it : nRenderer;
182 : 0 : mpWindow->printPage( nPage, pPrinter );
183 : : }
184 : : else
185 : 0 : mpWindow->printPage( nRenderer, pPrinter );
186 : : }
187 : : else
188 : 0 : mpWindow->printPage( nRenderer, pPrinter );
189 : : }
190 : : else
191 : 0 : throw lang::IllegalArgumentException();
192 : : }
193 : 0 : }
194 : :
195 : :
196 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|