update dev300-m58
[ooovba.git] / starmath / source / unomodel.cxx
blob8339e4ed666bd429f0817f8d56f65fc9fb1fd518
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: unomodel.cxx,v $
10 * $Revision: 1.49 $
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_starmath.hxx"
35 #include <vos/mutex.hxx>
36 #include <osl/mutex.hxx>
37 #include <sfx2/printer.hxx>
38 #include <vcl/svapp.hxx>
39 #include <svtools/ctrltool.hxx>
40 #include <svtools/itemprop.hxx>
41 #include <unotools/localedatawrapper.hxx>
42 #include <unotools/processfactory.hxx>
43 #include <svx/paperinf.hxx>
44 #include <vcl/settings.hxx>
45 #include <toolkit/awt/vclxdevice.hxx>
46 #include <com/sun/star/beans/PropertyState.hpp>
47 #include <com/sun/star/beans/PropertyAttribute.hpp>
48 #include <com/sun/star/formula/SymbolDescriptor.hpp>
49 #include <com/sun/star/awt/Size.hpp>
50 #include <com/sun/star/script/XLibraryContainer.hpp>
51 #include <xmloff/xmluconv.hxx>
52 #include <rtl/ustrbuf.hxx>
53 #include <comphelper/propertysetinfo.hxx>
54 #include <unomodel.hxx>
55 #include <document.hxx>
56 #include <view.hxx>
57 #include <symbol.hxx>
58 #ifndef STARMATH_HRC
59 #include <starmath.hrc>
60 #endif
61 #include <config.hxx>
63 #include <smdll.hxx>
65 using namespace ::vos;
66 using namespace ::rtl;
67 using namespace ::cppu;
68 using namespace ::std;
69 using namespace ::comphelper;
70 using namespace ::com::sun::star;
71 using namespace ::com::sun::star::uno;
72 using namespace ::com::sun::star::beans;
73 using namespace ::com::sun::star::lang;
74 using namespace ::com::sun::star::formula;
75 using namespace ::com::sun::star::view;
76 using namespace ::com::sun::star::script;
78 #define TWIP_TO_MM100(TWIP) ((TWIP) >= 0 ? (((TWIP)*127L+36L)/72L) : (((TWIP)*127L-36L)/72L))
79 #define MM100_TO_TWIP(MM100) ((MM100) >= 0 ? (((MM100)*72L+63L)/127L) : (((MM100)*72L-63L)/127L))
82 ////////////////////////////////////////
84 // class SmModel
86 #define PROPERTY_NONE 0
87 enum SmModelPropertyHandles
89 HANDLE_FORMULA,
90 HANDLE_FONT_NAME_VARIABLES,
91 HANDLE_FONT_NAME_FUNCTIONS,
92 HANDLE_FONT_NAME_NUMBERS,
93 HANDLE_FONT_NAME_TEXT,
94 HANDLE_CUSTOM_FONT_NAME_SERIF,
95 HANDLE_CUSTOM_FONT_NAME_SANS,
96 HANDLE_CUSTOM_FONT_NAME_FIXED,
97 HANDLE_CUSTOM_FONT_FIXED_POSTURE,
98 HANDLE_CUSTOM_FONT_FIXED_WEIGHT,
99 HANDLE_CUSTOM_FONT_SANS_POSTURE,
100 HANDLE_CUSTOM_FONT_SANS_WEIGHT,
101 HANDLE_CUSTOM_FONT_SERIF_POSTURE,
102 HANDLE_CUSTOM_FONT_SERIF_WEIGHT,
103 HANDLE_FONT_VARIABLES_POSTURE,
104 HANDLE_FONT_VARIABLES_WEIGHT,
105 HANDLE_FONT_FUNCTIONS_POSTURE,
106 HANDLE_FONT_FUNCTIONS_WEIGHT,
107 HANDLE_FONT_NUMBERS_POSTURE,
108 HANDLE_FONT_NUMBERS_WEIGHT,
109 HANDLE_FONT_TEXT_POSTURE,
110 HANDLE_FONT_TEXT_WEIGHT,
111 HANDLE_BASE_FONT_HEIGHT,
112 HANDLE_RELATIVE_FONT_HEIGHT_TEXT,
113 HANDLE_RELATIVE_FONT_HEIGHT_INDICES,
114 HANDLE_RELATIVE_FONT_HEIGHT_FUNCTIONS,
115 HANDLE_RELATIVE_FONT_HEIGHT_OPERATORS,
116 HANDLE_RELATIVE_FONT_HEIGHT_LIMITS,
117 HANDLE_IS_TEXT_MODE,
118 HANDLE_ALIGNMENT,
119 HANDLE_RELATIVE_SPACING,
120 HANDLE_RELATIVE_LINE_SPACING,
121 HANDLE_RELATIVE_ROOT_SPACING,
122 HANDLE_RELATIVE_INDEX_SUPERSCRIPT,
123 HANDLE_RELATIVE_INDEX_SUBSCRIPT,
124 HANDLE_RELATIVE_FRACTION_NUMERATOR_HEIGHT,
125 HANDLE_RELATIVE_FRACTION_DENOMINATOR_DEPTH,
126 HANDLE_RELATIVE_FRACTION_BAR_EXCESS_LENGTH,
127 HANDLE_RELATIVE_FRACTION_BAR_LINE_WEIGHT,
128 HANDLE_RELATIVE_UPPER_LIMIT_DISTANCE,
129 HANDLE_RELATIVE_LOWER_LIMIT_DISTANCE,
130 HANDLE_RELATIVE_BRACKET_EXCESS_SIZE,
131 HANDLE_RELATIVE_BRACKET_DISTANCE,
132 HANDLE_IS_SCALE_ALL_BRACKETS,
133 HANDLE_RELATIVE_SCALE_BRACKET_EXCESS_SIZE,
134 HANDLE_RELATIVE_MATRIX_LINE_SPACING,
135 HANDLE_RELATIVE_MATRIX_COLUMN_SPACING,
136 HANDLE_RELATIVE_SYMBOL_PRIMARY_HEIGHT,
137 HANDLE_RELATIVE_SYMBOL_MINIMUM_HEIGHT,
138 HANDLE_RELATIVE_OPERATOR_EXCESS_SIZE,
139 HANDLE_RELATIVE_OPERATOR_SPACING,
140 HANDLE_LEFT_MARGIN,
141 HANDLE_RIGHT_MARGIN,
142 HANDLE_TOP_MARGIN,
143 HANDLE_BOTTOM_MARGIN,
144 HANDLE_PRINTER_NAME,
145 HANDLE_PRINTER_SETUP,
146 HANDLE_SYMBOLS,
147 HANDLE_BASIC_LIBRARIES, /* #93295# */
148 HANDLE_RUNTIME_UID,
149 // --> PB 2004-08-25 #i33095# Security Options
150 HANDLE_LOAD_READONLY,
151 // <--
152 HANDLE_DIALOG_LIBRARIES // #i73329#
155 PropertySetInfo * lcl_createModelPropertyInfo ()
157 static PropertyMapEntry aModelPropertyInfoMap[] =
159 { RTL_CONSTASCII_STRINGPARAM( "Alignment" ), HANDLE_ALIGNMENT , &::getCppuType((const sal_Int16*)0), PROPERTY_NONE, 0},
160 { RTL_CONSTASCII_STRINGPARAM( "BaseFontHeight" ), HANDLE_BASE_FONT_HEIGHT , &::getCppuType((const sal_Int16*)0), PROPERTY_NONE, 0},
161 { RTL_CONSTASCII_STRINGPARAM( "BasicLibraries" ), HANDLE_BASIC_LIBRARIES , &::getCppuType((const uno::Reference< script::XLibraryContainer > *)0), PropertyAttribute::READONLY, 0},
162 { RTL_CONSTASCII_STRINGPARAM( "BottomMargin" ), HANDLE_BOTTOM_MARGIN , &::getCppuType((const sal_Int16*)0), PROPERTY_NONE, DIS_BOTTOMSPACE },
163 { RTL_CONSTASCII_STRINGPARAM( "CustomFontNameFixed" ), HANDLE_CUSTOM_FONT_NAME_FIXED , &::getCppuType((const OUString*)0), PROPERTY_NONE, FNT_FIXED },
164 { RTL_CONSTASCII_STRINGPARAM( "CustomFontNameSans" ), HANDLE_CUSTOM_FONT_NAME_SANS , &::getCppuType((const OUString*)0), PROPERTY_NONE, FNT_SANS },
165 { RTL_CONSTASCII_STRINGPARAM( "CustomFontNameSerif" ), HANDLE_CUSTOM_FONT_NAME_SERIF , &::getCppuType((const OUString*)0), PROPERTY_NONE, FNT_SERIF },
166 { RTL_CONSTASCII_STRINGPARAM( "DialogLibraries" ), HANDLE_DIALOG_LIBRARIES , &::getCppuType((const uno::Reference< script::XLibraryContainer > *)0), PropertyAttribute::READONLY, 0},
167 { RTL_CONSTASCII_STRINGPARAM( "FontFixedIsBold"), HANDLE_CUSTOM_FONT_FIXED_WEIGHT , &::getBooleanCppuType(), PROPERTY_NONE, FNT_FIXED},
168 { RTL_CONSTASCII_STRINGPARAM( "FontFixedIsItalic"), HANDLE_CUSTOM_FONT_FIXED_POSTURE , &::getBooleanCppuType(), PROPERTY_NONE, FNT_FIXED},
169 { RTL_CONSTASCII_STRINGPARAM( "FontFunctionsIsBold"), HANDLE_FONT_FUNCTIONS_WEIGHT , &::getBooleanCppuType(), PROPERTY_NONE, FNT_FUNCTION},
170 { RTL_CONSTASCII_STRINGPARAM( "FontFunctionsIsItalic"), HANDLE_FONT_FUNCTIONS_POSTURE , &::getBooleanCppuType(), PROPERTY_NONE, FNT_FUNCTION},
171 { RTL_CONSTASCII_STRINGPARAM( "FontNameFunctions" ), HANDLE_FONT_NAME_FUNCTIONS , &::getCppuType((const OUString*)0), PROPERTY_NONE, FNT_FUNCTION },
172 { RTL_CONSTASCII_STRINGPARAM( "FontNameNumbers" ), HANDLE_FONT_NAME_NUMBERS , &::getCppuType((const OUString*)0), PROPERTY_NONE, FNT_NUMBER },
173 { RTL_CONSTASCII_STRINGPARAM( "FontNameText" ), HANDLE_FONT_NAME_TEXT , &::getCppuType((const OUString*)0), PROPERTY_NONE, FNT_TEXT },
174 { RTL_CONSTASCII_STRINGPARAM( "FontNameVariables" ), HANDLE_FONT_NAME_VARIABLES , &::getCppuType((const OUString*)0), PROPERTY_NONE, FNT_VARIABLE },
175 { RTL_CONSTASCII_STRINGPARAM( "FontNumbersIsBold"), HANDLE_FONT_NUMBERS_WEIGHT , &::getBooleanCppuType(), PROPERTY_NONE, FNT_NUMBER},
176 { RTL_CONSTASCII_STRINGPARAM( "FontNumbersIsItalic"), HANDLE_FONT_NUMBERS_POSTURE , &::getBooleanCppuType(), PROPERTY_NONE, FNT_NUMBER},
177 { RTL_CONSTASCII_STRINGPARAM( "FontSansIsBold"), HANDLE_CUSTOM_FONT_SANS_WEIGHT , &::getBooleanCppuType(), PROPERTY_NONE, FNT_SANS},
178 { RTL_CONSTASCII_STRINGPARAM( "FontSansIsItalic"), HANDLE_CUSTOM_FONT_SANS_POSTURE , &::getBooleanCppuType(), PROPERTY_NONE, FNT_SANS},
179 { RTL_CONSTASCII_STRINGPARAM( "FontSerifIsBold"), HANDLE_CUSTOM_FONT_SERIF_WEIGHT , &::getBooleanCppuType(), PROPERTY_NONE, FNT_SERIF},
180 { RTL_CONSTASCII_STRINGPARAM( "FontSerifIsItalic"), HANDLE_CUSTOM_FONT_SERIF_POSTURE , &::getBooleanCppuType(), PROPERTY_NONE, FNT_SERIF},
181 { RTL_CONSTASCII_STRINGPARAM( "FontTextIsBold"), HANDLE_FONT_TEXT_WEIGHT , &::getBooleanCppuType(), PROPERTY_NONE, FNT_TEXT},
182 { RTL_CONSTASCII_STRINGPARAM( "FontTextIsItalic"), HANDLE_FONT_TEXT_POSTURE , &::getBooleanCppuType(), PROPERTY_NONE, FNT_TEXT},
183 { RTL_CONSTASCII_STRINGPARAM( "FontVariablesIsBold"), HANDLE_FONT_VARIABLES_WEIGHT , &::getBooleanCppuType(), PROPERTY_NONE, FNT_VARIABLE},
184 { RTL_CONSTASCII_STRINGPARAM( "FontVariablesIsItalic"), HANDLE_FONT_VARIABLES_POSTURE, &::getBooleanCppuType(), PROPERTY_NONE, FNT_VARIABLE},
185 { RTL_CONSTASCII_STRINGPARAM( "Formula" ), HANDLE_FORMULA , &::getCppuType((const OUString*)0), PROPERTY_NONE, 0},
186 { RTL_CONSTASCII_STRINGPARAM( "IsScaleAllBrackets" ), HANDLE_IS_SCALE_ALL_BRACKETS , &::getBooleanCppuType(), PROPERTY_NONE, 0},
187 { RTL_CONSTASCII_STRINGPARAM( "IsTextMode" ), HANDLE_IS_TEXT_MODE , &::getBooleanCppuType(), PROPERTY_NONE, 0},
188 { RTL_CONSTASCII_STRINGPARAM( "LeftMargin" ), HANDLE_LEFT_MARGIN , &::getCppuType((const sal_Int16*)0), PROPERTY_NONE, DIS_LEFTSPACE },
189 { RTL_CONSTASCII_STRINGPARAM( "PrinterName" ), HANDLE_PRINTER_NAME , &::getCppuType((const OUString*)0), PROPERTY_NONE, 0 },
190 { RTL_CONSTASCII_STRINGPARAM( "PrinterSetup" ), HANDLE_PRINTER_SETUP , &::getCppuType((const Sequence < sal_Int8 >*)0), PROPERTY_NONE, 0 },
191 { RTL_CONSTASCII_STRINGPARAM( "RelativeBracketDistance" ), HANDLE_RELATIVE_BRACKET_DISTANCE , &::getCppuType((const sal_Int16*)0), PROPERTY_NONE, DIS_BRACKETSPACE },
192 { RTL_CONSTASCII_STRINGPARAM( "RelativeBracketExcessSize" ), HANDLE_RELATIVE_BRACKET_EXCESS_SIZE , &::getCppuType((const sal_Int16*)0), PROPERTY_NONE, DIS_BRACKETSIZE },
193 { RTL_CONSTASCII_STRINGPARAM( "RelativeFontHeightFunctions" ), HANDLE_RELATIVE_FONT_HEIGHT_FUNCTIONS , &::getCppuType((const sal_Int16*)0), PROPERTY_NONE, SIZ_FUNCTION},
194 { RTL_CONSTASCII_STRINGPARAM( "RelativeFontHeightIndices" ), HANDLE_RELATIVE_FONT_HEIGHT_INDICES , &::getCppuType((const sal_Int16*)0), PROPERTY_NONE, SIZ_INDEX },
195 { RTL_CONSTASCII_STRINGPARAM( "RelativeFontHeightLimits" ), HANDLE_RELATIVE_FONT_HEIGHT_LIMITS , &::getCppuType((const sal_Int16*)0), PROPERTY_NONE, SIZ_LIMITS },
196 { RTL_CONSTASCII_STRINGPARAM( "RelativeFontHeightOperators" ), HANDLE_RELATIVE_FONT_HEIGHT_OPERATORS , &::getCppuType((const sal_Int16*)0), PROPERTY_NONE, SIZ_OPERATOR},
197 { RTL_CONSTASCII_STRINGPARAM( "RelativeFontHeightText" ), HANDLE_RELATIVE_FONT_HEIGHT_TEXT , &::getCppuType((const sal_Int16*)0), PROPERTY_NONE, SIZ_TEXT },
198 { RTL_CONSTASCII_STRINGPARAM( "RelativeFractionBarExcessLength"), HANDLE_RELATIVE_FRACTION_BAR_EXCESS_LENGTH, &::getCppuType((const sal_Int16*)0), PROPERTY_NONE, DIS_FRACTION },
199 { RTL_CONSTASCII_STRINGPARAM( "RelativeFractionBarLineWeight" ), HANDLE_RELATIVE_FRACTION_BAR_LINE_WEIGHT , &::getCppuType((const sal_Int16*)0), PROPERTY_NONE, DIS_STROKEWIDTH },
200 { RTL_CONSTASCII_STRINGPARAM( "RelativeFractionDenominatorDepth"), HANDLE_RELATIVE_FRACTION_DENOMINATOR_DEPTH, &::getCppuType((const sal_Int16*)0), PROPERTY_NONE, DIS_DENOMINATOR },
201 { RTL_CONSTASCII_STRINGPARAM( "RelativeFractionNumeratorHeight" ), HANDLE_RELATIVE_FRACTION_NUMERATOR_HEIGHT , &::getCppuType((const sal_Int16*)0), PROPERTY_NONE, DIS_NUMERATOR },
202 { RTL_CONSTASCII_STRINGPARAM( "RelativeIndexSubscript" ), HANDLE_RELATIVE_INDEX_SUBSCRIPT , &::getCppuType((const sal_Int16*)0), PROPERTY_NONE, DIS_SUBSCRIPT },
203 { RTL_CONSTASCII_STRINGPARAM( "RelativeIndexSuperscript" ), HANDLE_RELATIVE_INDEX_SUPERSCRIPT , &::getCppuType((const sal_Int16*)0), PROPERTY_NONE, DIS_SUPERSCRIPT },
204 { RTL_CONSTASCII_STRINGPARAM( "RelativeLineSpacing" ), HANDLE_RELATIVE_LINE_SPACING , &::getCppuType((const sal_Int16*)0), PROPERTY_NONE, DIS_VERTICAL },
205 { RTL_CONSTASCII_STRINGPARAM( "RelativeLowerLimitDistance" ), HANDLE_RELATIVE_LOWER_LIMIT_DISTANCE , &::getCppuType((const sal_Int16*)0), PROPERTY_NONE, DIS_LOWERLIMIT },
206 { RTL_CONSTASCII_STRINGPARAM( "RelativeMatrixColumnSpacing" ), HANDLE_RELATIVE_MATRIX_COLUMN_SPACING , &::getCppuType((const sal_Int16*)0), PROPERTY_NONE, DIS_MATRIXCOL},
207 { RTL_CONSTASCII_STRINGPARAM( "RelativeMatrixLineSpacing" ), HANDLE_RELATIVE_MATRIX_LINE_SPACING , &::getCppuType((const sal_Int16*)0), PROPERTY_NONE, DIS_MATRIXROW},
208 { RTL_CONSTASCII_STRINGPARAM( "RelativeOperatorExcessSize" ), HANDLE_RELATIVE_OPERATOR_EXCESS_SIZE , &::getCppuType((const sal_Int16*)0), PROPERTY_NONE, DIS_OPERATORSIZE },
209 { RTL_CONSTASCII_STRINGPARAM( "RelativeOperatorSpacing" ), HANDLE_RELATIVE_OPERATOR_SPACING , &::getCppuType((const sal_Int16*)0), PROPERTY_NONE, DIS_OPERATORSPACE},
210 { RTL_CONSTASCII_STRINGPARAM( "RelativeRootSpacing" ), HANDLE_RELATIVE_ROOT_SPACING , &::getCppuType((const sal_Int16*)0), PROPERTY_NONE, DIS_ROOT },
211 { RTL_CONSTASCII_STRINGPARAM( "RelativeScaleBracketExcessSize" ), HANDLE_RELATIVE_SCALE_BRACKET_EXCESS_SIZE , &::getCppuType((const sal_Int16*)0), PROPERTY_NONE, DIS_NORMALBRACKETSIZE},
212 { RTL_CONSTASCII_STRINGPARAM( "RelativeSpacing" ), HANDLE_RELATIVE_SPACING , &::getCppuType((const sal_Int16*)0), PROPERTY_NONE, DIS_HORIZONTAL },
213 { RTL_CONSTASCII_STRINGPARAM( "RelativeSymbolMinimumHeight" ), HANDLE_RELATIVE_SYMBOL_MINIMUM_HEIGHT , &::getCppuType((const sal_Int16*)0), PROPERTY_NONE, DIS_ORNAMENTSPACE },
214 { RTL_CONSTASCII_STRINGPARAM( "RelativeSymbolPrimaryHeight" ), HANDLE_RELATIVE_SYMBOL_PRIMARY_HEIGHT , &::getCppuType((const sal_Int16*)0), PROPERTY_NONE, DIS_ORNAMENTSIZE },
215 { RTL_CONSTASCII_STRINGPARAM( "RelativeUpperLimitDistance" ), HANDLE_RELATIVE_UPPER_LIMIT_DISTANCE , &::getCppuType((const sal_Int16*)0), PROPERTY_NONE, DIS_UPPERLIMIT },
216 { RTL_CONSTASCII_STRINGPARAM( "RightMargin" ), HANDLE_RIGHT_MARGIN , &::getCppuType((const sal_Int16*)0), PROPERTY_NONE, DIS_RIGHTSPACE },
217 { RTL_CONSTASCII_STRINGPARAM( "RuntimeUID" ), HANDLE_RUNTIME_UID , &::getCppuType(static_cast< const rtl::OUString * >(0)), PropertyAttribute::READONLY, 0 },
218 { RTL_CONSTASCII_STRINGPARAM( "Symbols" ), HANDLE_SYMBOLS , &::getCppuType((const Sequence < SymbolDescriptor > *)0), PROPERTY_NONE, 0 },
219 { RTL_CONSTASCII_STRINGPARAM( "TopMargin" ), HANDLE_TOP_MARGIN , &::getCppuType((const sal_Int16*)0), PROPERTY_NONE, DIS_TOPSPACE },
220 // --> PB 2004-08-25 #i33095# Security Options
221 { RTL_CONSTASCII_STRINGPARAM( "LoadReadonly" ), HANDLE_LOAD_READONLY, &::getBooleanCppuType(), PROPERTY_NONE, 0 },
222 // <--
223 { NULL, 0, 0, NULL, 0, 0 }
225 PropertySetInfo *pInfo = new PropertySetInfo ( aModelPropertyInfoMap );
226 return pInfo;
228 //-----------------------------------------------------------------------
229 SmModel::SmModel( SfxObjectShell *pObjSh )
230 : SfxBaseModel(pObjSh)
231 , PropertySetHelper ( lcl_createModelPropertyInfo () )
234 //-----------------------------------------------------------------------
235 SmModel::~SmModel() throw ()
238 /*-- 28.03.00 14:18:17---------------------------------------------------
240 -----------------------------------------------------------------------*/
241 uno::Any SAL_CALL SmModel::queryInterface( const uno::Type& rType ) throw(uno::RuntimeException)
243 uno::Any aRet = ::cppu::queryInterface ( rType,
244 // OWeakObject interfaces
245 dynamic_cast< XInterface* > ( static_cast< XUnoTunnel* > ( this )),
246 static_cast< XWeak* > ( this ),
247 // PropertySetHelper interfaces
248 static_cast< XPropertySet* > ( this ),
249 static_cast< XMultiPropertySet* > ( this ),
250 //static_cast< XPropertyState* > ( this ),
251 // my own interfaces
252 static_cast< XServiceInfo* > ( this ),
253 static_cast< XRenderable* > ( this ) );
254 if (!aRet.hasValue())
255 aRet = SfxBaseModel::queryInterface ( rType );
256 return aRet;
258 /*-- 28.03.00 14:18:18---------------------------------------------------
260 -----------------------------------------------------------------------*/
261 void SAL_CALL SmModel::acquire() throw()
263 OWeakObject::acquire();
265 /*-- 28.03.00 14:18:18---------------------------------------------------
267 -----------------------------------------------------------------------*/
268 void SAL_CALL SmModel::release() throw()
270 OWeakObject::release();
272 /*-- 28.03.00 14:18:19---------------------------------------------------
274 -----------------------------------------------------------------------*/
275 uno::Sequence< uno::Type > SAL_CALL SmModel::getTypes( ) throw(uno::RuntimeException)
277 ::vos::OGuard aGuard(Application::GetSolarMutex());
278 uno::Sequence< uno::Type > aTypes = SfxBaseModel::getTypes();
279 sal_Int32 nLen = aTypes.getLength();
280 aTypes.realloc(nLen + 4);
281 uno::Type* pTypes = aTypes.getArray();
282 pTypes[nLen++] = ::getCppuType((Reference<XServiceInfo>*)0);
283 pTypes[nLen++] = ::getCppuType((Reference<XPropertySet>*)0);
284 pTypes[nLen++] = ::getCppuType((Reference<XMultiPropertySet>*)0);
285 pTypes[nLen++] = ::getCppuType((Reference<XRenderable>*)0);
287 // XPropertyState not supported?? (respective virtual functions from
288 // PropertySetHelper not overloaded)
289 //pTypes[nLen++] = ::getCppuType((Reference<XPropertyState>*)0);
291 return aTypes;
293 /* -----------------------------28.03.00 14:23--------------------------------
295 ---------------------------------------------------------------------------*/
296 const uno::Sequence< sal_Int8 > & SmModel::getUnoTunnelId()
298 static osl::Mutex aCreateMutex;
299 osl::Guard<osl::Mutex> aGuard( aCreateMutex );
301 static uno::Sequence< sal_Int8 > aSeq;
302 if(!aSeq.getLength())
304 aSeq.realloc( 16 );
305 rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True );
307 return aSeq;
308 } /* -----------------------------28.03.00 14:23--------------------------------
310 ---------------------------------------------------------------------------*/
311 sal_Int64 SAL_CALL SmModel::getSomething( const uno::Sequence< sal_Int8 >& rId )
312 throw(uno::RuntimeException)
314 if( rId.getLength() == 16
315 && 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
316 rId.getConstArray(), 16 ) )
318 return sal::static_int_cast< sal_Int64 >(reinterpret_cast< sal_uIntPtr >(this));
321 return SfxBaseModel::getSomething( rId );
323 /*-- 07.01.00 16:32:59---------------------------------------------------
325 -----------------------------------------------------------------------*/
326 /*-- 07.01.00 16:33:00---------------------------------------------------
328 -----------------------------------------------------------------------*/
329 sal_Int16 lcl_AnyToINT16(const uno::Any& rAny)
331 uno::TypeClass eType = rAny.getValueType().getTypeClass();
333 sal_Int16 nRet = 0;
334 if( eType == uno::TypeClass_DOUBLE )
335 nRet = (sal_Int16)*(double*)rAny.getValue();
336 else if( eType == uno::TypeClass_FLOAT )
337 nRet = (sal_Int16)*(float*)rAny.getValue();
338 else
339 rAny >>= nRet;
340 return nRet;
342 //-----------------------------------------------------------------------------
344 OUString SmModel::getImplementationName(void) throw( uno::RuntimeException )
346 return getImplementationName_Static();
350 ::rtl::OUString SmModel::getImplementationName_Static()
352 return rtl::OUString::createFromAscii("com.sun.star.comp.math.FormulaDocument");
355 /*-- 20.01.04 11:21:00---------------------------------------------------
357 -----------------------------------------------------------------------*/
358 sal_Bool SmModel::supportsService(const OUString& rServiceName) throw( uno::RuntimeException )
360 return (
361 rServiceName == A2OU("com.sun.star.document.OfficeDocument" ) ||
362 rServiceName == A2OU("com.sun.star.formula.FormulaProperties")
365 /*-- 20.01.04 11:21:00---------------------------------------------------
367 -----------------------------------------------------------------------*/
368 uno::Sequence< OUString > SmModel::getSupportedServiceNames(void) throw( uno::RuntimeException )
370 return getSupportedServiceNames_Static();
373 uno::Sequence< OUString > SmModel::getSupportedServiceNames_Static(void)
375 ::vos::OGuard aGuard(Application::GetSolarMutex());
377 uno::Sequence< OUString > aRet(2);
378 OUString* pArray = aRet.getArray();
379 pArray[0] = A2OU("com.sun.star.document.OfficeDocument");
380 pArray[1] = A2OU("com.sun.star.formula.FormulaProperties");
381 return aRet;
384 void SmModel::_setPropertyValues(const PropertyMapEntry** ppEntries, const Any* pValues)
385 throw( UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException)
387 ::vos::OGuard aGuard(Application::GetSolarMutex());
389 SmDocShell *pDocSh = static_cast < SmDocShell * > (GetObjectShell());
391 if ( NULL == pDocSh )
392 throw UnknownPropertyException();
394 SmFormat aFormat = pDocSh->GetFormat();
396 for (; *ppEntries; ppEntries++, pValues++ )
398 if ((*ppEntries)->mnAttributes & PropertyAttribute::READONLY)
399 throw PropertyVetoException();
401 switch ( (*ppEntries)->mnHandle )
403 case HANDLE_FORMULA:
405 OUString aText;
406 *pValues >>= aText;
407 pDocSh->SetText(aText);
409 break;
410 case HANDLE_FONT_NAME_VARIABLES :
411 case HANDLE_FONT_NAME_FUNCTIONS :
412 case HANDLE_FONT_NAME_NUMBERS :
413 case HANDLE_FONT_NAME_TEXT :
414 case HANDLE_CUSTOM_FONT_NAME_SERIF :
415 case HANDLE_CUSTOM_FONT_NAME_SANS :
416 case HANDLE_CUSTOM_FONT_NAME_FIXED :
418 OUString aText;
419 *pValues >>= aText;
420 String sFontName = aText;
421 if(!sFontName.Len())
422 throw IllegalArgumentException();
424 if(aFormat.GetFont((*ppEntries)->mnMemberId).GetName() != sFontName)
426 const SmFace rOld = aFormat.GetFont((*ppEntries)->mnMemberId);
428 SmFace aSet( sFontName, rOld.GetSize() );
429 aSet.SetBorderWidth( rOld.GetBorderWidth() );
430 aSet.SetAlign( ALIGN_BASELINE );
431 aFormat.SetFont( (*ppEntries)->mnMemberId, aSet );
434 break;
435 case HANDLE_CUSTOM_FONT_FIXED_POSTURE:
436 case HANDLE_CUSTOM_FONT_SANS_POSTURE :
437 case HANDLE_CUSTOM_FONT_SERIF_POSTURE:
438 case HANDLE_FONT_VARIABLES_POSTURE :
439 case HANDLE_FONT_FUNCTIONS_POSTURE :
440 case HANDLE_FONT_NUMBERS_POSTURE :
441 case HANDLE_FONT_TEXT_POSTURE :
443 if((*pValues).getValueType() != ::getBooleanCppuType())
444 throw IllegalArgumentException();
445 BOOL bVal = *(sal_Bool*)(*pValues).getValue();
446 Font aNewFont(aFormat.GetFont((*ppEntries)->mnMemberId));
447 aNewFont.SetItalic((bVal) ? ITALIC_NORMAL : ITALIC_NONE);
448 aFormat.SetFont((*ppEntries)->mnMemberId, aNewFont);
450 break;
451 case HANDLE_CUSTOM_FONT_FIXED_WEIGHT :
452 case HANDLE_CUSTOM_FONT_SANS_WEIGHT :
453 case HANDLE_CUSTOM_FONT_SERIF_WEIGHT :
454 case HANDLE_FONT_VARIABLES_WEIGHT :
455 case HANDLE_FONT_FUNCTIONS_WEIGHT :
456 case HANDLE_FONT_NUMBERS_WEIGHT :
457 case HANDLE_FONT_TEXT_WEIGHT :
459 if((*pValues).getValueType() != ::getBooleanCppuType())
460 throw IllegalArgumentException();
461 BOOL bVal = *(sal_Bool*)(*pValues).getValue();
462 Font aNewFont(aFormat.GetFont((*ppEntries)->mnMemberId));
463 aNewFont.SetWeight((bVal) ? WEIGHT_BOLD : WEIGHT_NORMAL);
464 aFormat.SetFont((*ppEntries)->mnMemberId, aNewFont);
466 break;
467 case HANDLE_BASE_FONT_HEIGHT :
469 // Point!
470 sal_Int16 nVal = lcl_AnyToINT16(*pValues);
471 if(nVal < 1)
472 throw IllegalArgumentException();
473 Size aSize = aFormat.GetBaseSize();
474 nVal *= 20;
475 nVal = static_cast < sal_Int16 > ( TWIP_TO_MM100(nVal) );
476 aSize.Height() = nVal;
477 aFormat.SetBaseSize(aSize);
479 // apply base size to fonts
480 const Size aTmp( aFormat.GetBaseSize() );
481 for (USHORT i = FNT_BEGIN; i <= FNT_END; i++)
482 aFormat.SetFontSize(i, aTmp);
484 break;
485 case HANDLE_RELATIVE_FONT_HEIGHT_TEXT :
486 case HANDLE_RELATIVE_FONT_HEIGHT_INDICES :
487 case HANDLE_RELATIVE_FONT_HEIGHT_FUNCTIONS :
488 case HANDLE_RELATIVE_FONT_HEIGHT_OPERATORS :
489 case HANDLE_RELATIVE_FONT_HEIGHT_LIMITS :
491 sal_Int16 nVal = 0;
492 *pValues >>= nVal;
493 if(nVal < 1)
494 throw IllegalArgumentException();
495 aFormat.SetRelSize((*ppEntries)->mnMemberId, nVal);
497 break;
499 case HANDLE_IS_TEXT_MODE :
501 aFormat.SetTextmode(*(sal_Bool*)(*pValues).getValue());
503 break;
505 case HANDLE_ALIGNMENT :
507 // SmHorAlign uses the same values as HorizontalAlignment
508 sal_Int16 nVal = 0;
509 *pValues >>= nVal;
510 if(nVal < 0 || nVal > 2)
511 throw IllegalArgumentException();
512 aFormat.SetHorAlign((SmHorAlign)nVal);
514 break;
516 case HANDLE_RELATIVE_SPACING :
517 case HANDLE_RELATIVE_LINE_SPACING :
518 case HANDLE_RELATIVE_ROOT_SPACING :
519 case HANDLE_RELATIVE_INDEX_SUPERSCRIPT :
520 case HANDLE_RELATIVE_INDEX_SUBSCRIPT :
521 case HANDLE_RELATIVE_FRACTION_NUMERATOR_HEIGHT :
522 case HANDLE_RELATIVE_FRACTION_DENOMINATOR_DEPTH:
523 case HANDLE_RELATIVE_FRACTION_BAR_EXCESS_LENGTH:
524 case HANDLE_RELATIVE_FRACTION_BAR_LINE_WEIGHT :
525 case HANDLE_RELATIVE_UPPER_LIMIT_DISTANCE :
526 case HANDLE_RELATIVE_LOWER_LIMIT_DISTANCE :
527 case HANDLE_RELATIVE_BRACKET_EXCESS_SIZE :
528 case HANDLE_RELATIVE_BRACKET_DISTANCE :
529 case HANDLE_RELATIVE_SCALE_BRACKET_EXCESS_SIZE :
530 case HANDLE_RELATIVE_MATRIX_LINE_SPACING :
531 case HANDLE_RELATIVE_MATRIX_COLUMN_SPACING :
532 case HANDLE_RELATIVE_SYMBOL_PRIMARY_HEIGHT :
533 case HANDLE_RELATIVE_SYMBOL_MINIMUM_HEIGHT :
534 case HANDLE_RELATIVE_OPERATOR_EXCESS_SIZE :
535 case HANDLE_RELATIVE_OPERATOR_SPACING :
536 case HANDLE_LEFT_MARGIN :
537 case HANDLE_RIGHT_MARGIN :
538 case HANDLE_TOP_MARGIN :
539 case HANDLE_BOTTOM_MARGIN :
541 sal_Int16 nVal = 0;
542 *pValues >>= nVal;
543 if(nVal < 0)
544 throw IllegalArgumentException();
545 aFormat.SetDistance((*ppEntries)->mnMemberId, nVal);
547 break;
548 case HANDLE_IS_SCALE_ALL_BRACKETS :
549 aFormat.SetScaleNormalBrackets(*(sal_Bool*)(*pValues).getValue());
550 break;
551 case HANDLE_PRINTER_NAME:
553 // embedded documents just ignore this property for now
554 if ( pDocSh->GetCreateMode() != SFX_CREATE_MODE_EMBEDDED )
556 SfxPrinter *pPrinter = pDocSh->GetPrinter ( );
557 if (pPrinter)
559 OUString sPrinterName;
560 if (*pValues >>= sPrinterName )
562 if ( sPrinterName.getLength() )
564 SfxPrinter *pNewPrinter = new SfxPrinter ( pPrinter->GetOptions().Clone(), sPrinterName );
565 if (pNewPrinter->IsKnown())
566 pDocSh->SetPrinter ( pNewPrinter );
567 else
568 delete pNewPrinter;
571 else
572 throw IllegalArgumentException();
576 break;
577 case HANDLE_PRINTER_SETUP:
579 Sequence < sal_Int8 > aSequence;
580 if ( *pValues >>= aSequence )
582 sal_uInt32 nSize = aSequence.getLength();
583 SvMemoryStream aStream ( aSequence.getArray(), nSize, STREAM_READ );
584 aStream.Seek ( STREAM_SEEK_TO_BEGIN );
585 static sal_uInt16 __READONLY_DATA nRange[] =
587 SID_PRINTSIZE, SID_PRINTSIZE,
588 SID_PRINTZOOM, SID_PRINTZOOM,
589 SID_PRINTTITLE, SID_PRINTTITLE,
590 SID_PRINTTEXT, SID_PRINTTEXT,
591 SID_PRINTFRAME, SID_PRINTFRAME,
592 SID_NO_RIGHT_SPACES, SID_NO_RIGHT_SPACES,
595 SfxItemSet *pItemSet = new SfxItemSet( pDocSh->GetPool(), nRange );
596 SmModule *pp = SM_MOD1();
597 pp->GetConfig()->ConfigToItemSet(*pItemSet);
598 SfxPrinter *pPrinter = SfxPrinter::Create ( aStream, pItemSet );
600 pDocSh->SetPrinter( pPrinter );
602 else
603 throw IllegalArgumentException();
605 break;
606 case HANDLE_SYMBOLS:
608 // this is set
609 Sequence < SymbolDescriptor > aSequence;
610 if ( *pValues >>= aSequence )
612 sal_uInt32 nSize = aSequence.getLength();
613 SmModule *pp = SM_MOD1();
614 SmSymSetManager &rManager = pp->GetSymSetManager();
615 SymbolDescriptor *pDescriptor = aSequence.getArray();
616 for (sal_uInt32 i = 0; i < nSize ; i++, pDescriptor++)
618 Font aFont;
619 aFont.SetName ( pDescriptor->sFontName );
620 aFont.SetCharSet ( static_cast < rtl_TextEncoding > (pDescriptor->nCharSet) );
621 aFont.SetFamily ( static_cast < FontFamily > (pDescriptor->nFamily ) );
622 aFont.SetPitch ( static_cast < FontPitch > (pDescriptor->nPitch ) );
623 aFont.SetWeight ( static_cast < FontWeight > (pDescriptor->nWeight ) );
624 aFont.SetItalic ( static_cast < FontItalic > (pDescriptor->nItalic ) );
625 SmSym aSymbol ( pDescriptor->sName, aFont, static_cast < sal_Unicode > (pDescriptor->nCharacter),
626 pDescriptor->sSymbolSet );
627 aSymbol.SetExportName ( pDescriptor->sExportName );
628 aSymbol.SetDocSymbol( TRUE );
629 rManager.AddReplaceSymbol ( aSymbol );
632 else
633 throw IllegalArgumentException();
635 break;
636 // --> PB 2004-08-25 #i33095# Security Options
637 case HANDLE_LOAD_READONLY :
639 if ( (*pValues).getValueType() != ::getBooleanCppuType() )
640 throw IllegalArgumentException();
641 sal_Bool bReadonly = FALSE;
642 if ( *pValues >>= bReadonly )
643 pDocSh->SetLoadReadonly( bReadonly );
644 break;
646 // <--
650 pDocSh->SetFormat( aFormat );
652 // #i67283# since about all of the above changes are likely to change
653 // the formula size we have to recalculate the vis-area now
654 pDocSh->SetVisArea( Rectangle( Point(0, 0), pDocSh->GetSize() ) );
657 void SmModel::_getPropertyValues( const PropertyMapEntry **ppEntries, Any *pValue )
658 throw( UnknownPropertyException, WrappedTargetException )
660 SmDocShell *pDocSh = static_cast < SmDocShell * > (GetObjectShell());
662 if ( NULL == pDocSh )
663 throw UnknownPropertyException();
665 const SmFormat & aFormat = pDocSh->GetFormat();
667 for (; *ppEntries; ppEntries++, pValue++ )
669 switch ( (*ppEntries)->mnHandle )
671 case HANDLE_FORMULA:
672 *pValue <<= OUString(pDocSh->GetText());
673 break;
674 case HANDLE_FONT_NAME_VARIABLES :
675 case HANDLE_FONT_NAME_FUNCTIONS :
676 case HANDLE_FONT_NAME_NUMBERS :
677 case HANDLE_FONT_NAME_TEXT :
678 case HANDLE_CUSTOM_FONT_NAME_SERIF :
679 case HANDLE_CUSTOM_FONT_NAME_SANS :
680 case HANDLE_CUSTOM_FONT_NAME_FIXED :
682 const SmFace & rFace = aFormat.GetFont((*ppEntries)->mnMemberId);
683 *pValue <<= OUString(rFace.GetName());
685 break;
686 case HANDLE_CUSTOM_FONT_FIXED_POSTURE:
687 case HANDLE_CUSTOM_FONT_SANS_POSTURE :
688 case HANDLE_CUSTOM_FONT_SERIF_POSTURE:
689 case HANDLE_FONT_VARIABLES_POSTURE :
690 case HANDLE_FONT_FUNCTIONS_POSTURE :
691 case HANDLE_FONT_NUMBERS_POSTURE :
692 case HANDLE_FONT_TEXT_POSTURE :
694 const SmFace & rFace = aFormat.GetFont((*ppEntries)->mnMemberId);
695 BOOL bVal = IsItalic( rFace );
696 (*pValue).setValue(&bVal, *(*ppEntries)->mpType);
698 break;
699 case HANDLE_CUSTOM_FONT_FIXED_WEIGHT :
700 case HANDLE_CUSTOM_FONT_SANS_WEIGHT :
701 case HANDLE_CUSTOM_FONT_SERIF_WEIGHT :
702 case HANDLE_FONT_VARIABLES_WEIGHT :
703 case HANDLE_FONT_FUNCTIONS_WEIGHT :
704 case HANDLE_FONT_NUMBERS_WEIGHT :
705 case HANDLE_FONT_TEXT_WEIGHT :
707 const SmFace & rFace = aFormat.GetFont((*ppEntries)->mnMemberId);
708 BOOL bVal = IsBold( rFace ); // bold?
709 (*pValue).setValue(&bVal, *(*ppEntries)->mpType);
711 break;
712 case HANDLE_BASE_FONT_HEIGHT :
714 // Point!
715 sal_Int16 nVal = static_cast < sal_Int16 > (aFormat.GetBaseSize().Height());
716 nVal = static_cast < sal_Int16 > (MM100_TO_TWIP(nVal));
717 nVal = (nVal + 10) / 20;
718 *pValue <<= nVal;
720 break;
721 case HANDLE_RELATIVE_FONT_HEIGHT_TEXT :
722 case HANDLE_RELATIVE_FONT_HEIGHT_INDICES :
723 case HANDLE_RELATIVE_FONT_HEIGHT_FUNCTIONS :
724 case HANDLE_RELATIVE_FONT_HEIGHT_OPERATORS :
725 case HANDLE_RELATIVE_FONT_HEIGHT_LIMITS :
726 *pValue <<= (sal_Int16) aFormat.GetRelSize((*ppEntries)->mnMemberId);
727 break;
729 case HANDLE_IS_TEXT_MODE :
731 sal_Bool bVal = aFormat.IsTextmode();
732 (*pValue).setValue(&bVal, ::getBooleanCppuType());
734 break;
736 case HANDLE_ALIGNMENT :
737 // SmHorAlign uses the same values as HorizontalAlignment
738 *pValue <<= (sal_Int16)aFormat.GetHorAlign();
739 break;
741 case HANDLE_RELATIVE_SPACING :
742 case HANDLE_RELATIVE_LINE_SPACING :
743 case HANDLE_RELATIVE_ROOT_SPACING :
744 case HANDLE_RELATIVE_INDEX_SUPERSCRIPT :
745 case HANDLE_RELATIVE_INDEX_SUBSCRIPT :
746 case HANDLE_RELATIVE_FRACTION_NUMERATOR_HEIGHT :
747 case HANDLE_RELATIVE_FRACTION_DENOMINATOR_DEPTH:
748 case HANDLE_RELATIVE_FRACTION_BAR_EXCESS_LENGTH:
749 case HANDLE_RELATIVE_FRACTION_BAR_LINE_WEIGHT :
750 case HANDLE_RELATIVE_UPPER_LIMIT_DISTANCE :
751 case HANDLE_RELATIVE_LOWER_LIMIT_DISTANCE :
752 case HANDLE_RELATIVE_BRACKET_EXCESS_SIZE :
753 case HANDLE_RELATIVE_BRACKET_DISTANCE :
754 case HANDLE_RELATIVE_SCALE_BRACKET_EXCESS_SIZE :
755 case HANDLE_RELATIVE_MATRIX_LINE_SPACING :
756 case HANDLE_RELATIVE_MATRIX_COLUMN_SPACING :
757 case HANDLE_RELATIVE_SYMBOL_PRIMARY_HEIGHT :
758 case HANDLE_RELATIVE_SYMBOL_MINIMUM_HEIGHT :
759 case HANDLE_RELATIVE_OPERATOR_EXCESS_SIZE :
760 case HANDLE_RELATIVE_OPERATOR_SPACING :
761 case HANDLE_LEFT_MARGIN :
762 case HANDLE_RIGHT_MARGIN :
763 case HANDLE_TOP_MARGIN :
764 case HANDLE_BOTTOM_MARGIN :
765 *pValue <<= (sal_Int16)aFormat.GetDistance((*ppEntries)->mnMemberId);
766 break;
767 case HANDLE_IS_SCALE_ALL_BRACKETS :
769 sal_Bool bVal = aFormat.IsScaleNormalBrackets();
770 (*pValue).setValue(&bVal, ::getBooleanCppuType());
772 break;
773 case HANDLE_PRINTER_NAME:
775 SfxPrinter *pPrinter = pDocSh->GetPrinter ( );
776 *pValue <<= pPrinter ? OUString ( pPrinter->GetName()) : OUString();
778 break;
779 case HANDLE_PRINTER_SETUP:
781 SfxPrinter *pPrinter = pDocSh->GetPrinter ();
782 if (pPrinter)
784 SvMemoryStream aStream;
785 pPrinter->Store( aStream );
786 aStream.Seek ( STREAM_SEEK_TO_END );
787 sal_uInt32 nSize = aStream.Tell();
788 aStream.Seek ( STREAM_SEEK_TO_BEGIN );
789 Sequence < sal_Int8 > aSequence ( nSize );
790 aStream.Read ( aSequence.getArray(), nSize );
791 *pValue <<= aSequence;
794 break;
795 case HANDLE_SYMBOLS:
797 // this is get
798 SmModule *pp = SM_MOD1();
799 const SmSymSetManager &rManager = pp->GetSymSetManager();
800 vector < const SmSym * > aVector;
802 USHORT nCount = 0;
803 for (USHORT i = 0, nEnd = rManager.GetSymbolCount(); i < nEnd; i++)
805 const SmSym * pSymbol = rManager.GetSymbolByPos( i );
806 if (pSymbol && !pSymbol->IsPredefined () )
808 aVector.push_back ( pSymbol );
809 nCount++;
812 Sequence < SymbolDescriptor > aSequence ( nCount );
813 SymbolDescriptor * pDescriptor = aSequence.getArray();
815 vector <const SmSym * >::const_iterator aIter = aVector.begin(), aEnd = aVector.end();
816 for(; aIter != aEnd; pDescriptor++, aIter++)
818 pDescriptor->sName = (*aIter)->GetName();
819 pDescriptor->sExportName = (*aIter)->GetExportName();
820 pDescriptor->sSymbolSet = (*aIter)->GetSetName();
821 pDescriptor->nCharacter = static_cast < sal_Int32 > ((*aIter)->GetCharacter());
823 Font rFont = (*aIter)->GetFace();
824 pDescriptor->sFontName = rFont.GetName();
825 pDescriptor->nCharSet = sal::static_int_cast< sal_Int16 >(rFont.GetCharSet());
826 pDescriptor->nFamily = sal::static_int_cast< sal_Int16 >(rFont.GetFamily());
827 pDescriptor->nPitch = sal::static_int_cast< sal_Int16 >(rFont.GetPitch());
828 pDescriptor->nWeight = sal::static_int_cast< sal_Int16 >(rFont.GetWeight());
829 pDescriptor->nItalic = sal::static_int_cast< sal_Int16 >(rFont.GetItalic());
831 *pValue <<= aSequence;
833 break;
834 case HANDLE_BASIC_LIBRARIES:
835 *pValue <<= pDocSh->GetBasicContainer();
836 break;
837 case HANDLE_DIALOG_LIBRARIES:
838 *pValue <<= pDocSh->GetDialogContainer();
839 break;
840 case HANDLE_RUNTIME_UID:
841 *pValue <<= getRuntimeUID();
842 break;
843 // --> PB 2004-08-25 #i33095# Security Options
844 case HANDLE_LOAD_READONLY :
846 *pValue <<= pDocSh->IsLoadReadonly();
847 break;
849 // <--
854 //////////////////////////////////////////////////////////////////////
856 sal_Int32 SAL_CALL SmModel::getRendererCount(
857 const uno::Any& /*rSelection*/,
858 const uno::Sequence< beans::PropertyValue >& /*xOptions*/ )
859 throw (IllegalArgumentException, RuntimeException)
861 ::vos::OGuard aGuard(Application::GetSolarMutex());
862 return 1;
865 uno::Sequence< beans::PropertyValue > SAL_CALL SmModel::getRenderer(
866 sal_Int32 nRenderer,
867 const uno::Any& /*rSelection*/,
868 const uno::Sequence< beans::PropertyValue >& /*xOptions*/ )
869 throw (IllegalArgumentException, RuntimeException)
871 ::vos::OGuard aGuard(Application::GetSolarMutex());
873 if (0 != nRenderer)
874 throw IllegalArgumentException();
876 SmDocShell *pDocSh = static_cast < SmDocShell * >( GetObjectShell() );
877 if (!pDocSh)
878 throw RuntimeException();
880 SmPrinterAccess aPrinterAccess( *pDocSh );
881 Printer *pPrinter = aPrinterAccess.GetPrinter();
882 //Point aPrtPageOffset( pPrinter->GetPageOffset() );
883 Size aPrtPaperSize ( pPrinter->GetPaperSize() );
885 // if paper size is 0 (usually if no 'real' printer is found),
886 // guess the paper size
887 if (aPrtPaperSize.Height() == 0 || aPrtPaperSize.Width() == 0)
888 aPrtPaperSize = SvxPaperInfo::GetDefaultPaperSize(MAP_100TH_MM);
889 awt::Size aPageSize( aPrtPaperSize.Width(), aPrtPaperSize.Height() );
891 uno::Sequence< beans::PropertyValue > aRenderer(1);
892 PropertyValue &rValue = aRenderer.getArray()[0];
893 rValue.Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "PageSize" ) );
894 rValue.Value <<= aPageSize;
896 return aRenderer;
899 void SAL_CALL SmModel::render(
900 sal_Int32 nRenderer,
901 const uno::Any& rSelection,
902 const uno::Sequence< beans::PropertyValue >& rxOptions )
903 throw (IllegalArgumentException, RuntimeException)
905 ::vos::OGuard aGuard(Application::GetSolarMutex());
907 if (0 != nRenderer)
908 throw IllegalArgumentException();
910 SmDocShell *pDocSh = static_cast < SmDocShell * >( GetObjectShell() );
911 if (!pDocSh)
912 throw RuntimeException();
914 // get device to be rendered in
915 uno::Reference< awt::XDevice > xRenderDevice;
916 for (sal_Int32 i = 0, nCount = rxOptions.getLength(); i < nCount; ++i)
918 if( rxOptions[i].Name == OUString( RTL_CONSTASCII_USTRINGPARAM( "RenderDevice" ) ) )
919 rxOptions[i].Value >>= xRenderDevice;
922 if (xRenderDevice.is())
924 VCLXDevice* pDevice = VCLXDevice::GetImplementation( xRenderDevice );
925 OutputDevice* pOut = pDevice ? pDevice->GetOutputDevice() : NULL;
927 if (!pOut)
928 throw RuntimeException();
930 pOut->SetMapMode( MAP_100TH_MM );
932 uno::Reference< frame::XModel > xModel;
933 rSelection >>= xModel;
934 if (xModel == pDocSh->GetModel())
936 //!! when called via API we may not have an active view
937 //!! thus we go and look for a view that can be used.
938 const TypeId aTypeId = TYPE( SmViewShell );
939 SfxViewShell* pViewSh = SfxViewShell::GetFirst( &aTypeId, sal_False /* search non-visible views as well*/ );
940 while (pViewSh && pViewSh->GetObjectShell() != pDocSh)
941 pViewSh = SfxViewShell::GetNext( *pViewSh, &aTypeId, sal_False /* search non-visible views as well*/ );
942 SmViewShell *pView = PTR_CAST( SmViewShell, pViewSh );
943 DBG_ASSERT( pView, "SmModel::render : no SmViewShell found" );
945 if (pView)
947 SmPrinterAccess aPrinterAccess( *pDocSh );
948 Printer *pPrinter = aPrinterAccess.GetPrinter();
950 Size aPrtPaperSize ( pPrinter->GetPaperSize() );
951 Size aOutputSize ( pPrinter->GetOutputSize() );
952 Point aPrtPageOffset( pPrinter->GetPageOffset() );
954 // no real printer ??
955 if (aPrtPaperSize.Height() == 0 || aPrtPaperSize.Width() == 0)
957 aPrtPaperSize = SvxPaperInfo::GetDefaultPaperSize(MAP_100TH_MM);
958 // factors from Windows DIN A4
959 aOutputSize = Size( (long)(aPrtPaperSize.Width() * 0.941),
960 (long)(aPrtPaperSize.Height() * 0.961));
961 aPrtPageOffset = Point( (long)(aPrtPaperSize.Width() * 0.0250),
962 (long)(aPrtPaperSize.Height() * 0.0214));
964 Point aZeroPoint;
965 Rectangle OutputRect( aZeroPoint, aOutputSize );
968 // set minimum top and bottom border
969 if (aPrtPageOffset.Y() < 2000)
970 OutputRect.Top() += 2000 - aPrtPageOffset.Y();
971 if ((aPrtPaperSize.Height() - (aPrtPageOffset.Y() + OutputRect.Bottom())) < 2000)
972 OutputRect.Bottom() -= 2000 - (aPrtPaperSize.Height() -
973 (aPrtPageOffset.Y() + OutputRect.Bottom()));
975 // set minimum left and right border
976 if (aPrtPageOffset.X() < 2500)
977 OutputRect.Left() += 2500 - aPrtPageOffset.X();
978 if ((aPrtPaperSize.Width() - (aPrtPageOffset.X() + OutputRect.Right())) < 1500)
979 OutputRect.Right() -= 1500 - (aPrtPaperSize.Width() -
980 (aPrtPageOffset.X() + OutputRect.Right()));
982 pView->Impl_Print( *pOut, PRINT_SIZE_NORMAL,
983 Rectangle( OutputRect ), Point() );
989 void SAL_CALL SmModel::setParent( const uno::Reference< uno::XInterface >& xParent)
990 throw( lang::NoSupportException, uno::RuntimeException )
992 ::vos::OGuard aGuard( Application::GetSolarMutex() );
993 SfxBaseModel::setParent( xParent );
994 uno::Reference< lang::XUnoTunnel > xParentTunnel( xParent, uno::UNO_QUERY );
995 if ( xParentTunnel.is() )
997 SvGlobalName aSfxIdent( SFX_GLOBAL_CLASSID );
998 SfxObjectShell* pDoc = reinterpret_cast<SfxObjectShell *>(xParentTunnel->getSomething(
999 uno::Sequence< sal_Int8 >( aSfxIdent.GetByteSequence() ) ) );
1000 if ( pDoc )
1001 GetObjectShell()->OnDocumentPrinterChanged( pDoc->GetDocumentPrinter() );