LibreOffice Module toolkit (master) 1
vclxprinter.cxx
Go to the documentation of this file.
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 <com/sun/star/uno/XComponentContext.hpp>
21#include <awt/vclxprinter.hxx>
23#include <comphelper/string.hxx>
24
25#include <vcl/print.hxx>
26#include <vcl/jobset.hxx>
28#include <vcl/svapp.hxx>
29
30#include <tools/debug.hxx>
31#include <tools/stream.hxx>
32#include <o3tl/string_view.hxx>
33
35
36
37#define BINARYSETUPMARKER 0x23864691
38
39#define PROPERTY_Orientation 0
40#define PROPERTY_Horizontal 1
41
42// ----------------------------------------------------
43// class VCLXPrinterPropertySet
44// ----------------------------------------------------
45
48
49VCLXPrinterPropertySet::VCLXPrinterPropertySet( const OUString& rPrinterName )
50 : OPropertySetHelper( m_aBHelper )
51 , mxPrinter(VclPtrInstance< Printer >(rPrinterName))
52{
53 SolarMutexGuard aSolarGuard;
54
55 mnOrientation = 0;
56 mbHorizontal = false;
57}
58
60{
61 SolarMutexGuard aSolarGuard;
63}
64
65css::uno::Reference< css::awt::XDevice > const & VCLXPrinterPropertySet::GetDevice()
66{
67 if ( !mxPrnDevice.is() )
68 {
70 pDev->SetOutputDevice( GetPrinter() );
71 mxPrnDevice = pDev;
72 }
73 return mxPrnDevice;
74}
75
76css::uno::Reference< css::beans::XPropertySetInfo > VCLXPrinterPropertySet::getPropertySetInfo( )
77{
78 static css::uno::Reference< css::beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
79 return xInfo;
80}
81
83{
84 static ::cppu::OPropertyArrayHelper s_PropertyArrayHelper(
85 css::uno::Sequence<css::beans::Property>{
86 css::beans::Property( "Orientation", PROPERTY_Orientation, cppu::UnoType<sal_Int16>::get(), 0 ),
87 css::beans::Property( "Horizontal", PROPERTY_Horizontal, cppu::UnoType<bool>::get(), 0 )},
88 false);
89
90 return s_PropertyArrayHelper;
91}
92
93sal_Bool VCLXPrinterPropertySet::convertFastPropertyValue( css::uno::Any & rConvertedValue, css::uno::Any & rOldValue, sal_Int32 nHandle, const css::uno::Any& rValue )
94{
95 ::osl::MutexGuard aGuard( m_aMutex );
96
97 bool bDifferent = false;
98 switch ( nHandle )
99 {
101 {
102 sal_Int16 n;
103 if( ( rValue >>= n ) && ( n != mnOrientation ) )
104 {
105 rConvertedValue <<= n;
106 rOldValue <<= mnOrientation;
107 bDifferent = true;
108 }
109 }
110 break;
112 {
113 bool b;
114 if( ( rValue >>= b ) && ( b != mbHorizontal ) )
115 {
116 rConvertedValue <<= b;
117 rOldValue <<= mbHorizontal;
118 bDifferent = true;
119 }
120 }
121 break;
122 default:
123 {
124 OSL_FAIL( "VCLXPrinterPropertySet_Impl::convertFastPropertyValue - invalid Handle" );
125 }
126 }
127 return bDifferent;
128}
129
130void VCLXPrinterPropertySet::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const css::uno::Any& rValue )
131{
132 ::osl::MutexGuard aGuard( m_aMutex );
133
134 switch( nHandle )
135 {
137 {
138 rValue >>= mnOrientation;
139 }
140 break;
142 {
143 rValue >>= mbHorizontal;
144 }
145 break;
146 default:
147 {
148 OSL_FAIL( "VCLXPrinterPropertySet_Impl::convertFastPropertyValue - invalid Handle" );
149 }
150 }
151}
152
153void VCLXPrinterPropertySet::getFastPropertyValue( css::uno::Any& rValue, sal_Int32 nHandle ) const
154{
155 ::osl::MutexGuard aGuard( const_cast<VCLXPrinterPropertySet*>(this)->m_aMutex );
156
157 switch( nHandle )
158 {
160 rValue <<= mnOrientation;
161 break;
163 rValue <<= mbHorizontal;
164 break;
165 default:
166 {
167 OSL_FAIL( "VCLXPrinterPropertySet_Impl::convertFastPropertyValue - invalid Handle" );
168 }
169 }
170}
171
172// css::awt::XPrinterPropertySet
174{
175 ::osl::MutexGuard aGuard( m_aMutex );
176
177 css::uno::Any aValue;
178 aValue <<= bHorizontal;
180}
181
182css::uno::Sequence< OUString > VCLXPrinterPropertySet::getFormDescriptions( )
183{
184 ::osl::MutexGuard aGuard( m_aMutex );
185
186 const sal_uInt16 nPaperBinCount = GetPrinter()->GetPaperBinCount();
187 css::uno::Sequence< OUString > aDescriptions( nPaperBinCount );
188 for ( sal_uInt16 n = 0; n < nPaperBinCount; n++ )
189 {
190 // Format: <DisplayFormName;FormNameId;DisplayPaperBinName;PaperBinNameId;DisplayPaperName;PaperNameId>
191 OUString aDescr = "*;*;" + GetPrinter()->GetPaperBinName( n ) + ";" +
192 OUString::number(n) + ";*;*";
193
194 aDescriptions.getArray()[n] = aDescr;
195 }
196 return aDescriptions;
197}
198
199void VCLXPrinterPropertySet::selectForm( const OUString& rFormDescription )
200{
201 ::osl::MutexGuard aGuard( m_aMutex );
202
203 sal_uInt16 nPaperBin = sal::static_int_cast< sal_uInt16 >(
204 o3tl::toInt32(o3tl::getToken(rFormDescription, 3, ';' )));
205 GetPrinter()->SetPaperBin( nPaperBin );
206}
207
208css::uno::Sequence< sal_Int8 > VCLXPrinterPropertySet::getBinarySetup( )
209{
210 ::osl::MutexGuard aGuard( m_aMutex );
211
212 SvMemoryStream aMem;
214 WriteJobSetup( aMem, GetPrinter()->GetJobSetup() );
215 return css::uno::Sequence<sal_Int8>( static_cast<sal_Int8 const *>(aMem.GetData()), aMem.Tell() );
216}
217
218void VCLXPrinterPropertySet::setBinarySetup( const css::uno::Sequence< sal_Int8 >& data )
219{
220 ::osl::MutexGuard aGuard( m_aMutex );
221
222 SvMemoryStream aMem( const_cast<signed char*>(data.getConstArray()), data.getLength(), StreamMode::READ );
223 sal_uInt32 nMarker;
224 aMem.ReadUInt32( nMarker );
225 DBG_ASSERT( nMarker == BINARYSETUPMARKER, "setBinarySetup - invalid!" );
226 if ( nMarker == BINARYSETUPMARKER )
227 {
228 JobSetup aSetup;
229 ReadJobSetup( aMem, aSetup );
230 GetPrinter()->SetJobSetup( aSetup );
231 }
232}
233
234
235// ----------------------------------------------------
236// class VCLXPrinter
237// ----------------------------------------------------
238VCLXPrinter::VCLXPrinter( const OUString& rPrinterName )
239 : VCLXPrinter_Base( rPrinterName )
240{
241}
242
244{
245}
246
247sal_Bool VCLXPrinter::start( const OUString& /*rJobName*/, sal_Int16 /*nCopies*/, sal_Bool /*bCollate*/ )
248{
249 ::osl::MutexGuard aGuard( m_aMutex );
250
251 if (mxPrinter)
252 {
253 maInitJobSetup = mxPrinter->GetJobSetup();
254 mxListener = std::make_shared<vcl::OldStylePrintAdaptor>(mxPrinter, nullptr);
255 }
256
257 return true;
258}
259
261{
262 ::osl::MutexGuard aGuard( m_aMutex );
263
264 if (mxListener)
265 {
267 mxListener.reset();
268 }
269}
270
272{
273 ::osl::MutexGuard aGuard( m_aMutex );
274
275 mxListener.reset();
276}
277
278css::uno::Reference< css::awt::XDevice > VCLXPrinter::startPage( )
279{
280 ::osl::MutexGuard aGuard( m_aMutex );
281
282 if (mxListener)
283 {
284 mxListener->StartPage();
285 }
286 return GetDevice();
287}
288
290{
291 ::osl::MutexGuard aGuard( m_aMutex );
292
293 if (mxListener)
294 {
295 mxListener->EndPage();
296 }
297}
298
299
300// ----------------------------------------------------
301// class VCLXInfoPrinter
302// ----------------------------------------------------
303
304VCLXInfoPrinter::VCLXInfoPrinter( const OUString& rPrinterName )
305 : VCLXInfoPrinter_Base( rPrinterName )
306{
307}
308
310{
311}
312
313// css::awt::XInfoPrinter
314css::uno::Reference< css::awt::XDevice > VCLXInfoPrinter::createDevice( )
315{
316 ::osl::MutexGuard aGuard( m_aMutex );
317
318 return GetDevice();
319}
320
321// ----------------------------------------------------
322// class VCLXPrinterServer
323// ----------------------------------------------------
324
325// css::awt::XPrinterServer2
326css::uno::Sequence< OUString > VCLXPrinterServer::getPrinterNames( )
327{
328 const std::vector<OUString>& rQueues = Printer::GetPrinterQueues();
329 sal_uInt32 nPrinters = rQueues.size();
330
331 css::uno::Sequence< OUString > aNames( nPrinters );
332 for ( sal_uInt32 n = 0; n < nPrinters; n++ )
333 aNames.getArray()[n] = rQueues[n];
334
335 return aNames;
336}
337
339{
341}
342
343css::uno::Reference< css::awt::XPrinter > VCLXPrinterServer::createPrinter( const OUString& rPrinterName )
344{
345 css::uno::Reference< css::awt::XPrinter > xP = new VCLXPrinter( rPrinterName );
346 return xP;
347}
348
349css::uno::Reference< css::awt::XInfoPrinter > VCLXPrinterServer::createInfoPrinter( const OUString& rPrinterName )
350{
351 css::uno::Reference< css::awt::XInfoPrinter > xP = new VCLXInfoPrinter( rPrinterName );
352 return xP;
353}
354
356{
357 return "stardiv.Toolkit.VCLXPrinterServer";
358}
359
360sal_Bool VCLXPrinterServer::supportsService(OUString const & ServiceName)
361{
363}
364
366{
367 return css::uno::Sequence<OUString>{
368 "com.sun.star.awt.PrinterServer", "stardiv.vcl.PrinterServer"};
369}
370
371extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
373 css::uno::XComponentContext *,
374 css::uno::Sequence<css::uno::Any> const &)
375{
376 return cppu::acquire(new VCLXPrinterServer);
377}
378
379/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static OUString GetDefaultPrinterName()
bool SetJobSetup(const JobSetup &rSetup)
bool SetPaperBin(sal_uInt16 nPaperBin)
sal_uInt16 GetPaperBinCount() const
static const std::vector< OUString > & GetPrinterQueues()
static void PrintJob(const std::shared_ptr< vcl::PrinterController > &i_pController, const JobSetup &i_rInitSetup)
OUString GetPaperBinName(sal_uInt16 nPaperBin) const
const void * GetData()
sal_uInt64 Tell() const
SvStream & WriteUInt32(sal_uInt32 nUInt32)
SvStream & ReadUInt32(sal_uInt32 &rUInt32)
A UNO wrapper for the VCL OutputDevice.
Definition: vclxdevice.hxx:37
css::uno::Reference< css::awt::XDevice > SAL_CALL createDevice() override
VCLXInfoPrinter(const OUString &rPrinterName)
virtual ~VCLXInfoPrinter() override
css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
Definition: vclxprinter.cxx:76
sal_Bool SAL_CALL convertFastPropertyValue(css::uno::Any &rConvertedValue, css::uno::Any &rOldValue, sal_Int32 nHandle, const css::uno::Any &rValue) override
Definition: vclxprinter.cxx:93
VclPtr< Printer > mxPrinter
Definition: vclxprinter.hxx:60
Printer * GetPrinter() const
Definition: vclxprinter.hxx:69
void SAL_CALL setBinarySetup(const css::uno::Sequence< sal_Int8 > &data) override
css::uno::Reference< css::awt::XDevice > mxPrnDevice
Definition: vclxprinter.hxx:61
css::uno::Reference< css::awt::XDevice > const & GetDevice()
Definition: vclxprinter.cxx:65
void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const css::uno::Any &rValue) override
css::uno::Sequence< sal_Int8 > SAL_CALL getBinarySetup() override
void SAL_CALL getFastPropertyValue(css::uno::Any &rValue, sal_Int32 nHandle) const override
virtual ~VCLXPrinterPropertySet() override
Definition: vclxprinter.cxx:59
void SAL_CALL setHorizontal(sal_Bool bHorizontal) override
void SAL_CALL selectForm(const OUString &aFormDescription) override
::cppu::IPropertyArrayHelper &SAL_CALL getInfoHelper() override
Definition: vclxprinter.cxx:82
css::uno::Sequence< OUString > SAL_CALL getFormDescriptions() override
css::uno::Sequence< OUString > SAL_CALL getPrinterNames() override
OUString SAL_CALL getImplementationName() override
css::uno::Reference< css::awt::XInfoPrinter > SAL_CALL createInfoPrinter(const OUString &printerName) override
sal_Bool SAL_CALL supportsService(OUString const &ServiceName) override
css::uno::Reference< css::awt::XPrinter > SAL_CALL createPrinter(const OUString &printerName) override
css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
OUString SAL_CALL getDefaultPrinterName() override
JobSetup maInitJobSetup
virtual ~VCLXPrinter() override
void SAL_CALL endPage() override
void SAL_CALL terminate() override
std::shared_ptr< vcl::OldStylePrintAdaptor > mxListener
void SAL_CALL end() override
sal_Bool SAL_CALL start(const OUString &nJobName, sal_Int16 nCopies, sal_Bool nCollate) override
VCLXPrinter(const OUString &rPrinterName)
css::uno::Reference< css::awt::XDevice > SAL_CALL startPage() override
void reset(reference_type *pBody)
virtual void SAL_CALL setFastPropertyValue(sal_Int32 nHandle, const css::uno::Any &rValue) SAL_OVERRIDE
static css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL createPropertySetInfo(IPropertyArrayHelper &rProperties)
#define DBG_ASSERT(sCon, aError)
std::mutex m_aMutex
sal_Int64 n
SvStream & ReadJobSetup(SvStream &rIStream, JobSetup &rJobSetup)
SvStream & WriteJobSetup(SvStream &rOStream, const JobSetup &rJobSetup)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
sal_Int32 toInt32(std::u16string_view str, sal_Int16 radix=10)
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
sal_Int32 nHandle
IMPLEMENT_FORWARD_XINTERFACE2(ORoadmapEntry, ORoadmapEntry_Base, ::comphelper::OPropertyContainer)
IMPLEMENT_FORWARD_XTYPEPROVIDER2(ORoadmapEntry, ORoadmapEntry_Base, ::comphelper::OPropertyContainer)
unsigned char sal_Bool
signed char sal_Int8
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * stardiv_Toolkit_VCLXPrinterServer_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
#define PROPERTY_Horizontal
Definition: vclxprinter.cxx:40
#define BINARYSETUPMARKER
Definition: vclxprinter.cxx:37
#define PROPERTY_Orientation
Definition: vclxprinter.cxx:39
::cppu::WeakImplHelper< css::awt::XPrinterPropertySet > VCLXPrinterPropertySet_Base
Definition: vclxprinter.hxx:39
::cppu::ImplInheritanceHelper< VCLXPrinterPropertySet, css::awt::XPrinter > VCLXPrinter_Base
::cppu::ImplInheritanceHelper< VCLXPrinterPropertySet, css::awt::XInfoPrinter > VCLXInfoPrinter_Base