Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / starmath / source / unomodel.cxx
blobad21f46a002c34bd1e7aafc18b95e70ef3cc76da
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>
21 #include <sal/log.hxx>
23 #include <utility>
25 #include <o3tl/any.hxx>
26 #include <sfx2/printer.hxx>
27 #include <svl/itemprop.hxx>
28 #include <svl/itemset.hxx>
29 #include <vcl/svapp.hxx>
30 #include <unotools/localedatawrapper.hxx>
31 #include <vcl/settings.hxx>
32 #include <vcl/print.hxx>
33 #include <toolkit/awt/vclxdevice.hxx>
34 #include <com/sun/star/beans/PropertyAttribute.hpp>
35 #include <com/sun/star/formula/SymbolDescriptor.hpp>
36 #include <com/sun/star/awt/Size.hpp>
37 #include <comphelper/propertysetinfo.hxx>
38 #include <comphelper/sequence.hxx>
39 #include <comphelper/servicehelper.hxx>
40 #include <cppuhelper/queryinterface.hxx>
41 #include <cppuhelper/supportsservice.hxx>
42 #include <unotools/moduleoptions.hxx>
43 #include <tools/mapunit.hxx>
44 #include <tools/stream.hxx>
46 #include <unomodel.hxx>
47 #include <document.hxx>
48 #include <view.hxx>
49 #include <symbol.hxx>
50 #include <starmath.hrc>
51 #include <strings.hrc>
52 #include <smmod.hxx>
53 #include "cfgitem.hxx"
55 using namespace ::cppu;
56 using namespace ::std;
57 using namespace ::comphelper;
58 using namespace ::com::sun::star;
59 using namespace ::com::sun::star::uno;
60 using namespace ::com::sun::star::beans;
61 using namespace ::com::sun::star::lang;
62 using namespace ::com::sun::star::formula;
63 using namespace ::com::sun::star::view;
64 using namespace ::com::sun::star::script;
66 SmPrintUIOptions::SmPrintUIOptions()
68 SmModule *pp = SM_MOD();
69 SmMathConfig *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.resize( 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 SmResId( RID_PRINTUIOPT_PRODNAME ).
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", SmResId( RID_PRINTUIOPT_CONTENTS ), OUString());
94 // create a bool option for title row (matches to SID_PRINTTITLE)
95 m_aUIProperties[nIdx++].Value = setBoolControlOpt("title", SmResId( RID_PRINTUIOPT_TITLE ),
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", SmResId( RID_PRINTUIOPT_FRMLTXT ),
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", SmResId( RID_PRINTUIOPT_BORDERS ),
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", SmResId( RID_PRINTUIOPT_SIZE ), OUString());
113 // create a radio button group for print format (matches to SID_PRINTSIZE)
114 Sequence< OUString > aChoices{
115 SmResId( RID_PRINTUIOPT_ORIGSIZE ),
116 SmResId( RID_PRINTUIOPT_FITTOPAGE ),
117 SmResId( RID_PRINTUIOPT_SCALING )
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 <<= true;
149 m_aUIProperties[nIdx++].Value <<= aHintNoLayoutPage;
151 assert(nIdx == nNumProps);
155 // class SmModel
157 enum SmModelPropertyHandles
159 HANDLE_FORMULA,
160 HANDLE_FONT_NAME_VARIABLES,
161 HANDLE_FONT_NAME_FUNCTIONS,
162 HANDLE_FONT_NAME_NUMBERS,
163 HANDLE_FONT_NAME_TEXT,
164 HANDLE_CUSTOM_FONT_NAME_SERIF,
165 HANDLE_CUSTOM_FONT_NAME_SANS,
166 HANDLE_CUSTOM_FONT_NAME_FIXED,
167 HANDLE_CUSTOM_FONT_FIXED_POSTURE,
168 HANDLE_CUSTOM_FONT_FIXED_WEIGHT,
169 HANDLE_CUSTOM_FONT_SANS_POSTURE,
170 HANDLE_CUSTOM_FONT_SANS_WEIGHT,
171 HANDLE_CUSTOM_FONT_SERIF_POSTURE,
172 HANDLE_CUSTOM_FONT_SERIF_WEIGHT,
173 HANDLE_FONT_VARIABLES_POSTURE,
174 HANDLE_FONT_VARIABLES_WEIGHT,
175 HANDLE_FONT_FUNCTIONS_POSTURE,
176 HANDLE_FONT_FUNCTIONS_WEIGHT,
177 HANDLE_FONT_NUMBERS_POSTURE,
178 HANDLE_FONT_NUMBERS_WEIGHT,
179 HANDLE_FONT_TEXT_POSTURE,
180 HANDLE_FONT_TEXT_WEIGHT,
181 HANDLE_BASE_FONT_HEIGHT,
182 HANDLE_RELATIVE_FONT_HEIGHT_TEXT,
183 HANDLE_RELATIVE_FONT_HEIGHT_INDICES,
184 HANDLE_RELATIVE_FONT_HEIGHT_FUNCTIONS,
185 HANDLE_RELATIVE_FONT_HEIGHT_OPERATORS,
186 HANDLE_RELATIVE_FONT_HEIGHT_LIMITS,
187 HANDLE_IS_TEXT_MODE,
188 HANDLE_GREEK_CHAR_STYLE,
189 HANDLE_ALIGNMENT,
190 HANDLE_RELATIVE_SPACING,
191 HANDLE_RELATIVE_LINE_SPACING,
192 HANDLE_RELATIVE_ROOT_SPACING,
193 HANDLE_RELATIVE_INDEX_SUPERSCRIPT,
194 HANDLE_RELATIVE_INDEX_SUBSCRIPT,
195 HANDLE_RELATIVE_FRACTION_NUMERATOR_HEIGHT,
196 HANDLE_RELATIVE_FRACTION_DENOMINATOR_DEPTH,
197 HANDLE_RELATIVE_FRACTION_BAR_EXCESS_LENGTH,
198 HANDLE_RELATIVE_FRACTION_BAR_LINE_WEIGHT,
199 HANDLE_RELATIVE_UPPER_LIMIT_DISTANCE,
200 HANDLE_RELATIVE_LOWER_LIMIT_DISTANCE,
201 HANDLE_RELATIVE_BRACKET_EXCESS_SIZE,
202 HANDLE_RELATIVE_BRACKET_DISTANCE,
203 HANDLE_IS_SCALE_ALL_BRACKETS,
204 HANDLE_RELATIVE_SCALE_BRACKET_EXCESS_SIZE,
205 HANDLE_RELATIVE_MATRIX_LINE_SPACING,
206 HANDLE_RELATIVE_MATRIX_COLUMN_SPACING,
207 HANDLE_RELATIVE_SYMBOL_PRIMARY_HEIGHT,
208 HANDLE_RELATIVE_SYMBOL_MINIMUM_HEIGHT,
209 HANDLE_RELATIVE_OPERATOR_EXCESS_SIZE,
210 HANDLE_RELATIVE_OPERATOR_SPACING,
211 HANDLE_LEFT_MARGIN,
212 HANDLE_RIGHT_MARGIN,
213 HANDLE_TOP_MARGIN,
214 HANDLE_BOTTOM_MARGIN,
215 HANDLE_PRINTER_NAME,
216 HANDLE_PRINTER_SETUP,
217 HANDLE_SYMBOLS,
218 HANDLE_SAVE_THUMBNAIL,
219 HANDLE_USED_SYMBOLS,
220 HANDLE_BASIC_LIBRARIES,
221 HANDLE_RUNTIME_UID,
222 HANDLE_LOAD_READONLY, // Security Options
223 HANDLE_DIALOG_LIBRARIES, // #i73329#
224 HANDLE_BASELINE,
225 HANDLE_INTEROP_GRAB_BAG,
228 static rtl::Reference<PropertySetInfo> lcl_createModelPropertyInfo ()
230 static PropertyMapEntry aModelPropertyInfoMap[] =
232 { OUString("Alignment") , HANDLE_ALIGNMENT , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, 0 },
233 { OUString("BaseFontHeight") , HANDLE_BASE_FONT_HEIGHT , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, 0 },
234 { OUString("BasicLibraries") , HANDLE_BASIC_LIBRARIES , cppu::UnoType<script::XLibraryContainer>::get(), PropertyAttribute::READONLY, 0 },
235 { OUString("BottomMargin") , HANDLE_BOTTOM_MARGIN , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_BOTTOMSPACE },
236 { OUString("CustomFontNameFixed") , HANDLE_CUSTOM_FONT_NAME_FIXED , ::cppu::UnoType<OUString>::get(), PROPERTY_NONE, FNT_FIXED },
237 { OUString("CustomFontNameSans") , HANDLE_CUSTOM_FONT_NAME_SANS , ::cppu::UnoType<OUString>::get(), PROPERTY_NONE, FNT_SANS },
238 { OUString("CustomFontNameSerif") , HANDLE_CUSTOM_FONT_NAME_SERIF , ::cppu::UnoType<OUString>::get(), PROPERTY_NONE, FNT_SERIF },
239 { OUString("DialogLibraries") , HANDLE_DIALOG_LIBRARIES , cppu::UnoType<script::XLibraryContainer>::get(), PropertyAttribute::READONLY, 0 },
240 { OUString("FontFixedIsBold") , HANDLE_CUSTOM_FONT_FIXED_WEIGHT , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_FIXED },
241 { OUString("FontFixedIsItalic") , HANDLE_CUSTOM_FONT_FIXED_POSTURE , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_FIXED },
242 { OUString("FontFunctionsIsBold") , HANDLE_FONT_FUNCTIONS_WEIGHT , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_FUNCTION },
243 { OUString("FontFunctionsIsItalic") , HANDLE_FONT_FUNCTIONS_POSTURE , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_FUNCTION },
244 { OUString("FontNameFunctions") , HANDLE_FONT_NAME_FUNCTIONS , ::cppu::UnoType<OUString>::get(), PROPERTY_NONE, FNT_FUNCTION },
245 { OUString("FontNameNumbers") , HANDLE_FONT_NAME_NUMBERS , ::cppu::UnoType<OUString>::get(), PROPERTY_NONE, FNT_NUMBER },
246 { OUString("FontNameText") , HANDLE_FONT_NAME_TEXT , ::cppu::UnoType<OUString>::get(), PROPERTY_NONE, FNT_TEXT },
247 { OUString("FontNameVariables") , HANDLE_FONT_NAME_VARIABLES , ::cppu::UnoType<OUString>::get(), PROPERTY_NONE, FNT_VARIABLE },
248 { OUString("FontNumbersIsBold") , HANDLE_FONT_NUMBERS_WEIGHT , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_NUMBER },
249 { OUString("FontNumbersIsItalic") , HANDLE_FONT_NUMBERS_POSTURE , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_NUMBER },
250 { OUString("FontSansIsBold") , HANDLE_CUSTOM_FONT_SANS_WEIGHT , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_SANS },
251 { OUString("FontSansIsItalic") , HANDLE_CUSTOM_FONT_SANS_POSTURE , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_SANS },
252 { OUString("FontSerifIsBold") , HANDLE_CUSTOM_FONT_SERIF_WEIGHT , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_SERIF },
253 { OUString("FontSerifIsItalic") , HANDLE_CUSTOM_FONT_SERIF_POSTURE , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_SERIF },
254 { OUString("FontTextIsBold") , HANDLE_FONT_TEXT_WEIGHT , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_TEXT },
255 { OUString("FontTextIsItalic") , HANDLE_FONT_TEXT_POSTURE , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_TEXT },
256 { OUString("FontVariablesIsBold") , HANDLE_FONT_VARIABLES_WEIGHT , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_VARIABLE },
257 { OUString("FontVariablesIsItalic") , HANDLE_FONT_VARIABLES_POSTURE , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_VARIABLE },
258 { OUString("Formula") , HANDLE_FORMULA , ::cppu::UnoType<OUString>::get(), PROPERTY_NONE, 0 },
259 { OUString("IsScaleAllBrackets") , HANDLE_IS_SCALE_ALL_BRACKETS , cppu::UnoType<bool>::get(), PROPERTY_NONE, 0 },
260 { OUString("IsTextMode") , HANDLE_IS_TEXT_MODE , cppu::UnoType<bool>::get(), PROPERTY_NONE, 0 },
261 { OUString("GreekCharStyle") , HANDLE_GREEK_CHAR_STYLE , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, 0 },
262 { OUString("LeftMargin") , HANDLE_LEFT_MARGIN , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_LEFTSPACE },
263 { OUString("PrinterName") , HANDLE_PRINTER_NAME , ::cppu::UnoType<OUString>::get(), PROPERTY_NONE, 0 },
264 { OUString("PrinterSetup") , HANDLE_PRINTER_SETUP , cppu::UnoType<const Sequence < sal_Int8 >>::get(), PROPERTY_NONE, 0 },
265 { OUString("RelativeBracketDistance") , HANDLE_RELATIVE_BRACKET_DISTANCE , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_BRACKETSPACE },
266 { OUString("RelativeBracketExcessSize") , HANDLE_RELATIVE_BRACKET_EXCESS_SIZE , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_BRACKETSIZE },
267 { OUString("RelativeFontHeightFunctions") , HANDLE_RELATIVE_FONT_HEIGHT_FUNCTIONS , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, SIZ_FUNCTION },
268 { OUString("RelativeFontHeightIndices") , HANDLE_RELATIVE_FONT_HEIGHT_INDICES , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, SIZ_INDEX },
269 { OUString("RelativeFontHeightLimits") , HANDLE_RELATIVE_FONT_HEIGHT_LIMITS , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, SIZ_LIMITS },
270 { OUString("RelativeFontHeightOperators") , HANDLE_RELATIVE_FONT_HEIGHT_OPERATORS , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, SIZ_OPERATOR },
271 { OUString("RelativeFontHeightText") , HANDLE_RELATIVE_FONT_HEIGHT_TEXT , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, SIZ_TEXT },
272 { OUString("RelativeFractionBarExcessLength") , HANDLE_RELATIVE_FRACTION_BAR_EXCESS_LENGTH, ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_FRACTION },
273 { OUString("RelativeFractionBarLineWeight") , HANDLE_RELATIVE_FRACTION_BAR_LINE_WEIGHT , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_STROKEWIDTH },
274 { OUString("RelativeFractionDenominatorDepth") , HANDLE_RELATIVE_FRACTION_DENOMINATOR_DEPTH, ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_DENOMINATOR },
275 { OUString("RelativeFractionNumeratorHeight") , HANDLE_RELATIVE_FRACTION_NUMERATOR_HEIGHT , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_NUMERATOR },
276 { OUString("RelativeIndexSubscript") , HANDLE_RELATIVE_INDEX_SUBSCRIPT , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_SUBSCRIPT },
277 { OUString("RelativeIndexSuperscript") , HANDLE_RELATIVE_INDEX_SUPERSCRIPT , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_SUPERSCRIPT },
278 { OUString("RelativeLineSpacing") , HANDLE_RELATIVE_LINE_SPACING , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_VERTICAL },
279 { OUString("RelativeLowerLimitDistance") , HANDLE_RELATIVE_LOWER_LIMIT_DISTANCE , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_LOWERLIMIT },
280 { OUString("RelativeMatrixColumnSpacing") , HANDLE_RELATIVE_MATRIX_COLUMN_SPACING , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_MATRIXCOL },
281 { OUString("RelativeMatrixLineSpacing") , HANDLE_RELATIVE_MATRIX_LINE_SPACING , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_MATRIXROW },
282 { OUString("RelativeOperatorExcessSize") , HANDLE_RELATIVE_OPERATOR_EXCESS_SIZE , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_OPERATORSIZE },
283 { OUString("RelativeOperatorSpacing") , HANDLE_RELATIVE_OPERATOR_SPACING , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_OPERATORSPACE },
284 { OUString("RelativeRootSpacing") , HANDLE_RELATIVE_ROOT_SPACING , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_ROOT },
285 { OUString("RelativeScaleBracketExcessSize") , HANDLE_RELATIVE_SCALE_BRACKET_EXCESS_SIZE , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_NORMALBRACKETSIZE },
286 { OUString("RelativeSpacing") , HANDLE_RELATIVE_SPACING , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_HORIZONTAL },
287 { OUString("RelativeSymbolMinimumHeight") , HANDLE_RELATIVE_SYMBOL_MINIMUM_HEIGHT , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_ORNAMENTSPACE },
288 { OUString("RelativeSymbolPrimaryHeight") , HANDLE_RELATIVE_SYMBOL_PRIMARY_HEIGHT , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_ORNAMENTSIZE },
289 { OUString("RelativeUpperLimitDistance") , HANDLE_RELATIVE_UPPER_LIMIT_DISTANCE , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_UPPERLIMIT },
290 { OUString("RightMargin") , HANDLE_RIGHT_MARGIN , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_RIGHTSPACE },
291 { OUString("RuntimeUID") , HANDLE_RUNTIME_UID , cppu::UnoType<OUString>::get(), PropertyAttribute::READONLY, 0 },
292 { OUString("SaveThumbnail") , HANDLE_SAVE_THUMBNAIL , cppu::UnoType<bool>::get(), PROPERTY_NONE, 0 },
293 { OUString("Symbols") , HANDLE_SYMBOLS , cppu::UnoType<Sequence < SymbolDescriptor >>::get(), PROPERTY_NONE, 0 },
294 { OUString("UserDefinedSymbolsInUse") , HANDLE_USED_SYMBOLS , cppu::UnoType<Sequence < SymbolDescriptor >>::get(), PropertyAttribute::READONLY, 0 },
295 { OUString("TopMargin") , HANDLE_TOP_MARGIN , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_TOPSPACE },
296 // #i33095# Security Options
297 { OUString("LoadReadonly") , HANDLE_LOAD_READONLY , cppu::UnoType<bool>::get(), PROPERTY_NONE, 0 },
298 // #i972#
299 { OUString("BaseLine") , HANDLE_BASELINE , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, 0 },
300 { OUString("InteropGrabBag") , HANDLE_INTEROP_GRAB_BAG , cppu::UnoType<uno::Sequence< beans::PropertyValue >>::get(), PROPERTY_NONE, 0 },
301 { OUString(), 0, css::uno::Type(), 0, 0 }
303 return rtl::Reference<PropertySetInfo>( new PropertySetInfo ( aModelPropertyInfoMap ) );
306 SmModel::SmModel( SfxObjectShell *pObjSh )
307 : SfxBaseModel(pObjSh)
308 , PropertySetHelper ( lcl_createModelPropertyInfo () )
312 SmModel::~SmModel() throw ()
316 uno::Any SAL_CALL SmModel::queryInterface( const uno::Type& rType )
318 uno::Any aRet = ::cppu::queryInterface ( rType,
319 // OWeakObject interfaces
320 &dynamic_cast<XInterface&>(static_cast<XUnoTunnel&>(*this)),
321 static_cast< XWeak* > ( this ),
322 // PropertySetHelper interfaces
323 static_cast< XPropertySet* > ( this ),
324 static_cast< XMultiPropertySet* > ( this ),
325 // my own interfaces
326 static_cast< XServiceInfo* > ( this ),
327 static_cast< XRenderable* > ( this ) );
328 if (!aRet.hasValue())
329 aRet = SfxBaseModel::queryInterface ( rType );
330 return aRet;
333 void SAL_CALL SmModel::acquire() throw()
335 OWeakObject::acquire();
338 void SAL_CALL SmModel::release() throw()
340 OWeakObject::release();
343 uno::Sequence< uno::Type > SAL_CALL SmModel::getTypes( )
345 return comphelper::concatSequences(SfxBaseModel::getTypes(),
346 uno::Sequence {
347 cppu::UnoType<XServiceInfo>::get(),
348 cppu::UnoType<XPropertySet>::get(),
349 cppu::UnoType<XMultiPropertySet>::get(),
350 cppu::UnoType<XRenderable>::get() });
353 namespace
355 class theSmModelUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSmModelUnoTunnelId> {};
358 const uno::Sequence< sal_Int8 > & SmModel::getUnoTunnelId()
360 return theSmModelUnoTunnelId::get().getSeq();
363 sal_Int64 SAL_CALL SmModel::getSomething( const uno::Sequence< sal_Int8 >& rId )
365 if( isUnoTunnelId<SmModel>(rId) )
367 return sal::static_int_cast< sal_Int64 >(reinterpret_cast< sal_uIntPtr >(this));
370 return SfxBaseModel::getSomething( rId );
373 static sal_Int16 lcl_AnyToINT16(const uno::Any& rAny)
375 sal_Int16 nRet = 0;
376 if( auto x = o3tl::tryAccess<double>(rAny) )
377 nRet = static_cast<sal_Int16>(*x);
378 else
379 rAny >>= nRet;
380 return nRet;
383 OUString SmModel::getImplementationName()
385 return "com.sun.star.comp.Math.FormulaDocument";
388 sal_Bool SmModel::supportsService(const OUString& rServiceName)
390 return cppu::supportsService(this, rServiceName);
393 uno::Sequence< OUString > SmModel::getSupportedServiceNames()
395 return uno::Sequence<OUString>{
396 "com.sun.star.document.OfficeDocument",
397 "com.sun.star.formula.FormulaProperties"
401 void SmModel::_setPropertyValues(const PropertyMapEntry** ppEntries, const Any* pValues)
403 SolarMutexGuard aGuard;
405 SmDocShell *pDocSh = static_cast < SmDocShell * > (GetObjectShell());
407 if ( nullptr == pDocSh )
408 throw UnknownPropertyException();
410 SmFormat aFormat = pDocSh->GetFormat();
412 for (; *ppEntries; ppEntries++, pValues++ )
414 if ((*ppEntries)->mnAttributes & PropertyAttribute::READONLY)
415 throw PropertyVetoException();
417 switch ( (*ppEntries)->mnHandle )
419 case HANDLE_FORMULA:
421 OUString aText;
422 *pValues >>= aText;
423 pDocSh->SetText(aText);
425 break;
426 case HANDLE_FONT_NAME_VARIABLES :
427 case HANDLE_FONT_NAME_FUNCTIONS :
428 case HANDLE_FONT_NAME_NUMBERS :
429 case HANDLE_FONT_NAME_TEXT :
430 case HANDLE_CUSTOM_FONT_NAME_SERIF :
431 case HANDLE_CUSTOM_FONT_NAME_SANS :
432 case HANDLE_CUSTOM_FONT_NAME_FIXED :
434 OUString sFontName;
435 *pValues >>= sFontName;
436 if(sFontName.isEmpty())
437 throw IllegalArgumentException();
439 if(aFormat.GetFont((*ppEntries)->mnMemberId).GetFamilyName() != sFontName)
441 const SmFace rOld = aFormat.GetFont((*ppEntries)->mnMemberId);
443 SmFace aSet( sFontName, rOld.GetFontSize() );
444 aSet.SetBorderWidth( rOld.GetBorderWidth() );
445 aSet.SetAlignment( ALIGN_BASELINE );
446 aFormat.SetFont( (*ppEntries)->mnMemberId, aSet );
449 break;
450 case HANDLE_CUSTOM_FONT_FIXED_POSTURE:
451 case HANDLE_CUSTOM_FONT_SANS_POSTURE :
452 case HANDLE_CUSTOM_FONT_SERIF_POSTURE:
453 case HANDLE_FONT_VARIABLES_POSTURE :
454 case HANDLE_FONT_FUNCTIONS_POSTURE :
455 case HANDLE_FONT_NUMBERS_POSTURE :
456 case HANDLE_FONT_TEXT_POSTURE :
458 auto bVal = o3tl::tryAccess<bool>(*pValues);
459 if(!bVal)
460 throw IllegalArgumentException();
461 vcl::Font aNewFont(aFormat.GetFont((*ppEntries)->mnMemberId));
462 aNewFont.SetItalic(*bVal ? ITALIC_NORMAL : ITALIC_NONE);
463 aFormat.SetFont((*ppEntries)->mnMemberId, aNewFont);
465 break;
466 case HANDLE_CUSTOM_FONT_FIXED_WEIGHT :
467 case HANDLE_CUSTOM_FONT_SANS_WEIGHT :
468 case HANDLE_CUSTOM_FONT_SERIF_WEIGHT :
469 case HANDLE_FONT_VARIABLES_WEIGHT :
470 case HANDLE_FONT_FUNCTIONS_WEIGHT :
471 case HANDLE_FONT_NUMBERS_WEIGHT :
472 case HANDLE_FONT_TEXT_WEIGHT :
474 auto bVal = o3tl::tryAccess<bool>(*pValues);
475 if(!bVal)
476 throw IllegalArgumentException();
477 vcl::Font aNewFont(aFormat.GetFont((*ppEntries)->mnMemberId));
478 aNewFont.SetWeight(*bVal ? WEIGHT_BOLD : WEIGHT_NORMAL);
479 aFormat.SetFont((*ppEntries)->mnMemberId, aNewFont);
481 break;
482 case HANDLE_BASE_FONT_HEIGHT :
484 // Point!
485 sal_Int16 nVal = lcl_AnyToINT16(*pValues);
486 if(nVal < 1)
487 throw IllegalArgumentException();
488 Size aSize = aFormat.GetBaseSize();
489 aSize.setHeight( SmPtsTo100th_mm(nVal) );
490 aFormat.SetBaseSize(aSize);
492 // apply base size to fonts
493 const Size aTmp( aFormat.GetBaseSize() );
494 for (sal_uInt16 i = FNT_BEGIN; i <= FNT_END; i++)
495 aFormat.SetFontSize(i, aTmp);
497 break;
498 case HANDLE_RELATIVE_FONT_HEIGHT_TEXT :
499 case HANDLE_RELATIVE_FONT_HEIGHT_INDICES :
500 case HANDLE_RELATIVE_FONT_HEIGHT_FUNCTIONS :
501 case HANDLE_RELATIVE_FONT_HEIGHT_OPERATORS :
502 case HANDLE_RELATIVE_FONT_HEIGHT_LIMITS :
504 sal_Int16 nVal = 0;
505 *pValues >>= nVal;
506 if(nVal < 1)
507 throw IllegalArgumentException();
508 aFormat.SetRelSize((*ppEntries)->mnMemberId, nVal);
510 break;
512 case HANDLE_IS_TEXT_MODE :
514 aFormat.SetTextmode(*o3tl::doAccess<bool>(*pValues));
516 break;
518 case HANDLE_GREEK_CHAR_STYLE :
520 sal_Int16 nVal = 0;
521 *pValues >>= nVal;
522 if (nVal < 0 || nVal > 2)
523 throw IllegalArgumentException();
524 aFormat.SetGreekCharStyle( nVal );
526 break;
528 case HANDLE_ALIGNMENT :
530 // SmHorAlign uses the same values as HorizontalAlignment
531 sal_Int16 nVal = 0;
532 *pValues >>= nVal;
533 if(nVal < 0 || nVal > 2)
534 throw IllegalArgumentException();
535 aFormat.SetHorAlign(static_cast<SmHorAlign>(nVal));
537 break;
539 case HANDLE_RELATIVE_SPACING :
540 case HANDLE_RELATIVE_LINE_SPACING :
541 case HANDLE_RELATIVE_ROOT_SPACING :
542 case HANDLE_RELATIVE_INDEX_SUPERSCRIPT :
543 case HANDLE_RELATIVE_INDEX_SUBSCRIPT :
544 case HANDLE_RELATIVE_FRACTION_NUMERATOR_HEIGHT :
545 case HANDLE_RELATIVE_FRACTION_DENOMINATOR_DEPTH:
546 case HANDLE_RELATIVE_FRACTION_BAR_EXCESS_LENGTH:
547 case HANDLE_RELATIVE_FRACTION_BAR_LINE_WEIGHT :
548 case HANDLE_RELATIVE_UPPER_LIMIT_DISTANCE :
549 case HANDLE_RELATIVE_LOWER_LIMIT_DISTANCE :
550 case HANDLE_RELATIVE_BRACKET_EXCESS_SIZE :
551 case HANDLE_RELATIVE_BRACKET_DISTANCE :
552 case HANDLE_RELATIVE_SCALE_BRACKET_EXCESS_SIZE :
553 case HANDLE_RELATIVE_MATRIX_LINE_SPACING :
554 case HANDLE_RELATIVE_MATRIX_COLUMN_SPACING :
555 case HANDLE_RELATIVE_SYMBOL_PRIMARY_HEIGHT :
556 case HANDLE_RELATIVE_SYMBOL_MINIMUM_HEIGHT :
557 case HANDLE_RELATIVE_OPERATOR_EXCESS_SIZE :
558 case HANDLE_RELATIVE_OPERATOR_SPACING :
559 case HANDLE_LEFT_MARGIN :
560 case HANDLE_RIGHT_MARGIN :
561 case HANDLE_TOP_MARGIN :
562 case HANDLE_BOTTOM_MARGIN :
564 sal_Int16 nVal = 0;
565 *pValues >>= nVal;
566 if(nVal < 0)
567 throw IllegalArgumentException();
568 aFormat.SetDistance((*ppEntries)->mnMemberId, nVal);
570 break;
571 case HANDLE_IS_SCALE_ALL_BRACKETS :
572 aFormat.SetScaleNormalBrackets(*o3tl::doAccess<bool>(*pValues));
573 break;
574 case HANDLE_PRINTER_NAME:
576 // embedded documents just ignore this property for now
577 if ( pDocSh->GetCreateMode() != SfxObjectCreateMode::EMBEDDED )
579 SfxPrinter *pPrinter = pDocSh->GetPrinter ( );
580 if (pPrinter)
582 OUString sPrinterName;
583 if ( !(*pValues >>= sPrinterName) )
584 throw IllegalArgumentException();
586 if ( !sPrinterName.isEmpty() )
588 VclPtrInstance<SfxPrinter> pNewPrinter( pPrinter->GetOptions().Clone(), sPrinterName );
589 if (pNewPrinter->IsKnown())
590 pDocSh->SetPrinter ( pNewPrinter );
591 else
592 pNewPrinter.disposeAndClear();
597 break;
598 case HANDLE_PRINTER_SETUP:
600 Sequence < sal_Int8 > aSequence;
601 if ( !(*pValues >>= aSequence) )
602 throw IllegalArgumentException();
604 sal_uInt32 nSize = aSequence.getLength();
605 SvMemoryStream aStream ( aSequence.getArray(), nSize, StreamMode::READ );
606 aStream.Seek ( STREAM_SEEK_TO_BEGIN );
607 static sal_uInt16 const nRange[] =
609 SID_PRINTSIZE, SID_PRINTSIZE,
610 SID_PRINTZOOM, SID_PRINTZOOM,
611 SID_PRINTTITLE, SID_PRINTTITLE,
612 SID_PRINTTEXT, SID_PRINTTEXT,
613 SID_PRINTFRAME, SID_PRINTFRAME,
614 SID_NO_RIGHT_SPACES, SID_NO_RIGHT_SPACES,
615 SID_SAVE_ONLY_USED_SYMBOLS, SID_SAVE_ONLY_USED_SYMBOLS,
616 SID_AUTO_CLOSE_BRACKETS, SID_AUTO_CLOSE_BRACKETS,
619 auto pItemSet = std::make_unique<SfxItemSet>( SmDocShell::GetPool(), nRange );
620 SmModule *pp = SM_MOD();
621 pp->GetConfig()->ConfigToItemSet(*pItemSet);
622 VclPtr<SfxPrinter> pPrinter = SfxPrinter::Create ( aStream, std::move(pItemSet) );
624 pDocSh->SetPrinter( pPrinter );
626 break;
627 case HANDLE_SYMBOLS:
629 // this is set
630 Sequence < SymbolDescriptor > aSequence;
631 if ( !(*pValues >>= aSequence) )
632 throw IllegalArgumentException();
634 SmModule *pp = SM_MOD();
635 SmSymbolManager &rManager = pp->GetSymbolManager();
636 for (const SymbolDescriptor& rDescriptor : std::as_const(aSequence))
638 vcl::Font aFont;
639 aFont.SetFamilyName ( rDescriptor.sFontName );
640 aFont.SetCharSet ( static_cast < rtl_TextEncoding > (rDescriptor.nCharSet) );
641 aFont.SetFamily ( static_cast < FontFamily > (rDescriptor.nFamily ) );
642 aFont.SetPitch ( static_cast < FontPitch > (rDescriptor.nPitch ) );
643 aFont.SetWeight ( static_cast < FontWeight > (rDescriptor.nWeight ) );
644 aFont.SetItalic ( static_cast < FontItalic > (rDescriptor.nItalic ) );
645 SmSym aSymbol ( rDescriptor.sName, aFont, static_cast < sal_Unicode > (rDescriptor.nCharacter),
646 rDescriptor.sSymbolSet );
647 aSymbol.SetExportName ( rDescriptor.sExportName );
648 rManager.AddOrReplaceSymbol ( aSymbol );
651 break;
652 // #i33095# Security Options
653 case HANDLE_LOAD_READONLY :
655 if ( (*pValues).getValueType() != cppu::UnoType<bool>::get() )
656 throw IllegalArgumentException();
657 bool bReadonly = false;
658 if ( *pValues >>= bReadonly )
659 pDocSh->SetLoadReadonly( bReadonly );
660 break;
662 case HANDLE_INTEROP_GRAB_BAG:
663 setGrabBagItem(*pValues);
664 break;
665 case HANDLE_SAVE_THUMBNAIL:
667 if ((*pValues).getValueType() != cppu::UnoType<bool>::get())
668 throw IllegalArgumentException();
669 bool bThumbnail = false;
670 if (*pValues >>= bThumbnail)
671 pDocSh->SetUseThumbnailSave(bThumbnail);
673 break;
677 pDocSh->SetFormat( aFormat );
679 // #i67283# since about all of the above changes are likely to change
680 // the formula size we have to recalculate the vis-area now
681 pDocSh->SetVisArea( tools::Rectangle( Point(0, 0), pDocSh->GetSize() ) );
684 void SmModel::_getPropertyValues( const PropertyMapEntry **ppEntries, Any *pValue )
686 SmDocShell *pDocSh = static_cast < SmDocShell * > (GetObjectShell());
688 if ( nullptr == pDocSh )
689 throw UnknownPropertyException();
691 const SmFormat & aFormat = pDocSh->GetFormat();
693 for (; *ppEntries; ppEntries++, pValue++ )
695 switch ( (*ppEntries)->mnHandle )
697 case HANDLE_FORMULA:
698 *pValue <<= pDocSh->GetText();
699 break;
700 case HANDLE_FONT_NAME_VARIABLES :
701 case HANDLE_FONT_NAME_FUNCTIONS :
702 case HANDLE_FONT_NAME_NUMBERS :
703 case HANDLE_FONT_NAME_TEXT :
704 case HANDLE_CUSTOM_FONT_NAME_SERIF :
705 case HANDLE_CUSTOM_FONT_NAME_SANS :
706 case HANDLE_CUSTOM_FONT_NAME_FIXED :
708 const SmFace & rFace = aFormat.GetFont((*ppEntries)->mnMemberId);
709 *pValue <<= rFace.GetFamilyName();
711 break;
712 case HANDLE_CUSTOM_FONT_FIXED_POSTURE:
713 case HANDLE_CUSTOM_FONT_SANS_POSTURE :
714 case HANDLE_CUSTOM_FONT_SERIF_POSTURE:
715 case HANDLE_FONT_VARIABLES_POSTURE :
716 case HANDLE_FONT_FUNCTIONS_POSTURE :
717 case HANDLE_FONT_NUMBERS_POSTURE :
718 case HANDLE_FONT_TEXT_POSTURE :
720 const SmFace & rFace = aFormat.GetFont((*ppEntries)->mnMemberId);
721 *pValue <<= IsItalic( rFace );
723 break;
724 case HANDLE_CUSTOM_FONT_FIXED_WEIGHT :
725 case HANDLE_CUSTOM_FONT_SANS_WEIGHT :
726 case HANDLE_CUSTOM_FONT_SERIF_WEIGHT :
727 case HANDLE_FONT_VARIABLES_WEIGHT :
728 case HANDLE_FONT_FUNCTIONS_WEIGHT :
729 case HANDLE_FONT_NUMBERS_WEIGHT :
730 case HANDLE_FONT_TEXT_WEIGHT :
732 const SmFace & rFace = aFormat.GetFont((*ppEntries)->mnMemberId);
733 *pValue <<= IsBold( rFace );
735 break;
736 case HANDLE_BASE_FONT_HEIGHT :
738 // Point!
739 *pValue <<= sal_Int16(
740 SmRoundFraction(
741 Sm100th_mmToPts(aFormat.GetBaseSize().Height())));
743 break;
744 case HANDLE_RELATIVE_FONT_HEIGHT_TEXT :
745 case HANDLE_RELATIVE_FONT_HEIGHT_INDICES :
746 case HANDLE_RELATIVE_FONT_HEIGHT_FUNCTIONS :
747 case HANDLE_RELATIVE_FONT_HEIGHT_OPERATORS :
748 case HANDLE_RELATIVE_FONT_HEIGHT_LIMITS :
749 *pValue <<= static_cast<sal_Int16>(aFormat.GetRelSize((*ppEntries)->mnMemberId));
750 break;
752 case HANDLE_IS_TEXT_MODE :
753 *pValue <<= aFormat.IsTextmode();
754 break;
756 case HANDLE_GREEK_CHAR_STYLE :
757 *pValue <<= aFormat.GetGreekCharStyle();
758 break;
760 case HANDLE_ALIGNMENT :
761 // SmHorAlign uses the same values as HorizontalAlignment
762 *pValue <<= static_cast<sal_Int16>(aFormat.GetHorAlign());
763 break;
765 case HANDLE_RELATIVE_SPACING :
766 case HANDLE_RELATIVE_LINE_SPACING :
767 case HANDLE_RELATIVE_ROOT_SPACING :
768 case HANDLE_RELATIVE_INDEX_SUPERSCRIPT :
769 case HANDLE_RELATIVE_INDEX_SUBSCRIPT :
770 case HANDLE_RELATIVE_FRACTION_NUMERATOR_HEIGHT :
771 case HANDLE_RELATIVE_FRACTION_DENOMINATOR_DEPTH:
772 case HANDLE_RELATIVE_FRACTION_BAR_EXCESS_LENGTH:
773 case HANDLE_RELATIVE_FRACTION_BAR_LINE_WEIGHT :
774 case HANDLE_RELATIVE_UPPER_LIMIT_DISTANCE :
775 case HANDLE_RELATIVE_LOWER_LIMIT_DISTANCE :
776 case HANDLE_RELATIVE_BRACKET_EXCESS_SIZE :
777 case HANDLE_RELATIVE_BRACKET_DISTANCE :
778 case HANDLE_RELATIVE_SCALE_BRACKET_EXCESS_SIZE :
779 case HANDLE_RELATIVE_MATRIX_LINE_SPACING :
780 case HANDLE_RELATIVE_MATRIX_COLUMN_SPACING :
781 case HANDLE_RELATIVE_SYMBOL_PRIMARY_HEIGHT :
782 case HANDLE_RELATIVE_SYMBOL_MINIMUM_HEIGHT :
783 case HANDLE_RELATIVE_OPERATOR_EXCESS_SIZE :
784 case HANDLE_RELATIVE_OPERATOR_SPACING :
785 case HANDLE_LEFT_MARGIN :
786 case HANDLE_RIGHT_MARGIN :
787 case HANDLE_TOP_MARGIN :
788 case HANDLE_BOTTOM_MARGIN :
789 *pValue <<= static_cast<sal_Int16>(aFormat.GetDistance((*ppEntries)->mnMemberId));
790 break;
791 case HANDLE_IS_SCALE_ALL_BRACKETS :
792 *pValue <<= aFormat.IsScaleNormalBrackets();
793 break;
794 case HANDLE_PRINTER_NAME:
796 SfxPrinter *pPrinter = pDocSh->GetPrinter ( );
797 *pValue <<= pPrinter ? pPrinter->GetName() : OUString();
799 break;
800 case HANDLE_PRINTER_SETUP:
802 SfxPrinter *pPrinter = pDocSh->GetPrinter ();
803 if (pPrinter)
805 SvMemoryStream aStream;
806 pPrinter->Store( aStream );
807 sal_uInt32 nSize = aStream.TellEnd();
808 aStream.Seek ( STREAM_SEEK_TO_BEGIN );
809 Sequence < sal_Int8 > aSequence ( nSize );
810 aStream.ReadBytes(aSequence.getArray(), nSize);
811 *pValue <<= aSequence;
814 break;
815 case HANDLE_SYMBOLS:
816 case HANDLE_USED_SYMBOLS:
818 const bool bUsedSymbolsOnly = (*ppEntries)->mnHandle == HANDLE_USED_SYMBOLS;
819 const std::set< OUString > &rUsedSymbols = pDocSh->GetUsedSymbols();
821 // this is get
822 SmModule *pp = SM_MOD();
823 const SmSymbolManager &rManager = pp->GetSymbolManager();
824 vector < const SmSym * > aVector;
826 const SymbolPtrVec_t aSymbols( rManager.GetSymbols() );
827 for (const SmSym* pSymbol : aSymbols)
829 if (pSymbol && !pSymbol->IsPredefined() &&
830 (!bUsedSymbolsOnly ||
831 rUsedSymbols.find( pSymbol->GetName() ) != rUsedSymbols.end()))
832 aVector.push_back ( pSymbol );
834 Sequence < SymbolDescriptor > aSequence ( aVector.size() );
835 SymbolDescriptor * pDescriptor = aSequence.getArray();
837 for (const SmSym* pSymbol : aVector)
839 pDescriptor->sName = pSymbol->GetName();
840 pDescriptor->sExportName = pSymbol->GetExportName();
841 pDescriptor->sSymbolSet = pSymbol->GetSymbolSetName();
842 pDescriptor->nCharacter = static_cast < sal_Int32 > (pSymbol->GetCharacter());
844 vcl::Font rFont = pSymbol->GetFace();
845 pDescriptor->sFontName = rFont.GetFamilyName();
846 pDescriptor->nCharSet = sal::static_int_cast< sal_Int16 >(rFont.GetCharSet());
847 pDescriptor->nFamily = sal::static_int_cast< sal_Int16 >(rFont.GetFamilyType());
848 pDescriptor->nPitch = sal::static_int_cast< sal_Int16 >(rFont.GetPitch());
849 pDescriptor->nWeight = sal::static_int_cast< sal_Int16 >(rFont.GetWeight());
850 pDescriptor->nItalic = sal::static_int_cast< sal_Int16 >(rFont.GetItalic());
851 pDescriptor++;
853 *pValue <<= aSequence;
855 break;
856 case HANDLE_BASIC_LIBRARIES:
857 *pValue <<= pDocSh->GetBasicContainer();
858 break;
859 case HANDLE_DIALOG_LIBRARIES:
860 *pValue <<= pDocSh->GetDialogContainer();
861 break;
862 case HANDLE_RUNTIME_UID:
863 *pValue <<= getRuntimeUID();
864 break;
865 // #i33095# Security Options
866 case HANDLE_LOAD_READONLY :
868 *pValue <<= pDocSh->IsLoadReadonly();
869 break;
871 // #i972#
872 case HANDLE_BASELINE:
874 if ( !pDocSh->GetFormulaTree() )
875 pDocSh->Parse();
876 if ( pDocSh->GetFormulaTree() )
878 pDocSh->ArrangeFormula();
880 *pValue <<= static_cast<sal_Int32>( pDocSh->GetFormulaTree()->GetFormulaBaseline() );
882 break;
884 case HANDLE_INTEROP_GRAB_BAG:
885 getGrabBagItem(*pValue);
886 break;
887 case HANDLE_SAVE_THUMBNAIL:
889 *pValue <<= pDocSh->IsUseThumbnailSave();
891 break;
897 sal_Int32 SAL_CALL SmModel::getRendererCount(
898 const uno::Any& /*rSelection*/,
899 const uno::Sequence< beans::PropertyValue >& /*xOptions*/ )
901 return 1;
905 static Size lcl_GuessPaperSize()
907 Size aRes;
908 const LocaleDataWrapper& rLocWrp( AllSettings().GetLocaleDataWrapper() );
909 if( MeasurementSystem::Metric == rLocWrp.getMeasurementSystemEnum() )
911 // in 100th mm
912 PaperInfo aInfo( PAPER_A4 );
913 aRes.setWidth( aInfo.getWidth() );
914 aRes.setHeight( aInfo.getHeight() );
916 else
918 // in 100th mm
919 PaperInfo aInfo( PAPER_LETTER );
920 aRes.setWidth( aInfo.getWidth() );
921 aRes.setHeight( aInfo.getHeight() );
923 return aRes;
926 uno::Sequence< beans::PropertyValue > SAL_CALL SmModel::getRenderer(
927 sal_Int32 nRenderer,
928 const uno::Any& /*rSelection*/,
929 const uno::Sequence< beans::PropertyValue >& /*rxOptions*/ )
931 SolarMutexGuard aGuard;
933 if (0 != nRenderer)
934 throw IllegalArgumentException();
936 SmDocShell *pDocSh = static_cast < SmDocShell * >( GetObjectShell() );
937 if (!pDocSh)
938 throw RuntimeException();
940 SmPrinterAccess aPrinterAccess( *pDocSh );
941 Printer *pPrinter = aPrinterAccess.GetPrinter();
942 Size aPrtPaperSize ( pPrinter->GetPaperSize() );
944 // if paper size is 0 (usually if no 'real' printer is found),
945 // guess the paper size
946 if (aPrtPaperSize.Height() == 0 || aPrtPaperSize.Width() == 0)
947 aPrtPaperSize = lcl_GuessPaperSize();
948 awt::Size aPageSize( aPrtPaperSize.Width(), aPrtPaperSize.Height() );
950 uno::Sequence< beans::PropertyValue > aRenderer(1);
951 PropertyValue &rValue = aRenderer.getArray()[0];
952 rValue.Name = "PageSize";
953 rValue.Value <<= aPageSize;
955 if (!m_pPrintUIOptions)
956 m_pPrintUIOptions.reset(new SmPrintUIOptions);
957 m_pPrintUIOptions->appendPrintUIOptions( aRenderer );
959 return aRenderer;
962 void SAL_CALL SmModel::render(
963 sal_Int32 nRenderer,
964 const uno::Any& rSelection,
965 const uno::Sequence< beans::PropertyValue >& rxOptions )
967 SolarMutexGuard aGuard;
969 if (0 != nRenderer)
970 throw IllegalArgumentException();
972 SmDocShell *pDocSh = static_cast < SmDocShell * >( GetObjectShell() );
973 if (!pDocSh)
974 throw RuntimeException();
976 // get device to be rendered in
977 uno::Reference< awt::XDevice > xRenderDevice;
978 for (const auto& rxOption : rxOptions)
980 if( rxOption.Name == "RenderDevice" )
981 rxOption.Value >>= xRenderDevice;
984 if (!xRenderDevice.is())
985 return;
987 VCLXDevice* pDevice = comphelper::getUnoTunnelImplementation<VCLXDevice>( xRenderDevice );
988 VclPtr< OutputDevice> pOut = pDevice ? pDevice->GetOutputDevice()
989 : VclPtr< OutputDevice >();
990 if (!pOut)
991 throw RuntimeException();
993 pOut->SetMapMode(MapMode(MapUnit::Map100thMM));
995 uno::Reference< frame::XModel > xModel;
996 rSelection >>= xModel;
997 if (xModel != pDocSh->GetModel())
998 return;
1000 //!! when called via API we may not have an active view
1001 //!! thus we go and look for a view that can be used.
1002 SfxViewShell* pViewSh = SfxViewShell::GetFirst( false /* search non-visible views as well*/, checkSfxViewShell<SmViewShell> );
1003 while (pViewSh && pViewSh->GetObjectShell() != pDocSh)
1004 pViewSh = SfxViewShell::GetNext( *pViewSh, false /* search non-visible views as well*/, checkSfxViewShell<SmViewShell> );
1005 SmViewShell *pView = dynamic_cast< SmViewShell *>( pViewSh );
1006 SAL_WARN_IF( !pView, "starmath", "SmModel::render : no SmViewShell found" );
1008 if (!pView)
1009 return;
1011 SmPrinterAccess aPrinterAccess( *pDocSh );
1012 Printer *pPrinter = aPrinterAccess.GetPrinter();
1014 Size aPrtPaperSize ( pPrinter->GetPaperSize() );
1015 Size aOutputSize ( pPrinter->GetOutputSize() );
1016 Point aPrtPageOffset( pPrinter->GetPageOffset() );
1018 // no real printer ??
1019 if (aPrtPaperSize.Height() == 0 || aPrtPaperSize.Width() == 0)
1021 aPrtPaperSize = lcl_GuessPaperSize();
1022 // factors from Windows DIN A4
1023 aOutputSize = Size( static_cast<long>(aPrtPaperSize.Width() * 0.941),
1024 static_cast<long>(aPrtPaperSize.Height() * 0.961));
1025 aPrtPageOffset = Point( static_cast<long>(aPrtPaperSize.Width() * 0.0250),
1026 static_cast<long>(aPrtPaperSize.Height() * 0.0214));
1028 tools::Rectangle OutputRect( Point(), aOutputSize );
1031 // set minimum top and bottom border
1032 if (aPrtPageOffset.Y() < 2000)
1033 OutputRect.AdjustTop(2000 - aPrtPageOffset.Y() );
1034 if ((aPrtPaperSize.Height() - (aPrtPageOffset.Y() + OutputRect.Bottom())) < 2000)
1035 OutputRect.AdjustBottom( -(2000 - (aPrtPaperSize.Height() -
1036 (aPrtPageOffset.Y() + OutputRect.Bottom()))) );
1038 // set minimum left and right border
1039 if (aPrtPageOffset.X() < 2500)
1040 OutputRect.AdjustLeft(2500 - aPrtPageOffset.X() );
1041 if ((aPrtPaperSize.Width() - (aPrtPageOffset.X() + OutputRect.Right())) < 1500)
1042 OutputRect.AdjustRight( -(1500 - (aPrtPaperSize.Width() -
1043 (aPrtPageOffset.X() + OutputRect.Right()))) );
1045 if (!m_pPrintUIOptions)
1046 m_pPrintUIOptions.reset(new SmPrintUIOptions);
1047 m_pPrintUIOptions->processProperties( rxOptions );
1049 pView->Impl_Print( *pOut, *m_pPrintUIOptions, OutputRect );
1051 // release SmPrintUIOptions when everything is done.
1052 // That way, when SmPrintUIOptions is needed again it will read the latest configuration settings in its c-tor.
1053 if (m_pPrintUIOptions->getBoolValue( "IsLastPage" ))
1055 m_pPrintUIOptions.reset();
1059 void SAL_CALL SmModel::setParent( const uno::Reference< uno::XInterface >& xParent)
1061 SolarMutexGuard aGuard;
1062 SfxBaseModel::setParent( xParent );
1063 uno::Reference< lang::XUnoTunnel > xParentTunnel( xParent, uno::UNO_QUERY );
1064 if ( xParentTunnel.is() )
1066 SvGlobalName aSfxIdent( SFX_GLOBAL_CLASSID );
1067 SfxObjectShell* pDoc = reinterpret_cast<SfxObjectShell *>(xParentTunnel->getSomething(
1068 aSfxIdent.GetByteSequence() ) );
1069 if ( pDoc )
1070 GetObjectShell()->OnDocumentPrinterChanged( pDoc->GetDocumentPrinter() );
1074 void SmModel::writeFormulaOoxml(
1075 ::sax_fastparser::FSHelperPtr const pSerializer,
1076 oox::core::OoxmlVersion const version,
1077 oox::drawingml::DocumentType const documentType)
1079 static_cast<SmDocShell*>(GetObjectShell())->writeFormulaOoxml(pSerializer, version, documentType);
1082 void SmModel::writeFormulaRtf(OStringBuffer& rBuffer, rtl_TextEncoding nEncoding)
1084 static_cast<SmDocShell*>(GetObjectShell())->writeFormulaRtf(rBuffer, nEncoding);
1087 void SmModel::readFormulaOoxml( oox::formulaimport::XmlStream& stream )
1089 static_cast< SmDocShell* >( GetObjectShell())->readFormulaOoxml( stream );
1092 Size SmModel::getFormulaSize() const
1094 return static_cast< SmDocShell* >( GetObjectShell())->GetSize();
1097 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */