xref: /trunk/main/starmath/source/unomodel.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_starmath.hxx"
30 
31 
32 #include <vos/mutex.hxx>
33 #include <osl/mutex.hxx>
34 #include <sfx2/printer.hxx>
35 #include <vcl/svapp.hxx>
36 #include <svtools/ctrltool.hxx>
37 #include <svl/itemprop.hxx>
38 #include <unotools/localedatawrapper.hxx>
39 #include <unotools/processfactory.hxx>
40 #include <editeng/paperinf.hxx>
41 #include <vcl/settings.hxx>
42 #include <vcl/print.hxx>
43 #include <toolkit/awt/vclxdevice.hxx>
44 #include <com/sun/star/beans/PropertyState.hpp>
45 #include <com/sun/star/beans/PropertyAttribute.hpp>
46 #include <com/sun/star/formula/SymbolDescriptor.hpp>
47 #include <com/sun/star/awt/Size.hpp>
48 #include <com/sun/star/script/XLibraryContainer.hpp>
49 #include <xmloff/xmluconv.hxx>
50 #include <rtl/ustrbuf.hxx>
51 #include <comphelper/propertysetinfo.hxx>
52 #include <unotools/moduleoptions.hxx>
53 
54 #include <unomodel.hxx>
55 #include <document.hxx>
56 #include <view.hxx>
57 #include <symbol.hxx>
58 #include <starmath.hrc>
59 #include <config.hxx>
60 #include <smdll.hxx>
61 
62 using namespace ::vos;
63 using namespace ::rtl;
64 using namespace ::cppu;
65 using namespace ::std;
66 using namespace ::comphelper;
67 using namespace ::com::sun::star;
68 using namespace ::com::sun::star::uno;
69 using namespace ::com::sun::star::beans;
70 using namespace ::com::sun::star::lang;
71 using namespace ::com::sun::star::formula;
72 using namespace ::com::sun::star::view;
73 using namespace ::com::sun::star::script;
74 
75 
76 #define TWIP_TO_MM100(TWIP)     ((TWIP) >= 0 ? (((TWIP)*127L+36L)/72L) : (((TWIP)*127L-36L)/72L))
77 #define MM100_TO_TWIP(MM100)    ((MM100) >= 0 ? (((MM100)*72L+63L)/127L) : (((MM100)*72L-63L)/127L))
78 
79 ////////////////////////////////////////////////////////////
80 
81 SmPrintUIOptions::SmPrintUIOptions()
82 {
83     ResStringArray      aLocalizedStrings( SmResId( RID_PRINTUIOPTIONS ) );
84     DBG_ASSERT( aLocalizedStrings.Count() >= 9, "resource incomplete" );
85     if( aLocalizedStrings.Count() < 9 ) // bad resource ?
86         return;
87 
88     SmModule *pp = SM_MOD();
89     SmConfig *pConfig = pp->GetConfig();
90     DBG_ASSERT( pConfig, "SmConfig not found" );
91     if (!pConfig)
92         return;
93 
94     // create sequence of print UI options
95     // (Actually IsIgnoreSpacesRight is a parser option. Without it we need only 8 properties here.)
96     m_aUIProperties.realloc( 9 );
97 
98     // create Section for formula (results in an extra tab page in dialog)
99     SvtModuleOptions aOpt;
100     String aAppGroupname( aLocalizedStrings.GetString( 0 ) );
101     aAppGroupname.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "%s" ) ),
102                                     aOpt.GetModuleName( SvtModuleOptions::E_SMATH ) );
103     m_aUIProperties[0].Value = getGroupControlOpt( aAppGroupname, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".HelpID:vcl:PrintDialog:TabPage:AppPage" ) ) );
104 
105     // create subgroup for print options
106     m_aUIProperties[1].Value = getSubgroupControlOpt( aLocalizedStrings.GetString( 1 ), rtl::OUString() );
107 
108     // create a bool option for title row (matches to SID_PRINTTITLE)
109     m_aUIProperties[2].Value = getBoolControlOpt( aLocalizedStrings.GetString( 2 ),
110                                                   rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".HelpID:vcl:PrintDialog:TitleRow:CheckBox" ) ),
111                                                   rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( PRTUIOPT_TITLE_ROW ) ),
112                                                   pConfig->IsPrintTitle() );
113     // create a bool option for formula text (matches to SID_PRINTTEXT)
114     m_aUIProperties[3].Value = getBoolControlOpt( aLocalizedStrings.GetString( 3 ),
115                                                   rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".HelpID:vcl:PrintDialog:FormulaText:CheckBox" ) ),
116                                                   rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( PRTUIOPT_FORMULA_TEXT ) ),
117                                                   pConfig->IsPrintFormulaText() );
118     // create a bool option for border (matches to SID_PRINTFRAME)
119     m_aUIProperties[4].Value = getBoolControlOpt( aLocalizedStrings.GetString( 4 ),
120                                                   rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".HelpID:vcl:PrintDialog:Border:CheckBox" ) ),
121                                                   rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( PRTUIOPT_BORDER ) ),
122                                                   pConfig->IsPrintFrame() );
123 
124     // create subgroup for print format
125     m_aUIProperties[5].Value = getSubgroupControlOpt( aLocalizedStrings.GetString( 5 ), rtl::OUString() );
126 
127     // create a radio button group for print format (matches to SID_PRINTSIZE)
128     Sequence< rtl::OUString > aChoices( 3 );
129     aChoices[0] = aLocalizedStrings.GetString( 6 );
130     aChoices[1] = aLocalizedStrings.GetString( 7 );
131     aChoices[2] = aLocalizedStrings.GetString( 8 );
132     Sequence< rtl::OUString > aHelpIds( 3 );
133     aHelpIds[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".HelpID:vcl:PrintDialog:PrintFormat:RadioButton:0" ) );
134     aHelpIds[1] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".HelpID:vcl:PrintDialog:PrintFormat:RadioButton:1" ) );
135     aHelpIds[2] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".HelpID:vcl:PrintDialog:PrintFormat:RadioButton:2" ) );
136     OUString aPrintFormatProp( RTL_CONSTASCII_USTRINGPARAM( PRTUIOPT_PRINT_FORMAT ) );
137     m_aUIProperties[6].Value = getChoiceControlOpt( rtl::OUString(),
138                                                     aHelpIds,
139                                                     aPrintFormatProp,
140                                                     aChoices, static_cast< sal_Int32 >(pConfig->GetPrintSize())
141                                                     );
142 
143     // create a numeric box for scale dependent on PrintFormat = "Scaling" (matches to SID_PRINTZOOM)
144     vcl::PrinterOptionsHelper::UIControlOptions aRangeOpt( aPrintFormatProp, 2, sal_True );
145     m_aUIProperties[ 7 ].Value = getRangeControlOpt( rtl::OUString(),
146                                                      rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".HelpID:vcl:PrintDialog:PrintScale:NumericField" ) ),
147                                                      rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( PRTUIOPT_PRINT_SCALE ) ),
148                                                      pConfig->GetPrintZoomFactor(),    // initial value
149                                                      10,     // min value
150                                                      1000,   // max value
151                                                      aRangeOpt );
152 
153     Sequence< PropertyValue > aHintNoLayoutPage( 1 );
154     aHintNoLayoutPage[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HintNoLayoutPage" ) );
155     aHintNoLayoutPage[0].Value = makeAny( sal_True );
156     m_aUIProperties[8].Value <<= aHintNoLayoutPage;
157 
158 // IsIgnoreSpacesRight is a parser option! Thus we don't add it to the printer UI.
159 //
160 //    // create subgroup for misc options
161 //    m_aUIProperties[8].Value = getSubgroupControlOpt( aLocalizedStrings.GetString( 9 ) );
162 //
163 //    // create a bool option for ignore spacing (matches to SID_NO_RIGHT_SPACES)
164 //    m_aUIProperties[9].Value = getBoolControlOpt( aLocalizedStrings.GetString( 10 ),
165 //                                                  rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( PRTUIOPT_NO_RIGHT_SPACE ) ),
166 //                                                  pConfig->IsIgnoreSpacesRight() );
167 }
168 
169 
170 ////////////////////////////////////////////////////////////
171 //
172 // class SmModel
173 //
174 
175 // values from com/sun/star/beans/PropertyAttribute
176 #define PROPERTY_NONE        0
177 #define PROPERTY_READONLY   16
178 
179 enum SmModelPropertyHandles
180 {
181     HANDLE_FORMULA,
182     HANDLE_FONT_NAME_VARIABLES,
183     HANDLE_FONT_NAME_FUNCTIONS,
184     HANDLE_FONT_NAME_NUMBERS,
185     HANDLE_FONT_NAME_TEXT,
186     HANDLE_CUSTOM_FONT_NAME_SERIF,
187     HANDLE_CUSTOM_FONT_NAME_SANS,
188     HANDLE_CUSTOM_FONT_NAME_FIXED,
189     HANDLE_CUSTOM_FONT_FIXED_POSTURE,
190     HANDLE_CUSTOM_FONT_FIXED_WEIGHT,
191     HANDLE_CUSTOM_FONT_SANS_POSTURE,
192     HANDLE_CUSTOM_FONT_SANS_WEIGHT,
193     HANDLE_CUSTOM_FONT_SERIF_POSTURE,
194     HANDLE_CUSTOM_FONT_SERIF_WEIGHT,
195     HANDLE_FONT_VARIABLES_POSTURE,
196     HANDLE_FONT_VARIABLES_WEIGHT,
197     HANDLE_FONT_FUNCTIONS_POSTURE,
198     HANDLE_FONT_FUNCTIONS_WEIGHT,
199     HANDLE_FONT_NUMBERS_POSTURE,
200     HANDLE_FONT_NUMBERS_WEIGHT,
201     HANDLE_FONT_TEXT_POSTURE,
202     HANDLE_FONT_TEXT_WEIGHT,
203     HANDLE_BASE_FONT_HEIGHT,
204     HANDLE_RELATIVE_FONT_HEIGHT_TEXT,
205     HANDLE_RELATIVE_FONT_HEIGHT_INDICES,
206     HANDLE_RELATIVE_FONT_HEIGHT_FUNCTIONS,
207     HANDLE_RELATIVE_FONT_HEIGHT_OPERATORS,
208     HANDLE_RELATIVE_FONT_HEIGHT_LIMITS,
209     HANDLE_IS_TEXT_MODE,
210     HANDLE_GREEK_CHAR_STYLE,
211     HANDLE_ALIGNMENT,
212     HANDLE_RELATIVE_SPACING,
213     HANDLE_RELATIVE_LINE_SPACING,
214     HANDLE_RELATIVE_ROOT_SPACING,
215     HANDLE_RELATIVE_INDEX_SUPERSCRIPT,
216     HANDLE_RELATIVE_INDEX_SUBSCRIPT,
217     HANDLE_RELATIVE_FRACTION_NUMERATOR_HEIGHT,
218     HANDLE_RELATIVE_FRACTION_DENOMINATOR_DEPTH,
219     HANDLE_RELATIVE_FRACTION_BAR_EXCESS_LENGTH,
220     HANDLE_RELATIVE_FRACTION_BAR_LINE_WEIGHT,
221     HANDLE_RELATIVE_UPPER_LIMIT_DISTANCE,
222     HANDLE_RELATIVE_LOWER_LIMIT_DISTANCE,
223     HANDLE_RELATIVE_BRACKET_EXCESS_SIZE,
224     HANDLE_RELATIVE_BRACKET_DISTANCE,
225     HANDLE_IS_SCALE_ALL_BRACKETS,
226     HANDLE_RELATIVE_SCALE_BRACKET_EXCESS_SIZE,
227     HANDLE_RELATIVE_MATRIX_LINE_SPACING,
228     HANDLE_RELATIVE_MATRIX_COLUMN_SPACING,
229     HANDLE_RELATIVE_SYMBOL_PRIMARY_HEIGHT,
230     HANDLE_RELATIVE_SYMBOL_MINIMUM_HEIGHT,
231     HANDLE_RELATIVE_OPERATOR_EXCESS_SIZE,
232     HANDLE_RELATIVE_OPERATOR_SPACING,
233     HANDLE_LEFT_MARGIN,
234     HANDLE_RIGHT_MARGIN,
235     HANDLE_TOP_MARGIN,
236     HANDLE_BOTTOM_MARGIN,
237     HANDLE_PRINTER_NAME,
238     HANDLE_PRINTER_SETUP,
239     HANDLE_SYMBOLS,
240     HANDLE_USED_SYMBOLS,
241     HANDLE_BASIC_LIBRARIES,     /* #93295# */
242     HANDLE_RUNTIME_UID,
243     // --> PB 2004-08-25 #i33095# Security Options
244     HANDLE_LOAD_READONLY,
245     // <--
246     HANDLE_DIALOG_LIBRARIES,     // #i73329#
247     HANDLE_BASELINE // 3.7.2010 #i972#
248 };
249 
250 PropertySetInfo * lcl_createModelPropertyInfo ()
251 {
252     static PropertyMapEntry aModelPropertyInfoMap[] =
253     {
254         { RTL_CONSTASCII_STRINGPARAM( "Alignment"                          ), HANDLE_ALIGNMENT                          ,       &::getCppuType((const sal_Int16*)0),    PROPERTY_NONE, 0},
255         { RTL_CONSTASCII_STRINGPARAM( "BaseFontHeight"                  ), HANDLE_BASE_FONT_HEIGHT                   ,      &::getCppuType((const sal_Int16*)0),    PROPERTY_NONE, 0},
256         { RTL_CONSTASCII_STRINGPARAM( "BasicLibraries"                  ), HANDLE_BASIC_LIBRARIES                   ,      &::getCppuType((const uno::Reference< script::XLibraryContainer > *)0),    PropertyAttribute::READONLY, 0},
257         { RTL_CONSTASCII_STRINGPARAM( "BottomMargin"                      ), HANDLE_BOTTOM_MARGIN                      ,        &::getCppuType((const sal_Int16*)0),    PROPERTY_NONE, DIS_BOTTOMSPACE             },
258         { RTL_CONSTASCII_STRINGPARAM( "CustomFontNameFixed"            ), HANDLE_CUSTOM_FONT_NAME_FIXED             ,       &::getCppuType((const OUString*)0),     PROPERTY_NONE, FNT_FIXED          },
259         { RTL_CONSTASCII_STRINGPARAM( "CustomFontNameSans"              ), HANDLE_CUSTOM_FONT_NAME_SANS              ,      &::getCppuType((const OUString*)0),     PROPERTY_NONE, FNT_SANS        },
260         { RTL_CONSTASCII_STRINGPARAM( "CustomFontNameSerif"             ), HANDLE_CUSTOM_FONT_NAME_SERIF             ,      &::getCppuType((const OUString*)0),     PROPERTY_NONE, FNT_SERIF          },
261         { RTL_CONSTASCII_STRINGPARAM( "DialogLibraries"                 ), HANDLE_DIALOG_LIBRARIES                   ,      &::getCppuType((const uno::Reference< script::XLibraryContainer > *)0),    PropertyAttribute::READONLY, 0},
262         { RTL_CONSTASCII_STRINGPARAM( "FontFixedIsBold"),     HANDLE_CUSTOM_FONT_FIXED_WEIGHT    ,  &::getBooleanCppuType(),  PROPERTY_NONE, FNT_FIXED},
263         { RTL_CONSTASCII_STRINGPARAM( "FontFixedIsItalic"), HANDLE_CUSTOM_FONT_FIXED_POSTURE   ,  &::getBooleanCppuType(),  PROPERTY_NONE, FNT_FIXED},
264         { RTL_CONSTASCII_STRINGPARAM( "FontFunctionsIsBold"),    HANDLE_FONT_FUNCTIONS_WEIGHT    ,  &::getBooleanCppuType(),            PROPERTY_NONE, FNT_FUNCTION},
265         { RTL_CONSTASCII_STRINGPARAM( "FontFunctionsIsItalic"),   HANDLE_FONT_FUNCTIONS_POSTURE   ,  &::getBooleanCppuType(),  PROPERTY_NONE, FNT_FUNCTION},
266         { RTL_CONSTASCII_STRINGPARAM( "FontNameFunctions"                ), HANDLE_FONT_NAME_FUNCTIONS                ,         &::getCppuType((const OUString*)0),     PROPERTY_NONE, FNT_FUNCTION },
267         { RTL_CONSTASCII_STRINGPARAM( "FontNameNumbers"                  ), HANDLE_FONT_NAME_NUMBERS                  ,         &::getCppuType((const OUString*)0),     PROPERTY_NONE, FNT_NUMBER        },
268         { RTL_CONSTASCII_STRINGPARAM( "FontNameText"                     ), HANDLE_FONT_NAME_TEXT                     ,         &::getCppuType((const OUString*)0),     PROPERTY_NONE, FNT_TEXT        },
269         { RTL_CONSTASCII_STRINGPARAM( "FontNameVariables"                ), HANDLE_FONT_NAME_VARIABLES                ,         &::getCppuType((const OUString*)0),     PROPERTY_NONE, FNT_VARIABLE },
270         { RTL_CONSTASCII_STRINGPARAM( "FontNumbersIsBold"),  HANDLE_FONT_NUMBERS_WEIGHT    ,  &::getBooleanCppuType(),              PROPERTY_NONE, FNT_NUMBER},
271         { RTL_CONSTASCII_STRINGPARAM( "FontNumbersIsItalic"),   HANDLE_FONT_NUMBERS_POSTURE   ,  &::getBooleanCppuType(),  PROPERTY_NONE, FNT_NUMBER},
272         { RTL_CONSTASCII_STRINGPARAM( "FontSansIsBold"),     HANDLE_CUSTOM_FONT_SANS_WEIGHT    ,  &::getBooleanCppuType(),              PROPERTY_NONE, FNT_SANS},
273         { RTL_CONSTASCII_STRINGPARAM( "FontSansIsItalic"),   HANDLE_CUSTOM_FONT_SANS_POSTURE   ,  &::getBooleanCppuType(),  PROPERTY_NONE, FNT_SANS},
274         { RTL_CONSTASCII_STRINGPARAM( "FontSerifIsBold"),    HANDLE_CUSTOM_FONT_SERIF_WEIGHT    ,  &::getBooleanCppuType(),             PROPERTY_NONE,  FNT_SERIF},
275         { RTL_CONSTASCII_STRINGPARAM( "FontSerifIsItalic"),   HANDLE_CUSTOM_FONT_SERIF_POSTURE   ,  &::getBooleanCppuType(),  PROPERTY_NONE, FNT_SERIF},
276         { RTL_CONSTASCII_STRINGPARAM( "FontTextIsBold"),     HANDLE_FONT_TEXT_WEIGHT    ,  &::getBooleanCppuType(),             PROPERTY_NONE, FNT_TEXT},
277         { RTL_CONSTASCII_STRINGPARAM( "FontTextIsItalic"),   HANDLE_FONT_TEXT_POSTURE   ,  &::getBooleanCppuType(),  PROPERTY_NONE, FNT_TEXT},
278         { RTL_CONSTASCII_STRINGPARAM( "FontVariablesIsBold"),    HANDLE_FONT_VARIABLES_WEIGHT    ,  &::getBooleanCppuType(),            PROPERTY_NONE, FNT_VARIABLE},
279         { RTL_CONSTASCII_STRINGPARAM( "FontVariablesIsItalic"),   HANDLE_FONT_VARIABLES_POSTURE,  &::getBooleanCppuType(),  PROPERTY_NONE, FNT_VARIABLE},
280         { RTL_CONSTASCII_STRINGPARAM( "Formula"                           ),    HANDLE_FORMULA                             ,        &::getCppuType((const OUString*)0),     PROPERTY_NONE, 0},
281         { RTL_CONSTASCII_STRINGPARAM( "IsScaleAllBrackets"              ), HANDLE_IS_SCALE_ALL_BRACKETS              ,      &::getBooleanCppuType(),    PROPERTY_NONE, 0},
282         { RTL_CONSTASCII_STRINGPARAM( "IsTextMode"                       ), HANDLE_IS_TEXT_MODE                       ,         &::getBooleanCppuType(),    PROPERTY_NONE, 0},
283         { RTL_CONSTASCII_STRINGPARAM( "GreekCharStyle" ),                   HANDLE_GREEK_CHAR_STYLE,    &::getCppuType((const sal_Int16*)0),    PROPERTY_NONE, 0},
284         { RTL_CONSTASCII_STRINGPARAM( "LeftMargin"                        ), HANDLE_LEFT_MARGIN                        ,        &::getCppuType((const sal_Int16*)0),    PROPERTY_NONE, DIS_LEFTSPACE                 },
285         { RTL_CONSTASCII_STRINGPARAM( "PrinterName"                    ), HANDLE_PRINTER_NAME                        ,      &::getCppuType((const OUString*)0),     PROPERTY_NONE, 0                  },
286         { RTL_CONSTASCII_STRINGPARAM( "PrinterSetup"                       ), HANDLE_PRINTER_SETUP                       ,      &::getCppuType((const Sequence < sal_Int8 >*)0),    PROPERTY_NONE, 0                  },
287         { RTL_CONSTASCII_STRINGPARAM( "RelativeBracketDistance"          ), HANDLE_RELATIVE_BRACKET_DISTANCE          ,         &::getCppuType((const sal_Int16*)0),    PROPERTY_NONE, DIS_BRACKETSPACE },
288         { RTL_CONSTASCII_STRINGPARAM( "RelativeBracketExcessSize"       ), HANDLE_RELATIVE_BRACKET_EXCESS_SIZE       ,      &::getCppuType((const sal_Int16*)0),    PROPERTY_NONE, DIS_BRACKETSIZE  },
289         { RTL_CONSTASCII_STRINGPARAM( "RelativeFontHeightFunctions"     ), HANDLE_RELATIVE_FONT_HEIGHT_FUNCTIONS     ,      &::getCppuType((const sal_Int16*)0),    PROPERTY_NONE, SIZ_FUNCTION},
290         { RTL_CONSTASCII_STRINGPARAM( "RelativeFontHeightIndices"       ), HANDLE_RELATIVE_FONT_HEIGHT_INDICES       ,      &::getCppuType((const sal_Int16*)0),    PROPERTY_NONE, SIZ_INDEX      },
291         { RTL_CONSTASCII_STRINGPARAM( "RelativeFontHeightLimits"        ), HANDLE_RELATIVE_FONT_HEIGHT_LIMITS        ,      &::getCppuType((const sal_Int16*)0),    PROPERTY_NONE, SIZ_LIMITS    },
292         { RTL_CONSTASCII_STRINGPARAM( "RelativeFontHeightOperators"     ), HANDLE_RELATIVE_FONT_HEIGHT_OPERATORS     ,      &::getCppuType((const sal_Int16*)0),    PROPERTY_NONE, SIZ_OPERATOR},
293         { RTL_CONSTASCII_STRINGPARAM( "RelativeFontHeightText"            ), HANDLE_RELATIVE_FONT_HEIGHT_TEXT          ,        &::getCppuType((const sal_Int16*)0),    PROPERTY_NONE, SIZ_TEXT   },
294         { RTL_CONSTASCII_STRINGPARAM( "RelativeFractionBarExcessLength"), HANDLE_RELATIVE_FRACTION_BAR_EXCESS_LENGTH,       &::getCppuType((const sal_Int16*)0),    PROPERTY_NONE, DIS_FRACTION        },
295         { RTL_CONSTASCII_STRINGPARAM( "RelativeFractionBarLineWeight"  ), HANDLE_RELATIVE_FRACTION_BAR_LINE_WEIGHT  ,       &::getCppuType((const sal_Int16*)0),    PROPERTY_NONE, DIS_STROKEWIDTH  },
296         { RTL_CONSTASCII_STRINGPARAM( "RelativeFractionDenominatorDepth"), HANDLE_RELATIVE_FRACTION_DENOMINATOR_DEPTH,      &::getCppuType((const sal_Int16*)0),    PROPERTY_NONE, DIS_DENOMINATOR  },
297         { RTL_CONSTASCII_STRINGPARAM( "RelativeFractionNumeratorHeight" ), HANDLE_RELATIVE_FRACTION_NUMERATOR_HEIGHT ,      &::getCppuType((const sal_Int16*)0),    PROPERTY_NONE, DIS_NUMERATOR          },
298         { RTL_CONSTASCII_STRINGPARAM( "RelativeIndexSubscript"           ), HANDLE_RELATIVE_INDEX_SUBSCRIPT           ,         &::getCppuType((const sal_Int16*)0),    PROPERTY_NONE, DIS_SUBSCRIPT          },
299         { RTL_CONSTASCII_STRINGPARAM( "RelativeIndexSuperscript"         ), HANDLE_RELATIVE_INDEX_SUPERSCRIPT         ,         &::getCppuType((const sal_Int16*)0),    PROPERTY_NONE, DIS_SUPERSCRIPT  },
300         { RTL_CONSTASCII_STRINGPARAM( "RelativeLineSpacing"              ), HANDLE_RELATIVE_LINE_SPACING              ,         &::getCppuType((const sal_Int16*)0),    PROPERTY_NONE, DIS_VERTICAL        },
301         { RTL_CONSTASCII_STRINGPARAM( "RelativeLowerLimitDistance"      ), HANDLE_RELATIVE_LOWER_LIMIT_DISTANCE      ,      &::getCppuType((const sal_Int16*)0),    PROPERTY_NONE, DIS_LOWERLIMIT        },
302         { RTL_CONSTASCII_STRINGPARAM( "RelativeMatrixColumnSpacing"     ), HANDLE_RELATIVE_MATRIX_COLUMN_SPACING     ,      &::getCppuType((const sal_Int16*)0),    PROPERTY_NONE, DIS_MATRIXCOL},
303         { RTL_CONSTASCII_STRINGPARAM( "RelativeMatrixLineSpacing"       ), HANDLE_RELATIVE_MATRIX_LINE_SPACING       ,      &::getCppuType((const sal_Int16*)0),    PROPERTY_NONE, DIS_MATRIXROW},
304         { RTL_CONSTASCII_STRINGPARAM( "RelativeOperatorExcessSize"      ), HANDLE_RELATIVE_OPERATOR_EXCESS_SIZE      ,      &::getCppuType((const sal_Int16*)0),    PROPERTY_NONE, DIS_OPERATORSIZE        },
305         { RTL_CONSTASCII_STRINGPARAM( "RelativeOperatorSpacing"          ), HANDLE_RELATIVE_OPERATOR_SPACING          ,         &::getCppuType((const sal_Int16*)0),    PROPERTY_NONE, DIS_OPERATORSPACE},
306         { RTL_CONSTASCII_STRINGPARAM( "RelativeRootSpacing"              ), HANDLE_RELATIVE_ROOT_SPACING              ,         &::getCppuType((const sal_Int16*)0),    PROPERTY_NONE, DIS_ROOT               },
307         { RTL_CONSTASCII_STRINGPARAM( "RelativeScaleBracketExcessSize" ), HANDLE_RELATIVE_SCALE_BRACKET_EXCESS_SIZE ,       &::getCppuType((const sal_Int16*)0),    PROPERTY_NONE, DIS_NORMALBRACKETSIZE},
308         { RTL_CONSTASCII_STRINGPARAM( "RelativeSpacing"                   ), HANDLE_RELATIVE_SPACING                   ,        &::getCppuType((const sal_Int16*)0),    PROPERTY_NONE, DIS_HORIZONTAL        },
309         { RTL_CONSTASCII_STRINGPARAM( "RelativeSymbolMinimumHeight"     ), HANDLE_RELATIVE_SYMBOL_MINIMUM_HEIGHT     ,      &::getCppuType((const sal_Int16*)0),    PROPERTY_NONE, DIS_ORNAMENTSPACE         },
310         { RTL_CONSTASCII_STRINGPARAM( "RelativeSymbolPrimaryHeight"     ), HANDLE_RELATIVE_SYMBOL_PRIMARY_HEIGHT     ,      &::getCppuType((const sal_Int16*)0),    PROPERTY_NONE, DIS_ORNAMENTSIZE        },
311         { RTL_CONSTASCII_STRINGPARAM( "RelativeUpperLimitDistance"      ),  HANDLE_RELATIVE_UPPER_LIMIT_DISTANCE     ,      &::getCppuType((const sal_Int16*)0),    PROPERTY_NONE, DIS_UPPERLIMIT        },
312         { RTL_CONSTASCII_STRINGPARAM( "RightMargin"                       ),    HANDLE_RIGHT_MARGIN                  ,      &::getCppuType((const sal_Int16*)0),    PROPERTY_NONE, DIS_RIGHTSPACE               },
313         { RTL_CONSTASCII_STRINGPARAM( "RuntimeUID"                      ), HANDLE_RUNTIME_UID                        ,      &::getCppuType(static_cast< const rtl::OUString * >(0)),    PropertyAttribute::READONLY, 0 },
314         { RTL_CONSTASCII_STRINGPARAM( "Symbols"                       ),        HANDLE_SYMBOLS                       ,      &::getCppuType((const Sequence < SymbolDescriptor > *)0),   PROPERTY_NONE, 0  },
315         { RTL_CONSTASCII_STRINGPARAM( "UserDefinedSymbolsInUse"       ),        HANDLE_USED_SYMBOLS                  ,      &::getCppuType((const Sequence < SymbolDescriptor > *)0),   PropertyAttribute::READONLY, 0  },
316         { RTL_CONSTASCII_STRINGPARAM( "TopMargin"                         ),    HANDLE_TOP_MARGIN                    ,      &::getCppuType((const sal_Int16*)0),    PROPERTY_NONE, DIS_TOPSPACE               },
317         // --> PB 2004-08-25 #i33095# Security Options
318         { RTL_CONSTASCII_STRINGPARAM( "LoadReadonly" ), HANDLE_LOAD_READONLY, &::getBooleanCppuType(), PROPERTY_NONE, 0 },
319         // <--
320         // --> 3.7.2010 #i972#
321         { RTL_CONSTASCII_STRINGPARAM( "BaseLine"), HANDLE_BASELINE, &::getCppuType((const sal_Int16*)0), PROPERTY_NONE, 0},
322         // <--
323         { NULL, 0, 0, NULL, 0, 0 }
324     };
325     PropertySetInfo *pInfo = new PropertySetInfo ( aModelPropertyInfoMap );
326     return pInfo;
327 }
328 //-----------------------------------------------------------------------
329 SmModel::SmModel( SfxObjectShell *pObjSh )
330 : SfxBaseModel(pObjSh)
331 , PropertySetHelper ( lcl_createModelPropertyInfo () )
332 , m_pPrintUIOptions( NULL )
333 
334 {
335 }
336 //-----------------------------------------------------------------------
337 SmModel::~SmModel() throw ()
338 {
339     delete m_pPrintUIOptions;
340 }
341 /*-- 28.03.00 14:18:17---------------------------------------------------
342 
343   -----------------------------------------------------------------------*/
344 uno::Any SAL_CALL SmModel::queryInterface( const uno::Type& rType ) throw(uno::RuntimeException)
345 {
346     uno::Any aRet =  ::cppu::queryInterface ( rType,
347                                     // OWeakObject interfaces
348                                     dynamic_cast< XInterface* > ( static_cast< XUnoTunnel* > ( this )),
349                                     static_cast< XWeak* > ( this ),
350                                     // PropertySetHelper interfaces
351                                     static_cast< XPropertySet* > ( this ),
352                                     static_cast< XMultiPropertySet* > ( this ),
353                                     //static_cast< XPropertyState* > ( this ),
354                                     // my own interfaces
355                                     static_cast< XServiceInfo*  > ( this ),
356                                     static_cast< XRenderable*  > ( this ) );
357     if (!aRet.hasValue())
358         aRet = SfxBaseModel::queryInterface ( rType );
359     return aRet;
360 }
361 /*-- 28.03.00 14:18:18---------------------------------------------------
362 
363   -----------------------------------------------------------------------*/
364 void SAL_CALL SmModel::acquire() throw()
365 {
366     OWeakObject::acquire();
367 }
368 /*-- 28.03.00 14:18:18---------------------------------------------------
369 
370   -----------------------------------------------------------------------*/
371 void SAL_CALL SmModel::release() throw()
372 {
373     OWeakObject::release();
374 }
375 /*-- 28.03.00 14:18:19---------------------------------------------------
376 
377   -----------------------------------------------------------------------*/
378 uno::Sequence< uno::Type > SAL_CALL SmModel::getTypes(  ) throw(uno::RuntimeException)
379 {
380     ::vos::OGuard aGuard(Application::GetSolarMutex());
381     uno::Sequence< uno::Type > aTypes = SfxBaseModel::getTypes();
382     sal_Int32 nLen = aTypes.getLength();
383     aTypes.realloc(nLen + 4);
384     uno::Type* pTypes = aTypes.getArray();
385     pTypes[nLen++] = ::getCppuType((Reference<XServiceInfo>*)0);
386     pTypes[nLen++] = ::getCppuType((Reference<XPropertySet>*)0);
387     pTypes[nLen++] = ::getCppuType((Reference<XMultiPropertySet>*)0);
388     pTypes[nLen++] = ::getCppuType((Reference<XRenderable>*)0);
389 
390     // XPropertyState not supported?? (respective virtual functions from
391     // PropertySetHelper not overloaded)
392     //pTypes[nLen++] = ::getCppuType((Reference<XPropertyState>*)0);
393 
394     return aTypes;
395 }
396 /* -----------------------------28.03.00 14:23--------------------------------
397 
398  ---------------------------------------------------------------------------*/
399 const uno::Sequence< sal_Int8 > & SmModel::getUnoTunnelId()
400 {
401     static osl::Mutex aCreateMutex;
402     osl::Guard<osl::Mutex> aGuard( aCreateMutex );
403 
404     static uno::Sequence< sal_Int8 > aSeq;
405     if(!aSeq.getLength())
406     {
407         aSeq.realloc( 16 );
408         rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True );
409     }
410     return aSeq;
411 } /* -----------------------------28.03.00 14:23--------------------------------
412 
413  ---------------------------------------------------------------------------*/
414 sal_Int64 SAL_CALL SmModel::getSomething( const uno::Sequence< sal_Int8 >& rId )
415     throw(uno::RuntimeException)
416 {
417     if( rId.getLength() == 16
418         && 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
419                                         rId.getConstArray(), 16 ) )
420     {
421             return sal::static_int_cast< sal_Int64 >(reinterpret_cast< sal_uIntPtr >(this));
422     }
423 
424     return SfxBaseModel::getSomething( rId );
425 }
426 /*-- 07.01.00 16:32:59---------------------------------------------------
427 
428   -----------------------------------------------------------------------*/
429 /*-- 07.01.00 16:33:00---------------------------------------------------
430 
431   -----------------------------------------------------------------------*/
432 sal_Int16 lcl_AnyToINT16(const uno::Any& rAny)
433 {
434     uno::TypeClass eType = rAny.getValueType().getTypeClass();
435 
436     sal_Int16 nRet = 0;
437     if( eType == uno::TypeClass_DOUBLE )
438         nRet = (sal_Int16)*(double*)rAny.getValue();
439     else if( eType == uno::TypeClass_FLOAT )
440         nRet = (sal_Int16)*(float*)rAny.getValue();
441     else
442         rAny >>= nRet;
443     return nRet;
444 }
445 //-----------------------------------------------------------------------------
446 
447 OUString SmModel::getImplementationName(void) throw( uno::RuntimeException )
448 {
449     return getImplementationName_Static();
450 }
451 
452 
453 ::rtl::OUString SmModel::getImplementationName_Static()
454 {
455     return rtl::OUString::createFromAscii("com.sun.star.comp.math.FormulaDocument");
456 }
457 
458 /*-- 20.01.04 11:21:00---------------------------------------------------
459 
460   -----------------------------------------------------------------------*/
461 sal_Bool SmModel::supportsService(const OUString& rServiceName) throw( uno::RuntimeException )
462 {
463     return (
464             rServiceName == A2OU("com.sun.star.document.OfficeDocument"  ) ||
465             rServiceName == A2OU("com.sun.star.formula.FormulaProperties")
466            );
467 }
468 /*-- 20.01.04 11:21:00---------------------------------------------------
469 
470   -----------------------------------------------------------------------*/
471 uno::Sequence< OUString > SmModel::getSupportedServiceNames(void) throw( uno::RuntimeException )
472 {
473     return getSupportedServiceNames_Static();
474 }
475 
476 uno::Sequence< OUString > SmModel::getSupportedServiceNames_Static(void)
477 {
478     ::vos::OGuard aGuard(Application::GetSolarMutex());
479 
480     uno::Sequence< OUString > aRet(2);
481     OUString* pArray = aRet.getArray();
482     pArray[0] = A2OU("com.sun.star.document.OfficeDocument");
483     pArray[1] = A2OU("com.sun.star.formula.FormulaProperties");
484     return aRet;
485 }
486 
487 void SmModel::_setPropertyValues(const PropertyMapEntry** ppEntries, const Any* pValues)
488     throw( UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException)
489 {
490     ::vos::OGuard aGuard(Application::GetSolarMutex());
491 
492     SmDocShell *pDocSh = static_cast < SmDocShell * > (GetObjectShell());
493 
494     if ( NULL == pDocSh )
495         throw UnknownPropertyException();
496 
497     SmFormat aFormat = pDocSh->GetFormat();
498 
499     for (; *ppEntries; ppEntries++, pValues++ )
500     {
501         if ((*ppEntries)->mnAttributes & PropertyAttribute::READONLY)
502             throw PropertyVetoException();
503 
504         switch ( (*ppEntries)->mnHandle )
505         {
506             case HANDLE_FORMULA:
507             {
508                 OUString aText;
509                 *pValues >>= aText;
510                 pDocSh->SetText(aText);
511             }
512             break;
513             case HANDLE_FONT_NAME_VARIABLES                :
514             case HANDLE_FONT_NAME_FUNCTIONS                :
515             case HANDLE_FONT_NAME_NUMBERS                  :
516             case HANDLE_FONT_NAME_TEXT                     :
517             case HANDLE_CUSTOM_FONT_NAME_SERIF             :
518             case HANDLE_CUSTOM_FONT_NAME_SANS              :
519             case HANDLE_CUSTOM_FONT_NAME_FIXED             :
520             {
521                 OUString aText;
522                 *pValues >>= aText;
523                 String sFontName = aText;
524                 if(!sFontName.Len())
525                     throw IllegalArgumentException();
526 
527                 if(aFormat.GetFont((*ppEntries)->mnMemberId).GetName() != sFontName)
528                 {
529                     const SmFace rOld = aFormat.GetFont((*ppEntries)->mnMemberId);
530 
531                     SmFace aSet( sFontName, rOld.GetSize() );
532                     aSet.SetBorderWidth( rOld.GetBorderWidth() );
533                     aSet.SetAlign( ALIGN_BASELINE );
534                     aFormat.SetFont( (*ppEntries)->mnMemberId, aSet );
535                 }
536             }
537             break;
538             case HANDLE_CUSTOM_FONT_FIXED_POSTURE:
539             case HANDLE_CUSTOM_FONT_SANS_POSTURE :
540             case HANDLE_CUSTOM_FONT_SERIF_POSTURE:
541             case HANDLE_FONT_VARIABLES_POSTURE   :
542             case HANDLE_FONT_FUNCTIONS_POSTURE   :
543             case HANDLE_FONT_NUMBERS_POSTURE     :
544             case HANDLE_FONT_TEXT_POSTURE        :
545             {
546                 if((*pValues).getValueType() != ::getBooleanCppuType())
547                     throw IllegalArgumentException();
548                 sal_Bool bVal = *(sal_Bool*)(*pValues).getValue();
549                 Font aNewFont(aFormat.GetFont((*ppEntries)->mnMemberId));
550                 aNewFont.SetItalic((bVal) ? ITALIC_NORMAL : ITALIC_NONE);
551                 aFormat.SetFont((*ppEntries)->mnMemberId, aNewFont);
552             }
553             break;
554             case HANDLE_CUSTOM_FONT_FIXED_WEIGHT :
555             case HANDLE_CUSTOM_FONT_SANS_WEIGHT  :
556             case HANDLE_CUSTOM_FONT_SERIF_WEIGHT :
557             case HANDLE_FONT_VARIABLES_WEIGHT    :
558             case HANDLE_FONT_FUNCTIONS_WEIGHT    :
559             case HANDLE_FONT_NUMBERS_WEIGHT      :
560             case HANDLE_FONT_TEXT_WEIGHT         :
561             {
562                 if((*pValues).getValueType() != ::getBooleanCppuType())
563                     throw IllegalArgumentException();
564                 sal_Bool bVal = *(sal_Bool*)(*pValues).getValue();
565                 Font aNewFont(aFormat.GetFont((*ppEntries)->mnMemberId));
566                 aNewFont.SetWeight((bVal) ? WEIGHT_BOLD : WEIGHT_NORMAL);
567                 aFormat.SetFont((*ppEntries)->mnMemberId, aNewFont);
568             }
569             break;
570             case HANDLE_BASE_FONT_HEIGHT                   :
571             {
572                 // Point!
573                 sal_Int16 nVal = lcl_AnyToINT16(*pValues);
574                 if(nVal < 1)
575                     throw IllegalArgumentException();
576                 Size aSize = aFormat.GetBaseSize();
577                 nVal *= 20;
578                 nVal = static_cast < sal_Int16 > ( TWIP_TO_MM100(nVal) );
579                 aSize.Height() = nVal;
580                 aFormat.SetBaseSize(aSize);
581 
582                 // apply base size to fonts
583                 const Size aTmp( aFormat.GetBaseSize() );
584                 for (sal_uInt16  i = FNT_BEGIN;  i <= FNT_END;  i++)
585                     aFormat.SetFontSize(i, aTmp);
586             }
587             break;
588             case HANDLE_RELATIVE_FONT_HEIGHT_TEXT          :
589             case HANDLE_RELATIVE_FONT_HEIGHT_INDICES       :
590             case HANDLE_RELATIVE_FONT_HEIGHT_FUNCTIONS     :
591             case HANDLE_RELATIVE_FONT_HEIGHT_OPERATORS     :
592             case HANDLE_RELATIVE_FONT_HEIGHT_LIMITS        :
593             {
594                 sal_Int16 nVal = 0;
595                 *pValues >>= nVal;
596                 if(nVal < 1)
597                     throw IllegalArgumentException();
598                 aFormat.SetRelSize((*ppEntries)->mnMemberId, nVal);
599             }
600             break;
601 
602             case HANDLE_IS_TEXT_MODE                       :
603             {
604                 aFormat.SetTextmode(*(sal_Bool*)(*pValues).getValue());
605             }
606             break;
607 
608             case HANDLE_GREEK_CHAR_STYLE                    :
609             {
610                 sal_Int16 nVal = 0;
611                 *pValues >>= nVal;
612                 if (nVal < 0 || nVal > 2)
613                     throw IllegalArgumentException();
614                 aFormat.SetGreekCharStyle( nVal );
615             }
616             break;
617 
618             case HANDLE_ALIGNMENT                          :
619             {
620                 // SmHorAlign uses the same values as HorizontalAlignment
621                 sal_Int16 nVal = 0;
622                 *pValues >>= nVal;
623                 if(nVal < 0 || nVal > 2)
624                     throw IllegalArgumentException();
625                 aFormat.SetHorAlign((SmHorAlign)nVal);
626             }
627             break;
628 
629             case HANDLE_RELATIVE_SPACING                   :
630             case HANDLE_RELATIVE_LINE_SPACING              :
631             case HANDLE_RELATIVE_ROOT_SPACING              :
632             case HANDLE_RELATIVE_INDEX_SUPERSCRIPT         :
633             case HANDLE_RELATIVE_INDEX_SUBSCRIPT           :
634             case HANDLE_RELATIVE_FRACTION_NUMERATOR_HEIGHT :
635             case HANDLE_RELATIVE_FRACTION_DENOMINATOR_DEPTH:
636             case HANDLE_RELATIVE_FRACTION_BAR_EXCESS_LENGTH:
637             case HANDLE_RELATIVE_FRACTION_BAR_LINE_WEIGHT  :
638             case HANDLE_RELATIVE_UPPER_LIMIT_DISTANCE      :
639             case HANDLE_RELATIVE_LOWER_LIMIT_DISTANCE      :
640             case HANDLE_RELATIVE_BRACKET_EXCESS_SIZE       :
641             case HANDLE_RELATIVE_BRACKET_DISTANCE          :
642             case HANDLE_RELATIVE_SCALE_BRACKET_EXCESS_SIZE :
643             case HANDLE_RELATIVE_MATRIX_LINE_SPACING       :
644             case HANDLE_RELATIVE_MATRIX_COLUMN_SPACING     :
645             case HANDLE_RELATIVE_SYMBOL_PRIMARY_HEIGHT     :
646             case HANDLE_RELATIVE_SYMBOL_MINIMUM_HEIGHT     :
647             case HANDLE_RELATIVE_OPERATOR_EXCESS_SIZE      :
648             case HANDLE_RELATIVE_OPERATOR_SPACING          :
649             case HANDLE_LEFT_MARGIN               :
650             case HANDLE_RIGHT_MARGIN              :
651             case HANDLE_TOP_MARGIN                :
652             case HANDLE_BOTTOM_MARGIN             :
653             {
654                 sal_Int16 nVal = 0;
655                 *pValues >>= nVal;
656                 if(nVal < 0)
657                     throw IllegalArgumentException();
658                 aFormat.SetDistance((*ppEntries)->mnMemberId, nVal);
659             }
660             break;
661             case HANDLE_IS_SCALE_ALL_BRACKETS              :
662                 aFormat.SetScaleNormalBrackets(*(sal_Bool*)(*pValues).getValue());
663             break;
664             case HANDLE_PRINTER_NAME:
665             {
666                 // embedded documents just ignore this property for now
667                 if ( pDocSh->GetCreateMode() != SFX_CREATE_MODE_EMBEDDED )
668                 {
669                     SfxPrinter *pPrinter = pDocSh->GetPrinter ( );
670                     if (pPrinter)
671                     {
672                         OUString sPrinterName;
673                         if (*pValues >>= sPrinterName )
674                         {
675                             if ( sPrinterName.getLength() )
676                             {
677                                 SfxPrinter *pNewPrinter = new SfxPrinter ( pPrinter->GetOptions().Clone(), sPrinterName );
678                                 if (pNewPrinter->IsKnown())
679                                     pDocSh->SetPrinter ( pNewPrinter );
680                                 else
681                                     delete pNewPrinter;
682                             }
683                         }
684                         else
685                             throw IllegalArgumentException();
686                     }
687                 }
688             }
689             break;
690             case HANDLE_PRINTER_SETUP:
691             {
692                 Sequence < sal_Int8 > aSequence;
693                 if ( *pValues >>= aSequence )
694                 {
695                     sal_uInt32 nSize = aSequence.getLength();
696                     SvMemoryStream aStream ( aSequence.getArray(), nSize, STREAM_READ );
697                     aStream.Seek ( STREAM_SEEK_TO_BEGIN );
698                     static sal_uInt16 __READONLY_DATA nRange[] =
699                     {
700                         SID_PRINTSIZE,       SID_PRINTSIZE,
701                         SID_PRINTZOOM,       SID_PRINTZOOM,
702                         SID_PRINTTITLE,      SID_PRINTTITLE,
703                         SID_PRINTTEXT,       SID_PRINTTEXT,
704                         SID_PRINTFRAME,      SID_PRINTFRAME,
705                         SID_NO_RIGHT_SPACES, SID_NO_RIGHT_SPACES,
706                         0
707                     };
708                     SfxItemSet *pItemSet = new SfxItemSet( pDocSh->GetPool(), nRange );
709                     SmModule *pp = SM_MOD();
710                     pp->GetConfig()->ConfigToItemSet(*pItemSet);
711                     SfxPrinter *pPrinter = SfxPrinter::Create ( aStream, pItemSet );
712 
713                     pDocSh->SetPrinter( pPrinter );
714                 }
715                 else
716                     throw IllegalArgumentException();
717             }
718             break;
719             case HANDLE_SYMBOLS:
720             {
721                 // this is set
722                 Sequence < SymbolDescriptor > aSequence;
723                 if ( *pValues >>= aSequence )
724                 {
725                     sal_uInt32 nSize = aSequence.getLength();
726                     SmModule *pp = SM_MOD();
727                     SmSymbolManager &rManager = pp->GetSymbolManager();
728                     SymbolDescriptor *pDescriptor = aSequence.getArray();
729                     for (sal_uInt32 i = 0; i < nSize ; i++, pDescriptor++)
730                     {
731                         Font aFont;
732                         aFont.SetName ( pDescriptor->sFontName );
733                         aFont.SetCharSet ( static_cast < rtl_TextEncoding > (pDescriptor->nCharSet) );
734                         aFont.SetFamily ( static_cast < FontFamily > (pDescriptor->nFamily ) );
735                         aFont.SetPitch  ( static_cast < FontPitch >  (pDescriptor->nPitch ) );
736                         aFont.SetWeight ( static_cast < FontWeight > (pDescriptor->nWeight ) );
737                         aFont.SetItalic ( static_cast < FontItalic > (pDescriptor->nItalic ) );
738                         SmSym aSymbol ( pDescriptor->sName, aFont, static_cast < sal_Unicode > (pDescriptor->nCharacter),
739                                         pDescriptor->sSymbolSet );
740                         aSymbol.SetExportName ( pDescriptor->sExportName );
741                         aSymbol.SetDocSymbol( sal_True );
742                         rManager.AddOrReplaceSymbol ( aSymbol );
743                     }
744                 }
745                 else
746                     throw IllegalArgumentException();
747             }
748             break;
749             // --> PB 2004-08-25 #i33095# Security Options
750             case HANDLE_LOAD_READONLY :
751             {
752                 if ( (*pValues).getValueType() != ::getBooleanCppuType() )
753                     throw IllegalArgumentException();
754                 sal_Bool bReadonly = sal_False;
755                 if ( *pValues >>= bReadonly )
756                     pDocSh->SetLoadReadonly( bReadonly );
757                 break;
758             }
759             // <--
760         }
761     }
762 
763     pDocSh->SetFormat( aFormat );
764 
765     // #i67283# since about all of the above changes are likely to change
766     // the formula size we have to recalculate the vis-area now
767     pDocSh->SetVisArea( Rectangle( Point(0, 0), pDocSh->GetSize() ) );
768 }
769 
770 void SmModel::_getPropertyValues( const PropertyMapEntry **ppEntries, Any *pValue )
771     throw( UnknownPropertyException, WrappedTargetException )
772 {
773     SmDocShell *pDocSh = static_cast < SmDocShell * > (GetObjectShell());
774 
775     if ( NULL == pDocSh )
776         throw UnknownPropertyException();
777 
778     const SmFormat & aFormat = pDocSh->GetFormat();
779 
780     for (; *ppEntries; ppEntries++, pValue++ )
781     {
782         switch ( (*ppEntries)->mnHandle )
783         {
784             case HANDLE_FORMULA:
785                 *pValue <<= OUString(pDocSh->GetText());
786             break;
787             case HANDLE_FONT_NAME_VARIABLES                :
788             case HANDLE_FONT_NAME_FUNCTIONS                :
789             case HANDLE_FONT_NAME_NUMBERS                  :
790             case HANDLE_FONT_NAME_TEXT                     :
791             case HANDLE_CUSTOM_FONT_NAME_SERIF             :
792             case HANDLE_CUSTOM_FONT_NAME_SANS              :
793             case HANDLE_CUSTOM_FONT_NAME_FIXED             :
794             {
795                 const SmFace &  rFace = aFormat.GetFont((*ppEntries)->mnMemberId);
796                 *pValue <<= OUString(rFace.GetName());
797             }
798             break;
799             case HANDLE_CUSTOM_FONT_FIXED_POSTURE:
800             case HANDLE_CUSTOM_FONT_SANS_POSTURE :
801             case HANDLE_CUSTOM_FONT_SERIF_POSTURE:
802             case HANDLE_FONT_VARIABLES_POSTURE   :
803             case HANDLE_FONT_FUNCTIONS_POSTURE   :
804             case HANDLE_FONT_NUMBERS_POSTURE     :
805             case HANDLE_FONT_TEXT_POSTURE        :
806             {
807                 const SmFace &  rFace = aFormat.GetFont((*ppEntries)->mnMemberId);
808                 sal_Bool bVal = IsItalic( rFace );
809                 (*pValue).setValue(&bVal, *(*ppEntries)->mpType);
810             }
811             break;
812             case HANDLE_CUSTOM_FONT_FIXED_WEIGHT :
813             case HANDLE_CUSTOM_FONT_SANS_WEIGHT  :
814             case HANDLE_CUSTOM_FONT_SERIF_WEIGHT :
815             case HANDLE_FONT_VARIABLES_WEIGHT    :
816             case HANDLE_FONT_FUNCTIONS_WEIGHT    :
817             case HANDLE_FONT_NUMBERS_WEIGHT      :
818             case HANDLE_FONT_TEXT_WEIGHT         :
819             {
820                 const SmFace &  rFace = aFormat.GetFont((*ppEntries)->mnMemberId);
821                 sal_Bool bVal = IsBold( rFace ); // bold?
822                 (*pValue).setValue(&bVal, *(*ppEntries)->mpType);
823             }
824             break;
825             case HANDLE_BASE_FONT_HEIGHT                   :
826             {
827                 // Point!
828                 sal_Int16 nVal = static_cast < sal_Int16 > (aFormat.GetBaseSize().Height());
829                 nVal = static_cast < sal_Int16 > (MM100_TO_TWIP(nVal));
830                 nVal = (nVal + 10) / 20;
831                 *pValue <<= nVal;
832             }
833             break;
834             case HANDLE_RELATIVE_FONT_HEIGHT_TEXT           :
835             case HANDLE_RELATIVE_FONT_HEIGHT_INDICES       :
836             case HANDLE_RELATIVE_FONT_HEIGHT_FUNCTIONS     :
837             case HANDLE_RELATIVE_FONT_HEIGHT_OPERATORS     :
838             case HANDLE_RELATIVE_FONT_HEIGHT_LIMITS        :
839                 *pValue <<= (sal_Int16) aFormat.GetRelSize((*ppEntries)->mnMemberId);
840             break;
841 
842             case HANDLE_IS_TEXT_MODE                       :
843             {
844                 sal_Bool bVal = aFormat.IsTextmode();
845                 (*pValue).setValue(&bVal, ::getBooleanCppuType());
846             }
847             break;
848 
849             case HANDLE_GREEK_CHAR_STYLE                    :
850                 *pValue <<= (sal_Int16)aFormat.GetGreekCharStyle();
851             break;
852 
853             case HANDLE_ALIGNMENT                          :
854                 // SmHorAlign uses the same values as HorizontalAlignment
855                 *pValue <<= (sal_Int16)aFormat.GetHorAlign();
856             break;
857 
858             case HANDLE_RELATIVE_SPACING                   :
859             case HANDLE_RELATIVE_LINE_SPACING              :
860             case HANDLE_RELATIVE_ROOT_SPACING              :
861             case HANDLE_RELATIVE_INDEX_SUPERSCRIPT         :
862             case HANDLE_RELATIVE_INDEX_SUBSCRIPT           :
863             case HANDLE_RELATIVE_FRACTION_NUMERATOR_HEIGHT :
864             case HANDLE_RELATIVE_FRACTION_DENOMINATOR_DEPTH:
865             case HANDLE_RELATIVE_FRACTION_BAR_EXCESS_LENGTH:
866             case HANDLE_RELATIVE_FRACTION_BAR_LINE_WEIGHT  :
867             case HANDLE_RELATIVE_UPPER_LIMIT_DISTANCE      :
868             case HANDLE_RELATIVE_LOWER_LIMIT_DISTANCE      :
869             case HANDLE_RELATIVE_BRACKET_EXCESS_SIZE       :
870             case HANDLE_RELATIVE_BRACKET_DISTANCE          :
871             case HANDLE_RELATIVE_SCALE_BRACKET_EXCESS_SIZE :
872             case HANDLE_RELATIVE_MATRIX_LINE_SPACING       :
873             case HANDLE_RELATIVE_MATRIX_COLUMN_SPACING     :
874             case HANDLE_RELATIVE_SYMBOL_PRIMARY_HEIGHT     :
875             case HANDLE_RELATIVE_SYMBOL_MINIMUM_HEIGHT     :
876             case HANDLE_RELATIVE_OPERATOR_EXCESS_SIZE      :
877             case HANDLE_RELATIVE_OPERATOR_SPACING          :
878             case HANDLE_LEFT_MARGIN               :
879             case HANDLE_RIGHT_MARGIN              :
880             case HANDLE_TOP_MARGIN                :
881             case HANDLE_BOTTOM_MARGIN             :
882                 *pValue <<= (sal_Int16)aFormat.GetDistance((*ppEntries)->mnMemberId);
883             break;
884             case HANDLE_IS_SCALE_ALL_BRACKETS              :
885             {
886                 sal_Bool bVal = aFormat.IsScaleNormalBrackets();
887                 (*pValue).setValue(&bVal, ::getBooleanCppuType());
888             }
889             break;
890             case HANDLE_PRINTER_NAME:
891             {
892                 SfxPrinter *pPrinter = pDocSh->GetPrinter ( );
893                 *pValue <<= pPrinter ? OUString ( pPrinter->GetName()) : OUString();
894             }
895             break;
896             case HANDLE_PRINTER_SETUP:
897             {
898                 SfxPrinter *pPrinter = pDocSh->GetPrinter ();
899                 if (pPrinter)
900                 {
901                     SvMemoryStream aStream;
902                     pPrinter->Store( aStream );
903                     aStream.Seek ( STREAM_SEEK_TO_END );
904                     sal_uInt32 nSize = aStream.Tell();
905                     aStream.Seek ( STREAM_SEEK_TO_BEGIN );
906                     Sequence < sal_Int8 > aSequence ( nSize );
907                     aStream.Read ( aSequence.getArray(), nSize );
908                     *pValue <<= aSequence;
909                 }
910             }
911             break;
912             case HANDLE_SYMBOLS:
913             case HANDLE_USED_SYMBOLS:
914             {
915                 const bool bUsedSymbolsOnly = (*ppEntries)->mnHandle == HANDLE_USED_SYMBOLS;
916                 const std::set< rtl::OUString > &rUsedSymbols = pDocSh->GetUsedSymbols();
917 
918                 // this is get
919                 SmModule *pp = SM_MOD();
920                 const SmSymbolManager &rManager = pp->GetSymbolManager();
921                 vector < const SmSym * > aVector;
922 
923                 const SymbolPtrVec_t aSymbols( rManager.GetSymbols() );
924                 size_t nCount = 0;
925                 for (size_t i = 0; i < aSymbols.size(); ++i)
926                 {
927                     const SmSym * pSymbol = aSymbols[ i ];
928                     const bool bIsUsedSymbol = rUsedSymbols.find( pSymbol->GetName() ) != rUsedSymbols.end();
929                     if (pSymbol && !pSymbol->IsPredefined() &&
930                         (!bUsedSymbolsOnly || bIsUsedSymbol))
931                     {
932                         aVector.push_back ( pSymbol );
933                         nCount++;
934                     }
935                 }
936                 Sequence < SymbolDescriptor > aSequence ( nCount );
937                 SymbolDescriptor * pDescriptor = aSequence.getArray();
938 
939                 vector < const SmSym * >::const_iterator aIter = aVector.begin(), aEnd = aVector.end();
940                 for(; aIter != aEnd; pDescriptor++, aIter++)
941                 {
942                     pDescriptor->sName = (*aIter)->GetName();
943                     pDescriptor->sExportName = (*aIter)->GetExportName();
944                     pDescriptor->sSymbolSet = (*aIter)->GetSymbolSetName();
945                     pDescriptor->nCharacter = static_cast < sal_Int32 > ((*aIter)->GetCharacter());
946 
947                     Font rFont = (*aIter)->GetFace();
948                     pDescriptor->sFontName = rFont.GetName();
949                     pDescriptor->nCharSet  = sal::static_int_cast< sal_Int16 >(rFont.GetCharSet());
950                     pDescriptor->nFamily   = sal::static_int_cast< sal_Int16 >(rFont.GetFamily());
951                     pDescriptor->nPitch    = sal::static_int_cast< sal_Int16 >(rFont.GetPitch());
952                     pDescriptor->nWeight   = sal::static_int_cast< sal_Int16 >(rFont.GetWeight());
953                     pDescriptor->nItalic   = sal::static_int_cast< sal_Int16 >(rFont.GetItalic());
954                 }
955                 *pValue <<= aSequence;
956             }
957             break;
958             case HANDLE_BASIC_LIBRARIES:
959                 *pValue <<= pDocSh->GetBasicContainer();
960             break;
961             case HANDLE_DIALOG_LIBRARIES:
962                 *pValue <<= pDocSh->GetDialogContainer();
963             break;
964             case HANDLE_RUNTIME_UID:
965                 *pValue <<= getRuntimeUID();
966             break;
967             // --> PB 2004-08-25 #i33095# Security Options
968             case HANDLE_LOAD_READONLY :
969             {
970                 *pValue <<= pDocSh->IsLoadReadonly();
971                 break;
972             }
973             // <--
974             // --> 3.7.2010 #i972#
975             case HANDLE_BASELINE:
976             {
977                 if ( !pDocSh->pTree )
978                     pDocSh->Parse();
979                 if ( pDocSh->pTree )
980                 {
981                     if ( !pDocSh->IsFormulaArranged() )
982                         pDocSh->ArrangeFormula();
983 
984                     *pValue <<= static_cast<sal_Int32>( pDocSh->pTree->GetFormulaBaseline() );
985                 }
986             }
987             break;
988             // <--
989         }
990     }
991 }
992 
993 //////////////////////////////////////////////////////////////////////
994 
995 sal_Int32 SAL_CALL SmModel::getRendererCount(
996         const uno::Any& /*rSelection*/,
997         const uno::Sequence< beans::PropertyValue >& /*xOptions*/ )
998     throw (IllegalArgumentException, RuntimeException)
999 {
1000     ::vos::OGuard aGuard(Application::GetSolarMutex());
1001     return 1;
1002 }
1003 
1004 
1005 static Size lcl_GuessPaperSize()
1006 {
1007     Size aRes;
1008     Reference< XMultiServiceFactory >  xMgr( getProcessServiceFactory() );
1009     LocaleDataWrapper aLocWrp( xMgr, AllSettings().GetLocale() );
1010     if( MEASURE_METRIC == aLocWrp.getMeasurementSystemEnum() )
1011     {
1012         // in 100th mm
1013         PaperInfo aInfo( PAPER_A4 );
1014         aRes.Width()  = aInfo.getWidth();
1015         aRes.Height() = aInfo.getHeight();
1016     }
1017     else
1018     {
1019         // in 100th mm
1020         PaperInfo aInfo( PAPER_LETTER );
1021         aRes.Width()  = aInfo.getWidth();
1022         aRes.Height() = aInfo.getHeight();
1023     }
1024     return aRes;
1025 }
1026 
1027 uno::Sequence< beans::PropertyValue > SAL_CALL SmModel::getRenderer(
1028         sal_Int32 nRenderer,
1029         const uno::Any& /*rSelection*/,
1030         const uno::Sequence< beans::PropertyValue >& /*rxOptions*/ )
1031     throw (IllegalArgumentException, RuntimeException)
1032 {
1033     ::vos::OGuard aGuard(Application::GetSolarMutex());
1034 
1035     if (0 != nRenderer)
1036         throw IllegalArgumentException();
1037 
1038     SmDocShell *pDocSh = static_cast < SmDocShell * >( GetObjectShell() );
1039     if (!pDocSh)
1040         throw RuntimeException();
1041 
1042     SmPrinterAccess aPrinterAccess( *pDocSh );
1043     Printer *pPrinter = aPrinterAccess.GetPrinter();
1044     //Point   aPrtPageOffset( pPrinter->GetPageOffset() );
1045     Size    aPrtPaperSize ( pPrinter->GetPaperSize() );
1046 
1047     // if paper size is 0 (usually if no 'real' printer is found),
1048     // guess the paper size
1049     if (aPrtPaperSize.Height() == 0 || aPrtPaperSize.Width() == 0)
1050         aPrtPaperSize = lcl_GuessPaperSize();
1051     awt::Size   aPageSize( aPrtPaperSize.Width(), aPrtPaperSize.Height() );
1052 
1053     uno::Sequence< beans::PropertyValue > aRenderer(1);
1054     PropertyValue  &rValue = aRenderer.getArray()[0];
1055     rValue.Name  = OUString( RTL_CONSTASCII_USTRINGPARAM( "PageSize" ) );
1056     rValue.Value <<= aPageSize;
1057 
1058     if (!m_pPrintUIOptions)
1059         m_pPrintUIOptions = new SmPrintUIOptions();
1060     m_pPrintUIOptions->appendPrintUIOptions( aRenderer );
1061 
1062     return aRenderer;
1063 }
1064 
1065 void SAL_CALL SmModel::render(
1066         sal_Int32 nRenderer,
1067         const uno::Any& rSelection,
1068         const uno::Sequence< beans::PropertyValue >& rxOptions )
1069     throw (IllegalArgumentException, RuntimeException)
1070 {
1071     ::vos::OGuard aGuard(Application::GetSolarMutex());
1072 
1073     if (0 != nRenderer)
1074         throw IllegalArgumentException();
1075 
1076     SmDocShell *pDocSh = static_cast < SmDocShell * >( GetObjectShell() );
1077     if (!pDocSh)
1078         throw RuntimeException();
1079 
1080     // get device to be rendered in
1081     uno::Reference< awt::XDevice >  xRenderDevice;
1082     for (sal_Int32 i = 0, nCount = rxOptions.getLength();  i < nCount;  ++i)
1083     {
1084         if( rxOptions[i].Name == OUString( RTL_CONSTASCII_USTRINGPARAM( "RenderDevice" ) ) )
1085             rxOptions[i].Value >>= xRenderDevice;
1086     }
1087 
1088     if (xRenderDevice.is())
1089     {
1090         VCLXDevice*   pDevice = VCLXDevice::GetImplementation( xRenderDevice );
1091         OutputDevice* pOut = pDevice ? pDevice->GetOutputDevice() : NULL;
1092 
1093         if (!pOut)
1094             throw RuntimeException();
1095 
1096         pOut->SetMapMode( MAP_100TH_MM );
1097 
1098         uno::Reference< frame::XModel > xModel;
1099         rSelection >>= xModel;
1100         if (xModel == pDocSh->GetModel())
1101         {
1102             //!! when called via API we may not have an active view
1103             //!! thus we go and look for a view that can be used.
1104             const TypeId aTypeId = TYPE( SmViewShell );
1105             SfxViewShell* pViewSh = SfxViewShell::GetFirst( &aTypeId, sal_False /* search non-visible views as well*/ );
1106             while (pViewSh && pViewSh->GetObjectShell() != pDocSh)
1107                 pViewSh = SfxViewShell::GetNext( *pViewSh, &aTypeId, sal_False /* search non-visible views as well*/ );
1108             SmViewShell *pView = PTR_CAST( SmViewShell, pViewSh );
1109             DBG_ASSERT( pView, "SmModel::render : no SmViewShell found" );
1110 
1111             if (pView)
1112             {
1113                 SmPrinterAccess aPrinterAccess( *pDocSh );
1114                 Printer *pPrinter = aPrinterAccess.GetPrinter();
1115 
1116                 Size    aPrtPaperSize ( pPrinter->GetPaperSize() );
1117                 Size    aOutputSize   ( pPrinter->GetOutputSize() );
1118                 Point   aPrtPageOffset( pPrinter->GetPageOffset() );
1119 
1120                 // no real printer ??
1121                 if (aPrtPaperSize.Height() == 0 || aPrtPaperSize.Width() == 0)
1122                 {
1123                     aPrtPaperSize = lcl_GuessPaperSize();
1124                     // factors from Windows DIN A4
1125                     aOutputSize    = Size( (long)(aPrtPaperSize.Width()  * 0.941),
1126                                            (long)(aPrtPaperSize.Height() * 0.961));
1127                     aPrtPageOffset = Point( (long)(aPrtPaperSize.Width()  * 0.0250),
1128                                             (long)(aPrtPaperSize.Height() * 0.0214));
1129                 }
1130                 Point   aZeroPoint;
1131                 Rectangle OutputRect( aZeroPoint, aOutputSize );
1132 
1133 
1134                 // set minimum top and bottom border
1135                 if (aPrtPageOffset.Y() < 2000)
1136                     OutputRect.Top() += 2000 - aPrtPageOffset.Y();
1137                 if ((aPrtPaperSize.Height() - (aPrtPageOffset.Y() + OutputRect.Bottom())) < 2000)
1138                     OutputRect.Bottom() -= 2000 - (aPrtPaperSize.Height() -
1139                                                 (aPrtPageOffset.Y() + OutputRect.Bottom()));
1140 
1141                 // set minimum left and right border
1142                 if (aPrtPageOffset.X() < 2500)
1143                     OutputRect.Left() += 2500 - aPrtPageOffset.X();
1144                 if ((aPrtPaperSize.Width() - (aPrtPageOffset.X() + OutputRect.Right())) < 1500)
1145                     OutputRect.Right() -= 1500 - (aPrtPaperSize.Width() -
1146                                                 (aPrtPageOffset.X() + OutputRect.Right()));
1147 
1148                 if (!m_pPrintUIOptions)
1149                     m_pPrintUIOptions = new SmPrintUIOptions();
1150                 m_pPrintUIOptions->processProperties( rxOptions );
1151 
1152                 pView->Impl_Print( *pOut, *m_pPrintUIOptions, Rectangle( OutputRect ), Point() );
1153 
1154                 // release SmPrintUIOptions when everything is done.
1155                 // That way, when SmPrintUIOptions is needed again it will read the latest configuration settings in its c-tor.
1156                 if (m_pPrintUIOptions->getBoolValue( "IsLastPage", sal_False ))
1157                 {
1158                     delete m_pPrintUIOptions;   m_pPrintUIOptions = 0;
1159                 }
1160             }
1161         }
1162     }
1163 }
1164 
1165 void SAL_CALL SmModel::setParent( const uno::Reference< uno::XInterface >& xParent)
1166         throw( lang::NoSupportException, uno::RuntimeException )
1167 {
1168     ::vos::OGuard aGuard( Application::GetSolarMutex() );
1169     SfxBaseModel::setParent( xParent );
1170     uno::Reference< lang::XUnoTunnel > xParentTunnel( xParent, uno::UNO_QUERY );
1171     if ( xParentTunnel.is() )
1172     {
1173         SvGlobalName aSfxIdent( SFX_GLOBAL_CLASSID );
1174         SfxObjectShell* pDoc = reinterpret_cast<SfxObjectShell *>(xParentTunnel->getSomething(
1175                                         uno::Sequence< sal_Int8 >( aSfxIdent.GetByteSequence() ) ) );
1176         if ( pDoc )
1177             GetObjectShell()->OnDocumentPrinterChanged( pDoc->GetDocumentPrinter() );
1178     }
1179 }
1180 
1181