nss: upgrade to release 3.73
[LibreOffice.git] / starmath / source / unomodel.cxx
blob623fad7858446432bbe015e5c7100e3bd6cc79c6
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);
156 namespace {
158 enum SmModelPropertyHandles
160 HANDLE_FORMULA,
161 HANDLE_FONT_NAME_VARIABLES,
162 HANDLE_FONT_NAME_FUNCTIONS,
163 HANDLE_FONT_NAME_NUMBERS,
164 HANDLE_FONT_NAME_TEXT,
165 HANDLE_CUSTOM_FONT_NAME_SERIF,
166 HANDLE_CUSTOM_FONT_NAME_SANS,
167 HANDLE_CUSTOM_FONT_NAME_FIXED,
168 HANDLE_CUSTOM_FONT_FIXED_POSTURE,
169 HANDLE_CUSTOM_FONT_FIXED_WEIGHT,
170 HANDLE_CUSTOM_FONT_SANS_POSTURE,
171 HANDLE_CUSTOM_FONT_SANS_WEIGHT,
172 HANDLE_CUSTOM_FONT_SERIF_POSTURE,
173 HANDLE_CUSTOM_FONT_SERIF_WEIGHT,
174 HANDLE_FONT_VARIABLES_POSTURE,
175 HANDLE_FONT_VARIABLES_WEIGHT,
176 HANDLE_FONT_FUNCTIONS_POSTURE,
177 HANDLE_FONT_FUNCTIONS_WEIGHT,
178 HANDLE_FONT_NUMBERS_POSTURE,
179 HANDLE_FONT_NUMBERS_WEIGHT,
180 HANDLE_FONT_TEXT_POSTURE,
181 HANDLE_FONT_TEXT_WEIGHT,
182 HANDLE_BASE_FONT_HEIGHT,
183 HANDLE_RELATIVE_FONT_HEIGHT_TEXT,
184 HANDLE_RELATIVE_FONT_HEIGHT_INDICES,
185 HANDLE_RELATIVE_FONT_HEIGHT_FUNCTIONS,
186 HANDLE_RELATIVE_FONT_HEIGHT_OPERATORS,
187 HANDLE_RELATIVE_FONT_HEIGHT_LIMITS,
188 HANDLE_IS_TEXT_MODE,
189 HANDLE_GREEK_CHAR_STYLE,
190 HANDLE_ALIGNMENT,
191 HANDLE_RELATIVE_SPACING,
192 HANDLE_RELATIVE_LINE_SPACING,
193 HANDLE_RELATIVE_ROOT_SPACING,
194 HANDLE_RELATIVE_INDEX_SUPERSCRIPT,
195 HANDLE_RELATIVE_INDEX_SUBSCRIPT,
196 HANDLE_RELATIVE_FRACTION_NUMERATOR_HEIGHT,
197 HANDLE_RELATIVE_FRACTION_DENOMINATOR_DEPTH,
198 HANDLE_RELATIVE_FRACTION_BAR_EXCESS_LENGTH,
199 HANDLE_RELATIVE_FRACTION_BAR_LINE_WEIGHT,
200 HANDLE_RELATIVE_UPPER_LIMIT_DISTANCE,
201 HANDLE_RELATIVE_LOWER_LIMIT_DISTANCE,
202 HANDLE_RELATIVE_BRACKET_EXCESS_SIZE,
203 HANDLE_RELATIVE_BRACKET_DISTANCE,
204 HANDLE_IS_SCALE_ALL_BRACKETS,
205 HANDLE_RELATIVE_SCALE_BRACKET_EXCESS_SIZE,
206 HANDLE_RELATIVE_MATRIX_LINE_SPACING,
207 HANDLE_RELATIVE_MATRIX_COLUMN_SPACING,
208 HANDLE_RELATIVE_SYMBOL_PRIMARY_HEIGHT,
209 HANDLE_RELATIVE_SYMBOL_MINIMUM_HEIGHT,
210 HANDLE_RELATIVE_OPERATOR_EXCESS_SIZE,
211 HANDLE_RELATIVE_OPERATOR_SPACING,
212 HANDLE_LEFT_MARGIN,
213 HANDLE_RIGHT_MARGIN,
214 HANDLE_TOP_MARGIN,
215 HANDLE_BOTTOM_MARGIN,
216 HANDLE_PRINTER_NAME,
217 HANDLE_PRINTER_SETUP,
218 HANDLE_SYMBOLS,
219 HANDLE_SAVE_THUMBNAIL,
220 HANDLE_USED_SYMBOLS,
221 HANDLE_BASIC_LIBRARIES,
222 HANDLE_RUNTIME_UID,
223 HANDLE_LOAD_READONLY, // Security Options
224 HANDLE_DIALOG_LIBRARIES, // #i73329#
225 HANDLE_BASELINE,
226 HANDLE_INTEROP_GRAB_BAG,
231 static rtl::Reference<PropertySetInfo> lcl_createModelPropertyInfo ()
233 static PropertyMapEntry aModelPropertyInfoMap[] =
235 { OUString("Alignment") , HANDLE_ALIGNMENT , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, 0 },
236 { OUString("BaseFontHeight") , HANDLE_BASE_FONT_HEIGHT , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, 0 },
237 { OUString("BasicLibraries") , HANDLE_BASIC_LIBRARIES , cppu::UnoType<script::XLibraryContainer>::get(), PropertyAttribute::READONLY, 0 },
238 { OUString("BottomMargin") , HANDLE_BOTTOM_MARGIN , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_BOTTOMSPACE },
239 { OUString("CustomFontNameFixed") , HANDLE_CUSTOM_FONT_NAME_FIXED , ::cppu::UnoType<OUString>::get(), PROPERTY_NONE, FNT_FIXED },
240 { OUString("CustomFontNameSans") , HANDLE_CUSTOM_FONT_NAME_SANS , ::cppu::UnoType<OUString>::get(), PROPERTY_NONE, FNT_SANS },
241 { OUString("CustomFontNameSerif") , HANDLE_CUSTOM_FONT_NAME_SERIF , ::cppu::UnoType<OUString>::get(), PROPERTY_NONE, FNT_SERIF },
242 { OUString("DialogLibraries") , HANDLE_DIALOG_LIBRARIES , cppu::UnoType<script::XLibraryContainer>::get(), PropertyAttribute::READONLY, 0 },
243 { OUString("FontFixedIsBold") , HANDLE_CUSTOM_FONT_FIXED_WEIGHT , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_FIXED },
244 { OUString("FontFixedIsItalic") , HANDLE_CUSTOM_FONT_FIXED_POSTURE , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_FIXED },
245 { OUString("FontFunctionsIsBold") , HANDLE_FONT_FUNCTIONS_WEIGHT , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_FUNCTION },
246 { OUString("FontFunctionsIsItalic") , HANDLE_FONT_FUNCTIONS_POSTURE , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_FUNCTION },
247 { OUString("FontNameFunctions") , HANDLE_FONT_NAME_FUNCTIONS , ::cppu::UnoType<OUString>::get(), PROPERTY_NONE, FNT_FUNCTION },
248 { OUString("FontNameNumbers") , HANDLE_FONT_NAME_NUMBERS , ::cppu::UnoType<OUString>::get(), PROPERTY_NONE, FNT_NUMBER },
249 { OUString("FontNameText") , HANDLE_FONT_NAME_TEXT , ::cppu::UnoType<OUString>::get(), PROPERTY_NONE, FNT_TEXT },
250 { OUString("FontNameVariables") , HANDLE_FONT_NAME_VARIABLES , ::cppu::UnoType<OUString>::get(), PROPERTY_NONE, FNT_VARIABLE },
251 { OUString("FontNumbersIsBold") , HANDLE_FONT_NUMBERS_WEIGHT , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_NUMBER },
252 { OUString("FontNumbersIsItalic") , HANDLE_FONT_NUMBERS_POSTURE , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_NUMBER },
253 { OUString("FontSansIsBold") , HANDLE_CUSTOM_FONT_SANS_WEIGHT , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_SANS },
254 { OUString("FontSansIsItalic") , HANDLE_CUSTOM_FONT_SANS_POSTURE , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_SANS },
255 { OUString("FontSerifIsBold") , HANDLE_CUSTOM_FONT_SERIF_WEIGHT , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_SERIF },
256 { OUString("FontSerifIsItalic") , HANDLE_CUSTOM_FONT_SERIF_POSTURE , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_SERIF },
257 { OUString("FontTextIsBold") , HANDLE_FONT_TEXT_WEIGHT , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_TEXT },
258 { OUString("FontTextIsItalic") , HANDLE_FONT_TEXT_POSTURE , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_TEXT },
259 { OUString("FontVariablesIsBold") , HANDLE_FONT_VARIABLES_WEIGHT , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_VARIABLE },
260 { OUString("FontVariablesIsItalic") , HANDLE_FONT_VARIABLES_POSTURE , cppu::UnoType<bool>::get(), PROPERTY_NONE, FNT_VARIABLE },
261 { OUString("Formula") , HANDLE_FORMULA , ::cppu::UnoType<OUString>::get(), PROPERTY_NONE, 0 },
262 { OUString("IsScaleAllBrackets") , HANDLE_IS_SCALE_ALL_BRACKETS , cppu::UnoType<bool>::get(), PROPERTY_NONE, 0 },
263 { OUString("IsTextMode") , HANDLE_IS_TEXT_MODE , cppu::UnoType<bool>::get(), PROPERTY_NONE, 0 },
264 { OUString("GreekCharStyle") , HANDLE_GREEK_CHAR_STYLE , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, 0 },
265 { OUString("LeftMargin") , HANDLE_LEFT_MARGIN , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_LEFTSPACE },
266 { OUString("PrinterName") , HANDLE_PRINTER_NAME , ::cppu::UnoType<OUString>::get(), PROPERTY_NONE, 0 },
267 { OUString("PrinterSetup") , HANDLE_PRINTER_SETUP , cppu::UnoType<const Sequence < sal_Int8 >>::get(), PROPERTY_NONE, 0 },
268 { OUString("RelativeBracketDistance") , HANDLE_RELATIVE_BRACKET_DISTANCE , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_BRACKETSPACE },
269 { OUString("RelativeBracketExcessSize") , HANDLE_RELATIVE_BRACKET_EXCESS_SIZE , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_BRACKETSIZE },
270 { OUString("RelativeFontHeightFunctions") , HANDLE_RELATIVE_FONT_HEIGHT_FUNCTIONS , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, SIZ_FUNCTION },
271 { OUString("RelativeFontHeightIndices") , HANDLE_RELATIVE_FONT_HEIGHT_INDICES , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, SIZ_INDEX },
272 { OUString("RelativeFontHeightLimits") , HANDLE_RELATIVE_FONT_HEIGHT_LIMITS , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, SIZ_LIMITS },
273 { OUString("RelativeFontHeightOperators") , HANDLE_RELATIVE_FONT_HEIGHT_OPERATORS , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, SIZ_OPERATOR },
274 { OUString("RelativeFontHeightText") , HANDLE_RELATIVE_FONT_HEIGHT_TEXT , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, SIZ_TEXT },
275 { OUString("RelativeFractionBarExcessLength") , HANDLE_RELATIVE_FRACTION_BAR_EXCESS_LENGTH, ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_FRACTION },
276 { OUString("RelativeFractionBarLineWeight") , HANDLE_RELATIVE_FRACTION_BAR_LINE_WEIGHT , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_STROKEWIDTH },
277 { OUString("RelativeFractionDenominatorDepth") , HANDLE_RELATIVE_FRACTION_DENOMINATOR_DEPTH, ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_DENOMINATOR },
278 { OUString("RelativeFractionNumeratorHeight") , HANDLE_RELATIVE_FRACTION_NUMERATOR_HEIGHT , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_NUMERATOR },
279 { OUString("RelativeIndexSubscript") , HANDLE_RELATIVE_INDEX_SUBSCRIPT , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_SUBSCRIPT },
280 { OUString("RelativeIndexSuperscript") , HANDLE_RELATIVE_INDEX_SUPERSCRIPT , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_SUPERSCRIPT },
281 { OUString("RelativeLineSpacing") , HANDLE_RELATIVE_LINE_SPACING , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_VERTICAL },
282 { OUString("RelativeLowerLimitDistance") , HANDLE_RELATIVE_LOWER_LIMIT_DISTANCE , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_LOWERLIMIT },
283 { OUString("RelativeMatrixColumnSpacing") , HANDLE_RELATIVE_MATRIX_COLUMN_SPACING , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_MATRIXCOL },
284 { OUString("RelativeMatrixLineSpacing") , HANDLE_RELATIVE_MATRIX_LINE_SPACING , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_MATRIXROW },
285 { OUString("RelativeOperatorExcessSize") , HANDLE_RELATIVE_OPERATOR_EXCESS_SIZE , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_OPERATORSIZE },
286 { OUString("RelativeOperatorSpacing") , HANDLE_RELATIVE_OPERATOR_SPACING , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_OPERATORSPACE },
287 { OUString("RelativeRootSpacing") , HANDLE_RELATIVE_ROOT_SPACING , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_ROOT },
288 { OUString("RelativeScaleBracketExcessSize") , HANDLE_RELATIVE_SCALE_BRACKET_EXCESS_SIZE , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_NORMALBRACKETSIZE },
289 { OUString("RelativeSpacing") , HANDLE_RELATIVE_SPACING , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_HORIZONTAL },
290 { OUString("RelativeSymbolMinimumHeight") , HANDLE_RELATIVE_SYMBOL_MINIMUM_HEIGHT , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_ORNAMENTSPACE },
291 { OUString("RelativeSymbolPrimaryHeight") , HANDLE_RELATIVE_SYMBOL_PRIMARY_HEIGHT , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_ORNAMENTSIZE },
292 { OUString("RelativeUpperLimitDistance") , HANDLE_RELATIVE_UPPER_LIMIT_DISTANCE , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_UPPERLIMIT },
293 { OUString("RightMargin") , HANDLE_RIGHT_MARGIN , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_RIGHTSPACE },
294 { OUString("RuntimeUID") , HANDLE_RUNTIME_UID , cppu::UnoType<OUString>::get(), PropertyAttribute::READONLY, 0 },
295 { OUString("SaveThumbnail") , HANDLE_SAVE_THUMBNAIL , cppu::UnoType<bool>::get(), PROPERTY_NONE, 0 },
296 { OUString("Symbols") , HANDLE_SYMBOLS , cppu::UnoType<Sequence < SymbolDescriptor >>::get(), PROPERTY_NONE, 0 },
297 { OUString("UserDefinedSymbolsInUse") , HANDLE_USED_SYMBOLS , cppu::UnoType<Sequence < SymbolDescriptor >>::get(), PropertyAttribute::READONLY, 0 },
298 { OUString("TopMargin") , HANDLE_TOP_MARGIN , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, DIS_TOPSPACE },
299 // #i33095# Security Options
300 { OUString("LoadReadonly") , HANDLE_LOAD_READONLY , cppu::UnoType<bool>::get(), PROPERTY_NONE, 0 },
301 // #i972#
302 { OUString("BaseLine") , HANDLE_BASELINE , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE, 0 },
303 { OUString("InteropGrabBag") , HANDLE_INTEROP_GRAB_BAG , cppu::UnoType<uno::Sequence< beans::PropertyValue >>::get(), PROPERTY_NONE, 0 },
304 { OUString(), 0, css::uno::Type(), 0, 0 }
306 return rtl::Reference<PropertySetInfo>( new PropertySetInfo ( aModelPropertyInfoMap ) );
309 SmModel::SmModel( SfxObjectShell *pObjSh )
310 : SfxBaseModel(pObjSh)
311 , PropertySetHelper ( lcl_createModelPropertyInfo () )
315 SmModel::~SmModel() throw ()
319 uno::Any SAL_CALL SmModel::queryInterface( const uno::Type& rType )
321 uno::Any aRet = ::cppu::queryInterface ( rType,
322 // OWeakObject interfaces
323 &dynamic_cast<XInterface&>(static_cast<XUnoTunnel&>(*this)),
324 static_cast< XWeak* > ( this ),
325 // PropertySetHelper interfaces
326 static_cast< XPropertySet* > ( this ),
327 static_cast< XMultiPropertySet* > ( this ),
328 // my own interfaces
329 static_cast< XServiceInfo* > ( this ),
330 static_cast< XRenderable* > ( this ) );
331 if (!aRet.hasValue())
332 aRet = SfxBaseModel::queryInterface ( rType );
333 return aRet;
336 void SAL_CALL SmModel::acquire() throw()
338 OWeakObject::acquire();
341 void SAL_CALL SmModel::release() throw()
343 OWeakObject::release();
346 uno::Sequence< uno::Type > SAL_CALL SmModel::getTypes( )
348 return comphelper::concatSequences(SfxBaseModel::getTypes(),
349 uno::Sequence {
350 cppu::UnoType<XServiceInfo>::get(),
351 cppu::UnoType<XPropertySet>::get(),
352 cppu::UnoType<XMultiPropertySet>::get(),
353 cppu::UnoType<XRenderable>::get() });
356 namespace
358 class theSmModelUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSmModelUnoTunnelId> {};
361 const uno::Sequence< sal_Int8 > & SmModel::getUnoTunnelId()
363 return theSmModelUnoTunnelId::get().getSeq();
366 sal_Int64 SAL_CALL SmModel::getSomething( const uno::Sequence< sal_Int8 >& rId )
368 if( isUnoTunnelId<SmModel>(rId) )
370 return sal::static_int_cast< sal_Int64 >(reinterpret_cast< sal_uIntPtr >(this));
373 return SfxBaseModel::getSomething( rId );
376 static sal_Int16 lcl_AnyToINT16(const uno::Any& rAny)
378 sal_Int16 nRet = 0;
379 if( auto x = o3tl::tryAccess<double>(rAny) )
380 nRet = static_cast<sal_Int16>(*x);
381 else
382 rAny >>= nRet;
383 return nRet;
386 OUString SmModel::getImplementationName()
388 return "com.sun.star.comp.Math.FormulaDocument";
391 sal_Bool SmModel::supportsService(const OUString& rServiceName)
393 return cppu::supportsService(this, rServiceName);
396 uno::Sequence< OUString > SmModel::getSupportedServiceNames()
398 return uno::Sequence<OUString>{
399 "com.sun.star.document.OfficeDocument",
400 "com.sun.star.formula.FormulaProperties"
404 void SmModel::_setPropertyValues(const PropertyMapEntry** ppEntries, const Any* pValues)
406 SolarMutexGuard aGuard;
408 SmDocShell *pDocSh = static_cast < SmDocShell * > (GetObjectShell());
410 if ( nullptr == pDocSh )
411 throw UnknownPropertyException();
413 SmFormat aFormat = pDocSh->GetFormat();
415 for (; *ppEntries; ppEntries++, pValues++ )
417 if ((*ppEntries)->mnAttributes & PropertyAttribute::READONLY)
418 throw PropertyVetoException();
420 switch ( (*ppEntries)->mnHandle )
422 case HANDLE_FORMULA:
424 OUString aText;
425 *pValues >>= aText;
426 pDocSh->SetText(aText);
428 break;
429 case HANDLE_FONT_NAME_VARIABLES :
430 case HANDLE_FONT_NAME_FUNCTIONS :
431 case HANDLE_FONT_NAME_NUMBERS :
432 case HANDLE_FONT_NAME_TEXT :
433 case HANDLE_CUSTOM_FONT_NAME_SERIF :
434 case HANDLE_CUSTOM_FONT_NAME_SANS :
435 case HANDLE_CUSTOM_FONT_NAME_FIXED :
437 OUString sFontName;
438 *pValues >>= sFontName;
439 if(sFontName.isEmpty())
440 throw IllegalArgumentException();
442 if(aFormat.GetFont((*ppEntries)->mnMemberId).GetFamilyName() != sFontName)
444 const SmFace rOld = aFormat.GetFont((*ppEntries)->mnMemberId);
446 SmFace aSet( sFontName, rOld.GetFontSize() );
447 aSet.SetBorderWidth( rOld.GetBorderWidth() );
448 aSet.SetAlignment( ALIGN_BASELINE );
449 aFormat.SetFont( (*ppEntries)->mnMemberId, aSet );
452 break;
453 case HANDLE_CUSTOM_FONT_FIXED_POSTURE:
454 case HANDLE_CUSTOM_FONT_SANS_POSTURE :
455 case HANDLE_CUSTOM_FONT_SERIF_POSTURE:
456 case HANDLE_FONT_VARIABLES_POSTURE :
457 case HANDLE_FONT_FUNCTIONS_POSTURE :
458 case HANDLE_FONT_NUMBERS_POSTURE :
459 case HANDLE_FONT_TEXT_POSTURE :
461 auto bVal = o3tl::tryAccess<bool>(*pValues);
462 if(!bVal)
463 throw IllegalArgumentException();
464 vcl::Font aNewFont(aFormat.GetFont((*ppEntries)->mnMemberId));
465 aNewFont.SetItalic(*bVal ? ITALIC_NORMAL : ITALIC_NONE);
466 aFormat.SetFont((*ppEntries)->mnMemberId, aNewFont);
468 break;
469 case HANDLE_CUSTOM_FONT_FIXED_WEIGHT :
470 case HANDLE_CUSTOM_FONT_SANS_WEIGHT :
471 case HANDLE_CUSTOM_FONT_SERIF_WEIGHT :
472 case HANDLE_FONT_VARIABLES_WEIGHT :
473 case HANDLE_FONT_FUNCTIONS_WEIGHT :
474 case HANDLE_FONT_NUMBERS_WEIGHT :
475 case HANDLE_FONT_TEXT_WEIGHT :
477 auto bVal = o3tl::tryAccess<bool>(*pValues);
478 if(!bVal)
479 throw IllegalArgumentException();
480 vcl::Font aNewFont(aFormat.GetFont((*ppEntries)->mnMemberId));
481 aNewFont.SetWeight(*bVal ? WEIGHT_BOLD : WEIGHT_NORMAL);
482 aFormat.SetFont((*ppEntries)->mnMemberId, aNewFont);
484 break;
485 case HANDLE_BASE_FONT_HEIGHT :
487 // Point!
488 sal_Int16 nVal = lcl_AnyToINT16(*pValues);
489 if(nVal < 1)
490 throw IllegalArgumentException();
491 Size aSize = aFormat.GetBaseSize();
492 aSize.setHeight( SmPtsTo100th_mm(nVal) );
493 aFormat.SetBaseSize(aSize);
495 // apply base size to fonts
496 const Size aTmp( aFormat.GetBaseSize() );
497 for (sal_uInt16 i = FNT_BEGIN; i <= FNT_END; i++)
498 aFormat.SetFontSize(i, aTmp);
500 break;
501 case HANDLE_RELATIVE_FONT_HEIGHT_TEXT :
502 case HANDLE_RELATIVE_FONT_HEIGHT_INDICES :
503 case HANDLE_RELATIVE_FONT_HEIGHT_FUNCTIONS :
504 case HANDLE_RELATIVE_FONT_HEIGHT_OPERATORS :
505 case HANDLE_RELATIVE_FONT_HEIGHT_LIMITS :
507 sal_Int16 nVal = 0;
508 *pValues >>= nVal;
509 if(nVal < 1)
510 throw IllegalArgumentException();
511 aFormat.SetRelSize((*ppEntries)->mnMemberId, nVal);
513 break;
515 case HANDLE_IS_TEXT_MODE :
517 aFormat.SetTextmode(*o3tl::doAccess<bool>(*pValues));
519 break;
521 case HANDLE_GREEK_CHAR_STYLE :
523 sal_Int16 nVal = 0;
524 *pValues >>= nVal;
525 if (nVal < 0 || nVal > 2)
526 throw IllegalArgumentException();
527 aFormat.SetGreekCharStyle( nVal );
529 break;
531 case HANDLE_ALIGNMENT :
533 // SmHorAlign uses the same values as HorizontalAlignment
534 sal_Int16 nVal = 0;
535 *pValues >>= nVal;
536 if(nVal < 0 || nVal > 2)
537 throw IllegalArgumentException();
538 aFormat.SetHorAlign(static_cast<SmHorAlign>(nVal));
540 break;
542 case HANDLE_RELATIVE_SPACING :
543 case HANDLE_RELATIVE_LINE_SPACING :
544 case HANDLE_RELATIVE_ROOT_SPACING :
545 case HANDLE_RELATIVE_INDEX_SUPERSCRIPT :
546 case HANDLE_RELATIVE_INDEX_SUBSCRIPT :
547 case HANDLE_RELATIVE_FRACTION_NUMERATOR_HEIGHT :
548 case HANDLE_RELATIVE_FRACTION_DENOMINATOR_DEPTH:
549 case HANDLE_RELATIVE_FRACTION_BAR_EXCESS_LENGTH:
550 case HANDLE_RELATIVE_FRACTION_BAR_LINE_WEIGHT :
551 case HANDLE_RELATIVE_UPPER_LIMIT_DISTANCE :
552 case HANDLE_RELATIVE_LOWER_LIMIT_DISTANCE :
553 case HANDLE_RELATIVE_BRACKET_EXCESS_SIZE :
554 case HANDLE_RELATIVE_BRACKET_DISTANCE :
555 case HANDLE_RELATIVE_SCALE_BRACKET_EXCESS_SIZE :
556 case HANDLE_RELATIVE_MATRIX_LINE_SPACING :
557 case HANDLE_RELATIVE_MATRIX_COLUMN_SPACING :
558 case HANDLE_RELATIVE_SYMBOL_PRIMARY_HEIGHT :
559 case HANDLE_RELATIVE_SYMBOL_MINIMUM_HEIGHT :
560 case HANDLE_RELATIVE_OPERATOR_EXCESS_SIZE :
561 case HANDLE_RELATIVE_OPERATOR_SPACING :
562 case HANDLE_LEFT_MARGIN :
563 case HANDLE_RIGHT_MARGIN :
564 case HANDLE_TOP_MARGIN :
565 case HANDLE_BOTTOM_MARGIN :
567 sal_Int16 nVal = 0;
568 *pValues >>= nVal;
569 if(nVal < 0)
570 throw IllegalArgumentException();
571 aFormat.SetDistance((*ppEntries)->mnMemberId, nVal);
573 break;
574 case HANDLE_IS_SCALE_ALL_BRACKETS :
575 aFormat.SetScaleNormalBrackets(*o3tl::doAccess<bool>(*pValues));
576 break;
577 case HANDLE_PRINTER_NAME:
579 // embedded documents just ignore this property for now
580 if ( pDocSh->GetCreateMode() != SfxObjectCreateMode::EMBEDDED )
582 SfxPrinter *pPrinter = pDocSh->GetPrinter ( );
583 if (pPrinter)
585 OUString sPrinterName;
586 if ( !(*pValues >>= sPrinterName) )
587 throw IllegalArgumentException();
589 if ( !sPrinterName.isEmpty() )
591 VclPtrInstance<SfxPrinter> pNewPrinter( pPrinter->GetOptions().Clone(), sPrinterName );
592 if (pNewPrinter->IsKnown())
593 pDocSh->SetPrinter ( pNewPrinter );
594 else
595 pNewPrinter.disposeAndClear();
600 break;
601 case HANDLE_PRINTER_SETUP:
603 Sequence < sal_Int8 > aSequence;
604 if ( !(*pValues >>= aSequence) )
605 throw IllegalArgumentException();
607 sal_uInt32 nSize = aSequence.getLength();
608 SvMemoryStream aStream ( aSequence.getArray(), nSize, StreamMode::READ );
609 aStream.Seek ( STREAM_SEEK_TO_BEGIN );
610 static sal_uInt16 const nRange[] =
612 SID_PRINTSIZE, SID_PRINTSIZE,
613 SID_PRINTZOOM, SID_PRINTZOOM,
614 SID_PRINTTITLE, SID_PRINTTITLE,
615 SID_PRINTTEXT, SID_PRINTTEXT,
616 SID_PRINTFRAME, SID_PRINTFRAME,
617 SID_NO_RIGHT_SPACES, SID_NO_RIGHT_SPACES,
618 SID_SAVE_ONLY_USED_SYMBOLS, SID_SAVE_ONLY_USED_SYMBOLS,
619 SID_AUTO_CLOSE_BRACKETS, SID_AUTO_CLOSE_BRACKETS,
622 auto pItemSet = std::make_unique<SfxItemSet>( SmDocShell::GetPool(), nRange );
623 SmModule *pp = SM_MOD();
624 pp->GetConfig()->ConfigToItemSet(*pItemSet);
625 VclPtr<SfxPrinter> pPrinter = SfxPrinter::Create ( aStream, std::move(pItemSet) );
627 pDocSh->SetPrinter( pPrinter );
629 break;
630 case HANDLE_SYMBOLS:
632 // this is set
633 Sequence < SymbolDescriptor > aSequence;
634 if ( !(*pValues >>= aSequence) )
635 throw IllegalArgumentException();
637 SmModule *pp = SM_MOD();
638 SmSymbolManager &rManager = pp->GetSymbolManager();
639 for (const SymbolDescriptor& rDescriptor : std::as_const(aSequence))
641 vcl::Font aFont;
642 aFont.SetFamilyName ( rDescriptor.sFontName );
643 aFont.SetCharSet ( static_cast < rtl_TextEncoding > (rDescriptor.nCharSet) );
644 aFont.SetFamily ( static_cast < FontFamily > (rDescriptor.nFamily ) );
645 aFont.SetPitch ( static_cast < FontPitch > (rDescriptor.nPitch ) );
646 aFont.SetWeight ( static_cast < FontWeight > (rDescriptor.nWeight ) );
647 aFont.SetItalic ( static_cast < FontItalic > (rDescriptor.nItalic ) );
648 SmSym aSymbol ( rDescriptor.sName, aFont, static_cast < sal_Unicode > (rDescriptor.nCharacter),
649 rDescriptor.sSymbolSet );
650 aSymbol.SetExportName ( rDescriptor.sExportName );
651 rManager.AddOrReplaceSymbol ( aSymbol );
654 break;
655 // #i33095# Security Options
656 case HANDLE_LOAD_READONLY :
658 if ( (*pValues).getValueType() != cppu::UnoType<bool>::get() )
659 throw IllegalArgumentException();
660 bool bReadonly = false;
661 if ( *pValues >>= bReadonly )
662 pDocSh->SetLoadReadonly( bReadonly );
663 break;
665 case HANDLE_INTEROP_GRAB_BAG:
666 setGrabBagItem(*pValues);
667 break;
668 case HANDLE_SAVE_THUMBNAIL:
670 if ((*pValues).getValueType() != cppu::UnoType<bool>::get())
671 throw IllegalArgumentException();
672 bool bThumbnail = false;
673 if (*pValues >>= bThumbnail)
674 pDocSh->SetUseThumbnailSave(bThumbnail);
676 break;
680 pDocSh->SetFormat( aFormat );
682 // #i67283# since about all of the above changes are likely to change
683 // the formula size we have to recalculate the vis-area now
684 pDocSh->SetVisArea( tools::Rectangle( Point(0, 0), pDocSh->GetSize() ) );
687 void SmModel::_getPropertyValues( const PropertyMapEntry **ppEntries, Any *pValue )
689 SmDocShell *pDocSh = static_cast < SmDocShell * > (GetObjectShell());
691 if ( nullptr == pDocSh )
692 throw UnknownPropertyException();
694 const SmFormat & aFormat = pDocSh->GetFormat();
696 for (; *ppEntries; ppEntries++, pValue++ )
698 switch ( (*ppEntries)->mnHandle )
700 case HANDLE_FORMULA:
701 *pValue <<= pDocSh->GetText();
702 break;
703 case HANDLE_FONT_NAME_VARIABLES :
704 case HANDLE_FONT_NAME_FUNCTIONS :
705 case HANDLE_FONT_NAME_NUMBERS :
706 case HANDLE_FONT_NAME_TEXT :
707 case HANDLE_CUSTOM_FONT_NAME_SERIF :
708 case HANDLE_CUSTOM_FONT_NAME_SANS :
709 case HANDLE_CUSTOM_FONT_NAME_FIXED :
711 const SmFace & rFace = aFormat.GetFont((*ppEntries)->mnMemberId);
712 *pValue <<= rFace.GetFamilyName();
714 break;
715 case HANDLE_CUSTOM_FONT_FIXED_POSTURE:
716 case HANDLE_CUSTOM_FONT_SANS_POSTURE :
717 case HANDLE_CUSTOM_FONT_SERIF_POSTURE:
718 case HANDLE_FONT_VARIABLES_POSTURE :
719 case HANDLE_FONT_FUNCTIONS_POSTURE :
720 case HANDLE_FONT_NUMBERS_POSTURE :
721 case HANDLE_FONT_TEXT_POSTURE :
723 const SmFace & rFace = aFormat.GetFont((*ppEntries)->mnMemberId);
724 *pValue <<= IsItalic( rFace );
726 break;
727 case HANDLE_CUSTOM_FONT_FIXED_WEIGHT :
728 case HANDLE_CUSTOM_FONT_SANS_WEIGHT :
729 case HANDLE_CUSTOM_FONT_SERIF_WEIGHT :
730 case HANDLE_FONT_VARIABLES_WEIGHT :
731 case HANDLE_FONT_FUNCTIONS_WEIGHT :
732 case HANDLE_FONT_NUMBERS_WEIGHT :
733 case HANDLE_FONT_TEXT_WEIGHT :
735 const SmFace & rFace = aFormat.GetFont((*ppEntries)->mnMemberId);
736 *pValue <<= IsBold( rFace );
738 break;
739 case HANDLE_BASE_FONT_HEIGHT :
741 // Point!
742 *pValue <<= sal_Int16(
743 SmRoundFraction(
744 Sm100th_mmToPts(aFormat.GetBaseSize().Height())));
746 break;
747 case HANDLE_RELATIVE_FONT_HEIGHT_TEXT :
748 case HANDLE_RELATIVE_FONT_HEIGHT_INDICES :
749 case HANDLE_RELATIVE_FONT_HEIGHT_FUNCTIONS :
750 case HANDLE_RELATIVE_FONT_HEIGHT_OPERATORS :
751 case HANDLE_RELATIVE_FONT_HEIGHT_LIMITS :
752 *pValue <<= static_cast<sal_Int16>(aFormat.GetRelSize((*ppEntries)->mnMemberId));
753 break;
755 case HANDLE_IS_TEXT_MODE :
756 *pValue <<= aFormat.IsTextmode();
757 break;
759 case HANDLE_GREEK_CHAR_STYLE :
760 *pValue <<= aFormat.GetGreekCharStyle();
761 break;
763 case HANDLE_ALIGNMENT :
764 // SmHorAlign uses the same values as HorizontalAlignment
765 *pValue <<= static_cast<sal_Int16>(aFormat.GetHorAlign());
766 break;
768 case HANDLE_RELATIVE_SPACING :
769 case HANDLE_RELATIVE_LINE_SPACING :
770 case HANDLE_RELATIVE_ROOT_SPACING :
771 case HANDLE_RELATIVE_INDEX_SUPERSCRIPT :
772 case HANDLE_RELATIVE_INDEX_SUBSCRIPT :
773 case HANDLE_RELATIVE_FRACTION_NUMERATOR_HEIGHT :
774 case HANDLE_RELATIVE_FRACTION_DENOMINATOR_DEPTH:
775 case HANDLE_RELATIVE_FRACTION_BAR_EXCESS_LENGTH:
776 case HANDLE_RELATIVE_FRACTION_BAR_LINE_WEIGHT :
777 case HANDLE_RELATIVE_UPPER_LIMIT_DISTANCE :
778 case HANDLE_RELATIVE_LOWER_LIMIT_DISTANCE :
779 case HANDLE_RELATIVE_BRACKET_EXCESS_SIZE :
780 case HANDLE_RELATIVE_BRACKET_DISTANCE :
781 case HANDLE_RELATIVE_SCALE_BRACKET_EXCESS_SIZE :
782 case HANDLE_RELATIVE_MATRIX_LINE_SPACING :
783 case HANDLE_RELATIVE_MATRIX_COLUMN_SPACING :
784 case HANDLE_RELATIVE_SYMBOL_PRIMARY_HEIGHT :
785 case HANDLE_RELATIVE_SYMBOL_MINIMUM_HEIGHT :
786 case HANDLE_RELATIVE_OPERATOR_EXCESS_SIZE :
787 case HANDLE_RELATIVE_OPERATOR_SPACING :
788 case HANDLE_LEFT_MARGIN :
789 case HANDLE_RIGHT_MARGIN :
790 case HANDLE_TOP_MARGIN :
791 case HANDLE_BOTTOM_MARGIN :
792 *pValue <<= static_cast<sal_Int16>(aFormat.GetDistance((*ppEntries)->mnMemberId));
793 break;
794 case HANDLE_IS_SCALE_ALL_BRACKETS :
795 *pValue <<= aFormat.IsScaleNormalBrackets();
796 break;
797 case HANDLE_PRINTER_NAME:
799 SfxPrinter *pPrinter = pDocSh->GetPrinter ( );
800 *pValue <<= pPrinter ? pPrinter->GetName() : OUString();
802 break;
803 case HANDLE_PRINTER_SETUP:
805 SfxPrinter *pPrinter = pDocSh->GetPrinter ();
806 if (pPrinter)
808 SvMemoryStream aStream;
809 pPrinter->Store( aStream );
810 sal_uInt32 nSize = aStream.TellEnd();
811 aStream.Seek ( STREAM_SEEK_TO_BEGIN );
812 Sequence < sal_Int8 > aSequence ( nSize );
813 aStream.ReadBytes(aSequence.getArray(), nSize);
814 *pValue <<= aSequence;
817 break;
818 case HANDLE_SYMBOLS:
819 case HANDLE_USED_SYMBOLS:
821 const bool bUsedSymbolsOnly = (*ppEntries)->mnHandle == HANDLE_USED_SYMBOLS;
822 const std::set< OUString > &rUsedSymbols = pDocSh->GetUsedSymbols();
824 // this is get
825 SmModule *pp = SM_MOD();
826 const SmSymbolManager &rManager = pp->GetSymbolManager();
827 vector < const SmSym * > aVector;
829 const SymbolPtrVec_t aSymbols( rManager.GetSymbols() );
830 for (const SmSym* pSymbol : aSymbols)
832 if (pSymbol && !pSymbol->IsPredefined() &&
833 (!bUsedSymbolsOnly ||
834 rUsedSymbols.find( pSymbol->GetName() ) != rUsedSymbols.end()))
835 aVector.push_back ( pSymbol );
837 Sequence < SymbolDescriptor > aSequence ( aVector.size() );
838 SymbolDescriptor * pDescriptor = aSequence.getArray();
840 for (const SmSym* pSymbol : aVector)
842 pDescriptor->sName = pSymbol->GetName();
843 pDescriptor->sExportName = pSymbol->GetExportName();
844 pDescriptor->sSymbolSet = pSymbol->GetSymbolSetName();
845 pDescriptor->nCharacter = static_cast < sal_Int32 > (pSymbol->GetCharacter());
847 vcl::Font rFont = pSymbol->GetFace();
848 pDescriptor->sFontName = rFont.GetFamilyName();
849 pDescriptor->nCharSet = sal::static_int_cast< sal_Int16 >(rFont.GetCharSet());
850 pDescriptor->nFamily = sal::static_int_cast< sal_Int16 >(rFont.GetFamilyType());
851 pDescriptor->nPitch = sal::static_int_cast< sal_Int16 >(rFont.GetPitch());
852 pDescriptor->nWeight = sal::static_int_cast< sal_Int16 >(rFont.GetWeight());
853 pDescriptor->nItalic = sal::static_int_cast< sal_Int16 >(rFont.GetItalic());
854 pDescriptor++;
856 *pValue <<= aSequence;
858 break;
859 case HANDLE_BASIC_LIBRARIES:
860 *pValue <<= pDocSh->GetBasicContainer();
861 break;
862 case HANDLE_DIALOG_LIBRARIES:
863 *pValue <<= pDocSh->GetDialogContainer();
864 break;
865 case HANDLE_RUNTIME_UID:
866 *pValue <<= getRuntimeUID();
867 break;
868 // #i33095# Security Options
869 case HANDLE_LOAD_READONLY :
871 *pValue <<= pDocSh->IsLoadReadonly();
872 break;
874 // #i972#
875 case HANDLE_BASELINE:
877 if ( !pDocSh->GetFormulaTree() )
878 pDocSh->Parse();
879 if ( pDocSh->GetFormulaTree() )
881 pDocSh->ArrangeFormula();
883 *pValue <<= static_cast<sal_Int32>( pDocSh->GetFormulaTree()->GetFormulaBaseline() );
885 break;
887 case HANDLE_INTEROP_GRAB_BAG:
888 getGrabBagItem(*pValue);
889 break;
890 case HANDLE_SAVE_THUMBNAIL:
892 *pValue <<= pDocSh->IsUseThumbnailSave();
894 break;
900 sal_Int32 SAL_CALL SmModel::getRendererCount(
901 const uno::Any& /*rSelection*/,
902 const uno::Sequence< beans::PropertyValue >& /*xOptions*/ )
904 return 1;
908 static Size lcl_GuessPaperSize()
910 Size aRes;
911 const LocaleDataWrapper& rLocWrp( AllSettings().GetLocaleDataWrapper() );
912 if( MeasurementSystem::Metric == rLocWrp.getMeasurementSystemEnum() )
914 // in 100th mm
915 PaperInfo aInfo( PAPER_A4 );
916 aRes.setWidth( aInfo.getWidth() );
917 aRes.setHeight( aInfo.getHeight() );
919 else
921 // in 100th mm
922 PaperInfo aInfo( PAPER_LETTER );
923 aRes.setWidth( aInfo.getWidth() );
924 aRes.setHeight( aInfo.getHeight() );
926 return aRes;
929 uno::Sequence< beans::PropertyValue > SAL_CALL SmModel::getRenderer(
930 sal_Int32 nRenderer,
931 const uno::Any& /*rSelection*/,
932 const uno::Sequence< beans::PropertyValue >& /*rxOptions*/ )
934 SolarMutexGuard aGuard;
936 if (0 != nRenderer)
937 throw IllegalArgumentException();
939 SmDocShell *pDocSh = static_cast < SmDocShell * >( GetObjectShell() );
940 if (!pDocSh)
941 throw RuntimeException();
943 SmPrinterAccess aPrinterAccess( *pDocSh );
944 Printer *pPrinter = aPrinterAccess.GetPrinter();
945 Size aPrtPaperSize ( pPrinter->GetPaperSize() );
947 // if paper size is 0 (usually if no 'real' printer is found),
948 // guess the paper size
949 if (aPrtPaperSize.IsEmpty())
950 aPrtPaperSize = lcl_GuessPaperSize();
951 awt::Size aPageSize( aPrtPaperSize.Width(), aPrtPaperSize.Height() );
953 uno::Sequence< beans::PropertyValue > aRenderer(1);
954 PropertyValue &rValue = aRenderer.getArray()[0];
955 rValue.Name = "PageSize";
956 rValue.Value <<= aPageSize;
958 if (!m_pPrintUIOptions)
959 m_pPrintUIOptions.reset(new SmPrintUIOptions);
960 m_pPrintUIOptions->appendPrintUIOptions( aRenderer );
962 return aRenderer;
965 void SAL_CALL SmModel::render(
966 sal_Int32 nRenderer,
967 const uno::Any& rSelection,
968 const uno::Sequence< beans::PropertyValue >& rxOptions )
970 SolarMutexGuard aGuard;
972 if (0 != nRenderer)
973 throw IllegalArgumentException();
975 SmDocShell *pDocSh = static_cast < SmDocShell * >( GetObjectShell() );
976 if (!pDocSh)
977 throw RuntimeException();
979 // get device to be rendered in
980 uno::Reference< awt::XDevice > xRenderDevice;
981 for (const auto& rxOption : rxOptions)
983 if( rxOption.Name == "RenderDevice" )
984 rxOption.Value >>= xRenderDevice;
987 if (!xRenderDevice.is())
988 return;
990 VCLXDevice* pDevice = comphelper::getUnoTunnelImplementation<VCLXDevice>( xRenderDevice );
991 VclPtr< OutputDevice> pOut = pDevice ? pDevice->GetOutputDevice()
992 : VclPtr< OutputDevice >();
993 if (!pOut)
994 throw RuntimeException();
996 pOut->SetMapMode(MapMode(MapUnit::Map100thMM));
998 uno::Reference< frame::XModel > xModel;
999 rSelection >>= xModel;
1000 if (xModel != pDocSh->GetModel())
1001 return;
1003 //!! when called via API we may not have an active view
1004 //!! thus we go and look for a view that can be used.
1005 SfxViewShell* pViewSh = SfxViewShell::GetFirst( false /* search non-visible views as well*/, checkSfxViewShell<SmViewShell> );
1006 while (pViewSh && pViewSh->GetObjectShell() != pDocSh)
1007 pViewSh = SfxViewShell::GetNext( *pViewSh, false /* search non-visible views as well*/, checkSfxViewShell<SmViewShell> );
1008 SmViewShell *pView = dynamic_cast< SmViewShell *>( pViewSh );
1009 SAL_WARN_IF( !pView, "starmath", "SmModel::render : no SmViewShell found" );
1011 if (!pView)
1012 return;
1014 SmPrinterAccess aPrinterAccess( *pDocSh );
1015 Printer *pPrinter = aPrinterAccess.GetPrinter();
1017 Size aPrtPaperSize ( pPrinter->GetPaperSize() );
1018 Size aOutputSize ( pPrinter->GetOutputSize() );
1019 Point aPrtPageOffset( pPrinter->GetPageOffset() );
1021 // no real printer ??
1022 if (aPrtPaperSize.IsEmpty())
1024 aPrtPaperSize = lcl_GuessPaperSize();
1025 // factors from Windows DIN A4
1026 aOutputSize = Size( static_cast<tools::Long>(aPrtPaperSize.Width() * 0.941),
1027 static_cast<tools::Long>(aPrtPaperSize.Height() * 0.961));
1028 aPrtPageOffset = Point( static_cast<tools::Long>(aPrtPaperSize.Width() * 0.0250),
1029 static_cast<tools::Long>(aPrtPaperSize.Height() * 0.0214));
1031 tools::Rectangle OutputRect( Point(), aOutputSize );
1034 // set minimum top and bottom border
1035 if (aPrtPageOffset.Y() < 2000)
1036 OutputRect.AdjustTop(2000 - aPrtPageOffset.Y() );
1037 if ((aPrtPaperSize.Height() - (aPrtPageOffset.Y() + OutputRect.Bottom())) < 2000)
1038 OutputRect.AdjustBottom( -(2000 - (aPrtPaperSize.Height() -
1039 (aPrtPageOffset.Y() + OutputRect.Bottom()))) );
1041 // set minimum left and right border
1042 if (aPrtPageOffset.X() < 2500)
1043 OutputRect.AdjustLeft(2500 - aPrtPageOffset.X() );
1044 if ((aPrtPaperSize.Width() - (aPrtPageOffset.X() + OutputRect.Right())) < 1500)
1045 OutputRect.AdjustRight( -(1500 - (aPrtPaperSize.Width() -
1046 (aPrtPageOffset.X() + OutputRect.Right()))) );
1048 if (!m_pPrintUIOptions)
1049 m_pPrintUIOptions.reset(new SmPrintUIOptions);
1050 m_pPrintUIOptions->processProperties( rxOptions );
1052 pView->Impl_Print( *pOut, *m_pPrintUIOptions, OutputRect );
1054 // release SmPrintUIOptions when everything is done.
1055 // That way, when SmPrintUIOptions is needed again it will read the latest configuration settings in its c-tor.
1056 if (m_pPrintUIOptions->getBoolValue( "IsLastPage" ))
1058 m_pPrintUIOptions.reset();
1062 void SAL_CALL SmModel::setParent( const uno::Reference< uno::XInterface >& xParent)
1064 SolarMutexGuard aGuard;
1065 SfxBaseModel::setParent( xParent );
1066 if (SfxObjectShell* pDoc = SfxObjectShell::GetShellFromComponent(xParent))
1067 GetObjectShell()->OnDocumentPrinterChanged(pDoc->GetDocumentPrinter());
1070 void SmModel::writeFormulaOoxml(
1071 ::sax_fastparser::FSHelperPtr const pSerializer,
1072 oox::core::OoxmlVersion const version,
1073 oox::drawingml::DocumentType const documentType, sal_Int8 nAlign)
1075 static_cast<SmDocShell*>(GetObjectShell())->writeFormulaOoxml(pSerializer, version, documentType, nAlign);
1078 void SmModel::writeFormulaRtf(OStringBuffer& rBuffer, rtl_TextEncoding nEncoding)
1080 static_cast<SmDocShell*>(GetObjectShell())->writeFormulaRtf(rBuffer, nEncoding);
1083 void SmModel::readFormulaOoxml( oox::formulaimport::XmlStream& stream )
1085 static_cast< SmDocShell* >( GetObjectShell())->readFormulaOoxml( stream );
1088 Size SmModel::getFormulaSize() const
1090 return static_cast< SmDocShell* >( GetObjectShell())->GetSize();
1093 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */