bump product version to 5.0.4.1
[LibreOffice.git] / starmath / source / unomodel.cxx
blobdbebc9b92786b6d4a09ba080881ecf4b81454839
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <osl/mutex.hxx>
21 #include <sfx2/printer.hxx>
22 #include <vcl/svapp.hxx>
23 #include <svtools/ctrltool.hxx>
24 #include <svl/itemprop.hxx>
25 #include <unotools/localedatawrapper.hxx>
26 #include <editeng/paperinf.hxx>
27 #include <vcl/settings.hxx>
28 #include <vcl/print.hxx>
29 #include <toolkit/awt/vclxdevice.hxx>
30 #include <com/sun/star/beans/PropertyAttribute.hpp>
31 #include <com/sun/star/formula/SymbolDescriptor.hpp>
32 #include <com/sun/star/awt/Size.hpp>
33 #include <com/sun/star/script/XLibraryContainer.hpp>
34 #include <xmloff/xmluconv.hxx>
35 #include <rtl/ustrbuf.hxx>
36 #include <comphelper/propertysetinfo.hxx>
37 #include <comphelper/servicehelper.hxx>
38 #include <cppuhelper/supportsservice.hxx>
39 #include <unotools/moduleoptions.hxx>
40 #include <tools/mapunit.hxx>
42 #include <unomodel.hxx>
43 #include <document.hxx>
44 #include <view.hxx>
45 #include <symbol.hxx>
46 #include <starmath.hrc>
47 #include <config.hxx>
48 #include <smdll.hxx>
50 using namespace ::cppu;
51 using namespace ::std;
52 using namespace ::comphelper;
53 using namespace ::com::sun::star;
54 using namespace ::com::sun::star::uno;
55 using namespace ::com::sun::star::beans;
56 using namespace ::com::sun::star::lang;
57 using namespace ::com::sun::star::formula;
58 using namespace ::com::sun::star::view;
59 using namespace ::com::sun::star::script;
61 SmPrintUIOptions::SmPrintUIOptions()
63 ResStringArray aLocalizedStrings( SmResId( RID_PRINTUIOPTIONS ) );
64 SAL_WARN_IF( aLocalizedStrings.Count() < 18, "starmath", "resource incomplete" );
65 if( aLocalizedStrings.Count() < 9 ) // bad resource ?
66 return;
68 SmModule *pp = SM_MOD();
69 SmConfig *pConfig = pp->GetConfig();
70 SAL_WARN_IF( !pConfig, "starmath", "SmConfig not found" );
71 if (!pConfig)
72 return;
74 sal_Int32 nNumProps = 10, nIdx=0;
76 // create sequence of print UI options
77 // (Actually IsIgnoreSpacesRight is a parser option. Without it we need only 8 properties here.)
78 m_aUIProperties.realloc( nNumProps );
80 // load the math PrinterOptions into the custom tab
81 m_aUIProperties[nIdx].Name = "OptionsUIFile";
82 m_aUIProperties[nIdx++].Value <<= OUString("modules/smath/ui/printeroptions.ui");
84 // create Section for formula (results in an extra tab page in dialog)
85 SvtModuleOptions aOpt;
86 OUString aAppGroupname(
87 aLocalizedStrings.GetString( 0 ).
88 replaceFirst( "%s", aOpt.GetModuleName( SvtModuleOptions::EModule::MATH ) ) );
89 m_aUIProperties[nIdx++].Value = setGroupControlOpt("tabcontrol-page2", aAppGroupname, ".HelpID:vcl:PrintDialog:TabPage:AppPage");
91 // create subgroup for print options
92 m_aUIProperties[nIdx++].Value = setSubgroupControlOpt("contents", aLocalizedStrings.GetString(1), OUString());
94 // create a bool option for title row (matches to SID_PRINTTITLE)
95 m_aUIProperties[nIdx++].Value = setBoolControlOpt("title", aLocalizedStrings.GetString( 2 ),
96 ".HelpID:vcl:PrintDialog:TitleRow:CheckBox",
97 PRTUIOPT_TITLE_ROW,
98 pConfig->IsPrintTitle());
99 // create a bool option for formula text (matches to SID_PRINTTEXT)
100 m_aUIProperties[nIdx++].Value = setBoolControlOpt("formulatext", aLocalizedStrings.GetString( 3 ),
101 ".HelpID:vcl:PrintDialog:FormulaText:CheckBox",
102 PRTUIOPT_FORMULA_TEXT,
103 pConfig->IsPrintFormulaText());
104 // create a bool option for border (matches to SID_PRINTFRAME)
105 m_aUIProperties[nIdx++].Value = setBoolControlOpt("borders", aLocalizedStrings.GetString( 4 ),
106 ".HelpID:vcl:PrintDialog:Border:CheckBox",
107 PRTUIOPT_BORDER,
108 pConfig->IsPrintFrame());
110 // create subgroup for print format
111 m_aUIProperties[nIdx++].Value = setSubgroupControlOpt("size", aLocalizedStrings.GetString(5), OUString());
113 // create a radio button group for print format (matches to SID_PRINTSIZE)
114 Sequence< OUString > aChoices{
115 aLocalizedStrings.GetString( 6 ),
116 aLocalizedStrings.GetString( 7 ),
117 aLocalizedStrings.GetString( 8 )
119 Sequence< OUString > aHelpIds{
120 ".HelpID:vcl:PrintDialog:PrintFormat:RadioButton:0",
121 ".HelpID:vcl:PrintDialog:PrintFormat:RadioButton:1",
122 ".HelpID:vcl:PrintDialog:PrintFormat:RadioButton:2"
124 Sequence< OUString > aWidgetIds{
125 "originalsize",
126 "fittopage",
127 "scaling"
129 OUString aPrintFormatProp( PRTUIOPT_PRINT_FORMAT );
130 m_aUIProperties[nIdx++].Value = setChoiceRadiosControlOpt(aWidgetIds, OUString(),
131 aHelpIds,
132 aPrintFormatProp,
133 aChoices, static_cast< sal_Int32 >(pConfig->GetPrintSize())
136 // create a numeric box for scale dependent on PrintFormat = "Scaling" (matches to SID_PRINTZOOM)
137 vcl::PrinterOptionsHelper::UIControlOptions aRangeOpt( aPrintFormatProp, 2, true );
138 m_aUIProperties[nIdx++].Value = setRangeControlOpt("scalingspin", OUString(),
139 ".HelpID:vcl:PrintDialog:PrintScale:NumericField",
140 PRTUIOPT_PRINT_SCALE,
141 pConfig->GetPrintZoomFactor(), // initial value
142 10, // min value
143 1000, // max value
144 aRangeOpt);
146 Sequence< PropertyValue > aHintNoLayoutPage( 1 );
147 aHintNoLayoutPage[0].Name = "HintNoLayoutPage";
148 aHintNoLayoutPage[0].Value = makeAny( sal_True );
149 m_aUIProperties[nIdx++].Value <<= aHintNoLayoutPage;
151 assert(nIdx == nNumProps);
157 // class SmModel
160 // values from com/sun/star/beans/PropertyAttribute
161 #define PROPERTY_NONE 0
163 enum SmModelPropertyHandles
165 HANDLE_FORMULA,
166 HANDLE_FONT_NAME_VARIABLES,
167 HANDLE_FONT_NAME_FUNCTIONS,
168 HANDLE_FONT_NAME_NUMBERS,
169 HANDLE_FONT_NAME_TEXT,
170 HANDLE_CUSTOM_FONT_NAME_SERIF,
171 HANDLE_CUSTOM_FONT_NAME_SANS,
172 HANDLE_CUSTOM_FONT_NAME_FIXED,
173 HANDLE_CUSTOM_FONT_FIXED_POSTURE,
174 HANDLE_CUSTOM_FONT_FIXED_WEIGHT,
175 HANDLE_CUSTOM_FONT_SANS_POSTURE,
176 HANDLE_CUSTOM_FONT_SANS_WEIGHT,
177 HANDLE_CUSTOM_FONT_SERIF_POSTURE,
178 HANDLE_CUSTOM_FONT_SERIF_WEIGHT,
179 HANDLE_FONT_VARIABLES_POSTURE,
180 HANDLE_FONT_VARIABLES_WEIGHT,
181 HANDLE_FONT_FUNCTIONS_POSTURE,
182 HANDLE_FONT_FUNCTIONS_WEIGHT,
183 HANDLE_FONT_NUMBERS_POSTURE,
184 HANDLE_FONT_NUMBERS_WEIGHT,
185 HANDLE_FONT_TEXT_POSTURE,
186 HANDLE_FONT_TEXT_WEIGHT,
187 HANDLE_BASE_FONT_HEIGHT,
188 HANDLE_RELATIVE_FONT_HEIGHT_TEXT,
189 HANDLE_RELATIVE_FONT_HEIGHT_INDICES,
190 HANDLE_RELATIVE_FONT_HEIGHT_FUNCTIONS,
191 HANDLE_RELATIVE_FONT_HEIGHT_OPERATORS,
192 HANDLE_RELATIVE_FONT_HEIGHT_LIMITS,
193 HANDLE_IS_TEXT_MODE,
194 HANDLE_GREEK_CHAR_STYLE,
195 HANDLE_ALIGNMENT,
196 HANDLE_RELATIVE_SPACING,
197 HANDLE_RELATIVE_LINE_SPACING,
198 HANDLE_RELATIVE_ROOT_SPACING,
199 HANDLE_RELATIVE_INDEX_SUPERSCRIPT,
200 HANDLE_RELATIVE_INDEX_SUBSCRIPT,
201 HANDLE_RELATIVE_FRACTION_NUMERATOR_HEIGHT,
202 HANDLE_RELATIVE_FRACTION_DENOMINATOR_DEPTH,
203 HANDLE_RELATIVE_FRACTION_BAR_EXCESS_LENGTH,
204 HANDLE_RELATIVE_FRACTION_BAR_LINE_WEIGHT,
205 HANDLE_RELATIVE_UPPER_LIMIT_DISTANCE,
206 HANDLE_RELATIVE_LOWER_LIMIT_DISTANCE,
207 HANDLE_RELATIVE_BRACKET_EXCESS_SIZE,
208 HANDLE_RELATIVE_BRACKET_DISTANCE,
209 HANDLE_IS_SCALE_ALL_BRACKETS,
210 HANDLE_RELATIVE_SCALE_BRACKET_EXCESS_SIZE,
211 HANDLE_RELATIVE_MATRIX_LINE_SPACING,
212 HANDLE_RELATIVE_MATRIX_COLUMN_SPACING,
213 HANDLE_RELATIVE_SYMBOL_PRIMARY_HEIGHT,
214 HANDLE_RELATIVE_SYMBOL_MINIMUM_HEIGHT,
215 HANDLE_RELATIVE_OPERATOR_EXCESS_SIZE,
216 HANDLE_RELATIVE_OPERATOR_SPACING,
217 HANDLE_LEFT_MARGIN,
218 HANDLE_RIGHT_MARGIN,
219 HANDLE_TOP_MARGIN,
220 HANDLE_BOTTOM_MARGIN,
221 HANDLE_PRINTER_NAME,
222 HANDLE_PRINTER_SETUP,
223 HANDLE_SYMBOLS,
224 HANDLE_USED_SYMBOLS,
225 HANDLE_BASIC_LIBRARIES,
226 HANDLE_RUNTIME_UID,
227 HANDLE_LOAD_READONLY, // Security Options
228 HANDLE_DIALOG_LIBRARIES, // #i73329#
229 HANDLE_BASELINE,
230 HANDLE_INTEROP_GRAB_BAG,
233 static PropertySetInfo * lcl_createModelPropertyInfo ()
235 static PropertyMapEntry aModelPropertyInfoMap[] =
237 { OUString("Alignment") , HANDLE_ALIGNMENT , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, 0 },
238 { OUString("BaseFontHeight") , HANDLE_BASE_FONT_HEIGHT , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, 0 },
239 { OUString("BasicLibraries") , HANDLE_BASIC_LIBRARIES , cppu::UnoType<script::XLibraryContainer>::get(), PropertyAttribute::READONLY, 0 },
240 { OUString("BottomMargin") , HANDLE_BOTTOM_MARGIN , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_BOTTOMSPACE },
241 { OUString("CustomFontNameFixed") , HANDLE_CUSTOM_FONT_NAME_FIXED , ::cppu::UnoType<OUString>::get(), PROPERTY_NONE, FNT_FIXED },
242 { OUString("CustomFontNameSans") , HANDLE_CUSTOM_FONT_NAME_SANS , ::cppu::UnoType<OUString>::get(), PROPERTY_NONE, FNT_SANS },
243 { OUString("CustomFontNameSerif") , HANDLE_CUSTOM_FONT_NAME_SERIF , ::cppu::UnoType<OUString>::get(), PROPERTY_NONE, FNT_SERIF },
244 { OUString("DialogLibraries") , HANDLE_DIALOG_LIBRARIES , cppu::UnoType<script::XLibraryContainer>::get(), PropertyAttribute::READONLY, 0 },
245 { OUString("FontFixedIsBold") , HANDLE_CUSTOM_FONT_FIXED_WEIGHT , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_FIXED },
246 { OUString("FontFixedIsItalic") , HANDLE_CUSTOM_FONT_FIXED_POSTURE , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_FIXED },
247 { OUString("FontFunctionsIsBold") , HANDLE_FONT_FUNCTIONS_WEIGHT , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_FUNCTION },
248 { OUString("FontFunctionsIsItalic") , HANDLE_FONT_FUNCTIONS_POSTURE , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_FUNCTION },
249 { OUString("FontNameFunctions") , HANDLE_FONT_NAME_FUNCTIONS , ::cppu::UnoType<OUString>::get(), PROPERTY_NONE, FNT_FUNCTION },
250 { OUString("FontNameNumbers") , HANDLE_FONT_NAME_NUMBERS , ::cppu::UnoType<OUString>::get(), PROPERTY_NONE, FNT_NUMBER },
251 { OUString("FontNameText") , HANDLE_FONT_NAME_TEXT , ::cppu::UnoType<OUString>::get(), PROPERTY_NONE, FNT_TEXT },
252 { OUString("FontNameVariables") , HANDLE_FONT_NAME_VARIABLES , ::cppu::UnoType<OUString>::get(), PROPERTY_NONE, FNT_VARIABLE },
253 { OUString("FontNumbersIsBold") , HANDLE_FONT_NUMBERS_WEIGHT , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_NUMBER },
254 { OUString("FontNumbersIsItalic") , HANDLE_FONT_NUMBERS_POSTURE , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_NUMBER },
255 { OUString("FontSansIsBold") , HANDLE_CUSTOM_FONT_SANS_WEIGHT , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_SANS },
256 { OUString("FontSansIsItalic") , HANDLE_CUSTOM_FONT_SANS_POSTURE , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_SANS },
257 { OUString("FontSerifIsBold") , HANDLE_CUSTOM_FONT_SERIF_WEIGHT , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_SERIF },
258 { OUString("FontSerifIsItalic") , HANDLE_CUSTOM_FONT_SERIF_POSTURE , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_SERIF },
259 { OUString("FontTextIsBold") , HANDLE_FONT_TEXT_WEIGHT , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_TEXT },
260 { OUString("FontTextIsItalic") , HANDLE_FONT_TEXT_POSTURE , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_TEXT },
261 { OUString("FontVariablesIsBold") , HANDLE_FONT_VARIABLES_WEIGHT , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_VARIABLE },
262 { OUString("FontVariablesIsItalic") , HANDLE_FONT_VARIABLES_POSTURE , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_VARIABLE },
263 { OUString("Formula") , HANDLE_FORMULA , ::cppu::UnoType<OUString>::get(), PROPERTY_NONE, 0 },
264 { OUString("IsScaleAllBrackets") , HANDLE_IS_SCALE_ALL_BRACKETS , cppu::UnoType<bool>::get(), PROPERTY_NONE, 0 },
265 { OUString("IsTextMode") , HANDLE_IS_TEXT_MODE , cppu::UnoType<bool>::get(), PROPERTY_NONE, 0 },
266 { OUString("GreekCharStyle") , HANDLE_GREEK_CHAR_STYLE , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, 0 },
267 { OUString("LeftMargin") , HANDLE_LEFT_MARGIN , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_LEFTSPACE },
268 { OUString("PrinterName") , HANDLE_PRINTER_NAME , ::cppu::UnoType<OUString>::get(), PROPERTY_NONE, 0 },
269 { OUString("PrinterSetup") , HANDLE_PRINTER_SETUP , cppu::UnoType<const Sequence < sal_Int8 >>::get(), PROPERTY_NONE, 0 },
270 { OUString("RelativeBracketDistance") , HANDLE_RELATIVE_BRACKET_DISTANCE , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_BRACKETSPACE },
271 { OUString("RelativeBracketExcessSize") , HANDLE_RELATIVE_BRACKET_EXCESS_SIZE , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_BRACKETSIZE },
272 { OUString("RelativeFontHeightFunctions") , HANDLE_RELATIVE_FONT_HEIGHT_FUNCTIONS , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, SIZ_FUNCTION },
273 { OUString("RelativeFontHeightIndices") , HANDLE_RELATIVE_FONT_HEIGHT_INDICES , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, SIZ_INDEX },
274 { OUString("RelativeFontHeightLimits") , HANDLE_RELATIVE_FONT_HEIGHT_LIMITS , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, SIZ_LIMITS },
275 { OUString("RelativeFontHeightOperators") , HANDLE_RELATIVE_FONT_HEIGHT_OPERATORS , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, SIZ_OPERATOR },
276 { OUString("RelativeFontHeightText") , HANDLE_RELATIVE_FONT_HEIGHT_TEXT , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, SIZ_TEXT },
277 { OUString("RelativeFractionBarExcessLength") , HANDLE_RELATIVE_FRACTION_BAR_EXCESS_LENGTH, ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_FRACTION },
278 { OUString("RelativeFractionBarLineWeight") , HANDLE_RELATIVE_FRACTION_BAR_LINE_WEIGHT , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_STROKEWIDTH },
279 { OUString("RelativeFractionDenominatorDepth") , HANDLE_RELATIVE_FRACTION_DENOMINATOR_DEPTH, ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_DENOMINATOR },
280 { OUString("RelativeFractionNumeratorHeight") , HANDLE_RELATIVE_FRACTION_NUMERATOR_HEIGHT , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_NUMERATOR },
281 { OUString("RelativeIndexSubscript") , HANDLE_RELATIVE_INDEX_SUBSCRIPT , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_SUBSCRIPT },
282 { OUString("RelativeIndexSuperscript") , HANDLE_RELATIVE_INDEX_SUPERSCRIPT , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_SUPERSCRIPT },
283 { OUString("RelativeLineSpacing") , HANDLE_RELATIVE_LINE_SPACING , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_VERTICAL },
284 { OUString("RelativeLowerLimitDistance") , HANDLE_RELATIVE_LOWER_LIMIT_DISTANCE , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_LOWERLIMIT },
285 { OUString("RelativeMatrixColumnSpacing") , HANDLE_RELATIVE_MATRIX_COLUMN_SPACING , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_MATRIXCOL },
286 { OUString("RelativeMatrixLineSpacing") , HANDLE_RELATIVE_MATRIX_LINE_SPACING , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_MATRIXROW },
287 { OUString("RelativeOperatorExcessSize") , HANDLE_RELATIVE_OPERATOR_EXCESS_SIZE , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_OPERATORSIZE },
288 { OUString("RelativeOperatorSpacing") , HANDLE_RELATIVE_OPERATOR_SPACING , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_OPERATORSPACE },
289 { OUString("RelativeRootSpacing") , HANDLE_RELATIVE_ROOT_SPACING , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_ROOT },
290 { OUString("RelativeScaleBracketExcessSize") , HANDLE_RELATIVE_SCALE_BRACKET_EXCESS_SIZE , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_NORMALBRACKETSIZE },
291 { OUString("RelativeSpacing") , HANDLE_RELATIVE_SPACING , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_HORIZONTAL },
292 { OUString("RelativeSymbolMinimumHeight") , HANDLE_RELATIVE_SYMBOL_MINIMUM_HEIGHT , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_ORNAMENTSPACE },
293 { OUString("RelativeSymbolPrimaryHeight") , HANDLE_RELATIVE_SYMBOL_PRIMARY_HEIGHT , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_ORNAMENTSIZE },
294 { OUString("RelativeUpperLimitDistance") , HANDLE_RELATIVE_UPPER_LIMIT_DISTANCE , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_UPPERLIMIT },
295 { OUString("RightMargin") , HANDLE_RIGHT_MARGIN , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_RIGHTSPACE },
296 { OUString("RuntimeUID") , HANDLE_RUNTIME_UID , cppu::UnoType<OUString>::get(), PropertyAttribute::READONLY, 0 },
297 { OUString("Symbols") , HANDLE_SYMBOLS , cppu::UnoType<Sequence < SymbolDescriptor >>::get(), PROPERTY_NONE, 0 },
298 { OUString("UserDefinedSymbolsInUse") , HANDLE_USED_SYMBOLS , cppu::UnoType<Sequence < SymbolDescriptor >>::get(), PropertyAttribute::READONLY, 0 },
299 { OUString("TopMargin") , HANDLE_TOP_MARGIN , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_TOPSPACE },
300 // #i33095# Security Options
301 { OUString("LoadReadonly") , HANDLE_LOAD_READONLY , cppu::UnoType<bool>::get(), PROPERTY_NONE, 0 },
302 // #i972#
303 { OUString("BaseLine") , HANDLE_BASELINE , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, 0 },
304 { OUString("InteropGrabBag") , HANDLE_INTEROP_GRAB_BAG , cppu::UnoType<uno::Sequence< beans::PropertyValue >>::get(), PROPERTY_NONE, 0 },
305 { OUString(), 0, css::uno::Type(), 0, 0 }
307 PropertySetInfo *pInfo = new PropertySetInfo ( aModelPropertyInfoMap );
308 return pInfo;
311 SmModel::SmModel( SfxObjectShell *pObjSh )
312 : SfxBaseModel(pObjSh)
313 , PropertySetHelper ( lcl_createModelPropertyInfo () )
317 SmModel::~SmModel() throw ()
321 uno::Any SAL_CALL SmModel::queryInterface( const uno::Type& rType ) throw(uno::RuntimeException, std::exception)
323 uno::Any aRet = ::cppu::queryInterface ( rType,
324 // OWeakObject interfaces
325 dynamic_cast< XInterface* > ( static_cast< XUnoTunnel* > ( this )),
326 static_cast< XWeak* > ( this ),
327 // PropertySetHelper interfaces
328 static_cast< XPropertySet* > ( this ),
329 static_cast< XMultiPropertySet* > ( this ),
330 // my own interfaces
331 static_cast< XServiceInfo* > ( this ),
332 static_cast< XRenderable* > ( this ) );
333 if (!aRet.hasValue())
334 aRet = SfxBaseModel::queryInterface ( rType );
335 return aRet;
338 void SAL_CALL SmModel::acquire() throw()
340 OWeakObject::acquire();
343 void SAL_CALL SmModel::release() throw()
345 OWeakObject::release();
348 uno::Sequence< uno::Type > SAL_CALL SmModel::getTypes( ) throw(uno::RuntimeException, std::exception)
350 SolarMutexGuard aGuard;
351 uno::Sequence< uno::Type > aTypes = SfxBaseModel::getTypes();
352 sal_Int32 nLen = aTypes.getLength();
353 aTypes.realloc(nLen + 4);
354 uno::Type* pTypes = aTypes.getArray();
355 pTypes[nLen++] = cppu::UnoType<XServiceInfo>::get();
356 pTypes[nLen++] = cppu::UnoType<XPropertySet>::get();
357 pTypes[nLen++] = cppu::UnoType<XMultiPropertySet>::get();
358 pTypes[nLen++] = cppu::UnoType<XRenderable>::get();
360 return aTypes;
363 namespace
365 class theSmModelUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSmModelUnoTunnelId> {};
368 const uno::Sequence< sal_Int8 > & SmModel::getUnoTunnelId()
370 return theSmModelUnoTunnelId::get().getSeq();
373 sal_Int64 SAL_CALL SmModel::getSomething( const uno::Sequence< sal_Int8 >& rId )
374 throw(uno::RuntimeException, std::exception)
376 if( rId.getLength() == 16
377 && 0 == memcmp( getUnoTunnelId().getConstArray(),
378 rId.getConstArray(), 16 ) )
380 return sal::static_int_cast< sal_Int64 >(reinterpret_cast< sal_uIntPtr >(this));
383 return SfxBaseModel::getSomething( rId );
386 static sal_Int16 lcl_AnyToINT16(const uno::Any& rAny)
388 uno::TypeClass eType = rAny.getValueType().getTypeClass();
390 sal_Int16 nRet = 0;
391 if( eType == uno::TypeClass_DOUBLE )
392 nRet = (sal_Int16)*static_cast<double const *>(rAny.getValue());
393 else if( eType == uno::TypeClass_FLOAT )
394 nRet = (sal_Int16)*static_cast<float const *>(rAny.getValue());
395 else
396 rAny >>= nRet;
397 return nRet;
400 OUString SmModel::getImplementationName() throw( uno::RuntimeException, std::exception )
402 return OUString("com.sun.star.comp.Math.FormulaDocument");
405 sal_Bool SmModel::supportsService(const OUString& rServiceName) throw( uno::RuntimeException, std::exception )
407 return cppu::supportsService(this, rServiceName);
410 uno::Sequence< OUString > SmModel::getSupportedServiceNames() throw( uno::RuntimeException, std::exception )
412 return uno::Sequence<OUString>{
413 "com.sun.star.document.OfficeDocument",
414 "com.sun.star.formula.FormulaProperties"
418 void SmModel::_setPropertyValues(const PropertyMapEntry** ppEntries, const Any* pValues)
419 throw (RuntimeException, UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, std::exception)
421 SolarMutexGuard aGuard;
423 SmDocShell *pDocSh = static_cast < SmDocShell * > (GetObjectShell());
425 if ( NULL == pDocSh )
426 throw UnknownPropertyException();
428 SmFormat aFormat = pDocSh->GetFormat();
430 for (; *ppEntries; ppEntries++, pValues++ )
432 if ((*ppEntries)->mnAttributes & PropertyAttribute::READONLY)
433 throw PropertyVetoException();
435 switch ( (*ppEntries)->mnHandle )
437 case HANDLE_FORMULA:
439 OUString aText;
440 *pValues >>= aText;
441 pDocSh->SetText(aText);
443 break;
444 case HANDLE_FONT_NAME_VARIABLES :
445 case HANDLE_FONT_NAME_FUNCTIONS :
446 case HANDLE_FONT_NAME_NUMBERS :
447 case HANDLE_FONT_NAME_TEXT :
448 case HANDLE_CUSTOM_FONT_NAME_SERIF :
449 case HANDLE_CUSTOM_FONT_NAME_SANS :
450 case HANDLE_CUSTOM_FONT_NAME_FIXED :
452 OUString sFontName;
453 *pValues >>= sFontName;
454 if(sFontName.isEmpty())
455 throw IllegalArgumentException();
457 if(OUString(aFormat.GetFont((*ppEntries)->mnMemberId).GetName()) != sFontName)
459 const SmFace rOld = aFormat.GetFont((*ppEntries)->mnMemberId);
461 SmFace aSet( sFontName, rOld.GetSize() );
462 aSet.SetBorderWidth( rOld.GetBorderWidth() );
463 aSet.SetAlign( ALIGN_BASELINE );
464 aFormat.SetFont( (*ppEntries)->mnMemberId, aSet );
467 break;
468 case HANDLE_CUSTOM_FONT_FIXED_POSTURE:
469 case HANDLE_CUSTOM_FONT_SANS_POSTURE :
470 case HANDLE_CUSTOM_FONT_SERIF_POSTURE:
471 case HANDLE_FONT_VARIABLES_POSTURE :
472 case HANDLE_FONT_FUNCTIONS_POSTURE :
473 case HANDLE_FONT_NUMBERS_POSTURE :
474 case HANDLE_FONT_TEXT_POSTURE :
476 if((*pValues).getValueType() != cppu::UnoType<bool>::get())
477 throw IllegalArgumentException();
478 bool bVal = *static_cast<sal_Bool const *>((*pValues).getValue());
479 vcl::Font aNewFont(aFormat.GetFont((*ppEntries)->mnMemberId));
480 aNewFont.SetItalic((bVal) ? ITALIC_NORMAL : ITALIC_NONE);
481 aFormat.SetFont((*ppEntries)->mnMemberId, aNewFont);
483 break;
484 case HANDLE_CUSTOM_FONT_FIXED_WEIGHT :
485 case HANDLE_CUSTOM_FONT_SANS_WEIGHT :
486 case HANDLE_CUSTOM_FONT_SERIF_WEIGHT :
487 case HANDLE_FONT_VARIABLES_WEIGHT :
488 case HANDLE_FONT_FUNCTIONS_WEIGHT :
489 case HANDLE_FONT_NUMBERS_WEIGHT :
490 case HANDLE_FONT_TEXT_WEIGHT :
492 if((*pValues).getValueType() != cppu::UnoType<bool>::get())
493 throw IllegalArgumentException();
494 bool bVal = *static_cast<sal_Bool const *>((*pValues).getValue());
495 vcl::Font aNewFont(aFormat.GetFont((*ppEntries)->mnMemberId));
496 aNewFont.SetWeight((bVal) ? WEIGHT_BOLD : WEIGHT_NORMAL);
497 aFormat.SetFont((*ppEntries)->mnMemberId, aNewFont);
499 break;
500 case HANDLE_BASE_FONT_HEIGHT :
502 // Point!
503 sal_Int16 nVal = lcl_AnyToINT16(*pValues);
504 if(nVal < 1)
505 throw IllegalArgumentException();
506 Size aSize = aFormat.GetBaseSize();
507 nVal *= 20;
508 nVal = static_cast < sal_Int16 > ( convertTwipToMm100(nVal) );
509 aSize.Height() = nVal;
510 aFormat.SetBaseSize(aSize);
512 // apply base size to fonts
513 const Size aTmp( aFormat.GetBaseSize() );
514 for (sal_uInt16 i = FNT_BEGIN; i <= FNT_END; i++)
515 aFormat.SetFontSize(i, aTmp);
517 break;
518 case HANDLE_RELATIVE_FONT_HEIGHT_TEXT :
519 case HANDLE_RELATIVE_FONT_HEIGHT_INDICES :
520 case HANDLE_RELATIVE_FONT_HEIGHT_FUNCTIONS :
521 case HANDLE_RELATIVE_FONT_HEIGHT_OPERATORS :
522 case HANDLE_RELATIVE_FONT_HEIGHT_LIMITS :
524 sal_Int16 nVal = 0;
525 *pValues >>= nVal;
526 if(nVal < 1)
527 throw IllegalArgumentException();
528 aFormat.SetRelSize((*ppEntries)->mnMemberId, nVal);
530 break;
532 case HANDLE_IS_TEXT_MODE :
534 aFormat.SetTextmode(*static_cast<sal_Bool const *>((*pValues).getValue()));
536 break;
538 case HANDLE_GREEK_CHAR_STYLE :
540 sal_Int16 nVal = 0;
541 *pValues >>= nVal;
542 if (nVal < 0 || nVal > 2)
543 throw IllegalArgumentException();
544 aFormat.SetGreekCharStyle( nVal );
546 break;
548 case HANDLE_ALIGNMENT :
550 // SmHorAlign uses the same values as HorizontalAlignment
551 sal_Int16 nVal = 0;
552 *pValues >>= nVal;
553 if(nVal < 0 || nVal > 2)
554 throw IllegalArgumentException();
555 aFormat.SetHorAlign((SmHorAlign)nVal);
557 break;
559 case HANDLE_RELATIVE_SPACING :
560 case HANDLE_RELATIVE_LINE_SPACING :
561 case HANDLE_RELATIVE_ROOT_SPACING :
562 case HANDLE_RELATIVE_INDEX_SUPERSCRIPT :
563 case HANDLE_RELATIVE_INDEX_SUBSCRIPT :
564 case HANDLE_RELATIVE_FRACTION_NUMERATOR_HEIGHT :
565 case HANDLE_RELATIVE_FRACTION_DENOMINATOR_DEPTH:
566 case HANDLE_RELATIVE_FRACTION_BAR_EXCESS_LENGTH:
567 case HANDLE_RELATIVE_FRACTION_BAR_LINE_WEIGHT :
568 case HANDLE_RELATIVE_UPPER_LIMIT_DISTANCE :
569 case HANDLE_RELATIVE_LOWER_LIMIT_DISTANCE :
570 case HANDLE_RELATIVE_BRACKET_EXCESS_SIZE :
571 case HANDLE_RELATIVE_BRACKET_DISTANCE :
572 case HANDLE_RELATIVE_SCALE_BRACKET_EXCESS_SIZE :
573 case HANDLE_RELATIVE_MATRIX_LINE_SPACING :
574 case HANDLE_RELATIVE_MATRIX_COLUMN_SPACING :
575 case HANDLE_RELATIVE_SYMBOL_PRIMARY_HEIGHT :
576 case HANDLE_RELATIVE_SYMBOL_MINIMUM_HEIGHT :
577 case HANDLE_RELATIVE_OPERATOR_EXCESS_SIZE :
578 case HANDLE_RELATIVE_OPERATOR_SPACING :
579 case HANDLE_LEFT_MARGIN :
580 case HANDLE_RIGHT_MARGIN :
581 case HANDLE_TOP_MARGIN :
582 case HANDLE_BOTTOM_MARGIN :
584 sal_Int16 nVal = 0;
585 *pValues >>= nVal;
586 if(nVal < 0)
587 throw IllegalArgumentException();
588 aFormat.SetDistance((*ppEntries)->mnMemberId, nVal);
590 break;
591 case HANDLE_IS_SCALE_ALL_BRACKETS :
592 aFormat.SetScaleNormalBrackets(*static_cast<sal_Bool const *>((*pValues).getValue()));
593 break;
594 case HANDLE_PRINTER_NAME:
596 // embedded documents just ignore this property for now
597 if ( pDocSh->GetCreateMode() != SfxObjectCreateMode::EMBEDDED )
599 SfxPrinter *pPrinter = pDocSh->GetPrinter ( );
600 if (pPrinter)
602 OUString sPrinterName;
603 if (*pValues >>= sPrinterName )
605 if ( !sPrinterName.isEmpty() )
607 VclPtrInstance<SfxPrinter> pNewPrinter( pPrinter->GetOptions().Clone(), sPrinterName );
608 if (pNewPrinter->IsKnown())
609 pDocSh->SetPrinter ( pNewPrinter );
610 else
611 pNewPrinter.disposeAndClear();
614 else
615 throw IllegalArgumentException();
619 break;
620 case HANDLE_PRINTER_SETUP:
622 Sequence < sal_Int8 > aSequence;
623 if ( *pValues >>= aSequence )
625 sal_uInt32 nSize = aSequence.getLength();
626 SvMemoryStream aStream ( aSequence.getArray(), nSize, StreamMode::READ );
627 aStream.Seek ( STREAM_SEEK_TO_BEGIN );
628 static sal_uInt16 const nRange[] =
630 SID_PRINTSIZE, SID_PRINTSIZE,
631 SID_PRINTZOOM, SID_PRINTZOOM,
632 SID_PRINTTITLE, SID_PRINTTITLE,
633 SID_PRINTTEXT, SID_PRINTTEXT,
634 SID_PRINTFRAME, SID_PRINTFRAME,
635 SID_NO_RIGHT_SPACES, SID_NO_RIGHT_SPACES,
636 SID_SAVE_ONLY_USED_SYMBOLS, SID_SAVE_ONLY_USED_SYMBOLS,
639 SfxItemSet *pItemSet = new SfxItemSet( SmDocShell::GetPool(), nRange );
640 SmModule *pp = SM_MOD();
641 pp->GetConfig()->ConfigToItemSet(*pItemSet);
642 VclPtr<SfxPrinter> pPrinter = SfxPrinter::Create ( aStream, pItemSet );
644 pDocSh->SetPrinter( pPrinter );
646 else
647 throw IllegalArgumentException();
649 break;
650 case HANDLE_SYMBOLS:
652 // this is set
653 Sequence < SymbolDescriptor > aSequence;
654 if ( *pValues >>= aSequence )
656 sal_uInt32 nSize = aSequence.getLength();
657 SmModule *pp = SM_MOD();
658 SmSymbolManager &rManager = pp->GetSymbolManager();
659 SymbolDescriptor *pDescriptor = aSequence.getArray();
660 for (sal_uInt32 i = 0; i < nSize ; i++, pDescriptor++)
662 vcl::Font aFont;
663 aFont.SetName ( pDescriptor->sFontName );
664 aFont.SetCharSet ( static_cast < rtl_TextEncoding > (pDescriptor->nCharSet) );
665 aFont.SetFamily ( static_cast < FontFamily > (pDescriptor->nFamily ) );
666 aFont.SetPitch ( static_cast < FontPitch > (pDescriptor->nPitch ) );
667 aFont.SetWeight ( static_cast < FontWeight > (pDescriptor->nWeight ) );
668 aFont.SetItalic ( static_cast < FontItalic > (pDescriptor->nItalic ) );
669 SmSym aSymbol ( pDescriptor->sName, aFont, static_cast < sal_Unicode > (pDescriptor->nCharacter),
670 pDescriptor->sSymbolSet );
671 aSymbol.SetExportName ( pDescriptor->sExportName );
672 aSymbol.SetDocSymbol( true );
673 rManager.AddOrReplaceSymbol ( aSymbol );
676 else
677 throw IllegalArgumentException();
679 break;
680 // #i33095# Security Options
681 case HANDLE_LOAD_READONLY :
683 if ( (*pValues).getValueType() != cppu::UnoType<bool>::get() )
684 throw IllegalArgumentException();
685 bool bReadonly = false;
686 if ( *pValues >>= bReadonly )
687 pDocSh->SetLoadReadonly( bReadonly );
688 break;
690 case HANDLE_INTEROP_GRAB_BAG:
691 setGrabBagItem(*pValues);
692 break;
696 pDocSh->SetFormat( aFormat );
698 // #i67283# since about all of the above changes are likely to change
699 // the formula size we have to recalculate the vis-area now
700 pDocSh->SetVisArea( Rectangle( Point(0, 0), pDocSh->GetSize() ) );
703 void SmModel::_getPropertyValues( const PropertyMapEntry **ppEntries, Any *pValue )
704 throw (RuntimeException, UnknownPropertyException, WrappedTargetException, std::exception)
706 SmDocShell *pDocSh = static_cast < SmDocShell * > (GetObjectShell());
708 if ( NULL == pDocSh )
709 throw UnknownPropertyException();
711 const SmFormat & aFormat = pDocSh->GetFormat();
713 for (; *ppEntries; ppEntries++, pValue++ )
715 switch ( (*ppEntries)->mnHandle )
717 case HANDLE_FORMULA:
718 *pValue <<= OUString(pDocSh->GetText());
719 break;
720 case HANDLE_FONT_NAME_VARIABLES :
721 case HANDLE_FONT_NAME_FUNCTIONS :
722 case HANDLE_FONT_NAME_NUMBERS :
723 case HANDLE_FONT_NAME_TEXT :
724 case HANDLE_CUSTOM_FONT_NAME_SERIF :
725 case HANDLE_CUSTOM_FONT_NAME_SANS :
726 case HANDLE_CUSTOM_FONT_NAME_FIXED :
728 const SmFace & rFace = aFormat.GetFont((*ppEntries)->mnMemberId);
729 *pValue <<= OUString(rFace.GetName());
731 break;
732 case HANDLE_CUSTOM_FONT_FIXED_POSTURE:
733 case HANDLE_CUSTOM_FONT_SANS_POSTURE :
734 case HANDLE_CUSTOM_FONT_SERIF_POSTURE:
735 case HANDLE_FONT_VARIABLES_POSTURE :
736 case HANDLE_FONT_FUNCTIONS_POSTURE :
737 case HANDLE_FONT_NUMBERS_POSTURE :
738 case HANDLE_FONT_TEXT_POSTURE :
740 const SmFace & rFace = aFormat.GetFont((*ppEntries)->mnMemberId);
741 bool bVal = IsItalic( rFace );
742 (*pValue).setValue(&bVal, (*ppEntries)->maType);
744 break;
745 case HANDLE_CUSTOM_FONT_FIXED_WEIGHT :
746 case HANDLE_CUSTOM_FONT_SANS_WEIGHT :
747 case HANDLE_CUSTOM_FONT_SERIF_WEIGHT :
748 case HANDLE_FONT_VARIABLES_WEIGHT :
749 case HANDLE_FONT_FUNCTIONS_WEIGHT :
750 case HANDLE_FONT_NUMBERS_WEIGHT :
751 case HANDLE_FONT_TEXT_WEIGHT :
753 const SmFace & rFace = aFormat.GetFont((*ppEntries)->mnMemberId);
754 bool bVal = IsBold( rFace ); // bold?
755 (*pValue).setValue(&bVal, (*ppEntries)->maType);
757 break;
758 case HANDLE_BASE_FONT_HEIGHT :
760 // Point!
761 sal_Int16 nVal = static_cast < sal_Int16 > (aFormat.GetBaseSize().Height());
762 nVal = static_cast < sal_Int16 > (convertMm100ToTwip(nVal));
763 nVal = (nVal + 10) / 20;
764 *pValue <<= nVal;
766 break;
767 case HANDLE_RELATIVE_FONT_HEIGHT_TEXT :
768 case HANDLE_RELATIVE_FONT_HEIGHT_INDICES :
769 case HANDLE_RELATIVE_FONT_HEIGHT_FUNCTIONS :
770 case HANDLE_RELATIVE_FONT_HEIGHT_OPERATORS :
771 case HANDLE_RELATIVE_FONT_HEIGHT_LIMITS :
772 *pValue <<= (sal_Int16) aFormat.GetRelSize((*ppEntries)->mnMemberId);
773 break;
775 case HANDLE_IS_TEXT_MODE :
777 sal_Bool bVal = aFormat.IsTextmode();
778 (*pValue).setValue(&bVal, cppu::UnoType<bool>::get());
780 break;
782 case HANDLE_GREEK_CHAR_STYLE :
783 *pValue <<= (sal_Int16)aFormat.GetGreekCharStyle();
784 break;
786 case HANDLE_ALIGNMENT :
787 // SmHorAlign uses the same values as HorizontalAlignment
788 *pValue <<= (sal_Int16)aFormat.GetHorAlign();
789 break;
791 case HANDLE_RELATIVE_SPACING :
792 case HANDLE_RELATIVE_LINE_SPACING :
793 case HANDLE_RELATIVE_ROOT_SPACING :
794 case HANDLE_RELATIVE_INDEX_SUPERSCRIPT :
795 case HANDLE_RELATIVE_INDEX_SUBSCRIPT :
796 case HANDLE_RELATIVE_FRACTION_NUMERATOR_HEIGHT :
797 case HANDLE_RELATIVE_FRACTION_DENOMINATOR_DEPTH:
798 case HANDLE_RELATIVE_FRACTION_BAR_EXCESS_LENGTH:
799 case HANDLE_RELATIVE_FRACTION_BAR_LINE_WEIGHT :
800 case HANDLE_RELATIVE_UPPER_LIMIT_DISTANCE :
801 case HANDLE_RELATIVE_LOWER_LIMIT_DISTANCE :
802 case HANDLE_RELATIVE_BRACKET_EXCESS_SIZE :
803 case HANDLE_RELATIVE_BRACKET_DISTANCE :
804 case HANDLE_RELATIVE_SCALE_BRACKET_EXCESS_SIZE :
805 case HANDLE_RELATIVE_MATRIX_LINE_SPACING :
806 case HANDLE_RELATIVE_MATRIX_COLUMN_SPACING :
807 case HANDLE_RELATIVE_SYMBOL_PRIMARY_HEIGHT :
808 case HANDLE_RELATIVE_SYMBOL_MINIMUM_HEIGHT :
809 case HANDLE_RELATIVE_OPERATOR_EXCESS_SIZE :
810 case HANDLE_RELATIVE_OPERATOR_SPACING :
811 case HANDLE_LEFT_MARGIN :
812 case HANDLE_RIGHT_MARGIN :
813 case HANDLE_TOP_MARGIN :
814 case HANDLE_BOTTOM_MARGIN :
815 *pValue <<= (sal_Int16)aFormat.GetDistance((*ppEntries)->mnMemberId);
816 break;
817 case HANDLE_IS_SCALE_ALL_BRACKETS :
819 sal_Bool bVal = aFormat.IsScaleNormalBrackets();
820 (*pValue).setValue(&bVal, cppu::UnoType<bool>::get());
822 break;
823 case HANDLE_PRINTER_NAME:
825 SfxPrinter *pPrinter = pDocSh->GetPrinter ( );
826 *pValue <<= pPrinter ? OUString ( pPrinter->GetName()) : OUString();
828 break;
829 case HANDLE_PRINTER_SETUP:
831 SfxPrinter *pPrinter = pDocSh->GetPrinter ();
832 if (pPrinter)
834 SvMemoryStream aStream;
835 pPrinter->Store( aStream );
836 aStream.Seek ( STREAM_SEEK_TO_END );
837 sal_uInt32 nSize = aStream.Tell();
838 aStream.Seek ( STREAM_SEEK_TO_BEGIN );
839 Sequence < sal_Int8 > aSequence ( nSize );
840 aStream.Read ( aSequence.getArray(), nSize );
841 *pValue <<= aSequence;
844 break;
845 case HANDLE_SYMBOLS:
846 case HANDLE_USED_SYMBOLS:
848 const bool bUsedSymbolsOnly = (*ppEntries)->mnHandle == HANDLE_USED_SYMBOLS;
849 const std::set< OUString > &rUsedSymbols = pDocSh->GetUsedSymbols();
851 // this is get
852 SmModule *pp = SM_MOD();
853 const SmSymbolManager &rManager = pp->GetSymbolManager();
854 vector < const SmSym * > aVector;
856 const SymbolPtrVec_t aSymbols( rManager.GetSymbols() );
857 size_t nCount = 0;
858 for (size_t i = 0; i < aSymbols.size(); ++i)
860 const SmSym * pSymbol = aSymbols[ i ];
861 if (pSymbol && !pSymbol->IsPredefined() &&
862 (!bUsedSymbolsOnly ||
863 rUsedSymbols.find( pSymbol->GetName() ) != rUsedSymbols.end()))
865 aVector.push_back ( pSymbol );
866 nCount++;
869 Sequence < SymbolDescriptor > aSequence ( nCount );
870 SymbolDescriptor * pDescriptor = aSequence.getArray();
872 vector < const SmSym * >::const_iterator aIter = aVector.begin(), aEnd = aVector.end();
873 for(; aIter != aEnd; pDescriptor++, ++aIter)
875 pDescriptor->sName = (*aIter)->GetName();
876 pDescriptor->sExportName = (*aIter)->GetExportName();
877 pDescriptor->sSymbolSet = (*aIter)->GetSymbolSetName();
878 pDescriptor->nCharacter = static_cast < sal_Int32 > ((*aIter)->GetCharacter());
880 vcl::Font rFont = (*aIter)->GetFace();
881 pDescriptor->sFontName = rFont.GetName();
882 pDescriptor->nCharSet = sal::static_int_cast< sal_Int16 >(rFont.GetCharSet());
883 pDescriptor->nFamily = sal::static_int_cast< sal_Int16 >(rFont.GetFamily());
884 pDescriptor->nPitch = sal::static_int_cast< sal_Int16 >(rFont.GetPitch());
885 pDescriptor->nWeight = sal::static_int_cast< sal_Int16 >(rFont.GetWeight());
886 pDescriptor->nItalic = sal::static_int_cast< sal_Int16 >(rFont.GetItalic());
888 *pValue <<= aSequence;
890 break;
891 case HANDLE_BASIC_LIBRARIES:
892 *pValue <<= pDocSh->GetBasicContainer();
893 break;
894 case HANDLE_DIALOG_LIBRARIES:
895 *pValue <<= pDocSh->GetDialogContainer();
896 break;
897 case HANDLE_RUNTIME_UID:
898 *pValue <<= getRuntimeUID();
899 break;
900 // #i33095# Security Options
901 case HANDLE_LOAD_READONLY :
903 *pValue <<= pDocSh->IsLoadReadonly();
904 break;
906 // #i972#
907 case HANDLE_BASELINE:
909 if ( !pDocSh->pTree )
910 pDocSh->Parse();
911 if ( pDocSh->pTree )
913 if ( !pDocSh->IsFormulaArranged() )
914 pDocSh->ArrangeFormula();
916 *pValue <<= static_cast<sal_Int32>( pDocSh->pTree->GetFormulaBaseline() );
918 break;
920 case HANDLE_INTEROP_GRAB_BAG:
921 getGrabBagItem(*pValue);
922 break;
929 sal_Int32 SAL_CALL SmModel::getRendererCount(
930 const uno::Any& /*rSelection*/,
931 const uno::Sequence< beans::PropertyValue >& /*xOptions*/ )
932 throw (IllegalArgumentException, RuntimeException, std::exception)
934 SolarMutexGuard aGuard;
935 return 1;
939 static Size lcl_GuessPaperSize()
941 Size aRes;
942 const LocaleDataWrapper& rLocWrp( AllSettings().GetLocaleDataWrapper() );
943 if( MEASURE_METRIC == rLocWrp.getMeasurementSystemEnum() )
945 // in 100th mm
946 PaperInfo aInfo( PAPER_A4 );
947 aRes.Width() = aInfo.getWidth();
948 aRes.Height() = aInfo.getHeight();
950 else
952 // in 100th mm
953 PaperInfo aInfo( PAPER_LETTER );
954 aRes.Width() = aInfo.getWidth();
955 aRes.Height() = aInfo.getHeight();
957 return aRes;
960 uno::Sequence< beans::PropertyValue > SAL_CALL SmModel::getRenderer(
961 sal_Int32 nRenderer,
962 const uno::Any& /*rSelection*/,
963 const uno::Sequence< beans::PropertyValue >& /*rxOptions*/ )
964 throw (IllegalArgumentException, RuntimeException, std::exception)
966 SolarMutexGuard aGuard;
968 if (0 != nRenderer)
969 throw IllegalArgumentException();
971 SmDocShell *pDocSh = static_cast < SmDocShell * >( GetObjectShell() );
972 if (!pDocSh)
973 throw RuntimeException();
975 SmPrinterAccess aPrinterAccess( *pDocSh );
976 Printer *pPrinter = aPrinterAccess.GetPrinter();
977 Size aPrtPaperSize ( pPrinter->GetPaperSize() );
979 // if paper size is 0 (usually if no 'real' printer is found),
980 // guess the paper size
981 if (aPrtPaperSize.Height() == 0 || aPrtPaperSize.Width() == 0)
982 aPrtPaperSize = lcl_GuessPaperSize();
983 awt::Size aPageSize( aPrtPaperSize.Width(), aPrtPaperSize.Height() );
985 uno::Sequence< beans::PropertyValue > aRenderer(1);
986 PropertyValue &rValue = aRenderer.getArray()[0];
987 rValue.Name = "PageSize";
988 rValue.Value <<= aPageSize;
990 if (!m_pPrintUIOptions)
991 m_pPrintUIOptions.reset(new SmPrintUIOptions);
992 m_pPrintUIOptions->appendPrintUIOptions( aRenderer );
994 return aRenderer;
997 void SAL_CALL SmModel::render(
998 sal_Int32 nRenderer,
999 const uno::Any& rSelection,
1000 const uno::Sequence< beans::PropertyValue >& rxOptions )
1001 throw (IllegalArgumentException, RuntimeException, std::exception)
1003 SolarMutexGuard aGuard;
1005 if (0 != nRenderer)
1006 throw IllegalArgumentException();
1008 SmDocShell *pDocSh = static_cast < SmDocShell * >( GetObjectShell() );
1009 if (!pDocSh)
1010 throw RuntimeException();
1012 // get device to be rendered in
1013 uno::Reference< awt::XDevice > xRenderDevice;
1014 for (sal_Int32 i = 0, nCount = rxOptions.getLength(); i < nCount; ++i)
1016 if( rxOptions[i].Name == "RenderDevice" )
1017 rxOptions[i].Value >>= xRenderDevice;
1020 if (xRenderDevice.is())
1022 VCLXDevice* pDevice = VCLXDevice::GetImplementation( xRenderDevice );
1023 VclPtr< OutputDevice> pOut = pDevice ? pDevice->GetOutputDevice()
1024 : VclPtr< OutputDevice >();
1025 if (!pOut)
1026 throw RuntimeException();
1028 pOut->SetMapMode( MAP_100TH_MM );
1030 uno::Reference< frame::XModel > xModel;
1031 rSelection >>= xModel;
1032 if (xModel == pDocSh->GetModel())
1034 //!! when called via API we may not have an active view
1035 //!! thus we go and look for a view that can be used.
1036 const TypeId aTypeId = TYPE( SmViewShell );
1037 SfxViewShell* pViewSh = SfxViewShell::GetFirst( &aTypeId, false /* search non-visible views as well*/ );
1038 while (pViewSh && pViewSh->GetObjectShell() != pDocSh)
1039 pViewSh = SfxViewShell::GetNext( *pViewSh, &aTypeId, false /* search non-visible views as well*/ );
1040 SmViewShell *pView = PTR_CAST( SmViewShell, pViewSh );
1041 SAL_WARN_IF( !pView, "starmath", "SmModel::render : no SmViewShell found" );
1043 if (pView)
1045 SmPrinterAccess aPrinterAccess( *pDocSh );
1046 Printer *pPrinter = aPrinterAccess.GetPrinter();
1048 Size aPrtPaperSize ( pPrinter->GetPaperSize() );
1049 Size aOutputSize ( pPrinter->GetOutputSize() );
1050 Point aPrtPageOffset( pPrinter->GetPageOffset() );
1052 // no real printer ??
1053 if (aPrtPaperSize.Height() == 0 || aPrtPaperSize.Width() == 0)
1055 aPrtPaperSize = lcl_GuessPaperSize();
1056 // factors from Windows DIN A4
1057 aOutputSize = Size( (long)(aPrtPaperSize.Width() * 0.941),
1058 (long)(aPrtPaperSize.Height() * 0.961));
1059 aPrtPageOffset = Point( (long)(aPrtPaperSize.Width() * 0.0250),
1060 (long)(aPrtPaperSize.Height() * 0.0214));
1062 Point aZeroPoint;
1063 Rectangle OutputRect( aZeroPoint, aOutputSize );
1066 // set minimum top and bottom border
1067 if (aPrtPageOffset.Y() < 2000)
1068 OutputRect.Top() += 2000 - aPrtPageOffset.Y();
1069 if ((aPrtPaperSize.Height() - (aPrtPageOffset.Y() + OutputRect.Bottom())) < 2000)
1070 OutputRect.Bottom() -= 2000 - (aPrtPaperSize.Height() -
1071 (aPrtPageOffset.Y() + OutputRect.Bottom()));
1073 // set minimum left and right border
1074 if (aPrtPageOffset.X() < 2500)
1075 OutputRect.Left() += 2500 - aPrtPageOffset.X();
1076 if ((aPrtPaperSize.Width() - (aPrtPageOffset.X() + OutputRect.Right())) < 1500)
1077 OutputRect.Right() -= 1500 - (aPrtPaperSize.Width() -
1078 (aPrtPageOffset.X() + OutputRect.Right()));
1080 if (!m_pPrintUIOptions)
1081 m_pPrintUIOptions.reset(new SmPrintUIOptions);
1082 m_pPrintUIOptions->processProperties( rxOptions );
1084 pView->Impl_Print( *pOut, *m_pPrintUIOptions, Rectangle( OutputRect ), Point() );
1086 // release SmPrintUIOptions when everything is done.
1087 // That way, when SmPrintUIOptions is needed again it will read the latest configuration settings in its c-tor.
1088 if (m_pPrintUIOptions->getBoolValue( "IsLastPage", false ))
1090 m_pPrintUIOptions.reset();
1097 void SAL_CALL SmModel::setParent( const uno::Reference< uno::XInterface >& xParent)
1098 throw( lang::NoSupportException, uno::RuntimeException, std::exception )
1100 SolarMutexGuard aGuard;
1101 SfxBaseModel::setParent( xParent );
1102 uno::Reference< lang::XUnoTunnel > xParentTunnel( xParent, uno::UNO_QUERY );
1103 if ( xParentTunnel.is() )
1105 SvGlobalName aSfxIdent( SFX_GLOBAL_CLASSID );
1106 SfxObjectShell* pDoc = reinterpret_cast<SfxObjectShell *>(xParentTunnel->getSomething(
1107 uno::Sequence< sal_Int8 >( aSfxIdent.GetByteSequence() ) ) );
1108 if ( pDoc )
1109 GetObjectShell()->OnDocumentPrinterChanged( pDoc->GetDocumentPrinter() );
1113 void SmModel::writeFormulaOoxml( ::sax_fastparser::FSHelperPtr m_pSerializer, oox::core::OoxmlVersion version )
1115 static_cast< SmDocShell* >( GetObjectShell())->writeFormulaOoxml( m_pSerializer, version );
1118 void SmModel::writeFormulaRtf(OStringBuffer& rBuffer, rtl_TextEncoding nEncoding)
1120 static_cast<SmDocShell*>(GetObjectShell())->writeFormulaRtf(rBuffer, nEncoding);
1123 void SmModel::readFormulaOoxml( oox::formulaimport::XmlStream& stream )
1125 static_cast< SmDocShell* >( GetObjectShell())->readFormulaOoxml( stream );
1128 Size SmModel::getFormulaSize() const
1130 return static_cast< SmDocShell* >( GetObjectShell())->GetSize();
1133 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */