1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cfgitem.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_starmath.hxx"
35 #include <vcl/svapp.hxx>
37 #include "cfgitem.hxx"
39 #include "starmath.hrc"
44 using namespace com::sun::star
;
45 using namespace com::sun::star::uno
;
46 using namespace com::sun::star::beans
;
48 #define A2OU(x) rtl::OUString::createFromAscii( x )
50 static const char* aRootName
= "Office.Math";
52 #define SYMBOL_LIST "SymbolList"
53 #define FONT_FORMAT_LIST "FontFormatList"
55 SV_IMPL_OBJARR( SmFntFmtListEntryArr
, SmFntFmtListEntry
);
57 /////////////////////////////////////////////////////////////////
60 static Sequence
< OUString
> lcl_GetFontPropertyNames()
62 static const char * aPropNames
[] =
73 const char** ppPropName
= aPropNames
;
75 Sequence
< OUString
> aNames( 6 );
76 OUString
*pNames
= aNames
.getArray();
77 for( INT32 i
= 0; *ppPropName
; ++i
, ++ppPropName
)
79 pNames
[i
] = A2OU( *ppPropName
);
81 //aNames.realloc( i );
85 /////////////////////////////////////////////////////////////////
88 static Sequence
< OUString
> lcl_GetSymbolPropertyNames()
90 static const char * aPropNames
[] =
99 const char** ppPropName
= aPropNames
;
101 Sequence
< OUString
> aNames( 4 );
102 OUString
*pNames
= aNames
.getArray();
103 for( INT32 i
= 0; *ppPropName
; ++i
, ++ppPropName
)
105 pNames
[i
] = A2OU( *ppPropName
);
107 //aNames.realloc( i );
111 /////////////////////////////////////////////////////////////////
113 static const char * aMathPropNames
[] =
120 //"Misc/NoSymbolsWarning",
121 "Misc/IgnoreSpacesRight",
122 "View/ToolboxVisible",
128 //! Beware of order according to *_BEGIN *_END defines in format.hxx !
129 //! see respective load/save routines here
130 static const char * aFormatPropNames
[] =
132 "StandardFormat/Textmode",
133 "StandardFormat/ScaleNormalBracket",
134 "StandardFormat/HorizontalAlignment",
135 "StandardFormat/BaseSize",
136 "StandardFormat/TextSize",
137 "StandardFormat/IndexSize",
138 "StandardFormat/FunctionSize",
139 "StandardFormat/OperatorSize",
140 "StandardFormat/LimitsSize",
141 "StandardFormat/Distance/Horizontal",
142 "StandardFormat/Distance/Vertical",
143 "StandardFormat/Distance/Root",
144 "StandardFormat/Distance/SuperScript",
145 "StandardFormat/Distance/SubScript",
146 "StandardFormat/Distance/Numerator",
147 "StandardFormat/Distance/Denominator",
148 "StandardFormat/Distance/Fraction",
149 "StandardFormat/Distance/StrokeWidth",
150 "StandardFormat/Distance/UpperLimit",
151 "StandardFormat/Distance/LowerLimit",
152 "StandardFormat/Distance/BracketSize",
153 "StandardFormat/Distance/BracketSpace",
154 "StandardFormat/Distance/MatrixRow",
155 "StandardFormat/Distance/MatrixColumn",
156 "StandardFormat/Distance/OrnamentSize",
157 "StandardFormat/Distance/OrnamentSpace",
158 "StandardFormat/Distance/OperatorSize",
159 "StandardFormat/Distance/OperatorSpace",
160 "StandardFormat/Distance/LeftSpace",
161 "StandardFormat/Distance/RightSpace",
162 "StandardFormat/Distance/TopSpace",
163 "StandardFormat/Distance/BottomSpace",
164 "StandardFormat/Distance/NormalBracketSize",
165 "StandardFormat/VariableFont",
166 "StandardFormat/FunctionFont",
167 "StandardFormat/NumberFont",
168 "StandardFormat/TextFont",
169 "StandardFormat/SerifFont",
170 "StandardFormat/SansFont",
171 "StandardFormat/FixedFont"
175 static Sequence
< OUString
> lcl_GetPropertyNames(
176 const char * aPropNames
[], USHORT nCount
)
179 const char** ppPropName
= aPropNames
;
181 Sequence
< OUString
> aNames( nCount
);
182 OUString
*pNames
= aNames
.getArray();
183 for (INT32 i
= 0; i
< nCount
; ++i
, ++ppPropName
)
185 pNames
[i
] = A2OU( *ppPropName
);
187 //aNames.realloc( i );
192 static Sequence
< OUString
> GetFormatPropertyNames()
194 USHORT nCnt
= sizeof(aFormatPropNames
) / sizeof(aFormatPropNames
[0]);
195 return lcl_GetPropertyNames( aFormatPropNames
, nCnt
);
199 static Sequence
< OUString
> GetOtherPropertyNames()
201 USHORT nCnt
= sizeof(aMathPropNames
) / sizeof(aMathPropNames
[0]);
202 return lcl_GetPropertyNames( aMathPropNames
, nCnt
);
205 /////////////////////////////////////////////////////////////////
209 SmPrintSize ePrintSize
;
210 USHORT nPrintZoomFactor
;
212 BOOL bPrintFormulaText
;
214 BOOL bIgnoreSpacesRight
;
215 BOOL bToolboxVisible
;
218 //BOOL bNoSymbolsWarning;
224 SmCfgOther::SmCfgOther()
226 ePrintSize
= PRINT_SIZE_NORMAL
;
227 nPrintZoomFactor
= 100;
228 bPrintTitle
= bPrintFormulaText
=
229 bPrintFrame
= bIgnoreSpacesRight
=
230 bToolboxVisible
= bAutoRedraw
=
231 bFormulaCursor
= /*bNoSymbolsWarning =*/ TRUE
;
234 /////////////////////////////////////////////////////////////////
237 SmFontFormat::SmFontFormat()
239 aName
.AssignAscii( FONTNAME_MATH
);
240 nCharSet
= RTL_TEXTENCODING_UNICODE
;
241 nFamily
= FAMILY_DONTKNOW
;
242 nPitch
= PITCH_DONTKNOW
;
243 nWeight
= WEIGHT_DONTKNOW
;
244 nItalic
= ITALIC_NONE
;
248 SmFontFormat::SmFontFormat( const Font
&rFont
)
250 aName
= rFont
.GetName();
251 nCharSet
= (INT16
) rFont
.GetCharSet();
252 nFamily
= (INT16
) rFont
.GetFamily();
253 nPitch
= (INT16
) rFont
.GetPitch();
254 nWeight
= (INT16
) rFont
.GetWeight();
255 nItalic
= (INT16
) rFont
.GetItalic();
259 const Font
SmFontFormat::GetFont() const
262 aRes
.SetName( aName
);
263 aRes
.SetCharSet( (rtl_TextEncoding
) nCharSet
);
264 aRes
.SetFamily( (FontFamily
) nFamily
);
265 aRes
.SetPitch( (FontPitch
) nPitch
);
266 aRes
.SetWeight( (FontWeight
) nWeight
);
267 aRes
.SetItalic( (FontItalic
) nItalic
);
272 BOOL
SmFontFormat::operator == ( const SmFontFormat
&rFntFmt
) const
274 return aName
== rFntFmt
.aName
&&
275 nCharSet
== rFntFmt
.nCharSet
&&
276 nFamily
== rFntFmt
.nFamily
&&
277 nPitch
== rFntFmt
.nPitch
&&
278 nWeight
== rFntFmt
.nWeight
&&
279 nItalic
== rFntFmt
.nItalic
;
283 /////////////////////////////////////////////////////////////////
285 SmFntFmtListEntry::SmFntFmtListEntry( const String
&rId
, const SmFontFormat
&rFntFmt
) :
292 SmFontFormatList::SmFontFormatList()
298 void SmFontFormatList::Clear()
300 USHORT nCnt
= aEntries
.Count();
303 aEntries
.Remove( 0, nCnt
);
309 void SmFontFormatList::AddFontFormat( const String
&rFntFmtId
,
310 const SmFontFormat
&rFntFmt
)
312 const SmFontFormat
*pFntFmt
= GetFontFormat( rFntFmtId
);
313 DBG_ASSERT( !pFntFmt
, "FontFormatId already exists" );
316 SmFntFmtListEntry
aEntry( rFntFmtId
, rFntFmt
);
317 aEntries
.Insert( aEntry
, aEntries
.Count() );
323 void SmFontFormatList::RemoveFontFormat( const String
&rFntFmtId
)
325 USHORT nPos
= 0xFFFF;
328 USHORT nCnt
= aEntries
.Count();
329 for (USHORT i
= 0; i
< nCnt
&& nPos
== 0xFFFF; ++i
)
331 if (aEntries
[i
].aId
== rFntFmtId
)
335 // remove entry if found
338 aEntries
.Remove( nPos
);
344 const SmFontFormat
* SmFontFormatList::GetFontFormat( const String
&rFntFmtId
) const
346 SmFontFormat
*pRes
= 0;
348 USHORT nCnt
= aEntries
.Count();
350 for (i
= 0; i
< nCnt
&& !pRes
; ++i
)
352 if (aEntries
[i
].aId
== rFntFmtId
)
353 pRes
= &aEntries
[i
].aFntFmt
;
361 const SmFontFormat
* SmFontFormatList::GetFontFormat( USHORT nPos
) const
363 SmFontFormat
*pRes
= 0;
364 if (nPos
< aEntries
.Count())
365 pRes
= &aEntries
[ nPos
].aFntFmt
;
370 const String
SmFontFormatList::GetFontFormatId( const SmFontFormat
&rFntFmt
) const
374 USHORT nCnt
= aEntries
.Count();
376 for (i
= 0; i
< nCnt
&& 0 == aRes
.Len(); ++i
)
378 if (aEntries
[i
].aFntFmt
== rFntFmt
)
379 aRes
= aEntries
[i
].aId
;
386 const String
SmFontFormatList::GetFontFormatId( const SmFontFormat
&rFntFmt
, BOOL bAdd
)
388 String
aRes( GetFontFormatId( rFntFmt
) );
389 if (0 == aRes
.Len() && bAdd
)
391 aRes
= GetNewFontFormatId();
392 AddFontFormat( aRes
, rFntFmt
);
398 const String
SmFontFormatList::GetFontFormatId( USHORT nPos
) const
401 if (nPos
< aEntries
.Count())
402 aRes
= aEntries
[nPos
].aId
;
407 const String
SmFontFormatList::GetNewFontFormatId() const
409 // returns first unused FormatId
413 String
aPrefix( RTL_CONSTASCII_STRINGPARAM( "Id" ) );
414 INT32 nCnt
= GetCount();
415 for (INT32 i
= 1; i
<= nCnt
+ 1 && 0 == aRes
.Len(); ++i
)
417 String
aTmpId( aPrefix
);
418 aTmpId
+= String::CreateFromInt32( i
);
419 if (!GetFontFormat( aTmpId
))
422 DBG_ASSERT( 0 != aRes
.Len(), "failed to create new FontFormatId" );
427 /////////////////////////////////////////////////////////////////
429 SmMathConfig::SmMathConfig() :
430 ConfigItem( String::CreateFromAscii( aRootName
))
437 bIsOtherModified
= bIsFormatModified
= FALSE
;
441 SmMathConfig::~SmMathConfig()
446 delete pFontFormatList
;
451 void SmMathConfig::SetOtherModified( BOOL bVal
)
453 bIsOtherModified
= bVal
;
457 void SmMathConfig::SetFormatModified( BOOL bVal
)
459 bIsFormatModified
= bVal
;
463 void SmMathConfig::SetFontFormatListModified( BOOL bVal
)
466 pFontFormatList
->SetModified( bVal
);
470 void SmMathConfig::ReadSymbol( SmSym
&rSymbol
,
471 const rtl::OUString
&rSymbolName
,
472 const rtl::OUString
&rBaseNode
) const
474 Sequence
< OUString
> aNames
= lcl_GetSymbolPropertyNames();
475 INT32 nProps
= aNames
.getLength();
477 OUString
aDelim( OUString::valueOf( (sal_Unicode
) '/' ) );
478 OUString
*pName
= aNames
.getArray();
479 for (INT32 i
= 0; i
< nProps
; ++i
)
481 OUString
&rName
= pName
[i
];
482 OUString
aTmp( rName
);
485 rName
+= rSymbolName
;
490 const Sequence
< Any
> aValues
= ((SmMathConfig
*) this)->GetProperties( aNames
);
492 if (nProps
&& aValues
.getLength() == nProps
)
494 const Any
* pValue
= aValues
.getConstArray();
496 sal_Unicode cChar
= '\0';
498 BOOL bPredefined
= FALSE
;
505 if (pValue
->hasValue() && (*pValue
>>= nTmp32
))
506 cChar
= (sal_Unicode
) nTmp32
;
510 if (pValue
->hasValue() && (*pValue
>>= aTmpStr
))
515 if (pValue
->hasValue() && (*pValue
>>= bTmp
))
520 if (pValue
->hasValue() && (*pValue
>>= aTmpStr
))
522 const SmFontFormat
*pFntFmt
= GetFontFormatList().GetFontFormat( aTmpStr
);
523 DBG_ASSERT( pFntFmt
, "unknown FontFormat" );
525 aFont
= pFntFmt
->GetFont();
533 String
aUiName( rSymbolName
);
534 String
aUiSetName( aSet
);
538 aTmp
= GetUiSymbolName( rSymbolName
);
539 DBG_ASSERT( aTmp
.Len(), "localized symbol-name not found" );
542 aTmp
= GetUiSymbolSetName( aSet
);
543 DBG_ASSERT( aTmp
.Len(), "localized symbolset-name not found" );
548 rSymbol
= SmSym( aUiName
, aFont
, cChar
, aUiSetName
, bPredefined
);
549 if (aUiName
!= String(rSymbolName
))
550 rSymbol
.SetExportName( rSymbolName
);
554 DBG_ERROR( "symbol read error" );
560 SmSymSetManager
& SmMathConfig::GetSymSetManager()
564 pSymSetMgr
= new SmSymSetManager
;
571 void SmMathConfig::Commit()
576 void SmMathConfig::Save()
580 SaveFontFormatList();
583 void SmMathConfig::GetSymbols( std::vector
< SmSym
> &rSymbols
) const
585 Sequence
< OUString
> aNodes( ((SmMathConfig
*) this)->GetNodeNames( A2OU( SYMBOL_LIST
) ) );
586 const OUString
*pNode
= aNodes
.getConstArray();
587 INT32 nNodes
= aNodes
.getLength();
589 rSymbols
.resize( nNodes
);
590 std::vector
< SmSym
>::iterator
aIt( rSymbols
.begin() );
591 std::vector
< SmSym
>::iterator
aEnd( rSymbols
.end() );
594 ReadSymbol( *aIt
++, *pNode
++, A2OU( SYMBOL_LIST
) );
599 void SmMathConfig::SetSymbols( const std::vector
< SmSym
> &rNewSymbols
)
601 sal_uIntPtr nCount
= rNewSymbols
.size();
603 Sequence
< OUString
> aNames
= lcl_GetSymbolPropertyNames();
604 const OUString
*pNames
= aNames
.getConstArray();
605 sal_uIntPtr nSymbolProps
= sal::static_int_cast
< UINT32
>(aNames
.getLength());
607 Sequence
< PropertyValue
> aValues( nCount
* nSymbolProps
);
608 PropertyValue
*pValues
= aValues
.getArray();
610 PropertyValue
*pVal
= pValues
;
611 OUString
aDelim( OUString::valueOf( (sal_Unicode
) '/' ) );
612 std::vector
< SmSym
>::const_iterator
aIt( rNewSymbols
.begin() );
613 std::vector
< SmSym
>::const_iterator
aEnd( rNewSymbols
.end() );
616 const SmSym
&rSymbol
= *aIt
++;
617 //const Font &rFont = rSymbol.GetFace();
618 OUString
aNodeNameDelim( A2OU( SYMBOL_LIST
) );
619 aNodeNameDelim
+= aDelim
;
620 aNodeNameDelim
+= rSymbol
.GetExportName();
621 aNodeNameDelim
+= aDelim
;
623 const OUString
*pName
= pNames
;
626 pVal
->Name
= aNodeNameDelim
;
627 pVal
->Name
+= *pName
++;
628 pVal
->Value
<<= (INT32
) rSymbol
.GetCharacter();
631 pVal
->Name
= aNodeNameDelim
;
632 pVal
->Name
+= *pName
++;
633 OUString
aTmp( rSymbol
.GetSetName() );
634 if (rSymbol
.IsPredefined())
635 aTmp
= GetExportSymbolSetName( aTmp
);
636 pVal
->Value
<<= aTmp
;
639 pVal
->Name
= aNodeNameDelim
;
640 pVal
->Name
+= *pName
++;
641 pVal
->Value
<<= (BOOL
) rSymbol
.IsPredefined();
644 SmFontFormat
aFntFmt( rSymbol
.GetFace() );
645 String
aFntFmtId( GetFontFormatList().GetFontFormatId( aFntFmt
, TRUE
) );
646 DBG_ASSERT( aFntFmtId
.Len(), "FontFormatId not found" );
647 pVal
->Name
= aNodeNameDelim
;
648 pVal
->Name
+= *pName
++;
649 pVal
->Value
<<= OUString( aFntFmtId
);
652 DBG_ASSERT( pVal
- pValues
== sal::static_int_cast
< ptrdiff_t >(nCount
* nSymbolProps
), "properties missing" );
653 ReplaceSetProperties( A2OU( SYMBOL_LIST
) , aValues
);
655 StripFontFormatList( rNewSymbols
);
656 SaveFontFormatList();
660 SmFontFormatList
& SmMathConfig::GetFontFormatList()
662 if (!pFontFormatList
)
664 LoadFontFormatList();
666 return *pFontFormatList
;
670 void SmMathConfig::LoadFontFormatList()
672 if (!pFontFormatList
)
673 pFontFormatList
= new SmFontFormatList
;
675 pFontFormatList
->Clear();
677 Sequence
< OUString
> aNodes( GetNodeNames( A2OU( FONT_FORMAT_LIST
) ) );
678 const OUString
*pNode
= aNodes
.getConstArray();
679 INT32 nNodes
= aNodes
.getLength();
681 for (INT32 i
= 0; i
< nNodes
; ++i
)
683 SmFontFormat aFntFmt
;
684 ReadFontFormat( aFntFmt
, pNode
[i
], A2OU( FONT_FORMAT_LIST
) );
685 if (!pFontFormatList
->GetFontFormat( pNode
[i
] ))
687 DBG_ASSERT( 0 == pFontFormatList
->GetFontFormat( pNode
[i
] ),
688 "FontFormat ID already exists" );
689 pFontFormatList
->AddFontFormat( pNode
[i
], aFntFmt
);
692 pFontFormatList
->SetModified( FALSE
);
696 void SmMathConfig::ReadFontFormat( SmFontFormat
&rFontFormat
,
697 const OUString
&rSymbolName
, const OUString
&rBaseNode
) const
699 Sequence
< OUString
> aNames
= lcl_GetFontPropertyNames();
700 INT32 nProps
= aNames
.getLength();
702 OUString
aDelim( OUString::valueOf( (sal_Unicode
) '/' ) );
703 OUString
*pName
= aNames
.getArray();
704 for (INT32 i
= 0; i
< nProps
; ++i
)
706 OUString
&rName
= pName
[i
];
707 OUString
aTmp( rName
);
710 rName
+= rSymbolName
;
715 const Sequence
< Any
> aValues
= ((SmMathConfig
*) this)->GetProperties( aNames
);
717 if (nProps
&& aValues
.getLength() == nProps
)
719 const Any
* pValue
= aValues
.getConstArray();
725 if (pValue
->hasValue() && (*pValue
>>= aTmpStr
))
726 rFontFormat
.aName
= aTmpStr
;
730 if (pValue
->hasValue() && (*pValue
>>= nTmp16
))
731 rFontFormat
.nCharSet
= nTmp16
; // 6.0 file-format GetSOLoadTextEncoding not needed
735 if (pValue
->hasValue() && (*pValue
>>= nTmp16
))
736 rFontFormat
.nFamily
= nTmp16
;
740 if (pValue
->hasValue() && (*pValue
>>= nTmp16
))
741 rFontFormat
.nPitch
= nTmp16
;
745 if (pValue
->hasValue() && (*pValue
>>= nTmp16
))
746 rFontFormat
.nWeight
= nTmp16
;
750 if (pValue
->hasValue() && (*pValue
>>= nTmp16
))
751 rFontFormat
.nItalic
= nTmp16
;
756 DBG_ASSERT( bOK
, "read FontFormat failed" );
761 void SmMathConfig::SaveFontFormatList()
763 SmFontFormatList
&rFntFmtList
= GetFontFormatList();
765 if (!rFntFmtList
.IsModified())
768 Sequence
< OUString
> aNames
= lcl_GetFontPropertyNames();
769 INT32 nSymbolProps
= aNames
.getLength();
771 USHORT nCount
= rFntFmtList
.GetCount();
773 Sequence
< PropertyValue
> aValues( nCount
* nSymbolProps
);
774 PropertyValue
*pValues
= aValues
.getArray();
776 PropertyValue
*pVal
= pValues
;
777 OUString
aDelim( OUString::valueOf( (sal_Unicode
) '/' ) );
778 for (USHORT i
= 0; i
< nCount
; ++i
)
780 String
aFntFmtId( rFntFmtList
.GetFontFormatId( i
) );
781 const SmFontFormat
aFntFmt( *rFntFmtList
.GetFontFormat( aFntFmtId
) );
783 OUString
aNodeNameDelim( A2OU( FONT_FORMAT_LIST
) );
784 aNodeNameDelim
+= aDelim
;
785 aNodeNameDelim
+= aFntFmtId
;
786 aNodeNameDelim
+= aDelim
;
788 const OUString
*pName
= aNames
.getConstArray();;
791 pVal
->Name
= aNodeNameDelim
;
792 pVal
->Name
+= *pName
++;
793 pVal
->Value
<<= OUString( aFntFmt
.aName
);
796 pVal
->Name
= aNodeNameDelim
;
797 pVal
->Name
+= *pName
++;
798 pVal
->Value
<<= (INT16
) aFntFmt
.nCharSet
; // 6.0 file-format GetSOStoreTextEncoding not needed
801 pVal
->Name
= aNodeNameDelim
;
802 pVal
->Name
+= *pName
++;
803 pVal
->Value
<<= (INT16
) aFntFmt
.nFamily
;
806 pVal
->Name
= aNodeNameDelim
;
807 pVal
->Name
+= *pName
++;
808 pVal
->Value
<<= (INT16
) aFntFmt
.nPitch
;
811 pVal
->Name
= aNodeNameDelim
;
812 pVal
->Name
+= *pName
++;
813 pVal
->Value
<<= (INT16
) aFntFmt
.nWeight
;
816 pVal
->Name
= aNodeNameDelim
;
817 pVal
->Name
+= *pName
++;
818 pVal
->Value
<<= (INT16
) aFntFmt
.nItalic
;
821 DBG_ASSERT( pVal
- pValues
== nCount
* nSymbolProps
, "properties missing" );
822 ReplaceSetProperties( A2OU( FONT_FORMAT_LIST
) , aValues
);
824 rFntFmtList
.SetModified( FALSE
);
828 void SmMathConfig::StripFontFormatList( const std::vector
< SmSym
> &rSymbols
)
830 size_t nCount
= rSymbols
.size();
833 // build list of used font-formats only
834 //!! font-format IDs may be different !!
835 SmFontFormatList aUsedList
;
836 for (i
= 0; i
< nCount
; ++i
)
838 DBG_ASSERT( rSymbols
[i
].GetName().Len() > 0, "non named symbol" );
839 aUsedList
.GetFontFormatId( SmFontFormat( rSymbols
[i
].GetFace() ) , TRUE
);
841 const SmFormat
& rStdFmt
= GetStandardFormat();
842 for (i
= FNT_BEGIN
; i
<= FNT_END
; ++i
)
844 aUsedList
.GetFontFormatId( SmFontFormat( rStdFmt
.GetFont( i
) ) , TRUE
);
847 // remove unused font-formats from list
848 SmFontFormatList
&rFntFmtList
= GetFontFormatList();
849 USHORT nCnt
= rFntFmtList
.GetCount();
850 SmFontFormat
*pTmpFormat
= new SmFontFormat
[ nCnt
];
851 String
*pId
= new String
[ nCnt
];
853 for (k
= 0; k
< nCnt
; ++k
)
855 pTmpFormat
[k
] = *rFntFmtList
.GetFontFormat( (USHORT
) k
);
856 pId
[k
] = rFntFmtList
.GetFontFormatId( (USHORT
) k
);
858 for (k
= 0; k
< nCnt
; ++k
)
860 if (0 == aUsedList
.GetFontFormatId( pTmpFormat
[k
] ).Len())
862 rFntFmtList
.RemoveFontFormat( pId
[k
] );
866 delete [] pTmpFormat
;
870 void SmMathConfig::LoadOther()
873 pOther
= new SmCfgOther
;
875 Sequence
< OUString
> aNames( GetOtherPropertyNames() );
876 INT32 nProps
= aNames
.getLength();
878 Sequence
< Any
> aValues( GetProperties( aNames
) );
879 if (nProps
&& aValues
.getLength() == nProps
)
881 const Any
*pValues
= aValues
.getConstArray();
882 const Any
*pVal
= pValues
;
888 if (pVal
->hasValue() && (*pVal
>>= bTmp
))
889 pOther
->bPrintTitle
= bTmp
;
892 if (pVal
->hasValue() && (*pVal
>>= bTmp
))
893 pOther
->bPrintFormulaText
= bTmp
;
896 if (pVal
->hasValue() && (*pVal
>>= bTmp
))
897 pOther
->bPrintFrame
= bTmp
;
900 if (pVal
->hasValue() && (*pVal
>>= nTmp16
))
901 pOther
->ePrintSize
= (SmPrintSize
) nTmp16
;
904 if (pVal
->hasValue() && (*pVal
>>= nTmp16
))
905 pOther
->nPrintZoomFactor
= nTmp16
;
907 // Misc/NoSymbolsWarning
908 if (pVal->hasValue() && (*pVal >>= bTmp))
909 pOther->bNoSymbolsWarning = bTmp;
912 // Misc/IgnoreSpacesRight
913 if (pVal
->hasValue() && (*pVal
>>= bTmp
))
914 pOther
->bIgnoreSpacesRight
= bTmp
;
916 // View/ToolboxVisible
917 if (pVal
->hasValue() && (*pVal
>>= bTmp
))
918 pOther
->bToolboxVisible
= bTmp
;
921 if (pVal
->hasValue() && (*pVal
>>= bTmp
))
922 pOther
->bAutoRedraw
= bTmp
;
924 // View/FormulaCursor
925 if (pVal
->hasValue() && (*pVal
>>= bTmp
))
926 pOther
->bFormulaCursor
= bTmp
;
929 DBG_ASSERT( pVal
- pValues
== nProps
, "property mismatch" );
930 SetOtherModified( FALSE
);
935 void SmMathConfig::SaveOther()
937 if (!pOther
|| !IsOtherModified())
940 const Sequence
< OUString
> aNames( GetOtherPropertyNames() );
941 INT32 nProps
= aNames
.getLength();
943 Sequence
< Any
> aValues( nProps
);
944 Any
*pValues
= aValues
.getArray();
945 Any
*pValue
= pValues
;
948 *pValue
++ <<= (BOOL
) pOther
->bPrintTitle
;
950 *pValue
++ <<= (BOOL
) pOther
->bPrintFormulaText
;
952 *pValue
++ <<= (BOOL
) pOther
->bPrintFrame
;
954 *pValue
++ <<= (INT16
) pOther
->ePrintSize
;
956 *pValue
++ <<= (INT16
) pOther
->nPrintZoomFactor
;
957 /* // Misc/NoSymbolsWarning
958 *pValue++ <<= (BOOL) pOther->bNoSymbolsWarning;
960 // Misc/IgnoreSpacesRight
961 *pValue
++ <<= (BOOL
) pOther
->bIgnoreSpacesRight
;
962 // View/ToolboxVisible
963 *pValue
++ <<= (BOOL
) pOther
->bToolboxVisible
;
965 *pValue
++ <<= (BOOL
) pOther
->bAutoRedraw
;
966 // View/FormulaCursor
967 *pValue
++ <<= (BOOL
) pOther
->bFormulaCursor
;
969 DBG_ASSERT( pValue
- pValues
== nProps
, "property mismatch" );
970 PutProperties( aNames
, aValues
);
972 SetOtherModified( FALSE
);
975 void SmMathConfig::LoadFormat()
978 pFormat
= new SmFormat
;
981 Sequence
< OUString
> aNames( GetFormatPropertyNames() );
982 INT32 nProps
= aNames
.getLength();
984 Sequence
< Any
> aValues( GetProperties( aNames
) );
985 if (nProps
&& aValues
.getLength() == nProps
)
987 const Any
*pValues
= aValues
.getConstArray();
988 const Any
*pVal
= pValues
;
994 // StandardFormat/Textmode
995 if (pVal
->hasValue() && (*pVal
>>= bTmp
))
996 pFormat
->SetTextmode( bTmp
);
998 // StandardFormat/ScaleNormalBracket
999 if (pVal
->hasValue() && (*pVal
>>= bTmp
))
1000 pFormat
->SetScaleNormalBrackets( bTmp
);
1002 // StandardFormat/HorizontalAlignment
1003 if (pVal
->hasValue() && (*pVal
>>= nTmp16
))
1004 pFormat
->SetHorAlign( (SmHorAlign
) nTmp16
);
1006 // StandardFormat/BaseSize
1007 if (pVal
->hasValue() && (*pVal
>>= nTmp16
))
1008 pFormat
->SetBaseSize( Size(0, SmPtsTo100th_mm( nTmp16
)) );
1012 for (i
= SIZ_BEGIN
; i
<= SIZ_END
; ++i
)
1014 if (pVal
->hasValue() && (*pVal
>>= nTmp16
))
1015 pFormat
->SetRelSize( i
, nTmp16
);
1019 for (i
= DIS_BEGIN
; i
<= DIS_END
; ++i
)
1021 if (pVal
->hasValue() && (*pVal
>>= nTmp16
))
1022 pFormat
->SetDistance( i
, nTmp16
);
1026 LanguageType nLang
= Application::GetSettings().GetUILanguage();
1027 for (i
= FNT_BEGIN
; i
< FNT_END
; ++i
)
1030 BOOL bUseDefaultFont
= TRUE
;
1031 if (pVal
->hasValue() && (*pVal
>>= aTmpStr
))
1033 bUseDefaultFont
= 0 == aTmpStr
.getLength();
1034 if (bUseDefaultFont
)
1036 aFnt
= pFormat
->GetFont( i
);
1037 aFnt
.SetName( GetDefaultFontName( nLang
, i
) );
1041 const SmFontFormat
*pFntFmt
= GetFontFormatList().GetFontFormat( aTmpStr
);
1042 DBG_ASSERT( pFntFmt
, "unknown FontFormat" );
1044 aFnt
= pFntFmt
->GetFont();
1049 aFnt
.SetSize( pFormat
->GetBaseSize() );
1050 pFormat
->SetFont( i
, aFnt
, bUseDefaultFont
);
1053 DBG_ASSERT( pVal
- pValues
== nProps
, "property mismatch" );
1054 SetFormatModified( FALSE
);
1059 void SmMathConfig::SaveFormat()
1061 if (!pFormat
|| !IsFormatModified())
1064 const Sequence
< OUString
> aNames( GetFormatPropertyNames() );
1065 INT32 nProps
= aNames
.getLength();
1067 Sequence
< Any
> aValues( nProps
);
1068 Any
*pValues
= aValues
.getArray();
1069 Any
*pValue
= pValues
;
1071 // StandardFormat/Textmode
1072 *pValue
++ <<= (BOOL
) pFormat
->IsTextmode();
1073 // StandardFormat/ScaleNormalBracket
1074 *pValue
++ <<= (BOOL
) pFormat
->IsScaleNormalBrackets();
1075 // StandardFormat/HorizontalAlignment
1076 *pValue
++ <<= (INT16
) pFormat
->GetHorAlign();
1077 // StandardFormat/BaseSize
1078 *pValue
++ <<= (INT16
) SmRoundFraction( Sm100th_mmToPts(
1079 pFormat
->GetBaseSize().Height() ) );
1082 for (i
= SIZ_BEGIN
; i
<= SIZ_END
; ++i
)
1083 *pValue
++ <<= (INT16
) pFormat
->GetRelSize( i
);
1085 for (i
= DIS_BEGIN
; i
<= DIS_END
; ++i
)
1086 *pValue
++ <<= (INT16
) pFormat
->GetDistance( i
);
1088 for (i
= FNT_BEGIN
; i
< FNT_END
; ++i
)
1092 if (!pFormat
->IsDefaultFont( i
))
1094 SmFontFormat
aFntFmt( pFormat
->GetFont( i
) );
1095 aFntFmtId
= GetFontFormatList().GetFontFormatId( aFntFmt
, TRUE
);
1096 DBG_ASSERT( aFntFmtId
.getLength(), "FontFormatId not found" );
1099 *pValue
++ <<= aFntFmtId
;
1102 DBG_ASSERT( pValue
- pValues
== nProps
, "property mismatch" );
1103 PutProperties( aNames
, aValues
);
1105 SetFormatModified( FALSE
);
1109 const SmFormat
& SmMathConfig::GetStandardFormat() const
1112 ((SmMathConfig
*) this)->LoadFormat();
1117 void SmMathConfig::SetStandardFormat( const SmFormat
&rFormat
, BOOL bSaveFontFormatList
)
1121 if (rFormat
!= *pFormat
)
1124 SetFormatModified( TRUE
);
1127 if (bSaveFontFormatList
)
1129 // needed for SmFontTypeDialog's DefaultButtonClickHdl
1130 SetFontFormatListModified( TRUE
);
1131 SaveFontFormatList();
1137 SmPrintSize
SmMathConfig::GetPrintSize() const
1140 ((SmMathConfig
*) this)->LoadOther();
1141 return pOther
->ePrintSize
;
1145 void SmMathConfig::SetPrintSize( SmPrintSize eSize
)
1149 if (eSize
!= pOther
->ePrintSize
)
1151 pOther
->ePrintSize
= eSize
;
1152 SetOtherModified( TRUE
);
1157 USHORT
SmMathConfig::GetPrintZoomFactor() const
1160 ((SmMathConfig
*) this)->LoadOther();
1161 return pOther
->nPrintZoomFactor
;
1165 void SmMathConfig::SetPrintZoomFactor( USHORT nVal
)
1169 if (nVal
!= pOther
->nPrintZoomFactor
)
1171 pOther
->nPrintZoomFactor
= nVal
;
1172 SetOtherModified( TRUE
);
1177 void SmMathConfig::SetOtherIfNotEqual( BOOL
&rbItem
, BOOL bNewVal
)
1179 if (bNewVal
!= rbItem
)
1182 SetOtherModified( TRUE
);
1187 BOOL
SmMathConfig::IsPrintTitle() const
1190 ((SmMathConfig
*) this)->LoadOther();
1191 return pOther
->bPrintTitle
;
1195 void SmMathConfig::SetPrintTitle( BOOL bVal
)
1199 SetOtherIfNotEqual( pOther
->bPrintTitle
, bVal
);
1203 BOOL
SmMathConfig::IsPrintFormulaText() const
1206 ((SmMathConfig
*) this)->LoadOther();
1207 return pOther
->bPrintFormulaText
;
1211 void SmMathConfig::SetPrintFormulaText( BOOL bVal
)
1215 SetOtherIfNotEqual( pOther
->bPrintFormulaText
, bVal
);
1219 BOOL
SmMathConfig::IsPrintFrame() const
1222 ((SmMathConfig
*) this)->LoadOther();
1223 return pOther
->bPrintFrame
;
1227 void SmMathConfig::SetPrintFrame( BOOL bVal
)
1231 SetOtherIfNotEqual( pOther
->bPrintFrame
, bVal
);
1235 BOOL
SmMathConfig::IsIgnoreSpacesRight() const
1238 ((SmMathConfig
*) this)->LoadOther();
1239 return pOther
->bIgnoreSpacesRight
;
1243 void SmMathConfig::SetIgnoreSpacesRight( BOOL bVal
)
1247 SetOtherIfNotEqual( pOther
->bIgnoreSpacesRight
, bVal
);
1251 BOOL
SmMathConfig::IsAutoRedraw() const
1254 ((SmMathConfig
*) this)->LoadOther();
1255 return pOther
->bAutoRedraw
;
1259 void SmMathConfig::SetAutoRedraw( BOOL bVal
)
1263 SetOtherIfNotEqual( pOther
->bAutoRedraw
, bVal
);
1267 BOOL
SmMathConfig::IsShowFormulaCursor() const
1270 ((SmMathConfig
*) this)->LoadOther();
1271 return pOther
->bFormulaCursor
;
1275 void SmMathConfig::SetShowFormulaCursor( BOOL bVal
)
1279 SetOtherIfNotEqual( pOther
->bFormulaCursor
, bVal
);
1283 /////////////////////////////////////////////////////////////////