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();
584 USHORT
SmMathConfig::GetSymbolCount() const
586 return ((SmMathConfig
*) this)->GetSymSetManager().GetSymbolCount();
590 const SmSym
* SmMathConfig::GetSymbol( USHORT nIndex
) const
592 return ((SmMathConfig
*) this)->GetSymSetManager().GetSymbolByPos( nIndex
);
596 void SmMathConfig::GetSymbols( std::vector
< SmSym
> &rSymbols
) const
598 Sequence
< OUString
> aNodes( ((SmMathConfig
*) this)->GetNodeNames( A2OU( SYMBOL_LIST
) ) );
599 const OUString
*pNode
= aNodes
.getConstArray();
600 INT32 nNodes
= aNodes
.getLength();
602 rSymbols
.resize( nNodes
);
603 std::vector
< SmSym
>::iterator
aIt( rSymbols
.begin() );
604 std::vector
< SmSym
>::iterator
aEnd( rSymbols
.end() );
607 ReadSymbol( *aIt
++, *pNode
++, A2OU( SYMBOL_LIST
) );
612 void SmMathConfig::SetSymbols( const std::vector
< SmSym
> &rNewSymbols
)
614 sal_uIntPtr nCount
= rNewSymbols
.size();
616 Sequence
< OUString
> aNames
= lcl_GetSymbolPropertyNames();
617 const OUString
*pNames
= aNames
.getConstArray();
618 sal_uIntPtr nSymbolProps
= sal::static_int_cast
< UINT32
>(aNames
.getLength());
620 Sequence
< PropertyValue
> aValues( nCount
* nSymbolProps
);
621 PropertyValue
*pValues
= aValues
.getArray();
623 PropertyValue
*pVal
= pValues
;
624 OUString
aDelim( OUString::valueOf( (sal_Unicode
) '/' ) );
625 std::vector
< SmSym
>::const_iterator
aIt( rNewSymbols
.begin() );
626 std::vector
< SmSym
>::const_iterator
aEnd( rNewSymbols
.end() );
629 const SmSym
&rSymbol
= *aIt
++;
630 //const Font &rFont = rSymbol.GetFace();
631 OUString
aNodeNameDelim( A2OU( SYMBOL_LIST
) );
632 aNodeNameDelim
+= aDelim
;
633 aNodeNameDelim
+= rSymbol
.GetExportName();
634 aNodeNameDelim
+= aDelim
;
636 const OUString
*pName
= pNames
;
639 pVal
->Name
= aNodeNameDelim
;
640 pVal
->Name
+= *pName
++;
641 pVal
->Value
<<= (INT32
) rSymbol
.GetCharacter();
644 pVal
->Name
= aNodeNameDelim
;
645 pVal
->Name
+= *pName
++;
646 OUString
aTmp( rSymbol
.GetSetName() );
647 if (rSymbol
.IsPredefined())
648 aTmp
= GetExportSymbolSetName( aTmp
);
649 pVal
->Value
<<= aTmp
;
652 pVal
->Name
= aNodeNameDelim
;
653 pVal
->Name
+= *pName
++;
654 pVal
->Value
<<= (BOOL
) rSymbol
.IsPredefined();
657 SmFontFormat
aFntFmt( rSymbol
.GetFace() );
658 String
aFntFmtId( GetFontFormatList().GetFontFormatId( aFntFmt
, TRUE
) );
659 DBG_ASSERT( aFntFmtId
.Len(), "FontFormatId not found" );
660 pVal
->Name
= aNodeNameDelim
;
661 pVal
->Name
+= *pName
++;
662 pVal
->Value
<<= OUString( aFntFmtId
);
665 DBG_ASSERT( pVal
- pValues
== sal::static_int_cast
< ptrdiff_t >(nCount
* nSymbolProps
), "properties missing" );
666 ReplaceSetProperties( A2OU( SYMBOL_LIST
) , aValues
);
668 StripFontFormatList( rNewSymbols
);
669 SaveFontFormatList();
673 SmFontFormatList
& SmMathConfig::GetFontFormatList()
675 if (!pFontFormatList
)
677 LoadFontFormatList();
679 return *pFontFormatList
;
683 void SmMathConfig::LoadFontFormatList()
685 if (!pFontFormatList
)
686 pFontFormatList
= new SmFontFormatList
;
688 pFontFormatList
->Clear();
690 Sequence
< OUString
> aNodes( GetNodeNames( A2OU( FONT_FORMAT_LIST
) ) );
691 const OUString
*pNode
= aNodes
.getConstArray();
692 INT32 nNodes
= aNodes
.getLength();
694 for (INT32 i
= 0; i
< nNodes
; ++i
)
696 SmFontFormat aFntFmt
;
697 ReadFontFormat( aFntFmt
, pNode
[i
], A2OU( FONT_FORMAT_LIST
) );
698 if (!pFontFormatList
->GetFontFormat( pNode
[i
] ))
700 DBG_ASSERT( 0 == pFontFormatList
->GetFontFormat( pNode
[i
] ),
701 "FontFormat ID already exists" );
702 pFontFormatList
->AddFontFormat( pNode
[i
], aFntFmt
);
705 pFontFormatList
->SetModified( FALSE
);
709 void SmMathConfig::ReadFontFormat( SmFontFormat
&rFontFormat
,
710 const OUString
&rSymbolName
, const OUString
&rBaseNode
) const
712 Sequence
< OUString
> aNames
= lcl_GetFontPropertyNames();
713 INT32 nProps
= aNames
.getLength();
715 OUString
aDelim( OUString::valueOf( (sal_Unicode
) '/' ) );
716 OUString
*pName
= aNames
.getArray();
717 for (INT32 i
= 0; i
< nProps
; ++i
)
719 OUString
&rName
= pName
[i
];
720 OUString
aTmp( rName
);
723 rName
+= rSymbolName
;
728 const Sequence
< Any
> aValues
= ((SmMathConfig
*) this)->GetProperties( aNames
);
730 if (nProps
&& aValues
.getLength() == nProps
)
732 const Any
* pValue
= aValues
.getConstArray();
738 if (pValue
->hasValue() && (*pValue
>>= aTmpStr
))
739 rFontFormat
.aName
= aTmpStr
;
743 if (pValue
->hasValue() && (*pValue
>>= nTmp16
))
744 rFontFormat
.nCharSet
= nTmp16
; // 6.0 file-format GetSOLoadTextEncoding not needed
748 if (pValue
->hasValue() && (*pValue
>>= nTmp16
))
749 rFontFormat
.nFamily
= nTmp16
;
753 if (pValue
->hasValue() && (*pValue
>>= nTmp16
))
754 rFontFormat
.nPitch
= nTmp16
;
758 if (pValue
->hasValue() && (*pValue
>>= nTmp16
))
759 rFontFormat
.nWeight
= nTmp16
;
763 if (pValue
->hasValue() && (*pValue
>>= nTmp16
))
764 rFontFormat
.nItalic
= nTmp16
;
769 DBG_ASSERT( bOK
, "read FontFormat failed" );
774 void SmMathConfig::SaveFontFormatList()
776 SmFontFormatList
&rFntFmtList
= GetFontFormatList();
778 if (!rFntFmtList
.IsModified())
781 Sequence
< OUString
> aNames
= lcl_GetFontPropertyNames();
782 INT32 nSymbolProps
= aNames
.getLength();
784 USHORT nCount
= rFntFmtList
.GetCount();
786 Sequence
< PropertyValue
> aValues( nCount
* nSymbolProps
);
787 PropertyValue
*pValues
= aValues
.getArray();
789 PropertyValue
*pVal
= pValues
;
790 OUString
aDelim( OUString::valueOf( (sal_Unicode
) '/' ) );
791 for (USHORT i
= 0; i
< nCount
; ++i
)
793 String
aFntFmtId( rFntFmtList
.GetFontFormatId( i
) );
794 const SmFontFormat
aFntFmt( *rFntFmtList
.GetFontFormat( aFntFmtId
) );
796 OUString
aNodeNameDelim( A2OU( FONT_FORMAT_LIST
) );
797 aNodeNameDelim
+= aDelim
;
798 aNodeNameDelim
+= aFntFmtId
;
799 aNodeNameDelim
+= aDelim
;
801 const OUString
*pName
= aNames
.getConstArray();;
804 pVal
->Name
= aNodeNameDelim
;
805 pVal
->Name
+= *pName
++;
806 pVal
->Value
<<= OUString( aFntFmt
.aName
);
809 pVal
->Name
= aNodeNameDelim
;
810 pVal
->Name
+= *pName
++;
811 pVal
->Value
<<= (INT16
) aFntFmt
.nCharSet
; // 6.0 file-format GetSOStoreTextEncoding not needed
814 pVal
->Name
= aNodeNameDelim
;
815 pVal
->Name
+= *pName
++;
816 pVal
->Value
<<= (INT16
) aFntFmt
.nFamily
;
819 pVal
->Name
= aNodeNameDelim
;
820 pVal
->Name
+= *pName
++;
821 pVal
->Value
<<= (INT16
) aFntFmt
.nPitch
;
824 pVal
->Name
= aNodeNameDelim
;
825 pVal
->Name
+= *pName
++;
826 pVal
->Value
<<= (INT16
) aFntFmt
.nWeight
;
829 pVal
->Name
= aNodeNameDelim
;
830 pVal
->Name
+= *pName
++;
831 pVal
->Value
<<= (INT16
) aFntFmt
.nItalic
;
834 DBG_ASSERT( pVal
- pValues
== nCount
* nSymbolProps
, "properties missing" );
835 ReplaceSetProperties( A2OU( FONT_FORMAT_LIST
) , aValues
);
837 rFntFmtList
.SetModified( FALSE
);
841 void SmMathConfig::StripFontFormatList( const std::vector
< SmSym
> &rSymbols
)
843 size_t nCount
= rSymbols
.size();
846 // build list of used font-formats only
847 //!! font-format IDs may be different !!
848 SmFontFormatList aUsedList
;
849 for (i
= 0; i
< nCount
; ++i
)
851 DBG_ASSERT( rSymbols
[i
].GetName().Len() > 0, "non named symbol" );
852 aUsedList
.GetFontFormatId( SmFontFormat( rSymbols
[i
].GetFace() ) , TRUE
);
854 const SmFormat
& rStdFmt
= GetStandardFormat();
855 for (i
= FNT_BEGIN
; i
<= FNT_END
; ++i
)
857 aUsedList
.GetFontFormatId( SmFontFormat( rStdFmt
.GetFont( i
) ) , TRUE
);
860 // remove unused font-formats from list
861 SmFontFormatList
&rFntFmtList
= GetFontFormatList();
862 USHORT nCnt
= rFntFmtList
.GetCount();
863 SmFontFormat
*pTmpFormat
= new SmFontFormat
[ nCnt
];
864 String
*pId
= new String
[ nCnt
];
866 for (k
= 0; k
< nCnt
; ++k
)
868 pTmpFormat
[k
] = *rFntFmtList
.GetFontFormat( (USHORT
) k
);
869 pId
[k
] = rFntFmtList
.GetFontFormatId( (USHORT
) k
);
871 for (k
= 0; k
< nCnt
; ++k
)
873 if (0 == aUsedList
.GetFontFormatId( pTmpFormat
[k
] ).Len())
875 rFntFmtList
.RemoveFontFormat( pId
[k
] );
879 delete [] pTmpFormat
;
883 void SmMathConfig::LoadOther()
886 pOther
= new SmCfgOther
;
888 Sequence
< OUString
> aNames( GetOtherPropertyNames() );
889 INT32 nProps
= aNames
.getLength();
891 Sequence
< Any
> aValues( GetProperties( aNames
) );
892 if (nProps
&& aValues
.getLength() == nProps
)
894 const Any
*pValues
= aValues
.getConstArray();
895 const Any
*pVal
= pValues
;
901 if (pVal
->hasValue() && (*pVal
>>= bTmp
))
902 pOther
->bPrintTitle
= bTmp
;
905 if (pVal
->hasValue() && (*pVal
>>= bTmp
))
906 pOther
->bPrintFormulaText
= bTmp
;
909 if (pVal
->hasValue() && (*pVal
>>= bTmp
))
910 pOther
->bPrintFrame
= bTmp
;
913 if (pVal
->hasValue() && (*pVal
>>= nTmp16
))
914 pOther
->ePrintSize
= (SmPrintSize
) nTmp16
;
917 if (pVal
->hasValue() && (*pVal
>>= nTmp16
))
918 pOther
->nPrintZoomFactor
= nTmp16
;
920 // Misc/NoSymbolsWarning
921 if (pVal->hasValue() && (*pVal >>= bTmp))
922 pOther->bNoSymbolsWarning = bTmp;
925 // Misc/IgnoreSpacesRight
926 if (pVal
->hasValue() && (*pVal
>>= bTmp
))
927 pOther
->bIgnoreSpacesRight
= bTmp
;
929 // View/ToolboxVisible
930 if (pVal
->hasValue() && (*pVal
>>= bTmp
))
931 pOther
->bToolboxVisible
= bTmp
;
934 if (pVal
->hasValue() && (*pVal
>>= bTmp
))
935 pOther
->bAutoRedraw
= bTmp
;
937 // View/FormulaCursor
938 if (pVal
->hasValue() && (*pVal
>>= bTmp
))
939 pOther
->bFormulaCursor
= bTmp
;
942 DBG_ASSERT( pVal
- pValues
== nProps
, "property mismatch" );
943 SetOtherModified( FALSE
);
948 void SmMathConfig::SaveOther()
950 if (!pOther
|| !IsOtherModified())
953 const Sequence
< OUString
> aNames( GetOtherPropertyNames() );
954 INT32 nProps
= aNames
.getLength();
956 Sequence
< Any
> aValues( nProps
);
957 Any
*pValues
= aValues
.getArray();
958 Any
*pValue
= pValues
;
961 *pValue
++ <<= (BOOL
) pOther
->bPrintTitle
;
963 *pValue
++ <<= (BOOL
) pOther
->bPrintFormulaText
;
965 *pValue
++ <<= (BOOL
) pOther
->bPrintFrame
;
967 *pValue
++ <<= (INT16
) pOther
->ePrintSize
;
969 *pValue
++ <<= (INT16
) pOther
->nPrintZoomFactor
;
970 /* // Misc/NoSymbolsWarning
971 *pValue++ <<= (BOOL) pOther->bNoSymbolsWarning;
973 // Misc/IgnoreSpacesRight
974 *pValue
++ <<= (BOOL
) pOther
->bIgnoreSpacesRight
;
975 // View/ToolboxVisible
976 *pValue
++ <<= (BOOL
) pOther
->bToolboxVisible
;
978 *pValue
++ <<= (BOOL
) pOther
->bAutoRedraw
;
979 // View/FormulaCursor
980 *pValue
++ <<= (BOOL
) pOther
->bFormulaCursor
;
982 DBG_ASSERT( pValue
- pValues
== nProps
, "property mismatch" );
983 PutProperties( aNames
, aValues
);
985 SetOtherModified( FALSE
);
988 void SmMathConfig::LoadFormat()
991 pFormat
= new SmFormat
;
994 Sequence
< OUString
> aNames( GetFormatPropertyNames() );
995 INT32 nProps
= aNames
.getLength();
997 Sequence
< Any
> aValues( GetProperties( aNames
) );
998 if (nProps
&& aValues
.getLength() == nProps
)
1000 const Any
*pValues
= aValues
.getConstArray();
1001 const Any
*pVal
= pValues
;
1007 // StandardFormat/Textmode
1008 if (pVal
->hasValue() && (*pVal
>>= bTmp
))
1009 pFormat
->SetTextmode( bTmp
);
1011 // StandardFormat/ScaleNormalBracket
1012 if (pVal
->hasValue() && (*pVal
>>= bTmp
))
1013 pFormat
->SetScaleNormalBrackets( bTmp
);
1015 // StandardFormat/HorizontalAlignment
1016 if (pVal
->hasValue() && (*pVal
>>= nTmp16
))
1017 pFormat
->SetHorAlign( (SmHorAlign
) nTmp16
);
1019 // StandardFormat/BaseSize
1020 if (pVal
->hasValue() && (*pVal
>>= nTmp16
))
1021 pFormat
->SetBaseSize( Size(0, SmPtsTo100th_mm( nTmp16
)) );
1025 for (i
= SIZ_BEGIN
; i
<= SIZ_END
; ++i
)
1027 if (pVal
->hasValue() && (*pVal
>>= nTmp16
))
1028 pFormat
->SetRelSize( i
, nTmp16
);
1032 for (i
= DIS_BEGIN
; i
<= DIS_END
; ++i
)
1034 if (pVal
->hasValue() && (*pVal
>>= nTmp16
))
1035 pFormat
->SetDistance( i
, nTmp16
);
1039 LanguageType nLang
= Application::GetSettings().GetUILanguage();
1040 for (i
= FNT_BEGIN
; i
< FNT_END
; ++i
)
1043 BOOL bUseDefaultFont
= TRUE
;
1044 if (pVal
->hasValue() && (*pVal
>>= aTmpStr
))
1046 bUseDefaultFont
= 0 == aTmpStr
.getLength();
1047 if (bUseDefaultFont
)
1049 aFnt
= pFormat
->GetFont( i
);
1050 aFnt
.SetName( GetDefaultFontName( nLang
, i
) );
1054 const SmFontFormat
*pFntFmt
= GetFontFormatList().GetFontFormat( aTmpStr
);
1055 DBG_ASSERT( pFntFmt
, "unknown FontFormat" );
1057 aFnt
= pFntFmt
->GetFont();
1062 aFnt
.SetSize( pFormat
->GetBaseSize() );
1063 pFormat
->SetFont( i
, aFnt
, bUseDefaultFont
);
1066 DBG_ASSERT( pVal
- pValues
== nProps
, "property mismatch" );
1067 SetFormatModified( FALSE
);
1072 void SmMathConfig::SaveFormat()
1074 if (!pFormat
|| !IsFormatModified())
1077 const Sequence
< OUString
> aNames( GetFormatPropertyNames() );
1078 INT32 nProps
= aNames
.getLength();
1080 Sequence
< Any
> aValues( nProps
);
1081 Any
*pValues
= aValues
.getArray();
1082 Any
*pValue
= pValues
;
1084 // StandardFormat/Textmode
1085 *pValue
++ <<= (BOOL
) pFormat
->IsTextmode();
1086 // StandardFormat/ScaleNormalBracket
1087 *pValue
++ <<= (BOOL
) pFormat
->IsScaleNormalBrackets();
1088 // StandardFormat/HorizontalAlignment
1089 *pValue
++ <<= (INT16
) pFormat
->GetHorAlign();
1090 // StandardFormat/BaseSize
1091 *pValue
++ <<= (INT16
) SmRoundFraction( Sm100th_mmToPts(
1092 pFormat
->GetBaseSize().Height() ) );
1095 for (i
= SIZ_BEGIN
; i
<= SIZ_END
; ++i
)
1096 *pValue
++ <<= (INT16
) pFormat
->GetRelSize( i
);
1098 for (i
= DIS_BEGIN
; i
<= DIS_END
; ++i
)
1099 *pValue
++ <<= (INT16
) pFormat
->GetDistance( i
);
1101 for (i
= FNT_BEGIN
; i
< FNT_END
; ++i
)
1105 if (!pFormat
->IsDefaultFont( i
))
1107 SmFontFormat
aFntFmt( pFormat
->GetFont( i
) );
1108 aFntFmtId
= GetFontFormatList().GetFontFormatId( aFntFmt
, TRUE
);
1109 DBG_ASSERT( aFntFmtId
.getLength(), "FontFormatId not found" );
1112 *pValue
++ <<= aFntFmtId
;
1115 DBG_ASSERT( pValue
- pValues
== nProps
, "property mismatch" );
1116 PutProperties( aNames
, aValues
);
1118 SetFormatModified( FALSE
);
1122 const SmFormat
& SmMathConfig::GetStandardFormat() const
1125 ((SmMathConfig
*) this)->LoadFormat();
1130 void SmMathConfig::SetStandardFormat( const SmFormat
&rFormat
, BOOL bSaveFontFormatList
)
1134 if (rFormat
!= *pFormat
)
1137 SetFormatModified( TRUE
);
1140 if (bSaveFontFormatList
)
1142 // needed for SmFontTypeDialog's DefaultButtonClickHdl
1143 SetFontFormatListModified( TRUE
);
1144 SaveFontFormatList();
1150 SmPrintSize
SmMathConfig::GetPrintSize() const
1153 ((SmMathConfig
*) this)->LoadOther();
1154 return pOther
->ePrintSize
;
1158 void SmMathConfig::SetPrintSize( SmPrintSize eSize
)
1162 if (eSize
!= pOther
->ePrintSize
)
1164 pOther
->ePrintSize
= eSize
;
1165 SetOtherModified( TRUE
);
1170 USHORT
SmMathConfig::GetPrintZoomFactor() const
1173 ((SmMathConfig
*) this)->LoadOther();
1174 return pOther
->nPrintZoomFactor
;
1178 void SmMathConfig::SetPrintZoomFactor( USHORT nVal
)
1182 if (nVal
!= pOther
->nPrintZoomFactor
)
1184 pOther
->nPrintZoomFactor
= nVal
;
1185 SetOtherModified( TRUE
);
1190 void SmMathConfig::SetOtherIfNotEqual( BOOL
&rbItem
, BOOL bNewVal
)
1192 if (bNewVal
!= rbItem
)
1195 SetOtherModified( TRUE
);
1200 BOOL
SmMathConfig::IsPrintTitle() const
1203 ((SmMathConfig
*) this)->LoadOther();
1204 return pOther
->bPrintTitle
;
1208 void SmMathConfig::SetPrintTitle( BOOL bVal
)
1212 SetOtherIfNotEqual( pOther
->bPrintTitle
, bVal
);
1216 BOOL
SmMathConfig::IsPrintFormulaText() const
1219 ((SmMathConfig
*) this)->LoadOther();
1220 return pOther
->bPrintFormulaText
;
1224 void SmMathConfig::SetPrintFormulaText( BOOL bVal
)
1228 SetOtherIfNotEqual( pOther
->bPrintFormulaText
, bVal
);
1232 BOOL
SmMathConfig::IsPrintFrame() const
1235 ((SmMathConfig
*) this)->LoadOther();
1236 return pOther
->bPrintFrame
;
1240 void SmMathConfig::SetPrintFrame( BOOL bVal
)
1244 SetOtherIfNotEqual( pOther
->bPrintFrame
, bVal
);
1248 BOOL
SmMathConfig::IsIgnoreSpacesRight() const
1251 ((SmMathConfig
*) this)->LoadOther();
1252 return pOther
->bIgnoreSpacesRight
;
1256 void SmMathConfig::SetIgnoreSpacesRight( BOOL bVal
)
1260 SetOtherIfNotEqual( pOther
->bIgnoreSpacesRight
, bVal
);
1264 BOOL
SmMathConfig::IsToolboxVisible() const
1267 ((SmMathConfig
*) this)->LoadOther();
1268 return pOther
->bToolboxVisible
;
1272 void SmMathConfig::SetToolboxVisible( BOOL bVal
)
1276 SetOtherIfNotEqual( pOther
->bToolboxVisible
, bVal
);
1280 BOOL
SmMathConfig::IsAutoRedraw() const
1283 ((SmMathConfig
*) this)->LoadOther();
1284 return pOther
->bAutoRedraw
;
1288 void SmMathConfig::SetAutoRedraw( BOOL bVal
)
1292 SetOtherIfNotEqual( pOther
->bAutoRedraw
, bVal
);
1296 BOOL
SmMathConfig::IsShowFormulaCursor() const
1299 ((SmMathConfig
*) this)->LoadOther();
1300 return pOther
->bFormulaCursor
;
1304 void SmMathConfig::SetShowFormulaCursor( BOOL bVal
)
1308 SetOtherIfNotEqual( pOther
->bFormulaCursor
, bVal
);
1312 /////////////////////////////////////////////////////////////////