LCOV - code coverage report
Current view: top level - libreoffice/svx/source/items - hlnkitem.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 165 0.6 %
Date: 2012-12-27 Functions: 1 15 6.7 %
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 <svx/svxids.hrc>
      21             : #include <tools/stream.hxx>
      22             : #include <svl/memberid.hrc>
      23             : #include <basic/sbxvar.hxx>
      24             : 
      25             : #include "svx/hlnkitem.hxx"
      26             : 
      27             : // -----------------------------------------------------------------------
      28             : 
      29          18 : TYPEINIT1_FACTORY(SvxHyperlinkItem, SfxPoolItem, new SvxHyperlinkItem(0));
      30             : 
      31             : // class SvxHyperlinkItem ------------------------------------------------
      32             : 
      33             : #define HYPERLINKFF_MARKER  0x599401FE
      34             : 
      35           0 : SvStream& SvxHyperlinkItem::Store( SvStream& rStrm, sal_uInt16 /*nItemVersion*/ ) const
      36             : {
      37             :     // store 'simple' data
      38             :     // UNICODE: rStrm << sName;
      39           0 :     rStrm.WriteUniOrByteString(sName, rStrm.GetStreamCharSet());
      40             : 
      41             :     // UNICODE: rStrm << sURL;
      42           0 :     rStrm.WriteUniOrByteString(sURL, rStrm.GetStreamCharSet());
      43             : 
      44             :     // UNICODE: rStrm << sTarget;
      45           0 :     rStrm.WriteUniOrByteString(sTarget, rStrm.GetStreamCharSet());
      46             : 
      47           0 :     rStrm << (sal_uInt32) eType;
      48             : 
      49             :     // marker for versioninfo
      50           0 :     rStrm << (sal_uInt32) HYPERLINKFF_MARKER;
      51             : 
      52             :     // new data
      53             :     // UNICODE: rStrm << sIntName;
      54           0 :     rStrm.WriteUniOrByteString(sIntName, rStrm.GetStreamCharSet());
      55             : 
      56             :     // macro-events
      57           0 :     rStrm << nMacroEvents;
      58             : 
      59             :     // store macros
      60           0 :     sal_uInt16 nCnt = pMacroTable ? (sal_uInt16)pMacroTable->size() : 0;
      61           0 :     sal_uInt16 nMax = nCnt;
      62           0 :     if( nCnt )
      63             :     {
      64           0 :         for ( SvxMacroTable::const_iterator it = pMacroTable->begin();
      65           0 :               it != pMacroTable->end(); ++it)
      66           0 :             if( STARBASIC != it->second.GetScriptType() )
      67           0 :                 --nCnt;
      68             :     }
      69             : 
      70           0 :     rStrm << nCnt;
      71             : 
      72           0 :     if( nCnt )
      73             :     {
      74             :         // 1. StarBasic-Macros
      75           0 :         for ( SvxMacroTable::const_iterator it = pMacroTable->begin();
      76           0 :               it != pMacroTable->end(); ++it)
      77             :         {
      78           0 :             const SvxMacro& rMac = it->second;
      79           0 :             if( STARBASIC == rMac.GetScriptType() )
      80             :             {
      81           0 :                 rStrm << (sal_uInt16)it->first;
      82             : 
      83             :                 // UNICODE: rStrm << pMac->GetLibName();
      84           0 :                 rStrm.WriteUniOrByteString(rMac.GetLibName(), rStrm.GetStreamCharSet());
      85             : 
      86             :                 // UNICODE: rStrm << pMac->GetMacName();
      87           0 :                 rStrm.WriteUniOrByteString(rMac.GetMacName(), rStrm.GetStreamCharSet());
      88             :             }
      89             :         }
      90             :     }
      91             : 
      92           0 :     nCnt = nMax - nCnt;
      93           0 :     rStrm << nCnt;
      94           0 :     if( nCnt )
      95             :     {
      96             :         // 2. ::com::sun::star::script::JavaScript-Macros
      97           0 :         for ( SvxMacroTable::const_iterator it = pMacroTable->begin();
      98           0 :               it != pMacroTable->end(); ++it)
      99             :         {
     100           0 :             const SvxMacro& rMac = it->second;
     101           0 :             if( STARBASIC != rMac.GetScriptType() )
     102             :             {
     103           0 :                 rStrm << (sal_uInt16)it->first;
     104             : 
     105             :                 // UNICODE: rStrm << pMac->GetLibName();
     106           0 :                 rStrm.WriteUniOrByteString(rMac.GetLibName(), rStrm.GetStreamCharSet());
     107             : 
     108             :                 // UNICODE: rStrm << pMac->GetMacName();
     109           0 :                 rStrm.WriteUniOrByteString(rMac.GetMacName(), rStrm.GetStreamCharSet());
     110             : 
     111           0 :                 rStrm << (sal_uInt16)rMac.GetScriptType();
     112             :             }
     113             :         }
     114             :     }
     115             : 
     116           0 :     return rStrm;
     117             : }
     118             : 
     119           0 : SfxPoolItem*    SvxHyperlinkItem::Create( SvStream &rStrm, sal_uInt16 /*nItemVersion*/ ) const
     120             : {
     121           0 :     SvxHyperlinkItem* pNew = new SvxHyperlinkItem( Which() );
     122             :     sal_uInt32 nType;
     123             : 
     124             :     // simple data-types
     125             :     // UNICODE: rStrm >> pNew->sName;
     126           0 :     pNew->sName = rStrm.ReadUniOrByteString(rStrm.GetStreamCharSet());
     127             : 
     128             :     // UNICODE: rStrm >> pNew->sURL;
     129           0 :     pNew->sURL = rStrm.ReadUniOrByteString(rStrm.GetStreamCharSet());
     130             : 
     131             :     // UNICODE: rStrm >> pNew->sTarget;
     132           0 :     pNew->sTarget = rStrm.ReadUniOrByteString(rStrm.GetStreamCharSet());
     133             : 
     134           0 :     rStrm >> nType;
     135           0 :     pNew->eType = (SvxLinkInsertMode) nType;
     136             : 
     137           0 :     sal_uInt32 nPos = rStrm.Tell();
     138             :     sal_uInt32 nMarker;
     139           0 :     rStrm >> nMarker;
     140           0 :     if ( nMarker == HYPERLINKFF_MARKER )
     141             :     {
     142             :         // new data
     143             :         // UNICODE: rStrm >> pNew->sIntName;
     144           0 :         pNew->sIntName = rStrm.ReadUniOrByteString(rStrm.GetStreamCharSet());
     145             : 
     146             :         // macro-events
     147           0 :         rStrm >> pNew->nMacroEvents;
     148             : 
     149             :         // macros
     150             :         sal_uInt16 nCnt;
     151           0 :         rStrm >> nCnt;
     152           0 :         while( nCnt-- )
     153             :         {
     154             :             sal_uInt16 nCurKey;
     155           0 :             String aLibName, aMacName;
     156             : 
     157           0 :             rStrm >> nCurKey;
     158             :             // UNICODE: rStrm >> aLibName;
     159           0 :             aLibName = rStrm.ReadUniOrByteString(rStrm.GetStreamCharSet());
     160             : 
     161             :             // UNICODE: rStrm >> aMacName;
     162           0 :             aMacName = rStrm.ReadUniOrByteString(rStrm.GetStreamCharSet());
     163             : 
     164           0 :             pNew->SetMacro( nCurKey, SvxMacro( aMacName, aLibName, STARBASIC ) );
     165           0 :         }
     166             : 
     167           0 :         rStrm >> nCnt;
     168           0 :         while( nCnt-- )
     169             :         {
     170             :             sal_uInt16 nCurKey, nScriptType;
     171           0 :             String aLibName, aMacName;
     172             : 
     173           0 :             rStrm >> nCurKey;
     174             : 
     175             :             // UNICODE: rStrm >> aLibName;
     176           0 :             aLibName = rStrm.ReadUniOrByteString(rStrm.GetStreamCharSet());
     177             : 
     178             :             // UNICODE: rStrm >> aMacName;
     179           0 :             aMacName = rStrm.ReadUniOrByteString(rStrm.GetStreamCharSet());
     180             : 
     181           0 :             rStrm >> nScriptType;
     182             : 
     183             :             pNew->SetMacro( nCurKey, SvxMacro( aMacName, aLibName,
     184           0 :                                         (ScriptType)nScriptType ) );
     185           0 :         }
     186             :     }
     187             :     else
     188           0 :         rStrm.Seek( nPos );
     189             : 
     190           0 :     return pNew;
     191             : }
     192             : 
     193           0 : SvxHyperlinkItem::SvxHyperlinkItem( const SvxHyperlinkItem& rHyperlinkItem ):
     194           0 :             SfxPoolItem(rHyperlinkItem)
     195             : {
     196           0 :     sName   = rHyperlinkItem.sName;
     197           0 :     sURL    = rHyperlinkItem.sURL;
     198           0 :     sTarget = rHyperlinkItem.sTarget;
     199           0 :     eType   = rHyperlinkItem.eType;
     200           0 :     sIntName = rHyperlinkItem.sIntName;
     201           0 :     nMacroEvents = rHyperlinkItem.nMacroEvents;
     202             : 
     203           0 :     if( rHyperlinkItem.GetMacroTbl() )
     204           0 :         pMacroTable = new SvxMacroTableDtor( *rHyperlinkItem.GetMacroTbl() );
     205             :     else
     206           0 :         pMacroTable=NULL;
     207             : 
     208           0 : };
     209             : 
     210           0 : SvxHyperlinkItem::SvxHyperlinkItem( sal_uInt16 _nWhich, String& rName, String& rURL,
     211             :                                     String& rTarget, String& rIntName, SvxLinkInsertMode eTyp,
     212             :                                     sal_uInt16 nEvents, SvxMacroTableDtor *pMacroTbl ):
     213             :     SfxPoolItem (_nWhich),
     214             :     sName       (rName),
     215             :     sURL        (rURL),
     216             :     sTarget     (rTarget),
     217             :     eType       (eTyp),
     218             :     sIntName (rIntName),
     219           0 :     nMacroEvents (nEvents)
     220             : {
     221           0 :     if (pMacroTbl)
     222           0 :         pMacroTable = new SvxMacroTableDtor ( *pMacroTbl );
     223             :     else
     224           0 :         pMacroTable=NULL;
     225           0 : }
     226             : 
     227           0 : SfxPoolItem* SvxHyperlinkItem::Clone( SfxItemPool* ) const
     228             : {
     229           0 :     return new SvxHyperlinkItem( *this );
     230             : }
     231             : 
     232           0 : int SvxHyperlinkItem::operator==( const SfxPoolItem& rAttr ) const
     233             : {
     234             :     DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unterschiedliche Typen" );
     235             : 
     236           0 :     const SvxHyperlinkItem& rItem = (const SvxHyperlinkItem&) rAttr;
     237             : 
     238           0 :     sal_Bool bRet = ( sName   == rItem.sName   &&
     239           0 :                   sURL    == rItem.sURL    &&
     240           0 :                   sTarget == rItem.sTarget &&
     241             :                   eType   == rItem.eType   &&
     242           0 :                   sIntName == rItem.sIntName &&
     243           0 :                   nMacroEvents == rItem.nMacroEvents);
     244           0 :     if (!bRet)
     245           0 :         return sal_False;
     246             : 
     247           0 :     const SvxMacroTableDtor* pOther = ((SvxHyperlinkItem&)rAttr).pMacroTable;
     248           0 :     if( !pMacroTable )
     249           0 :         return ( !pOther || pOther->empty() );
     250           0 :     if( !pOther )
     251           0 :         return pMacroTable->empty();
     252             : 
     253           0 :     const SvxMacroTableDtor& rOwn = *pMacroTable;
     254           0 :     const SvxMacroTableDtor& rOther = *pOther;
     255             : 
     256           0 :     return rOwn == rOther;
     257             : }
     258             : 
     259           0 : void SvxHyperlinkItem::SetMacro( sal_uInt16 nEvent, const SvxMacro& rMacro )
     260             : {
     261           0 :     if( nEvent < EVENT_SFX_START )
     262             :     {
     263           0 :         switch( nEvent )
     264             :         {
     265             :             case HYPERDLG_EVENT_MOUSEOVER_OBJECT:
     266           0 :                 nEvent = SFX_EVENT_MOUSEOVER_OBJECT;
     267           0 :                 break;
     268             :             case HYPERDLG_EVENT_MOUSECLICK_OBJECT:
     269           0 :                 nEvent = SFX_EVENT_MOUSECLICK_OBJECT;
     270           0 :                 break;
     271             :             case HYPERDLG_EVENT_MOUSEOUT_OBJECT:
     272           0 :                 nEvent = SFX_EVENT_MOUSEOUT_OBJECT;
     273           0 :                 break;
     274             :         }
     275             :     }
     276             : 
     277           0 :     if( !pMacroTable )
     278           0 :         pMacroTable = new SvxMacroTableDtor;
     279             : 
     280           0 :     pMacroTable->Insert( nEvent, rMacro);
     281           0 : }
     282             : 
     283           0 : void SvxHyperlinkItem::SetMacroTable( const SvxMacroTableDtor& rTbl )
     284             : {
     285           0 :     if ( pMacroTable )
     286           0 :         delete pMacroTable;
     287             : 
     288           0 :     pMacroTable = new SvxMacroTableDtor ( rTbl );
     289           0 : }
     290             : 
     291           0 : bool SvxHyperlinkItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId ) const
     292             : {
     293             : //    sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
     294           0 :     nMemberId &= ~CONVERT_TWIPS;
     295           0 :     switch(nMemberId)
     296             :     {
     297             :         case MID_HLINK_NAME   :
     298           0 :             rVal <<= ::rtl::OUString(sIntName.GetBuffer());
     299           0 :         break;
     300             :         case MID_HLINK_TEXT   :
     301           0 :             rVal <<= ::rtl::OUString(sName.GetBuffer());
     302           0 :         break;
     303             :         case MID_HLINK_URL:
     304           0 :             rVal <<= ::rtl::OUString(sURL.GetBuffer());
     305           0 :         break;
     306             :         case MID_HLINK_TARGET:
     307           0 :             rVal <<= ::rtl::OUString(sTarget.GetBuffer());
     308           0 :         break;
     309             :         case MID_HLINK_TYPE:
     310           0 :             rVal <<= (sal_Int32) eType;
     311           0 :         break;
     312             :         default:
     313           0 :             return false;
     314             :     }
     315             : 
     316           0 :     return true;
     317             : }
     318             : 
     319           0 : bool SvxHyperlinkItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId )
     320             : {
     321             : //    sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
     322           0 :     nMemberId &= ~CONVERT_TWIPS;
     323           0 :     ::rtl::OUString aStr;
     324           0 :     sal_Int32 nVal = 0;
     325           0 :     switch(nMemberId)
     326             :     {
     327             :         case MID_HLINK_NAME   :
     328           0 :             if(!(rVal >>= aStr))
     329           0 :                 return sal_False;
     330           0 :             sIntName = aStr.getStr();
     331           0 :         break;
     332             :         case MID_HLINK_TEXT   :
     333           0 :             if(!(rVal >>= aStr))
     334           0 :                 return sal_False;
     335           0 :             sName = aStr.getStr();
     336           0 :         break;
     337             :         case MID_HLINK_URL:
     338           0 :             if(!(rVal >>= aStr))
     339           0 :                 return sal_False;
     340           0 :             sURL = aStr.getStr();
     341           0 :         break;
     342             :         case MID_HLINK_TARGET:
     343           0 :             if(!(rVal >>= aStr))
     344           0 :                 return sal_False;
     345           0 :             sTarget = aStr.getStr();
     346           0 :         break;
     347             :         case MID_HLINK_TYPE:
     348           0 :             if(!(rVal >>= nVal))
     349           0 :                 return sal_False;
     350           0 :             eType = (SvxLinkInsertMode) (sal_uInt16) nVal;
     351           0 :         break;
     352             :         default:
     353           0 :             return false;
     354             :     }
     355             : 
     356           0 :     return true;
     357             : }
     358             : 
     359             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10