sync master with lastest vba changes
[ooovba.git] / starmath / source / cfgitem.cxx
blobe5920bb3e960e179c39e27ef00832bcb947ed35b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cfgitem.cxx,v $
10 * $Revision: 1.20 $
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"
40 #include "smdll.hxx"
41 #include "format.hxx"
43 using namespace rtl;
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[] =
64 "Name",
65 "CharSet",
66 "Family",
67 "Pitch",
68 "Weight",
69 "Italic",
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 );
82 return aNames;
85 /////////////////////////////////////////////////////////////////
88 static Sequence< OUString > lcl_GetSymbolPropertyNames()
90 static const char * aPropNames[] =
92 "Char",
93 "Set",
94 "Predefined",
95 "FontFormatId",
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 );
108 return aNames;
111 /////////////////////////////////////////////////////////////////
113 static const char * aMathPropNames[] =
115 "Print/Title",
116 "Print/FormulaText",
117 "Print/Frame",
118 "Print/Size",
119 "Print/ZoomFactor",
120 //"Misc/NoSymbolsWarning",
121 "Misc/IgnoreSpacesRight",
122 "View/ToolboxVisible",
123 "View/AutoRedraw",
124 "View/FormulaCursor"
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 );
188 return aNames;
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 /////////////////////////////////////////////////////////////////
207 struct SmCfgOther
209 SmPrintSize ePrintSize;
210 USHORT nPrintZoomFactor;
211 BOOL bPrintTitle;
212 BOOL bPrintFormulaText;
213 BOOL bPrintFrame;
214 BOOL bIgnoreSpacesRight;
215 BOOL bToolboxVisible;
216 BOOL bAutoRedraw;
217 BOOL bFormulaCursor;
218 //BOOL bNoSymbolsWarning;
220 SmCfgOther();
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
261 Font aRes;
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 );
268 return aRes;
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 ) :
286 aId (rId),
287 aFntFmt (rFntFmt)
292 SmFontFormatList::SmFontFormatList()
294 bModified = FALSE;
298 void SmFontFormatList::Clear()
300 USHORT nCnt = aEntries.Count();
301 if (nCnt)
303 aEntries.Remove( 0, nCnt );
304 SetModified( TRUE );
309 void SmFontFormatList::AddFontFormat( const String &rFntFmtId,
310 const SmFontFormat &rFntFmt )
312 const SmFontFormat *pFntFmt = GetFontFormat( rFntFmtId );
313 DBG_ASSERT( !pFntFmt, "FontFormatId already exists" );
314 if (!pFntFmt)
316 SmFntFmtListEntry aEntry( rFntFmtId, rFntFmt );
317 aEntries.Insert( aEntry, aEntries.Count() );
318 SetModified( TRUE );
323 void SmFontFormatList::RemoveFontFormat( const String &rFntFmtId )
325 USHORT nPos = 0xFFFF;
327 // search for entry
328 USHORT nCnt = aEntries.Count();
329 for (USHORT i = 0; i < nCnt && nPos == 0xFFFF; ++i)
331 if (aEntries[i].aId == rFntFmtId)
332 nPos = i;
335 // remove entry if found
336 if (nPos != 0xFFFF)
338 aEntries.Remove( nPos );
339 SetModified( TRUE );
344 const SmFontFormat * SmFontFormatList::GetFontFormat( const String &rFntFmtId ) const
346 SmFontFormat *pRes = 0;
348 USHORT nCnt = aEntries.Count();
349 USHORT i;
350 for (i = 0; i < nCnt && !pRes; ++i)
352 if (aEntries[i].aId == rFntFmtId)
353 pRes = &aEntries[i].aFntFmt;
356 return pRes;
361 const SmFontFormat * SmFontFormatList::GetFontFormat( USHORT nPos ) const
363 SmFontFormat *pRes = 0;
364 if (nPos < aEntries.Count())
365 pRes = &aEntries[ nPos ].aFntFmt;
366 return pRes;
370 const String SmFontFormatList::GetFontFormatId( const SmFontFormat &rFntFmt ) const
372 String aRes;
374 USHORT nCnt = aEntries.Count();
375 USHORT i;
376 for (i = 0; i < nCnt && 0 == aRes.Len(); ++i)
378 if (aEntries[i].aFntFmt == rFntFmt)
379 aRes = aEntries[i].aId;
382 return aRes;
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 );
394 return aRes;
398 const String SmFontFormatList::GetFontFormatId( USHORT nPos ) const
400 String aRes;
401 if (nPos < aEntries.Count())
402 aRes = aEntries[nPos].aId;
403 return aRes;
407 const String SmFontFormatList::GetNewFontFormatId() const
409 // returns first unused FormatId
411 String aRes;
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 ))
420 aRes = aTmpId;
422 DBG_ASSERT( 0 != aRes.Len(), "failed to create new FontFormatId" );
424 return aRes;
427 /////////////////////////////////////////////////////////////////
429 SmMathConfig::SmMathConfig() :
430 ConfigItem( String::CreateFromAscii( aRootName ))
432 pFormat = 0;
433 pOther = 0;
434 pFontFormatList = 0;
435 pSymSetMgr = 0;
437 bIsOtherModified = bIsFormatModified = FALSE;
441 SmMathConfig::~SmMathConfig()
443 Save();
444 delete pFormat;
445 delete pOther;
446 delete pFontFormatList;
447 delete pSymSetMgr;
451 void SmMathConfig::SetOtherModified( BOOL bVal )
453 bIsOtherModified = bVal;
457 void SmMathConfig::SetFormatModified( BOOL bVal )
459 bIsFormatModified = bVal;
463 void SmMathConfig::SetFontFormatListModified( BOOL bVal )
465 if (pFontFormatList)
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 );
483 rName = rBaseNode;
484 rName += aDelim;
485 rName += rSymbolName;
486 rName += aDelim;
487 rName += aTmp;
490 const Sequence< Any > aValues = ((SmMathConfig*) this)->GetProperties( aNames );
492 if (nProps && aValues.getLength() == nProps)
494 const Any * pValue = aValues.getConstArray();
495 Font aFont;
496 sal_Unicode cChar = '\0';
497 String aSet;
498 BOOL bPredefined = FALSE;
500 OUString aTmpStr;
501 INT32 nTmp32 = 0;
502 BOOL bTmp = FALSE;
504 BOOL bOK = TRUE;
505 if (pValue->hasValue() && (*pValue >>= nTmp32))
506 cChar = (sal_Unicode) nTmp32;
507 else
508 bOK = FALSE;
509 ++pValue;
510 if (pValue->hasValue() && (*pValue >>= aTmpStr))
511 aSet = aTmpStr;
512 else
513 bOK = FALSE;
514 ++pValue;
515 if (pValue->hasValue() && (*pValue >>= bTmp))
516 bPredefined = bTmp;
517 else
518 bOK = FALSE;
519 ++pValue;
520 if (pValue->hasValue() && (*pValue >>= aTmpStr))
522 const SmFontFormat *pFntFmt = GetFontFormatList().GetFontFormat( aTmpStr );
523 DBG_ASSERT( pFntFmt, "unknown FontFormat" );
524 if (pFntFmt)
525 aFont = pFntFmt->GetFont();
527 else
528 bOK = FALSE;
529 ++pValue;
531 if (bOK)
533 String aUiName( rSymbolName );
534 String aUiSetName( aSet );
535 if (bPredefined)
537 String aTmp;
538 aTmp = GetUiSymbolName( rSymbolName );
539 DBG_ASSERT( aTmp.Len(), "localized symbol-name not found" );
540 if (aTmp.Len())
541 aUiName = aTmp;
542 aTmp = GetUiSymbolSetName( aSet );
543 DBG_ASSERT( aTmp.Len(), "localized symbolset-name not found" );
544 if (aTmp.Len())
545 aUiSetName = aTmp;
548 rSymbol = SmSym( aUiName, aFont, cChar, aUiSetName, bPredefined );
549 if (aUiName != String(rSymbolName))
550 rSymbol.SetExportName( rSymbolName );
552 else
554 DBG_ERROR( "symbol read error" );
560 SmSymSetManager & SmMathConfig::GetSymSetManager()
562 if (!pSymSetMgr)
564 pSymSetMgr = new SmSymSetManager;
565 pSymSetMgr->Load();
567 return *pSymSetMgr;
571 void SmMathConfig::Commit()
573 Save();
576 void SmMathConfig::Save()
578 SaveOther();
579 SaveFormat();
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() );
605 while (aIt != aEnd)
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() );
627 while (aIt != aEnd)
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;
638 // Char
639 pVal->Name = aNodeNameDelim;
640 pVal->Name += *pName++;
641 pVal->Value <<= (INT32) rSymbol.GetCharacter();
642 pVal++;
643 // Set
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;
650 pVal++;
651 // Predefined
652 pVal->Name = aNodeNameDelim;
653 pVal->Name += *pName++;
654 pVal->Value <<= (BOOL) rSymbol.IsPredefined();
655 pVal++;
656 // FontFormatId
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 );
663 pVal++;
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;
687 else
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 );
721 rName = rBaseNode;
722 rName += aDelim;
723 rName += rSymbolName;
724 rName += aDelim;
725 rName += aTmp;
728 const Sequence< Any > aValues = ((SmMathConfig*) this)->GetProperties( aNames );
730 if (nProps && aValues.getLength() == nProps)
732 const Any * pValue = aValues.getConstArray();
734 OUString aTmpStr;
735 INT16 nTmp16 = 0;
737 BOOL bOK = TRUE;
738 if (pValue->hasValue() && (*pValue >>= aTmpStr))
739 rFontFormat.aName = aTmpStr;
740 else
741 bOK = FALSE;
742 ++pValue;
743 if (pValue->hasValue() && (*pValue >>= nTmp16))
744 rFontFormat.nCharSet = nTmp16; // 6.0 file-format GetSOLoadTextEncoding not needed
745 else
746 bOK = FALSE;
747 ++pValue;
748 if (pValue->hasValue() && (*pValue >>= nTmp16))
749 rFontFormat.nFamily = nTmp16;
750 else
751 bOK = FALSE;
752 ++pValue;
753 if (pValue->hasValue() && (*pValue >>= nTmp16))
754 rFontFormat.nPitch = nTmp16;
755 else
756 bOK = FALSE;
757 ++pValue;
758 if (pValue->hasValue() && (*pValue >>= nTmp16))
759 rFontFormat.nWeight = nTmp16;
760 else
761 bOK = FALSE;
762 ++pValue;
763 if (pValue->hasValue() && (*pValue >>= nTmp16))
764 rFontFormat.nItalic = nTmp16;
765 else
766 bOK = FALSE;
767 ++pValue;
769 DBG_ASSERT( bOK, "read FontFormat failed" );
774 void SmMathConfig::SaveFontFormatList()
776 SmFontFormatList &rFntFmtList = GetFontFormatList();
778 if (!rFntFmtList.IsModified())
779 return;
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();;
803 // Name
804 pVal->Name = aNodeNameDelim;
805 pVal->Name += *pName++;
806 pVal->Value <<= OUString( aFntFmt.aName );
807 pVal++;
808 // CharSet
809 pVal->Name = aNodeNameDelim;
810 pVal->Name += *pName++;
811 pVal->Value <<= (INT16) aFntFmt.nCharSet; // 6.0 file-format GetSOStoreTextEncoding not needed
812 pVal++;
813 // Family
814 pVal->Name = aNodeNameDelim;
815 pVal->Name += *pName++;
816 pVal->Value <<= (INT16) aFntFmt.nFamily;
817 pVal++;
818 // Pitch
819 pVal->Name = aNodeNameDelim;
820 pVal->Name += *pName++;
821 pVal->Value <<= (INT16) aFntFmt.nPitch;
822 pVal++;
823 // Weight
824 pVal->Name = aNodeNameDelim;
825 pVal->Name += *pName++;
826 pVal->Value <<= (INT16) aFntFmt.nWeight;
827 pVal++;
828 // Italic
829 pVal->Name = aNodeNameDelim;
830 pVal->Name += *pName++;
831 pVal->Value <<= (INT16) aFntFmt.nItalic;
832 pVal++;
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();
844 USHORT i;
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 ];
865 INT32 k;
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] );
878 delete [] pId;
879 delete [] pTmpFormat;
883 void SmMathConfig::LoadOther()
885 if (!pOther)
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;
897 INT16 nTmp16 = 0;
898 BOOL bTmp = FALSE;
900 // Print/Title
901 if (pVal->hasValue() && (*pVal >>= bTmp))
902 pOther->bPrintTitle = bTmp;
903 ++pVal;
904 // Print/FormulaText
905 if (pVal->hasValue() && (*pVal >>= bTmp))
906 pOther->bPrintFormulaText = bTmp;
907 ++pVal;
908 // Print/Frame
909 if (pVal->hasValue() && (*pVal >>= bTmp))
910 pOther->bPrintFrame = bTmp;
911 ++pVal;
912 // Print/Size
913 if (pVal->hasValue() && (*pVal >>= nTmp16))
914 pOther->ePrintSize = (SmPrintSize) nTmp16;
915 ++pVal;
916 // Print/ZoomFactor
917 if (pVal->hasValue() && (*pVal >>= nTmp16))
918 pOther->nPrintZoomFactor = nTmp16;
919 /* ++pVal;
920 // Misc/NoSymbolsWarning
921 if (pVal->hasValue() && (*pVal >>= bTmp))
922 pOther->bNoSymbolsWarning = bTmp;
924 ++pVal;
925 // Misc/IgnoreSpacesRight
926 if (pVal->hasValue() && (*pVal >>= bTmp))
927 pOther->bIgnoreSpacesRight = bTmp;
928 ++pVal;
929 // View/ToolboxVisible
930 if (pVal->hasValue() && (*pVal >>= bTmp))
931 pOther->bToolboxVisible = bTmp;
932 ++pVal;
933 // View/AutoRedraw
934 if (pVal->hasValue() && (*pVal >>= bTmp))
935 pOther->bAutoRedraw = bTmp;
936 ++pVal;
937 // View/FormulaCursor
938 if (pVal->hasValue() && (*pVal >>= bTmp))
939 pOther->bFormulaCursor = bTmp;
940 ++pVal;
942 DBG_ASSERT( pVal - pValues == nProps, "property mismatch" );
943 SetOtherModified( FALSE );
948 void SmMathConfig::SaveOther()
950 if (!pOther || !IsOtherModified())
951 return;
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;
960 // Print/Title
961 *pValue++ <<= (BOOL) pOther->bPrintTitle;
962 // Print/FormulaText
963 *pValue++ <<= (BOOL) pOther->bPrintFormulaText;
964 // Print/Frame
965 *pValue++ <<= (BOOL) pOther->bPrintFrame;
966 // Print/Size
967 *pValue++ <<= (INT16) pOther->ePrintSize;
968 // Print/ZoomFactor
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;
977 // View/AutoRedraw
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()
990 if (!pFormat)
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;
1003 OUString aTmpStr;
1004 INT16 nTmp16 = 0;
1005 BOOL bTmp = FALSE;
1007 // StandardFormat/Textmode
1008 if (pVal->hasValue() && (*pVal >>= bTmp))
1009 pFormat->SetTextmode( bTmp );
1010 ++pVal;
1011 // StandardFormat/ScaleNormalBracket
1012 if (pVal->hasValue() && (*pVal >>= bTmp))
1013 pFormat->SetScaleNormalBrackets( bTmp );
1014 ++pVal;
1015 // StandardFormat/HorizontalAlignment
1016 if (pVal->hasValue() && (*pVal >>= nTmp16))
1017 pFormat->SetHorAlign( (SmHorAlign) nTmp16 );
1018 ++pVal;
1019 // StandardFormat/BaseSize
1020 if (pVal->hasValue() && (*pVal >>= nTmp16))
1021 pFormat->SetBaseSize( Size(0, SmPtsTo100th_mm( nTmp16 )) );
1022 ++pVal;
1024 USHORT i;
1025 for (i = SIZ_BEGIN; i <= SIZ_END; ++i)
1027 if (pVal->hasValue() && (*pVal >>= nTmp16))
1028 pFormat->SetRelSize( i, nTmp16 );
1029 ++pVal;
1032 for (i = DIS_BEGIN; i <= DIS_END; ++i)
1034 if (pVal->hasValue() && (*pVal >>= nTmp16))
1035 pFormat->SetDistance( i, nTmp16 );
1036 ++pVal;
1039 LanguageType nLang = Application::GetSettings().GetUILanguage();
1040 for (i = FNT_BEGIN; i < FNT_END; ++i)
1042 Font aFnt;
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 ) );
1052 else
1054 const SmFontFormat *pFntFmt = GetFontFormatList().GetFontFormat( aTmpStr );
1055 DBG_ASSERT( pFntFmt, "unknown FontFormat" );
1056 if (pFntFmt)
1057 aFnt = pFntFmt->GetFont();
1060 ++pVal;
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())
1075 return;
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() ) );
1094 USHORT i;
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)
1103 OUString aFntFmtId;
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
1124 if (!pFormat)
1125 ((SmMathConfig *) this)->LoadFormat();
1126 return *pFormat;
1130 void SmMathConfig::SetStandardFormat( const SmFormat &rFormat, BOOL bSaveFontFormatList )
1132 if (!pFormat)
1133 LoadFormat();
1134 if (rFormat != *pFormat)
1136 *pFormat = rFormat;
1137 SetFormatModified( TRUE );
1138 SaveFormat();
1140 if (bSaveFontFormatList)
1142 // needed for SmFontTypeDialog's DefaultButtonClickHdl
1143 SetFontFormatListModified( TRUE );
1144 SaveFontFormatList();
1150 SmPrintSize SmMathConfig::GetPrintSize() const
1152 if (!pOther)
1153 ((SmMathConfig *) this)->LoadOther();
1154 return pOther->ePrintSize;
1158 void SmMathConfig::SetPrintSize( SmPrintSize eSize )
1160 if (!pOther)
1161 LoadOther();
1162 if (eSize != pOther->ePrintSize)
1164 pOther->ePrintSize = eSize;
1165 SetOtherModified( TRUE );
1170 USHORT SmMathConfig::GetPrintZoomFactor() const
1172 if (!pOther)
1173 ((SmMathConfig *) this)->LoadOther();
1174 return pOther->nPrintZoomFactor;
1178 void SmMathConfig::SetPrintZoomFactor( USHORT nVal )
1180 if (!pOther)
1181 LoadOther();
1182 if (nVal != pOther->nPrintZoomFactor)
1184 pOther->nPrintZoomFactor = nVal;
1185 SetOtherModified( TRUE );
1190 void SmMathConfig::SetOtherIfNotEqual( BOOL &rbItem, BOOL bNewVal )
1192 if (bNewVal != rbItem)
1194 rbItem = bNewVal;
1195 SetOtherModified( TRUE );
1200 BOOL SmMathConfig::IsPrintTitle() const
1202 if (!pOther)
1203 ((SmMathConfig *) this)->LoadOther();
1204 return pOther->bPrintTitle;
1208 void SmMathConfig::SetPrintTitle( BOOL bVal )
1210 if (!pOther)
1211 LoadOther();
1212 SetOtherIfNotEqual( pOther->bPrintTitle, bVal );
1216 BOOL SmMathConfig::IsPrintFormulaText() const
1218 if (!pOther)
1219 ((SmMathConfig *) this)->LoadOther();
1220 return pOther->bPrintFormulaText;
1224 void SmMathConfig::SetPrintFormulaText( BOOL bVal )
1226 if (!pOther)
1227 LoadOther();
1228 SetOtherIfNotEqual( pOther->bPrintFormulaText, bVal );
1232 BOOL SmMathConfig::IsPrintFrame() const
1234 if (!pOther)
1235 ((SmMathConfig *) this)->LoadOther();
1236 return pOther->bPrintFrame;
1240 void SmMathConfig::SetPrintFrame( BOOL bVal )
1242 if (!pOther)
1243 LoadOther();
1244 SetOtherIfNotEqual( pOther->bPrintFrame, bVal );
1248 BOOL SmMathConfig::IsIgnoreSpacesRight() const
1250 if (!pOther)
1251 ((SmMathConfig *) this)->LoadOther();
1252 return pOther->bIgnoreSpacesRight;
1256 void SmMathConfig::SetIgnoreSpacesRight( BOOL bVal )
1258 if (!pOther)
1259 LoadOther();
1260 SetOtherIfNotEqual( pOther->bIgnoreSpacesRight, bVal );
1264 BOOL SmMathConfig::IsToolboxVisible() const
1266 if (!pOther)
1267 ((SmMathConfig *) this)->LoadOther();
1268 return pOther->bToolboxVisible;
1272 void SmMathConfig::SetToolboxVisible( BOOL bVal )
1274 if (!pOther)
1275 LoadOther();
1276 SetOtherIfNotEqual( pOther->bToolboxVisible, bVal );
1280 BOOL SmMathConfig::IsAutoRedraw() const
1282 if (!pOther)
1283 ((SmMathConfig *) this)->LoadOther();
1284 return pOther->bAutoRedraw;
1288 void SmMathConfig::SetAutoRedraw( BOOL bVal )
1290 if (!pOther)
1291 LoadOther();
1292 SetOtherIfNotEqual( pOther->bAutoRedraw, bVal );
1296 BOOL SmMathConfig::IsShowFormulaCursor() const
1298 if (!pOther)
1299 ((SmMathConfig *) this)->LoadOther();
1300 return pOther->bFormulaCursor;
1304 void SmMathConfig::SetShowFormulaCursor( BOOL bVal )
1306 if (!pOther)
1307 LoadOther();
1308 SetOtherIfNotEqual( pOther->bFormulaCursor, bVal );
1312 /////////////////////////////////////////////////////////////////