bump product version to 4.1.6.2
[LibreOffice.git] / starmath / source / cfgitem.cxx
blob979ee4319ddd36181a9fd31ce9ab5f159870aa2a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <vcl/svapp.hxx>
21 #include <sal/macros.h>
22 #include "cfgitem.hxx"
24 #include "starmath.hrc"
25 #include "smdll.hxx"
26 #include "format.hxx"
28 using namespace com::sun::star;
29 using namespace com::sun::star::uno;
30 using namespace com::sun::star::beans;
34 static const char aRootName[] = "Office.Math";
36 #define SYMBOL_LIST "SymbolList"
37 #define FONT_FORMAT_LIST "FontFormatList"
39 /////////////////////////////////////////////////////////////////
42 static Sequence< OUString > lcl_GetFontPropertyNames()
44 static const char * aPropNames[] =
46 "Name",
47 "CharSet",
48 "Family",
49 "Pitch",
50 "Weight",
51 "Italic",
55 const char** ppPropName = aPropNames;
57 Sequence< OUString > aNames( 6 );
58 OUString *pNames = aNames.getArray();
59 for( sal_Int32 i = 0; *ppPropName; ++i, ++ppPropName )
61 pNames[i] = OUString::createFromAscii( *ppPropName );
63 return aNames;
66 /////////////////////////////////////////////////////////////////
69 static Sequence< OUString > lcl_GetSymbolPropertyNames()
71 static const char * aPropNames[] =
73 "Char",
74 "Set",
75 "Predefined",
76 "FontFormatId",
80 const char** ppPropName = aPropNames;
82 Sequence< OUString > aNames( 4 );
83 OUString *pNames = aNames.getArray();
84 for( sal_Int32 i = 0; *ppPropName; ++i, ++ppPropName )
86 pNames[i] = OUString::createFromAscii( *ppPropName );
88 return aNames;
91 /////////////////////////////////////////////////////////////////
93 static const char * aMathPropNames[] =
95 "Print/Title",
96 "Print/FormulaText",
97 "Print/Frame",
98 "Print/Size",
99 "Print/ZoomFactor",
100 "LoadSave/IsSaveOnlyUsedSymbols",
101 "Misc/IgnoreSpacesRight",
102 "View/ToolboxVisible",
103 "View/AutoRedraw",
104 "View/FormulaCursor"
108 //! Beware of order according to *_BEGIN *_END defines in format.hxx !
109 //! see respective load/save routines here
110 static const char * aFormatPropNames[] =
112 "StandardFormat/Textmode",
113 "StandardFormat/GreekCharStyle",
114 "StandardFormat/ScaleNormalBracket",
115 "StandardFormat/HorizontalAlignment",
116 "StandardFormat/BaseSize",
117 "StandardFormat/TextSize",
118 "StandardFormat/IndexSize",
119 "StandardFormat/FunctionSize",
120 "StandardFormat/OperatorSize",
121 "StandardFormat/LimitsSize",
122 "StandardFormat/Distance/Horizontal",
123 "StandardFormat/Distance/Vertical",
124 "StandardFormat/Distance/Root",
125 "StandardFormat/Distance/SuperScript",
126 "StandardFormat/Distance/SubScript",
127 "StandardFormat/Distance/Numerator",
128 "StandardFormat/Distance/Denominator",
129 "StandardFormat/Distance/Fraction",
130 "StandardFormat/Distance/StrokeWidth",
131 "StandardFormat/Distance/UpperLimit",
132 "StandardFormat/Distance/LowerLimit",
133 "StandardFormat/Distance/BracketSize",
134 "StandardFormat/Distance/BracketSpace",
135 "StandardFormat/Distance/MatrixRow",
136 "StandardFormat/Distance/MatrixColumn",
137 "StandardFormat/Distance/OrnamentSize",
138 "StandardFormat/Distance/OrnamentSpace",
139 "StandardFormat/Distance/OperatorSize",
140 "StandardFormat/Distance/OperatorSpace",
141 "StandardFormat/Distance/LeftSpace",
142 "StandardFormat/Distance/RightSpace",
143 "StandardFormat/Distance/TopSpace",
144 "StandardFormat/Distance/BottomSpace",
145 "StandardFormat/Distance/NormalBracketSize",
146 "StandardFormat/VariableFont",
147 "StandardFormat/FunctionFont",
148 "StandardFormat/NumberFont",
149 "StandardFormat/TextFont",
150 "StandardFormat/SerifFont",
151 "StandardFormat/SansFont",
152 "StandardFormat/FixedFont"
156 static Sequence< OUString > lcl_GetPropertyNames(
157 const char * aPropNames[], sal_uInt16 nCount )
160 const char** ppPropName = aPropNames;
162 Sequence< OUString > aNames( nCount );
163 OUString *pNames = aNames.getArray();
164 for (sal_Int32 i = 0; i < nCount; ++i, ++ppPropName)
166 pNames[i] = OUString::createFromAscii( *ppPropName );
168 return aNames;
171 static Sequence< OUString > GetFormatPropertyNames()
173 return lcl_GetPropertyNames( aFormatPropNames, SAL_N_ELEMENTS( aFormatPropNames ) );
176 static Sequence< OUString > GetOtherPropertyNames()
178 return lcl_GetPropertyNames( aMathPropNames, SAL_N_ELEMENTS( aMathPropNames ) );
181 /////////////////////////////////////////////////////////////////
183 struct SmCfgOther
185 SmPrintSize ePrintSize;
186 sal_uInt16 nPrintZoomFactor;
187 bool bPrintTitle;
188 bool bPrintFormulaText;
189 bool bPrintFrame;
190 bool bIsSaveOnlyUsedSymbols;
191 bool bIgnoreSpacesRight;
192 bool bToolboxVisible;
193 bool bAutoRedraw;
194 bool bFormulaCursor;
196 SmCfgOther();
200 SmCfgOther::SmCfgOther()
202 ePrintSize = PRINT_SIZE_NORMAL;
203 nPrintZoomFactor = 100;
204 bPrintTitle = bPrintFormulaText =
205 bPrintFrame = bIgnoreSpacesRight =
206 bToolboxVisible = bAutoRedraw =
207 bFormulaCursor = bIsSaveOnlyUsedSymbols = true;
210 /////////////////////////////////////////////////////////////////
213 SmFontFormat::SmFontFormat()
215 aName.AssignAscii( FONTNAME_MATH );
216 nCharSet = RTL_TEXTENCODING_UNICODE;
217 nFamily = FAMILY_DONTKNOW;
218 nPitch = PITCH_DONTKNOW;
219 nWeight = WEIGHT_DONTKNOW;
220 nItalic = ITALIC_NONE;
224 SmFontFormat::SmFontFormat( const Font &rFont )
226 aName = rFont.GetName();
227 nCharSet = (sal_Int16) rFont.GetCharSet();
228 nFamily = (sal_Int16) rFont.GetFamily();
229 nPitch = (sal_Int16) rFont.GetPitch();
230 nWeight = (sal_Int16) rFont.GetWeight();
231 nItalic = (sal_Int16) rFont.GetItalic();
235 const Font SmFontFormat::GetFont() const
237 Font aRes;
238 aRes.SetName( aName );
239 aRes.SetCharSet( (rtl_TextEncoding) nCharSet );
240 aRes.SetFamily( (FontFamily) nFamily );
241 aRes.SetPitch( (FontPitch) nPitch );
242 aRes.SetWeight( (FontWeight) nWeight );
243 aRes.SetItalic( (FontItalic) nItalic );
244 return aRes;
248 bool SmFontFormat::operator == ( const SmFontFormat &rFntFmt ) const
250 return aName == rFntFmt.aName &&
251 nCharSet == rFntFmt.nCharSet &&
252 nFamily == rFntFmt.nFamily &&
253 nPitch == rFntFmt.nPitch &&
254 nWeight == rFntFmt.nWeight &&
255 nItalic == rFntFmt.nItalic;
259 /////////////////////////////////////////////////////////////////
261 SmFntFmtListEntry::SmFntFmtListEntry( const String &rId, const SmFontFormat &rFntFmt ) :
262 aId (rId),
263 aFntFmt (rFntFmt)
268 SmFontFormatList::SmFontFormatList()
270 bModified = false;
274 void SmFontFormatList::Clear()
276 if (!aEntries.empty())
278 aEntries.clear();
279 SetModified( true );
284 void SmFontFormatList::AddFontFormat( const String &rFntFmtId,
285 const SmFontFormat &rFntFmt )
287 const SmFontFormat *pFntFmt = GetFontFormat( rFntFmtId );
288 OSL_ENSURE( !pFntFmt, "FontFormatId already exists" );
289 if (!pFntFmt)
291 SmFntFmtListEntry aEntry( rFntFmtId, rFntFmt );
292 aEntries.push_back( aEntry );
293 SetModified( true );
298 void SmFontFormatList::RemoveFontFormat( const String &rFntFmtId )
301 // search for entry
302 for (size_t i = 0; i < aEntries.size(); ++i)
304 if (aEntries[i].aId == rFntFmtId)
306 // remove entry if found
307 aEntries.erase( aEntries.begin() + i );
308 SetModified( true );
309 break;
315 const SmFontFormat * SmFontFormatList::GetFontFormat( const String &rFntFmtId ) const
317 const SmFontFormat *pRes = 0;
319 for (size_t i = 0; i < aEntries.size(); ++i)
321 if (aEntries[i].aId == rFntFmtId)
323 pRes = &aEntries[i].aFntFmt;
324 break;
328 return pRes;
333 const SmFontFormat * SmFontFormatList::GetFontFormat( size_t nPos ) const
335 const SmFontFormat *pRes = 0;
336 if (nPos < aEntries.size())
337 pRes = &aEntries[nPos].aFntFmt;
338 return pRes;
342 const String SmFontFormatList::GetFontFormatId( const SmFontFormat &rFntFmt ) const
344 String aRes;
346 for (size_t i = 0; i < aEntries.size(); ++i)
348 if (aEntries[i].aFntFmt == rFntFmt)
350 aRes = aEntries[i].aId;
351 break;
355 return aRes;
359 const String SmFontFormatList::GetFontFormatId( const SmFontFormat &rFntFmt, bool bAdd )
361 String aRes( GetFontFormatId( rFntFmt) );
362 if (0 == aRes.Len() && bAdd)
364 aRes = GetNewFontFormatId();
365 AddFontFormat( aRes, rFntFmt );
367 return aRes;
371 const String SmFontFormatList::GetFontFormatId( size_t nPos ) const
373 String aRes;
374 if (nPos < aEntries.size())
375 aRes = aEntries[nPos].aId;
376 return aRes;
380 const OUString SmFontFormatList::GetNewFontFormatId() const
382 // returns first unused FormatId
384 OUString aPrefix("Id");
385 sal_Int32 nCnt = GetCount();
386 for (sal_Int32 i = 1; i <= nCnt + 1; ++i)
388 OUString aTmpId = aPrefix + OUString::valueOf(i);
389 if (!GetFontFormat(aTmpId))
390 return aTmpId;
392 OSL_ENSURE( !this, "failed to create new FontFormatId" );
394 return OUString();
397 /////////////////////////////////////////////////////////////////
399 SmMathConfig::SmMathConfig() :
400 ConfigItem(OUString(aRootName))
402 pFormat = 0;
403 pOther = 0;
404 pFontFormatList = 0;
405 pSymbolMgr = 0;
407 bIsOtherModified = bIsFormatModified = false;
411 SmMathConfig::~SmMathConfig()
413 Save();
414 delete pFormat;
415 delete pOther;
416 delete pFontFormatList;
417 delete pSymbolMgr;
421 void SmMathConfig::SetOtherModified( bool bVal )
423 bIsOtherModified = bVal;
427 void SmMathConfig::SetFormatModified( bool bVal )
429 bIsFormatModified = bVal;
433 void SmMathConfig::SetFontFormatListModified( bool bVal )
435 if (pFontFormatList)
436 pFontFormatList->SetModified( bVal );
440 void SmMathConfig::ReadSymbol( SmSym &rSymbol,
441 const OUString &rSymbolName,
442 const OUString &rBaseNode ) const
444 Sequence< OUString > aNames = lcl_GetSymbolPropertyNames();
445 sal_Int32 nProps = aNames.getLength();
447 OUString aDelim( OUString::valueOf( (sal_Unicode) '/' ) );
448 OUString *pName = aNames.getArray();
449 for (sal_Int32 i = 0; i < nProps; ++i)
451 OUString &rName = pName[i];
452 OUString aTmp( rName );
453 rName = rBaseNode;
454 rName += aDelim;
455 rName += rSymbolName;
456 rName += aDelim;
457 rName += aTmp;
460 const Sequence< Any > aValues = ((SmMathConfig*) this)->GetProperties( aNames );
462 if (nProps && aValues.getLength() == nProps)
464 const Any * pValue = aValues.getConstArray();
465 Font aFont;
466 sal_UCS4 cChar = '\0';
467 String aSet;
468 bool bPredefined = false;
470 OUString aTmpStr;
471 sal_Int32 nTmp32 = 0;
472 bool bTmp = false;
474 bool bOK = true;
475 if (pValue->hasValue() && (*pValue >>= nTmp32))
476 cChar = static_cast< sal_UCS4 >( nTmp32 );
477 else
478 bOK = false;
479 ++pValue;
480 if (pValue->hasValue() && (*pValue >>= aTmpStr))
481 aSet = aTmpStr;
482 else
483 bOK = false;
484 ++pValue;
485 if (pValue->hasValue() && (*pValue >>= bTmp))
486 bPredefined = bTmp;
487 else
488 bOK = false;
489 ++pValue;
490 if (pValue->hasValue() && (*pValue >>= aTmpStr))
492 const SmFontFormat *pFntFmt = GetFontFormatList().GetFontFormat( aTmpStr );
493 OSL_ENSURE( pFntFmt, "unknown FontFormat" );
494 if (pFntFmt)
495 aFont = pFntFmt->GetFont();
497 else
498 bOK = false;
499 ++pValue;
501 if (bOK)
503 String aUiName( rSymbolName );
504 String aUiSetName( aSet );
505 if (bPredefined)
507 String aTmp;
508 aTmp = GetUiSymbolName( rSymbolName );
509 OSL_ENSURE( aTmp.Len(), "localized symbol-name not found" );
510 if (aTmp.Len())
511 aUiName = aTmp;
512 aTmp = GetUiSymbolSetName( aSet );
513 OSL_ENSURE( aTmp.Len(), "localized symbolset-name not found" );
514 if (aTmp.Len())
515 aUiSetName = aTmp;
518 rSymbol = SmSym( aUiName, aFont, cChar, aUiSetName, bPredefined );
519 if (aUiName != String(rSymbolName))
520 rSymbol.SetExportName( rSymbolName );
522 else
524 OSL_FAIL( "symbol read error" );
530 SmSymbolManager & SmMathConfig::GetSymbolManager()
532 if (!pSymbolMgr)
534 pSymbolMgr = new SmSymbolManager;
535 pSymbolMgr->Load();
537 return *pSymbolMgr;
541 void SmMathConfig::Commit()
543 Save();
547 void SmMathConfig::Save()
549 SaveOther();
550 SaveFormat();
551 SaveFontFormatList();
555 void SmMathConfig::GetSymbols( std::vector< SmSym > &rSymbols ) const
557 Sequence< OUString > aNodes( ((SmMathConfig*) this)->GetNodeNames( SYMBOL_LIST ) );
558 const OUString *pNode = aNodes.getConstArray();
559 sal_Int32 nNodes = aNodes.getLength();
561 rSymbols.resize( nNodes );
562 std::vector< SmSym >::iterator aIt( rSymbols.begin() );
563 std::vector< SmSym >::iterator aEnd( rSymbols.end() );
564 while (aIt != aEnd)
566 ReadSymbol( *aIt++, *pNode++, SYMBOL_LIST );
571 void SmMathConfig::SetSymbols( const std::vector< SmSym > &rNewSymbols )
573 sal_uIntPtr nCount = rNewSymbols.size();
575 Sequence< OUString > aNames = lcl_GetSymbolPropertyNames();
576 const OUString *pNames = aNames.getConstArray();
577 sal_uIntPtr nSymbolProps = sal::static_int_cast< sal_uInt32 >(aNames.getLength());
579 Sequence< PropertyValue > aValues( nCount * nSymbolProps );
580 PropertyValue *pValues = aValues.getArray();
582 PropertyValue *pVal = pValues;
583 OUString aDelim( OUString::valueOf( (sal_Unicode) '/' ) );
584 std::vector< SmSym >::const_iterator aIt( rNewSymbols.begin() );
585 std::vector< SmSym >::const_iterator aEnd( rNewSymbols.end() );
586 while (aIt != aEnd)
588 const SmSym &rSymbol = *aIt++;
589 OUString aNodeNameDelim( SYMBOL_LIST );
590 aNodeNameDelim += aDelim;
591 aNodeNameDelim += rSymbol.GetExportName();
592 aNodeNameDelim += aDelim;
594 const OUString *pName = pNames;
596 // Char
597 pVal->Name = aNodeNameDelim;
598 pVal->Name += *pName++;
599 pVal->Value <<= static_cast< sal_UCS4 >( rSymbol.GetCharacter() );
600 pVal++;
601 // Set
602 pVal->Name = aNodeNameDelim;
603 pVal->Name += *pName++;
604 OUString aTmp( rSymbol.GetSymbolSetName() );
605 if (rSymbol.IsPredefined())
606 aTmp = GetExportSymbolSetName( aTmp );
607 pVal->Value <<= aTmp;
608 pVal++;
609 // Predefined
610 pVal->Name = aNodeNameDelim;
611 pVal->Name += *pName++;
612 pVal->Value <<= (sal_Bool) rSymbol.IsPredefined();
613 pVal++;
614 // FontFormatId
615 SmFontFormat aFntFmt( rSymbol.GetFace() );
616 String aFntFmtId( GetFontFormatList().GetFontFormatId( aFntFmt, true ) );
617 OSL_ENSURE( aFntFmtId.Len(), "FontFormatId not found" );
618 pVal->Name = aNodeNameDelim;
619 pVal->Name += *pName++;
620 pVal->Value <<= OUString( aFntFmtId );
621 pVal++;
623 OSL_ENSURE( pVal - pValues == sal::static_int_cast< ptrdiff_t >(nCount * nSymbolProps), "properties missing" );
624 ReplaceSetProperties( SYMBOL_LIST, aValues );
626 StripFontFormatList( rNewSymbols );
627 SaveFontFormatList();
631 SmFontFormatList & SmMathConfig::GetFontFormatList()
633 if (!pFontFormatList)
635 LoadFontFormatList();
637 return *pFontFormatList;
641 void SmMathConfig::LoadFontFormatList()
643 if (!pFontFormatList)
644 pFontFormatList = new SmFontFormatList;
645 else
646 pFontFormatList->Clear();
648 Sequence< OUString > aNodes( GetNodeNames( FONT_FORMAT_LIST ) );
649 const OUString *pNode = aNodes.getConstArray();
650 sal_Int32 nNodes = aNodes.getLength();
652 for (sal_Int32 i = 0; i < nNodes; ++i)
654 SmFontFormat aFntFmt;
655 ReadFontFormat( aFntFmt, pNode[i], FONT_FORMAT_LIST );
656 if (!pFontFormatList->GetFontFormat( pNode[i] ))
658 OSL_ENSURE( 0 == pFontFormatList->GetFontFormat( pNode[i] ),
659 "FontFormat ID already exists" );
660 pFontFormatList->AddFontFormat( pNode[i], aFntFmt );
663 pFontFormatList->SetModified( false );
667 void SmMathConfig::ReadFontFormat( SmFontFormat &rFontFormat,
668 const OUString &rSymbolName, const OUString &rBaseNode ) const
670 Sequence< OUString > aNames = lcl_GetFontPropertyNames();
671 sal_Int32 nProps = aNames.getLength();
673 OUString aDelim( OUString::valueOf( (sal_Unicode) '/' ) );
674 OUString *pName = aNames.getArray();
675 for (sal_Int32 i = 0; i < nProps; ++i)
677 OUString &rName = pName[i];
678 OUString aTmp( rName );
679 rName = rBaseNode;
680 rName += aDelim;
681 rName += rSymbolName;
682 rName += aDelim;
683 rName += aTmp;
686 const Sequence< Any > aValues = ((SmMathConfig*) this)->GetProperties( aNames );
688 if (nProps && aValues.getLength() == nProps)
690 const Any * pValue = aValues.getConstArray();
692 OUString aTmpStr;
693 sal_Int16 nTmp16 = 0;
695 bool bOK = true;
696 if (pValue->hasValue() && (*pValue >>= aTmpStr))
697 rFontFormat.aName = aTmpStr;
698 else
699 bOK = false;
700 ++pValue;
701 if (pValue->hasValue() && (*pValue >>= nTmp16))
702 rFontFormat.nCharSet = nTmp16; // 6.0 file-format GetSOLoadTextEncoding not needed
703 else
704 bOK = false;
705 ++pValue;
706 if (pValue->hasValue() && (*pValue >>= nTmp16))
707 rFontFormat.nFamily = nTmp16;
708 else
709 bOK = false;
710 ++pValue;
711 if (pValue->hasValue() && (*pValue >>= nTmp16))
712 rFontFormat.nPitch = nTmp16;
713 else
714 bOK = false;
715 ++pValue;
716 if (pValue->hasValue() && (*pValue >>= nTmp16))
717 rFontFormat.nWeight = nTmp16;
718 else
719 bOK = false;
720 ++pValue;
721 if (pValue->hasValue() && (*pValue >>= nTmp16))
722 rFontFormat.nItalic = nTmp16;
723 else
724 bOK = false;
725 ++pValue;
727 OSL_ENSURE( bOK, "read FontFormat failed" );
728 (void)bOK;
733 void SmMathConfig::SaveFontFormatList()
735 SmFontFormatList &rFntFmtList = GetFontFormatList();
737 if (!rFntFmtList.IsModified())
738 return;
740 Sequence< OUString > aNames = lcl_GetFontPropertyNames();
741 sal_Int32 nSymbolProps = aNames.getLength();
743 size_t nCount = rFntFmtList.GetCount();
745 Sequence< PropertyValue > aValues( nCount * nSymbolProps );
746 PropertyValue *pValues = aValues.getArray();
748 PropertyValue *pVal = pValues;
749 OUString aDelim( OUString::valueOf( (sal_Unicode) '/' ) );
750 for (size_t i = 0; i < nCount; ++i)
752 String aFntFmtId( rFntFmtList.GetFontFormatId( i ) );
753 const SmFontFormat aFntFmt( *rFntFmtList.GetFontFormat( aFntFmtId ) );
755 OUString aNodeNameDelim( FONT_FORMAT_LIST );
756 aNodeNameDelim += aDelim;
757 aNodeNameDelim += aFntFmtId;
758 aNodeNameDelim += aDelim;
760 const OUString *pName = aNames.getConstArray();
762 // Name
763 pVal->Name = aNodeNameDelim;
764 pVal->Name += *pName++;
765 pVal->Value <<= OUString( aFntFmt.aName );
766 pVal++;
767 // CharSet
768 pVal->Name = aNodeNameDelim;
769 pVal->Name += *pName++;
770 pVal->Value <<= (sal_Int16) aFntFmt.nCharSet; // 6.0 file-format GetSOStoreTextEncoding not needed
771 pVal++;
772 // Family
773 pVal->Name = aNodeNameDelim;
774 pVal->Name += *pName++;
775 pVal->Value <<= (sal_Int16) aFntFmt.nFamily;
776 pVal++;
777 // Pitch
778 pVal->Name = aNodeNameDelim;
779 pVal->Name += *pName++;
780 pVal->Value <<= (sal_Int16) aFntFmt.nPitch;
781 pVal++;
782 // Weight
783 pVal->Name = aNodeNameDelim;
784 pVal->Name += *pName++;
785 pVal->Value <<= (sal_Int16) aFntFmt.nWeight;
786 pVal++;
787 // Italic
788 pVal->Name = aNodeNameDelim;
789 pVal->Name += *pName++;
790 pVal->Value <<= (sal_Int16) aFntFmt.nItalic;
791 pVal++;
793 OSL_ENSURE( sal::static_int_cast<size_t>(pVal - pValues) == nCount * nSymbolProps, "properties missing" );
794 ReplaceSetProperties( FONT_FORMAT_LIST, aValues );
796 rFntFmtList.SetModified( false );
800 void SmMathConfig::StripFontFormatList( const std::vector< SmSym > &rSymbols )
802 size_t i;
804 // build list of used font-formats only
805 //!! font-format IDs may be different !!
806 SmFontFormatList aUsedList;
807 for (i = 0; i < rSymbols.size(); ++i)
809 OSL_ENSURE( rSymbols[i].GetName().getLength() > 0, "non named symbol" );
810 aUsedList.GetFontFormatId( SmFontFormat( rSymbols[i].GetFace() ) , true );
812 const SmFormat & rStdFmt = GetStandardFormat();
813 for (i = FNT_BEGIN; i <= FNT_END; ++i)
815 aUsedList.GetFontFormatId( SmFontFormat( rStdFmt.GetFont( i ) ) , true );
818 // remove unused font-formats from list
819 SmFontFormatList &rFntFmtList = GetFontFormatList();
820 size_t nCnt = rFntFmtList.GetCount();
821 SmFontFormat *pTmpFormat = new SmFontFormat[ nCnt ];
822 String *pId = new String [ nCnt ];
823 size_t k;
824 for (k = 0; k < nCnt; ++k)
826 pTmpFormat[k] = *rFntFmtList.GetFontFormat( k );
827 pId[k] = rFntFmtList.GetFontFormatId( k );
829 for (k = 0; k < nCnt; ++k)
831 if (0 == aUsedList.GetFontFormatId( pTmpFormat[k] ).Len())
833 rFntFmtList.RemoveFontFormat( pId[k] );
836 delete [] pId;
837 delete [] pTmpFormat;
841 void SmMathConfig::LoadOther()
843 if (!pOther)
844 pOther = new SmCfgOther;
846 Sequence< OUString > aNames( GetOtherPropertyNames() );
847 sal_Int32 nProps = aNames.getLength();
849 Sequence< Any > aValues( GetProperties( aNames ) );
850 if (nProps && aValues.getLength() == nProps)
852 const Any *pValues = aValues.getConstArray();
853 const Any *pVal = pValues;
855 sal_Int16 nTmp16 = 0;
856 bool bTmp = false;
858 // Print/Title
859 if (pVal->hasValue() && (*pVal >>= bTmp))
860 pOther->bPrintTitle = bTmp;
861 ++pVal;
862 // Print/FormulaText
863 if (pVal->hasValue() && (*pVal >>= bTmp))
864 pOther->bPrintFormulaText = bTmp;
865 ++pVal;
866 // Print/Frame
867 if (pVal->hasValue() && (*pVal >>= bTmp))
868 pOther->bPrintFrame = bTmp;
869 ++pVal;
870 // Print/Size
871 if (pVal->hasValue() && (*pVal >>= nTmp16))
872 pOther->ePrintSize = (SmPrintSize) nTmp16;
873 ++pVal;
874 // Print/ZoomFactor
875 if (pVal->hasValue() && (*pVal >>= nTmp16))
876 pOther->nPrintZoomFactor = nTmp16;
877 ++pVal;
878 // LoadSave/IsSaveOnlyUsedSymbols
879 if (pVal->hasValue() && (*pVal >>= bTmp))
880 pOther->bIsSaveOnlyUsedSymbols = bTmp;
881 ++pVal;
882 // Misc/IgnoreSpacesRight
883 if (pVal->hasValue() && (*pVal >>= bTmp))
884 pOther->bIgnoreSpacesRight = bTmp;
885 ++pVal;
886 // View/ToolboxVisible
887 if (pVal->hasValue() && (*pVal >>= bTmp))
888 pOther->bToolboxVisible = bTmp;
889 ++pVal;
890 // View/AutoRedraw
891 if (pVal->hasValue() && (*pVal >>= bTmp))
892 pOther->bAutoRedraw = bTmp;
893 ++pVal;
894 // View/FormulaCursor
895 if (pVal->hasValue() && (*pVal >>= bTmp))
896 pOther->bFormulaCursor = bTmp;
897 ++pVal;
899 OSL_ENSURE( pVal - pValues == nProps, "property mismatch" );
900 SetOtherModified( false );
905 void SmMathConfig::SaveOther()
907 if (!pOther || !IsOtherModified())
908 return;
910 const Sequence< OUString > aNames( GetOtherPropertyNames() );
911 sal_Int32 nProps = aNames.getLength();
913 Sequence< Any > aValues( nProps );
914 Any *pValues = aValues.getArray();
915 Any *pValue = pValues;
917 // Print/Title
918 *pValue++ <<= (sal_Bool) pOther->bPrintTitle;
919 // Print/FormulaText
920 *pValue++ <<= (sal_Bool) pOther->bPrintFormulaText;
921 // Print/Frame
922 *pValue++ <<= (sal_Bool) pOther->bPrintFrame;
923 // Print/Size
924 *pValue++ <<= (sal_Int16) pOther->ePrintSize;
925 // Print/ZoomFactor
926 *pValue++ <<= (sal_Int16) pOther->nPrintZoomFactor;
927 // LoadSave/IsSaveOnlyUsedSymbols
928 *pValue++ <<= (sal_Bool) pOther->bIsSaveOnlyUsedSymbols;
929 // Misc/IgnoreSpacesRight
930 *pValue++ <<= (sal_Bool) pOther->bIgnoreSpacesRight;
931 // View/ToolboxVisible
932 *pValue++ <<= (sal_Bool) pOther->bToolboxVisible;
933 // View/AutoRedraw
934 *pValue++ <<= (sal_Bool) pOther->bAutoRedraw;
935 // View/FormulaCursor
936 *pValue++ <<= (sal_Bool) pOther->bFormulaCursor;
938 OSL_ENSURE( pValue - pValues == nProps, "property mismatch" );
939 PutProperties( aNames , aValues );
941 SetOtherModified( false );
944 void SmMathConfig::LoadFormat()
946 if (!pFormat)
947 pFormat = new SmFormat;
950 Sequence< OUString > aNames( GetFormatPropertyNames() );
951 sal_Int32 nProps = aNames.getLength();
953 Sequence< Any > aValues( GetProperties( aNames ) );
954 if (nProps && aValues.getLength() == nProps)
956 const Any *pValues = aValues.getConstArray();
957 const Any *pVal = pValues;
959 OUString aTmpStr;
960 sal_Int16 nTmp16 = 0;
961 bool bTmp = false;
963 // StandardFormat/Textmode
964 if (pVal->hasValue() && (*pVal >>= bTmp))
965 pFormat->SetTextmode( bTmp );
966 ++pVal;
967 // StandardFormat/GreekCharStyle
968 if (pVal->hasValue() && (*pVal >>= nTmp16))
969 pFormat->SetGreekCharStyle( nTmp16 );
970 ++pVal;
971 // StandardFormat/ScaleNormalBracket
972 if (pVal->hasValue() && (*pVal >>= bTmp))
973 pFormat->SetScaleNormalBrackets( bTmp );
974 ++pVal;
975 // StandardFormat/HorizontalAlignment
976 if (pVal->hasValue() && (*pVal >>= nTmp16))
977 pFormat->SetHorAlign( (SmHorAlign) nTmp16 );
978 ++pVal;
979 // StandardFormat/BaseSize
980 if (pVal->hasValue() && (*pVal >>= nTmp16))
981 pFormat->SetBaseSize( Size(0, SmPtsTo100th_mm( nTmp16 )) );
982 ++pVal;
984 sal_uInt16 i;
985 for (i = SIZ_BEGIN; i <= SIZ_END; ++i)
987 if (pVal->hasValue() && (*pVal >>= nTmp16))
988 pFormat->SetRelSize( i, nTmp16 );
989 ++pVal;
992 for (i = DIS_BEGIN; i <= DIS_END; ++i)
994 if (pVal->hasValue() && (*pVal >>= nTmp16))
995 pFormat->SetDistance( i, nTmp16 );
996 ++pVal;
999 LanguageType nLang = Application::GetSettings().GetUILanguageTag().getLanguageType();
1000 for (i = FNT_BEGIN; i < FNT_END; ++i)
1002 Font aFnt;
1003 bool bUseDefaultFont = true;
1004 if (pVal->hasValue() && (*pVal >>= aTmpStr))
1006 bUseDefaultFont = aTmpStr.isEmpty();
1007 if (bUseDefaultFont)
1009 aFnt = pFormat->GetFont( i );
1010 aFnt.SetName( GetDefaultFontName( nLang, i ) );
1012 else
1014 const SmFontFormat *pFntFmt = GetFontFormatList().GetFontFormat( aTmpStr );
1015 OSL_ENSURE( pFntFmt, "unknown FontFormat" );
1016 if (pFntFmt)
1017 aFnt = pFntFmt->GetFont();
1020 ++pVal;
1022 aFnt.SetSize( pFormat->GetBaseSize() );
1023 pFormat->SetFont( i, aFnt, bUseDefaultFont );
1026 OSL_ENSURE( pVal - pValues == nProps, "property mismatch" );
1027 SetFormatModified( false );
1032 void SmMathConfig::SaveFormat()
1034 if (!pFormat || !IsFormatModified())
1035 return;
1037 const Sequence< OUString > aNames( GetFormatPropertyNames() );
1038 sal_Int32 nProps = aNames.getLength();
1040 Sequence< Any > aValues( nProps );
1041 Any *pValues = aValues.getArray();
1042 Any *pValue = pValues;
1044 // StandardFormat/Textmode
1045 *pValue++ <<= (sal_Bool) pFormat->IsTextmode();
1046 // StandardFormat/GreekCharStyle
1047 *pValue++ <<= (sal_Int16) pFormat->GetGreekCharStyle();
1048 // StandardFormat/ScaleNormalBracket
1049 *pValue++ <<= (sal_Bool) pFormat->IsScaleNormalBrackets();
1050 // StandardFormat/HorizontalAlignment
1051 *pValue++ <<= (sal_Int16) pFormat->GetHorAlign();
1052 // StandardFormat/BaseSize
1053 *pValue++ <<= (sal_Int16) SmRoundFraction( Sm100th_mmToPts(
1054 pFormat->GetBaseSize().Height() ) );
1056 sal_uInt16 i;
1057 for (i = SIZ_BEGIN; i <= SIZ_END; ++i)
1058 *pValue++ <<= (sal_Int16) pFormat->GetRelSize( i );
1060 for (i = DIS_BEGIN; i <= DIS_END; ++i)
1061 *pValue++ <<= (sal_Int16) pFormat->GetDistance( i );
1063 for (i = FNT_BEGIN; i < FNT_END; ++i)
1065 OUString aFntFmtId;
1067 if (!pFormat->IsDefaultFont( i ))
1069 SmFontFormat aFntFmt( pFormat->GetFont( i ) );
1070 aFntFmtId = GetFontFormatList().GetFontFormatId( aFntFmt, true );
1071 OSL_ENSURE( !aFntFmtId.isEmpty(), "FontFormatId not found" );
1074 *pValue++ <<= aFntFmtId;
1077 OSL_ENSURE( pValue - pValues == nProps, "property mismatch" );
1078 PutProperties( aNames , aValues );
1080 SetFormatModified( false );
1084 const SmFormat & SmMathConfig::GetStandardFormat() const
1086 if (!pFormat)
1087 ((SmMathConfig *) this)->LoadFormat();
1088 return *pFormat;
1092 void SmMathConfig::SetStandardFormat( const SmFormat &rFormat, bool bSaveFontFormatList )
1094 if (!pFormat)
1095 LoadFormat();
1096 if (rFormat != *pFormat)
1098 *pFormat = rFormat;
1099 SetFormatModified( true );
1100 SaveFormat();
1102 if (bSaveFontFormatList)
1104 // needed for SmFontTypeDialog's DefaultButtonClickHdl
1105 SetFontFormatListModified( true );
1106 SaveFontFormatList();
1112 SmPrintSize SmMathConfig::GetPrintSize() const
1114 if (!pOther)
1115 ((SmMathConfig *) this)->LoadOther();
1116 return pOther->ePrintSize;
1120 void SmMathConfig::SetPrintSize( SmPrintSize eSize )
1122 if (!pOther)
1123 LoadOther();
1124 if (eSize != pOther->ePrintSize)
1126 pOther->ePrintSize = eSize;
1127 SetOtherModified( true );
1132 sal_uInt16 SmMathConfig::GetPrintZoomFactor() const
1134 if (!pOther)
1135 ((SmMathConfig *) this)->LoadOther();
1136 return pOther->nPrintZoomFactor;
1140 void SmMathConfig::SetPrintZoomFactor( sal_uInt16 nVal )
1142 if (!pOther)
1143 LoadOther();
1144 if (nVal != pOther->nPrintZoomFactor)
1146 pOther->nPrintZoomFactor = nVal;
1147 SetOtherModified( true );
1152 void SmMathConfig::SetOtherIfNotEqual( bool &rbItem, bool bNewVal )
1154 if (bNewVal != rbItem)
1156 rbItem = bNewVal;
1157 SetOtherModified( true );
1162 bool SmMathConfig::IsPrintTitle() const
1164 if (!pOther)
1165 ((SmMathConfig *) this)->LoadOther();
1166 return pOther->bPrintTitle;
1170 void SmMathConfig::SetPrintTitle( bool bVal )
1172 if (!pOther)
1173 LoadOther();
1174 SetOtherIfNotEqual( pOther->bPrintTitle, bVal );
1178 bool SmMathConfig::IsPrintFormulaText() const
1180 if (!pOther)
1181 ((SmMathConfig *) this)->LoadOther();
1182 return pOther->bPrintFormulaText;
1186 void SmMathConfig::SetPrintFormulaText( bool bVal )
1188 if (!pOther)
1189 LoadOther();
1190 SetOtherIfNotEqual( pOther->bPrintFormulaText, bVal );
1193 bool SmMathConfig::IsSaveOnlyUsedSymbols() const
1195 if (!pOther)
1196 ((SmMathConfig *) this)->LoadOther();
1197 return pOther->bIsSaveOnlyUsedSymbols;
1200 bool SmMathConfig::IsPrintFrame() const
1202 if (!pOther)
1203 ((SmMathConfig *) this)->LoadOther();
1204 return pOther->bPrintFrame;
1208 void SmMathConfig::SetPrintFrame( bool bVal )
1210 if (!pOther)
1211 LoadOther();
1212 SetOtherIfNotEqual( pOther->bPrintFrame, bVal );
1216 void SmMathConfig::SetSaveOnlyUsedSymbols( bool bVal )
1218 if (!pOther)
1219 LoadOther();
1220 SetOtherIfNotEqual( pOther->bIsSaveOnlyUsedSymbols, bVal );
1224 bool SmMathConfig::IsIgnoreSpacesRight() const
1226 if (!pOther)
1227 ((SmMathConfig *) this)->LoadOther();
1228 return pOther->bIgnoreSpacesRight;
1232 void SmMathConfig::SetIgnoreSpacesRight( bool bVal )
1234 if (!pOther)
1235 LoadOther();
1236 SetOtherIfNotEqual( pOther->bIgnoreSpacesRight, bVal );
1240 bool SmMathConfig::IsAutoRedraw() const
1242 if (!pOther)
1243 ((SmMathConfig *) this)->LoadOther();
1244 return pOther->bAutoRedraw;
1248 void SmMathConfig::SetAutoRedraw( bool bVal )
1250 if (!pOther)
1251 LoadOther();
1252 SetOtherIfNotEqual( pOther->bAutoRedraw, bVal );
1256 bool SmMathConfig::IsShowFormulaCursor() const
1258 if (!pOther)
1259 ((SmMathConfig *) this)->LoadOther();
1260 return pOther->bFormulaCursor;
1264 void SmMathConfig::SetShowFormulaCursor( bool bVal )
1266 if (!pOther)
1267 LoadOther();
1268 SetOtherIfNotEqual( pOther->bFormulaCursor, bVal );
1271 void SmMathConfig::Notify( const com::sun::star::uno::Sequence< OUString >& )
1274 /////////////////////////////////////////////////////////////////
1276 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */