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