merge the formfield patch from ooo-build
[ooovba.git] / starmath / source / cfgitem.cxx
blob9d34209aff083ebff69c1ee72cd3a25eda2f713e
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();
583 void SmMathConfig::GetSymbols( std::vector< SmSym > &rSymbols ) const
585 Sequence< OUString > aNodes( ((SmMathConfig*) this)->GetNodeNames( A2OU( SYMBOL_LIST ) ) );
586 const OUString *pNode = aNodes.getConstArray();
587 INT32 nNodes = aNodes.getLength();
589 rSymbols.resize( nNodes );
590 std::vector< SmSym >::iterator aIt( rSymbols.begin() );
591 std::vector< SmSym >::iterator aEnd( rSymbols.end() );
592 while (aIt != aEnd)
594 ReadSymbol( *aIt++, *pNode++, A2OU( SYMBOL_LIST ) );
599 void SmMathConfig::SetSymbols( const std::vector< SmSym > &rNewSymbols )
601 sal_uIntPtr nCount = rNewSymbols.size();
603 Sequence< OUString > aNames = lcl_GetSymbolPropertyNames();
604 const OUString *pNames = aNames.getConstArray();
605 sal_uIntPtr nSymbolProps = sal::static_int_cast< UINT32 >(aNames.getLength());
607 Sequence< PropertyValue > aValues( nCount * nSymbolProps );
608 PropertyValue *pValues = aValues.getArray();
610 PropertyValue *pVal = pValues;
611 OUString aDelim( OUString::valueOf( (sal_Unicode) '/' ) );
612 std::vector< SmSym >::const_iterator aIt( rNewSymbols.begin() );
613 std::vector< SmSym >::const_iterator aEnd( rNewSymbols.end() );
614 while (aIt != aEnd)
616 const SmSym &rSymbol = *aIt++;
617 //const Font &rFont = rSymbol.GetFace();
618 OUString aNodeNameDelim( A2OU( SYMBOL_LIST ) );
619 aNodeNameDelim += aDelim;
620 aNodeNameDelim += rSymbol.GetExportName();
621 aNodeNameDelim += aDelim;
623 const OUString *pName = pNames;
625 // Char
626 pVal->Name = aNodeNameDelim;
627 pVal->Name += *pName++;
628 pVal->Value <<= (INT32) rSymbol.GetCharacter();
629 pVal++;
630 // Set
631 pVal->Name = aNodeNameDelim;
632 pVal->Name += *pName++;
633 OUString aTmp( rSymbol.GetSetName() );
634 if (rSymbol.IsPredefined())
635 aTmp = GetExportSymbolSetName( aTmp );
636 pVal->Value <<= aTmp;
637 pVal++;
638 // Predefined
639 pVal->Name = aNodeNameDelim;
640 pVal->Name += *pName++;
641 pVal->Value <<= (BOOL) rSymbol.IsPredefined();
642 pVal++;
643 // FontFormatId
644 SmFontFormat aFntFmt( rSymbol.GetFace() );
645 String aFntFmtId( GetFontFormatList().GetFontFormatId( aFntFmt, TRUE ) );
646 DBG_ASSERT( aFntFmtId.Len(), "FontFormatId not found" );
647 pVal->Name = aNodeNameDelim;
648 pVal->Name += *pName++;
649 pVal->Value <<= OUString( aFntFmtId );
650 pVal++;
652 DBG_ASSERT( pVal - pValues == sal::static_int_cast< ptrdiff_t >(nCount * nSymbolProps), "properties missing" );
653 ReplaceSetProperties( A2OU( SYMBOL_LIST ) , aValues );
655 StripFontFormatList( rNewSymbols );
656 SaveFontFormatList();
660 SmFontFormatList & SmMathConfig::GetFontFormatList()
662 if (!pFontFormatList)
664 LoadFontFormatList();
666 return *pFontFormatList;
670 void SmMathConfig::LoadFontFormatList()
672 if (!pFontFormatList)
673 pFontFormatList = new SmFontFormatList;
674 else
675 pFontFormatList->Clear();
677 Sequence< OUString > aNodes( GetNodeNames( A2OU( FONT_FORMAT_LIST ) ) );
678 const OUString *pNode = aNodes.getConstArray();
679 INT32 nNodes = aNodes.getLength();
681 for (INT32 i = 0; i < nNodes; ++i)
683 SmFontFormat aFntFmt;
684 ReadFontFormat( aFntFmt, pNode[i], A2OU( FONT_FORMAT_LIST ) );
685 if (!pFontFormatList->GetFontFormat( pNode[i] ))
687 DBG_ASSERT( 0 == pFontFormatList->GetFontFormat( pNode[i] ),
688 "FontFormat ID already exists" );
689 pFontFormatList->AddFontFormat( pNode[i], aFntFmt );
692 pFontFormatList->SetModified( FALSE );
696 void SmMathConfig::ReadFontFormat( SmFontFormat &rFontFormat,
697 const OUString &rSymbolName, const OUString &rBaseNode ) const
699 Sequence< OUString > aNames = lcl_GetFontPropertyNames();
700 INT32 nProps = aNames.getLength();
702 OUString aDelim( OUString::valueOf( (sal_Unicode) '/' ) );
703 OUString *pName = aNames.getArray();
704 for (INT32 i = 0; i < nProps; ++i)
706 OUString &rName = pName[i];
707 OUString aTmp( rName );
708 rName = rBaseNode;
709 rName += aDelim;
710 rName += rSymbolName;
711 rName += aDelim;
712 rName += aTmp;
715 const Sequence< Any > aValues = ((SmMathConfig*) this)->GetProperties( aNames );
717 if (nProps && aValues.getLength() == nProps)
719 const Any * pValue = aValues.getConstArray();
721 OUString aTmpStr;
722 INT16 nTmp16 = 0;
724 BOOL bOK = TRUE;
725 if (pValue->hasValue() && (*pValue >>= aTmpStr))
726 rFontFormat.aName = aTmpStr;
727 else
728 bOK = FALSE;
729 ++pValue;
730 if (pValue->hasValue() && (*pValue >>= nTmp16))
731 rFontFormat.nCharSet = nTmp16; // 6.0 file-format GetSOLoadTextEncoding not needed
732 else
733 bOK = FALSE;
734 ++pValue;
735 if (pValue->hasValue() && (*pValue >>= nTmp16))
736 rFontFormat.nFamily = nTmp16;
737 else
738 bOK = FALSE;
739 ++pValue;
740 if (pValue->hasValue() && (*pValue >>= nTmp16))
741 rFontFormat.nPitch = nTmp16;
742 else
743 bOK = FALSE;
744 ++pValue;
745 if (pValue->hasValue() && (*pValue >>= nTmp16))
746 rFontFormat.nWeight = nTmp16;
747 else
748 bOK = FALSE;
749 ++pValue;
750 if (pValue->hasValue() && (*pValue >>= nTmp16))
751 rFontFormat.nItalic = nTmp16;
752 else
753 bOK = FALSE;
754 ++pValue;
756 DBG_ASSERT( bOK, "read FontFormat failed" );
761 void SmMathConfig::SaveFontFormatList()
763 SmFontFormatList &rFntFmtList = GetFontFormatList();
765 if (!rFntFmtList.IsModified())
766 return;
768 Sequence< OUString > aNames = lcl_GetFontPropertyNames();
769 INT32 nSymbolProps = aNames.getLength();
771 USHORT nCount = rFntFmtList.GetCount();
773 Sequence< PropertyValue > aValues( nCount * nSymbolProps );
774 PropertyValue *pValues = aValues.getArray();
776 PropertyValue *pVal = pValues;
777 OUString aDelim( OUString::valueOf( (sal_Unicode) '/' ) );
778 for (USHORT i = 0; i < nCount; ++i)
780 String aFntFmtId( rFntFmtList.GetFontFormatId( i ) );
781 const SmFontFormat aFntFmt( *rFntFmtList.GetFontFormat( aFntFmtId ) );
783 OUString aNodeNameDelim( A2OU( FONT_FORMAT_LIST ) );
784 aNodeNameDelim += aDelim;
785 aNodeNameDelim += aFntFmtId;
786 aNodeNameDelim += aDelim;
788 const OUString *pName = aNames.getConstArray();;
790 // Name
791 pVal->Name = aNodeNameDelim;
792 pVal->Name += *pName++;
793 pVal->Value <<= OUString( aFntFmt.aName );
794 pVal++;
795 // CharSet
796 pVal->Name = aNodeNameDelim;
797 pVal->Name += *pName++;
798 pVal->Value <<= (INT16) aFntFmt.nCharSet; // 6.0 file-format GetSOStoreTextEncoding not needed
799 pVal++;
800 // Family
801 pVal->Name = aNodeNameDelim;
802 pVal->Name += *pName++;
803 pVal->Value <<= (INT16) aFntFmt.nFamily;
804 pVal++;
805 // Pitch
806 pVal->Name = aNodeNameDelim;
807 pVal->Name += *pName++;
808 pVal->Value <<= (INT16) aFntFmt.nPitch;
809 pVal++;
810 // Weight
811 pVal->Name = aNodeNameDelim;
812 pVal->Name += *pName++;
813 pVal->Value <<= (INT16) aFntFmt.nWeight;
814 pVal++;
815 // Italic
816 pVal->Name = aNodeNameDelim;
817 pVal->Name += *pName++;
818 pVal->Value <<= (INT16) aFntFmt.nItalic;
819 pVal++;
821 DBG_ASSERT( pVal - pValues == nCount * nSymbolProps, "properties missing" );
822 ReplaceSetProperties( A2OU( FONT_FORMAT_LIST ) , aValues );
824 rFntFmtList.SetModified( FALSE );
828 void SmMathConfig::StripFontFormatList( const std::vector< SmSym > &rSymbols )
830 size_t nCount = rSymbols.size();
831 USHORT i;
833 // build list of used font-formats only
834 //!! font-format IDs may be different !!
835 SmFontFormatList aUsedList;
836 for (i = 0; i < nCount; ++i)
838 DBG_ASSERT( rSymbols[i].GetName().Len() > 0, "non named symbol" );
839 aUsedList.GetFontFormatId( SmFontFormat( rSymbols[i].GetFace() ) , TRUE );
841 const SmFormat & rStdFmt = GetStandardFormat();
842 for (i = FNT_BEGIN; i <= FNT_END; ++i)
844 aUsedList.GetFontFormatId( SmFontFormat( rStdFmt.GetFont( i ) ) , TRUE );
847 // remove unused font-formats from list
848 SmFontFormatList &rFntFmtList = GetFontFormatList();
849 USHORT nCnt = rFntFmtList.GetCount();
850 SmFontFormat *pTmpFormat = new SmFontFormat[ nCnt ];
851 String *pId = new String [ nCnt ];
852 INT32 k;
853 for (k = 0; k < nCnt; ++k)
855 pTmpFormat[k] = *rFntFmtList.GetFontFormat( (USHORT) k );
856 pId[k] = rFntFmtList.GetFontFormatId( (USHORT) k );
858 for (k = 0; k < nCnt; ++k)
860 if (0 == aUsedList.GetFontFormatId( pTmpFormat[k] ).Len())
862 rFntFmtList.RemoveFontFormat( pId[k] );
865 delete [] pId;
866 delete [] pTmpFormat;
870 void SmMathConfig::LoadOther()
872 if (!pOther)
873 pOther = new SmCfgOther;
875 Sequence< OUString > aNames( GetOtherPropertyNames() );
876 INT32 nProps = aNames.getLength();
878 Sequence< Any > aValues( GetProperties( aNames ) );
879 if (nProps && aValues.getLength() == nProps)
881 const Any *pValues = aValues.getConstArray();
882 const Any *pVal = pValues;
884 INT16 nTmp16 = 0;
885 BOOL bTmp = FALSE;
887 // Print/Title
888 if (pVal->hasValue() && (*pVal >>= bTmp))
889 pOther->bPrintTitle = bTmp;
890 ++pVal;
891 // Print/FormulaText
892 if (pVal->hasValue() && (*pVal >>= bTmp))
893 pOther->bPrintFormulaText = bTmp;
894 ++pVal;
895 // Print/Frame
896 if (pVal->hasValue() && (*pVal >>= bTmp))
897 pOther->bPrintFrame = bTmp;
898 ++pVal;
899 // Print/Size
900 if (pVal->hasValue() && (*pVal >>= nTmp16))
901 pOther->ePrintSize = (SmPrintSize) nTmp16;
902 ++pVal;
903 // Print/ZoomFactor
904 if (pVal->hasValue() && (*pVal >>= nTmp16))
905 pOther->nPrintZoomFactor = nTmp16;
906 /* ++pVal;
907 // Misc/NoSymbolsWarning
908 if (pVal->hasValue() && (*pVal >>= bTmp))
909 pOther->bNoSymbolsWarning = bTmp;
911 ++pVal;
912 // Misc/IgnoreSpacesRight
913 if (pVal->hasValue() && (*pVal >>= bTmp))
914 pOther->bIgnoreSpacesRight = bTmp;
915 ++pVal;
916 // View/ToolboxVisible
917 if (pVal->hasValue() && (*pVal >>= bTmp))
918 pOther->bToolboxVisible = bTmp;
919 ++pVal;
920 // View/AutoRedraw
921 if (pVal->hasValue() && (*pVal >>= bTmp))
922 pOther->bAutoRedraw = bTmp;
923 ++pVal;
924 // View/FormulaCursor
925 if (pVal->hasValue() && (*pVal >>= bTmp))
926 pOther->bFormulaCursor = bTmp;
927 ++pVal;
929 DBG_ASSERT( pVal - pValues == nProps, "property mismatch" );
930 SetOtherModified( FALSE );
935 void SmMathConfig::SaveOther()
937 if (!pOther || !IsOtherModified())
938 return;
940 const Sequence< OUString > aNames( GetOtherPropertyNames() );
941 INT32 nProps = aNames.getLength();
943 Sequence< Any > aValues( nProps );
944 Any *pValues = aValues.getArray();
945 Any *pValue = pValues;
947 // Print/Title
948 *pValue++ <<= (BOOL) pOther->bPrintTitle;
949 // Print/FormulaText
950 *pValue++ <<= (BOOL) pOther->bPrintFormulaText;
951 // Print/Frame
952 *pValue++ <<= (BOOL) pOther->bPrintFrame;
953 // Print/Size
954 *pValue++ <<= (INT16) pOther->ePrintSize;
955 // Print/ZoomFactor
956 *pValue++ <<= (INT16) pOther->nPrintZoomFactor;
957 /* // Misc/NoSymbolsWarning
958 *pValue++ <<= (BOOL) pOther->bNoSymbolsWarning;
960 // Misc/IgnoreSpacesRight
961 *pValue++ <<= (BOOL) pOther->bIgnoreSpacesRight;
962 // View/ToolboxVisible
963 *pValue++ <<= (BOOL) pOther->bToolboxVisible;
964 // View/AutoRedraw
965 *pValue++ <<= (BOOL) pOther->bAutoRedraw;
966 // View/FormulaCursor
967 *pValue++ <<= (BOOL) pOther->bFormulaCursor;
969 DBG_ASSERT( pValue - pValues == nProps, "property mismatch" );
970 PutProperties( aNames , aValues );
972 SetOtherModified( FALSE );
975 void SmMathConfig::LoadFormat()
977 if (!pFormat)
978 pFormat = new SmFormat;
981 Sequence< OUString > aNames( GetFormatPropertyNames() );
982 INT32 nProps = aNames.getLength();
984 Sequence< Any > aValues( GetProperties( aNames ) );
985 if (nProps && aValues.getLength() == nProps)
987 const Any *pValues = aValues.getConstArray();
988 const Any *pVal = pValues;
990 OUString aTmpStr;
991 INT16 nTmp16 = 0;
992 BOOL bTmp = FALSE;
994 // StandardFormat/Textmode
995 if (pVal->hasValue() && (*pVal >>= bTmp))
996 pFormat->SetTextmode( bTmp );
997 ++pVal;
998 // StandardFormat/ScaleNormalBracket
999 if (pVal->hasValue() && (*pVal >>= bTmp))
1000 pFormat->SetScaleNormalBrackets( bTmp );
1001 ++pVal;
1002 // StandardFormat/HorizontalAlignment
1003 if (pVal->hasValue() && (*pVal >>= nTmp16))
1004 pFormat->SetHorAlign( (SmHorAlign) nTmp16 );
1005 ++pVal;
1006 // StandardFormat/BaseSize
1007 if (pVal->hasValue() && (*pVal >>= nTmp16))
1008 pFormat->SetBaseSize( Size(0, SmPtsTo100th_mm( nTmp16 )) );
1009 ++pVal;
1011 USHORT i;
1012 for (i = SIZ_BEGIN; i <= SIZ_END; ++i)
1014 if (pVal->hasValue() && (*pVal >>= nTmp16))
1015 pFormat->SetRelSize( i, nTmp16 );
1016 ++pVal;
1019 for (i = DIS_BEGIN; i <= DIS_END; ++i)
1021 if (pVal->hasValue() && (*pVal >>= nTmp16))
1022 pFormat->SetDistance( i, nTmp16 );
1023 ++pVal;
1026 LanguageType nLang = Application::GetSettings().GetUILanguage();
1027 for (i = FNT_BEGIN; i < FNT_END; ++i)
1029 Font aFnt;
1030 BOOL bUseDefaultFont = TRUE;
1031 if (pVal->hasValue() && (*pVal >>= aTmpStr))
1033 bUseDefaultFont = 0 == aTmpStr.getLength();
1034 if (bUseDefaultFont)
1036 aFnt = pFormat->GetFont( i );
1037 aFnt.SetName( GetDefaultFontName( nLang, i ) );
1039 else
1041 const SmFontFormat *pFntFmt = GetFontFormatList().GetFontFormat( aTmpStr );
1042 DBG_ASSERT( pFntFmt, "unknown FontFormat" );
1043 if (pFntFmt)
1044 aFnt = pFntFmt->GetFont();
1047 ++pVal;
1049 aFnt.SetSize( pFormat->GetBaseSize() );
1050 pFormat->SetFont( i, aFnt, bUseDefaultFont );
1053 DBG_ASSERT( pVal - pValues == nProps, "property mismatch" );
1054 SetFormatModified( FALSE );
1059 void SmMathConfig::SaveFormat()
1061 if (!pFormat || !IsFormatModified())
1062 return;
1064 const Sequence< OUString > aNames( GetFormatPropertyNames() );
1065 INT32 nProps = aNames.getLength();
1067 Sequence< Any > aValues( nProps );
1068 Any *pValues = aValues.getArray();
1069 Any *pValue = pValues;
1071 // StandardFormat/Textmode
1072 *pValue++ <<= (BOOL) pFormat->IsTextmode();
1073 // StandardFormat/ScaleNormalBracket
1074 *pValue++ <<= (BOOL) pFormat->IsScaleNormalBrackets();
1075 // StandardFormat/HorizontalAlignment
1076 *pValue++ <<= (INT16) pFormat->GetHorAlign();
1077 // StandardFormat/BaseSize
1078 *pValue++ <<= (INT16) SmRoundFraction( Sm100th_mmToPts(
1079 pFormat->GetBaseSize().Height() ) );
1081 USHORT i;
1082 for (i = SIZ_BEGIN; i <= SIZ_END; ++i)
1083 *pValue++ <<= (INT16) pFormat->GetRelSize( i );
1085 for (i = DIS_BEGIN; i <= DIS_END; ++i)
1086 *pValue++ <<= (INT16) pFormat->GetDistance( i );
1088 for (i = FNT_BEGIN; i < FNT_END; ++i)
1090 OUString aFntFmtId;
1092 if (!pFormat->IsDefaultFont( i ))
1094 SmFontFormat aFntFmt( pFormat->GetFont( i ) );
1095 aFntFmtId = GetFontFormatList().GetFontFormatId( aFntFmt, TRUE );
1096 DBG_ASSERT( aFntFmtId.getLength(), "FontFormatId not found" );
1099 *pValue++ <<= aFntFmtId;
1102 DBG_ASSERT( pValue - pValues == nProps, "property mismatch" );
1103 PutProperties( aNames , aValues );
1105 SetFormatModified( FALSE );
1109 const SmFormat & SmMathConfig::GetStandardFormat() const
1111 if (!pFormat)
1112 ((SmMathConfig *) this)->LoadFormat();
1113 return *pFormat;
1117 void SmMathConfig::SetStandardFormat( const SmFormat &rFormat, BOOL bSaveFontFormatList )
1119 if (!pFormat)
1120 LoadFormat();
1121 if (rFormat != *pFormat)
1123 *pFormat = rFormat;
1124 SetFormatModified( TRUE );
1125 SaveFormat();
1127 if (bSaveFontFormatList)
1129 // needed for SmFontTypeDialog's DefaultButtonClickHdl
1130 SetFontFormatListModified( TRUE );
1131 SaveFontFormatList();
1137 SmPrintSize SmMathConfig::GetPrintSize() const
1139 if (!pOther)
1140 ((SmMathConfig *) this)->LoadOther();
1141 return pOther->ePrintSize;
1145 void SmMathConfig::SetPrintSize( SmPrintSize eSize )
1147 if (!pOther)
1148 LoadOther();
1149 if (eSize != pOther->ePrintSize)
1151 pOther->ePrintSize = eSize;
1152 SetOtherModified( TRUE );
1157 USHORT SmMathConfig::GetPrintZoomFactor() const
1159 if (!pOther)
1160 ((SmMathConfig *) this)->LoadOther();
1161 return pOther->nPrintZoomFactor;
1165 void SmMathConfig::SetPrintZoomFactor( USHORT nVal )
1167 if (!pOther)
1168 LoadOther();
1169 if (nVal != pOther->nPrintZoomFactor)
1171 pOther->nPrintZoomFactor = nVal;
1172 SetOtherModified( TRUE );
1177 void SmMathConfig::SetOtherIfNotEqual( BOOL &rbItem, BOOL bNewVal )
1179 if (bNewVal != rbItem)
1181 rbItem = bNewVal;
1182 SetOtherModified( TRUE );
1187 BOOL SmMathConfig::IsPrintTitle() const
1189 if (!pOther)
1190 ((SmMathConfig *) this)->LoadOther();
1191 return pOther->bPrintTitle;
1195 void SmMathConfig::SetPrintTitle( BOOL bVal )
1197 if (!pOther)
1198 LoadOther();
1199 SetOtherIfNotEqual( pOther->bPrintTitle, bVal );
1203 BOOL SmMathConfig::IsPrintFormulaText() const
1205 if (!pOther)
1206 ((SmMathConfig *) this)->LoadOther();
1207 return pOther->bPrintFormulaText;
1211 void SmMathConfig::SetPrintFormulaText( BOOL bVal )
1213 if (!pOther)
1214 LoadOther();
1215 SetOtherIfNotEqual( pOther->bPrintFormulaText, bVal );
1219 BOOL SmMathConfig::IsPrintFrame() const
1221 if (!pOther)
1222 ((SmMathConfig *) this)->LoadOther();
1223 return pOther->bPrintFrame;
1227 void SmMathConfig::SetPrintFrame( BOOL bVal )
1229 if (!pOther)
1230 LoadOther();
1231 SetOtherIfNotEqual( pOther->bPrintFrame, bVal );
1235 BOOL SmMathConfig::IsIgnoreSpacesRight() const
1237 if (!pOther)
1238 ((SmMathConfig *) this)->LoadOther();
1239 return pOther->bIgnoreSpacesRight;
1243 void SmMathConfig::SetIgnoreSpacesRight( BOOL bVal )
1245 if (!pOther)
1246 LoadOther();
1247 SetOtherIfNotEqual( pOther->bIgnoreSpacesRight, bVal );
1251 BOOL SmMathConfig::IsAutoRedraw() const
1253 if (!pOther)
1254 ((SmMathConfig *) this)->LoadOther();
1255 return pOther->bAutoRedraw;
1259 void SmMathConfig::SetAutoRedraw( BOOL bVal )
1261 if (!pOther)
1262 LoadOther();
1263 SetOtherIfNotEqual( pOther->bAutoRedraw, bVal );
1267 BOOL SmMathConfig::IsShowFormulaCursor() const
1269 if (!pOther)
1270 ((SmMathConfig *) this)->LoadOther();
1271 return pOther->bFormulaCursor;
1275 void SmMathConfig::SetShowFormulaCursor( BOOL bVal )
1277 if (!pOther)
1278 LoadOther();
1279 SetOtherIfNotEqual( pOther->bFormulaCursor, bVal );
1283 /////////////////////////////////////////////////////////////////