CWS-TOOLING: integrate CWS tl88
[LibreOffice.git] / starmath / source / cfgitem.cxx
blob43c0fbe27dd0a2d7db221167fd2168ed78667b67
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_starmath.hxx"
32 #include <vcl/svapp.hxx>
34 #include "cfgitem.hxx"
36 #include "starmath.hrc"
37 #include "smdll.hxx"
38 #include "format.hxx"
40 using namespace rtl;
41 using namespace com::sun::star;
42 using namespace com::sun::star::uno;
43 using namespace com::sun::star::beans;
46 static const char* aRootName = "Office.Math";
48 #define SYMBOL_LIST "SymbolList"
49 #define FONT_FORMAT_LIST "FontFormatList"
51 SV_IMPL_OBJARR( SmFntFmtListEntryArr, SmFntFmtListEntry );
53 /////////////////////////////////////////////////////////////////
56 static Sequence< OUString > lcl_GetFontPropertyNames()
58 static const char * aPropNames[] =
60 "Name",
61 "CharSet",
62 "Family",
63 "Pitch",
64 "Weight",
65 "Italic",
69 const char** ppPropName = aPropNames;
71 Sequence< OUString > aNames( 6 );
72 OUString *pNames = aNames.getArray();
73 for( INT32 i = 0; *ppPropName; ++i, ++ppPropName )
75 pNames[i] = A2OU( *ppPropName );
77 //aNames.realloc( i );
78 return aNames;
81 /////////////////////////////////////////////////////////////////
84 static Sequence< OUString > lcl_GetSymbolPropertyNames()
86 static const char * aPropNames[] =
88 "Char",
89 "Set",
90 "Predefined",
91 "FontFormatId",
95 const char** ppPropName = aPropNames;
97 Sequence< OUString > aNames( 4 );
98 OUString *pNames = aNames.getArray();
99 for( INT32 i = 0; *ppPropName; ++i, ++ppPropName )
101 pNames[i] = A2OU( *ppPropName );
103 //aNames.realloc( i );
104 return aNames;
107 /////////////////////////////////////////////////////////////////
109 static const char * aMathPropNames[] =
111 "Print/Title",
112 "Print/FormulaText",
113 "Print/Frame",
114 "Print/Size",
115 "Print/ZoomFactor",
116 //"Misc/NoSymbolsWarning",
117 "Misc/IgnoreSpacesRight",
118 "View/ToolboxVisible",
119 "View/AutoRedraw",
120 "View/FormulaCursor"
124 //! Beware of order according to *_BEGIN *_END defines in format.hxx !
125 //! see respective load/save routines here
126 static const char * aFormatPropNames[] =
128 "StandardFormat/Textmode",
129 "StandardFormat/GreekCharStyle",
130 "StandardFormat/ScaleNormalBracket",
131 "StandardFormat/HorizontalAlignment",
132 "StandardFormat/BaseSize",
133 "StandardFormat/TextSize",
134 "StandardFormat/IndexSize",
135 "StandardFormat/FunctionSize",
136 "StandardFormat/OperatorSize",
137 "StandardFormat/LimitsSize",
138 "StandardFormat/Distance/Horizontal",
139 "StandardFormat/Distance/Vertical",
140 "StandardFormat/Distance/Root",
141 "StandardFormat/Distance/SuperScript",
142 "StandardFormat/Distance/SubScript",
143 "StandardFormat/Distance/Numerator",
144 "StandardFormat/Distance/Denominator",
145 "StandardFormat/Distance/Fraction",
146 "StandardFormat/Distance/StrokeWidth",
147 "StandardFormat/Distance/UpperLimit",
148 "StandardFormat/Distance/LowerLimit",
149 "StandardFormat/Distance/BracketSize",
150 "StandardFormat/Distance/BracketSpace",
151 "StandardFormat/Distance/MatrixRow",
152 "StandardFormat/Distance/MatrixColumn",
153 "StandardFormat/Distance/OrnamentSize",
154 "StandardFormat/Distance/OrnamentSpace",
155 "StandardFormat/Distance/OperatorSize",
156 "StandardFormat/Distance/OperatorSpace",
157 "StandardFormat/Distance/LeftSpace",
158 "StandardFormat/Distance/RightSpace",
159 "StandardFormat/Distance/TopSpace",
160 "StandardFormat/Distance/BottomSpace",
161 "StandardFormat/Distance/NormalBracketSize",
162 "StandardFormat/VariableFont",
163 "StandardFormat/FunctionFont",
164 "StandardFormat/NumberFont",
165 "StandardFormat/TextFont",
166 "StandardFormat/SerifFont",
167 "StandardFormat/SansFont",
168 "StandardFormat/FixedFont"
172 static Sequence< OUString > lcl_GetPropertyNames(
173 const char * aPropNames[], USHORT nCount )
176 const char** ppPropName = aPropNames;
178 Sequence< OUString > aNames( nCount );
179 OUString *pNames = aNames.getArray();
180 for (INT32 i = 0; i < nCount; ++i, ++ppPropName)
182 pNames[i] = A2OU( *ppPropName );
184 //aNames.realloc( i );
185 return aNames;
189 static Sequence< OUString > GetFormatPropertyNames()
191 USHORT nCnt = sizeof(aFormatPropNames) / sizeof(aFormatPropNames[0]);
192 return lcl_GetPropertyNames( aFormatPropNames, nCnt );
196 static Sequence< OUString > GetOtherPropertyNames()
198 USHORT nCnt = sizeof(aMathPropNames) / sizeof(aMathPropNames[0]);
199 return lcl_GetPropertyNames( aMathPropNames, nCnt );
202 /////////////////////////////////////////////////////////////////
204 struct SmCfgOther
206 SmPrintSize ePrintSize;
207 USHORT nPrintZoomFactor;
208 BOOL bPrintTitle;
209 BOOL bPrintFormulaText;
210 BOOL bPrintFrame;
211 BOOL bIgnoreSpacesRight;
212 BOOL bToolboxVisible;
213 BOOL bAutoRedraw;
214 BOOL bFormulaCursor;
215 //BOOL bNoSymbolsWarning;
217 SmCfgOther();
221 SmCfgOther::SmCfgOther()
223 ePrintSize = PRINT_SIZE_NORMAL;
224 nPrintZoomFactor = 100;
225 bPrintTitle = bPrintFormulaText =
226 bPrintFrame = bIgnoreSpacesRight =
227 bToolboxVisible = bAutoRedraw =
228 bFormulaCursor = /*bNoSymbolsWarning =*/ TRUE;
231 /////////////////////////////////////////////////////////////////
234 SmFontFormat::SmFontFormat()
236 aName.AssignAscii( FONTNAME_MATH );
237 nCharSet = RTL_TEXTENCODING_UNICODE;
238 nFamily = FAMILY_DONTKNOW;
239 nPitch = PITCH_DONTKNOW;
240 nWeight = WEIGHT_DONTKNOW;
241 nItalic = ITALIC_NONE;
245 SmFontFormat::SmFontFormat( const Font &rFont )
247 aName = rFont.GetName();
248 nCharSet = (INT16) rFont.GetCharSet();
249 nFamily = (INT16) rFont.GetFamily();
250 nPitch = (INT16) rFont.GetPitch();
251 nWeight = (INT16) rFont.GetWeight();
252 nItalic = (INT16) rFont.GetItalic();
256 const Font SmFontFormat::GetFont() const
258 Font aRes;
259 aRes.SetName( aName );
260 aRes.SetCharSet( (rtl_TextEncoding) nCharSet );
261 aRes.SetFamily( (FontFamily) nFamily );
262 aRes.SetPitch( (FontPitch) nPitch );
263 aRes.SetWeight( (FontWeight) nWeight );
264 aRes.SetItalic( (FontItalic) nItalic );
265 return aRes;
269 BOOL SmFontFormat::operator == ( const SmFontFormat &rFntFmt ) const
271 return aName == rFntFmt.aName &&
272 nCharSet == rFntFmt.nCharSet &&
273 nFamily == rFntFmt.nFamily &&
274 nPitch == rFntFmt.nPitch &&
275 nWeight == rFntFmt.nWeight &&
276 nItalic == rFntFmt.nItalic;
280 /////////////////////////////////////////////////////////////////
282 SmFntFmtListEntry::SmFntFmtListEntry( const String &rId, const SmFontFormat &rFntFmt ) :
283 aId (rId),
284 aFntFmt (rFntFmt)
289 SmFontFormatList::SmFontFormatList()
291 bModified = FALSE;
295 void SmFontFormatList::Clear()
297 USHORT nCnt = aEntries.Count();
298 if (nCnt)
300 aEntries.Remove( 0, nCnt );
301 SetModified( TRUE );
306 void SmFontFormatList::AddFontFormat( const String &rFntFmtId,
307 const SmFontFormat &rFntFmt )
309 const SmFontFormat *pFntFmt = GetFontFormat( rFntFmtId );
310 DBG_ASSERT( !pFntFmt, "FontFormatId already exists" );
311 if (!pFntFmt)
313 SmFntFmtListEntry aEntry( rFntFmtId, rFntFmt );
314 aEntries.Insert( aEntry, aEntries.Count() );
315 SetModified( TRUE );
320 void SmFontFormatList::RemoveFontFormat( const String &rFntFmtId )
322 USHORT nPos = 0xFFFF;
324 // search for entry
325 USHORT nCnt = aEntries.Count();
326 for (USHORT i = 0; i < nCnt && nPos == 0xFFFF; ++i)
328 if (aEntries[i].aId == rFntFmtId)
329 nPos = i;
332 // remove entry if found
333 if (nPos != 0xFFFF)
335 aEntries.Remove( nPos );
336 SetModified( TRUE );
341 const SmFontFormat * SmFontFormatList::GetFontFormat( const String &rFntFmtId ) const
343 SmFontFormat *pRes = 0;
345 USHORT nCnt = aEntries.Count();
346 USHORT i;
347 for (i = 0; i < nCnt && !pRes; ++i)
349 if (aEntries[i].aId == rFntFmtId)
350 pRes = &aEntries[i].aFntFmt;
353 return pRes;
358 const SmFontFormat * SmFontFormatList::GetFontFormat( USHORT nPos ) const
360 SmFontFormat *pRes = 0;
361 if (nPos < aEntries.Count())
362 pRes = &aEntries[ nPos ].aFntFmt;
363 return pRes;
367 const String SmFontFormatList::GetFontFormatId( const SmFontFormat &rFntFmt ) const
369 String aRes;
371 USHORT nCnt = aEntries.Count();
372 USHORT i;
373 for (i = 0; i < nCnt && 0 == aRes.Len(); ++i)
375 if (aEntries[i].aFntFmt == rFntFmt)
376 aRes = aEntries[i].aId;
379 return aRes;
383 const String SmFontFormatList::GetFontFormatId( const SmFontFormat &rFntFmt, BOOL bAdd )
385 String aRes( GetFontFormatId( rFntFmt) );
386 if (0 == aRes.Len() && bAdd)
388 aRes = GetNewFontFormatId();
389 AddFontFormat( aRes, rFntFmt );
391 return aRes;
395 const String SmFontFormatList::GetFontFormatId( USHORT nPos ) const
397 String aRes;
398 if (nPos < aEntries.Count())
399 aRes = aEntries[nPos].aId;
400 return aRes;
404 const String SmFontFormatList::GetNewFontFormatId() const
406 // returns first unused FormatId
408 String aRes;
410 String aPrefix( RTL_CONSTASCII_STRINGPARAM( "Id" ) );
411 INT32 nCnt = GetCount();
412 for (INT32 i = 1; i <= nCnt + 1 && 0 == aRes.Len(); ++i)
414 String aTmpId( aPrefix );
415 aTmpId += String::CreateFromInt32( i );
416 if (!GetFontFormat( aTmpId ))
417 aRes = aTmpId;
419 DBG_ASSERT( 0 != aRes.Len(), "failed to create new FontFormatId" );
421 return aRes;
424 /////////////////////////////////////////////////////////////////
426 SmMathConfig::SmMathConfig() :
427 ConfigItem( String::CreateFromAscii( aRootName ))
429 pFormat = 0;
430 pOther = 0;
431 pFontFormatList = 0;
432 pSymbolMgr = 0;
434 bIsOtherModified = bIsFormatModified = FALSE;
438 SmMathConfig::~SmMathConfig()
440 Save();
441 delete pFormat;
442 delete pOther;
443 delete pFontFormatList;
444 delete pSymbolMgr;
448 void SmMathConfig::SetOtherModified( BOOL bVal )
450 bIsOtherModified = bVal;
454 void SmMathConfig::SetFormatModified( BOOL bVal )
456 bIsFormatModified = bVal;
460 void SmMathConfig::SetFontFormatListModified( BOOL bVal )
462 if (pFontFormatList)
463 pFontFormatList->SetModified( bVal );
467 void SmMathConfig::ReadSymbol( SmSym &rSymbol,
468 const rtl::OUString &rSymbolName,
469 const rtl::OUString &rBaseNode ) const
471 Sequence< OUString > aNames = lcl_GetSymbolPropertyNames();
472 INT32 nProps = aNames.getLength();
474 OUString aDelim( OUString::valueOf( (sal_Unicode) '/' ) );
475 OUString *pName = aNames.getArray();
476 for (INT32 i = 0; i < nProps; ++i)
478 OUString &rName = pName[i];
479 OUString aTmp( rName );
480 rName = rBaseNode;
481 rName += aDelim;
482 rName += rSymbolName;
483 rName += aDelim;
484 rName += aTmp;
487 const Sequence< Any > aValues = ((SmMathConfig*) this)->GetProperties( aNames );
489 if (nProps && aValues.getLength() == nProps)
491 const Any * pValue = aValues.getConstArray();
492 Font aFont;
493 sal_Unicode cChar = '\0';
494 String aSet;
495 BOOL bPredefined = FALSE;
497 OUString aTmpStr;
498 INT32 nTmp32 = 0;
499 BOOL bTmp = FALSE;
501 BOOL bOK = TRUE;
502 if (pValue->hasValue() && (*pValue >>= nTmp32))
503 cChar = (sal_Unicode) nTmp32;
504 else
505 bOK = FALSE;
506 ++pValue;
507 if (pValue->hasValue() && (*pValue >>= aTmpStr))
508 aSet = aTmpStr;
509 else
510 bOK = FALSE;
511 ++pValue;
512 if (pValue->hasValue() && (*pValue >>= bTmp))
513 bPredefined = bTmp;
514 else
515 bOK = FALSE;
516 ++pValue;
517 if (pValue->hasValue() && (*pValue >>= aTmpStr))
519 const SmFontFormat *pFntFmt = GetFontFormatList().GetFontFormat( aTmpStr );
520 DBG_ASSERT( pFntFmt, "unknown FontFormat" );
521 if (pFntFmt)
522 aFont = pFntFmt->GetFont();
524 else
525 bOK = FALSE;
526 ++pValue;
528 if (bOK)
530 String aUiName( rSymbolName );
531 String aUiSetName( aSet );
532 if (bPredefined)
534 String aTmp;
535 aTmp = GetUiSymbolName( rSymbolName );
536 DBG_ASSERT( aTmp.Len(), "localized symbol-name not found" );
537 if (aTmp.Len())
538 aUiName = aTmp;
539 aTmp = GetUiSymbolSetName( aSet );
540 DBG_ASSERT( aTmp.Len(), "localized symbolset-name not found" );
541 if (aTmp.Len())
542 aUiSetName = aTmp;
545 rSymbol = SmSym( aUiName, aFont, cChar, aUiSetName, bPredefined );
546 if (aUiName != String(rSymbolName))
547 rSymbol.SetExportName( rSymbolName );
549 else
551 DBG_ERROR( "symbol read error" );
557 SmSymbolManager & SmMathConfig::GetSymbolManager()
559 if (!pSymbolMgr)
561 pSymbolMgr = new SmSymbolManager;
562 pSymbolMgr->Load();
564 return *pSymbolMgr;
568 void SmMathConfig::Commit()
570 Save();
574 void SmMathConfig::Save()
576 SaveOther();
577 SaveFormat();
578 SaveFontFormatList();
582 void SmMathConfig::GetSymbols( std::vector< SmSym > &rSymbols ) const
584 Sequence< OUString > aNodes( ((SmMathConfig*) this)->GetNodeNames( A2OU( SYMBOL_LIST ) ) );
585 const OUString *pNode = aNodes.getConstArray();
586 INT32 nNodes = aNodes.getLength();
588 rSymbols.resize( nNodes );
589 std::vector< SmSym >::iterator aIt( rSymbols.begin() );
590 std::vector< SmSym >::iterator aEnd( rSymbols.end() );
591 while (aIt != aEnd)
593 ReadSymbol( *aIt++, *pNode++, A2OU( SYMBOL_LIST ) );
598 void SmMathConfig::SetSymbols( const std::vector< SmSym > &rNewSymbols )
600 sal_uIntPtr nCount = rNewSymbols.size();
602 Sequence< OUString > aNames = lcl_GetSymbolPropertyNames();
603 const OUString *pNames = aNames.getConstArray();
604 sal_uIntPtr nSymbolProps = sal::static_int_cast< UINT32 >(aNames.getLength());
606 Sequence< PropertyValue > aValues( nCount * nSymbolProps );
607 PropertyValue *pValues = aValues.getArray();
609 PropertyValue *pVal = pValues;
610 OUString aDelim( OUString::valueOf( (sal_Unicode) '/' ) );
611 std::vector< SmSym >::const_iterator aIt( rNewSymbols.begin() );
612 std::vector< SmSym >::const_iterator aEnd( rNewSymbols.end() );
613 while (aIt != aEnd)
615 const SmSym &rSymbol = *aIt++;
616 //const Font &rFont = rSymbol.GetFace();
617 OUString aNodeNameDelim( A2OU( SYMBOL_LIST ) );
618 aNodeNameDelim += aDelim;
619 aNodeNameDelim += rSymbol.GetExportName();
620 aNodeNameDelim += aDelim;
622 const OUString *pName = pNames;
624 // Char
625 pVal->Name = aNodeNameDelim;
626 pVal->Name += *pName++;
627 pVal->Value <<= (INT32) rSymbol.GetCharacter();
628 pVal++;
629 // Set
630 pVal->Name = aNodeNameDelim;
631 pVal->Name += *pName++;
632 OUString aTmp( rSymbol.GetSymbolSetName() );
633 if (rSymbol.IsPredefined())
634 aTmp = GetExportSymbolSetName( aTmp );
635 pVal->Value <<= aTmp;
636 pVal++;
637 // Predefined
638 pVal->Name = aNodeNameDelim;
639 pVal->Name += *pName++;
640 pVal->Value <<= (BOOL) rSymbol.IsPredefined();
641 pVal++;
642 // FontFormatId
643 SmFontFormat aFntFmt( rSymbol.GetFace() );
644 String aFntFmtId( GetFontFormatList().GetFontFormatId( aFntFmt, TRUE ) );
645 DBG_ASSERT( aFntFmtId.Len(), "FontFormatId not found" );
646 pVal->Name = aNodeNameDelim;
647 pVal->Name += *pName++;
648 pVal->Value <<= OUString( aFntFmtId );
649 pVal++;
651 DBG_ASSERT( pVal - pValues == sal::static_int_cast< ptrdiff_t >(nCount * nSymbolProps), "properties missing" );
652 ReplaceSetProperties( A2OU( SYMBOL_LIST ) , aValues );
654 StripFontFormatList( rNewSymbols );
655 SaveFontFormatList();
659 SmFontFormatList & SmMathConfig::GetFontFormatList()
661 if (!pFontFormatList)
663 LoadFontFormatList();
665 return *pFontFormatList;
669 void SmMathConfig::LoadFontFormatList()
671 if (!pFontFormatList)
672 pFontFormatList = new SmFontFormatList;
673 else
674 pFontFormatList->Clear();
676 Sequence< OUString > aNodes( GetNodeNames( A2OU( FONT_FORMAT_LIST ) ) );
677 const OUString *pNode = aNodes.getConstArray();
678 INT32 nNodes = aNodes.getLength();
680 for (INT32 i = 0; i < nNodes; ++i)
682 SmFontFormat aFntFmt;
683 ReadFontFormat( aFntFmt, pNode[i], A2OU( FONT_FORMAT_LIST ) );
684 if (!pFontFormatList->GetFontFormat( pNode[i] ))
686 DBG_ASSERT( 0 == pFontFormatList->GetFontFormat( pNode[i] ),
687 "FontFormat ID already exists" );
688 pFontFormatList->AddFontFormat( pNode[i], aFntFmt );
691 pFontFormatList->SetModified( FALSE );
695 void SmMathConfig::ReadFontFormat( SmFontFormat &rFontFormat,
696 const OUString &rSymbolName, const OUString &rBaseNode ) const
698 Sequence< OUString > aNames = lcl_GetFontPropertyNames();
699 INT32 nProps = aNames.getLength();
701 OUString aDelim( OUString::valueOf( (sal_Unicode) '/' ) );
702 OUString *pName = aNames.getArray();
703 for (INT32 i = 0; i < nProps; ++i)
705 OUString &rName = pName[i];
706 OUString aTmp( rName );
707 rName = rBaseNode;
708 rName += aDelim;
709 rName += rSymbolName;
710 rName += aDelim;
711 rName += aTmp;
714 const Sequence< Any > aValues = ((SmMathConfig*) this)->GetProperties( aNames );
716 if (nProps && aValues.getLength() == nProps)
718 const Any * pValue = aValues.getConstArray();
720 OUString aTmpStr;
721 INT16 nTmp16 = 0;
723 BOOL bOK = TRUE;
724 if (pValue->hasValue() && (*pValue >>= aTmpStr))
725 rFontFormat.aName = aTmpStr;
726 else
727 bOK = FALSE;
728 ++pValue;
729 if (pValue->hasValue() && (*pValue >>= nTmp16))
730 rFontFormat.nCharSet = nTmp16; // 6.0 file-format GetSOLoadTextEncoding not needed
731 else
732 bOK = FALSE;
733 ++pValue;
734 if (pValue->hasValue() && (*pValue >>= nTmp16))
735 rFontFormat.nFamily = nTmp16;
736 else
737 bOK = FALSE;
738 ++pValue;
739 if (pValue->hasValue() && (*pValue >>= nTmp16))
740 rFontFormat.nPitch = nTmp16;
741 else
742 bOK = FALSE;
743 ++pValue;
744 if (pValue->hasValue() && (*pValue >>= nTmp16))
745 rFontFormat.nWeight = nTmp16;
746 else
747 bOK = FALSE;
748 ++pValue;
749 if (pValue->hasValue() && (*pValue >>= nTmp16))
750 rFontFormat.nItalic = nTmp16;
751 else
752 bOK = FALSE;
753 ++pValue;
755 DBG_ASSERT( bOK, "read FontFormat failed" );
760 void SmMathConfig::SaveFontFormatList()
762 SmFontFormatList &rFntFmtList = GetFontFormatList();
764 if (!rFntFmtList.IsModified())
765 return;
767 Sequence< OUString > aNames = lcl_GetFontPropertyNames();
768 INT32 nSymbolProps = aNames.getLength();
770 USHORT nCount = rFntFmtList.GetCount();
772 Sequence< PropertyValue > aValues( nCount * nSymbolProps );
773 PropertyValue *pValues = aValues.getArray();
775 PropertyValue *pVal = pValues;
776 OUString aDelim( OUString::valueOf( (sal_Unicode) '/' ) );
777 for (USHORT i = 0; i < nCount; ++i)
779 String aFntFmtId( rFntFmtList.GetFontFormatId( i ) );
780 const SmFontFormat aFntFmt( *rFntFmtList.GetFontFormat( aFntFmtId ) );
782 OUString aNodeNameDelim( A2OU( FONT_FORMAT_LIST ) );
783 aNodeNameDelim += aDelim;
784 aNodeNameDelim += aFntFmtId;
785 aNodeNameDelim += aDelim;
787 const OUString *pName = aNames.getConstArray();;
789 // Name
790 pVal->Name = aNodeNameDelim;
791 pVal->Name += *pName++;
792 pVal->Value <<= OUString( aFntFmt.aName );
793 pVal++;
794 // CharSet
795 pVal->Name = aNodeNameDelim;
796 pVal->Name += *pName++;
797 pVal->Value <<= (INT16) aFntFmt.nCharSet; // 6.0 file-format GetSOStoreTextEncoding not needed
798 pVal++;
799 // Family
800 pVal->Name = aNodeNameDelim;
801 pVal->Name += *pName++;
802 pVal->Value <<= (INT16) aFntFmt.nFamily;
803 pVal++;
804 // Pitch
805 pVal->Name = aNodeNameDelim;
806 pVal->Name += *pName++;
807 pVal->Value <<= (INT16) aFntFmt.nPitch;
808 pVal++;
809 // Weight
810 pVal->Name = aNodeNameDelim;
811 pVal->Name += *pName++;
812 pVal->Value <<= (INT16) aFntFmt.nWeight;
813 pVal++;
814 // Italic
815 pVal->Name = aNodeNameDelim;
816 pVal->Name += *pName++;
817 pVal->Value <<= (INT16) aFntFmt.nItalic;
818 pVal++;
820 DBG_ASSERT( pVal - pValues == nCount * nSymbolProps, "properties missing" );
821 ReplaceSetProperties( A2OU( FONT_FORMAT_LIST ) , aValues );
823 rFntFmtList.SetModified( FALSE );
827 void SmMathConfig::StripFontFormatList( const std::vector< SmSym > &rSymbols )
829 size_t nCount = rSymbols.size();
830 USHORT i;
832 // build list of used font-formats only
833 //!! font-format IDs may be different !!
834 SmFontFormatList aUsedList;
835 for (i = 0; i < nCount; ++i)
837 DBG_ASSERT( rSymbols[i].GetName().Len() > 0, "non named symbol" );
838 aUsedList.GetFontFormatId( SmFontFormat( rSymbols[i].GetFace() ) , TRUE );
840 const SmFormat & rStdFmt = GetStandardFormat();
841 for (i = FNT_BEGIN; i <= FNT_END; ++i)
843 aUsedList.GetFontFormatId( SmFontFormat( rStdFmt.GetFont( i ) ) , TRUE );
846 // remove unused font-formats from list
847 SmFontFormatList &rFntFmtList = GetFontFormatList();
848 USHORT nCnt = rFntFmtList.GetCount();
849 SmFontFormat *pTmpFormat = new SmFontFormat[ nCnt ];
850 String *pId = new String [ nCnt ];
851 INT32 k;
852 for (k = 0; k < nCnt; ++k)
854 pTmpFormat[k] = *rFntFmtList.GetFontFormat( (USHORT) k );
855 pId[k] = rFntFmtList.GetFontFormatId( (USHORT) k );
857 for (k = 0; k < nCnt; ++k)
859 if (0 == aUsedList.GetFontFormatId( pTmpFormat[k] ).Len())
861 rFntFmtList.RemoveFontFormat( pId[k] );
864 delete [] pId;
865 delete [] pTmpFormat;
869 void SmMathConfig::LoadOther()
871 if (!pOther)
872 pOther = new SmCfgOther;
874 Sequence< OUString > aNames( GetOtherPropertyNames() );
875 INT32 nProps = aNames.getLength();
877 Sequence< Any > aValues( GetProperties( aNames ) );
878 if (nProps && aValues.getLength() == nProps)
880 const Any *pValues = aValues.getConstArray();
881 const Any *pVal = pValues;
883 INT16 nTmp16 = 0;
884 BOOL bTmp = FALSE;
886 // Print/Title
887 if (pVal->hasValue() && (*pVal >>= bTmp))
888 pOther->bPrintTitle = bTmp;
889 ++pVal;
890 // Print/FormulaText
891 if (pVal->hasValue() && (*pVal >>= bTmp))
892 pOther->bPrintFormulaText = bTmp;
893 ++pVal;
894 // Print/Frame
895 if (pVal->hasValue() && (*pVal >>= bTmp))
896 pOther->bPrintFrame = bTmp;
897 ++pVal;
898 // Print/Size
899 if (pVal->hasValue() && (*pVal >>= nTmp16))
900 pOther->ePrintSize = (SmPrintSize) nTmp16;
901 ++pVal;
902 // Print/ZoomFactor
903 if (pVal->hasValue() && (*pVal >>= nTmp16))
904 pOther->nPrintZoomFactor = nTmp16;
905 /* ++pVal;
906 // Misc/NoSymbolsWarning
907 if (pVal->hasValue() && (*pVal >>= bTmp))
908 pOther->bNoSymbolsWarning = bTmp;
910 ++pVal;
911 // Misc/IgnoreSpacesRight
912 if (pVal->hasValue() && (*pVal >>= bTmp))
913 pOther->bIgnoreSpacesRight = bTmp;
914 ++pVal;
915 // View/ToolboxVisible
916 if (pVal->hasValue() && (*pVal >>= bTmp))
917 pOther->bToolboxVisible = bTmp;
918 ++pVal;
919 // View/AutoRedraw
920 if (pVal->hasValue() && (*pVal >>= bTmp))
921 pOther->bAutoRedraw = bTmp;
922 ++pVal;
923 // View/FormulaCursor
924 if (pVal->hasValue() && (*pVal >>= bTmp))
925 pOther->bFormulaCursor = bTmp;
926 ++pVal;
928 DBG_ASSERT( pVal - pValues == nProps, "property mismatch" );
929 SetOtherModified( FALSE );
934 void SmMathConfig::SaveOther()
936 if (!pOther || !IsOtherModified())
937 return;
939 const Sequence< OUString > aNames( GetOtherPropertyNames() );
940 INT32 nProps = aNames.getLength();
942 Sequence< Any > aValues( nProps );
943 Any *pValues = aValues.getArray();
944 Any *pValue = pValues;
946 // Print/Title
947 *pValue++ <<= (BOOL) pOther->bPrintTitle;
948 // Print/FormulaText
949 *pValue++ <<= (BOOL) pOther->bPrintFormulaText;
950 // Print/Frame
951 *pValue++ <<= (BOOL) pOther->bPrintFrame;
952 // Print/Size
953 *pValue++ <<= (INT16) pOther->ePrintSize;
954 // Print/ZoomFactor
955 *pValue++ <<= (INT16) pOther->nPrintZoomFactor;
956 /* // Misc/NoSymbolsWarning
957 *pValue++ <<= (BOOL) pOther->bNoSymbolsWarning;
959 // Misc/IgnoreSpacesRight
960 *pValue++ <<= (BOOL) pOther->bIgnoreSpacesRight;
961 // View/ToolboxVisible
962 *pValue++ <<= (BOOL) pOther->bToolboxVisible;
963 // View/AutoRedraw
964 *pValue++ <<= (BOOL) pOther->bAutoRedraw;
965 // View/FormulaCursor
966 *pValue++ <<= (BOOL) pOther->bFormulaCursor;
968 DBG_ASSERT( pValue - pValues == nProps, "property mismatch" );
969 PutProperties( aNames , aValues );
971 SetOtherModified( FALSE );
974 void SmMathConfig::LoadFormat()
976 if (!pFormat)
977 pFormat = new SmFormat;
980 Sequence< OUString > aNames( GetFormatPropertyNames() );
981 INT32 nProps = aNames.getLength();
983 Sequence< Any > aValues( GetProperties( aNames ) );
984 if (nProps && aValues.getLength() == nProps)
986 const Any *pValues = aValues.getConstArray();
987 const Any *pVal = pValues;
989 OUString aTmpStr;
990 INT16 nTmp16 = 0;
991 BOOL bTmp = FALSE;
993 // StandardFormat/Textmode
994 if (pVal->hasValue() && (*pVal >>= bTmp))
995 pFormat->SetTextmode( bTmp );
996 ++pVal;
997 // StandardFormat/GreekCharStyle
998 if (pVal->hasValue() && (*pVal >>= nTmp16))
999 pFormat->SetGreekCharStyle( nTmp16 );
1000 ++pVal;
1001 // StandardFormat/ScaleNormalBracket
1002 if (pVal->hasValue() && (*pVal >>= bTmp))
1003 pFormat->SetScaleNormalBrackets( bTmp );
1004 ++pVal;
1005 // StandardFormat/HorizontalAlignment
1006 if (pVal->hasValue() && (*pVal >>= nTmp16))
1007 pFormat->SetHorAlign( (SmHorAlign) nTmp16 );
1008 ++pVal;
1009 // StandardFormat/BaseSize
1010 if (pVal->hasValue() && (*pVal >>= nTmp16))
1011 pFormat->SetBaseSize( Size(0, SmPtsTo100th_mm( nTmp16 )) );
1012 ++pVal;
1014 USHORT i;
1015 for (i = SIZ_BEGIN; i <= SIZ_END; ++i)
1017 if (pVal->hasValue() && (*pVal >>= nTmp16))
1018 pFormat->SetRelSize( i, nTmp16 );
1019 ++pVal;
1022 for (i = DIS_BEGIN; i <= DIS_END; ++i)
1024 if (pVal->hasValue() && (*pVal >>= nTmp16))
1025 pFormat->SetDistance( i, nTmp16 );
1026 ++pVal;
1029 LanguageType nLang = Application::GetSettings().GetUILanguage();
1030 for (i = FNT_BEGIN; i < FNT_END; ++i)
1032 Font aFnt;
1033 BOOL bUseDefaultFont = TRUE;
1034 if (pVal->hasValue() && (*pVal >>= aTmpStr))
1036 bUseDefaultFont = 0 == aTmpStr.getLength();
1037 if (bUseDefaultFont)
1039 aFnt = pFormat->GetFont( i );
1040 aFnt.SetName( GetDefaultFontName( nLang, i ) );
1042 else
1044 const SmFontFormat *pFntFmt = GetFontFormatList().GetFontFormat( aTmpStr );
1045 DBG_ASSERT( pFntFmt, "unknown FontFormat" );
1046 if (pFntFmt)
1047 aFnt = pFntFmt->GetFont();
1050 ++pVal;
1052 aFnt.SetSize( pFormat->GetBaseSize() );
1053 pFormat->SetFont( i, aFnt, bUseDefaultFont );
1056 DBG_ASSERT( pVal - pValues == nProps, "property mismatch" );
1057 SetFormatModified( FALSE );
1062 void SmMathConfig::SaveFormat()
1064 if (!pFormat || !IsFormatModified())
1065 return;
1067 const Sequence< OUString > aNames( GetFormatPropertyNames() );
1068 INT32 nProps = aNames.getLength();
1070 Sequence< Any > aValues( nProps );
1071 Any *pValues = aValues.getArray();
1072 Any *pValue = pValues;
1074 // StandardFormat/Textmode
1075 *pValue++ <<= (BOOL) pFormat->IsTextmode();
1076 // StandardFormat/GreekCharStyle
1077 *pValue++ <<= (INT16) pFormat->GetGreekCharStyle();
1078 // StandardFormat/ScaleNormalBracket
1079 *pValue++ <<= (BOOL) pFormat->IsScaleNormalBrackets();
1080 // StandardFormat/HorizontalAlignment
1081 *pValue++ <<= (INT16) pFormat->GetHorAlign();
1082 // StandardFormat/BaseSize
1083 *pValue++ <<= (INT16) SmRoundFraction( Sm100th_mmToPts(
1084 pFormat->GetBaseSize().Height() ) );
1086 USHORT i;
1087 for (i = SIZ_BEGIN; i <= SIZ_END; ++i)
1088 *pValue++ <<= (INT16) pFormat->GetRelSize( i );
1090 for (i = DIS_BEGIN; i <= DIS_END; ++i)
1091 *pValue++ <<= (INT16) pFormat->GetDistance( i );
1093 for (i = FNT_BEGIN; i < FNT_END; ++i)
1095 OUString aFntFmtId;
1097 if (!pFormat->IsDefaultFont( i ))
1099 SmFontFormat aFntFmt( pFormat->GetFont( i ) );
1100 aFntFmtId = GetFontFormatList().GetFontFormatId( aFntFmt, TRUE );
1101 DBG_ASSERT( aFntFmtId.getLength(), "FontFormatId not found" );
1104 *pValue++ <<= aFntFmtId;
1107 DBG_ASSERT( pValue - pValues == nProps, "property mismatch" );
1108 PutProperties( aNames , aValues );
1110 SetFormatModified( FALSE );
1114 const SmFormat & SmMathConfig::GetStandardFormat() const
1116 if (!pFormat)
1117 ((SmMathConfig *) this)->LoadFormat();
1118 return *pFormat;
1122 void SmMathConfig::SetStandardFormat( const SmFormat &rFormat, BOOL bSaveFontFormatList )
1124 if (!pFormat)
1125 LoadFormat();
1126 if (rFormat != *pFormat)
1128 *pFormat = rFormat;
1129 SetFormatModified( TRUE );
1130 SaveFormat();
1132 if (bSaveFontFormatList)
1134 // needed for SmFontTypeDialog's DefaultButtonClickHdl
1135 SetFontFormatListModified( TRUE );
1136 SaveFontFormatList();
1142 SmPrintSize SmMathConfig::GetPrintSize() const
1144 if (!pOther)
1145 ((SmMathConfig *) this)->LoadOther();
1146 return pOther->ePrintSize;
1150 void SmMathConfig::SetPrintSize( SmPrintSize eSize )
1152 if (!pOther)
1153 LoadOther();
1154 if (eSize != pOther->ePrintSize)
1156 pOther->ePrintSize = eSize;
1157 SetOtherModified( TRUE );
1162 USHORT SmMathConfig::GetPrintZoomFactor() const
1164 if (!pOther)
1165 ((SmMathConfig *) this)->LoadOther();
1166 return pOther->nPrintZoomFactor;
1170 void SmMathConfig::SetPrintZoomFactor( USHORT nVal )
1172 if (!pOther)
1173 LoadOther();
1174 if (nVal != pOther->nPrintZoomFactor)
1176 pOther->nPrintZoomFactor = nVal;
1177 SetOtherModified( TRUE );
1182 void SmMathConfig::SetOtherIfNotEqual( BOOL &rbItem, BOOL bNewVal )
1184 if (bNewVal != rbItem)
1186 rbItem = bNewVal;
1187 SetOtherModified( TRUE );
1192 BOOL SmMathConfig::IsPrintTitle() const
1194 if (!pOther)
1195 ((SmMathConfig *) this)->LoadOther();
1196 return pOther->bPrintTitle;
1200 void SmMathConfig::SetPrintTitle( BOOL bVal )
1202 if (!pOther)
1203 LoadOther();
1204 SetOtherIfNotEqual( pOther->bPrintTitle, bVal );
1208 BOOL SmMathConfig::IsPrintFormulaText() const
1210 if (!pOther)
1211 ((SmMathConfig *) this)->LoadOther();
1212 return pOther->bPrintFormulaText;
1216 void SmMathConfig::SetPrintFormulaText( BOOL bVal )
1218 if (!pOther)
1219 LoadOther();
1220 SetOtherIfNotEqual( pOther->bPrintFormulaText, bVal );
1224 BOOL SmMathConfig::IsPrintFrame() const
1226 if (!pOther)
1227 ((SmMathConfig *) this)->LoadOther();
1228 return pOther->bPrintFrame;
1232 void SmMathConfig::SetPrintFrame( BOOL bVal )
1234 if (!pOther)
1235 LoadOther();
1236 SetOtherIfNotEqual( pOther->bPrintFrame, bVal );
1240 BOOL SmMathConfig::IsIgnoreSpacesRight() const
1242 if (!pOther)
1243 ((SmMathConfig *) this)->LoadOther();
1244 return pOther->bIgnoreSpacesRight;
1248 void SmMathConfig::SetIgnoreSpacesRight( BOOL bVal )
1250 if (!pOther)
1251 LoadOther();
1252 SetOtherIfNotEqual( pOther->bIgnoreSpacesRight, bVal );
1256 BOOL SmMathConfig::IsAutoRedraw() const
1258 if (!pOther)
1259 ((SmMathConfig *) this)->LoadOther();
1260 return pOther->bAutoRedraw;
1264 void SmMathConfig::SetAutoRedraw( BOOL bVal )
1266 if (!pOther)
1267 LoadOther();
1268 SetOtherIfNotEqual( pOther->bAutoRedraw, bVal );
1272 BOOL SmMathConfig::IsShowFormulaCursor() const
1274 if (!pOther)
1275 ((SmMathConfig *) this)->LoadOther();
1276 return pOther->bFormulaCursor;
1280 void SmMathConfig::SetShowFormulaCursor( BOOL bVal )
1282 if (!pOther)
1283 LoadOther();
1284 SetOtherIfNotEqual( pOther->bFormulaCursor, bVal );
1287 void SmMathConfig::Notify( const com::sun::star::uno::Sequence< rtl::OUString >& )
1290 /////////////////////////////////////////////////////////////////