1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SwXPrintPreviewSettings.cxx,v $
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>
40 #ifndef _COM_SUN_STAR_BEANS_PropertyAttribute_HPP_
41 #include <com/sun/star/beans/PropertyAttribute.hpp>
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
)
88 /*-- 17.12.98 12:54:05---------------------------------------------------
90 -----------------------------------------------------------------------*/
91 SwXPrintPreviewSettings::~SwXPrintPreviewSettings()
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 ) ,
104 dynamic_cast< XServiceInfo
* >( this ) ,
105 dynamic_cast< XPropertySet
* >( this ) ,
106 dynamic_cast< XMultiPropertySet
* >( this ) );
108 void SwXPrintPreviewSettings::acquire ()
111 OWeakObject::acquire();
113 void SwXPrintPreviewSettings::release ()
116 OWeakObject::release();
119 void SwXPrintPreviewSettings::_preSetValues ()
120 throw(UnknownPropertyException
, PropertyVetoException
, IllegalArgumentException
, WrappedTargetException
)
124 const SwPagePreViewPrtData
*pConstPrtData
= mpDoc
->GetPreViewPrtData();
125 mpPreViewData
= new SwPagePreViewPrtData
;
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
:
150 nVal
= MM100_TO_TWIP( nVal
);
151 if ( nVal
!= static_cast < sal_Int32
> (mpPreViewData
->GetLeftSpace() ) )
153 mbPreviewDataChanged
= sal_True
;
154 mpPreViewData
->SetLeftSpace( nVal
);
158 case HANDLE_PRINTSET_PREVIEW_RIGHT_MARGIN
:
162 nVal
= MM100_TO_TWIP( nVal
);
163 if ( nVal
!= static_cast < sal_Int32
> (mpPreViewData
->GetRightSpace() ) )
165 mbPreviewDataChanged
= sal_True
;
166 mpPreViewData
->SetRightSpace( nVal
);
170 case HANDLE_PRINTSET_PREVIEW_TOP_MARGIN
:
174 nVal
= MM100_TO_TWIP( nVal
);
175 if ( nVal
!= static_cast < sal_Int32
> ( mpPreViewData
->GetTopSpace() ) )
177 mbPreviewDataChanged
= sal_True
;
178 mpPreViewData
->SetTopSpace( nVal
);
182 case HANDLE_PRINTSET_PREVIEW_BOTTOM_MARGIN
:
186 nVal
= MM100_TO_TWIP( nVal
);
187 if ( nVal
!= static_cast < sal_Int32
> ( mpPreViewData
->GetBottomSpace() ) )
189 mbPreviewDataChanged
= sal_True
;
190 mpPreViewData
->SetBottomSpace( nVal
);
194 case HANDLE_PRINTSET_PREVIEW_HORIZONTAL_SPACING
:
198 nVal
= MM100_TO_TWIP( nVal
);
199 if ( nVal
!= static_cast < sal_Int32
> ( mpPreViewData
->GetHorzSpace() ) )
201 mbPreviewDataChanged
= sal_True
;
202 mpPreViewData
->SetHorzSpace( nVal
);
206 case HANDLE_PRINTSET_PREVIEW_VERTICAL_SPACING
:
210 nVal
= MM100_TO_TWIP( nVal
);
211 if ( nVal
!= static_cast < sal_Int32
> ( mpPreViewData
->GetVertSpace() ) )
213 mbPreviewDataChanged
= sal_True
;
214 mpPreViewData
->SetVertSpace( nVal
);
218 case HANDLE_PRINTSET_PREVIEW_NUM_ROWS
:
222 if ( nVal
!= mpPreViewData
->GetRow() )
224 mbPreviewDataChanged
= sal_True
;
225 mpPreViewData
->SetRow( nVal
);
229 case HANDLE_PRINTSET_PREVIEW_NUM_COLUMNS
:
233 if ( nVal
!= mpPreViewData
->GetCol() )
235 mbPreviewDataChanged
= sal_True
;
236 mpPreViewData
->SetCol( nVal
);
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
);
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
)
270 mpConstPreViewData
= mpDoc
->GetPreViewPrtData();
272 void SwXPrintPreviewSettings::_getSingleValue( const comphelper::PropertyInfo
& rInfo
, uno::Any
& rValue
)
273 throw(UnknownPropertyException
, WrappedTargetException
)
275 sal_Bool bBool
= TRUE
;
277 switch( rInfo
.mnHandle
)
279 case HANDLE_PRINTSET_PREVIEW_LEFT_MARGIN
:
282 if ( mpConstPreViewData
)
283 rValue
<<= static_cast < sal_Int32
> ( TWIP_TO_MM100_UNSIGNED( mpConstPreViewData
->GetLeftSpace() ) );
286 case HANDLE_PRINTSET_PREVIEW_RIGHT_MARGIN
:
289 if ( mpConstPreViewData
)
290 rValue
<<= static_cast < sal_Int32
> ( TWIP_TO_MM100_UNSIGNED( mpConstPreViewData
->GetRightSpace() ) );
293 case HANDLE_PRINTSET_PREVIEW_TOP_MARGIN
:
296 if ( mpConstPreViewData
)
297 rValue
<<= static_cast < sal_Int32
> ( TWIP_TO_MM100_UNSIGNED( mpConstPreViewData
->GetTopSpace() ) );
300 case HANDLE_PRINTSET_PREVIEW_BOTTOM_MARGIN
:
303 if ( mpConstPreViewData
)
304 rValue
<<= static_cast < sal_Int32
> ( TWIP_TO_MM100_UNSIGNED( mpConstPreViewData
->GetBottomSpace() ) );
307 case HANDLE_PRINTSET_PREVIEW_HORIZONTAL_SPACING
:
310 if ( mpConstPreViewData
)
311 rValue
<<= static_cast < sal_Int32
> ( TWIP_TO_MM100_UNSIGNED( mpConstPreViewData
->GetHorzSpace() ) );
314 case HANDLE_PRINTSET_PREVIEW_VERTICAL_SPACING
:
317 if ( mpConstPreViewData
)
318 rValue
<<= static_cast < sal_Int32
> ( TWIP_TO_MM100_UNSIGNED( mpConstPreViewData
->GetVertSpace() ) );
321 case HANDLE_PRINTSET_PREVIEW_NUM_ROWS
:
324 if ( mpConstPreViewData
)
325 rValue
<<= static_cast < sal_Int8
> ( mpConstPreViewData
->GetRow() );
328 case HANDLE_PRINTSET_PREVIEW_NUM_COLUMNS
:
331 if ( mpConstPreViewData
)
332 rValue
<<= static_cast < sal_Int8
> ( mpConstPreViewData
->GetCol() );
335 case HANDLE_PRINTSET_PREVIEW_LANDSCAPE
:
337 if (mpConstPreViewData
)
338 bBoolVal
= mpConstPreViewData
->GetLandscape();
344 throw UnknownPropertyException();
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" ) );