/Users/ericb/Desktop/SRC680_m247/starmath/source/cfgitem.cxx

Go to the documentation of this file.
00001 /*************************************************************************
00002  *
00003  *  OpenOffice.org - a multi-platform office productivity suite
00004  *
00005  *  $RCSfile: cfgitem.cxx,v $
00006  *
00007  *  $Revision: 1.18 $
00008  *
00009  *  last change: $Author: kz $ $Date: 2007/06/18 16:33:27 $
00010  *
00011  *  The Contents of this file are made available subject to
00012  *  the terms of GNU Lesser General Public License Version 2.1.
00013  *
00014  *
00015  *    GNU Lesser General Public License Version 2.1
00016  *    =============================================
00017  *    Copyright 2005 by Sun Microsystems, Inc.
00018  *    901 San Antonio Road, Palo Alto, CA 94303, USA
00019  *
00020  *    This library is free software; you can redistribute it and/or
00021  *    modify it under the terms of the GNU Lesser General Public
00022  *    License version 2.1, as published by the Free Software Foundation.
00023  *
00024  *    This library is distributed in the hope that it will be useful,
00025  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00026  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00027  *    Lesser General Public License for more details.
00028  *
00029  *    You should have received a copy of the GNU Lesser General Public
00030  *    License along with this library; if not, write to the Free Software
00031  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00032  *    MA  02111-1307  USA
00033  *
00034  ************************************************************************/
00035 
00036 // MARKER(update_precomp.py): autogen include statement, do not remove
00037 #include "precompiled_starmath.hxx"
00038 
00039 
00040 #ifndef _SV_SVAPP_HXX
00041 #include <vcl/svapp.hxx>
00042 #endif
00043 
00044 #include "cfgitem.hxx"
00045 
00046 #include "starmath.hrc"
00047 #include "smdll.hxx"
00048 #include "format.hxx"
00049 
00050 using namespace rtl;
00051 using namespace com::sun::star;
00052 using namespace com::sun::star::uno;
00053 using namespace com::sun::star::beans;
00054 
00055 #define A2OU(x)        rtl::OUString::createFromAscii( x )
00056 
00057 static const char* aRootName = "Office.Math";
00058 
00059 #define SYMBOL_LIST         "SymbolList"
00060 #define FONT_FORMAT_LIST    "FontFormatList"
00061 
00062 SV_IMPL_OBJARR( SmFntFmtListEntryArr, SmFntFmtListEntry );
00063 
00065 
00066 
00067 static Sequence< OUString > lcl_GetFontPropertyNames()
00068 {
00069         static const char * aPropNames[] =
00070         {
00071         "Name",
00072         "CharSet",
00073         "Family",
00074         "Pitch",
00075         "Weight",
00076         "Italic",
00077                 0
00078         };
00079 
00080         const char** ppPropName = aPropNames;
00081 
00082     Sequence< OUString > aNames( 6 );
00083         OUString *pNames = aNames.getArray();
00084         for( INT32 i = 0; *ppPropName;  ++i, ++ppPropName )
00085         {
00086                 pNames[i] = A2OU( *ppPropName );
00087         }
00088         //aNames.realloc( i );
00089         return aNames;
00090 }
00091 
00093 
00094 
00095 static Sequence< OUString > lcl_GetSymbolPropertyNames()
00096 {
00097         static const char * aPropNames[] =
00098         {
00099         "Char",
00100         "Set",
00101         "Predefined",
00102         "FontFormatId",
00103                 0
00104         };
00105 
00106         const char** ppPropName = aPropNames;
00107 
00108     Sequence< OUString > aNames( 4 );
00109         OUString *pNames = aNames.getArray();
00110         for( INT32 i = 0; *ppPropName;  ++i, ++ppPropName )
00111         {
00112                 pNames[i] = A2OU( *ppPropName );
00113         }
00114         //aNames.realloc( i );
00115         return aNames;
00116 }
00117 
00119 
00120 static const char * aMathPropNames[] =
00121 {
00122     "Print/Title",
00123     "Print/FormulaText",
00124     "Print/Frame",
00125     "Print/Size",
00126     "Print/ZoomFactor",
00127     //"Misc/NoSymbolsWarning",
00128     "Misc/IgnoreSpacesRight",
00129     "View/ToolboxVisible",
00130     "View/AutoRedraw",
00131     "View/FormulaCursor"
00132 };
00133 
00134 
00137 static const char * aFormatPropNames[] =
00138 {
00139     "StandardFormat/Textmode",
00140     "StandardFormat/ScaleNormalBracket",
00141     "StandardFormat/HorizontalAlignment",
00142     "StandardFormat/BaseSize",
00143     "StandardFormat/TextSize",
00144     "StandardFormat/IndexSize",
00145     "StandardFormat/FunctionSize",
00146     "StandardFormat/OperatorSize",
00147     "StandardFormat/LimitsSize",
00148     "StandardFormat/Distance/Horizontal",
00149     "StandardFormat/Distance/Vertical",
00150     "StandardFormat/Distance/Root",
00151     "StandardFormat/Distance/SuperScript",
00152     "StandardFormat/Distance/SubScript",
00153     "StandardFormat/Distance/Numerator",
00154     "StandardFormat/Distance/Denominator",
00155     "StandardFormat/Distance/Fraction",
00156     "StandardFormat/Distance/StrokeWidth",
00157     "StandardFormat/Distance/UpperLimit",
00158     "StandardFormat/Distance/LowerLimit",
00159     "StandardFormat/Distance/BracketSize",
00160     "StandardFormat/Distance/BracketSpace",
00161     "StandardFormat/Distance/MatrixRow",
00162     "StandardFormat/Distance/MatrixColumn",
00163     "StandardFormat/Distance/OrnamentSize",
00164     "StandardFormat/Distance/OrnamentSpace",
00165     "StandardFormat/Distance/OperatorSize",
00166     "StandardFormat/Distance/OperatorSpace",
00167     "StandardFormat/Distance/LeftSpace",
00168     "StandardFormat/Distance/RightSpace",
00169     "StandardFormat/Distance/TopSpace",
00170     "StandardFormat/Distance/BottomSpace",
00171     "StandardFormat/Distance/NormalBracketSize",
00172     "StandardFormat/VariableFont",
00173     "StandardFormat/FunctionFont",
00174     "StandardFormat/NumberFont",
00175     "StandardFormat/TextFont",
00176     "StandardFormat/SerifFont",
00177     "StandardFormat/SansFont",
00178     "StandardFormat/FixedFont"
00179 };
00180 
00181 
00182 static Sequence< OUString > lcl_GetPropertyNames( 
00183         const char * aPropNames[], USHORT nCount )
00184 {
00185 
00186         const char** ppPropName = aPropNames;
00187 
00188     Sequence< OUString > aNames( nCount );
00189         OUString *pNames = aNames.getArray();
00190     for (INT32 i = 0;  i < nCount;  ++i, ++ppPropName)
00191         {
00192                 pNames[i] = A2OU( *ppPropName );
00193         }
00194         //aNames.realloc( i );
00195         return aNames;
00196 }
00197 
00198     
00199 static Sequence< OUString > GetFormatPropertyNames()
00200 {
00201     USHORT nCnt = sizeof(aFormatPropNames) / sizeof(aFormatPropNames[0]);
00202     return lcl_GetPropertyNames( aFormatPropNames, nCnt );
00203 }
00204 
00205 
00206 static Sequence< OUString > GetOtherPropertyNames()
00207 {
00208     USHORT nCnt = sizeof(aMathPropNames) / sizeof(aMathPropNames[0]);
00209     return lcl_GetPropertyNames( aMathPropNames, nCnt );
00210 }
00211 
00213 
00214 struct SmCfgOther
00215 {
00216     SmPrintSize     ePrintSize;
00217     USHORT          nPrintZoomFactor;
00218     BOOL            bPrintTitle;
00219     BOOL            bPrintFormulaText;
00220     BOOL            bPrintFrame;
00221     BOOL            bIgnoreSpacesRight;
00222     BOOL            bToolboxVisible;
00223     BOOL            bAutoRedraw;
00224     BOOL            bFormulaCursor;
00225     //BOOL            bNoSymbolsWarning;
00226 
00227     SmCfgOther();
00228 };
00229 
00230 
00231 SmCfgOther::SmCfgOther()
00232 {
00233     ePrintSize          = PRINT_SIZE_NORMAL;
00234     nPrintZoomFactor    = 100;
00235     bPrintTitle         = bPrintFormulaText   =
00236     bPrintFrame         = bIgnoreSpacesRight  =
00237     bToolboxVisible     = bAutoRedraw         =
00238     bFormulaCursor      = /*bNoSymbolsWarning   =*/ TRUE;
00239 }
00240 
00242 
00243 
00244 SmFontFormat::SmFontFormat()
00245 {
00246     aName.AssignAscii( FONTNAME_MATH );
00247     nCharSet    = RTL_TEXTENCODING_UNICODE;
00248     nFamily     = FAMILY_DONTKNOW;
00249     nPitch      = PITCH_DONTKNOW;
00250     nWeight     = WEIGHT_DONTKNOW;
00251     nItalic     = ITALIC_NONE;
00252 }
00253     
00254 
00255 SmFontFormat::SmFontFormat( const Font &rFont )
00256 {
00257     aName       = rFont.GetName();
00258     nCharSet    = (INT16) rFont.GetCharSet();
00259     nFamily     = (INT16) rFont.GetFamily();
00260     nPitch      = (INT16) rFont.GetPitch();
00261     nWeight     = (INT16) rFont.GetWeight();
00262     nItalic     = (INT16) rFont.GetItalic();
00263 }
00264 
00265 
00266 const Font SmFontFormat::GetFont() const
00267 {
00268     Font aRes;
00269     aRes.SetName( aName );
00270     aRes.SetCharSet( (rtl_TextEncoding) nCharSet );
00271     aRes.SetFamily( (FontFamily) nFamily );
00272     aRes.SetPitch( (FontPitch) nPitch );
00273     aRes.SetWeight( (FontWeight) nWeight );
00274     aRes.SetItalic( (FontItalic) nItalic );
00275     return aRes;
00276 }
00277 
00278     
00279 BOOL SmFontFormat::operator == ( const SmFontFormat &rFntFmt ) const
00280 {
00281     return  aName    == rFntFmt.aName       &&
00282             nCharSet == rFntFmt.nCharSet    &&
00283             nFamily  == rFntFmt.nFamily     &&
00284             nPitch   == rFntFmt.nPitch      &&
00285             nWeight  == rFntFmt.nWeight     &&
00286             nItalic  == rFntFmt.nItalic;
00287 }
00288 
00289 
00291 
00292 SmFntFmtListEntry::SmFntFmtListEntry( const String &rId, const SmFontFormat &rFntFmt ) :
00293     aId     (rId),
00294     aFntFmt (rFntFmt)
00295 {
00296 }
00297 
00298 
00299 SmFontFormatList::SmFontFormatList()
00300 {
00301     bModified = FALSE;
00302 }
00303 
00304 
00305 void SmFontFormatList::Clear()
00306 {
00307     USHORT nCnt = aEntries.Count();
00308     if (nCnt)
00309     {
00310         aEntries.Remove( 0, nCnt );
00311         SetModified( TRUE );
00312     }
00313 }
00314 
00315 
00316 void SmFontFormatList::AddFontFormat( const String &rFntFmtId, 
00317         const SmFontFormat &rFntFmt )
00318 {
00319     const SmFontFormat *pFntFmt = GetFontFormat( rFntFmtId );
00320     DBG_ASSERT( !pFntFmt, "FontFormatId already exists" );
00321     if (!pFntFmt)
00322     {
00323         SmFntFmtListEntry aEntry( rFntFmtId, rFntFmt );
00324         aEntries.Insert( aEntry, aEntries.Count() );
00325         SetModified( TRUE );
00326     }
00327 }
00328     
00329     
00330 void SmFontFormatList::RemoveFontFormat( const String &rFntFmtId )
00331 {
00332     USHORT nPos = 0xFFFF;
00333 
00334     // search for entry
00335     USHORT nCnt = aEntries.Count();
00336     for (USHORT i = 0;  i < nCnt  &&  nPos == 0xFFFF;  ++i)
00337     {
00338         if (aEntries[i].aId == rFntFmtId)
00339             nPos = i;
00340     }
00341 
00342     // remove entry if found
00343     if (nPos != 0xFFFF)
00344     {
00345         aEntries.Remove( nPos );
00346         SetModified( TRUE );
00347     }
00348 }
00349 
00350     
00351 const SmFontFormat * SmFontFormatList::GetFontFormat( const String &rFntFmtId ) const
00352 {
00353     SmFontFormat *pRes = 0;
00354 
00355     USHORT nCnt = aEntries.Count();
00356     USHORT i;
00357     for (i = 0;  i < nCnt  &&  !pRes;  ++i)
00358     {
00359         if (aEntries[i].aId == rFntFmtId)
00360             pRes = &aEntries[i].aFntFmt;
00361     }
00362     
00363     return pRes;
00364 }
00365 
00366 
00367 
00368 const SmFontFormat * SmFontFormatList::GetFontFormat( USHORT nPos ) const
00369 {
00370     SmFontFormat *pRes = 0;
00371     if (nPos < aEntries.Count())
00372         pRes = &aEntries[ nPos ].aFntFmt;
00373     return pRes;
00374 }
00375 
00376 
00377 const String SmFontFormatList::GetFontFormatId( const SmFontFormat &rFntFmt ) const
00378 {
00379     String aRes;
00380 
00381     USHORT nCnt = aEntries.Count();
00382     USHORT i;
00383     for (i = 0;  i < nCnt  &&  0 == aRes.Len();  ++i)
00384     {
00385         if (aEntries[i].aFntFmt == rFntFmt)
00386             aRes = aEntries[i].aId;
00387     }
00388     
00389     return aRes;
00390 }
00391 
00392 
00393 const String SmFontFormatList::GetFontFormatId( const SmFontFormat &rFntFmt, BOOL bAdd )
00394 {
00395     String aRes( GetFontFormatId( rFntFmt) );
00396     if (0 == aRes.Len()  &&  bAdd)
00397     {
00398         aRes = GetNewFontFormatId();
00399         AddFontFormat( aRes, rFntFmt );
00400     }
00401     return aRes;
00402 }
00403 
00404 
00405 const String SmFontFormatList::GetFontFormatId( USHORT nPos ) const
00406 {
00407     String aRes;
00408     if (nPos < aEntries.Count())
00409         aRes = aEntries[nPos].aId;
00410     return aRes;
00411 }
00412 
00413 
00414 const String SmFontFormatList::GetNewFontFormatId() const
00415 {
00416     // returns first unused FormatId
00417     
00418     String aRes;
00419 
00420     String aPrefix( RTL_CONSTASCII_STRINGPARAM( "Id" ) );
00421     INT32 nCnt = GetCount();
00422     for (INT32 i = 1;  i <= nCnt + 1  &&  0 == aRes.Len();  ++i)
00423     {
00424         String aTmpId( aPrefix );
00425         aTmpId += String::CreateFromInt32( i );
00426         if (!GetFontFormat( aTmpId ))
00427             aRes = aTmpId;
00428     }
00429     DBG_ASSERT( 0 != aRes.Len(), "failed to create new FontFormatId" );
00430 
00431     return aRes;
00432 }
00433 
00435 
00436 SmMathConfig::SmMathConfig() :
00437     ConfigItem( String::CreateFromAscii( aRootName ))
00438 {
00439     pFormat         = 0;
00440     pOther          = 0;
00441     pFontFormatList = 0;
00442     pSymSetMgr      = 0;
00443 
00444     bIsOtherModified = bIsFormatModified = FALSE;
00445 }
00446         
00447 
00448 SmMathConfig::~SmMathConfig()
00449 {
00450     Save();
00451     delete pFormat;
00452     delete pOther;
00453     delete pFontFormatList;
00454     delete pSymSetMgr;
00455 }
00456 
00457                   
00458 void SmMathConfig::SetOtherModified( BOOL bVal )
00459 {
00460     bIsOtherModified = bVal;
00461 }
00462 
00463 
00464 void SmMathConfig::SetFormatModified( BOOL bVal )
00465 {
00466     bIsFormatModified = bVal;
00467 }
00468 
00469 
00470 void SmMathConfig::ReadSymbol( SmSym &rSymbol,
00471                                                 const rtl::OUString &rSymbolName, 
00472                                                 const rtl::OUString &rBaseNode ) const
00473 {
00474         Sequence< OUString > aNames = lcl_GetSymbolPropertyNames();
00475         INT32 nProps = aNames.getLength();
00476 
00477         OUString aDelim( OUString::valueOf( (sal_Unicode) '/' ) );
00478         OUString *pName = aNames.getArray();
00479         for (INT32 i = 0;  i < nProps;  ++i)
00480         {
00481                 OUString &rName = pName[i];
00482                 OUString aTmp( rName );
00483                 rName = rBaseNode;
00484                 rName += aDelim;
00485                 rName += rSymbolName;
00486                 rName += aDelim;
00487                 rName += aTmp;
00488         }
00489 
00490     const Sequence< Any > aValues = ((SmMathConfig*) this)->GetProperties( aNames );
00491 
00492         if (nProps  &&  aValues.getLength() == nProps)
00493         {
00494                 const Any * pValue = aValues.getConstArray();
00495         Font        aFont;
00496         sal_Unicode cChar = '\0';
00497         String      aSet;
00498         BOOL        bPredefined = FALSE;
00499 
00500         OUString    aTmpStr;
00501         INT32       nTmp32 = 0;
00502         BOOL        bTmp = FALSE;
00503 
00504         BOOL bOK = TRUE;
00505         if (pValue->hasValue()  &&  (*pValue >>= nTmp32))
00506             cChar = (sal_Unicode) nTmp32;
00507         else
00508             bOK = FALSE;
00509         ++pValue;
00510         if (pValue->hasValue()  &&  (*pValue >>= aTmpStr))
00511             aSet = aTmpStr;
00512         else
00513             bOK = FALSE;
00514                 ++pValue;
00515         if (pValue->hasValue()  &&  (*pValue >>= bTmp))
00516             bPredefined = bTmp;
00517         else
00518             bOK = FALSE;
00519                 ++pValue;
00520         if (pValue->hasValue()  &&  (*pValue >>= aTmpStr))
00521         {
00522             const SmFontFormat *pFntFmt = GetFontFormatList().GetFontFormat( aTmpStr );
00523             DBG_ASSERT( pFntFmt, "unknown FontFormat" );
00524             if (pFntFmt)
00525                 aFont = pFntFmt->GetFont();
00526         }
00527         else
00528             bOK = FALSE;
00529         ++pValue;
00530 
00531         if (bOK)
00532         {
00533             String aUiName( rSymbolName );
00534             String aUiSetName( aSet );
00535             if (bPredefined)
00536             {
00537                 String aTmp;
00538                 aTmp = GetUiSymbolName( rSymbolName );
00539                 DBG_ASSERT( aTmp.Len(), "localized symbol-name not found" );
00540                 if (aTmp.Len())
00541                     aUiName = aTmp;
00542                 aTmp = GetUiSymbolSetName( aSet );
00543                 DBG_ASSERT( aTmp.Len(), "localized symbolset-name not found" );
00544                 if (aTmp.Len())
00545                     aUiSetName = aTmp;
00546             }
00547 
00548             rSymbol = SmSym( aUiName, aFont, cChar, aUiSetName, bPredefined );
00549             if (aUiName != String(rSymbolName))
00550                 rSymbol.SetExportName( rSymbolName );
00551         }
00552         else
00553         {
00554             DBG_ERROR( "symbol read error" );
00555         }
00556         }
00557 }
00558 
00559 
00560 SmSymSetManager & SmMathConfig::GetSymSetManager()
00561 {
00562     if (!pSymSetMgr)
00563     {
00564         pSymSetMgr = new SmSymSetManager;
00565         pSymSetMgr->Load();
00566     }
00567     return *pSymSetMgr;
00568 }
00569 
00570 
00571 void SmMathConfig::Commit()
00572 {
00573     Save();
00574 }
00575 
00576 void SmMathConfig::Save()
00577 {
00578     SaveOther();
00579     SaveFormat();
00580     SaveFontFormatList();
00581 }
00582 
00583 
00584 USHORT SmMathConfig::GetSymbolCount() const
00585 {
00586     return ((SmMathConfig *) this)->GetSymSetManager().GetSymbolCount();
00587 }
00588 
00589 
00590 const SmSym * SmMathConfig::GetSymbol( USHORT nIndex ) const
00591 {
00592     return ((SmMathConfig *) this)->GetSymSetManager().GetSymbolByPos( nIndex );
00593 }    
00594 
00595 
00596 void SmMathConfig::GetSymbols( std::vector< SmSym > &rSymbols ) const
00597 {
00598     Sequence< OUString > aNodes( ((SmMathConfig*) this)->GetNodeNames( A2OU( SYMBOL_LIST ) ) );
00599     const OUString *pNode = aNodes.getConstArray();
00600     INT32 nNodes = aNodes.getLength();
00601     
00602     rSymbols.resize( nNodes );
00603     std::vector< SmSym >::iterator aIt( rSymbols.begin() );
00604     std::vector< SmSym >::iterator aEnd( rSymbols.end() );
00605     while (aIt != aEnd)
00606     {
00607         ReadSymbol( *aIt++, *pNode++, A2OU( SYMBOL_LIST ) );
00608     }
00609 }
00610 
00611 
00612 void SmMathConfig::SetSymbols( const std::vector< SmSym > &rNewSymbols )
00613 {
00614     sal_uIntPtr nCount = rNewSymbols.size();
00615 
00616     Sequence< OUString > aNames = lcl_GetSymbolPropertyNames();
00617     const OUString *pNames = aNames.getConstArray();
00618     sal_uIntPtr nSymbolProps = sal::static_int_cast< UINT32 >(aNames.getLength());
00619     
00620     Sequence< PropertyValue > aValues( nCount * nSymbolProps );
00621     PropertyValue *pValues = aValues.getArray();
00622 
00623     PropertyValue *pVal = pValues;
00624     OUString aDelim( OUString::valueOf( (sal_Unicode) '/' ) );
00625     std::vector< SmSym >::const_iterator aIt( rNewSymbols.begin() );
00626     std::vector< SmSym >::const_iterator aEnd( rNewSymbols.end() );
00627     while (aIt != aEnd)
00628     {
00629         const SmSym &rSymbol = *aIt++;
00630         //const Font  &rFont = rSymbol.GetFace(); 
00631         OUString  aNodeNameDelim( A2OU( SYMBOL_LIST ) );
00632         aNodeNameDelim += aDelim;
00633         aNodeNameDelim += rSymbol.GetExportName();
00634         aNodeNameDelim += aDelim;
00635 
00636         const OUString *pName = pNames;
00637 
00638         // Char
00639         pVal->Name  = aNodeNameDelim;
00640         pVal->Name += *pName++;
00641         pVal->Value <<= (INT32) rSymbol.GetCharacter();
00642         pVal++;
00643         // Set
00644         pVal->Name  = aNodeNameDelim;
00645         pVal->Name += *pName++;
00646         OUString aTmp( rSymbol.GetSetName() );
00647         if (rSymbol.IsPredefined())
00648             aTmp = GetExportSymbolSetName( aTmp );
00649         pVal->Value <<= aTmp;
00650         pVal++;
00651         // Predefined
00652         pVal->Name  = aNodeNameDelim;
00653         pVal->Name += *pName++;
00654         pVal->Value <<= (BOOL) rSymbol.IsPredefined();
00655         pVal++;
00656         // FontFormatId
00657         SmFontFormat aFntFmt( rSymbol.GetFace() );
00658         String aFntFmtId( GetFontFormatList().GetFontFormatId( aFntFmt, TRUE ) );
00659         DBG_ASSERT( aFntFmtId.Len(), "FontFormatId not found" );
00660         pVal->Name  = aNodeNameDelim;
00661         pVal->Name += *pName++;
00662         pVal->Value <<= OUString( aFntFmtId );
00663         pVal++;
00664     }
00665     DBG_ASSERT( pVal - pValues == sal::static_int_cast< ptrdiff_t >(nCount * nSymbolProps), "properties missing" );
00666     ReplaceSetProperties( A2OU( SYMBOL_LIST ) , aValues );
00667 
00668     StripFontFormatList( rNewSymbols );
00669     SaveFontFormatList();
00670 }
00671 
00672 
00673 SmFontFormatList & SmMathConfig::GetFontFormatList()
00674 {
00675     if (!pFontFormatList)
00676     {
00677         LoadFontFormatList();
00678     }
00679     return *pFontFormatList;
00680 }
00681 
00682 
00683 void SmMathConfig::LoadFontFormatList()
00684 {
00685     if (!pFontFormatList)
00686         pFontFormatList = new SmFontFormatList;
00687     else
00688         pFontFormatList->Clear();
00689 
00690     Sequence< OUString > aNodes( GetNodeNames( A2OU( FONT_FORMAT_LIST ) ) );
00691         const OUString *pNode = aNodes.getConstArray();
00692         INT32 nNodes = aNodes.getLength();
00693 
00694         for (INT32 i = 0;  i < nNodes;  ++i)
00695         {
00696         SmFontFormat aFntFmt;
00697         ReadFontFormat( aFntFmt, pNode[i], A2OU( FONT_FORMAT_LIST ) );
00698         if (!pFontFormatList->GetFontFormat( pNode[i] ))
00699         {
00700             DBG_ASSERT( 0 == pFontFormatList->GetFontFormat( pNode[i] ), 
00701                     "FontFormat ID already exists" );
00702             pFontFormatList->AddFontFormat( pNode[i], aFntFmt );
00703         }
00704         }
00705     pFontFormatList->SetModified( FALSE );
00706 }
00707     
00708 
00709 void SmMathConfig::ReadFontFormat( SmFontFormat &rFontFormat,
00710         const OUString &rSymbolName, const OUString &rBaseNode ) const
00711 {
00712     Sequence< OUString > aNames = lcl_GetFontPropertyNames();
00713         INT32 nProps = aNames.getLength();
00714 
00715         OUString aDelim( OUString::valueOf( (sal_Unicode) '/' ) );
00716         OUString *pName = aNames.getArray();
00717         for (INT32 i = 0;  i < nProps;  ++i)
00718         {
00719                 OUString &rName = pName[i];
00720                 OUString aTmp( rName );
00721                 rName = rBaseNode;
00722                 rName += aDelim;
00723                 rName += rSymbolName;
00724                 rName += aDelim;
00725                 rName += aTmp;
00726         }
00727 
00728     const Sequence< Any > aValues = ((SmMathConfig*) this)->GetProperties( aNames );
00729 
00730         if (nProps  &&  aValues.getLength() == nProps)
00731         {
00732                 const Any * pValue = aValues.getConstArray();
00733 
00734         OUString    aTmpStr;
00735         INT16       nTmp16 = 0;
00736 
00737         BOOL bOK = TRUE;
00738         if (pValue->hasValue()  &&  (*pValue >>= aTmpStr))
00739             rFontFormat.aName = aTmpStr;
00740         else
00741             bOK = FALSE;
00742         ++pValue;
00743         if (pValue->hasValue()  &&  (*pValue >>= nTmp16))
00744             rFontFormat.nCharSet = nTmp16; // 6.0 file-format GetSOLoadTextEncoding not needed
00745         else
00746             bOK = FALSE;
00747                 ++pValue;
00748         if (pValue->hasValue()  &&  (*pValue >>= nTmp16))
00749             rFontFormat.nFamily = nTmp16;
00750         else
00751             bOK = FALSE;
00752                 ++pValue;
00753         if (pValue->hasValue()  &&  (*pValue >>= nTmp16))
00754             rFontFormat.nPitch = nTmp16;
00755         else
00756             bOK = FALSE;
00757                 ++pValue;
00758         if (pValue->hasValue()  &&  (*pValue >>= nTmp16))
00759             rFontFormat.nWeight = nTmp16;
00760         else
00761             bOK = FALSE;
00762                 ++pValue;
00763         if (pValue->hasValue()  &&  (*pValue >>= nTmp16))
00764             rFontFormat.nItalic = nTmp16;
00765         else
00766             bOK = FALSE;
00767                 ++pValue;
00768 
00769         DBG_ASSERT( bOK, "read FontFormat failed" );
00770         }
00771 }
00772 
00773 
00774 void SmMathConfig::SaveFontFormatList()
00775 {
00776     SmFontFormatList &rFntFmtList = GetFontFormatList();
00777     
00778     if (!rFntFmtList.IsModified())
00779         return;
00780 
00781     Sequence< OUString > aNames = lcl_GetFontPropertyNames();
00782     INT32 nSymbolProps = aNames.getLength();
00783     
00784     USHORT nCount = rFntFmtList.GetCount();
00785 
00786     Sequence< PropertyValue > aValues( nCount * nSymbolProps );
00787     PropertyValue *pValues = aValues.getArray();
00788 
00789     PropertyValue *pVal = pValues;
00790     OUString aDelim( OUString::valueOf( (sal_Unicode) '/' ) );
00791     for (USHORT i = 0;  i < nCount;  ++i)
00792     {
00793         String aFntFmtId( rFntFmtList.GetFontFormatId( i ) );
00794         const SmFontFormat aFntFmt( *rFntFmtList.GetFontFormat( aFntFmtId ) );
00795 
00796         OUString  aNodeNameDelim( A2OU( FONT_FORMAT_LIST ) );
00797         aNodeNameDelim += aDelim;
00798         aNodeNameDelim += aFntFmtId;
00799         aNodeNameDelim += aDelim;
00800 
00801         const OUString *pName = aNames.getConstArray();;
00802 
00803         // Name
00804         pVal->Name  = aNodeNameDelim;
00805         pVal->Name += *pName++;
00806         pVal->Value <<= OUString( aFntFmt.aName );
00807         pVal++;
00808         // CharSet
00809         pVal->Name  = aNodeNameDelim;
00810         pVal->Name += *pName++;
00811         pVal->Value <<= (INT16) aFntFmt.nCharSet; // 6.0 file-format GetSOStoreTextEncoding not needed
00812         pVal++;
00813         // Family
00814         pVal->Name  = aNodeNameDelim;
00815         pVal->Name += *pName++;
00816         pVal->Value <<= (INT16) aFntFmt.nFamily;
00817         pVal++;
00818         // Pitch
00819         pVal->Name  = aNodeNameDelim;
00820         pVal->Name += *pName++;
00821         pVal->Value <<= (INT16) aFntFmt.nPitch;
00822         pVal++;
00823         // Weight
00824         pVal->Name  = aNodeNameDelim;
00825         pVal->Name += *pName++;
00826         pVal->Value <<= (INT16) aFntFmt.nWeight;
00827         pVal++;
00828         // Italic
00829         pVal->Name  = aNodeNameDelim;
00830         pVal->Name += *pName++;
00831         pVal->Value <<= (INT16) aFntFmt.nItalic;
00832         pVal++;
00833     }
00834     DBG_ASSERT( pVal - pValues == nCount * nSymbolProps, "properties missing" );
00835     ReplaceSetProperties( A2OU( FONT_FORMAT_LIST ) , aValues );
00836     
00837     rFntFmtList.SetModified( FALSE );
00838 }
00839 
00840 
00841 void SmMathConfig::StripFontFormatList( const std::vector< SmSym > &rSymbols )
00842 {
00843     size_t nCount = rSymbols.size();
00844     USHORT i;
00845     
00846     // build list of used font-formats only
00848     SmFontFormatList aUsedList;
00849     for (i = 0;  i < nCount;  ++i)
00850     {
00851         DBG_ASSERT( rSymbols[i].GetName().Len() > 0, "non named symbol" );
00852         aUsedList.GetFontFormatId( SmFontFormat( rSymbols[i].GetFace() ) , TRUE );
00853     }
00854     const SmFormat & rStdFmt = GetStandardFormat();
00855     for (i = FNT_BEGIN;  i <= FNT_END;  ++i)
00856     {
00857         aUsedList.GetFontFormatId( SmFontFormat( rStdFmt.GetFont( i ) ) , TRUE );
00858     }
00859 
00860     // remove unused font-formats from list
00861     SmFontFormatList &rFntFmtList = GetFontFormatList();
00862     USHORT nCnt = rFntFmtList.GetCount();
00863     SmFontFormat *pTmpFormat = new SmFontFormat[ nCnt ];
00864     String       *pId     = new String      [ nCnt ];
00865     INT32 k;
00866     for (k = 0;  k < nCnt;  ++k)
00867     {
00868         pTmpFormat[k] = *rFntFmtList.GetFontFormat( (USHORT) k );
00869         pId[k]     = rFntFmtList.GetFontFormatId( (USHORT) k );
00870     }
00871     for (k = 0;  k < nCnt;  ++k)
00872     {
00873         if (0 == aUsedList.GetFontFormatId( pTmpFormat[k] ).Len())
00874         {
00875             rFntFmtList.RemoveFontFormat( pId[k] );
00876         }
00877     }
00878     delete [] pId;
00879     delete [] pTmpFormat;
00880 }
00881 
00882        
00883 void SmMathConfig::LoadOther()
00884 {
00885     if (!pOther)
00886         pOther = new SmCfgOther;
00887 
00888     Sequence< OUString > aNames( GetOtherPropertyNames() );
00889     INT32 nProps = aNames.getLength();
00890 
00891     Sequence< Any > aValues( GetProperties( aNames ) );
00892     if (nProps  &&  aValues.getLength() == nProps)
00893     {
00894         const Any *pValues = aValues.getConstArray();
00895         const Any *pVal = pValues;
00896 
00897         INT16   nTmp16 = 0;
00898         BOOL    bTmp = FALSE;
00899 
00900         // Print/Title
00901         if (pVal->hasValue()  &&  (*pVal >>= bTmp))
00902             pOther->bPrintTitle = bTmp;
00903         ++pVal;
00904         // Print/FormulaText
00905         if (pVal->hasValue()  &&  (*pVal >>= bTmp))
00906             pOther->bPrintFormulaText = bTmp;
00907         ++pVal;
00908         // Print/Frame
00909         if (pVal->hasValue()  &&  (*pVal >>= bTmp))
00910             pOther->bPrintFrame = bTmp;
00911         ++pVal;
00912         // Print/Size
00913         if (pVal->hasValue()  &&  (*pVal >>= nTmp16))
00914             pOther->ePrintSize = (SmPrintSize) nTmp16;
00915         ++pVal;
00916         // Print/ZoomFactor
00917         if (pVal->hasValue()  &&  (*pVal >>= nTmp16))
00918             pOther->nPrintZoomFactor = nTmp16;
00919 /*        ++pVal;
00920         // Misc/NoSymbolsWarning
00921         if (pVal->hasValue()  &&  (*pVal >>= bTmp))
00922             pOther->bNoSymbolsWarning = bTmp;
00923 */
00924         ++pVal;
00925         // Misc/IgnoreSpacesRight
00926         if (pVal->hasValue()  &&  (*pVal >>= bTmp))
00927             pOther->bIgnoreSpacesRight = bTmp;
00928         ++pVal;
00929         // View/ToolboxVisible
00930         if (pVal->hasValue()  &&  (*pVal >>= bTmp))
00931             pOther->bToolboxVisible = bTmp;
00932         ++pVal;
00933         // View/AutoRedraw
00934         if (pVal->hasValue()  &&  (*pVal >>= bTmp))
00935             pOther->bAutoRedraw = bTmp;
00936         ++pVal;
00937         // View/FormulaCursor
00938         if (pVal->hasValue()  &&  (*pVal >>= bTmp))
00939             pOther->bFormulaCursor = bTmp;
00940         ++pVal;
00941 
00942         DBG_ASSERT( pVal - pValues == nProps, "property mismatch" );
00943         SetOtherModified( FALSE );
00944     }
00945 }
00946 
00947 
00948 void SmMathConfig::SaveOther()
00949 {
00950     if (!pOther || !IsOtherModified())
00951         return;
00952 
00953     const Sequence< OUString > aNames( GetOtherPropertyNames() );
00954     INT32 nProps = aNames.getLength();
00955 
00956     Sequence< Any > aValues( nProps );
00957     Any *pValues = aValues.getArray();
00958     Any *pValue  = pValues;
00959 
00960     // Print/Title
00961     *pValue++ <<= (BOOL) pOther->bPrintTitle;
00962     // Print/FormulaText
00963     *pValue++ <<= (BOOL) pOther->bPrintFormulaText;
00964     // Print/Frame
00965     *pValue++ <<= (BOOL) pOther->bPrintFrame;
00966     // Print/Size
00967     *pValue++ <<= (INT16) pOther->ePrintSize;
00968     // Print/ZoomFactor
00969     *pValue++ <<= (INT16) pOther->nPrintZoomFactor;
00970 /*    // Misc/NoSymbolsWarning
00971     *pValue++ <<= (BOOL) pOther->bNoSymbolsWarning;
00972 */
00973     // Misc/IgnoreSpacesRight
00974     *pValue++ <<= (BOOL) pOther->bIgnoreSpacesRight;
00975     // View/ToolboxVisible
00976     *pValue++ <<= (BOOL) pOther->bToolboxVisible;
00977     // View/AutoRedraw
00978     *pValue++ <<= (BOOL) pOther->bAutoRedraw;
00979     // View/FormulaCursor
00980     *pValue++ <<= (BOOL) pOther->bFormulaCursor;
00981     
00982     DBG_ASSERT( pValue - pValues == nProps, "property mismatch" );
00983     PutProperties( aNames , aValues );
00984 
00985     SetOtherModified( FALSE );
00986 }
00987 
00988 void SmMathConfig::LoadFormat()
00989 {
00990     if (!pFormat)
00991         pFormat = new SmFormat;
00992 
00993     
00994     Sequence< OUString > aNames( GetFormatPropertyNames() );
00995     INT32 nProps = aNames.getLength();
00996 
00997     Sequence< Any > aValues( GetProperties( aNames ) );
00998     if (nProps  &&  aValues.getLength() == nProps)
00999     {
01000         const Any *pValues = aValues.getConstArray();
01001         const Any *pVal = pValues;
01002 
01003         OUString    aTmpStr;
01004         INT16       nTmp16 = 0;
01005         BOOL        bTmp = FALSE;
01006 
01007         // StandardFormat/Textmode
01008         if (pVal->hasValue()  &&  (*pVal >>= bTmp))
01009             pFormat->SetTextmode( bTmp );
01010         ++pVal;
01011         // StandardFormat/ScaleNormalBracket
01012         if (pVal->hasValue()  &&  (*pVal >>= bTmp))
01013             pFormat->SetScaleNormalBrackets( bTmp );
01014         ++pVal;
01015         // StandardFormat/HorizontalAlignment
01016         if (pVal->hasValue()  &&  (*pVal >>= nTmp16))
01017             pFormat->SetHorAlign( (SmHorAlign) nTmp16 );
01018         ++pVal;
01019         // StandardFormat/BaseSize
01020         if (pVal->hasValue()  &&  (*pVal >>= nTmp16))
01021             pFormat->SetBaseSize( Size(0, SmPtsTo100th_mm( nTmp16 )) );
01022         ++pVal;
01023 
01024         USHORT i;
01025         for (i = SIZ_BEGIN;  i <= SIZ_END;  ++i)
01026         {
01027             if (pVal->hasValue()  &&  (*pVal >>= nTmp16))
01028                 pFormat->SetRelSize( i, nTmp16 );
01029             ++pVal;
01030         }
01031 
01032         for (i = DIS_BEGIN;  i <= DIS_END;  ++i)
01033         {
01034             if (pVal->hasValue()  &&  (*pVal >>= nTmp16))
01035                 pFormat->SetDistance( i, nTmp16 );
01036             ++pVal;
01037         }
01038 
01039         LanguageType nLang = Application::GetSettings().GetUILanguage(); 
01040         for (i = FNT_BEGIN;  i < FNT_END;  ++i)
01041         {
01042             Font aFnt;
01043             BOOL bUseDefaultFont = TRUE;
01044             if (pVal->hasValue()  &&  (*pVal >>= aTmpStr))
01045             {
01046                 bUseDefaultFont = 0 == aTmpStr.getLength();
01047                 if (bUseDefaultFont)
01048                 {
01049                     aFnt = pFormat->GetFont( i );
01050                     aFnt.SetName( GetDefaultFontName( nLang, i ) );
01051                 }
01052                 else
01053                 {
01054                     const SmFontFormat *pFntFmt = GetFontFormatList().GetFontFormat( aTmpStr );
01055                     DBG_ASSERT( pFntFmt, "unknown FontFormat" );
01056                     if (pFntFmt)
01057                         aFnt = pFntFmt->GetFont();
01058                 }
01059             }
01060             ++pVal;
01061 
01062             aFnt.SetSize( pFormat->GetBaseSize() );
01063             pFormat->SetFont( i, aFnt, bUseDefaultFont );
01064         }
01065 
01066         DBG_ASSERT( pVal - pValues == nProps, "property mismatch" );
01067         SetFormatModified( FALSE );
01068     }
01069 }
01070 
01071 
01072 void SmMathConfig::SaveFormat()
01073 {
01074     if (!pFormat || !IsFormatModified())
01075         return;
01076 
01077     const Sequence< OUString > aNames( GetFormatPropertyNames() );
01078     INT32 nProps = aNames.getLength();
01079 
01080     Sequence< Any > aValues( nProps );
01081     Any *pValues = aValues.getArray();
01082     Any *pValue  = pValues;
01083 
01084     // StandardFormat/Textmode
01085     *pValue++ <<= (BOOL) pFormat->IsTextmode();
01086     // StandardFormat/ScaleNormalBracket
01087     *pValue++ <<= (BOOL) pFormat->IsScaleNormalBrackets();
01088     // StandardFormat/HorizontalAlignment
01089     *pValue++ <<= (INT16) pFormat->GetHorAlign();
01090     // StandardFormat/BaseSize
01091     *pValue++ <<= (INT16) SmRoundFraction( Sm100th_mmToPts( 
01092                                     pFormat->GetBaseSize().Height() ) );
01093 
01094     USHORT i;
01095     for (i = SIZ_BEGIN;  i <= SIZ_END;  ++i)
01096         *pValue++ <<= (INT16) pFormat->GetRelSize( i );
01097 
01098     for (i = DIS_BEGIN;  i <= DIS_END;  ++i)
01099         *pValue++ <<= (INT16) pFormat->GetDistance( i );
01100 
01101     for (i = FNT_BEGIN;  i < FNT_END;  ++i)
01102     {
01103         OUString aFntFmtId;
01104 
01105         if (!pFormat->IsDefaultFont( i ))
01106         {
01107             SmFontFormat aFntFmt( pFormat->GetFont( i ) );
01108             aFntFmtId = GetFontFormatList().GetFontFormatId( aFntFmt, TRUE );
01109             DBG_ASSERT( aFntFmtId.getLength(), "FontFormatId not found" );
01110         }
01111 
01112         *pValue++ <<= aFntFmtId;
01113     }
01114     
01115     DBG_ASSERT( pValue - pValues == nProps, "property mismatch" );
01116     PutProperties( aNames , aValues );
01117     
01118     SetFormatModified( FALSE );
01119 }
01120 
01121 
01122 const SmFormat & SmMathConfig::GetStandardFormat() const
01123 {
01124     if (!pFormat)
01125         ((SmMathConfig *) this)->LoadFormat();
01126     return *pFormat;
01127 }
01128 
01129 
01130 void SmMathConfig::SetStandardFormat( const SmFormat &rFormat )
01131 {
01132     if (!pFormat)
01133         LoadFormat();
01134     if (rFormat != *pFormat)
01135     {
01136         *pFormat = rFormat;
01137         SetFormatModified( TRUE );
01138                 SaveFormat();
01139     }
01140 }
01141         
01142 
01143 SmPrintSize SmMathConfig::GetPrintSize() const
01144 {
01145     if (!pOther)
01146         ((SmMathConfig *) this)->LoadOther();
01147     return pOther->ePrintSize;
01148 }
01149 
01150 
01151 void SmMathConfig::SetPrintSize( SmPrintSize eSize )
01152 {
01153     if (!pOther)
01154         LoadOther();
01155     if (eSize != pOther->ePrintSize)
01156     {
01157         pOther->ePrintSize = eSize;
01158         SetOtherModified( TRUE );
01159     }
01160 }
01161 
01162 
01163 USHORT SmMathConfig::GetPrintZoomFactor() const
01164 {
01165     if (!pOther)
01166         ((SmMathConfig *) this)->LoadOther();
01167     return pOther->nPrintZoomFactor;
01168 }
01169 
01170 
01171 void SmMathConfig::SetPrintZoomFactor( USHORT nVal )
01172 {
01173     if (!pOther)
01174         LoadOther();
01175     if (nVal != pOther->nPrintZoomFactor)
01176     {
01177         pOther->nPrintZoomFactor = nVal;
01178         SetOtherModified( TRUE );
01179     }
01180 }
01181     
01182 
01183 void SmMathConfig::SetOtherIfNotEqual( BOOL &rbItem, BOOL bNewVal )
01184 {
01185     if (bNewVal != rbItem)
01186     {
01187         rbItem = bNewVal;
01188         SetOtherModified( TRUE );
01189     }
01190 }
01191 
01192 
01193 BOOL SmMathConfig::IsPrintTitle() const
01194 {
01195     if (!pOther)
01196         ((SmMathConfig *) this)->LoadOther();
01197     return pOther->bPrintTitle;
01198 }
01199 
01200 
01201 void SmMathConfig::SetPrintTitle( BOOL bVal )
01202 {
01203     if (!pOther)
01204         LoadOther();
01205     SetOtherIfNotEqual( pOther->bPrintTitle, bVal );
01206 }
01207 
01208 
01209 BOOL SmMathConfig::IsPrintFormulaText() const
01210 {
01211     if (!pOther)
01212         ((SmMathConfig *) this)->LoadOther();
01213     return pOther->bPrintFormulaText;
01214 }
01215 
01216 
01217 void SmMathConfig::SetPrintFormulaText( BOOL bVal )
01218 {
01219     if (!pOther)
01220         LoadOther();
01221     SetOtherIfNotEqual( pOther->bPrintFormulaText, bVal );
01222 }
01223 
01224 
01225 BOOL SmMathConfig::IsPrintFrame() const
01226 {
01227     if (!pOther)
01228         ((SmMathConfig *) this)->LoadOther();
01229     return pOther->bPrintFrame;
01230 }
01231 
01232 
01233 void SmMathConfig::SetPrintFrame( BOOL bVal )
01234 {
01235     if (!pOther)
01236         LoadOther();
01237     SetOtherIfNotEqual( pOther->bPrintFrame, bVal );
01238 }
01239 
01240 
01241 BOOL SmMathConfig::IsIgnoreSpacesRight() const
01242 {
01243     if (!pOther)
01244         ((SmMathConfig *) this)->LoadOther();
01245     return pOther->bIgnoreSpacesRight;
01246 }
01247 
01248 
01249 void SmMathConfig::SetIgnoreSpacesRight( BOOL bVal )
01250 {
01251     if (!pOther)
01252         LoadOther();
01253     SetOtherIfNotEqual( pOther->bIgnoreSpacesRight, bVal );
01254 }
01255 
01256 
01257 BOOL SmMathConfig::IsToolboxVisible() const
01258 {
01259     if (!pOther)
01260         ((SmMathConfig *) this)->LoadOther();
01261     return pOther->bToolboxVisible;
01262 }
01263 
01264 
01265 void SmMathConfig::SetToolboxVisible( BOOL bVal )
01266 {
01267     if (!pOther)
01268         LoadOther();
01269     SetOtherIfNotEqual( pOther->bToolboxVisible, bVal );
01270 }
01271 
01272 
01273 BOOL SmMathConfig::IsAutoRedraw() const
01274 {
01275     if (!pOther)
01276         ((SmMathConfig *) this)->LoadOther();
01277     return pOther->bAutoRedraw;
01278 }
01279 
01280 
01281 void SmMathConfig::SetAutoRedraw( BOOL bVal )
01282 {
01283     if (!pOther)
01284         LoadOther();
01285     SetOtherIfNotEqual( pOther->bAutoRedraw, bVal );
01286 }
01287 
01288 
01289 BOOL SmMathConfig::IsShowFormulaCursor() const
01290 {
01291     if (!pOther)
01292         ((SmMathConfig *) this)->LoadOther();
01293     return pOther->bFormulaCursor;
01294 }
01295 
01296 
01297 void SmMathConfig::SetShowFormulaCursor( BOOL bVal )
01298 {
01299     if (!pOther)
01300         LoadOther();
01301     SetOtherIfNotEqual( pOther->bFormulaCursor, bVal );
01302 }
01303 
01304 
01306 

Generated on Wed Feb 20 17:21:56 2008 for maths by  doxygen 1.5.1