Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / starmath / source / unomodel.cxx
blob0afc6093de1531b2b362444fae8edb208ae3c829
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 <sal/config.h>
22 #include <utility>
24 #include <o3tl/any.hxx>
25 #include <o3tl/make_unique.hxx>
26 #include <sfx2/printer.hxx>
27 #include <vcl/svapp.hxx>
28 #include <unotools/localedatawrapper.hxx>
29 #include <vcl/settings.hxx>
30 #include <vcl/print.hxx>
31 #include <toolkit/awt/vclxdevice.hxx>
32 #include <com/sun/star/beans/PropertyAttribute.hpp>
33 #include <com/sun/star/formula/SymbolDescriptor.hpp>
34 #include <com/sun/star/awt/Size.hpp>
35 #include <com/sun/star/script/XLibraryContainer.hpp>
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 <strings.hrc>
48 #include "cfgitem.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 SmModule *pp = SM_MOD();
64 SmMathConfig *pConfig = pp->GetConfig();
65 SAL_WARN_IF( !pConfig, "starmath", "SmConfig not found" );
66 if (!pConfig)
67 return;
69 sal_Int32 nNumProps = 10, nIdx=0;
71 // create sequence of print UI options
72 // (Actually IsIgnoreSpacesRight is a parser option. Without it we need only 8 properties here.)
73 m_aUIProperties.resize( nNumProps );
75 // load the math PrinterOptions into the custom tab
76 m_aUIProperties[nIdx].Name = "OptionsUIFile";
77 m_aUIProperties[nIdx++].Value <<= OUString("modules/smath/ui/printeroptions.ui");
79 // create Section for formula (results in an extra tab page in dialog)
80 SvtModuleOptions aOpt;
81 OUString aAppGroupname(
82 SmResId( RID_PRINTUIOPT_PRODNAME ).
83 replaceFirst( "%s", aOpt.GetModuleName( SvtModuleOptions::EModule::MATH ) ) );
84 m_aUIProperties[nIdx++].Value = setGroupControlOpt("tabcontrol-page2", aAppGroupname, ".HelpID:vcl:PrintDialog:TabPage:AppPage");
86 // create subgroup for print options
87 m_aUIProperties[nIdx++].Value = setSubgroupControlOpt("contents", SmResId( RID_PRINTUIOPT_CONTENTS ), OUString());
89 // create a bool option for title row (matches to SID_PRINTTITLE)
90 m_aUIProperties[nIdx++].Value = setBoolControlOpt("title", SmResId( RID_PRINTUIOPT_TITLE ),
91 ".HelpID:vcl:PrintDialog:TitleRow:CheckBox",
92 PRTUIOPT_TITLE_ROW,
93 pConfig->IsPrintTitle());
94 // create a bool option for formula text (matches to SID_PRINTTEXT)
95 m_aUIProperties[nIdx++].Value = setBoolControlOpt("formulatext", SmResId( RID_PRINTUIOPT_FRMLTXT ),
96 ".HelpID:vcl:PrintDialog:FormulaText:CheckBox",
97 PRTUIOPT_FORMULA_TEXT,
98 pConfig->IsPrintFormulaText());
99 // create a bool option for border (matches to SID_PRINTFRAME)
100 m_aUIProperties[nIdx++].Value = setBoolControlOpt("borders", SmResId( RID_PRINTUIOPT_BORDERS ),
101 ".HelpID:vcl:PrintDialog:Border:CheckBox",
102 PRTUIOPT_BORDER,
103 pConfig->IsPrintFrame());
105 // create subgroup for print format
106 m_aUIProperties[nIdx++].Value = setSubgroupControlOpt("size", SmResId( RID_PRINTUIOPT_SIZE ), OUString());
108 // create a radio button group for print format (matches to SID_PRINTSIZE)
109 Sequence< OUString > aChoices{
110 SmResId( RID_PRINTUIOPT_ORIGSIZE ),
111 SmResId( RID_PRINTUIOPT_FITTOPAGE ),
112 SmResId( RID_PRINTUIOPT_SCALING )
114 Sequence< OUString > aHelpIds{
115 ".HelpID:vcl:PrintDialog:PrintFormat:RadioButton:0",
116 ".HelpID:vcl:PrintDialog:PrintFormat:RadioButton:1",
117 ".HelpID:vcl:PrintDialog:PrintFormat:RadioButton:2"
119 Sequence< OUString > aWidgetIds{
120 "originalsize",
121 "fittopage",
122 "scaling"
124 OUString aPrintFormatProp( PRTUIOPT_PRINT_FORMAT );
125 m_aUIProperties[nIdx++].Value = setChoiceRadiosControlOpt(aWidgetIds, OUString(),
126 aHelpIds,
127 aPrintFormatProp,
128 aChoices, static_cast< sal_Int32 >(pConfig->GetPrintSize())
131 // create a numeric box for scale dependent on PrintFormat = "Scaling" (matches to SID_PRINTZOOM)
132 vcl::PrinterOptionsHelper::UIControlOptions aRangeOpt( aPrintFormatProp, 2, true );
133 m_aUIProperties[nIdx++].Value = setRangeControlOpt("scalingspin", OUString(),
134 ".HelpID:vcl:PrintDialog:PrintScale:NumericField",
135 PRTUIOPT_PRINT_SCALE,
136 pConfig->GetPrintZoomFactor(), // initial value
137 10, // min value
138 1000, // max value
139 aRangeOpt);
141 Sequence< PropertyValue > aHintNoLayoutPage( 1 );
142 aHintNoLayoutPage[0].Name = "HintNoLayoutPage";
143 aHintNoLayoutPage[0].Value <<= true;
144 m_aUIProperties[nIdx++].Value <<= aHintNoLayoutPage;
146 assert(nIdx == nNumProps);
150 // class SmModel
153 // values from com/sun/star/beans/PropertyAttribute
154 #define PROPERTY_NONE 0
156 enum SmModelPropertyHandles
158 HANDLE_FORMULA,
159 HANDLE_FONT_NAME_VARIABLES,
160 HANDLE_FONT_NAME_FUNCTIONS,
161 HANDLE_FONT_NAME_NUMBERS,
162 HANDLE_FONT_NAME_TEXT,
163 HANDLE_CUSTOM_FONT_NAME_SERIF,
164 HANDLE_CUSTOM_FONT_NAME_SANS,
165 HANDLE_CUSTOM_FONT_NAME_FIXED,
166 HANDLE_CUSTOM_FONT_FIXED_POSTURE,
167 HANDLE_CUSTOM_FONT_FIXED_WEIGHT,
168 HANDLE_CUSTOM_FONT_SANS_POSTURE,
169 HANDLE_CUSTOM_FONT_SANS_WEIGHT,
170 HANDLE_CUSTOM_FONT_SERIF_POSTURE,
171 HANDLE_CUSTOM_FONT_SERIF_WEIGHT,
172 HANDLE_FONT_VARIABLES_POSTURE,
173 HANDLE_FONT_VARIABLES_WEIGHT,
174 HANDLE_FONT_FUNCTIONS_POSTURE,
175 HANDLE_FONT_FUNCTIONS_WEIGHT,
176 HANDLE_FONT_NUMBERS_POSTURE,
177 HANDLE_FONT_NUMBERS_WEIGHT,
178 HANDLE_FONT_TEXT_POSTURE,
179 HANDLE_FONT_TEXT_WEIGHT,
180 HANDLE_BASE_FONT_HEIGHT,
181 HANDLE_RELATIVE_FONT_HEIGHT_TEXT,
182 HANDLE_RELATIVE_FONT_HEIGHT_INDICES,
183 HANDLE_RELATIVE_FONT_HEIGHT_FUNCTIONS,
184 HANDLE_RELATIVE_FONT_HEIGHT_OPERATORS,
185 HANDLE_RELATIVE_FONT_HEIGHT_LIMITS,
186 HANDLE_IS_TEXT_MODE,
187 HANDLE_GREEK_CHAR_STYLE,
188 HANDLE_ALIGNMENT,
189 HANDLE_RELATIVE_SPACING,
190 HANDLE_RELATIVE_LINE_SPACING,
191 HANDLE_RELATIVE_ROOT_SPACING,
192 HANDLE_RELATIVE_INDEX_SUPERSCRIPT,
193 HANDLE_RELATIVE_INDEX_SUBSCRIPT,
194 HANDLE_RELATIVE_FRACTION_NUMERATOR_HEIGHT,
195 HANDLE_RELATIVE_FRACTION_DENOMINATOR_DEPTH,
196 HANDLE_RELATIVE_FRACTION_BAR_EXCESS_LENGTH,
197 HANDLE_RELATIVE_FRACTION_BAR_LINE_WEIGHT,
198 HANDLE_RELATIVE_UPPER_LIMIT_DISTANCE,
199 HANDLE_RELATIVE_LOWER_LIMIT_DISTANCE,
200 HANDLE_RELATIVE_BRACKET_EXCESS_SIZE,
201 HANDLE_RELATIVE_BRACKET_DISTANCE,
202 HANDLE_IS_SCALE_ALL_BRACKETS,
203 HANDLE_RELATIVE_SCALE_BRACKET_EXCESS_SIZE,
204 HANDLE_RELATIVE_MATRIX_LINE_SPACING,
205 HANDLE_RELATIVE_MATRIX_COLUMN_SPACING,
206 HANDLE_RELATIVE_SYMBOL_PRIMARY_HEIGHT,
207 HANDLE_RELATIVE_SYMBOL_MINIMUM_HEIGHT,
208 HANDLE_RELATIVE_OPERATOR_EXCESS_SIZE,
209 HANDLE_RELATIVE_OPERATOR_SPACING,
210 HANDLE_LEFT_MARGIN,
211 HANDLE_RIGHT_MARGIN,
212 HANDLE_TOP_MARGIN,
213 HANDLE_BOTTOM_MARGIN,
214 HANDLE_PRINTER_NAME,
215 HANDLE_PRINTER_SETUP,
216 HANDLE_SYMBOLS,
217 HANDLE_USED_SYMBOLS,
218 HANDLE_BASIC_LIBRARIES,
219 HANDLE_RUNTIME_UID,
220 HANDLE_LOAD_READONLY, // Security Options
221 HANDLE_DIALOG_LIBRARIES, // #i73329#
222 HANDLE_BASELINE,
223 HANDLE_INTEROP_GRAB_BAG,
226 static rtl::Reference<PropertySetInfo> lcl_createModelPropertyInfo ()
228 static PropertyMapEntry aModelPropertyInfoMap[] =
230 { OUString("Alignment") , HANDLE_ALIGNMENT , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, 0 },
231 { OUString("BaseFontHeight") , HANDLE_BASE_FONT_HEIGHT , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, 0 },
232 { OUString("BasicLibraries") , HANDLE_BASIC_LIBRARIES , cppu::UnoType<script::XLibraryContainer>::get(), PropertyAttribute::READONLY, 0 },
233 { OUString("BottomMargin") , HANDLE_BOTTOM_MARGIN , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_BOTTOMSPACE },
234 { OUString("CustomFontNameFixed") , HANDLE_CUSTOM_FONT_NAME_FIXED , ::cppu::UnoType<OUString>::get(), PROPERTY_NONE, FNT_FIXED },
235 { OUString("CustomFontNameSans") , HANDLE_CUSTOM_FONT_NAME_SANS , ::cppu::UnoType<OUString>::get(), PROPERTY_NONE, FNT_SANS },
236 { OUString("CustomFontNameSerif") , HANDLE_CUSTOM_FONT_NAME_SERIF , ::cppu::UnoType<OUString>::get(), PROPERTY_NONE, FNT_SERIF },
237 { OUString("DialogLibraries") , HANDLE_DIALOG_LIBRARIES , cppu::UnoType<script::XLibraryContainer>::get(), PropertyAttribute::READONLY, 0 },
238 { OUString("FontFixedIsBold") , HANDLE_CUSTOM_FONT_FIXED_WEIGHT , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_FIXED },
239 { OUString("FontFixedIsItalic") , HANDLE_CUSTOM_FONT_FIXED_POSTURE , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_FIXED },
240 { OUString("FontFunctionsIsBold") , HANDLE_FONT_FUNCTIONS_WEIGHT , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_FUNCTION },
241 { OUString("FontFunctionsIsItalic") , HANDLE_FONT_FUNCTIONS_POSTURE , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_FUNCTION },
242 { OUString("FontNameFunctions") , HANDLE_FONT_NAME_FUNCTIONS , ::cppu::UnoType<OUString>::get(), PROPERTY_NONE, FNT_FUNCTION },
243 { OUString("FontNameNumbers") , HANDLE_FONT_NAME_NUMBERS , ::cppu::UnoType<OUString>::get(), PROPERTY_NONE, FNT_NUMBER },
244 { OUString("FontNameText") , HANDLE_FONT_NAME_TEXT , ::cppu::UnoType<OUString>::get(), PROPERTY_NONE, FNT_TEXT },
245 { OUString("FontNameVariables") , HANDLE_FONT_NAME_VARIABLES , ::cppu::UnoType<OUString>::get(), PROPERTY_NONE, FNT_VARIABLE },
246 { OUString("FontNumbersIsBold") , HANDLE_FONT_NUMBERS_WEIGHT , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_NUMBER },
247 { OUString("FontNumbersIsItalic") , HANDLE_FONT_NUMBERS_POSTURE , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_NUMBER },
248 { OUString("FontSansIsBold") , HANDLE_CUSTOM_FONT_SANS_WEIGHT , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_SANS },
249 { OUString("FontSansIsItalic") , HANDLE_CUSTOM_FONT_SANS_POSTURE , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_SANS },
250 { OUString("FontSerifIsBold") , HANDLE_CUSTOM_FONT_SERIF_WEIGHT , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_SERIF },
251 { OUString("FontSerifIsItalic") , HANDLE_CUSTOM_FONT_SERIF_POSTURE , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_SERIF },
252 { OUString("FontTextIsBold") , HANDLE_FONT_TEXT_WEIGHT , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_TEXT },
253 { OUString("FontTextIsItalic") , HANDLE_FONT_TEXT_POSTURE , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_TEXT },
254 { OUString("FontVariablesIsBold") , HANDLE_FONT_VARIABLES_WEIGHT , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_VARIABLE },
255 { OUString("FontVariablesIsItalic") , HANDLE_FONT_VARIABLES_POSTURE , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_VARIABLE },
256 { OUString("Formula") , HANDLE_FORMULA , ::cppu::UnoType<OUString>::get(), PROPERTY_NONE, 0 },
257 { OUString("IsScaleAllBrackets") , HANDLE_IS_SCALE_ALL_BRACKETS , cppu::UnoType<bool>::get(), PROPERTY_NONE, 0 },
258 { OUString("IsTextMode") , HANDLE_IS_TEXT_MODE , cppu::UnoType<bool>::get(), PROPERTY_NONE, 0 },
259 { OUString("GreekCharStyle") , HANDLE_GREEK_CHAR_STYLE , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, 0 },
260 { OUString("LeftMargin") , HANDLE_LEFT_MARGIN , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_LEFTSPACE },
261 { OUString("PrinterName") , HANDLE_PRINTER_NAME , ::cppu::UnoType<OUString>::get(), PROPERTY_NONE, 0 },
262 { OUString("PrinterSetup") , HANDLE_PRINTER_SETUP , cppu::UnoType<const Sequence < sal_Int8 >>::get(), PROPERTY_NONE, 0 },
263 { OUString("RelativeBracketDistance") , HANDLE_RELATIVE_BRACKET_DISTANCE , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_BRACKETSPACE },
264 { OUString("RelativeBracketExcessSize") , HANDLE_RELATIVE_BRACKET_EXCESS_SIZE , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_BRACKETSIZE },
265 { OUString("RelativeFontHeightFunctions") , HANDLE_RELATIVE_FONT_HEIGHT_FUNCTIONS , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, SIZ_FUNCTION },
266 { OUString("RelativeFontHeightIndices") , HANDLE_RELATIVE_FONT_HEIGHT_INDICES , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, SIZ_INDEX },
267 { OUString("RelativeFontHeightLimits") , HANDLE_RELATIVE_FONT_HEIGHT_LIMITS , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, SIZ_LIMITS },
268 { OUString("RelativeFontHeightOperators") , HANDLE_RELATIVE_FONT_HEIGHT_OPERATORS , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, SIZ_OPERATOR },
269 { OUString("RelativeFontHeightText") , HANDLE_RELATIVE_FONT_HEIGHT_TEXT , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, SIZ_TEXT },
270 { OUString("RelativeFractionBarExcessLength") , HANDLE_RELATIVE_FRACTION_BAR_EXCESS_LENGTH, ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_FRACTION },
271 { OUString("RelativeFractionBarLineWeight") , HANDLE_RELATIVE_FRACTION_BAR_LINE_WEIGHT , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_STROKEWIDTH },
272 { OUString("RelativeFractionDenominatorDepth") , HANDLE_RELATIVE_FRACTION_DENOMINATOR_DEPTH, ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_DENOMINATOR },
273 { OUString("RelativeFractionNumeratorHeight") , HANDLE_RELATIVE_FRACTION_NUMERATOR_HEIGHT , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_NUMERATOR },
274 { OUString("RelativeIndexSubscript") , HANDLE_RELATIVE_INDEX_SUBSCRIPT , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_SUBSCRIPT },
275 { OUString("RelativeIndexSuperscript") , HANDLE_RELATIVE_INDEX_SUPERSCRIPT , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_SUPERSCRIPT },
276 { OUString("RelativeLineSpacing") , HANDLE_RELATIVE_LINE_SPACING , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_VERTICAL },
277 { OUString("RelativeLowerLimitDistance") , HANDLE_RELATIVE_LOWER_LIMIT_DISTANCE , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_LOWERLIMIT },
278 { OUString("RelativeMatrixColumnSpacing") , HANDLE_RELATIVE_MATRIX_COLUMN_SPACING , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_MATRIXCOL },
279 { OUString("RelativeMatrixLineSpacing") , HANDLE_RELATIVE_MATRIX_LINE_SPACING , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_MATRIXROW },
280 { OUString("RelativeOperatorExcessSize") , HANDLE_RELATIVE_OPERATOR_EXCESS_SIZE , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_OPERATORSIZE },
281 { OUString("RelativeOperatorSpacing") , HANDLE_RELATIVE_OPERATOR_SPACING , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_OPERATORSPACE },
282 { OUString("RelativeRootSpacing") , HANDLE_RELATIVE_ROOT_SPACING , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_ROOT },
283 { OUString("RelativeScaleBracketExcessSize") , HANDLE_RELATIVE_SCALE_BRACKET_EXCESS_SIZE , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_NORMALBRACKETSIZE },
284 { OUString("RelativeSpacing") , HANDLE_RELATIVE_SPACING , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_HORIZONTAL },
285 { OUString("RelativeSymbolMinimumHeight") , HANDLE_RELATIVE_SYMBOL_MINIMUM_HEIGHT , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_ORNAMENTSPACE },
286 { OUString("RelativeSymbolPrimaryHeight") , HANDLE_RELATIVE_SYMBOL_PRIMARY_HEIGHT , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_ORNAMENTSIZE },
287 { OUString("RelativeUpperLimitDistance") , HANDLE_RELATIVE_UPPER_LIMIT_DISTANCE , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_UPPERLIMIT },
288 { OUString("RightMargin") , HANDLE_RIGHT_MARGIN , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_RIGHTSPACE },
289 { OUString("RuntimeUID") , HANDLE_RUNTIME_UID , cppu::UnoType<OUString>::get(), PropertyAttribute::READONLY, 0 },
290 { OUString("Symbols") , HANDLE_SYMBOLS , cppu::UnoType<Sequence < SymbolDescriptor >>::get(), PROPERTY_NONE, 0 },
291 { OUString("UserDefinedSymbolsInUse") , HANDLE_USED_SYMBOLS , cppu::UnoType<Sequence < SymbolDescriptor >>::get(), PropertyAttribute::READONLY, 0 },
292 { OUString("TopMargin") , HANDLE_TOP_MARGIN , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_TOPSPACE },
293 // #i33095# Security Options
294 { OUString("LoadReadonly") , HANDLE_LOAD_READONLY , cppu::UnoType<bool>::get(), PROPERTY_NONE, 0 },
295 // #i972#
296 { OUString("BaseLine") , HANDLE_BASELINE , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, 0 },
297 { OUString("InteropGrabBag") , HANDLE_INTEROP_GRAB_BAG , cppu::UnoType<uno::Sequence< beans::PropertyValue >>::get(), PROPERTY_NONE, 0 },
298 { OUString(), 0, css::uno::Type(), 0, 0 }
300 return rtl::Reference<PropertySetInfo>( new PropertySetInfo ( aModelPropertyInfoMap ) );
303 SmModel::SmModel( SfxObjectShell *pObjSh )
304 : SfxBaseModel(pObjSh)
305 , PropertySetHelper ( lcl_createModelPropertyInfo () )
309 SmModel::~SmModel() throw ()
313 uno::Any SAL_CALL SmModel::queryInterface( const uno::Type& rType )
315 uno::Any aRet = ::cppu::queryInterface ( rType,
316 // OWeakObject interfaces
317 dynamic_cast< XInterface* > ( static_cast< XUnoTunnel* > ( this )),
318 static_cast< XWeak* > ( this ),
319 // PropertySetHelper interfaces
320 static_cast< XPropertySet* > ( this ),
321 static_cast< XMultiPropertySet* > ( this ),
322 // my own interfaces
323 static_cast< XServiceInfo* > ( this ),
324 static_cast< XRenderable* > ( this ) );
325 if (!aRet.hasValue())
326 aRet = SfxBaseModel::queryInterface ( rType );
327 return aRet;
330 void SAL_CALL SmModel::acquire() throw()
332 OWeakObject::acquire();
335 void SAL_CALL SmModel::release() throw()
337 OWeakObject::release();
340 uno::Sequence< uno::Type > SAL_CALL SmModel::getTypes( )
342 SolarMutexGuard aGuard;
343 uno::Sequence< uno::Type > aTypes = SfxBaseModel::getTypes();
344 sal_Int32 nLen = aTypes.getLength();
345 aTypes.realloc(nLen + 4);
346 uno::Type* pTypes = aTypes.getArray();
347 pTypes[nLen++] = cppu::UnoType<XServiceInfo>::get();
348 pTypes[nLen++] = cppu::UnoType<XPropertySet>::get();
349 pTypes[nLen++] = cppu::UnoType<XMultiPropertySet>::get();
350 pTypes[nLen++] = cppu::UnoType<XRenderable>::get();
352 return aTypes;
355 namespace
357 class theSmModelUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSmModelUnoTunnelId> {};
360 const uno::Sequence< sal_Int8 > & SmModel::getUnoTunnelId()
362 return theSmModelUnoTunnelId::get().getSeq();
365 sal_Int64 SAL_CALL SmModel::getSomething( const uno::Sequence< sal_Int8 >& rId )
367 if( rId.getLength() == 16
368 && 0 == memcmp( getUnoTunnelId().getConstArray(),
369 rId.getConstArray(), 16 ) )
371 return sal::static_int_cast< sal_Int64 >(reinterpret_cast< sal_uIntPtr >(this));
374 return SfxBaseModel::getSomething( rId );
377 static sal_Int16 lcl_AnyToINT16(const uno::Any& rAny)
379 sal_Int16 nRet = 0;
380 if( auto x = o3tl::tryAccess<double>(rAny) )
381 nRet = static_cast<sal_Int16>(*x);
382 else
383 rAny >>= nRet;
384 return nRet;
387 OUString SmModel::getImplementationName()
389 return OUString("com.sun.star.comp.Math.FormulaDocument");
392 sal_Bool SmModel::supportsService(const OUString& rServiceName)
394 return cppu::supportsService(this, rServiceName);
397 uno::Sequence< OUString > SmModel::getSupportedServiceNames()
399 return uno::Sequence<OUString>{
400 "com.sun.star.document.OfficeDocument",
401 "com.sun.star.formula.FormulaProperties"
405 void SmModel::_setPropertyValues(const PropertyMapEntry** ppEntries, const Any* pValues)
407 SolarMutexGuard aGuard;
409 SmDocShell *pDocSh = static_cast < SmDocShell * > (GetObjectShell());
411 if ( nullptr == pDocSh )
412 throw UnknownPropertyException();
414 SmFormat aFormat = pDocSh->GetFormat();
416 for (; *ppEntries; ppEntries++, pValues++ )
418 if ((*ppEntries)->mnAttributes & PropertyAttribute::READONLY)
419 throw PropertyVetoException();
421 switch ( (*ppEntries)->mnHandle )
423 case HANDLE_FORMULA:
425 OUString aText;
426 *pValues >>= aText;
427 pDocSh->SetText(aText);
429 break;
430 case HANDLE_FONT_NAME_VARIABLES :
431 case HANDLE_FONT_NAME_FUNCTIONS :
432 case HANDLE_FONT_NAME_NUMBERS :
433 case HANDLE_FONT_NAME_TEXT :
434 case HANDLE_CUSTOM_FONT_NAME_SERIF :
435 case HANDLE_CUSTOM_FONT_NAME_SANS :
436 case HANDLE_CUSTOM_FONT_NAME_FIXED :
438 OUString sFontName;
439 *pValues >>= sFontName;
440 if(sFontName.isEmpty())
441 throw IllegalArgumentException();
443 if(aFormat.GetFont((*ppEntries)->mnMemberId).GetFamilyName() != sFontName)
445 const SmFace rOld = aFormat.GetFont((*ppEntries)->mnMemberId);
447 SmFace aSet( sFontName, rOld.GetFontSize() );
448 aSet.SetBorderWidth( rOld.GetBorderWidth() );
449 aSet.SetAlignment( ALIGN_BASELINE );
450 aFormat.SetFont( (*ppEntries)->mnMemberId, aSet );
453 break;
454 case HANDLE_CUSTOM_FONT_FIXED_POSTURE:
455 case HANDLE_CUSTOM_FONT_SANS_POSTURE :
456 case HANDLE_CUSTOM_FONT_SERIF_POSTURE:
457 case HANDLE_FONT_VARIABLES_POSTURE :
458 case HANDLE_FONT_FUNCTIONS_POSTURE :
459 case HANDLE_FONT_NUMBERS_POSTURE :
460 case HANDLE_FONT_TEXT_POSTURE :
462 auto bVal = o3tl::tryAccess<bool>(*pValues);
463 if(!bVal)
464 throw IllegalArgumentException();
465 vcl::Font aNewFont(aFormat.GetFont((*ppEntries)->mnMemberId));
466 aNewFont.SetItalic(*bVal ? ITALIC_NORMAL : ITALIC_NONE);
467 aFormat.SetFont((*ppEntries)->mnMemberId, aNewFont);
469 break;
470 case HANDLE_CUSTOM_FONT_FIXED_WEIGHT :
471 case HANDLE_CUSTOM_FONT_SANS_WEIGHT :
472 case HANDLE_CUSTOM_FONT_SERIF_WEIGHT :
473 case HANDLE_FONT_VARIABLES_WEIGHT :
474 case HANDLE_FONT_FUNCTIONS_WEIGHT :
475 case HANDLE_FONT_NUMBERS_WEIGHT :
476 case HANDLE_FONT_TEXT_WEIGHT :
478 auto bVal = o3tl::tryAccess<bool>(*pValues);
479 if(!bVal)
480 throw IllegalArgumentException();
481 vcl::Font aNewFont(aFormat.GetFont((*ppEntries)->mnMemberId));
482 aNewFont.SetWeight(*bVal ? WEIGHT_BOLD : WEIGHT_NORMAL);
483 aFormat.SetFont((*ppEntries)->mnMemberId, aNewFont);
485 break;
486 case HANDLE_BASE_FONT_HEIGHT :
488 // Point!
489 sal_Int16 nVal = lcl_AnyToINT16(*pValues);
490 if(nVal < 1)
491 throw IllegalArgumentException();
492 Size aSize = aFormat.GetBaseSize();
493 aSize.setHeight( SmPtsTo100th_mm(nVal) );
494 aFormat.SetBaseSize(aSize);
496 // apply base size to fonts
497 const Size aTmp( aFormat.GetBaseSize() );
498 for (sal_uInt16 i = FNT_BEGIN; i <= FNT_END; i++)
499 aFormat.SetFontSize(i, aTmp);
501 break;
502 case HANDLE_RELATIVE_FONT_HEIGHT_TEXT :
503 case HANDLE_RELATIVE_FONT_HEIGHT_INDICES :
504 case HANDLE_RELATIVE_FONT_HEIGHT_FUNCTIONS :
505 case HANDLE_RELATIVE_FONT_HEIGHT_OPERATORS :
506 case HANDLE_RELATIVE_FONT_HEIGHT_LIMITS :
508 sal_Int16 nVal = 0;
509 *pValues >>= nVal;
510 if(nVal < 1)
511 throw IllegalArgumentException();
512 aFormat.SetRelSize((*ppEntries)->mnMemberId, nVal);
514 break;
516 case HANDLE_IS_TEXT_MODE :
518 aFormat.SetTextmode(*o3tl::doAccess<bool>(*pValues));
520 break;
522 case HANDLE_GREEK_CHAR_STYLE :
524 sal_Int16 nVal = 0;
525 *pValues >>= nVal;
526 if (nVal < 0 || nVal > 2)
527 throw IllegalArgumentException();
528 aFormat.SetGreekCharStyle( nVal );
530 break;
532 case HANDLE_ALIGNMENT :
534 // SmHorAlign uses the same values as HorizontalAlignment
535 sal_Int16 nVal = 0;
536 *pValues >>= nVal;
537 if(nVal < 0 || nVal > 2)
538 throw IllegalArgumentException();
539 aFormat.SetHorAlign(static_cast<SmHorAlign>(nVal));
541 break;
543 case HANDLE_RELATIVE_SPACING :
544 case HANDLE_RELATIVE_LINE_SPACING :
545 case HANDLE_RELATIVE_ROOT_SPACING :
546 case HANDLE_RELATIVE_INDEX_SUPERSCRIPT :
547 case HANDLE_RELATIVE_INDEX_SUBSCRIPT :
548 case HANDLE_RELATIVE_FRACTION_NUMERATOR_HEIGHT :
549 case HANDLE_RELATIVE_FRACTION_DENOMINATOR_DEPTH:
550 case HANDLE_RELATIVE_FRACTION_BAR_EXCESS_LENGTH:
551 case HANDLE_RELATIVE_FRACTION_BAR_LINE_WEIGHT :
552 case HANDLE_RELATIVE_UPPER_LIMIT_DISTANCE :
553 case HANDLE_RELATIVE_LOWER_LIMIT_DISTANCE :
554 case HANDLE_RELATIVE_BRACKET_EXCESS_SIZE :
555 case HANDLE_RELATIVE_BRACKET_DISTANCE :
556 case HANDLE_RELATIVE_SCALE_BRACKET_EXCESS_SIZE :
557 case HANDLE_RELATIVE_MATRIX_LINE_SPACING :
558 case HANDLE_RELATIVE_MATRIX_COLUMN_SPACING :
559 case HANDLE_RELATIVE_SYMBOL_PRIMARY_HEIGHT :
560 case HANDLE_RELATIVE_SYMBOL_MINIMUM_HEIGHT :
561 case HANDLE_RELATIVE_OPERATOR_EXCESS_SIZE :
562 case HANDLE_RELATIVE_OPERATOR_SPACING :
563 case HANDLE_LEFT_MARGIN :
564 case HANDLE_RIGHT_MARGIN :
565 case HANDLE_TOP_MARGIN :
566 case HANDLE_BOTTOM_MARGIN :
568 sal_Int16 nVal = 0;
569 *pValues >>= nVal;
570 if(nVal < 0)
571 throw IllegalArgumentException();
572 aFormat.SetDistance((*ppEntries)->mnMemberId, nVal);
574 break;
575 case HANDLE_IS_SCALE_ALL_BRACKETS :
576 aFormat.SetScaleNormalBrackets(*o3tl::doAccess<bool>(*pValues));
577 break;
578 case HANDLE_PRINTER_NAME:
580 // embedded documents just ignore this property for now
581 if ( pDocSh->GetCreateMode() != SfxObjectCreateMode::EMBEDDED )
583 SfxPrinter *pPrinter = pDocSh->GetPrinter ( );
584 if (pPrinter)
586 OUString sPrinterName;
587 if ( !(*pValues >>= sPrinterName) )
588 throw IllegalArgumentException();
590 if ( !sPrinterName.isEmpty() )
592 VclPtrInstance<SfxPrinter> pNewPrinter( pPrinter->GetOptions().Clone(), sPrinterName );
593 if (pNewPrinter->IsKnown())
594 pDocSh->SetPrinter ( pNewPrinter );
595 else
596 pNewPrinter.disposeAndClear();
601 break;
602 case HANDLE_PRINTER_SETUP:
604 Sequence < sal_Int8 > aSequence;
605 if ( !(*pValues >>= aSequence) )
606 throw IllegalArgumentException();
608 sal_uInt32 nSize = aSequence.getLength();
609 SvMemoryStream aStream ( aSequence.getArray(), nSize, StreamMode::READ );
610 aStream.Seek ( STREAM_SEEK_TO_BEGIN );
611 static sal_uInt16 const nRange[] =
613 SID_PRINTSIZE, SID_PRINTSIZE,
614 SID_PRINTZOOM, SID_PRINTZOOM,
615 SID_PRINTTITLE, SID_PRINTTITLE,
616 SID_PRINTTEXT, SID_PRINTTEXT,
617 SID_PRINTFRAME, SID_PRINTFRAME,
618 SID_NO_RIGHT_SPACES, SID_NO_RIGHT_SPACES,
619 SID_SAVE_ONLY_USED_SYMBOLS, SID_SAVE_ONLY_USED_SYMBOLS,
620 SID_AUTO_CLOSE_BRACKETS, SID_AUTO_CLOSE_BRACKETS,
623 auto pItemSet = o3tl::make_unique<SfxItemSet>( SmDocShell::GetPool(), nRange );
624 SmModule *pp = SM_MOD();
625 pp->GetConfig()->ConfigToItemSet(*pItemSet);
626 VclPtr<SfxPrinter> pPrinter = SfxPrinter::Create ( aStream, std::move(pItemSet) );
628 pDocSh->SetPrinter( pPrinter );
630 break;
631 case HANDLE_SYMBOLS:
633 // this is set
634 Sequence < SymbolDescriptor > aSequence;
635 if ( !(*pValues >>= aSequence) )
636 throw IllegalArgumentException();
638 sal_uInt32 nSize = aSequence.getLength();
639 SmModule *pp = SM_MOD();
640 SmSymbolManager &rManager = pp->GetSymbolManager();
641 SymbolDescriptor *pDescriptor = aSequence.getArray();
642 for (sal_uInt32 i = 0; i < nSize ; i++, pDescriptor++)
644 vcl::Font aFont;
645 aFont.SetFamilyName ( pDescriptor->sFontName );
646 aFont.SetCharSet ( static_cast < rtl_TextEncoding > (pDescriptor->nCharSet) );
647 aFont.SetFamily ( static_cast < FontFamily > (pDescriptor->nFamily ) );
648 aFont.SetPitch ( static_cast < FontPitch > (pDescriptor->nPitch ) );
649 aFont.SetWeight ( static_cast < FontWeight > (pDescriptor->nWeight ) );
650 aFont.SetItalic ( static_cast < FontItalic > (pDescriptor->nItalic ) );
651 SmSym aSymbol ( pDescriptor->sName, aFont, static_cast < sal_Unicode > (pDescriptor->nCharacter),
652 pDescriptor->sSymbolSet );
653 aSymbol.SetExportName ( pDescriptor->sExportName );
654 rManager.AddOrReplaceSymbol ( aSymbol );
657 break;
658 // #i33095# Security Options
659 case HANDLE_LOAD_READONLY :
661 if ( (*pValues).getValueType() != cppu::UnoType<bool>::get() )
662 throw IllegalArgumentException();
663 bool bReadonly = false;
664 if ( *pValues >>= bReadonly )
665 pDocSh->SetLoadReadonly( bReadonly );
666 break;
668 case HANDLE_INTEROP_GRAB_BAG:
669 setGrabBagItem(*pValues);
670 break;
674 pDocSh->SetFormat( aFormat );
676 // #i67283# since about all of the above changes are likely to change
677 // the formula size we have to recalculate the vis-area now
678 pDocSh->SetVisArea( tools::Rectangle( Point(0, 0), pDocSh->GetSize() ) );
681 void SmModel::_getPropertyValues( const PropertyMapEntry **ppEntries, Any *pValue )
683 SmDocShell *pDocSh = static_cast < SmDocShell * > (GetObjectShell());
685 if ( nullptr == pDocSh )
686 throw UnknownPropertyException();
688 const SmFormat & aFormat = pDocSh->GetFormat();
690 for (; *ppEntries; ppEntries++, pValue++ )
692 switch ( (*ppEntries)->mnHandle )
694 case HANDLE_FORMULA:
695 *pValue <<= pDocSh->GetText();
696 break;
697 case HANDLE_FONT_NAME_VARIABLES :
698 case HANDLE_FONT_NAME_FUNCTIONS :
699 case HANDLE_FONT_NAME_NUMBERS :
700 case HANDLE_FONT_NAME_TEXT :
701 case HANDLE_CUSTOM_FONT_NAME_SERIF :
702 case HANDLE_CUSTOM_FONT_NAME_SANS :
703 case HANDLE_CUSTOM_FONT_NAME_FIXED :
705 const SmFace & rFace = aFormat.GetFont((*ppEntries)->mnMemberId);
706 *pValue <<= rFace.GetFamilyName();
708 break;
709 case HANDLE_CUSTOM_FONT_FIXED_POSTURE:
710 case HANDLE_CUSTOM_FONT_SANS_POSTURE :
711 case HANDLE_CUSTOM_FONT_SERIF_POSTURE:
712 case HANDLE_FONT_VARIABLES_POSTURE :
713 case HANDLE_FONT_FUNCTIONS_POSTURE :
714 case HANDLE_FONT_NUMBERS_POSTURE :
715 case HANDLE_FONT_TEXT_POSTURE :
717 const SmFace & rFace = aFormat.GetFont((*ppEntries)->mnMemberId);
718 *pValue <<= IsItalic( rFace );
720 break;
721 case HANDLE_CUSTOM_FONT_FIXED_WEIGHT :
722 case HANDLE_CUSTOM_FONT_SANS_WEIGHT :
723 case HANDLE_CUSTOM_FONT_SERIF_WEIGHT :
724 case HANDLE_FONT_VARIABLES_WEIGHT :
725 case HANDLE_FONT_FUNCTIONS_WEIGHT :
726 case HANDLE_FONT_NUMBERS_WEIGHT :
727 case HANDLE_FONT_TEXT_WEIGHT :
729 const SmFace & rFace = aFormat.GetFont((*ppEntries)->mnMemberId);
730 *pValue <<= IsBold( rFace );
732 break;
733 case HANDLE_BASE_FONT_HEIGHT :
735 // Point!
736 *pValue <<= sal_Int16(
737 SmRoundFraction(
738 Sm100th_mmToPts(aFormat.GetBaseSize().Height())));
740 break;
741 case HANDLE_RELATIVE_FONT_HEIGHT_TEXT :
742 case HANDLE_RELATIVE_FONT_HEIGHT_INDICES :
743 case HANDLE_RELATIVE_FONT_HEIGHT_FUNCTIONS :
744 case HANDLE_RELATIVE_FONT_HEIGHT_OPERATORS :
745 case HANDLE_RELATIVE_FONT_HEIGHT_LIMITS :
746 *pValue <<= static_cast<sal_Int16>(aFormat.GetRelSize((*ppEntries)->mnMemberId));
747 break;
749 case HANDLE_IS_TEXT_MODE :
750 *pValue <<= aFormat.IsTextmode();
751 break;
753 case HANDLE_GREEK_CHAR_STYLE :
754 *pValue <<= aFormat.GetGreekCharStyle();
755 break;
757 case HANDLE_ALIGNMENT :
758 // SmHorAlign uses the same values as HorizontalAlignment
759 *pValue <<= static_cast<sal_Int16>(aFormat.GetHorAlign());
760 break;
762 case HANDLE_RELATIVE_SPACING :
763 case HANDLE_RELATIVE_LINE_SPACING :
764 case HANDLE_RELATIVE_ROOT_SPACING :
765 case HANDLE_RELATIVE_INDEX_SUPERSCRIPT :
766 case HANDLE_RELATIVE_INDEX_SUBSCRIPT :
767 case HANDLE_RELATIVE_FRACTION_NUMERATOR_HEIGHT :
768 case HANDLE_RELATIVE_FRACTION_DENOMINATOR_DEPTH:
769 case HANDLE_RELATIVE_FRACTION_BAR_EXCESS_LENGTH:
770 case HANDLE_RELATIVE_FRACTION_BAR_LINE_WEIGHT :
771 case HANDLE_RELATIVE_UPPER_LIMIT_DISTANCE :
772 case HANDLE_RELATIVE_LOWER_LIMIT_DISTANCE :
773 case HANDLE_RELATIVE_BRACKET_EXCESS_SIZE :
774 case HANDLE_RELATIVE_BRACKET_DISTANCE :
775 case HANDLE_RELATIVE_SCALE_BRACKET_EXCESS_SIZE :
776 case HANDLE_RELATIVE_MATRIX_LINE_SPACING :
777 case HANDLE_RELATIVE_MATRIX_COLUMN_SPACING :
778 case HANDLE_RELATIVE_SYMBOL_PRIMARY_HEIGHT :
779 case HANDLE_RELATIVE_SYMBOL_MINIMUM_HEIGHT :
780 case HANDLE_RELATIVE_OPERATOR_EXCESS_SIZE :
781 case HANDLE_RELATIVE_OPERATOR_SPACING :
782 case HANDLE_LEFT_MARGIN :
783 case HANDLE_RIGHT_MARGIN :
784 case HANDLE_TOP_MARGIN :
785 case HANDLE_BOTTOM_MARGIN :
786 *pValue <<= static_cast<sal_Int16>(aFormat.GetDistance((*ppEntries)->mnMemberId));
787 break;
788 case HANDLE_IS_SCALE_ALL_BRACKETS :
789 *pValue <<= aFormat.IsScaleNormalBrackets();
790 break;
791 case HANDLE_PRINTER_NAME:
793 SfxPrinter *pPrinter = pDocSh->GetPrinter ( );
794 *pValue <<= pPrinter ? pPrinter->GetName() : OUString();
796 break;
797 case HANDLE_PRINTER_SETUP:
799 SfxPrinter *pPrinter = pDocSh->GetPrinter ();
800 if (pPrinter)
802 SvMemoryStream aStream;
803 pPrinter->Store( aStream );
804 aStream.Seek ( STREAM_SEEK_TO_END );
805 sal_uInt32 nSize = aStream.Tell();
806 aStream.Seek ( STREAM_SEEK_TO_BEGIN );
807 Sequence < sal_Int8 > aSequence ( nSize );
808 aStream.ReadBytes(aSequence.getArray(), nSize);
809 *pValue <<= aSequence;
812 break;
813 case HANDLE_SYMBOLS:
814 case HANDLE_USED_SYMBOLS:
816 const bool bUsedSymbolsOnly = (*ppEntries)->mnHandle == HANDLE_USED_SYMBOLS;
817 const std::set< OUString > &rUsedSymbols = pDocSh->GetUsedSymbols();
819 // this is get
820 SmModule *pp = SM_MOD();
821 const SmSymbolManager &rManager = pp->GetSymbolManager();
822 vector < const SmSym * > aVector;
824 const SymbolPtrVec_t aSymbols( rManager.GetSymbols() );
825 for (const SmSym* pSymbol : aSymbols)
827 if (pSymbol && !pSymbol->IsPredefined() &&
828 (!bUsedSymbolsOnly ||
829 rUsedSymbols.find( pSymbol->GetName() ) != rUsedSymbols.end()))
830 aVector.push_back ( pSymbol );
832 Sequence < SymbolDescriptor > aSequence ( aVector.size() );
833 SymbolDescriptor * pDescriptor = aSequence.getArray();
835 vector < const SmSym * >::const_iterator aIter = aVector.begin(), aEnd = aVector.end();
836 for(; aIter != aEnd; pDescriptor++, ++aIter)
838 pDescriptor->sName = (*aIter)->GetName();
839 pDescriptor->sExportName = (*aIter)->GetExportName();
840 pDescriptor->sSymbolSet = (*aIter)->GetSymbolSetName();
841 pDescriptor->nCharacter = static_cast < sal_Int32 > ((*aIter)->GetCharacter());
843 vcl::Font rFont = (*aIter)->GetFace();
844 pDescriptor->sFontName = rFont.GetFamilyName();
845 pDescriptor->nCharSet = sal::static_int_cast< sal_Int16 >(rFont.GetCharSet());
846 pDescriptor->nFamily = sal::static_int_cast< sal_Int16 >(rFont.GetFamilyType());
847 pDescriptor->nPitch = sal::static_int_cast< sal_Int16 >(rFont.GetPitch());
848 pDescriptor->nWeight = sal::static_int_cast< sal_Int16 >(rFont.GetWeight());
849 pDescriptor->nItalic = sal::static_int_cast< sal_Int16 >(rFont.GetItalic());
851 *pValue <<= aSequence;
853 break;
854 case HANDLE_BASIC_LIBRARIES:
855 *pValue <<= pDocSh->GetBasicContainer();
856 break;
857 case HANDLE_DIALOG_LIBRARIES:
858 *pValue <<= pDocSh->GetDialogContainer();
859 break;
860 case HANDLE_RUNTIME_UID:
861 *pValue <<= getRuntimeUID();
862 break;
863 // #i33095# Security Options
864 case HANDLE_LOAD_READONLY :
866 *pValue <<= pDocSh->IsLoadReadonly();
867 break;
869 // #i972#
870 case HANDLE_BASELINE:
872 if ( !pDocSh->GetFormulaTree() )
873 pDocSh->Parse();
874 if ( pDocSh->GetFormulaTree() )
876 pDocSh->ArrangeFormula();
878 *pValue <<= static_cast<sal_Int32>( pDocSh->GetFormulaTree()->GetFormulaBaseline() );
880 break;
882 case HANDLE_INTEROP_GRAB_BAG:
883 getGrabBagItem(*pValue);
884 break;
890 sal_Int32 SAL_CALL SmModel::getRendererCount(
891 const uno::Any& /*rSelection*/,
892 const uno::Sequence< beans::PropertyValue >& /*xOptions*/ )
894 return 1;
898 static Size lcl_GuessPaperSize()
900 Size aRes;
901 const LocaleDataWrapper& rLocWrp( AllSettings().GetLocaleDataWrapper() );
902 if( MeasurementSystem::Metric == rLocWrp.getMeasurementSystemEnum() )
904 // in 100th mm
905 PaperInfo aInfo( PAPER_A4 );
906 aRes.setWidth( aInfo.getWidth() );
907 aRes.setHeight( aInfo.getHeight() );
909 else
911 // in 100th mm
912 PaperInfo aInfo( PAPER_LETTER );
913 aRes.setWidth( aInfo.getWidth() );
914 aRes.setHeight( aInfo.getHeight() );
916 return aRes;
919 uno::Sequence< beans::PropertyValue > SAL_CALL SmModel::getRenderer(
920 sal_Int32 nRenderer,
921 const uno::Any& /*rSelection*/,
922 const uno::Sequence< beans::PropertyValue >& /*rxOptions*/ )
924 SolarMutexGuard aGuard;
926 if (0 != nRenderer)
927 throw IllegalArgumentException();
929 SmDocShell *pDocSh = static_cast < SmDocShell * >( GetObjectShell() );
930 if (!pDocSh)
931 throw RuntimeException();
933 SmPrinterAccess aPrinterAccess( *pDocSh );
934 Printer *pPrinter = aPrinterAccess.GetPrinter();
935 Size aPrtPaperSize ( pPrinter->GetPaperSize() );
937 // if paper size is 0 (usually if no 'real' printer is found),
938 // guess the paper size
939 if (aPrtPaperSize.Height() == 0 || aPrtPaperSize.Width() == 0)
940 aPrtPaperSize = lcl_GuessPaperSize();
941 awt::Size aPageSize( aPrtPaperSize.Width(), aPrtPaperSize.Height() );
943 uno::Sequence< beans::PropertyValue > aRenderer(1);
944 PropertyValue &rValue = aRenderer.getArray()[0];
945 rValue.Name = "PageSize";
946 rValue.Value <<= aPageSize;
948 if (!m_pPrintUIOptions)
949 m_pPrintUIOptions.reset(new SmPrintUIOptions);
950 m_pPrintUIOptions->appendPrintUIOptions( aRenderer );
952 return aRenderer;
955 void SAL_CALL SmModel::render(
956 sal_Int32 nRenderer,
957 const uno::Any& rSelection,
958 const uno::Sequence< beans::PropertyValue >& rxOptions )
960 SolarMutexGuard aGuard;
962 if (0 != nRenderer)
963 throw IllegalArgumentException();
965 SmDocShell *pDocSh = static_cast < SmDocShell * >( GetObjectShell() );
966 if (!pDocSh)
967 throw RuntimeException();
969 // get device to be rendered in
970 uno::Reference< awt::XDevice > xRenderDevice;
971 for (sal_Int32 i = 0, nCount = rxOptions.getLength(); i < nCount; ++i)
973 if( rxOptions[i].Name == "RenderDevice" )
974 rxOptions[i].Value >>= xRenderDevice;
977 if (xRenderDevice.is())
979 VCLXDevice* pDevice = VCLXDevice::GetImplementation( xRenderDevice );
980 VclPtr< OutputDevice> pOut = pDevice ? pDevice->GetOutputDevice()
981 : VclPtr< OutputDevice >();
982 if (!pOut)
983 throw RuntimeException();
985 pOut->SetMapMode(MapMode(MapUnit::Map100thMM));
987 uno::Reference< frame::XModel > xModel;
988 rSelection >>= xModel;
989 if (xModel == pDocSh->GetModel())
991 //!! when called via API we may not have an active view
992 //!! thus we go and look for a view that can be used.
993 SfxViewShell* pViewSh = SfxViewShell::GetFirst( false /* search non-visible views as well*/, checkSfxViewShell<SmViewShell> );
994 while (pViewSh && pViewSh->GetObjectShell() != pDocSh)
995 pViewSh = SfxViewShell::GetNext( *pViewSh, false /* search non-visible views as well*/, checkSfxViewShell<SmViewShell> );
996 SmViewShell *pView = dynamic_cast< SmViewShell *>( pViewSh );
997 SAL_WARN_IF( !pView, "starmath", "SmModel::render : no SmViewShell found" );
999 if (pView)
1001 SmPrinterAccess aPrinterAccess( *pDocSh );
1002 Printer *pPrinter = aPrinterAccess.GetPrinter();
1004 Size aPrtPaperSize ( pPrinter->GetPaperSize() );
1005 Size aOutputSize ( pPrinter->GetOutputSize() );
1006 Point aPrtPageOffset( pPrinter->GetPageOffset() );
1008 // no real printer ??
1009 if (aPrtPaperSize.Height() == 0 || aPrtPaperSize.Width() == 0)
1011 aPrtPaperSize = lcl_GuessPaperSize();
1012 // factors from Windows DIN A4
1013 aOutputSize = Size( static_cast<long>(aPrtPaperSize.Width() * 0.941),
1014 static_cast<long>(aPrtPaperSize.Height() * 0.961));
1015 aPrtPageOffset = Point( static_cast<long>(aPrtPaperSize.Width() * 0.0250),
1016 static_cast<long>(aPrtPaperSize.Height() * 0.0214));
1018 tools::Rectangle OutputRect( Point(), aOutputSize );
1021 // set minimum top and bottom border
1022 if (aPrtPageOffset.Y() < 2000)
1023 OutputRect.AdjustTop(2000 - aPrtPageOffset.Y() );
1024 if ((aPrtPaperSize.Height() - (aPrtPageOffset.Y() + OutputRect.Bottom())) < 2000)
1025 OutputRect.AdjustBottom( -(2000 - (aPrtPaperSize.Height() -
1026 (aPrtPageOffset.Y() + OutputRect.Bottom()))) );
1028 // set minimum left and right border
1029 if (aPrtPageOffset.X() < 2500)
1030 OutputRect.AdjustLeft(2500 - aPrtPageOffset.X() );
1031 if ((aPrtPaperSize.Width() - (aPrtPageOffset.X() + OutputRect.Right())) < 1500)
1032 OutputRect.AdjustRight( -(1500 - (aPrtPaperSize.Width() -
1033 (aPrtPageOffset.X() + OutputRect.Right()))) );
1035 if (!m_pPrintUIOptions)
1036 m_pPrintUIOptions.reset(new SmPrintUIOptions);
1037 m_pPrintUIOptions->processProperties( rxOptions );
1039 pView->Impl_Print( *pOut, *m_pPrintUIOptions, OutputRect );
1041 // release SmPrintUIOptions when everything is done.
1042 // That way, when SmPrintUIOptions is needed again it will read the latest configuration settings in its c-tor.
1043 if (m_pPrintUIOptions->getBoolValue( "IsLastPage" ))
1045 m_pPrintUIOptions.reset();
1052 void SAL_CALL SmModel::setParent( const uno::Reference< uno::XInterface >& xParent)
1054 SolarMutexGuard aGuard;
1055 SfxBaseModel::setParent( xParent );
1056 uno::Reference< lang::XUnoTunnel > xParentTunnel( xParent, uno::UNO_QUERY );
1057 if ( xParentTunnel.is() )
1059 SvGlobalName aSfxIdent( SFX_GLOBAL_CLASSID );
1060 SfxObjectShell* pDoc = reinterpret_cast<SfxObjectShell *>(xParentTunnel->getSomething(
1061 aSfxIdent.GetByteSequence() ) );
1062 if ( pDoc )
1063 GetObjectShell()->OnDocumentPrinterChanged( pDoc->GetDocumentPrinter() );
1067 void SmModel::writeFormulaOoxml(
1068 ::sax_fastparser::FSHelperPtr const pSerializer,
1069 oox::core::OoxmlVersion const version,
1070 oox::drawingml::DocumentType const documentType)
1072 static_cast<SmDocShell*>(GetObjectShell())->writeFormulaOoxml(pSerializer, version, documentType);
1075 void SmModel::writeFormulaRtf(OStringBuffer& rBuffer, rtl_TextEncoding nEncoding)
1077 static_cast<SmDocShell*>(GetObjectShell())->writeFormulaRtf(rBuffer, nEncoding);
1080 void SmModel::readFormulaOoxml( oox::formulaimport::XmlStream& stream )
1082 static_cast< SmDocShell* >( GetObjectShell())->readFormulaOoxml( stream );
1085 Size SmModel::getFormulaSize() const
1087 return static_cast< SmDocShell* >( GetObjectShell())->GetSize();
1090 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */