LCOV - code coverage report
Current view: top level - sw/source/core/txtnode - fmtatr2.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 291 363 80.2 %
Date: 2014-04-11 Functions: 74 83 89.2 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #include <hintids.hxx>
      21             : #include <poolfmt.hxx>
      22             : #include "unomid.h"
      23             : 
      24             : #include <basic/sbxvar.hxx>
      25             : #include <svl/macitem.hxx>
      26             : #include <svl/stritem.hxx>
      27             : #include <svl/stylepool.hxx>
      28             : #include <fmtautofmt.hxx>
      29             : #include <fchrfmt.hxx>
      30             : #include <fmtinfmt.hxx>
      31             : #include <txtatr.hxx>
      32             : #include <fmtruby.hxx>
      33             : #include <charfmt.hxx>
      34             : #include <hints.hxx>
      35             : #include <unostyle.hxx>
      36             : #include <unoevent.hxx>
      37             : #include <com/sun/star/text/RubyAdjust.hpp>
      38             : 
      39             : #include <cmdid.h>
      40             : #include <com/sun/star/uno/Any.h>
      41             : #include <SwStyleNameMapper.hxx>
      42             : 
      43             : #include <fmtmeta.hxx>
      44             : #include <ndtxt.hxx>
      45             : #include <doc.hxx>
      46             : #include <unometa.hxx>
      47             : #include <docsh.hxx>
      48             : #include <svl/zforlist.hxx>
      49             : 
      50             : #include <boost/bind.hpp>
      51             : #include <algorithm>
      52             : 
      53             : using namespace ::com::sun::star;
      54             : 
      55        9384 : TYPEINIT1_AUTOFACTORY(SwFmtINetFmt, SfxPoolItem);
      56       14845 : TYPEINIT1_AUTOFACTORY(SwFmtAutoFmt, SfxPoolItem);
      57             : 
      58             : /*************************************************************************
      59             : |*
      60             : |*    class SwFmtCharFmt
      61             : |*
      62             : *************************************************************************/
      63             : 
      64        2711 : SwFmtCharFmt::SwFmtCharFmt( SwCharFmt *pFmt )
      65             :     : SfxPoolItem( RES_TXTATR_CHARFMT ),
      66             :     SwClient(pFmt),
      67        2711 :     pTxtAttr( 0 )
      68             : {
      69        2711 : }
      70             : 
      71       66055 : SwFmtCharFmt::SwFmtCharFmt( const SwFmtCharFmt& rAttr )
      72             :     : SfxPoolItem( RES_TXTATR_CHARFMT ),
      73       66055 :     SwClient( rAttr.GetCharFmt() ),
      74      132110 :     pTxtAttr( 0 )
      75             : {
      76       66055 : }
      77             : 
      78      134860 : SwFmtCharFmt::~SwFmtCharFmt() {}
      79             : 
      80         571 : bool SwFmtCharFmt::operator==( const SfxPoolItem& rAttr ) const
      81             : {
      82             :     OSL_ENSURE( SfxPoolItem::operator==( rAttr ), "keine gleichen Attribute" );
      83         571 :     return GetCharFmt() == ((SwFmtCharFmt&)rAttr).GetCharFmt();
      84             : }
      85             : 
      86       66055 : SfxPoolItem* SwFmtCharFmt::Clone( SfxItemPool* ) const
      87             : {
      88       66055 :     return new SwFmtCharFmt( *this );
      89             : }
      90             : 
      91             : // weiterleiten an das TextAttribut
      92         756 : void SwFmtCharFmt::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew )
      93             : {
      94         756 :     if( pTxtAttr )
      95         648 :         pTxtAttr->ModifyNotification( pOld, pNew );
      96         756 : }
      97             : 
      98             : // weiterleiten an das TextAttribut
      99           5 : bool SwFmtCharFmt::GetInfo( SfxPoolItem& rInfo ) const
     100             : {
     101           5 :     return pTxtAttr ? pTxtAttr->GetInfo( rInfo ) : false;
     102             : }
     103          10 : bool SwFmtCharFmt::QueryValue( uno::Any& rVal, sal_uInt8 ) const
     104             : {
     105          10 :     OUString sCharFmtName;
     106          10 :     if(GetCharFmt())
     107           5 :         SwStyleNameMapper::FillProgName(GetCharFmt()->GetName(), sCharFmtName,  nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, true );
     108          10 :     rVal <<= sCharFmtName;
     109          10 :     return true;
     110             : }
     111           0 : bool SwFmtCharFmt::PutValue( const uno::Any& , sal_uInt8   )
     112             : {
     113             :     OSL_FAIL("Zeichenvorlage kann mit PutValue nicht gesetzt werden!");
     114           0 :     return false;
     115             : }
     116             : 
     117             : /*************************************************************************
     118             : |*
     119             : |*    class SwFmtAutoFmt
     120             : |*
     121             : *************************************************************************/
     122             : 
     123       79609 : SwFmtAutoFmt::SwFmtAutoFmt( sal_uInt16 nInitWhich )
     124       79609 :     : SfxPoolItem( nInitWhich )
     125             : {
     126       79609 : }
     127             : 
     128       24120 : SwFmtAutoFmt::SwFmtAutoFmt( const SwFmtAutoFmt& rAttr )
     129       24120 :     : SfxPoolItem( rAttr.Which() ), mpHandle( rAttr.mpHandle )
     130             : {
     131       24120 : }
     132             : 
     133      127919 : SwFmtAutoFmt::~SwFmtAutoFmt()
     134             : {
     135      127919 : }
     136             : 
     137     1988318 : bool SwFmtAutoFmt::operator==( const SfxPoolItem& rAttr ) const
     138             : {
     139             :     OSL_ENSURE( SfxPoolItem::operator==( rAttr ), "different attributes" );
     140     1988318 :     return mpHandle == ((SwFmtAutoFmt&)rAttr).mpHandle;
     141             : }
     142             : 
     143       24120 : SfxPoolItem* SwFmtAutoFmt::Clone( SfxItemPool* ) const
     144             : {
     145       24120 :     return new SwFmtAutoFmt( *this );
     146             : }
     147             : 
     148           6 : bool SwFmtAutoFmt::QueryValue( uno::Any& rVal, sal_uInt8 ) const
     149             : {
     150           6 :     OUString sCharFmtName = StylePool::nameOf( mpHandle );
     151           6 :     rVal <<= OUString( sCharFmtName );
     152           6 :     return true;
     153             : }
     154             : 
     155           0 : bool SwFmtAutoFmt::PutValue( const uno::Any& , sal_uInt8 )
     156             : {
     157             :     //the format is not renameable via API
     158           0 :     return false;
     159             : }
     160             : 
     161             : /*************************************************************************
     162             : |*
     163             : |*    class SwFmtINetFmt
     164             : |*
     165             : *************************************************************************/
     166             : 
     167           0 : SwFmtINetFmt::SwFmtINetFmt()
     168             :     : SfxPoolItem( RES_TXTATR_INETFMT )
     169             :     , msURL()
     170             :     , msTargetFrame()
     171             :     , msINetFmtName()
     172             :     , msVisitedFmtName()
     173             :     , msHyperlinkName()
     174             :     , mpMacroTbl( 0 )
     175             :     , mpTxtAttr( 0 )
     176             :     , mnINetFmtId( 0 )
     177           0 :     , mnVisitedFmtId( 0 )
     178           0 : {}
     179             : 
     180          47 : SwFmtINetFmt::SwFmtINetFmt( const OUString& rURL, const OUString& rTarget )
     181             :     : SfxPoolItem( RES_TXTATR_INETFMT )
     182             :     , msURL( rURL )
     183             :     , msTargetFrame( rTarget )
     184             :     , msINetFmtName()
     185             :     , msVisitedFmtName()
     186             :     , msHyperlinkName()
     187             :     , mpMacroTbl( 0 )
     188             :     , mpTxtAttr( 0 )
     189             :     , mnINetFmtId( RES_POOLCHR_INET_NORMAL )
     190          47 :     , mnVisitedFmtId( RES_POOLCHR_INET_VISIT )
     191             : {
     192          47 :     SwStyleNameMapper::FillUIName( mnINetFmtId, msINetFmtName );
     193          47 :     SwStyleNameMapper::FillUIName( mnVisitedFmtId, msVisitedFmtName );
     194          47 : }
     195             : 
     196        7089 : SwFmtINetFmt::SwFmtINetFmt( const SwFmtINetFmt& rAttr )
     197             :     : SfxPoolItem( RES_TXTATR_INETFMT )
     198        7089 :     , msURL( rAttr.GetValue() )
     199             :     , msTargetFrame( rAttr.msTargetFrame )
     200             :     , msINetFmtName( rAttr.msINetFmtName )
     201             :     , msVisitedFmtName( rAttr.msVisitedFmtName )
     202             :     , msHyperlinkName( rAttr.msHyperlinkName )
     203             :     , mpMacroTbl( 0 )
     204             :     , mpTxtAttr( 0 )
     205             :     , mnINetFmtId( rAttr.mnINetFmtId )
     206       14178 :     , mnVisitedFmtId( rAttr.mnVisitedFmtId )
     207             : {
     208        7089 :     if ( rAttr.GetMacroTbl() )
     209           0 :         mpMacroTbl = new SvxMacroTableDtor( *rAttr.GetMacroTbl() );
     210        7089 : }
     211             : 
     212       21398 : SwFmtINetFmt::~SwFmtINetFmt()
     213             : {
     214        7136 :     delete mpMacroTbl;
     215       14262 : }
     216             : 
     217         644 : bool SwFmtINetFmt::operator==( const SfxPoolItem& rAttr ) const
     218             : {
     219             :     OSL_ENSURE( SfxPoolItem::operator==( rAttr ), "keine gleichen Attribute" );
     220         644 :     bool bRet = SfxPoolItem::operator==( (SfxPoolItem&) rAttr )
     221         644 :                 && msURL == ((SwFmtINetFmt&)rAttr).msURL
     222         606 :                 && msHyperlinkName == ((SwFmtINetFmt&)rAttr).msHyperlinkName
     223         604 :                 && msTargetFrame == ((SwFmtINetFmt&)rAttr).msTargetFrame
     224         602 :                 && msINetFmtName == ((SwFmtINetFmt&)rAttr).msINetFmtName
     225         305 :                 && msVisitedFmtName == ((SwFmtINetFmt&)rAttr).msVisitedFmtName
     226           8 :                 && mnINetFmtId == ((SwFmtINetFmt&)rAttr).mnINetFmtId
     227         652 :                 && mnVisitedFmtId == ((SwFmtINetFmt&)rAttr).mnVisitedFmtId;
     228             : 
     229         644 :     if( !bRet )
     230         636 :         return false;
     231             : 
     232           8 :     const SvxMacroTableDtor* pOther = ((SwFmtINetFmt&)rAttr).mpMacroTbl;
     233           8 :     if( !mpMacroTbl )
     234           8 :         return ( !pOther || pOther->empty() );
     235           0 :     if( !pOther )
     236           0 :         return mpMacroTbl->empty();
     237             : 
     238           0 :     const SvxMacroTableDtor& rOwn = *mpMacroTbl;
     239           0 :     const SvxMacroTableDtor& rOther = *pOther;
     240             : 
     241           0 :     return rOwn == rOther;
     242             : }
     243             : 
     244        7089 : SfxPoolItem* SwFmtINetFmt::Clone( SfxItemPool* ) const
     245             : {
     246        7089 :     return new SwFmtINetFmt( *this );
     247             : }
     248             : 
     249           0 : void SwFmtINetFmt::SetMacroTbl( const SvxMacroTableDtor* pNewTbl )
     250             : {
     251           0 :     if( pNewTbl )
     252             :     {
     253           0 :         if( mpMacroTbl )
     254           0 :             *mpMacroTbl = *pNewTbl;
     255             :         else
     256           0 :             mpMacroTbl = new SvxMacroTableDtor( *pNewTbl );
     257             :     }
     258             :     else
     259           0 :         delete mpMacroTbl, mpMacroTbl = 0;
     260           0 : }
     261             : 
     262           0 : void SwFmtINetFmt::SetMacro( sal_uInt16 nEvent, const SvxMacro& rMacro )
     263             : {
     264           0 :     if( !mpMacroTbl )
     265           0 :         mpMacroTbl = new SvxMacroTableDtor;
     266             : 
     267           0 :     mpMacroTbl->Insert( nEvent, rMacro );
     268           0 : }
     269             : 
     270           9 : const SvxMacro* SwFmtINetFmt::GetMacro( sal_uInt16 nEvent ) const
     271             : {
     272           9 :     const SvxMacro* pRet = 0;
     273           9 :     if( mpMacroTbl && mpMacroTbl->IsKeyValid( nEvent ) )
     274           0 :         pRet = mpMacroTbl->Get( nEvent );
     275           9 :     return pRet;
     276             : }
     277             : 
     278         520 : bool SwFmtINetFmt::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
     279             : {
     280         520 :     nMemberId &= ~CONVERT_TWIPS;
     281         520 :     switch(nMemberId)
     282             :     {
     283             :         case MID_URL_URL:
     284         489 :             rVal <<= msURL;
     285         489 :         break;
     286             :         case MID_URL_TARGET:
     287           7 :             rVal <<= msTargetFrame;
     288           7 :         break;
     289             :         case MID_URL_HYPERLINKNAME:
     290           7 :             rVal <<= msHyperlinkName;
     291           7 :         break;
     292             :         case MID_URL_VISITED_FMT:
     293             :         {
     294           7 :             OUString sVal = msVisitedFmtName;
     295           7 :             if (sVal.isEmpty() && mnVisitedFmtId != 0)
     296           0 :                 SwStyleNameMapper::FillUIName(mnVisitedFmtId, sVal);
     297           7 :             if (!sVal.isEmpty())
     298             :                 SwStyleNameMapper::FillProgName(sVal, sVal,
     299           7 :                         nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, true);
     300           7 :             rVal <<= sVal;
     301             :         }
     302           7 :         break;
     303             :         case MID_URL_UNVISITED_FMT:
     304             :         {
     305           7 :             OUString sVal = msINetFmtName;
     306           7 :             if (sVal.isEmpty() && mnINetFmtId != 0)
     307           0 :                 SwStyleNameMapper::FillUIName(mnINetFmtId, sVal);
     308           7 :             if (!sVal.isEmpty())
     309             :                 SwStyleNameMapper::FillProgName(sVal, sVal,
     310           7 :                         nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, true);
     311           7 :             rVal <<= sVal;
     312             :         }
     313           7 :         break;
     314             :         case MID_URL_HYPERLINKEVENTS:
     315             :         {
     316             :             // create (and return) event descriptor
     317             :             SwHyperlinkEventDescriptor* pEvents =
     318           3 :                 new SwHyperlinkEventDescriptor();
     319           3 :             pEvents->copyMacrosFromINetFmt(*this);
     320           3 :             uno::Reference<container::XNameReplace> xNameReplace(pEvents);
     321             : 
     322             :             // all others return a string; so we just set rVal here and exit
     323           3 :             rVal <<= xNameReplace;
     324             :         }
     325           3 :         break;
     326             :         default:
     327           0 :             rVal <<= OUString();
     328           0 :         break;
     329             :     }
     330         520 :     return true;
     331             : }
     332        1566 : bool SwFmtINetFmt::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId  )
     333             : {
     334        1566 :     bool bRet = true;
     335        1566 :     nMemberId &= ~CONVERT_TWIPS;
     336             : 
     337             :     // all properties except HyperlinkEvents are of type string, hence
     338             :     // we treat HyperlinkEvents specially
     339        1566 :     if (MID_URL_HYPERLINKEVENTS == nMemberId)
     340             :     {
     341           0 :         uno::Reference<container::XNameReplace> xReplace;
     342           0 :         rVal >>= xReplace;
     343           0 :         if (xReplace.is())
     344             :         {
     345             :             // Create hyperlink event descriptor. Then copy events
     346             :             // from argument into descriptor. Then copy events from
     347             :             // the descriptor into the format.
     348           0 :             SwHyperlinkEventDescriptor* pEvents = new SwHyperlinkEventDescriptor();
     349           0 :             uno::Reference< lang::XServiceInfo> xHold = pEvents;
     350           0 :             pEvents->copyMacrosFromNameReplace(xReplace);
     351           0 :             pEvents->copyMacrosIntoINetFmt(*this);
     352             :         }
     353             :         else
     354             :         {
     355             :             // wrong type!
     356           0 :             bRet = false;
     357           0 :         }
     358             :     }
     359             :     else
     360             :     {
     361             :         // all string properties:
     362        1566 :         if(rVal.getValueType() != ::getCppuType((OUString*)0))
     363           0 :             return false;
     364             : 
     365        1566 :         switch(nMemberId)
     366             :         {
     367             :             case MID_URL_URL:
     368         960 :                 rVal >>= msURL;
     369         960 :                 break;
     370             :             case MID_URL_TARGET:
     371           6 :                 rVal >>= msTargetFrame;
     372           6 :                 break;
     373             :             case MID_URL_HYPERLINKNAME:
     374           6 :                 rVal >>= msHyperlinkName;
     375           6 :                 break;
     376             :             case MID_URL_VISITED_FMT:
     377             :             {
     378         297 :                 OUString sVal;
     379         297 :                 rVal >>= sVal;
     380         594 :                 OUString aString;
     381         297 :                 SwStyleNameMapper::FillUIName( sVal, aString, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, true );
     382         297 :                 msVisitedFmtName = aString;
     383             :                 mnVisitedFmtId = SwStyleNameMapper::GetPoolIdFromUIName( msVisitedFmtName,
     384         594 :                                                nsSwGetPoolIdFromName::GET_POOLID_CHRFMT );
     385             :             }
     386         297 :             break;
     387             :             case MID_URL_UNVISITED_FMT:
     388             :             {
     389         297 :                 OUString sVal;
     390         297 :                 rVal >>= sVal;
     391         594 :                 OUString aString;
     392         297 :                 SwStyleNameMapper::FillUIName( sVal, aString, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, true );
     393         297 :                 msINetFmtName = aString;
     394         594 :                 mnINetFmtId = SwStyleNameMapper::GetPoolIdFromUIName( msINetFmtName, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT );
     395             :             }
     396         297 :             break;
     397             :             default:
     398           0 :                 bRet = false;
     399             :         }
     400             :     }
     401        1566 :     return bRet;
     402             : }
     403             : 
     404             : /*************************************************************************
     405             : |*    class SwFmtRuby
     406             : *************************************************************************/
     407             : 
     408          37 : SwFmtRuby::SwFmtRuby( const OUString& rRubyTxt )
     409             :     : SfxPoolItem( RES_TXTATR_CJK_RUBY ),
     410             :     sRubyTxt( rRubyTxt ),
     411             :     pTxtAttr( 0 ),
     412             :     nCharFmtId( 0 ),
     413             :     nPosition( 0 ),
     414          37 :     nAdjustment( 0 )
     415             : {
     416          37 : }
     417             : 
     418        2411 : SwFmtRuby::SwFmtRuby( const SwFmtRuby& rAttr )
     419             :     : SfxPoolItem( RES_TXTATR_CJK_RUBY ),
     420             :     sRubyTxt( rAttr.sRubyTxt ),
     421             :     sCharFmtName( rAttr.sCharFmtName ),
     422             :     pTxtAttr( 0 ),
     423             :     nCharFmtId( rAttr.nCharFmtId),
     424             :     nPosition( rAttr.nPosition ),
     425        2411 :     nAdjustment( rAttr.nAdjustment )
     426             : {
     427        2411 : }
     428             : 
     429        4896 : SwFmtRuby::~SwFmtRuby()
     430             : {
     431        4896 : }
     432             : 
     433           0 : SwFmtRuby& SwFmtRuby::operator=( const SwFmtRuby& rAttr )
     434             : {
     435           0 :     sRubyTxt = rAttr.sRubyTxt;
     436           0 :     sCharFmtName = rAttr.sCharFmtName;
     437           0 :     nCharFmtId = rAttr.nCharFmtId;
     438           0 :     nPosition = rAttr.nPosition;
     439           0 :     nAdjustment = rAttr.nAdjustment;
     440           0 :     pTxtAttr =  0;
     441           0 :     return *this;
     442             : }
     443             : 
     444         963 : bool SwFmtRuby::operator==( const SfxPoolItem& rAttr ) const
     445             : {
     446             :     OSL_ENSURE( SfxPoolItem::operator==( rAttr ), "keine gleichen Attribute" );
     447        1911 :     return sRubyTxt == ((SwFmtRuby&)rAttr).sRubyTxt &&
     448        1892 :            sCharFmtName == ((SwFmtRuby&)rAttr).sCharFmtName &&
     449        1888 :            nCharFmtId == ((SwFmtRuby&)rAttr).nCharFmtId &&
     450        2847 :            nPosition == ((SwFmtRuby&)rAttr).nPosition &&
     451        1903 :            nAdjustment == ((SwFmtRuby&)rAttr).nAdjustment;
     452             : }
     453             : 
     454        2407 : SfxPoolItem* SwFmtRuby::Clone( SfxItemPool* ) const
     455             : {
     456        2407 :     return new SwFmtRuby( *this );
     457             : }
     458             : 
     459         534 : bool SwFmtRuby::QueryValue( uno::Any& rVal,
     460             :                             sal_uInt8 nMemberId ) const
     461             : {
     462         534 :     bool bRet = true;
     463         534 :     nMemberId &= ~CONVERT_TWIPS;
     464         534 :     switch( nMemberId )
     465             :     {
     466         133 :         case MID_RUBY_TEXT: rVal <<= (OUString)sRubyTxt;                    break;
     467         134 :          case MID_RUBY_ADJUST:  rVal <<= (sal_Int16)nAdjustment;    break;
     468             :         case MID_RUBY_CHARSTYLE:
     469             :         {
     470         133 :             OUString aString;
     471         133 :             SwStyleNameMapper::FillProgName(sCharFmtName, aString, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, true );
     472         133 :             rVal <<= aString;
     473             :         }
     474         133 :         break;
     475             :         case MID_RUBY_ABOVE:
     476             :         {
     477         134 :             sal_Bool bAbove = !nPosition;
     478         134 :             rVal.setValue(&bAbove, ::getBooleanCppuType());
     479             :         }
     480         134 :         break;
     481             :         default:
     482           0 :             bRet = false;
     483             :     }
     484         534 :     return bRet;
     485             : }
     486          84 : bool SwFmtRuby::PutValue( const uno::Any& rVal,
     487             :                             sal_uInt8 nMemberId  )
     488             : {
     489          84 :     bool bRet = true;
     490          84 :     nMemberId &= ~CONVERT_TWIPS;
     491          84 :     switch( nMemberId )
     492             :     {
     493             :         case MID_RUBY_TEXT:
     494             :         {
     495          52 :             OUString sTmp;
     496          52 :             bRet = rVal >>= sTmp;
     497          52 :             sRubyTxt = sTmp;
     498             :         }
     499          52 :         break;
     500             :          case MID_RUBY_ADJUST:
     501             :         {
     502          16 :             sal_Int16 nSet = 0;
     503          16 :             rVal >>= nSet;
     504          16 :             if(nSet >= 0 && nSet <= text::RubyAdjust_INDENT_BLOCK)
     505          16 :                 nAdjustment = nSet;
     506             :             else
     507           0 :                 bRet = false;
     508             :         }
     509          16 :         break;
     510             :         case MID_RUBY_ABOVE:
     511             :         {
     512          16 :             const uno::Type& rType = ::getBooleanCppuType();
     513          16 :             if(rVal.hasValue() && rVal.getValueType() == rType)
     514             :             {
     515          16 :                 sal_Bool bAbove = *(sal_Bool*)rVal.getValue();
     516          16 :                 nPosition = bAbove ? 0 : 1;
     517             :             }
     518             :         }
     519          16 :         break;
     520             :         case MID_RUBY_CHARSTYLE:
     521             :         {
     522           0 :             OUString sTmp;
     523           0 :             bRet = rVal >>= sTmp;
     524           0 :             if(bRet)
     525           0 :                 sCharFmtName = SwStyleNameMapper::GetUIName(sTmp, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT );
     526             :         }
     527           0 :         break;
     528             :         default:
     529           0 :             bRet = false;
     530             :     }
     531          84 :     return bRet;
     532             : }
     533             : 
     534             : /*************************************************************************
     535             :  class SwFmtMeta
     536             :  ************************************************************************/
     537             : 
     538          74 : SwFmtMeta * SwFmtMeta::CreatePoolDefault(const sal_uInt16 i_nWhich)
     539             : {
     540          74 :     return new SwFmtMeta(i_nWhich);
     541             : }
     542             : 
     543          74 : SwFmtMeta::SwFmtMeta(const sal_uInt16 i_nWhich)
     544             :     : SfxPoolItem( i_nWhich )
     545             :     , m_pMeta()
     546          74 :     , m_pTxtAttr( 0 )
     547             : {
     548             :    OSL_ENSURE((RES_TXTATR_META == i_nWhich) || (RES_TXTATR_METAFIELD == i_nWhich),
     549             :             "ERROR: SwFmtMeta: invalid which id!");
     550          74 : }
     551             : 
     552         997 : SwFmtMeta::SwFmtMeta( ::boost::shared_ptr< ::sw::Meta > const & i_pMeta,
     553             :                         const sal_uInt16 i_nWhich )
     554             :     : SfxPoolItem( i_nWhich )
     555             :     , m_pMeta( i_pMeta )
     556         997 :     , m_pTxtAttr( 0 )
     557             : {
     558             :    OSL_ENSURE((RES_TXTATR_META == i_nWhich) || (RES_TXTATR_METAFIELD == i_nWhich),
     559             :             "ERROR: SwFmtMeta: invalid which id!");
     560             :     OSL_ENSURE(m_pMeta, "SwFmtMeta: no Meta ?");
     561             :     // DO NOT call m_pMeta->SetFmtMeta(this) here; only from SetTxtAttr!
     562         997 : }
     563             : 
     564        3116 : SwFmtMeta::~SwFmtMeta()
     565             : {
     566        1071 :     if (m_pMeta && (m_pMeta->GetFmtMeta() == this))
     567             :     {
     568           0 :         NotifyChangeTxtNode(0);
     569           0 :         m_pMeta->SetFmtMeta(0);
     570             :     }
     571        2045 : }
     572             : 
     573          69 : bool SwFmtMeta::operator==( const SfxPoolItem & i_rOther ) const
     574             : {
     575             :     OSL_ENSURE( SfxPoolItem::operator==( i_rOther ), "i just copied this assert" );
     576          69 :     return SfxPoolItem::operator==( i_rOther )
     577          69 :         && (m_pMeta == static_cast<SwFmtMeta const &>( i_rOther ).m_pMeta);
     578             : }
     579             : 
     580         900 : SfxPoolItem * SwFmtMeta::Clone( SfxItemPool * /*pPool*/ ) const
     581             : {
     582             :     // if this is indeed a copy, then DoCopy must be called later!
     583             :     return (m_pMeta) // #i105148# pool default may be cloned also!
     584         900 :         ? new SwFmtMeta( m_pMeta, Which() ) : new SwFmtMeta( Which() );
     585             : }
     586             : 
     587         194 : void SwFmtMeta::SetTxtAttr(SwTxtMeta * const i_pTxtAttr)
     588             : {
     589             :     OSL_ENSURE(!(m_pTxtAttr && i_pTxtAttr),
     590             :         "SwFmtMeta::SetTxtAttr: already has text attribute?");
     591             :     OSL_ENSURE(  m_pTxtAttr || i_pTxtAttr ,
     592             :         "SwFmtMeta::SetTxtAttr: no attribute to remove?");
     593         194 :     m_pTxtAttr = i_pTxtAttr;
     594             :     OSL_ENSURE(m_pMeta, "inserted SwFmtMeta has no sw::Meta?");
     595             :     // the sw::Meta must be able to find the current text attribute!
     596         194 :     if (m_pMeta)
     597             :     {
     598         194 :         if (i_pTxtAttr)
     599             :         {
     600          97 :             m_pMeta->SetFmtMeta(this);
     601             :         }
     602          97 :         else if (m_pMeta->GetFmtMeta() == this)
     603             :         {   // text attribute gone => de-register from text node!
     604          97 :             NotifyChangeTxtNode(0);
     605          97 :             m_pMeta->SetFmtMeta(0);
     606             :         }
     607             :     }
     608         194 : }
     609             : 
     610         291 : void SwFmtMeta::NotifyChangeTxtNode(SwTxtNode *const pTxtNode)
     611             : {
     612             :     // N.B.: do not reset m_pTxtAttr here: see call in nodes.cxx,
     613             :     // where the hint is not deleted!
     614             :     OSL_ENSURE(m_pMeta, "SwFmtMeta::NotifyChangeTxtNode: no Meta?");
     615         291 :     if (m_pMeta && (m_pMeta->GetFmtMeta() == this))
     616             :     {   // do not call Modify, that would call SwXMeta::Modify!
     617         291 :         m_pMeta->NotifyChangeTxtNode(pTxtNode);
     618             :     }
     619         291 : }
     620             : 
     621             : // this SwFmtMeta has been cloned and points at the same sw::Meta as the source
     622             : // this method copies the sw::Meta
     623           0 : void SwFmtMeta::DoCopy(::sw::MetaFieldManager & i_rTargetDocManager,
     624             :         SwTxtNode & i_rTargetTxtNode)
     625             : {
     626             :     OSL_ENSURE(m_pMeta, "DoCopy called for SwFmtMeta with no sw::Meta?");
     627           0 :     if (m_pMeta)
     628             :     {
     629           0 :         const ::boost::shared_ptr< ::sw::Meta> pOriginal( m_pMeta );
     630           0 :         if (RES_TXTATR_META == Which())
     631             :         {
     632           0 :             m_pMeta.reset( new ::sw::Meta(this) );
     633             :         }
     634             :         else
     635             :         {
     636             :             ::sw::MetaField *const pMetaField(
     637           0 :                 static_cast< ::sw::MetaField* >(pOriginal.get()));
     638           0 :             m_pMeta = i_rTargetDocManager.makeMetaField( this,
     639           0 :                 pMetaField->m_nNumberFormat, pMetaField->IsFixedLanguage() );
     640             :         }
     641             :         // Meta must have a text node before calling RegisterAsCopyOf
     642           0 :         m_pMeta->NotifyChangeTxtNode(& i_rTargetTxtNode);
     643             :         // this cannot be done in Clone: a Clone is not necessarily a copy!
     644           0 :         m_pMeta->RegisterAsCopyOf(*pOriginal);
     645             :     }
     646           0 : }
     647             : 
     648             : namespace sw {
     649             : 
     650             : /*************************************************************************
     651             :  class sw::Meta
     652             :  ************************************************************************/
     653             : 
     654          97 : Meta::Meta(SwFmtMeta * const i_pFmt)
     655             :     : ::sfx2::Metadatable()
     656             :     , SwModify()
     657             :     , m_pFmt(i_pFmt)
     658          97 :     , m_pTxtNode(0)
     659             : {
     660          97 : }
     661             : 
     662         168 : Meta::~Meta()
     663             : {
     664         168 : }
     665             : 
     666         808 : SwTxtMeta * Meta::GetTxtAttr() const
     667             : {
     668         808 :     return (m_pFmt) ? m_pFmt->GetTxtAttr() : 0;
     669             : }
     670             : 
     671        2006 : SwTxtNode * Meta::GetTxtNode() const
     672             : {
     673        2006 :     return m_pTxtNode;
     674             : }
     675             : 
     676         291 : void Meta::NotifyChangeTxtNodeImpl()
     677             : {
     678         291 :     if (m_pTxtNode && (GetRegisteredIn() != m_pTxtNode))
     679             :     {
     680          97 :         m_pTxtNode->Add(this);
     681             :     }
     682         194 :     else if (!m_pTxtNode && GetRegisteredIn())
     683             :     {
     684          97 :         GetRegisteredInNonConst()->Remove(this);
     685             :     }
     686         291 : }
     687             : 
     688         291 : void Meta::NotifyChangeTxtNode(SwTxtNode *const pTxtNode)
     689             : {
     690         291 :     m_pTxtNode = pTxtNode;
     691         291 :     NotifyChangeTxtNodeImpl();
     692         291 :     if (!pTxtNode) // text node gone? invalidate UNO object!
     693             :     {
     694             :         SwPtrMsgPoolItem aMsgHint( RES_REMOVE_UNO_OBJECT,
     695         194 :             &static_cast<SwModify&>(*this) ); // cast to base class!
     696         194 :         this->Modify(&aMsgHint, &aMsgHint);
     697             :     }
     698         291 : }
     699             : 
     700             : // SwClient
     701        2072 : void Meta::Modify( const SfxPoolItem *pOld, const SfxPoolItem *pNew )
     702             : {
     703        2072 :     NotifyClients(pOld, pNew);
     704        2072 :     if (pOld && (RES_REMOVE_UNO_OBJECT == pOld->Which()))
     705             :     {   // invalidate cached uno object
     706         194 :         SetXMeta(uno::Reference<rdf::XMetadatable>(0));
     707             :     }
     708        2072 : }
     709             : 
     710             : // sfx2::Metadatable
     711          94 : ::sfx2::IXmlIdRegistry& Meta::GetRegistry()
     712             : {
     713          94 :     SwTxtNode * const pTxtNode( GetTxtNode() );
     714             :     // GetRegistry may only be called on a meta that is actually in the
     715             :     // document, which means it has a pointer to its text node
     716             :     OSL_ENSURE(pTxtNode, "ERROR: GetRegistry: no text node?");
     717          94 :     if (!pTxtNode)
     718           0 :         throw uno::RuntimeException();
     719          94 :     return pTxtNode->GetRegistry();
     720             : }
     721             : 
     722         423 : bool Meta::IsInClipboard() const
     723             : {
     724         423 :     const SwTxtNode * const pTxtNode( GetTxtNode() );
     725             : // no text node: in UNDO  OSL_ENSURE(pTxtNode, "IsInClipboard: no text node?");
     726         423 :     return (pTxtNode) ? pTxtNode->IsInClipboard() : false;
     727             : }
     728             : 
     729         433 : bool Meta::IsInUndo() const
     730             : {
     731         433 :     const SwTxtNode * const pTxtNode( GetTxtNode() );
     732             : // no text node: in UNDO  OSL_ENSURE(pTxtNode, "IsInUndo: no text node?");
     733         433 :     return (pTxtNode) ? pTxtNode->IsInUndo() : true;
     734             : }
     735             : 
     736         114 : bool Meta::IsInContent() const
     737             : {
     738         114 :     const SwTxtNode * const pTxtNode( GetTxtNode() );
     739             :     OSL_ENSURE(pTxtNode, "IsInContent: no text node?");
     740         114 :     return (pTxtNode) ? pTxtNode->IsInContent() : true;
     741             : }
     742             : 
     743             : ::com::sun::star::uno::Reference< ::com::sun::star::rdf::XMetadatable >
     744          66 : Meta::MakeUnoObject()
     745             : {
     746          66 :     return SwXMeta::CreateXMeta(*this);
     747             : }
     748             : 
     749             : /*************************************************************************
     750             :  class sw::MetaField
     751             :  ************************************************************************/
     752             : 
     753          26 : MetaField::MetaField(SwFmtMeta * const i_pFmt,
     754             :             const sal_uInt32 nNumberFormat, const bool bIsFixedLanguage)
     755             :     : Meta(i_pFmt)
     756             :     , m_nNumberFormat( nNumberFormat )
     757          26 :     , m_bIsFixedLanguage( bIsFixedLanguage )
     758             : {
     759          26 : }
     760             : 
     761          40 : void MetaField::GetPrefixAndSuffix(
     762             :         OUString *const o_pPrefix, OUString *const o_pSuffix)
     763             : {
     764             :     try
     765             :     {
     766          40 :         const uno::Reference<rdf::XMetadatable> xMetaField( MakeUnoObject() );
     767             :         OSL_ENSURE(dynamic_cast<SwXMetaField*>(xMetaField.get()),
     768             :                 "GetPrefixAndSuffix: no SwXMetaField?");
     769          40 :         if (xMetaField.is())
     770             :         {
     771          40 :             SwTxtNode * const pTxtNode( GetTxtNode() );
     772          40 :             SwDocShell const * const pShell(pTxtNode->GetDoc()->GetDocShell());
     773             :             const uno::Reference<frame::XModel> xModel(
     774          40 :                 (pShell) ? pShell->GetModel() : 0,  uno::UNO_SET_THROW);
     775          40 :             getPrefixAndSuffix(xModel, xMetaField, o_pPrefix, o_pSuffix);
     776          40 :         }
     777             :     }
     778           0 :     catch (const uno::Exception&)
     779             :     {
     780             :         OSL_FAIL("exception?");
     781             :     }
     782          40 : }
     783             : 
     784          24 : sal_uInt32 MetaField::GetNumberFormat(OUString const & rContent) const
     785             : {
     786             :     //TODO: this probably lacks treatment for some special cases
     787          24 :     sal_uInt32 nNumberFormat( m_nNumberFormat );
     788          24 :     SwTxtNode * const pTxtNode( GetTxtNode() );
     789          24 :     if (pTxtNode)
     790             :     {
     791             :         SvNumberFormatter *const pNumberFormatter(
     792          24 :                 pTxtNode->GetDoc()->GetNumberFormatter() );
     793             :         double number;
     794             :         (void) pNumberFormatter->IsNumberFormat(
     795          24 :                 rContent, nNumberFormat, number );
     796             :     }
     797          24 :     return nNumberFormat;
     798             : }
     799             : 
     800           5 : void MetaField::SetNumberFormat(sal_uInt32 nNumberFormat)
     801             : {
     802             :     // effectively, the member is only a default:
     803             :     // GetNumberFormat checks if the text actually conforms
     804           5 :     m_nNumberFormat = nNumberFormat;
     805           5 : }
     806             : 
     807             : /*************************************************************************
     808             :  class sw::MetaFieldManager
     809             :  ************************************************************************/
     810             : 
     811        1852 : MetaFieldManager::MetaFieldManager()
     812             : {
     813        1852 : }
     814             : 
     815             : ::boost::shared_ptr<MetaField>
     816          26 : MetaFieldManager::makeMetaField(SwFmtMeta * const i_pFmt,
     817             :         const sal_uInt32 nNumberFormat, const bool bIsFixedLanguage)
     818             : {
     819             :     const ::boost::shared_ptr<MetaField> pMetaField(
     820          26 :         new MetaField(i_pFmt, nNumberFormat, bIsFixedLanguage) );
     821          26 :     m_MetaFields.push_back(pMetaField);
     822          26 :     return pMetaField;
     823             : }
     824             : 
     825             : struct IsInUndo
     826             : {
     827          10 :     bool operator()(::boost::weak_ptr<MetaField> const & pMetaField) {
     828          10 :         return pMetaField.lock()->IsInUndo();
     829             :     }
     830             : };
     831             : 
     832             : struct MakeUnoObject
     833             : {
     834             :     uno::Reference<text::XTextField>
     835          10 :     operator()(::boost::weak_ptr<MetaField> const & pMetaField) {
     836             :         return uno::Reference<text::XTextField>(
     837          10 :                 pMetaField.lock()->MakeUnoObject(), uno::UNO_QUERY);
     838             :     }
     839             : };
     840             : 
     841             : ::std::vector< uno::Reference<text::XTextField> >
     842        1413 : MetaFieldManager::getMetaFields()
     843             : {
     844             :     // erase deleted fields
     845             :     const MetaFieldList_t::iterator iter(
     846             :         ::std::remove_if(m_MetaFields.begin(), m_MetaFields.end(),
     847        1413 :             ::boost::bind(&::boost::weak_ptr<MetaField>::expired, _1)));
     848        1413 :     m_MetaFields.erase(iter, m_MetaFields.end());
     849             :     // filter out fields in UNDO
     850        1413 :     MetaFieldList_t filtered(m_MetaFields.size());
     851             :     const MetaFieldList_t::iterator iter2(
     852             :     ::std::remove_copy_if(m_MetaFields.begin(), m_MetaFields.end(),
     853        1413 :         filtered.begin(), IsInUndo()));
     854        1413 :     filtered.erase(iter2, filtered.end());
     855             :     // create uno objects
     856        1413 :     ::std::vector< uno::Reference<text::XTextField> > ret(filtered.size());
     857             :     ::std::transform(filtered.begin(), filtered.end(), ret.begin(),
     858        1413 :             MakeUnoObject());
     859        1413 :     return ret;
     860             : }
     861             : 
     862         111 : } // namespace sw
     863             : 
     864             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10