merge the formfield patch from ooo-build
[ooovba.git] / sw / source / ui / uno / SwXPrintPreviewSettings.cxx
blob0cbe81757b6ef990519829d3542c1fdec363cf88
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SwXPrintPreviewSettings.cxx,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
33 #include <SwXPrintPreviewSettings.hxx>
34 #include <comphelper/ChainablePropertySetInfo.hxx>
35 #include <pvprtdat.hxx>
36 #include <swtypes.hxx>
37 #ifndef _COM_SUN_STAR_BEANS_PropertyAttribute_HPP_
38 #include <com/sun/star/beans/PropertyAttribute.hpp>
39 #endif
40 #ifndef _COM_SUN_STAR_BEANS_PropertyAttribute_HPP_
41 #include <com/sun/star/beans/PropertyAttribute.hpp>
42 #endif
43 #include <doc.hxx>
44 #include <vcl/svapp.hxx>
45 using namespace ::com::sun::star;
46 using namespace ::com::sun::star::uno;
47 using namespace ::com::sun::star::beans;
48 using namespace ::com::sun::star::lang;
49 using namespace ::comphelper;
50 using ::rtl::OUString;
52 enum SwPrintSettingsPropertyHandles
54 HANDLE_PRINTSET_PREVIEW_LEFT_MARGIN,
55 HANDLE_PRINTSET_PREVIEW_RIGHT_MARGIN,
56 HANDLE_PRINTSET_PREVIEW_TOP_MARGIN,
57 HANDLE_PRINTSET_PREVIEW_BOTTOM_MARGIN,
58 HANDLE_PRINTSET_PREVIEW_HORIZONTAL_SPACING,
59 HANDLE_PRINTSET_PREVIEW_VERTICAL_SPACING,
60 HANDLE_PRINTSET_PREVIEW_NUM_ROWS,
61 HANDLE_PRINTSET_PREVIEW_NUM_COLUMNS,
62 HANDLE_PRINTSET_PREVIEW_LANDSCAPE
65 static ChainablePropertySetInfo * lcl_createPrintPreviewSettingsInfo()
67 static PropertyInfo aPrintPreviewSettingsMap_Impl[] =
69 { RTL_CONSTASCII_STRINGPARAM ( "PreviewPrintLeftMargin" ), HANDLE_PRINTSET_PREVIEW_LEFT_MARGIN, CPPUTYPE_INT32, PropertyAttribute::MAYBEVOID, 0 },
70 { RTL_CONSTASCII_STRINGPARAM ( "PreviewPrintRightMargin" ), HANDLE_PRINTSET_PREVIEW_RIGHT_MARGIN, CPPUTYPE_INT32, PropertyAttribute::MAYBEVOID, 0 },
71 { RTL_CONSTASCII_STRINGPARAM ( "PreviewPrintTopMargin" ), HANDLE_PRINTSET_PREVIEW_TOP_MARGIN, CPPUTYPE_INT32, PropertyAttribute::MAYBEVOID, 0 },
72 { RTL_CONSTASCII_STRINGPARAM ( "PreviewPrintBottomMargin" ),HANDLE_PRINTSET_PREVIEW_BOTTOM_MARGIN, CPPUTYPE_INT32, PropertyAttribute::MAYBEVOID, 0 },
73 { RTL_CONSTASCII_STRINGPARAM ( "PreviewPrintHorizontalSpacing" ),HANDLE_PRINTSET_PREVIEW_HORIZONTAL_SPACING, CPPUTYPE_INT32, PropertyAttribute::MAYBEVOID, 0 },
74 { RTL_CONSTASCII_STRINGPARAM ( "PreviewPrintVerticalSpacing" ), HANDLE_PRINTSET_PREVIEW_VERTICAL_SPACING, CPPUTYPE_INT32, PropertyAttribute::MAYBEVOID, 0 },
75 { RTL_CONSTASCII_STRINGPARAM ( "PreviewPrintNumRows" ), HANDLE_PRINTSET_PREVIEW_NUM_ROWS, CPPUTYPE_INT8, PropertyAttribute::MAYBEVOID, 0 },
76 { RTL_CONSTASCII_STRINGPARAM ( "PreviewPrintNumColumns" ), HANDLE_PRINTSET_PREVIEW_NUM_COLUMNS, CPPUTYPE_INT8, PropertyAttribute::MAYBEVOID, 0 },
77 { RTL_CONSTASCII_STRINGPARAM ( "PreviewPrintLandscape" ), HANDLE_PRINTSET_PREVIEW_LANDSCAPE, CPPUTYPE_BOOLEAN, PropertyAttribute::MAYBEVOID, 0 },
78 { 0, 0, 0, CPPUTYPE_UNKNOWN, 0, 0 }
80 return new ChainablePropertySetInfo ( aPrintPreviewSettingsMap_Impl );
82 SwXPrintPreviewSettings::SwXPrintPreviewSettings( SwDoc *pDoc)
83 : ChainablePropertySet ( lcl_createPrintPreviewSettingsInfo (), &Application::GetSolarMutex() )
84 , mbPreviewDataChanged( sal_False )
85 , mpDoc( pDoc)
88 /*-- 17.12.98 12:54:05---------------------------------------------------
90 -----------------------------------------------------------------------*/
91 SwXPrintPreviewSettings::~SwXPrintPreviewSettings()
92 throw()
96 Any SAL_CALL SwXPrintPreviewSettings::queryInterface( const Type& rType )
97 throw(RuntimeException)
99 return ::cppu::queryInterface ( rType ,
100 // OWeakObject interfaces
101 dynamic_cast< XInterface* >( dynamic_cast< OWeakObject* >(this) ) ,
102 dynamic_cast< XWeak* >( this ) ,
103 // my own interfaces
104 dynamic_cast< XServiceInfo* >( this ) ,
105 dynamic_cast< XPropertySet* >( this ) ,
106 dynamic_cast< XMultiPropertySet* >( this ) );
108 void SwXPrintPreviewSettings::acquire ()
109 throw ()
111 OWeakObject::acquire();
113 void SwXPrintPreviewSettings::release ()
114 throw ()
116 OWeakObject::release();
119 void SwXPrintPreviewSettings::_preSetValues ()
120 throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException )
122 if ( mpDoc )
124 const SwPagePreViewPrtData *pConstPrtData = mpDoc->GetPreViewPrtData();
125 mpPreViewData = new SwPagePreViewPrtData;
126 if ( pConstPrtData )
128 mpPreViewData->SetLeftSpace ( pConstPrtData->GetLeftSpace() );
129 mpPreViewData->SetRightSpace ( pConstPrtData->GetRightSpace() );
130 mpPreViewData->SetTopSpace ( pConstPrtData->GetTopSpace() );
131 mpPreViewData->SetBottomSpace ( pConstPrtData->GetBottomSpace() );
132 mpPreViewData->SetHorzSpace ( pConstPrtData->GetHorzSpace() );
133 mpPreViewData->SetVertSpace ( pConstPrtData->GetVertSpace() );
134 mpPreViewData->SetRow ( pConstPrtData->GetRow() );
135 mpPreViewData->SetCol ( pConstPrtData->GetCol() );
136 mpPreViewData->SetLandscape ( pConstPrtData->GetLandscape() );
141 void SwXPrintPreviewSettings::_setSingleValue( const comphelper::PropertyInfo & rInfo, const uno::Any &rValue )
142 throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException )
144 switch( rInfo.mnHandle )
146 case HANDLE_PRINTSET_PREVIEW_LEFT_MARGIN:
148 sal_Int32 nVal = 0;
149 rValue >>= nVal;
150 nVal = MM100_TO_TWIP( nVal );
151 if ( nVal != static_cast < sal_Int32 > (mpPreViewData->GetLeftSpace() ) )
153 mbPreviewDataChanged = sal_True;
154 mpPreViewData->SetLeftSpace( nVal );
157 break;
158 case HANDLE_PRINTSET_PREVIEW_RIGHT_MARGIN:
160 sal_Int32 nVal = 0;
161 rValue >>= nVal;
162 nVal = MM100_TO_TWIP( nVal );
163 if ( nVal != static_cast < sal_Int32 > (mpPreViewData->GetRightSpace() ) )
165 mbPreviewDataChanged = sal_True;
166 mpPreViewData->SetRightSpace( nVal );
169 break;
170 case HANDLE_PRINTSET_PREVIEW_TOP_MARGIN:
172 sal_Int32 nVal = 0;
173 rValue >>= nVal;
174 nVal = MM100_TO_TWIP( nVal );
175 if ( nVal != static_cast < sal_Int32 > ( mpPreViewData->GetTopSpace() ) )
177 mbPreviewDataChanged = sal_True;
178 mpPreViewData->SetTopSpace( nVal );
181 break;
182 case HANDLE_PRINTSET_PREVIEW_BOTTOM_MARGIN:
184 sal_Int32 nVal = 0;
185 rValue >>= nVal;
186 nVal = MM100_TO_TWIP( nVal );
187 if ( nVal != static_cast < sal_Int32 > ( mpPreViewData->GetBottomSpace() ) )
189 mbPreviewDataChanged = sal_True;
190 mpPreViewData->SetBottomSpace( nVal );
193 break;
194 case HANDLE_PRINTSET_PREVIEW_HORIZONTAL_SPACING:
196 sal_Int32 nVal = 0;
197 rValue >>= nVal;
198 nVal = MM100_TO_TWIP( nVal );
199 if ( nVal != static_cast < sal_Int32 > ( mpPreViewData->GetHorzSpace() ) )
201 mbPreviewDataChanged = sal_True;
202 mpPreViewData->SetHorzSpace( nVal );
205 break;
206 case HANDLE_PRINTSET_PREVIEW_VERTICAL_SPACING:
208 sal_Int32 nVal = 0;
209 rValue >>= nVal;
210 nVal = MM100_TO_TWIP( nVal );
211 if ( nVal != static_cast < sal_Int32 > ( mpPreViewData->GetVertSpace() ) )
213 mbPreviewDataChanged = sal_True;
214 mpPreViewData->SetVertSpace( nVal );
217 break;
218 case HANDLE_PRINTSET_PREVIEW_NUM_ROWS:
220 sal_Int8 nVal = 0;
221 rValue >>= nVal;
222 if ( nVal != mpPreViewData->GetRow() )
224 mbPreviewDataChanged = sal_True;
225 mpPreViewData->SetRow( nVal );
228 break;
229 case HANDLE_PRINTSET_PREVIEW_NUM_COLUMNS:
231 sal_Int8 nVal = 0;
232 rValue >>= nVal;
233 if ( nVal != mpPreViewData->GetCol() )
235 mbPreviewDataChanged = sal_True;
236 mpPreViewData->SetCol( nVal );
239 break;
240 case HANDLE_PRINTSET_PREVIEW_LANDSCAPE:
242 sal_Bool bVal = *(sal_Bool*)rValue.getValue();
243 if ( bVal != mpPreViewData->GetLandscape() )
245 mbPreviewDataChanged = sal_True;
246 mpPreViewData->SetLandscape ( bVal );
249 break;
250 default:
251 throw UnknownPropertyException();
254 void SwXPrintPreviewSettings::_postSetValues ()
255 throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException )
257 if ( mbPreviewDataChanged )
259 mpDoc->SetPreViewPrtData ( mpPreViewData );
260 mbPreviewDataChanged = sal_False;
262 delete mpPreViewData;
263 mpPreViewData = NULL;
266 void SwXPrintPreviewSettings::_preGetValues ()
267 throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException )
269 if (mpDoc)
270 mpConstPreViewData = mpDoc->GetPreViewPrtData();
272 void SwXPrintPreviewSettings::_getSingleValue( const comphelper::PropertyInfo & rInfo, uno::Any & rValue )
273 throw(UnknownPropertyException, WrappedTargetException )
275 sal_Bool bBool = TRUE;
276 sal_Bool bBoolVal;
277 switch( rInfo.mnHandle )
279 case HANDLE_PRINTSET_PREVIEW_LEFT_MARGIN:
281 bBool = FALSE;
282 if ( mpConstPreViewData )
283 rValue <<= static_cast < sal_Int32 > ( TWIP_TO_MM100_UNSIGNED( mpConstPreViewData->GetLeftSpace() ) );
285 break;
286 case HANDLE_PRINTSET_PREVIEW_RIGHT_MARGIN:
288 bBool = FALSE;
289 if ( mpConstPreViewData )
290 rValue <<= static_cast < sal_Int32 > ( TWIP_TO_MM100_UNSIGNED( mpConstPreViewData->GetRightSpace() ) );
292 break;
293 case HANDLE_PRINTSET_PREVIEW_TOP_MARGIN:
295 bBool = FALSE;
296 if ( mpConstPreViewData )
297 rValue <<= static_cast < sal_Int32 > ( TWIP_TO_MM100_UNSIGNED( mpConstPreViewData->GetTopSpace() ) );
299 break;
300 case HANDLE_PRINTSET_PREVIEW_BOTTOM_MARGIN:
302 bBool = FALSE;
303 if ( mpConstPreViewData )
304 rValue <<= static_cast < sal_Int32 > ( TWIP_TO_MM100_UNSIGNED( mpConstPreViewData->GetBottomSpace() ) );
306 break;
307 case HANDLE_PRINTSET_PREVIEW_HORIZONTAL_SPACING:
309 bBool = FALSE;
310 if ( mpConstPreViewData )
311 rValue <<= static_cast < sal_Int32 > ( TWIP_TO_MM100_UNSIGNED( mpConstPreViewData->GetHorzSpace() ) );
313 break;
314 case HANDLE_PRINTSET_PREVIEW_VERTICAL_SPACING:
316 bBool = FALSE;
317 if ( mpConstPreViewData )
318 rValue <<= static_cast < sal_Int32 > ( TWIP_TO_MM100_UNSIGNED( mpConstPreViewData->GetVertSpace() ) );
320 break;
321 case HANDLE_PRINTSET_PREVIEW_NUM_ROWS:
323 bBool = FALSE;
324 if ( mpConstPreViewData )
325 rValue <<= static_cast < sal_Int8 > ( mpConstPreViewData->GetRow() );
327 break;
328 case HANDLE_PRINTSET_PREVIEW_NUM_COLUMNS:
330 bBool = FALSE;
331 if ( mpConstPreViewData )
332 rValue <<= static_cast < sal_Int8 > ( mpConstPreViewData->GetCol() );
334 break;
335 case HANDLE_PRINTSET_PREVIEW_LANDSCAPE:
337 if (mpConstPreViewData)
338 bBoolVal = mpConstPreViewData->GetLandscape();
339 else
340 bBool = FALSE;
342 break;
343 default:
344 throw UnknownPropertyException();
346 if(bBool)
347 rValue.setValue(&bBoolVal, ::getBooleanCppuType());
349 void SwXPrintPreviewSettings::_postGetValues ()
350 throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException )
352 mpConstPreViewData = NULL;
354 /* -----------------------------06.04.00 11:02--------------------------------
356 ---------------------------------------------------------------------------*/
357 OUString SwXPrintPreviewSettings::getImplementationName(void) throw( RuntimeException )
359 return OUString( RTL_CONSTASCII_USTRINGPARAM ( "SwXPrintPreviewSettings" ) );
361 /* -----------------------------06.04.00 11:02--------------------------------
363 ---------------------------------------------------------------------------*/
364 sal_Bool SwXPrintPreviewSettings::supportsService(const OUString& rServiceName) throw( RuntimeException )
366 return rServiceName.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "com.sun.star.text.PrintPreviewSettings") );
368 /* -----------------------------06.04.00 11:02--------------------------------
370 ---------------------------------------------------------------------------*/
371 Sequence< OUString > SwXPrintPreviewSettings::getSupportedServiceNames(void) throw( RuntimeException )
373 Sequence< OUString > aRet(1);
374 OUString* pArray = aRet.getArray();
375 pArray[0] = OUString( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.text.PrintPreviewSettings" ) );
376 return aRet;