cURL: follow redirects
[LibreOffice.git] / starmath / source / cfgitem.cxx
blobb849bdd4e0be43ff0a2d5ad3085b18825866c756
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 <vector>
22 #include <svl/itemset.hxx>
23 #include <svl/stritem.hxx>
24 #include <svl/intitem.hxx>
25 #include <svl/itempool.hxx>
26 #include <svl/eitem.hxx>
27 #include <vcl/svapp.hxx>
28 #include <vcl/settings.hxx>
30 #include <sal/macros.h>
31 #include <officecfg/Office/Math.hxx>
32 #include "cfgitem.hxx"
34 #include "starmath.hrc"
35 #include "smdll.hxx"
36 #include "smmod.hxx"
37 #include "format.hxx"
39 using namespace com::sun::star::uno;
40 using namespace com::sun::star::beans;
42 #define SYMBOL_LIST "SymbolList"
43 #define FONT_FORMAT_LIST "FontFormatList"
45 static Sequence< OUString > lcl_GetFontPropertyNames()
47 return Sequence< OUString > {
48 "Name",
49 "CharSet",
50 "Family",
51 "Pitch",
52 "Weight",
53 "Italic"
57 static Sequence< OUString > lcl_GetSymbolPropertyNames()
59 return Sequence< OUString > {
60 "Char",
61 "Set",
62 "Predefined",
63 "FontFormatId"
67 static Sequence< OUString > lcl_GetFormatPropertyNames()
69 //! Beware of order according to *_BEGIN *_END defines in format.hxx !
70 //! see respective load/save routines here
71 return Sequence< OUString > {
72 "StandardFormat/Textmode",
73 "StandardFormat/GreekCharStyle",
74 "StandardFormat/ScaleNormalBracket",
75 "StandardFormat/HorizontalAlignment",
76 "StandardFormat/BaseSize",
77 "StandardFormat/TextSize",
78 "StandardFormat/IndexSize",
79 "StandardFormat/FunctionSize",
80 "StandardFormat/OperatorSize",
81 "StandardFormat/LimitsSize",
82 "StandardFormat/Distance/Horizontal",
83 "StandardFormat/Distance/Vertical",
84 "StandardFormat/Distance/Root",
85 "StandardFormat/Distance/SuperScript",
86 "StandardFormat/Distance/SubScript",
87 "StandardFormat/Distance/Numerator",
88 "StandardFormat/Distance/Denominator",
89 "StandardFormat/Distance/Fraction",
90 "StandardFormat/Distance/StrokeWidth",
91 "StandardFormat/Distance/UpperLimit",
92 "StandardFormat/Distance/LowerLimit",
93 "StandardFormat/Distance/BracketSize",
94 "StandardFormat/Distance/BracketSpace",
95 "StandardFormat/Distance/MatrixRow",
96 "StandardFormat/Distance/MatrixColumn",
97 "StandardFormat/Distance/OrnamentSize",
98 "StandardFormat/Distance/OrnamentSpace",
99 "StandardFormat/Distance/OperatorSize",
100 "StandardFormat/Distance/OperatorSpace",
101 "StandardFormat/Distance/LeftSpace",
102 "StandardFormat/Distance/RightSpace",
103 "StandardFormat/Distance/TopSpace",
104 "StandardFormat/Distance/BottomSpace",
105 "StandardFormat/Distance/NormalBracketSize",
106 "StandardFormat/VariableFont",
107 "StandardFormat/FunctionFont",
108 "StandardFormat/NumberFont",
109 "StandardFormat/TextFont",
110 "StandardFormat/SerifFont",
111 "StandardFormat/SansFont",
112 "StandardFormat/FixedFont"
116 struct SmCfgOther
118 SmPrintSize ePrintSize;
119 sal_uInt16 nPrintZoomFactor;
120 bool bPrintTitle;
121 bool bPrintFormulaText;
122 bool bPrintFrame;
123 bool bIsSaveOnlyUsedSymbols;
124 bool bIsAutoCloseBrackets;
125 bool bIgnoreSpacesRight;
126 bool bToolboxVisible;
127 bool bAutoRedraw;
128 bool bFormulaCursor;
130 SmCfgOther();
134 SmCfgOther::SmCfgOther()
135 : ePrintSize(PRINT_SIZE_NORMAL)
136 , nPrintZoomFactor(100)
137 , bPrintTitle(true)
138 , bPrintFormulaText(true)
139 , bPrintFrame(true)
140 , bIsSaveOnlyUsedSymbols(true)
141 , bIsAutoCloseBrackets(true)
142 , bIgnoreSpacesRight(true)
143 , bToolboxVisible(true)
144 , bAutoRedraw(true)
145 , bFormulaCursor(true)
150 SmFontFormat::SmFontFormat()
151 : aName(FONTNAME_MATH)
152 , nCharSet(RTL_TEXTENCODING_UNICODE)
153 , nFamily(FAMILY_DONTKNOW)
154 , nPitch(PITCH_DONTKNOW)
155 , nWeight(WEIGHT_DONTKNOW)
156 , nItalic(ITALIC_NONE)
161 SmFontFormat::SmFontFormat( const vcl::Font &rFont )
162 : aName(rFont.GetFamilyName())
163 , nCharSet(static_cast<sal_Int16>(rFont.GetCharSet()))
164 , nFamily(static_cast<sal_Int16>(rFont.GetFamilyType()))
165 , nPitch(static_cast<sal_Int16>(rFont.GetPitch()))
166 , nWeight(static_cast<sal_Int16>(rFont.GetWeight()))
167 , nItalic(static_cast<sal_Int16>(rFont.GetItalic()))
172 const vcl::Font SmFontFormat::GetFont() const
174 vcl::Font aRes;
175 aRes.SetFamilyName( aName );
176 aRes.SetCharSet( static_cast<rtl_TextEncoding>(nCharSet) );
177 aRes.SetFamily( static_cast<FontFamily>(nFamily) );
178 aRes.SetPitch( static_cast<FontPitch>(nPitch) );
179 aRes.SetWeight( static_cast<FontWeight>(nWeight) );
180 aRes.SetItalic( static_cast<FontItalic>(nItalic) );
181 return aRes;
185 bool SmFontFormat::operator == ( const SmFontFormat &rFntFmt ) const
187 return aName == rFntFmt.aName &&
188 nCharSet == rFntFmt.nCharSet &&
189 nFamily == rFntFmt.nFamily &&
190 nPitch == rFntFmt.nPitch &&
191 nWeight == rFntFmt.nWeight &&
192 nItalic == rFntFmt.nItalic;
196 SmFntFmtListEntry::SmFntFmtListEntry( const OUString &rId, const SmFontFormat &rFntFmt ) :
197 aId (rId),
198 aFntFmt (rFntFmt)
203 SmFontFormatList::SmFontFormatList()
204 : bModified(false)
209 void SmFontFormatList::Clear()
211 if (!aEntries.empty())
213 aEntries.clear();
214 SetModified( true );
219 void SmFontFormatList::AddFontFormat( const OUString &rFntFmtId,
220 const SmFontFormat &rFntFmt )
222 const SmFontFormat *pFntFmt = GetFontFormat( rFntFmtId );
223 OSL_ENSURE( !pFntFmt, "FontFormatId already exists" );
224 if (!pFntFmt)
226 SmFntFmtListEntry aEntry( rFntFmtId, rFntFmt );
227 aEntries.push_back( aEntry );
228 SetModified( true );
233 void SmFontFormatList::RemoveFontFormat( const OUString &rFntFmtId )
236 // search for entry
237 for (size_t i = 0; i < aEntries.size(); ++i)
239 if (aEntries[i].aId == rFntFmtId)
241 // remove entry if found
242 aEntries.erase( aEntries.begin() + i );
243 SetModified( true );
244 break;
250 const SmFontFormat * SmFontFormatList::GetFontFormat( const OUString &rFntFmtId ) const
252 const SmFontFormat *pRes = nullptr;
254 for (const auto & rEntry : aEntries)
256 if (rEntry.aId == rFntFmtId)
258 pRes = &rEntry.aFntFmt;
259 break;
263 return pRes;
267 const SmFontFormat * SmFontFormatList::GetFontFormat( size_t nPos ) const
269 const SmFontFormat *pRes = nullptr;
270 if (nPos < aEntries.size())
271 pRes = &aEntries[nPos].aFntFmt;
272 return pRes;
276 const OUString SmFontFormatList::GetFontFormatId( const SmFontFormat &rFntFmt ) const
278 OUString aRes;
280 for (const auto & rEntry : aEntries)
282 if (rEntry.aFntFmt == rFntFmt)
284 aRes = rEntry.aId;
285 break;
289 return aRes;
293 const OUString SmFontFormatList::GetFontFormatId( const SmFontFormat &rFntFmt, bool bAdd )
295 OUString aRes( GetFontFormatId( rFntFmt) );
296 if (aRes.isEmpty() && bAdd)
298 aRes = GetNewFontFormatId();
299 AddFontFormat( aRes, rFntFmt );
301 return aRes;
305 const OUString SmFontFormatList::GetFontFormatId( size_t nPos ) const
307 OUString aRes;
308 if (nPos < aEntries.size())
309 aRes = aEntries[nPos].aId;
310 return aRes;
314 const OUString SmFontFormatList::GetNewFontFormatId() const
316 // returns first unused FormatId
318 OUString aPrefix("Id");
319 sal_Int32 nCnt = GetCount();
320 for (sal_Int32 i = 1; i <= nCnt + 1; ++i)
322 OUString aTmpId = aPrefix + OUString::number(i);
323 if (!GetFontFormat(aTmpId))
324 return aTmpId;
326 OSL_ENSURE( false, "failed to create new FontFormatId" );
328 return OUString();
332 SmMathConfig::SmMathConfig() :
333 ConfigItem(OUString("Office.Math"))
334 , pFormat()
335 , pOther()
336 , pFontFormatList()
337 , pSymbolMgr()
338 , bIsOtherModified(false)
339 , bIsFormatModified(false)
344 SmMathConfig::~SmMathConfig()
346 Save();
350 void SmMathConfig::SetOtherModified( bool bVal )
352 bIsOtherModified = bVal;
356 void SmMathConfig::SetFormatModified( bool bVal )
358 bIsFormatModified = bVal;
362 void SmMathConfig::ReadSymbol( SmSym &rSymbol,
363 const OUString &rSymbolName,
364 const OUString &rBaseNode ) const
366 Sequence< OUString > aNames = lcl_GetSymbolPropertyNames();
367 sal_Int32 nProps = aNames.getLength();
369 OUString aDelim( "/" );
370 OUString *pName = aNames.getArray();
371 for (sal_Int32 i = 0; i < nProps; ++i)
373 OUString &rName = pName[i];
374 OUString aTmp( rName );
375 rName = rBaseNode;
376 rName += aDelim;
377 rName += rSymbolName;
378 rName += aDelim;
379 rName += aTmp;
382 const Sequence< Any > aValues = const_cast<SmMathConfig*>(this)->GetProperties(aNames);
384 if (nProps && aValues.getLength() == nProps)
386 const Any * pValue = aValues.getConstArray();
387 vcl::Font aFont;
388 sal_UCS4 cChar = '\0';
389 OUString aSet;
390 bool bPredefined = false;
392 OUString aTmpStr;
393 sal_Int32 nTmp32 = 0;
394 bool bTmp = false;
396 bool bOK = true;
397 if (pValue->hasValue() && (*pValue >>= nTmp32))
398 cChar = static_cast< sal_UCS4 >( nTmp32 );
399 else
400 bOK = false;
401 ++pValue;
402 if (pValue->hasValue() && (*pValue >>= aTmpStr))
403 aSet = aTmpStr;
404 else
405 bOK = false;
406 ++pValue;
407 if (pValue->hasValue() && (*pValue >>= bTmp))
408 bPredefined = bTmp;
409 else
410 bOK = false;
411 ++pValue;
412 if (pValue->hasValue() && (*pValue >>= aTmpStr))
414 const SmFontFormat *pFntFmt = GetFontFormatList().GetFontFormat( aTmpStr );
415 OSL_ENSURE( pFntFmt, "unknown FontFormat" );
416 if (pFntFmt)
417 aFont = pFntFmt->GetFont();
419 else
420 bOK = false;
421 ++pValue;
423 if (bOK)
425 OUString aUiName( rSymbolName );
426 OUString aUiSetName( aSet );
427 if (bPredefined)
429 OUString aTmp;
430 aTmp = SmLocalizedSymbolData::GetUiSymbolName( rSymbolName );
431 OSL_ENSURE( !aTmp.isEmpty(), "localized symbol-name not found" );
432 if (!aTmp.isEmpty())
433 aUiName = aTmp;
434 aTmp = SmLocalizedSymbolData::GetUiSymbolSetName( aSet );
435 OSL_ENSURE( !aTmp.isEmpty(), "localized symbolset-name not found" );
436 if (!aTmp.isEmpty())
437 aUiSetName = aTmp;
440 rSymbol = SmSym( aUiName, aFont, cChar, aUiSetName, bPredefined );
441 if (aUiName != rSymbolName)
442 rSymbol.SetExportName( rSymbolName );
444 else
446 SAL_WARN("starmath", "symbol read error");
452 SmSymbolManager & SmMathConfig::GetSymbolManager()
454 if (!pSymbolMgr)
456 pSymbolMgr.reset(new SmSymbolManager);
457 pSymbolMgr->Load();
459 return *pSymbolMgr;
463 void SmMathConfig::ImplCommit()
465 Save();
469 void SmMathConfig::Save()
471 SaveOther();
472 SaveFormat();
473 SaveFontFormatList();
477 void SmMathConfig::GetSymbols( std::vector< SmSym > &rSymbols ) const
479 Sequence< OUString > aNodes(const_cast<SmMathConfig*>(this)->GetNodeNames(SYMBOL_LIST));
480 const OUString *pNode = aNodes.getConstArray();
481 sal_Int32 nNodes = aNodes.getLength();
483 rSymbols.resize( nNodes );
484 std::vector< SmSym >::iterator aIt( rSymbols.begin() );
485 std::vector< SmSym >::iterator aEnd( rSymbols.end() );
486 while (aIt != aEnd)
488 ReadSymbol( *aIt++, *pNode++, SYMBOL_LIST );
493 void SmMathConfig::SetSymbols( const std::vector< SmSym > &rNewSymbols )
495 sal_uIntPtr nCount = rNewSymbols.size();
497 Sequence< OUString > aNames = lcl_GetSymbolPropertyNames();
498 const OUString *pNames = aNames.getConstArray();
499 sal_uIntPtr nSymbolProps = sal::static_int_cast< sal_uInt32 >(aNames.getLength());
501 Sequence< PropertyValue > aValues( nCount * nSymbolProps );
502 PropertyValue *pValues = aValues.getArray();
504 PropertyValue *pVal = pValues;
505 OUString aDelim( "/" );
506 std::vector< SmSym >::const_iterator aIt( rNewSymbols.begin() );
507 std::vector< SmSym >::const_iterator aEnd( rNewSymbols.end() );
508 while (aIt != aEnd)
510 const SmSym &rSymbol = *aIt++;
511 OUString aNodeNameDelim( SYMBOL_LIST );
512 aNodeNameDelim += aDelim;
513 aNodeNameDelim += rSymbol.GetExportName();
514 aNodeNameDelim += aDelim;
516 const OUString *pName = pNames;
518 // Char
519 pVal->Name = aNodeNameDelim;
520 pVal->Name += *pName++;
521 pVal->Value <<= static_cast< sal_UCS4 >( rSymbol.GetCharacter() );
522 pVal++;
523 // Set
524 pVal->Name = aNodeNameDelim;
525 pVal->Name += *pName++;
526 OUString aTmp( rSymbol.GetSymbolSetName() );
527 if (rSymbol.IsPredefined())
528 aTmp = SmLocalizedSymbolData::GetExportSymbolSetName( aTmp );
529 pVal->Value <<= aTmp;
530 pVal++;
531 // Predefined
532 pVal->Name = aNodeNameDelim;
533 pVal->Name += *pName++;
534 pVal->Value <<= rSymbol.IsPredefined();
535 pVal++;
536 // FontFormatId
537 SmFontFormat aFntFmt( rSymbol.GetFace() );
538 OUString aFntFmtId( GetFontFormatList().GetFontFormatId( aFntFmt, true ) );
539 OSL_ENSURE( !aFntFmtId.isEmpty(), "FontFormatId not found" );
540 pVal->Name = aNodeNameDelim;
541 pVal->Name += *pName++;
542 pVal->Value <<= aFntFmtId;
543 pVal++;
545 OSL_ENSURE( pVal - pValues == sal::static_int_cast< ptrdiff_t >(nCount * nSymbolProps), "properties missing" );
546 ReplaceSetProperties( SYMBOL_LIST, aValues );
548 StripFontFormatList( rNewSymbols );
549 SaveFontFormatList();
553 SmFontFormatList & SmMathConfig::GetFontFormatList()
555 if (!pFontFormatList)
557 LoadFontFormatList();
559 return *pFontFormatList;
563 void SmMathConfig::LoadFontFormatList()
565 if (!pFontFormatList)
566 pFontFormatList.reset(new SmFontFormatList);
567 else
568 pFontFormatList->Clear();
570 Sequence< OUString > aNodes( GetNodeNames( FONT_FORMAT_LIST ) );
571 const OUString *pNode = aNodes.getConstArray();
572 sal_Int32 nNodes = aNodes.getLength();
574 for (sal_Int32 i = 0; i < nNodes; ++i)
576 SmFontFormat aFntFmt;
577 ReadFontFormat( aFntFmt, pNode[i], FONT_FORMAT_LIST );
578 if (!pFontFormatList->GetFontFormat( pNode[i] ))
580 OSL_ENSURE( nullptr == pFontFormatList->GetFontFormat( pNode[i] ),
581 "FontFormat ID already exists" );
582 pFontFormatList->AddFontFormat( pNode[i], aFntFmt );
585 pFontFormatList->SetModified( false );
589 void SmMathConfig::ReadFontFormat( SmFontFormat &rFontFormat,
590 const OUString &rSymbolName, const OUString &rBaseNode ) const
592 Sequence< OUString > aNames = lcl_GetFontPropertyNames();
593 sal_Int32 nProps = aNames.getLength();
595 OUString aDelim( "/" );
596 OUString *pName = aNames.getArray();
597 for (sal_Int32 i = 0; i < nProps; ++i)
599 OUString &rName = pName[i];
600 OUString aTmp( rName );
601 rName = rBaseNode;
602 rName += aDelim;
603 rName += rSymbolName;
604 rName += aDelim;
605 rName += aTmp;
608 const Sequence< Any > aValues = const_cast<SmMathConfig*>(this)->GetProperties(aNames);
610 if (nProps && aValues.getLength() == nProps)
612 const Any * pValue = aValues.getConstArray();
614 OUString aTmpStr;
615 sal_Int16 nTmp16 = 0;
617 bool bOK = true;
618 if (pValue->hasValue() && (*pValue >>= aTmpStr))
619 rFontFormat.aName = aTmpStr;
620 else
621 bOK = false;
622 ++pValue;
623 if (pValue->hasValue() && (*pValue >>= nTmp16))
624 rFontFormat.nCharSet = nTmp16; // 6.0 file-format GetSOLoadTextEncoding not needed
625 else
626 bOK = false;
627 ++pValue;
628 if (pValue->hasValue() && (*pValue >>= nTmp16))
629 rFontFormat.nFamily = nTmp16;
630 else
631 bOK = false;
632 ++pValue;
633 if (pValue->hasValue() && (*pValue >>= nTmp16))
634 rFontFormat.nPitch = nTmp16;
635 else
636 bOK = false;
637 ++pValue;
638 if (pValue->hasValue() && (*pValue >>= nTmp16))
639 rFontFormat.nWeight = nTmp16;
640 else
641 bOK = false;
642 ++pValue;
643 if (pValue->hasValue() && (*pValue >>= nTmp16))
644 rFontFormat.nItalic = nTmp16;
645 else
646 bOK = false;
647 ++pValue;
649 OSL_ENSURE( bOK, "read FontFormat failed" );
650 (void)bOK;
655 void SmMathConfig::SaveFontFormatList()
657 SmFontFormatList &rFntFmtList = GetFontFormatList();
659 if (!rFntFmtList.IsModified())
660 return;
662 Sequence< OUString > aNames = lcl_GetFontPropertyNames();
663 sal_Int32 nSymbolProps = aNames.getLength();
665 size_t nCount = rFntFmtList.GetCount();
667 Sequence< PropertyValue > aValues( nCount * nSymbolProps );
668 PropertyValue *pValues = aValues.getArray();
670 PropertyValue *pVal = pValues;
671 OUString aDelim( "/" );
672 for (size_t i = 0; i < nCount; ++i)
674 OUString aFntFmtId(rFntFmtList.GetFontFormatId(i));
675 const SmFontFormat *pFntFmt = rFntFmtList.GetFontFormat(i);
676 assert(pFntFmt);
677 const SmFontFormat aFntFmt(*pFntFmt);
679 OUString aNodeNameDelim( FONT_FORMAT_LIST );
680 aNodeNameDelim += aDelim;
681 aNodeNameDelim += aFntFmtId;
682 aNodeNameDelim += aDelim;
684 const OUString *pName = aNames.getConstArray();
686 // Name
687 pVal->Name = aNodeNameDelim;
688 pVal->Name += *pName++;
689 pVal->Value <<= OUString( aFntFmt.aName );
690 pVal++;
691 // CharSet
692 pVal->Name = aNodeNameDelim;
693 pVal->Name += *pName++;
694 pVal->Value <<= static_cast<sal_Int16>(aFntFmt.nCharSet); // 6.0 file-format GetSOStoreTextEncoding not needed
695 pVal++;
696 // Family
697 pVal->Name = aNodeNameDelim;
698 pVal->Name += *pName++;
699 pVal->Value <<= static_cast<sal_Int16>(aFntFmt.nFamily);
700 pVal++;
701 // Pitch
702 pVal->Name = aNodeNameDelim;
703 pVal->Name += *pName++;
704 pVal->Value <<= static_cast<sal_Int16>(aFntFmt.nPitch);
705 pVal++;
706 // Weight
707 pVal->Name = aNodeNameDelim;
708 pVal->Name += *pName++;
709 pVal->Value <<= static_cast<sal_Int16>(aFntFmt.nWeight);
710 pVal++;
711 // Italic
712 pVal->Name = aNodeNameDelim;
713 pVal->Name += *pName++;
714 pVal->Value <<= static_cast<sal_Int16>(aFntFmt.nItalic);
715 pVal++;
717 OSL_ENSURE( sal::static_int_cast<size_t>(pVal - pValues) == nCount * nSymbolProps, "properties missing" );
718 ReplaceSetProperties( FONT_FORMAT_LIST, aValues );
720 rFntFmtList.SetModified( false );
724 void SmMathConfig::StripFontFormatList( const std::vector< SmSym > &rSymbols )
726 size_t i;
728 // build list of used font-formats only
729 //!! font-format IDs may be different !!
730 SmFontFormatList aUsedList;
731 for (i = 0; i < rSymbols.size(); ++i)
733 OSL_ENSURE( rSymbols[i].GetName().getLength() > 0, "non named symbol" );
734 aUsedList.GetFontFormatId( SmFontFormat( rSymbols[i].GetFace() ) , true );
736 const SmFormat & rStdFmt = GetStandardFormat();
737 for (i = FNT_BEGIN; i <= FNT_END; ++i)
739 aUsedList.GetFontFormatId( SmFontFormat( rStdFmt.GetFont( i ) ) , true );
742 // remove unused font-formats from list
743 SmFontFormatList &rFntFmtList = GetFontFormatList();
744 size_t nCnt = rFntFmtList.GetCount();
745 std::unique_ptr<SmFontFormat[]> pTmpFormat(new SmFontFormat[ nCnt ]);
746 std::unique_ptr<OUString[]> pId(new OUString[ nCnt ]);
747 size_t k;
748 for (k = 0; k < nCnt; ++k)
750 pTmpFormat[k] = *rFntFmtList.GetFontFormat( k );
751 pId[k] = rFntFmtList.GetFontFormatId( k );
753 for (k = 0; k < nCnt; ++k)
755 if (aUsedList.GetFontFormatId( pTmpFormat[k] ).isEmpty())
757 rFntFmtList.RemoveFontFormat( pId[k] );
763 void SmMathConfig::LoadOther()
765 if (!pOther)
766 pOther.reset(new SmCfgOther);
768 pOther->bPrintTitle = officecfg::Office::Math::Print::Title::get();
769 pOther->bPrintFormulaText = officecfg::Office::Math::Print::FormulaText::get();
770 pOther->bPrintFrame = officecfg::Office::Math::Print::Frame::get();
771 pOther->ePrintSize = static_cast<SmPrintSize>(officecfg::Office::Math::Print::Size::get());
772 pOther->nPrintZoomFactor = officecfg::Office::Math::Print::ZoomFactor::get();
773 pOther->bIsSaveOnlyUsedSymbols = officecfg::Office::Math::LoadSave::IsSaveOnlyUsedSymbols::get();
774 pOther->bIsAutoCloseBrackets = officecfg::Office::Math::Misc::AutoCloseBrackets::get();
775 pOther->bIgnoreSpacesRight = officecfg::Office::Math::Misc::IgnoreSpacesRight::get();
776 pOther->bToolboxVisible = officecfg::Office::Math::View::ToolboxVisible::get();
777 pOther->bAutoRedraw = officecfg::Office::Math::View::AutoRedraw::get();
778 pOther->bFormulaCursor = officecfg::Office::Math::View::FormulaCursor::get();
779 SetOtherModified( false );
783 void SmMathConfig::SaveOther()
785 if (!pOther || !IsOtherModified())
786 return;
788 std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create());
790 officecfg::Office::Math::Print::Title::set(pOther->bPrintTitle, batch);
791 officecfg::Office::Math::Print::FormulaText::set(pOther->bPrintFormulaText, batch);
792 officecfg::Office::Math::Print::Frame::set(pOther->bPrintFrame, batch);
793 officecfg::Office::Math::Print::Size::set(pOther->ePrintSize, batch);
794 officecfg::Office::Math::Print::ZoomFactor::set(pOther->nPrintZoomFactor, batch);
795 officecfg::Office::Math::LoadSave::IsSaveOnlyUsedSymbols::set(pOther->bIsSaveOnlyUsedSymbols, batch);
796 officecfg::Office::Math::Misc::AutoCloseBrackets::set(pOther->bIsAutoCloseBrackets, batch);
797 officecfg::Office::Math::Misc::IgnoreSpacesRight::set(pOther->bIgnoreSpacesRight, batch);
798 officecfg::Office::Math::View::ToolboxVisible::set(pOther->bToolboxVisible, batch);
799 officecfg::Office::Math::View::AutoRedraw::set(pOther->bAutoRedraw, batch);
800 officecfg::Office::Math::View::FormulaCursor::set(pOther->bFormulaCursor, batch);
802 batch->commit();
803 SetOtherModified( false );
806 void SmMathConfig::LoadFormat()
808 if (!pFormat)
809 pFormat.reset(new SmFormat);
812 Sequence< OUString > aNames = lcl_GetFormatPropertyNames();
814 sal_Int32 nProps = aNames.getLength();
816 Sequence< Any > aValues( GetProperties( aNames ) );
817 if (nProps && aValues.getLength() == nProps)
819 const Any *pValues = aValues.getConstArray();
820 const Any *pVal = pValues;
822 OUString aTmpStr;
823 sal_Int16 nTmp16 = 0;
824 bool bTmp = false;
826 // StandardFormat/Textmode
827 if (pVal->hasValue() && (*pVal >>= bTmp))
828 pFormat->SetTextmode( bTmp );
829 ++pVal;
830 // StandardFormat/GreekCharStyle
831 if (pVal->hasValue() && (*pVal >>= nTmp16))
832 pFormat->SetGreekCharStyle( nTmp16 );
833 ++pVal;
834 // StandardFormat/ScaleNormalBracket
835 if (pVal->hasValue() && (*pVal >>= bTmp))
836 pFormat->SetScaleNormalBrackets( bTmp );
837 ++pVal;
838 // StandardFormat/HorizontalAlignment
839 if (pVal->hasValue() && (*pVal >>= nTmp16))
840 pFormat->SetHorAlign( static_cast<SmHorAlign>(nTmp16) );
841 ++pVal;
842 // StandardFormat/BaseSize
843 if (pVal->hasValue() && (*pVal >>= nTmp16))
844 pFormat->SetBaseSize( Size(0, SmPtsTo100th_mm( nTmp16 )) );
845 ++pVal;
847 sal_uInt16 i;
848 for (i = SIZ_BEGIN; i <= SIZ_END; ++i)
850 if (pVal->hasValue() && (*pVal >>= nTmp16))
851 pFormat->SetRelSize( i, nTmp16 );
852 ++pVal;
855 for (i = DIS_BEGIN; i <= DIS_END; ++i)
857 if (pVal->hasValue() && (*pVal >>= nTmp16))
858 pFormat->SetDistance( i, nTmp16 );
859 ++pVal;
862 LanguageType nLang = Application::GetSettings().GetUILanguageTag().getLanguageType();
863 for (i = FNT_BEGIN; i < FNT_END; ++i)
865 vcl::Font aFnt;
866 bool bUseDefaultFont = true;
867 if (pVal->hasValue() && (*pVal >>= aTmpStr))
869 bUseDefaultFont = aTmpStr.isEmpty();
870 if (bUseDefaultFont)
872 aFnt = pFormat->GetFont( i );
873 aFnt.SetFamilyName( GetDefaultFontName( nLang, i ) );
875 else
877 const SmFontFormat *pFntFmt = GetFontFormatList().GetFontFormat( aTmpStr );
878 OSL_ENSURE( pFntFmt, "unknown FontFormat" );
879 if (pFntFmt)
880 aFnt = pFntFmt->GetFont();
883 ++pVal;
885 aFnt.SetFontSize( pFormat->GetBaseSize() );
886 pFormat->SetFont( i, aFnt, bUseDefaultFont );
889 OSL_ENSURE( pVal - pValues == nProps, "property mismatch" );
890 SetFormatModified( false );
895 void SmMathConfig::SaveFormat()
897 if (!pFormat || !IsFormatModified())
898 return;
900 const Sequence< OUString > aNames = lcl_GetFormatPropertyNames();
901 sal_Int32 nProps = aNames.getLength();
903 Sequence< Any > aValues( nProps );
904 Any *pValues = aValues.getArray();
905 Any *pValue = pValues;
907 // StandardFormat/Textmode
908 *pValue++ <<= pFormat->IsTextmode();
909 // StandardFormat/GreekCharStyle
910 *pValue++ <<= static_cast<sal_Int16>(pFormat->GetGreekCharStyle());
911 // StandardFormat/ScaleNormalBracket
912 *pValue++ <<= pFormat->IsScaleNormalBrackets();
913 // StandardFormat/HorizontalAlignment
914 *pValue++ <<= static_cast<sal_Int16>(pFormat->GetHorAlign());
915 // StandardFormat/BaseSize
916 *pValue++ <<= static_cast<sal_Int16>(SmRoundFraction( Sm100th_mmToPts(
917 pFormat->GetBaseSize().Height() ) ));
919 sal_uInt16 i;
920 for (i = SIZ_BEGIN; i <= SIZ_END; ++i)
921 *pValue++ <<= static_cast<sal_Int16>(pFormat->GetRelSize( i ));
923 for (i = DIS_BEGIN; i <= DIS_END; ++i)
924 *pValue++ <<= static_cast<sal_Int16>(pFormat->GetDistance( i ));
926 for (i = FNT_BEGIN; i < FNT_END; ++i)
928 OUString aFntFmtId;
930 if (!pFormat->IsDefaultFont( i ))
932 SmFontFormat aFntFmt( pFormat->GetFont( i ) );
933 aFntFmtId = GetFontFormatList().GetFontFormatId( aFntFmt, true );
934 OSL_ENSURE( !aFntFmtId.isEmpty(), "FontFormatId not found" );
937 *pValue++ <<= aFntFmtId;
940 OSL_ENSURE( pValue - pValues == nProps, "property mismatch" );
941 PutProperties( aNames , aValues );
943 SetFormatModified( false );
947 const SmFormat & SmMathConfig::GetStandardFormat() const
949 if (!pFormat)
950 const_cast<SmMathConfig*>(this)->LoadFormat();
951 return *pFormat;
955 void SmMathConfig::SetStandardFormat( const SmFormat &rFormat, bool bSaveFontFormatList )
957 if (!pFormat)
958 LoadFormat();
959 if (rFormat != *pFormat)
961 *pFormat = rFormat;
962 SetFormatModified( true );
963 SaveFormat();
965 if (bSaveFontFormatList)
967 // needed for SmFontTypeDialog's DefaultButtonClickHdl
968 if (pFontFormatList)
969 pFontFormatList->SetModified( true );
970 SaveFontFormatList();
976 SmPrintSize SmMathConfig::GetPrintSize() const
978 if (!pOther)
979 const_cast<SmMathConfig*>(this)->LoadOther();
980 return pOther->ePrintSize;
984 void SmMathConfig::SetPrintSize( SmPrintSize eSize )
986 if (!pOther)
987 LoadOther();
988 if (eSize != pOther->ePrintSize)
990 pOther->ePrintSize = eSize;
991 SetOtherModified( true );
996 sal_uInt16 SmMathConfig::GetPrintZoomFactor() const
998 if (!pOther)
999 const_cast<SmMathConfig*>(this)->LoadOther();
1000 return pOther->nPrintZoomFactor;
1004 void SmMathConfig::SetPrintZoomFactor( sal_uInt16 nVal )
1006 if (!pOther)
1007 LoadOther();
1008 if (nVal != pOther->nPrintZoomFactor)
1010 pOther->nPrintZoomFactor = nVal;
1011 SetOtherModified( true );
1016 void SmMathConfig::SetOtherIfNotEqual( bool &rbItem, bool bNewVal )
1018 if (bNewVal != rbItem)
1020 rbItem = bNewVal;
1021 SetOtherModified( true );
1026 bool SmMathConfig::IsPrintTitle() const
1028 if (!pOther)
1029 const_cast<SmMathConfig*>(this)->LoadOther();
1030 return pOther->bPrintTitle;
1034 void SmMathConfig::SetPrintTitle( bool bVal )
1036 if (!pOther)
1037 LoadOther();
1038 SetOtherIfNotEqual( pOther->bPrintTitle, bVal );
1042 bool SmMathConfig::IsPrintFormulaText() const
1044 if (!pOther)
1045 const_cast<SmMathConfig*>(this)->LoadOther();
1046 return pOther->bPrintFormulaText;
1050 void SmMathConfig::SetPrintFormulaText( bool bVal )
1052 if (!pOther)
1053 LoadOther();
1054 SetOtherIfNotEqual( pOther->bPrintFormulaText, bVal );
1057 bool SmMathConfig::IsSaveOnlyUsedSymbols() const
1059 if (!pOther)
1060 const_cast<SmMathConfig*>(this)->LoadOther();
1061 return pOther->bIsSaveOnlyUsedSymbols;
1064 bool SmMathConfig::IsAutoCloseBrackets() const
1066 if (!pOther)
1067 const_cast<SmMathConfig*>(this)->LoadOther();
1068 return pOther->bIsAutoCloseBrackets;
1071 bool SmMathConfig::IsPrintFrame() const
1073 if (!pOther)
1074 const_cast<SmMathConfig*>(this)->LoadOther();
1075 return pOther->bPrintFrame;
1079 void SmMathConfig::SetPrintFrame( bool bVal )
1081 if (!pOther)
1082 LoadOther();
1083 SetOtherIfNotEqual( pOther->bPrintFrame, bVal );
1087 void SmMathConfig::SetSaveOnlyUsedSymbols( bool bVal )
1089 if (!pOther)
1090 LoadOther();
1091 SetOtherIfNotEqual( pOther->bIsSaveOnlyUsedSymbols, bVal );
1095 void SmMathConfig::SetAutoCloseBrackets( bool bVal )
1097 if (!pOther)
1098 LoadOther();
1099 SetOtherIfNotEqual( pOther->bIsAutoCloseBrackets, bVal );
1103 bool SmMathConfig::IsIgnoreSpacesRight() const
1105 if (!pOther)
1106 const_cast<SmMathConfig*>(this)->LoadOther();
1107 return pOther->bIgnoreSpacesRight;
1111 void SmMathConfig::SetIgnoreSpacesRight( bool bVal )
1113 if (!pOther)
1114 LoadOther();
1115 SetOtherIfNotEqual( pOther->bIgnoreSpacesRight, bVal );
1119 bool SmMathConfig::IsAutoRedraw() const
1121 if (!pOther)
1122 const_cast<SmMathConfig*>(this)->LoadOther();
1123 return pOther->bAutoRedraw;
1127 void SmMathConfig::SetAutoRedraw( bool bVal )
1129 if (!pOther)
1130 LoadOther();
1131 SetOtherIfNotEqual( pOther->bAutoRedraw, bVal );
1135 bool SmMathConfig::IsShowFormulaCursor() const
1137 if (!pOther)
1138 const_cast<SmMathConfig*>(this)->LoadOther();
1139 return pOther->bFormulaCursor;
1143 void SmMathConfig::SetShowFormulaCursor( bool bVal )
1145 if (!pOther)
1146 LoadOther();
1147 SetOtherIfNotEqual( pOther->bFormulaCursor, bVal );
1150 void SmMathConfig::Notify( const css::uno::Sequence< OUString >& )
1154 void SmMathConfig::ItemSetToConfig(const SfxItemSet &rSet)
1156 const SfxPoolItem *pItem = nullptr;
1158 sal_uInt16 nU16;
1159 bool bVal;
1160 if (rSet.GetItemState(SID_PRINTSIZE, true, &pItem) == SfxItemState::SET)
1161 { nU16 = static_cast<const SfxUInt16Item *>(pItem)->GetValue();
1162 SetPrintSize( static_cast<SmPrintSize>(nU16) );
1164 if (rSet.GetItemState(SID_PRINTZOOM, true, &pItem) == SfxItemState::SET)
1165 { nU16 = static_cast<const SfxUInt16Item *>(pItem)->GetValue();
1166 SetPrintZoomFactor( nU16 );
1168 if (rSet.GetItemState(SID_PRINTTITLE, true, &pItem) == SfxItemState::SET)
1169 { bVal = static_cast<const SfxBoolItem *>(pItem)->GetValue();
1170 SetPrintTitle( bVal );
1172 if (rSet.GetItemState(SID_PRINTTEXT, true, &pItem) == SfxItemState::SET)
1173 { bVal = static_cast<const SfxBoolItem *>(pItem)->GetValue();
1174 SetPrintFormulaText( bVal );
1176 if (rSet.GetItemState(SID_PRINTFRAME, true, &pItem) == SfxItemState::SET)
1177 { bVal = static_cast<const SfxBoolItem *>(pItem)->GetValue();
1178 SetPrintFrame( bVal );
1180 if (rSet.GetItemState(SID_AUTOREDRAW, true, &pItem) == SfxItemState::SET)
1181 { bVal = static_cast<const SfxBoolItem *>(pItem)->GetValue();
1182 SetAutoRedraw( bVal );
1184 if (rSet.GetItemState(SID_NO_RIGHT_SPACES, true, &pItem) == SfxItemState::SET)
1185 { bVal = static_cast<const SfxBoolItem *>(pItem)->GetValue();
1186 if (IsIgnoreSpacesRight() != bVal)
1188 SetIgnoreSpacesRight( bVal );
1190 // reformat (displayed) formulas accordingly
1191 Broadcast(SfxHint(HINT_FORMATCHANGED));
1194 if (rSet.GetItemState(SID_SAVE_ONLY_USED_SYMBOLS, true, &pItem) == SfxItemState::SET)
1195 { bVal = static_cast<const SfxBoolItem *>(pItem)->GetValue();
1196 SetSaveOnlyUsedSymbols( bVal );
1199 if (rSet.GetItemState(SID_AUTO_CLOSE_BRACKETS, true, &pItem) == SfxItemState::SET)
1201 bVal = static_cast<const SfxBoolItem *>(pItem)->GetValue();
1202 SetAutoCloseBrackets( bVal );
1205 SaveOther();
1209 void SmMathConfig::ConfigToItemSet(SfxItemSet &rSet) const
1211 const SfxItemPool *pPool = rSet.GetPool();
1213 rSet.Put(SfxUInt16Item(pPool->GetWhich(SID_PRINTSIZE),
1214 sal::static_int_cast<sal_uInt16>(GetPrintSize())));
1215 rSet.Put(SfxUInt16Item(pPool->GetWhich(SID_PRINTZOOM),
1216 GetPrintZoomFactor()));
1218 rSet.Put(SfxBoolItem(pPool->GetWhich(SID_PRINTTITLE), IsPrintTitle()));
1219 rSet.Put(SfxBoolItem(pPool->GetWhich(SID_PRINTTEXT), IsPrintFormulaText()));
1220 rSet.Put(SfxBoolItem(pPool->GetWhich(SID_PRINTFRAME), IsPrintFrame()));
1221 rSet.Put(SfxBoolItem(pPool->GetWhich(SID_AUTOREDRAW), IsAutoRedraw()));
1222 rSet.Put(SfxBoolItem(pPool->GetWhich(SID_NO_RIGHT_SPACES), IsIgnoreSpacesRight()));
1223 rSet.Put(SfxBoolItem(pPool->GetWhich(SID_SAVE_ONLY_USED_SYMBOLS), IsSaveOnlyUsedSymbols()));
1224 rSet.Put(SfxBoolItem(pPool->GetWhich(SID_AUTO_CLOSE_BRACKETS), IsAutoCloseBrackets()));
1227 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */